test2-gpios = <&gpio_a 1>, <&gpio_a 4>, <&gpio_b 6 1 3 2 1>,
<&gpio_b 7 2 3 2 1>, <&gpio_b 8 4 3 2 1>,
<&gpio_b 9 0xc 3 2 1>;
+ int-value = <1234>;
+ uint-value = <(-1234)>;
};
junk {
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
+int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp)
+{
+ return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp);
+}
+
+int dev_read_s32_default(struct udevice *dev, const char *propname, int def)
+{
+ return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
+}
+
+int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp)
+{
+ u32 val;
+ int ret;
+
+ ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
+ if (ret)
+ return ret;
+ *outp = val;
+
+ return 0;
+}
+
const char *dev_read_string(struct udevice *dev, const char *propname)
{
return ofnode_read_string(dev_ofnode(dev), propname);
*/
int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
+/**
+ * dev_read_s32() - read a signed 32-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_s32(struct udevice *dev, const char *propname, s32 *outp);
+
+/**
+ * dev_read_s32_default() - read a signed 32-bit int 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
+ */
+int dev_read_s32_default(struct udevice *dev, const char *propname, int def);
+
+/**
+ * dev_read_u32u() - read a 32-bit integer from a device's DT property
+ *
+ * This version uses a standard uint type.
+ *
+ * @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_u32u(struct udevice *dev, const char *propname, uint *outp);
+
/**
* dev_read_string() - Read a string from a device's DT property
*
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
+static inline int dev_read_s32(struct udevice *dev,
+ const char *propname, s32 *outp)
+{
+ return ofnode_read_s32(dev_ofnode(dev), propname, outp);
+}
+
+static inline int dev_read_s32_default(struct udevice *dev,
+ const char *propname, int def)
+{
+ return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
+}
+
+static inline int dev_read_u32u(struct udevice *dev,
+ const char *propname, uint *outp)
+{
+ u32 val;
+ int ret;
+
+ ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
+ if (ret)
+ return ret;
+ *outp = val;
+
+ return 0;
+}
+
static inline const char *dev_read_string(struct udevice *dev,
const char *propname)
{
return 0;
}
DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test integer functions in dm_read_...() */
+static int dm_test_read_int(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ 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_u32(dev, "int-value", &val32));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_u32(dev, "missing", &val32));
+ ut_asserteq(6, dev_read_u32_default(dev, "missing", 6));
+
+ ut_asserteq(1234, dev_read_u32_default(dev, "int-value", 6));
+ ut_asserteq(1234, val32);
+
+ ut_asserteq(-EINVAL, dev_read_s32(dev, "missing", &sval));
+ ut_asserteq(6, dev_read_s32_default(dev, "missing", 6));
+
+ ut_asserteq(-1234, dev_read_s32_default(dev, "uint-value", 6));
+ ut_assertok(dev_read_s32(dev, "uint-value", &sval));
+ ut_asserteq(-1234, sval);
+
+ val = 0;
+ ut_asserteq(-EINVAL, dev_read_u32u(dev, "missing", &val));
+ ut_assertok(dev_read_u32u(dev, "uint-value", &val));
+ ut_asserteq(-1234, val);
+
+ return 0;
+}
+DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);