diff mbox

[U-Boot,v2,07/26] dm: pci: Add a driver-model version of pci_find_class()

Message ID 1448828291-12660-8-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Nov. 29, 2015, 8:17 p.m. UTC
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>
---

Changes in v2: None

 drivers/pci/pci-uclass.c | 20 ++++++++++++++++++++
 include/pci.h            | 10 ++++++++++
 2 files changed, 30 insertions(+)

Comments

Bin Meng Dec. 3, 2015, 10:03 a.m. UTC | #1
On Mon, Nov 30, 2015 at 4:17 AM, Simon Glass <sjg@chromium.org> wrote:
> 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>
> ---
>
> Changes in v2: None
>

Tested-by: Bin Meng <bmeng.cn@gmail.com>
Simon Glass Dec. 14, 2015, 3:45 a.m. UTC | #2
Applied to u-boot-dm/next.
diff mbox

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index af6de51..dea0cb6 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -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)
 {
diff --git a/include/pci.h b/include/pci.h
index 347dd0a..443af83 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -1179,6 +1179,16 @@  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
  */
 struct dm_pci_emul_ops {