--- /dev/null
+/*
+ * Copyright (c) 2017 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/of_access.h>
+
+int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
+{
+ return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
+}
+
+const char *dev_read_string(struct udevice *dev, const char *propname)
+{
+ return ofnode_read_string(dev_ofnode(dev), propname);
+}
+
+bool dev_read_bool(struct udevice *dev, const char *propname)
+{
+ return ofnode_read_bool(dev_ofnode(dev), propname);
+}
+
+ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name)
+{
+ return ofnode_find_subnode(dev_ofnode(dev), subnode_name);
+}
+
+ofnode dev_read_first_subnode(struct udevice *dev)
+{
+ return ofnode_first_subnode(dev_ofnode(dev));
+}
+
+ofnode dev_read_next_subnode(ofnode node)
+{
+ return ofnode_next_subnode(node);
+}
+
+int dev_read_size(struct udevice *dev, const char *propname)
+{
+ return ofnode_read_size(dev_ofnode(dev), propname);
+}
+
+fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
+{
+ if (ofnode_is_np(dev_ofnode(dev)))
+ return ofnode_get_addr_index(dev_ofnode(dev), index);
+ else
+ return devfdt_get_addr_index(dev, index);
+}
+
+fdt_addr_t dev_read_addr(struct udevice *dev)
+{
+ return dev_read_addr_index(dev, 0);
+}
+
+fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property,
+ fdt_size_t *sizep)
+{
+ return ofnode_get_addr_size(dev_ofnode(dev), property, sizep);
+}
+
+const char *dev_read_name(struct udevice *dev)
+{
+ return ofnode_get_name(dev_ofnode(dev));
+}
+
+int dev_read_stringlist_search(struct udevice *dev, const char *property,
+ const char *string)
+{
+ return ofnode_stringlist_search(dev_ofnode(dev), property, string);
+}
+
+int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
+ const char *cells_name, int cell_count,
+ int index,
+ struct ofnode_phandle_args *out_args)
+{
+ return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
+ cells_name, cell_count, index,
+ out_args);
+}
+
+int dev_read_addr_cells(struct udevice *dev)
+{
+ return ofnode_read_addr_cells(dev_ofnode(dev));
+}
+
+int dev_read_size_cells(struct udevice *dev)
+{
+ return ofnode_read_size_cells(dev_ofnode(dev));
+}
+
+int dev_read_phandle(struct udevice *dev)
+{
+ ofnode node = dev_ofnode(dev);
+
+ if (ofnode_is_np(node))
+ return ofnode_to_np(node)->phandle;
+ else
+ return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node));
+}
+
+const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
+{
+ return ofnode_read_prop(dev_ofnode(dev), propname, lenp);
+}
+
+int dev_read_alias_seq(struct udevice *dev, int *devnump)
+{
+ ofnode node = dev_ofnode(dev);
+ const char *uc_name = dev->uclass->uc_drv->name;
+ int ret;
+
+ if (ofnode_is_np(node)) {
+ ret = of_alias_get_id(ofnode_to_np(node), uc_name);
+ if (ret >= 0)
+ *devnump = ret;
+ } else {
+ ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
+ ofnode_to_offset(node), devnump);
+ }
+
+ return ret;
+}
+
+int dev_read_u32_array(struct udevice *dev, const char *propname,
+ u32 *out_values, size_t sz)
+{
+ return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
+}
+
+const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
+ size_t sz)
+{
+ return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
+}
return ofnode_valid(dev_ofnode(dev));
}
-#ifdef CONFIG_DM_DEV_READ_INLINE
-
-static inline int dev_read_u32_default(struct udevice *dev,
- const char *propname, int def)
-{
- return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
-}
+#ifndef CONFIG_DM_DEV_READ_INLINE
+/**
+ * dev_read_u32_default() - read a 32-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
+ */
+int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
/**
* dev_read_string() - Read a string from a device's DT property
* @propname: name of the property to read
* @return string from property value, or NULL if there is no such property
*/
-static inline const char *dev_read_string(struct udevice *dev,
- const char *propname)
-{
- return ofnode_read_string(dev_ofnode(dev), propname);
-}
+const char *dev_read_string(struct udevice *dev, const char *propname);
/**
* dev_read_bool() - read a boolean value from a device's DT property
* @propname: name of property to read
* @return true if property is present (meaning true), false if not present
*/
-static inline bool dev_read_bool(struct udevice *dev, const char *propname)
-{
- return ofnode_read_bool(dev_ofnode(dev), propname);
-}
+bool dev_read_bool(struct udevice *dev, const char *propname);
/**
* dev_read_subnode() - find a named subnode of a device
* @return reference to subnode (which can be invalid if there is no such
* subnode)
*/
-static inline ofnode dev_read_subnode(struct udevice *dev,
- const char *subbnode_name)
-{
- return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
-}
+ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
/**
* dev_read_size() - read the size of a property
* @propname: property to check
* @return size of property if present, or -EINVAL if not
*/
-static inline int dev_read_size(struct udevice *dev, const char *propname)
-{
- return ofnode_read_size(dev_ofnode(dev), propname);
-}
+int dev_read_size(struct udevice *dev, const char *propname);
/**
* dev_read_addr_index() - Get the indexed reg property of a device
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
-{
- return devfdt_get_addr_index(dev, index);
-}
+fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
/**
* dev_read_addr() - Get the reg property of a device
*
* @return address or FDT_ADDR_T_NONE if not found
*/
-static inline fdt_addr_t dev_read_addr(struct udevice *dev)
-{
- return devfdt_get_addr(dev);
-}
+fdt_addr_t dev_read_addr(struct udevice *dev);
/**
* dev_read_addr_size() - get address and size from a device property
* @sizep: place to put size value (on success)
* @return address value, or FDT_ADDR_T_NONE on error
*/
-static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
- const char *propname,
- fdt_size_t *sizep)
-{
- return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
-}
+fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
+ fdt_size_t *sizep);
/**
* dev_read_name() - get the name of a device's node
* @node: valid node to look up
* @return name of node
*/
-static inline const char *dev_read_name(struct udevice *dev)
-{
- return ofnode_get_name(dev_ofnode(dev));
-}
+const char *dev_read_name(struct udevice *dev);
/**
* dev_read_stringlist_search() - find string in a string list and return index
* -ENODATA if the property is not found
* -EINVAL on some other error
*/
-static inline int dev_read_stringlist_search(struct udevice *dev,
- const char *propname,
- const char *string)
-{
- return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
-}
+int dev_read_stringlist_search(struct udevice *dev, const char *property,
+ const char *string);
/**
* dev_read_phandle_with_args() - Find a node pointed by phandle in a list
* @cells_name could not be found, the arguments were truncated or there
* were too many arguments.
*/
-static inline int dev_read_phandle_with_args(struct udevice *dev,
- const char *list_name, const char *cells_name, int cell_count,
- int index, struct ofnode_phandle_args *out_args)
-{
- return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
- cells_name, cell_count, index,
- out_args);
-}
+int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
+ const char *cells_name, int cell_count,
+ int index,
+ struct ofnode_phandle_args *out_args);
/**
* dev_read_addr_cells() - Get the number of address cells for a device's node
* @dev: devioe to check
* @return number of address cells this node uses
*/
-static inline int dev_read_addr_cells(struct udevice *dev)
-{
- return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
-}
+int dev_read_addr_cells(struct udevice *dev);
/**
* dev_read_size_cells() - Get the number of size cells for a device's node
* @dev: devioe to check
* @return number of size cells this node uses
*/
-static inline int dev_read_size_cells(struct udevice *dev)
-{
- return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
-}
+int dev_read_size_cells(struct udevice *dev);
/**
* dev_read_phandle() - Get the phandle from a device
* @dev: device to check
* @return phandle (1 or greater), or 0 if no phandle or other error
*/
-static inline int dev_read_phandle(struct udevice *dev)
-{
- return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
-}
+int dev_read_phandle(struct udevice *dev);
/**
* dev_read_prop()- - read a property from a device's node
* @lenp: place to put length on success
* @return pointer to property, or NULL if not found
*/
-static inline const u32 *dev_read_prop(struct udevice *dev,
- const char *propname, int *lenp)
-{
- return ofnode_read_prop(dev_ofnode(dev), propname, lenp);
-}
+const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
/**
* dev_read_alias_seq() - Get the alias sequence number of a node
* @devnump: set to the sequence number if one is found
* @return 0 if a sequence was found, -ve if not
*/
-static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
-{
- return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
- dev_of_offset(dev), devnump);
-}
+int dev_read_alias_seq(struct udevice *dev, int *devnump);
/**
* dev_read_u32_array() - Find and read an array of 32 bit integers
* property does not have a value, and -EOVERFLOW if the property data isn't
* large enough.
*/
-static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
- u32 *out_values, size_t sz)
-{
- return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
-}
+int dev_read_u32_array(struct udevice *dev, const char *propname,
+ u32 *out_values, size_t sz);
/**
* dev_read_first_subnode() - find the first subnode of a device's node
* @return reference to the first subnode (which can be invalid if the device's
* node has no subnodes)
*/
-static inline ofnode dev_read_first_subnode(struct udevice *dev)
-{
- return ofnode_first_subnode(dev_ofnode(dev));
-}
+ofnode dev_read_first_subnode(struct udevice *dev);
/**
* ofnode_next_subnode() - find the next sibling of a subnode
* @return reference to the next subnode (which can be invalid if the node
* has no more siblings)
*/
-static inline ofnode dev_read_next_subnode(ofnode node)
-{
- return ofnode_next_subnode(node);
-}
+ofnode dev_read_next_subnode(ofnode node);
/**
* dev_read_u8_array_ptr() - find an 8-bit array
* @return pointer to byte array if found, or NULL if the property is not
* found or there is not enough data
*/
+const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
+ size_t sz);
+
+#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
+
+static inline int dev_read_u32_default(struct udevice *dev,
+ const char *propname, int def)
+{
+ return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
+}
+
+static inline const char *dev_read_string(struct udevice *dev,
+ const char *propname)
+{
+ return ofnode_read_string(dev_ofnode(dev), propname);
+}
+
+static inline bool dev_read_bool(struct udevice *dev, const char *propname)
+{
+ return ofnode_read_bool(dev_ofnode(dev), propname);
+}
+
+static inline ofnode dev_read_subnode(struct udevice *dev,
+ const char *subbnode_name)
+{
+ return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
+}
+
+static inline int dev_read_size(struct udevice *dev, const char *propname)
+{
+ return ofnode_read_size(dev_ofnode(dev), propname);
+}
+
+static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
+{
+ return devfdt_get_addr_index(dev, index);
+}
+
+static inline fdt_addr_t dev_read_addr(struct udevice *dev)
+{
+ return devfdt_get_addr(dev);
+}
+
+static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
+ const char *propname,
+ fdt_size_t *sizep)
+{
+ return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
+}
+
+static inline const char *dev_read_name(struct udevice *dev)
+{
+ return ofnode_get_name(dev_ofnode(dev));
+}
+
+static inline int dev_read_stringlist_search(struct udevice *dev,
+ const char *propname,
+ const char *string)
+{
+ return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
+}
+
+static inline int dev_read_phandle_with_args(struct udevice *dev,
+ const char *list_name, const char *cells_name, int cell_count,
+ int index, struct ofnode_phandle_args *out_args)
+{
+ return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
+ cells_name, cell_count, index,
+ out_args);
+}
+
+static inline int dev_read_addr_cells(struct udevice *dev)
+{
+ return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
+}
+
+static inline int dev_read_size_cells(struct udevice *dev)
+{
+ return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
+}
+
+static inline int dev_read_phandle(struct udevice *dev)
+{
+ return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
+}
+
+static inline const u32 *dev_read_prop(struct udevice *dev,
+ const char *propname, int *lenp)
+{
+ return ofnode_read_prop(dev_ofnode(dev), propname, lenp);
+}
+
+static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
+{
+ return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
+ dev_of_offset(dev), devnump);
+}
+
+static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
+ u32 *out_values, size_t sz)
+{
+ return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
+}
+
+static inline ofnode dev_read_first_subnode(struct udevice *dev)
+{
+ return ofnode_first_subnode(dev_ofnode(dev));
+}
+
+static inline ofnode dev_read_next_subnode(ofnode node)
+{
+ return ofnode_next_subnode(node);
+}
+
static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
const char *propname, size_t sz)
{