2 * comedi/drivers/dt9812.c
3 * COMEDI driver for DataTranslation DT9812 USB module
5 * Copyright (C) 2005 Anders Blomdell <anders.blomdell@control.lth.se>
7 * COMEDI - Linux Control and Measurement Device Interface
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
22 Description: Data Translation DT9812 USB module
23 Author: anders.blomdell@control.lth.se (Anders Blomdell)
24 Status: in development
25 Devices: [Data Translation] DT9812 (dt9812)
26 Updated: Sun Nov 20 20:18:34 EST 2005
28 This driver works, but bulk transfers not implemented. Might be a starting point
29 for someone else. I found out too late that USB has too high latencies (>1 ms)
35 * 1. All writes to command pipe has to be 32 bytes (ISP1181B SHRTP=0 ?)
36 * 2. The DDK source (as of sep 2005) is in error regarding the
37 * input MUX bits (example code says P4, but firmware schematics
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/errno.h>
44 #include <linux/init.h>
45 #include <linux/uaccess.h>
46 #include <linux/usb.h>
48 #include "../comedidev.h"
50 #define DT9812_DIAGS_BOARD_INFO_ADDR 0xFBFF
51 #define DT9812_MAX_WRITE_CMD_PIPE_SIZE 32
52 #define DT9812_MAX_READ_CMD_PIPE_SIZE 32
54 /* usb_bulk_msg() timout in milliseconds */
55 #define DT9812_USB_TIMEOUT 1000
58 * See Silican Laboratories C8051F020/1/2/3 manual
60 #define F020_SFR_P4 0x84
61 #define F020_SFR_P1 0x90
62 #define F020_SFR_P2 0xa0
63 #define F020_SFR_P3 0xb0
64 #define F020_SFR_AMX0CF 0xba
65 #define F020_SFR_AMX0SL 0xbb
66 #define F020_SFR_ADC0CF 0xbc
67 #define F020_SFR_ADC0L 0xbe
68 #define F020_SFR_ADC0H 0xbf
69 #define F020_SFR_DAC0L 0xd2
70 #define F020_SFR_DAC0H 0xd3
71 #define F020_SFR_DAC0CN 0xd4
72 #define F020_SFR_DAC1L 0xd5
73 #define F020_SFR_DAC1H 0xd6
74 #define F020_SFR_DAC1CN 0xd7
75 #define F020_SFR_ADC0CN 0xe8
77 #define F020_MASK_ADC0CF_AMP0GN0 0x01
78 #define F020_MASK_ADC0CF_AMP0GN1 0x02
79 #define F020_MASK_ADC0CF_AMP0GN2 0x04
81 #define F020_MASK_ADC0CN_AD0EN 0x80
82 #define F020_MASK_ADC0CN_AD0INT 0x20
83 #define F020_MASK_ADC0CN_AD0BUSY 0x10
85 #define F020_MASK_DACxCN_DACxEN 0x80
88 /* A/D D/A DI DO CT */
89 DT9812_DEVID_DT9812_10, /* 8 2 8 8 1 +/- 10V */
90 DT9812_DEVID_DT9812_2PT5, /* 8 2 8 8 1 0-2.44V */
92 DT9812_DEVID_DT9813, /* 16 2 4 4 1 +/- 10V */
93 DT9812_DEVID_DT9814 /* 24 2 0 0 1 +/- 10V */
98 DT9812_GAIN_0PT25 = 1,
108 DT9812_LEAST_USB_FIRMWARE_CMD_CODE = 0,
109 /* Write Flash memory */
110 DT9812_W_FLASH_DATA = 0,
111 /* Read Flash memory misc config info */
112 DT9812_R_FLASH_DATA = 1,
115 * Register read/write commands for processor
118 /* Read a single byte of USB memory */
119 DT9812_R_SINGLE_BYTE_REG = 2,
120 /* Write a single byte of USB memory */
121 DT9812_W_SINGLE_BYTE_REG = 3,
122 /* Multiple Reads of USB memory */
123 DT9812_R_MULTI_BYTE_REG = 4,
124 /* Multiple Writes of USB memory */
125 DT9812_W_MULTI_BYTE_REG = 5,
126 /* Read, (AND) with mask, OR value, then write (single) */
127 DT9812_RMW_SINGLE_BYTE_REG = 6,
128 /* Read, (AND) with mask, OR value, then write (multiple) */
129 DT9812_RMW_MULTI_BYTE_REG = 7,
132 * Register read/write commands for SMBus
135 /* Read a single byte of SMBus */
136 DT9812_R_SINGLE_BYTE_SMBUS = 8,
137 /* Write a single byte of SMBus */
138 DT9812_W_SINGLE_BYTE_SMBUS = 9,
139 /* Multiple Reads of SMBus */
140 DT9812_R_MULTI_BYTE_SMBUS = 10,
141 /* Multiple Writes of SMBus */
142 DT9812_W_MULTI_BYTE_SMBUS = 11,
145 * Register read/write commands for a device
148 /* Read a single byte of a device */
149 DT9812_R_SINGLE_BYTE_DEV = 12,
150 /* Write a single byte of a device */
151 DT9812_W_SINGLE_BYTE_DEV = 13,
152 /* Multiple Reads of a device */
153 DT9812_R_MULTI_BYTE_DEV = 14,
154 /* Multiple Writes of a device */
155 DT9812_W_MULTI_BYTE_DEV = 15,
157 /* Not sure if we'll need this */
158 DT9812_W_DAC_THRESHOLD = 16,
160 /* Set interrupt on change mask */
161 DT9812_W_INT_ON_CHANGE_MASK = 17,
163 /* Write (or Clear) the CGL for the ADC */
165 /* Multiple Reads of USB memory */
166 DT9812_R_MULTI_BYTE_USBMEM = 19,
167 /* Multiple Writes to USB memory */
168 DT9812_W_MULTI_BYTE_USBMEM = 20,
170 /* Issue a start command to a given subsystem */
171 DT9812_START_SUBSYSTEM = 21,
172 /* Issue a stop command to a given subsystem */
173 DT9812_STOP_SUBSYSTEM = 22,
175 /* calibrate the board using CAL_POT_CMD */
176 DT9812_CALIBRATE_POT = 23,
177 /* set the DAC FIFO size */
178 DT9812_W_DAC_FIFO_SIZE = 24,
179 /* Write or Clear the CGL for the DAC */
180 DT9812_W_CGL_DAC = 25,
181 /* Read a single value from a subsystem */
182 DT9812_R_SINGLE_VALUE_CMD = 26,
183 /* Write a single value to a subsystem */
184 DT9812_W_SINGLE_VALUE_CMD = 27,
185 /* Valid DT9812_USB_FIRMWARE_CMD_CODE's will be less than this number */
186 DT9812_MAX_USB_FIRMWARE_CMD_CODE,
189 struct dt9812_flash_data {
194 #define DT9812_MAX_NUM_MULTI_BYTE_RDS \
195 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / sizeof(u8))
197 struct dt9812_read_multi {
199 u8 address[DT9812_MAX_NUM_MULTI_BYTE_RDS];
202 struct dt9812_write_byte {
207 #define DT9812_MAX_NUM_MULTI_BYTE_WRTS \
208 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
209 sizeof(struct dt9812_write_byte))
211 struct dt9812_write_multi {
213 struct dt9812_write_byte write[DT9812_MAX_NUM_MULTI_BYTE_WRTS];
216 struct dt9812_rmw_byte {
222 #define DT9812_MAX_NUM_MULTI_BYTE_RMWS \
223 ((DT9812_MAX_WRITE_CMD_PIPE_SIZE - 4 - 1) / \
224 sizeof(struct dt9812_rmw_byte))
226 struct dt9812_rmw_multi {
228 struct dt9812_rmw_byte rmw[DT9812_MAX_NUM_MULTI_BYTE_RMWS];
231 struct dt9812_usb_cmd {
234 struct dt9812_flash_data flash_data_info;
235 struct dt9812_read_multi read_multi_info;
236 struct dt9812_write_multi write_multi_info;
237 struct dt9812_rmw_multi rmw_multi_info;
241 struct dt9812_private {
242 struct semaphore sem;
251 static int dt9812_read_info(struct comedi_device *dev,
252 int offset, void *buf, size_t buf_size)
254 struct usb_device *usb = comedi_to_usb_dev(dev);
255 struct dt9812_private *devpriv = dev->private;
256 struct dt9812_usb_cmd cmd;
259 cmd.cmd = cpu_to_le32(DT9812_R_FLASH_DATA);
260 cmd.u.flash_data_info.address =
261 cpu_to_le16(DT9812_DIAGS_BOARD_INFO_ADDR + offset);
262 cmd.u.flash_data_info.numbytes = cpu_to_le16(buf_size);
264 /* DT9812 only responds to 32 byte writes!! */
265 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
266 &cmd, 32, &count, DT9812_USB_TIMEOUT);
270 return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr),
271 buf, buf_size, &count, DT9812_USB_TIMEOUT);
274 static int dt9812_read_multiple_registers(struct comedi_device *dev,
275 int reg_count, u8 *address,
278 struct usb_device *usb = comedi_to_usb_dev(dev);
279 struct dt9812_private *devpriv = dev->private;
280 struct dt9812_usb_cmd cmd;
283 cmd.cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG);
284 cmd.u.read_multi_info.count = reg_count;
285 for (i = 0; i < reg_count; i++)
286 cmd.u.read_multi_info.address[i] = address[i];
288 /* DT9812 only responds to 32 byte writes!! */
289 ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
290 &cmd, 32, &count, DT9812_USB_TIMEOUT);
294 return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, devpriv->cmd_rd.addr),
295 value, reg_count, &count, DT9812_USB_TIMEOUT);
298 static int dt9812_write_multiple_registers(struct comedi_device *dev,
299 int reg_count, u8 *address,
302 struct usb_device *usb = comedi_to_usb_dev(dev);
303 struct dt9812_private *devpriv = dev->private;
304 struct dt9812_usb_cmd cmd;
307 cmd.cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG);
308 cmd.u.read_multi_info.count = reg_count;
309 for (i = 0; i < reg_count; i++) {
310 cmd.u.write_multi_info.write[i].address = address[i];
311 cmd.u.write_multi_info.write[i].value = value[i];
314 /* DT9812 only responds to 32 byte writes!! */
315 return usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
316 &cmd, 32, &count, DT9812_USB_TIMEOUT);
319 static int dt9812_rmw_multiple_registers(struct comedi_device *dev,
321 struct dt9812_rmw_byte *rmw)
323 struct usb_device *usb = comedi_to_usb_dev(dev);
324 struct dt9812_private *devpriv = dev->private;
325 struct dt9812_usb_cmd cmd;
328 cmd.cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG);
329 cmd.u.rmw_multi_info.count = reg_count;
330 for (i = 0; i < reg_count; i++)
331 cmd.u.rmw_multi_info.rmw[i] = rmw[i];
333 /* DT9812 only responds to 32 byte writes!! */
334 return usb_bulk_msg(usb, usb_sndbulkpipe(usb, devpriv->cmd_wr.addr),
335 &cmd, 32, &count, DT9812_USB_TIMEOUT);
338 static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
340 struct dt9812_private *devpriv = dev->private;
341 u8 reg[2] = { F020_SFR_P3, F020_SFR_P1 };
346 ret = dt9812_read_multiple_registers(dev, 2, reg, value);
349 * bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital
350 * input port bit 3 in F020_SFR_P1 is bit 7 in the
353 *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4);
360 static int dt9812_digital_out(struct comedi_device *dev, u8 bits)
362 struct dt9812_private *devpriv = dev->private;
363 u8 reg[1] = { F020_SFR_P2 };
364 u8 value[1] = { bits };
368 ret = dt9812_write_multiple_registers(dev, 1, reg, value);
374 static void dt9812_configure_mux(struct comedi_device *dev,
375 struct dt9812_rmw_byte *rmw, int channel)
377 struct dt9812_private *devpriv = dev->private;
379 if (devpriv->device == DT9812_DEVID_DT9812_10) {
380 /* In the DT9812/10V MUX is selected by P1.5-7 */
381 rmw->address = F020_SFR_P1;
382 rmw->and_mask = 0xe0;
383 rmw->or_value = channel << 5;
385 /* In the DT9812/2.5V, internal mux is selected by bits 0:2 */
386 rmw->address = F020_SFR_AMX0SL;
387 rmw->and_mask = 0xff;
388 rmw->or_value = channel & 0x07;
392 static void dt9812_configure_gain(struct comedi_device *dev,
393 struct dt9812_rmw_byte *rmw,
394 enum dt9812_gain gain)
396 struct dt9812_private *devpriv = dev->private;
398 /* In the DT9812/10V, there is an external gain of 0.5 */
399 if (devpriv->device == DT9812_DEVID_DT9812_10)
402 rmw->address = F020_SFR_ADC0CF;
403 rmw->and_mask = F020_MASK_ADC0CF_AMP0GN2 |
404 F020_MASK_ADC0CF_AMP0GN1 |
405 F020_MASK_ADC0CF_AMP0GN0;
416 case DT9812_GAIN_0PT5:
417 rmw->or_value = F020_MASK_ADC0CF_AMP0GN2 |
418 F020_MASK_ADC0CF_AMP0GN1;
421 /* this should never happen, just use a gain of 1 */
423 rmw->or_value = 0x00;
426 rmw->or_value = F020_MASK_ADC0CF_AMP0GN0;
429 rmw->or_value = F020_MASK_ADC0CF_AMP0GN1;
432 rmw->or_value = F020_MASK_ADC0CF_AMP0GN1 |
433 F020_MASK_ADC0CF_AMP0GN0;
436 rmw->or_value = F020_MASK_ADC0CF_AMP0GN2;
441 static int dt9812_analog_in(struct comedi_device *dev,
442 int channel, u16 *value, enum dt9812_gain gain)
444 struct dt9812_private *devpriv = dev->private;
445 struct dt9812_rmw_byte rmw[3];
456 /* 1 select the gain */
457 dt9812_configure_gain(dev, &rmw[0], gain);
459 /* 2 set the MUX to select the channel */
460 dt9812_configure_mux(dev, &rmw[1], channel);
462 /* 3 start conversion */
463 rmw[2].address = F020_SFR_ADC0CN;
464 rmw[2].and_mask = 0xff;
465 rmw[2].or_value = F020_MASK_ADC0CN_AD0EN | F020_MASK_ADC0CN_AD0BUSY;
467 ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
471 /* read the status and ADC */
472 ret = dt9812_read_multiple_registers(dev, 3, reg, val);
477 * An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us.
478 * Therefore, between the instant that AD0BUSY was set via
479 * dt9812_rmw_multiple_registers and the read of AD0BUSY via
480 * dt9812_read_multiple_registers, the conversion should be complete
481 * since these two operations require two USB transactions each taking
482 * at least a millisecond to complete. However, lets make sure that
483 * conversion is finished.
485 if ((val[0] & (F020_MASK_ADC0CN_AD0INT | F020_MASK_ADC0CN_AD0BUSY)) ==
486 F020_MASK_ADC0CN_AD0INT) {
487 switch (devpriv->device) {
488 case DT9812_DEVID_DT9812_10:
490 * For DT9812-10V the personality module set the
491 * encoding to 2's complement. Hence, convert it before
494 *value = ((val[1] << 8) | val[2]) + 0x800;
496 case DT9812_DEVID_DT9812_2PT5:
497 *value = (val[1] << 8) | val[2];
508 static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
510 struct dt9812_private *devpriv = dev->private;
511 struct dt9812_rmw_byte rmw[3];
518 /* 1. Set DAC mode */
519 rmw[0].address = F020_SFR_DAC0CN;
520 rmw[0].and_mask = 0xff;
521 rmw[0].or_value = F020_MASK_DACxCN_DACxEN;
523 /* 2 load low byte of DAC value first */
524 rmw[1].address = F020_SFR_DAC0L;
525 rmw[1].and_mask = 0xff;
526 rmw[1].or_value = value & 0xff;
528 /* 3 load high byte of DAC value next to latch the
530 rmw[2].address = F020_SFR_DAC0H;
531 rmw[2].and_mask = 0xff;
532 rmw[2].or_value = (value >> 8) & 0xf;
536 /* 1. Set DAC mode */
537 rmw[0].address = F020_SFR_DAC1CN;
538 rmw[0].and_mask = 0xff;
539 rmw[0].or_value = F020_MASK_DACxCN_DACxEN;
541 /* 2 load low byte of DAC value first */
542 rmw[1].address = F020_SFR_DAC1L;
543 rmw[1].and_mask = 0xff;
544 rmw[1].or_value = value & 0xff;
546 /* 3 load high byte of DAC value next to latch the
548 rmw[2].address = F020_SFR_DAC1H;
549 rmw[2].and_mask = 0xff;
550 rmw[2].or_value = (value >> 8) & 0xf;
553 ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
554 devpriv->ao_shadow[channel] = value;
561 static int dt9812_di_insn_bits(struct comedi_device *dev,
562 struct comedi_subdevice *s,
563 struct comedi_insn *insn,
569 ret = dt9812_digital_in(dev, &bits);
578 static int dt9812_do_insn_bits(struct comedi_device *dev,
579 struct comedi_subdevice *s,
580 struct comedi_insn *insn,
583 unsigned int mask = data[0];
584 unsigned int bits = data[1];
588 s->state |= (bits & mask);
590 dt9812_digital_out(dev, s->state);
598 static int dt9812_ai_insn_read(struct comedi_device *dev,
599 struct comedi_subdevice *s,
600 struct comedi_insn *insn,
603 unsigned int chan = CR_CHAN(insn->chanspec);
608 for (i = 0; i < insn->n; i++) {
609 ret = dt9812_analog_in(dev, chan, &val, DT9812_GAIN_1);
618 static int dt9812_ao_insn_read(struct comedi_device *dev,
619 struct comedi_subdevice *s,
620 struct comedi_insn *insn,
623 struct dt9812_private *devpriv = dev->private;
624 unsigned int chan = CR_CHAN(insn->chanspec);
628 for (i = 0; i < insn->n; i++)
629 data[i] = devpriv->ao_shadow[chan];
635 static int dt9812_ao_insn_write(struct comedi_device *dev,
636 struct comedi_subdevice *s,
637 struct comedi_insn *insn,
640 unsigned int chan = CR_CHAN(insn->chanspec);
644 for (i = 0; i < insn->n; i++) {
645 ret = dt9812_analog_out(dev, chan, data[i]);
653 static int dt9812_find_endpoints(struct comedi_device *dev)
655 struct usb_interface *intf = comedi_to_usb_interface(dev);
656 struct usb_host_interface *host = intf->cur_altsetting;
657 struct dt9812_private *devpriv = dev->private;
658 struct usb_endpoint_descriptor *ep;
661 if (host->desc.bNumEndpoints != 5) {
662 dev_err(dev->class_dev, "Wrong number of endpoints\n");
666 for (i = 0; i < host->desc.bNumEndpoints; ++i) {
668 ep = &host->endpoint[i].desc;
671 /* unused message pipe */
676 devpriv->cmd_wr.addr = ep->bEndpointAddress;
677 devpriv->cmd_wr.size = le16_to_cpu(ep->wMaxPacketSize);
681 devpriv->cmd_rd.addr = ep->bEndpointAddress;
682 devpriv->cmd_rd.size = le16_to_cpu(ep->wMaxPacketSize);
685 /* unused write stream */
689 /* unused read stream */
693 if ((ep->bEndpointAddress & USB_DIR_IN) != dir) {
694 dev_err(dev->class_dev,
695 "Endpoint has wrong direction\n");
702 static int dt9812_reset_device(struct comedi_device *dev)
704 struct usb_device *usb = comedi_to_usb_dev(dev);
705 struct dt9812_private *devpriv = dev->private;
715 ret = dt9812_read_info(dev, 0, &tmp8, sizeof(tmp8));
718 * Seems like a configuration reset is necessary if driver is
719 * reloaded while device is attached
721 usb_reset_configuration(usb);
722 for (i = 0; i < 10; i++) {
723 ret = dt9812_read_info(dev, 1, &tmp8, sizeof(tmp8));
728 dev_err(dev->class_dev,
729 "unable to reset configuration\n");
734 ret = dt9812_read_info(dev, 1, &tmp16, sizeof(tmp16));
736 dev_err(dev->class_dev, "failed to read vendor id\n");
739 vendor = le16_to_cpu(tmp16);
741 ret = dt9812_read_info(dev, 3, &tmp16, sizeof(tmp16));
743 dev_err(dev->class_dev, "failed to read product id\n");
746 product = le16_to_cpu(tmp16);
748 ret = dt9812_read_info(dev, 5, &tmp16, sizeof(tmp16));
750 dev_err(dev->class_dev, "failed to read device id\n");
753 devpriv->device = le16_to_cpu(tmp16);
755 ret = dt9812_read_info(dev, 7, &tmp32, sizeof(tmp32));
757 dev_err(dev->class_dev, "failed to read serial number\n");
760 serial = le32_to_cpu(tmp32);
762 /* let the user know what node this device is now attached to */
763 dev_info(dev->class_dev, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
764 vendor, product, devpriv->device, serial);
766 if (devpriv->device != DT9812_DEVID_DT9812_10 &&
767 devpriv->device != DT9812_DEVID_DT9812_2PT5) {
768 dev_err(dev->class_dev, "Unsupported device!\n");
775 static int dt9812_auto_attach(struct comedi_device *dev,
776 unsigned long context)
778 struct usb_interface *intf = comedi_to_usb_interface(dev);
779 struct dt9812_private *devpriv;
780 struct comedi_subdevice *s;
784 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
788 sema_init(&devpriv->sem, 1);
789 usb_set_intfdata(intf, devpriv);
791 ret = dt9812_find_endpoints(dev);
795 ret = dt9812_reset_device(dev);
799 is_unipolar = (devpriv->device == DT9812_DEVID_DT9812_2PT5);
801 ret = comedi_alloc_subdevices(dev, 4);
805 /* Digital Input subdevice */
806 s = &dev->subdevices[0];
807 s->type = COMEDI_SUBD_DI;
808 s->subdev_flags = SDF_READABLE;
811 s->range_table = &range_digital;
812 s->insn_bits = dt9812_di_insn_bits;
814 /* Digital Output subdevice */
815 s = &dev->subdevices[1];
816 s->type = COMEDI_SUBD_DO;
817 s->subdev_flags = SDF_WRITEABLE;
820 s->range_table = &range_digital;
821 s->insn_bits = dt9812_do_insn_bits;
823 /* Analog Input subdevice */
824 s = &dev->subdevices[2];
825 s->type = COMEDI_SUBD_AI;
826 s->subdev_flags = SDF_READABLE | SDF_GROUND;
829 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10;
830 s->insn_read = dt9812_ai_insn_read;
832 /* Analog Output subdevice */
833 s = &dev->subdevices[3];
834 s->type = COMEDI_SUBD_AO;
835 s->subdev_flags = SDF_WRITEABLE;
838 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10;
839 s->insn_write = dt9812_ao_insn_write;
840 s->insn_read = dt9812_ao_insn_read;
842 devpriv->ao_shadow[0] = is_unipolar ? 0x0000 : 0x0800;
843 devpriv->ao_shadow[1] = is_unipolar ? 0x0000 : 0x0800;
848 static void dt9812_detach(struct comedi_device *dev)
850 struct usb_interface *intf = comedi_to_usb_interface(dev);
851 struct dt9812_private *devpriv = dev->private;
858 usb_set_intfdata(intf, NULL);
863 static struct comedi_driver dt9812_driver = {
864 .driver_name = "dt9812",
865 .module = THIS_MODULE,
866 .auto_attach = dt9812_auto_attach,
867 .detach = dt9812_detach,
870 static int dt9812_usb_probe(struct usb_interface *intf,
871 const struct usb_device_id *id)
873 return comedi_usb_auto_config(intf, &dt9812_driver, id->driver_info);
876 static const struct usb_device_id dt9812_usb_table[] = {
877 { USB_DEVICE(0x0867, 0x9812) },
880 MODULE_DEVICE_TABLE(usb, dt9812_usb_table);
882 static struct usb_driver dt9812_usb_driver = {
884 .id_table = dt9812_usb_table,
885 .probe = dt9812_usb_probe,
886 .disconnect = comedi_usb_auto_unconfig,
888 module_comedi_usb_driver(dt9812_driver, dt9812_usb_driver);
890 MODULE_AUTHOR("Anders Blomdell <anders.blomdell@control.lth.se>");
891 MODULE_DESCRIPTION("Comedi DT9812 driver");
892 MODULE_LICENSE("GPL");