2 comedi/drivers/adl_pci7296.c
4 COMEDI - Linux Control and Measurement Device Interface
5 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
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.
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.
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.
24 Description: Driver for the Adlink PCI-7296 96 ch. digital io board
25 Devices: [ADLink] PCI-7296 (pci7296)
26 Author: Jon Grierson <jd@renko.co.uk>
30 Configuration Options:
34 #include <linux/comedidev.h>
35 #include <linux/kernel.h>
36 #include <linux/pci.h>
46 #define PCI_DEVICE_ID_PCI7296 0x7296
50 typedef struct skel_board_struct{
56 static adl_pci7296_board adl_pci7296_boards[] = {
57 { "pci7296", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296 },
60 static struct pci_device_id adl_pci7296_pci_table[] __devinitdata = {
61 { PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
64 MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
66 #define thisboard ((adl_pci7296_board *)dev->board_ptr)
70 struct pci_dev *pci_dev;
73 #define devpriv ((adl_pci7296_private *)dev->private)
75 static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it);
76 static int adl_pci7296_detach(comedi_device *dev);
77 static comedi_driver driver_adl_pci7296={
78 driver_name: "adl_pci7296",
80 attach: adl_pci7296_attach,
81 detach: adl_pci7296_detach,
83 board_name: &adl_pci7296_boards[0].name,
84 offset: sizeof(adl_pci7296_board),
85 num_names: sizeof(adl_pci7296_boards) / sizeof(adl_pci7296_board),
89 static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it)
91 struct pci_dev *pcidev;
94 printk("comedi: attempt to attach...\n");
95 printk("comedi%d: adl_pci7432: board=%s\n",dev->minor, thisboard->name);
97 dev->board_name = thisboard->name;
99 if(alloc_private(dev,sizeof(adl_pci7296_private))<0)
102 if(alloc_subdevices(dev, 4)<0)
105 for(pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); pcidev != NULL ;
106 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev))
109 if ( pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
110 pcidev->device == PCI_DEVICE_ID_PCI7296 ) {
111 devpriv->pci_dev = pcidev;
112 if (pci_enable_device(pcidev) < 0) {
113 printk("comedi%d: Failed to enable PCI device\n", dev->minor);
116 if (pci_request_regions(pcidev, "adl_pci7296") < 0) {
117 printk("comedi%d: I/O port conflict\n", dev->minor);
121 dev->iobase = pci_resource_start ( pcidev, 2 );
122 printk ( "comedi: base addr %4lx\n", dev->iobase );
124 dev->board_ptr = adl_pci7296_boards + 0;
126 // four 8255 digital io subdevices
127 s = dev->subdevices + 0;
128 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase));
130 s = dev->subdevices + 1;
131 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT2A));
133 s = dev->subdevices + 2;
134 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT3A));
136 s = dev->subdevices + 3;
137 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT4A));
143 printk("attached\n");
149 static int adl_pci7296_detach(comedi_device *dev)
151 printk("comedi%d: pci7432: remove\n",dev->minor);
153 if (devpriv && devpriv->pci_dev) {
155 pci_release_regions(devpriv->pci_dev);
156 pci_disable_device(devpriv->pci_dev);
158 pci_dev_put(devpriv->pci_dev);
161 // detach four 8255 digital io subdevices
164 subdev_8255_cleanup(dev, dev->subdevices + 0);
165 subdev_8255_cleanup(dev, dev->subdevices + 1);
166 subdev_8255_cleanup(dev, dev->subdevices + 2);
167 subdev_8255_cleanup(dev, dev->subdevices + 3);
174 COMEDI_INITCLEANUP(driver_adl_pci7296);