Commit 3ab48f62230b6753bf5535655c40e3b975825bd9

Authored by Masahiro Yamada
Committed by Jaehoon Chung
1 parent 557767ed29

dm: add dev_read_u32()

dev_read_u32_default() always returns something even when the property
is missing.  So, it is impossible to do nothing in the case.  One
solution is to use ofnode_read_u32() instead, but adding dev_read_u32()
will be helpful.

BTW, Linux has an equvalent function, device_property_read_u32();
it is clearer that it reads a property.  I cannot understand the
behavior of dev_read_u32() from its name.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Showing 2 changed files with 21 additions and 0 deletions Side-by-side Diff

... ... @@ -10,6 +10,11 @@
10 10 #include <mapmem.h>
11 11 #include <dm/of_access.h>
12 12  
  13 +int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp)
  14 +{
  15 + return ofnode_read_u32(dev_ofnode(dev), propname, outp);
  16 +}
  17 +
13 18 int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
14 19 {
15 20 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
... ... @@ -46,6 +46,16 @@
46 46  
47 47 #ifndef CONFIG_DM_DEV_READ_INLINE
48 48 /**
  49 + * dev_read_u32() - read a 32-bit integer from a device's DT property
  50 + *
  51 + * @dev: device to read DT property from
  52 + * @propname: name of the property to read from
  53 + * @outp: place to put value (if found)
  54 + * @return 0 if OK, -ve on error
  55 + */
  56 +int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
  57 +
  58 +/**
49 59 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
50 60 *
51 61 * @dev: device to read DT property from
... ... @@ -411,6 +421,12 @@
411 421 struct resource *res);
412 422  
413 423 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
  424 +
  425 +static inline int dev_read_u32(struct udevice *dev,
  426 + const char *propname, u32 *outp)
  427 +{
  428 + return ofnode_read_u32(dev_ofnode(dev), propname, outp);
  429 +}
414 430  
415 431 static inline int dev_read_u32_default(struct udevice *dev,
416 432 const char *propname, int def)