43 #include "../comedidev.h"
46 #include <linux/ctype.h>
49 #include <linux/slab.h>
51 #include <linux/kernel.h>
54 #define PCI_VENDOR_ID_JR3 0x1762
55 #define PCI_DEVICE_ID_JR3_1_CHANNEL 0x3111
56 #define PCI_DEVICE_ID_JR3_1_CHANNEL_NEW 0x1111
57 #define PCI_DEVICE_ID_JR3_2_CHANNEL 0x3112
58 #define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113
59 #define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114
108 static const char *
prefix =
"comedi/";
112 if (!firmware_path) {
115 firmware_path[0] =
'\0';
116 strcat(firmware_path, prefix);
117 strcat(firmware_path, name);
127 kfree(firmware_path);
159 for (i = 0; i < 8; i++) {
161 set_u16(&channel->
transforms[num].link[i].link_type,
162 transf.
link[i].link_type);
164 set_s16(&channel->
transforms[num].link[i].link_amount,
165 transf.
link[i].link_amount);
175 set_s16(&channel->
command_word0, 0x0500 + (transf_num & 0x000f));
180 set_s16(&channel->
command_word0, 0x0600 + (offset_num & 0x000f));
200 printk(
"%d %d %d %d %d %d\n",
203 full_scale.
fz, full_scale.
mx, full_scale.
my, full_scale.
mz);
217 result.
fx = get_s16(&
channel->min_full_scale.fx);
218 result.fy = get_s16(&
channel->min_full_scale.fy);
219 result.fz = get_s16(&
channel->min_full_scale.fz);
220 result.mx = get_s16(&
channel->min_full_scale.mx);
221 result.my = get_s16(&
channel->min_full_scale.my);
222 result.mz = get_s16(&
channel->min_full_scale.mz);
230 result.
fx = get_s16(&
channel->max_full_scale.fx);
231 result.fy = get_s16(&
channel->max_full_scale.fy);
232 result.fz = get_s16(&
channel->max_full_scale.fz);
233 result.mx = get_s16(&
channel->max_full_scale.mx);
234 result.my = get_s16(&
channel->max_full_scale.my);
235 result.mz = get_s16(&
channel->max_full_scale.mz);
249 if (p ==
NULL || channel > 57) {
265 for (i = 0; i < insn->
n; i++) {
270 filter = channel / 8;
325 data[
i] = F + 0x4000;
327 }
else if (channel == 56) {
334 }
else if (channel == 57) {
365 static int read_idm_word(
const u8 *data,
size_t size,
int *
pos,
371 for (; *pos < size && !
isxdigit(data[*pos]); (*pos)++) {
375 for (; *pos <
size; (*pos)++) {
380 *val = (*val << 4) + value;
388 static int jr3_download_firmware(
struct comedi_device *dev,
const u8 * data,
405 more = more && read_idm_word(data, size, &pos, &count);
406 if (more && count == 0xffff) {
410 more = more && read_idm_word(data, size, &pos, &addr);
411 while (more && count > 0) {
413 more = more && read_idm_word(data, size, &pos, &dummy);
433 && read_idm_word(data, size, &pos, &count);
434 if (more && count == 0xffff)
437 && read_idm_word(data, size, &pos, &addr);
439 "Loading#%d %4.4x bytes at %4.4x\n",
441 while (more && count > 0) {
447 && read_idm_word(data,
458 && read_idm_word(data,
462 && read_idm_word(data, size,
490 struct poll_delay_t result = poll_delay_min_max(1000, 2000);
498 if (errors != p->
errors) {
504 p->
state = state_jr3_poll;
508 case state_jr3_poll:{
512 model_no == 0 || serial_no == 0) {
517 result = poll_delay_min_max(1000, 2000);
521 state_jr3_init_wait_for_offset;
522 result = poll_delay_min_max(1000, 2000);
526 case state_jr3_init_wait_for_offset:{
530 result = poll_delay_min_max(1000, 2000);
540 (
"Setting transform for channel %d\n",
542 printk(
"Sensor Model = %i\n",
544 printk(
"Sensor Serial = %i\n",
548 for (i = 0; i <
ARRAY_SIZE(transf.link); i++) {
549 transf.link[
i].link_type =
551 transf.link[
i].link_amount = 0;
554 set_transforms(channel, transf, 0);
555 use_transform(channel, 0);
557 state_jr3_init_transform_complete;
558 result = poll_delay_min_max(20, 100);
561 case state_jr3_init_transform_complete:{
562 if (!is_complete(channel)) {
564 (
"state_jr3_init_transform_complete complete = %d\n",
565 is_complete(channel));
566 result = poll_delay_min_max(20, 100);
573 get_min_full_scales(channel);
574 printk(
"Obtained Min. Full Scales:\n");
584 get_max_full_scales(channel);
585 printk(
"Obtained Max. Full Scales:\n");
594 set_full_scales(channel,
598 state_jr3_init_set_full_scale_complete;
599 result = poll_delay_min_max(20, 100);
603 case state_jr3_init_set_full_scale_complete:{
604 if (!is_complete(channel)) {
606 (
"state_jr3_init_set_full_scale_complete complete = %d\n",
607 is_complete(channel));
608 result = poll_delay_min_max(20, 100);
614 p->
range[0].range.min =
615 -get_s16(&full_scale->
fx) * 1000;
616 p->
range[0].range.max =
617 get_s16(&full_scale->
fx) * 1000;
618 p->
range[1].range.min =
619 -get_s16(&full_scale->
fy) * 1000;
620 p->
range[1].range.max =
621 get_s16(&full_scale->
fy) * 1000;
622 p->
range[2].range.min =
623 -get_s16(&full_scale->
fz) * 1000;
624 p->
range[2].range.max =
625 get_s16(&full_scale->
fz) * 1000;
626 p->
range[3].range.min =
627 -get_s16(&full_scale->
mx) * 100;
628 p->
range[3].range.max =
629 get_s16(&full_scale->
mx) * 100;
630 p->
range[4].range.min =
631 -get_s16(&full_scale->
my) * 100;
632 p->
range[4].range.max =
633 get_s16(&full_scale->
my) * 100;
634 p->
range[5].range.min =
635 -get_s16(&full_scale->
mz) * 100;
636 p->
range[5].range.max =
637 get_s16(&full_scale->
mz) * 100;
638 p->
range[6].range.min = -get_s16(&full_scale->
v1) * 100;
639 p->
range[6].range.max = get_s16(&full_scale->
v1) * 100;
640 p->
range[7].range.min = -get_s16(&full_scale->
v2) * 100;
641 p->
range[7].range.max = get_s16(&full_scale->
v2) * 100;
642 p->
range[8].range.min = 0;
643 p->
range[8].range.max = 65535;
647 for (i = 0; i < 9; i++) {
659 use_offset(channel, 0);
661 state_jr3_init_use_offset_complete;
662 result = poll_delay_min_max(40, 100);
666 case state_jr3_init_use_offset_complete:{
667 if (!is_complete(channel)) {
669 (
"state_jr3_init_use_offset_complete complete = %d\n",
670 is_complete(channel));
671 result = poll_delay_min_max(20, 100);
674 (
"Default offsets %d %d %d %d %d %d\n",
680 get_s16(&channel->
offsets.mz));
682 set_s16(&channel->
offsets.fx, 0);
683 set_s16(&channel->
offsets.fy, 0);
684 set_s16(&channel->
offsets.fz, 0);
685 set_s16(&channel->
offsets.mx, 0);
686 set_s16(&channel->
offsets.my, 0);
687 set_s16(&channel->
offsets.mz, 0);
691 p->
state = state_jr3_done;
695 case state_jr3_done:{
696 poll_delay_min_max(10000, 20000);
700 poll_delay_min_max(1000, 2000);
708 static void jr3_pci_poll_dev(
unsigned long data)
727 sub_delay = jr3_pci_poll_subdevice(&dev->
subdevices[i]);
732 if (sub_delay.max && sub_delay.max < delay) {
737 delay = sub_delay.max;
741 spin_unlock_irqrestore(&dev->
spinlock, flags);
752 int opt_bus, opt_slot,
i;
760 "sizeof(struct jr3_channel) = %x [expected %x]\n",
803 if (opt_bus == 0 && opt_slot == 0) {
806 }
else if (opt_bus == card->
bus->number &&
836 dev->
open = jr3_pci_open;
841 dev->
subdevices[
i].insn_read = jr3_pci_ai_insn_read;
853 (
char *)(devpriv->
iobase)));
855 for (j = 0; j < 8; j++) {
859 p->
range[
j].range.min = -1000000;
860 p->
range[
j].range.max = 1000000;
861 for (k = 0; k < 7; k++) {
868 p->
range[8].length = 1;
869 p->
range[8].range.min = 0;
870 p->
range[8].range.max = 65536;
890 result = comedi_load_firmware(dev,
"jr3pci.idm", jr3_download_firmware);
908 for (i = 0; i < 0x18; i++) {
911 data.copyright[i]) >> 8);
922 devpriv->
timer.data = (
unsigned long)dev;
923 devpriv->
timer.function = jr3_pci_poll_dev;
953 .driver_name =
"jr3_pci",
955 .attach = jr3_pci_attach,
956 .detach = jr3_pci_detach,
980 static struct pci_driver jr3_pci_pci_driver = {
982 .id_table = jr3_pci_pci_table,
983 .probe = jr3_pci_pci_probe,