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 ************************************************************************
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)
34 Updated: Thu, 07 Nov 2002 21:53:06 -0800
36 This is just a wrapper around the 8255.o driver to properly handle
40 /* #define LABPC_DEBUG *//* enable debugging messages */
43 #include <linux/interrupt.h>
44 #include <linux/slab.h>
45 #include "../comedidev.h"
47 #include <linux/ioport.h>
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/cisreg.h>
53 #include <pcmcia/ds.h>
55 static struct pcmcia_device
*pcmcia_cur_dev
= NULL
;
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 int dio24_detach(struct comedi_device
*dev
);
62 enum dio24_bustype
{ pcmcia_bustype
};
64 struct dio24_board_struct
{
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
,
82 .name
= "ni_daq_dio24",
83 .device_id
= 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */
84 .bustype
= pcmcia_bustype
,
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 #define devpriv ((struct dio24_private *)dev->private)
101 static struct comedi_driver driver_dio24
= {
102 .driver_name
= "ni_daq_dio24",
103 .module
= THIS_MODULE
,
104 .attach
= dio24_attach
,
105 .detach
= dio24_detach
,
106 .num_names
= ARRAY_SIZE(dio24_boards
),
107 .board_name
= &dio24_boards
[0].name
,
108 .offset
= sizeof(struct dio24_board_struct
),
111 static int dio24_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
113 struct comedi_subdevice
*s
;
114 unsigned long iobase
= 0;
116 unsigned int irq
= 0;
118 struct pcmcia_device
*link
;
120 /* allocate and initialize dev->private */
121 if (alloc_private(dev
, sizeof(struct dio24_private
)) < 0)
124 /* get base address, irq etc. based on bustype */
125 switch (thisboard
->bustype
) {
127 link
= pcmcia_cur_dev
; /* XXX hack */
130 iobase
= link
->resource
[0]->start
;
136 printk("bug! couldn't determine board type\n");
140 printk("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev
->minor
,
141 thisboard
->name
, iobase
);
144 printk(", irq %u", irq
);
151 printk("io base address is zero!\n");
155 dev
->iobase
= iobase
;
162 dev
->board_name
= thisboard
->name
;
164 if (alloc_subdevices(dev
, 1) < 0)
168 s
= dev
->subdevices
+ 0;
169 subdev_8255_init(dev
, s
, NULL
, dev
->iobase
);
174 static int dio24_detach(struct comedi_device
*dev
)
176 printk("comedi%d: ni_daq_dio24: remove\n", dev
->minor
);
179 subdev_8255_cleanup(dev
, dev
->subdevices
+ 0);
181 if (thisboard
->bustype
!= pcmcia_bustype
&& dev
->iobase
)
182 release_region(dev
->iobase
, DIO24_SIZE
);
184 free_irq(dev
->irq
, dev
);
189 /* PCMCIA crap -- watch your words! */
191 static void dio24_config(struct pcmcia_device
*link
);
192 static void dio24_release(struct pcmcia_device
*link
);
193 static int dio24_cs_suspend(struct pcmcia_device
*p_dev
);
194 static int dio24_cs_resume(struct pcmcia_device
*p_dev
);
197 The attach() and detach() entry points are used to create and destroy
198 "instances" of the driver, where each instance represents everything
199 needed to manage one actual PCMCIA card.
202 static int dio24_cs_attach(struct pcmcia_device
*);
203 static void dio24_cs_detach(struct pcmcia_device
*);
206 You'll also need to prototype all the functions that will actually
207 be used to talk to your device. See 'memory_cs' for a good example
208 of a fully self-sufficient driver; the other drivers rely more or
209 less on other parts of the kernel.
212 struct local_info_t
{
213 struct pcmcia_device
*link
;
215 struct bus_operations
*bus
;
218 /*======================================================================
220 dio24_cs_attach() creates an "instance" of the driver, allocating
221 local data structures for one device. The device is registered
224 The dev_link structure is initialized, but we don't actually
225 configure the card at this point -- we wait until we receive a
226 card insertion event.
228 ======================================================================*/
230 static int dio24_cs_attach(struct pcmcia_device
*link
)
232 struct local_info_t
*local
;
234 printk(KERN_INFO
"ni_daq_dio24: HOLA SOY YO - CS-attach!\n");
236 dev_dbg(&link
->dev
, "dio24_cs_attach()\n");
238 /* Allocate space for private device-specific data */
239 local
= kzalloc(sizeof(struct local_info_t
), GFP_KERNEL
);
245 pcmcia_cur_dev
= link
;
250 } /* dio24_cs_attach */
252 /*======================================================================
254 This deletes a driver "instance". The device is de-registered
255 with Card Services. If it has been released, all local data
256 structures are freed. Otherwise, the structures will be freed
257 when the device is released.
259 ======================================================================*/
261 static void dio24_cs_detach(struct pcmcia_device
*link
)
264 printk(KERN_INFO
"ni_daq_dio24: HOLA SOY YO - cs-detach!\n");
266 dev_dbg(&link
->dev
, "dio24_cs_detach\n");
268 ((struct local_info_t
*)link
->priv
)->stop
= 1;
271 /* This points to the parent local_info_t struct */
274 } /* dio24_cs_detach */
276 /*======================================================================
278 dio24_config() is scheduled to run after a CARD_INSERTION event
279 is received, to configure the PCMCIA socket, and to make the
280 device available to the system.
282 ======================================================================*/
284 static int dio24_pcmcia_config_loop(struct pcmcia_device
*p_dev
,
287 if (p_dev
->config_index
== 0)
290 return pcmcia_request_io(p_dev
);
293 static void dio24_config(struct pcmcia_device
*link
)
297 printk(KERN_INFO
"ni_daq_dio24: HOLA SOY YO! - config\n");
299 dev_dbg(&link
->dev
, "dio24_config\n");
301 link
->config_flags
|= CONF_ENABLE_IRQ
| CONF_AUTO_AUDIO
|
304 ret
= pcmcia_loop_config(link
, dio24_pcmcia_config_loop
, NULL
);
306 dev_warn(&link
->dev
, "no configuration found\n");
314 This actually configures the PCMCIA socket -- setting up
315 the I/O windows and the interrupt mapping, and putting the
316 card and host interface into "Memory and IO" mode.
318 ret
= pcmcia_enable_device(link
);
322 /* Finally, report what we've done */
323 dev_info(&link
->dev
, "index 0x%02x", link
->config_index
);
324 printk(", irq %d", link
->irq
);
325 if (link
->resource
[0])
326 printk(" & %pR", link
->resource
[0]);
327 if (link
->resource
[1])
328 printk(" & %pR", link
->resource
[1]);
334 printk(KERN_INFO
"Fallo");
339 static void dio24_release(struct pcmcia_device
*link
)
341 dev_dbg(&link
->dev
, "dio24_release\n");
343 pcmcia_disable_device(link
);
344 } /* dio24_release */
346 /*======================================================================
348 The card status event handler. Mostly, this schedules other
349 stuff to run after an event is received.
351 When a CARD_REMOVAL event is received, we immediately set a
352 private flag to block future accesses to this device. All the
353 functions that actually access the device should check this flag
354 to make sure the card is still present.
356 ======================================================================*/
358 static int dio24_cs_suspend(struct pcmcia_device
*link
)
360 struct local_info_t
*local
= link
->priv
;
362 /* Mark the device as stopped, to block IO until later */
365 } /* dio24_cs_suspend */
367 static int dio24_cs_resume(struct pcmcia_device
*link
)
369 struct local_info_t
*local
= link
->priv
;
373 } /* dio24_cs_resume */
375 /*====================================================================*/
377 static struct pcmcia_device_id dio24_cs_ids
[] = {
378 /* N.B. These IDs should match those in dio24_boards */
379 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */
383 MODULE_DEVICE_TABLE(pcmcia
, dio24_cs_ids
);
384 MODULE_AUTHOR("Daniel Vecino Castel <dvecino@able.es>");
385 MODULE_DESCRIPTION("Comedi driver for National Instruments "
386 "PCMCIA DAQ-Card DIO-24");
387 MODULE_LICENSE("GPL");
389 struct pcmcia_driver dio24_cs_driver
= {
390 .probe
= dio24_cs_attach
,
391 .remove
= dio24_cs_detach
,
392 .suspend
= dio24_cs_suspend
,
393 .resume
= dio24_cs_resume
,
394 .id_table
= dio24_cs_ids
,
395 .owner
= THIS_MODULE
,
397 .name
= "ni_daq_dio24",
401 static int __init
init_dio24_cs(void)
403 printk("ni_daq_dio24: HOLA SOY YO!\n");
404 pcmcia_register_driver(&dio24_cs_driver
);
408 static void __exit
exit_dio24_cs(void)
410 pcmcia_unregister_driver(&dio24_cs_driver
);
413 int __init
init_module(void)
417 ret
= init_dio24_cs();
421 return comedi_driver_register(&driver_dio24
);
424 void __exit
cleanup_module(void)
427 comedi_driver_unregister(&driver_dio24
);