2 comedi/drivers/vmk80xx.c
3 Velleman USB Board Low-Level Driver
5 Copyright (C) 2009 Manuel Gebele <forensixs@gmx.de>, Germany
7 COMEDI - Linux Control and Measurement Device Interface
8 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
22 Description: Velleman USB Board Low-Level Driver
23 Devices: K8055/K8061 aka VM110/VM140
24 Author: Manuel Gebele <forensixs@gmx.de>
25 Updated: Sun, 10 May 2009 11:14:59 +0200
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/mutex.h>
40 #include <linux/errno.h>
41 #include <linux/input.h>
42 #include <linux/slab.h>
43 #include <linux/poll.h>
44 #include <linux/usb.h>
45 #include <linux/uaccess.h>
47 #include "../comedidev.h"
54 #define VMK8055_DI_REG 0x00
55 #define VMK8055_DO_REG 0x01
56 #define VMK8055_AO1_REG 0x02
57 #define VMK8055_AO2_REG 0x03
58 #define VMK8055_AI1_REG 0x02
59 #define VMK8055_AI2_REG 0x03
60 #define VMK8055_CNT1_REG 0x04
61 #define VMK8055_CNT2_REG 0x06
63 #define VMK8061_CH_REG 0x01
64 #define VMK8061_DI_REG 0x01
65 #define VMK8061_DO_REG 0x01
66 #define VMK8061_PWM_REG1 0x01
67 #define VMK8061_PWM_REG2 0x02
68 #define VMK8061_CNT_REG 0x02
69 #define VMK8061_AO_REG 0x02
70 #define VMK8061_AI_REG1 0x02
71 #define VMK8061_AI_REG2 0x03
73 #define VMK8055_CMD_RST 0x00
74 #define VMK8055_CMD_DEB1_TIME 0x01
75 #define VMK8055_CMD_DEB2_TIME 0x02
76 #define VMK8055_CMD_RST_CNT1 0x03
77 #define VMK8055_CMD_RST_CNT2 0x04
78 #define VMK8055_CMD_WRT_AD 0x05
80 #define VMK8061_CMD_RD_AI 0x00
81 #define VMK8061_CMR_RD_ALL_AI 0x01 /* !non-active! */
82 #define VMK8061_CMD_SET_AO 0x02
83 #define VMK8061_CMD_SET_ALL_AO 0x03 /* !non-active! */
84 #define VMK8061_CMD_OUT_PWM 0x04
85 #define VMK8061_CMD_RD_DI 0x05
86 #define VMK8061_CMD_DO 0x06 /* !non-active! */
87 #define VMK8061_CMD_CLR_DO 0x07
88 #define VMK8061_CMD_SET_DO 0x08
89 #define VMK8061_CMD_RD_CNT 0x09 /* TODO: completely pointless? */
90 #define VMK8061_CMD_RST_CNT 0x0a /* TODO: completely pointless? */
91 #define VMK8061_CMD_RD_VERSION 0x0b /* internal usage */
92 #define VMK8061_CMD_RD_JMP_STAT 0x0c /* TODO: not implemented yet */
93 #define VMK8061_CMD_RD_PWR_STAT 0x0d /* internal usage */
94 #define VMK8061_CMD_RD_DO 0x0e
95 #define VMK8061_CMD_RD_AO 0x0f
96 #define VMK8061_CMD_RD_PWM 0x10
98 #define IC3_VERSION (1 << 0)
99 #define IC6_VERSION (1 << 1)
106 struct firmware_version {
107 unsigned char ic3_vers[32]; /* USB-Controller */
108 unsigned char ic6_vers[32]; /* CPU */
111 static const struct comedi_lrange vmk8061_range = {
118 struct vmk80xx_board {
120 enum vmk80xx_model model;
121 const struct comedi_lrange *range;
123 unsigned int ai_maxdata;
126 unsigned int cnt_maxdata;
128 unsigned int pwm_maxdata;
131 static const struct vmk80xx_board vmk80xx_boardinfo[] = {
133 .name = "K8055 (VM110)",
134 .model = VMK8055_MODEL,
135 .range = &range_unipolar5,
137 .ai_maxdata = 0x00ff,
140 .cnt_maxdata = 0xffff,
143 .name = "K8061 (VM140)",
144 .model = VMK8061_MODEL,
145 .range = &vmk8061_range,
147 .ai_maxdata = 0x03ff,
150 .cnt_maxdata = 0, /* unknown, device is not writeable */
152 .pwm_maxdata = 0x03ff,
156 struct vmk80xx_private {
157 struct usb_endpoint_descriptor *ep_rx;
158 struct usb_endpoint_descriptor *ep_tx;
159 struct firmware_version fw;
160 struct semaphore limit_sem;
161 unsigned char *usb_rx_buf;
162 unsigned char *usb_tx_buf;
163 enum vmk80xx_model model;
166 static int vmk80xx_check_data_link(struct comedi_device *dev)
168 struct vmk80xx_private *devpriv = dev->private;
169 struct usb_device *usb = comedi_to_usb_dev(dev);
170 unsigned int tx_pipe;
171 unsigned int rx_pipe;
175 tx_pipe = usb_sndbulkpipe(usb, 0x01);
176 rx_pipe = usb_rcvbulkpipe(usb, 0x81);
178 tx[0] = VMK8061_CMD_RD_PWR_STAT;
181 * Check that IC6 (PIC16F871) is powered and
182 * running and the data link between IC3 and
183 * IC6 is working properly
185 usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
186 usb_bulk_msg(usb, rx_pipe, rx, 2, NULL, HZ * 10);
191 static void vmk80xx_read_eeprom(struct comedi_device *dev, int flag)
193 struct vmk80xx_private *devpriv = dev->private;
194 struct usb_device *usb = comedi_to_usb_dev(dev);
195 unsigned int tx_pipe;
196 unsigned int rx_pipe;
198 unsigned char rx[64];
201 tx_pipe = usb_sndbulkpipe(usb, 0x01);
202 rx_pipe = usb_rcvbulkpipe(usb, 0x81);
204 tx[0] = VMK8061_CMD_RD_VERSION;
207 * Read the firmware version info of IC3 and
208 * IC6 from the internal EEPROM of the IC
210 usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
211 usb_bulk_msg(usb, rx_pipe, rx, 64, &cnt, HZ * 10);
215 if (flag & IC3_VERSION)
216 strncpy(devpriv->fw.ic3_vers, rx + 1, 24);
217 else /* IC6_VERSION */
218 strncpy(devpriv->fw.ic6_vers, rx + 25, 24);
221 static void vmk80xx_do_bulk_msg(struct comedi_device *dev)
223 struct vmk80xx_private *devpriv = dev->private;
224 struct usb_device *usb = comedi_to_usb_dev(dev);
227 unsigned int tx_pipe;
228 unsigned int rx_pipe;
231 tx_addr = devpriv->ep_tx->bEndpointAddress;
232 rx_addr = devpriv->ep_rx->bEndpointAddress;
233 tx_pipe = usb_sndbulkpipe(usb, tx_addr);
234 rx_pipe = usb_rcvbulkpipe(usb, rx_addr);
237 * The max packet size attributes of the K8061
238 * input/output endpoints are identical
240 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
242 usb_bulk_msg(usb, tx_pipe, devpriv->usb_tx_buf,
243 size, NULL, devpriv->ep_tx->bInterval);
244 usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10);
247 static int vmk80xx_read_packet(struct comedi_device *dev)
249 struct vmk80xx_private *devpriv = dev->private;
250 struct usb_device *usb = comedi_to_usb_dev(dev);
251 struct usb_endpoint_descriptor *ep;
254 if (devpriv->model == VMK8061_MODEL) {
255 vmk80xx_do_bulk_msg(dev);
260 pipe = usb_rcvintpipe(usb, ep->bEndpointAddress);
261 return usb_interrupt_msg(usb, pipe, devpriv->usb_rx_buf,
262 le16_to_cpu(ep->wMaxPacketSize), NULL,
266 static int vmk80xx_write_packet(struct comedi_device *dev, int cmd)
268 struct vmk80xx_private *devpriv = dev->private;
269 struct usb_device *usb = comedi_to_usb_dev(dev);
270 struct usb_endpoint_descriptor *ep;
273 devpriv->usb_tx_buf[0] = cmd;
275 if (devpriv->model == VMK8061_MODEL) {
276 vmk80xx_do_bulk_msg(dev);
281 pipe = usb_sndintpipe(usb, ep->bEndpointAddress);
282 return usb_interrupt_msg(usb, pipe, devpriv->usb_tx_buf,
283 le16_to_cpu(ep->wMaxPacketSize), NULL,
287 static int vmk80xx_reset_device(struct comedi_device *dev)
289 struct vmk80xx_private *devpriv = dev->private;
293 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
294 memset(devpriv->usb_tx_buf, 0, size);
295 retval = vmk80xx_write_packet(dev, VMK8055_CMD_RST);
298 /* set outputs to known state as we cannot read them */
299 return vmk80xx_write_packet(dev, VMK8055_CMD_WRT_AD);
302 static int vmk80xx_ai_insn_read(struct comedi_device *dev,
303 struct comedi_subdevice *s,
304 struct comedi_insn *insn,
307 struct vmk80xx_private *devpriv = dev->private;
312 down(&devpriv->limit_sem);
313 chan = CR_CHAN(insn->chanspec);
315 switch (devpriv->model) {
318 reg[0] = VMK8055_AI1_REG;
320 reg[0] = VMK8055_AI2_REG;
324 reg[0] = VMK8061_AI_REG1;
325 reg[1] = VMK8061_AI_REG2;
326 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AI;
327 devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
331 for (n = 0; n < insn->n; n++) {
332 if (vmk80xx_read_packet(dev))
335 if (devpriv->model == VMK8055_MODEL) {
336 data[n] = devpriv->usb_rx_buf[reg[0]];
341 data[n] = devpriv->usb_rx_buf[reg[0]] + 256 *
342 devpriv->usb_rx_buf[reg[1]];
345 up(&devpriv->limit_sem);
350 static int vmk80xx_ao_insn_write(struct comedi_device *dev,
351 struct comedi_subdevice *s,
352 struct comedi_insn *insn,
355 struct vmk80xx_private *devpriv = dev->private;
361 down(&devpriv->limit_sem);
362 chan = CR_CHAN(insn->chanspec);
364 switch (devpriv->model) {
366 cmd = VMK8055_CMD_WRT_AD;
368 reg = VMK8055_AO1_REG;
370 reg = VMK8055_AO2_REG;
372 default: /* NOTE: avoid compiler warnings */
373 cmd = VMK8061_CMD_SET_AO;
374 reg = VMK8061_AO_REG;
375 devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
379 for (n = 0; n < insn->n; n++) {
380 devpriv->usb_tx_buf[reg] = data[n];
382 if (vmk80xx_write_packet(dev, cmd))
386 up(&devpriv->limit_sem);
391 static int vmk80xx_ao_insn_read(struct comedi_device *dev,
392 struct comedi_subdevice *s,
393 struct comedi_insn *insn,
396 struct vmk80xx_private *devpriv = dev->private;
401 down(&devpriv->limit_sem);
402 chan = CR_CHAN(insn->chanspec);
404 reg = VMK8061_AO_REG - 1;
406 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AO;
408 for (n = 0; n < insn->n; n++) {
409 if (vmk80xx_read_packet(dev))
412 data[n] = devpriv->usb_rx_buf[reg + chan];
415 up(&devpriv->limit_sem);
420 static int vmk80xx_di_insn_bits(struct comedi_device *dev,
421 struct comedi_subdevice *s,
422 struct comedi_insn *insn,
425 struct vmk80xx_private *devpriv = dev->private;
426 unsigned char *rx_buf;
430 down(&devpriv->limit_sem);
432 rx_buf = devpriv->usb_rx_buf;
434 if (devpriv->model == VMK8061_MODEL) {
435 reg = VMK8061_DI_REG;
436 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI;
438 reg = VMK8055_DI_REG;
441 retval = vmk80xx_read_packet(dev);
444 if (devpriv->model == VMK8055_MODEL)
445 data[1] = (((rx_buf[reg] >> 4) & 0x03) |
446 ((rx_buf[reg] << 2) & 0x04) |
447 ((rx_buf[reg] >> 3) & 0x18));
449 data[1] = rx_buf[reg];
454 up(&devpriv->limit_sem);
459 static int vmk80xx_do_insn_bits(struct comedi_device *dev,
460 struct comedi_subdevice *s,
461 struct comedi_insn *insn,
464 struct vmk80xx_private *devpriv = dev->private;
465 unsigned char *rx_buf, *tx_buf;
469 if (devpriv->model == VMK8061_MODEL) {
470 reg = VMK8061_DO_REG;
471 cmd = VMK8061_CMD_DO;
472 } else { /* VMK8055_MODEL */
473 reg = VMK8055_DO_REG;
474 cmd = VMK8055_CMD_WRT_AD;
477 down(&devpriv->limit_sem);
479 rx_buf = devpriv->usb_rx_buf;
480 tx_buf = devpriv->usb_tx_buf;
483 tx_buf[reg] &= ~data[0];
484 tx_buf[reg] |= (data[0] & data[1]);
486 retval = vmk80xx_write_packet(dev, cmd);
492 if (devpriv->model == VMK8061_MODEL) {
493 tx_buf[0] = VMK8061_CMD_RD_DO;
495 retval = vmk80xx_read_packet(dev);
498 data[1] = rx_buf[reg];
502 data[1] = tx_buf[reg];
507 up(&devpriv->limit_sem);
512 static int vmk80xx_cnt_insn_read(struct comedi_device *dev,
513 struct comedi_subdevice *s,
514 struct comedi_insn *insn,
517 struct vmk80xx_private *devpriv = dev->private;
522 down(&devpriv->limit_sem);
523 chan = CR_CHAN(insn->chanspec);
525 switch (devpriv->model) {
528 reg[0] = VMK8055_CNT1_REG;
530 reg[0] = VMK8055_CNT2_REG;
534 reg[0] = VMK8061_CNT_REG;
535 reg[1] = VMK8061_CNT_REG;
536 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_CNT;
540 for (n = 0; n < insn->n; n++) {
541 if (vmk80xx_read_packet(dev))
544 if (devpriv->model == VMK8055_MODEL)
545 data[n] = devpriv->usb_rx_buf[reg[0]];
546 else /* VMK8061_MODEL */
547 data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1]
548 + 256 * devpriv->usb_rx_buf[reg[1] * 2 + 2];
551 up(&devpriv->limit_sem);
556 static int vmk80xx_cnt_insn_config(struct comedi_device *dev,
557 struct comedi_subdevice *s,
558 struct comedi_insn *insn,
561 struct vmk80xx_private *devpriv = dev->private;
562 unsigned int insn_cmd;
569 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET)
572 down(&devpriv->limit_sem);
574 chan = CR_CHAN(insn->chanspec);
576 if (devpriv->model == VMK8055_MODEL) {
578 cmd = VMK8055_CMD_RST_CNT1;
579 reg = VMK8055_CNT1_REG;
581 cmd = VMK8055_CMD_RST_CNT2;
582 reg = VMK8055_CNT2_REG;
585 devpriv->usb_tx_buf[reg] = 0x00;
587 cmd = VMK8061_CMD_RST_CNT;
590 for (n = 0; n < insn->n; n++)
591 if (vmk80xx_write_packet(dev, cmd))
594 up(&devpriv->limit_sem);
599 static int vmk80xx_cnt_insn_write(struct comedi_device *dev,
600 struct comedi_subdevice *s,
601 struct comedi_insn *insn,
604 struct vmk80xx_private *devpriv = dev->private;
605 unsigned long debtime;
611 down(&devpriv->limit_sem);
612 chan = CR_CHAN(insn->chanspec);
615 cmd = VMK8055_CMD_DEB1_TIME;
617 cmd = VMK8055_CMD_DEB2_TIME;
619 for (n = 0; n < insn->n; n++) {
624 /* TODO: Prevent overflows */
628 val = int_sqrt(debtime * 1000 / 115);
629 if (((val + 1) * val) < debtime * 1000 / 115)
632 devpriv->usb_tx_buf[6 + chan] = val;
634 if (vmk80xx_write_packet(dev, cmd))
638 up(&devpriv->limit_sem);
643 static int vmk80xx_pwm_insn_read(struct comedi_device *dev,
644 struct comedi_subdevice *s,
645 struct comedi_insn *insn,
648 struct vmk80xx_private *devpriv = dev->private;
649 unsigned char *tx_buf;
650 unsigned char *rx_buf;
654 down(&devpriv->limit_sem);
656 tx_buf = devpriv->usb_tx_buf;
657 rx_buf = devpriv->usb_rx_buf;
659 reg[0] = VMK8061_PWM_REG1;
660 reg[1] = VMK8061_PWM_REG2;
662 tx_buf[0] = VMK8061_CMD_RD_PWM;
664 for (n = 0; n < insn->n; n++) {
665 if (vmk80xx_read_packet(dev))
668 data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]];
671 up(&devpriv->limit_sem);
676 static int vmk80xx_pwm_insn_write(struct comedi_device *dev,
677 struct comedi_subdevice *s,
678 struct comedi_insn *insn,
681 struct vmk80xx_private *devpriv = dev->private;
682 unsigned char *tx_buf;
687 down(&devpriv->limit_sem);
689 tx_buf = devpriv->usb_tx_buf;
691 reg[0] = VMK8061_PWM_REG1;
692 reg[1] = VMK8061_PWM_REG2;
694 cmd = VMK8061_CMD_OUT_PWM;
697 * The followin piece of code was translated from the inline
698 * assembler code in the DLL source code.
701 * mov eax, k ; k is the value (data[n])
702 * and al, 03h ; al are the lower 8 bits of eax
703 * mov lo, al ; lo is the low part (tx_buf[reg[0]])
705 * shr eax, 2 ; right shift eax register by 2
706 * mov hi, al ; hi is the high part (tx_buf[reg[1]])
709 for (n = 0; n < insn->n; n++) {
710 tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03);
711 tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff;
713 if (vmk80xx_write_packet(dev, cmd))
717 up(&devpriv->limit_sem);
722 static int vmk80xx_find_usb_endpoints(struct comedi_device *dev)
724 struct vmk80xx_private *devpriv = dev->private;
725 struct usb_interface *intf = comedi_to_usb_interface(dev);
726 struct usb_host_interface *iface_desc = intf->cur_altsetting;
727 struct usb_endpoint_descriptor *ep_desc;
730 if (iface_desc->desc.bNumEndpoints != 2)
733 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
734 ep_desc = &iface_desc->endpoint[i].desc;
736 if (usb_endpoint_is_int_in(ep_desc) ||
737 usb_endpoint_is_bulk_in(ep_desc)) {
739 devpriv->ep_rx = ep_desc;
743 if (usb_endpoint_is_int_out(ep_desc) ||
744 usb_endpoint_is_bulk_out(ep_desc)) {
746 devpriv->ep_tx = ep_desc;
751 if (!devpriv->ep_rx || !devpriv->ep_tx)
757 static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev)
759 struct vmk80xx_private *devpriv = dev->private;
762 size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
763 devpriv->usb_rx_buf = kzalloc(size, GFP_KERNEL);
764 if (!devpriv->usb_rx_buf)
767 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
768 devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL);
769 if (!devpriv->usb_tx_buf) {
770 kfree(devpriv->usb_rx_buf);
777 static int vmk80xx_init_subdevices(struct comedi_device *dev)
779 const struct vmk80xx_board *boardinfo = comedi_board(dev);
780 struct vmk80xx_private *devpriv = dev->private;
781 struct comedi_subdevice *s;
785 down(&devpriv->limit_sem);
787 if (devpriv->model == VMK8055_MODEL)
791 ret = comedi_alloc_subdevices(dev, n_subd);
793 up(&devpriv->limit_sem);
797 /* Analog input subdevice */
798 s = &dev->subdevices[0];
799 s->type = COMEDI_SUBD_AI;
800 s->subdev_flags = SDF_READABLE | SDF_GROUND;
801 s->n_chan = boardinfo->ai_nchans;
802 s->maxdata = boardinfo->ai_maxdata;
803 s->range_table = boardinfo->range;
804 s->insn_read = vmk80xx_ai_insn_read;
806 /* Analog output subdevice */
807 s = &dev->subdevices[1];
808 s->type = COMEDI_SUBD_AO;
809 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
810 s->n_chan = boardinfo->ao_nchans;
812 s->range_table = boardinfo->range;
813 s->insn_write = vmk80xx_ao_insn_write;
814 if (devpriv->model == VMK8061_MODEL) {
815 s->subdev_flags |= SDF_READABLE;
816 s->insn_read = vmk80xx_ao_insn_read;
819 /* Digital input subdevice */
820 s = &dev->subdevices[2];
821 s->type = COMEDI_SUBD_DI;
822 s->subdev_flags = SDF_READABLE;
823 s->n_chan = boardinfo->di_nchans;
825 s->range_table = &range_digital;
826 s->insn_bits = vmk80xx_di_insn_bits;
828 /* Digital output subdevice */
829 s = &dev->subdevices[3];
830 s->type = COMEDI_SUBD_DO;
831 s->subdev_flags = SDF_WRITEABLE;
834 s->range_table = &range_digital;
835 s->insn_bits = vmk80xx_do_insn_bits;
837 /* Counter subdevice */
838 s = &dev->subdevices[4];
839 s->type = COMEDI_SUBD_COUNTER;
840 s->subdev_flags = SDF_READABLE;
842 s->maxdata = boardinfo->cnt_maxdata;
843 s->insn_read = vmk80xx_cnt_insn_read;
844 s->insn_config = vmk80xx_cnt_insn_config;
845 if (devpriv->model == VMK8055_MODEL) {
846 s->subdev_flags |= SDF_WRITEABLE;
847 s->insn_write = vmk80xx_cnt_insn_write;
851 if (devpriv->model == VMK8061_MODEL) {
852 s = &dev->subdevices[5];
853 s->type = COMEDI_SUBD_PWM;
854 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE;
855 s->n_chan = boardinfo->pwm_nchans;
856 s->maxdata = boardinfo->pwm_maxdata;
857 s->insn_read = vmk80xx_pwm_insn_read;
858 s->insn_write = vmk80xx_pwm_insn_write;
861 up(&devpriv->limit_sem);
866 static int vmk80xx_auto_attach(struct comedi_device *dev,
867 unsigned long context)
869 struct usb_interface *intf = comedi_to_usb_interface(dev);
870 const struct vmk80xx_board *boardinfo;
871 struct vmk80xx_private *devpriv;
874 boardinfo = &vmk80xx_boardinfo[context];
875 dev->board_ptr = boardinfo;
876 dev->board_name = boardinfo->name;
878 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
882 devpriv->model = boardinfo->model;
884 ret = vmk80xx_find_usb_endpoints(dev);
888 ret = vmk80xx_alloc_usb_buffers(dev);
892 sema_init(&devpriv->limit_sem, 8);
894 usb_set_intfdata(intf, devpriv);
896 if (devpriv->model == VMK8061_MODEL) {
897 vmk80xx_read_eeprom(dev, IC3_VERSION);
898 dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers);
900 if (vmk80xx_check_data_link(dev)) {
901 vmk80xx_read_eeprom(dev, IC6_VERSION);
902 dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers);
906 if (devpriv->model == VMK8055_MODEL)
907 vmk80xx_reset_device(dev);
909 return vmk80xx_init_subdevices(dev);
912 static void vmk80xx_detach(struct comedi_device *dev)
914 struct usb_interface *intf = comedi_to_usb_interface(dev);
915 struct vmk80xx_private *devpriv = dev->private;
920 down(&devpriv->limit_sem);
922 usb_set_intfdata(intf, NULL);
924 kfree(devpriv->usb_rx_buf);
925 kfree(devpriv->usb_tx_buf);
927 up(&devpriv->limit_sem);
930 static struct comedi_driver vmk80xx_driver = {
931 .module = THIS_MODULE,
932 .driver_name = "vmk80xx",
933 .auto_attach = vmk80xx_auto_attach,
934 .detach = vmk80xx_detach,
937 static int vmk80xx_usb_probe(struct usb_interface *intf,
938 const struct usb_device_id *id)
940 return comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info);
943 static const struct usb_device_id vmk80xx_usb_id_table[] = {
944 { USB_DEVICE(0x10cf, 0x5500), .driver_info = DEVICE_VMK8055 },
945 { USB_DEVICE(0x10cf, 0x5501), .driver_info = DEVICE_VMK8055 },
946 { USB_DEVICE(0x10cf, 0x5502), .driver_info = DEVICE_VMK8055 },
947 { USB_DEVICE(0x10cf, 0x5503), .driver_info = DEVICE_VMK8055 },
948 { USB_DEVICE(0x10cf, 0x8061), .driver_info = DEVICE_VMK8061 },
949 { USB_DEVICE(0x10cf, 0x8062), .driver_info = DEVICE_VMK8061 },
950 { USB_DEVICE(0x10cf, 0x8063), .driver_info = DEVICE_VMK8061 },
951 { USB_DEVICE(0x10cf, 0x8064), .driver_info = DEVICE_VMK8061 },
952 { USB_DEVICE(0x10cf, 0x8065), .driver_info = DEVICE_VMK8061 },
953 { USB_DEVICE(0x10cf, 0x8066), .driver_info = DEVICE_VMK8061 },
954 { USB_DEVICE(0x10cf, 0x8067), .driver_info = DEVICE_VMK8061 },
955 { USB_DEVICE(0x10cf, 0x8068), .driver_info = DEVICE_VMK8061 },
958 MODULE_DEVICE_TABLE(usb, vmk80xx_usb_id_table);
960 static struct usb_driver vmk80xx_usb_driver = {
962 .id_table = vmk80xx_usb_id_table,
963 .probe = vmk80xx_usb_probe,
964 .disconnect = comedi_usb_auto_unconfig,
966 module_comedi_usb_driver(vmk80xx_driver, vmk80xx_usb_driver);
968 MODULE_AUTHOR("Manuel Gebele <forensixs@gmx.de>");
969 MODULE_DESCRIPTION("Velleman USB Board Low-Level Driver");
970 MODULE_SUPPORTED_DEVICE("K8055/K8061 aka VM110/VM140");
971 MODULE_VERSION("0.8.01");
972 MODULE_LICENSE("GPL");