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