[PATCH 78/79] staging: comedi: ni_labpc: only ISA boards need to request_region()

H Hartley Sweeten hsweeten at visionengravers.com
Tue Apr 9 23:34:17 UTC 2013


Currently this driver calls request_region() in labpc_common_attach()
which is the common attach function for the ISA, PCMCIA, and PCI
versions of the labpc board.

The PCMCIA support is handled in a separate driver, ni_labpc_cs.
That driver sets the dev->iobase after aquiring the resource and
then just passes it to labpc_common_attach() which then sets
dev->iobase again.

The PCI support, currently in this driver, calls mite_setup() to
aquire the resource and then passes it to labpc_common_attach()
to set the dev->iobase.

The ISA support, also in this driver, passes a user supplied
configuration option to labpc_common_attach() which then does
the request_region() before setting the dev->iobase.

Move the request_region() to the ISA support code in labpc_attach()
and set the dev->iobase there before calling the common attach
code.

For the PCI support, also set the dev->iobase before calling the
common code.

This allows removing the extra parameter from labpc_common_attach().

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 drivers/staging/comedi/drivers/ni_labpc.c    | 20 +++++++-------------
 drivers/staging/comedi/drivers/ni_labpc.h    |  2 +-
 drivers/staging/comedi/drivers/ni_labpc_cs.c |  2 +-
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index e46854f..8083f48 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -1606,7 +1606,7 @@ static int labpc_eeprom_insn_read(struct comedi_device *dev,
 	return insn->n;
 }
 
-int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
+int labpc_common_attach(struct comedi_device *dev,
 			unsigned int irq, unsigned int dma_chan)
 {
 	const struct labpc_boardinfo *board = comedi_board(dev);
@@ -1616,14 +1616,6 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
 	int ret;
 	int i;
 
-	if (iobase == 0)
-		return -EINVAL;
-	if (board->bustype == isa_bustype) {
-		if (!request_region(iobase, LABPC_SIZE, dev->board_name))
-			return -EIO;
-	}
-	dev->iobase = iobase;
-
 	if (board->has_mmio) {
 		devpriv->read_byte = labpc_readb;
 		devpriv->write_byte = labpc_writeb;
@@ -1782,6 +1774,9 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		iobase = it->options[0];
 		irq = it->options[1];
 		dma_chan = it->options[2];
+		if (!request_region(iobase, LABPC_SIZE, dev->board_name))
+			return -EIO;
+		dev->iobase = iobase;
 #else
 		dev_err(dev->class_dev,
 			"ni_labpc driver has not been built with ISA DMA support.\n");
@@ -1807,7 +1802,7 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		break;
 	}
 
-	return labpc_common_attach(dev, iobase, irq, dma_chan);
+	return labpc_common_attach(dev, irq, dma_chan);
 }
 
 static const struct labpc_boardinfo *
@@ -1831,7 +1826,6 @@ static int labpc_auto_attach(struct comedi_device *dev,
 	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	const struct labpc_boardinfo *board;
 	struct labpc_private *devpriv;
-	unsigned long iobase;
 	unsigned int irq;
 	int ret;
 
@@ -1858,9 +1852,9 @@ static int labpc_auto_attach(struct comedi_device *dev,
 	ret = mite_setup(devpriv->mite);
 	if (ret < 0)
 		return ret;
-	iobase = (unsigned long)devpriv->mite->daq_io_addr;
+	dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
 	irq = mite_irq(devpriv->mite);
-	return labpc_common_attach(dev, iobase, irq, 0);
+	return labpc_common_attach(dev, irq, 0);
 }
 
 void labpc_common_detach(struct comedi_device *dev)
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index 0bf2ca1..e214bb9 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -100,7 +100,7 @@ struct labpc_private {
 	void (*write_byte) (unsigned int byte, unsigned long address);
 };
 
-int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
+int labpc_common_attach(struct comedi_device *dev,
 			unsigned int irq, unsigned int dma);
 void labpc_common_detach(struct comedi_device *dev);
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index 4e1deed..f9cb9cf 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -111,7 +111,7 @@ static int labpc_auto_attach(struct comedi_device *dev,
 		return -ENOMEM;
 	dev->private = devpriv;
 
-	return labpc_common_attach(dev, dev->iobase, link->irq, 0);
+	return labpc_common_attach(dev, link->irq, 0);
 }
 
 static void labpc_detach(struct comedi_device *dev)
-- 
1.8.1.4




More information about the devel mailing list