1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/dt9812.c
4 * COMEDI driver for DataTranslation DT9812 USB module
6 * Copyright (C) 2005 Anders Blomdell <anders.blomdell@control.lth.se>
8 * COMEDI - Linux Control and Measurement Device Interface
13 * Description: Data Translation DT9812 USB module
14 * Devices: [Data Translation] DT9812 (dt9812)
15 * Author: anders.blomdell@control.lth.se (Anders Blomdell)
16 * Status: in development
17 * Updated: Sun Nov 20 20:18:34 EST 2005
19 * This driver works, but bulk transfers not implemented. Might be a
20 * starting point for someone else. I found out too late that USB has
21 * too high latencies (>1 ms) for my needs.
26 * 1. All writes to command pipe has to be 32 bytes (ISP1181B SHRTP=0 ?)
27 * 2. The DDK source (as of sep 2005) is in error regarding the
28 * input MUX bits (example code says P4, but firmware schematics
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/errno.h>
35 #include <linux/slab.h>
36 #include <linux/uaccess.h>
37 #include <linux/comedi/comedi_usb.h>
39 #define DT9812_DIAGS_BOARD_INFO_ADDR 0xFBFF
40 #define DT9812_MAX_WRITE_CMD_PIPE_SIZE 32
41 #define DT9812_MAX_READ_CMD_PIPE_SIZE 32
43 /* usb_bulk_msg() timeout in milliseconds */
44 #define DT9812_USB_TIMEOUT 1000
47 * See Silican Laboratories C8051F020/1/2/3 manual
49 #define F020_SFR_P4 0x84
50 #define F020_SFR_P1 0x90
51 #define F020_SFR_P2 0xa0
52 #define F020_SFR_P3 0xb0
53 #define F020_SFR_AMX0CF 0xba
54 #define F020_SFR_AMX0SL 0xbb
55 #define F020_SFR_ADC0CF 0xbc
56 #define F020_SFR_ADC0L 0xbe
57 #define F020_SFR_ADC0H 0xbf
58 #define F020_SFR_DAC0L 0xd2
59 #define F020_SFR_DAC0H 0xd3
60 #define F020_SFR_DAC0CN 0xd4
61 #define F020_SFR_DAC1L 0xd5
62 #define F020_SFR_DAC1H 0xd6
63 #define F020_SFR_DAC1CN 0xd7
64 #define F020_SFR_ADC0CN 0xe8
66 #define F020_MASK_ADC0CF_AMP0GN0 0x01
67 #define F020_MASK_ADC0CF_AMP0GN1 0x02
68 #define F020_MASK_ADC0CF_AMP0GN2 0x04
70 #define F020_MASK_ADC0CN_AD0EN 0x80
71 #define F020_MASK_ADC0CN_AD0INT 0x20
72 #define F020_MASK_ADC0CN_AD0BUSY 0x10
74 #define F020_MASK_DACXCN_DACXEN 0x80
77 /* A/D D/A DI DO CT */
78 DT9812_DEVID_DT9812_10, /* 8 2 8 8 1 +/- 10V */
79 DT9812_DEVID_DT9812_2PT5, /* 8 2 8 8 1 0-2.44V */
83 DT9812_GAIN_0PT25 = 1,
93 DT9812_LEAST_USB_FIRMWARE_CMD_CODE = 0,
94 /* Write Flash memory */
95 DT9812_W_FLASH_DATA = 0,
96 /* Read Flash memory misc config info */
97 DT9812_R_FLASH_DATA = 1,
100 * Register read/write commands for processor
103 /* Read a single byte of USB memory */
104 DT9812_R_SINGLE_BYTE_REG = 2,
105 /* Write a single byte of USB memory */
106 DT9812_W_SINGLE_BYTE_REG = 3,
107 /* Multiple Reads of USB memory */
108 DT9812_R_MULTI_BYTE_REG = 4,
109 /* Multiple Writes of USB memory */
110 DT9812_W_MULTI_BYTE_REG = 5,
111 /* Read, (AND) with mask, OR value, then write (single) */
112 DT9812_RMW_SINGLE_BYTE_REG = 6,
113 /* Read, (AND) with mask, OR value, then write (multiple) */
114 DT9812_RMW_MULTI_BYTE_REG = 7,
117 * Register read/write commands for SMBus
120 /* Read a single byte of SMBus */
121 DT9812_R_SINGLE_BYTE_SMBUS = 8,
122 /* Write a single byte of SMBus */
123 DT9812_W_SINGLE_BYTE_SMBUS = 9,
124 /* Multiple Reads of SMBus */
125 DT9812_R_MULTI_BYTE_SMBUS = 10,
126 /* Multiple Writes of SMBus */
127 DT9812_W_MULTI_BYTE_SMBUS = 11,
130 * Register read/write commands for a device
133 /* Read a single byte of a device */
134 DT9812_R_SINGLE_BYTE_DEV = 12,
135 /* Write a single byte of a device */
136 DT9812_W_SINGLE_BYTE_DEV = 13,
137 /* Multiple Reads of a device */
138 DT9812_R_MULTI_BYTE_DEV = 14,
139 /* Multiple Writes of a device */
140 DT9812_W_MULTI_BYTE_DEV = 15,
142 /* Not sure if we'll need this */
143 DT9812_W_DAC_THRESHOLD = 16,
145 /* Set interrupt on change mask */
146 DT9812_W_INT_ON_CHANGE_MASK = 17,
148 /* Write (or Clear) the CGL for the ADC */
150 /* Multiple Reads of USB memory */
151 DT9812_R_MULTI_BYTE_USBMEM = 19,
152 /* Multiple Writes to USB memory */
153 DT9812_W_MULTI_BYTE_USBMEM = 20,
155 /* Issue a start command to a given subsystem */
156 DT9812_START_SUBSYSTEM = 21,
157 /* Issue a stop command to a given subsystem */
158 DT9812_STOP_SUBSYSTEM = 22,
160 /* calibrate the board using CAL_POT_CMD */
161 DT9812_CALIBRATE_POT = 23,
162 /* set the DAC FIFO size */
163 DT9812_W_DAC_FIFO_SIZE = 24,
164 /* Write or Clear the CGL for the DAC */
165 DT9812_W_CGL_DAC = 25,
166 /* Read a single value from a subsystem */
167 DT9812_R_SINGLE_VALUE_CMD = 26,
168 /* Write a single value to a subsystem */
169 DT9812_W_SINGLE_VALUE_CMD = 27,
170 /* Valid DT9812_USB_FIRMWARE_CMD_CODE's will be less than this number */
171 DT9812_MAX_USB_FIRMWARE_CMD_CODE,
174 struct dt9812_flash_data {
179 #define DT9812_MAX_NUM_MULTI_BYTE_RDS \
180 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(u8))
182 struct dt9812_read_multi {
184 u8 address[DT9812_MAX_NUM_MULTI_BYTE_RDS];
187 struct dt9812_write_byte {
192 #define DT9812_MAX_NUM_MULTI_BYTE_WRTS \
193 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
194 sizeof(struct dt9812_write_byte))
196 struct dt9812_write_multi {
198 struct dt9812_write_byte write[DT9812_MAX_NUM_MULTI_BYTE_WRTS];
201 struct dt9812_rmw_byte {
207 #define DT9812_MAX_NUM_MULTI_BYTE_RMWS \
208 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
209 sizeof(struct dt9812_rmw_byte))
211 struct dt9812_rmw_multi {
213 struct dt9812_rmw_byte rmw[DT9812_MAX_NUM_MULTI_BYTE_RMWS];
216 struct dt9812_usb_cmd {
219 struct dt9812_flash_data flash_data_info;
220 struct dt9812_read_multi read_multi_info;
221 struct dt9812_write_multi write_multi_info;
222 struct dt9812_rmw_multi rmw_multi_info;
226 struct dt9812_private {
235 static int dt9812_read_info(struct comedi_device *dev,
236 int offset, void *buf, size_t buf_size)
238 struct usb_device *usb = comedi_to_usb_dev(dev);
239 struct dt9812_private *devpriv = dev->private;
240 struct dt9812_usb_cmd *cmd;
245 tbuf_size = max(sizeof(*cmd), buf_size);
247 tbuf = kzalloc(tbuf_size, GFP_KERNEL);
253 cmd->cmd = cpu_to_le32(DT9812_R_FLASH_DATA);
254 cmd->u.flash_data_info.address =
255 cpu_to_le16(DT9812_DIAGS_BOARD_INFO_ADDR + offset);
256 cmd->u.flash_data_info.numbytes = cpu_to_le16(buf_size);
258 /* DT9812 only responds to 32 byte writes!! */
259 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
260 cmd, sizeof(*cmd), &count, DT9812_USB_TIMEOUT);
264 ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr),
265 tbuf, buf_size, &count, DT9812_USB_TIMEOUT);
267 if (count == buf_size)
268 memcpy(buf, tbuf, buf_size);
278 static int dt9812_read_multiple_registers(struct comedi_device *dev,
279 int reg_count, u8 *address,
282 struct usb_device *usb = comedi_to_usb_dev(dev);
283 struct dt9812_private *devpriv = dev->private;
284 struct dt9812_usb_cmd *cmd;
289 buf_size = max_t(size_t, sizeof(*cmd), reg_count);
291 buf = kzalloc(buf_size, GFP_KERNEL);
297 cmd->cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG);
298 cmd->u.read_multi_info.count = reg_count;
299 for (i = 0; i < reg_count; i++)
300 cmd->u.read_multi_info.address[i] = address[i];
302 /* DT9812 only responds to 32 byte writes!! */
303 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
304 cmd, sizeof(*cmd), &count, DT9812_USB_TIMEOUT);
308 ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr),
309 buf, reg_count, &count, DT9812_USB_TIMEOUT);
311 if (count == reg_count)
312 memcpy(value, buf, reg_count);
322 static int dt9812_write_multiple_registers(struct comedi_device *dev,
323 int reg_count, u8 *address,
326 struct usb_device *usb = comedi_to_usb_dev(dev);
327 struct dt9812_private *devpriv = dev->private;
328 struct dt9812_usb_cmd *cmd;
332 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
336 cmd->cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG);
337 cmd->u.read_multi_info.count = reg_count;
338 for (i = 0; i < reg_count; i++) {
339 cmd->u.write_multi_info.write[i].address = address[i];
340 cmd->u.write_multi_info.write[i].value = value[i];
343 /* DT9812 only responds to 32 byte writes!! */
344 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
345 cmd, sizeof(*cmd), &count, DT9812_USB_TIMEOUT);
351 static int dt9812_rmw_multiple_registers(struct comedi_device *dev,
353 struct dt9812_rmw_byte *rmw)
355 struct usb_device *usb = comedi_to_usb_dev(dev);
356 struct dt9812_private *devpriv = dev->private;
357 struct dt9812_usb_cmd *cmd;
361 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
365 cmd->cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG);
366 cmd->u.rmw_multi_info.count = reg_count;
367 for (i = 0; i < reg_count; i++)
368 cmd->u.rmw_multi_info.rmw[i] = rmw[i];
370 /* DT9812 only responds to 32 byte writes!! */
371 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
372 cmd, sizeof(*cmd), &count, DT9812_USB_TIMEOUT);
378 static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
380 struct dt9812_private *devpriv = dev->private;
381 u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 };
385 mutex_lock(&devpriv->mut);
386 ret = dt9812_read_multiple_registers(dev, 2, reg, value);
389 * bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital
390 * input port bit 3 in F020_SFR_P1 is bit 7 in the
393 *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4);
395 mutex_unlock(&devpriv->mut);
400 static int dt9812_digital_out(struct comedi_device *dev, u8 bits)
402 struct dt9812_private *devpriv = dev->private;
403 u8 reg[1] = { F020_SFR_P2 };
404 u8 value[1] = { bits };
407 mutex_lock(&devpriv->mut);
408 ret = dt9812_write_multiple_registers(dev, 1, reg, value);
409 mutex_unlock(&devpriv->mut);
414 static void dt9812_configure_mux(struct comedi_device *dev,
415 struct dt9812_rmw_byte *rmw, int channel)
417 struct dt9812_private *devpriv = dev->private;
419 if (devpriv->device == DT9812_DEVID_DT9812_10) {
420 /* In the DT9812/10V MUX is selected by P1.5-7 */
421 rmw->address = F020_SFR_P1;
422 rmw->and_mask = 0xe0;
423 rmw->or_value = channel << 5;
425 /* In the DT9812/2.5V, internal mux is selected by bits 0:2 */
426 rmw->address = F020_SFR_AMX0SL;
427 rmw->and_mask = 0xff;
428 rmw->or_value = channel & 0x07;
432 static void dt9812_configure_gain(struct comedi_device *dev,
433 struct dt9812_rmw_byte *rmw,
434 enum dt9812_gain gain)
436 struct dt9812_private *devpriv = dev->private;
438 /* In the DT9812/10V, there is an external gain of 0.5 */
439 if (devpriv->device == DT9812_DEVID_DT9812_10)
442 rmw->address = F020_SFR_ADC0CF;
443 rmw->and_mask = F020_MASK_ADC0CF_AMP0GN2 |
444 F020_MASK_ADC0CF_AMP0GN1 |
445 F020_MASK_ADC0CF_AMP0GN0;
456 case DT9812_GAIN_0PT5:
457 rmw->or_value = F020_MASK_ADC0CF_AMP0GN2 |
458 F020_MASK_ADC0CF_AMP0GN1;
461 /* this should never happen, just use a gain of 1 */
463 rmw->or_value = 0x00;
466 rmw->or_value = F020_MASK_ADC0CF_AMP0GN0;
469 rmw->or_value = F020_MASK_ADC0CF_AMP0GN1;
472 rmw->or_value = F020_MASK_ADC0CF_AMP0GN1 |
473 F020_MASK_ADC0CF_AMP0GN0;
476 rmw->or_value = F020_MASK_ADC0CF_AMP0GN2;
481 static int dt9812_analog_in(struct comedi_device *dev,
482 int channel, u16 *value, enum dt9812_gain gain)
484 struct dt9812_private *devpriv = dev->private;
485 struct dt9812_rmw_byte rmw[3];
494 mutex_lock(&devpriv->mut);
496 /* 1 select the gain */
497 dt9812_configure_gain(dev, &rmw[0], gain);
499 /* 2 set the MUX to select the channel */
500 dt9812_configure_mux(dev, &rmw[1], channel);
502 /* 3 start conversion */
503 rmw[2].address = F020_SFR_ADC0CN;
504 rmw[2].and_mask = 0xff;
505 rmw[2].or_value = F020_MASK_ADC0CN_AD0EN | F020_MASK_ADC0CN_AD0BUSY;
507 ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
511 /* read the status and ADC */
512 ret = dt9812_read_multiple_registers(dev, 3, reg, val);
517 * An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us.
518 * Therefore, between the instant that AD0BUSY was set via
519 * dt9812_rmw_multiple_registers and the read of AD0BUSY via
520 * dt9812_read_multiple_registers, the conversion should be complete
521 * since these two operations require two USB transactions each taking
522 * at least a millisecond to complete. However, lets make sure that
523 * conversion is finished.
525 if ((val[0] & (F020_MASK_ADC0CN_AD0INT | F020_MASK_ADC0CN_AD0BUSY)) ==
526 F020_MASK_ADC0CN_AD0INT) {
527 switch (devpriv->device) {
528 case DT9812_DEVID_DT9812_10:
530 * For DT9812-10V the personality module set the
531 * encoding to 2's complement. Hence, convert it before
534 *value = ((val[1] << 8) | val[2]) + 0x800;
536 case DT9812_DEVID_DT9812_2PT5:
537 *value = (val[1] << 8) | val[2];
543 mutex_unlock(&devpriv->mut);
548 static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
550 struct dt9812_private *devpriv = dev->private;
551 struct dt9812_rmw_byte rmw[3];
554 mutex_lock(&devpriv->mut);
558 /* 1. Set DAC mode */
559 rmw[0].address = F020_SFR_DAC0CN;
560 rmw[0].and_mask = 0xff;
561 rmw[0].or_value = F020_MASK_DACXCN_DACXEN;
563 /* 2. load lsb of DAC value first */
564 rmw[1].address = F020_SFR_DAC0L;
565 rmw[1].and_mask = 0xff;
566 rmw[1].or_value = value & 0xff;
568 /* 3. load msb of DAC value next to latch the 12-bit value */
569 rmw[2].address = F020_SFR_DAC0H;
570 rmw[2].and_mask = 0xff;
571 rmw[2].or_value = (value >> 8) & 0xf;
575 /* 1. Set DAC mode */
576 rmw[0].address = F020_SFR_DAC1CN;
577 rmw[0].and_mask = 0xff;
578 rmw[0].or_value = F020_MASK_DACXCN_DACXEN;
580 /* 2. load lsb of DAC value first */
581 rmw[1].address = F020_SFR_DAC1L;
582 rmw[1].and_mask = 0xff;
583 rmw[1].or_value = value & 0xff;
585 /* 3. load msb of DAC value next to latch the 12-bit value */
586 rmw[2].address = F020_SFR_DAC1H;
587 rmw[2].and_mask = 0xff;
588 rmw[2].or_value = (value >> 8) & 0xf;
591 ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
593 mutex_unlock(&devpriv->mut);
598 static int dt9812_di_insn_bits(struct comedi_device *dev,
599 struct comedi_subdevice *s,
600 struct comedi_insn *insn,
606 ret = dt9812_digital_in(dev, &bits);
615 static int dt9812_do_insn_bits(struct comedi_device *dev,
616 struct comedi_subdevice *s,
617 struct comedi_insn *insn,
620 if (comedi_dio_update_state(s, data))
621 dt9812_digital_out(dev, s->state);
628 static int dt9812_ai_insn_read(struct comedi_device *dev,
629 struct comedi_subdevice *s,
630 struct comedi_insn *insn,
633 unsigned int chan = CR_CHAN(insn->chanspec);
638 for (i = 0; i < insn->n; i++) {
639 ret = dt9812_analog_in(dev, chan, &val, DT9812_GAIN_1);
648 static int dt9812_ao_insn_read(struct comedi_device *dev,
649 struct comedi_subdevice *s,
650 struct comedi_insn *insn,
653 struct dt9812_private *devpriv = dev->private;
656 mutex_lock(&devpriv->mut);
657 ret = comedi_readback_insn_read(dev, s, insn, data);
658 mutex_unlock(&devpriv->mut);
663 static int dt9812_ao_insn_write(struct comedi_device *dev,
664 struct comedi_subdevice *s,
665 struct comedi_insn *insn,
668 unsigned int chan = CR_CHAN(insn->chanspec);
671 for (i = 0; i < insn->n; i++) {
672 unsigned int val = data[i];
675 ret = dt9812_analog_out(dev, chan, val);
679 s->readback[chan] = val;
685 static int dt9812_find_endpoints(struct comedi_device *dev)
687 struct usb_interface *intf = comedi_to_usb_interface(dev);
688 struct usb_host_interface *host = intf->cur_altsetting;
689 struct dt9812_private *devpriv = dev->private;
690 struct usb_endpoint_descriptor *ep;
693 if (host->desc.bNumEndpoints != 5) {
694 dev_err(dev->class_dev, "Wrong number of endpoints\n");
698 for (i = 0; i < host->desc.bNumEndpoints; ++i) {
701 ep = &host->endpoint[i].desc;
704 /* unused message pipe */
709 devpriv->cmd_wr.addr = ep->bEndpointAddress;
710 devpriv->cmd_wr.size = usb_endpoint_maxp(ep);
714 devpriv->cmd_rd.addr = ep->bEndpointAddress;
715 devpriv->cmd_rd.size = usb_endpoint_maxp(ep);
718 /* unused write stream */
722 /* unused read stream */
726 if ((ep->bEndpointAddress & USB_DIR_IN) != dir) {
727 dev_err(dev->class_dev,
728 "Endpoint has wrong direction\n");
735 static int dt9812_reset_device(struct comedi_device *dev)
737 struct usb_device *usb = comedi_to_usb_dev(dev);
738 struct dt9812_private *devpriv = dev->private;
748 ret = dt9812_read_info(dev, 0, &tmp8, sizeof(tmp8));
751 * Seems like a configuration reset is necessary if driver is
752 * reloaded while device is attached
754 usb_reset_configuration(usb);
755 for (i = 0; i < 10; i++) {
756 ret = dt9812_read_info(dev, 1, &tmp8, sizeof(tmp8));
761 dev_err(dev->class_dev,
762 "unable to reset configuration\n");
767 ret = dt9812_read_info(dev, 1, &tmp16, sizeof(tmp16));
769 dev_err(dev->class_dev, "failed to read vendor id\n");
772 vendor = le16_to_cpu(tmp16);
774 ret = dt9812_read_info(dev, 3, &tmp16, sizeof(tmp16));
776 dev_err(dev->class_dev, "failed to read product id\n");
779 product = le16_to_cpu(tmp16);
781 ret = dt9812_read_info(dev, 5, &tmp16, sizeof(tmp16));
783 dev_err(dev->class_dev, "failed to read device id\n");
786 devpriv->device = le16_to_cpu(tmp16);
788 ret = dt9812_read_info(dev, 7, &tmp32, sizeof(tmp32));
790 dev_err(dev->class_dev, "failed to read serial number\n");
793 serial = le32_to_cpu(tmp32);
795 /* let the user know what node this device is now attached to */
796 dev_info(dev->class_dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
797 vendor, product, devpriv->device, serial);
799 if (devpriv->device != DT9812_DEVID_DT9812_10 &&
800 devpriv->device != DT9812_DEVID_DT9812_2PT5) {
801 dev_err(dev->class_dev, "Unsupported device!\n");
808 static int dt9812_auto_attach(struct comedi_device *dev,
809 unsigned long context)
811 struct usb_interface *intf = comedi_to_usb_interface(dev);
812 struct dt9812_private *devpriv;
813 struct comedi_subdevice *s;
818 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
822 mutex_init(&devpriv->mut);
823 usb_set_intfdata(intf, devpriv);
825 ret = dt9812_find_endpoints(dev);
829 ret = dt9812_reset_device(dev);
833 is_unipolar = (devpriv->device == DT9812_DEVID_DT9812_2PT5);
835 ret = comedi_alloc_subdevices(dev, 4);
839 /* Digital Input subdevice */
840 s = &dev->subdevices[0];
841 s->type = COMEDI_SUBD_DI;
842 s->subdev_flags = SDF_READABLE;
845 s->range_table = &range_digital;
846 s->insn_bits = dt9812_di_insn_bits;
848 /* Digital Output subdevice */
849 s = &dev->subdevices[1];
850 s->type = COMEDI_SUBD_DO;
851 s->subdev_flags = SDF_WRITABLE;
854 s->range_table = &range_digital;
855 s->insn_bits = dt9812_do_insn_bits;
857 /* Analog Input subdevice */
858 s = &dev->subdevices[2];
859 s->type = COMEDI_SUBD_AI;
860 s->subdev_flags = SDF_READABLE | SDF_GROUND;
863 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10;
864 s->insn_read = dt9812_ai_insn_read;
866 /* Analog Output subdevice */
867 s = &dev->subdevices[3];
868 s->type = COMEDI_SUBD_AO;
869 s->subdev_flags = SDF_WRITABLE;
872 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10;
873 s->insn_write = dt9812_ao_insn_write;
874 s->insn_read = dt9812_ao_insn_read;
876 ret = comedi_alloc_subdev_readback(s);
880 for (i = 0; i < s->n_chan; i++)
881 s->readback[i] = is_unipolar ? 0x0000 : 0x0800;
886 static void dt9812_detach(struct comedi_device *dev)
888 struct usb_interface *intf = comedi_to_usb_interface(dev);
889 struct dt9812_private *devpriv = dev->private;
894 mutex_destroy(&devpriv->mut);
895 usb_set_intfdata(intf, NULL);
898 static struct comedi_driver dt9812_driver = {
899 .driver_name = "dt9812",
900 .module = THIS_MODULE,
901 .auto_attach = dt9812_auto_attach,
902 .detach = dt9812_detach,
905 static int dt9812_usb_probe(struct usb_interface *intf,
906 const struct usb_device_id *id)
908 return comedi_usb_auto_config(intf, &dt9812_driver, id->driver_info);
911 static const struct usb_device_id dt9812_usb_table[] = {
912 { USB_DEVICE(0x0867, 0x9812) },
915 MODULE_DEVICE_TABLE(usb, dt9812_usb_table);
917 static struct usb_driver dt9812_usb_driver = {
919 .id_table = dt9812_usb_table,
920 .probe = dt9812_usb_probe,
921 .disconnect = comedi_usb_auto_unconfig,
923 module_comedi_usb_driver(dt9812_driver, dt9812_usb_driver);
925 MODULE_AUTHOR("Anders Blomdell <anders.blomdell@control.lth.se>");
926 MODULE_DESCRIPTION("Comedi DT9812 driver");
927 MODULE_LICENSE("GPL");