This source file includes following definitions.
- apci16xx_insn_config
- apci16xx_dio_insn_bits
- apci16xx_auto_attach
- apci16xx_pci_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/module.h>
17
18 #include "../comedi_pci.h"
19
20
21
22
23 #define APCI16XX_IN_REG(x) (((x) * 4) + 0x08)
24 #define APCI16XX_OUT_REG(x) (((x) * 4) + 0x14)
25 #define APCI16XX_DIR_REG(x) (((x) * 4) + 0x20)
26
27 enum apci16xx_boardid {
28 BOARD_APCI1648,
29 BOARD_APCI1696,
30 };
31
32 struct apci16xx_boardinfo {
33 const char *name;
34 int n_chan;
35 };
36
37 static const struct apci16xx_boardinfo apci16xx_boardtypes[] = {
38 [BOARD_APCI1648] = {
39 .name = "apci1648",
40 .n_chan = 48,
41 },
42 [BOARD_APCI1696] = {
43 .name = "apci1696",
44 .n_chan = 96,
45 },
46 };
47
48 static int apci16xx_insn_config(struct comedi_device *dev,
49 struct comedi_subdevice *s,
50 struct comedi_insn *insn,
51 unsigned int *data)
52 {
53 unsigned int chan = CR_CHAN(insn->chanspec);
54 unsigned int mask;
55 int ret;
56
57 if (chan < 8)
58 mask = 0x000000ff;
59 else if (chan < 16)
60 mask = 0x0000ff00;
61 else if (chan < 24)
62 mask = 0x00ff0000;
63 else
64 mask = 0xff000000;
65
66 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
67 if (ret)
68 return ret;
69
70 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(s->index));
71
72 return insn->n;
73 }
74
75 static int apci16xx_dio_insn_bits(struct comedi_device *dev,
76 struct comedi_subdevice *s,
77 struct comedi_insn *insn,
78 unsigned int *data)
79 {
80 if (comedi_dio_update_state(s, data))
81 outl(s->state, dev->iobase + APCI16XX_OUT_REG(s->index));
82
83 data[1] = inl(dev->iobase + APCI16XX_IN_REG(s->index));
84
85 return insn->n;
86 }
87
88 static int apci16xx_auto_attach(struct comedi_device *dev,
89 unsigned long context)
90 {
91 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
92 const struct apci16xx_boardinfo *board = NULL;
93 struct comedi_subdevice *s;
94 unsigned int n_subdevs;
95 unsigned int last;
96 int i;
97 int ret;
98
99 if (context < ARRAY_SIZE(apci16xx_boardtypes))
100 board = &apci16xx_boardtypes[context];
101 if (!board)
102 return -ENODEV;
103 dev->board_ptr = board;
104 dev->board_name = board->name;
105
106 ret = comedi_pci_enable(dev);
107 if (ret)
108 return ret;
109
110 dev->iobase = pci_resource_start(pcidev, 0);
111
112
113
114
115
116
117 n_subdevs = board->n_chan / 32;
118 if ((n_subdevs * 32) < board->n_chan) {
119 last = board->n_chan - (n_subdevs * 32);
120 n_subdevs++;
121 } else {
122 last = 0;
123 }
124
125 ret = comedi_alloc_subdevices(dev, n_subdevs);
126 if (ret)
127 return ret;
128
129
130 for (i = 0; i < n_subdevs; i++) {
131 s = &dev->subdevices[i];
132 s->type = COMEDI_SUBD_DIO;
133 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
134 s->n_chan = ((i * 32) < board->n_chan) ? 32 : last;
135 s->maxdata = 1;
136 s->range_table = &range_digital;
137 s->insn_config = apci16xx_insn_config;
138 s->insn_bits = apci16xx_dio_insn_bits;
139
140
141 s->io_bits = 0;
142 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(i));
143 }
144
145 return 0;
146 }
147
148 static struct comedi_driver apci16xx_driver = {
149 .driver_name = "addi_apci_16xx",
150 .module = THIS_MODULE,
151 .auto_attach = apci16xx_auto_attach,
152 .detach = comedi_pci_detach,
153 };
154
155 static int apci16xx_pci_probe(struct pci_dev *dev,
156 const struct pci_device_id *id)
157 {
158 return comedi_pci_auto_config(dev, &apci16xx_driver, id->driver_data);
159 }
160
161 static const struct pci_device_id apci16xx_pci_table[] = {
162 { PCI_VDEVICE(ADDIDATA, 0x1009), BOARD_APCI1648 },
163 { PCI_VDEVICE(ADDIDATA, 0x100a), BOARD_APCI1696 },
164 { 0 }
165 };
166 MODULE_DEVICE_TABLE(pci, apci16xx_pci_table);
167
168 static struct pci_driver apci16xx_pci_driver = {
169 .name = "addi_apci_16xx",
170 .id_table = apci16xx_pci_table,
171 .probe = apci16xx_pci_probe,
172 .remove = comedi_pci_auto_unconfig,
173 };
174 module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver);
175
176 MODULE_DESCRIPTION("ADDI-DATA APCI-1648/1696, TTL I/O boards");
177 MODULE_AUTHOR("Comedi http://www.comedi.org");
178 MODULE_LICENSE("GPL");