staging: comedi: cb_das16_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. 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>
This commit is contained in:
parent
1f021e1f3b
commit
2bdaef1afc
1 changed files with 49 additions and 66 deletions
|
@ -40,9 +40,10 @@ Status: experimental
|
||||||
|
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include "../comedidev.h"
|
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
|
|
||||||
|
#include "../comedidev.h"
|
||||||
|
|
||||||
#include <pcmcia/cistpl.h>
|
#include <pcmcia/cistpl.h>
|
||||||
#include <pcmcia/ds.h>
|
#include <pcmcia/ds.h>
|
||||||
|
|
||||||
|
@ -89,8 +90,6 @@ struct das16cs_private {
|
||||||
unsigned short status2;
|
unsigned short status2;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct pcmcia_device *cur_dev;
|
|
||||||
|
|
||||||
static const struct comedi_lrange das16cs_ai_range = {
|
static const struct comedi_lrange das16cs_ai_range = {
|
||||||
4, {
|
4, {
|
||||||
BIP_RANGE(10),
|
BIP_RANGE(10),
|
||||||
|
@ -383,45 +382,62 @@ static int das16cs_dio_insn_config(struct comedi_device *dev,
|
||||||
return insn->n;
|
return insn->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct das16cs_board *das16cs_probe(struct comedi_device *dev,
|
static const void *das16cs_find_boardinfo(struct comedi_device *dev,
|
||||||
struct pcmcia_device *link)
|
struct pcmcia_device *link)
|
||||||
{
|
{
|
||||||
|
const struct das16cs_board *board;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
|
for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
|
||||||
if (das16cs_boards[i].device_id == link->card_id)
|
board = &das16cs_boards[i];
|
||||||
return das16cs_boards + i;
|
if (board->device_id == link->card_id)
|
||||||
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_dbg(dev->class_dev, "unknown board!\n");
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int das16cs_attach(struct comedi_device *dev,
|
static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev,
|
||||||
struct comedi_devconfig *it)
|
void *priv_data)
|
||||||
{
|
{
|
||||||
const struct das16cs_board *thisboard;
|
if (p_dev->config_index == 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return pcmcia_request_io(p_dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int das16cs_auto_attach(struct comedi_device *dev,
|
||||||
|
unsigned long context)
|
||||||
|
{
|
||||||
|
struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
|
||||||
|
const struct das16cs_board *board;
|
||||||
struct das16cs_private *devpriv;
|
struct das16cs_private *devpriv;
|
||||||
struct pcmcia_device *link;
|
|
||||||
struct comedi_subdevice *s;
|
struct comedi_subdevice *s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
link = cur_dev; /* XXX hack */
|
board = das16cs_find_boardinfo(dev, link);
|
||||||
if (!link)
|
if (!board)
|
||||||
return -EIO;
|
return -ENODEV;
|
||||||
|
dev->board_ptr = board;
|
||||||
|
dev->board_name = board->name;
|
||||||
|
|
||||||
dev->board_ptr = das16cs_probe(dev, link);
|
/* Do we need to allocate an interrupt? */
|
||||||
if (!dev->board_ptr)
|
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
|
||||||
return -EIO;
|
|
||||||
thisboard = comedi_board(dev);
|
|
||||||
|
|
||||||
dev->board_name = thisboard->name;
|
ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (!link->irq)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
ret = pcmcia_enable_device(link);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
dev->iobase = link->resource[0]->start;
|
dev->iobase = link->resource[0]->start;
|
||||||
|
|
||||||
ret = request_irq(link->irq, das16cs_interrupt,
|
ret = request_irq(link->irq, das16cs_interrupt, IRQF_SHARED,
|
||||||
IRQF_SHARED, "cb_das16_cs", dev);
|
dev->board_name, dev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
dev->irq = link->irq;
|
dev->irq = link->irq;
|
||||||
|
@ -450,10 +466,10 @@ static int das16cs_attach(struct comedi_device *dev,
|
||||||
|
|
||||||
s = &dev->subdevices[1];
|
s = &dev->subdevices[1];
|
||||||
/* analog output subdevice */
|
/* analog output subdevice */
|
||||||
if (thisboard->n_ao_chans) {
|
if (board->n_ao_chans) {
|
||||||
s->type = COMEDI_SUBD_AO;
|
s->type = COMEDI_SUBD_AO;
|
||||||
s->subdev_flags = SDF_WRITABLE;
|
s->subdev_flags = SDF_WRITABLE;
|
||||||
s->n_chan = thisboard->n_ao_chans;
|
s->n_chan = board->n_ao_chans;
|
||||||
s->maxdata = 0xffff;
|
s->maxdata = 0xffff;
|
||||||
s->range_table = &range_bipolar10;
|
s->range_table = &range_bipolar10;
|
||||||
s->insn_write = &das16cs_ao_winsn;
|
s->insn_write = &das16cs_ao_winsn;
|
||||||
|
@ -481,56 +497,24 @@ static int das16cs_attach(struct comedi_device *dev,
|
||||||
|
|
||||||
static void das16cs_detach(struct comedi_device *dev)
|
static void das16cs_detach(struct comedi_device *dev)
|
||||||
{
|
{
|
||||||
|
struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
|
||||||
|
|
||||||
if (dev->irq)
|
if (dev->irq)
|
||||||
free_irq(dev->irq, dev);
|
free_irq(dev->irq, dev);
|
||||||
|
if (dev->iobase)
|
||||||
|
pcmcia_disable_device(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct comedi_driver driver_das16cs = {
|
static struct comedi_driver driver_das16cs = {
|
||||||
.driver_name = "cb_das16_cs",
|
.driver_name = "cb_das16_cs",
|
||||||
.module = THIS_MODULE,
|
.module = THIS_MODULE,
|
||||||
.attach = das16cs_attach,
|
.auto_attach = das16cs_auto_attach,
|
||||||
.detach = das16cs_detach,
|
.detach = das16cs_detach,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int das16cs_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 das16cs_pcmcia_attach(struct pcmcia_device *link)
|
static int das16cs_pcmcia_attach(struct pcmcia_device *link)
|
||||||
{
|
{
|
||||||
int ret;
|
return comedi_pcmcia_auto_config(link, &driver_das16cs);
|
||||||
|
|
||||||
/* Do we need to allocate an interrupt? */
|
|
||||||
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
|
|
||||||
|
|
||||||
ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL);
|
|
||||||
if (ret)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
if (!link->irq)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
ret = pcmcia_enable_device(link);
|
|
||||||
if (ret)
|
|
||||||
goto failed;
|
|
||||||
|
|
||||||
cur_dev = link;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
failed:
|
|
||||||
pcmcia_disable_device(link);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void das16cs_pcmcia_detach(struct pcmcia_device *link)
|
|
||||||
{
|
|
||||||
pcmcia_disable_device(link);
|
|
||||||
cur_dev = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct pcmcia_device_id das16cs_id_table[] = {
|
static const struct pcmcia_device_id das16cs_id_table[] = {
|
||||||
|
@ -543,11 +527,10 @@ MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
|
||||||
static struct pcmcia_driver das16cs_driver = {
|
static struct pcmcia_driver das16cs_driver = {
|
||||||
.name = "cb_das16_cs",
|
.name = "cb_das16_cs",
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.probe = das16cs_pcmcia_attach,
|
|
||||||
.remove = das16cs_pcmcia_detach,
|
|
||||||
.id_table = das16cs_id_table,
|
.id_table = das16cs_id_table,
|
||||||
|
.probe = das16cs_pcmcia_attach,
|
||||||
|
.remove = comedi_pcmcia_auto_unconfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
|
module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
|
||||||
|
|
||||||
MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
|
MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
|
||||||
|
|
Loading…
Add table
Reference in a new issue