2 comedi/drivers/usbdux.c
3 Copyright (C) 2011 Bernd Porr, Bernd.Porr@f2s.com
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.
17 Description: University of Stirling USB DAQ & INCITE Technology Limited
18 Devices: [ITL] USB-DUX (usbduxsigma.o)
19 Author: Bernd Porr <BerndPorr@f2s.com>
24 * I must give credit here to Chris Baugher who
25 * wrote the driver for AT-MIO-16d. I used some parts of this
26 * driver. I also must give credits to David Brownell
27 * who supported me with the USB development.
29 * Note: the raw data from the A/D converter is 24 bit big endian
30 * anything else is little endian to/from the dux board
34 * 0.1: initial version
35 * 0.2: all basic functions implemented, digital I/O only for one port
36 * 0.3: proper vendor ID and driver name
37 * 0.4: fixed D/A voltage range
38 * 0.5: various bug fixes, health check at startup
39 * 0.6: corrected wrong input range
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/slab.h>
46 #include <linux/input.h>
47 #include <linux/usb.h>
48 #include <linux/fcntl.h>
49 #include <linux/compiler.h>
51 #include "comedi_fc.h"
52 #include "../comedidev.h"
54 /* timeout for the USB-transfer in ms*/
55 #define BULK_TIMEOUT 1000
57 /* constants for "firmware" upload and download */
58 #define FIRMWARE "usbduxsigma_firmware.bin"
59 #define FIRMWARE_MAX_LEN 0x4000
60 #define USBDUXSUB_FIRMWARE 0xa0
61 #define VENDOR_DIR_IN 0xc0
62 #define VENDOR_DIR_OUT 0x40
64 /* internal addresses of the 8051 processor */
65 #define USBDUXSUB_CPUCS 0xE600
68 * the minor device number, major is 180 only for debugging purposes and to
69 * upload special firmware (programming the eeprom etc) which is not
70 * compatible with the comedi framwork
72 #define USBDUXSUB_MINOR 32
74 /* max lenghth of the transfer-buffer for software upload */
77 /* Input endpoint number: ISO/IRQ */
80 /* Output endpoint number: ISO/IRQ */
83 /* This EP sends DUX commands to USBDUX */
84 #define COMMAND_OUT_EP 1
86 /* This EP receives the DUX commands from USBDUX */
87 #define COMMAND_IN_EP 8
89 /* Output endpoint for PWM */
92 /* 300Hz max frequ under PWM */
93 #define MIN_PWM_PERIOD ((long)(1E9/300))
95 /* Default PWM frequency */
96 #define PWM_DEFAULT_PERIOD ((long)(1E9/100))
98 /* Number of channels (16 AD and offset)*/
99 #define NUMCHANNELS 16
101 /* Size of one A/D value */
102 #define SIZEADIN ((sizeof(int32_t)))
105 * Size of the async input-buffer IN BYTES, the DIO state is transmitted
108 #define SIZEINBUF (((NUMCHANNELS+1)*SIZEADIN))
111 #define SIZEINSNBUF 16
113 /* Number of DA channels */
114 #define NUMOUTCHANNELS 8
116 /* size of one value for the D/A converter: channel and value */
117 #define SIZEDAOUT ((sizeof(uint8_t)+sizeof(int16_t)))
120 * Size of the output-buffer in bytes
121 * Actually only the first 4 triplets are used but for the
122 * high speed mode we need to pad it to 8 (microframes).
124 #define SIZEOUTBUF ((8*SIZEDAOUT))
127 * Size of the buffer for the dux commands: just now max size is determined
128 * by the analogue out + command byte + panic bytes...
130 #define SIZEOFDUXBUFFER ((8*SIZEDAOUT+2))
132 /* Number of in-URBs which receive the data: min=2 */
133 #define NUMOFINBUFFERSFULL 5
135 /* Number of out-URBs which send the data: min=2 */
136 #define NUMOFOUTBUFFERSFULL 5
138 /* Number of in-URBs which receive the data: min=5 */
139 /* must have more buffers due to buggy USB ctr */
140 #define NUMOFINBUFFERSHIGH 10
142 /* Number of out-URBs which send the data: min=5 */
143 /* must have more buffers due to buggy USB ctr */
144 #define NUMOFOUTBUFFERSHIGH 10
146 /* number of retries to get the right dux command */
149 /**************************************************/
150 /* comedi constants */
151 static const struct comedi_lrange range_usbdux_ai_range = { 1, {
157 struct usbduxsigma_private {
158 /* actual number of in-buffers */
160 /* actual number of out-buffers */
162 /* ISO-transfer handling: buffers */
165 /* pwm-transfer handling */
168 unsigned int pwmPeriod;
169 /* PWM internal delay for the GPIF in the FX2 */
171 /* size of the PWM buffer which holds the bit pattern */
173 /* input buffer for the ISO-transfer */
175 /* input buffer for single insn */
177 /* output buffer for single DA outputs */
180 unsigned high_speed:1;
181 unsigned ai_cmd_running:1;
182 unsigned ai_continuous:1;
183 unsigned ao_cmd_running:1;
184 unsigned ao_continuous:1;
185 unsigned pwm_cmd_running:1;
187 /* number of samples to acquire */
190 /* time between samples in units of the timer */
191 unsigned int ai_timer;
192 unsigned int ao_timer;
193 /* counter between acquisitions */
194 unsigned int ai_counter;
195 unsigned int ao_counter;
196 /* interval in frames/uframes */
197 unsigned int ai_interval;
199 uint8_t *dac_commands;
201 uint8_t *dux_commands;
202 struct semaphore sem;
205 static void usbdux_ai_stop(struct usbduxsigma_private *devpriv, int do_unlink)
210 for (i = 0; i < devpriv->numOfInBuffers; i++) {
211 if (devpriv->urbIn[i])
212 usb_kill_urb(devpriv->urbIn[i]);
216 devpriv->ai_cmd_running = 0;
219 static int usbdux_ai_cancel(struct comedi_device *dev,
220 struct comedi_subdevice *s)
222 struct usbduxsigma_private *devpriv = dev->private;
225 /* unlink only if it is really running */
226 usbdux_ai_stop(devpriv, devpriv->ai_cmd_running);
232 static void usbduxsub_ai_IsocIrq(struct urb *urb)
234 struct comedi_device *dev = urb->context;
235 struct usbduxsigma_private *devpriv = dev->private;
236 struct comedi_subdevice *s = dev->read_subdev;
237 unsigned int dio_state;
242 /* first we test if something unusual has just happened */
243 switch (urb->status) {
245 /* copy the result in the transfer buffer */
246 memcpy(devpriv->inBuffer, urb->transfer_buffer, SIZEINBUF);
250 * error in the ISOchronous data
251 * we don't copy the data into the transfer buffer
252 * and recycle the last data byte
254 dev_dbg(dev->class_dev,"CRC error in ISO IN stream\n");
262 /* happens after an unlink command */
263 if (devpriv->ai_cmd_running) {
264 usbdux_ai_stop(devpriv, 0); /* w/o unlink */
265 /* we are still running a command, tell comedi */
266 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
267 comedi_event(dev, s);
273 * a real error on the bus
274 * pass error to comedi if we are really running a command
276 if (devpriv->ai_cmd_running) {
277 dev_err(dev->class_dev,
278 "%s: non-zero urb status (%d)\n",
279 __func__, urb->status);
280 usbdux_ai_stop(devpriv, 0); /* w/o unlink */
281 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
282 comedi_event(dev, s);
287 if (unlikely(!devpriv->ai_cmd_running))
290 urb->dev = comedi_to_usb_dev(dev);
292 ret = usb_submit_urb(urb, GFP_ATOMIC);
293 if (unlikely(ret < 0)) {
294 dev_err(dev->class_dev, "%s: urb resubmit failed (%d)\n",
296 if (ret == -EL2NSYNC)
297 dev_err(dev->class_dev,
298 "buggy USB host controller or bug in IRQ handler\n");
299 usbdux_ai_stop(devpriv, 0); /* w/o unlink */
300 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
301 comedi_event(dev, s);
305 /* get the state of the dio pins to allow external trigger */
306 dio_state = be32_to_cpu(devpriv->inBuffer[0]);
308 devpriv->ai_counter--;
309 if (likely(devpriv->ai_counter > 0))
312 /* timer zero, transfer measurements to comedi */
313 devpriv->ai_counter = devpriv->ai_timer;
315 if (!devpriv->ai_continuous) {
316 /* not continuous, fixed number of samples */
317 devpriv->ai_sample_count--;
318 if (devpriv->ai_sample_count < 0) {
319 usbdux_ai_stop(devpriv, 0); /* w/o unlink */
320 /* acquistion is over, tell comedi */
321 s->async->events |= COMEDI_CB_EOA;
322 comedi_event(dev, s);
327 /* get the data from the USB bus and hand it over to comedi */
328 for (i = 0; i < s->async->cmd.chanlist_len; i++) {
329 /* transfer data, note first byte is the DIO state */
330 val = be32_to_cpu(devpriv->inBuffer[i+1]);
331 val &= 0x00ffffff; /* strip status byte */
332 val ^= 0x00800000; /* convert to unsigned */
334 ret = cfc_write_array_to_buffer(s, &val, sizeof(uint32_t));
335 if (unlikely(ret == 0)) {
336 /* buffer overflow */
337 usbdux_ai_stop(devpriv, 0); /* w/o unlink */
341 /* tell comedi that data is there */
342 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
343 comedi_event(dev, s);
346 static void usbdux_ao_stop(struct usbduxsigma_private *devpriv, int do_unlink)
351 for (i = 0; i < devpriv->numOfOutBuffers; i++) {
352 if (devpriv->urbOut[i])
353 usb_kill_urb(devpriv->urbOut[i]);
357 devpriv->ao_cmd_running = 0;
360 static int usbdux_ao_cancel(struct comedi_device *dev,
361 struct comedi_subdevice *s)
363 struct usbduxsigma_private *devpriv = dev->private;
366 /* unlink only if it is really running */
367 usbdux_ao_stop(devpriv, devpriv->ao_cmd_running);
373 static void usbduxsub_ao_IsocIrq(struct urb *urb)
375 struct comedi_device *dev = urb->context;
376 struct usbduxsigma_private *devpriv = dev->private;
377 struct comedi_subdevice *s = dev->write_subdev;
383 switch (urb->status) {
392 /* happens after an unlink command */
393 if (devpriv->ao_cmd_running) {
394 usbdux_ao_stop(devpriv, 0); /* w/o unlink */
395 s->async->events |= COMEDI_CB_EOA;
396 comedi_event(dev, s);
402 if (devpriv->ao_cmd_running) {
403 dev_err(dev->class_dev,
404 "%s: non-zero urb status (%d)\n",
405 __func__, urb->status);
406 usbdux_ao_stop(devpriv, 0); /* w/o unlink */
407 s->async->events |= (COMEDI_CB_ERROR | COMEDI_CB_EOA);
408 comedi_event(dev, s);
413 if (!devpriv->ao_cmd_running)
416 devpriv->ao_counter--;
417 if ((int)devpriv->ao_counter <= 0) {
418 /* timer zero, transfer from comedi */
419 devpriv->ao_counter = devpriv->ao_timer;
421 if (!devpriv->ao_continuous) {
422 /* not continuous, fixed number of samples */
423 devpriv->ao_sample_count--;
424 if (devpriv->ao_sample_count < 0) {
425 usbdux_ao_stop(devpriv, 0); /* w/o unlink */
426 /* acquistion is over, tell comedi */
427 s->async->events |= COMEDI_CB_EOA;
428 comedi_event(dev, s);
433 /* transmit data to the USB bus */
434 datap = urb->transfer_buffer;
435 len = s->async->cmd.chanlist_len;
437 for (i = 0; i < len; i++) {
440 if (i >= NUMOUTCHANNELS)
443 ret = comedi_buf_get(s->async, &val);
445 dev_err(dev->class_dev, "buffer underflow\n");
446 s->async->events |= (COMEDI_CB_EOA |
450 *datap++ = devpriv->dac_commands[i];
452 s->async->events |= COMEDI_CB_BLOCK;
453 comedi_event(dev, s);
457 urb->transfer_buffer_length = SIZEOUTBUF;
458 urb->dev = comedi_to_usb_dev(dev);
460 if (devpriv->high_speed)
461 urb->interval = 8; /* uframes */
463 urb->interval = 1; /* frames */
464 urb->number_of_packets = 1;
465 urb->iso_frame_desc[0].offset = 0;
466 urb->iso_frame_desc[0].length = SIZEOUTBUF;
467 urb->iso_frame_desc[0].status = 0;
468 ret = usb_submit_urb(urb, GFP_ATOMIC);
470 dev_err(dev->class_dev,
471 "%s: urb resubmit failed (%d)\n",
474 dev_err(dev->class_dev,
475 "buggy USB host controller or bug in IRQ handler\n");
476 usbdux_ao_stop(devpriv, 0); /* w/o unlink */
477 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
478 comedi_event(dev, s);
482 static int usbduxsigma_submit_urbs(struct comedi_device *dev,
483 struct urb **urbs, int num_urbs,
486 struct usb_device *usb = comedi_to_usb_dev(dev);
487 struct usbduxsigma_private *devpriv = dev->private;
492 /* Submit all URBs and start the transfer on the bus */
493 for (i = 0; i < num_urbs; i++) {
496 /* in case of a resubmission after an unlink... */
498 urb->interval = devpriv->ai_interval;
502 urb->transfer_flags = URB_ISO_ASAP;
504 ret = usb_submit_urb(urb, GFP_ATOMIC);
511 static int chanToInterval(int nChannels)
523 static int usbdux_ai_cmdtest(struct comedi_device *dev,
524 struct comedi_subdevice *s,
525 struct comedi_cmd *cmd)
527 struct usbduxsigma_private *this_usbduxsub = dev->private;
529 unsigned int tmpTimer;
531 /* Step 1 : check if triggers are trivially valid */
533 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
534 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
535 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
536 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
537 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
542 /* Step 2a : make sure trigger sources are unique */
544 err |= cfc_check_trigger_is_unique(cmd->start_src);
545 err |= cfc_check_trigger_is_unique(cmd->stop_src);
547 /* Step 2b : and mutually compatible */
552 /* Step 3: check if arguments are trivially valid */
554 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
556 if (cmd->scan_begin_src == TRIG_FOLLOW) /* internal trigger */
557 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
559 if (cmd->scan_begin_src == TRIG_TIMER) {
560 if (this_usbduxsub->high_speed) {
562 * In high speed mode microframes are possible.
563 * However, during one microframe we can roughly
564 * sample two channels. Thus, the more channels
565 * are in the channel list the more time we need.
567 i = chanToInterval(cmd->chanlist_len);
568 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
570 /* now calc the real sampling rate with all the
573 ((unsigned int)(cmd->scan_begin_arg / 125000)) *
577 /* 1kHz scans every USB frame */
578 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
581 * calc the real sampling rate with the rounding errors
583 tmpTimer = ((unsigned int)(cmd->scan_begin_arg /
586 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg,
590 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
592 if (cmd->stop_src == TRIG_COUNT) {
593 /* any count is allowed */
596 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
606 * creates the ADC command for the MAX1271
607 * range is the range value from comedi
609 static void create_adc_command(unsigned int chan,
614 (*muxsg0) = (*muxsg0) | (1 << chan);
616 (*muxsg1) = (*muxsg1) | (1 << (chan-8));
620 /* bulk transfers to usbdux */
622 #define SENDADCOMMANDS 0
623 #define SENDDACOMMANDS 1
624 #define SENDDIOCONFIGCOMMAND 2
625 #define SENDDIOBITSCOMMAND 3
626 #define SENDSINGLEAD 4
630 static int send_dux_commands(struct comedi_device *dev, int cmd_type)
632 struct usb_device *usb = comedi_to_usb_dev(dev);
633 struct usbduxsigma_private *devpriv = dev->private;
636 devpriv->dux_commands[0] = cmd_type;
638 return usb_bulk_msg(usb, usb_sndbulkpipe(usb, COMMAND_OUT_EP),
639 devpriv->dux_commands, SIZEOFDUXBUFFER,
640 &nsent, BULK_TIMEOUT);
643 static int receive_dux_commands(struct comedi_device *dev, int command)
645 struct usb_device *usb = comedi_to_usb_dev(dev);
646 struct usbduxsigma_private *devpriv = dev->private;
651 for (i = 0; i < RETRIES; i++) {
652 ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, COMMAND_IN_EP),
653 devpriv->insnBuffer, SIZEINSNBUF,
654 &nrec, BULK_TIMEOUT);
658 if (devpriv->insnBuffer[0] == command)
662 * This is only reached if the data has been requested a
663 * couple of times and the command was not received.
668 static int usbduxsigma_ai_inttrig(struct comedi_device *dev,
669 struct comedi_subdevice *s,
670 unsigned int trignum)
672 struct usbduxsigma_private *devpriv= dev->private;
679 if (!devpriv->ai_cmd_running) {
680 ret = usbduxsigma_submit_urbs(dev, devpriv->urbIn,
681 devpriv->numOfInBuffers, 1);
686 devpriv->ai_cmd_running = 1;
687 s->async->inttrig = NULL;
694 static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
696 struct usbduxsigma_private *this_usbduxsub = dev->private;
697 struct comedi_cmd *cmd = &s->async->cmd;
705 /* block other CPUs from starting an ai_cmd */
706 down(&this_usbduxsub->sem);
707 if (this_usbduxsub->ai_cmd_running) {
708 up(&this_usbduxsub->sem);
711 /* set current channel of the running acquisition to zero */
712 s->async->cur_chan = 0;
714 /* first the number of channels per time step */
715 this_usbduxsub->dux_commands[1] = cmd->chanlist_len;
718 this_usbduxsub->dux_commands[2] = 0x12;
720 /* CONFIG1: 23kHz sampling rate, delay = 0us, */
721 this_usbduxsub->dux_commands[3] = 0x03;
723 /* CONFIG3: differential channels off */
724 this_usbduxsub->dux_commands[4] = 0x00;
726 for (i = 0; i < cmd->chanlist_len; i++) {
727 chan = CR_CHAN(cmd->chanlist[i]);
728 create_adc_command(chan, &muxsg0, &muxsg1);
730 this_usbduxsub->dux_commands[5] = muxsg0;
731 this_usbduxsub->dux_commands[6] = muxsg1;
732 this_usbduxsub->dux_commands[7] = sysred;
734 result = send_dux_commands(dev, SENDADCOMMANDS);
736 up(&this_usbduxsub->sem);
740 if (this_usbduxsub->high_speed) {
742 * every 2 channels get a time window of 125us. Thus, if we
743 * sample all 16 channels we need 1ms. If we sample only one
744 * channel we need only 125us
746 this_usbduxsub->ai_interval =
747 chanToInterval(cmd->chanlist_len);
748 this_usbduxsub->ai_timer = cmd->scan_begin_arg / (125000 *
752 /* interval always 1ms */
753 this_usbduxsub->ai_interval = 1;
754 this_usbduxsub->ai_timer = cmd->scan_begin_arg / 1000000;
756 if (this_usbduxsub->ai_timer < 1) {
757 up(&this_usbduxsub->sem);
760 this_usbduxsub->ai_counter = this_usbduxsub->ai_timer;
762 if (cmd->stop_src == TRIG_COUNT) {
763 /* data arrives as one packet */
764 this_usbduxsub->ai_sample_count = cmd->stop_arg;
765 this_usbduxsub->ai_continuous = 0;
767 /* continuous acquisition */
768 this_usbduxsub->ai_continuous = 1;
769 this_usbduxsub->ai_sample_count = 0;
772 if (cmd->start_src == TRIG_NOW) {
773 /* enable this acquisition operation */
774 ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbIn,
775 this_usbduxsub->numOfInBuffers,
778 up(&this_usbduxsub->sem);
781 this_usbduxsub->ai_cmd_running = 1;
782 s->async->inttrig = NULL;
785 /* don't enable the acquision operation */
786 /* wait for an internal signal */
787 s->async->inttrig = usbduxsigma_ai_inttrig;
789 up(&this_usbduxsub->sem);
793 /* Mode 0 is used to get a single conversion on demand */
794 static int usbdux_ai_insn_read(struct comedi_device *dev,
795 struct comedi_subdevice *s,
796 struct comedi_insn *insn, unsigned int *data)
798 struct usbduxsigma_private *this_usbduxsub = dev->private;
807 down(&this_usbduxsub->sem);
808 if (this_usbduxsub->ai_cmd_running) {
809 up(&this_usbduxsub->sem);
813 /* sample one channel */
814 /* CONFIG0: chopper on */
815 this_usbduxsub->dux_commands[1] = 0x16;
817 /* CONFIG1: 2kHz sampling rate */
818 this_usbduxsub->dux_commands[2] = 0x80;
820 /* CONFIG3: differential channels off */
821 this_usbduxsub->dux_commands[3] = 0x00;
823 chan = CR_CHAN(insn->chanspec);
824 create_adc_command(chan, &muxsg0, &muxsg1);
826 this_usbduxsub->dux_commands[4] = muxsg0;
827 this_usbduxsub->dux_commands[5] = muxsg1;
828 this_usbduxsub->dux_commands[6] = sysred;
831 err = send_dux_commands(dev, SENDSINGLEAD);
833 up(&this_usbduxsub->sem);
837 for (i = 0; i < insn->n; i++) {
838 err = receive_dux_commands(dev, SENDSINGLEAD);
840 up(&this_usbduxsub->sem);
843 /* 32 bits big endian from the A/D converter */
844 one = be32_to_cpu(*((int32_t *)
845 ((this_usbduxsub->insnBuffer)+1)));
846 /* mask out the status byte */
847 one = one & 0x00ffffff;
848 /* turn it into an unsigned integer */
849 one = one ^ 0x00800000;
852 up(&this_usbduxsub->sem);
856 /************************************/
859 static int usbdux_ao_insn_read(struct comedi_device *dev,
860 struct comedi_subdevice *s,
861 struct comedi_insn *insn, unsigned int *data)
863 struct usbduxsigma_private *this_usbduxsub = dev->private;
865 int chan = CR_CHAN(insn->chanspec);
867 down(&this_usbduxsub->sem);
868 for (i = 0; i < insn->n; i++)
869 data[i] = this_usbduxsub->outBuffer[chan];
871 up(&this_usbduxsub->sem);
875 static int usbdux_ao_insn_write(struct comedi_device *dev,
876 struct comedi_subdevice *s,
877 struct comedi_insn *insn, unsigned int *data)
879 struct usbduxsigma_private *this_usbduxsub = dev->private;
881 int chan = CR_CHAN(insn->chanspec);
883 down(&this_usbduxsub->sem);
884 if (this_usbduxsub->ao_cmd_running) {
885 up(&this_usbduxsub->sem);
889 for (i = 0; i < insn->n; i++) {
890 /* number of channels: 1 */
891 this_usbduxsub->dux_commands[1] = 1;
893 this_usbduxsub->dux_commands[2] = data[i];
894 this_usbduxsub->outBuffer[chan] = data[i];
895 this_usbduxsub->dux_commands[3] = chan;
896 err = send_dux_commands(dev, SENDDACOMMANDS);
898 up(&this_usbduxsub->sem);
902 up(&this_usbduxsub->sem);
907 static int usbduxsigma_ao_inttrig(struct comedi_device *dev,
908 struct comedi_subdevice *s,
909 unsigned int trignum)
911 struct usbduxsigma_private *devpriv = dev->private;
918 if (!devpriv->ao_cmd_running) {
919 ret = usbduxsigma_submit_urbs(dev, devpriv->urbOut,
920 devpriv->numOfOutBuffers, 0);
925 devpriv->ao_cmd_running = 1;
926 s->async->inttrig = NULL;
933 static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
934 struct comedi_subdevice *s,
935 struct comedi_cmd *cmd)
937 struct usbduxsigma_private *devpriv = dev->private;
942 /* high speed conversions are not used yet */
943 high_speed = 0; /* (devpriv->high_speed) */
945 /* Step 1 : check if triggers are trivially valid */
947 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
951 * start immediately a new scan
952 * the sampling rate is set by the coversion rate
956 /* start a new scan (output at once) with a timer */
959 err |= cfc_check_trigger_src(&cmd->scan_begin_src, flags);
961 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
962 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
963 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
970 /* Step 2a : make sure trigger sources are unique */
972 err |= cfc_check_trigger_is_unique(cmd->start_src);
973 err |= cfc_check_trigger_is_unique(cmd->stop_src);
975 /* Step 2b : and mutually compatible */
980 /* Step 3: check if arguments are trivially valid */
982 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
984 if (cmd->scan_begin_src == TRIG_FOLLOW) /* internal trigger */
985 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
987 if (cmd->scan_begin_src == TRIG_TIMER)
988 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
991 /* not used now, is for later use */
992 if (cmd->convert_src == TRIG_TIMER)
993 err |= cfc_check_trigger_arg_min(&cmd->convert_arg, 125000);
995 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
997 if (cmd->stop_src == TRIG_COUNT) {
998 /* any count is allowed */
1001 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
1007 /* Step 4: fix up any arguments */
1009 /* we count in timer steps */
1011 /* timing of the conversion itself: every 125 us */
1012 devpriv->ao_timer = cmd->convert_arg / 125000;
1015 * timing of the scan: every 1ms
1016 * we get all channels at once
1018 devpriv->ao_timer = cmd->scan_begin_arg / 1000000;
1019 if (devpriv->ao_timer < 1)
1023 if (cmd->stop_src == TRIG_COUNT) {
1024 /* not continuous, use counter */
1026 /* high speed also scans everything at once */
1027 devpriv->ao_sample_count = cmd->stop_arg *
1031 * There's no scan as the scan has been
1032 * handled inside the FX2. Data arrives as
1035 devpriv->ao_sample_count = cmd->stop_arg;
1037 devpriv->ao_continuous = 0;
1039 /* continuous acquisition */
1040 devpriv->ao_continuous = 1;
1041 devpriv->ao_sample_count = 0;
1050 static int usbduxsigma_ao_cmd(struct comedi_device *dev,
1051 struct comedi_subdevice *s)
1053 struct usbduxsigma_private *devpriv = dev->private;
1054 struct comedi_cmd *cmd = &s->async->cmd;
1058 down(&devpriv->sem);
1060 /* set current channel of the running acquisition to zero */
1061 s->async->cur_chan = 0;
1062 for (i = 0; i < cmd->chanlist_len; ++i)
1063 devpriv->dac_commands[i] = CR_CHAN(cmd->chanlist[i]);
1065 devpriv->ao_counter = devpriv->ao_timer;
1067 if (cmd->start_src == TRIG_NOW) {
1068 /* enable this acquisition operation */
1069 ret = usbduxsigma_submit_urbs(dev, devpriv->urbOut,
1070 devpriv->numOfOutBuffers, 0);
1075 s->async->inttrig = NULL;
1076 devpriv->ao_cmd_running = 1;
1077 } else { /* TRIG_INT */
1078 /* wait for an internal signal and submit the urbs later */
1079 s->async->inttrig = usbduxsigma_ao_inttrig;
1087 static int usbduxsigma_dio_insn_config(struct comedi_device *dev,
1088 struct comedi_subdevice *s,
1089 struct comedi_insn *insn,
1092 unsigned int chan = CR_CHAN(insn->chanspec);
1093 unsigned int mask = 1 << chan;
1096 case INSN_CONFIG_DIO_OUTPUT:
1099 case INSN_CONFIG_DIO_INPUT:
1100 s->io_bits &= ~mask;
1102 case INSN_CONFIG_DIO_QUERY:
1103 data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
1111 * We don't tell the firmware here as it would take 8 frames
1112 * to submit the information. We do it in the (*insn_bits).
1117 static int usbduxsigma_dio_insn_bits(struct comedi_device *dev,
1118 struct comedi_subdevice *s,
1119 struct comedi_insn *insn,
1122 struct usbduxsigma_private *devpriv = dev->private;
1123 unsigned int mask = data[0];
1124 unsigned int bits = data[1];
1127 down(&devpriv->sem);
1130 s->state |= (bits & mask);
1132 devpriv->dux_commands[1] = s->io_bits & 0xff;
1133 devpriv->dux_commands[4] = s->state & 0xff;
1134 devpriv->dux_commands[2] = (s->io_bits >> 8) & 0xff;
1135 devpriv->dux_commands[5] = (s->state >> 8) & 0xff;
1136 devpriv->dux_commands[3] = (s->io_bits >> 16) & 0xff;
1137 devpriv->dux_commands[6] = (s->state >> 16) & 0xff;
1139 ret = send_dux_commands(dev, SENDDIOBITSCOMMAND);
1142 ret = receive_dux_commands(dev, SENDDIOBITSCOMMAND);
1146 s->state = devpriv->insnBuffer[1] |
1147 (devpriv->insnBuffer[2] << 8) |
1148 (devpriv->insnBuffer[3] << 16);
1159 static void usbduxsigma_pwm_stop(struct comedi_device *dev, int do_unlink)
1161 struct usbduxsigma_private *devpriv = dev->private;
1164 if (devpriv->urbPwm)
1165 usb_kill_urb(devpriv->urbPwm);
1168 devpriv->pwm_cmd_running = 0;
1171 static int usbduxsigma_pwm_cancel(struct comedi_device *dev,
1172 struct comedi_subdevice *s)
1174 struct usbduxsigma_private *devpriv = dev->private;
1176 /* unlink only if it is really running */
1177 usbduxsigma_pwm_stop(dev, devpriv->pwm_cmd_running);
1179 return send_dux_commands(dev, SENDPWMOFF);
1182 static void usbduxsigma_pwm_irq(struct urb *urb)
1184 struct comedi_device *dev = urb->context;
1185 struct usbduxsigma_private *devpriv = dev->private;
1188 switch (urb->status) {
1197 /* happens after an unlink command */
1198 if (devpriv->pwm_cmd_running)
1199 usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */
1204 if (devpriv->pwm_cmd_running) {
1205 dev_err(dev->class_dev,
1206 "%s: non-zero urb status (%d)\n",
1207 __func__, urb->status);
1208 usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */
1213 if (!devpriv->pwm_cmd_running)
1216 urb->transfer_buffer_length = devpriv->sizePwmBuf;
1217 urb->dev = comedi_to_usb_dev(dev);
1219 ret = usb_submit_urb(urb, GFP_ATOMIC);
1221 dev_err(dev->class_dev, "%s: urb resubmit failed (%d)\n",
1223 if (ret == EL2NSYNC)
1224 dev_err(dev->class_dev,
1225 "buggy USB host controller or bug in IRQ handler\n");
1226 usbduxsigma_pwm_stop(dev, 0); /* w/o unlink */
1230 static int usbduxsigma_submit_pwm_urb(struct comedi_device *dev)
1232 struct usb_device *usb = comedi_to_usb_dev(dev);
1233 struct usbduxsigma_private *devpriv = dev->private;
1234 struct urb *urb = devpriv->urbPwm;
1236 /* in case of a resubmission after an unlink... */
1237 usb_fill_bulk_urb(urb, usb, usb_sndbulkpipe(usb, PWM_EP),
1238 urb->transfer_buffer, devpriv->sizePwmBuf,
1239 usbduxsigma_pwm_irq, dev);
1241 return usb_submit_urb(urb, GFP_ATOMIC);
1244 static int usbduxsigma_pwm_period(struct comedi_device *dev,
1245 struct comedi_subdevice *s,
1246 unsigned int period)
1248 struct usbduxsigma_private *devpriv = dev->private;
1251 if (period < MIN_PWM_PERIOD) {
1254 fx2delay = (period / (6 * 512 * 1000 / 33)) - 6;
1258 devpriv->pwmDelay = fx2delay;
1259 devpriv->pwmPeriod = period;
1263 static int usbduxsigma_pwm_start(struct comedi_device *dev,
1264 struct comedi_subdevice *s)
1266 struct usbduxsigma_private *devpriv = dev->private;
1269 if (devpriv->pwm_cmd_running)
1272 devpriv->dux_commands[1] = devpriv->pwmDelay;
1273 ret = send_dux_commands(dev, SENDPWMON);
1277 memset(devpriv->urbPwm->transfer_buffer, 0, devpriv->sizePwmBuf);
1279 ret = usbduxsigma_submit_pwm_urb(dev);
1282 devpriv->pwm_cmd_running = 1;
1287 static int usbduxsigma_pwm_pattern(struct comedi_device *dev,
1288 struct comedi_subdevice *s,
1293 struct usbduxsigma_private *devpriv = dev->private;
1294 char pwm_mask = (1 << chan); /* DIO bit for the PWM data */
1295 char sgn_mask = (16 << chan); /* DIO bit for the sign */
1296 char *buf = (char *)(devpriv->urbPwm->transfer_buffer);
1297 int szbuf = devpriv->sizePwmBuf;
1300 for (i = 0; i < szbuf; i++) {
1315 static int usbduxsigma_pwm_write(struct comedi_device *dev,
1316 struct comedi_subdevice *s,
1317 struct comedi_insn *insn,
1320 unsigned int chan = CR_CHAN(insn->chanspec);
1323 * It doesn't make sense to support more than one value here
1324 * because it would just overwrite the PWM buffer.
1330 * The sign is set via a special INSN only, this gives us 8 bits
1331 * for normal operation, sign is 0 by default.
1333 return usbduxsigma_pwm_pattern(dev, s, chan, data[0], 0);
1336 static int usbduxsigma_pwm_config(struct comedi_device *dev,
1337 struct comedi_subdevice *s,
1338 struct comedi_insn *insn,
1341 struct usbduxsigma_private *devpriv = dev->private;
1342 unsigned int chan = CR_CHAN(insn->chanspec);
1345 case INSN_CONFIG_ARM:
1347 * if not zero the PWM is limited to a certain time which is
1348 * not supported here
1352 return usbduxsigma_pwm_start(dev, s);
1353 case INSN_CONFIG_DISARM:
1354 return usbduxsigma_pwm_cancel(dev, s);
1355 case INSN_CONFIG_GET_PWM_STATUS:
1356 data[1] = devpriv->pwm_cmd_running;
1358 case INSN_CONFIG_PWM_SET_PERIOD:
1359 return usbduxsigma_pwm_period(dev, s, data[1]);
1360 case INSN_CONFIG_PWM_GET_PERIOD:
1361 data[1] = devpriv->pwmPeriod;
1363 case INSN_CONFIG_PWM_SET_H_BRIDGE:
1366 * data[2] = sign (for a relay)
1368 return usbduxsigma_pwm_pattern(dev, s, chan,
1369 data[1], (data[2] != 0));
1370 case INSN_CONFIG_PWM_GET_H_BRIDGE:
1371 /* values are not kept in this driver, nothing to return */
1377 static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan)
1379 struct usbduxsigma_private *devpriv = dev->private;
1387 sysred = 0; /* ADC zero */
1390 sysred = 1; /* ADC offset */
1393 sysred = 4; /* VCC */
1396 sysred = 8; /* temperature */
1399 sysred = 16; /* gain */
1402 sysred = 32; /* ref */
1406 devpriv->dux_commands[1] = 0x12; /* CONFIG0 */
1407 devpriv->dux_commands[2] = 0x80; /* CONFIG1: 2kHz sampling rate */
1408 devpriv->dux_commands[3] = 0x00; /* CONFIG3: diff. channels off */
1409 devpriv->dux_commands[4] = 0;
1410 devpriv->dux_commands[5] = 0;
1411 devpriv->dux_commands[6] = sysred;
1412 ret = send_dux_commands(dev, SENDSINGLEAD);
1416 ret = receive_dux_commands(dev, SENDSINGLEAD);
1420 /* 32 bits big endian from the A/D converter */
1421 val = be32_to_cpu(*((int32_t *)((devpriv->insnBuffer)+1)));
1422 val &= 0x00ffffff; /* strip status byte */
1423 val ^= 0x00800000; /* convert to unsigned */
1428 static int usbduxsigma_attach_common(struct comedi_device *dev)
1430 struct usbduxsigma_private *devpriv = dev->private;
1431 struct comedi_subdevice *s;
1436 down(&devpriv->sem);
1438 if (devpriv->high_speed)
1439 n_subdevs = 4; /* with pwm */
1441 n_subdevs = 3; /* without pwm */
1442 ret = comedi_alloc_subdevices(dev, n_subdevs);
1448 /* Analog Input subdevice */
1449 s = &dev->subdevices[0];
1450 dev->read_subdev = s;
1451 s->type = COMEDI_SUBD_AI;
1452 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ | SDF_LSAMPL;
1453 s->n_chan = NUMCHANNELS;
1454 s->len_chanlist = NUMCHANNELS;
1455 s->maxdata = 0x00ffffff;
1456 s->range_table = &range_usbdux_ai_range;
1457 s->insn_read = usbdux_ai_insn_read;
1458 s->do_cmdtest = usbdux_ai_cmdtest;
1459 s->do_cmd = usbdux_ai_cmd;
1460 s->cancel = usbdux_ai_cancel;
1462 /* Analog Output subdevice */
1463 s = &dev->subdevices[1];
1464 dev->write_subdev = s;
1465 s->type = COMEDI_SUBD_AO;
1466 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE;
1468 s->len_chanlist = 4;
1469 s->maxdata = 0x00ff;
1470 s->range_table = &range_unipolar2_5;
1471 s->insn_write = usbdux_ao_insn_write;
1472 s->insn_read = usbdux_ao_insn_read;
1473 s->do_cmdtest = usbduxsigma_ao_cmdtest;
1474 s->do_cmd = usbduxsigma_ao_cmd;
1475 s->cancel = usbdux_ao_cancel;
1477 /* Digital I/O subdevice */
1478 s = &dev->subdevices[2];
1479 s->type = COMEDI_SUBD_DIO;
1480 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
1483 s->range_table = &range_digital;
1484 s->insn_bits = usbduxsigma_dio_insn_bits;
1485 s->insn_config = usbduxsigma_dio_insn_config;
1487 if (devpriv->high_speed) {
1488 /* Timer / pwm subdevice */
1489 s = &dev->subdevices[3];
1490 s->type = COMEDI_SUBD_PWM;
1491 s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE;
1493 s->maxdata = devpriv->sizePwmBuf;
1494 s->insn_write = usbduxsigma_pwm_write;
1495 s->insn_config = usbduxsigma_pwm_config;
1497 usbduxsigma_pwm_period(dev, s, PWM_DEFAULT_PERIOD);
1502 offset = usbduxsigma_getstatusinfo(dev, 0);
1504 dev_err(dev->class_dev,
1505 "Communication to USBDUXSIGMA failed! Check firmware and cabling\n");
1507 dev_info(dev->class_dev, "attached, ADC_zero = %x\n", offset);
1512 static int usbduxsigma_firmware_upload(struct comedi_device *dev,
1513 const u8 *data, size_t size,
1514 unsigned long context)
1516 struct usb_device *usb = comedi_to_usb_dev(dev);
1524 if (size > FIRMWARE_MAX_LEN) {
1525 dev_err(dev->class_dev, "firmware binary too large for FX2\n");
1529 /* we generate a local buffer for the firmware */
1530 buf = kmemdup(data, size, GFP_KERNEL);
1534 /* we need a malloc'ed buffer for usb_control_msg() */
1535 tmp = kmalloc(1, GFP_KERNEL);
1541 /* stop the current firmware on the device */
1542 *tmp = 1; /* 7f92 to one */
1543 ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
1546 USBDUXSUB_CPUCS, 0x0000,
1550 dev_err(dev->class_dev, "can not stop firmware\n");
1554 /* upload the new firmware to the device */
1555 ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
1562 dev_err(dev->class_dev, "firmware upload failed\n");
1566 /* start the new firmware on the device */
1567 *tmp = 0; /* 7f92 to zero */
1568 ret = usb_control_msg(usb, usb_sndctrlpipe(usb, 0),
1571 USBDUXSUB_CPUCS, 0x0000,
1575 dev_err(dev->class_dev, "can not start firmware\n");
1583 static int usbduxsigma_alloc_usb_buffers(struct comedi_device *dev)
1585 struct usb_device *usb = comedi_to_usb_dev(dev);
1586 struct usbduxsigma_private *devpriv = dev->private;
1590 devpriv->dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
1591 devpriv->dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
1592 devpriv->inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
1593 devpriv->insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
1594 devpriv->outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
1595 devpriv->urbIn = kcalloc(devpriv->numOfInBuffers, sizeof(*urb),
1597 devpriv->urbOut = kcalloc(devpriv->numOfOutBuffers, sizeof(*urb),
1599 if (!devpriv->dac_commands || !devpriv->dux_commands ||
1600 !devpriv->inBuffer || !devpriv->insnBuffer ||
1601 !devpriv->outBuffer || !devpriv->urbIn || !devpriv->urbOut)
1604 for (i = 0; i < devpriv->numOfInBuffers; i++) {
1605 /* one frame: 1ms */
1606 urb = usb_alloc_urb(1, GFP_KERNEL);
1609 devpriv->urbIn[i] = urb;
1611 /* will be filled later with a pointer to the comedi-device */
1612 /* and ONLY then the urb should be submitted */
1613 urb->context = NULL;
1614 urb->pipe = usb_rcvisocpipe(usb, ISOINEP);
1615 urb->transfer_flags = URB_ISO_ASAP;
1616 urb->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL);
1617 if (!urb->transfer_buffer)
1619 urb->complete = usbduxsub_ai_IsocIrq;
1620 urb->number_of_packets = 1;
1621 urb->transfer_buffer_length = SIZEINBUF;
1622 urb->iso_frame_desc[0].offset = 0;
1623 urb->iso_frame_desc[0].length = SIZEINBUF;
1626 for (i = 0; i < devpriv->numOfOutBuffers; i++) {
1627 /* one frame: 1ms */
1628 urb = usb_alloc_urb(1, GFP_KERNEL);
1631 devpriv->urbOut[i] = urb;
1633 /* will be filled later with a pointer to the comedi-device */
1634 /* and ONLY then the urb should be submitted */
1635 urb->context = NULL;
1636 urb->pipe = usb_sndisocpipe(usb, ISOOUTEP);
1637 urb->transfer_flags = URB_ISO_ASAP;
1638 urb->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
1639 if (!urb->transfer_buffer)
1641 urb->complete = usbduxsub_ao_IsocIrq;
1642 urb->number_of_packets = 1;
1643 urb->transfer_buffer_length = SIZEOUTBUF;
1644 urb->iso_frame_desc[0].offset = 0;
1645 urb->iso_frame_desc[0].length = SIZEOUTBUF;
1646 if (devpriv->high_speed)
1647 urb->interval = 8; /* uframes */
1649 urb->interval = 1; /* frames */
1652 if (devpriv->high_speed) {
1653 /* max bulk ep size in high speed */
1654 devpriv->sizePwmBuf = 512;
1655 urb = usb_alloc_urb(0, GFP_KERNEL);
1658 devpriv->urbPwm = urb;
1659 urb->transfer_buffer = kzalloc(devpriv->sizePwmBuf, GFP_KERNEL);
1660 if (!urb->transfer_buffer)
1663 devpriv->urbPwm = NULL;
1664 devpriv->sizePwmBuf = 0;
1670 static void usbduxsigma_free_usb_buffers(struct comedi_device *dev)
1672 struct usbduxsigma_private *devpriv = dev->private;
1676 /* force unlink all urbs */
1677 usbdux_ai_stop(devpriv, 1);
1678 usbdux_ao_stop(devpriv, 1);
1679 usbduxsigma_pwm_stop(dev, 1);
1681 urb = devpriv->urbPwm;
1683 kfree(urb->transfer_buffer);
1686 if (devpriv->urbOut) {
1687 for (i = 0; i < devpriv->numOfOutBuffers; i++) {
1688 urb = devpriv->urbOut[i];
1690 kfree(urb->transfer_buffer);
1694 kfree(devpriv->urbOut);
1696 if (devpriv->urbIn) {
1697 for (i = 0; i < devpriv->numOfInBuffers; i++) {
1698 urb = devpriv->urbIn[i];
1700 kfree(urb->transfer_buffer);
1704 kfree(devpriv->urbIn);
1706 kfree(devpriv->outBuffer);
1707 kfree(devpriv->insnBuffer);
1708 kfree(devpriv->inBuffer);
1709 kfree(devpriv->dux_commands);
1710 kfree(devpriv->dac_commands);
1713 static int usbduxsigma_auto_attach(struct comedi_device *dev,
1714 unsigned long context_unused)
1716 struct usb_interface *intf = comedi_to_usb_interface(dev);
1717 struct usb_device *usb = comedi_to_usb_dev(dev);
1718 struct usbduxsigma_private *devpriv;
1721 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
1724 dev->private = devpriv;
1726 sema_init(&devpriv->sem, 1);
1727 usb_set_intfdata(intf, devpriv);
1729 ret = usb_set_interface(usb,
1730 intf->altsetting->desc.bInterfaceNumber, 3);
1732 dev_err(dev->class_dev,
1733 "could not set alternate setting 3 in high speed\n");
1737 /* test if it is high speed (USB 2.0) */
1738 devpriv->high_speed = (usb->speed == USB_SPEED_HIGH);
1739 if (devpriv->high_speed) {
1740 devpriv->numOfInBuffers = NUMOFINBUFFERSHIGH;
1741 devpriv->numOfOutBuffers = NUMOFOUTBUFFERSHIGH;
1743 devpriv->numOfInBuffers = NUMOFINBUFFERSFULL;
1744 devpriv->numOfOutBuffers = NUMOFOUTBUFFERSFULL;
1747 ret = usbduxsigma_alloc_usb_buffers(dev);
1751 ret = comedi_load_firmware(dev, &usb->dev, FIRMWARE,
1752 usbduxsigma_firmware_upload, 0);
1756 return usbduxsigma_attach_common(dev);
1759 static void usbduxsigma_detach(struct comedi_device *dev)
1761 struct usb_interface *intf = comedi_to_usb_interface(dev);
1762 struct usbduxsigma_private *devpriv = dev->private;
1767 usb_set_intfdata(intf, NULL);
1769 down(&devpriv->sem);
1770 usbduxsigma_free_usb_buffers(dev);
1774 static struct comedi_driver usbduxsigma_driver = {
1775 .driver_name = "usbduxsigma",
1776 .module = THIS_MODULE,
1777 .auto_attach = usbduxsigma_auto_attach,
1778 .detach = usbduxsigma_detach,
1781 static int usbduxsigma_usb_probe(struct usb_interface *intf,
1782 const struct usb_device_id *id)
1784 return comedi_usb_auto_config(intf, &usbduxsigma_driver, 0);
1787 static const struct usb_device_id usbduxsigma_usb_table[] = {
1788 { USB_DEVICE(0x13d8, 0x0020) },
1789 { USB_DEVICE(0x13d8, 0x0021) },
1790 { USB_DEVICE(0x13d8, 0x0022) },
1793 MODULE_DEVICE_TABLE(usb, usbduxsigma_usb_table);
1795 static struct usb_driver usbduxsigma_usb_driver = {
1796 .name = "usbduxsigma",
1797 .probe = usbduxsigma_usb_probe,
1798 .disconnect = comedi_usb_auto_unconfig,
1799 .id_table = usbduxsigma_usb_table,
1801 module_comedi_usb_driver(usbduxsigma_driver, usbduxsigma_usb_driver);
1803 MODULE_AUTHOR("Bernd Porr, BerndPorr@f2s.com");
1804 MODULE_DESCRIPTION("Stirling/ITL USB-DUX SIGMA -- Bernd.Porr@f2s.com");
1805 MODULE_LICENSE("GPL");
1806 MODULE_FIRMWARE(FIRMWARE);