]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
dm: core: Add dev_read_enabled() to check if a device is enabled
authorSimon Glass <sjg@chromium.org>
Mon, 12 Jun 2017 12:21:30 +0000 (06:21 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 11 Jul 2017 16:08:20 +0000 (10:08 -0600)
This function allows a device's status to be read. This indicates whether
the device should be enabled or disabled.

Note: In normal operation disabled devices will not be present in the
driver-model tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1

drivers/core/read.c
include/dm/read.h

index 3131e5379c966a831a56b6dc6b1e80a33d3fe627..10807673136139416b244575c5a748f140bcdb9c 100644 (file)
@@ -138,3 +138,14 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
 {
        return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
 }
+
+int dev_read_enabled(struct udevice *dev)
+{
+       ofnode node = dev_ofnode(dev);
+
+       if (ofnode_is_np(node))
+               return of_device_is_available(ofnode_to_np(node));
+       else
+               return fdtdec_get_is_enabled(gd->fdt_blob,
+                                            ofnode_to_offset(node));
+}
index 65d5d1f3577fdb93f58195b60f5d832aea58d673..cea1c16a006005bacd8d1f52adc1eb104cbfc7f7 100644 (file)
@@ -315,6 +315,19 @@ ofnode dev_read_next_subnode(ofnode node);
 const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
                                     size_t sz);
 
+/**
+ * dev_read_enabled() - check whether a node is enabled
+ *
+ * This looks for a 'status' property. If this exists, then returns 1 if
+ * the status is 'ok' and 0 otherwise. If there is no status property,
+ * it returns 1 on the assumption that anything mentioned should be enabled
+ * by default.
+ *
+ * @dev: device to examine
+ * @return integer value 0 (not enabled) or 1 (enabled)
+ */
+int dev_read_enabled(struct udevice *dev);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32_default(struct udevice *dev,
@@ -432,6 +445,11 @@ static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
        return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
 }
 
+static inline int dev_read_enabled(struct udevice *dev)
+{
+       return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**