aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2013-01-30 17:24:13 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-31 04:40:41 -0500
commit52c9bf4cf51d992b1b88edeaa63e018d178cbc83 (patch)
treef7215663979349697ea83f66befa043fb43ffea1
parent8cd98c826352b74281b8995a592b02e1c71b7204 (diff)
staging: comedi: ni_daq_700: convert to auto attach
Convert this pcmcia driver to the comedi auto attach mechanism. This allows getting rid of the "hack" needed to pass the pcmcia_device pointer from the pcmcia_driver to the comedi_driver. We can also get rid of the boardinfo since it was only used to provide the "name" that was used with the manual attach. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_700.c107
1 files changed, 33 insertions, 74 deletions
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index ff0e1993f173..e537b8f05903 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -50,22 +50,15 @@ Manuals: Register level: http://www.ni.com/pdf/manuals/340698.pdf
50 User Manual: http://www.ni.com/pdf/manuals/320676d.pdf 50 User Manual: http://www.ni.com/pdf/manuals/320676d.pdf
51*/ 51*/
52 52
53#include <linux/ioport.h>
53#include <linux/interrupt.h> 54#include <linux/interrupt.h>
54#include <linux/slab.h> 55#include <linux/slab.h>
55#include "../comedidev.h"
56 56
57#include <linux/ioport.h> 57#include "../comedidev.h"
58 58
59#include <pcmcia/cistpl.h> 59#include <pcmcia/cistpl.h>
60#include <pcmcia/cisreg.h>
61#include <pcmcia/ds.h> 60#include <pcmcia/ds.h>
62 61
63static struct pcmcia_device *pcmcia_cur_dev;
64
65struct daq700_board {
66 const char *name;
67};
68
69/* daqcard700 registers */ 62/* daqcard700 registers */
70#define DIO_W 0x04 /* WO 8bit */ 63#define DIO_W 0x04 /* WO 8bit */
71#define DIO_R 0x05 /* RO 8bit */ 64#define DIO_R 0x05 /* RO 8bit */
@@ -202,24 +195,35 @@ static void daq700_ai_config(struct comedi_device *dev,
202 inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ 195 inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */
203} 196}
204 197
205static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) 198static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev,
199 void *priv_data)
200{
201 if (p_dev->config_index == 0)
202 return -EINVAL;
203
204 return pcmcia_request_io(p_dev);
205}
206
207static int daq700_auto_attach(struct comedi_device *dev,
208 unsigned long context)
206{ 209{
207 const struct daq700_board *thisboard = comedi_board(dev); 210 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
208 struct comedi_subdevice *s; 211 struct comedi_subdevice *s;
209 struct pcmcia_device *link;
210 int ret; 212 int ret;
211 213
212 link = pcmcia_cur_dev; /* XXX hack */ 214 dev->board_name = dev->driver->driver_name;
213 if (!link)
214 return -EIO;
215 215
216 dev->iobase = link->resource[0]->start; 216 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
217 if (!dev->iobase) { 217 CONF_AUTO_SET_IO;
218 dev_err(dev->class_dev, "io base address is zero!\n"); 218
219 return -EINVAL; 219 ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL);
220 } 220 if (ret)
221 return ret;
221 222
222 dev->board_name = thisboard->name; 223 ret = pcmcia_enable_device(link);
224 if (ret)
225 return ret;
226 dev->iobase = link->resource[0]->start;
223 227
224 ret = comedi_alloc_subdevices(dev, 2); 228 ret = comedi_alloc_subdevices(dev, 2);
225 if (ret) 229 if (ret)
@@ -258,66 +262,22 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it)
258 262
259static void daq700_detach(struct comedi_device *dev) 263static void daq700_detach(struct comedi_device *dev)
260{ 264{
261 /* nothing to cleanup */ 265 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
262}
263 266
264static const struct daq700_board daq700_boards[] = { 267 if (dev->iobase)
265 { 268 pcmcia_disable_device(link);
266 .name = "daqcard-700", 269}
267 }, {
268 .name = "ni_daq_700",
269 },
270};
271 270
272static struct comedi_driver daq700_driver = { 271static struct comedi_driver daq700_driver = {
273 .driver_name = "ni_daq_700", 272 .driver_name = "ni_daq_700",
274 .module = THIS_MODULE, 273 .module = THIS_MODULE,
275 .attach = daq700_attach, 274 .auto_attach = daq700_auto_attach,
276 .detach = daq700_detach, 275 .detach = daq700_detach,
277 .board_name = &daq700_boards[0].name,
278 .num_names = ARRAY_SIZE(daq700_boards),
279 .offset = sizeof(struct daq700_board),
280}; 276};
281 277
282static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev,
283 void *priv_data)
284{
285 if (p_dev->config_index == 0)
286 return -EINVAL;
287
288 return pcmcia_request_io(p_dev);
289}
290
291static int daq700_cs_attach(struct pcmcia_device *link) 278static int daq700_cs_attach(struct pcmcia_device *link)
292{ 279{
293 int ret; 280 return comedi_pcmcia_auto_config(link, &daq700_driver);
294
295 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
296 CONF_AUTO_SET_IO;
297
298 ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL);
299 if (ret)
300 goto failed;
301
302 if (!link->irq)
303 goto failed;
304
305 ret = pcmcia_enable_device(link);
306 if (ret)
307 goto failed;
308
309 pcmcia_cur_dev = link;
310 return 0;
311
312failed:
313 pcmcia_disable_device(link);
314 return ret;
315}
316
317static void daq700_cs_detach(struct pcmcia_device *link)
318{
319 pcmcia_disable_device(link);
320 pcmcia_cur_dev = NULL;
321} 281}
322 282
323static const struct pcmcia_device_id daq700_cs_ids[] = { 283static const struct pcmcia_device_id daq700_cs_ids[] = {
@@ -329,11 +289,10 @@ MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids);
329static struct pcmcia_driver daq700_cs_driver = { 289static struct pcmcia_driver daq700_cs_driver = {
330 .name = "ni_daq_700", 290 .name = "ni_daq_700",
331 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
332 .probe = daq700_cs_attach,
333 .remove = daq700_cs_detach,
334 .id_table = daq700_cs_ids, 292 .id_table = daq700_cs_ids,
293 .probe = daq700_cs_attach,
294 .remove = comedi_pcmcia_auto_unconfig,
335}; 295};
336
337module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver); 296module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver);
338 297
339MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>"); 298MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>");