Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cd98c82 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2bdaef1a
Loading
Loading
Loading
Loading
+48 −82
Original line number Diff line number Diff line
@@ -51,12 +51,11 @@ 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",
@@ -69,61 +68,6 @@ static const struct das08_board_struct das08_cs_boards[] = {
		.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,
	},
};

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,
@@ -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;

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

failed:
	pcmcia_disable_device(link);
	return ret;
	return das08_common_attach(dev, iobase);
}

static void das08_pcmcia_detach(struct pcmcia_device *link)
static void das08_cs_detach(struct comedi_device *dev)
{
	struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);

	das08_common_detach(dev);
	if (dev->iobase)
		pcmcia_disable_device(link);
	cur_dev = NULL;
}

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)
{
	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>, "