Commit | Line | Data |
---|---|---|
a7b5a2c4 AB |
1 | /* |
2 | comedi/drivers/rti802.c | |
3 | Hardware driver for Analog Devices RTI-802 board | |
4 | ||
5 | COMEDI - Linux Control and Measurement Device Interface | |
6 | Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | ||
22 | */ | |
23 | /* | |
24 | Driver: rti802 | |
25 | Description: Analog Devices RTI-802 | |
26 | Author: Anders Blomdell <anders.blomdell@control.lth.se> | |
27 | Devices: [Analog Devices] RTI-802 (rti802) | |
28 | Status: works | |
29 | ||
30 | Configuration Options: | |
31 | [0] - i/o base | |
32 | [1] - unused | |
33 | [2] - dac#0 0=two's comp, 1=straight | |
34 | [3] - dac#0 0=bipolar, 1=unipolar | |
35 | [4] - dac#1 ... | |
36 | ... | |
37 | [17] - dac#7 ... | |
38 | */ | |
39 | ||
40 | #include "../comedidev.h" | |
41 | ||
42 | #include <linux/ioport.h> | |
43 | ||
44 | #define RTI802_SIZE 4 | |
45 | ||
46 | #define RTI802_SELECT 0 | |
47 | #define RTI802_DATALOW 1 | |
48 | #define RTI802_DATAHIGH 2 | |
49 | ||
201007e8 | 50 | struct rti802_private { |
a7b5a2c4 AB |
51 | enum { |
52 | dac_2comp, dac_straight | |
53 | } dac_coding[8]; | |
9ced1de6 | 54 | const struct comedi_lrange *range_type_list[8]; |
790c5541 | 55 | unsigned int ao_readback[8]; |
201007e8 | 56 | }; |
a7b5a2c4 | 57 | |
201007e8 | 58 | #define devpriv ((struct rti802_private *)dev->private) |
a7b5a2c4 | 59 | |
0a85b6f0 MT |
60 | static int rti802_ao_insn_read(struct comedi_device *dev, |
61 | struct comedi_subdevice *s, | |
62 | struct comedi_insn *insn, unsigned int *data) | |
a7b5a2c4 AB |
63 | { |
64 | int i; | |
65 | ||
66 | for (i = 0; i < insn->n; i++) | |
67 | data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)]; | |
68 | ||
69 | return i; | |
70 | } | |
71 | ||
0a85b6f0 MT |
72 | static int rti802_ao_insn_write(struct comedi_device *dev, |
73 | struct comedi_subdevice *s, | |
74 | struct comedi_insn *insn, unsigned int *data) | |
a7b5a2c4 AB |
75 | { |
76 | int i, d; | |
77 | int chan = CR_CHAN(insn->chanspec); | |
78 | ||
79 | for (i = 0; i < insn->n; i++) { | |
80 | d = devpriv->ao_readback[chan] = data[i]; | |
81 | if (devpriv->dac_coding[chan] == dac_2comp) | |
82 | d ^= 0x800; | |
83 | outb(chan, dev->iobase + RTI802_SELECT); | |
84 | outb(d & 0xff, dev->iobase + RTI802_DATALOW); | |
85 | outb(d >> 8, dev->iobase + RTI802_DATAHIGH); | |
86 | } | |
87 | return i; | |
88 | } | |
89 | ||
da91b269 | 90 | static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
a7b5a2c4 | 91 | { |
34c43922 | 92 | struct comedi_subdevice *s; |
a7b5a2c4 AB |
93 | int i; |
94 | unsigned long iobase; | |
95 | ||
96 | iobase = it->options[0]; | |
83c41dab | 97 | printk(KERN_INFO "comedi%d: rti802: 0x%04lx ", dev->minor, iobase); |
a7b5a2c4 | 98 | if (!request_region(iobase, RTI802_SIZE, "rti802")) { |
83c41dab | 99 | printk(KERN_WARNING "I/O port conflict\n"); |
a7b5a2c4 AB |
100 | return -EIO; |
101 | } | |
102 | dev->iobase = iobase; | |
103 | ||
104 | dev->board_name = "rti802"; | |
105 | ||
106 | if (alloc_subdevices(dev, 1) < 0 | |
0a85b6f0 | 107 | || alloc_private(dev, sizeof(struct rti802_private))) { |
a7b5a2c4 AB |
108 | return -ENOMEM; |
109 | } | |
110 | ||
111 | s = dev->subdevices; | |
112 | /* ao subdevice */ | |
113 | s->type = COMEDI_SUBD_AO; | |
114 | s->subdev_flags = SDF_WRITABLE; | |
115 | s->maxdata = 0xfff; | |
116 | s->n_chan = 8; | |
117 | s->insn_read = rti802_ao_insn_read; | |
118 | s->insn_write = rti802_ao_insn_write; | |
119 | s->range_table_list = devpriv->range_type_list; | |
120 | ||
121 | for (i = 0; i < 8; i++) { | |
122 | devpriv->dac_coding[i] = (it->options[3 + 2 * i]) | |
0a85b6f0 MT |
123 | ? (dac_straight) |
124 | : (dac_2comp); | |
a7b5a2c4 | 125 | devpriv->range_type_list[i] = (it->options[2 + 2 * i]) |
0a85b6f0 | 126 | ? &range_unipolar10 : &range_bipolar10; |
a7b5a2c4 AB |
127 | } |
128 | ||
a7b5a2c4 AB |
129 | return 0; |
130 | } | |
131 | ||
da91b269 | 132 | static int rti802_detach(struct comedi_device *dev) |
a7b5a2c4 | 133 | { |
83c41dab | 134 | printk(KERN_INFO "comedi%d: rti802: remove\n", dev->minor); |
a7b5a2c4 AB |
135 | |
136 | if (dev->iobase) | |
137 | release_region(dev->iobase, RTI802_SIZE); | |
138 | ||
139 | return 0; | |
140 | } | |
90f703d3 | 141 | |
cb5f5237 HS |
142 | static struct comedi_driver driver_rti802 = { |
143 | .driver_name = "rti802", | |
144 | .module = THIS_MODULE, | |
145 | .attach = rti802_attach, | |
146 | .detach = rti802_detach, | |
147 | }; | |
148 | ||
149 | static int __init driver_rti802_init_module(void) | |
150 | { | |
151 | return comedi_driver_register(&driver_rti802); | |
152 | } | |
153 | module_init(driver_rti802_init_module); | |
154 | ||
155 | static void __exit driver_rti802_cleanup_module(void) | |
156 | { | |
157 | comedi_driver_unregister(&driver_rti802); | |
158 | } | |
159 | module_exit(driver_rti802_cleanup_module); | |
160 | ||
90f703d3 AT |
161 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
162 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
163 | MODULE_LICENSE("GPL"); |