aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-07-18 21:56:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-19 19:32:57 -0400
commitf34ec8002b685e865e26c384887b90149949c5bf (patch)
treec8da87f3b4c0115141b24778ca8e06b573549c47
parent6896ddfa109b32bef1892a3cbeb5c90d78d568c5 (diff)
staging: comedi: daqboard2000: cleanup "find pci device" code
The "find pci device" code for this driver was quite a bit different from the other comedi pci drivers. Clean it up so it follows the format of the other drivers. Use for_each_pci_dev() instead of open-coding the loop using pci_get_device(). Check for a specific bus/slot then the vendor/device ids. The loop checking for the matching boardinfo was creating an "id" based on the subsystem_device and subsystem_vendor info from the pci_dev. The vendor id was already checked so just check against the subsystem_device. Only return the pci_dev if a matching boardinfo is found. Consolidate the dev_err messages when a device is not found into a single message. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c56
1 files changed, 20 insertions, 36 deletions
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index fe2f39cc5114..eb07466a2152 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -120,8 +120,10 @@ Configuration options:
120 120
121#include "8255.h" 121#include "8255.h"
122 122
123#define DAQBOARD2000_SUBSYSTEM_IDS2 0x00021616 /* Daqboard/2000 - 2 Dacs */ 123#define PCI_VENDOR_ID_IOTECH 0x1616
124#define DAQBOARD2000_SUBSYSTEM_IDS4 0x00041616 /* Daqboard/2000 - 4 Dacs */ 124
125#define DAQBOARD2000_SUBSYSTEM_IDS2 0x0002 /* Daqboard/2000 - 2 Dacs */
126#define DAQBOARD2000_SUBSYSTEM_IDS4 0x0004 /* Daqboard/2000 - 4 Dacs */
125 127
126#define DAQBOARD2000_DAQ_SIZE 0x1002 128#define DAQBOARD2000_DAQ_SIZE 0x1002
127#define DAQBOARD2000_PLX_SIZE 0x100 129#define DAQBOARD2000_PLX_SIZE 0x100
@@ -709,47 +711,29 @@ static struct pci_dev *daqboard2000_find_pci_dev(struct comedi_device *dev,
709 struct pci_dev *pcidev = NULL; 711 struct pci_dev *pcidev = NULL;
710 int bus = it->options[0]; 712 int bus = it->options[0];
711 int slot = it->options[1]; 713 int slot = it->options[1];
714 int i;
712 715
713 for (pcidev = pci_get_device(0x1616, 0x0409, NULL); 716 for_each_pci_dev(pcidev) {
714 pcidev != NULL; pcidev = pci_get_device(0x1616, 0x0409, pcidev)) {
715 if (bus || slot) { 717 if (bus || slot) {
716 /* requested particular bus/slot */ 718 if (bus != pcidev->bus->number ||
717 if (pcidev->bus->number != bus || 719 slot != PCI_SLOT(pcidev->devfn))
718 PCI_SLOT(pcidev->devfn) != slot) {
719 continue; 720 continue;
720 }
721 } 721 }
722 break; /* found one */ 722 if (pcidev->vendor != PCI_VENDOR_ID_IOTECH ||
723 } 723 pcidev->device != 0x0409)
724 if (!pcidev) { 724 continue;
725 if (bus || slot)
726 dev_err(dev->class_dev,
727 "no daqboard2000 found at bus/slot: %d/%d\n",
728 bus, slot);
729 else
730 dev_err(dev->class_dev, "no daqboard2000 found\n");
731 return NULL;
732 } else {
733 u32 id;
734 int i;
735 725
736 id = ((u32) pcidev->
737 subsystem_device << 16) | pcidev->subsystem_vendor;
738 for (i = 0; i < ARRAY_SIZE(boardtypes); i++) { 726 for (i = 0; i < ARRAY_SIZE(boardtypes); i++) {
739 if (boardtypes[i].id == id) { 727 if (boardtypes[i].id != pcidev->subsystem_device)
740 dev_dbg(dev->class_dev, "%s\n", 728 continue;
741 boardtypes[i].name); 729 dev->board_ptr = boardtypes + i;
742 dev->board_ptr = boardtypes + i; 730 return pcidev;
743 }
744 }
745 if (!dev->board_ptr) {
746 printk
747 (" unknown subsystem id %08x (pretend it is an ids2)",
748 id);
749 dev->board_ptr = boardtypes;
750 } 731 }
751 return pcidev;
752 } 732 }
733 dev_err(dev->class_dev,
734 "No supported board found! (req. bus %d, slot %d)\n",
735 bus, slot);
736 return NULL;
753} 737}
754 738
755static int daqboard2000_attach(struct comedi_device *dev, 739static int daqboard2000_attach(struct comedi_device *dev,
@@ -886,7 +870,7 @@ static void __devexit daqboard2000_pci_remove(struct pci_dev *dev)
886} 870}
887 871
888static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = { 872static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
889 { PCI_DEVICE(0x1616, 0x0409) }, 873 { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) },
890 { 0 } 874 { 0 }
891}; 875};
892MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table); 876MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table);