Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Function to read values from the device tree node attached to a udevice. |
| 4 | * |
| 5 | * Copyright (c) 2017 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DM_READ_H |
| 10 | #define _DM_READ_H |
| 11 | |
| 12 | #include <dm/fdtaddr.h> |
| 13 | #include <dm/ofnode.h> |
| 14 | #include <dm/uclass.h> |
| 15 | |
Simon Glass | a448101 | 2017-06-12 06:21:29 -0600 | [diff] [blame] | 16 | struct resource; |
| 17 | |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 18 | #if CONFIG_IS_ENABLED(OF_LIVE) |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 19 | static inline const struct device_node *dev_np(const struct udevice *dev) |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 20 | { |
| 21 | return ofnode_to_np(dev->node); |
| 22 | } |
| 23 | #else |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 24 | static inline const struct device_node *dev_np(const struct udevice *dev) |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 25 | { |
| 26 | return NULL; |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | /** |
| 31 | * dev_ofnode() - get the DT node reference associated with a udevice |
| 32 | * |
| 33 | * @dev: device to check |
| 34 | * @return reference of the the device's DT node |
| 35 | */ |
Simon Glass | fc347fb | 2020-01-27 08:49:36 -0700 | [diff] [blame] | 36 | static inline ofnode dev_ofnode(const struct udevice *dev) |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 37 | { |
| 38 | return dev->node; |
| 39 | } |
| 40 | |
Simon Glass | fc347fb | 2020-01-27 08:49:36 -0700 | [diff] [blame] | 41 | static inline bool dev_of_valid(const struct udevice *dev) |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 42 | { |
| 43 | return ofnode_valid(dev_ofnode(dev)); |
| 44 | } |
| 45 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 46 | #ifndef CONFIG_DM_DEV_READ_INLINE |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 47 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 48 | /** |
Masahiro Yamada | 3ab48f6 | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 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 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 56 | int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp); |
Masahiro Yamada | 3ab48f6 | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 57 | |
| 58 | /** |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 59 | * dev_read_u32_default() - read a 32-bit integer from a device's DT property |
| 60 | * |
| 61 | * @dev: device to read DT property from |
| 62 | * @propname: name of the property to read from |
| 63 | * @def: default value to return if the property has no value |
| 64 | * @return property value, or @def if not found |
| 65 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 66 | int dev_read_u32_default(const struct udevice *dev, const char *propname, |
| 67 | int def); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 68 | |
| 69 | /** |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 70 | * dev_read_s32() - read a signed 32-bit integer from a device's DT property |
| 71 | * |
| 72 | * @dev: device to read DT property from |
| 73 | * @propname: name of the property to read from |
| 74 | * @outp: place to put value (if found) |
| 75 | * @return 0 if OK, -ve on error |
| 76 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 77 | int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp); |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * dev_read_s32_default() - read a signed 32-bit int from a device's DT property |
| 81 | * |
| 82 | * @dev: device to read DT property from |
| 83 | * @propname: name of the property to read from |
| 84 | * @def: default value to return if the property has no value |
| 85 | * @return property value, or @def if not found |
| 86 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 87 | int dev_read_s32_default(const struct udevice *dev, const char *propname, |
| 88 | int def); |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * dev_read_u32u() - read a 32-bit integer from a device's DT property |
| 92 | * |
| 93 | * This version uses a standard uint type. |
| 94 | * |
| 95 | * @dev: device to read DT property from |
| 96 | * @propname: name of the property to read from |
| 97 | * @outp: place to put value (if found) |
| 98 | * @return 0 if OK, -ve on error |
| 99 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 100 | int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp); |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 103 | * dev_read_u64() - read a 64-bit integer from a device's DT property |
| 104 | * |
| 105 | * @dev: device to read DT property from |
| 106 | * @propname: name of the property to read from |
| 107 | * @outp: place to put value (if found) |
| 108 | * @return 0 if OK, -ve on error |
| 109 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 110 | int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp); |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * dev_read_u64_default() - read a 64-bit integer from a device's DT property |
| 114 | * |
| 115 | * @dev: device to read DT property from |
| 116 | * @propname: name of the property to read from |
| 117 | * @def: default value to return if the property has no value |
| 118 | * @return property value, or @def if not found |
| 119 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 120 | u64 dev_read_u64_default(const struct udevice *dev, const char *propname, |
| 121 | u64 def); |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 122 | |
| 123 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 124 | * dev_read_string() - Read a string from a device's DT property |
| 125 | * |
| 126 | * @dev: device to read DT property from |
| 127 | * @propname: name of the property to read |
| 128 | * @return string from property value, or NULL if there is no such property |
| 129 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 130 | const char *dev_read_string(const struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * dev_read_bool() - read a boolean value from a device's DT property |
| 134 | * |
| 135 | * @dev: device to read DT property from |
| 136 | * @propname: name of property to read |
| 137 | * @return true if property is present (meaning true), false if not present |
| 138 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 139 | bool dev_read_bool(const struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * dev_read_subnode() - find a named subnode of a device |
| 143 | * |
| 144 | * @dev: device whose DT node contains the subnode |
| 145 | * @subnode_name: name of subnode to find |
| 146 | * @return reference to subnode (which can be invalid if there is no such |
| 147 | * subnode) |
| 148 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 149 | ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * dev_read_size() - read the size of a property |
| 153 | * |
| 154 | * @dev: device to check |
| 155 | * @propname: property to check |
| 156 | * @return size of property if present, or -EINVAL if not |
| 157 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 158 | int dev_read_size(const struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * dev_read_addr_index() - Get the indexed reg property of a device |
| 162 | * |
| 163 | * @dev: Device to read from |
| 164 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 165 | * and @index is used to select which one is required |
| 166 | * |
| 167 | * @return address or FDT_ADDR_T_NONE if not found |
| 168 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 169 | fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 170 | |
| 171 | /** |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 172 | * dev_read_addr_size_index() - Get the indexed reg property of a device |
| 173 | * |
| 174 | * @dev: Device to read from |
| 175 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 176 | * and @index is used to select which one is required |
| 177 | * @size: place to put size value (on success) |
| 178 | * |
| 179 | * @return address or FDT_ADDR_T_NONE if not found |
| 180 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 181 | fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 182 | fdt_size_t *size); |
| 183 | |
| 184 | /** |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 185 | * dev_remap_addr_index() - Get the indexed reg property of a device |
| 186 | * as a memory-mapped I/O pointer |
| 187 | * |
| 188 | * @dev: Device to read from |
| 189 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 190 | * and @index is used to select which one is required |
| 191 | * |
| 192 | * @return pointer or NULL if not found |
| 193 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 194 | void *dev_remap_addr_index(const struct udevice *dev, int index); |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 195 | |
| 196 | /** |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 197 | * dev_read_addr_name() - Get the reg property of a device, indexed by name |
| 198 | * |
| 199 | * @dev: Device to read from |
| 200 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 201 | * 'reg-names' property providing named-based identification. @index |
| 202 | * indicates the value to search for in 'reg-names'. |
| 203 | * |
| 204 | * @return address or FDT_ADDR_T_NONE if not found |
| 205 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 206 | fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name); |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 207 | |
| 208 | /** |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 209 | * dev_read_addr_size_name() - Get the reg property of a device, indexed by name |
| 210 | * |
| 211 | * @dev: Device to read from |
| 212 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 213 | * 'reg-names' property providing named-based identification. @index |
| 214 | * indicates the value to search for in 'reg-names'. |
| 215 | * @size: place to put size value (on success) |
| 216 | * |
| 217 | * @return address or FDT_ADDR_T_NONE if not found |
| 218 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 219 | fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 220 | fdt_size_t *size); |
| 221 | |
| 222 | /** |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 223 | * dev_remap_addr_name() - Get the reg property of a device, indexed by name, |
| 224 | * as a memory-mapped I/O pointer |
| 225 | * |
| 226 | * @dev: Device to read from |
| 227 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 228 | * 'reg-names' property providing named-based identification. @index |
| 229 | * indicates the value to search for in 'reg-names'. |
| 230 | * |
| 231 | * @return pointer or NULL if not found |
| 232 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 233 | void *dev_remap_addr_name(const struct udevice *dev, const char *name); |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 234 | |
| 235 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 236 | * dev_read_addr() - Get the reg property of a device |
| 237 | * |
| 238 | * @dev: Device to read from |
| 239 | * |
| 240 | * @return address or FDT_ADDR_T_NONE if not found |
| 241 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 242 | fdt_addr_t dev_read_addr(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 243 | |
| 244 | /** |
Philipp Tomsich | c131c8b | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 245 | * dev_read_addr_ptr() - Get the reg property of a device |
| 246 | * as a pointer |
| 247 | * |
| 248 | * @dev: Device to read from |
| 249 | * |
| 250 | * @return pointer or NULL if not found |
| 251 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 252 | void *dev_read_addr_ptr(const struct udevice *dev); |
Philipp Tomsich | c131c8b | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 253 | |
| 254 | /** |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 255 | * dev_read_addr_pci() - Read an address and handle PCI address translation |
| 256 | * |
| 257 | * At present U-Boot does not have address translation logic for PCI in the |
| 258 | * livetree implementation (of_addr.c). This special function supports this for |
| 259 | * the flat tree implementation. |
| 260 | * |
| 261 | * This function should be removed (and code should use dev_read() instead) |
| 262 | * once: |
| 263 | * |
| 264 | * 1. PCI address translation is added; and either |
| 265 | * 2. everything uses livetree where PCI translation is used (which is feasible |
| 266 | * in SPL and U-Boot proper) or PCI address translation is added to |
| 267 | * fdtdec_get_addr() and friends. |
| 268 | * |
| 269 | * @dev: Device to read from |
| 270 | * @return address or FDT_ADDR_T_NONE if not found |
| 271 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 272 | fdt_addr_t dev_read_addr_pci(const struct udevice *dev); |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 273 | |
| 274 | /** |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 275 | * dev_remap_addr() - Get the reg property of a device as a |
| 276 | * memory-mapped I/O pointer |
| 277 | * |
| 278 | * @dev: Device to read from |
| 279 | * |
| 280 | * @return pointer or NULL if not found |
| 281 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 282 | void *dev_remap_addr(const struct udevice *dev); |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 283 | |
| 284 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 285 | * dev_read_addr_size() - get address and size from a device property |
| 286 | * |
| 287 | * This does no address translation. It simply reads an property that contains |
| 288 | * an address and a size value, one after the other. |
| 289 | * |
| 290 | * @dev: Device to read from |
| 291 | * @propname: property to read |
| 292 | * @sizep: place to put size value (on success) |
| 293 | * @return address value, or FDT_ADDR_T_NONE on error |
| 294 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 295 | fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname, |
| 296 | fdt_size_t *sizep); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * dev_read_name() - get the name of a device's node |
| 300 | * |
Bin Meng | 15d61d0 | 2019-07-05 09:23:18 -0700 | [diff] [blame] | 301 | * @dev: Device to read from |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 302 | * @return name of node |
| 303 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 304 | const char *dev_read_name(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * dev_read_stringlist_search() - find string in a string list and return index |
| 308 | * |
| 309 | * Note that it is possible for this function to succeed on property values |
| 310 | * that are not NUL-terminated. That's because the function will stop after |
| 311 | * finding the first occurrence of @string. This can for example happen with |
| 312 | * small-valued cell properties, such as #address-cells, when searching for |
| 313 | * the empty string. |
| 314 | * |
| 315 | * @dev: device to check |
| 316 | * @propname: name of the property containing the string list |
| 317 | * @string: string to look up in the string list |
| 318 | * |
| 319 | * @return: |
| 320 | * the index of the string in the list of strings |
| 321 | * -ENODATA if the property is not found |
| 322 | * -EINVAL on some other error |
| 323 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 324 | int dev_read_stringlist_search(const struct udevice *dev, const char *property, |
| 325 | const char *string); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 326 | |
| 327 | /** |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 328 | * dev_read_string_index() - obtain an indexed string from a string list |
| 329 | * |
| 330 | * @dev: device to examine |
| 331 | * @propname: name of the property containing the string list |
| 332 | * @index: index of the string to return |
| 333 | * @out: return location for the string |
| 334 | * |
| 335 | * @return: |
| 336 | * length of string, if found or -ve error value if not found |
| 337 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 338 | int dev_read_string_index(const struct udevice *dev, const char *propname, |
| 339 | int index, const char **outp); |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 340 | |
| 341 | /** |
| 342 | * dev_read_string_count() - find the number of strings in a string list |
| 343 | * |
| 344 | * @dev: device to examine |
| 345 | * @propname: name of the property containing the string list |
| 346 | * @return: |
| 347 | * number of strings in the list, or -ve error value if not found |
| 348 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 349 | int dev_read_string_count(const struct udevice *dev, const char *propname); |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 350 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 351 | * dev_read_phandle_with_args() - Find a node pointed by phandle in a list |
| 352 | * |
| 353 | * This function is useful to parse lists of phandles and their arguments. |
| 354 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 355 | * errno value. |
| 356 | * |
| 357 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 358 | * pointer. |
| 359 | * |
| 360 | * Example: |
| 361 | * |
| 362 | * phandle1: node1 { |
| 363 | * #list-cells = <2>; |
| 364 | * } |
| 365 | * |
| 366 | * phandle2: node2 { |
| 367 | * #list-cells = <1>; |
| 368 | * } |
| 369 | * |
| 370 | * node3 { |
| 371 | * list = <&phandle1 1 2 &phandle2 3>; |
| 372 | * } |
| 373 | * |
| 374 | * To get a device_node of the `node2' node you may call this: |
| 375 | * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args); |
| 376 | * |
| 377 | * @dev: device whose node containing a list |
| 378 | * @list_name: property name that contains a list |
| 379 | * @cells_name: property name that specifies phandles' arguments count |
| 380 | * @cells_count: Cell count to use if @cells_name is NULL |
| 381 | * @index: index of a phandle to parse out |
| 382 | * @out_args: optional pointer to output arguments structure (will be filled) |
| 383 | * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 384 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 385 | * @cells_name could not be found, the arguments were truncated or there |
| 386 | * were too many arguments. |
| 387 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 388 | int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, |
| 389 | const char *cells_name, int cell_count, |
| 390 | int index, struct ofnode_phandle_args *out_args); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 391 | |
| 392 | /** |
Patrice Chotard | 642346a | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 393 | * dev_count_phandle_with_args() - Return phandle number in a list |
| 394 | * |
| 395 | * This function is usefull to get phandle number contained in a property list. |
| 396 | * For example, this allows to allocate the right amount of memory to keep |
| 397 | * clock's reference contained into the "clocks" property. |
| 398 | * |
| 399 | * |
| 400 | * @dev: device whose node containing a list |
| 401 | * @list_name: property name that contains a list |
| 402 | * @cells_name: property name that specifies phandles' arguments count |
| 403 | * @Returns number of phandle found on success, on error returns appropriate |
| 404 | * errno value. |
| 405 | */ |
| 406 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 407 | int dev_count_phandle_with_args(const struct udevice *dev, |
| 408 | const char *list_name, const char *cells_name); |
Patrice Chotard | 642346a | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 409 | |
| 410 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 411 | * dev_read_addr_cells() - Get the number of address cells for a device's node |
| 412 | * |
| 413 | * This walks back up the tree to find the closest #address-cells property |
| 414 | * which controls the given node. |
| 415 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 416 | * @dev: device to check |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 417 | * @return number of address cells this node uses |
| 418 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 419 | int dev_read_addr_cells(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 420 | |
| 421 | /** |
| 422 | * dev_read_size_cells() - Get the number of size cells for a device's node |
| 423 | * |
| 424 | * This walks back up the tree to find the closest #size-cells property |
| 425 | * which controls the given node. |
| 426 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 427 | * @dev: device to check |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 428 | * @return number of size cells this node uses |
| 429 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 430 | int dev_read_size_cells(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 431 | |
| 432 | /** |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 433 | * dev_read_addr_cells() - Get the address cells property in a node |
| 434 | * |
| 435 | * This function matches fdt_address_cells(). |
| 436 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 437 | * @dev: device to check |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 438 | * @return number of address cells this node uses |
| 439 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 440 | int dev_read_simple_addr_cells(const struct udevice *dev); |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * dev_read_size_cells() - Get the size cells property in a node |
| 444 | * |
| 445 | * This function matches fdt_size_cells(). |
| 446 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 447 | * @dev: device to check |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 448 | * @return number of size cells this node uses |
| 449 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 450 | int dev_read_simple_size_cells(const struct udevice *dev); |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 451 | |
| 452 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 453 | * dev_read_phandle() - Get the phandle from a device |
| 454 | * |
| 455 | * @dev: device to check |
| 456 | * @return phandle (1 or greater), or 0 if no phandle or other error |
| 457 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 458 | int dev_read_phandle(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 459 | |
| 460 | /** |
| 461 | * dev_read_prop()- - read a property from a device's node |
| 462 | * |
| 463 | * @dev: device to check |
| 464 | * @propname: property to read |
| 465 | * @lenp: place to put length on success |
| 466 | * @return pointer to property, or NULL if not found |
| 467 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 468 | const void *dev_read_prop(const struct udevice *dev, const char *propname, |
| 469 | int *lenp); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * dev_read_alias_seq() - Get the alias sequence number of a node |
| 473 | * |
| 474 | * This works out whether a node is pointed to by an alias, and if so, the |
| 475 | * sequence number of that alias. Aliases are of the form <base><num> where |
| 476 | * <num> is the sequence number. For example spi2 would be sequence number 2. |
| 477 | * |
| 478 | * @dev: device to look up |
| 479 | * @devnump: set to the sequence number if one is found |
| 480 | * @return 0 if a sequence was found, -ve if not |
| 481 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 482 | int dev_read_alias_seq(const struct udevice *dev, int *devnump); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 483 | |
| 484 | /** |
| 485 | * dev_read_u32_array() - Find and read an array of 32 bit integers |
| 486 | * |
| 487 | * Search for a property in a device node and read 32-bit value(s) from |
| 488 | * it. |
| 489 | * |
| 490 | * The out_values is modified only if a valid u32 value can be decoded. |
| 491 | * |
| 492 | * @dev: device to look up |
| 493 | * @propname: name of the property to read |
| 494 | * @out_values: pointer to return value, modified only if return value is 0 |
| 495 | * @sz: number of array elements to read |
| 496 | * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if |
| 497 | * property does not have a value, and -EOVERFLOW if the property data isn't |
| 498 | * large enough. |
| 499 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 500 | int dev_read_u32_array(const struct udevice *dev, const char *propname, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 501 | u32 *out_values, size_t sz); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * dev_read_first_subnode() - find the first subnode of a device's node |
| 505 | * |
| 506 | * @dev: device to look up |
| 507 | * @return reference to the first subnode (which can be invalid if the device's |
| 508 | * node has no subnodes) |
| 509 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 510 | ofnode dev_read_first_subnode(const struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 514 | * |
| 515 | * @node: valid reference to previous node (sibling) |
| 516 | * @return reference to the next subnode (which can be invalid if the node |
| 517 | * has no more siblings) |
| 518 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 519 | ofnode dev_read_next_subnode(ofnode node); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 520 | |
| 521 | /** |
| 522 | * dev_read_u8_array_ptr() - find an 8-bit array |
| 523 | * |
| 524 | * Look up a device's node property and return a pointer to its contents as a |
| 525 | * byte array of given length. The property must have at least enough data |
| 526 | * for the array (count bytes). It may have more, but this will be ignored. |
| 527 | * The data is not copied. |
| 528 | * |
| 529 | * @dev: device to look up |
| 530 | * @propname: name of property to find |
| 531 | * @sz: number of array elements |
| 532 | * @return pointer to byte array if found, or NULL if the property is not |
| 533 | * found or there is not enough data |
| 534 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 535 | const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, |
| 536 | const char *propname, size_t sz); |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 537 | |
Simon Glass | f7d6fcf | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 538 | /** |
| 539 | * dev_read_enabled() - check whether a node is enabled |
| 540 | * |
| 541 | * This looks for a 'status' property. If this exists, then returns 1 if |
| 542 | * the status is 'ok' and 0 otherwise. If there is no status property, |
| 543 | * it returns 1 on the assumption that anything mentioned should be enabled |
| 544 | * by default. |
| 545 | * |
| 546 | * @dev: device to examine |
| 547 | * @return integer value 0 (not enabled) or 1 (enabled) |
| 548 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 549 | int dev_read_enabled(const struct udevice *dev); |
Simon Glass | f7d6fcf | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 550 | |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 551 | /** |
| 552 | * dev_read_resource() - obtain an indexed resource from a device. |
| 553 | * |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 554 | * @dev: device to examine |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 555 | * @index index of the resource to retrieve (0 = first) |
| 556 | * @res returns the resource |
| 557 | * @return 0 if ok, negative on error |
| 558 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 559 | int dev_read_resource(const struct udevice *dev, uint index, |
| 560 | struct resource *res); |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 561 | |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 562 | /** |
| 563 | * dev_read_resource_byname() - obtain a named resource from a device. |
| 564 | * |
| 565 | * @dev: device to examine |
| 566 | * @name: name of the resource to retrieve |
| 567 | * @res: returns the resource |
| 568 | * @return 0 if ok, negative on error |
| 569 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 570 | int dev_read_resource_byname(const struct udevice *dev, const char *name, |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 571 | struct resource *res); |
| 572 | |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 573 | /** |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 574 | * dev_translate_address() - Translate a device-tree address |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 575 | * |
| 576 | * Translate an address from the device-tree into a CPU physical address. This |
| 577 | * function walks up the tree and applies the various bus mappings along the |
| 578 | * way. |
| 579 | * |
| 580 | * @dev: device giving the context in which to translate the address |
| 581 | * @in_addr: pointer to the address to translate |
| 582 | * @return the translated address; OF_BAD_ADDR on error |
| 583 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 584 | u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr); |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 585 | |
| 586 | /** |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 587 | * dev_translate_dma_address() - Translate a device-tree DMA address |
| 588 | * |
| 589 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 590 | * This function walks up the tree and applies the various bus mappings along |
| 591 | * the way. |
| 592 | * |
| 593 | * @dev: device giving the context in which to translate the DMA address |
| 594 | * @in_addr: pointer to the DMA address to translate |
| 595 | * @return the translated DMA address; OF_BAD_ADDR on error |
| 596 | */ |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 597 | u64 dev_translate_dma_address(const struct udevice *dev, |
| 598 | const fdt32_t *in_addr); |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 599 | |
| 600 | /** |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 601 | * dev_read_alias_highest_id - Get highest alias id for the given stem |
| 602 | * @stem: Alias stem to be examined |
| 603 | * |
| 604 | * The function travels the lookup table to get the highest alias id for the |
| 605 | * given alias stem. |
| 606 | * @return alias ID, if found, else -1 |
| 607 | */ |
| 608 | int dev_read_alias_highest_id(const char *stem); |
| 609 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 610 | #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ |
| 611 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 612 | static inline int dev_read_u32(const struct udevice *dev, |
Masahiro Yamada | 3ab48f6 | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 613 | const char *propname, u32 *outp) |
| 614 | { |
| 615 | return ofnode_read_u32(dev_ofnode(dev), propname, outp); |
| 616 | } |
| 617 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 618 | static inline int dev_read_u32_default(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 619 | const char *propname, int def) |
| 620 | { |
| 621 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 622 | } |
| 623 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 624 | static inline int dev_read_s32(const struct udevice *dev, |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 625 | const char *propname, s32 *outp) |
| 626 | { |
| 627 | return ofnode_read_s32(dev_ofnode(dev), propname, outp); |
| 628 | } |
| 629 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 630 | static inline int dev_read_s32_default(const struct udevice *dev, |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 631 | const char *propname, int def) |
| 632 | { |
| 633 | return ofnode_read_s32_default(dev_ofnode(dev), propname, def); |
| 634 | } |
| 635 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 636 | static inline int dev_read_u32u(const struct udevice *dev, |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 637 | const char *propname, uint *outp) |
| 638 | { |
| 639 | u32 val; |
| 640 | int ret; |
| 641 | |
| 642 | ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); |
| 643 | if (ret) |
| 644 | return ret; |
| 645 | *outp = val; |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 650 | static inline int dev_read_u64(const struct udevice *dev, |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 651 | const char *propname, u64 *outp) |
| 652 | { |
| 653 | return ofnode_read_u64(dev_ofnode(dev), propname, outp); |
| 654 | } |
| 655 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 656 | static inline u64 dev_read_u64_default(const struct udevice *dev, |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 657 | const char *propname, u64 def) |
| 658 | { |
| 659 | return ofnode_read_u64_default(dev_ofnode(dev), propname, def); |
| 660 | } |
| 661 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 662 | static inline const char *dev_read_string(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 663 | const char *propname) |
| 664 | { |
| 665 | return ofnode_read_string(dev_ofnode(dev), propname); |
| 666 | } |
| 667 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 668 | static inline bool dev_read_bool(const struct udevice *dev, |
| 669 | const char *propname) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 670 | { |
| 671 | return ofnode_read_bool(dev_ofnode(dev), propname); |
| 672 | } |
| 673 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 674 | static inline ofnode dev_read_subnode(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 675 | const char *subbnode_name) |
| 676 | { |
| 677 | return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); |
| 678 | } |
| 679 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 680 | static inline int dev_read_size(const struct udevice *dev, const char *propname) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 681 | { |
| 682 | return ofnode_read_size(dev_ofnode(dev), propname); |
| 683 | } |
| 684 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 685 | static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev, |
| 686 | int index) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 687 | { |
| 688 | return devfdt_get_addr_index(dev, index); |
| 689 | } |
| 690 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 691 | static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 692 | int index, |
| 693 | fdt_size_t *size) |
| 694 | { |
| 695 | return devfdt_get_addr_size_index(dev, index, size); |
| 696 | } |
| 697 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 698 | static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev, |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 699 | const char *name) |
| 700 | { |
| 701 | return devfdt_get_addr_name(dev, name); |
| 702 | } |
| 703 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 704 | static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 705 | const char *name, |
| 706 | fdt_size_t *size) |
| 707 | { |
| 708 | return devfdt_get_addr_size_name(dev, name, size); |
| 709 | } |
| 710 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 711 | static inline fdt_addr_t dev_read_addr(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 712 | { |
| 713 | return devfdt_get_addr(dev); |
| 714 | } |
| 715 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 716 | static inline void *dev_read_addr_ptr(const struct udevice *dev) |
Philipp Tomsich | c131c8b | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 717 | { |
| 718 | return devfdt_get_addr_ptr(dev); |
| 719 | } |
| 720 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 721 | static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev) |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 722 | { |
| 723 | return devfdt_get_addr_pci(dev); |
| 724 | } |
| 725 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 726 | static inline void *dev_remap_addr(const struct udevice *dev) |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 727 | { |
| 728 | return devfdt_remap_addr(dev); |
| 729 | } |
| 730 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 731 | static inline void *dev_remap_addr_index(const struct udevice *dev, int index) |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 732 | { |
| 733 | return devfdt_remap_addr_index(dev, index); |
| 734 | } |
| 735 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 736 | static inline void *dev_remap_addr_name(const struct udevice *dev, |
| 737 | const char *name) |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 738 | { |
| 739 | return devfdt_remap_addr_name(dev, name); |
| 740 | } |
| 741 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 742 | static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 743 | const char *propname, |
| 744 | fdt_size_t *sizep) |
| 745 | { |
| 746 | return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); |
| 747 | } |
| 748 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 749 | static inline const char *dev_read_name(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 750 | { |
| 751 | return ofnode_get_name(dev_ofnode(dev)); |
| 752 | } |
| 753 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 754 | static inline int dev_read_stringlist_search(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 755 | const char *propname, |
| 756 | const char *string) |
| 757 | { |
| 758 | return ofnode_stringlist_search(dev_ofnode(dev), propname, string); |
| 759 | } |
| 760 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 761 | static inline int dev_read_string_index(const struct udevice *dev, |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 762 | const char *propname, int index, |
| 763 | const char **outp) |
| 764 | { |
| 765 | return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); |
| 766 | } |
| 767 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 768 | static inline int dev_read_string_count(const struct udevice *dev, |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 769 | const char *propname) |
| 770 | { |
| 771 | return ofnode_read_string_count(dev_ofnode(dev), propname); |
| 772 | } |
| 773 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 774 | static inline int dev_read_phandle_with_args(const struct udevice *dev, |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 775 | const char *list_name, const char *cells_name, int cell_count, |
| 776 | int index, struct ofnode_phandle_args *out_args) |
| 777 | { |
| 778 | return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, |
| 779 | cells_name, cell_count, index, |
| 780 | out_args); |
| 781 | } |
| 782 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 783 | static inline int dev_count_phandle_with_args(const struct udevice *dev, |
Patrice Chotard | 642346a | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 784 | const char *list_name, const char *cells_name) |
| 785 | { |
| 786 | return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, |
| 787 | cells_name); |
| 788 | } |
| 789 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 790 | static inline int dev_read_addr_cells(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 791 | { |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 792 | /* NOTE: this call should walk up the parent stack */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 793 | return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 794 | } |
| 795 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 796 | static inline int dev_read_size_cells(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 797 | { |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 798 | /* NOTE: this call should walk up the parent stack */ |
| 799 | return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 800 | } |
| 801 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 802 | static inline int dev_read_simple_addr_cells(const struct udevice *dev) |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 803 | { |
| 804 | return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 805 | } |
| 806 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 807 | static inline int dev_read_simple_size_cells(const struct udevice *dev) |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 808 | { |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 809 | return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 810 | } |
| 811 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 812 | static inline int dev_read_phandle(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 813 | { |
| 814 | return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); |
| 815 | } |
| 816 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 817 | static inline const void *dev_read_prop(const struct udevice *dev, |
Masahiro Yamada | fd73621 | 2017-07-17 12:18:39 +0900 | [diff] [blame] | 818 | const char *propname, int *lenp) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 819 | { |
Masahiro Yamada | 61e51ba | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 820 | return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 821 | } |
| 822 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 823 | static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 824 | { |
| 825 | return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, |
| 826 | dev_of_offset(dev), devnump); |
| 827 | } |
| 828 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 829 | static inline int dev_read_u32_array(const struct udevice *dev, |
| 830 | const char *propname, u32 *out_values, |
| 831 | size_t sz) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 832 | { |
| 833 | return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); |
| 834 | } |
| 835 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 836 | static inline ofnode dev_read_first_subnode(const struct udevice *dev) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 837 | { |
| 838 | return ofnode_first_subnode(dev_ofnode(dev)); |
| 839 | } |
| 840 | |
| 841 | static inline ofnode dev_read_next_subnode(ofnode node) |
| 842 | { |
| 843 | return ofnode_next_subnode(node); |
| 844 | } |
| 845 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 846 | static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, |
Simon Glass | f262d4c | 2020-01-27 08:49:47 -0700 | [diff] [blame] | 847 | const char *propname, |
| 848 | size_t sz) |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 849 | { |
| 850 | return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); |
| 851 | } |
| 852 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 853 | static inline int dev_read_enabled(const struct udevice *dev) |
Simon Glass | f7d6fcf | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 854 | { |
| 855 | return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); |
| 856 | } |
| 857 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 858 | static inline int dev_read_resource(const struct udevice *dev, uint index, |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 859 | struct resource *res) |
| 860 | { |
| 861 | return ofnode_read_resource(dev_ofnode(dev), index, res); |
| 862 | } |
| 863 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 864 | static inline int dev_read_resource_byname(const struct udevice *dev, |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 865 | const char *name, |
| 866 | struct resource *res) |
| 867 | { |
| 868 | return ofnode_read_resource_byname(dev_ofnode(dev), name, res); |
| 869 | } |
| 870 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 871 | static inline u64 dev_translate_address(const struct udevice *dev, |
| 872 | const fdt32_t *in_addr) |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 873 | { |
| 874 | return ofnode_translate_address(dev_ofnode(dev), in_addr); |
| 875 | } |
| 876 | |
Simon Glass | 88b3a37 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 877 | static inline u64 dev_translate_dma_address(const struct udevice *dev, |
| 878 | const fdt32_t *in_addr) |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 879 | { |
| 880 | return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); |
| 881 | } |
| 882 | |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 883 | static inline int dev_read_alias_highest_id(const char *stem) |
| 884 | { |
| 885 | return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); |
| 886 | } |
| 887 | |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 888 | #endif /* CONFIG_DM_DEV_READ_INLINE */ |
| 889 | |
| 890 | /** |
| 891 | * dev_for_each_subnode() - Helper function to iterate through subnodes |
| 892 | * |
| 893 | * This creates a for() loop which works through the subnodes in a device's |
| 894 | * device-tree node. |
| 895 | * |
| 896 | * @subnode: ofnode holding the current subnode |
| 897 | * @dev: device to use for interation (struct udevice *) |
| 898 | */ |
| 899 | #define dev_for_each_subnode(subnode, dev) \ |
| 900 | for (subnode = dev_read_first_subnode(dev); \ |
| 901 | ofnode_valid(subnode); \ |
| 902 | subnode = ofnode_next_subnode(subnode)) |
| 903 | |
| 904 | #endif |