]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
drivers: core: device: add support to check dt compatible for a device/machine
authorMugunthan V N <mugunthanvnm@ti.com>
Thu, 28 Apr 2016 10:06:02 +0000 (15:36 +0530)
committerJoe Hershberger <joe.hershberger@ni.com>
Tue, 24 May 2016 16:42:02 +0000 (11:42 -0500)
Provide an api to check whether the given device or machine is
compatible with the given compat string which helps in making
decisions in drivers based on device or machine compatible.

Idea taken from Linux.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
drivers/core/device.c
include/dm/device.h

index 5c2dc7021fb1623347e2dfb7f27a14aa76254a1e..45d5e3e12c0fb9b1b380f3db41948b22de5b5e85 100644 (file)
@@ -721,3 +721,17 @@ int device_set_name(struct udevice *dev, const char *name)
 
        return 0;
 }
+
+bool of_device_is_compatible(struct udevice *dev, const char *compat)
+{
+       const void *fdt = gd->fdt_blob;
+
+       return !fdt_node_check_compatible(fdt, dev->of_offset, compat);
+}
+
+bool of_machine_is_compatible(const char *compat)
+{
+       const void *fdt = gd->fdt_blob;
+
+       return !fdt_node_check_compatible(fdt, 0, compat);
+}
index e9a8ec72c90eba36d93b365e9afe49c2298df7a5..f03bcd3b49ee45f962126f67272587364ec52356 100644 (file)
@@ -547,6 +547,29 @@ int device_set_name(struct udevice *dev, const char *name);
  */
 void device_set_name_alloced(struct udevice *dev);
 
+/**
+ * of_device_is_compatible() - check if the device is compatible with the compat
+ *
+ * This allows to check whether the device is comaptible with the compat.
+ *
+ * @dev:       udevice pointer for which compatible needs to be verified.
+ * @compat:    Compatible string which needs to verified in the given
+ *             device
+ * @return true if OK, false if the compatible is not found
+ */
+bool of_device_is_compatible(struct udevice *dev, const char *compat);
+
+/**
+ * of_machine_is_compatible() - check if the machine is compatible with
+ *                             the compat
+ *
+ * This allows to check whether the machine is comaptible with the compat.
+ *
+ * @compat:    Compatible string which needs to verified
+ * @return true if OK, false if the compatible is not found
+ */
+bool of_machine_is_compatible(const char *compat);
+
 /**
  * device_is_on_pci_bus - Test if a device is on a PCI bus
  *