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 = devpriv->usb_rx_buf;
466 unsigned char *tx_buf = devpriv->usb_tx_buf;
470 if (devpriv->model == VMK8061_MODEL) {
471 reg = VMK8061_DO_REG;
472 cmd = VMK8061_CMD_DO;
473 } else { /* VMK8055_MODEL */
474 reg = VMK8055_DO_REG;
475 cmd = VMK8055_CMD_WRT_AD;
478 down(&devpriv->limit_sem);
480 if (comedi_dio_update_state(s, data)) {
481 tx_buf[reg] = s->state;
482 ret = vmk80xx_write_packet(dev, cmd);
487 if (devpriv->model == VMK8061_MODEL) {
488 tx_buf[0] = VMK8061_CMD_RD_DO;
489 ret = vmk80xx_read_packet(dev);
492 data[1] = rx_buf[reg];
498 up(&devpriv->limit_sem);
500 return ret ? ret : insn->n;
503 static int vmk80xx_cnt_insn_read(struct comedi_device *dev,
504 struct comedi_subdevice *s,
505 struct comedi_insn *insn,
508 struct vmk80xx_private *devpriv = dev->private;
513 down(&devpriv->limit_sem);
514 chan = CR_CHAN(insn->chanspec);
516 switch (devpriv->model) {
519 reg[0] = VMK8055_CNT1_REG;
521 reg[0] = VMK8055_CNT2_REG;
525 reg[0] = VMK8061_CNT_REG;
526 reg[1] = VMK8061_CNT_REG;
527 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_CNT;
531 for (n = 0; n < insn->n; n++) {
532 if (vmk80xx_read_packet(dev))
535 if (devpriv->model == VMK8055_MODEL)
536 data[n] = devpriv->usb_rx_buf[reg[0]];
537 else /* VMK8061_MODEL */
538 data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1]
539 + 256 * devpriv->usb_rx_buf[reg[1] * 2 + 2];
542 up(&devpriv->limit_sem);
547 static int vmk80xx_cnt_insn_config(struct comedi_device *dev,
548 struct comedi_subdevice *s,
549 struct comedi_insn *insn,
552 struct vmk80xx_private *devpriv = dev->private;
553 unsigned int insn_cmd;
560 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET)
563 down(&devpriv->limit_sem);
565 chan = CR_CHAN(insn->chanspec);
567 if (devpriv->model == VMK8055_MODEL) {
569 cmd = VMK8055_CMD_RST_CNT1;
570 reg = VMK8055_CNT1_REG;
572 cmd = VMK8055_CMD_RST_CNT2;
573 reg = VMK8055_CNT2_REG;
576 devpriv->usb_tx_buf[reg] = 0x00;
578 cmd = VMK8061_CMD_RST_CNT;
581 for (n = 0; n < insn->n; n++)
582 if (vmk80xx_write_packet(dev, cmd))
585 up(&devpriv->limit_sem);
590 static int vmk80xx_cnt_insn_write(struct comedi_device *dev,
591 struct comedi_subdevice *s,
592 struct comedi_insn *insn,
595 struct vmk80xx_private *devpriv = dev->private;
596 unsigned long debtime;
602 down(&devpriv->limit_sem);
603 chan = CR_CHAN(insn->chanspec);
606 cmd = VMK8055_CMD_DEB1_TIME;
608 cmd = VMK8055_CMD_DEB2_TIME;
610 for (n = 0; n < insn->n; n++) {
615 /* TODO: Prevent overflows */
619 val = int_sqrt(debtime * 1000 / 115);
620 if (((val + 1) * val) < debtime * 1000 / 115)
623 devpriv->usb_tx_buf[6 + chan] = val;
625 if (vmk80xx_write_packet(dev, cmd))
629 up(&devpriv->limit_sem);
634 static int vmk80xx_pwm_insn_read(struct comedi_device *dev,
635 struct comedi_subdevice *s,
636 struct comedi_insn *insn,
639 struct vmk80xx_private *devpriv = dev->private;
640 unsigned char *tx_buf;
641 unsigned char *rx_buf;
645 down(&devpriv->limit_sem);
647 tx_buf = devpriv->usb_tx_buf;
648 rx_buf = devpriv->usb_rx_buf;
650 reg[0] = VMK8061_PWM_REG1;
651 reg[1] = VMK8061_PWM_REG2;
653 tx_buf[0] = VMK8061_CMD_RD_PWM;
655 for (n = 0; n < insn->n; n++) {
656 if (vmk80xx_read_packet(dev))
659 data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]];
662 up(&devpriv->limit_sem);
667 static int vmk80xx_pwm_insn_write(struct comedi_device *dev,
668 struct comedi_subdevice *s,
669 struct comedi_insn *insn,
672 struct vmk80xx_private *devpriv = dev->private;
673 unsigned char *tx_buf;
678 down(&devpriv->limit_sem);
680 tx_buf = devpriv->usb_tx_buf;
682 reg[0] = VMK8061_PWM_REG1;
683 reg[1] = VMK8061_PWM_REG2;
685 cmd = VMK8061_CMD_OUT_PWM;
688 * The followin piece of code was translated from the inline
689 * assembler code in the DLL source code.
692 * mov eax, k ; k is the value (data[n])
693 * and al, 03h ; al are the lower 8 bits of eax
694 * mov lo, al ; lo is the low part (tx_buf[reg[0]])
696 * shr eax, 2 ; right shift eax register by 2
697 * mov hi, al ; hi is the high part (tx_buf[reg[1]])
700 for (n = 0; n < insn->n; n++) {
701 tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03);
702 tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff;
704 if (vmk80xx_write_packet(dev, cmd))
708 up(&devpriv->limit_sem);
713 static int vmk80xx_find_usb_endpoints(struct comedi_device *dev)
715 struct vmk80xx_private *devpriv = dev->private;
716 struct usb_interface *intf = comedi_to_usb_interface(dev);
717 struct usb_host_interface *iface_desc = intf->cur_altsetting;
718 struct usb_endpoint_descriptor *ep_desc;
721 if (iface_desc->desc.bNumEndpoints != 2)
724 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
725 ep_desc = &iface_desc->endpoint[i].desc;
727 if (usb_endpoint_is_int_in(ep_desc) ||
728 usb_endpoint_is_bulk_in(ep_desc)) {
730 devpriv->ep_rx = ep_desc;
734 if (usb_endpoint_is_int_out(ep_desc) ||
735 usb_endpoint_is_bulk_out(ep_desc)) {
737 devpriv->ep_tx = ep_desc;
742 if (!devpriv->ep_rx || !devpriv->ep_tx)
748 static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev)
750 struct vmk80xx_private *devpriv = dev->private;
753 size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
754 devpriv->usb_rx_buf = kzalloc(size, GFP_KERNEL);
755 if (!devpriv->usb_rx_buf)
758 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
759 devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL);
760 if (!devpriv->usb_tx_buf) {
761 kfree(devpriv->usb_rx_buf);
768 static int vmk80xx_init_subdevices(struct comedi_device *dev)
770 const struct vmk80xx_board *boardinfo = comedi_board(dev);
771 struct vmk80xx_private *devpriv = dev->private;
772 struct comedi_subdevice *s;
776 down(&devpriv->limit_sem);
778 if (devpriv->model == VMK8055_MODEL)
782 ret = comedi_alloc_subdevices(dev, n_subd);
784 up(&devpriv->limit_sem);
788 /* Analog input subdevice */
789 s = &dev->subdevices[0];
790 s->type = COMEDI_SUBD_AI;
791 s->subdev_flags = SDF_READABLE | SDF_GROUND;
792 s->n_chan = boardinfo->ai_nchans;
793 s->maxdata = boardinfo->ai_maxdata;
794 s->range_table = boardinfo->range;
795 s->insn_read = vmk80xx_ai_insn_read;
797 /* Analog output subdevice */
798 s = &dev->subdevices[1];
799 s->type = COMEDI_SUBD_AO;
800 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
801 s->n_chan = boardinfo->ao_nchans;
803 s->range_table = boardinfo->range;
804 s->insn_write = vmk80xx_ao_insn_write;
805 if (devpriv->model == VMK8061_MODEL) {
806 s->subdev_flags |= SDF_READABLE;
807 s->insn_read = vmk80xx_ao_insn_read;
810 /* Digital input subdevice */
811 s = &dev->subdevices[2];
812 s->type = COMEDI_SUBD_DI;
813 s->subdev_flags = SDF_READABLE;
814 s->n_chan = boardinfo->di_nchans;
816 s->range_table = &range_digital;
817 s->insn_bits = vmk80xx_di_insn_bits;
819 /* Digital output subdevice */
820 s = &dev->subdevices[3];
821 s->type = COMEDI_SUBD_DO;
822 s->subdev_flags = SDF_WRITEABLE;
825 s->range_table = &range_digital;
826 s->insn_bits = vmk80xx_do_insn_bits;
828 /* Counter subdevice */
829 s = &dev->subdevices[4];
830 s->type = COMEDI_SUBD_COUNTER;
831 s->subdev_flags = SDF_READABLE;
833 s->maxdata = boardinfo->cnt_maxdata;
834 s->insn_read = vmk80xx_cnt_insn_read;
835 s->insn_config = vmk80xx_cnt_insn_config;
836 if (devpriv->model == VMK8055_MODEL) {
837 s->subdev_flags |= SDF_WRITEABLE;
838 s->insn_write = vmk80xx_cnt_insn_write;
842 if (devpriv->model == VMK8061_MODEL) {
843 s = &dev->subdevices[5];
844 s->type = COMEDI_SUBD_PWM;
845 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE;
846 s->n_chan = boardinfo->pwm_nchans;
847 s->maxdata = boardinfo->pwm_maxdata;
848 s->insn_read = vmk80xx_pwm_insn_read;
849 s->insn_write = vmk80xx_pwm_insn_write;
852 up(&devpriv->limit_sem);
857 static int vmk80xx_auto_attach(struct comedi_device *dev,
858 unsigned long context)
860 struct usb_interface *intf = comedi_to_usb_interface(dev);
861 const struct vmk80xx_board *boardinfo;
862 struct vmk80xx_private *devpriv;
865 boardinfo = &vmk80xx_boardinfo[context];
866 dev->board_ptr = boardinfo;
867 dev->board_name = boardinfo->name;
869 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
873 devpriv->model = boardinfo->model;
875 ret = vmk80xx_find_usb_endpoints(dev);
879 ret = vmk80xx_alloc_usb_buffers(dev);
883 sema_init(&devpriv->limit_sem, 8);
885 usb_set_intfdata(intf, devpriv);
887 if (devpriv->model == VMK8061_MODEL) {
888 vmk80xx_read_eeprom(dev, IC3_VERSION);
889 dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers);
891 if (vmk80xx_check_data_link(dev)) {
892 vmk80xx_read_eeprom(dev, IC6_VERSION);
893 dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers);
897 if (devpriv->model == VMK8055_MODEL)
898 vmk80xx_reset_device(dev);
900 return vmk80xx_init_subdevices(dev);
903 static void vmk80xx_detach(struct comedi_device *dev)
905 struct usb_interface *intf = comedi_to_usb_interface(dev);
906 struct vmk80xx_private *devpriv = dev->private;
911 down(&devpriv->limit_sem);
913 usb_set_intfdata(intf, NULL);
915 kfree(devpriv->usb_rx_buf);
916 kfree(devpriv->usb_tx_buf);
918 up(&devpriv->limit_sem);
921 static struct comedi_driver vmk80xx_driver = {
922 .module = THIS_MODULE,
923 .driver_name = "vmk80xx",
924 .auto_attach = vmk80xx_auto_attach,
925 .detach = vmk80xx_detach,
928 static int vmk80xx_usb_probe(struct usb_interface *intf,
929 const struct usb_device_id *id)
931 return comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info);
934 static const struct usb_device_id vmk80xx_usb_id_table[] = {
935 { USB_DEVICE(0x10cf, 0x5500), .driver_info = DEVICE_VMK8055 },
936 { USB_DEVICE(0x10cf, 0x5501), .driver_info = DEVICE_VMK8055 },
937 { USB_DEVICE(0x10cf, 0x5502), .driver_info = DEVICE_VMK8055 },
938 { USB_DEVICE(0x10cf, 0x5503), .driver_info = DEVICE_VMK8055 },
939 { USB_DEVICE(0x10cf, 0x8061), .driver_info = DEVICE_VMK8061 },
940 { USB_DEVICE(0x10cf, 0x8062), .driver_info = DEVICE_VMK8061 },
941 { USB_DEVICE(0x10cf, 0x8063), .driver_info = DEVICE_VMK8061 },
942 { USB_DEVICE(0x10cf, 0x8064), .driver_info = DEVICE_VMK8061 },
943 { USB_DEVICE(0x10cf, 0x8065), .driver_info = DEVICE_VMK8061 },
944 { USB_DEVICE(0x10cf, 0x8066), .driver_info = DEVICE_VMK8061 },
945 { USB_DEVICE(0x10cf, 0x8067), .driver_info = DEVICE_VMK8061 },
946 { USB_DEVICE(0x10cf, 0x8068), .driver_info = DEVICE_VMK8061 },
949 MODULE_DEVICE_TABLE(usb, vmk80xx_usb_id_table);
951 static struct usb_driver vmk80xx_usb_driver = {
953 .id_table = vmk80xx_usb_id_table,
954 .probe = vmk80xx_usb_probe,
955 .disconnect = comedi_usb_auto_unconfig,
957 module_comedi_usb_driver(vmk80xx_driver, vmk80xx_usb_driver);
959 MODULE_AUTHOR("Manuel Gebele <forensixs@gmx.de>");
960 MODULE_DESCRIPTION("Velleman USB Board Low-Level Driver");
961 MODULE_SUPPORTED_DEVICE("K8055/K8061 aka VM110/VM140");
962 MODULE_LICENSE("GPL");