2 comedi/drivers/rti802.c
3 Hardware driver for Analog Devices RTI-802 board
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 Description: Analog Devices RTI-802
21 Author: Anders Blomdell <anders.blomdell@control.lth.se>
22 Devices: [Analog Devices] RTI-802 (rti802)
25 Configuration Options:
28 [2] - dac#0 0=two's comp, 1=straight
29 [3] - dac#0 0=bipolar, 1=unipolar
35 #include "../comedidev.h"
37 #include <linux/ioport.h>
41 #define RTI802_SELECT 0
42 #define RTI802_DATALOW 1
43 #define RTI802_DATAHIGH 2
45 struct rti802_private
{
47 dac_2comp
, dac_straight
49 const struct comedi_lrange
*range_type_list
[8];
50 unsigned int ao_readback
[8];
53 static int rti802_ao_insn_read(struct comedi_device
*dev
,
54 struct comedi_subdevice
*s
,
55 struct comedi_insn
*insn
, unsigned int *data
)
57 struct rti802_private
*devpriv
= dev
->private;
60 for (i
= 0; i
< insn
->n
; i
++)
61 data
[i
] = devpriv
->ao_readback
[CR_CHAN(insn
->chanspec
)];
66 static int rti802_ao_insn_write(struct comedi_device
*dev
,
67 struct comedi_subdevice
*s
,
68 struct comedi_insn
*insn
, unsigned int *data
)
70 struct rti802_private
*devpriv
= dev
->private;
72 int chan
= CR_CHAN(insn
->chanspec
);
74 for (i
= 0; i
< insn
->n
; i
++) {
75 d
= devpriv
->ao_readback
[chan
] = data
[i
];
76 if (devpriv
->dac_coding
[chan
] == dac_2comp
)
78 outb(chan
, dev
->iobase
+ RTI802_SELECT
);
79 outb(d
& 0xff, dev
->iobase
+ RTI802_DATALOW
);
80 outb(d
>> 8, dev
->iobase
+ RTI802_DATAHIGH
);
85 static int rti802_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
87 struct rti802_private
*devpriv
;
88 struct comedi_subdevice
*s
;
92 ret
= comedi_request_region(dev
, it
->options
[0], RTI802_SIZE
);
96 devpriv
= kzalloc(sizeof(*devpriv
), GFP_KERNEL
);
99 dev
->private = devpriv
;
101 ret
= comedi_alloc_subdevices(dev
, 1);
105 s
= &dev
->subdevices
[0];
107 s
->type
= COMEDI_SUBD_AO
;
108 s
->subdev_flags
= SDF_WRITABLE
;
111 s
->insn_read
= rti802_ao_insn_read
;
112 s
->insn_write
= rti802_ao_insn_write
;
113 s
->range_table_list
= devpriv
->range_type_list
;
115 for (i
= 0; i
< 8; i
++) {
116 devpriv
->dac_coding
[i
] = (it
->options
[3 + 2 * i
])
119 devpriv
->range_type_list
[i
] = (it
->options
[2 + 2 * i
])
120 ? &range_unipolar10
: &range_bipolar10
;
126 static struct comedi_driver rti802_driver
= {
127 .driver_name
= "rti802",
128 .module
= THIS_MODULE
,
129 .attach
= rti802_attach
,
130 .detach
= comedi_legacy_detach
,
132 module_comedi_driver(rti802_driver
);
134 MODULE_AUTHOR("Comedi http://www.comedi.org");
135 MODULE_DESCRIPTION("Comedi low-level driver");
136 MODULE_LICENSE("GPL");