32 #include "../comedidev.h"
36 #define DT2801_TIMEOUT 1000
41 #define DT2801_MAX_DMA_SIZE (64 * 1024)
44 #define DT2801_IOSIZE 2
50 #define DT_C_RESET 0x0
51 #define DT_C_CLEAR_ERR 0x1
52 #define DT_C_READ_ERRREG 0x2
53 #define DT_C_SET_CLOCK 0x3
58 #define DT_C_SET_DIGIN 0x4
59 #define DT_C_SET_DIGOUT 0x5
60 #define DT_C_READ_DIG 0x6
61 #define DT_C_WRITE_DIG 0x7
63 #define DT_C_WRITE_DAIM 0x8
64 #define DT_C_SET_DA 0x9
65 #define DT_C_WRITE_DA 0xa
67 #define DT_C_READ_ADIM 0xc
68 #define DT_C_SET_AD 0xd
69 #define DT_C_READ_AD 0xe
74 #define DT_MOD_DMA (1<<4)
75 #define DT_MOD_CONT (1<<5)
76 #define DT_MOD_EXTCLK (1<<6)
77 #define DT_MOD_EXTTRIG (1<<7)
80 #define DT_S_DATA_OUT_READY (1<<0)
81 #define DT_S_DATA_IN_FULL (1<<1)
82 #define DT_S_READY (1<<2)
83 #define DT_S_COMMAND (1<<3)
84 #define DT_S_COMPOSITE_ERROR (1<<7)
88 #define DT2801_STATUS 1
93 static const struct comedi_lrange range_dt2801_ai_pgh_bipolar = { 4, {
107 static const struct comedi_lrange range_dt2801_ai_pgl_bipolar = { 4, {
123 static const struct comedi_lrange range_dt2801_ai_pgh_unipolar = { 4, {
135 static const struct comedi_lrange range_dt2801_ai_pgl_unipolar = { 4, {
179 .name =
"dt2801/5716a",
195 .name =
"dt2805/5716a",
228 #define boardtype (*(const struct dt2801_board *)dev->board_ptr)
236 #define devpriv ((struct dt2801_private *)dev->private)
260 }
while (--timeout > 0);
270 ret = dt2801_readdata(dev, &lb);
273 ret = dt2801_readdata(dev, &hb);
277 *data = (hb << 8) + lb;
281 static int dt2801_writedata(
struct comedi_device *dev,
unsigned int data)
298 (
"dt2801: ready flag set (bad!) in dt2801_writedata()\n");
302 }
while (--timeout > 0);
307 static int dt2801_writedata2(
struct comedi_device *dev,
unsigned int data)
311 ret = dt2801_writedata(dev, data & 0xff);
314 ret = dt2801_writedata(dev, (data >> 8));
332 if (stat & DT_S_COMPOSITE_ERROR)
334 if (stat & DT_S_READY)
336 }
while (--timeout > 0);
345 dt2801_wait_for_ready(dev);
348 if (stat & DT_S_COMPOSITE_ERROR) {
350 (
"dt2801: composite-error in dt2801_writecmd(), ignoring\n");
352 if (!(stat & DT_S_READY))
353 printk(
"dt2801: !ready in dt2801_writecmd(), ignoring\n");
365 DPRINTK(
"dt2801: resetting board...\n");
384 if (stat & DT_S_READY)
388 printk(
"dt2801: timeout 1 status=0x%02x\n", stat);
401 if (stat & DT_S_READY)
405 printk(
"dt2801: timeout 2 status=0x%02x\n", stat);
407 DPRINTK(
"dt2801: reading code\n");
408 dt2801_readdata(dev, &board_code);
410 DPRINTK(
"dt2801: ok. code=0x%02x\n", board_code);
415 static int probe_number_of_ai_chans(
struct comedi_device *dev)
421 for (n_chans = 0; n_chans < 16; n_chans++) {
423 dt2801_writedata(dev, 0);
424 dt2801_writedata(dev, n_chans);
425 stat = dt2801_readdata2(dev, &data);
447 if (opt < 0 || opt >= 5)
449 return dac_range_table[
opt];
457 &range_dt2801_ai_pgl_unipolar :
458 &range_dt2801_ai_pgl_bipolar;
471 printk(
"dt2801: timeout\n");
473 printk(
"dt2801: error %d\n", stat);
476 printk(
"dt2801: error status 0x%02x, resetting...\n", stat);
492 for (i = 0; i < insn->
n; i++) {
496 stat = dt2801_readdata2(dev, &d);
499 return dt2801_error(dev, stat);
522 dt2801_writedata2(dev, data[0]);
539 s->
state &= ~data[0];
540 s->
state |= (data[0] & data[1]);
542 dt2801_writedata(dev, which);
543 dt2801_writedata(dev, s->
state);
546 dt2801_writedata(dev, which);
547 dt2801_readdata(dev, data + 1);
577 dt2801_writedata(dev, which);
595 int board_code,
type;
608 board_code = dt2801_reset(dev);
612 board_code = dt2801_reset(dev);
614 for (type = 0; type <
ARRAY_SIZE(boardtypes); type++) {
615 if (boardtypes[type].boardcode == board_code)
618 printk(
"dt2801: unrecognized board code=0x%02x, contact author\n",
626 n_ai_chans = probe_number_of_ai_chans(dev);
627 printk(
" (ai channels = %d)\n", n_ai_chans);
699 .driver_name =
"dt2801",
701 .attach = dt2801_attach,
702 .detach = dt2801_detach,