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>
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
61 struct jr3_pci_dev_private
{
63 struct pci_dev
*pci_dev
;
65 volatile struct jr3_t
*iobase
;
67 struct timer_list timer
;
76 struct jr3_pci_subdev_private
{
77 volatile struct jr3_channel
*channel
;
78 unsigned long next_time_min
;
79 unsigned long next_time_max
;
80 enum { state_jr3_poll
,
81 state_jr3_init_wait_for_offset
,
82 state_jr3_init_transform_complete
,
83 state_jr3_init_set_full_scale_complete
,
84 state_jr3_init_use_offset_complete
,
92 struct comedi_krange range
;
94 const struct comedi_lrange
*range_table_list
[8 * 7 + 2];
95 unsigned int maxdata_list
[8 * 7 + 2];
100 /* Hotplug firmware loading stuff */
101 static int comedi_load_firmware(struct comedi_device
*dev
, char *name
,
102 int (*cb
)(struct comedi_device
*dev
,
103 const u8
*data
, size_t size
))
106 const struct firmware
*fw
;
108 static const char *prefix
= "comedi/";
109 struct jr3_pci_dev_private
*devpriv
= dev
->private;
111 firmware_path
= kmalloc(strlen(prefix
) + strlen(name
) + 1, GFP_KERNEL
);
112 if (!firmware_path
) {
115 firmware_path
[0] = '\0';
116 strcat(firmware_path
, prefix
);
117 strcat(firmware_path
, name
);
118 result
= request_firmware(&fw
, firmware_path
,
119 &devpriv
->pci_dev
->dev
);
124 result
= cb(dev
, fw
->data
, fw
->size
);
125 release_firmware(fw
);
127 kfree(firmware_path
);
132 static struct poll_delay_t
poll_delay_min_max(int min
, int max
)
134 struct poll_delay_t result
;
141 static int is_complete(volatile struct jr3_channel
*channel
)
143 return get_s16(&channel
->command_word0
) == 0;
153 static void set_transforms(volatile struct jr3_channel
*channel
,
154 struct transform_t transf
, short num
)
158 num
&= 0x000f; /* Make sure that 0 <= num <= 15 */
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
);
167 if (transf
.link
[i
].link_type
== end_x_form
)
172 static void use_transform(volatile struct jr3_channel
*channel
,
175 set_s16(&channel
->command_word0
, 0x0500 + (transf_num
& 0x000f));
178 static void use_offset(volatile struct jr3_channel
*channel
, short offset_num
)
180 set_s16(&channel
->command_word0
, 0x0600 + (offset_num
& 0x000f));
183 static void set_offset(volatile struct jr3_channel
*channel
)
185 set_s16(&channel
->command_word0
, 0x0700);
197 static void set_full_scales(volatile struct jr3_channel
*channel
,
198 struct six_axis_t full_scale
)
200 printk("%d %d %d %d %d %d\n",
203 full_scale
.fz
, full_scale
.mx
, full_scale
.my
, full_scale
.mz
);
204 set_s16(&channel
->full_scale
.fx
, full_scale
.fx
);
205 set_s16(&channel
->full_scale
.fy
, full_scale
.fy
);
206 set_s16(&channel
->full_scale
.fz
, full_scale
.fz
);
207 set_s16(&channel
->full_scale
.mx
, full_scale
.mx
);
208 set_s16(&channel
->full_scale
.my
, full_scale
.my
);
209 set_s16(&channel
->full_scale
.mz
, full_scale
.mz
);
210 set_s16(&channel
->command_word0
, 0x0a00);
213 static struct six_axis_t
get_min_full_scales(volatile struct jr3_channel
216 struct six_axis_t result
;
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
);
226 static struct six_axis_t
get_max_full_scales(volatile struct jr3_channel
229 struct six_axis_t result
;
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
);
239 static int jr3_pci_ai_insn_read(struct comedi_device
*dev
,
240 struct comedi_subdevice
*s
,
241 struct comedi_insn
*insn
, unsigned int *data
)
244 struct jr3_pci_subdev_private
*p
;
248 channel
= CR_CHAN(insn
->chanspec
);
249 if (p
== NULL
|| channel
> 57) {
255 if (p
->state
!= state_jr3_done
||
256 (get_u16(&p
->channel
->errors
) & (watch_dog
| watch_dog2
|
258 /* No sensor or sensor changed */
259 if (p
->state
== state_jr3_done
) {
260 /* Restart polling */
261 p
->state
= state_jr3_poll
;
265 for (i
= 0; i
< insn
->n
; i
++) {
270 filter
= channel
/ 8;
271 if (p
->state
!= state_jr3_done
) {
325 data
[i
] = F
+ 0x4000;
327 } else if (channel
== 56) {
328 if (p
->state
!= state_jr3_done
) {
332 get_u16(&p
->channel
->model_no
);
334 } else if (channel
== 57) {
335 if (p
->state
!= state_jr3_done
) {
339 get_u16(&p
->channel
->serial_no
);
347 static int jr3_pci_open(struct comedi_device
*dev
)
350 struct jr3_pci_dev_private
*devpriv
= dev
->private;
352 dev_dbg(dev
->class_dev
, "jr3_pci_open\n");
353 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
354 struct jr3_pci_subdev_private
*p
;
356 p
= dev
->subdevices
[i
].private;
358 dev_dbg(dev
->class_dev
, "serial: %p %d (%d)\n", p
,
359 p
->serial_no
, p
->channel_no
);
365 static int read_idm_word(const u8
*data
, size_t size
, int *pos
,
370 /* Skip over non hex */
371 for (; *pos
< size
&& !isxdigit(data
[*pos
]); (*pos
)++) {
375 for (; *pos
< size
; (*pos
)++) {
377 value
= hex_to_bin(data
[*pos
]);
380 *val
= (*val
<< 4) + value
;
388 static int jr3_download_firmware(struct comedi_device
*dev
, const u8
* data
,
392 * IDM file format is:
393 * { count, address, data <count> } *
396 int result
, more
, pos
, OK
;
403 unsigned int count
, addr
;
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
);
422 struct jr3_pci_dev_private
*p
= dev
->private;
424 for (i
= 0; i
< p
->n_channels
; i
++) {
425 struct jr3_pci_subdev_private
*sp
;
427 sp
= dev
->subdevices
[i
].private;
431 unsigned int count
, addr
;
433 && read_idm_word(data
, size
, &pos
, &count
);
434 if (more
&& count
== 0xffff)
437 && read_idm_word(data
, size
, &pos
, &addr
);
438 dev_dbg(dev
->class_dev
,
439 "Loading#%d %4.4x bytes at %4.4x\n",
441 while (more
&& count
> 0) {
443 /* 16 bit data, never seen in real life!! */
447 && read_idm_word(data
,
451 /* printk("jr3_data, not tested\n"); */
452 /* jr3[addr + 0x20000 * pnum] = data1; */
454 /* Download 24 bit program */
455 unsigned int data1
, data2
;
458 && read_idm_word(data
,
462 && read_idm_word(data
, size
,
488 static struct poll_delay_t
jr3_pci_poll_subdevice(struct comedi_subdevice
*s
)
490 struct poll_delay_t result
= poll_delay_min_max(1000, 2000);
491 struct jr3_pci_subdev_private
*p
= s
->private;
495 volatile struct jr3_channel
*channel
= p
->channel
;
496 int errors
= get_u16(&channel
->errors
);
498 if (errors
!= p
->errors
) {
499 printk("Errors: %x -> %x\n", p
->errors
, errors
);
502 if (errors
& (watch_dog
| watch_dog2
| sensor_change
)) {
503 /* Sensor communication lost, force poll mode */
504 p
->state
= state_jr3_poll
;
508 case state_jr3_poll
:{
509 u16 model_no
= get_u16(&channel
->model_no
);
510 u16 serial_no
= get_u16(&channel
->serial_no
);
511 if ((errors
& (watch_dog
| watch_dog2
)) ||
512 model_no
== 0 || serial_no
== 0) {
514 * Still no sensor, keep on polling. Since it takes up to 10 seconds
515 * for offsets to stabilize, polling each second should suffice.
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
:{
528 if (p
->retries
< 10) {
529 /* Wait for offeset to stabilize (< 10 s according to manual) */
530 result
= poll_delay_min_max(1000, 2000);
532 struct transform_t transf
;
535 get_u16(&channel
->model_no
);
537 get_u16(&channel
->serial_no
);
540 ("Setting transform for channel %d\n",
542 printk("Sensor Model = %i\n",
544 printk("Sensor Serial = %i\n",
547 /* Transformation all zeros */
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); /* Allow 20 ms for completion */
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);
569 struct six_axis_t min_full_scale
;
570 struct six_axis_t max_full_scale
;
573 get_min_full_scales(channel
);
574 printk("Obtained Min. Full Scales:\n");
575 printk(KERN_DEBUG
"%i ", (min_full_scale
).fx
);
576 printk(KERN_CONT
"%i ", (min_full_scale
).fy
);
577 printk(KERN_CONT
"%i ", (min_full_scale
).fz
);
578 printk(KERN_CONT
"%i ", (min_full_scale
).mx
);
579 printk(KERN_CONT
"%i ", (min_full_scale
).my
);
580 printk(KERN_CONT
"%i ", (min_full_scale
).mz
);
581 printk(KERN_CONT
"\n");
584 get_max_full_scales(channel
);
585 printk("Obtained Max. Full Scales:\n");
586 printk(KERN_DEBUG
"%i ", (max_full_scale
).fx
);
587 printk(KERN_CONT
"%i ", (max_full_scale
).fy
);
588 printk(KERN_CONT
"%i ", (max_full_scale
).fz
);
589 printk(KERN_CONT
"%i ", (max_full_scale
).mx
);
590 printk(KERN_CONT
"%i ", (max_full_scale
).my
);
591 printk(KERN_CONT
"%i ", (max_full_scale
).mz
);
592 printk(KERN_CONT
"\n");
594 set_full_scales(channel
,
598 state_jr3_init_set_full_scale_complete
;
599 result
= poll_delay_min_max(20, 100); /* Allow 20 ms for completion */
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);
610 volatile struct force_array
*full_scale
;
612 /* Use ranges in kN or we will overflow arount 2000N! */
613 full_scale
= &channel
->full_scale
;
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
++) {
648 printk("%d %d - %d\n",
659 use_offset(channel
, 0);
661 state_jr3_init_use_offset_complete
;
662 result
= poll_delay_min_max(40, 100); /* Allow 40 ms for completion */
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",
675 get_s16(&channel
->offsets
.fx
),
676 get_s16(&channel
->offsets
.fy
),
677 get_s16(&channel
->offsets
.fz
),
678 get_s16(&channel
->offsets
.mx
),
679 get_s16(&channel
->offsets
.my
),
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
)
711 struct comedi_device
*dev
= (struct comedi_device
*)data
;
712 struct jr3_pci_dev_private
*devpriv
= dev
->private;
717 spin_lock_irqsave(&dev
->spinlock
, flags
);
720 /* Poll all channels that are ready to be polled */
721 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
722 struct jr3_pci_subdev_private
*subdevpriv
=
723 dev
->subdevices
[i
].private;
724 if (now
> subdevpriv
->next_time_min
) {
725 struct poll_delay_t sub_delay
;
727 sub_delay
= jr3_pci_poll_subdevice(&dev
->subdevices
[i
]);
728 subdevpriv
->next_time_min
=
729 jiffies
+ msecs_to_jiffies(sub_delay
.min
);
730 subdevpriv
->next_time_max
=
731 jiffies
+ msecs_to_jiffies(sub_delay
.max
);
732 if (sub_delay
.max
&& sub_delay
.max
< delay
) {
734 * Wake up as late as possible -> poll as many channels as possible
737 delay
= sub_delay
.max
;
741 spin_unlock_irqrestore(&dev
->spinlock
, flags
);
743 devpriv
->timer
.expires
= jiffies
+ msecs_to_jiffies(delay
);
744 add_timer(&devpriv
->timer
);
747 static int jr3_pci_attach(struct comedi_device
*dev
,
748 struct comedi_devconfig
*it
)
751 struct pci_dev
*card
= NULL
;
752 int opt_bus
, opt_slot
, i
;
753 struct jr3_pci_dev_private
*devpriv
;
755 opt_bus
= it
->options
[0];
756 opt_slot
= it
->options
[1];
758 if (sizeof(struct jr3_channel
) != 0xc00) {
759 dev_err(dev
->class_dev
,
760 "sizeof(struct jr3_channel) = %x [expected %x]\n",
761 (unsigned)sizeof(struct jr3_channel
), 0xc00);
765 result
= alloc_private(dev
, sizeof(struct jr3_pci_dev_private
));
769 devpriv
= dev
->private;
770 init_timer(&devpriv
->timer
);
772 card
= pci_get_device(PCI_VENDOR_ID_JR3
, PCI_ANY_ID
, card
);
777 switch (card
->device
) {
778 case PCI_DEVICE_ID_JR3_1_CHANNEL
:{
779 devpriv
->n_channels
= 1;
782 case PCI_DEVICE_ID_JR3_1_CHANNEL_NEW
:{
783 devpriv
->n_channels
= 1;
786 case PCI_DEVICE_ID_JR3_2_CHANNEL
:{
787 devpriv
->n_channels
= 2;
790 case PCI_DEVICE_ID_JR3_3_CHANNEL
:{
791 devpriv
->n_channels
= 3;
794 case PCI_DEVICE_ID_JR3_4_CHANNEL
:{
795 devpriv
->n_channels
= 4;
799 devpriv
->n_channels
= 0;
802 if (devpriv
->n_channels
>= 1) {
803 if (opt_bus
== 0 && opt_slot
== 0) {
804 /* Take first available card */
806 } else if (opt_bus
== card
->bus
->number
&&
807 opt_slot
== PCI_SLOT(card
->devfn
)) {
808 /* Take requested card */
815 dev_err(dev
->class_dev
, "no jr3_pci found\n");
818 devpriv
->pci_dev
= card
;
819 dev
->board_name
= "jr3_pci";
822 result
= comedi_pci_enable(card
, "jr3_pci");
826 devpriv
->pci_enabled
= 1;
827 devpriv
->iobase
= ioremap(pci_resource_start(card
, 0),
828 offsetof(struct jr3_t
, channel
[devpriv
->n_channels
]));
829 if (!devpriv
->iobase
)
832 result
= comedi_alloc_subdevices(dev
, devpriv
->n_channels
);
836 dev
->open
= jr3_pci_open
;
837 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
838 dev
->subdevices
[i
].type
= COMEDI_SUBD_AI
;
839 dev
->subdevices
[i
].subdev_flags
= SDF_READABLE
| SDF_GROUND
;
840 dev
->subdevices
[i
].n_chan
= 8 * 7 + 2;
841 dev
->subdevices
[i
].insn_read
= jr3_pci_ai_insn_read
;
842 dev
->subdevices
[i
].private =
843 kzalloc(sizeof(struct jr3_pci_subdev_private
), GFP_KERNEL
);
844 if (dev
->subdevices
[i
].private) {
845 struct jr3_pci_subdev_private
*p
;
848 p
= dev
->subdevices
[i
].private;
849 p
->channel
= &devpriv
->iobase
->channel
[i
].data
;
850 dev_dbg(dev
->class_dev
, "p->channel %p %p (%tx)\n",
851 p
->channel
, devpriv
->iobase
,
852 ((char *)(p
->channel
) -
853 (char *)(devpriv
->iobase
)));
855 for (j
= 0; j
< 8; j
++) {
858 p
->range
[j
].length
= 1;
859 p
->range
[j
].range
.min
= -1000000;
860 p
->range
[j
].range
.max
= 1000000;
861 for (k
= 0; k
< 7; k
++) {
862 p
->range_table_list
[j
+ k
* 8] =
863 (struct comedi_lrange
*)&p
->
865 p
->maxdata_list
[j
+ k
* 8] = 0x7fff;
868 p
->range
[8].length
= 1;
869 p
->range
[8].range
.min
= 0;
870 p
->range
[8].range
.max
= 65536;
872 p
->range_table_list
[56] =
873 (struct comedi_lrange
*)&p
->range
[8];
874 p
->range_table_list
[57] =
875 (struct comedi_lrange
*)&p
->range
[8];
876 p
->maxdata_list
[56] = 0xffff;
877 p
->maxdata_list
[57] = 0xffff;
878 /* Channel specific range and maxdata */
879 dev
->subdevices
[i
].range_table
= NULL
;
880 dev
->subdevices
[i
].range_table_list
=
882 dev
->subdevices
[i
].maxdata
= 0;
883 dev
->subdevices
[i
].maxdata_list
= p
->maxdata_list
;
888 writel(0, &devpriv
->iobase
->channel
[0].reset
);
890 result
= comedi_load_firmware(dev
, "jr3pci.idm", jr3_download_firmware
);
891 dev_dbg(dev
->class_dev
, "Firmare load %d\n", result
);
896 * TODO: use firmware to load preferred offset tables. Suggested
898 * model serial Fx Fy Fz Mx My Mz\n
900 * comedi_load_firmware(dev, "jr3_offsets_table", jr3_download_firmware);
904 * It takes a few milliseconds for software to settle as much as we
905 * can read firmware version
907 msleep_interruptible(25);
908 for (i
= 0; i
< 0x18; i
++) {
909 dev_dbg(dev
->class_dev
, "%c\n",
910 get_u16(&devpriv
->iobase
->channel
[0].
911 data
.copyright
[i
]) >> 8);
914 /* Start card timer */
915 for (i
= 0; i
< devpriv
->n_channels
; i
++) {
916 struct jr3_pci_subdev_private
*p
= dev
->subdevices
[i
].private;
918 p
->next_time_min
= jiffies
+ msecs_to_jiffies(500);
919 p
->next_time_max
= jiffies
+ msecs_to_jiffies(2000);
922 devpriv
->timer
.data
= (unsigned long)dev
;
923 devpriv
->timer
.function
= jr3_pci_poll_dev
;
924 devpriv
->timer
.expires
= jiffies
+ msecs_to_jiffies(1000);
925 add_timer(&devpriv
->timer
);
931 static void jr3_pci_detach(struct comedi_device
*dev
)
934 struct jr3_pci_dev_private
*devpriv
= dev
->private;
937 del_timer_sync(&devpriv
->timer
);
939 if (dev
->subdevices
) {
940 for (i
= 0; i
< devpriv
->n_channels
; i
++)
941 kfree(dev
->subdevices
[i
].private);
944 iounmap((void *)devpriv
->iobase
);
945 if (devpriv
->pci_enabled
)
946 comedi_pci_disable(devpriv
->pci_dev
);
947 if (devpriv
->pci_dev
)
948 pci_dev_put(devpriv
->pci_dev
);
952 static struct comedi_driver jr3_pci_driver
= {
953 .driver_name
= "jr3_pci",
954 .module
= THIS_MODULE
,
955 .attach
= jr3_pci_attach
,
956 .detach
= jr3_pci_detach
,
959 static int __devinit
jr3_pci_pci_probe(struct pci_dev
*dev
,
960 const struct pci_device_id
*ent
)
962 return comedi_pci_auto_config(dev
, &jr3_pci_driver
);
965 static void __devexit
jr3_pci_pci_remove(struct pci_dev
*dev
)
967 comedi_pci_auto_unconfig(dev
);
970 static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table
) = {
971 { PCI_DEVICE(PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_1_CHANNEL
) },
972 { PCI_DEVICE(PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW
) },
973 { PCI_DEVICE(PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_2_CHANNEL
) },
974 { PCI_DEVICE(PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_3_CHANNEL
) },
975 { PCI_DEVICE(PCI_VENDOR_ID_JR3
, PCI_DEVICE_ID_JR3_4_CHANNEL
) },
978 MODULE_DEVICE_TABLE(pci
, jr3_pci_pci_table
);
980 static struct pci_driver jr3_pci_pci_driver
= {
982 .id_table
= jr3_pci_pci_table
,
983 .probe
= jr3_pci_pci_probe
,
984 .remove
= __devexit_p(jr3_pci_pci_remove
),
986 module_comedi_pci_driver(jr3_pci_driver
, jr3_pci_pci_driver
);
988 MODULE_AUTHOR("Comedi http://www.comedi.org");
989 MODULE_DESCRIPTION("Comedi low-level driver");
990 MODULE_LICENSE("GPL");
991 MODULE_FIRMWARE("comedi/jr3pci.idm");