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