Skip to content

Commit

Permalink
staging: comedi: ni_labpc_cs: convert to auto attach
Browse files Browse the repository at this point in the history
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 ni_labpc 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>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Feb 4, 2013
1 parent 89d714c commit 42e4472
Showing 1 changed file with 36 additions and 70 deletions.
106 changes: 36 additions & 70 deletions drivers/staging/comedi/drivers/ni_labpc_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ NI manuals:
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>

static struct pcmcia_device *pcmcia_cur_dev;

static const struct labpc_board_struct labpc_cs_boards[] = {
{
.name = "daqcard-1200",
Expand All @@ -86,60 +84,9 @@ static const struct labpc_board_struct labpc_cs_boards[] = {
.ai_range_table = &range_labpc_1200_ai,
.ai_range_code = labpc_1200_ai_gain_bits,
.ai_range_is_unipolar = labpc_1200_is_unipolar,
}, {
/* duplicate entry, to support using alternate name */
.name = "ni_labpc_cs",
.device_id = 0x103,
.ai_speed = 10000,
.bustype = pcmcia_bustype,
.register_layout = labpc_1200_layout,
.has_ao = 1,
.ai_range_table = &range_labpc_1200_ai,
.ai_range_code = labpc_1200_ai_gain_bits,
.ai_range_is_unipolar = labpc_1200_is_unipolar,
},
};

static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
const struct labpc_board_struct *thisboard = comedi_board(dev);
struct labpc_private *devpriv;
unsigned long iobase = 0;
unsigned int irq = 0;
struct pcmcia_device *link;

devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
dev->private = devpriv;

/* get base address, irq etc. based on bustype */
switch (thisboard->bustype) {
case pcmcia_bustype:
link = pcmcia_cur_dev; /* XXX hack */
if (!link)
return -EIO;
iobase = link->resource[0]->start;
irq = link->irq;
break;
default:
pr_err("bug! couldn't determine board type\n");
return -EINVAL;
break;
}
return labpc_common_attach(dev, iobase, irq, 0);
}

static struct comedi_driver driver_labpc_cs = {
.driver_name = "ni_labpc_cs",
.module = THIS_MODULE,
.attach = labpc_attach,
.detach = labpc_common_detach,
.num_names = ARRAY_SIZE(labpc_cs_boards),
.board_name = &labpc_cs_boards[0].name,
.offset = sizeof(struct labpc_board_struct),
};

static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
void *priv_data)
{
Expand All @@ -149,42 +96,61 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
return pcmcia_request_io(p_dev);
}

static int labpc_cs_attach(struct pcmcia_device *link)
static int labpc_auto_attach(struct comedi_device *dev,
unsigned long context)
{
struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
struct labpc_private *devpriv;
int ret;

/* The ni_labpc driver needs the board_ptr */
dev->board_ptr = &labpc_cs_boards[0];

link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ |
CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;

ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL);
if (ret) {
dev_warn(&link->dev, "no configuration found\n");
goto failed;
}
if (ret)
return ret;

if (!link->irq)
goto failed;
return -EINVAL;

ret = pcmcia_enable_device(link);
if (ret)
goto failed;
return ret;
dev->iobase = link->resource[0]->start;

pcmcia_cur_dev = link;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
dev->private = devpriv;

return 0;
return labpc_common_attach(dev, dev->iobase, link->irq, 0);
}

failed:
pcmcia_disable_device(link);
return ret;
static void labpc_detach(struct comedi_device *dev)
{
struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);

labpc_common_detach(dev);
if (dev->iobase)
pcmcia_disable_device(link);
}

static void labpc_cs_detach(struct pcmcia_device *link)
static struct comedi_driver driver_labpc_cs = {
.driver_name = "ni_labpc_cs",
.module = THIS_MODULE,
.auto_attach = labpc_auto_attach,
.detach = labpc_detach,
};

static int labpc_cs_attach(struct pcmcia_device *link)
{
pcmcia_disable_device(link);
return comedi_pcmcia_auto_config(link, &driver_labpc_cs);
}

static const struct pcmcia_device_id labpc_cs_ids[] = {
/* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */
PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */
PCMCIA_DEVICE_NULL
};
Expand All @@ -195,7 +161,7 @@ static struct pcmcia_driver labpc_cs_driver = {
.owner = THIS_MODULE,
.id_table = labpc_cs_ids,
.probe = labpc_cs_attach,
.remove = labpc_cs_detach,
.remove = comedi_pcmcia_auto_unconfig,
};
module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver);

Expand Down

0 comments on commit 42e4472

Please sign in to comment.