]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/adl_pci7296.c
19b47af9c10e50729558663e36fff54e5a36139e
[karo-tx-linux.git] / drivers / staging / comedi / drivers / adl_pci7296.c
1 /*
2     comedi/drivers/adl_pci7296.c
3
4     COMEDI - Linux Control and Measurement Device Interface
5     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22 /*
23 Driver: adl_pci7296
24 Description: Driver for the Adlink PCI-7296 96 ch. digital io board
25 Devices: [ADLink] PCI-7296 (adl_pci7296)
26 Author: Jon Grierson <jd@renko.co.uk>
27 Updated: Mon, 14 Apr 2008 15:05:56 +0100
28 Status: testing
29
30 Configuration Options:
31   [0] - PCI bus of device (optional)
32   [1] - PCI slot of device (optional)
33   If bus/slot is not specified, the first supported
34   PCI device found will be used.
35 */
36
37 #include "../comedidev.h"
38 #include <linux/kernel.h>
39
40 #include "8255.h"
41 /* #include "8253.h" */
42
43 #define PORT1A 0
44 #define PORT2A 4
45 #define PORT3A 8
46 #define PORT4A 12
47
48 #define PCI_DEVICE_ID_PCI7296 0x7296
49
50 static struct pci_dev *adl_pci7296_find_pci(struct comedi_device *dev,
51                                             struct comedi_devconfig *it)
52 {
53         struct pci_dev *pcidev = NULL;
54         int bus = it->options[0];
55         int slot = it->options[1];
56
57         for_each_pci_dev(pcidev) {
58                 if (pcidev->vendor != PCI_VENDOR_ID_ADLINK ||
59                     pcidev->device != PCI_DEVICE_ID_PCI7296)
60                         continue;
61                 if (bus || slot) {
62                         /* requested particular bus/slot */
63                         if (pcidev->bus->number != bus ||
64                             PCI_SLOT(pcidev->devfn) != slot)
65                                 continue;
66                 }
67                 return pcidev;
68         }
69         printk(KERN_ERR
70                 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
71                dev->minor, bus, slot);
72         return NULL;
73 }
74
75 static int adl_pci7296_attach(struct comedi_device *dev,
76                               struct comedi_devconfig *it)
77 {
78         struct pci_dev *pcidev;
79         struct comedi_subdevice *s;
80         int ret;
81
82         printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
83
84         dev->board_name = "pci7432";
85
86         ret = comedi_alloc_subdevices(dev, 4);
87         if (ret)
88                 return ret;
89
90         pcidev = adl_pci7296_find_pci(dev, it);
91         if (!pcidev)
92                 return -EIO;
93         comedi_set_hw_dev(dev, &pcidev->dev);
94
95         if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) {
96                 printk(KERN_ERR
97                         "comedi%d: Failed to enable PCI device and request regions\n",
98                         dev->minor);
99                 return -EIO;
100         }
101
102         dev->iobase = pci_resource_start(pcidev, 2);
103         printk(KERN_INFO "comedi: base addr %4lx\n", dev->iobase);
104
105         /*  four 8255 digital io subdevices */
106         s = dev->subdevices + 0;
107         subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase));
108
109         s = dev->subdevices + 1;
110         ret = subdev_8255_init(dev, s, NULL,
111                                 (unsigned long)(dev->iobase + PORT2A));
112         if (ret < 0)
113                 return ret;
114
115         s = dev->subdevices + 2;
116         ret = subdev_8255_init(dev, s, NULL,
117                                 (unsigned long)(dev->iobase + PORT3A));
118         if (ret < 0)
119                 return ret;
120
121         s = dev->subdevices + 3;
122         ret = subdev_8255_init(dev, s, NULL,
123                                 (unsigned long)(dev->iobase + PORT4A));
124         if (ret < 0)
125                 return ret;
126
127         printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n", dev->minor);
128
129         return 0;
130 }
131
132 static void adl_pci7296_detach(struct comedi_device *dev)
133 {
134         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
135
136         if (pcidev) {
137                 if (dev->iobase)
138                         comedi_pci_disable(pcidev);
139                 pci_dev_put(pcidev);
140         }
141         if (dev->subdevices) {
142                 subdev_8255_cleanup(dev, dev->subdevices + 0);
143                 subdev_8255_cleanup(dev, dev->subdevices + 1);
144                 subdev_8255_cleanup(dev, dev->subdevices + 2);
145                 subdev_8255_cleanup(dev, dev->subdevices + 3);
146         }
147 }
148
149 static struct comedi_driver adl_pci7296_driver = {
150         .driver_name    = "adl_pci7296",
151         .module         = THIS_MODULE,
152         .attach         = adl_pci7296_attach,
153         .detach         = adl_pci7296_detach,
154 };
155
156 static int __devinit adl_pci7296_pci_probe(struct pci_dev *dev,
157                                            const struct pci_device_id *ent)
158 {
159         return comedi_pci_auto_config(dev, &adl_pci7296_driver);
160 }
161
162 static void __devexit adl_pci7296_pci_remove(struct pci_dev *dev)
163 {
164         comedi_pci_auto_unconfig(dev);
165 }
166
167 static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
168         { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
169         { 0 }
170 };
171 MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
172
173 static struct pci_driver adl_pci7296_pci_driver = {
174         .name           = "adl_pci7296",
175         .id_table       = adl_pci7296_pci_table,
176         .probe          = adl_pci7296_pci_probe,
177         .remove         = __devexit_p(adl_pci7296_pci_remove),
178 };
179 module_comedi_pci_driver(adl_pci7296_driver, adl_pci7296_pci_driver);
180
181 MODULE_AUTHOR("Comedi http://www.comedi.org");
182 MODULE_DESCRIPTION("Comedi low-level driver");
183 MODULE_LICENSE("GPL");