Version:  2.0.40 2.2.26 2.4.37 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0

Linux/drivers/staging/comedi/drivers/8255_pci.c

  1 /*
  2  * COMEDI driver for generic PCI based 8255 digital i/o boards
  3  * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
  4  *
  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:
  8  *      Yoshiya Matsuzaka
  9  *
 10  * COMEDI - Linux Control and Measurement Device Interface
 11  * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
 12  *
 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.
 17  *
 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.
 22  */
 23 
 24 /*
 25  * Driver: 8255_pci
 26  * Description: Generic PCI based 8255 Digital I/O boards
 27  * Devices: [ADLink] PCI-7224 (adl_pci-7224), PCI-7248 (adl_pci-7248),
 28  *   PCI-7296 (adl_pci-7296),
 29  *   [Measurement Computing] PCI-DIO24 (cb_pci-dio24),
 30  *   PCI-DIO24H (cb_pci-dio24h), PCI-DIO48H (cb_pci-dio48h),
 31  *   PCI-DIO96H (cb_pci-dio96h),
 32  *   [National Instruments] PCI-DIO-96 (ni_pci-dio-96),
 33  *   PCI-DIO-96B (ni_pci-dio-96b), PXI-6508 (ni_pxi-6508),
 34  *   PCI-6503 (ni_pci-6503), PCI-6503B (ni_pci-6503b),
 35  *   PCI-6503X (ni_pci-6503x), PXI-6503 (ni_pxi-6503)
 36  * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
 37  * Updated: Wed, 12 Sep 2012 11:52:01 -0700
 38  * Status: untested
 39  *
 40  * These boards have one or more 8255 digital I/O chips, each of which
 41  * is supported as a separate 24-channel DIO subdevice.
 42  *
 43  * Boards with 24 DIO channels (1 DIO subdevice):
 44  *
 45  *   PCI-7224, PCI-DIO24, PCI-DIO24H, PCI-6503, PCI-6503B, PCI-6503X,
 46  *   PXI-6503
 47  *
 48  * Boards with 48 DIO channels (2 DIO subdevices):
 49  *
 50  *   PCI-7248, PCI-DIO48H
 51  *
 52  * Boards with 96 DIO channels (4 DIO subdevices):
 53  *
 54  *   PCI-7296, PCI-DIO96H, PCI-DIO-96, PCI-DIO-96B, PXI-6508
 55  *
 56  * Some of these boards also have an 8254 programmable timer/counter
 57  * chip.  This chip is not currently supported by this driver.
 58  *
 59  * Interrupt support for these boards is also not currently supported.
 60  *
 61  * Configuration Options: not applicable, uses PCI auto config.
 62  */
 63 
 64 #include <linux/module.h>
 65 #include <linux/pci.h>
 66 
 67 #include "../comedidev.h"
 68 
 69 #include "8255.h"
 70 
 71 enum pci_8255_boardid {
 72         BOARD_ADLINK_PCI7224,
 73         BOARD_ADLINK_PCI7248,
 74         BOARD_ADLINK_PCI7296,
 75         BOARD_CB_PCIDIO24,
 76         BOARD_CB_PCIDIO24H,
 77         BOARD_CB_PCIDIO48H_OLD,
 78         BOARD_CB_PCIDIO48H_NEW,
 79         BOARD_CB_PCIDIO96H,
 80         BOARD_NI_PCIDIO96,
 81         BOARD_NI_PCIDIO96B,
 82         BOARD_NI_PXI6508,
 83         BOARD_NI_PCI6503,
 84         BOARD_NI_PCI6503B,
 85         BOARD_NI_PCI6503X,
 86         BOARD_NI_PXI_6503,
 87 };
 88 
 89 struct pci_8255_boardinfo {
 90         const char *name;
 91         int dio_badr;
 92         int n_8255;
 93         unsigned int has_mite:1;
 94 };
 95 
 96 static const struct pci_8255_boardinfo pci_8255_boards[] = {
 97         [BOARD_ADLINK_PCI7224] = {
 98                 .name           = "adl_pci-7224",
 99                 .dio_badr       = 2,
100                 .n_8255         = 1,
101         },
102         [BOARD_ADLINK_PCI7248] = {
103                 .name           = "adl_pci-7248",
104                 .dio_badr       = 2,
105                 .n_8255         = 2,
106         },
107         [BOARD_ADLINK_PCI7296] = {
108                 .name           = "adl_pci-7296",
109                 .dio_badr       = 2,
110                 .n_8255         = 4,
111         },
112         [BOARD_CB_PCIDIO24] = {
113                 .name           = "cb_pci-dio24",
114                 .dio_badr       = 2,
115                 .n_8255         = 1,
116         },
117         [BOARD_CB_PCIDIO24H] = {
118                 .name           = "cb_pci-dio24h",
119                 .dio_badr       = 2,
120                 .n_8255         = 1,
121         },
122         [BOARD_CB_PCIDIO48H_OLD] = {
123                 .name           = "cb_pci-dio48h",
124                 .dio_badr       = 1,
125                 .n_8255         = 2,
126         },
127         [BOARD_CB_PCIDIO48H_NEW] = {
128                 .name           = "cb_pci-dio48h",
129                 .dio_badr       = 2,
130                 .n_8255         = 2,
131         },
132         [BOARD_CB_PCIDIO96H] = {
133                 .name           = "cb_pci-dio96h",
134                 .dio_badr       = 2,
135                 .n_8255         = 4,
136         },
137         [BOARD_NI_PCIDIO96] = {
138                 .name           = "ni_pci-dio-96",
139                 .dio_badr       = 1,
140                 .n_8255         = 4,
141                 .has_mite       = 1,
142         },
143         [BOARD_NI_PCIDIO96B] = {
144                 .name           = "ni_pci-dio-96b",
145                 .dio_badr       = 1,
146                 .n_8255         = 4,
147                 .has_mite       = 1,
148         },
149         [BOARD_NI_PXI6508] = {
150                 .name           = "ni_pxi-6508",
151                 .dio_badr       = 1,
152                 .n_8255         = 4,
153                 .has_mite       = 1,
154         },
155         [BOARD_NI_PCI6503] = {
156                 .name           = "ni_pci-6503",
157                 .dio_badr       = 1,
158                 .n_8255         = 1,
159                 .has_mite       = 1,
160         },
161         [BOARD_NI_PCI6503B] = {
162                 .name           = "ni_pci-6503b",
163                 .dio_badr       = 1,
164                 .n_8255         = 1,
165                 .has_mite       = 1,
166         },
167         [BOARD_NI_PCI6503X] = {
168                 .name           = "ni_pci-6503x",
169                 .dio_badr       = 1,
170                 .n_8255         = 1,
171                 .has_mite       = 1,
172         },
173         [BOARD_NI_PXI_6503] = {
174                 .name           = "ni_pxi-6503",
175                 .dio_badr       = 1,
176                 .n_8255         = 1,
177                 .has_mite       = 1,
178         },
179 };
180 
181 /* ripped from mite.h and mite_setup2() to avoid mite dependancy */
182 #define MITE_IODWBSR    0xc0     /* IO Device Window Base Size Register */
183 #define WENAB           (1 << 7) /* window enable */
184 
185 static int pci_8255_mite_init(struct pci_dev *pcidev)
186 {
187         void __iomem *mite_base;
188         u32 main_phys_addr;
189 
190         /* ioremap the MITE registers (BAR 0) temporarily */
191         mite_base = pci_ioremap_bar(pcidev, 0);
192         if (!mite_base)
193                 return -ENOMEM;
194 
195         /* set data window to main registers (BAR 1) */
196         main_phys_addr = pci_resource_start(pcidev, 1);
197         writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
198 
199         /* finished with MITE registers */
200         iounmap(mite_base);
201         return 0;
202 }
203 
204 static int pci_8255_auto_attach(struct comedi_device *dev,
205                                 unsigned long context)
206 {
207         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
208         const struct pci_8255_boardinfo *board = NULL;
209         struct comedi_subdevice *s;
210         int ret;
211         int i;
212 
213         if (context < ARRAY_SIZE(pci_8255_boards))
214                 board = &pci_8255_boards[context];
215         if (!board)
216                 return -ENODEV;
217         dev->board_ptr = board;
218         dev->board_name = board->name;
219 
220         ret = comedi_pci_enable(dev);
221         if (ret)
222                 return ret;
223 
224         if (board->has_mite) {
225                 ret = pci_8255_mite_init(pcidev);
226                 if (ret)
227                         return ret;
228         }
229 
230         if ((pci_resource_flags(pcidev, board->dio_badr) & IORESOURCE_MEM)) {
231                 dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr);
232                 if (!dev->mmio)
233                         return -ENOMEM;
234         } else {
235                 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
236         }
237 
238         /*
239          * One, two, or four subdevices are setup by this driver depending
240          * on the number of channels provided by the board. Each subdevice
241          * has 24 channels supported by the 8255 module.
242          */
243         ret = comedi_alloc_subdevices(dev, board->n_8255);
244         if (ret)
245                 return ret;
246 
247         for (i = 0; i < board->n_8255; i++) {
248                 s = &dev->subdevices[i];
249                 if (dev->mmio)
250                         ret = subdev_8255_mm_init(dev, s, NULL, i * I8255_SIZE);
251                 else
252                         ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE);
253                 if (ret)
254                         return ret;
255         }
256 
257         return 0;
258 }
259 
260 static struct comedi_driver pci_8255_driver = {
261         .driver_name    = "8255_pci",
262         .module         = THIS_MODULE,
263         .auto_attach    = pci_8255_auto_attach,
264         .detach         = comedi_pci_detach,
265 };
266 
267 static int pci_8255_pci_probe(struct pci_dev *dev,
268                               const struct pci_device_id *id)
269 {
270         return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
271 }
272 
273 static const struct pci_device_id pci_8255_pci_table[] = {
274         { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
275         { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
276         { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
277         { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
278         { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
279         { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, 0x0000, 0x0000),
280           .driver_data = BOARD_CB_PCIDIO48H_OLD },
281         { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b),
282           .driver_data = BOARD_CB_PCIDIO48H_NEW },
283         { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
284         { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
285         { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
286         { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
287         { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
288         { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
289         { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
290         { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
291         { 0 }
292 };
293 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
294 
295 static struct pci_driver pci_8255_pci_driver = {
296         .name           = "8255_pci",
297         .id_table       = pci_8255_pci_table,
298         .probe          = pci_8255_pci_probe,
299         .remove         = comedi_pci_auto_unconfig,
300 };
301 module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
302 
303 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
304 MODULE_AUTHOR("Comedi http://www.comedi.org");
305 MODULE_LICENSE("GPL");
306 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us