]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/comedi/drivers/adl_pci7296.c
staging: comedi: adl_pci7432: factor out the PCI device code
[mirror_ubuntu-hirsute-kernel.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
bb71f8b3 40#include "8255.h"
2696fb57 41/* #include "8253.h" */
bb71f8b3
JG
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
8dca707e 50struct adl_pci7296_private {
bb71f8b3
JG
51 int data;
52 struct pci_dev *pci_dev;
8dca707e
BP
53};
54
8dca707e 55#define devpriv ((struct adl_pci7296_private *)dev->private)
bb71f8b3 56
0a85b6f0
MT
57static int adl_pci7296_attach(struct comedi_device *dev,
58 struct comedi_devconfig *it)
bb71f8b3 59{
20fb2280 60 struct pci_dev *pcidev = NULL;
34c43922 61 struct comedi_subdevice *s;
bb71f8b3
JG
62 int bus, slot;
63 int ret;
64
1ab1774f 65 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
bb71f8b3
JG
66
67 dev->board_name = "pci7432";
68 bus = it->options[0];
69 slot = it->options[1];
70
8dca707e 71 if (alloc_private(dev, sizeof(struct adl_pci7296_private)) < 0)
bb71f8b3
JG
72 return -ENOMEM;
73
74 if (alloc_subdevices(dev, 4) < 0)
75 return -ENOMEM;
76
20fb2280 77 for_each_pci_dev(pcidev) {
bb71f8b3 78 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
0a85b6f0 79 pcidev->device == PCI_DEVICE_ID_PCI7296) {
bb71f8b3
JG
80 if (bus || slot) {
81 /* requested particular bus/slot */
82 if (pcidev->bus->number != bus
0a85b6f0 83 || PCI_SLOT(pcidev->devfn) != slot) {
bb71f8b3
JG
84 continue;
85 }
86 }
87 devpriv->pci_dev = pcidev;
88 if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) {
1ab1774f 89 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
0a85b6f0 90 dev->minor);
bb71f8b3
JG
91 return -EIO;
92 }
93
94 dev->iobase = pci_resource_start(pcidev, 2);
1ab1774f
BJ
95 printk(KERN_INFO "comedi: base addr %4lx\n",
96 dev->iobase);
bb71f8b3 97
2696fb57 98 /* four 8255 digital io subdevices */
bb71f8b3
JG
99 s = dev->subdevices + 0;
100 subdev_8255_init(dev, s, NULL,
0a85b6f0 101 (unsigned long)(dev->iobase));
bb71f8b3
JG
102
103 s = dev->subdevices + 1;
104 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
105 (unsigned long)(dev->iobase +
106 PORT2A));
bb71f8b3
JG
107 if (ret < 0)
108 return ret;
109
110 s = dev->subdevices + 2;
111 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
112 (unsigned long)(dev->iobase +
113 PORT3A));
bb71f8b3
JG
114 if (ret < 0)
115 return ret;
116
117 s = dev->subdevices + 3;
118 ret = subdev_8255_init(dev, s, NULL,
0a85b6f0
MT
119 (unsigned long)(dev->iobase +
120 PORT4A));
bb71f8b3
JG
121 if (ret < 0)
122 return ret;
123
1ab1774f
BJ
124 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n",
125 dev->minor);
bb71f8b3
JG
126
127 return 1;
128 }
129 }
130
1ab1774f 131 printk(KERN_ERR "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
0a85b6f0 132 dev->minor, bus, slot);
bb71f8b3
JG
133 return -EIO;
134}
135
484ecc95 136static void adl_pci7296_detach(struct comedi_device *dev)
bb71f8b3 137{
bb71f8b3 138 if (devpriv && devpriv->pci_dev) {
1ab1774f 139 if (dev->iobase)
bb71f8b3 140 comedi_pci_disable(devpriv->pci_dev);
bb71f8b3
JG
141 pci_dev_put(devpriv->pci_dev);
142 }
bb71f8b3
JG
143 if (dev->subdevices) {
144 subdev_8255_cleanup(dev, dev->subdevices + 0);
145 subdev_8255_cleanup(dev, dev->subdevices + 1);
146 subdev_8255_cleanup(dev, dev->subdevices + 2);
147 subdev_8255_cleanup(dev, dev->subdevices + 3);
bb71f8b3 148 }
bb71f8b3
JG
149}
150
75e6301b 151static struct comedi_driver adl_pci7296_driver = {
db0eaeed
HS
152 .driver_name = "adl_pci7296",
153 .module = THIS_MODULE,
154 .attach = adl_pci7296_attach,
155 .detach = adl_pci7296_detach,
156};
157
75e6301b
HS
158static int __devinit adl_pci7296_pci_probe(struct pci_dev *dev,
159 const struct pci_device_id *ent)
727b286b 160{
75e6301b 161 return comedi_pci_auto_config(dev, &adl_pci7296_driver);
727b286b
AT
162}
163
75e6301b 164static void __devexit adl_pci7296_pci_remove(struct pci_dev *dev)
727b286b
AT
165{
166 comedi_pci_auto_unconfig(dev);
167}
168
db0eaeed
HS
169static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
170 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
75e6301b 171 { 0 }
db0eaeed
HS
172};
173MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
174
75e6301b
HS
175static struct pci_driver adl_pci7296_pci_driver = {
176 .name = "adl_pci7296",
db0eaeed 177 .id_table = adl_pci7296_pci_table,
75e6301b
HS
178 .probe = adl_pci7296_pci_probe,
179 .remove = __devexit_p(adl_pci7296_pci_remove),
727b286b 180};
75e6301b 181module_comedi_pci_driver(adl_pci7296_driver, adl_pci7296_pci_driver);
90f703d3
AT
182
183MODULE_AUTHOR("Comedi http://www.comedi.org");
184MODULE_DESCRIPTION("Comedi low-level driver");
185MODULE_LICENSE("GPL");