[PATCH 14/14] staging: comedi: daqboard2000: use pci_id_table 'driver_data'

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

 



The driver's COMEDI "auto-attach" handler `db2k_auto_attach()` calls
`db2k_find_boardinfo()` to find an element of our board information
array `db2k_boardtypes[]` that matches the probed PCI device.  The
driver's PCI device table matches several boards in the DaqBoard/2000
series that match a single PCI vendor and device ID combination.
`db2k_find_boardinfo()` uses the probed PCI device's subvendor and
subdevice IDs to find the matching board information, returning `NULL`
for no match.

Change the driver's PCI device table `db2k_pci_table[]` to match
supported PCI vendor, device, subvendor and subdevice IDs, and set the
`.driver_data` member of each element to the index of the matching
element of `db2k_boardtypes[]`.  That index gets passed through to the
COMEDI auto-attach handler `db2k_auto_attach()`.  Use it to index
directly into `db2k_boardtypes[]` instead of calling
`db2k_find_boardinfo()` to find the match.
Use array index designators in the initializer of `db2k_boardtypes[]`.
Use enumerated constants defined by new type `enum db2k_boardids` to
name the board type indices.

The `id` member of `struct db2k_boardtype` is no longer used, so remove
it.  Also remove the subdevice ID macros `DB2K_SUBSYSTEM_IDS2` and
`DB2K_SUBSYSTEM_IDS4` as the subdevice IDs are now specified as numbers
in the PCI device table.  Remove `db2k_find_boardinfo()` as it is no
longer used.

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
 drivers/staging/comedi/drivers/daqboard2000.c | 46 ++++++++++-----------------
 1 file changed, 16 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index 5460d138830a..32dd8a857b6b 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -113,9 +113,6 @@
 
 #define DB2K_FIRMWARE		"daqboard2000_firmware.bin"
 
-#define DB2K_SUBSYSTEM_IDS2	0x0002	/* Daqboard/2000 - 2 Dacs */
-#define DB2K_SUBSYSTEM_IDS4	0x0004	/* Daqboard/2001 - 4 Dacs */
-
 static const struct comedi_lrange db2k_ai_range = {
 	13, {
 		BIP_RANGE(10),
@@ -245,21 +242,23 @@ static const struct comedi_lrange db2k_ai_range = {
 /* "New CPLD" signature. */
 #define DB2K_CPLD_VERSION_NEW				0x5000
 
+enum db2k_boardid {
+	BOARD_DAQBOARD2000,
+	BOARD_DAQBOARD2001
+};
+
 struct db2k_boardtype {
 	const char *name;
-	int id;
 	bool has_2_ao:1;	/* false: 4 AO chans; true: 2 AO chans */
 };
 
 static const struct db2k_boardtype db2k_boardtypes[] = {
-	{
+	[BOARD_DAQBOARD2000] = {
 		.name		= "daqboard2000",
-		.id		= DB2K_SUBSYSTEM_IDS2,
 		.has_2_ao	= true,
 	},
-	{
+	[BOARD_DAQBOARD2001] = {
 		.name		= "daqboard2001",
-		.id		= DB2K_SUBSYSTEM_IDS4,
 	},
 };
 
@@ -690,25 +689,7 @@ static int db2k_8255_cb(struct comedi_device *dev, int dir, int port, int data,
 	return readw(dev->mmio + iobase + port * 2);
 }
 
-static const void *db2k_find_boardinfo(struct comedi_device *dev,
-				       struct pci_dev *pcidev)
-{
-	const struct db2k_boardtype *board;
-	int i;
-
-	if (pcidev->subsystem_vendor != PCI_VENDOR_ID_IOTECH)
-		return NULL;
-
-	for (i = 0; i < ARRAY_SIZE(db2k_boardtypes); i++) {
-		board = &db2k_boardtypes[i];
-		if (pcidev->subsystem_device == board->id)
-			return board;
-	}
-	return NULL;
-}
-
-static int db2k_auto_attach(struct comedi_device *dev,
-			    unsigned long context_unused)
+static int db2k_auto_attach(struct comedi_device *dev, unsigned long context)
 {
 	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 	const struct db2k_boardtype *board;
@@ -716,8 +697,10 @@ static int db2k_auto_attach(struct comedi_device *dev,
 	struct comedi_subdevice *s;
 	int result;
 
-	board = db2k_find_boardinfo(dev, pcidev);
-	if (!board)
+	if (context >= ARRAY_SIZE(db2k_boardtypes))
+		return -ENODEV;
+	board = &db2k_boardtypes[context];
+	if (!board->name)
 		return -ENODEV;
 	dev->board_ptr = board;
 	dev->board_name = board->name;
@@ -796,7 +779,10 @@ static int db2k_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 }
 
 static const struct pci_device_id db2k_pci_table[] = {
-	{ PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) },
+	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_IOTECH, 0x0409, PCI_VENDOR_ID_IOTECH,
+			 0x0002), .driver_data = BOARD_DAQBOARD2000, },
+	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_IOTECH, 0x0409, PCI_VENDOR_ID_IOTECH,
+			 0x0004), .driver_data = BOARD_DAQBOARD2001, },
 	{ 0 }
 };
 MODULE_DEVICE_TABLE(pci, db2k_pci_table);
-- 
2.11.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-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