Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 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

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] - 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
 43 Status: untested
 44 
 45 Some of these boards also have an 8254 programmable timer/counter
 46 chip. This chip is not currently supported by this driver.
 47 
 48 Interrupt support for these boards is also not currently supported.
 49 
 50 Configuration Options: not applicable, uses PCI auto config
 51 */
 52 
 53 #include <linux/module.h>
 54 #include <linux/pci.h>
 55 
 56 #include "../comedidev.h"
 57 
 58 #include "8255.h"
 59 #include "mite.h"
 60 
 61 enum pci_8255_boardid {
 62         BOARD_ADLINK_PCI7224,
 63         BOARD_ADLINK_PCI7248,
 64         BOARD_ADLINK_PCI7296,
 65         BOARD_CB_PCIDIO24,
 66         BOARD_CB_PCIDIO24H,
 67         BOARD_CB_PCIDIO48H_OLD,
 68         BOARD_CB_PCIDIO48H_NEW,
 69         BOARD_CB_PCIDIO96H,
 70         BOARD_NI_PCIDIO96,
 71         BOARD_NI_PCIDIO96B,
 72         BOARD_NI_PXI6508,
 73         BOARD_NI_PCI6503,
 74         BOARD_NI_PCI6503B,
 75         BOARD_NI_PCI6503X,
 76         BOARD_NI_PXI_6503,
 77 };
 78 
 79 struct pci_8255_boardinfo {
 80         const char *name;
 81         int dio_badr;
 82         int n_8255;
 83         unsigned int has_mite:1;
 84 };
 85 
 86 static const struct pci_8255_boardinfo pci_8255_boards[] = {
 87         [BOARD_ADLINK_PCI7224] = {
 88                 .name           = "adl_pci-7224",
 89                 .dio_badr       = 2,
 90                 .n_8255         = 1,
 91         },
 92         [BOARD_ADLINK_PCI7248] = {
 93                 .name           = "adl_pci-7248",
 94                 .dio_badr       = 2,
 95                 .n_8255         = 2,
 96         },
 97         [BOARD_ADLINK_PCI7296] = {
 98                 .name           = "adl_pci-7296",
 99                 .dio_badr       = 2,
100                 .n_8255         = 4,
101         },
102         [BOARD_CB_PCIDIO24] = {
103                 .name           = "cb_pci-dio24",
104                 .dio_badr       = 2,
105                 .n_8255         = 1,
106         },
107         [BOARD_CB_PCIDIO24H] = {
108                 .name           = "cb_pci-dio24h",
109                 .dio_badr       = 2,
110                 .n_8255         = 1,
111         },
112         [BOARD_CB_PCIDIO48H_OLD] = {
113                 .name           = "cb_pci-dio48h",
114                 .dio_badr       = 1,
115                 .n_8255         = 2,
116         },
117         [BOARD_CB_PCIDIO48H_NEW] = {
118                 .name           = "cb_pci-dio48h",
119                 .dio_badr       = 2,
120                 .n_8255         = 2,
121         },
122         [BOARD_CB_PCIDIO96H] = {
123                 .name           = "cb_pci-dio96h",
124                 .dio_badr       = 2,
125                 .n_8255         = 4,
126         },
127         [BOARD_NI_PCIDIO96] = {
128                 .name           = "ni_pci-dio-96",
129                 .dio_badr       = 1,
130                 .n_8255         = 4,
131                 .has_mite       = 1,
132         },
133         [BOARD_NI_PCIDIO96B] = {
134                 .name           = "ni_pci-dio-96b",
135                 .dio_badr       = 1,
136                 .n_8255         = 4,
137                 .has_mite       = 1,
138         },
139         [BOARD_NI_PXI6508] = {
140                 .name           = "ni_pxi-6508",
141                 .dio_badr       = 1,
142                 .n_8255         = 4,
143                 .has_mite       = 1,
144         },
145         [BOARD_NI_PCI6503] = {
146                 .name           = "ni_pci-6503",
147                 .dio_badr       = 1,
148                 .n_8255         = 1,
149                 .has_mite       = 1,
150         },
151         [BOARD_NI_PCI6503B] = {
152                 .name           = "ni_pci-6503b",
153                 .dio_badr       = 1,
154                 .n_8255         = 1,
155                 .has_mite       = 1,
156         },
157         [BOARD_NI_PCI6503X] = {
158                 .name           = "ni_pci-6503x",
159                 .dio_badr       = 1,
160                 .n_8255         = 1,
161                 .has_mite       = 1,
162         },
163         [BOARD_NI_PXI_6503] = {
164                 .name           = "ni_pxi-6503",
165                 .dio_badr       = 1,
166                 .n_8255         = 1,
167                 .has_mite       = 1,
168         },
169 };
170 
171 struct pci_8255_private {
172         void __iomem *mmio_base;
173 };
174 
175 static int pci_8255_mite_init(struct pci_dev *pcidev)
176 {
177         void __iomem *mite_base;
178         u32 main_phys_addr;
179 
180         /* ioremap the MITE registers (BAR 0) temporarily */
181         mite_base = pci_ioremap_bar(pcidev, 0);
182         if (!mite_base)
183                 return -ENOMEM;
184 
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);
188 
189         /* finished with MITE registers */
190         iounmap(mite_base);
191         return 0;
192 }
193 
194 static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
195 {
196         void __iomem *mmio_base = (void __iomem *)iobase;
197 
198         if (dir) {
199                 writeb(data, mmio_base + port);
200                 return 0;
201         } else {
202                 return readb(mmio_base  + port);
203         }
204 }
205 
206 static int pci_8255_auto_attach(struct comedi_device *dev,
207                                 unsigned long context)
208 {
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;
213         bool is_mmio;
214         int ret;
215         int i;
216 
217         if (context < ARRAY_SIZE(pci_8255_boards))
218                 board = &pci_8255_boards[context];
219         if (!board)
220                 return -ENODEV;
221         dev->board_ptr = board;
222         dev->board_name = board->name;
223 
224         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
225         if (!devpriv)
226                 return -ENOMEM;
227 
228         ret = comedi_pci_enable(dev);
229         if (ret)
230                 return ret;
231 
232         if (board->has_mite) {
233                 ret = pci_8255_mite_init(pcidev);
234                 if (ret)
235                         return ret;
236         }
237 
238         is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
239                    IORESOURCE_MEM) != 0;
240         if (is_mmio) {
241                 devpriv->mmio_base = pci_ioremap_bar(pcidev, board->dio_badr);
242                 if (!devpriv->mmio_base)
243                         return -ENOMEM;
244         } else {
245                 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
246         }
247 
248         /*
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.
252          */
253         ret = comedi_alloc_subdevices(dev, board->n_8255);
254         if (ret)
255                 return ret;
256 
257         for (i = 0; i < board->n_8255; i++) {
258                 unsigned long iobase;
259 
260                 s = &dev->subdevices[i];
261                 if (is_mmio) {
262                         iobase = (unsigned long)(devpriv->mmio_base + (i * 4));
263                         ret = subdev_8255_init(dev, s, pci_8255_mmio, iobase);
264                 } else {
265                         iobase = dev->iobase + (i * 4);
266                         ret = subdev_8255_init(dev, s, NULL, iobase);
267                 }
268                 if (ret)
269                         return ret;
270         }
271 
272         return 0;
273 }
274 
275 static void pci_8255_detach(struct comedi_device *dev)
276 {
277         struct pci_8255_private *devpriv = dev->private;
278 
279         if (devpriv && devpriv->mmio_base)
280                 iounmap(devpriv->mmio_base);
281         comedi_pci_disable(dev);
282 }
283 
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,
289 };
290 
291 static int pci_8255_pci_probe(struct pci_dev *dev,
292                               const struct pci_device_id *id)
293 {
294         return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
295 }
296 
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 },
315         { 0 }
316 };
317 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
318 
319 static struct pci_driver pci_8255_pci_driver = {
320         .name           = "8255_pci",
321         .id_table       = pci_8255_pci_table,
322         .probe          = pci_8255_pci_probe,
323         .remove         = comedi_pci_auto_unconfig,
324 };
325 module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
326 
327 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
328 MODULE_AUTHOR("Comedi http://www.comedi.org");
329 MODULE_LICENSE("GPL");
330 

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