3 * Copyright (C) 2011-2015 Bernd Porr, mail@berndporr.me.uk
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 * Description: University of Stirling USB DAQ & INCITE Technology Limited
19 * Devices: [ITL] USB-DUX-SIGMA (usbduxsigma)
20 * Author: Bernd Porr <mail@berndporr.me.uk>
21 * Updated: 20 July 2015
26 * I must give credit here to Chris Baugher who
27 * wrote the driver for AT-MIO-16d. I used some parts of this
28 * driver. I also must give credits to David Brownell
29 * who supported me with the USB development.
31 * Note: the raw data from the A/D converter is 24 bit big endian
32 * anything else is little endian to/from the dux board
36 * 0.1: initial version
37 * 0.2: all basic functions implemented, digital I/O only for one port
38 * 0.3: proper vendor ID and driver name
39 * 0.4: fixed D/A voltage range
40 * 0.5: various bug fixes, health check at startup
41 * 0.6: corrected wrong input range
42 * 0.7: rewrite code that urb->interval is always 1
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/slab.h>
48 #include <linux/input.h>
49 #include <linux/fcntl.h>
50 #include <linux/compiler.h>
51 #include <asm/unaligned.h>
53 #include "../comedi_usb.h"
55 /* timeout for the USB-transfer in ms*/
56 #define BULK_TIMEOUT 1000
58 /* constants for "firmware" upload and download */
59 #define FIRMWARE "usbduxsigma_firmware.bin"
60 #define FIRMWARE_MAX_LEN 0x4000
61 #define USBDUXSUB_FIRMWARE 0xa0
62 #define VENDOR_DIR_IN 0xc0
63 #define VENDOR_DIR_OUT 0x40
65 /* internal addresses of the 8051 processor */
66 #define USBDUXSUB_CPUCS 0xE600
68 /* 300Hz max frequ under PWM */
69 #define MIN_PWM_PERIOD ((long)(1E9/300))
71 /* Default PWM frequency */
72 #define PWM_DEFAULT_PERIOD ((long)(1E9/100))
74 /* Number of channels (16 AD and offset)*/
75 #define NUMCHANNELS 16
77 /* Size of one A/D value */
78 #define SIZEADIN ((sizeof(uint32_t)))
81 * Size of the async input-buffer IN BYTES, the DIO state is transmitted
84 #define SIZEINBUF (((NUMCHANNELS+1)*SIZEADIN))
87 #define SIZEINSNBUF 16
89 /* Number of DA channels */
90 #define NUMOUTCHANNELS 8
92 /* size of one value for the D/A converter: channel and value */
93 #define SIZEDAOUT ((sizeof(uint8_t)+sizeof(uint16_t)))
96 * Size of the output-buffer in bytes
97 * Actually only the first 4 triplets are used but for the
98 * high speed mode we need to pad it to 8 (microframes).
100 #define SIZEOUTBUF ((8*SIZEDAOUT))
103 * Size of the buffer for the dux commands: just now max size is determined
104 * by the analogue out + command byte + panic bytes...
106 #define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2))
108 /* Number of in-URBs which receive the data: min=2 */
109 #define NUMOFINBUFFERSFULL 5
111 /* Number of out-URBs which send the data: min=2 */
112 #define NUMOFOUTBUFFERSFULL 5
114 /* Number of in-URBs which receive the data: min=5 */
115 /* must have more buffers due to buggy USB ctr */
116 #define NUMOFINBUFFERSHIGH 10
118 /* Number of out-URBs which send the data: min=5 */
119 /* must have more buffers due to buggy USB ctr */
120 #define NUMOFOUTBUFFERSHIGH 10
122 /* number of retries to get the right dux command */
125 /* bulk transfer commands to usbduxsigma */
126 #define USBBUXSIGMA_AD_CMD 9
127 #define USBDUXSIGMA_DA_CMD 1
128 #define USBDUXSIGMA_DIO_CFG_CMD 2
129 #define USBDUXSIGMA_DIO_BITS_CMD 3
130 #define USBDUXSIGMA_SINGLE_AD_CMD 4
131 #define USBDUXSIGMA_PWM_ON_CMD 7
132 #define USBDUXSIGMA_PWM_OFF_CMD 8
134 static const struct comedi_lrange usbduxsigma_ai_range
= {
136 BIP_RANGE(2.5 * 0x800000 / 0x780000 / 2.0)
140 struct usbduxsigma_private
{
141 /* actual number of in-buffers */
143 /* actual number of out-buffers */
145 /* ISO-transfer handling: buffers */
146 struct urb
**ai_urbs
;
147 struct urb
**ao_urbs
;
148 /* pwm-transfer handling */
151 unsigned int pwm_period
;
152 /* PWM internal delay for the GPIF in the FX2 */
154 /* size of the PWM buffer which holds the bit pattern */
156 /* input buffer for the ISO-transfer */
158 /* input buffer for single insn */
161 unsigned high_speed
:1;
162 unsigned ai_cmd_running
:1;
163 unsigned ao_cmd_running
:1;
164 unsigned pwm_cmd_running
:1;
166 /* time between samples in units of the timer */
167 unsigned int ai_timer
;
168 unsigned int ao_timer
;
169 /* counter between acquisitions */
170 unsigned int ai_counter
;
171 unsigned int ao_counter
;
172 /* interval in frames/uframes */
173 unsigned int ai_interval
;
175 uint8_t *dux_commands
;
176 struct semaphore sem
;
179 static void usbduxsigma_unlink_urbs(struct urb
**urbs
, int num_urbs
)
183 for (i
= 0; i
< num_urbs
; i
++)
184 usb_kill_urb(urbs
[i
]);
187 static void usbduxsigma_ai_stop(struct comedi_device
*dev
, int do_unlink
)
189 struct usbduxsigma_private
*devpriv
= dev
->private;
191 if (do_unlink
&& devpriv
->ai_urbs
)
192 usbduxsigma_unlink_urbs(devpriv
->ai_urbs
, devpriv
->n_ai_urbs
);
194 devpriv
->ai_cmd_running
= 0;
197 static int usbduxsigma_ai_cancel(struct comedi_device
*dev
,
198 struct comedi_subdevice
*s
)
200 struct usbduxsigma_private
*devpriv
= dev
->private;
203 /* unlink only if it is really running */
204 usbduxsigma_ai_stop(dev
, devpriv
->ai_cmd_running
);
210 static void usbduxsigma_ai_handle_urb(struct comedi_device
*dev
,
211 struct comedi_subdevice
*s
,
214 struct usbduxsigma_private
*devpriv
= dev
->private;
215 struct comedi_async
*async
= s
->async
;
216 struct comedi_cmd
*cmd
= &async
->cmd
;
221 if ((urb
->actual_length
> 0) && (urb
->status
!= -EXDEV
)) {
222 devpriv
->ai_counter
--;
223 if (devpriv
->ai_counter
== 0) {
224 devpriv
->ai_counter
= devpriv
->ai_timer
;
226 /* get the data from the USB bus
227 and hand it over to comedi */
228 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
230 note first byte is the DIO state */
231 val
= be32_to_cpu(devpriv
->in_buf
[i
+1]);
232 val
&= 0x00ffffff; /* strip status byte */
233 val
^= 0x00800000; /* convert to unsigned */
235 if (!comedi_buf_write_samples(s
, &val
, 1))
239 if (cmd
->stop_src
== TRIG_COUNT
&&
240 async
->scans_done
>= cmd
->stop_arg
)
241 async
->events
|= COMEDI_CB_EOA
;
245 /* if command is still running, resubmit urb */
246 if (!(async
->events
& COMEDI_CB_CANCEL_MASK
)) {
247 urb
->dev
= comedi_to_usb_dev(dev
);
248 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
250 dev_err(dev
->class_dev
, "urb resubmit failed (%d)\n",
252 if (ret
== -EL2NSYNC
)
253 dev_err(dev
->class_dev
,
254 "buggy USB host controller or bug in IRQ handler\n");
255 async
->events
|= COMEDI_CB_ERROR
;
260 static void usbduxsigma_ai_urb_complete(struct urb
*urb
)
262 struct comedi_device
*dev
= urb
->context
;
263 struct usbduxsigma_private
*devpriv
= dev
->private;
264 struct comedi_subdevice
*s
= dev
->read_subdev
;
265 struct comedi_async
*async
= s
->async
;
267 /* exit if not running a command, do not resubmit urb */
268 if (!devpriv
->ai_cmd_running
)
271 switch (urb
->status
) {
273 /* copy the result in the transfer buffer */
274 memcpy(devpriv
->in_buf
, urb
->transfer_buffer
, SIZEINBUF
);
275 usbduxsigma_ai_handle_urb(dev
, s
, urb
);
280 * error in the ISOchronous data
281 * we don't copy the data into the transfer buffer
282 * and recycle the last data byte
284 dev_dbg(dev
->class_dev
, "CRC error in ISO IN stream\n");
285 usbduxsigma_ai_handle_urb(dev
, s
, urb
);
292 /* happens after an unlink command */
293 async
->events
|= COMEDI_CB_ERROR
;
298 dev_err(dev
->class_dev
, "non-zero urb status (%d)\n",
300 async
->events
|= COMEDI_CB_ERROR
;
305 * comedi_handle_events() cannot be used in this driver. The (*cancel)
306 * operation would unlink the urb.
308 if (async
->events
& COMEDI_CB_CANCEL_MASK
)
309 usbduxsigma_ai_stop(dev
, 0);
311 comedi_event(dev
, s
);
314 static void usbduxsigma_ao_stop(struct comedi_device
*dev
, int do_unlink
)
316 struct usbduxsigma_private
*devpriv
= dev
->private;
318 if (do_unlink
&& devpriv
->ao_urbs
)
319 usbduxsigma_unlink_urbs(devpriv
->ao_urbs
, devpriv
->n_ao_urbs
);
321 devpriv
->ao_cmd_running
= 0;
324 static int usbduxsigma_ao_cancel(struct comedi_device
*dev
,
325 struct comedi_subdevice
*s
)
327 struct usbduxsigma_private
*devpriv
= dev
->private;
330 /* unlink only if it is really running */
331 usbduxsigma_ao_stop(dev
, devpriv
->ao_cmd_running
);
337 static void usbduxsigma_ao_handle_urb(struct comedi_device
*dev
,
338 struct comedi_subdevice
*s
,
341 struct usbduxsigma_private
*devpriv
= dev
->private;
342 struct comedi_async
*async
= s
->async
;
343 struct comedi_cmd
*cmd
= &async
->cmd
;
348 devpriv
->ao_counter
--;
349 if (devpriv
->ao_counter
== 0) {
350 devpriv
->ao_counter
= devpriv
->ao_timer
;
352 if (cmd
->stop_src
== TRIG_COUNT
&&
353 async
->scans_done
>= cmd
->stop_arg
) {
354 async
->events
|= COMEDI_CB_EOA
;
358 /* transmit data to the USB bus */
359 datap
= urb
->transfer_buffer
;
360 *datap
++ = cmd
->chanlist_len
;
361 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
362 unsigned int chan
= CR_CHAN(cmd
->chanlist
[i
]);
365 if (!comedi_buf_read_samples(s
, &val
, 1)) {
366 dev_err(dev
->class_dev
, "buffer underflow\n");
367 async
->events
|= COMEDI_CB_OVERFLOW
;
373 s
->readback
[chan
] = val
;
377 /* if command is still running, resubmit urb */
378 if (!(async
->events
& COMEDI_CB_CANCEL_MASK
)) {
379 urb
->transfer_buffer_length
= SIZEOUTBUF
;
380 urb
->dev
= comedi_to_usb_dev(dev
);
382 urb
->interval
= 1; /* (u)frames */
383 urb
->number_of_packets
= 1;
384 urb
->iso_frame_desc
[0].offset
= 0;
385 urb
->iso_frame_desc
[0].length
= SIZEOUTBUF
;
386 urb
->iso_frame_desc
[0].status
= 0;
387 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
389 dev_err(dev
->class_dev
, "urb resubmit failed (%d)\n",
391 if (ret
== -EL2NSYNC
)
392 dev_err(dev
->class_dev
,
393 "buggy USB host controller or bug in IRQ handler\n");
394 async
->events
|= COMEDI_CB_ERROR
;
399 static void usbduxsigma_ao_urb_complete(struct urb
*urb
)
401 struct comedi_device
*dev
= urb
->context
;
402 struct usbduxsigma_private
*devpriv
= dev
->private;
403 struct comedi_subdevice
*s
= dev
->write_subdev
;
404 struct comedi_async
*async
= s
->async
;
406 /* exit if not running a command, do not resubmit urb */
407 if (!devpriv
->ao_cmd_running
)
410 switch (urb
->status
) {
412 usbduxsigma_ao_handle_urb(dev
, s
, urb
);
419 /* happens after an unlink command */
420 async
->events
|= COMEDI_CB_ERROR
;
425 dev_err(dev
->class_dev
, "non-zero urb status (%d)\n",
427 async
->events
|= COMEDI_CB_ERROR
;
432 * comedi_handle_events() cannot be used in this driver. The (*cancel)
433 * operation would unlink the urb.
435 if (async
->events
& COMEDI_CB_CANCEL_MASK
)
436 usbduxsigma_ao_stop(dev
, 0);
438 comedi_event(dev
, s
);
441 static int usbduxsigma_submit_urbs(struct comedi_device
*dev
,
442 struct urb
**urbs
, int num_urbs
,
445 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
450 /* Submit all URBs and start the transfer on the bus */
451 for (i
= 0; i
< num_urbs
; i
++) {
454 /* in case of a resubmission after an unlink... */
460 urb
->transfer_flags
= URB_ISO_ASAP
;
462 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
469 static int usbduxsigma_chans_to_interval(int num_chan
)
478 static int usbduxsigma_ai_cmdtest(struct comedi_device
*dev
,
479 struct comedi_subdevice
*s
,
480 struct comedi_cmd
*cmd
)
482 struct usbduxsigma_private
*devpriv
= dev
->private;
483 int high_speed
= devpriv
->high_speed
;
484 int interval
= usbduxsigma_chans_to_interval(cmd
->chanlist_len
);
487 /* Step 1 : check if triggers are trivially valid */
489 err
|= comedi_check_trigger_src(&cmd
->start_src
, TRIG_NOW
| TRIG_INT
);
490 err
|= comedi_check_trigger_src(&cmd
->scan_begin_src
, TRIG_TIMER
);
491 err
|= comedi_check_trigger_src(&cmd
->convert_src
, TRIG_NOW
);
492 err
|= comedi_check_trigger_src(&cmd
->scan_end_src
, TRIG_COUNT
);
493 err
|= comedi_check_trigger_src(&cmd
->stop_src
, TRIG_COUNT
| TRIG_NONE
);
498 /* Step 2a : make sure trigger sources are unique */
500 err
|= comedi_check_trigger_is_unique(cmd
->start_src
);
501 err
|= comedi_check_trigger_is_unique(cmd
->stop_src
);
503 /* Step 2b : and mutually compatible */
508 /* Step 3: check if arguments are trivially valid */
510 err
|= comedi_check_trigger_arg_is(&cmd
->start_arg
, 0);
512 if (cmd
->scan_begin_src
== TRIG_FOLLOW
) /* internal trigger */
513 err
|= comedi_check_trigger_arg_is(&cmd
->scan_begin_arg
, 0);
515 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
520 * In high speed mode microframes are possible.
521 * However, during one microframe we can roughly
522 * sample two channels. Thus, the more channels
523 * are in the channel list the more time we need.
525 err
|= comedi_check_trigger_arg_min(&cmd
->
530 tmp
= (cmd
->scan_begin_arg
/ 125000) * 125000;
533 /* 1kHz scans every USB frame */
534 err
|= comedi_check_trigger_arg_min(&cmd
->
538 tmp
= (cmd
->scan_begin_arg
/ 1000000) * 1000000;
540 err
|= comedi_check_trigger_arg_is(&cmd
->scan_begin_arg
, tmp
);
543 err
|= comedi_check_trigger_arg_is(&cmd
->scan_end_arg
,
546 if (cmd
->stop_src
== TRIG_COUNT
)
547 err
|= comedi_check_trigger_arg_min(&cmd
->stop_arg
, 1);
549 err
|= comedi_check_trigger_arg_is(&cmd
->stop_arg
, 0);
558 * creates the ADC command for the MAX1271
559 * range is the range value from comedi
561 static void create_adc_command(unsigned int chan
,
566 (*muxsg0
) = (*muxsg0
) | (1 << chan
);
568 (*muxsg1
) = (*muxsg1
) | (1 << (chan
-8));
571 static int usbbuxsigma_send_cmd(struct comedi_device
*dev
, int cmd_type
)
573 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
574 struct usbduxsigma_private
*devpriv
= dev
->private;
577 devpriv
->dux_commands
[0] = cmd_type
;
579 return usb_bulk_msg(usb
, usb_sndbulkpipe(usb
, 1),
580 devpriv
->dux_commands
, SIZEOFDUXBUFFER
,
581 &nsent
, BULK_TIMEOUT
);
584 static int usbduxsigma_receive_cmd(struct comedi_device
*dev
, int command
)
586 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
587 struct usbduxsigma_private
*devpriv
= dev
->private;
592 for (i
= 0; i
< RETRIES
; i
++) {
593 ret
= usb_bulk_msg(usb
, usb_rcvbulkpipe(usb
, 8),
594 devpriv
->insn_buf
, SIZEINSNBUF
,
595 &nrec
, BULK_TIMEOUT
);
599 if (devpriv
->insn_buf
[0] == command
)
603 * This is only reached if the data has been requested a
604 * couple of times and the command was not received.
609 static int usbduxsigma_ai_inttrig(struct comedi_device
*dev
,
610 struct comedi_subdevice
*s
,
611 unsigned int trig_num
)
613 struct usbduxsigma_private
*devpriv
= dev
->private;
614 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
617 if (trig_num
!= cmd
->start_arg
)
621 if (!devpriv
->ai_cmd_running
) {
622 devpriv
->ai_cmd_running
= 1;
623 ret
= usbduxsigma_submit_urbs(dev
, devpriv
->ai_urbs
,
624 devpriv
->n_ai_urbs
, 1);
626 devpriv
->ai_cmd_running
= 0;
630 s
->async
->inttrig
= NULL
;
637 static int usbduxsigma_ai_cmd(struct comedi_device
*dev
,
638 struct comedi_subdevice
*s
)
640 struct usbduxsigma_private
*devpriv
= dev
->private;
641 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
642 unsigned int len
= cmd
->chanlist_len
;
651 if (devpriv
->high_speed
) {
653 * every 2 channels get a time window of 125us. Thus, if we
654 * sample all 16 channels we need 1ms. If we sample only one
655 * channel we need only 125us
657 unsigned int interval
= usbduxsigma_chans_to_interval(len
);
659 devpriv
->ai_interval
= interval
;
660 devpriv
->ai_timer
= cmd
->scan_begin_arg
/ (125000 * interval
);
662 /* interval always 1ms */
663 devpriv
->ai_interval
= 1;
664 devpriv
->ai_timer
= cmd
->scan_begin_arg
/ 1000000;
667 for (i
= 0; i
< len
; i
++) {
668 unsigned int chan
= CR_CHAN(cmd
->chanlist
[i
]);
670 create_adc_command(chan
, &muxsg0
, &muxsg1
);
673 devpriv
->dux_commands
[1] = devpriv
->ai_interval
;
674 devpriv
->dux_commands
[2] = len
; /* num channels per time step */
675 devpriv
->dux_commands
[3] = 0x12; /* CONFIG0 */
676 devpriv
->dux_commands
[4] = 0x03; /* CONFIG1: 23kHz sample, delay 0us */
677 devpriv
->dux_commands
[5] = 0x00; /* CONFIG3: diff. channels off */
678 devpriv
->dux_commands
[6] = muxsg0
;
679 devpriv
->dux_commands
[7] = muxsg1
;
680 devpriv
->dux_commands
[8] = sysred
;
682 ret
= usbbuxsigma_send_cmd(dev
, USBBUXSIGMA_AD_CMD
);
688 devpriv
->ai_counter
= devpriv
->ai_timer
;
690 if (cmd
->start_src
== TRIG_NOW
) {
691 /* enable this acquisition operation */
692 devpriv
->ai_cmd_running
= 1;
693 ret
= usbduxsigma_submit_urbs(dev
, devpriv
->ai_urbs
,
694 devpriv
->n_ai_urbs
, 1);
696 devpriv
->ai_cmd_running
= 0;
700 s
->async
->inttrig
= NULL
;
701 } else { /* TRIG_INT */
702 s
->async
->inttrig
= usbduxsigma_ai_inttrig
;
710 static int usbduxsigma_ai_insn_read(struct comedi_device
*dev
,
711 struct comedi_subdevice
*s
,
712 struct comedi_insn
*insn
,
715 struct usbduxsigma_private
*devpriv
= dev
->private;
716 unsigned int chan
= CR_CHAN(insn
->chanspec
);
724 if (devpriv
->ai_cmd_running
) {
729 create_adc_command(chan
, &muxsg0
, &muxsg1
);
731 /* Mode 0 is used to get a single conversion on demand */
732 devpriv
->dux_commands
[1] = 0x16; /* CONFIG0: chopper on */
733 devpriv
->dux_commands
[2] = 0x80; /* CONFIG1: 2kHz sampling rate */
734 devpriv
->dux_commands
[3] = 0x00; /* CONFIG3: diff. channels off */
735 devpriv
->dux_commands
[4] = muxsg0
;
736 devpriv
->dux_commands
[5] = muxsg1
;
737 devpriv
->dux_commands
[6] = sysred
;
740 ret
= usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_SINGLE_AD_CMD
);
746 for (i
= 0; i
< insn
->n
; i
++) {
749 ret
= usbduxsigma_receive_cmd(dev
, USBDUXSIGMA_SINGLE_AD_CMD
);
755 /* 32 bits big endian from the A/D converter */
756 val
= be32_to_cpu(get_unaligned((__be32
757 *)(devpriv
->insn_buf
+ 1)));
758 val
&= 0x00ffffff; /* strip status byte */
759 val
^= 0x00800000; /* convert to unsigned */
768 static int usbduxsigma_ao_insn_read(struct comedi_device
*dev
,
769 struct comedi_subdevice
*s
,
770 struct comedi_insn
*insn
,
773 struct usbduxsigma_private
*devpriv
= dev
->private;
777 ret
= comedi_readback_insn_read(dev
, s
, insn
, data
);
783 static int usbduxsigma_ao_insn_write(struct comedi_device
*dev
,
784 struct comedi_subdevice
*s
,
785 struct comedi_insn
*insn
,
788 struct usbduxsigma_private
*devpriv
= dev
->private;
789 unsigned int chan
= CR_CHAN(insn
->chanspec
);
794 if (devpriv
->ao_cmd_running
) {
799 for (i
= 0; i
< insn
->n
; i
++) {
800 devpriv
->dux_commands
[1] = 1; /* num channels */
801 devpriv
->dux_commands
[2] = data
[i
]; /* value */
802 devpriv
->dux_commands
[3] = chan
; /* channel number */
803 ret
= usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_DA_CMD
);
808 s
->readback
[chan
] = data
[i
];
815 static int usbduxsigma_ao_inttrig(struct comedi_device
*dev
,
816 struct comedi_subdevice
*s
,
817 unsigned int trig_num
)
819 struct usbduxsigma_private
*devpriv
= dev
->private;
820 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
823 if (trig_num
!= cmd
->start_arg
)
827 if (!devpriv
->ao_cmd_running
) {
828 devpriv
->ao_cmd_running
= 1;
829 ret
= usbduxsigma_submit_urbs(dev
, devpriv
->ao_urbs
,
830 devpriv
->n_ao_urbs
, 0);
832 devpriv
->ao_cmd_running
= 0;
836 s
->async
->inttrig
= NULL
;
843 static int usbduxsigma_ao_cmdtest(struct comedi_device
*dev
,
844 struct comedi_subdevice
*s
,
845 struct comedi_cmd
*cmd
)
847 struct usbduxsigma_private
*devpriv
= dev
->private;
852 /* high speed conversions are not used yet */
853 high_speed
= 0; /* (devpriv->high_speed) */
855 /* Step 1 : check if triggers are trivially valid */
857 err
|= comedi_check_trigger_src(&cmd
->start_src
, TRIG_NOW
| TRIG_INT
);
861 * start immediately a new scan
862 * the sampling rate is set by the coversion rate
866 /* start a new scan (output at once) with a timer */
869 err
|= comedi_check_trigger_src(&cmd
->scan_begin_src
, flags
);
871 err
|= comedi_check_trigger_src(&cmd
->convert_src
, TRIG_NOW
);
872 err
|= comedi_check_trigger_src(&cmd
->scan_end_src
, TRIG_COUNT
);
873 err
|= comedi_check_trigger_src(&cmd
->stop_src
, TRIG_COUNT
| TRIG_NONE
);
880 /* Step 2a : make sure trigger sources are unique */
882 err
|= comedi_check_trigger_is_unique(cmd
->start_src
);
883 err
|= comedi_check_trigger_is_unique(cmd
->stop_src
);
885 /* Step 2b : and mutually compatible */
890 /* Step 3: check if arguments are trivially valid */
892 err
|= comedi_check_trigger_arg_is(&cmd
->start_arg
, 0);
894 if (cmd
->scan_begin_src
== TRIG_FOLLOW
) /* internal trigger */
895 err
|= comedi_check_trigger_arg_is(&cmd
->scan_begin_arg
, 0);
897 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
898 err
|= comedi_check_trigger_arg_min(&cmd
->scan_begin_arg
,
902 /* not used now, is for later use */
903 if (cmd
->convert_src
== TRIG_TIMER
)
904 err
|= comedi_check_trigger_arg_min(&cmd
->convert_arg
, 125000);
906 err
|= comedi_check_trigger_arg_is(&cmd
->scan_end_arg
,
909 if (cmd
->stop_src
== TRIG_COUNT
)
910 err
|= comedi_check_trigger_arg_min(&cmd
->stop_arg
, 1);
912 err
|= comedi_check_trigger_arg_is(&cmd
->stop_arg
, 0);
920 static int usbduxsigma_ao_cmd(struct comedi_device
*dev
,
921 struct comedi_subdevice
*s
)
923 struct usbduxsigma_private
*devpriv
= dev
->private;
924 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
929 if (cmd
->convert_src
== TRIG_TIMER
) {
931 * timing of the conversion itself: every 125 us
932 * at high speed (not used yet)
934 devpriv
->ao_timer
= cmd
->convert_arg
/ 125000;
937 * timing of the scan: every 1ms
938 * we get all channels at once
940 devpriv
->ao_timer
= cmd
->scan_begin_arg
/ 1000000;
943 devpriv
->ao_counter
= devpriv
->ao_timer
;
945 if (cmd
->start_src
== TRIG_NOW
) {
946 /* enable this acquisition operation */
947 devpriv
->ao_cmd_running
= 1;
948 ret
= usbduxsigma_submit_urbs(dev
, devpriv
->ao_urbs
,
949 devpriv
->n_ao_urbs
, 0);
951 devpriv
->ao_cmd_running
= 0;
955 s
->async
->inttrig
= NULL
;
956 } else { /* TRIG_INT */
957 s
->async
->inttrig
= usbduxsigma_ao_inttrig
;
965 static int usbduxsigma_dio_insn_config(struct comedi_device
*dev
,
966 struct comedi_subdevice
*s
,
967 struct comedi_insn
*insn
,
972 ret
= comedi_dio_insn_config(dev
, s
, insn
, data
, 0);
977 * We don't tell the firmware here as it would take 8 frames
978 * to submit the information. We do it in the (*insn_bits).
983 static int usbduxsigma_dio_insn_bits(struct comedi_device
*dev
,
984 struct comedi_subdevice
*s
,
985 struct comedi_insn
*insn
,
988 struct usbduxsigma_private
*devpriv
= dev
->private;
993 comedi_dio_update_state(s
, data
);
995 /* Always update the hardware. See the (*insn_config). */
996 devpriv
->dux_commands
[1] = s
->io_bits
& 0xff;
997 devpriv
->dux_commands
[4] = s
->state
& 0xff;
998 devpriv
->dux_commands
[2] = (s
->io_bits
>> 8) & 0xff;
999 devpriv
->dux_commands
[5] = (s
->state
>> 8) & 0xff;
1000 devpriv
->dux_commands
[3] = (s
->io_bits
>> 16) & 0xff;
1001 devpriv
->dux_commands
[6] = (s
->state
>> 16) & 0xff;
1003 ret
= usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_DIO_BITS_CMD
);
1006 ret
= usbduxsigma_receive_cmd(dev
, USBDUXSIGMA_DIO_BITS_CMD
);
1010 s
->state
= devpriv
->insn_buf
[1] |
1011 (devpriv
->insn_buf
[2] << 8) |
1012 (devpriv
->insn_buf
[3] << 16);
1023 static void usbduxsigma_pwm_stop(struct comedi_device
*dev
, int do_unlink
)
1025 struct usbduxsigma_private
*devpriv
= dev
->private;
1028 if (devpriv
->pwm_urb
)
1029 usb_kill_urb(devpriv
->pwm_urb
);
1032 devpriv
->pwm_cmd_running
= 0;
1035 static int usbduxsigma_pwm_cancel(struct comedi_device
*dev
,
1036 struct comedi_subdevice
*s
)
1038 struct usbduxsigma_private
*devpriv
= dev
->private;
1040 /* unlink only if it is really running */
1041 usbduxsigma_pwm_stop(dev
, devpriv
->pwm_cmd_running
);
1043 return usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_PWM_OFF_CMD
);
1046 static void usbduxsigma_pwm_urb_complete(struct urb
*urb
)
1048 struct comedi_device
*dev
= urb
->context
;
1049 struct usbduxsigma_private
*devpriv
= dev
->private;
1052 switch (urb
->status
) {
1061 /* happens after an unlink command */
1062 if (devpriv
->pwm_cmd_running
)
1063 usbduxsigma_pwm_stop(dev
, 0); /* w/o unlink */
1068 if (devpriv
->pwm_cmd_running
) {
1069 dev_err(dev
->class_dev
, "non-zero urb status (%d)\n",
1071 usbduxsigma_pwm_stop(dev
, 0); /* w/o unlink */
1076 if (!devpriv
->pwm_cmd_running
)
1079 urb
->transfer_buffer_length
= devpriv
->pwm_buf_sz
;
1080 urb
->dev
= comedi_to_usb_dev(dev
);
1082 ret
= usb_submit_urb(urb
, GFP_ATOMIC
);
1084 dev_err(dev
->class_dev
, "urb resubmit failed (%d)\n", ret
);
1085 if (ret
== -EL2NSYNC
)
1086 dev_err(dev
->class_dev
,
1087 "buggy USB host controller or bug in IRQ handler\n");
1088 usbduxsigma_pwm_stop(dev
, 0); /* w/o unlink */
1092 static int usbduxsigma_submit_pwm_urb(struct comedi_device
*dev
)
1094 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
1095 struct usbduxsigma_private
*devpriv
= dev
->private;
1096 struct urb
*urb
= devpriv
->pwm_urb
;
1098 /* in case of a resubmission after an unlink... */
1099 usb_fill_bulk_urb(urb
, usb
, usb_sndbulkpipe(usb
, 4),
1100 urb
->transfer_buffer
, devpriv
->pwm_buf_sz
,
1101 usbduxsigma_pwm_urb_complete
, dev
);
1103 return usb_submit_urb(urb
, GFP_ATOMIC
);
1106 static int usbduxsigma_pwm_period(struct comedi_device
*dev
,
1107 struct comedi_subdevice
*s
,
1108 unsigned int period
)
1110 struct usbduxsigma_private
*devpriv
= dev
->private;
1113 if (period
< MIN_PWM_PERIOD
)
1116 fx2delay
= (period
/ (6 * 512 * 1000 / 33)) - 6;
1120 devpriv
->pwm_delay
= fx2delay
;
1121 devpriv
->pwm_period
= period
;
1125 static int usbduxsigma_pwm_start(struct comedi_device
*dev
,
1126 struct comedi_subdevice
*s
)
1128 struct usbduxsigma_private
*devpriv
= dev
->private;
1131 if (devpriv
->pwm_cmd_running
)
1134 devpriv
->dux_commands
[1] = devpriv
->pwm_delay
;
1135 ret
= usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_PWM_ON_CMD
);
1139 memset(devpriv
->pwm_urb
->transfer_buffer
, 0, devpriv
->pwm_buf_sz
);
1141 devpriv
->pwm_cmd_running
= 1;
1142 ret
= usbduxsigma_submit_pwm_urb(dev
);
1144 devpriv
->pwm_cmd_running
= 0;
1151 static void usbduxsigma_pwm_pattern(struct comedi_device
*dev
,
1152 struct comedi_subdevice
*s
,
1157 struct usbduxsigma_private
*devpriv
= dev
->private;
1158 char pwm_mask
= (1 << chan
); /* DIO bit for the PWM data */
1159 char sgn_mask
= (16 << chan
); /* DIO bit for the sign */
1160 char *buf
= (char *)(devpriv
->pwm_urb
->transfer_buffer
);
1161 int szbuf
= devpriv
->pwm_buf_sz
;
1164 for (i
= 0; i
< szbuf
; i
++) {
1178 static int usbduxsigma_pwm_write(struct comedi_device
*dev
,
1179 struct comedi_subdevice
*s
,
1180 struct comedi_insn
*insn
,
1183 unsigned int chan
= CR_CHAN(insn
->chanspec
);
1186 * It doesn't make sense to support more than one value here
1187 * because it would just overwrite the PWM buffer.
1193 * The sign is set via a special INSN only, this gives us 8 bits
1194 * for normal operation, sign is 0 by default.
1196 usbduxsigma_pwm_pattern(dev
, s
, chan
, data
[0], 0);
1201 static int usbduxsigma_pwm_config(struct comedi_device
*dev
,
1202 struct comedi_subdevice
*s
,
1203 struct comedi_insn
*insn
,
1206 struct usbduxsigma_private
*devpriv
= dev
->private;
1207 unsigned int chan
= CR_CHAN(insn
->chanspec
);
1210 case INSN_CONFIG_ARM
:
1212 * if not zero the PWM is limited to a certain time which is
1213 * not supported here
1217 return usbduxsigma_pwm_start(dev
, s
);
1218 case INSN_CONFIG_DISARM
:
1219 return usbduxsigma_pwm_cancel(dev
, s
);
1220 case INSN_CONFIG_GET_PWM_STATUS
:
1221 data
[1] = devpriv
->pwm_cmd_running
;
1223 case INSN_CONFIG_PWM_SET_PERIOD
:
1224 return usbduxsigma_pwm_period(dev
, s
, data
[1]);
1225 case INSN_CONFIG_PWM_GET_PERIOD
:
1226 data
[1] = devpriv
->pwm_period
;
1228 case INSN_CONFIG_PWM_SET_H_BRIDGE
:
1231 * data[2] = sign (for a relay)
1233 usbduxsigma_pwm_pattern(dev
, s
, chan
, data
[1], (data
[2] != 0));
1235 case INSN_CONFIG_PWM_GET_H_BRIDGE
:
1236 /* values are not kept in this driver, nothing to return */
1242 static int usbduxsigma_getstatusinfo(struct comedi_device
*dev
, int chan
)
1244 struct usbduxsigma_private
*devpriv
= dev
->private;
1252 sysred
= 0; /* ADC zero */
1255 sysred
= 1; /* ADC offset */
1258 sysred
= 4; /* VCC */
1261 sysred
= 8; /* temperature */
1264 sysred
= 16; /* gain */
1267 sysred
= 32; /* ref */
1271 devpriv
->dux_commands
[1] = 0x12; /* CONFIG0 */
1272 devpriv
->dux_commands
[2] = 0x80; /* CONFIG1: 2kHz sampling rate */
1273 devpriv
->dux_commands
[3] = 0x00; /* CONFIG3: diff. channels off */
1274 devpriv
->dux_commands
[4] = 0;
1275 devpriv
->dux_commands
[5] = 0;
1276 devpriv
->dux_commands
[6] = sysred
;
1277 ret
= usbbuxsigma_send_cmd(dev
, USBDUXSIGMA_SINGLE_AD_CMD
);
1281 ret
= usbduxsigma_receive_cmd(dev
, USBDUXSIGMA_SINGLE_AD_CMD
);
1285 /* 32 bits big endian from the A/D converter */
1286 val
= be32_to_cpu(get_unaligned((__be32
*)(devpriv
->insn_buf
+ 1)));
1287 val
&= 0x00ffffff; /* strip status byte */
1288 val
^= 0x00800000; /* convert to unsigned */
1293 static int usbduxsigma_firmware_upload(struct comedi_device
*dev
,
1294 const u8
*data
, size_t size
,
1295 unsigned long context
)
1297 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
1305 if (size
> FIRMWARE_MAX_LEN
) {
1306 dev_err(dev
->class_dev
, "firmware binary too large for FX2\n");
1310 /* we generate a local buffer for the firmware */
1311 buf
= kmemdup(data
, size
, GFP_KERNEL
);
1315 /* we need a malloc'ed buffer for usb_control_msg() */
1316 tmp
= kmalloc(1, GFP_KERNEL
);
1322 /* stop the current firmware on the device */
1323 *tmp
= 1; /* 7f92 to one */
1324 ret
= usb_control_msg(usb
, usb_sndctrlpipe(usb
, 0),
1327 USBDUXSUB_CPUCS
, 0x0000,
1331 dev_err(dev
->class_dev
, "can not stop firmware\n");
1335 /* upload the new firmware to the device */
1336 ret
= usb_control_msg(usb
, usb_sndctrlpipe(usb
, 0),
1343 dev_err(dev
->class_dev
, "firmware upload failed\n");
1347 /* start the new firmware on the device */
1348 *tmp
= 0; /* 7f92 to zero */
1349 ret
= usb_control_msg(usb
, usb_sndctrlpipe(usb
, 0),
1352 USBDUXSUB_CPUCS
, 0x0000,
1356 dev_err(dev
->class_dev
, "can not start firmware\n");
1364 static int usbduxsigma_alloc_usb_buffers(struct comedi_device
*dev
)
1366 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
1367 struct usbduxsigma_private
*devpriv
= dev
->private;
1371 devpriv
->dux_commands
= kzalloc(SIZEOFDUXBUFFER
, GFP_KERNEL
);
1372 devpriv
->in_buf
= kzalloc(SIZEINBUF
, GFP_KERNEL
);
1373 devpriv
->insn_buf
= kzalloc(SIZEINSNBUF
, GFP_KERNEL
);
1374 devpriv
->ai_urbs
= kcalloc(devpriv
->n_ai_urbs
, sizeof(urb
), GFP_KERNEL
);
1375 devpriv
->ao_urbs
= kcalloc(devpriv
->n_ao_urbs
, sizeof(urb
), GFP_KERNEL
);
1376 if (!devpriv
->dux_commands
|| !devpriv
->in_buf
|| !devpriv
->insn_buf
||
1377 !devpriv
->ai_urbs
|| !devpriv
->ao_urbs
)
1380 for (i
= 0; i
< devpriv
->n_ai_urbs
; i
++) {
1381 /* one frame: 1ms */
1382 urb
= usb_alloc_urb(1, GFP_KERNEL
);
1385 devpriv
->ai_urbs
[i
] = urb
;
1387 /* will be filled later with a pointer to the comedi-device */
1388 /* and ONLY then the urb should be submitted */
1389 urb
->context
= NULL
;
1390 urb
->pipe
= usb_rcvisocpipe(usb
, 6);
1391 urb
->transfer_flags
= URB_ISO_ASAP
;
1392 urb
->transfer_buffer
= kzalloc(SIZEINBUF
, GFP_KERNEL
);
1393 if (!urb
->transfer_buffer
)
1395 urb
->complete
= usbduxsigma_ai_urb_complete
;
1396 urb
->number_of_packets
= 1;
1397 urb
->transfer_buffer_length
= SIZEINBUF
;
1398 urb
->iso_frame_desc
[0].offset
= 0;
1399 urb
->iso_frame_desc
[0].length
= SIZEINBUF
;
1402 for (i
= 0; i
< devpriv
->n_ao_urbs
; i
++) {
1403 /* one frame: 1ms */
1404 urb
= usb_alloc_urb(1, GFP_KERNEL
);
1407 devpriv
->ao_urbs
[i
] = urb
;
1409 /* will be filled later with a pointer to the comedi-device */
1410 /* and ONLY then the urb should be submitted */
1411 urb
->context
= NULL
;
1412 urb
->pipe
= usb_sndisocpipe(usb
, 2);
1413 urb
->transfer_flags
= URB_ISO_ASAP
;
1414 urb
->transfer_buffer
= kzalloc(SIZEOUTBUF
, GFP_KERNEL
);
1415 if (!urb
->transfer_buffer
)
1417 urb
->complete
= usbduxsigma_ao_urb_complete
;
1418 urb
->number_of_packets
= 1;
1419 urb
->transfer_buffer_length
= SIZEOUTBUF
;
1420 urb
->iso_frame_desc
[0].offset
= 0;
1421 urb
->iso_frame_desc
[0].length
= SIZEOUTBUF
;
1422 urb
->interval
= 1; /* (u)frames */
1425 if (devpriv
->pwm_buf_sz
) {
1426 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1429 devpriv
->pwm_urb
= urb
;
1431 urb
->transfer_buffer
= kzalloc(devpriv
->pwm_buf_sz
,
1433 if (!urb
->transfer_buffer
)
1440 static void usbduxsigma_free_usb_buffers(struct comedi_device
*dev
)
1442 struct usbduxsigma_private
*devpriv
= dev
->private;
1446 urb
= devpriv
->pwm_urb
;
1448 kfree(urb
->transfer_buffer
);
1451 if (devpriv
->ao_urbs
) {
1452 for (i
= 0; i
< devpriv
->n_ao_urbs
; i
++) {
1453 urb
= devpriv
->ao_urbs
[i
];
1455 kfree(urb
->transfer_buffer
);
1459 kfree(devpriv
->ao_urbs
);
1461 if (devpriv
->ai_urbs
) {
1462 for (i
= 0; i
< devpriv
->n_ai_urbs
; i
++) {
1463 urb
= devpriv
->ai_urbs
[i
];
1465 kfree(urb
->transfer_buffer
);
1469 kfree(devpriv
->ai_urbs
);
1471 kfree(devpriv
->insn_buf
);
1472 kfree(devpriv
->in_buf
);
1473 kfree(devpriv
->dux_commands
);
1476 static int usbduxsigma_auto_attach(struct comedi_device
*dev
,
1477 unsigned long context_unused
)
1479 struct usb_interface
*intf
= comedi_to_usb_interface(dev
);
1480 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
1481 struct usbduxsigma_private
*devpriv
;
1482 struct comedi_subdevice
*s
;
1486 devpriv
= comedi_alloc_devpriv(dev
, sizeof(*devpriv
));
1490 sema_init(&devpriv
->sem
, 1);
1492 usb_set_intfdata(intf
, devpriv
);
1494 devpriv
->high_speed
= (usb
->speed
== USB_SPEED_HIGH
);
1495 if (devpriv
->high_speed
) {
1496 devpriv
->n_ai_urbs
= NUMOFINBUFFERSHIGH
;
1497 devpriv
->n_ao_urbs
= NUMOFOUTBUFFERSHIGH
;
1498 devpriv
->pwm_buf_sz
= 512;
1500 devpriv
->n_ai_urbs
= NUMOFINBUFFERSFULL
;
1501 devpriv
->n_ao_urbs
= NUMOFOUTBUFFERSFULL
;
1504 ret
= usbduxsigma_alloc_usb_buffers(dev
);
1508 /* setting to alternate setting 3: enabling iso ep and bulk ep. */
1509 ret
= usb_set_interface(usb
, intf
->altsetting
->desc
.bInterfaceNumber
,
1512 dev_err(dev
->class_dev
,
1513 "could not set alternate setting 3 in high speed\n");
1517 ret
= comedi_load_firmware(dev
, &usb
->dev
, FIRMWARE
,
1518 usbduxsigma_firmware_upload
, 0);
1522 ret
= comedi_alloc_subdevices(dev
, (devpriv
->high_speed
) ? 4 : 3);
1526 /* Analog Input subdevice */
1527 s
= &dev
->subdevices
[0];
1528 dev
->read_subdev
= s
;
1529 s
->type
= COMEDI_SUBD_AI
;
1530 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
| SDF_CMD_READ
| SDF_LSAMPL
;
1531 s
->n_chan
= NUMCHANNELS
;
1532 s
->len_chanlist
= NUMCHANNELS
;
1533 s
->maxdata
= 0x00ffffff;
1534 s
->range_table
= &usbduxsigma_ai_range
;
1535 s
->insn_read
= usbduxsigma_ai_insn_read
;
1536 s
->do_cmdtest
= usbduxsigma_ai_cmdtest
;
1537 s
->do_cmd
= usbduxsigma_ai_cmd
;
1538 s
->cancel
= usbduxsigma_ai_cancel
;
1540 /* Analog Output subdevice */
1541 s
= &dev
->subdevices
[1];
1542 dev
->write_subdev
= s
;
1543 s
->type
= COMEDI_SUBD_AO
;
1544 s
->subdev_flags
= SDF_WRITABLE
| SDF_GROUND
| SDF_CMD_WRITE
;
1546 s
->len_chanlist
= s
->n_chan
;
1547 s
->maxdata
= 0x00ff;
1548 s
->range_table
= &range_unipolar2_5
;
1549 s
->insn_write
= usbduxsigma_ao_insn_write
;
1550 s
->insn_read
= usbduxsigma_ao_insn_read
;
1551 s
->do_cmdtest
= usbduxsigma_ao_cmdtest
;
1552 s
->do_cmd
= usbduxsigma_ao_cmd
;
1553 s
->cancel
= usbduxsigma_ao_cancel
;
1555 ret
= comedi_alloc_subdev_readback(s
);
1559 /* Digital I/O subdevice */
1560 s
= &dev
->subdevices
[2];
1561 s
->type
= COMEDI_SUBD_DIO
;
1562 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
1565 s
->range_table
= &range_digital
;
1566 s
->insn_bits
= usbduxsigma_dio_insn_bits
;
1567 s
->insn_config
= usbduxsigma_dio_insn_config
;
1569 if (devpriv
->high_speed
) {
1570 /* Timer / pwm subdevice */
1571 s
= &dev
->subdevices
[3];
1572 s
->type
= COMEDI_SUBD_PWM
;
1573 s
->subdev_flags
= SDF_WRITABLE
| SDF_PWM_HBRIDGE
;
1575 s
->maxdata
= devpriv
->pwm_buf_sz
;
1576 s
->insn_write
= usbduxsigma_pwm_write
;
1577 s
->insn_config
= usbduxsigma_pwm_config
;
1579 usbduxsigma_pwm_period(dev
, s
, PWM_DEFAULT_PERIOD
);
1582 offset
= usbduxsigma_getstatusinfo(dev
, 0);
1584 dev_err(dev
->class_dev
,
1585 "Communication to USBDUXSIGMA failed! Check firmware and cabling.\n");
1589 dev_info(dev
->class_dev
, "ADC_zero = %x\n", offset
);
1594 static void usbduxsigma_detach(struct comedi_device
*dev
)
1596 struct usb_interface
*intf
= comedi_to_usb_interface(dev
);
1597 struct usbduxsigma_private
*devpriv
= dev
->private;
1599 usb_set_intfdata(intf
, NULL
);
1604 down(&devpriv
->sem
);
1606 /* force unlink all urbs */
1607 usbduxsigma_ai_stop(dev
, 1);
1608 usbduxsigma_ao_stop(dev
, 1);
1609 usbduxsigma_pwm_stop(dev
, 1);
1611 usbduxsigma_free_usb_buffers(dev
);
1616 static struct comedi_driver usbduxsigma_driver
= {
1617 .driver_name
= "usbduxsigma",
1618 .module
= THIS_MODULE
,
1619 .auto_attach
= usbduxsigma_auto_attach
,
1620 .detach
= usbduxsigma_detach
,
1623 static int usbduxsigma_usb_probe(struct usb_interface
*intf
,
1624 const struct usb_device_id
*id
)
1626 return comedi_usb_auto_config(intf
, &usbduxsigma_driver
, 0);
1629 static const struct usb_device_id usbduxsigma_usb_table
[] = {
1630 { USB_DEVICE(0x13d8, 0x0020) },
1631 { USB_DEVICE(0x13d8, 0x0021) },
1632 { USB_DEVICE(0x13d8, 0x0022) },
1635 MODULE_DEVICE_TABLE(usb
, usbduxsigma_usb_table
);
1637 static struct usb_driver usbduxsigma_usb_driver
= {
1638 .name
= "usbduxsigma",
1639 .probe
= usbduxsigma_usb_probe
,
1640 .disconnect
= comedi_usb_auto_unconfig
,
1641 .id_table
= usbduxsigma_usb_table
,
1643 module_comedi_usb_driver(usbduxsigma_driver
, usbduxsigma_usb_driver
);
1645 MODULE_AUTHOR("Bernd Porr, mail@berndporr.me.uk");
1646 MODULE_DESCRIPTION("Stirling/ITL USB-DUX SIGMA -- mail@berndporr.me.uk");
1647 MODULE_LICENSE("GPL");
1648 MODULE_FIRMWARE(FIRMWARE
);