staging: comedi: ni_daq_dio24: remove 'stop' from private pcmcia data
[linux-2.6/cjktty.git] / drivers / staging / comedi / drivers / ni_daq_dio24.c
blob51c25ac0dcae5d4c70a100e11652fb511ecfc898
1 /*
2 comedi/drivers/ni_daq_dio24.c
3 Driver for National Instruments PCMCIA DAQ-Card DIO-24
4 Copyright (C) 2002 Daniel Vecino Castel <dvecino@able.es>
6 PCMCIA crap at end of file is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
7 from the pcmcia package.
8 The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
9 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 ************************************************************************
29 Driver: ni_daq_dio24
30 Description: National Instruments PCMCIA DAQ-Card DIO-24
31 Author: Daniel Vecino Castel <dvecino@able.es>
32 Devices: [National Instruments] PCMCIA DAQ-Card DIO-24 (ni_daq_dio24)
33 Status: ?
34 Updated: Thu, 07 Nov 2002 21:53:06 -0800
36 This is just a wrapper around the 8255.o driver to properly handle
37 the PCMCIA interface.
40 /* #define LABPC_DEBUG *//* enable debugging messages */
41 #undef LABPC_DEBUG
43 #include <linux/interrupt.h>
44 #include <linux/slab.h>
45 #include "../comedidev.h"
47 #include <linux/ioport.h>
49 #include "8255.h"
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/cisreg.h>
53 #include <pcmcia/ds.h>
55 static struct pcmcia_device *pcmcia_cur_dev;
57 #define DIO24_SIZE 4 /* size of io region used by board */
59 static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it);
60 static void dio24_detach(struct comedi_device *dev);
62 enum dio24_bustype { pcmcia_bustype };
64 struct dio24_board_struct {
65 const char *name;
66 int device_id; /* device id for pcmcia board */
67 enum dio24_bustype bustype; /* PCMCIA */
68 int have_dio; /* have 8255 chip */
69 /* function pointers so we can use inb/outb or readb/writeb as appropriate */
70 unsigned int (*read_byte) (unsigned int address);
71 void (*write_byte) (unsigned int byte, unsigned int address);
74 static const struct dio24_board_struct dio24_boards[] = {
76 .name = "daqcard-dio24",
77 .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */
78 .bustype = pcmcia_bustype,
79 .have_dio = 1,
82 .name = "ni_daq_dio24",
83 .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */
84 .bustype = pcmcia_bustype,
85 .have_dio = 1,
90 * Useful for shorthand access to the particular board structure
92 #define thisboard ((const struct dio24_board_struct *)dev->board_ptr)
94 struct dio24_private {
96 int data; /* number of data points left to be taken */
99 static struct comedi_driver driver_dio24 = {
100 .driver_name = "ni_daq_dio24",
101 .module = THIS_MODULE,
102 .attach = dio24_attach,
103 .detach = dio24_detach,
104 .num_names = ARRAY_SIZE(dio24_boards),
105 .board_name = &dio24_boards[0].name,
106 .offset = sizeof(struct dio24_board_struct),
109 static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it)
111 struct dio24_private *devpriv;
112 struct comedi_subdevice *s;
113 unsigned long iobase = 0;
114 #ifdef incomplete
115 unsigned int irq = 0;
116 #endif
117 struct pcmcia_device *link;
118 int ret;
120 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
121 if (!devpriv)
122 return -ENOMEM;
123 dev->private = devpriv;
125 /* get base address, irq etc. based on bustype */
126 switch (thisboard->bustype) {
127 case pcmcia_bustype:
128 link = pcmcia_cur_dev; /* XXX hack */
129 if (!link)
130 return -EIO;
131 iobase = link->resource[0]->start;
132 #ifdef incomplete
133 irq = link->irq;
134 #endif
135 break;
136 default:
137 pr_err("bug! couldn't determine board type\n");
138 return -EINVAL;
139 break;
141 pr_debug("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor,
142 thisboard->name, iobase);
143 #ifdef incomplete
144 if (irq)
145 pr_debug("irq %u\n", irq);
146 #endif
148 if (iobase == 0) {
149 pr_err("io base address is zero!\n");
150 return -EINVAL;
153 dev->iobase = iobase;
155 #ifdef incomplete
156 /* grab our IRQ */
157 dev->irq = irq;
158 #endif
160 dev->board_name = thisboard->name;
162 ret = comedi_alloc_subdevices(dev, 1);
163 if (ret)
164 return ret;
166 /* 8255 dio */
167 s = &dev->subdevices[0];
168 subdev_8255_init(dev, s, NULL, dev->iobase);
170 return 0;
173 static void dio24_detach(struct comedi_device *dev)
175 struct comedi_subdevice *s;
177 if (dev->subdevices) {
178 s = &dev->subdevices[0];
179 subdev_8255_cleanup(dev, s);
181 if (thisboard->bustype != pcmcia_bustype && dev->iobase)
182 release_region(dev->iobase, DIO24_SIZE);
183 if (dev->irq)
184 free_irq(dev->irq, dev);
187 static void dio24_config(struct pcmcia_device *link);
189 struct local_info_t {
190 struct pcmcia_device *link;
191 struct bus_operations *bus;
194 static int dio24_cs_attach(struct pcmcia_device *link)
196 struct local_info_t *local;
198 dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO - CS-attach!\n");
200 dev_dbg(&link->dev, "dio24_cs_attach()\n");
202 /* Allocate space for private device-specific data */
203 local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL);
204 if (!local)
205 return -ENOMEM;
206 local->link = link;
207 link->priv = local;
209 pcmcia_cur_dev = link;
211 dio24_config(link);
213 return 0;
214 } /* dio24_cs_attach */
216 static void dio24_cs_detach(struct pcmcia_device *link)
218 pcmcia_disable_device(link);
220 /* This points to the parent local_info_t struct */
221 kfree(link->priv);
224 static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
225 void *priv_data)
227 if (p_dev->config_index == 0)
228 return -EINVAL;
230 return pcmcia_request_io(p_dev);
233 static void dio24_config(struct pcmcia_device *link)
235 int ret;
237 dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO! - config\n");
239 dev_dbg(&link->dev, "dio24_config\n");
241 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
242 CONF_AUTO_SET_IO;
244 ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL);
245 if (ret) {
246 dev_warn(&link->dev, "no configuration found\n");
247 goto failed;
250 if (!link->irq)
251 goto failed;
253 ret = pcmcia_enable_device(link);
254 if (ret)
255 goto failed;
257 return;
259 failed:
260 dev_info(&link->dev, "Fallo");
261 pcmcia_disable_device(link);
264 static int dio24_cs_suspend(struct pcmcia_device *link)
266 return 0;
267 } /* dio24_cs_suspend */
269 static int dio24_cs_resume(struct pcmcia_device *link)
271 return 0;
272 } /* dio24_cs_resume */
274 /*====================================================================*/
276 static const struct pcmcia_device_id dio24_cs_ids[] = {
277 /* N.B. These IDs should match those in dio24_boards */
278 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */
279 PCMCIA_DEVICE_NULL
281 MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids);
283 static struct pcmcia_driver dio24_cs_driver = {
284 .name = "ni_daq_dio24",
285 .owner = THIS_MODULE,
286 .id_table = dio24_cs_ids,
287 .probe = dio24_cs_attach,
288 .remove = dio24_cs_detach,
289 .suspend = dio24_cs_suspend,
290 .resume = dio24_cs_resume,
292 module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver);
294 MODULE_AUTHOR("Daniel Vecino Castel <dvecino@able.es>");
295 MODULE_DESCRIPTION(
296 "Comedi driver for National Instruments PCMCIA DAQ-Card DIO-24");
297 MODULE_LICENSE("GPL");