test5-gpios = <&gpio_a 19>;
bool-value;
+ int8-value = /bits/ 8 <0x12>;
+ int16-value = /bits/ 16 <0x1234>;
int-value = <1234>;
uint-value = <(-1234)>;
int64-value = /bits/ 64 <0x1111222233334444>;
return prop->value;
}
+int of_read_u8(const struct device_node *np, const char *propname, u8 *outp)
+{
+ const u8 *val;
+
+ debug("%s: %s: ", __func__, propname);
+ if (!np)
+ return -EINVAL;
+ val = of_find_property_value_of_size(np, propname, sizeof(*outp));
+ if (IS_ERR(val)) {
+ debug("(not found)\n");
+ return PTR_ERR(val);
+ }
+
+ *outp = *val;
+ debug("%#x (%d)\n", *outp, *outp);
+
+ return 0;
+}
+
+int of_read_u16(const struct device_node *np, const char *propname, u16 *outp)
+{
+ const __be16 *val;
+
+ debug("%s: %s: ", __func__, propname);
+ if (!np)
+ return -EINVAL;
+ val = of_find_property_value_of_size(np, propname, sizeof(*outp));
+ if (IS_ERR(val)) {
+ debug("(not found)\n");
+ return PTR_ERR(val);
+ }
+
+ *outp = be16_to_cpup(val);
+ debug("%#x (%d)\n", *outp, *outp);
+
+ return 0;
+}
+
int of_read_u32(const struct device_node *np, const char *propname, u32 *outp)
{
return of_read_u32_index(np, propname, 0, outp);
return (strlen(name) == len) && !strncmp(node_name, name, len);
}
+int ofnode_read_u8(ofnode node, const char *propname, u8 *outp)
+{
+ const u8 *cell;
+ int len;
+
+ assert(ofnode_valid(node));
+ debug("%s: %s: ", __func__, propname);
+
+ if (ofnode_is_np(node))
+ return of_read_u8(ofnode_to_np(node), propname, outp);
+
+ cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
+ &len);
+ if (!cell || len < sizeof(*cell)) {
+ debug("(not found)\n");
+ return -EINVAL;
+ }
+ *outp = *cell;
+ debug("%#x (%d)\n", *outp, *outp);
+
+ return 0;
+}
+
+u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def)
+{
+ assert(ofnode_valid(node));
+ ofnode_read_u8(node, propname, &def);
+
+ return def;
+}
+
+int ofnode_read_u16(ofnode node, const char *propname, u16 *outp)
+{
+ const fdt16_t *cell;
+ int len;
+
+ assert(ofnode_valid(node));
+ debug("%s: %s: ", __func__, propname);
+
+ if (ofnode_is_np(node))
+ return of_read_u16(ofnode_to_np(node), propname, outp);
+
+ cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
+ &len);
+ if (!cell || len < sizeof(*cell)) {
+ debug("(not found)\n");
+ return -EINVAL;
+ }
+ *outp = be16_to_cpup(cell);
+ debug("%#x (%d)\n", *outp, *outp);
+
+ return 0;
+}
+
+u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def)
+{
+ assert(ofnode_valid(node));
+ ofnode_read_u16(node, propname, &def);
+
+ return def;
+}
+
int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
{
return ofnode_read_u32_index(node, propname, 0, outp);
#include <asm/io.h>
#include <linux/ioport.h>
+int dev_read_u8(const struct udevice *dev, const char *propname, u8 *outp)
+{
+ return ofnode_read_u8(dev_ofnode(dev), propname, outp);
+}
+
+u8 dev_read_u8_default(const struct udevice *dev, const char *propname, u8 def)
+{
+ return ofnode_read_u8_default(dev_ofnode(dev), propname, def);
+}
+
+int dev_read_u16(const struct udevice *dev, const char *propname, u16 *outp)
+{
+ return ofnode_read_u16(dev_ofnode(dev), propname, outp);
+}
+
+u16 dev_read_u16_default(const struct udevice *dev, const char *propname,
+ u16 def)
+{
+ return ofnode_read_u16_default(dev_ofnode(dev), propname, def);
+}
+
int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp)
{
return ofnode_read_u32(dev_ofnode(dev), propname, outp);
*/
struct device_node *of_find_node_by_phandle(phandle handle);
+/**
+ * of_read_u8() - Find and read a 8-bit integer from a property
+ *
+ * Search for a property in a device node and read a 8-bit value from
+ * it.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @outp: pointer to return value, modified only if return value is 0.
+ *
+ * Return: 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ */
+int of_read_u8(const struct device_node *np, const char *propname, u8 *outp);
+
+/**
+ * of_read_u16() - Find and read a 16-bit integer from a property
+ *
+ * Search for a property in a device node and read a 16-bit value from
+ * it.
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @outp: pointer to return value, modified only if return value is 0.
+ *
+ * Return: 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ */
+int of_read_u16(const struct device_node *np, const char *propname, u16 *outp);
+
/**
* of_read_u32() - Find and read a 32-bit integer from a property
*
*/
bool ofnode_name_eq(ofnode node, const char *name);
+/**
+ * ofnode_read_u8() - Read a 8-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int ofnode_read_u8(ofnode node, const char *propname, u8 *outp);
+
+/**
+ * ofnode_read_u8_default() - Read a 8-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u8 ofnode_read_u8_default(ofnode node, const char *propname, u8 def);
+
+/**
+ * ofnode_read_u16() - Read a 16-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int ofnode_read_u16(ofnode node, const char *propname, u16 *outp);
+
+/**
+ * ofnode_read_u16_default() - Read a 16-bit integer from a property
+ *
+ * @node: valid node reference to read property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u16 ofnode_read_u16_default(ofnode node, const char *propname, u16 def);
+
/**
* ofnode_read_u32() - Read a 32-bit integer from a property
*
#endif
#if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA)
+/**
+ * dev_read_u8() - read a 8-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int dev_read_u8(const struct udevice *dev, const char *propname, u8 *outp);
+
+/**
+ * dev_read_u8_default() - read a 8-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u8 dev_read_u8_default(const struct udevice *dev, const char *propname, u8 def);
+
+/**
+ * dev_read_u16() - read a 16-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @outp: place to put value (if found)
+ * Return: 0 if OK, -ve on error
+ */
+int dev_read_u16(const struct udevice *dev, const char *propname, u16 *outp);
+
+/**
+ * dev_read_u16_default() - read a 16-bit integer from a device's DT property
+ *
+ * @dev: device to read DT property from
+ * @propname: name of the property to read from
+ * @def: default value to return if the property has no value
+ * Return: property value, or @def if not found
+ */
+u16 dev_read_u16_default(const struct udevice *dev, const char *propname,
+ u16 def);
+
/**
* dev_read_u32() - read a 32-bit integer from a device's DT property
*
#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
#include <asm/global_data.h>
+static inline int dev_read_u8(const struct udevice *dev,
+ const char *propname, u8 *outp)
+{
+ return ofnode_read_u8(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_u8_default(const struct udevice *dev,
+ const char *propname, u8 def)
+{
+ return ofnode_read_u8_default(dev_ofnode(dev), propname, def);
+}
+
+static inline int dev_read_u16(const struct udevice *dev,
+ const char *propname, u16 *outp)
+{
+ return ofnode_read_u16(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_u16_default(const struct udevice *dev,
+ const char *propname, u16 def)
+{
+ return ofnode_read_u16_default(dev_ofnode(dev), propname, def);
+}
+
static inline int dev_read_u32(const struct udevice *dev,
const char *propname, u32 *outp)
{
static int dm_test_read_int(struct unit_test_state *uts)
{
struct udevice *dev;
+ u8 val8;
+ u16 val16;
u32 val32;
s32 sval;
uint val;
ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
ut_asserteq_str("a-test", dev->name);
+
+ ut_assertok(dev_read_u8(dev, "int8-value", &val8));
+ ut_asserteq(0x12, val8);
+
+ ut_asserteq(-EINVAL, dev_read_u8(dev, "missing", &val8));
+ ut_asserteq(6, dev_read_u8_default(dev, "missing", 6));
+
+ ut_asserteq(0x12, dev_read_u8_default(dev, "int8-value", 6));
+
+ ut_assertok(dev_read_u16(dev, "int16-value", &val16));
+ ut_asserteq(0x1234, val16);
+
+ ut_asserteq(-EINVAL, dev_read_u16(dev, "missing", &val16));
+ ut_asserteq(6, dev_read_u16_default(dev, "missing", 6));
+
+ ut_asserteq(0x1234, dev_read_u16_default(dev, "int16-value", 6));
+
ut_assertok(dev_read_u32(dev, "int-value", &val32));
ut_asserteq(1234, val32);