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