This source file includes following definitions.
- pci1720_ao_insn_write
- pci1720_di_insn_bits
- pci1720_auto_attach
- adv_pci1720_pci_probe
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 #include <linux/module.h>
44 #include <linux/delay.h>
45
46 #include "../comedi_pci.h"
47
48
49
50
51 #define PCI1720_AO_LSB_REG(x) (0x00 + ((x) * 2))
52 #define PCI1720_AO_MSB_REG(x) (0x01 + ((x) * 2))
53 #define PCI1720_AO_RANGE_REG 0x08
54 #define PCI1720_AO_RANGE(c, r) (((r) & 0x3) << ((c) * 2))
55 #define PCI1720_AO_RANGE_MASK(c) PCI1720_AO_RANGE((c), 0x3)
56 #define PCI1720_SYNC_REG 0x09
57 #define PCI1720_SYNC_CTRL_REG 0x0f
58 #define PCI1720_SYNC_CTRL_SC0 BIT(0)
59 #define PCI1720_BOARDID_REG 0x14
60
61 static const struct comedi_lrange pci1720_ao_range = {
62 4, {
63 UNI_RANGE(5),
64 UNI_RANGE(10),
65 BIP_RANGE(5),
66 BIP_RANGE(10)
67 }
68 };
69
70 static int pci1720_ao_insn_write(struct comedi_device *dev,
71 struct comedi_subdevice *s,
72 struct comedi_insn *insn,
73 unsigned int *data)
74 {
75 unsigned int chan = CR_CHAN(insn->chanspec);
76 unsigned int range = CR_RANGE(insn->chanspec);
77 unsigned int val;
78 int i;
79
80
81 val = inb(dev->iobase + PCI1720_AO_RANGE_REG);
82 val &= ~PCI1720_AO_RANGE_MASK(chan);
83 val |= PCI1720_AO_RANGE(chan, range);
84 outb(val, dev->iobase + PCI1720_AO_RANGE_REG);
85
86 val = s->readback[chan];
87 for (i = 0; i < insn->n; i++) {
88 val = data[i];
89
90 outb(val & 0xff, dev->iobase + PCI1720_AO_LSB_REG(chan));
91 outb((val >> 8) & 0xff, dev->iobase + PCI1720_AO_MSB_REG(chan));
92
93
94 usleep_range(2, 100);
95 }
96
97 s->readback[chan] = val;
98
99 return insn->n;
100 }
101
102 static int pci1720_di_insn_bits(struct comedi_device *dev,
103 struct comedi_subdevice *s,
104 struct comedi_insn *insn,
105 unsigned int *data)
106 {
107 data[1] = inb(dev->iobase + PCI1720_BOARDID_REG);
108
109 return insn->n;
110 }
111
112 static int pci1720_auto_attach(struct comedi_device *dev,
113 unsigned long context)
114 {
115 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
116 struct comedi_subdevice *s;
117 int ret;
118
119 ret = comedi_pci_enable(dev);
120 if (ret)
121 return ret;
122 dev->iobase = pci_resource_start(pcidev, 2);
123
124 ret = comedi_alloc_subdevices(dev, 2);
125 if (ret)
126 return ret;
127
128
129 s = &dev->subdevices[0];
130 s->type = COMEDI_SUBD_AO;
131 s->subdev_flags = SDF_WRITABLE;
132 s->n_chan = 4;
133 s->maxdata = 0x0fff;
134 s->range_table = &pci1720_ao_range;
135 s->insn_write = pci1720_ao_insn_write;
136
137 ret = comedi_alloc_subdev_readback(s);
138 if (ret)
139 return ret;
140
141
142 s = &dev->subdevices[1];
143 s->type = COMEDI_SUBD_DI;
144 s->subdev_flags = SDF_READABLE;
145 s->n_chan = 4;
146 s->maxdata = 1;
147 s->range_table = &range_digital;
148 s->insn_bits = pci1720_di_insn_bits;
149
150
151 outb(0, dev->iobase + PCI1720_SYNC_CTRL_REG);
152
153 return 0;
154 }
155
156 static struct comedi_driver adv_pci1720_driver = {
157 .driver_name = "adv_pci1720",
158 .module = THIS_MODULE,
159 .auto_attach = pci1720_auto_attach,
160 .detach = comedi_pci_detach,
161 };
162
163 static int adv_pci1720_pci_probe(struct pci_dev *dev,
164 const struct pci_device_id *id)
165 {
166 return comedi_pci_auto_config(dev, &adv_pci1720_driver,
167 id->driver_data);
168 }
169
170 static const struct pci_device_id adv_pci1720_pci_table[] = {
171 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1720) },
172 { 0 }
173 };
174 MODULE_DEVICE_TABLE(pci, adv_pci1720_pci_table);
175
176 static struct pci_driver adv_pci1720_pci_driver = {
177 .name = "adv_pci1720",
178 .id_table = adv_pci1720_pci_table,
179 .probe = adv_pci1720_pci_probe,
180 .remove = comedi_pci_auto_unconfig,
181 };
182 module_comedi_pci_driver(adv_pci1720_driver, adv_pci1720_pci_driver);
183
184 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
185 MODULE_DESCRIPTION("Comedi driver for Advantech PCI-1720 Analog Output board");
186 MODULE_LICENSE("GPL");