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