From 52c9bf4cf51d992b1b88edeaa63e018d178cbc83 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:24:13 -0700 Subject: [PATCH] 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 Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/ni_daq_700.c | 107 ++++++-------------- 1 file 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 User Manual: http://www.ni.com/pdf/manuals/320676d.pdf */ +#include #include #include -#include "../comedidev.h" -#include +#include "../comedidev.h" #include -#include #include -static struct pcmcia_device *pcmcia_cur_dev; - -struct daq700_board { - const char *name; -}; - /* daqcard700 registers */ #define DIO_W 0x04 /* WO 8bit */ #define DIO_R 0x05 /* RO 8bit */ @@ -202,24 +195,35 @@ static void daq700_ai_config(struct comedi_device *dev, inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ } -static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev, + void *priv_data) +{ + if (p_dev->config_index == 0) + return -EINVAL; + + return pcmcia_request_io(p_dev); +} + +static int daq700_auto_attach(struct comedi_device *dev, + unsigned long context) { - const struct daq700_board *thisboard = comedi_board(dev); + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); struct comedi_subdevice *s; - struct pcmcia_device *link; int ret; - link = pcmcia_cur_dev; /* XXX hack */ - if (!link) - return -EIO; + dev->board_name = dev->driver->driver_name; - dev->iobase = link->resource[0]->start; - if (!dev->iobase) { - dev_err(dev->class_dev, "io base address is zero!\n"); - return -EINVAL; - } + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | + CONF_AUTO_SET_IO; + + ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL); + if (ret) + return ret; - dev->board_name = thisboard->name; + ret = pcmcia_enable_device(link); + if (ret) + return ret; + dev->iobase = link->resource[0]->start; ret = comedi_alloc_subdevices(dev, 2); if (ret) @@ -258,66 +262,22 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) static void daq700_detach(struct comedi_device *dev) { - /* nothing to cleanup */ -} + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); -static const struct daq700_board daq700_boards[] = { - { - .name = "daqcard-700", - }, { - .name = "ni_daq_700", - }, -}; + if (dev->iobase) + pcmcia_disable_device(link); +} static struct comedi_driver daq700_driver = { .driver_name = "ni_daq_700", .module = THIS_MODULE, - .attach = daq700_attach, + .auto_attach = daq700_auto_attach, .detach = daq700_detach, - .board_name = &daq700_boards[0].name, - .num_names = ARRAY_SIZE(daq700_boards), - .offset = sizeof(struct daq700_board), }; -static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev, - void *priv_data) -{ - if (p_dev->config_index == 0) - return -EINVAL; - - return pcmcia_request_io(p_dev); -} - static int daq700_cs_attach(struct pcmcia_device *link) { - int ret; - - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO | - CONF_AUTO_SET_IO; - - ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL); - if (ret) - goto failed; - - if (!link->irq) - goto failed; - - ret = pcmcia_enable_device(link); - if (ret) - goto failed; - - pcmcia_cur_dev = link; - return 0; - -failed: - pcmcia_disable_device(link); - return ret; -} - -static void daq700_cs_detach(struct pcmcia_device *link) -{ - pcmcia_disable_device(link); - pcmcia_cur_dev = NULL; + return comedi_pcmcia_auto_config(link, &daq700_driver); } static const struct pcmcia_device_id daq700_cs_ids[] = { @@ -329,11 +289,10 @@ MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids); static struct pcmcia_driver daq700_cs_driver = { .name = "ni_daq_700", .owner = THIS_MODULE, - .probe = daq700_cs_attach, - .remove = daq700_cs_detach, .id_table = daq700_cs_ids, + .probe = daq700_cs_attach, + .remove = comedi_pcmcia_auto_unconfig, }; - module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver); MODULE_AUTHOR("Fred Brooks "); -- 2.30.2