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/uaccess.h>
37 #include "../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
;
243 cmd
.cmd
= cpu_to_le32(DT9812_R_FLASH_DATA
);
244 cmd
.u
.flash_data_info
.address
=
245 cpu_to_le16(DT9812_DIAGS_BOARD_INFO_ADDR
+ offset
);
246 cmd
.u
.flash_data_info
.numbytes
= cpu_to_le16(buf_size
);
248 /* DT9812 only responds to 32 byte writes!! */
249 ret
= usb_bulk_msg(usb
, usb_sndbulkpipe(usb
, devpriv
->cmd_wr
.addr
),
250 &cmd
, 32, &count
, DT9812_USB_TIMEOUT
);
254 return usb_bulk_msg(usb
, usb_rcvbulkpipe(usb
, devpriv
->cmd_rd
.addr
),
255 buf
, buf_size
, &count
, DT9812_USB_TIMEOUT
);
258 static int dt9812_read_multiple_registers(struct comedi_device
*dev
,
259 int reg_count
, u8
*address
,
262 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
263 struct dt9812_private
*devpriv
= dev
->private;
264 struct dt9812_usb_cmd cmd
;
267 cmd
.cmd
= cpu_to_le32(DT9812_R_MULTI_BYTE_REG
);
268 cmd
.u
.read_multi_info
.count
= reg_count
;
269 for (i
= 0; i
< reg_count
; i
++)
270 cmd
.u
.read_multi_info
.address
[i
] = address
[i
];
272 /* DT9812 only responds to 32 byte writes!! */
273 ret
= usb_bulk_msg(usb
, usb_sndbulkpipe(usb
, devpriv
->cmd_wr
.addr
),
274 &cmd
, 32, &count
, DT9812_USB_TIMEOUT
);
278 return usb_bulk_msg(usb
, usb_rcvbulkpipe(usb
, devpriv
->cmd_rd
.addr
),
279 value
, reg_count
, &count
, DT9812_USB_TIMEOUT
);
282 static int dt9812_write_multiple_registers(struct comedi_device
*dev
,
283 int reg_count
, u8
*address
,
286 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
287 struct dt9812_private
*devpriv
= dev
->private;
288 struct dt9812_usb_cmd cmd
;
291 cmd
.cmd
= cpu_to_le32(DT9812_W_MULTI_BYTE_REG
);
292 cmd
.u
.read_multi_info
.count
= reg_count
;
293 for (i
= 0; i
< reg_count
; i
++) {
294 cmd
.u
.write_multi_info
.write
[i
].address
= address
[i
];
295 cmd
.u
.write_multi_info
.write
[i
].value
= value
[i
];
298 /* DT9812 only responds to 32 byte writes!! */
299 return usb_bulk_msg(usb
, usb_sndbulkpipe(usb
, devpriv
->cmd_wr
.addr
),
300 &cmd
, 32, &count
, DT9812_USB_TIMEOUT
);
303 static int dt9812_rmw_multiple_registers(struct comedi_device
*dev
,
305 struct dt9812_rmw_byte
*rmw
)
307 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
308 struct dt9812_private
*devpriv
= dev
->private;
309 struct dt9812_usb_cmd cmd
;
312 cmd
.cmd
= cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG
);
313 cmd
.u
.rmw_multi_info
.count
= reg_count
;
314 for (i
= 0; i
< reg_count
; i
++)
315 cmd
.u
.rmw_multi_info
.rmw
[i
] = rmw
[i
];
317 /* DT9812 only responds to 32 byte writes!! */
318 return usb_bulk_msg(usb
, usb_sndbulkpipe(usb
, devpriv
->cmd_wr
.addr
),
319 &cmd
, 32, &count
, DT9812_USB_TIMEOUT
);
322 static int dt9812_digital_in(struct comedi_device
*dev
, u8
*bits
)
324 struct dt9812_private
*devpriv
= dev
->private;
325 u8 reg
[2] = { F020_SFR_P3
, F020_SFR_P1
};
329 mutex_lock(&devpriv
->mut
);
330 ret
= dt9812_read_multiple_registers(dev
, 2, reg
, value
);
333 * bits 0-6 in F020_SFR_P3 are bits 0-6 in the digital
334 * input port bit 3 in F020_SFR_P1 is bit 7 in the
337 *bits
= (value
[0] & 0x7f) | ((value
[1] & 0x08) << 4);
339 mutex_unlock(&devpriv
->mut
);
344 static int dt9812_digital_out(struct comedi_device
*dev
, u8 bits
)
346 struct dt9812_private
*devpriv
= dev
->private;
347 u8 reg
[1] = { F020_SFR_P2
};
348 u8 value
[1] = { bits
};
351 mutex_lock(&devpriv
->mut
);
352 ret
= dt9812_write_multiple_registers(dev
, 1, reg
, value
);
353 mutex_unlock(&devpriv
->mut
);
358 static void dt9812_configure_mux(struct comedi_device
*dev
,
359 struct dt9812_rmw_byte
*rmw
, int channel
)
361 struct dt9812_private
*devpriv
= dev
->private;
363 if (devpriv
->device
== DT9812_DEVID_DT9812_10
) {
364 /* In the DT9812/10V MUX is selected by P1.5-7 */
365 rmw
->address
= F020_SFR_P1
;
366 rmw
->and_mask
= 0xe0;
367 rmw
->or_value
= channel
<< 5;
369 /* In the DT9812/2.5V, internal mux is selected by bits 0:2 */
370 rmw
->address
= F020_SFR_AMX0SL
;
371 rmw
->and_mask
= 0xff;
372 rmw
->or_value
= channel
& 0x07;
376 static void dt9812_configure_gain(struct comedi_device
*dev
,
377 struct dt9812_rmw_byte
*rmw
,
378 enum dt9812_gain gain
)
380 struct dt9812_private
*devpriv
= dev
->private;
382 /* In the DT9812/10V, there is an external gain of 0.5 */
383 if (devpriv
->device
== DT9812_DEVID_DT9812_10
)
386 rmw
->address
= F020_SFR_ADC0CF
;
387 rmw
->and_mask
= F020_MASK_ADC0CF_AMP0GN2
|
388 F020_MASK_ADC0CF_AMP0GN1
|
389 F020_MASK_ADC0CF_AMP0GN0
;
400 case DT9812_GAIN_0PT5
:
401 rmw
->or_value
= F020_MASK_ADC0CF_AMP0GN2
|
402 F020_MASK_ADC0CF_AMP0GN1
;
405 /* this should never happen, just use a gain of 1 */
407 rmw
->or_value
= 0x00;
410 rmw
->or_value
= F020_MASK_ADC0CF_AMP0GN0
;
413 rmw
->or_value
= F020_MASK_ADC0CF_AMP0GN1
;
416 rmw
->or_value
= F020_MASK_ADC0CF_AMP0GN1
|
417 F020_MASK_ADC0CF_AMP0GN0
;
420 rmw
->or_value
= F020_MASK_ADC0CF_AMP0GN2
;
425 static int dt9812_analog_in(struct comedi_device
*dev
,
426 int channel
, u16
*value
, enum dt9812_gain gain
)
428 struct dt9812_private
*devpriv
= dev
->private;
429 struct dt9812_rmw_byte rmw
[3];
438 mutex_lock(&devpriv
->mut
);
440 /* 1 select the gain */
441 dt9812_configure_gain(dev
, &rmw
[0], gain
);
443 /* 2 set the MUX to select the channel */
444 dt9812_configure_mux(dev
, &rmw
[1], channel
);
446 /* 3 start conversion */
447 rmw
[2].address
= F020_SFR_ADC0CN
;
448 rmw
[2].and_mask
= 0xff;
449 rmw
[2].or_value
= F020_MASK_ADC0CN_AD0EN
| F020_MASK_ADC0CN_AD0BUSY
;
451 ret
= dt9812_rmw_multiple_registers(dev
, 3, rmw
);
455 /* read the status and ADC */
456 ret
= dt9812_read_multiple_registers(dev
, 3, reg
, val
);
461 * An ADC conversion takes 16 SAR clocks cycles, i.e. about 9us.
462 * Therefore, between the instant that AD0BUSY was set via
463 * dt9812_rmw_multiple_registers and the read of AD0BUSY via
464 * dt9812_read_multiple_registers, the conversion should be complete
465 * since these two operations require two USB transactions each taking
466 * at least a millisecond to complete. However, lets make sure that
467 * conversion is finished.
469 if ((val
[0] & (F020_MASK_ADC0CN_AD0INT
| F020_MASK_ADC0CN_AD0BUSY
)) ==
470 F020_MASK_ADC0CN_AD0INT
) {
471 switch (devpriv
->device
) {
472 case DT9812_DEVID_DT9812_10
:
474 * For DT9812-10V the personality module set the
475 * encoding to 2's complement. Hence, convert it before
478 *value
= ((val
[1] << 8) | val
[2]) + 0x800;
480 case DT9812_DEVID_DT9812_2PT5
:
481 *value
= (val
[1] << 8) | val
[2];
487 mutex_unlock(&devpriv
->mut
);
492 static int dt9812_analog_out(struct comedi_device
*dev
, int channel
, u16 value
)
494 struct dt9812_private
*devpriv
= dev
->private;
495 struct dt9812_rmw_byte rmw
[3];
498 mutex_lock(&devpriv
->mut
);
502 /* 1. Set DAC mode */
503 rmw
[0].address
= F020_SFR_DAC0CN
;
504 rmw
[0].and_mask
= 0xff;
505 rmw
[0].or_value
= F020_MASK_DACXCN_DACXEN
;
507 /* 2. load lsb of DAC value first */
508 rmw
[1].address
= F020_SFR_DAC0L
;
509 rmw
[1].and_mask
= 0xff;
510 rmw
[1].or_value
= value
& 0xff;
512 /* 3. load msb of DAC value next to latch the 12-bit value */
513 rmw
[2].address
= F020_SFR_DAC0H
;
514 rmw
[2].and_mask
= 0xff;
515 rmw
[2].or_value
= (value
>> 8) & 0xf;
519 /* 1. Set DAC mode */
520 rmw
[0].address
= F020_SFR_DAC1CN
;
521 rmw
[0].and_mask
= 0xff;
522 rmw
[0].or_value
= F020_MASK_DACXCN_DACXEN
;
524 /* 2. load lsb of DAC value first */
525 rmw
[1].address
= F020_SFR_DAC1L
;
526 rmw
[1].and_mask
= 0xff;
527 rmw
[1].or_value
= value
& 0xff;
529 /* 3. load msb of DAC value next to latch the 12-bit value */
530 rmw
[2].address
= F020_SFR_DAC1H
;
531 rmw
[2].and_mask
= 0xff;
532 rmw
[2].or_value
= (value
>> 8) & 0xf;
535 ret
= dt9812_rmw_multiple_registers(dev
, 3, rmw
);
537 mutex_unlock(&devpriv
->mut
);
542 static int dt9812_di_insn_bits(struct comedi_device
*dev
,
543 struct comedi_subdevice
*s
,
544 struct comedi_insn
*insn
,
550 ret
= dt9812_digital_in(dev
, &bits
);
559 static int dt9812_do_insn_bits(struct comedi_device
*dev
,
560 struct comedi_subdevice
*s
,
561 struct comedi_insn
*insn
,
564 if (comedi_dio_update_state(s
, data
))
565 dt9812_digital_out(dev
, s
->state
);
572 static int dt9812_ai_insn_read(struct comedi_device
*dev
,
573 struct comedi_subdevice
*s
,
574 struct comedi_insn
*insn
,
577 unsigned int chan
= CR_CHAN(insn
->chanspec
);
582 for (i
= 0; i
< insn
->n
; i
++) {
583 ret
= dt9812_analog_in(dev
, chan
, &val
, DT9812_GAIN_1
);
592 static int dt9812_ao_insn_read(struct comedi_device
*dev
,
593 struct comedi_subdevice
*s
,
594 struct comedi_insn
*insn
,
597 struct dt9812_private
*devpriv
= dev
->private;
600 mutex_lock(&devpriv
->mut
);
601 ret
= comedi_readback_insn_read(dev
, s
, insn
, data
);
602 mutex_unlock(&devpriv
->mut
);
607 static int dt9812_ao_insn_write(struct comedi_device
*dev
,
608 struct comedi_subdevice
*s
,
609 struct comedi_insn
*insn
,
612 unsigned int chan
= CR_CHAN(insn
->chanspec
);
615 for (i
= 0; i
< insn
->n
; i
++) {
616 unsigned int val
= data
[i
];
619 ret
= dt9812_analog_out(dev
, chan
, val
);
623 s
->readback
[chan
] = val
;
629 static int dt9812_find_endpoints(struct comedi_device
*dev
)
631 struct usb_interface
*intf
= comedi_to_usb_interface(dev
);
632 struct usb_host_interface
*host
= intf
->cur_altsetting
;
633 struct dt9812_private
*devpriv
= dev
->private;
634 struct usb_endpoint_descriptor
*ep
;
637 if (host
->desc
.bNumEndpoints
!= 5) {
638 dev_err(dev
->class_dev
, "Wrong number of endpoints\n");
642 for (i
= 0; i
< host
->desc
.bNumEndpoints
; ++i
) {
645 ep
= &host
->endpoint
[i
].desc
;
648 /* unused message pipe */
653 devpriv
->cmd_wr
.addr
= ep
->bEndpointAddress
;
654 devpriv
->cmd_wr
.size
= usb_endpoint_maxp(ep
);
658 devpriv
->cmd_rd
.addr
= ep
->bEndpointAddress
;
659 devpriv
->cmd_rd
.size
= usb_endpoint_maxp(ep
);
662 /* unused write stream */
666 /* unused read stream */
670 if ((ep
->bEndpointAddress
& USB_DIR_IN
) != dir
) {
671 dev_err(dev
->class_dev
,
672 "Endpoint has wrong direction\n");
679 static int dt9812_reset_device(struct comedi_device
*dev
)
681 struct usb_device
*usb
= comedi_to_usb_dev(dev
);
682 struct dt9812_private
*devpriv
= dev
->private;
692 ret
= dt9812_read_info(dev
, 0, &tmp8
, sizeof(tmp8
));
695 * Seems like a configuration reset is necessary if driver is
696 * reloaded while device is attached
698 usb_reset_configuration(usb
);
699 for (i
= 0; i
< 10; i
++) {
700 ret
= dt9812_read_info(dev
, 1, &tmp8
, sizeof(tmp8
));
705 dev_err(dev
->class_dev
,
706 "unable to reset configuration\n");
711 ret
= dt9812_read_info(dev
, 1, &tmp16
, sizeof(tmp16
));
713 dev_err(dev
->class_dev
, "failed to read vendor id\n");
716 vendor
= le16_to_cpu(tmp16
);
718 ret
= dt9812_read_info(dev
, 3, &tmp16
, sizeof(tmp16
));
720 dev_err(dev
->class_dev
, "failed to read product id\n");
723 product
= le16_to_cpu(tmp16
);
725 ret
= dt9812_read_info(dev
, 5, &tmp16
, sizeof(tmp16
));
727 dev_err(dev
->class_dev
, "failed to read device id\n");
730 devpriv
->device
= le16_to_cpu(tmp16
);
732 ret
= dt9812_read_info(dev
, 7, &tmp32
, sizeof(tmp32
));
734 dev_err(dev
->class_dev
, "failed to read serial number\n");
737 serial
= le32_to_cpu(tmp32
);
739 /* let the user know what node this device is now attached to */
740 dev_info(dev
->class_dev
, "USB DT9812 (%4.4x.%4.4x.%4.4x) #0x%8.8x\n",
741 vendor
, product
, devpriv
->device
, serial
);
743 if (devpriv
->device
!= DT9812_DEVID_DT9812_10
&&
744 devpriv
->device
!= DT9812_DEVID_DT9812_2PT5
) {
745 dev_err(dev
->class_dev
, "Unsupported device!\n");
752 static int dt9812_auto_attach(struct comedi_device
*dev
,
753 unsigned long context
)
755 struct usb_interface
*intf
= comedi_to_usb_interface(dev
);
756 struct dt9812_private
*devpriv
;
757 struct comedi_subdevice
*s
;
762 devpriv
= comedi_alloc_devpriv(dev
, sizeof(*devpriv
));
766 mutex_init(&devpriv
->mut
);
767 usb_set_intfdata(intf
, devpriv
);
769 ret
= dt9812_find_endpoints(dev
);
773 ret
= dt9812_reset_device(dev
);
777 is_unipolar
= (devpriv
->device
== DT9812_DEVID_DT9812_2PT5
);
779 ret
= comedi_alloc_subdevices(dev
, 4);
783 /* Digital Input subdevice */
784 s
= &dev
->subdevices
[0];
785 s
->type
= COMEDI_SUBD_DI
;
786 s
->subdev_flags
= SDF_READABLE
;
789 s
->range_table
= &range_digital
;
790 s
->insn_bits
= dt9812_di_insn_bits
;
792 /* Digital Output subdevice */
793 s
= &dev
->subdevices
[1];
794 s
->type
= COMEDI_SUBD_DO
;
795 s
->subdev_flags
= SDF_WRITABLE
;
798 s
->range_table
= &range_digital
;
799 s
->insn_bits
= dt9812_do_insn_bits
;
801 /* Analog Input subdevice */
802 s
= &dev
->subdevices
[2];
803 s
->type
= COMEDI_SUBD_AI
;
804 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
807 s
->range_table
= is_unipolar
? &range_unipolar2_5
: &range_bipolar10
;
808 s
->insn_read
= dt9812_ai_insn_read
;
810 /* Analog Output subdevice */
811 s
= &dev
->subdevices
[3];
812 s
->type
= COMEDI_SUBD_AO
;
813 s
->subdev_flags
= SDF_WRITABLE
;
816 s
->range_table
= is_unipolar
? &range_unipolar2_5
: &range_bipolar10
;
817 s
->insn_write
= dt9812_ao_insn_write
;
818 s
->insn_read
= dt9812_ao_insn_read
;
820 ret
= comedi_alloc_subdev_readback(s
);
824 for (i
= 0; i
< s
->n_chan
; i
++)
825 s
->readback
[i
] = is_unipolar
? 0x0000 : 0x0800;
830 static void dt9812_detach(struct comedi_device
*dev
)
832 struct usb_interface
*intf
= comedi_to_usb_interface(dev
);
833 struct dt9812_private
*devpriv
= dev
->private;
838 mutex_lock(&devpriv
->mut
);
840 usb_set_intfdata(intf
, NULL
);
842 mutex_unlock(&devpriv
->mut
);
845 static struct comedi_driver dt9812_driver
= {
846 .driver_name
= "dt9812",
847 .module
= THIS_MODULE
,
848 .auto_attach
= dt9812_auto_attach
,
849 .detach
= dt9812_detach
,
852 static int dt9812_usb_probe(struct usb_interface
*intf
,
853 const struct usb_device_id
*id
)
855 return comedi_usb_auto_config(intf
, &dt9812_driver
, id
->driver_info
);
858 static const struct usb_device_id dt9812_usb_table
[] = {
859 { USB_DEVICE(0x0867, 0x9812) },
862 MODULE_DEVICE_TABLE(usb
, dt9812_usb_table
);
864 static struct usb_driver dt9812_usb_driver
= {
866 .id_table
= dt9812_usb_table
,
867 .probe
= dt9812_usb_probe
,
868 .disconnect
= comedi_usb_auto_unconfig
,
870 module_comedi_usb_driver(dt9812_driver
, dt9812_usb_driver
);
872 MODULE_AUTHOR("Anders Blomdell <anders.blomdell@control.lth.se>");
873 MODULE_DESCRIPTION("Comedi DT9812 driver");
874 MODULE_LICENSE("GPL");