1f11c7ab9SSimon Glass /* 2f11c7ab9SSimon Glass * Function to read values from the device tree node attached to a udevice. 3f11c7ab9SSimon Glass * 4f11c7ab9SSimon Glass * Copyright (c) 2017 Google, Inc 5f11c7ab9SSimon Glass * Written by Simon Glass <sjg@chromium.org> 6f11c7ab9SSimon Glass * 7f11c7ab9SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 8f11c7ab9SSimon Glass */ 9f11c7ab9SSimon Glass 10f11c7ab9SSimon Glass #ifndef _DM_READ_H 11f11c7ab9SSimon Glass #define _DM_READ_H 12f11c7ab9SSimon Glass 13f11c7ab9SSimon Glass #include <dm/fdtaddr.h> 14f11c7ab9SSimon Glass #include <dm/ofnode.h> 15f11c7ab9SSimon Glass #include <dm/uclass.h> 16f11c7ab9SSimon Glass 17a4481012SSimon Glass struct resource; 18a4481012SSimon Glass 19f11c7ab9SSimon Glass #if CONFIG_IS_ENABLED(OF_LIVE) 20f11c7ab9SSimon Glass static inline const struct device_node *dev_np(struct udevice *dev) 21f11c7ab9SSimon Glass { 22f11c7ab9SSimon Glass return ofnode_to_np(dev->node); 23f11c7ab9SSimon Glass } 24f11c7ab9SSimon Glass #else 25f11c7ab9SSimon Glass static inline const struct device_node *dev_np(struct udevice *dev) 26f11c7ab9SSimon Glass { 27f11c7ab9SSimon Glass return NULL; 28f11c7ab9SSimon Glass } 29f11c7ab9SSimon Glass #endif 30f11c7ab9SSimon Glass 31f11c7ab9SSimon Glass /** 32f11c7ab9SSimon Glass * dev_ofnode() - get the DT node reference associated with a udevice 33f11c7ab9SSimon Glass * 34f11c7ab9SSimon Glass * @dev: device to check 35f11c7ab9SSimon Glass * @return reference of the the device's DT node 36f11c7ab9SSimon Glass */ 37f11c7ab9SSimon Glass static inline ofnode dev_ofnode(struct udevice *dev) 38f11c7ab9SSimon Glass { 39f11c7ab9SSimon Glass return dev->node; 40f11c7ab9SSimon Glass } 41f11c7ab9SSimon Glass 42f11c7ab9SSimon Glass static inline bool dev_of_valid(struct udevice *dev) 43f11c7ab9SSimon Glass { 44f11c7ab9SSimon Glass return ofnode_valid(dev_ofnode(dev)); 45f11c7ab9SSimon Glass } 46f11c7ab9SSimon Glass 47a4481012SSimon Glass /** 48a4481012SSimon Glass * dev_read_resource() - obtain an indexed resource from a device. 49a4481012SSimon Glass * 50a4481012SSimon Glass * @dev: devuce to examine 51a4481012SSimon Glass * @index index of the resource to retrieve (0 = first) 52a4481012SSimon Glass * @res returns the resource 53a4481012SSimon Glass * @return 0 if ok, negative on error 54a4481012SSimon Glass */ 55a4481012SSimon Glass int dev_read_resource(struct udevice *dev, uint index, struct resource *res); 56a4481012SSimon Glass 5747a0fd3bSSimon Glass #ifndef CONFIG_DM_DEV_READ_INLINE 5847a0fd3bSSimon Glass /** 5947a0fd3bSSimon Glass * dev_read_u32_default() - read a 32-bit integer from a device's DT property 6047a0fd3bSSimon Glass * 6147a0fd3bSSimon Glass * @dev: device to read DT property from 6247a0fd3bSSimon Glass * @propname: name of the property to read from 6347a0fd3bSSimon Glass * @def: default value to return if the property has no value 6447a0fd3bSSimon Glass * @return property value, or @def if not found 6547a0fd3bSSimon Glass */ 6647a0fd3bSSimon Glass int dev_read_u32_default(struct udevice *dev, const char *propname, int def); 67f11c7ab9SSimon Glass 68f11c7ab9SSimon Glass /** 69f11c7ab9SSimon Glass * dev_read_string() - Read a string from a device's DT property 70f11c7ab9SSimon Glass * 71f11c7ab9SSimon Glass * @dev: device to read DT property from 72f11c7ab9SSimon Glass * @propname: name of the property to read 73f11c7ab9SSimon Glass * @return string from property value, or NULL if there is no such property 74f11c7ab9SSimon Glass */ 7547a0fd3bSSimon Glass const char *dev_read_string(struct udevice *dev, const char *propname); 76f11c7ab9SSimon Glass 77f11c7ab9SSimon Glass /** 78f11c7ab9SSimon Glass * dev_read_bool() - read a boolean value from a device's DT property 79f11c7ab9SSimon Glass * 80f11c7ab9SSimon Glass * @dev: device to read DT property from 81f11c7ab9SSimon Glass * @propname: name of property to read 82f11c7ab9SSimon Glass * @return true if property is present (meaning true), false if not present 83f11c7ab9SSimon Glass */ 8447a0fd3bSSimon Glass bool dev_read_bool(struct udevice *dev, const char *propname); 85f11c7ab9SSimon Glass 86f11c7ab9SSimon Glass /** 87f11c7ab9SSimon Glass * dev_read_subnode() - find a named subnode of a device 88f11c7ab9SSimon Glass * 89f11c7ab9SSimon Glass * @dev: device whose DT node contains the subnode 90f11c7ab9SSimon Glass * @subnode_name: name of subnode to find 91f11c7ab9SSimon Glass * @return reference to subnode (which can be invalid if there is no such 92f11c7ab9SSimon Glass * subnode) 93f11c7ab9SSimon Glass */ 9447a0fd3bSSimon Glass ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); 95f11c7ab9SSimon Glass 96f11c7ab9SSimon Glass /** 97f11c7ab9SSimon Glass * dev_read_size() - read the size of a property 98f11c7ab9SSimon Glass * 99f11c7ab9SSimon Glass * @dev: device to check 100f11c7ab9SSimon Glass * @propname: property to check 101f11c7ab9SSimon Glass * @return size of property if present, or -EINVAL if not 102f11c7ab9SSimon Glass */ 10347a0fd3bSSimon Glass int dev_read_size(struct udevice *dev, const char *propname); 104f11c7ab9SSimon Glass 105f11c7ab9SSimon Glass /** 106f11c7ab9SSimon Glass * dev_read_addr_index() - Get the indexed reg property of a device 107f11c7ab9SSimon Glass * 108f11c7ab9SSimon Glass * @dev: Device to read from 109f11c7ab9SSimon Glass * @index: the 'reg' property can hold a list of <addr, size> pairs 110f11c7ab9SSimon Glass * and @index is used to select which one is required 111f11c7ab9SSimon Glass * 112f11c7ab9SSimon Glass * @return address or FDT_ADDR_T_NONE if not found 113f11c7ab9SSimon Glass */ 11447a0fd3bSSimon Glass fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); 115f11c7ab9SSimon Glass 116f11c7ab9SSimon Glass /** 117f11c7ab9SSimon Glass * dev_read_addr() - Get the reg property of a device 118f11c7ab9SSimon Glass * 119f11c7ab9SSimon Glass * @dev: Device to read from 120f11c7ab9SSimon Glass * 121f11c7ab9SSimon Glass * @return address or FDT_ADDR_T_NONE if not found 122f11c7ab9SSimon Glass */ 12347a0fd3bSSimon Glass fdt_addr_t dev_read_addr(struct udevice *dev); 124f11c7ab9SSimon Glass 125f11c7ab9SSimon Glass /** 126f11c7ab9SSimon Glass * dev_read_addr_size() - get address and size from a device property 127f11c7ab9SSimon Glass * 128f11c7ab9SSimon Glass * This does no address translation. It simply reads an property that contains 129f11c7ab9SSimon Glass * an address and a size value, one after the other. 130f11c7ab9SSimon Glass * 131f11c7ab9SSimon Glass * @dev: Device to read from 132f11c7ab9SSimon Glass * @propname: property to read 133f11c7ab9SSimon Glass * @sizep: place to put size value (on success) 134f11c7ab9SSimon Glass * @return address value, or FDT_ADDR_T_NONE on error 135f11c7ab9SSimon Glass */ 13647a0fd3bSSimon Glass fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, 13747a0fd3bSSimon Glass fdt_size_t *sizep); 138f11c7ab9SSimon Glass 139f11c7ab9SSimon Glass /** 140f11c7ab9SSimon Glass * dev_read_name() - get the name of a device's node 141f11c7ab9SSimon Glass * 142f11c7ab9SSimon Glass * @node: valid node to look up 143f11c7ab9SSimon Glass * @return name of node 144f11c7ab9SSimon Glass */ 14547a0fd3bSSimon Glass const char *dev_read_name(struct udevice *dev); 146f11c7ab9SSimon Glass 147f11c7ab9SSimon Glass /** 148f11c7ab9SSimon Glass * dev_read_stringlist_search() - find string in a string list and return index 149f11c7ab9SSimon Glass * 150f11c7ab9SSimon Glass * Note that it is possible for this function to succeed on property values 151f11c7ab9SSimon Glass * that are not NUL-terminated. That's because the function will stop after 152f11c7ab9SSimon Glass * finding the first occurrence of @string. This can for example happen with 153f11c7ab9SSimon Glass * small-valued cell properties, such as #address-cells, when searching for 154f11c7ab9SSimon Glass * the empty string. 155f11c7ab9SSimon Glass * 156f11c7ab9SSimon Glass * @dev: device to check 157f11c7ab9SSimon Glass * @propname: name of the property containing the string list 158f11c7ab9SSimon Glass * @string: string to look up in the string list 159f11c7ab9SSimon Glass * 160f11c7ab9SSimon Glass * @return: 161f11c7ab9SSimon Glass * the index of the string in the list of strings 162f11c7ab9SSimon Glass * -ENODATA if the property is not found 163f11c7ab9SSimon Glass * -EINVAL on some other error 164f11c7ab9SSimon Glass */ 16547a0fd3bSSimon Glass int dev_read_stringlist_search(struct udevice *dev, const char *property, 16647a0fd3bSSimon Glass const char *string); 167f11c7ab9SSimon Glass 168f11c7ab9SSimon Glass /** 169f11c7ab9SSimon Glass * dev_read_phandle_with_args() - Find a node pointed by phandle in a list 170f11c7ab9SSimon Glass * 171f11c7ab9SSimon Glass * This function is useful to parse lists of phandles and their arguments. 172f11c7ab9SSimon Glass * Returns 0 on success and fills out_args, on error returns appropriate 173f11c7ab9SSimon Glass * errno value. 174f11c7ab9SSimon Glass * 175f11c7ab9SSimon Glass * Caller is responsible to call of_node_put() on the returned out_args->np 176f11c7ab9SSimon Glass * pointer. 177f11c7ab9SSimon Glass * 178f11c7ab9SSimon Glass * Example: 179f11c7ab9SSimon Glass * 180f11c7ab9SSimon Glass * phandle1: node1 { 181f11c7ab9SSimon Glass * #list-cells = <2>; 182f11c7ab9SSimon Glass * } 183f11c7ab9SSimon Glass * 184f11c7ab9SSimon Glass * phandle2: node2 { 185f11c7ab9SSimon Glass * #list-cells = <1>; 186f11c7ab9SSimon Glass * } 187f11c7ab9SSimon Glass * 188f11c7ab9SSimon Glass * node3 { 189f11c7ab9SSimon Glass * list = <&phandle1 1 2 &phandle2 3>; 190f11c7ab9SSimon Glass * } 191f11c7ab9SSimon Glass * 192f11c7ab9SSimon Glass * To get a device_node of the `node2' node you may call this: 193f11c7ab9SSimon Glass * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args); 194f11c7ab9SSimon Glass * 195f11c7ab9SSimon Glass * @dev: device whose node containing a list 196f11c7ab9SSimon Glass * @list_name: property name that contains a list 197f11c7ab9SSimon Glass * @cells_name: property name that specifies phandles' arguments count 198f11c7ab9SSimon Glass * @cells_count: Cell count to use if @cells_name is NULL 199f11c7ab9SSimon Glass * @index: index of a phandle to parse out 200f11c7ab9SSimon Glass * @out_args: optional pointer to output arguments structure (will be filled) 201f11c7ab9SSimon Glass * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if 202f11c7ab9SSimon Glass * @list_name does not exist, -EINVAL if a phandle was not found, 203f11c7ab9SSimon Glass * @cells_name could not be found, the arguments were truncated or there 204f11c7ab9SSimon Glass * were too many arguments. 205f11c7ab9SSimon Glass */ 20647a0fd3bSSimon Glass int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, 20747a0fd3bSSimon Glass const char *cells_name, int cell_count, 20847a0fd3bSSimon Glass int index, 20947a0fd3bSSimon Glass struct ofnode_phandle_args *out_args); 210f11c7ab9SSimon Glass 211f11c7ab9SSimon Glass /** 212*642346aeSPatrice Chotard * dev_count_phandle_with_args() - Return phandle number in a list 213*642346aeSPatrice Chotard * 214*642346aeSPatrice Chotard * This function is usefull to get phandle number contained in a property list. 215*642346aeSPatrice Chotard * For example, this allows to allocate the right amount of memory to keep 216*642346aeSPatrice Chotard * clock's reference contained into the "clocks" property. 217*642346aeSPatrice Chotard * 218*642346aeSPatrice Chotard * 219*642346aeSPatrice Chotard * @dev: device whose node containing a list 220*642346aeSPatrice Chotard * @list_name: property name that contains a list 221*642346aeSPatrice Chotard * @cells_name: property name that specifies phandles' arguments count 222*642346aeSPatrice Chotard * @Returns number of phandle found on success, on error returns appropriate 223*642346aeSPatrice Chotard * errno value. 224*642346aeSPatrice Chotard */ 225*642346aeSPatrice Chotard 226*642346aeSPatrice Chotard int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, 227*642346aeSPatrice Chotard const char *cells_name); 228*642346aeSPatrice Chotard 229*642346aeSPatrice Chotard /** 230f11c7ab9SSimon Glass * dev_read_addr_cells() - Get the number of address cells for a device's node 231f11c7ab9SSimon Glass * 232f11c7ab9SSimon Glass * This walks back up the tree to find the closest #address-cells property 233f11c7ab9SSimon Glass * which controls the given node. 234f11c7ab9SSimon Glass * 235f11c7ab9SSimon Glass * @dev: devioe to check 236f11c7ab9SSimon Glass * @return number of address cells this node uses 237f11c7ab9SSimon Glass */ 23847a0fd3bSSimon Glass int dev_read_addr_cells(struct udevice *dev); 239f11c7ab9SSimon Glass 240f11c7ab9SSimon Glass /** 241f11c7ab9SSimon Glass * dev_read_size_cells() - Get the number of size cells for a device's node 242f11c7ab9SSimon Glass * 243f11c7ab9SSimon Glass * This walks back up the tree to find the closest #size-cells property 244f11c7ab9SSimon Glass * which controls the given node. 245f11c7ab9SSimon Glass * 246f11c7ab9SSimon Glass * @dev: devioe to check 247f11c7ab9SSimon Glass * @return number of size cells this node uses 248f11c7ab9SSimon Glass */ 24947a0fd3bSSimon Glass int dev_read_size_cells(struct udevice *dev); 250f11c7ab9SSimon Glass 251f11c7ab9SSimon Glass /** 252878d68c0SSimon Glass * dev_read_addr_cells() - Get the address cells property in a node 253878d68c0SSimon Glass * 254878d68c0SSimon Glass * This function matches fdt_address_cells(). 255878d68c0SSimon Glass * 256878d68c0SSimon Glass * @dev: devioe to check 257878d68c0SSimon Glass * @return number of address cells this node uses 258878d68c0SSimon Glass */ 259878d68c0SSimon Glass int dev_read_simple_addr_cells(struct udevice *dev); 260878d68c0SSimon Glass 261878d68c0SSimon Glass /** 262878d68c0SSimon Glass * dev_read_size_cells() - Get the size cells property in a node 263878d68c0SSimon Glass * 264878d68c0SSimon Glass * This function matches fdt_size_cells(). 265878d68c0SSimon Glass * 266878d68c0SSimon Glass * @dev: devioe to check 267878d68c0SSimon Glass * @return number of size cells this node uses 268878d68c0SSimon Glass */ 269878d68c0SSimon Glass int dev_read_simple_size_cells(struct udevice *dev); 270878d68c0SSimon Glass 271878d68c0SSimon Glass /** 272f11c7ab9SSimon Glass * dev_read_phandle() - Get the phandle from a device 273f11c7ab9SSimon Glass * 274f11c7ab9SSimon Glass * @dev: device to check 275f11c7ab9SSimon Glass * @return phandle (1 or greater), or 0 if no phandle or other error 276f11c7ab9SSimon Glass */ 27747a0fd3bSSimon Glass int dev_read_phandle(struct udevice *dev); 278f11c7ab9SSimon Glass 279f11c7ab9SSimon Glass /** 280f11c7ab9SSimon Glass * dev_read_prop()- - read a property from a device's node 281f11c7ab9SSimon Glass * 282f11c7ab9SSimon Glass * @dev: device to check 283f11c7ab9SSimon Glass * @propname: property to read 284f11c7ab9SSimon Glass * @lenp: place to put length on success 285f11c7ab9SSimon Glass * @return pointer to property, or NULL if not found 286f11c7ab9SSimon Glass */ 28747a0fd3bSSimon Glass const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); 288f11c7ab9SSimon Glass 289f11c7ab9SSimon Glass /** 290f11c7ab9SSimon Glass * dev_read_alias_seq() - Get the alias sequence number of a node 291f11c7ab9SSimon Glass * 292f11c7ab9SSimon Glass * This works out whether a node is pointed to by an alias, and if so, the 293f11c7ab9SSimon Glass * sequence number of that alias. Aliases are of the form <base><num> where 294f11c7ab9SSimon Glass * <num> is the sequence number. For example spi2 would be sequence number 2. 295f11c7ab9SSimon Glass * 296f11c7ab9SSimon Glass * @dev: device to look up 297f11c7ab9SSimon Glass * @devnump: set to the sequence number if one is found 298f11c7ab9SSimon Glass * @return 0 if a sequence was found, -ve if not 299f11c7ab9SSimon Glass */ 30047a0fd3bSSimon Glass int dev_read_alias_seq(struct udevice *dev, int *devnump); 301f11c7ab9SSimon Glass 302f11c7ab9SSimon Glass /** 303f11c7ab9SSimon Glass * dev_read_u32_array() - Find and read an array of 32 bit integers 304f11c7ab9SSimon Glass * 305f11c7ab9SSimon Glass * Search for a property in a device node and read 32-bit value(s) from 306f11c7ab9SSimon Glass * it. 307f11c7ab9SSimon Glass * 308f11c7ab9SSimon Glass * The out_values is modified only if a valid u32 value can be decoded. 309f11c7ab9SSimon Glass * 310f11c7ab9SSimon Glass * @dev: device to look up 311f11c7ab9SSimon Glass * @propname: name of the property to read 312f11c7ab9SSimon Glass * @out_values: pointer to return value, modified only if return value is 0 313f11c7ab9SSimon Glass * @sz: number of array elements to read 314f11c7ab9SSimon Glass * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if 315f11c7ab9SSimon Glass * property does not have a value, and -EOVERFLOW if the property data isn't 316f11c7ab9SSimon Glass * large enough. 317f11c7ab9SSimon Glass */ 31847a0fd3bSSimon Glass int dev_read_u32_array(struct udevice *dev, const char *propname, 31947a0fd3bSSimon Glass u32 *out_values, size_t sz); 320f11c7ab9SSimon Glass 321f11c7ab9SSimon Glass /** 322f11c7ab9SSimon Glass * dev_read_first_subnode() - find the first subnode of a device's node 323f11c7ab9SSimon Glass * 324f11c7ab9SSimon Glass * @dev: device to look up 325f11c7ab9SSimon Glass * @return reference to the first subnode (which can be invalid if the device's 326f11c7ab9SSimon Glass * node has no subnodes) 327f11c7ab9SSimon Glass */ 32847a0fd3bSSimon Glass ofnode dev_read_first_subnode(struct udevice *dev); 329f11c7ab9SSimon Glass 330f11c7ab9SSimon Glass /** 331f11c7ab9SSimon Glass * ofnode_next_subnode() - find the next sibling of a subnode 332f11c7ab9SSimon Glass * 333f11c7ab9SSimon Glass * @node: valid reference to previous node (sibling) 334f11c7ab9SSimon Glass * @return reference to the next subnode (which can be invalid if the node 335f11c7ab9SSimon Glass * has no more siblings) 336f11c7ab9SSimon Glass */ 33747a0fd3bSSimon Glass ofnode dev_read_next_subnode(ofnode node); 338f11c7ab9SSimon Glass 339f11c7ab9SSimon Glass /** 340f11c7ab9SSimon Glass * dev_read_u8_array_ptr() - find an 8-bit array 341f11c7ab9SSimon Glass * 342f11c7ab9SSimon Glass * Look up a device's node property and return a pointer to its contents as a 343f11c7ab9SSimon Glass * byte array of given length. The property must have at least enough data 344f11c7ab9SSimon Glass * for the array (count bytes). It may have more, but this will be ignored. 345f11c7ab9SSimon Glass * The data is not copied. 346f11c7ab9SSimon Glass * 347f11c7ab9SSimon Glass * @dev: device to look up 348f11c7ab9SSimon Glass * @propname: name of property to find 349f11c7ab9SSimon Glass * @sz: number of array elements 350f11c7ab9SSimon Glass * @return pointer to byte array if found, or NULL if the property is not 351f11c7ab9SSimon Glass * found or there is not enough data 352f11c7ab9SSimon Glass */ 35347a0fd3bSSimon Glass const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, 35447a0fd3bSSimon Glass size_t sz); 35547a0fd3bSSimon Glass 356f7d6fcf7SSimon Glass /** 357f7d6fcf7SSimon Glass * dev_read_enabled() - check whether a node is enabled 358f7d6fcf7SSimon Glass * 359f7d6fcf7SSimon Glass * This looks for a 'status' property. If this exists, then returns 1 if 360f7d6fcf7SSimon Glass * the status is 'ok' and 0 otherwise. If there is no status property, 361f7d6fcf7SSimon Glass * it returns 1 on the assumption that anything mentioned should be enabled 362f7d6fcf7SSimon Glass * by default. 363f7d6fcf7SSimon Glass * 364f7d6fcf7SSimon Glass * @dev: device to examine 365f7d6fcf7SSimon Glass * @return integer value 0 (not enabled) or 1 (enabled) 366f7d6fcf7SSimon Glass */ 367f7d6fcf7SSimon Glass int dev_read_enabled(struct udevice *dev); 368f7d6fcf7SSimon Glass 36947a0fd3bSSimon Glass #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ 37047a0fd3bSSimon Glass 37147a0fd3bSSimon Glass static inline int dev_read_u32_default(struct udevice *dev, 37247a0fd3bSSimon Glass const char *propname, int def) 37347a0fd3bSSimon Glass { 37447a0fd3bSSimon Glass return ofnode_read_u32_default(dev_ofnode(dev), propname, def); 37547a0fd3bSSimon Glass } 37647a0fd3bSSimon Glass 37747a0fd3bSSimon Glass static inline const char *dev_read_string(struct udevice *dev, 37847a0fd3bSSimon Glass const char *propname) 37947a0fd3bSSimon Glass { 38047a0fd3bSSimon Glass return ofnode_read_string(dev_ofnode(dev), propname); 38147a0fd3bSSimon Glass } 38247a0fd3bSSimon Glass 38347a0fd3bSSimon Glass static inline bool dev_read_bool(struct udevice *dev, const char *propname) 38447a0fd3bSSimon Glass { 38547a0fd3bSSimon Glass return ofnode_read_bool(dev_ofnode(dev), propname); 38647a0fd3bSSimon Glass } 38747a0fd3bSSimon Glass 38847a0fd3bSSimon Glass static inline ofnode dev_read_subnode(struct udevice *dev, 38947a0fd3bSSimon Glass const char *subbnode_name) 39047a0fd3bSSimon Glass { 39147a0fd3bSSimon Glass return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); 39247a0fd3bSSimon Glass } 39347a0fd3bSSimon Glass 39447a0fd3bSSimon Glass static inline int dev_read_size(struct udevice *dev, const char *propname) 39547a0fd3bSSimon Glass { 39647a0fd3bSSimon Glass return ofnode_read_size(dev_ofnode(dev), propname); 39747a0fd3bSSimon Glass } 39847a0fd3bSSimon Glass 39947a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) 40047a0fd3bSSimon Glass { 40147a0fd3bSSimon Glass return devfdt_get_addr_index(dev, index); 40247a0fd3bSSimon Glass } 40347a0fd3bSSimon Glass 40447a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr(struct udevice *dev) 40547a0fd3bSSimon Glass { 40647a0fd3bSSimon Glass return devfdt_get_addr(dev); 40747a0fd3bSSimon Glass } 40847a0fd3bSSimon Glass 40947a0fd3bSSimon Glass static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, 41047a0fd3bSSimon Glass const char *propname, 41147a0fd3bSSimon Glass fdt_size_t *sizep) 41247a0fd3bSSimon Glass { 41347a0fd3bSSimon Glass return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); 41447a0fd3bSSimon Glass } 41547a0fd3bSSimon Glass 41647a0fd3bSSimon Glass static inline const char *dev_read_name(struct udevice *dev) 41747a0fd3bSSimon Glass { 41847a0fd3bSSimon Glass return ofnode_get_name(dev_ofnode(dev)); 41947a0fd3bSSimon Glass } 42047a0fd3bSSimon Glass 42147a0fd3bSSimon Glass static inline int dev_read_stringlist_search(struct udevice *dev, 42247a0fd3bSSimon Glass const char *propname, 42347a0fd3bSSimon Glass const char *string) 42447a0fd3bSSimon Glass { 42547a0fd3bSSimon Glass return ofnode_stringlist_search(dev_ofnode(dev), propname, string); 42647a0fd3bSSimon Glass } 42747a0fd3bSSimon Glass 42847a0fd3bSSimon Glass static inline int dev_read_phandle_with_args(struct udevice *dev, 42947a0fd3bSSimon Glass const char *list_name, const char *cells_name, int cell_count, 43047a0fd3bSSimon Glass int index, struct ofnode_phandle_args *out_args) 43147a0fd3bSSimon Glass { 43247a0fd3bSSimon Glass return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, 43347a0fd3bSSimon Glass cells_name, cell_count, index, 43447a0fd3bSSimon Glass out_args); 43547a0fd3bSSimon Glass } 43647a0fd3bSSimon Glass 437*642346aeSPatrice Chotard static inline int dev_count_phandle_with_args(struct udevice *dev, 438*642346aeSPatrice Chotard const char *list_name, const char *cells_name) 439*642346aeSPatrice Chotard { 440*642346aeSPatrice Chotard return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, 441*642346aeSPatrice Chotard cells_name); 442*642346aeSPatrice Chotard } 443*642346aeSPatrice Chotard 44447a0fd3bSSimon Glass static inline int dev_read_addr_cells(struct udevice *dev) 44547a0fd3bSSimon Glass { 446878d68c0SSimon Glass /* NOTE: this call should walk up the parent stack */ 44747a0fd3bSSimon Glass return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); 44847a0fd3bSSimon Glass } 44947a0fd3bSSimon Glass 45047a0fd3bSSimon Glass static inline int dev_read_size_cells(struct udevice *dev) 45147a0fd3bSSimon Glass { 452878d68c0SSimon Glass /* NOTE: this call should walk up the parent stack */ 453878d68c0SSimon Glass return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); 454878d68c0SSimon Glass } 455878d68c0SSimon Glass 456878d68c0SSimon Glass static inline int dev_read_simple_addr_cells(struct udevice *dev) 457878d68c0SSimon Glass { 458878d68c0SSimon Glass return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); 459878d68c0SSimon Glass } 460878d68c0SSimon Glass 461878d68c0SSimon Glass static inline int dev_read_simple_size_cells(struct udevice *dev) 462878d68c0SSimon Glass { 46347a0fd3bSSimon Glass return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); 46447a0fd3bSSimon Glass } 46547a0fd3bSSimon Glass 46647a0fd3bSSimon Glass static inline int dev_read_phandle(struct udevice *dev) 46747a0fd3bSSimon Glass { 46847a0fd3bSSimon Glass return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); 46947a0fd3bSSimon Glass } 47047a0fd3bSSimon Glass 47147a0fd3bSSimon Glass static inline const u32 *dev_read_prop(struct udevice *dev, 47247a0fd3bSSimon Glass const char *propname, int *lenp) 47347a0fd3bSSimon Glass { 47461e51babSMasahiro Yamada return ofnode_get_property(dev_ofnode(dev), propname, lenp); 47547a0fd3bSSimon Glass } 47647a0fd3bSSimon Glass 47747a0fd3bSSimon Glass static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) 47847a0fd3bSSimon Glass { 47947a0fd3bSSimon Glass return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, 48047a0fd3bSSimon Glass dev_of_offset(dev), devnump); 48147a0fd3bSSimon Glass } 48247a0fd3bSSimon Glass 48347a0fd3bSSimon Glass static inline int dev_read_u32_array(struct udevice *dev, const char *propname, 48447a0fd3bSSimon Glass u32 *out_values, size_t sz) 48547a0fd3bSSimon Glass { 48647a0fd3bSSimon Glass return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); 48747a0fd3bSSimon Glass } 48847a0fd3bSSimon Glass 48947a0fd3bSSimon Glass static inline ofnode dev_read_first_subnode(struct udevice *dev) 49047a0fd3bSSimon Glass { 49147a0fd3bSSimon Glass return ofnode_first_subnode(dev_ofnode(dev)); 49247a0fd3bSSimon Glass } 49347a0fd3bSSimon Glass 49447a0fd3bSSimon Glass static inline ofnode dev_read_next_subnode(ofnode node) 49547a0fd3bSSimon Glass { 49647a0fd3bSSimon Glass return ofnode_next_subnode(node); 49747a0fd3bSSimon Glass } 49847a0fd3bSSimon Glass 499f11c7ab9SSimon Glass static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, 500f11c7ab9SSimon Glass const char *propname, size_t sz) 501f11c7ab9SSimon Glass { 502f11c7ab9SSimon Glass return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); 503f11c7ab9SSimon Glass } 504f11c7ab9SSimon Glass 505f7d6fcf7SSimon Glass static inline int dev_read_enabled(struct udevice *dev) 506f7d6fcf7SSimon Glass { 507f7d6fcf7SSimon Glass return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); 508f7d6fcf7SSimon Glass } 509f7d6fcf7SSimon Glass 510f11c7ab9SSimon Glass #endif /* CONFIG_DM_DEV_READ_INLINE */ 511f11c7ab9SSimon Glass 512f11c7ab9SSimon Glass /** 513f11c7ab9SSimon Glass * dev_for_each_subnode() - Helper function to iterate through subnodes 514f11c7ab9SSimon Glass * 515f11c7ab9SSimon Glass * This creates a for() loop which works through the subnodes in a device's 516f11c7ab9SSimon Glass * device-tree node. 517f11c7ab9SSimon Glass * 518f11c7ab9SSimon Glass * @subnode: ofnode holding the current subnode 519f11c7ab9SSimon Glass * @dev: device to use for interation (struct udevice *) 520f11c7ab9SSimon Glass */ 521f11c7ab9SSimon Glass #define dev_for_each_subnode(subnode, dev) \ 522f11c7ab9SSimon Glass for (subnode = dev_read_first_subnode(dev); \ 523f11c7ab9SSimon Glass ofnode_valid(subnode); \ 524f11c7ab9SSimon Glass subnode = ofnode_next_subnode(subnode)) 525f11c7ab9SSimon Glass 526f11c7ab9SSimon Glass #endif 527