]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: pci: Add a driver-model version of pci_find_class()
authorSimon Glass <sjg@chromium.org>
Sun, 29 Nov 2015 20:17:52 +0000 (13:17 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 12 Jan 2016 17:19:09 +0000 (10:19 -0700)
Add a function which scans the driver model device information rather
than scanning the PCI bus again.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
drivers/pci/pci-uclass.c
include/pci.h

index af6de51482ce935f2db0910a152b37706587dd59..dea0cb6e06b70416497e90cf80cbb237695659f2 100644 (file)
@@ -234,6 +234,26 @@ int dm_pci_find_device(unsigned int vendor, unsigned int device, int index,
        return -ENODEV;
 }
 
+int dm_pci_find_class(uint find_class, int index, struct udevice **devp)
+{
+       struct udevice *dev;
+
+       /* Scan all known buses */
+       for (pci_find_first_device(&dev);
+            dev;
+            pci_find_next_device(&dev)) {
+               struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
+
+               if (pplat->class == find_class && !index--) {
+                       *devp = dev;
+                       return device_probe(*devp);
+               }
+       }
+       *devp = NULL;
+
+       return -ENODEV;
+}
+
 int pci_bus_write_config(struct udevice *bus, pci_dev_t bdf, int offset,
                         unsigned long value, enum pci_size_t size)
 {
index 347dd0af59b68ef22c2766e766538812c639366d..443af839b6c846f94b10e107ac117d9d152f2f68 100644 (file)
@@ -1178,6 +1178,16 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop,
 int dm_pci_find_device(unsigned int vendor, unsigned int device, int index,
                       struct udevice **devp);
 
+/**
+ * dm_pci_find_class() - find a device by class
+ *
+ * @find_class: 3-byte (24-bit) class value to find
+ * @index:     0 to find the first match, 1 for second, etc.
+ * @devp:      Returns pointer to the device, if found
+ * @return 0 if found, -ve on error
+ */
+int dm_pci_find_class(uint find_class, int index, struct udevice **devp);
+
 /**
  * struct dm_pci_emul_ops - PCI device emulator operations
  */