Staging: comedi: Remove COMEDI_INITCLEANUP macro
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / comedi / drivers / adl_pci7296.c
CommitLineData
bb71f8b3
JG
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/*
23Driver: adl_pci7296
24Description: Driver for the Adlink PCI-7296 96 ch. digital io board
25Devices: [ADLink] PCI-7296 (adl_pci7296)
26Author: Jon Grierson <jd@renko.co.uk>
27Updated: Mon, 14 Apr 2008 15:05:56 +0100
28Status: testing
29
30Configuration 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 "comedi_pci.h"
41#include "8255.h"
2696fb57 42/* #include "8253.h" */
bb71f8b3
JG
43
44#define PORT1A 0
45#define PORT2A 4
46#define PORT3A 8
47#define PORT4A 12
48
49#define PCI_DEVICE_ID_PCI7296 0x7296
50
51static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
0a85b6f0
MT
52 {
53 PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296, PCI_ANY_ID,
54 PCI_ANY_ID, 0, 0, 0}, {
55 0}
bb71f8b3
JG
56};
57
58MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
59
8dca707e 60struct adl_pci7296_private {
bb71f8b3
JG
61 int data;
62 struct pci_dev *pci_dev;
8dca707e
BP
63};
64
8dca707e 65#define devpriv ((struct adl_pci7296_private *)dev->private)
bb71f8b3 66
0a85b6f0
MT
67static int adl_pci7296_attach(struct comedi_device *dev,
68 struct comedi_devconfig *it);
da91b269 69static int adl_pci7296_detach(struct comedi_device *dev);
139dfbdf 70static struct comedi_driver driver_adl_pci7296 = {
68c3dbff
BP
71 .driver_name = "adl_pci7296",
72 .module = THIS_MODULE,
73 .attach = adl_pci7296_attach,
74 .detach = adl_pci7296_detach,
bb71f8b3
JG
75};
76
0a85b6f0
MT
77static int adl_pci7296_attach(struct comedi_device *dev,
78 struct comedi_devconfig *it)
bb71f8b3
JG
79{
80 struct pci_dev *pcidev;
34c43922 81 struct comedi_subdevice *s;
bb71f8b3
JG
82 int bus, slot;
83 int ret;
84
1ab1774f 85 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
bb71f8b3
JG
86
87 dev->board_name = "pci7432";
88 bus = it->options[0];
89 slot = it->options[1];
90
8dca707e 91 if (alloc_private(dev, sizeof(struct adl_pci7296_private)) < 0)
bb71f8b3
JG
92 return -ENOMEM;
93
94 if (alloc_subdevices(dev, 4) < 0)
95 return -ENOMEM;
96
97 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
0a85b6f0
MT
98 pcidev != NULL;
99 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
bb71f8b3
JG
100
101 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
0a85b6f0 102 pcidev->device == PCI_DEVICE_ID_PCI7296) {
bb71f8b3
JG
103 if (bus || slot) {
104 /* requested particular bus/slot */
105 if (pcidev->bus->number != bus
0a85b6f0 106 || PCI_SLOT(pcidev->devfn) != slot) {
bb71f8b3
JG
107 continue;
108 }
109 }
110 devpriv->pci_dev = pcidev;
111 if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) {
1ab1774f 112 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
0a85b6f0 113 dev->minor);
bb71f8b3
JG
114 return -EIO;
115 }
116
117 dev->iobase = pci_resource_start(pcidev, 2);
1ab1774f
BJ
118 printk(KERN_INFO "comedi: base addr %4lx\n",
119 dev->iobase);
bb71f8b3 120
2696fb57 121 /* four 8255 digital io subdevices */
bb71f8b3
JG
122 s = dev->subdevices + 0;
123 subdev_8255_init(dev, s, NULL,
0a85b6f0 124 (unsigned long)(dev->iobase));
bb71f8b3
JG
125
126 s = dev->subdevices + 1;
127 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
128 (unsigned long)(dev->iobase +
129 PORT2A));
bb71f8b3
JG
130 if (ret < 0)
131 return ret;
132
133 s = dev->subdevices + 2;
134 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
135 (unsigned long)(dev->iobase +
136 PORT3A));
bb71f8b3
JG
137 if (ret < 0)
138 return ret;
139
140 s = dev->subdevices + 3;
141 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
142 (unsigned long)(dev->iobase +
143 PORT4A));
bb71f8b3
JG
144 if (ret < 0)
145 return ret;
146
1ab1774f
BJ
147 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n",
148 dev->minor);
bb71f8b3
JG
149
150 return 1;
151 }
152 }
153
1ab1774f 154 printk(KERN_ERR "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
0a85b6f0 155 dev->minor, bus, slot);
bb71f8b3
JG
156 return -EIO;
157}
158
da91b269 159static int adl_pci7296_detach(struct comedi_device *dev)
bb71f8b3 160{
1ab1774f 161 printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);
bb71f8b3
JG
162
163 if (devpriv && devpriv->pci_dev) {
1ab1774f 164 if (dev->iobase)
bb71f8b3 165 comedi_pci_disable(devpriv->pci_dev);
bb71f8b3
JG
166 pci_dev_put(devpriv->pci_dev);
167 }
2696fb57 168 /* detach four 8255 digital io subdevices */
bb71f8b3
JG
169 if (dev->subdevices) {
170 subdev_8255_cleanup(dev, dev->subdevices + 0);
171 subdev_8255_cleanup(dev, dev->subdevices + 1);
172 subdev_8255_cleanup(dev, dev->subdevices + 2);
173 subdev_8255_cleanup(dev, dev->subdevices + 3);
174
175 }
176
177 return 0;
178}
179
180COMEDI_PCI_INITCLEANUP(driver_adl_pci7296, adl_pci7296_pci_table);
90f703d3
AT
181
182MODULE_AUTHOR("Comedi http://www.comedi.org");
183MODULE_DESCRIPTION("Comedi low-level driver");
184MODULE_LICENSE("GPL");