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 | 992b603 | 2020-07-19 10:15:39 -0600 | [diff] [blame] | 14 | #include <dm/device.h> |
Simon Glass | 34ef0c2 | 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 | 170e17c | 2017-06-12 06:21:29 -0600 | [diff] [blame] | 19 | struct resource; |
| 20 | |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 21 | #if CONFIG_IS_ENABLED(OF_LIVE) |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 22 | static inline const struct device_node *dev_np(const struct udevice *dev) |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 23 | { |
Simon Glass | a7ece58 | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 24 | return ofnode_to_np(dev_ofnode(dev)); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 25 | } |
| 26 | #else |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 27 | static inline const struct device_node *dev_np(const struct udevice *dev) |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 28 | { |
| 29 | return NULL; |
| 30 | } |
| 31 | #endif |
| 32 | |
Simon Glass | 77f7c1e | 2021-01-21 13:57:10 -0700 | [diff] [blame] | 33 | #if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 34 | /** |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 35 | * dev_read_u8() - read a 8-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 | */ |
| 42 | int dev_read_u8(const struct udevice *dev, const char *propname, u8 *outp); |
| 43 | |
| 44 | /** |
| 45 | * dev_read_u8_default() - read a 8-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 | */ |
| 52 | u8 dev_read_u8_default(const struct udevice *dev, const char *propname, u8 def); |
| 53 | |
| 54 | /** |
| 55 | * dev_read_u16() - read a 16-bit integer from a device's DT property |
| 56 | * |
| 57 | * @dev: device to read DT property from |
| 58 | * @propname: name of the property to read from |
| 59 | * @outp: place to put value (if found) |
| 60 | * Return: 0 if OK, -ve on error |
| 61 | */ |
| 62 | int dev_read_u16(const struct udevice *dev, const char *propname, u16 *outp); |
| 63 | |
| 64 | /** |
| 65 | * dev_read_u16_default() - read a 16-bit integer from a device's DT property |
| 66 | * |
| 67 | * @dev: device to read DT property from |
| 68 | * @propname: name of the property to read from |
| 69 | * @def: default value to return if the property has no value |
| 70 | * Return: property value, or @def if not found |
| 71 | */ |
| 72 | u16 dev_read_u16_default(const struct udevice *dev, const char *propname, |
| 73 | u16 def); |
| 74 | |
| 75 | /** |
Masahiro Yamada | 71d115f | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 76 | * dev_read_u32() - read a 32-bit integer from a device's DT property |
| 77 | * |
| 78 | * @dev: device to read DT property from |
| 79 | * @propname: name of the property to read from |
| 80 | * @outp: place to put value (if found) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 81 | * Return: 0 if OK, -ve on error |
Masahiro Yamada | 71d115f | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 82 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 83 | 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] | 84 | |
| 85 | /** |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 86 | * dev_read_u32_default() - read a 32-bit integer from a device's DT property |
| 87 | * |
| 88 | * @dev: device to read DT property from |
| 89 | * @propname: name of the property to read from |
| 90 | * @def: default value to return if the property has no value |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 91 | * Return: property value, or @def if not found |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 92 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 93 | int dev_read_u32_default(const struct udevice *dev, const char *propname, |
| 94 | int def); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 95 | |
| 96 | /** |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 97 | * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT |
| 98 | * property |
| 99 | * |
| 100 | * @dev: device to read DT property from |
| 101 | * @propname: name of the property to read from |
| 102 | * @index: index of the integer to return |
| 103 | * @outp: place to put value (if found) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 104 | * Return: 0 if OK, -ve on error |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 105 | */ |
| 106 | int dev_read_u32_index(struct udevice *dev, const char *propname, int index, |
| 107 | u32 *outp); |
| 108 | |
| 109 | /** |
| 110 | * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's |
| 111 | * DT property |
| 112 | * |
| 113 | * @dev: device to read DT property from |
| 114 | * @propname: name of the property to read from |
| 115 | * @index: index of the integer to return |
| 116 | * @def: default value to return if the property has no value |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 117 | * Return: property value, or @def if not found |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 118 | */ |
| 119 | u32 dev_read_u32_index_default(struct udevice *dev, const char *propname, |
| 120 | int index, u32 def); |
| 121 | |
| 122 | /** |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 123 | * dev_read_s32() - read a signed 32-bit integer from a device's DT property |
| 124 | * |
| 125 | * @dev: device to read DT property from |
| 126 | * @propname: name of the property to read from |
| 127 | * @outp: place to put value (if found) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 128 | * Return: 0 if OK, -ve on error |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 129 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 130 | 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] | 131 | |
| 132 | /** |
| 133 | * dev_read_s32_default() - read a signed 32-bit int from a device's DT property |
| 134 | * |
| 135 | * @dev: device to read DT property from |
| 136 | * @propname: name of the property to read from |
| 137 | * @def: default value to return if the property has no value |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 138 | * Return: property value, or @def if not found |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 139 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 140 | int dev_read_s32_default(const struct udevice *dev, const char *propname, |
| 141 | int def); |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * dev_read_u32u() - read a 32-bit integer from a device's DT property |
| 145 | * |
| 146 | * This version uses a standard uint type. |
| 147 | * |
| 148 | * @dev: device to read DT property from |
| 149 | * @propname: name of the property to read from |
| 150 | * @outp: place to put value (if found) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 151 | * Return: 0 if OK, -ve on error |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 152 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 153 | 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] | 154 | |
| 155 | /** |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 156 | * dev_read_u64() - read a 64-bit integer from a device's DT property |
| 157 | * |
| 158 | * @dev: device to read DT property from |
| 159 | * @propname: name of the property to read from |
| 160 | * @outp: place to put value (if found) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 161 | * Return: 0 if OK, -ve on error |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 162 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 163 | 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] | 164 | |
| 165 | /** |
| 166 | * dev_read_u64_default() - read a 64-bit integer from a device's DT property |
| 167 | * |
| 168 | * @dev: device to read DT property from |
| 169 | * @propname: name of the property to read from |
| 170 | * @def: default value to return if the property has no value |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 171 | * Return: property value, or @def if not found |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 172 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 173 | u64 dev_read_u64_default(const struct udevice *dev, const char *propname, |
| 174 | u64 def); |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 175 | |
| 176 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 177 | * dev_read_string() - Read a string from a device's DT property |
| 178 | * |
| 179 | * @dev: device to read DT property from |
| 180 | * @propname: name of the property to read |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 181 | * Return: string from property value, or NULL if there is no such property |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 182 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 183 | const char *dev_read_string(const struct udevice *dev, const char *propname); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * dev_read_bool() - read a boolean value from a device's DT property |
| 187 | * |
| 188 | * @dev: device to read DT property from |
| 189 | * @propname: name of property to read |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 190 | * Return: true if property is present (meaning true), false if not present |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 191 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 192 | bool dev_read_bool(const struct udevice *dev, const char *propname); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * dev_read_subnode() - find a named subnode of a device |
| 196 | * |
| 197 | * @dev: device whose DT node contains the subnode |
| 198 | * @subnode_name: name of subnode to find |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 199 | * Return: reference to subnode (which can be invalid if there is no such |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 200 | * subnode) |
| 201 | */ |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 202 | ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * dev_read_size() - read the size of a property |
| 206 | * |
| 207 | * @dev: device to check |
| 208 | * @propname: property to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 209 | * Return: size of property if present, or -EINVAL if not |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 210 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 211 | int dev_read_size(const struct udevice *dev, const char *propname); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * dev_read_addr_index() - Get the indexed reg property of a device |
| 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 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 220 | * Return: address or FDT_ADDR_T_NONE if not found |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 221 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 222 | 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] | 223 | |
| 224 | /** |
Bin Meng | 21cdfea | 2021-09-12 11:15:13 +0800 | [diff] [blame] | 225 | * dev_read_addr_index_ptr() - Get the indexed reg property of a device |
| 226 | * as a pointer |
| 227 | * |
| 228 | * @dev: Device to read from |
| 229 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 230 | * and @index is used to select which one is required |
| 231 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 232 | * Return: pointer or NULL if not found |
Bin Meng | 21cdfea | 2021-09-12 11:15:13 +0800 | [diff] [blame] | 233 | */ |
| 234 | void *dev_read_addr_index_ptr(const struct udevice *dev, int index); |
| 235 | |
| 236 | /** |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 237 | * dev_read_addr_size_index() - Get the indexed reg property of a device |
| 238 | * |
| 239 | * @dev: Device to read from |
| 240 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 241 | * and @index is used to select which one is required |
| 242 | * @size: place to put size value (on success) |
| 243 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 244 | * Return: address or FDT_ADDR_T_NONE if not found |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 245 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 246 | 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] | 247 | fdt_size_t *size); |
| 248 | |
| 249 | /** |
Jonas Karlman | 3b00730 | 2023-07-22 13:30:15 +0000 | [diff] [blame] | 250 | * dev_read_addr_size_index_ptr() - Get the indexed reg property of a device |
| 251 | * as a pointer |
| 252 | * |
| 253 | * @dev: Device to read from |
| 254 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 255 | * and @index is used to select which one is required |
| 256 | * @size: place to put size value (on success) |
| 257 | * |
| 258 | * Return: pointer or NULL if not found |
| 259 | */ |
| 260 | void *dev_read_addr_size_index_ptr(const struct udevice *dev, int index, |
| 261 | fdt_size_t *size); |
| 262 | |
| 263 | /** |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 264 | * dev_remap_addr_index() - Get the indexed reg property of a device |
| 265 | * as a memory-mapped I/O pointer |
| 266 | * |
| 267 | * @dev: Device to read from |
| 268 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 269 | * and @index is used to select which one is required |
| 270 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 271 | * Return: pointer or NULL if not found |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 272 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 273 | 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] | 274 | |
| 275 | /** |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 276 | * dev_read_addr_name() - Get the reg property of a device, indexed by name |
| 277 | * |
| 278 | * @dev: Device to read from |
| 279 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
Matthias Schiffer | 7c238d0 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 280 | * 'reg-names' property providing named-based identification. @name |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 281 | * indicates the value to search for in 'reg-names'. |
| 282 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 283 | * Return: address or FDT_ADDR_T_NONE if not found |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 284 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 285 | 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] | 286 | |
| 287 | /** |
Matthias Schiffer | 5e90d4e | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 288 | * dev_read_addr_name_ptr() - Get the reg property of a device as a pointer, |
| 289 | * indexed by name |
| 290 | * |
| 291 | * @dev: Device to read from |
| 292 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 293 | * 'reg-names' property providing named-based identification. @name |
| 294 | * indicates the value to search for in 'reg-names'. |
| 295 | * |
| 296 | * Return: pointer or NULL if not found |
| 297 | */ |
| 298 | void *dev_read_addr_name_ptr(const struct udevice *dev, const char *name); |
| 299 | |
| 300 | /** |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 301 | * dev_read_addr_size_name() - Get the reg property of a device, indexed by name |
| 302 | * |
| 303 | * @dev: Device to read from |
| 304 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
Matthias Schiffer | 7c238d0 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 305 | * 'reg-names' property providing named-based identification. @name |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 306 | * indicates the value to search for in 'reg-names'. |
| 307 | * @size: place to put size value (on success) |
| 308 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 309 | * Return: address or FDT_ADDR_T_NONE if not found |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 310 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 311 | 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] | 312 | fdt_size_t *size); |
| 313 | |
| 314 | /** |
Matthias Schiffer | 5e90d4e | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 315 | * dev_read_addr_size_name_ptr() - Get the reg property of a device as a pointer, |
| 316 | * indexed by name |
| 317 | * |
| 318 | * @dev: Device to read from |
| 319 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 320 | * 'reg-names' property providing named-based identification. @name |
| 321 | * indicates the value to search for in 'reg-names'. |
| 322 | * @size: place to put size value (on success) |
| 323 | * |
| 324 | * Return: pointer or NULL if not found |
| 325 | */ |
| 326 | void *dev_read_addr_size_name_ptr(const struct udevice *dev, const char *name, |
| 327 | fdt_size_t *size); |
| 328 | |
| 329 | /** |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 330 | * dev_remap_addr_name() - Get the reg property of a device, indexed by name, |
| 331 | * as a memory-mapped I/O pointer |
| 332 | * |
| 333 | * @dev: Device to read from |
| 334 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
Matthias Schiffer | 7c238d0 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 335 | * 'reg-names' property providing named-based identification. @name |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 336 | * indicates the value to search for in 'reg-names'. |
| 337 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 338 | * Return: pointer or NULL if not found |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 339 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 340 | 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] | 341 | |
| 342 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 343 | * dev_read_addr() - Get the reg property of a device |
| 344 | * |
| 345 | * @dev: Device to read from |
| 346 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 347 | * Return: address or FDT_ADDR_T_NONE if not found |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 348 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 349 | fdt_addr_t dev_read_addr(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 350 | |
| 351 | /** |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 352 | * dev_read_addr_ptr() - Get the reg property of a device |
| 353 | * as a pointer |
| 354 | * |
| 355 | * @dev: Device to read from |
| 356 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 357 | * Return: pointer or NULL if not found |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 358 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 359 | void *dev_read_addr_ptr(const struct udevice *dev); |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 360 | |
| 361 | /** |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 362 | * dev_read_addr_pci() - Read an address and handle PCI address translation |
| 363 | * |
| 364 | * At present U-Boot does not have address translation logic for PCI in the |
| 365 | * livetree implementation (of_addr.c). This special function supports this for |
| 366 | * the flat tree implementation. |
| 367 | * |
| 368 | * This function should be removed (and code should use dev_read() instead) |
| 369 | * once: |
| 370 | * |
| 371 | * 1. PCI address translation is added; and either |
| 372 | * 2. everything uses livetree where PCI translation is used (which is feasible |
| 373 | * in SPL and U-Boot proper) or PCI address translation is added to |
| 374 | * fdtdec_get_addr() and friends. |
| 375 | * |
| 376 | * @dev: Device to read from |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 377 | * @sizep: If non-NULL, returns size of address space found |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 378 | * Return: address or FDT_ADDR_T_NONE if not found |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 379 | */ |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 380 | fdt_addr_t dev_read_addr_pci(const struct udevice *dev, fdt_size_t *sizep); |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 381 | |
| 382 | /** |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 383 | * dev_remap_addr() - Get the reg property of a device as a |
| 384 | * memory-mapped I/O pointer |
| 385 | * |
| 386 | * @dev: Device to read from |
| 387 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 388 | * Return: pointer or NULL if not found |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 389 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 390 | void *dev_remap_addr(const struct udevice *dev); |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 391 | |
| 392 | /** |
John Keeping | ab62d0b | 2023-06-01 15:11:19 +0100 | [diff] [blame] | 393 | * dev_read_addr_size() - Get the reg property of a device |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 394 | * |
| 395 | * @dev: Device to read from |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 396 | * @sizep: place to put size value (on success) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 397 | * Return: address value, or FDT_ADDR_T_NONE on error |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 398 | */ |
John Keeping | ab62d0b | 2023-06-01 15:11:19 +0100 | [diff] [blame] | 399 | fdt_addr_t dev_read_addr_size(const struct udevice *dev, fdt_size_t *sizep); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 400 | |
| 401 | /** |
| 402 | * dev_read_name() - get the name of a device's node |
| 403 | * |
Bin Meng | 4cf914d | 2019-07-05 09:23:18 -0700 | [diff] [blame] | 404 | * @dev: Device to read from |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 405 | * Return: name of node |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 406 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 407 | const char *dev_read_name(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 408 | |
| 409 | /** |
| 410 | * dev_read_stringlist_search() - find string in a string list and return index |
| 411 | * |
| 412 | * Note that it is possible for this function to succeed on property values |
| 413 | * that are not NUL-terminated. That's because the function will stop after |
| 414 | * finding the first occurrence of @string. This can for example happen with |
| 415 | * small-valued cell properties, such as #address-cells, when searching for |
| 416 | * the empty string. |
| 417 | * |
| 418 | * @dev: device to check |
| 419 | * @propname: name of the property containing the string list |
| 420 | * @string: string to look up in the string list |
| 421 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 422 | * Return: |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 423 | * the index of the string in the list of strings |
| 424 | * -ENODATA if the property is not found |
| 425 | * -EINVAL on some other error |
| 426 | */ |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 427 | int dev_read_stringlist_search(const struct udevice *dev, const char *propname, |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 428 | const char *string); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 429 | |
| 430 | /** |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 431 | * dev_read_string_index() - obtain an indexed string from a string list |
| 432 | * |
| 433 | * @dev: device to examine |
| 434 | * @propname: name of the property containing the string list |
| 435 | * @index: index of the string to return |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 436 | * @outp: return location for the string |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 437 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 438 | * Return: |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 439 | * length of string, if found or -ve error value if not found |
| 440 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 441 | int dev_read_string_index(const struct udevice *dev, const char *propname, |
| 442 | int index, const char **outp); |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 443 | |
| 444 | /** |
| 445 | * dev_read_string_count() - find the number of strings in a string list |
| 446 | * |
| 447 | * @dev: device to examine |
| 448 | * @propname: name of the property containing the string list |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 449 | * Return: |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 450 | * number of strings in the list, or -ve error value if not found |
| 451 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 452 | int dev_read_string_count(const struct udevice *dev, const char *propname); |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 453 | |
| 454 | /** |
| 455 | * dev_read_string_list() - read a list of strings |
| 456 | * |
| 457 | * This produces a list of string pointers with each one pointing to a string |
| 458 | * in the string list. If the property does not exist, it returns {NULL}. |
| 459 | * |
| 460 | * The data is allocated and the caller is reponsible for freeing the return |
| 461 | * value (the list of string pointers). The strings themselves may not be |
| 462 | * changed as they point directly into the devicetree property. |
| 463 | * |
| 464 | * @dev: device to examine |
| 465 | * @propname: name of the property containing the string list |
| 466 | * @listp: returns an allocated, NULL-terminated list of strings if the return |
| 467 | * value is > 0, else is set to NULL |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 468 | * Return: |
| 469 | * number of strings in list, 0 if none, -ENOMEM if out of memory, |
| 470 | * -ENOENT if no such property |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 471 | */ |
| 472 | int dev_read_string_list(const struct udevice *dev, const char *propname, |
| 473 | const char ***listp); |
| 474 | |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 475 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 476 | * dev_read_phandle_with_args() - Find a node pointed by phandle in a list |
| 477 | * |
| 478 | * This function is useful to parse lists of phandles and their arguments. |
| 479 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 480 | * errno value. |
| 481 | * |
| 482 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 483 | * pointer. |
| 484 | * |
| 485 | * Example: |
| 486 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 487 | * .. code-block:: |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 488 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 489 | * phandle1: node1 { |
| 490 | * #list-cells = <2>; |
| 491 | * }; |
| 492 | * phandle2: node2 { |
| 493 | * #list-cells = <1>; |
| 494 | * }; |
| 495 | * node3 { |
| 496 | * list = <&phandle1 1 2 &phandle2 3>; |
| 497 | * }; |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 498 | * |
| 499 | * To get a device_node of the `node2' node you may call this: |
| 500 | * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args); |
| 501 | * |
| 502 | * @dev: device whose node containing a list |
| 503 | * @list_name: property name that contains a list |
| 504 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 505 | * @cell_count: Cell count to use if @cells_name is NULL |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 506 | * @index: index of a phandle to parse out |
| 507 | * @out_args: optional pointer to output arguments structure (will be filled) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 508 | * Return: 0 on success (with @out_args filled out if not NULL), -ENOENT if |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 509 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 510 | * @cells_name could not be found, the arguments were truncated or there |
| 511 | * were too many arguments. |
| 512 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 513 | int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, |
| 514 | const char *cells_name, int cell_count, |
| 515 | int index, struct ofnode_phandle_args *out_args); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 516 | |
| 517 | /** |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 518 | * dev_count_phandle_with_args() - Return phandle number in a list |
| 519 | * |
| 520 | * This function is usefull to get phandle number contained in a property list. |
| 521 | * For example, this allows to allocate the right amount of memory to keep |
| 522 | * clock's reference contained into the "clocks" property. |
| 523 | * |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 524 | * @dev: device whose node containing a list |
| 525 | * @list_name: property name that contains a list |
| 526 | * @cells_name: property name that specifies phandles' arguments count |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 527 | * @cell_count: Cell count to use if @cells_name is NULL |
| 528 | * Return: number of phandle found on success, on error returns appropriate |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 529 | * errno value. |
| 530 | */ |
| 531 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 532 | int dev_count_phandle_with_args(const struct udevice *dev, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 533 | const char *list_name, const char *cells_name, |
| 534 | int cell_count); |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 535 | |
| 536 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 537 | * dev_read_addr_cells() - Get the number of address cells for a device's node |
| 538 | * |
| 539 | * This walks back up the tree to find the closest #address-cells property |
| 540 | * which controls the given node. |
| 541 | * |
Mario Six | 16408ee | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 542 | * @dev: device to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 543 | * Return: number of address cells this node uses |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 544 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 545 | int dev_read_addr_cells(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * dev_read_size_cells() - Get the number of size cells for a device's node |
| 549 | * |
| 550 | * This walks back up the tree to find the closest #size-cells property |
| 551 | * which controls the given node. |
| 552 | * |
Mario Six | 16408ee | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 553 | * @dev: device to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 554 | * Return: number of size cells this node uses |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 555 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 556 | int dev_read_size_cells(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 557 | |
| 558 | /** |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 559 | * dev_read_addr_cells() - Get the address cells property in a node |
| 560 | * |
| 561 | * This function matches fdt_address_cells(). |
| 562 | * |
Mario Six | 16408ee | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 563 | * @dev: device to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 564 | * Return: number of address cells this node uses |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 565 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 566 | int dev_read_simple_addr_cells(const struct udevice *dev); |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 567 | |
| 568 | /** |
| 569 | * dev_read_size_cells() - Get the size cells property in a node |
| 570 | * |
| 571 | * This function matches fdt_size_cells(). |
| 572 | * |
Mario Six | 16408ee | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 573 | * @dev: device to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 574 | * Return: number of size cells this node uses |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 575 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 576 | int dev_read_simple_size_cells(const struct udevice *dev); |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 577 | |
| 578 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 579 | * dev_read_phandle() - Get the phandle from a device |
| 580 | * |
| 581 | * @dev: device to check |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 582 | * Return: phandle (1 or greater), or 0 if no phandle or other error |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 583 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 584 | int dev_read_phandle(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * dev_read_prop()- - read a property from a device's node |
| 588 | * |
| 589 | * @dev: device to check |
| 590 | * @propname: property to read |
| 591 | * @lenp: place to put length on success |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 592 | * Return: pointer to property, or NULL if not found |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 593 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 594 | const void *dev_read_prop(const struct udevice *dev, const char *propname, |
| 595 | int *lenp); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 596 | |
| 597 | /** |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 598 | * dev_read_first_prop()- get the reference of the first property |
| 599 | * |
| 600 | * Get reference to the first property of the node, it is used to iterate |
| 601 | * and read all the property with dev_read_prop_by_prop(). |
| 602 | * |
| 603 | * @dev: device to check |
| 604 | * @prop: place to put argument reference |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 605 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 606 | */ |
| 607 | int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop); |
| 608 | |
| 609 | /** |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 610 | * ofnode_next_property() - get the reference of the next property |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 611 | * |
| 612 | * Get reference to the next property of the node, it is used to iterate |
| 613 | * and read all the property with dev_read_prop_by_prop(). |
| 614 | * |
| 615 | * @prop: reference of current argument and place to put reference of next one |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 616 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 617 | */ |
| 618 | int dev_read_next_prop(struct ofprop *prop); |
| 619 | |
| 620 | /** |
| 621 | * dev_read_prop_by_prop() - get a pointer to the value of a property |
| 622 | * |
| 623 | * Get value for the property identified by the provided reference. |
| 624 | * |
| 625 | * @prop: reference on property |
| 626 | * @propname: If non-NULL, place to property name on success, |
| 627 | * @lenp: If non-NULL, place to put length on success |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 628 | * Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 629 | */ |
| 630 | const void *dev_read_prop_by_prop(struct ofprop *prop, |
| 631 | const char **propname, int *lenp); |
| 632 | |
| 633 | /** |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 634 | * dev_read_alias_seq() - Get the alias sequence number of a node |
| 635 | * |
| 636 | * This works out whether a node is pointed to by an alias, and if so, the |
| 637 | * sequence number of that alias. Aliases are of the form <base><num> where |
| 638 | * <num> is the sequence number. For example spi2 would be sequence number 2. |
| 639 | * |
| 640 | * @dev: device to look up |
| 641 | * @devnump: set to the sequence number if one is found |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 642 | * Return: 0 if a sequence was found, -ve if not |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 643 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 644 | int dev_read_alias_seq(const struct udevice *dev, int *devnump); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 645 | |
| 646 | /** |
| 647 | * dev_read_u32_array() - Find and read an array of 32 bit integers |
| 648 | * |
| 649 | * Search for a property in a device node and read 32-bit value(s) from |
| 650 | * it. |
| 651 | * |
| 652 | * The out_values is modified only if a valid u32 value can be decoded. |
| 653 | * |
| 654 | * @dev: device to look up |
| 655 | * @propname: name of the property to read |
| 656 | * @out_values: pointer to return value, modified only if return value is 0 |
| 657 | * @sz: number of array elements to read |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 658 | * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 659 | * property does not have a value, and -EOVERFLOW if the property data isn't |
| 660 | * large enough. |
| 661 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 662 | int dev_read_u32_array(const struct udevice *dev, const char *propname, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 663 | u32 *out_values, size_t sz); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 664 | |
| 665 | /** |
| 666 | * dev_read_first_subnode() - find the first subnode of a device's node |
| 667 | * |
| 668 | * @dev: device to look up |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 669 | * Return: reference to the first subnode (which can be invalid if the device's |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 670 | * node has no subnodes) |
| 671 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 672 | ofnode dev_read_first_subnode(const struct udevice *dev); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 673 | |
| 674 | /** |
| 675 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 676 | * |
| 677 | * @node: valid reference to previous node (sibling) |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 678 | * Return: reference to the next subnode (which can be invalid if the node |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 679 | * has no more siblings) |
| 680 | */ |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 681 | ofnode dev_read_next_subnode(ofnode node); |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 682 | |
| 683 | /** |
| 684 | * dev_read_u8_array_ptr() - find an 8-bit array |
| 685 | * |
| 686 | * Look up a device's node property and return a pointer to its contents as a |
| 687 | * byte array of given length. The property must have at least enough data |
| 688 | * for the array (count bytes). It may have more, but this will be ignored. |
| 689 | * The data is not copied. |
| 690 | * |
| 691 | * @dev: device to look up |
| 692 | * @propname: name of property to find |
| 693 | * @sz: number of array elements |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 694 | * Return: |
| 695 | * pointer to byte array if found, or NULL if the property is not found or |
| 696 | * there is not enough data |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 697 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 698 | const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, |
| 699 | const char *propname, size_t sz); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 700 | |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 701 | /** |
| 702 | * dev_read_enabled() - check whether a node is enabled |
| 703 | * |
| 704 | * This looks for a 'status' property. If this exists, then returns 1 if |
| 705 | * the status is 'ok' and 0 otherwise. If there is no status property, |
| 706 | * it returns 1 on the assumption that anything mentioned should be enabled |
| 707 | * by default. |
| 708 | * |
| 709 | * @dev: device to examine |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 710 | * Return: integer value 0 (not enabled) or 1 (enabled) |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 711 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 712 | int dev_read_enabled(const struct udevice *dev); |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 713 | |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 714 | /** |
| 715 | * dev_read_resource() - obtain an indexed resource from a device. |
| 716 | * |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 717 | * @dev: device to examine |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 718 | * @index: index of the resource to retrieve (0 = first) |
| 719 | * @res: returns the resource |
| 720 | * Return: 0 if ok, negative on error |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 721 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 722 | int dev_read_resource(const struct udevice *dev, uint index, |
| 723 | struct resource *res); |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 724 | |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 725 | /** |
| 726 | * dev_read_resource_byname() - obtain a named resource from a device. |
| 727 | * |
| 728 | * @dev: device to examine |
| 729 | * @name: name of the resource to retrieve |
| 730 | * @res: returns the resource |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 731 | * Return: 0 if ok, negative on error |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 732 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 733 | int dev_read_resource_byname(const struct udevice *dev, const char *name, |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 734 | struct resource *res); |
| 735 | |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 736 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 737 | * dev_translate_address() - Translate a device-tree address |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 738 | * |
| 739 | * Translate an address from the device-tree into a CPU physical address. This |
| 740 | * function walks up the tree and applies the various bus mappings along the |
| 741 | * way. |
| 742 | * |
| 743 | * @dev: device giving the context in which to translate the address |
| 744 | * @in_addr: pointer to the address to translate |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 745 | * Return: the translated address; OF_BAD_ADDR on error |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 746 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 747 | 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] | 748 | |
| 749 | /** |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 750 | * dev_translate_dma_address() - Translate a device-tree DMA address |
| 751 | * |
| 752 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 753 | * This function walks up the tree and applies the various bus mappings along |
| 754 | * the way. |
| 755 | * |
| 756 | * @dev: device giving the context in which to translate the DMA address |
| 757 | * @in_addr: pointer to the DMA address to translate |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 758 | * Return: the translated DMA address; OF_BAD_ADDR on error |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 759 | */ |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 760 | u64 dev_translate_dma_address(const struct udevice *dev, |
| 761 | const fdt32_t *in_addr); |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 762 | |
| 763 | /** |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 764 | * dev_get_dma_range() - Get a device's DMA constraints |
| 765 | * |
| 766 | * Provide the address bases and size of the linear mapping between the CPU and |
| 767 | * a device's BUS address space. |
| 768 | * |
| 769 | * @dev: device giving the context in which to translate the DMA address |
| 770 | * @cpu: base address for CPU's view of memory |
| 771 | * @bus: base address for BUS's view of memory |
| 772 | * @size: size of the address space |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 773 | * Return: 0 if ok, negative on error |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 774 | */ |
| 775 | int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu, |
| 776 | dma_addr_t *bus, u64 *size); |
| 777 | |
| 778 | /** |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 779 | * dev_read_alias_highest_id - Get highest alias id for the given stem |
| 780 | * @stem: Alias stem to be examined |
| 781 | * |
| 782 | * The function travels the lookup table to get the highest alias id for the |
| 783 | * given alias stem. |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 784 | * Return: alias ID, if found, else -1 |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 785 | */ |
| 786 | int dev_read_alias_highest_id(const char *stem); |
| 787 | |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 788 | /** |
| 789 | * dev_get_child_count() - get the child count of a device |
| 790 | * |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 791 | * @dev: device to use for interation (`struct udevice *`) |
| 792 | * Return: the count of child subnode |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 793 | */ |
| 794 | int dev_get_child_count(const struct udevice *dev); |
| 795 | |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 796 | /** |
| 797 | * dev_read_pci_bus_range - Read PCI bus-range resource |
| 798 | * |
| 799 | * Look at the bus range property of a device node and return the pci bus |
| 800 | * range for this node. |
| 801 | * |
| 802 | * @dev: device to examine |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 803 | * @res: returns the resource |
| 804 | * Return: 0 if ok, negative on error |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 805 | */ |
| 806 | int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res); |
| 807 | |
Dario Binacchi | 836cc9d | 2020-12-30 00:16:26 +0100 | [diff] [blame] | 808 | /** |
| 809 | * dev_decode_display_timing() - decode display timings |
| 810 | * |
| 811 | * Decode display timings from the supplied 'display-timings' node. |
| 812 | * See doc/device-tree-bindings/video/display-timing.txt for binding |
| 813 | * information. |
| 814 | * |
| 815 | * @dev: device to read DT display timings from. The node linked to the device |
| 816 | * contains a child node called 'display-timings' which in turn contains |
| 817 | * one or more display timing nodes. |
| 818 | * @index: index number to read (0=first timing subnode) |
| 819 | * @config: place to put timings |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 820 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
Dario Binacchi | 836cc9d | 2020-12-30 00:16:26 +0100 | [diff] [blame] | 821 | */ |
| 822 | int dev_decode_display_timing(const struct udevice *dev, int index, |
| 823 | struct display_timing *config); |
| 824 | |
Marek BehĂșn | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 825 | /** |
Nikhil M Jain | ff40706 | 2023-01-31 15:35:14 +0530 | [diff] [blame] | 826 | * dev_decode_panel_timing() - decode panel timings |
| 827 | * |
| 828 | * Decode display timings from the supplied 'panel-timings' node. |
| 829 | * |
| 830 | * @dev: device to read DT display timings from. The node linked to the device |
| 831 | * contains a child node called 'display-timings' which in turn contains |
| 832 | * one or more display timing nodes. |
| 833 | * @config: place to put timings |
| 834 | * Return: 0 if OK, -FDT_ERR_NOTFOUND if not found |
| 835 | */ |
| 836 | int dev_decode_panel_timing(const struct udevice *dev, |
| 837 | struct display_timing *config); |
| 838 | |
| 839 | /** |
Marek BehĂșn | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 840 | * dev_get_phy_node() - Get PHY node for a MAC (if not fixed-link) |
| 841 | * |
| 842 | * This function parses PHY handle from the Ethernet controller's ofnode |
| 843 | * (trying all possible PHY handle property names), and returns the PHY ofnode. |
| 844 | * |
| 845 | * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and |
| 846 | * if the result to that is true, this function should not be called. |
| 847 | * |
| 848 | * @dev: device representing the MAC |
| 849 | * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode |
| 850 | */ |
| 851 | ofnode dev_get_phy_node(const struct udevice *dev); |
| 852 | |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 853 | /** |
| 854 | * dev_read_phy_mode() - Read PHY connection type from a MAC |
| 855 | * |
| 856 | * This function parses the "phy-mode" / "phy-connection-type" property and |
| 857 | * returns the corresponding PHY interface type. |
| 858 | * |
| 859 | * @dev: device representing the MAC |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 860 | * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 861 | * error |
| 862 | */ |
| 863 | phy_interface_t dev_read_phy_mode(const struct udevice *dev); |
| 864 | |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 865 | #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 866 | #include <asm/global_data.h> |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 867 | |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 868 | static inline int dev_read_u8(const struct udevice *dev, |
| 869 | const char *propname, u8 *outp) |
| 870 | { |
| 871 | return ofnode_read_u8(dev_ofnode(dev), propname, outp); |
| 872 | } |
| 873 | |
| 874 | static inline int dev_read_u8_default(const struct udevice *dev, |
| 875 | const char *propname, u8 def) |
| 876 | { |
| 877 | return ofnode_read_u8_default(dev_ofnode(dev), propname, def); |
| 878 | } |
| 879 | |
| 880 | static inline int dev_read_u16(const struct udevice *dev, |
| 881 | const char *propname, u16 *outp) |
| 882 | { |
| 883 | return ofnode_read_u16(dev_ofnode(dev), propname, outp); |
| 884 | } |
| 885 | |
| 886 | static inline int dev_read_u16_default(const struct udevice *dev, |
| 887 | const char *propname, u16 def) |
| 888 | { |
| 889 | return ofnode_read_u16_default(dev_ofnode(dev), propname, def); |
| 890 | } |
| 891 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 892 | static inline int dev_read_u32(const struct udevice *dev, |
Masahiro Yamada | 71d115f | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 893 | const char *propname, u32 *outp) |
| 894 | { |
| 895 | return ofnode_read_u32(dev_ofnode(dev), propname, outp); |
| 896 | } |
| 897 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 898 | static inline int dev_read_u32_default(const struct udevice *dev, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 899 | const char *propname, int def) |
| 900 | { |
| 901 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 902 | } |
| 903 | |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 904 | static inline int dev_read_u32_index(struct udevice *dev, |
| 905 | const char *propname, int index, u32 *outp) |
| 906 | { |
| 907 | return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp); |
| 908 | } |
| 909 | |
| 910 | static inline u32 dev_read_u32_index_default(struct udevice *dev, |
| 911 | const char *propname, int index, |
| 912 | u32 def) |
| 913 | { |
| 914 | return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index, |
| 915 | def); |
| 916 | } |
| 917 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 918 | static inline int dev_read_s32(const struct udevice *dev, |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 919 | const char *propname, s32 *outp) |
| 920 | { |
| 921 | return ofnode_read_s32(dev_ofnode(dev), propname, outp); |
| 922 | } |
| 923 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 924 | static inline int dev_read_s32_default(const struct udevice *dev, |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 925 | const char *propname, int def) |
| 926 | { |
| 927 | return ofnode_read_s32_default(dev_ofnode(dev), propname, def); |
| 928 | } |
| 929 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 930 | static inline int dev_read_u32u(const struct udevice *dev, |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 931 | const char *propname, uint *outp) |
| 932 | { |
| 933 | u32 val; |
| 934 | int ret; |
| 935 | |
| 936 | ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); |
| 937 | if (ret) |
| 938 | return ret; |
| 939 | *outp = val; |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 944 | static inline int dev_read_u64(const struct udevice *dev, |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 945 | const char *propname, u64 *outp) |
| 946 | { |
| 947 | return ofnode_read_u64(dev_ofnode(dev), propname, outp); |
| 948 | } |
| 949 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 950 | static inline u64 dev_read_u64_default(const struct udevice *dev, |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 951 | const char *propname, u64 def) |
| 952 | { |
| 953 | return ofnode_read_u64_default(dev_ofnode(dev), propname, def); |
| 954 | } |
| 955 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 956 | static inline const char *dev_read_string(const struct udevice *dev, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 957 | const char *propname) |
| 958 | { |
| 959 | return ofnode_read_string(dev_ofnode(dev), propname); |
| 960 | } |
| 961 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 962 | static inline bool dev_read_bool(const struct udevice *dev, |
| 963 | const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 964 | { |
| 965 | return ofnode_read_bool(dev_ofnode(dev), propname); |
| 966 | } |
| 967 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 968 | static inline ofnode dev_read_subnode(const struct udevice *dev, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 969 | const char *subbnode_name) |
| 970 | { |
| 971 | return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); |
| 972 | } |
| 973 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 974 | 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] | 975 | { |
| 976 | return ofnode_read_size(dev_ofnode(dev), propname); |
| 977 | } |
| 978 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 979 | static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev, |
| 980 | int index) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 981 | { |
| 982 | return devfdt_get_addr_index(dev, index); |
| 983 | } |
| 984 | |
Bin Meng | 21cdfea | 2021-09-12 11:15:13 +0800 | [diff] [blame] | 985 | static inline void *dev_read_addr_index_ptr(const struct udevice *dev, |
| 986 | int index) |
| 987 | { |
| 988 | return devfdt_get_addr_index_ptr(dev, index); |
| 989 | } |
| 990 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 991 | 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] | 992 | int index, |
| 993 | fdt_size_t *size) |
| 994 | { |
| 995 | return devfdt_get_addr_size_index(dev, index, size); |
| 996 | } |
| 997 | |
Jonas Karlman | 3b00730 | 2023-07-22 13:30:15 +0000 | [diff] [blame] | 998 | static inline void *dev_read_addr_size_index_ptr(const struct udevice *dev, |
| 999 | int index, |
| 1000 | fdt_size_t *size) |
| 1001 | { |
| 1002 | return devfdt_get_addr_size_index_ptr(dev, index, size); |
| 1003 | } |
| 1004 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1005 | 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] | 1006 | const char *name) |
| 1007 | { |
| 1008 | return devfdt_get_addr_name(dev, name); |
| 1009 | } |
| 1010 | |
Matthias Schiffer | 5e90d4e | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 1011 | static inline void *dev_read_addr_name_ptr(const struct udevice *dev, |
| 1012 | const char *name) |
| 1013 | { |
| 1014 | return devfdt_get_addr_name_ptr(dev, name); |
| 1015 | } |
| 1016 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1017 | 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] | 1018 | const char *name, |
| 1019 | fdt_size_t *size) |
| 1020 | { |
| 1021 | return devfdt_get_addr_size_name(dev, name, size); |
| 1022 | } |
| 1023 | |
Matthias Schiffer | 5e90d4e | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 1024 | static inline void *dev_read_addr_size_name_ptr(const struct udevice *dev, |
| 1025 | const char *name, |
| 1026 | fdt_size_t *size) |
| 1027 | { |
| 1028 | return devfdt_get_addr_size_name_ptr(dev, name, size); |
| 1029 | } |
| 1030 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1031 | static inline fdt_addr_t dev_read_addr(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1032 | { |
| 1033 | return devfdt_get_addr(dev); |
| 1034 | } |
| 1035 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1036 | static inline void *dev_read_addr_ptr(const struct udevice *dev) |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 1037 | { |
Ovidiu Panait | a633f00 | 2020-08-03 22:17:35 +0300 | [diff] [blame] | 1038 | return devfdt_get_addr_ptr(dev); |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 1041 | static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev, |
| 1042 | fdt_size_t *sizep) |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 1043 | { |
Simon Glass | 4289c26 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 1044 | return devfdt_get_addr_pci(dev, sizep); |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 1045 | } |
| 1046 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1047 | static inline void *dev_remap_addr(const struct udevice *dev) |
Ălvaro FernĂĄndez Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 1048 | { |
| 1049 | return devfdt_remap_addr(dev); |
| 1050 | } |
| 1051 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1052 | 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] | 1053 | { |
| 1054 | return devfdt_remap_addr_index(dev, index); |
| 1055 | } |
| 1056 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1057 | static inline void *dev_remap_addr_name(const struct udevice *dev, |
| 1058 | const char *name) |
Ălvaro FernĂĄndez Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 1059 | { |
| 1060 | return devfdt_remap_addr_name(dev, name); |
| 1061 | } |
| 1062 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1063 | 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] | 1064 | fdt_size_t *sizep) |
| 1065 | { |
John Keeping | ab62d0b | 2023-06-01 15:11:19 +0100 | [diff] [blame] | 1066 | return dev_read_addr_size_index(dev, 0, sizep); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1067 | } |
| 1068 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1069 | static inline const char *dev_read_name(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1070 | { |
| 1071 | return ofnode_get_name(dev_ofnode(dev)); |
| 1072 | } |
| 1073 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1074 | static inline int dev_read_stringlist_search(const struct udevice *dev, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1075 | const char *propname, |
| 1076 | const char *string) |
| 1077 | { |
| 1078 | return ofnode_stringlist_search(dev_ofnode(dev), propname, string); |
| 1079 | } |
| 1080 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1081 | static inline int dev_read_string_index(const struct udevice *dev, |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 1082 | const char *propname, int index, |
| 1083 | const char **outp) |
| 1084 | { |
| 1085 | return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); |
| 1086 | } |
| 1087 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1088 | static inline int dev_read_string_count(const struct udevice *dev, |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 1089 | const char *propname) |
| 1090 | { |
| 1091 | return ofnode_read_string_count(dev_ofnode(dev), propname); |
| 1092 | } |
| 1093 | |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 1094 | static inline int dev_read_string_list(const struct udevice *dev, |
| 1095 | const char *propname, |
| 1096 | const char ***listp) |
| 1097 | { |
| 1098 | return ofnode_read_string_list(dev_ofnode(dev), propname, listp); |
| 1099 | } |
| 1100 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1101 | static inline int dev_read_phandle_with_args(const struct udevice *dev, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1102 | const char *list_name, const char *cells_name, int cell_count, |
| 1103 | int index, struct ofnode_phandle_args *out_args) |
| 1104 | { |
| 1105 | return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, |
| 1106 | cells_name, cell_count, index, |
| 1107 | out_args); |
| 1108 | } |
| 1109 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1110 | static inline int dev_count_phandle_with_args(const struct udevice *dev, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 1111 | const char *list_name, const char *cells_name, int cell_count) |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 1112 | { |
| 1113 | return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 1114 | cells_name, cell_count); |
Patrice Chotard | be7dd60 | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1117 | static inline int dev_read_addr_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1118 | { |
Heinrich Schuchardt | 60a84af | 2020-07-25 21:38:49 +0200 | [diff] [blame] | 1119 | int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev)); |
| 1120 | |
| 1121 | return fdt_address_cells(gd->fdt_blob, parent); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1122 | } |
| 1123 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1124 | static inline int dev_read_size_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1125 | { |
Heinrich Schuchardt | 60a84af | 2020-07-25 21:38:49 +0200 | [diff] [blame] | 1126 | int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev)); |
| 1127 | |
| 1128 | return fdt_size_cells(gd->fdt_blob, parent); |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 1129 | } |
| 1130 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1131 | static inline int dev_read_simple_addr_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 1132 | { |
| 1133 | return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 1134 | } |
| 1135 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1136 | static inline int dev_read_simple_size_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 1137 | { |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1138 | return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 1139 | } |
| 1140 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1141 | static inline int dev_read_phandle(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1142 | { |
| 1143 | return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); |
| 1144 | } |
| 1145 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1146 | static inline const void *dev_read_prop(const struct udevice *dev, |
Masahiro Yamada | baebec1 | 2017-07-17 12:18:39 +0900 | [diff] [blame] | 1147 | const char *propname, int *lenp) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1148 | { |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 1149 | return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1152 | static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop) |
| 1153 | { |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1154 | return ofnode_first_property(dev_ofnode(dev), prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static inline int dev_read_next_prop(struct ofprop *prop) |
| 1158 | { |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 1159 | return ofnode_next_property(prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static inline const void *dev_read_prop_by_prop(struct ofprop *prop, |
| 1163 | const char **propname, |
| 1164 | int *lenp) |
| 1165 | { |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 1166 | return ofprop_get_property(prop, propname, lenp); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1169 | 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] | 1170 | { |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 1171 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1172 | return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, |
| 1173 | dev_of_offset(dev), devnump); |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 1174 | #else |
| 1175 | return -ENOTSUPP; |
| 1176 | #endif |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1177 | } |
| 1178 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1179 | static inline int dev_read_u32_array(const struct udevice *dev, |
| 1180 | const char *propname, u32 *out_values, |
| 1181 | size_t sz) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1182 | { |
| 1183 | return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); |
| 1184 | } |
| 1185 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1186 | static inline ofnode dev_read_first_subnode(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 1187 | { |
| 1188 | return ofnode_first_subnode(dev_ofnode(dev)); |
| 1189 | } |
| 1190 | |
| 1191 | static inline ofnode dev_read_next_subnode(ofnode node) |
| 1192 | { |
| 1193 | return ofnode_next_subnode(node); |
| 1194 | } |
| 1195 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1196 | 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] | 1197 | const char *propname, |
| 1198 | size_t sz) |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 1199 | { |
| 1200 | return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); |
| 1201 | } |
| 1202 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1203 | static inline int dev_read_enabled(const struct udevice *dev) |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 1204 | { |
| 1205 | return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); |
| 1206 | } |
| 1207 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1208 | static inline int dev_read_resource(const struct udevice *dev, uint index, |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 1209 | struct resource *res) |
| 1210 | { |
| 1211 | return ofnode_read_resource(dev_ofnode(dev), index, res); |
| 1212 | } |
| 1213 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1214 | static inline int dev_read_resource_byname(const struct udevice *dev, |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 1215 | const char *name, |
| 1216 | struct resource *res) |
| 1217 | { |
| 1218 | return ofnode_read_resource_byname(dev_ofnode(dev), name, res); |
| 1219 | } |
| 1220 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1221 | static inline u64 dev_translate_address(const struct udevice *dev, |
| 1222 | const fdt32_t *in_addr) |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 1223 | { |
| 1224 | return ofnode_translate_address(dev_ofnode(dev), in_addr); |
| 1225 | } |
| 1226 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 1227 | static inline u64 dev_translate_dma_address(const struct udevice *dev, |
| 1228 | const fdt32_t *in_addr) |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 1229 | { |
| 1230 | return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); |
| 1231 | } |
| 1232 | |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 1233 | static inline int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu, |
| 1234 | dma_addr_t *bus, u64 *size) |
| 1235 | { |
| 1236 | return ofnode_get_dma_range(dev_ofnode(dev), cpu, bus, size); |
| 1237 | } |
| 1238 | |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 1239 | static inline int dev_read_alias_highest_id(const char *stem) |
| 1240 | { |
Stanislav Pinchuk | e864940 | 2021-01-20 21:52:23 +0300 | [diff] [blame] | 1241 | if (!CONFIG_IS_ENABLED(OF_LIBFDT) || !gd->fdt_blob) |
Michael Walle | eccf2d0 | 2020-06-02 01:47:08 +0200 | [diff] [blame] | 1242 | return -1; |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 1243 | return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); |
| 1244 | } |
| 1245 | |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 1246 | static inline int dev_get_child_count(const struct udevice *dev) |
| 1247 | { |
| 1248 | return ofnode_get_child_count(dev_ofnode(dev)); |
| 1249 | } |
| 1250 | |
Dario Binacchi | 836cc9d | 2020-12-30 00:16:26 +0100 | [diff] [blame] | 1251 | static inline int dev_decode_display_timing(const struct udevice *dev, |
| 1252 | int index, |
| 1253 | struct display_timing *config) |
| 1254 | { |
| 1255 | return ofnode_decode_display_timing(dev_ofnode(dev), index, config); |
| 1256 | } |
| 1257 | |
Nikhil M Jain | ff40706 | 2023-01-31 15:35:14 +0530 | [diff] [blame] | 1258 | static inline int dev_decode_panel_timing(const struct udevice *dev, |
| 1259 | struct display_timing *config) |
| 1260 | { |
| 1261 | return ofnode_decode_panel_timing(dev_ofnode(dev), config); |
| 1262 | } |
| 1263 | |
Marek BehĂșn | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 1264 | static inline ofnode dev_get_phy_node(const struct udevice *dev) |
| 1265 | { |
| 1266 | return ofnode_get_phy_node(dev_ofnode(dev)); |
| 1267 | } |
| 1268 | |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1269 | static inline phy_interface_t dev_read_phy_mode(const struct udevice *dev) |
| 1270 | { |
| 1271 | return ofnode_read_phy_mode(dev_ofnode(dev)); |
| 1272 | } |
| 1273 | |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 1274 | #endif /* CONFIG_DM_DEV_READ_INLINE */ |
| 1275 | |
| 1276 | /** |
| 1277 | * dev_for_each_subnode() - Helper function to iterate through subnodes |
| 1278 | * |
| 1279 | * This creates a for() loop which works through the subnodes in a device's |
| 1280 | * device-tree node. |
| 1281 | * |
| 1282 | * @subnode: ofnode holding the current subnode |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 1283 | * @dev: device to use for interation (`struct udevice *`) |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 1284 | */ |
| 1285 | #define dev_for_each_subnode(subnode, dev) \ |
| 1286 | for (subnode = dev_read_first_subnode(dev); \ |
| 1287 | ofnode_valid(subnode); \ |
| 1288 | subnode = ofnode_next_subnode(subnode)) |
| 1289 | |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1290 | /** |
| 1291 | * dev_for_each_property() - Helper function to iterate through property |
| 1292 | * |
| 1293 | * This creates a for() loop which works through the property in a device's |
| 1294 | * device-tree node. |
| 1295 | * |
| 1296 | * @prop: struct ofprop holding the current property |
Patrick Delaunay | cb3d6d6 | 2022-01-12 10:53:48 +0100 | [diff] [blame] | 1297 | * @dev: device to use for interation (`struct udevice *`) |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 1298 | */ |
| 1299 | #define dev_for_each_property(prop, dev) \ |
| 1300 | for (int ret_prop = dev_read_first_prop(dev, &prop); \ |
| 1301 | !ret_prop; \ |
| 1302 | ret_prop = dev_read_next_prop(&prop)) |
| 1303 | |
Simon Glass | 34ef0c2 | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 1304 | #endif |