mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: driverdev-devel@linuxdriverproject.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ian Abbott <abbotti@mev.co.uk>,
	H Hartley Sweeten <hartleys@visionengravers.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 15/18] staging: comedi: amplc_pci224: put board indices in PCI driver_data
Date: Thu, 31 Jul 2014 14:47:52 +0100	[thread overview]
Message-ID: <1406814475-5923-16-git-send-email-abbotti@mev.co.uk> (raw)
In-Reply-To: <1406814475-5923-1-git-send-email-abbotti@mev.co.uk>

The `driver_data` member value from the matched entry of the PCI module
device table `amplc_pci224_pci_table[]` is passed through to our comedi
"auto_attach" handler, `pci224_auto_attach()`.  Use that to index
directly into our static board data array `pci224_boards[]` instead of
calling `pci224_find_pci_board()` to search for the entry matching the
PCI device ID.  That function can be removed.  The `devid` and `model`
members of `struct pci224_board` are no longer needed either and can be
removed.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/drivers/amplc_pci224.c | 52 ++++++++++-----------------
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index bcef9e6..977894d 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -351,8 +351,6 @@ enum pci224_model { pci224_model, pci234_model };
 
 struct pci224_board {
 	const char *name;
-	unsigned short devid;
-	enum pci224_model model;
 	unsigned int ao_chans;
 	unsigned int ao_bits;
 	const struct comedi_lrange *ao_range;
@@ -361,20 +359,16 @@ struct pci224_board {
 };
 
 static const struct pci224_board pci224_boards[] = {
-	{
+	[pci224_model] {
 		.name		= "pci224",
-		.devid		= PCI_DEVICE_ID_AMPLICON_PCI224,
-		.model		= pci224_model,
 		.ao_chans	= 16,
 		.ao_bits	= 12,
 		.ao_range	= &range_pci224,
 		.ao_hwrange	= &hwrange_pci224[0],
 		.ao_range_check	= &range_check_pci224[0],
 	},
-	{
+	[pci234_model] {
 		.name		= "pci234",
-		.devid		= PCI_DEVICE_ID_AMPLICON_PCI234,
-		.model		= pci234_model,
 		.ao_chans	= 4,
 		.ao_bits	= 16,
 		.ao_range	= &range_pci234,
@@ -1071,20 +1065,6 @@ static irqreturn_t pci224_interrupt(int irq, void *d)
 }
 
 /*
- * This function looks for a board matching the supplied PCI device.
- */
-static const struct pci224_board
-*pci224_find_pci_board(struct pci_dev *pci_dev)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(pci224_boards); i++)
-		if (pci_dev->device == pci224_boards[i].devid)
-			return &pci224_boards[i];
-	return NULL;
-}
-
-/*
  * Common part of attach and auto_attach.
  */
 static int pci224_attach_common(struct comedi_device *dev,
@@ -1162,8 +1142,6 @@ static int pci224_attach_common(struct comedi_device *dev,
 	s->cancel = pci224_ao_cancel;
 	s->munge = pci224_ao_munge;
 
-	dev->board_name = thisboard->name;
-
 	if (irq) {
 		ret = request_irq(irq, pci224_interrupt, IRQF_SHARED,
 				  dev->board_name, dev);
@@ -1179,23 +1157,29 @@ static int pci224_attach_common(struct comedi_device *dev,
 }
 
 static int
-pci224_auto_attach(struct comedi_device *dev, unsigned long context_unused)
+pci224_auto_attach(struct comedi_device *dev, unsigned long context_model)
 {
 	struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
+	const struct pci224_board *thisboard = NULL;
 	struct pci224_private *devpriv;
 
-	dev_info(dev->class_dev, "attach pci %s\n", pci_name(pci_dev));
+	if (context_model < ARRAY_SIZE(pci224_boards))
+		thisboard = &pci224_boards[context_model];
+	if (!thisboard || !thisboard->name) {
+		dev_err(dev->class_dev,
+			"amplc_pci224: BUG! cannot determine board type!\n");
+		return -EINVAL;
+	}
+	dev->board_ptr = thisboard;
+	dev->board_name = thisboard->name;
+
+	dev_info(dev->class_dev, "amplc_pci224: attach pci %s - %s\n",
+		 pci_name(pci_dev), dev->board_name);
 
 	devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
 	if (!devpriv)
 		return -ENOMEM;
 
-	dev->board_ptr = pci224_find_pci_board(pci_dev);
-	if (dev->board_ptr == NULL) {
-		dev_err(dev->class_dev,
-			"BUG! cannot determine board type!\n");
-		return -EINVAL;
-	}
 	return pci224_attach_common(dev, pci_dev);
 }
 
@@ -1231,8 +1215,8 @@ static int amplc_pci224_pci_probe(struct pci_dev *dev,
 }
 
 static const struct pci_device_id amplc_pci224_pci_table[] = {
-	{ PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) },
-	{ PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) },
+	{ PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224), pci224_model },
+	{ PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234), pci234_model },
 	{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, amplc_pci224_pci_table);
-- 
2.0.0


  parent reply	other threads:[~2014-07-31 13:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31 13:47 [PATCH 00/18] staging: comedi: amplc_pci224: remove legacy stuff Ian Abbott
2014-07-31 13:47 ` [PATCH 01/18] staging: comedi: amplc_pci224: reformat some comments Ian Abbott
2014-07-31 13:47 ` [PATCH 02/18] staging: comedi: amplc_pci224: fix checkpatch line over 80 characters Ian Abbott
2014-07-31 13:47 ` [PATCH 03/18] staging: comedi: amplc_pci224: blank lines aren't necessary before a close brace '}' Ian Abbott
2014-07-31 13:47 ` [PATCH 04/18] staging: comedi: amplc_pci224: multiple assignments should be avoided Ian Abbott
2014-07-31 13:47 ` [PATCH 05/18] staging: comedi: amplc_pci224: fix spinlock_t definition without comment Ian Abbott
2014-07-31 13:47 ` [PATCH 06/18] staging: comedi: amplc_pci224: add whitespace to pci224_boards[] Ian Abbott
2014-07-31 13:47 ` [PATCH 07/18] staging: comedi: amplc_pci224: set a more descriptive MODULE_DESCRIPTION() Ian Abbott
2014-07-31 13:47 ` [PATCH 08/18] staging: comedi: amplc_pci224: omit '!= 0' from logical expressions Ian Abbott
2014-07-31 13:47 ` [PATCH 09/18] staging: comedi: amplc_pci224: remove some unnecessary parentheses Ian Abbott
2014-07-31 13:47 ` [PATCH 10/18] staging: comedi: amplc_pci224: reduce leading whitespace in a few places Ian Abbott
2014-07-31 13:47 ` [PATCH 11/18] staging: comedi: amplc_pci224: no need for '&function' Ian Abbott
2014-07-31 13:47 ` [PATCH 12/18] staging: comedi: amplc_pci224: remove options to select output ranges Ian Abbott
2014-07-31 13:47 ` [PATCH 13/18] staging: comedi: amplc_pci224: remove "legacy" attach mechanism Ian Abbott
2014-07-31 13:47 ` [PATCH 14/18] staging: comedi: amplc_pci224: no need to manipulate PCI ref count Ian Abbott
2014-07-31 13:47 ` Ian Abbott [this message]
2014-07-31 13:47 ` [PATCH 16/18] staging: comedi: amplc_pci224: remove PCI_DEVICE_ID_... macros Ian Abbott
2014-07-31 13:47 ` [PATCH 17/18] staging: comedi: amplc_pci224: absorb pci224_attach_common() Ian Abbott
2014-07-31 13:47 ` [PATCH 18/18] staging: comedi: amplc_pci224: no need to comedi_set_hw_dev() here Ian Abbott
2014-07-31 20:28 ` [PATCH 00/18] staging: comedi: amplc_pci224: remove legacy stuff Hartley Sweeten
2014-07-31 20:44   ` Hartley Sweeten
2014-08-04 10:57   ` Ian Abbott
2014-08-04 11:14 ` [PATCH 15/18 v2] staging: comedi: amplc_pci224: put board indices in PCI driver_data Ian Abbott
2014-08-04 16:38   ` Hartley Sweeten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406814475-5923-16-git-send-email-abbotti@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hartleys@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®