2 comedi/drivers/jr3_pci.c
3 hardware driver for JR3/PCI force sensor board
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2007 Anders Blomdell <anders.blomdell@control.lth.se>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Description: JR3/PCI force sensor board
26 Author: Anders Blomdell <anders.blomdell@control.lth.se>
28 Devices: [JR3] PCI force sensor board (jr3_pci)
30 The DSP on the board requires initialization code, which can
31 be loaded by placing it in /lib/firmware/comedi.
32 The initialization code should be somewhere on the media you got
33 with your card. One version is available from http://www.comedi.org
34 in the comedi_nonfree_firmware tarball.
36 Configuration options:
37 [0] - PCI bus number - if bus number and slot number are 0,
38 then driver search for first unused card
43 #include "../comedidev.h"
45 #include <linux/delay.h>
46 #include <linux/ctype.h>
47 #include <linux/firmware.h>
48 #include <linux/jiffies.h>
49 #include <linux/slab.h>
50 #include <linux/timer.h>
51 #include <linux/kernel.h>
52 #include "comedi_pci.h"
55 #define PCI_VENDOR_ID_JR3 0x1762
56 #define PCI_DEVICE_ID_JR3_1_CHANNEL 0x3111
57 #define PCI_DEVICE_ID_JR3_1_CHANNEL_NEW 0x1111
58 #define PCI_DEVICE_ID_JR3_2_CHANNEL 0x3112
59 #define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113
60 #define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114
62 static int jr3_pci_attach(struct comedi_device
*dev
,
63 struct comedi_devconfig
*it
);
64 static int jr3_pci_detach(struct comedi_device
*dev
);
66 static struct comedi_driver driver_jr3_pci
= {
67 .driver_name
= "jr3_pci",
68 .module
= THIS_MODULE
,
69 .attach
= jr3_pci_attach
,
70 .detach
= jr3_pci_detach
,
73 static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table
) = {
75 PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_1_CHANNEL
,
76 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
77 PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW
,
78 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
79 PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_2_CHANNEL
,
80 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
81 PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_3_CHANNEL
,
82 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
83 PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_4_CHANNEL
,
84 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
88 MODULE_DEVICE_TABLE(pci
, jr3_pci_pci_table
);
90 struct jr3_pci_dev_private
{
92 struct pci_dev
*pci_dev
;
94 volatile struct jr3_t
*iobase
;
96 struct timer_list timer
;
105 struct jr3_pci_subdev_private
{
106 volatile struct jr3_channel
*channel
;
107 unsigned long next_time_min
;
108 unsigned long next_time_max
;
109 enum { state_jr3_poll
,
110 state_jr3_init_wait_for_offset
,
111 state_jr3_init_transform_complete
,
112 state_jr3_init_set_full_scale_complete
,
113 state_jr3_init_use_offset_complete
,
121 struct comedi_krange range
;
123 const struct comedi_lrange
*range_table_list
[8 * 7 + 2];
124 unsigned int maxdata_list
[8 * 7 + 2];
129 /* Hotplug firmware loading stuff */
130 static int comedi_load_firmware(struct comedi_device
*dev
, char *name
,
131 int (*cb
)(struct comedi_device
*dev
,
132 const u8
*data
, size_t size
))
135 const struct firmware
*fw
;
137 static const char *prefix
= "comedi/";
138 struct jr3_pci_dev_private
*devpriv
= dev
->private;
140 firmware_path
= kmalloc(strlen(prefix
) + strlen(name
) + 1, GFP_KERNEL
);
141 if (!firmware_path
) {
144 firmware_path
[0] = '\0';
145 strcat(firmware_path
, prefix
);
146 strcat(firmware_path
, name
);
147 result
= request_firmware(&fw
, firmware_path
,
148 &devpriv
->pci_dev
->dev
);
153 result
= cb(dev
, fw
->data
, fw
->size
);
154 release_firmware(fw
);
156 kfree(firmware_path
);
161 static struct poll_delay_t
poll_delay_min_max(int min
, int max
)
163 struct poll_delay_t result
;
170 static int is_complete(volatile struct jr3_channel
*channel
)
172 return get_s16(&channel
->command_word0
) == 0;
182 static void set_transforms(volatile struct jr3_channel
*channel
,
183 struct transform_t transf
, short num
)
187 num
&= 0x000f; /* Make sure that 0 <= num <= 15 */
188 for (i
= 0; i
< 8; i
++) {
190 set_u16(&channel
->transforms
[num
].link
[i
].link_type
,
191 transf
.link
[i
].link_type
);
193 set_s16(&channel
->transforms
[num
].link
[i
].link_amount
,
194 transf
.link
[i
].link_amount
);
196 if (transf
.link
[i
].link_type
== end_x_form
) {
202 static void use_transform(volatile struct jr3_channel
*channel
,
205 set_s16(&channel
->command_word0
, 0x0500 + (transf_num
& 0x000f));
208 static void use_offset(volatile struct jr3_channel
*channel
, short offset_num
)
210 set_s16(&channel
->command_word0
, 0x0600 + (offset_num
& 0x000f));
213 static void set_offset(volatile struct jr3_channel
*channel
)
215 set_s16(&channel
->command_word0
, 0x0700);
227 static void set_full_scales(volatile struct jr3_channel
*channel
,
228 struct six_axis_t full_scale
)
230 printk("%d %d %d %d %d %d\n",
233 full_scale
.fz
, full_scale
.mx
, full_scale
.my
, full_scale
.mz
);
234 set_s16(&channel
->full_scale
.fx
, full_scale
.fx
);
235 set_s16(&channel
->full_scale
.fy
, full_scale
.fy
);
236 set_s16(&channel
->full_scale
.fz
, full_scale
.fz
);
237 set_s16(&channel
->full_scale
.mx
, full_scale
.mx
);
238 set_s16(&channel
->full_scale
.my
, full_scale
.my
);
239 set_s16(&channel
->full_scale
.mz
, full_scale
.mz
);
240 set_s16(&channel
->command_word0
, 0x0a00);
243 static struct six_axis_t
get_min_full_scales(volatile struct jr3_channel
246 struct six_axis_t result
;
247 result
.fx
= get_s16(&channel
->min_full_scale
.fx
);
248 result
.fy
= get_s16(&channel
->min_full_scale
.fy
);
249 result
.fz
= get_s16(&channel
->min_full_scale
.fz
);
250 result
.mx
= get_s16(&channel
->min_full_scale
.mx
);
251 result
.my
= get_s16(&channel
->min_full_scale
.my
);
252 result
.mz
= get_s16(&channel
->min_full_scale
.mz
);
256 static struct six_axis_t
get_max_full_scales(volatile struct jr3_channel
259 struct six_axis_t result
;
260 result
.fx
= get_s16(&channel
->max_full_scale
.fx
);
261 result
.fy
= get_s16(&channel
->max_full_scale
.fy
);
262 result
.fz
= get_s16(&channel
->max_full_scale
.fz
);
263 result
.mx
= get_s16(&channel
->max_full_scale
.mx
);
264 result
.my
= get_s16(&channel
->max_full_scale
.my
);
265 result
.mz
= get_s16(&channel
->max_full_scale
.mz
);
269 static int jr3_pci_ai_insn_read(struct comedi_device
*dev
,
270 struct comedi_subdevice
*s
,
271 struct comedi_insn
*insn
, unsigned int *data
)
274 struct jr3_pci_subdev_private
*p
;
278 channel
= CR_CHAN(insn
->chanspec
);
279 if (p
== NULL
|| channel
> 57) {
285 if (p
->state
!= state_jr3_done
||
286 (get_u16(&p
->channel
->errors
) & (watch_dog
| watch_dog2
|
288 /* No sensor or sensor changed */
289 if (p
->state
== state_jr3_done
) {
290 /* Restart polling */
291 p
->state
= state_jr3_poll
;
295 for (i
= 0; i
< insn
->n
; i
++) {
300 filter
= channel
/ 8;
301 if (p
->state
!= state_jr3_done
) {
355 data
[i
] = F
+ 0x4000;
357 } else if (channel
== 56) {
358 if (p
->state
!= state_jr3_done
) {
362 get_u16(&p
->channel
->model_no
);
364 } else if (channel
== 57) {
365 if (p
->state
!= state_jr3_done
) {
369 get_u16(&p
->channel
->serial_no
);
377 static int jr3_pci_open(struct comedi_device
*dev
)
380 struct jr3_pci_dev_private
*devpriv
= dev
->private;
382 printk("jr3_pci_open\n");
383 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
384 struct jr3_pci_subdev_private
*p
;
386 p
= dev
->subdevices
[i
].private;
388 printk("serial: %p %d (%d)\n", p
, p
->serial_no
,
395 int read_idm_word(const u8
* data
, size_t size
, int *pos
, unsigned int *val
)
398 if (pos
!= 0 && val
!= 0) {
399 /* Skip over non hex */
400 for (; *pos
< size
&& !isxdigit(data
[*pos
]); (*pos
)++) {
404 for (; *pos
< size
; (*pos
)++) {
406 value
= hex_to_bin(data
[*pos
]);
409 *val
= (*val
<< 4) + value
;
417 static int jr3_download_firmware(struct comedi_device
*dev
, const u8
* data
,
421 * IDM file format is:
422 * { count, address, data <count> } *
425 int result
, more
, pos
, OK
;
432 unsigned int count
, addr
;
434 more
= more
&& read_idm_word(data
, size
, &pos
, &count
);
435 if (more
&& count
== 0xffff) {
439 more
= more
&& read_idm_word(data
, size
, &pos
, &addr
);
440 while (more
&& count
> 0) {
442 more
= more
&& read_idm_word(data
, size
, &pos
, &dummy
);
451 struct jr3_pci_dev_private
*p
= dev
->private;
453 for (i
= 0; i
< p
->n_channels
; i
++) {
454 struct jr3_pci_subdev_private
*sp
;
456 sp
= dev
->subdevices
[i
].private;
460 unsigned int count
, addr
;
462 && read_idm_word(data
, size
, &pos
, &count
);
463 if (more
&& count
== 0xffff) {
467 && read_idm_word(data
, size
, &pos
, &addr
);
468 printk("Loading#%d %4.4x bytes at %4.4x\n", i
,
470 while (more
&& count
> 0) {
472 /* 16 bit data, never seen in real life!! */
476 && read_idm_word(data
,
480 /* printk("jr3_data, not tested\n"); */
481 /* jr3[addr + 0x20000 * pnum] = data1; */
483 /* Download 24 bit program */
484 unsigned int data1
, data2
;
487 && read_idm_word(data
,
491 && read_idm_word(data
, size
,
517 static struct poll_delay_t
jr3_pci_poll_subdevice(struct comedi_subdevice
*s
)
519 struct poll_delay_t result
= poll_delay_min_max(1000, 2000);
520 struct jr3_pci_subdev_private
*p
= s
->private;
524 volatile struct jr3_channel
*channel
= p
->channel
;
525 int errors
= get_u16(&channel
->errors
);
527 if (errors
!= p
->errors
) {
528 printk("Errors: %x -> %x\n", p
->errors
, errors
);
531 if (errors
& (watch_dog
| watch_dog2
| sensor_change
)) {
532 /* Sensor communication lost, force poll mode */
533 p
->state
= state_jr3_poll
;
537 case state_jr3_poll
:{
538 u16 model_no
= get_u16(&channel
->model_no
);
539 u16 serial_no
= get_u16(&channel
->serial_no
);
540 if ((errors
& (watch_dog
| watch_dog2
)) ||
541 model_no
== 0 || serial_no
== 0) {
543 * Still no sensor, keep on polling. Since it takes up to 10 seconds
544 * for offsets to stabilize, polling each second should suffice.
546 result
= poll_delay_min_max(1000, 2000);
550 state_jr3_init_wait_for_offset
;
551 result
= poll_delay_min_max(1000, 2000);
555 case state_jr3_init_wait_for_offset
:{
557 if (p
->retries
< 10) {
558 /* Wait for offeset to stabilize (< 10 s according to manual) */
559 result
= poll_delay_min_max(1000, 2000);
561 struct transform_t transf
;
564 get_u16(&channel
->model_no
);
566 get_u16(&channel
->serial_no
);
569 ("Setting transform for channel %d\n",
571 printk("Sensor Model = %i\n",
573 printk("Sensor Serial = %i\n",
576 /* Transformation all zeros */
577 for (i
= 0; i
< ARRAY_SIZE(transf
.link
); i
++) {
578 transf
.link
[i
].link_type
=
580 transf
.link
[i
].link_amount
= 0;
583 set_transforms(channel
, transf
, 0);
584 use_transform(channel
, 0);
586 state_jr3_init_transform_complete
;
587 result
= poll_delay_min_max(20, 100); /* Allow 20 ms for completion */
590 case state_jr3_init_transform_complete
:{
591 if (!is_complete(channel
)) {
593 ("state_jr3_init_transform_complete complete = %d\n",
594 is_complete(channel
));
595 result
= poll_delay_min_max(20, 100);
598 struct six_axis_t min_full_scale
;
599 struct six_axis_t max_full_scale
;
602 get_min_full_scales(channel
);
603 printk("Obtained Min. Full Scales:\n");
604 printk("%i ", (min_full_scale
).fx
);
605 printk("%i ", (min_full_scale
).fy
);
606 printk("%i ", (min_full_scale
).fz
);
607 printk("%i ", (min_full_scale
).mx
);
608 printk("%i ", (min_full_scale
).my
);
609 printk("%i ", (min_full_scale
).mz
);
613 get_max_full_scales(channel
);
614 printk("Obtained Max. Full Scales:\n");
615 printk("%i ", (max_full_scale
).fx
);
616 printk("%i ", (max_full_scale
).fy
);
617 printk("%i ", (max_full_scale
).fz
);
618 printk("%i ", (max_full_scale
).mx
);
619 printk("%i ", (max_full_scale
).my
);
620 printk("%i ", (max_full_scale
).mz
);
623 set_full_scales(channel
,
627 state_jr3_init_set_full_scale_complete
;
628 result
= poll_delay_min_max(20, 100); /* Allow 20 ms for completion */
632 case state_jr3_init_set_full_scale_complete
:{
633 if (!is_complete(channel
)) {
635 ("state_jr3_init_set_full_scale_complete complete = %d\n",
636 is_complete(channel
));
637 result
= poll_delay_min_max(20, 100);
639 volatile struct force_array
*full_scale
;
641 /* Use ranges in kN or we will overflow arount 2000N! */
642 full_scale
= &channel
->full_scale
;
643 p
->range
[0].range
.min
=
644 -get_s16(&full_scale
->fx
) * 1000;
645 p
->range
[0].range
.max
=
646 get_s16(&full_scale
->fx
) * 1000;
647 p
->range
[1].range
.min
=
648 -get_s16(&full_scale
->fy
) * 1000;
649 p
->range
[1].range
.max
=
650 get_s16(&full_scale
->fy
) * 1000;
651 p
->range
[2].range
.min
=
652 -get_s16(&full_scale
->fz
) * 1000;
653 p
->range
[2].range
.max
=
654 get_s16(&full_scale
->fz
) * 1000;
655 p
->range
[3].range
.min
=
656 -get_s16(&full_scale
->mx
) * 100;
657 p
->range
[3].range
.max
=
658 get_s16(&full_scale
->mx
) * 100;
659 p
->range
[4].range
.min
=
660 -get_s16(&full_scale
->my
) * 100;
661 p
->range
[4].range
.max
=
662 get_s16(&full_scale
->my
) * 100;
663 p
->range
[5].range
.min
=
664 -get_s16(&full_scale
->mz
) * 100;
665 p
->range
[5].range
.max
=
666 get_s16(&full_scale
->mz
) * 100;
667 p
->range
[6].range
.min
= -get_s16(&full_scale
->v1
) * 100; /* ?? */
668 p
->range
[6].range
.max
= get_s16(&full_scale
->v1
) * 100; /* ?? */
669 p
->range
[7].range
.min
= -get_s16(&full_scale
->v2
) * 100; /* ?? */
670 p
->range
[7].range
.max
= get_s16(&full_scale
->v2
) * 100; /* ?? */
671 p
->range
[8].range
.min
= 0;
672 p
->range
[8].range
.max
= 65535;
676 for (i
= 0; i
< 9; i
++) {
677 printk("%d %d - %d\n",
688 use_offset(channel
, 0);
690 state_jr3_init_use_offset_complete
;
691 result
= poll_delay_min_max(40, 100); /* Allow 40 ms for completion */
695 case state_jr3_init_use_offset_complete
:{
696 if (!is_complete(channel
)) {
698 ("state_jr3_init_use_offset_complete complete = %d\n",
699 is_complete(channel
));
700 result
= poll_delay_min_max(20, 100);
703 ("Default offsets %d %d %d %d %d %d\n",
704 get_s16(&channel
->offsets
.fx
),
705 get_s16(&channel
->offsets
.fy
),
706 get_s16(&channel
->offsets
.fz
),
707 get_s16(&channel
->offsets
.mx
),
708 get_s16(&channel
->offsets
.my
),
709 get_s16(&channel
->offsets
.mz
));
711 set_s16(&channel
->offsets
.fx
, 0);
712 set_s16(&channel
->offsets
.fy
, 0);
713 set_s16(&channel
->offsets
.fz
, 0);
714 set_s16(&channel
->offsets
.mx
, 0);
715 set_s16(&channel
->offsets
.my
, 0);
716 set_s16(&channel
->offsets
.mz
, 0);
720 p
->state
= state_jr3_done
;
724 case state_jr3_done
:{
725 poll_delay_min_max(10000, 20000);
729 poll_delay_min_max(1000, 2000);
737 static void jr3_pci_poll_dev(unsigned long data
)
740 struct comedi_device
*dev
= (struct comedi_device
*)data
;
741 struct jr3_pci_dev_private
*devpriv
= dev
->private;
746 spin_lock_irqsave(&dev
->spinlock
, flags
);
749 /* Poll all channels that are ready to be polled */
750 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
751 struct jr3_pci_subdev_private
*subdevpriv
=
752 dev
->subdevices
[i
].private;
753 if (now
> subdevpriv
->next_time_min
) {
754 struct poll_delay_t sub_delay
;
756 sub_delay
= jr3_pci_poll_subdevice(&dev
->subdevices
[i
]);
757 subdevpriv
->next_time_min
=
758 jiffies
+ msecs_to_jiffies(sub_delay
.min
);
759 subdevpriv
->next_time_max
=
760 jiffies
+ msecs_to_jiffies(sub_delay
.max
);
761 if (sub_delay
.max
&& sub_delay
.max
< delay
) {
763 * Wake up as late as possible -> poll as many channels as possible
766 delay
= sub_delay
.max
;
770 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
772 devpriv
->timer
.expires
= jiffies
+ msecs_to_jiffies(delay
);
773 add_timer(&devpriv
->timer
);
776 static int jr3_pci_attach(struct comedi_device
*dev
,
777 struct comedi_devconfig
*it
)
780 struct pci_dev
*card
= NULL
;
781 int opt_bus
, opt_slot
, i
;
782 struct jr3_pci_dev_private
*devpriv
;
784 printk("comedi%d: jr3_pci\n", dev
->minor
);
786 opt_bus
= it
->options
[0];
787 opt_slot
= it
->options
[1];
789 if (sizeof(struct jr3_channel
) != 0xc00) {
790 printk("sizeof(struct jr3_channel) = %x [expected %x]\n",
791 (unsigned)sizeof(struct jr3_channel
), 0xc00);
795 result
= alloc_private(dev
, sizeof(struct jr3_pci_dev_private
));
800 devpriv
= dev
->private;
801 init_timer(&devpriv
->timer
);
803 card
= pci_get_device(PCI_VENDOR_ID_JR3
, PCI_ANY_ID
, card
);
808 switch (card
->device
) {
809 case PCI_DEVICE_ID_JR3_1_CHANNEL
:{
810 devpriv
->n_channels
= 1;
813 case PCI_DEVICE_ID_JR3_1_CHANNEL_NEW
:{
814 devpriv
->n_channels
= 1;
817 case PCI_DEVICE_ID_JR3_2_CHANNEL
:{
818 devpriv
->n_channels
= 2;
821 case PCI_DEVICE_ID_JR3_3_CHANNEL
:{
822 devpriv
->n_channels
= 3;
825 case PCI_DEVICE_ID_JR3_4_CHANNEL
:{
826 devpriv
->n_channels
= 4;
830 devpriv
->n_channels
= 0;
833 if (devpriv
->n_channels
>= 1) {
834 if (opt_bus
== 0 && opt_slot
== 0) {
835 /* Take first available card */
837 } else if (opt_bus
== card
->bus
->number
&&
838 opt_slot
== PCI_SLOT(card
->devfn
)) {
839 /* Take requested card */
846 printk(" no jr3_pci found\n");
849 devpriv
->pci_dev
= card
;
850 dev
->board_name
= "jr3_pci";
853 result
= comedi_pci_enable(card
, "jr3_pci");
858 devpriv
->pci_enabled
= 1;
859 devpriv
->iobase
= ioremap(pci_resource_start(card
, 0),
860 offsetof(struct jr3_t
, channel
[devpriv
->n_channels
]));
861 if (!devpriv
->iobase
)
864 result
= alloc_subdevices(dev
, devpriv
->n_channels
);
868 dev
->open
= jr3_pci_open
;
869 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
870 dev
->subdevices
[i
].type
= COMEDI_SUBD_AI
;
871 dev
->subdevices
[i
].subdev_flags
= SDF_READABLE
| SDF_GROUND
;
872 dev
->subdevices
[i
].n_chan
= 8 * 7 + 2;
873 dev
->subdevices
[i
].insn_read
= jr3_pci_ai_insn_read
;
874 dev
->subdevices
[i
].private =
875 kzalloc(sizeof(struct jr3_pci_subdev_private
), GFP_KERNEL
);
876 if (dev
->subdevices
[i
].private) {
877 struct jr3_pci_subdev_private
*p
;
880 p
= dev
->subdevices
[i
].private;
881 p
->channel
= &devpriv
->iobase
->channel
[i
].data
;
882 printk("p->channel %p %p (%tx)\n",
883 p
->channel
, devpriv
->iobase
,
884 ((char *)(p
->channel
) -
885 (char *)(devpriv
->iobase
)));
887 for (j
= 0; j
< 8; j
++) {
890 p
->range
[j
].length
= 1;
891 p
->range
[j
].range
.min
= -1000000;
892 p
->range
[j
].range
.max
= 1000000;
893 for (k
= 0; k
< 7; k
++) {
894 p
->range_table_list
[j
+ k
* 8] =
895 (struct comedi_lrange
*)&p
->
897 p
->maxdata_list
[j
+ k
* 8] = 0x7fff;
900 p
->range
[8].length
= 1;
901 p
->range
[8].range
.min
= 0;
902 p
->range
[8].range
.max
= 65536;
904 p
->range_table_list
[56] =
905 (struct comedi_lrange
*)&p
->range
[8];
906 p
->range_table_list
[57] =
907 (struct comedi_lrange
*)&p
->range
[8];
908 p
->maxdata_list
[56] = 0xffff;
909 p
->maxdata_list
[57] = 0xffff;
910 /* Channel specific range and maxdata */
911 dev
->subdevices
[i
].range_table
= 0;
912 dev
->subdevices
[i
].range_table_list
=
914 dev
->subdevices
[i
].maxdata
= 0;
915 dev
->subdevices
[i
].maxdata_list
= p
->maxdata_list
;
920 devpriv
->iobase
->channel
[0].reset
= 0;
922 result
= comedi_load_firmware(dev
, "jr3pci.idm", jr3_download_firmware
);
923 printk("Firmare load %d\n", result
);
929 * TODO: use firmware to load preferred offset tables. Suggested
931 * model serial Fx Fy Fz Mx My Mz\n
933 * comedi_load_firmware(dev, "jr3_offsets_table", jr3_download_firmware);
937 * It takes a few milliseconds for software to settle as much as we
938 * can read firmware version
940 msleep_interruptible(25);
941 for (i
= 0; i
< 0x18; i
++) {
943 get_u16(&devpriv
->iobase
->channel
[0].
944 data
.copyright
[i
]) >> 8);
947 /* Start card timer */
948 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
949 struct jr3_pci_subdev_private
*p
= dev
->subdevices
[i
].private;
951 p
->next_time_min
= jiffies
+ msecs_to_jiffies(500);
952 p
->next_time_max
= jiffies
+ msecs_to_jiffies(2000);
955 devpriv
->timer
.data
= (unsigned long)dev
;
956 devpriv
->timer
.function
= jr3_pci_poll_dev
;
957 devpriv
->timer
.expires
= jiffies
+ msecs_to_jiffies(1000);
958 add_timer(&devpriv
->timer
);
964 MODULE_FIRMWARE("comedi/jr3pci.idm");
966 static int jr3_pci_detach(struct comedi_device
*dev
)
969 struct jr3_pci_dev_private
*devpriv
= dev
->private;
971 printk("comedi%d: jr3_pci: remove\n", dev
->minor
);
973 del_timer_sync(&devpriv
->timer
);
975 if (dev
->subdevices
) {
976 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
977 kfree(dev
->subdevices
[i
].private);
981 if (devpriv
->iobase
) {
982 iounmap((void *)devpriv
->iobase
);
984 if (devpriv
->pci_enabled
) {
985 comedi_pci_disable(devpriv
->pci_dev
);
988 if (devpriv
->pci_dev
) {
989 pci_dev_put(devpriv
->pci_dev
);
995 static int __devinit
driver_jr3_pci_pci_probe(struct pci_dev
*dev
,
996 const struct pci_device_id
*ent
)
998 return comedi_pci_auto_config(dev
, driver_jr3_pci
.driver_name
);
1001 static void __devexit
driver_jr3_pci_pci_remove(struct pci_dev
*dev
)
1003 comedi_pci_auto_unconfig(dev
);
1006 static struct pci_driver driver_jr3_pci_pci_driver
= {
1007 .id_table
= jr3_pci_pci_table
,
1008 .probe
= &driver_jr3_pci_pci_probe
,
1009 .remove
= __devexit_p(&driver_jr3_pci_pci_remove
)
1012 static int __init
driver_jr3_pci_init_module(void)
1016 retval
= comedi_driver_register(&driver_jr3_pci
);
1020 driver_jr3_pci_pci_driver
.name
= (char *)driver_jr3_pci
.driver_name
;
1021 return pci_register_driver(&driver_jr3_pci_pci_driver
);
1024 static void __exit
driver_jr3_pci_cleanup_module(void)
1026 pci_unregister_driver(&driver_jr3_pci_pci_driver
);
1027 comedi_driver_unregister(&driver_jr3_pci
);
1030 module_init(driver_jr3_pci_init_module
);
1031 module_exit(driver_jr3_pci_cleanup_module
);
1033 MODULE_AUTHOR("Comedi http://www.comedi.org");
1034 MODULE_DESCRIPTION("Comedi low-level driver");
1035 MODULE_LICENSE("GPL");