55 #include <linux/kernel.h>
56 #include <linux/module.h>
58 #include <linux/errno.h>
59 #include <linux/input.h>
60 #include <linux/slab.h>
61 #include <linux/poll.h>
65 #include "../comedidev.h"
72 #define VMK8055_DI_REG 0x00
73 #define VMK8055_DO_REG 0x01
74 #define VMK8055_AO1_REG 0x02
75 #define VMK8055_AO2_REG 0x03
76 #define VMK8055_AI1_REG 0x02
77 #define VMK8055_AI2_REG 0x03
78 #define VMK8055_CNT1_REG 0x04
79 #define VMK8055_CNT2_REG 0x06
81 #define VMK8061_CH_REG 0x01
82 #define VMK8061_DI_REG 0x01
83 #define VMK8061_DO_REG 0x01
84 #define VMK8061_PWM_REG1 0x01
85 #define VMK8061_PWM_REG2 0x02
86 #define VMK8061_CNT_REG 0x02
87 #define VMK8061_AO_REG 0x02
88 #define VMK8061_AI_REG1 0x02
89 #define VMK8061_AI_REG2 0x03
91 #define VMK8055_CMD_RST 0x00
92 #define VMK8055_CMD_DEB1_TIME 0x01
93 #define VMK8055_CMD_DEB2_TIME 0x02
94 #define VMK8055_CMD_RST_CNT1 0x03
95 #define VMK8055_CMD_RST_CNT2 0x04
96 #define VMK8055_CMD_WRT_AD 0x05
98 #define VMK8061_CMD_RD_AI 0x00
99 #define VMK8061_CMR_RD_ALL_AI 0x01
100 #define VMK8061_CMD_SET_AO 0x02
101 #define VMK8061_CMD_SET_ALL_AO 0x03
102 #define VMK8061_CMD_OUT_PWM 0x04
103 #define VMK8061_CMD_RD_DI 0x05
104 #define VMK8061_CMD_DO 0x06
105 #define VMK8061_CMD_CLR_DO 0x07
106 #define VMK8061_CMD_SET_DO 0x08
107 #define VMK8061_CMD_RD_CNT 0x09
108 #define VMK8061_CMD_RST_CNT 0x0a
109 #define VMK8061_CMD_RD_VERSION 0x0b
110 #define VMK8061_CMD_RD_JMP_STAT 0x0c
111 #define VMK8061_CMD_RD_PWR_STAT 0x0d
112 #define VMK8061_CMD_RD_DO 0x0e
113 #define VMK8061_CMD_RD_AO 0x0f
114 #define VMK8061_CMD_RD_PWM 0x10
116 #define VMK80XX_MAX_BOARDS COMEDI_NUM_BOARD_MINORS
118 #define TRANS_OUT_BUSY 1
119 #define TRANS_IN_BUSY 2
120 #define TRANS_IN_RUNNING 3
122 #define IC3_VERSION (1 << 0)
123 #define IC6_VERSION (1 << 1)
125 #define URB_RCV_FLAG (1 << 0)
126 #define URB_SND_FLAG (1 << 1)
128 #ifdef CONFIG_COMEDI_DEBUG
129 static int dbgcm = 1;
134 #define dbgcm(fmt, arg...) \
137 printk(KERN_DEBUG fmt, ##arg); \
209 static void vmk80xx_tx_callback(
struct urb *
urb)
212 int stat = urb->status;
214 if (stat && !(stat == -
ENOENT
216 dbgcm(
"comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
227 static void vmk80xx_rx_callback(
struct urb *urb)
230 int stat = urb->status;
240 dbgcm(
"comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
254 "comedi#: vmk80xx: %s - submit urb failed\n",
265 static int vmk80xx_check_data_link(
struct vmk80xx_usb *dev)
267 unsigned int tx_pipe;
268 unsigned int rx_pipe;
272 tx_pipe = usb_sndbulkpipe(dev->
udev, 0x01);
273 rx_pipe = usb_rcvbulkpipe(dev->
udev, 0x81);
290 unsigned int tx_pipe;
291 unsigned int rx_pipe;
293 unsigned char rx[64];
296 tx_pipe = usb_sndbulkpipe(dev->
udev, 0x01);
297 rx_pipe = usb_rcvbulkpipe(dev->
udev, 0x81);
316 static int vmk80xx_reset_device(
struct vmk80xx_usb *dev)
319 unsigned int tx_pipe;
327 tx_pipe = usb_sndintpipe(dev->
udev, 0x01);
329 ival = dev->
ep_tx->bInterval;
342 size, vmk80xx_tx_callback, dev, ival);
349 static void vmk80xx_build_int_urb(
struct urb *urb,
int flag)
361 rx_addr = dev->
ep_rx->bEndpointAddress;
362 pipe = usb_rcvintpipe(dev->
udev, rx_addr);
366 ival = dev->
ep_rx->bInterval;
368 tx_addr = dev->
ep_tx->bEndpointAddress;
369 pipe = usb_sndintpipe(dev->
udev, tx_addr);
373 ival = dev->
ep_tx->bInterval;
376 usb_fill_int_urb(urb, dev->
udev, pipe, buf, size,
callback, dev, ival);
379 static void vmk80xx_do_bulk_msg(
struct vmk80xx_usb *dev)
383 unsigned int tx_pipe;
384 unsigned int rx_pipe;
390 tx_addr = dev->
ep_tx->bEndpointAddress;
391 rx_addr = dev->
ep_rx->bEndpointAddress;
392 tx_pipe = usb_sndbulkpipe(dev->
udev, tx_addr);
393 rx_pipe = usb_rcvbulkpipe(dev->
udev, rx_addr);
409 static int vmk80xx_read_packet(
struct vmk80xx_usb *dev)
425 vmk80xx_do_bulk_msg(dev);
471 vmk80xx_do_bulk_msg(dev);
505 static int rudimentary_check(
struct vmk80xx_usb *dev,
int dir)
534 n = rudimentary_check(dev,
DIR_IN);
541 switch (dev->
board.model) {
557 for (n = 0; n < insn->
n; n++) {
558 if (vmk80xx_read_packet(dev))
586 n = rudimentary_check(dev,
DIR_OUT);
593 switch (dev->
board.model) {
608 for (n = 0; n < insn->
n; n++) {
611 if (vmk80xx_write_packet(dev, cmd))
629 n = rudimentary_check(dev,
DIR_IN);
640 for (n = 0; n < insn->
n; n++) {
641 if (vmk80xx_read_packet(dev))
657 unsigned char *rx_buf;
661 retval = rudimentary_check(dev,
DIR_IN);
676 retval = vmk80xx_read_packet(dev);
680 data[1] = (((rx_buf[
reg] >> 4) & 0x03) |
681 ((rx_buf[
reg] << 2) & 0x04) |
682 ((rx_buf[
reg] >> 3) & 0x18));
684 data[1] = rx_buf[
reg];
700 unsigned char *rx_buf;
705 n = rudimentary_check(dev,
DIR_IN);
720 for (n = 0; n < insn->
n; n++) {
721 if (vmk80xx_read_packet(dev))
725 inp = (((rx_buf[
reg] >> 4) & 0x03) |
726 ((rx_buf[
reg] << 2) & 0x04) |
727 ((rx_buf[
reg] >> 3) & 0x18));
731 data[
n] = (inp >> chan) & 1;
750 n = rudimentary_check(dev,
DIR_OUT);
759 for (n = 0; n < insn->
n; n++) {
764 tx_buf[
reg] |= (1 << chan);
766 tx_buf[
reg] ^= (1 << chan);
771 tx_buf[
reg] = 1 << chan;
774 tx_buf[
reg] = 0xff - (1 << chan);
778 if (vmk80xx_write_packet(dev, cmd))
796 n = rudimentary_check(dev,
DIR_IN);
807 for (n = 0; n < insn->
n; n++) {
808 if (vmk80xx_read_packet(dev))
824 unsigned char *rx_buf, *tx_buf;
836 retval = rudimentary_check(dev, dir);
854 tx_buf[
reg] &= ~data[0];
855 tx_buf[
reg] |= (data[0] & data[1]);
857 retval = vmk80xx_write_packet(dev, cmd);
867 retval = vmk80xx_read_packet(dev);
870 data[1] = rx_buf[
reg];
874 data[1] = tx_buf[
reg];
893 n = rudimentary_check(dev,
DIR_IN);
900 switch (dev->
board.model) {
915 for (n = 0; n < insn->
n; n++) {
916 if (vmk80xx_read_packet(dev))
936 unsigned int insn_cmd;
942 n = rudimentary_check(dev,
DIR_OUT);
968 for (n = 0; n < insn->
n; n++)
969 if (vmk80xx_write_packet(dev, cmd))
982 unsigned long debtime;
988 n = rudimentary_check(dev,
DIR_OUT);
1000 for (n = 0; n < insn->
n; n++) {
1009 val =
int_sqrt(debtime * 1000 / 115);
1010 if (((val + 1) * val) < debtime * 1000 / 115)
1015 if (vmk80xx_write_packet(dev, cmd))
1032 n = rudimentary_check(dev,
DIR_IN);
1043 for (n = 0; n < insn->
n; n++) {
1044 if (vmk80xx_read_packet(dev))
1060 unsigned char *tx_buf;
1065 n = rudimentary_check(dev,
DIR_OUT);
1091 for (n = 0; n < insn->
n; n++) {
1092 tx_buf[reg[0]] = (
unsigned char)(data[n] & 0x03);
1093 tx_buf[reg[1]] = (
unsigned char)(data[n] >> 2) & 0xff;
1095 if (vmk80xx_write_packet(dev, cmd))
1104 static int vmk80xx_attach_common(
struct comedi_device *cdev,
1201 if (vmb[i].probed && !vmb[i].attached)
1203 if (i == VMK80XX_MAX_BOARDS)
1206 ret = vmk80xx_attach_common(cdev, &vmb[i]);
1220 if (vmb[i].probed && vmb[i].intf == intf)
1222 if (i == VMK80XX_MAX_BOARDS)
1224 else if (vmb[i].attached)
1227 ret = vmk80xx_attach_common(cdev, &vmb[i]);
1246 .driver_name =
"vmk80xx",
1247 .attach = vmk80xx_attach,
1248 .detach = vmk80xx_detach,
1249 .attach_usb = vmk80xx_attach_usb,
1257 struct usb_host_interface *iface_desc;
1267 if (i == VMK80XX_MAX_BOARDS) {
1277 iface_desc = intf->cur_altsetting;
1278 if (iface_desc->desc.bNumEndpoints != 2)
1281 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
1282 ep_desc = &iface_desc->endpoint[
i].desc;
1284 if (usb_endpoint_is_int_in(ep_desc)) {
1289 if (usb_endpoint_is_int_out(ep_desc)) {
1294 if (usb_endpoint_is_bulk_in(ep_desc)) {
1299 if (usb_endpoint_is_bulk_out(ep_desc)) {
1323 dev->
udev = interface_to_usbdev(intf);
1333 usb_set_intfdata(intf, dev);
1335 switch (id->driver_info) {
1337 dev->
board.name =
"K8055 (VM110)";
1339 dev->
board.range = &vmk8055_range;
1340 dev->
board.ai_chans = 2;
1341 dev->
board.ai_bits = 8;
1342 dev->
board.ao_chans = 2;
1343 dev->
board.ao_bits = 8;
1344 dev->
board.di_chans = 5;
1345 dev->
board.di_bits = 1;
1346 dev->
board.do_chans = 8;
1347 dev->
board.do_bits = 1;
1348 dev->
board.cnt_chans = 2;
1349 dev->
board.cnt_bits = 16;
1350 dev->
board.pwm_chans = 0;
1351 dev->
board.pwm_bits = 0;
1354 dev->
board.name =
"K8061 (VM140)";
1356 dev->
board.range = &vmk8061_range;
1357 dev->
board.ai_chans = 8;
1358 dev->
board.ai_bits = 10;
1359 dev->
board.ao_chans = 8;
1360 dev->
board.ao_bits = 8;
1361 dev->
board.di_chans = 8;
1362 dev->
board.di_bits = 1;
1363 dev->
board.do_chans = 8;
1364 dev->
board.do_bits = 1;
1365 dev->
board.cnt_chans = 2;
1366 dev->
board.cnt_bits = 0;
1367 dev->
board.pwm_chans = 1;
1368 dev->
board.pwm_bits = 10;
1376 if (vmk80xx_check_data_link(dev)) {
1381 dbgcm(
"comedi#: vmk80xx: no conn. to CPU\n");
1386 vmk80xx_reset_device(dev);
1404 static void vmk80xx_usb_disconnect(
struct usb_interface *intf)
1432 static const struct usb_device_id vmk80xx_usb_id_table[] = {
1451 static struct usb_driver vmk80xx_usb_driver = {
1453 .probe = vmk80xx_usb_probe,
1454 .disconnect = vmk80xx_usb_disconnect,
1455 .id_table = vmk80xx_usb_id_table,