2 * Copyright (C) 2004 Bernd Porr, Bernd.Porr@f2s.com
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * I must give credit here to Chris Baugher who
21 * wrote the driver for AT-MIO-16d. I used some parts of this
22 * driver. I also must give credits to David Brownell
23 * who supported me with the USB development.
29 * 0.9: Dropping the first data packet which seems to be from the last transfer.
30 * Buffer overflows in the FX2 are handed over to comedi.
31 * 0.92: Dropping now 4 packets. The quad buffer has to be emptied.
32 * Added insn command basically for testing. Sample rate is
34 * 0.99: Ian Abbott pointed out a bug which has been corrected. Thanks!
35 * 0.99a: added external trigger.
36 * 1.00: added firmware kernel request to the driver which fixed
37 * udev coldplug problem
40 #include <linux/kernel.h>
41 #include <linux/firmware.h>
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/slab.h>
45 #include <linux/input.h>
46 #include <linux/usb.h>
47 #include <linux/fcntl.h>
48 #include <linux/compiler.h>
49 #include "comedi_fc.h"
50 #include "../comedidev.h"
53 * timeout for the USB-transfer
58 * constants for "firmware" upload and download
60 #define FIRMWARE "usbduxfast_firmware.bin"
61 #define USBDUXFASTSUB_FIRMWARE 0xA0
62 #define VENDOR_DIR_IN 0xC0
63 #define VENDOR_DIR_OUT 0x40
66 * internal addresses of the 8051 processor
68 #define USBDUXFASTSUB_CPUCS 0xE600
71 * max lenghth of the transfer-buffer for software upload
76 * input endpoint number
81 * endpoint for the A/D channellist: bulk OUT
83 #define CHANNELLISTEP 4
88 #define NUMCHANNELS 32
91 * size of the waveform descriptor
96 * size of one A/D value
98 #define SIZEADIN (sizeof(int16_t))
101 * size of the input-buffer IN BYTES
103 #define SIZEINBUF 512
108 #define SIZEINSNBUF 512
111 * size of the buffer for the dux commands in bytes
113 #define SIZEOFDUXBUFFER 256
116 * number of in-URBs which receive the data: min=5
118 #define NUMOFINBUFFERSHIGH 10
121 * total number of usbduxfast devices
123 #define NUMUSBDUXFAST 16
126 * analogue in subdevice
131 * min delay steps for more than one channel
132 * basically when the mux gives up ;-)
134 * steps at 30MHz in the FX2
136 #define MIN_SAMPLING_PERIOD 9
139 * max number of 1/30MHz delay steps
141 #define MAX_SAMPLING_PERIOD 500
144 * number of received packets to ignore before we start handing data
145 * over to comedi, it's quad buffering and we have to ignore 4 packets
147 #define PACKETS_TO_IGNORE 4
152 static const struct comedi_lrange range_usbduxfast_ai_range = {
153 2, {BIP_RANGE(0.75), BIP_RANGE(0.5)}
157 * private structure of one subdevice
159 * this is the structure which holds all the data of this driver
160 * one sub device just now: A/D
162 struct usbduxfastsub_s {
163 int attached; /* is attached? */
164 int probed; /* is it associated with a subdevice? */
165 struct usb_device *usbdev; /* pointer to the usb-device */
166 struct urb *urbIn; /* BULK-transfer handling: urb */
167 int8_t *transfer_buffer;
168 int16_t *insnBuffer; /* input buffer for single insn */
169 int ifnum; /* interface number */
170 struct usb_interface *interface; /* interface structure */
171 /* comedi device for the interrupt context */
172 struct comedi_device *comedidev;
173 short int ai_cmd_running; /* asynchronous command is running */
174 short int ai_continous; /* continous acquisition */
175 long int ai_sample_count; /* number of samples to acquire */
176 uint8_t *dux_commands; /* commands */
177 int ignore; /* counter which ignores the first
179 struct semaphore sem;
183 * The pointer to the private usb-data of the driver
184 * is also the private data for the comedi-device.
185 * This has to be global as the usb subsystem needs
186 * global variables. The other reason is that this
187 * structure must be there _before_ any comedi
188 * command is issued. The usb subsystem must be
189 * initialised before comedi can access it.
191 static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
193 static DEFINE_SEMAPHORE(start_stop_sem);
196 * bulk transfers to usbduxfast
198 #define SENDADCOMMANDS 0
199 #define SENDINITEP6 1
201 static int send_dux_commands(struct usbduxfastsub_s *udfs, int cmd_type)
205 udfs->dux_commands[0] = cmd_type;
207 #ifdef CONFIG_COMEDI_DEBUG
208 printk(KERN_DEBUG "comedi%d: usbduxfast: dux_commands: ",
209 udfs->comedidev->minor);
210 for (tmp = 0; tmp < SIZEOFDUXBUFFER; tmp++)
211 printk(" %02x", udfs->dux_commands[tmp]);
215 tmp = usb_bulk_msg(udfs->usbdev,
216 usb_sndbulkpipe(udfs->usbdev, CHANNELLISTEP),
217 udfs->dux_commands, SIZEOFDUXBUFFER, &nsent, 10000);
219 printk(KERN_ERR "comedi%d: could not transmit dux_commands to"
220 "the usb-device, err=%d\n", udfs->comedidev->minor, tmp);
225 * Stops the data acquision.
226 * It should be safe to call this function from any context.
228 static int usbduxfastsub_unlink_InURBs(struct usbduxfastsub_s *udfs)
233 if (udfs && udfs->urbIn) {
234 udfs->ai_cmd_running = 0;
235 /* waits until a running transfer is over */
236 usb_kill_urb(udfs->urbIn);
239 #ifdef CONFIG_COMEDI_DEBUG
240 printk(KERN_DEBUG "comedi: usbduxfast: unlinked InURB: res=%d\n", j);
246 * This will stop a running acquisition operation.
247 * Is called from within this driver from both the
248 * interrupt context and from comedi.
250 static int usbduxfast_ai_stop(struct usbduxfastsub_s *udfs, int do_unlink)
255 printk(KERN_ERR "comedi?: usbduxfast_ai_stop: udfs=NULL!\n");
258 #ifdef CONFIG_COMEDI_DEBUG
259 printk(KERN_DEBUG "comedi: usbduxfast_ai_stop\n");
262 udfs->ai_cmd_running = 0;
266 ret = usbduxfastsub_unlink_InURBs(udfs);
272 * This will cancel a running acquisition operation.
273 * This is called by comedi but never from inside the driver.
275 static int usbduxfast_ai_cancel(struct comedi_device *dev,
276 struct comedi_subdevice *s)
278 struct usbduxfastsub_s *udfs;
281 /* force unlink of all urbs */
282 #ifdef CONFIG_COMEDI_DEBUG
283 printk(KERN_DEBUG "comedi: usbduxfast_ai_cancel\n");
287 printk(KERN_ERR "comedi: usbduxfast_ai_cancel: udfs=NULL\n");
296 ret = usbduxfast_ai_stop(udfs, 1);
304 * interrupt service routine
306 static void usbduxfastsub_ai_Irq(struct urb *urb)
309 struct usbduxfastsub_s *udfs;
310 struct comedi_device *this_comedidev;
311 struct comedi_subdevice *s;
314 /* sanity checks - is the urb there? */
316 printk(KERN_ERR "comedi_: usbduxfast_: ao int-handler called "
320 /* the context variable points to the subdevice */
321 this_comedidev = urb->context;
322 if (!this_comedidev) {
323 printk(KERN_ERR "comedi_: usbduxfast_: urb context is a NULL "
327 /* the private structure of the subdevice is usbduxfastsub_s */
328 udfs = this_comedidev->private;
330 printk(KERN_ERR "comedi_: usbduxfast_: private of comedi "
331 "subdev is a NULL pointer!\n");
334 /* are we running a command? */
335 if (unlikely(!udfs->ai_cmd_running)) {
337 * not running a command
338 * do not continue execution if no asynchronous command
339 * is running in particular not resubmit
344 if (unlikely(!udfs->attached)) {
345 /* no comedi device there */
348 /* subdevice which is the AD converter */
349 s = this_comedidev->subdevices + SUBDEV_AD;
351 /* first we test if something unusual has just happened */
352 switch (urb->status) {
357 * happens after an unlink command or when the device
364 /* tell this comedi */
365 s->async->events |= COMEDI_CB_EOA;
366 s->async->events |= COMEDI_CB_ERROR;
367 comedi_event(udfs->comedidev, s);
368 /* stop the transfer w/o unlink */
369 usbduxfast_ai_stop(udfs, 0);
373 printk("comedi%d: usbduxfast: non-zero urb status received in "
374 "ai intr context: %d\n",
375 udfs->comedidev->minor, urb->status);
376 s->async->events |= COMEDI_CB_EOA;
377 s->async->events |= COMEDI_CB_ERROR;
378 comedi_event(udfs->comedidev, s);
379 usbduxfast_ai_stop(udfs, 0);
383 p = urb->transfer_buffer;
385 if (!udfs->ai_continous) {
386 /* not continuous, fixed number of samples */
387 n = urb->actual_length / sizeof(uint16_t);
388 if (unlikely(udfs->ai_sample_count < n)) {
390 * we have send only a fraction of the bytes
393 cfc_write_array_to_buffer(s,
394 urb->transfer_buffer,
395 udfs->ai_sample_count
397 usbduxfast_ai_stop(udfs, 0);
398 /* tell comedi that the acquistion is over */
399 s->async->events |= COMEDI_CB_EOA;
400 comedi_event(udfs->comedidev, s);
403 udfs->ai_sample_count -= n;
405 /* write the full buffer to comedi */
406 err = cfc_write_array_to_buffer(s, urb->transfer_buffer,
408 if (unlikely(err == 0)) {
409 /* buffer overflow */
410 usbduxfast_ai_stop(udfs, 0);
414 /* tell comedi that data is there */
415 comedi_event(udfs->comedidev, s);
418 /* ignore this packet */
423 * command is still running
424 * resubmit urb for BULK transfer
426 urb->dev = udfs->usbdev;
428 err = usb_submit_urb(urb, GFP_ATOMIC);
430 printk(KERN_ERR "comedi%d: usbduxfast: urb resubm failed: %d",
431 udfs->comedidev->minor, err);
432 s->async->events |= COMEDI_CB_EOA;
433 s->async->events |= COMEDI_CB_ERROR;
434 comedi_event(udfs->comedidev, s);
435 usbduxfast_ai_stop(udfs, 0);
439 static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
442 unsigned char local_transfer_buffer[16];
445 local_transfer_buffer[0] = 0;
446 /* bRequest, "Firmware" */
447 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
448 USBDUXFASTSUB_FIRMWARE,
449 VENDOR_DIR_OUT, /* bmRequestType */
450 USBDUXFASTSUB_CPUCS, /* Value */
452 /* address of the transfer buffer */
453 local_transfer_buffer,
455 EZTIMEOUT); /* Timeout */
457 printk("comedi_: usbduxfast_: control msg failed (start)\n");
464 static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
467 unsigned char local_transfer_buffer[16];
470 local_transfer_buffer[0] = 1;
471 /* bRequest, "Firmware" */
472 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
473 USBDUXFASTSUB_FIRMWARE,
474 VENDOR_DIR_OUT, /* bmRequestType */
475 USBDUXFASTSUB_CPUCS, /* Value */
477 local_transfer_buffer, 1, /* Length */
478 EZTIMEOUT); /* Timeout */
480 printk(KERN_ERR "comedi_: usbduxfast: control msg failed "
488 static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs,
489 unsigned char *local_transfer_buffer,
490 unsigned int startAddr, unsigned int len)
494 #ifdef CONFIG_COMEDI_DEBUG
495 printk(KERN_DEBUG "comedi: usbduxfast: uploading %d bytes", len);
496 printk(KERN_DEBUG " to addr %d, first byte=%d.\n",
497 startAddr, local_transfer_buffer[0]);
499 /* brequest, firmware */
500 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
501 USBDUXFASTSUB_FIRMWARE,
502 VENDOR_DIR_OUT, /* bmRequestType */
503 startAddr, /* value */
505 /* our local safe buffer */
506 local_transfer_buffer,
508 EZTIMEOUT); /* timeout */
510 #ifdef CONFIG_COMEDI_DEBUG
511 printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret);
515 printk(KERN_ERR "comedi_: usbduxfast: uppload failed\n");
522 static int usbduxfastsub_submit_InURBs(struct usbduxfastsub_s *udfs)
529 usb_fill_bulk_urb(udfs->urbIn, udfs->usbdev,
530 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
531 udfs->transfer_buffer,
532 SIZEINBUF, usbduxfastsub_ai_Irq, udfs->comedidev);
534 #ifdef CONFIG_COMEDI_DEBUG
535 printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
536 "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
539 ret = usb_submit_urb(udfs->urbIn, GFP_ATOMIC);
541 printk(KERN_ERR "comedi_: usbduxfast: ai: usb_submit_urb error"
548 static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
549 struct comedi_subdevice *s,
550 struct comedi_cmd *cmd)
552 int err = 0, stop_mask = 0;
555 struct usbduxfastsub_s *udfs = dev->private;
560 #ifdef CONFIG_COMEDI_DEBUG
561 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmdtest\n", dev->minor);
562 printk(KERN_DEBUG "comedi%d: usbduxfast: convert_arg=%u "
563 "scan_begin_arg=%u\n",
564 dev->minor, cmd->convert_arg, cmd->scan_begin_arg);
566 /* step 1: make sure trigger sources are trivially valid */
568 tmp = cmd->start_src;
569 cmd->start_src &= TRIG_NOW | TRIG_EXT | TRIG_INT;
570 if (!cmd->start_src || tmp != cmd->start_src)
573 tmp = cmd->scan_begin_src;
574 cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT;
575 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
578 tmp = cmd->convert_src;
579 cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
580 if (!cmd->convert_src || tmp != cmd->convert_src)
583 tmp = cmd->scan_end_src;
584 cmd->scan_end_src &= TRIG_COUNT;
585 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
589 stop_mask = TRIG_COUNT | TRIG_NONE;
590 cmd->stop_src &= stop_mask;
591 if (!cmd->stop_src || tmp != cmd->stop_src)
598 * step 2: make sure trigger sources are unique and mutually compatible
601 if (cmd->start_src != TRIG_NOW &&
602 cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT)
604 if (cmd->scan_begin_src != TRIG_TIMER &&
605 cmd->scan_begin_src != TRIG_FOLLOW &&
606 cmd->scan_begin_src != TRIG_EXT)
608 if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
610 if (cmd->stop_src != TRIG_COUNT &&
611 cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE)
614 /* can't have external stop and start triggers at once */
615 if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
621 /* step 3: make sure arguments are trivially compatible */
623 if (cmd->start_src == TRIG_NOW && cmd->start_arg != 0) {
628 if (!cmd->chanlist_len)
631 if (cmd->scan_end_arg != cmd->chanlist_len) {
632 cmd->scan_end_arg = cmd->chanlist_len;
636 if (cmd->chanlist_len == 1)
639 minSamplPer = MIN_SAMPLING_PERIOD;
641 if (cmd->convert_src == TRIG_TIMER) {
642 steps = cmd->convert_arg * 30;
643 if (steps < (minSamplPer * 1000))
644 steps = minSamplPer * 1000;
646 if (steps > (MAX_SAMPLING_PERIOD * 1000))
647 steps = MAX_SAMPLING_PERIOD * 1000;
651 if (cmd->convert_arg != tmp) {
652 cmd->convert_arg = tmp;
657 if (cmd->scan_begin_src == TRIG_TIMER)
661 switch (cmd->stop_src) {
663 if (!cmd->stop_arg) {
669 if (cmd->stop_arg != 0) {
675 * TRIG_EXT doesn't care since it doesn't trigger
676 * off a numbered channel
685 /* step 4: fix up any arguments */
691 static int usbduxfast_ai_inttrig(struct comedi_device *dev,
692 struct comedi_subdevice *s,
693 unsigned int trignum)
696 struct usbduxfastsub_s *udfs = dev->private;
706 #ifdef CONFIG_COMEDI_DEBUG
707 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_inttrig\n", dev->minor);
711 printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: invalid"
712 " trignum\n", dev->minor);
716 if (!udfs->ai_cmd_running) {
717 udfs->ai_cmd_running = 1;
718 ret = usbduxfastsub_submit_InURBs(udfs);
720 printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: "
721 "urbSubmit: err=%d\n", dev->minor, ret);
722 udfs->ai_cmd_running = 0;
726 s->async->inttrig = NULL;
728 printk(KERN_ERR "comedi%d: ai_inttrig but acqu is already"
729 " running\n", dev->minor);
736 * offsets for the GPIF bytes
737 * the first byte is the command byte
739 #define LENBASE (1+0x00)
740 #define OPBASE (1+0x08)
741 #define OUTBASE (1+0x10)
742 #define LOGBASE (1+0x18)
744 static int usbduxfast_ai_cmd(struct comedi_device *dev,
745 struct comedi_subdevice *s)
747 struct comedi_cmd *cmd = &s->async->cmd;
748 unsigned int chan, gain, rngmask = 0xff;
750 struct usbduxfastsub_s *udfs;
752 long steps, steps_tmp;
754 #ifdef CONFIG_COMEDI_DEBUG
755 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmd\n", dev->minor);
766 if (udfs->ai_cmd_running) {
767 printk(KERN_ERR "comedi%d: ai_cmd not possible. Another ai_cmd"
768 " is running.\n", dev->minor);
772 /* set current channel of the running acquisition to zero */
773 s->async->cur_chan = 0;
776 * ignore the first buffers from the device if there
777 * is an error condition
779 udfs->ignore = PACKETS_TO_IGNORE;
781 if (cmd->chanlist_len > 0) {
782 gain = CR_RANGE(cmd->chanlist[0]);
783 for (i = 0; i < cmd->chanlist_len; ++i) {
784 chan = CR_CHAN(cmd->chanlist[i]);
786 printk(KERN_ERR "comedi%d: cmd is accepting "
787 "only consecutive channels.\n",
792 if ((gain != CR_RANGE(cmd->chanlist[i]))
793 && (cmd->chanlist_len > 3)) {
794 printk(KERN_ERR "comedi%d: the gain must be"
795 " the same for all channels.\n",
800 if (i >= NUMCHANNELS) {
801 printk(KERN_ERR "comedi%d: channel list too"
802 " long\n", dev->minor);
808 if (cmd->scan_begin_src == TRIG_TIMER) {
809 printk(KERN_ERR "comedi%d: usbduxfast: "
810 "scan_begin_src==TRIG_TIMER not valid.\n", dev->minor);
814 if (cmd->convert_src == TRIG_TIMER)
815 steps = (cmd->convert_arg * 30) / 1000;
817 if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) {
818 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: steps=%ld, "
819 "scan_begin_arg=%d. Not properly tested by cmdtest?\n",
820 dev->minor, steps, cmd->scan_begin_arg);
824 if (steps > MAX_SAMPLING_PERIOD) {
825 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: sampling rate "
826 "too low.\n", dev->minor);
830 if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1)
831 && (cmd->chanlist_len != 16)) {
832 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: TRIG_EXT only"
833 " with 1 or 16 channels possible.\n", dev->minor);
837 #ifdef CONFIG_COMEDI_DEBUG
838 printk(KERN_DEBUG "comedi%d: usbduxfast: steps=%ld, convert_arg=%u\n",
839 dev->minor, steps, cmd->convert_arg);
842 switch (cmd->chanlist_len) {
848 if (CR_RANGE(cmd->chanlist[0]) > 0)
849 rngmask = 0xff - 0x04;
854 * for external trigger: looping in this state until
855 * the RDY0 pin becomes zero
858 /* we loop here until ready has been set */
859 if (cmd->start_src == TRIG_EXT) {
860 /* branch back to state 0 */
861 udfs->dux_commands[LENBASE + 0] = 0x01;
862 /* deceision state w/o data */
863 udfs->dux_commands[OPBASE + 0] = 0x01;
864 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
866 udfs->dux_commands[LOGBASE + 0] = 0x00;
867 } else { /* we just proceed to state 1 */
868 udfs->dux_commands[LENBASE + 0] = 1;
869 udfs->dux_commands[OPBASE + 0] = 0;
870 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
871 udfs->dux_commands[LOGBASE + 0] = 0;
874 if (steps < MIN_SAMPLING_PERIOD) {
875 /* for fast single channel aqu without mux */
878 * we just stay here at state 1 and rexecute
879 * the same state this gives us 30MHz sampling
883 /* branch back to state 1 */
884 udfs->dux_commands[LENBASE + 1] = 0x89;
885 /* deceision state with data */
886 udfs->dux_commands[OPBASE + 1] = 0x03;
887 udfs->dux_commands[OUTBASE + 1] =
890 udfs->dux_commands[LOGBASE + 1] = 0xFF;
893 * we loop through two states: data and delay
896 udfs->dux_commands[LENBASE + 1] = steps - 1;
898 udfs->dux_commands[OPBASE + 1] = 0x02;
899 udfs->dux_commands[OUTBASE + 1] =
902 udfs->dux_commands[LOGBASE + 1] = 0;
903 /* branch back to state 1 */
904 udfs->dux_commands[LENBASE + 2] = 0x09;
905 /* deceision state w/o data */
906 udfs->dux_commands[OPBASE + 2] = 0x01;
907 udfs->dux_commands[OUTBASE + 2] =
910 udfs->dux_commands[LOGBASE + 2] = 0xFF;
914 * we loop through 3 states: 2x delay and 1x data
915 * this gives a min sampling rate of 60kHz
918 /* we have 1 state with duration 1 */
921 /* do the first part of the delay */
922 udfs->dux_commands[LENBASE + 1] = steps / 2;
923 udfs->dux_commands[OPBASE + 1] = 0;
924 udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask;
925 udfs->dux_commands[LOGBASE + 1] = 0;
927 /* and the second part */
928 udfs->dux_commands[LENBASE + 2] = steps - steps / 2;
929 udfs->dux_commands[OPBASE + 2] = 0;
930 udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask;
931 udfs->dux_commands[LOGBASE + 2] = 0;
933 /* get the data and branch back */
935 /* branch back to state 1 */
936 udfs->dux_commands[LENBASE + 3] = 0x09;
937 /* deceision state w data */
938 udfs->dux_commands[OPBASE + 3] = 0x03;
939 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
941 udfs->dux_commands[LOGBASE + 3] = 0xFF;
948 * commit data to the FIFO
951 if (CR_RANGE(cmd->chanlist[0]) > 0)
952 rngmask = 0xff - 0x04;
956 udfs->dux_commands[LENBASE + 0] = 1;
958 udfs->dux_commands[OPBASE + 0] = 0x02;
959 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
960 udfs->dux_commands[LOGBASE + 0] = 0;
962 /* we have 1 state with duration 1: state 0 */
963 steps_tmp = steps - 1;
965 if (CR_RANGE(cmd->chanlist[1]) > 0)
966 rngmask = 0xff - 0x04;
970 /* do the first part of the delay */
971 udfs->dux_commands[LENBASE + 1] = steps_tmp / 2;
972 udfs->dux_commands[OPBASE + 1] = 0;
974 udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask;
975 udfs->dux_commands[LOGBASE + 1] = 0;
977 /* and the second part */
978 udfs->dux_commands[LENBASE + 2] = steps_tmp - steps_tmp / 2;
979 udfs->dux_commands[OPBASE + 2] = 0;
980 udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask;
981 udfs->dux_commands[LOGBASE + 2] = 0;
983 udfs->dux_commands[LENBASE + 3] = 1;
985 udfs->dux_commands[OPBASE + 3] = 0x02;
986 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
987 udfs->dux_commands[LOGBASE + 3] = 0;
990 * we have 2 states with duration 1: step 6 and
993 steps_tmp = steps - 2;
995 if (CR_RANGE(cmd->chanlist[0]) > 0)
996 rngmask = 0xff - 0x04;
1000 /* do the first part of the delay */
1001 udfs->dux_commands[LENBASE + 4] = steps_tmp / 2;
1002 udfs->dux_commands[OPBASE + 4] = 0;
1004 udfs->dux_commands[OUTBASE + 4] = (0xFF - 0x02) & rngmask;
1005 udfs->dux_commands[LOGBASE + 4] = 0;
1007 /* and the second part */
1008 udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2;
1009 udfs->dux_commands[OPBASE + 5] = 0;
1010 udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask;
1011 udfs->dux_commands[LOGBASE + 5] = 0;
1013 udfs->dux_commands[LENBASE + 6] = 1;
1014 udfs->dux_commands[OPBASE + 6] = 0;
1015 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1016 udfs->dux_commands[LOGBASE + 6] = 0;
1023 for (j = 0; j < 1; j++) {
1024 if (CR_RANGE(cmd->chanlist[j]) > 0)
1025 rngmask = 0xff - 0x04;
1029 * commit data to the FIFO and do the first part
1032 udfs->dux_commands[LENBASE + j * 2] = steps / 2;
1034 udfs->dux_commands[OPBASE + j * 2] = 0x02;
1036 udfs->dux_commands[OUTBASE + j * 2] = 0xFF & rngmask;
1037 udfs->dux_commands[LOGBASE + j * 2] = 0;
1039 if (CR_RANGE(cmd->chanlist[j + 1]) > 0)
1040 rngmask = 0xff - 0x04;
1044 /* do the second part of the delay */
1045 udfs->dux_commands[LENBASE + j * 2 + 1] =
1048 udfs->dux_commands[OPBASE + j * 2 + 1] = 0;
1050 udfs->dux_commands[OUTBASE + j * 2 + 1] =
1052 udfs->dux_commands[LOGBASE + j * 2 + 1] = 0;
1055 /* 2 steps with duration 1: the idele step and step 6: */
1056 steps_tmp = steps - 2;
1058 /* commit data to the FIFO and do the first part of the delay */
1059 udfs->dux_commands[LENBASE + 4] = steps_tmp / 2;
1061 udfs->dux_commands[OPBASE + 4] = 0x02;
1062 udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask;
1063 udfs->dux_commands[LOGBASE + 4] = 0;
1065 if (CR_RANGE(cmd->chanlist[0]) > 0)
1066 rngmask = 0xff - 0x04;
1070 /* do the second part of the delay */
1071 udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2;
1073 udfs->dux_commands[OPBASE + 5] = 0;
1075 udfs->dux_commands[OUTBASE + 5] = (0xFF - 0x02) & rngmask;
1076 udfs->dux_commands[LOGBASE + 5] = 0;
1078 udfs->dux_commands[LENBASE + 6] = 1;
1079 udfs->dux_commands[OPBASE + 6] = 0;
1080 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1081 udfs->dux_commands[LOGBASE + 6] = 0;
1084 if (CR_RANGE(cmd->chanlist[0]) > 0)
1085 rngmask = 0xff - 0x04;
1089 if (cmd->start_src == TRIG_EXT) {
1091 * we loop here until ready has been set
1094 /* branch back to state 0 */
1095 udfs->dux_commands[LENBASE + 0] = 0x01;
1096 /* deceision state w/o data */
1097 udfs->dux_commands[OPBASE + 0] = 0x01;
1099 udfs->dux_commands[OUTBASE + 0] =
1100 (0xFF - 0x02) & rngmask;
1102 udfs->dux_commands[LOGBASE + 0] = 0x00;
1105 * we just proceed to state 1
1108 /* 30us reset pulse */
1109 udfs->dux_commands[LENBASE + 0] = 255;
1110 udfs->dux_commands[OPBASE + 0] = 0;
1112 udfs->dux_commands[OUTBASE + 0] =
1113 (0xFF - 0x02) & rngmask;
1114 udfs->dux_commands[LOGBASE + 0] = 0;
1117 /* commit data to the FIFO */
1118 udfs->dux_commands[LENBASE + 1] = 1;
1120 udfs->dux_commands[OPBASE + 1] = 0x02;
1121 udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask;
1122 udfs->dux_commands[LOGBASE + 1] = 0;
1124 /* we have 2 states with duration 1 */
1127 /* do the first part of the delay */
1128 udfs->dux_commands[LENBASE + 2] = steps / 2;
1129 udfs->dux_commands[OPBASE + 2] = 0;
1130 udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask;
1131 udfs->dux_commands[LOGBASE + 2] = 0;
1133 /* and the second part */
1134 udfs->dux_commands[LENBASE + 3] = steps - steps / 2;
1135 udfs->dux_commands[OPBASE + 3] = 0;
1136 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
1137 udfs->dux_commands[LOGBASE + 3] = 0;
1139 /* branch back to state 1 */
1140 udfs->dux_commands[LENBASE + 4] = 0x09;
1141 /* deceision state w/o data */
1142 udfs->dux_commands[OPBASE + 4] = 0x01;
1143 udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask;
1144 /* doesn't matter */
1145 udfs->dux_commands[LOGBASE + 4] = 0xFF;
1150 printk(KERN_ERR "comedi %d: unsupported combination of "
1151 "channels\n", dev->minor);
1156 #ifdef CONFIG_COMEDI_DEBUG
1157 printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
1160 /* 0 means that the AD commands are sent */
1161 result = send_dux_commands(udfs, SENDADCOMMANDS);
1163 printk(KERN_ERR "comedi%d: adc command could not be submitted."
1164 "Aborting...\n", dev->minor);
1168 if (cmd->stop_src == TRIG_COUNT) {
1169 udfs->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg;
1170 if (udfs->ai_sample_count < 1) {
1171 printk(KERN_ERR "comedi%d: "
1172 "(cmd->stop_arg)*(cmd->scan_end_arg)<1, "
1173 "aborting.\n", dev->minor);
1177 udfs->ai_continous = 0;
1179 /* continous acquisition */
1180 udfs->ai_continous = 1;
1181 udfs->ai_sample_count = 0;
1184 if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
1185 /* enable this acquisition operation */
1186 udfs->ai_cmd_running = 1;
1187 ret = usbduxfastsub_submit_InURBs(udfs);
1189 udfs->ai_cmd_running = 0;
1190 /* fixme: unlink here?? */
1194 s->async->inttrig = NULL;
1198 * don't enable the acquision operation
1199 * wait for an internal signal
1201 s->async->inttrig = usbduxfast_ai_inttrig;
1209 * Mode 0 is used to get a single conversion on demand.
1211 static int usbduxfast_ai_insn_read(struct comedi_device *dev,
1212 struct comedi_subdevice *s,
1213 struct comedi_insn *insn, unsigned int *data)
1215 int i, j, n, actual_length;
1216 int chan, range, rngmask;
1218 struct usbduxfastsub_s *udfs;
1220 udfs = dev->private;
1222 printk(KERN_ERR "comedi%d: ai_insn_read: no usb dev.\n",
1226 #ifdef CONFIG_COMEDI_DEBUG
1227 printk(KERN_DEBUG "comedi%d: ai_insn_read, insn->n=%d, "
1228 "insn->subdev=%d\n", dev->minor, insn->n, insn->subdev);
1231 if (!udfs->probed) {
1235 if (udfs->ai_cmd_running) {
1236 printk(KERN_ERR "comedi%d: ai_insn_read not possible. Async "
1237 "Command is running.\n", dev->minor);
1241 /* sample one channel */
1242 chan = CR_CHAN(insn->chanspec);
1243 range = CR_RANGE(insn->chanspec);
1244 /* set command for the first channel */
1247 rngmask = 0xff - 0x04;
1251 /* commit data to the FIFO */
1252 udfs->dux_commands[LENBASE + 0] = 1;
1254 udfs->dux_commands[OPBASE + 0] = 0x02;
1255 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
1256 udfs->dux_commands[LOGBASE + 0] = 0;
1258 /* do the first part of the delay */
1259 udfs->dux_commands[LENBASE + 1] = 12;
1260 udfs->dux_commands[OPBASE + 1] = 0;
1261 udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask;
1262 udfs->dux_commands[LOGBASE + 1] = 0;
1264 udfs->dux_commands[LENBASE + 2] = 1;
1265 udfs->dux_commands[OPBASE + 2] = 0;
1266 udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask;
1267 udfs->dux_commands[LOGBASE + 2] = 0;
1269 udfs->dux_commands[LENBASE + 3] = 1;
1270 udfs->dux_commands[OPBASE + 3] = 0;
1271 udfs->dux_commands[OUTBASE + 3] = 0xFE & rngmask;
1272 udfs->dux_commands[LOGBASE + 3] = 0;
1274 udfs->dux_commands[LENBASE + 4] = 1;
1275 udfs->dux_commands[OPBASE + 4] = 0;
1276 udfs->dux_commands[OUTBASE + 4] = 0xFE & rngmask;
1277 udfs->dux_commands[LOGBASE + 4] = 0;
1280 udfs->dux_commands[LENBASE + 5] = 12;
1281 udfs->dux_commands[OPBASE + 5] = 0;
1282 udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask;
1283 udfs->dux_commands[LOGBASE + 5] = 0;
1285 udfs->dux_commands[LENBASE + 6] = 1;
1286 udfs->dux_commands[OPBASE + 6] = 0;
1287 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1288 udfs->dux_commands[LOGBASE + 0] = 0;
1290 #ifdef CONFIG_COMEDI_DEBUG
1291 printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
1294 /* 0 means that the AD commands are sent */
1295 err = send_dux_commands(udfs, SENDADCOMMANDS);
1297 printk(KERN_ERR "comedi%d: adc command could not be submitted."
1298 "Aborting...\n", dev->minor);
1302 #ifdef CONFIG_COMEDI_DEBUG
1303 printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
1304 "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
1307 for (i = 0; i < PACKETS_TO_IGNORE; i++) {
1308 err = usb_bulk_msg(udfs->usbdev,
1309 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
1310 udfs->transfer_buffer, SIZEINBUF,
1311 &actual_length, 10000);
1313 printk(KERN_ERR "comedi%d: insn timeout. No data.\n",
1320 for (i = 0; i < insn->n;) {
1321 err = usb_bulk_msg(udfs->usbdev,
1322 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
1323 udfs->transfer_buffer, SIZEINBUF,
1324 &actual_length, 10000);
1326 printk(KERN_ERR "comedi%d: insn data error: %d\n",
1331 n = actual_length / sizeof(uint16_t);
1332 if ((n % 16) != 0) {
1333 printk(KERN_ERR "comedi%d: insn data packet "
1334 "corrupted.\n", dev->minor);
1338 for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
1339 data[i] = ((uint16_t *) (udfs->transfer_buffer))[j];
1347 #define FIRMWARE_MAX_LEN 0x2000
1349 static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub,
1350 const u8 *firmwareBinary, int sizeFirmware)
1355 if (!firmwareBinary)
1358 if (sizeFirmware > FIRMWARE_MAX_LEN) {
1359 dev_err(&usbduxfastsub->interface->dev,
1360 "comedi_: usbduxfast firmware binary it too large for FX2.\n");
1364 /* we generate a local buffer for the firmware */
1365 fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
1367 dev_err(&usbduxfastsub->interface->dev,
1368 "comedi_: mem alloc for firmware failed\n");
1372 ret = usbduxfastsub_stop(usbduxfastsub);
1374 dev_err(&usbduxfastsub->interface->dev,
1375 "comedi_: can not stop firmware\n");
1380 ret = usbduxfastsub_upload(usbduxfastsub, fwBuf, 0, sizeFirmware);
1382 dev_err(&usbduxfastsub->interface->dev,
1383 "comedi_: firmware upload failed\n");
1387 ret = usbduxfastsub_start(usbduxfastsub);
1389 dev_err(&usbduxfastsub->interface->dev,
1390 "comedi_: can not start firmware\n");
1398 static void tidy_up(struct usbduxfastsub_s *udfs)
1400 #ifdef CONFIG_COMEDI_DEBUG
1401 printk(KERN_DEBUG "comedi_: usbduxfast: tiding up\n");
1407 /* shows the usb subsystem that the driver is down */
1408 if (udfs->interface)
1409 usb_set_intfdata(udfs->interface, NULL);
1414 /* waits until a running transfer is over */
1415 usb_kill_urb(udfs->urbIn);
1417 kfree(udfs->transfer_buffer);
1418 udfs->transfer_buffer = NULL;
1420 usb_free_urb(udfs->urbIn);
1424 kfree(udfs->insnBuffer);
1425 udfs->insnBuffer = NULL;
1427 kfree(udfs->dux_commands);
1428 udfs->dux_commands = NULL;
1430 udfs->ai_cmd_running = 0;
1433 /* common part of attach and attach_usb */
1434 static int usbduxfast_attach_common(struct comedi_device *dev,
1435 struct usbduxfastsub_s *udfs,
1436 void *aux_data, int aux_len)
1439 struct comedi_subdevice *s;
1442 /* pointer back to the corresponding comedi device */
1443 udfs->comedidev = dev;
1444 /* trying to upload the firmware into the chip */
1446 firmwareUpload(udfs, aux_data, aux_len);
1447 dev->board_name = "usbduxfast";
1448 ret = comedi_alloc_subdevices(dev, 1);
1453 /* private structure is also simply the usb-structure */
1454 dev->private = udfs;
1455 /* the first subdevice is the A/D converter */
1456 s = dev->subdevices + SUBDEV_AD;
1458 * the URBs get the comedi subdevice which is responsible for reading
1459 * this is the subdevice which reads data
1461 dev->read_subdev = s;
1462 /* the subdevice receives as private structure the usb-structure */
1465 s->type = COMEDI_SUBD_AI;
1466 /* readable and ref is to ground */
1467 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
1470 /* length of the channellist */
1471 s->len_chanlist = 16;
1472 /* callback functions */
1473 s->insn_read = usbduxfast_ai_insn_read;
1474 s->do_cmdtest = usbduxfast_ai_cmdtest;
1475 s->do_cmd = usbduxfast_ai_cmd;
1476 s->cancel = usbduxfast_ai_cancel;
1477 /* max value from the A/D converter (12bit+1 bit for overflow) */
1478 s->maxdata = 0x1000;
1479 /* range table to convert to physical units */
1480 s->range_table = &range_usbduxfast_ai_range;
1481 /* finally decide that it's attached */
1484 dev_info(dev->class_dev, "successfully attached to usbduxfast.\n");
1488 /* is called for COMEDI_DEVCONFIG ioctl (when comedi_config is run) */
1489 static int usbduxfast_attach(struct comedi_device *dev,
1490 struct comedi_devconfig *it)
1498 dev->private = NULL;
1500 aux_data = comedi_aux_data(it->options, 0);
1501 aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH];
1502 if (aux_data == NULL)
1504 else if (aux_len == 0)
1506 down(&start_stop_sem);
1508 * find a valid device which has been detected by the
1509 * probe function of the usb
1512 for (i = 0; i < NUMUSBDUXFAST; i++) {
1513 if (usbduxfastsub[i].probed && !usbduxfastsub[i].attached) {
1519 dev_err(dev->class_dev,
1520 "usbduxfast: error: attach failed, no usbduxfast devs connected to the usb bus.\n");
1523 ret = usbduxfast_attach_common(dev, &usbduxfastsub[index],
1525 up(&start_stop_sem);
1529 /* is called from comedi_usb_auto_config() */
1530 static int usbduxfast_attach_usb(struct comedi_device *dev,
1531 struct usb_interface *uinterf)
1534 struct usbduxfastsub_s *udfs;
1536 dev->private = NULL;
1537 down(&start_stop_sem);
1538 udfs = usb_get_intfdata(uinterf);
1539 if (!udfs || !udfs->probed) {
1540 dev_err(dev->class_dev,
1541 "usbduxfast: error: attach_usb failed, not connected\n");
1543 } else if (udfs->attached) {
1544 dev_err(dev->class_dev,
1545 "usbduxfast: error: attach_usb failed, already attached\n");
1548 ret = usbduxfast_attach_common(dev, udfs, NULL, 0);
1549 up(&start_stop_sem);
1553 static void usbduxfast_detach(struct comedi_device *dev)
1555 struct usbduxfastsub_s *usb = dev->private;
1559 down(&start_stop_sem);
1560 dev->private = NULL;
1562 usb->comedidev = NULL;
1563 up(&start_stop_sem);
1568 static struct comedi_driver usbduxfast_driver = {
1569 .driver_name = "usbduxfast",
1570 .module = THIS_MODULE,
1571 .attach = usbduxfast_attach,
1572 .detach = usbduxfast_detach,
1573 .attach_usb = usbduxfast_attach_usb,
1576 static void usbduxfast_firmware_request_complete_handler(const struct firmware
1579 struct usbduxfastsub_s *usbduxfastsub_tmp = context;
1580 struct usb_interface *uinterf = usbduxfastsub_tmp->interface;
1587 * we need to upload the firmware here because fw will be
1588 * freed once we've left this function
1590 ret = firmwareUpload(usbduxfastsub_tmp, fw->data, fw->size);
1593 dev_err(&uinterf->dev,
1594 "Could not upload firmware (err=%d)\n", ret);
1598 comedi_usb_auto_config(uinterf, &usbduxfast_driver);
1600 release_firmware(fw);
1603 static int usbduxfast_usb_probe(struct usb_interface *uinterf,
1604 const struct usb_device_id *id)
1606 struct usb_device *udev = interface_to_usbdev(uinterf);
1611 if (udev->speed != USB_SPEED_HIGH) {
1612 printk(KERN_ERR "comedi_: usbduxfast_: This driver needs"
1613 "USB 2.0 to operate. Aborting...\n");
1616 #ifdef CONFIG_COMEDI_DEBUG
1617 printk(KERN_DEBUG "comedi_: usbduxfast_: finding a free structure for "
1618 "the usb-device\n");
1620 down(&start_stop_sem);
1621 /* look for a free place in the usbduxfast array */
1623 for (i = 0; i < NUMUSBDUXFAST; i++) {
1624 if (!usbduxfastsub[i].probed) {
1632 printk(KERN_ERR "Too many usbduxfast-devices connected.\n");
1633 up(&start_stop_sem);
1636 #ifdef CONFIG_COMEDI_DEBUG
1637 printk(KERN_DEBUG "comedi_: usbduxfast: usbduxfastsub[%d] is ready to "
1638 "connect to comedi.\n", index);
1641 sema_init(&(usbduxfastsub[index].sem), 1);
1642 /* save a pointer to the usb device */
1643 usbduxfastsub[index].usbdev = udev;
1645 /* save the interface itself */
1646 usbduxfastsub[index].interface = uinterf;
1647 /* get the interface number from the interface */
1648 usbduxfastsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber;
1650 * hand the private data over to the usb subsystem
1651 * will be needed for disconnect
1653 usb_set_intfdata(uinterf, &(usbduxfastsub[index]));
1655 #ifdef CONFIG_COMEDI_DEBUG
1656 printk(KERN_DEBUG "comedi_: usbduxfast: ifnum=%d\n",
1657 usbduxfastsub[index].ifnum);
1659 /* create space for the commands going to the usb device */
1660 usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER,
1662 if (!usbduxfastsub[index].dux_commands) {
1663 printk(KERN_ERR "comedi_: usbduxfast: error alloc space for "
1665 tidy_up(&(usbduxfastsub[index]));
1666 up(&start_stop_sem);
1669 /* create space of the instruction buffer */
1670 usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL);
1671 if (!usbduxfastsub[index].insnBuffer) {
1672 printk(KERN_ERR "comedi_: usbduxfast: could not alloc space "
1673 "for insnBuffer\n");
1674 tidy_up(&(usbduxfastsub[index]));
1675 up(&start_stop_sem);
1678 /* setting to alternate setting 1: enabling bulk ep */
1679 i = usb_set_interface(usbduxfastsub[index].usbdev,
1680 usbduxfastsub[index].ifnum, 1);
1682 printk(KERN_ERR "comedi_: usbduxfast%d: could not switch to "
1683 "alternate setting 1.\n", index);
1684 tidy_up(&(usbduxfastsub[index]));
1685 up(&start_stop_sem);
1688 usbduxfastsub[index].urbIn = usb_alloc_urb(0, GFP_KERNEL);
1689 if (!usbduxfastsub[index].urbIn) {
1690 printk(KERN_ERR "comedi_: usbduxfast%d: Could not alloc."
1692 tidy_up(&(usbduxfastsub[index]));
1693 up(&start_stop_sem);
1696 usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL);
1697 if (!usbduxfastsub[index].transfer_buffer) {
1698 printk(KERN_ERR "comedi_: usbduxfast%d: could not alloc. "
1699 "transb.\n", index);
1700 tidy_up(&(usbduxfastsub[index]));
1701 up(&start_stop_sem);
1704 /* we've reached the bottom of the function */
1705 usbduxfastsub[index].probed = 1;
1706 up(&start_stop_sem);
1708 ret = request_firmware_nowait(THIS_MODULE,
1713 usbduxfastsub + index,
1714 usbduxfast_firmware_request_complete_handler);
1717 dev_err(&udev->dev, "could not load firmware (err=%d)\n", ret);
1721 printk(KERN_INFO "comedi_: usbduxfast%d has been successfully "
1722 "initialized.\n", index);
1727 static void usbduxfast_usb_disconnect(struct usb_interface *intf)
1729 struct usbduxfastsub_s *udfs = usb_get_intfdata(intf);
1730 struct usb_device *udev = interface_to_usbdev(intf);
1733 printk(KERN_ERR "comedi_: usbduxfast: disconnect called with "
1737 if (udfs->usbdev != udev) {
1738 printk(KERN_ERR "comedi_: usbduxfast: BUG! called with wrong "
1743 comedi_usb_auto_unconfig(intf);
1745 down(&start_stop_sem);
1749 up(&start_stop_sem);
1751 #ifdef CONFIG_COMEDI_DEBUG
1752 printk(KERN_DEBUG "comedi_: usbduxfast: disconnected from the usb\n");
1756 static const struct usb_device_id usbduxfast_usb_table[] = {
1757 /* { USB_DEVICE(0x4b4, 0x8613) }, testing */
1758 { USB_DEVICE(0x13d8, 0x0010) }, /* real ID */
1759 { USB_DEVICE(0x13d8, 0x0011) }, /* real ID */
1762 MODULE_DEVICE_TABLE(usb, usbduxfast_usb_table);
1764 static struct usb_driver usbduxfast_usb_driver = {
1765 #ifdef COMEDI_HAVE_USB_DRIVER_OWNER
1766 .owner = THIS_MODULE,
1768 .name = "usbduxfast",
1769 .probe = usbduxfast_usb_probe,
1770 .disconnect = usbduxfast_usb_disconnect,
1771 .id_table = usbduxfast_usb_table,
1773 module_comedi_usb_driver(usbduxfast_driver, usbduxfast_usb_driver);
1775 MODULE_AUTHOR("Bernd Porr, BerndPorr@f2s.com");
1776 MODULE_DESCRIPTION("USB-DUXfast, BerndPorr@f2s.com");
1777 MODULE_LICENSE("GPL");
1778 MODULE_FIRMWARE(FIRMWARE);