Version:  2.0.40 2.2.26 2.4.37 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 3.17

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 
 60 enum pci_8255_boardid {
 61         BOARD_ADLINK_PCI7224,
 62         BOARD_ADLINK_PCI7248,
 63         BOARD_ADLINK_PCI7296,
 64         BOARD_CB_PCIDIO24,
 65         BOARD_CB_PCIDIO24H,
 66         BOARD_CB_PCIDIO48H_OLD,
 67         BOARD_CB_PCIDIO48H_NEW,
 68         BOARD_CB_PCIDIO96H,
 69         BOARD_NI_PCIDIO96,
 70         BOARD_NI_PCIDIO96B,
 71         BOARD_NI_PXI6508,
 72         BOARD_NI_PCI6503,
 73         BOARD_NI_PCI6503B,
 74         BOARD_NI_PCI6503X,
 75         BOARD_NI_PXI_6503,
 76 };
 77 
 78 struct pci_8255_boardinfo {
 79         const char *name;
 80         int dio_badr;
 81         int n_8255;
 82         unsigned int has_mite:1;
 83 };
 84 
 85 static const struct pci_8255_boardinfo pci_8255_boards[] = {
 86         [BOARD_ADLINK_PCI7224] = {
 87                 .name           = "adl_pci-7224",
 88                 .dio_badr       = 2,
 89                 .n_8255         = 1,
 90         },
 91         [BOARD_ADLINK_PCI7248] = {
 92                 .name           = "adl_pci-7248",
 93                 .dio_badr       = 2,
 94                 .n_8255         = 2,
 95         },
 96         [BOARD_ADLINK_PCI7296] = {
 97                 .name           = "adl_pci-7296",
 98                 .dio_badr       = 2,
 99                 .n_8255         = 4,
100         },
101         [BOARD_CB_PCIDIO24] = {
102                 .name           = "cb_pci-dio24",
103                 .dio_badr       = 2,
104                 .n_8255         = 1,
105         },
106         [BOARD_CB_PCIDIO24H] = {
107                 .name           = "cb_pci-dio24h",
108                 .dio_badr       = 2,
109                 .n_8255         = 1,
110         },
111         [BOARD_CB_PCIDIO48H_OLD] = {
112                 .name           = "cb_pci-dio48h",
113                 .dio_badr       = 1,
114                 .n_8255         = 2,
115         },
116         [BOARD_CB_PCIDIO48H_NEW] = {
117                 .name           = "cb_pci-dio48h",
118                 .dio_badr       = 2,
119                 .n_8255         = 2,
120         },
121         [BOARD_CB_PCIDIO96H] = {
122                 .name           = "cb_pci-dio96h",
123                 .dio_badr       = 2,
124                 .n_8255         = 4,
125         },
126         [BOARD_NI_PCIDIO96] = {
127                 .name           = "ni_pci-dio-96",
128                 .dio_badr       = 1,
129                 .n_8255         = 4,
130                 .has_mite       = 1,
131         },
132         [BOARD_NI_PCIDIO96B] = {
133                 .name           = "ni_pci-dio-96b",
134                 .dio_badr       = 1,
135                 .n_8255         = 4,
136                 .has_mite       = 1,
137         },
138         [BOARD_NI_PXI6508] = {
139                 .name           = "ni_pxi-6508",
140                 .dio_badr       = 1,
141                 .n_8255         = 4,
142                 .has_mite       = 1,
143         },
144         [BOARD_NI_PCI6503] = {
145                 .name           = "ni_pci-6503",
146                 .dio_badr       = 1,
147                 .n_8255         = 1,
148                 .has_mite       = 1,
149         },
150         [BOARD_NI_PCI6503B] = {
151                 .name           = "ni_pci-6503b",
152                 .dio_badr       = 1,
153                 .n_8255         = 1,
154                 .has_mite       = 1,
155         },
156         [BOARD_NI_PCI6503X] = {
157                 .name           = "ni_pci-6503x",
158                 .dio_badr       = 1,
159                 .n_8255         = 1,
160                 .has_mite       = 1,
161         },
162         [BOARD_NI_PXI_6503] = {
163                 .name           = "ni_pxi-6503",
164                 .dio_badr       = 1,
165                 .n_8255         = 1,
166                 .has_mite       = 1,
167         },
168 };
169 
170 /* ripped from mite.h and mite_setup2() to avoid mite dependancy */
171 #define MITE_IODWBSR    0xc0     /* IO Device Window Base Size Register */
172 #define WENAB           (1 << 7) /* window enable */
173 
174 static int pci_8255_mite_init(struct pci_dev *pcidev)
175 {
176         void __iomem *mite_base;
177         u32 main_phys_addr;
178 
179         /* ioremap the MITE registers (BAR 0) temporarily */
180         mite_base = pci_ioremap_bar(pcidev, 0);
181         if (!mite_base)
182                 return -ENOMEM;
183 
184         /* set data window to main registers (BAR 1) */
185         main_phys_addr = pci_resource_start(pcidev, 1);
186         writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
187 
188         /* finished with MITE registers */
189         iounmap(mite_base);
190         return 0;
191 }
192 
193 static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
194 {
195         void __iomem *mmio_base = (void __iomem *)iobase;
196 
197         if (dir) {
198                 writeb(data, mmio_base + port);
199                 return 0;
200         }
201         return readb(mmio_base  + port);
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         bool is_mmio;
211         int ret;
212         int i;
213 
214         if (context < ARRAY_SIZE(pci_8255_boards))
215                 board = &pci_8255_boards[context];
216         if (!board)
217                 return -ENODEV;
218         dev->board_ptr = board;
219         dev->board_name = board->name;
220 
221         ret = comedi_pci_enable(dev);
222         if (ret)
223                 return ret;
224 
225         if (board->has_mite) {
226                 ret = pci_8255_mite_init(pcidev);
227                 if (ret)
228                         return ret;
229         }
230 
231         is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
232                    IORESOURCE_MEM) != 0;
233         if (is_mmio) {
234                 dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr);
235                 if (!dev->mmio)
236                         return -ENOMEM;
237         } else {
238                 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
239         }
240 
241         /*
242          * One, two, or four subdevices are setup by this driver depending
243          * on the number of channels provided by the board. Each subdevice
244          * has 24 channels supported by the 8255 module.
245          */
246         ret = comedi_alloc_subdevices(dev, board->n_8255);
247         if (ret)
248                 return ret;
249 
250         for (i = 0; i < board->n_8255; i++) {
251                 unsigned long iobase;
252 
253                 s = &dev->subdevices[i];
254                 if (is_mmio) {
255                         iobase = (unsigned long)(dev->mmio + (i * 4));
256                         ret = subdev_8255_init(dev, s, pci_8255_mmio, iobase);
257                 } else {
258                         iobase = dev->iobase + (i * 4);
259                         ret = subdev_8255_init(dev, s, NULL, iobase);
260                 }
261                 if (ret)
262                         return ret;
263         }
264 
265         return 0;
266 }
267 
268 static void pci_8255_detach(struct comedi_device *dev)
269 {
270         if (dev->mmio)
271                 iounmap(dev->mmio);
272         comedi_pci_disable(dev);
273 }
274 
275 static struct comedi_driver pci_8255_driver = {
276         .driver_name    = "8255_pci",
277         .module         = THIS_MODULE,
278         .auto_attach    = pci_8255_auto_attach,
279         .detach         = pci_8255_detach,
280 };
281 
282 static int pci_8255_pci_probe(struct pci_dev *dev,
283                               const struct pci_device_id *id)
284 {
285         return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
286 }
287 
288 static const struct pci_device_id pci_8255_pci_table[] = {
289         { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
290         { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
291         { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
292         { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
293         { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
294         { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, 0x0000, 0x0000),
295           .driver_data = BOARD_CB_PCIDIO48H_OLD },
296         { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b),
297           .driver_data = BOARD_CB_PCIDIO48H_NEW },
298         { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
299         { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
300         { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
301         { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
302         { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
303         { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
304         { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
305         { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
306         { 0 }
307 };
308 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
309 
310 static struct pci_driver pci_8255_pci_driver = {
311         .name           = "8255_pci",
312         .id_table       = pci_8255_pci_table,
313         .probe          = pci_8255_pci_probe,
314         .remove         = comedi_pci_auto_unconfig,
315 };
316 module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
317 
318 MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
319 MODULE_AUTHOR("Comedi http://www.comedi.org");
320 MODULE_LICENSE("GPL");
321 

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