Got rid of unnecessary casts when initializing comedi_driver.board_name
[comedi.git] / 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.o
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>
27 Updated: 2.8.2006
28 Status: testing
29
30 Configuration Options:
31   none
32 */
33
34 #include <linux/comedidev.h>
35 #include <linux/kernel.h>
36 #include <linux/pci.h>
37
38 #include "8255.h"
39 // #include "8253.h"
40
41 #define PORT1A 0
42 #define PORT2A 4
43 #define PORT3A 8
44 #define PORT4A 12
45
46 #define PCI_DEVICE_ID_PCI7296 0x7296
47
48
49
50 typedef struct skel_board_struct{
51         const char *name;
52         int vendor_id;
53         int device_id;
54 }adl_pci7296_board;
55
56 static adl_pci7296_board adl_pci7296_boards[] = {
57         { "pci7296", PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296 },
58 };
59
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 },
62         { 0 }
63 };
64 MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
65
66 #define thisboard ((adl_pci7296_board *)dev->board_ptr)
67
68 typedef struct{
69         int data;
70         struct pci_dev *pci_dev;
71 }adl_pci7296_private;
72
73 #define devpriv ((adl_pci7296_private *)dev->private)
74
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",
79         module:         THIS_MODULE,
80         attach:         adl_pci7296_attach,
81         detach:         adl_pci7296_detach,
82
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),
86 };
87
88
89 static int adl_pci7296_attach(comedi_device *dev,comedi_devconfig *it)
90 {
91         struct pci_dev *pcidev;
92         comedi_subdevice *s;
93
94         printk("comedi: attempt to attach...\n");
95         printk("comedi%d: adl_pci7432: board=%s\n",dev->minor, thisboard->name);
96
97         dev->board_name = thisboard->name;
98
99         if(alloc_private(dev,sizeof(adl_pci7296_private))<0)
100                 return -ENOMEM;
101
102         if(alloc_subdevices(dev, 4)<0)
103                 return -ENOMEM;
104
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))
107         {
108
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);
114                                 return -EIO;
115                         }
116                         if (pci_request_regions(pcidev, "adl_pci7296") < 0) {
117                                 printk("comedi%d: I/O port conflict\n", dev->minor);
118                                 return -EIO;
119                         }
120
121                         dev->iobase = pci_resource_start ( pcidev, 2 );
122                         printk ( "comedi: base addr %4lx\n", dev->iobase );
123
124                         dev->board_ptr = adl_pci7296_boards + 0;
125
126                         // four 8255 digital io subdevices
127                         s = dev->subdevices + 0;
128                         subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase));
129
130                         s = dev->subdevices + 1;
131                         subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT2A));
132
133                         s = dev->subdevices + 2;
134                         subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT3A));
135
136                         s = dev->subdevices + 3;
137                         subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase + PORT4A));
138
139                         break;
140                         }
141         }
142
143         printk("attached\n");
144
145         return 1;
146 }
147
148
149 static int adl_pci7296_detach(comedi_device *dev)
150 {
151         printk("comedi%d: pci7432: remove\n",dev->minor);
152
153         if (devpriv && devpriv->pci_dev) {
154                 if (dev->iobase) {
155                         pci_release_regions(devpriv->pci_dev);
156                         pci_disable_device(devpriv->pci_dev);
157                 }
158                 pci_dev_put(devpriv->pci_dev);
159         }
160
161         // detach four 8255 digital io subdevices
162         if(dev->subdevices)
163         {
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);
168
169         }
170
171         return 0;
172 }
173
174 COMEDI_INITCLEANUP(driver_adl_pci7296);
175
176