[PATCH 8/9] staging: comedi: das08: Support mutiple PCI card types in future

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rename the existing board entry named "das08" for the PCI-DAS08 board to
"pci-das08".  Add a new wildcard board entry called "das08" that will
match any supported PCI board.  If 'dev->board_ptr' points to the
wildcard board entry in the ->attach() routine, it will be replaced with
a supported PCI board entry if there are any (taking into account the
bus and slot specified by the device config options passed in to the
function).

Split the code that finds a matching PCI device into a new function
das08_find_pci().

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
 drivers/staging/comedi/drivers/das08.c |   84 ++++++++++++++++++++++++--------
 1 files changed, 63 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index ae60d39..7ec18a8 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -32,7 +32,7 @@
  *   [ComputerBoards] DAS08 (isa-das08), DAS08-PGM (das08-pgm),
  *   DAS08-PGH (das08-pgh), DAS08-PGL (das08-pgl), DAS08-AOH (das08-aoh),
  *   DAS08-AOL (das08-aol), DAS08-AOM (das08-aom), DAS08/JR-AO (das08/jr-ao),
- *   DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (das08),
+ *   DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (pci-das08 or das08),
  *   PC104-DAS08 (pc104-das08), DAS08/JR/16 (das08jr/16)
  * Status: works
  *
@@ -773,7 +773,7 @@ static const struct das08_board_struct das08_boards[] = {
 #endif /* IS_ENABLED(CONFIG_COMEDI_DAS08_ISA) */
 #if IS_ENABLED(CONFIG_COMEDI_DAS08_PCI)
 	{
-	 .name = "das08",	/*  pci-das08 */
+	 .name = "pci-das08",
 	 .id = PCI_DEVICE_ID_PCIDAS08,
 	 .bustype = pci,
 	 .ai = das08_ai_rinsn,
@@ -789,6 +789,11 @@ static const struct das08_board_struct das08_boards[] = {
 	 .i8254_offset = 4,
 	 .iosize = 8,
 	 },
+	{ /* wildcard entry matches any supported PCI device */
+	 .name = DRV_NAME,
+	 .id = PCI_ANY_ID,
+	 .bustype = pci,
+	 },
 #endif /* IS_ENABLED(CONFIG_COMEDI_DAS08_PCI) */
 };
 #endif /* DO_COMEDI_DRIVER_REGISTER */
@@ -972,6 +977,57 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
 }
 EXPORT_SYMBOL_GPL(das08_common_attach);
 
+#if IS_ENABLED(CONFIG_COMEDI_DAS08_PCI)
+static int das08_find_pci(struct comedi_device *dev, int bus, int slot,
+			  struct pci_dev **pci_dev_p)
+{
+	const struct das08_board_struct *thisboard = comedi_board(dev);
+	struct pci_dev *pdev;
+
+	*pci_dev_p = NULL;
+	/* find card */
+	pdev = NULL;
+	for_each_pci_dev(pdev) {
+		if ((bus || slot) &&
+		    (bus != pdev->bus->number || slot != PCI_SLOT(pdev->devfn)))
+			continue;
+		if (pdev->vendor != PCI_VENDOR_ID_COMPUTERBOARDS)
+			continue;
+		if (thisboard->id == PCI_ANY_ID) {
+			/* wildcard board matches any supported PCI board */
+			unsigned int i;
+			for (i = 0; i < ARRAY_SIZE(das08_boards); i++) {
+				if (das08_boards[i].bustype != pci)
+					continue;
+				if (pdev->device == das08_boards[i].id) {
+					/* replace wildcard board_ptr */
+					dev->board_ptr = &das08_boards[i];
+					thisboard = comedi_board(dev);
+					break;
+				}
+			}
+			if (i == ARRAY_SIZE(das08_boards))
+				continue;
+		} else {
+			/* match specific PCI board */
+			if (pdev->device != thisboard->id)
+				continue;
+		}
+		/* found a match */
+		*pci_dev_p = pdev;
+		return 0;
+	}
+	/* no match found */
+	if (bus || slot)
+		dev_err(dev->class_dev,
+			"No pci das08 cards found at PCI %02X:%02X\n",
+			bus , slot);
+	else
+		dev_err(dev->class_dev, "No pci das08 cards found\n");
+	return -EIO;
+}
+#endif
+
 #ifdef DO_COMEDI_DRIVER_REGISTER
 static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
@@ -998,25 +1054,11 @@ static int das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 			dev_info(dev->class_dev, "pci bus %i slot %i\n",
 			       it->options[0], it->options[1]);
 		}
-		/*  find card */
-		for_each_pci_dev(pdev) {
-			if (pdev->vendor == PCI_VENDOR_ID_COMPUTERBOARDS
-			    && pdev->device == PCI_DEVICE_ID_PCIDAS08) {
-				if (it->options[0] || it->options[1]) {
-					if (pdev->bus->number == it->options[0]
-					    && PCI_SLOT(pdev->devfn) ==
-					    it->options[1]) {
-						break;
-					}
-				} else {
-					break;
-				}
-			}
-		}
-		if (!pdev) {
-			dev_err(dev->class_dev, "No pci das08 cards found\n");
-			return -EIO;
-		}
+		ret = das08_find_pci(dev, it->options[0], it->options[1],
+				     &pdev);
+		if (ret < 0)
+			return ret;
+		thisboard = comedi_board(dev);	/* replaced wildcard board */
 		devpriv->pdev = pdev;
 		/*  enable PCI device and reserve I/O spaces */
 		if (comedi_pci_enable(pdev, dev->driver->driver_name)) {
-- 
1.7.8.6

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux