Commit | Line | Data |
---|---|---|
a7b5a2c4 | 1 | /* |
8f3367af HS |
2 | * rti802.c |
3 | * Comedi 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. | |
a7b5a2c4 | 17 | */ |
a7b5a2c4 | 18 | |
8f3367af HS |
19 | /* |
20 | * Driver: rti802 | |
21 | * Description: Analog Devices RTI-802 | |
22 | * Author: Anders Blomdell <anders.blomdell@control.lth.se> | |
36847203 | 23 | * Devices: [Analog Devices] RTI-802 (rti802) |
8f3367af HS |
24 | * Status: works |
25 | * | |
26 | * Configuration Options: | |
27 | * [0] - i/o base | |
28 | * [1] - unused | |
29 | * [2,4,6,8,10,12,14,16] - dac#[0-7] 0=two's comp, 1=straight | |
30 | * [3,5,7,9,11,13,15,17] - dac#[0-7] 0=bipolar, 1=unipolar | |
31 | */ | |
a7b5a2c4 | 32 | |
ce157f80 | 33 | #include <linux/module.h> |
a7b5a2c4 AB |
34 | #include "../comedidev.h" |
35 | ||
6938dd28 HS |
36 | /* |
37 | * Register I/O map | |
38 | */ | |
39 | #define RTI802_SELECT 0x00 | |
40 | #define RTI802_DATALOW 0x01 | |
41 | #define RTI802_DATAHIGH 0x02 | |
a7b5a2c4 | 42 | |
201007e8 | 43 | struct rti802_private { |
a7b5a2c4 AB |
44 | enum { |
45 | dac_2comp, dac_straight | |
46 | } dac_coding[8]; | |
9ced1de6 | 47 | const struct comedi_lrange *range_type_list[8]; |
201007e8 | 48 | }; |
a7b5a2c4 | 49 | |
0a85b6f0 MT |
50 | static int rti802_ao_insn_write(struct comedi_device *dev, |
51 | struct comedi_subdevice *s, | |
57450d90 HS |
52 | struct comedi_insn *insn, |
53 | unsigned int *data) | |
a7b5a2c4 | 54 | { |
9a1a6cf8 | 55 | struct rti802_private *devpriv = dev->private; |
57450d90 | 56 | unsigned int chan = CR_CHAN(insn->chanspec); |
57450d90 HS |
57 | int i; |
58 | ||
59 | outb(chan, dev->iobase + RTI802_SELECT); | |
a7b5a2c4 AB |
60 | |
61 | for (i = 0; i < insn->n; i++) { | |
f6085cb4 | 62 | unsigned int val = data[i]; |
57450d90 | 63 | |
f6085cb4 | 64 | s->readback[chan] = val; |
57450d90 HS |
65 | |
66 | /* munge offset binary to two's complement if needed */ | |
a7b5a2c4 | 67 | if (devpriv->dac_coding[chan] == dac_2comp) |
57450d90 HS |
68 | val = comedi_offset_munge(s, val); |
69 | ||
70 | outb(val & 0xff, dev->iobase + RTI802_DATALOW); | |
71 | outb((val >> 8) & 0xff, dev->iobase + RTI802_DATAHIGH); | |
a7b5a2c4 | 72 | } |
57450d90 HS |
73 | |
74 | return insn->n; | |
a7b5a2c4 AB |
75 | } |
76 | ||
da91b269 | 77 | static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
a7b5a2c4 | 78 | { |
9a1a6cf8 | 79 | struct rti802_private *devpriv; |
34c43922 | 80 | struct comedi_subdevice *s; |
a7b5a2c4 | 81 | int i; |
8b6c5694 | 82 | int ret; |
a7b5a2c4 | 83 | |
df8f09bb | 84 | ret = comedi_request_region(dev, it->options[0], 0x04); |
45f9fcc2 HS |
85 | if (ret) |
86 | return ret; | |
a7b5a2c4 | 87 | |
0bdab509 | 88 | devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); |
c34fa261 HS |
89 | if (!devpriv) |
90 | return -ENOMEM; | |
8b6c5694 HS |
91 | |
92 | ret = comedi_alloc_subdevices(dev, 1); | |
93 | if (ret) | |
94 | return ret; | |
a7b5a2c4 | 95 | |
052c198b | 96 | /* Analog Output subdevice */ |
7badc90d | 97 | s = &dev->subdevices[0]; |
052c198b HS |
98 | s->type = COMEDI_SUBD_AO; |
99 | s->subdev_flags = SDF_WRITABLE; | |
100 | s->maxdata = 0xfff; | |
101 | s->n_chan = 8; | |
052c198b | 102 | s->insn_write = rti802_ao_insn_write; |
a7b5a2c4 | 103 | |
f6085cb4 HS |
104 | ret = comedi_alloc_subdev_readback(s); |
105 | if (ret) | |
106 | return ret; | |
107 | ||
108 | s->range_table_list = devpriv->range_type_list; | |
a7b5a2c4 AB |
109 | for (i = 0; i < 8; i++) { |
110 | devpriv->dac_coding[i] = (it->options[3 + 2 * i]) | |
052c198b | 111 | ? (dac_straight) : (dac_2comp); |
a7b5a2c4 | 112 | devpriv->range_type_list[i] = (it->options[2 + 2 * i]) |
052c198b | 113 | ? &range_unipolar10 : &range_bipolar10; |
a7b5a2c4 AB |
114 | } |
115 | ||
a7b5a2c4 AB |
116 | return 0; |
117 | } | |
118 | ||
294f930d | 119 | static struct comedi_driver rti802_driver = { |
cb5f5237 HS |
120 | .driver_name = "rti802", |
121 | .module = THIS_MODULE, | |
122 | .attach = rti802_attach, | |
21208519 | 123 | .detach = comedi_legacy_detach, |
cb5f5237 | 124 | }; |
294f930d | 125 | module_comedi_driver(rti802_driver); |
cb5f5237 | 126 | |
90f703d3 | 127 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
2925cc86 | 128 | MODULE_DESCRIPTION("Comedi driver for Analog Devices RTI-802 board"); |
90f703d3 | 129 | MODULE_LICENSE("GPL"); |