diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-01-30 15:23:50 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-31 10:40:41 +0100 |
commit | 8cd98c826352b74281b8995a592b02e1c71b7204 (patch) | |
tree | ceaebabd2b008c160a99b1ed046b999cdcd080cd /drivers | |
parent | 2bdaef1afc15ae675a1d26e19d2b77bde215ef4a (diff) |
staging: comedi: das08_cs: 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 still need the boardinfo because the das08 driver uses it. But we
can get rid of the duplicate that allowed attaching with the driver
name.
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/das08_cs.c | 130 |
1 files changed, 48 insertions, 82 deletions
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index ff67348be77d..23fdb119ada6 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c @@ -51,81 +51,25 @@ Command support does not exist, but could be added for this board. #include "../comedidev.h" -#include "das08.h" - -/* pcmcia includes */ #include <pcmcia/cistpl.h> #include <pcmcia/ds.h> +#include "das08.h" + static const struct das08_board_struct das08_cs_boards[] = { { - .name = "pcm-das08", - .id = 0x0, /* XXX */ - .bustype = pcmcia, - .ai_nbits = 12, - .ai_pg = das08_bipolar5, - .ai_encoding = das08_pcm_encode12, - .di_nchan = 3, - .do_nchan = 3, - .iosize = 16, - }, - /* duplicate so driver name can be used also */ - { - .name = "das08_cs", - .id = 0x0, /* XXX */ - .bustype = pcmcia, - .ai_nbits = 12, - .ai_pg = das08_bipolar5, - .ai_encoding = das08_pcm_encode12, - .di_nchan = 3, - .do_nchan = 3, - .iosize = 16, + .name = "pcm-das08", + .id = 0x0, /* XXX */ + .bustype = pcmcia, + .ai_nbits = 12, + .ai_pg = das08_bipolar5, + .ai_encoding = das08_pcm_encode12, + .di_nchan = 3, + .do_nchan = 3, + .iosize = 16, }, }; -static struct pcmcia_device *cur_dev; - -static int das08_cs_attach(struct comedi_device *dev, - struct comedi_devconfig *it) -{ - const struct das08_board_struct *thisboard = comedi_board(dev); - struct das08_private_struct *devpriv; - unsigned long iobase; - struct pcmcia_device *link = cur_dev; /* XXX hack */ - - devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); - if (!devpriv) - return -ENOMEM; - dev->private = devpriv; - - dev_info(dev->class_dev, "das08_cs: attach\n"); - /* deal with a pci board */ - - if (thisboard->bustype == pcmcia) { - if (link == NULL) { - dev_err(dev->class_dev, "no pcmcia cards found\n"); - return -EIO; - } - iobase = link->resource[0]->start; - } else { - dev_err(dev->class_dev, - "bug! board does not have PCMCIA bustype\n"); - return -EINVAL; - } - - return das08_common_attach(dev, iobase); -} - -static struct comedi_driver driver_das08_cs = { - .driver_name = "das08_cs", - .module = THIS_MODULE, - .attach = das08_cs_attach, - .detach = das08_common_detach, - .board_name = &das08_cs_boards[0].name, - .num_names = ARRAY_SIZE(das08_cs_boards), - .offset = sizeof(struct das08_board_struct), -}; - static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) { @@ -135,35 +79,58 @@ static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, return pcmcia_request_io(p_dev); } -static int das08_pcmcia_attach(struct pcmcia_device *link) +static int das08_cs_auto_attach(struct comedi_device *dev, + unsigned long context) { + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); + struct das08_private_struct *devpriv; + unsigned long iobase; int ret; + /* The das08 driver needs the board_ptr */ + dev->board_ptr = &das08_cs_boards[0]; + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); if (ret) - goto failed; + return ret; if (!link->irq) - goto failed; + return -EINVAL; ret = pcmcia_enable_device(link); if (ret) - goto failed; + return ret; + iobase = link->resource[0]->start; + + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); + if (!devpriv) + return -ENOMEM; + dev->private = devpriv; + + return das08_common_attach(dev, iobase); +} - cur_dev = link; - return 0; +static void das08_cs_detach(struct comedi_device *dev) +{ + struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); -failed: - pcmcia_disable_device(link); - return ret; + das08_common_detach(dev); + if (dev->iobase) + pcmcia_disable_device(link); } -static void das08_pcmcia_detach(struct pcmcia_device *link) +static struct comedi_driver driver_das08_cs = { + .driver_name = "das08_cs", + .module = THIS_MODULE, + .auto_attach = das08_cs_auto_attach, + .detach = das08_cs_detach, +}; + +static int das08_pcmcia_attach(struct pcmcia_device *link) { - pcmcia_disable_device(link); - cur_dev = NULL; + return comedi_pcmcia_auto_config(link, &driver_das08_cs); } static const struct pcmcia_device_id das08_cs_id_table[] = { @@ -175,11 +142,10 @@ MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table); static struct pcmcia_driver das08_cs_driver = { .name = "pcm-das08", .owner = THIS_MODULE, - .probe = das08_pcmcia_attach, - .remove = das08_pcmcia_detach, .id_table = das08_cs_id_table, + .probe = das08_pcmcia_attach, + .remove = comedi_pcmcia_auto_unconfig, }; - module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " |