1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/module.h>
26#include <linux/delay.h>
27
28#include "../comedi_pci.h"
29
30
31
32
33#define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
34#define PCI6208_AO_STATUS 0x00
35#define PCI6208_AO_STATUS_DATA_SEND BIT(0)
36#define PCI6208_DIO 0x40
37#define PCI6208_DIO_DO_MASK (0x0f)
38#define PCI6208_DIO_DO_SHIFT (0)
39#define PCI6208_DIO_DI_MASK (0xf0)
40#define PCI6208_DIO_DI_SHIFT (4)
41
42static int pci6208_ao_eoc(struct comedi_device *dev,
43 struct comedi_subdevice *s,
44 struct comedi_insn *insn,
45 unsigned long context)
46{
47 unsigned int status;
48
49 status = inw(dev->iobase + PCI6208_AO_STATUS);
50 if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
51 return 0;
52 return -EBUSY;
53}
54
55static int pci6208_ao_insn_write(struct comedi_device *dev,
56 struct comedi_subdevice *s,
57 struct comedi_insn *insn,
58 unsigned int *data)
59{
60 unsigned int chan = CR_CHAN(insn->chanspec);
61 int ret;
62 int i;
63
64 for (i = 0; i < insn->n; i++) {
65 unsigned int val = data[i];
66
67
68 ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
69 if (ret)
70 return ret;
71
72
73 outw(comedi_offset_munge(s, val),
74 dev->iobase + PCI6208_AO_CONTROL(chan));
75
76 s->readback[chan] = val;
77 }
78
79 return insn->n;
80}
81
82static int pci6208_di_insn_bits(struct comedi_device *dev,
83 struct comedi_subdevice *s,
84 struct comedi_insn *insn,
85 unsigned int *data)
86{
87 unsigned int val;
88
89 val = inw(dev->iobase + PCI6208_DIO);
90 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
91
92 data[1] = val;
93
94 return insn->n;
95}
96
97static int pci6208_do_insn_bits(struct comedi_device *dev,
98 struct comedi_subdevice *s,
99 struct comedi_insn *insn,
100 unsigned int *data)
101{
102 if (comedi_dio_update_state(s, data))
103 outw(s->state, dev->iobase + PCI6208_DIO);
104
105 data[1] = s->state;
106
107 return insn->n;
108}
109
110static int pci6208_auto_attach(struct comedi_device *dev,
111 unsigned long context_unused)
112{
113 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
114 struct comedi_subdevice *s;
115 unsigned int val;
116 int ret;
117
118 ret = comedi_pci_enable(dev);
119 if (ret)
120 return ret;
121 dev->iobase = pci_resource_start(pcidev, 2);
122
123 ret = comedi_alloc_subdevices(dev, 3);
124 if (ret)
125 return ret;
126
127 s = &dev->subdevices[0];
128
129 s->type = COMEDI_SUBD_AO;
130 s->subdev_flags = SDF_WRITABLE;
131 s->n_chan = 16;
132 s->maxdata = 0xffff;
133 s->range_table = &range_bipolar10;
134 s->insn_write = pci6208_ao_insn_write;
135
136 ret = comedi_alloc_subdev_readback(s);
137 if (ret)
138 return ret;
139
140 s = &dev->subdevices[1];
141
142 s->type = COMEDI_SUBD_DI;
143 s->subdev_flags = SDF_READABLE;
144 s->n_chan = 4;
145 s->maxdata = 1;
146 s->range_table = &range_digital;
147 s->insn_bits = pci6208_di_insn_bits;
148
149 s = &dev->subdevices[2];
150
151 s->type = COMEDI_SUBD_DO;
152 s->subdev_flags = SDF_WRITABLE;
153 s->n_chan = 4;
154 s->maxdata = 1;
155 s->range_table = &range_digital;
156 s->insn_bits = pci6208_do_insn_bits;
157
158
159
160
161
162 val = inw(dev->iobase + PCI6208_DIO);
163 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
164 s->state = val;
165
166 return 0;
167}
168
169static struct comedi_driver adl_pci6208_driver = {
170 .driver_name = "adl_pci6208",
171 .module = THIS_MODULE,
172 .auto_attach = pci6208_auto_attach,
173 .detach = comedi_pci_detach,
174};
175
176static int adl_pci6208_pci_probe(struct pci_dev *dev,
177 const struct pci_device_id *id)
178{
179 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
180 id->driver_data);
181}
182
183static const struct pci_device_id adl_pci6208_pci_table[] = {
184 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
185 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
186 0x9999, 0x6208) },
187 { 0 }
188};
189MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
190
191static struct pci_driver adl_pci6208_pci_driver = {
192 .name = "adl_pci6208",
193 .id_table = adl_pci6208_pci_table,
194 .probe = adl_pci6208_pci_probe,
195 .remove = comedi_pci_auto_unconfig,
196};
197module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
198
199MODULE_AUTHOR("Comedi https://www.comedi.org");
200MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
201MODULE_LICENSE("GPL");
202