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"
61 enum pci_8255_boardid {
67 BOARD_CB_PCIDIO48H_OLD,
68 BOARD_CB_PCIDIO48H_NEW,
79 struct pci_8255_boardinfo {
83 unsigned int has_mite:1;
86 static const struct pci_8255_boardinfo pci_8255_boards[] = {
87 [BOARD_ADLINK_PCI7224] = {
88 .name = "adl_pci-7224",
92 [BOARD_ADLINK_PCI7248] = {
93 .name = "adl_pci-7248",
97 [BOARD_ADLINK_PCI7296] = {
98 .name = "adl_pci-7296",
102 [BOARD_CB_PCIDIO24] = {
103 .name = "cb_pci-dio24",
107 [BOARD_CB_PCIDIO24H] = {
108 .name = "cb_pci-dio24h",
112 [BOARD_CB_PCIDIO48H_OLD] = {
113 .name = "cb_pci-dio48h",
117 [BOARD_CB_PCIDIO48H_NEW] = {
118 .name = "cb_pci-dio48h",
122 [BOARD_CB_PCIDIO96H] = {
123 .name = "cb_pci-dio96h",
127 [BOARD_NI_PCIDIO96] = {
128 .name = "ni_pci-dio-96",
133 [BOARD_NI_PCIDIO96B] = {
134 .name = "ni_pci-dio-96b",
139 [BOARD_NI_PXI6508] = {
140 .name = "ni_pxi-6508",
145 [BOARD_NI_PCI6503] = {
146 .name = "ni_pci-6503",
151 [BOARD_NI_PCI6503B] = {
152 .name = "ni_pci-6503b",
157 [BOARD_NI_PCI6503X] = {
158 .name = "ni_pci-6503x",
163 [BOARD_NI_PXI_6503] = {
164 .name = "ni_pxi-6503",
171 struct pci_8255_private {
172 void __iomem *mmio_base;
175 static int pci_8255_mite_init(struct pci_dev *pcidev)
177 void __iomem *mite_base;
180 /* ioremap the MITE registers (BAR 0) temporarily */
181 mite_base = pci_ioremap_bar(pcidev, 0);
185 /* set data window to main registers (BAR 1) */
186 main_phys_addr = pci_resource_start(pcidev, 1);
187 writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
189 /* finished with MITE registers */
194 static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
196 void __iomem *mmio_base = (void __iomem *)iobase;
199 writeb(data, mmio_base + port);
202 return readb(mmio_base + port);
206 static int pci_8255_auto_attach(struct comedi_device *dev,
207 unsigned long context)
209 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
210 const struct pci_8255_boardinfo *board = NULL;
211 struct pci_8255_private *devpriv;
212 struct comedi_subdevice *s;
217 if (context < ARRAY_SIZE(pci_8255_boards))
218 board = &pci_8255_boards[context];
221 dev->board_ptr = board;
222 dev->board_name = board->name;
224 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
228 ret = comedi_pci_enable(dev);
232 if (board->has_mite) {
233 ret = pci_8255_mite_init(pcidev);
238 is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
239 IORESOURCE_MEM) != 0;
241 devpriv->mmio_base = pci_ioremap_bar(pcidev, board->dio_badr);
242 if (!devpriv->mmio_base)
245 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
249 * One, two, or four subdevices are setup by this driver depending
250 * on the number of channels provided by the board. Each subdevice
251 * has 24 channels supported by the 8255 module.
253 ret = comedi_alloc_subdevices(dev, board->n_8255);
257 for (i = 0; i < board->n_8255; i++) {
258 unsigned long iobase;
260 s = &dev->subdevices[i];
262 iobase = (unsigned long)(devpriv->mmio_base + (i * 4));
263 ret = subdev_8255_init(dev, s, pci_8255_mmio, iobase);
265 iobase = dev->iobase + (i * 4);
266 ret = subdev_8255_init(dev, s, NULL, iobase);
275 static void pci_8255_detach(struct comedi_device *dev)
277 struct pci_8255_private *devpriv = dev->private;
279 if (devpriv && devpriv->mmio_base)
280 iounmap(devpriv->mmio_base);
281 comedi_pci_disable(dev);
284 static struct comedi_driver pci_8255_driver = {
285 .driver_name = "8255_pci",
286 .module = THIS_MODULE,
287 .auto_attach = pci_8255_auto_attach,
288 .detach = pci_8255_detach,
291 static int pci_8255_pci_probe(struct pci_dev *dev,
292 const struct pci_device_id *id)
294 return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
297 static const struct pci_device_id pci_8255_pci_table[] = {
298 { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
299 { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
300 { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
301 { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
302 { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
303 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, 0x0000, 0x0000),
304 .driver_data = BOARD_CB_PCIDIO48H_OLD },
305 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b),
306 .driver_data = BOARD_CB_PCIDIO48H_NEW },
307 { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
308 { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
309 { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
310 { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
311 { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
312 { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
313 { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
314 { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
317 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
319 static struct pci_driver pci_8255_pci_driver = {
321 .id_table = pci_8255_pci_table,
322 .probe = pci_8255_pci_probe,
323 .remove = comedi_pci_auto_unconfig,
325 module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
327 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
328 MODULE_AUTHOR("Comedi http://www.comedi.org");
329 MODULE_LICENSE("GPL");