2 * COMEDI driver for generic PCI based 8255 digital i/o boards
3 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
5 * Based on the tested adl_pci7296 driver written by:
6 * Jon Grierson <jd@renko.co.uk>
7 * and the experimental cb_pcidio driver written by:
10 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
26 Description: Generic PCI based 8255 Digital I/O boards
27 Devices: (ADLink) PCI-7224 [adl_pci-7224] - 24 channels
28 (ADLink) PCI-7248 [adl_pci-7248] - 48 channels
29 (ADLink) PCI-7296 [adl_pci-7296] - 96 channels
30 (Measurement Computing) PCI-DIO24 [cb_pci-dio24] - 24 channels
31 (Measurement Computing) PCI-DIO24H [cb_pci-dio24h] - 24 channels
32 (Measurement Computing) PCI-DIO48H [cb_pci-dio48h] - 48 channels
33 (Measurement Computing) PCI-DIO96H [cb_pci-dio96h] - 96 channels
34 (National Instruments) PCI-DIO-96 [ni_pci-dio-96] - 96 channels
35 (National Instruments) PCI-DIO-96B [ni_pci-dio-96b] - 96 channels
36 (National Instruments) PXI-6508 [ni_pxi-6508] - 96 channels
37 (National Instruments) PCI-6503 [ni_pci-6503] - 24 channels
38 (National Instruments) PCI-6503B [ni_pci-6503b] - 24 channels
39 (National Instruments) PCI-6503X [ni_pci-6503x] - 24 channels
40 (National Instruments) PXI-6503 [ni_pxi-6503] - 24 channels
41 Author: H Hartley Sweeten <hsweeten@visionengravers.com>
42 Updated: Wed, 12 Sep 2012 11:52:01 -0700
45 Some of these boards also have an 8254 programmable timer/counter
46 chip. This chip is not currently supported by this driver.
48 Interrupt support for these boards is also not currently supported.
50 Configuration Options: not applicable, uses PCI auto config
53 #include <linux/module.h>
54 #include <linux/pci.h>
56 #include "../comedidev.h"
60 enum pci_8255_boardid {
66 BOARD_CB_PCIDIO48H_OLD,
67 BOARD_CB_PCIDIO48H_NEW,
78 struct pci_8255_boardinfo {
84 static const struct pci_8255_boardinfo pci_8255_boards[] = {
85 [BOARD_ADLINK_PCI7224] = {
86 .name = "adl_pci-7224",
90 [BOARD_ADLINK_PCI7248] = {
91 .name = "adl_pci-7248",
95 [BOARD_ADLINK_PCI7296] = {
96 .name = "adl_pci-7296",
100 [BOARD_CB_PCIDIO24] = {
101 .name = "cb_pci-dio24",
105 [BOARD_CB_PCIDIO24H] = {
106 .name = "cb_pci-dio24h",
110 [BOARD_CB_PCIDIO48H_OLD] = {
111 .name = "cb_pci-dio48h",
115 [BOARD_CB_PCIDIO48H_NEW] = {
116 .name = "cb_pci-dio48h",
120 [BOARD_CB_PCIDIO96H] = {
121 .name = "cb_pci-dio96h",
125 [BOARD_NI_PCIDIO96] = {
126 .name = "ni_pci-dio-96",
130 [BOARD_NI_PCIDIO96B] = {
131 .name = "ni_pci-dio-96b",
135 [BOARD_NI_PXI6508] = {
136 .name = "ni_pxi-6508",
140 [BOARD_NI_PCI6503] = {
141 .name = "ni_pci-6503",
145 [BOARD_NI_PCI6503B] = {
146 .name = "ni_pci-6503b",
150 [BOARD_NI_PCI6503X] = {
151 .name = "ni_pci-6503x",
155 [BOARD_NI_PXI_6503] = {
156 .name = "ni_pxi-6503",
162 struct pci_8255_private {
163 void __iomem *mmio_base;
166 static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
168 void __iomem *mmio_base = (void __iomem *)iobase;
171 writeb(data, mmio_base + port);
174 return readb(mmio_base + port);
178 static int pci_8255_auto_attach(struct comedi_device *dev,
179 unsigned long context)
181 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
182 const struct pci_8255_boardinfo *board = NULL;
183 struct pci_8255_private *devpriv;
184 struct comedi_subdevice *s;
189 if (context < ARRAY_SIZE(pci_8255_boards))
190 board = &pci_8255_boards[context];
193 dev->board_ptr = board;
194 dev->board_name = board->name;
196 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
200 ret = comedi_pci_enable(dev);
204 is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
205 IORESOURCE_MEM) != 0;
207 devpriv->mmio_base = pci_ioremap_bar(pcidev, board->dio_badr);
208 if (!devpriv->mmio_base)
211 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
215 * One, two, or four subdevices are setup by this driver depending
216 * on the number of channels provided by the board. Each subdevice
217 * has 24 channels supported by the 8255 module.
219 ret = comedi_alloc_subdevices(dev, board->n_8255);
223 for (i = 0; i < board->n_8255; i++) {
224 unsigned long iobase;
226 s = &dev->subdevices[i];
228 iobase = (unsigned long)(devpriv->mmio_base + (i * 4));
229 ret = subdev_8255_init(dev, s, pci_8255_mmio, iobase);
231 iobase = dev->iobase + (i * 4);
232 ret = subdev_8255_init(dev, s, NULL, iobase);
238 dev_info(dev->class_dev, "%s attached (%d digital i/o channels)\n",
239 dev->board_name, board->n_8255 * 24);
244 static void pci_8255_detach(struct comedi_device *dev)
246 struct pci_8255_private *devpriv = dev->private;
248 if (devpriv && devpriv->mmio_base)
249 iounmap(devpriv->mmio_base);
250 comedi_pci_disable(dev);
253 static struct comedi_driver pci_8255_driver = {
254 .driver_name = "8255_pci",
255 .module = THIS_MODULE,
256 .auto_attach = pci_8255_auto_attach,
257 .detach = pci_8255_detach,
260 static int pci_8255_pci_probe(struct pci_dev *dev,
261 const struct pci_device_id *id)
263 return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
266 static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table) = {
267 { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
268 { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
269 { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
270 { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
271 { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
272 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, 0x0000, 0x0000),
273 .driver_data = BOARD_CB_PCIDIO48H_OLD },
274 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b),
275 .driver_data = BOARD_CB_PCIDIO48H_NEW },
276 { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
277 { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
278 { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
279 { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
280 { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
281 { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
282 { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
283 { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
286 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
288 static struct pci_driver pci_8255_pci_driver = {
290 .id_table = pci_8255_pci_table,
291 .probe = pci_8255_pci_probe,
292 .remove = comedi_pci_auto_unconfig,
294 module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
296 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
297 MODULE_AUTHOR("Comedi http://www.comedi.org");
298 MODULE_LICENSE("GPL");