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.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 Description: Generic PCI based 8255 Digital I/O boards
31 Devices: (ADLink) PCI-7224 [adl_pci-7224] - 24 channels
32 (ADLink) PCI-7248 [adl_pci-7248] - 48 channels
33 (ADLink) PCI-7296 [adl_pci-7296] - 96 channels
34 (Measurement Computing) PCI-DIO24 [cb_pci-dio24] - 24 channels
35 (Measurement Computing) PCI-DIO24H [cb_pci-dio24h] - 24 channels
36 (Measurement Computing) PCI-DIO48H [cb_pci-dio48h] - 48 channels
37 (Measurement Computing) PCI-DIO96H [cb_pci-dio96h] - 96 channels
38 (National Instruments) PCI-DIO-96 [ni_pci-dio-96] - 96 channels
39 (National Instruments) PCI-DIO-96B [ni_pci-dio-96b] - 96 channels
40 (National Instruments) PXI-6508 [ni_pxi-6508] - 96 channels
41 (National Instruments) PCI-6503 [ni_pci-6503] - 24 channels
42 (National Instruments) PCI-6503B [ni_pci-6503b] - 24 channels
43 (National Instruments) PCI-6503X [ni_pci-6503x] - 24 channels
44 (National Instruments) PXI-6503 [ni_pxi-6503] - 24 channels
45 Author: H Hartley Sweeten <hsweeten@visionengravers.com>
46 Updated: Wed, 12 Sep 2012 11:52:01 -0700
49 Some of these boards also have an 8254 programmable timer/counter
50 chip. This chip is not currently supported by this driver.
52 Interrupt support for these boards is also not currently supported.
54 Configuration Options: not applicable, uses PCI auto config
57 #include <linux/pci.h>
59 #include "../comedidev.h"
64 * PCI Device ID's supported by this driver
66 #define PCI_DEVICE_ID_ADLINK_PCI7224 0x7224
67 #define PCI_DEVICE_ID_ADLINK_PCI7248 0x7248
68 #define PCI_DEVICE_ID_ADLINK_PCI7296 0x7296
70 #define PCI_DEVICE_ID_CB_PCIDIO48H 0x000b
71 #define PCI_DEVICE_ID_CB_PCIDIO24H 0x0014
72 #define PCI_DEVICE_ID_CB_PCIDIO96H 0x0017
73 #define PCI_DEVICE_ID_CB_PCIDIO24 0x0028
75 #define PCI_DEVICE_ID_NI_PCIDIO96 0x0160
76 #define PCI_DEVICE_ID_NI_PCI6503 0x0400
77 #define PCI_DEVICE_ID_NI_PCI6503B 0x1250
78 #define PCI_DEVICE_ID_NI_PXI6508 0x13c0
79 #define PCI_DEVICE_ID_NI_PCIDIO96B 0x1630
80 #define PCI_DEVICE_ID_NI_PCI6503X 0x17d0
81 #define PCI_DEVICE_ID_NI_PXI_6503 0x1800
83 struct pci_8255_boardinfo
{
85 unsigned short vendor
;
86 unsigned short device
;
92 static const struct pci_8255_boardinfo pci_8255_boards
[] = {
94 .name
= "adl_pci-7224",
95 .vendor
= PCI_VENDOR_ID_ADLINK
,
96 .device
= PCI_DEVICE_ID_ADLINK_PCI7224
,
100 .name
= "adl_pci-7248",
101 .vendor
= PCI_VENDOR_ID_ADLINK
,
102 .device
= PCI_DEVICE_ID_ADLINK_PCI7248
,
106 .name
= "adl_pci-7296",
107 .vendor
= PCI_VENDOR_ID_ADLINK
,
108 .device
= PCI_DEVICE_ID_ADLINK_PCI7296
,
112 .name
= "cb_pci-dio24",
113 .vendor
= PCI_VENDOR_ID_CB
,
114 .device
= PCI_DEVICE_ID_CB_PCIDIO24
,
118 .name
= "cb_pci-dio24h",
119 .vendor
= PCI_VENDOR_ID_CB
,
120 .device
= PCI_DEVICE_ID_CB_PCIDIO24H
,
124 .name
= "cb_pci-dio48h",
125 .vendor
= PCI_VENDOR_ID_CB
,
126 .device
= PCI_DEVICE_ID_CB_PCIDIO48H
,
130 .name
= "cb_pci-dio96h",
131 .vendor
= PCI_VENDOR_ID_CB
,
132 .device
= PCI_DEVICE_ID_CB_PCIDIO96H
,
136 .name
= "ni_pci-dio-96",
137 .vendor
= PCI_VENDOR_ID_NI
,
138 .device
= PCI_DEVICE_ID_NI_PCIDIO96
,
143 .name
= "ni_pci-dio-96b",
144 .vendor
= PCI_VENDOR_ID_NI
,
145 .device
= PCI_DEVICE_ID_NI_PCIDIO96B
,
150 .name
= "ni_pxi-6508",
151 .vendor
= PCI_VENDOR_ID_NI
,
152 .device
= PCI_DEVICE_ID_NI_PXI6508
,
157 .name
= "ni_pci-6503",
158 .vendor
= PCI_VENDOR_ID_NI
,
159 .device
= PCI_DEVICE_ID_NI_PCI6503
,
164 .name
= "ni_pci-6503b",
165 .vendor
= PCI_VENDOR_ID_NI
,
166 .device
= PCI_DEVICE_ID_NI_PCI6503B
,
171 .name
= "ni_pci-6503x",
172 .vendor
= PCI_VENDOR_ID_NI
,
173 .device
= PCI_DEVICE_ID_NI_PCI6503X
,
178 .name
= "ni_pxi-6503",
179 .vendor
= PCI_VENDOR_ID_NI
,
180 .device
= PCI_DEVICE_ID_NI_PXI_6503
,
187 struct pci_8255_private
{
188 void __iomem
*mmio_base
;
191 static int pci_8255_mmio(int dir
, int port
, int data
, unsigned long iobase
)
193 void __iomem
*mmio_base
= (void __iomem
*)iobase
;
196 writeb(data
, mmio_base
+ port
);
199 return readb(mmio_base
+ port
);
203 static const void *pci_8255_find_boardinfo(struct comedi_device
*dev
,
204 struct pci_dev
*pcidev
)
206 const struct pci_8255_boardinfo
*board
;
209 for (i
= 0; i
< ARRAY_SIZE(pci_8255_boards
); i
++) {
210 board
= &pci_8255_boards
[i
];
211 if (pcidev
->vendor
== board
->vendor
&&
212 pcidev
->device
== board
->device
)
218 static int pci_8255_auto_attach(struct comedi_device
*dev
,
219 unsigned long context_unused
)
221 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
222 const struct pci_8255_boardinfo
*board
;
223 struct pci_8255_private
*devpriv
;
224 struct comedi_subdevice
*s
;
225 resource_size_t iobase
;
230 board
= pci_8255_find_boardinfo(dev
, pcidev
);
233 dev
->board_ptr
= board
;
234 dev
->board_name
= board
->name
;
236 devpriv
= kzalloc(sizeof(*devpriv
), GFP_KERNEL
);
239 dev
->private = devpriv
;
241 ret
= comedi_pci_enable(pcidev
, dev
->board_name
);
244 iobase
= pci_resource_start(pcidev
, board
->dio_badr
);
245 len
= pci_resource_len(pcidev
, board
->dio_badr
);
247 if (board
->is_mmio
) {
248 devpriv
->mmio_base
= ioremap(iobase
, len
);
249 if (!devpriv
->mmio_base
)
252 dev
->iobase
= iobase
;
255 * One, two, or four subdevices are setup by this driver depending
256 * on the number of channels provided by the board. Each subdevice
257 * has 24 channels supported by the 8255 module.
259 ret
= comedi_alloc_subdevices(dev
, board
->n_8255
);
263 for (i
= 0; i
< board
->n_8255
; i
++) {
264 s
= &dev
->subdevices
[i
];
265 if (board
->is_mmio
) {
266 iobase
= (unsigned long)(devpriv
->mmio_base
+ (i
* 4));
267 ret
= subdev_8255_init(dev
, s
, pci_8255_mmio
, iobase
);
269 iobase
= dev
->iobase
+ (i
* 4);
270 ret
= subdev_8255_init(dev
, s
, NULL
, iobase
);
276 dev_info(dev
->class_dev
, "%s attached (%d digital i/o channels)\n",
277 dev
->board_name
, board
->n_8255
* 24);
282 static void pci_8255_detach(struct comedi_device
*dev
)
284 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
285 const struct pci_8255_boardinfo
*board
= comedi_board(dev
);
286 struct pci_8255_private
*devpriv
= dev
->private;
287 struct comedi_subdevice
*s
;
290 if (!board
|| !devpriv
)
292 if (dev
->subdevices
) {
293 for (i
= 0; i
< board
->n_8255
; i
++) {
294 s
= &dev
->subdevices
[i
];
295 subdev_8255_cleanup(dev
, s
);
299 if (devpriv
->mmio_base
)
300 iounmap(devpriv
->mmio_base
);
302 comedi_pci_disable(pcidev
);
306 static struct comedi_driver pci_8255_driver
= {
307 .driver_name
= "8255_pci",
308 .module
= THIS_MODULE
,
309 .auto_attach
= pci_8255_auto_attach
,
310 .detach
= pci_8255_detach
,
313 static int pci_8255_pci_probe(struct pci_dev
*dev
,
314 const struct pci_device_id
*ent
)
316 return comedi_pci_auto_config(dev
, &pci_8255_driver
);
319 static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table
) = {
320 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK
, PCI_DEVICE_ID_ADLINK_PCI7224
) },
321 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK
, PCI_DEVICE_ID_ADLINK_PCI7248
) },
322 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK
, PCI_DEVICE_ID_ADLINK_PCI7296
) },
323 { PCI_DEVICE(PCI_VENDOR_ID_CB
, PCI_DEVICE_ID_CB_PCIDIO24
) },
324 { PCI_DEVICE(PCI_VENDOR_ID_CB
, PCI_DEVICE_ID_CB_PCIDIO24H
) },
325 { PCI_DEVICE(PCI_VENDOR_ID_CB
, PCI_DEVICE_ID_CB_PCIDIO48H
) },
326 { PCI_DEVICE(PCI_VENDOR_ID_CB
, PCI_DEVICE_ID_CB_PCIDIO96H
) },
327 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PCIDIO96
) },
328 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PCIDIO96B
) },
329 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PXI6508
) },
330 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PCI6503
) },
331 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PCI6503B
) },
332 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PCI6503X
) },
333 { PCI_DEVICE(PCI_VENDOR_ID_NI
, PCI_DEVICE_ID_NI_PXI_6503
) },
336 MODULE_DEVICE_TABLE(pci
, pci_8255_pci_table
);
338 static struct pci_driver pci_8255_pci_driver
= {
340 .id_table
= pci_8255_pci_table
,
341 .probe
= pci_8255_pci_probe
,
342 .remove
= comedi_pci_auto_unconfig
,
344 module_comedi_pci_driver(pci_8255_driver
, pci_8255_pci_driver
);
346 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
347 MODULE_AUTHOR("Comedi http://www.comedi.org");
348 MODULE_LICENSE("GPL");