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 USBDUXFASTSUB_FIRMWARE 0xA0
61 #define VENDOR_DIR_IN 0xC0
62 #define VENDOR_DIR_OUT 0x40
65 * internal addresses of the 8051 processor
67 #define USBDUXFASTSUB_CPUCS 0xE600
70 * max lenghth of the transfer-buffer for software upload
75 * input endpoint number
80 * endpoint for the A/D channellist: bulk OUT
82 #define CHANNELLISTEP 4
87 #define NUMCHANNELS 32
90 * size of the waveform descriptor
95 * size of one A/D value
97 #define SIZEADIN (sizeof(int16_t))
100 * size of the input-buffer IN BYTES
102 #define SIZEINBUF 512
107 #define SIZEINSNBUF 512
110 * size of the buffer for the dux commands in bytes
112 #define SIZEOFDUXBUFFER 256
115 * number of in-URBs which receive the data: min=5
117 #define NUMOFINBUFFERSHIGH 10
120 * total number of usbduxfast devices
122 #define NUMUSBDUXFAST 16
125 * analogue in subdevice
130 * min delay steps for more than one channel
131 * basically when the mux gives up ;-)
133 * steps at 30MHz in the FX2
135 #define MIN_SAMPLING_PERIOD 9
138 * max number of 1/30MHz delay steps
140 #define MAX_SAMPLING_PERIOD 500
143 * number of received packets to ignore before we start handing data
144 * over to comedi, it's quad buffering and we have to ignore 4 packets
146 #define PACKETS_TO_IGNORE 4
151 static const struct comedi_lrange range_usbduxfast_ai_range = {
152 2, {BIP_RANGE(0.75), BIP_RANGE(0.5)}
156 * private structure of one subdevice
158 * this is the structure which holds all the data of this driver
159 * one sub device just now: A/D
161 struct usbduxfastsub_s {
162 int attached; /* is attached? */
163 int probed; /* is it associated with a subdevice? */
164 struct usb_device *usbdev; /* pointer to the usb-device */
165 struct urb *urbIn; /* BULK-transfer handling: urb */
166 int8_t *transfer_buffer;
167 int16_t *insnBuffer; /* input buffer for single insn */
168 int ifnum; /* interface number */
169 struct usb_interface *interface; /* interface structure */
170 /* comedi device for the interrupt context */
171 struct comedi_device *comedidev;
172 short int ai_cmd_running; /* asynchronous command is running */
173 short int ai_continous; /* continous acquisition */
174 long int ai_sample_count; /* number of samples to acquire */
175 uint8_t *dux_commands; /* commands */
176 int ignore; /* counter which ignores the first
178 struct semaphore sem;
182 * The pointer to the private usb-data of the driver
183 * is also the private data for the comedi-device.
184 * This has to be global as the usb subsystem needs
185 * global variables. The other reason is that this
186 * structure must be there _before_ any comedi
187 * command is issued. The usb subsystem must be
188 * initialised before comedi can access it.
190 static struct usbduxfastsub_s usbduxfastsub[NUMUSBDUXFAST];
192 static DEFINE_SEMAPHORE(start_stop_sem);
195 * bulk transfers to usbduxfast
197 #define SENDADCOMMANDS 0
198 #define SENDINITEP6 1
200 static int send_dux_commands(struct usbduxfastsub_s *udfs, int cmd_type)
204 udfs->dux_commands[0] = cmd_type;
206 #ifdef CONFIG_COMEDI_DEBUG
207 printk(KERN_DEBUG "comedi%d: usbduxfast: dux_commands: ",
208 udfs->comedidev->minor);
209 for (tmp = 0; tmp < SIZEOFDUXBUFFER; tmp++)
210 printk(" %02x", udfs->dux_commands[tmp]);
214 tmp = usb_bulk_msg(udfs->usbdev,
215 usb_sndbulkpipe(udfs->usbdev, CHANNELLISTEP),
216 udfs->dux_commands, SIZEOFDUXBUFFER, &nsent, 10000);
218 printk(KERN_ERR "comedi%d: could not transmit dux_commands to"
219 "the usb-device, err=%d\n", udfs->comedidev->minor, tmp);
224 * Stops the data acquision.
225 * It should be safe to call this function from any context.
227 static int usbduxfastsub_unlink_InURBs(struct usbduxfastsub_s *udfs)
232 if (udfs && udfs->urbIn) {
233 udfs->ai_cmd_running = 0;
234 /* waits until a running transfer is over */
235 usb_kill_urb(udfs->urbIn);
238 #ifdef CONFIG_COMEDI_DEBUG
239 printk(KERN_DEBUG "comedi: usbduxfast: unlinked InURB: res=%d\n", j);
245 * This will stop a running acquisition operation.
246 * Is called from within this driver from both the
247 * interrupt context and from comedi.
249 static int usbduxfast_ai_stop(struct usbduxfastsub_s *udfs, int do_unlink)
254 printk(KERN_ERR "comedi?: usbduxfast_ai_stop: udfs=NULL!\n");
257 #ifdef CONFIG_COMEDI_DEBUG
258 printk(KERN_DEBUG "comedi: usbduxfast_ai_stop\n");
261 udfs->ai_cmd_running = 0;
265 ret = usbduxfastsub_unlink_InURBs(udfs);
271 * This will cancel a running acquisition operation.
272 * This is called by comedi but never from inside the driver.
274 static int usbduxfast_ai_cancel(struct comedi_device *dev,
275 struct comedi_subdevice *s)
277 struct usbduxfastsub_s *udfs;
280 /* force unlink of all urbs */
281 #ifdef CONFIG_COMEDI_DEBUG
282 printk(KERN_DEBUG "comedi: usbduxfast_ai_cancel\n");
286 printk(KERN_ERR "comedi: usbduxfast_ai_cancel: udfs=NULL\n");
295 ret = usbduxfast_ai_stop(udfs, 1);
303 * interrupt service routine
305 static void usbduxfastsub_ai_Irq(struct urb *urb)
308 struct usbduxfastsub_s *udfs;
309 struct comedi_device *this_comedidev;
310 struct comedi_subdevice *s;
313 /* sanity checks - is the urb there? */
315 printk(KERN_ERR "comedi_: usbduxfast_: ao int-handler called "
319 /* the context variable points to the subdevice */
320 this_comedidev = urb->context;
321 if (!this_comedidev) {
322 printk(KERN_ERR "comedi_: usbduxfast_: urb context is a NULL "
326 /* the private structure of the subdevice is usbduxfastsub_s */
327 udfs = this_comedidev->private;
329 printk(KERN_ERR "comedi_: usbduxfast_: private of comedi "
330 "subdev is a NULL pointer!\n");
333 /* are we running a command? */
334 if (unlikely(!udfs->ai_cmd_running)) {
336 * not running a command
337 * do not continue execution if no asynchronous command
338 * is running in particular not resubmit
343 if (unlikely(!udfs->attached)) {
344 /* no comedi device there */
347 /* subdevice which is the AD converter */
348 s = this_comedidev->subdevices + SUBDEV_AD;
350 /* first we test if something unusual has just happened */
351 switch (urb->status) {
356 * happens after an unlink command or when the device
363 /* tell this comedi */
364 s->async->events |= COMEDI_CB_EOA;
365 s->async->events |= COMEDI_CB_ERROR;
366 comedi_event(udfs->comedidev, s);
367 /* stop the transfer w/o unlink */
368 usbduxfast_ai_stop(udfs, 0);
372 printk("comedi%d: usbduxfast: non-zero urb status received in "
373 "ai intr context: %d\n",
374 udfs->comedidev->minor, urb->status);
375 s->async->events |= COMEDI_CB_EOA;
376 s->async->events |= COMEDI_CB_ERROR;
377 comedi_event(udfs->comedidev, s);
378 usbduxfast_ai_stop(udfs, 0);
382 p = urb->transfer_buffer;
384 if (!udfs->ai_continous) {
385 /* not continuous, fixed number of samples */
386 n = urb->actual_length / sizeof(uint16_t);
387 if (unlikely(udfs->ai_sample_count < n)) {
389 * we have send only a fraction of the bytes
392 cfc_write_array_to_buffer(s,
393 urb->transfer_buffer,
394 udfs->ai_sample_count
396 usbduxfast_ai_stop(udfs, 0);
397 /* tell comedi that the acquistion is over */
398 s->async->events |= COMEDI_CB_EOA;
399 comedi_event(udfs->comedidev, s);
402 udfs->ai_sample_count -= n;
404 /* write the full buffer to comedi */
405 err = cfc_write_array_to_buffer(s, urb->transfer_buffer,
407 if (unlikely(err == 0)) {
408 /* buffer overflow */
409 usbduxfast_ai_stop(udfs, 0);
413 /* tell comedi that data is there */
414 comedi_event(udfs->comedidev, s);
417 /* ignore this packet */
422 * command is still running
423 * resubmit urb for BULK transfer
425 urb->dev = udfs->usbdev;
427 err = usb_submit_urb(urb, GFP_ATOMIC);
429 printk(KERN_ERR "comedi%d: usbduxfast: urb resubm failed: %d",
430 udfs->comedidev->minor, err);
431 s->async->events |= COMEDI_CB_EOA;
432 s->async->events |= COMEDI_CB_ERROR;
433 comedi_event(udfs->comedidev, s);
434 usbduxfast_ai_stop(udfs, 0);
438 static int usbduxfastsub_start(struct usbduxfastsub_s *udfs)
441 unsigned char local_transfer_buffer[16];
444 local_transfer_buffer[0] = 0;
445 /* bRequest, "Firmware" */
446 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
447 USBDUXFASTSUB_FIRMWARE,
448 VENDOR_DIR_OUT, /* bmRequestType */
449 USBDUXFASTSUB_CPUCS, /* Value */
451 /* address of the transfer buffer */
452 local_transfer_buffer,
454 EZTIMEOUT); /* Timeout */
456 printk("comedi_: usbduxfast_: control msg failed (start)\n");
463 static int usbduxfastsub_stop(struct usbduxfastsub_s *udfs)
466 unsigned char local_transfer_buffer[16];
469 local_transfer_buffer[0] = 1;
470 /* bRequest, "Firmware" */
471 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
472 USBDUXFASTSUB_FIRMWARE,
473 VENDOR_DIR_OUT, /* bmRequestType */
474 USBDUXFASTSUB_CPUCS, /* Value */
476 local_transfer_buffer, 1, /* Length */
477 EZTIMEOUT); /* Timeout */
479 printk(KERN_ERR "comedi_: usbduxfast: control msg failed "
487 static int usbduxfastsub_upload(struct usbduxfastsub_s *udfs,
488 unsigned char *local_transfer_buffer,
489 unsigned int startAddr, unsigned int len)
493 #ifdef CONFIG_COMEDI_DEBUG
494 printk(KERN_DEBUG "comedi: usbduxfast: uploading %d bytes", len);
495 printk(KERN_DEBUG " to addr %d, first byte=%d.\n",
496 startAddr, local_transfer_buffer[0]);
498 /* brequest, firmware */
499 ret = usb_control_msg(udfs->usbdev, usb_sndctrlpipe(udfs->usbdev, 0),
500 USBDUXFASTSUB_FIRMWARE,
501 VENDOR_DIR_OUT, /* bmRequestType */
502 startAddr, /* value */
504 /* our local safe buffer */
505 local_transfer_buffer,
507 EZTIMEOUT); /* timeout */
509 #ifdef CONFIG_COMEDI_DEBUG
510 printk(KERN_DEBUG "comedi_: usbduxfast: result=%d\n", ret);
514 printk(KERN_ERR "comedi_: usbduxfast: uppload failed\n");
521 static int usbduxfastsub_submit_InURBs(struct usbduxfastsub_s *udfs)
528 usb_fill_bulk_urb(udfs->urbIn, udfs->usbdev,
529 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
530 udfs->transfer_buffer,
531 SIZEINBUF, usbduxfastsub_ai_Irq, udfs->comedidev);
533 #ifdef CONFIG_COMEDI_DEBUG
534 printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
535 "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
538 ret = usb_submit_urb(udfs->urbIn, GFP_ATOMIC);
540 printk(KERN_ERR "comedi_: usbduxfast: ai: usb_submit_urb error"
547 static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
548 struct comedi_subdevice *s,
549 struct comedi_cmd *cmd)
551 int err = 0, stop_mask = 0;
554 struct usbduxfastsub_s *udfs = dev->private;
559 #ifdef CONFIG_COMEDI_DEBUG
560 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmdtest\n", dev->minor);
561 printk(KERN_DEBUG "comedi%d: usbduxfast: convert_arg=%u "
562 "scan_begin_arg=%u\n",
563 dev->minor, cmd->convert_arg, cmd->scan_begin_arg);
565 /* step 1: make sure trigger sources are trivially valid */
567 tmp = cmd->start_src;
568 cmd->start_src &= TRIG_NOW | TRIG_EXT | TRIG_INT;
569 if (!cmd->start_src || tmp != cmd->start_src)
572 tmp = cmd->scan_begin_src;
573 cmd->scan_begin_src &= TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT;
574 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
577 tmp = cmd->convert_src;
578 cmd->convert_src &= TRIG_TIMER | TRIG_EXT;
579 if (!cmd->convert_src || tmp != cmd->convert_src)
582 tmp = cmd->scan_end_src;
583 cmd->scan_end_src &= TRIG_COUNT;
584 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
588 stop_mask = TRIG_COUNT | TRIG_NONE;
589 cmd->stop_src &= stop_mask;
590 if (!cmd->stop_src || tmp != cmd->stop_src)
597 * step 2: make sure trigger sources are unique and mutually compatible
600 if (cmd->start_src != TRIG_NOW &&
601 cmd->start_src != TRIG_EXT && cmd->start_src != TRIG_INT)
603 if (cmd->scan_begin_src != TRIG_TIMER &&
604 cmd->scan_begin_src != TRIG_FOLLOW &&
605 cmd->scan_begin_src != TRIG_EXT)
607 if (cmd->convert_src != TRIG_TIMER && cmd->convert_src != TRIG_EXT)
609 if (cmd->stop_src != TRIG_COUNT &&
610 cmd->stop_src != TRIG_EXT && cmd->stop_src != TRIG_NONE)
613 /* can't have external stop and start triggers at once */
614 if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
620 /* step 3: make sure arguments are trivially compatible */
622 if (cmd->start_src == TRIG_NOW && cmd->start_arg != 0) {
627 if (!cmd->chanlist_len)
630 if (cmd->scan_end_arg != cmd->chanlist_len) {
631 cmd->scan_end_arg = cmd->chanlist_len;
635 if (cmd->chanlist_len == 1)
638 minSamplPer = MIN_SAMPLING_PERIOD;
640 if (cmd->convert_src == TRIG_TIMER) {
641 steps = cmd->convert_arg * 30;
642 if (steps < (minSamplPer * 1000))
643 steps = minSamplPer * 1000;
645 if (steps > (MAX_SAMPLING_PERIOD * 1000))
646 steps = MAX_SAMPLING_PERIOD * 1000;
650 if (cmd->convert_arg != tmp) {
651 cmd->convert_arg = tmp;
656 if (cmd->scan_begin_src == TRIG_TIMER)
660 switch (cmd->stop_src) {
662 if (!cmd->stop_arg) {
668 if (cmd->stop_arg != 0) {
674 * TRIG_EXT doesn't care since it doesn't trigger
675 * off a numbered channel
684 /* step 4: fix up any arguments */
690 static int usbduxfast_ai_inttrig(struct comedi_device *dev,
691 struct comedi_subdevice *s,
692 unsigned int trignum)
695 struct usbduxfastsub_s *udfs = dev->private;
705 #ifdef CONFIG_COMEDI_DEBUG
706 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_inttrig\n", dev->minor);
710 printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: invalid"
711 " trignum\n", dev->minor);
715 if (!udfs->ai_cmd_running) {
716 udfs->ai_cmd_running = 1;
717 ret = usbduxfastsub_submit_InURBs(udfs);
719 printk(KERN_ERR "comedi%d: usbduxfast_ai_inttrig: "
720 "urbSubmit: err=%d\n", dev->minor, ret);
721 udfs->ai_cmd_running = 0;
725 s->async->inttrig = NULL;
727 printk(KERN_ERR "comedi%d: ai_inttrig but acqu is already"
728 " running\n", dev->minor);
735 * offsets for the GPIF bytes
736 * the first byte is the command byte
738 #define LENBASE (1+0x00)
739 #define OPBASE (1+0x08)
740 #define OUTBASE (1+0x10)
741 #define LOGBASE (1+0x18)
743 static int usbduxfast_ai_cmd(struct comedi_device *dev,
744 struct comedi_subdevice *s)
746 struct comedi_cmd *cmd = &s->async->cmd;
747 unsigned int chan, gain, rngmask = 0xff;
749 struct usbduxfastsub_s *udfs;
751 long steps, steps_tmp;
753 #ifdef CONFIG_COMEDI_DEBUG
754 printk(KERN_DEBUG "comedi%d: usbduxfast_ai_cmd\n", dev->minor);
765 if (udfs->ai_cmd_running) {
766 printk(KERN_ERR "comedi%d: ai_cmd not possible. Another ai_cmd"
767 " is running.\n", dev->minor);
771 /* set current channel of the running acquisition to zero */
772 s->async->cur_chan = 0;
775 * ignore the first buffers from the device if there
776 * is an error condition
778 udfs->ignore = PACKETS_TO_IGNORE;
780 if (cmd->chanlist_len > 0) {
781 gain = CR_RANGE(cmd->chanlist[0]);
782 for (i = 0; i < cmd->chanlist_len; ++i) {
783 chan = CR_CHAN(cmd->chanlist[i]);
785 printk(KERN_ERR "comedi%d: cmd is accepting "
786 "only consecutive channels.\n",
791 if ((gain != CR_RANGE(cmd->chanlist[i]))
792 && (cmd->chanlist_len > 3)) {
793 printk(KERN_ERR "comedi%d: the gain must be"
794 " the same for all channels.\n",
799 if (i >= NUMCHANNELS) {
800 printk(KERN_ERR "comedi%d: channel list too"
801 " long\n", dev->minor);
807 if (cmd->scan_begin_src == TRIG_TIMER) {
808 printk(KERN_ERR "comedi%d: usbduxfast: "
809 "scan_begin_src==TRIG_TIMER not valid.\n", dev->minor);
813 if (cmd->convert_src == TRIG_TIMER)
814 steps = (cmd->convert_arg * 30) / 1000;
816 if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) {
817 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: steps=%ld, "
818 "scan_begin_arg=%d. Not properly tested by cmdtest?\n",
819 dev->minor, steps, cmd->scan_begin_arg);
823 if (steps > MAX_SAMPLING_PERIOD) {
824 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: sampling rate "
825 "too low.\n", dev->minor);
829 if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1)
830 && (cmd->chanlist_len != 16)) {
831 printk(KERN_ERR "comedi%d: usbduxfast: ai_cmd: TRIG_EXT only"
832 " with 1 or 16 channels possible.\n", dev->minor);
836 #ifdef CONFIG_COMEDI_DEBUG
837 printk(KERN_DEBUG "comedi%d: usbduxfast: steps=%ld, convert_arg=%u\n",
838 dev->minor, steps, cmd->convert_arg);
841 switch (cmd->chanlist_len) {
847 if (CR_RANGE(cmd->chanlist[0]) > 0)
848 rngmask = 0xff - 0x04;
853 * for external trigger: looping in this state until
854 * the RDY0 pin becomes zero
857 /* we loop here until ready has been set */
858 if (cmd->start_src == TRIG_EXT) {
859 /* branch back to state 0 */
860 udfs->dux_commands[LENBASE + 0] = 0x01;
861 /* deceision state w/o data */
862 udfs->dux_commands[OPBASE + 0] = 0x01;
863 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
865 udfs->dux_commands[LOGBASE + 0] = 0x00;
866 } else { /* we just proceed to state 1 */
867 udfs->dux_commands[LENBASE + 0] = 1;
868 udfs->dux_commands[OPBASE + 0] = 0;
869 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
870 udfs->dux_commands[LOGBASE + 0] = 0;
873 if (steps < MIN_SAMPLING_PERIOD) {
874 /* for fast single channel aqu without mux */
877 * we just stay here at state 1 and rexecute
878 * the same state this gives us 30MHz sampling
882 /* branch back to state 1 */
883 udfs->dux_commands[LENBASE + 1] = 0x89;
884 /* deceision state with data */
885 udfs->dux_commands[OPBASE + 1] = 0x03;
886 udfs->dux_commands[OUTBASE + 1] =
889 udfs->dux_commands[LOGBASE + 1] = 0xFF;
892 * we loop through two states: data and delay
895 udfs->dux_commands[LENBASE + 1] = steps - 1;
897 udfs->dux_commands[OPBASE + 1] = 0x02;
898 udfs->dux_commands[OUTBASE + 1] =
901 udfs->dux_commands[LOGBASE + 1] = 0;
902 /* branch back to state 1 */
903 udfs->dux_commands[LENBASE + 2] = 0x09;
904 /* deceision state w/o data */
905 udfs->dux_commands[OPBASE + 2] = 0x01;
906 udfs->dux_commands[OUTBASE + 2] =
909 udfs->dux_commands[LOGBASE + 2] = 0xFF;
913 * we loop through 3 states: 2x delay and 1x data
914 * this gives a min sampling rate of 60kHz
917 /* we have 1 state with duration 1 */
920 /* do the first part of the delay */
921 udfs->dux_commands[LENBASE + 1] = steps / 2;
922 udfs->dux_commands[OPBASE + 1] = 0;
923 udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask;
924 udfs->dux_commands[LOGBASE + 1] = 0;
926 /* and the second part */
927 udfs->dux_commands[LENBASE + 2] = steps - steps / 2;
928 udfs->dux_commands[OPBASE + 2] = 0;
929 udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask;
930 udfs->dux_commands[LOGBASE + 2] = 0;
932 /* get the data and branch back */
934 /* branch back to state 1 */
935 udfs->dux_commands[LENBASE + 3] = 0x09;
936 /* deceision state w data */
937 udfs->dux_commands[OPBASE + 3] = 0x03;
938 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
940 udfs->dux_commands[LOGBASE + 3] = 0xFF;
947 * commit data to the FIFO
950 if (CR_RANGE(cmd->chanlist[0]) > 0)
951 rngmask = 0xff - 0x04;
955 udfs->dux_commands[LENBASE + 0] = 1;
957 udfs->dux_commands[OPBASE + 0] = 0x02;
958 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
959 udfs->dux_commands[LOGBASE + 0] = 0;
961 /* we have 1 state with duration 1: state 0 */
962 steps_tmp = steps - 1;
964 if (CR_RANGE(cmd->chanlist[1]) > 0)
965 rngmask = 0xff - 0x04;
969 /* do the first part of the delay */
970 udfs->dux_commands[LENBASE + 1] = steps_tmp / 2;
971 udfs->dux_commands[OPBASE + 1] = 0;
973 udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask;
974 udfs->dux_commands[LOGBASE + 1] = 0;
976 /* and the second part */
977 udfs->dux_commands[LENBASE + 2] = steps_tmp - steps_tmp / 2;
978 udfs->dux_commands[OPBASE + 2] = 0;
979 udfs->dux_commands[OUTBASE + 2] = 0xFF & rngmask;
980 udfs->dux_commands[LOGBASE + 2] = 0;
982 udfs->dux_commands[LENBASE + 3] = 1;
984 udfs->dux_commands[OPBASE + 3] = 0x02;
985 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
986 udfs->dux_commands[LOGBASE + 3] = 0;
989 * we have 2 states with duration 1: step 6 and
992 steps_tmp = steps - 2;
994 if (CR_RANGE(cmd->chanlist[0]) > 0)
995 rngmask = 0xff - 0x04;
999 /* do the first part of the delay */
1000 udfs->dux_commands[LENBASE + 4] = steps_tmp / 2;
1001 udfs->dux_commands[OPBASE + 4] = 0;
1003 udfs->dux_commands[OUTBASE + 4] = (0xFF - 0x02) & rngmask;
1004 udfs->dux_commands[LOGBASE + 4] = 0;
1006 /* and the second part */
1007 udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2;
1008 udfs->dux_commands[OPBASE + 5] = 0;
1009 udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask;
1010 udfs->dux_commands[LOGBASE + 5] = 0;
1012 udfs->dux_commands[LENBASE + 6] = 1;
1013 udfs->dux_commands[OPBASE + 6] = 0;
1014 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1015 udfs->dux_commands[LOGBASE + 6] = 0;
1022 for (j = 0; j < 1; j++) {
1023 if (CR_RANGE(cmd->chanlist[j]) > 0)
1024 rngmask = 0xff - 0x04;
1028 * commit data to the FIFO and do the first part
1031 udfs->dux_commands[LENBASE + j * 2] = steps / 2;
1033 udfs->dux_commands[OPBASE + j * 2] = 0x02;
1035 udfs->dux_commands[OUTBASE + j * 2] = 0xFF & rngmask;
1036 udfs->dux_commands[LOGBASE + j * 2] = 0;
1038 if (CR_RANGE(cmd->chanlist[j + 1]) > 0)
1039 rngmask = 0xff - 0x04;
1043 /* do the second part of the delay */
1044 udfs->dux_commands[LENBASE + j * 2 + 1] =
1047 udfs->dux_commands[OPBASE + j * 2 + 1] = 0;
1049 udfs->dux_commands[OUTBASE + j * 2 + 1] =
1051 udfs->dux_commands[LOGBASE + j * 2 + 1] = 0;
1054 /* 2 steps with duration 1: the idele step and step 6: */
1055 steps_tmp = steps - 2;
1057 /* commit data to the FIFO and do the first part of the delay */
1058 udfs->dux_commands[LENBASE + 4] = steps_tmp / 2;
1060 udfs->dux_commands[OPBASE + 4] = 0x02;
1061 udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask;
1062 udfs->dux_commands[LOGBASE + 4] = 0;
1064 if (CR_RANGE(cmd->chanlist[0]) > 0)
1065 rngmask = 0xff - 0x04;
1069 /* do the second part of the delay */
1070 udfs->dux_commands[LENBASE + 5] = steps_tmp - steps_tmp / 2;
1072 udfs->dux_commands[OPBASE + 5] = 0;
1074 udfs->dux_commands[OUTBASE + 5] = (0xFF - 0x02) & rngmask;
1075 udfs->dux_commands[LOGBASE + 5] = 0;
1077 udfs->dux_commands[LENBASE + 6] = 1;
1078 udfs->dux_commands[OPBASE + 6] = 0;
1079 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1080 udfs->dux_commands[LOGBASE + 6] = 0;
1083 if (CR_RANGE(cmd->chanlist[0]) > 0)
1084 rngmask = 0xff - 0x04;
1088 if (cmd->start_src == TRIG_EXT) {
1090 * we loop here until ready has been set
1093 /* branch back to state 0 */
1094 udfs->dux_commands[LENBASE + 0] = 0x01;
1095 /* deceision state w/o data */
1096 udfs->dux_commands[OPBASE + 0] = 0x01;
1098 udfs->dux_commands[OUTBASE + 0] =
1099 (0xFF - 0x02) & rngmask;
1101 udfs->dux_commands[LOGBASE + 0] = 0x00;
1104 * we just proceed to state 1
1107 /* 30us reset pulse */
1108 udfs->dux_commands[LENBASE + 0] = 255;
1109 udfs->dux_commands[OPBASE + 0] = 0;
1111 udfs->dux_commands[OUTBASE + 0] =
1112 (0xFF - 0x02) & rngmask;
1113 udfs->dux_commands[LOGBASE + 0] = 0;
1116 /* commit data to the FIFO */
1117 udfs->dux_commands[LENBASE + 1] = 1;
1119 udfs->dux_commands[OPBASE + 1] = 0x02;
1120 udfs->dux_commands[OUTBASE + 1] = 0xFF & rngmask;
1121 udfs->dux_commands[LOGBASE + 1] = 0;
1123 /* we have 2 states with duration 1 */
1126 /* do the first part of the delay */
1127 udfs->dux_commands[LENBASE + 2] = steps / 2;
1128 udfs->dux_commands[OPBASE + 2] = 0;
1129 udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask;
1130 udfs->dux_commands[LOGBASE + 2] = 0;
1132 /* and the second part */
1133 udfs->dux_commands[LENBASE + 3] = steps - steps / 2;
1134 udfs->dux_commands[OPBASE + 3] = 0;
1135 udfs->dux_commands[OUTBASE + 3] = 0xFF & rngmask;
1136 udfs->dux_commands[LOGBASE + 3] = 0;
1138 /* branch back to state 1 */
1139 udfs->dux_commands[LENBASE + 4] = 0x09;
1140 /* deceision state w/o data */
1141 udfs->dux_commands[OPBASE + 4] = 0x01;
1142 udfs->dux_commands[OUTBASE + 4] = 0xFF & rngmask;
1143 /* doesn't matter */
1144 udfs->dux_commands[LOGBASE + 4] = 0xFF;
1149 printk(KERN_ERR "comedi %d: unsupported combination of "
1150 "channels\n", dev->minor);
1155 #ifdef CONFIG_COMEDI_DEBUG
1156 printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
1159 /* 0 means that the AD commands are sent */
1160 result = send_dux_commands(udfs, SENDADCOMMANDS);
1162 printk(KERN_ERR "comedi%d: adc command could not be submitted."
1163 "Aborting...\n", dev->minor);
1167 if (cmd->stop_src == TRIG_COUNT) {
1168 udfs->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg;
1169 if (udfs->ai_sample_count < 1) {
1170 printk(KERN_ERR "comedi%d: "
1171 "(cmd->stop_arg)*(cmd->scan_end_arg)<1, "
1172 "aborting.\n", dev->minor);
1176 udfs->ai_continous = 0;
1178 /* continous acquisition */
1179 udfs->ai_continous = 1;
1180 udfs->ai_sample_count = 0;
1183 if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
1184 /* enable this acquisition operation */
1185 udfs->ai_cmd_running = 1;
1186 ret = usbduxfastsub_submit_InURBs(udfs);
1188 udfs->ai_cmd_running = 0;
1189 /* fixme: unlink here?? */
1193 s->async->inttrig = NULL;
1197 * don't enable the acquision operation
1198 * wait for an internal signal
1200 s->async->inttrig = usbduxfast_ai_inttrig;
1208 * Mode 0 is used to get a single conversion on demand.
1210 static int usbduxfast_ai_insn_read(struct comedi_device *dev,
1211 struct comedi_subdevice *s,
1212 struct comedi_insn *insn, unsigned int *data)
1214 int i, j, n, actual_length;
1215 int chan, range, rngmask;
1217 struct usbduxfastsub_s *udfs;
1219 udfs = dev->private;
1221 printk(KERN_ERR "comedi%d: ai_insn_read: no usb dev.\n",
1225 #ifdef CONFIG_COMEDI_DEBUG
1226 printk(KERN_DEBUG "comedi%d: ai_insn_read, insn->n=%d, "
1227 "insn->subdev=%d\n", dev->minor, insn->n, insn->subdev);
1230 if (!udfs->probed) {
1234 if (udfs->ai_cmd_running) {
1235 printk(KERN_ERR "comedi%d: ai_insn_read not possible. Async "
1236 "Command is running.\n", dev->minor);
1240 /* sample one channel */
1241 chan = CR_CHAN(insn->chanspec);
1242 range = CR_RANGE(insn->chanspec);
1243 /* set command for the first channel */
1246 rngmask = 0xff - 0x04;
1250 /* commit data to the FIFO */
1251 udfs->dux_commands[LENBASE + 0] = 1;
1253 udfs->dux_commands[OPBASE + 0] = 0x02;
1254 udfs->dux_commands[OUTBASE + 0] = 0xFF & rngmask;
1255 udfs->dux_commands[LOGBASE + 0] = 0;
1257 /* do the first part of the delay */
1258 udfs->dux_commands[LENBASE + 1] = 12;
1259 udfs->dux_commands[OPBASE + 1] = 0;
1260 udfs->dux_commands[OUTBASE + 1] = 0xFE & rngmask;
1261 udfs->dux_commands[LOGBASE + 1] = 0;
1263 udfs->dux_commands[LENBASE + 2] = 1;
1264 udfs->dux_commands[OPBASE + 2] = 0;
1265 udfs->dux_commands[OUTBASE + 2] = 0xFE & rngmask;
1266 udfs->dux_commands[LOGBASE + 2] = 0;
1268 udfs->dux_commands[LENBASE + 3] = 1;
1269 udfs->dux_commands[OPBASE + 3] = 0;
1270 udfs->dux_commands[OUTBASE + 3] = 0xFE & rngmask;
1271 udfs->dux_commands[LOGBASE + 3] = 0;
1273 udfs->dux_commands[LENBASE + 4] = 1;
1274 udfs->dux_commands[OPBASE + 4] = 0;
1275 udfs->dux_commands[OUTBASE + 4] = 0xFE & rngmask;
1276 udfs->dux_commands[LOGBASE + 4] = 0;
1279 udfs->dux_commands[LENBASE + 5] = 12;
1280 udfs->dux_commands[OPBASE + 5] = 0;
1281 udfs->dux_commands[OUTBASE + 5] = 0xFF & rngmask;
1282 udfs->dux_commands[LOGBASE + 5] = 0;
1284 udfs->dux_commands[LENBASE + 6] = 1;
1285 udfs->dux_commands[OPBASE + 6] = 0;
1286 udfs->dux_commands[OUTBASE + 6] = 0xFF & rngmask;
1287 udfs->dux_commands[LOGBASE + 0] = 0;
1289 #ifdef CONFIG_COMEDI_DEBUG
1290 printk(KERN_DEBUG "comedi %d: sending commands to the usb device\n",
1293 /* 0 means that the AD commands are sent */
1294 err = send_dux_commands(udfs, SENDADCOMMANDS);
1296 printk(KERN_ERR "comedi%d: adc command could not be submitted."
1297 "Aborting...\n", dev->minor);
1301 #ifdef CONFIG_COMEDI_DEBUG
1302 printk(KERN_DEBUG "comedi%d: usbduxfast: submitting in-urb: "
1303 "0x%p,0x%p\n", udfs->comedidev->minor, udfs->urbIn->context,
1306 for (i = 0; i < PACKETS_TO_IGNORE; i++) {
1307 err = usb_bulk_msg(udfs->usbdev,
1308 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
1309 udfs->transfer_buffer, SIZEINBUF,
1310 &actual_length, 10000);
1312 printk(KERN_ERR "comedi%d: insn timeout. No data.\n",
1319 for (i = 0; i < insn->n;) {
1320 err = usb_bulk_msg(udfs->usbdev,
1321 usb_rcvbulkpipe(udfs->usbdev, BULKINEP),
1322 udfs->transfer_buffer, SIZEINBUF,
1323 &actual_length, 10000);
1325 printk(KERN_ERR "comedi%d: insn data error: %d\n",
1330 n = actual_length / sizeof(uint16_t);
1331 if ((n % 16) != 0) {
1332 printk(KERN_ERR "comedi%d: insn data packet "
1333 "corrupted.\n", dev->minor);
1337 for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
1338 data[i] = ((uint16_t *) (udfs->transfer_buffer))[j];
1346 #define FIRMWARE_MAX_LEN 0x2000
1348 static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub,
1349 const u8 *firmwareBinary, int sizeFirmware)
1354 if (!firmwareBinary)
1357 if (sizeFirmware > FIRMWARE_MAX_LEN) {
1358 dev_err(&usbduxfastsub->interface->dev,
1359 "comedi_: usbduxfast firmware binary it too large for FX2.\n");
1363 /* we generate a local buffer for the firmware */
1364 fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
1366 dev_err(&usbduxfastsub->interface->dev,
1367 "comedi_: mem alloc for firmware failed\n");
1371 ret = usbduxfastsub_stop(usbduxfastsub);
1373 dev_err(&usbduxfastsub->interface->dev,
1374 "comedi_: can not stop firmware\n");
1379 ret = usbduxfastsub_upload(usbduxfastsub, fwBuf, 0, sizeFirmware);
1381 dev_err(&usbduxfastsub->interface->dev,
1382 "comedi_: firmware upload failed\n");
1386 ret = usbduxfastsub_start(usbduxfastsub);
1388 dev_err(&usbduxfastsub->interface->dev,
1389 "comedi_: can not start firmware\n");
1397 static void tidy_up(struct usbduxfastsub_s *udfs)
1399 #ifdef CONFIG_COMEDI_DEBUG
1400 printk(KERN_DEBUG "comedi_: usbduxfast: tiding up\n");
1406 /* shows the usb subsystem that the driver is down */
1407 if (udfs->interface)
1408 usb_set_intfdata(udfs->interface, NULL);
1413 /* waits until a running transfer is over */
1414 usb_kill_urb(udfs->urbIn);
1416 kfree(udfs->transfer_buffer);
1417 udfs->transfer_buffer = NULL;
1419 usb_free_urb(udfs->urbIn);
1423 kfree(udfs->insnBuffer);
1424 udfs->insnBuffer = NULL;
1426 kfree(udfs->dux_commands);
1427 udfs->dux_commands = NULL;
1429 udfs->ai_cmd_running = 0;
1432 /* common part of attach and attach_usb */
1433 static int usbduxfast_attach_common(struct comedi_device *dev,
1434 struct usbduxfastsub_s *udfs,
1435 void *aux_data, int aux_len)
1438 struct comedi_subdevice *s;
1441 /* pointer back to the corresponding comedi device */
1442 udfs->comedidev = dev;
1443 /* trying to upload the firmware into the chip */
1445 firmwareUpload(udfs, aux_data, aux_len);
1446 dev->board_name = "usbduxfast";
1447 ret = comedi_alloc_subdevices(dev, 1);
1452 /* private structure is also simply the usb-structure */
1453 dev->private = udfs;
1454 /* the first subdevice is the A/D converter */
1455 s = dev->subdevices + SUBDEV_AD;
1457 * the URBs get the comedi subdevice which is responsible for reading
1458 * this is the subdevice which reads data
1460 dev->read_subdev = s;
1461 /* the subdevice receives as private structure the usb-structure */
1464 s->type = COMEDI_SUBD_AI;
1465 /* readable and ref is to ground */
1466 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
1469 /* length of the channellist */
1470 s->len_chanlist = 16;
1471 /* callback functions */
1472 s->insn_read = usbduxfast_ai_insn_read;
1473 s->do_cmdtest = usbduxfast_ai_cmdtest;
1474 s->do_cmd = usbduxfast_ai_cmd;
1475 s->cancel = usbduxfast_ai_cancel;
1476 /* max value from the A/D converter (12bit+1 bit for overflow) */
1477 s->maxdata = 0x1000;
1478 /* range table to convert to physical units */
1479 s->range_table = &range_usbduxfast_ai_range;
1480 /* finally decide that it's attached */
1483 dev_info(dev->class_dev, "successfully attached to usbduxfast.\n");
1487 /* is called for COMEDI_DEVCONFIG ioctl (when comedi_config is run) */
1488 static int usbduxfast_attach(struct comedi_device *dev,
1489 struct comedi_devconfig *it)
1497 dev->private = NULL;
1499 aux_data = comedi_aux_data(it->options, 0);
1500 aux_len = it->options[COMEDI_DEVCONF_AUX_DATA_LENGTH];
1501 if (aux_data == NULL)
1503 else if (aux_len == 0)
1505 down(&start_stop_sem);
1507 * find a valid device which has been detected by the
1508 * probe function of the usb
1511 for (i = 0; i < NUMUSBDUXFAST; i++) {
1512 if (usbduxfastsub[i].probed && !usbduxfastsub[i].attached) {
1518 dev_err(dev->class_dev,
1519 "usbduxfast: error: attach failed, no usbduxfast devs connected to the usb bus.\n");
1522 ret = usbduxfast_attach_common(dev, &usbduxfastsub[index],
1524 up(&start_stop_sem);
1528 /* is called from comedi_usb_auto_config() */
1529 static int usbduxfast_attach_usb(struct comedi_device *dev,
1530 struct usb_interface *uinterf)
1533 struct usbduxfastsub_s *udfs;
1535 dev->private = NULL;
1536 down(&start_stop_sem);
1537 udfs = usb_get_intfdata(uinterf);
1538 if (!udfs || !udfs->probed) {
1539 dev_err(dev->class_dev,
1540 "usbduxfast: error: attach_usb failed, not connected\n");
1542 } else if (udfs->attached) {
1543 dev_err(dev->class_dev,
1544 "usbduxfast: error: attach_usb failed, already attached\n");
1547 ret = usbduxfast_attach_common(dev, udfs, NULL, 0);
1548 up(&start_stop_sem);
1552 static void usbduxfast_detach(struct comedi_device *dev)
1554 struct usbduxfastsub_s *usb = dev->private;
1558 down(&start_stop_sem);
1559 dev->private = NULL;
1561 usb->comedidev = NULL;
1562 up(&start_stop_sem);
1567 static struct comedi_driver usbduxfast_driver = {
1568 .driver_name = "usbduxfast",
1569 .module = THIS_MODULE,
1570 .attach = usbduxfast_attach,
1571 .detach = usbduxfast_detach,
1572 .attach_usb = usbduxfast_attach_usb,
1575 static void usbduxfast_firmware_request_complete_handler(const struct firmware
1578 struct usbduxfastsub_s *usbduxfastsub_tmp = context;
1579 struct usb_interface *uinterf = usbduxfastsub_tmp->interface;
1586 * we need to upload the firmware here because fw will be
1587 * freed once we've left this function
1589 ret = firmwareUpload(usbduxfastsub_tmp, fw->data, fw->size);
1592 dev_err(&uinterf->dev,
1593 "Could not upload firmware (err=%d)\n", ret);
1597 comedi_usb_auto_config(uinterf, &usbduxfast_driver);
1599 release_firmware(fw);
1602 static int usbduxfast_usb_probe(struct usb_interface *uinterf,
1603 const struct usb_device_id *id)
1605 struct usb_device *udev = interface_to_usbdev(uinterf);
1610 if (udev->speed != USB_SPEED_HIGH) {
1611 printk(KERN_ERR "comedi_: usbduxfast_: This driver needs"
1612 "USB 2.0 to operate. Aborting...\n");
1615 #ifdef CONFIG_COMEDI_DEBUG
1616 printk(KERN_DEBUG "comedi_: usbduxfast_: finding a free structure for "
1617 "the usb-device\n");
1619 down(&start_stop_sem);
1620 /* look for a free place in the usbduxfast array */
1622 for (i = 0; i < NUMUSBDUXFAST; i++) {
1623 if (!usbduxfastsub[i].probed) {
1631 printk(KERN_ERR "Too many usbduxfast-devices connected.\n");
1632 up(&start_stop_sem);
1635 #ifdef CONFIG_COMEDI_DEBUG
1636 printk(KERN_DEBUG "comedi_: usbduxfast: usbduxfastsub[%d] is ready to "
1637 "connect to comedi.\n", index);
1640 sema_init(&(usbduxfastsub[index].sem), 1);
1641 /* save a pointer to the usb device */
1642 usbduxfastsub[index].usbdev = udev;
1644 /* save the interface itself */
1645 usbduxfastsub[index].interface = uinterf;
1646 /* get the interface number from the interface */
1647 usbduxfastsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber;
1649 * hand the private data over to the usb subsystem
1650 * will be needed for disconnect
1652 usb_set_intfdata(uinterf, &(usbduxfastsub[index]));
1654 #ifdef CONFIG_COMEDI_DEBUG
1655 printk(KERN_DEBUG "comedi_: usbduxfast: ifnum=%d\n",
1656 usbduxfastsub[index].ifnum);
1658 /* create space for the commands going to the usb device */
1659 usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER,
1661 if (!usbduxfastsub[index].dux_commands) {
1662 printk(KERN_ERR "comedi_: usbduxfast: error alloc space for "
1664 tidy_up(&(usbduxfastsub[index]));
1665 up(&start_stop_sem);
1668 /* create space of the instruction buffer */
1669 usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL);
1670 if (!usbduxfastsub[index].insnBuffer) {
1671 printk(KERN_ERR "comedi_: usbduxfast: could not alloc space "
1672 "for insnBuffer\n");
1673 tidy_up(&(usbduxfastsub[index]));
1674 up(&start_stop_sem);
1677 /* setting to alternate setting 1: enabling bulk ep */
1678 i = usb_set_interface(usbduxfastsub[index].usbdev,
1679 usbduxfastsub[index].ifnum, 1);
1681 printk(KERN_ERR "comedi_: usbduxfast%d: could not switch to "
1682 "alternate setting 1.\n", index);
1683 tidy_up(&(usbduxfastsub[index]));
1684 up(&start_stop_sem);
1687 usbduxfastsub[index].urbIn = usb_alloc_urb(0, GFP_KERNEL);
1688 if (!usbduxfastsub[index].urbIn) {
1689 printk(KERN_ERR "comedi_: usbduxfast%d: Could not alloc."
1691 tidy_up(&(usbduxfastsub[index]));
1692 up(&start_stop_sem);
1695 usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL);
1696 if (!usbduxfastsub[index].transfer_buffer) {
1697 printk(KERN_ERR "comedi_: usbduxfast%d: could not alloc. "
1698 "transb.\n", index);
1699 tidy_up(&(usbduxfastsub[index]));
1700 up(&start_stop_sem);
1703 /* we've reached the bottom of the function */
1704 usbduxfastsub[index].probed = 1;
1705 up(&start_stop_sem);
1707 ret = request_firmware_nowait(THIS_MODULE,
1709 "usbduxfast_firmware.bin",
1712 usbduxfastsub + index,
1713 usbduxfast_firmware_request_complete_handler);
1716 dev_err(&udev->dev, "could not load firmware (err=%d)\n", ret);
1720 printk(KERN_INFO "comedi_: usbduxfast%d has been successfully "
1721 "initialized.\n", index);
1726 static void usbduxfast_usb_disconnect(struct usb_interface *intf)
1728 struct usbduxfastsub_s *udfs = usb_get_intfdata(intf);
1729 struct usb_device *udev = interface_to_usbdev(intf);
1732 printk(KERN_ERR "comedi_: usbduxfast: disconnect called with "
1736 if (udfs->usbdev != udev) {
1737 printk(KERN_ERR "comedi_: usbduxfast: BUG! called with wrong "
1742 comedi_usb_auto_unconfig(intf);
1744 down(&start_stop_sem);
1748 up(&start_stop_sem);
1750 #ifdef CONFIG_COMEDI_DEBUG
1751 printk(KERN_DEBUG "comedi_: usbduxfast: disconnected from the usb\n");
1755 static const struct usb_device_id usbduxfast_usb_table[] = {
1756 /* { USB_DEVICE(0x4b4, 0x8613) }, testing */
1757 { USB_DEVICE(0x13d8, 0x0010) }, /* real ID */
1758 { USB_DEVICE(0x13d8, 0x0011) }, /* real ID */
1761 MODULE_DEVICE_TABLE(usb, usbduxfast_usb_table);
1763 static struct usb_driver usbduxfast_usb_driver = {
1764 #ifdef COMEDI_HAVE_USB_DRIVER_OWNER
1765 .owner = THIS_MODULE,
1767 .name = "usbduxfast",
1768 .probe = usbduxfast_usb_probe,
1769 .disconnect = usbduxfast_usb_disconnect,
1770 .id_table = usbduxfast_usb_table,
1772 module_comedi_usb_driver(usbduxfast_driver, usbduxfast_usb_driver);
1774 MODULE_AUTHOR("Bernd Porr, BerndPorr@f2s.com");
1775 MODULE_DESCRIPTION("USB-DUXfast, BerndPorr@f2s.com");
1776 MODULE_LICENSE("GPL");