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