]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Add ofnode function to read PCI vendor and device id
authorBin Meng <bmeng.cn@gmail.com>
Fri, 3 Aug 2018 08:14:35 +0000 (01:14 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 8 Aug 2018 11:49:31 +0000 (12:49 +0100)
We don't have the live-tree version of fdtdec_get_pci_vendev().
This adds the API.

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

index 29375397e04ffa3fe173091aa1eb79dbe9fb775e..0cfb0fbabb008f45798c49ddbf2ce9148ba57b15 100644 (file)
@@ -623,6 +623,42 @@ fail:
        return ret;
 }
 
+int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device)
+{
+       const char *list, *end;
+       int len;
+
+       list = ofnode_get_property(node, "compatible", &len);
+       if (!list)
+               return -ENOENT;
+
+       end = list + len;
+       while (list < end) {
+               len = strlen(list);
+               if (len >= strlen("pciVVVV,DDDD")) {
+                       char *s = strstr(list, "pci");
+
+                       /*
+                        * check if the string is something like pciVVVV,DDDD.RR
+                        * or just pciVVVV,DDDD
+                        */
+                       if (s && s[7] == ',' &&
+                           (s[12] == '.' || s[12] == 0)) {
+                               s += 3;
+                               *vendor = simple_strtol(s, NULL, 16);
+
+                               s += 5;
+                               *device = simple_strtol(s, NULL, 16);
+
+                               return 0;
+                       }
+               }
+               list += (len + 1);
+       }
+
+       return -ENOENT;
+}
+
 int ofnode_read_addr_cells(ofnode node)
 {
        if (ofnode_is_np(node))
index cd08a7e4d02806be0feed6e7472fb5b12d5ef12a..ab36b74c4ca415dee7dcfdcbe3040b062854cd37 100644 (file)
@@ -585,6 +585,19 @@ const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
 int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
                         const char *propname, struct fdt_pci_addr *addr);
 
+/**
+ * ofnode_read_pci_vendev() - look up PCI vendor and device id
+ *
+ * Look at the compatible property of a device node that represents a PCI
+ * device and extract pci vendor id and device id from it.
+ *
+ * @param node         node to examine
+ * @param vendor       vendor id of the pci device
+ * @param device       device id of the pci device
+ * @return 0 if ok, negative on error
+ */
+int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
+
 /**
  * ofnode_read_addr_cells() - Get the number of address cells for a node
  *