ni_daq_dio24.c revision ef7908ebc3f81bc85c22ebe5e91c85caeeeac544
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> 5 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. 11 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. 16 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. 21 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. 25 26************************************************************************ 27*/ 28/* 29Driver: ni_daq_dio24 30Description: National Instruments PCMCIA DAQ-Card DIO-24 31Author: Daniel Vecino Castel <dvecino@able.es> 32Devices: [National Instruments] PCMCIA DAQ-Card DIO-24 (ni_daq_dio24) 33Status: ? 34Updated: Thu, 07 Nov 2002 21:53:06 -0800 35 36This is just a wrapper around the 8255.o driver to properly handle 37the PCMCIA interface. 38*/ 39 40 /* #define LABPC_DEBUG *//* enable debugging messages */ 41#undef LABPC_DEBUG 42 43#include <linux/interrupt.h> 44#include <linux/slab.h> 45#include "../comedidev.h" 46 47#include <linux/ioport.h> 48 49#include "8255.h" 50 51#include <pcmcia/cistpl.h> 52#include <pcmcia/cisreg.h> 53#include <pcmcia/ds.h> 54 55static struct pcmcia_device *pcmcia_cur_dev; 56 57#define DIO24_SIZE 4 /* size of io region used by board */ 58 59static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it); 60static int dio24_detach(struct comedi_device *dev); 61 62enum dio24_bustype { pcmcia_bustype }; 63 64struct 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); 72}; 73 74static const struct dio24_board_struct dio24_boards[] = { 75 { 76 .name = "daqcard-dio24", 77 .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */ 78 .bustype = pcmcia_bustype, 79 .have_dio = 1, 80 }, 81 { 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, 86 }, 87}; 88 89/* 90 * Useful for shorthand access to the particular board structure 91 */ 92#define thisboard ((const struct dio24_board_struct *)dev->board_ptr) 93 94struct dio24_private { 95 96 int data; /* number of data points left to be taken */ 97}; 98 99#define devpriv ((struct dio24_private *)dev->private) 100 101static 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), 109}; 110 111static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) 112{ 113 struct comedi_subdevice *s; 114 unsigned long iobase = 0; 115#ifdef incomplete 116 unsigned int irq = 0; 117#endif 118 struct pcmcia_device *link; 119 120 /* allocate and initialize dev->private */ 121 if (alloc_private(dev, sizeof(struct dio24_private)) < 0) 122 return -ENOMEM; 123 124 /* get base address, irq etc. based on bustype */ 125 switch (thisboard->bustype) { 126 case pcmcia_bustype: 127 link = pcmcia_cur_dev; /* XXX hack */ 128 if (!link) 129 return -EIO; 130 iobase = link->resource[0]->start; 131#ifdef incomplete 132 irq = link->irq; 133#endif 134 break; 135 default: 136 printk("bug! couldn't determine board type\n"); 137 return -EINVAL; 138 break; 139 } 140 printk("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor, 141 thisboard->name, iobase); 142#ifdef incomplete 143 if (irq) 144 printk(", irq %u", irq); 145#endif 146 147 printk("\n"); 148 149 if (iobase == 0) { 150 printk("io base address is zero!\n"); 151 return -EINVAL; 152 } 153 154 dev->iobase = iobase; 155 156#ifdef incomplete 157 /* grab our IRQ */ 158 dev->irq = irq; 159#endif 160 161 dev->board_name = thisboard->name; 162 163 if (alloc_subdevices(dev, 1) < 0) 164 return -ENOMEM; 165 166 /* 8255 dio */ 167 s = dev->subdevices + 0; 168 subdev_8255_init(dev, s, NULL, dev->iobase); 169 170 return 0; 171}; 172 173static int dio24_detach(struct comedi_device *dev) 174{ 175 printk("comedi%d: ni_daq_dio24: remove\n", dev->minor); 176 177 if (dev->subdevices) 178 subdev_8255_cleanup(dev, dev->subdevices + 0); 179 180 if (thisboard->bustype != pcmcia_bustype && dev->iobase) 181 release_region(dev->iobase, DIO24_SIZE); 182 if (dev->irq) 183 free_irq(dev->irq, dev); 184 185 return 0; 186}; 187 188static void dio24_config(struct pcmcia_device *link); 189static void dio24_release(struct pcmcia_device *link); 190static int dio24_cs_suspend(struct pcmcia_device *p_dev); 191static int dio24_cs_resume(struct pcmcia_device *p_dev); 192 193static int dio24_cs_attach(struct pcmcia_device *); 194static void dio24_cs_detach(struct pcmcia_device *); 195 196struct local_info_t { 197 struct pcmcia_device *link; 198 int stop; 199 struct bus_operations *bus; 200}; 201 202static int dio24_cs_attach(struct pcmcia_device *link) 203{ 204 struct local_info_t *local; 205 206 printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - CS-attach!\n"); 207 208 dev_dbg(&link->dev, "dio24_cs_attach()\n"); 209 210 /* Allocate space for private device-specific data */ 211 local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL); 212 if (!local) 213 return -ENOMEM; 214 local->link = link; 215 link->priv = local; 216 217 pcmcia_cur_dev = link; 218 219 dio24_config(link); 220 221 return 0; 222} /* dio24_cs_attach */ 223 224static void dio24_cs_detach(struct pcmcia_device *link) 225{ 226 227 printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO - cs-detach!\n"); 228 229 dev_dbg(&link->dev, "dio24_cs_detach\n"); 230 231 ((struct local_info_t *)link->priv)->stop = 1; 232 dio24_release(link); 233 234 /* This points to the parent local_info_t struct */ 235 kfree(link->priv); 236 237} /* dio24_cs_detach */ 238 239static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, 240 void *priv_data) 241{ 242 if (p_dev->config_index == 0) 243 return -EINVAL; 244 245 return pcmcia_request_io(p_dev); 246} 247 248static void dio24_config(struct pcmcia_device *link) 249{ 250 int ret; 251 252 printk(KERN_INFO "ni_daq_dio24: HOLA SOY YO! - config\n"); 253 254 dev_dbg(&link->dev, "dio24_config\n"); 255 256 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | 257 CONF_AUTO_SET_IO; 258 259 ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL); 260 if (ret) { 261 dev_warn(&link->dev, "no configuration found\n"); 262 goto failed; 263 } 264 265 if (!link->irq) 266 goto failed; 267 268 ret = pcmcia_enable_device(link); 269 if (ret) 270 goto failed; 271 272 return; 273 274failed: 275 printk(KERN_INFO "Fallo"); 276 dio24_release(link); 277 278} /* dio24_config */ 279 280static void dio24_release(struct pcmcia_device *link) 281{ 282 dev_dbg(&link->dev, "dio24_release\n"); 283 284 pcmcia_disable_device(link); 285} /* dio24_release */ 286 287static int dio24_cs_suspend(struct pcmcia_device *link) 288{ 289 struct local_info_t *local = link->priv; 290 291 /* Mark the device as stopped, to block IO until later */ 292 local->stop = 1; 293 return 0; 294} /* dio24_cs_suspend */ 295 296static int dio24_cs_resume(struct pcmcia_device *link) 297{ 298 struct local_info_t *local = link->priv; 299 300 local->stop = 0; 301 return 0; 302} /* dio24_cs_resume */ 303 304/*====================================================================*/ 305 306static const struct pcmcia_device_id dio24_cs_ids[] = { 307 /* N.B. These IDs should match those in dio24_boards */ 308 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ 309 PCMCIA_DEVICE_NULL 310}; 311 312MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); 313MODULE_AUTHOR("Daniel Vecino Castel <dvecino@able.es>"); 314MODULE_DESCRIPTION("Comedi driver for National Instruments " 315 "PCMCIA DAQ-Card DIO-24"); 316MODULE_LICENSE("GPL"); 317 318struct pcmcia_driver dio24_cs_driver = { 319 .probe = dio24_cs_attach, 320 .remove = dio24_cs_detach, 321 .suspend = dio24_cs_suspend, 322 .resume = dio24_cs_resume, 323 .id_table = dio24_cs_ids, 324 .owner = THIS_MODULE, 325 .name = "ni_daq_dio24", 326}; 327 328static int __init init_dio24_cs(void) 329{ 330 printk("ni_daq_dio24: HOLA SOY YO!\n"); 331 pcmcia_register_driver(&dio24_cs_driver); 332 return 0; 333} 334 335static void __exit exit_dio24_cs(void) 336{ 337 pcmcia_unregister_driver(&dio24_cs_driver); 338} 339 340int __init init_module(void) 341{ 342 int ret; 343 344 ret = init_dio24_cs(); 345 if (ret < 0) 346 return ret; 347 348 return comedi_driver_register(&driver_dio24); 349} 350 351void __exit cleanup_module(void) 352{ 353 exit_dio24_cs(); 354 comedi_driver_unregister(&driver_dio24); 355} 356