Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <dm/of_access.h> |
Stefan Roese | a8c4306 | 2020-04-29 09:08:44 +0200 | [diff] [blame] | 10 | #include <mapmem.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Stefan Roese | a8c4306 | 2020-04-29 09:08:44 +0200 | [diff] [blame] | 12 | #include <asm/types.h> |
| 13 | #include <asm/io.h> |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 14 | #include <linux/ioport.h> |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 15 | |
Stefan Herbrechtsmeier | 1b090e6 | 2022-06-14 15:21:30 +0200 | [diff] [blame] | 16 | int dev_read_u8(const struct udevice *dev, const char *propname, u8 *outp) |
| 17 | { |
| 18 | return ofnode_read_u8(dev_ofnode(dev), propname, outp); |
| 19 | } |
| 20 | |
| 21 | u8 dev_read_u8_default(const struct udevice *dev, const char *propname, u8 def) |
| 22 | { |
| 23 | return ofnode_read_u8_default(dev_ofnode(dev), propname, def); |
| 24 | } |
| 25 | |
| 26 | int dev_read_u16(const struct udevice *dev, const char *propname, u16 *outp) |
| 27 | { |
| 28 | return ofnode_read_u16(dev_ofnode(dev), propname, outp); |
| 29 | } |
| 30 | |
| 31 | u16 dev_read_u16_default(const struct udevice *dev, const char *propname, |
| 32 | u16 def) |
| 33 | { |
| 34 | return ofnode_read_u16_default(dev_ofnode(dev), propname, def); |
| 35 | } |
| 36 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 37 | int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) |
Masahiro Yamada | 71d115f | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 38 | { |
| 39 | return ofnode_read_u32(dev_ofnode(dev), propname, outp); |
| 40 | } |
| 41 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 42 | int dev_read_u32_default(const struct udevice *dev, const char *propname, |
| 43 | int def) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 44 | { |
| 45 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 46 | } |
| 47 | |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 48 | int dev_read_u32_index(struct udevice *dev, const char *propname, int index, |
| 49 | u32 *outp) |
| 50 | { |
| 51 | return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp); |
| 52 | } |
| 53 | |
| 54 | u32 dev_read_u32_index_default(struct udevice *dev, const char *propname, |
| 55 | int index, u32 def) |
| 56 | { |
| 57 | return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index, |
| 58 | def); |
| 59 | } |
| 60 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 61 | int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 62 | { |
| 63 | return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); |
| 64 | } |
| 65 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 66 | int dev_read_s32_default(const struct udevice *dev, const char *propname, |
| 67 | int def) |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 68 | { |
| 69 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 70 | } |
| 71 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 72 | int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 73 | { |
| 74 | u32 val; |
| 75 | int ret; |
| 76 | |
| 77 | ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); |
| 78 | if (ret) |
| 79 | return ret; |
| 80 | *outp = val; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 85 | int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 86 | { |
| 87 | return ofnode_read_u64(dev_ofnode(dev), propname, outp); |
| 88 | } |
| 89 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 90 | u64 dev_read_u64_default(const struct udevice *dev, const char *propname, |
| 91 | u64 def) |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 92 | { |
| 93 | return ofnode_read_u64_default(dev_ofnode(dev), propname, def); |
| 94 | } |
| 95 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 96 | const char *dev_read_string(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 97 | { |
| 98 | return ofnode_read_string(dev_ofnode(dev), propname); |
| 99 | } |
| 100 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 101 | bool dev_read_bool(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 102 | { |
| 103 | return ofnode_read_bool(dev_ofnode(dev), propname); |
| 104 | } |
| 105 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 106 | ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 107 | { |
| 108 | return ofnode_find_subnode(dev_ofnode(dev), subnode_name); |
| 109 | } |
| 110 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 111 | ofnode dev_read_first_subnode(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 112 | { |
| 113 | return ofnode_first_subnode(dev_ofnode(dev)); |
| 114 | } |
| 115 | |
| 116 | ofnode dev_read_next_subnode(ofnode node) |
| 117 | { |
| 118 | return ofnode_next_subnode(node); |
| 119 | } |
| 120 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 121 | int dev_read_size(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 122 | { |
| 123 | return ofnode_read_size(dev_ofnode(dev), propname); |
| 124 | } |
| 125 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 126 | fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 127 | { |
| 128 | if (ofnode_is_np(dev_ofnode(dev))) |
| 129 | return ofnode_get_addr_index(dev_ofnode(dev), index); |
| 130 | else |
| 131 | return devfdt_get_addr_index(dev, index); |
| 132 | } |
| 133 | |
Johan Jonker | 54ab044 | 2023-03-13 01:31:25 +0100 | [diff] [blame] | 134 | void *dev_read_addr_index_ptr(const struct udevice *dev, int index) |
| 135 | { |
| 136 | fdt_addr_t addr = dev_read_addr_index(dev, index); |
| 137 | |
| 138 | if (addr == FDT_ADDR_T_NONE) |
| 139 | return NULL; |
| 140 | |
| 141 | return map_sysmem(addr, 0); |
| 142 | } |
| 143 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 144 | fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 145 | fdt_size_t *size) |
| 146 | { |
| 147 | if (ofnode_is_np(dev_ofnode(dev))) |
| 148 | return ofnode_get_addr_size_index(dev_ofnode(dev), index, size); |
| 149 | else |
| 150 | return devfdt_get_addr_size_index(dev, index, size); |
| 151 | } |
| 152 | |
Jonas Karlman | 3b00730 | 2023-07-22 13:30:15 +0000 | [diff] [blame] | 153 | void *dev_read_addr_size_index_ptr(const struct udevice *dev, int index, |
| 154 | fdt_size_t *size) |
| 155 | { |
| 156 | fdt_addr_t addr = dev_read_addr_size_index(dev, index, size); |
| 157 | |
| 158 | if (addr == FDT_ADDR_T_NONE) |
| 159 | return NULL; |
| 160 | |
| 161 | return map_sysmem(addr, 0); |
| 162 | } |
| 163 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 164 | void *dev_remap_addr_index(const struct udevice *dev, int index) |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 165 | { |
| 166 | fdt_addr_t addr = dev_read_addr_index(dev, index); |
| 167 | |
| 168 | if (addr == FDT_ADDR_T_NONE) |
| 169 | return NULL; |
| 170 | |
| 171 | return map_physmem(addr, 0, MAP_NOCACHE); |
| 172 | } |
| 173 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 174 | fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 175 | { |
| 176 | int index = dev_read_stringlist_search(dev, "reg-names", name); |
| 177 | |
| 178 | if (index < 0) |
| 179 | return FDT_ADDR_T_NONE; |
| 180 | else |
| 181 | return dev_read_addr_index(dev, index); |
| 182 | } |
| 183 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 184 | fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, |
Sekhar Nori | f677c6f | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 185 | fdt_size_t *size) |
| 186 | { |
| 187 | int index = dev_read_stringlist_search(dev, "reg-names", name); |
| 188 | |
| 189 | if (index < 0) |
| 190 | return FDT_ADDR_T_NONE; |
| 191 | else |
| 192 | return dev_read_addr_size_index(dev, index, size); |
| 193 | } |
| 194 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 195 | void *dev_remap_addr_name(const struct udevice *dev, const char *name) |
Álvaro Fernández Rojas | a318115 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 196 | { |
| 197 | fdt_addr_t addr = dev_read_addr_name(dev, name); |
| 198 | |
| 199 | if (addr == FDT_ADDR_T_NONE) |
| 200 | return NULL; |
| 201 | |
| 202 | return map_physmem(addr, 0, MAP_NOCACHE); |
| 203 | } |
| 204 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 205 | fdt_addr_t dev_read_addr(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 206 | { |
| 207 | return dev_read_addr_index(dev, 0); |
| 208 | } |
| 209 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 210 | void *dev_read_addr_ptr(const struct udevice *dev) |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 211 | { |
| 212 | fdt_addr_t addr = dev_read_addr(dev); |
| 213 | |
Johan Jonker | 54ab044 | 2023-03-13 01:31:25 +0100 | [diff] [blame] | 214 | if (addr == FDT_ADDR_T_NONE) |
| 215 | return NULL; |
| 216 | |
| 217 | return map_sysmem(addr, 0); |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 220 | void *dev_remap_addr(const struct udevice *dev) |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 221 | { |
| 222 | return dev_remap_addr_index(dev, 0); |
| 223 | } |
| 224 | |
John Keeping | ab62d0b | 2023-06-01 15:11:19 +0100 | [diff] [blame] | 225 | fdt_addr_t dev_read_addr_size(const struct udevice *dev, fdt_size_t *sizep) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 226 | { |
John Keeping | ab62d0b | 2023-06-01 15:11:19 +0100 | [diff] [blame] | 227 | return dev_read_addr_size_index(dev, 0, sizep); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 228 | } |
| 229 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 230 | const char *dev_read_name(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 231 | { |
| 232 | return ofnode_get_name(dev_ofnode(dev)); |
| 233 | } |
| 234 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 235 | int dev_read_stringlist_search(const struct udevice *dev, const char *property, |
Mario Six | 6eac222 | 2018-01-15 11:07:18 +0100 | [diff] [blame] | 236 | const char *string) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 237 | { |
| 238 | return ofnode_stringlist_search(dev_ofnode(dev), property, string); |
| 239 | } |
| 240 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 241 | int dev_read_string_index(const struct udevice *dev, const char *propname, |
| 242 | int index, const char **outp) |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 243 | { |
| 244 | return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); |
| 245 | } |
| 246 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 247 | int dev_read_string_count(const struct udevice *dev, const char *propname) |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 248 | { |
| 249 | return ofnode_read_string_count(dev_ofnode(dev), propname); |
| 250 | } |
| 251 | |
Simon Glass | 9580bfc | 2021-10-23 17:26:07 -0600 | [diff] [blame] | 252 | int dev_read_string_list(const struct udevice *dev, const char *propname, |
| 253 | const char ***listp) |
| 254 | { |
| 255 | return ofnode_read_string_list(dev_ofnode(dev), propname, listp); |
| 256 | } |
| 257 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 258 | int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, |
Mario Six | 6eac222 | 2018-01-15 11:07:18 +0100 | [diff] [blame] | 259 | const char *cells_name, int cell_count, |
| 260 | int index, struct ofnode_phandle_args *out_args) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 261 | { |
| 262 | return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, |
| 263 | cells_name, cell_count, index, |
| 264 | out_args); |
| 265 | } |
| 266 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 267 | int dev_count_phandle_with_args(const struct udevice *dev, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 268 | const char *list_name, const char *cells_name, |
| 269 | int cell_count) |
Patrice Chotard | 99503c1 | 2017-11-29 09:06:10 +0100 | [diff] [blame] | 270 | { |
| 271 | return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 272 | cells_name, cell_count); |
Patrice Chotard | 99503c1 | 2017-11-29 09:06:10 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 275 | int dev_read_addr_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 276 | { |
| 277 | return ofnode_read_addr_cells(dev_ofnode(dev)); |
| 278 | } |
| 279 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 280 | int dev_read_size_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 281 | { |
| 282 | return ofnode_read_size_cells(dev_ofnode(dev)); |
| 283 | } |
| 284 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 285 | int dev_read_simple_addr_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 286 | { |
| 287 | return ofnode_read_simple_addr_cells(dev_ofnode(dev)); |
| 288 | } |
| 289 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 290 | int dev_read_simple_size_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 291 | { |
| 292 | return ofnode_read_simple_size_cells(dev_ofnode(dev)); |
| 293 | } |
| 294 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 295 | int dev_read_phandle(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 296 | { |
| 297 | ofnode node = dev_ofnode(dev); |
| 298 | |
| 299 | if (ofnode_is_np(node)) |
| 300 | return ofnode_to_np(node)->phandle; |
| 301 | else |
| 302 | return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); |
| 303 | } |
| 304 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 305 | const void *dev_read_prop(const struct udevice *dev, const char *propname, |
| 306 | int *lenp) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 307 | { |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 308 | return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 309 | } |
| 310 | |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 311 | int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop) |
| 312 | { |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 313 | return ofnode_first_property(dev_ofnode(dev), prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | int dev_read_next_prop(struct ofprop *prop) |
| 317 | { |
Simon Glass | fec058d | 2022-09-06 20:27:13 -0600 | [diff] [blame] | 318 | return ofnode_next_property(prop); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | const void *dev_read_prop_by_prop(struct ofprop *prop, |
| 322 | const char **propname, int *lenp) |
| 323 | { |
Simon Glass | d0aff8b | 2022-09-06 20:27:14 -0600 | [diff] [blame] | 324 | return ofprop_get_property(prop, propname, lenp); |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 327 | int dev_read_alias_seq(const struct udevice *dev, int *devnump) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 328 | { |
| 329 | ofnode node = dev_ofnode(dev); |
| 330 | const char *uc_name = dev->uclass->uc_drv->name; |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 331 | int ret = -ENOTSUPP; |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 332 | |
| 333 | if (ofnode_is_np(node)) { |
| 334 | ret = of_alias_get_id(ofnode_to_np(node), uc_name); |
Simon Glass | a2b5855 | 2020-12-16 21:20:12 -0700 | [diff] [blame] | 335 | if (ret >= 0) { |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 336 | *devnump = ret; |
Simon Glass | a2b5855 | 2020-12-16 21:20:12 -0700 | [diff] [blame] | 337 | ret = 0; |
| 338 | } |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 339 | } else { |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 340 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 341 | ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name, |
| 342 | ofnode_to_offset(node), devnump); |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 343 | #endif |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | return ret; |
| 347 | } |
| 348 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 349 | int dev_read_u32_array(const struct udevice *dev, const char *propname, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 350 | u32 *out_values, size_t sz) |
| 351 | { |
| 352 | return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); |
| 353 | } |
| 354 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 355 | const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, |
| 356 | const char *propname, size_t sz) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 357 | { |
| 358 | return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); |
| 359 | } |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 360 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 361 | int dev_read_enabled(const struct udevice *dev) |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 362 | { |
| 363 | ofnode node = dev_ofnode(dev); |
| 364 | |
| 365 | if (ofnode_is_np(node)) |
| 366 | return of_device_is_available(ofnode_to_np(node)); |
| 367 | else |
| 368 | return fdtdec_get_is_enabled(gd->fdt_blob, |
| 369 | ofnode_to_offset(node)); |
| 370 | } |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 371 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 372 | int dev_read_resource(const struct udevice *dev, uint index, |
| 373 | struct resource *res) |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 374 | { |
| 375 | return ofnode_read_resource(dev_ofnode(dev), index, res); |
| 376 | } |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 377 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 378 | int dev_read_resource_byname(const struct udevice *dev, const char *name, |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 379 | struct resource *res) |
| 380 | { |
| 381 | return ofnode_read_resource_byname(dev_ofnode(dev), name, res); |
| 382 | } |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 383 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 384 | u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr) |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 385 | { |
| 386 | return ofnode_translate_address(dev_ofnode(dev), in_addr); |
| 387 | } |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 388 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 389 | u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr) |
Fabien Dessenne | 22236e0 | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 390 | { |
| 391 | return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); |
| 392 | } |
| 393 | |
Nicolas Saenz Julienne | 50d2fa4 | 2021-01-12 13:55:22 +0100 | [diff] [blame] | 394 | int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu, |
| 395 | dma_addr_t *bus, u64 *size) |
| 396 | { |
| 397 | return ofnode_get_dma_range(dev_ofnode(dev), cpu, bus, size); |
| 398 | } |
| 399 | |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 400 | int dev_read_alias_highest_id(const char *stem) |
| 401 | { |
| 402 | if (of_live_active()) |
| 403 | return of_alias_get_highest_id(stem); |
| 404 | |
| 405 | return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); |
| 406 | } |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 407 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 408 | fdt_addr_t dev_read_addr_pci(const struct udevice *dev) |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 409 | { |
| 410 | ulong addr; |
| 411 | |
| 412 | addr = dev_read_addr(dev); |
| 413 | if (addr == FDT_ADDR_T_NONE && !of_live_active()) |
| 414 | addr = devfdt_get_addr_pci(dev); |
| 415 | |
| 416 | return addr; |
| 417 | } |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 418 | |
| 419 | int dev_get_child_count(const struct udevice *dev) |
| 420 | { |
| 421 | return ofnode_get_child_count(dev_ofnode(dev)); |
| 422 | } |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 423 | |
| 424 | int dev_read_pci_bus_range(const struct udevice *dev, |
| 425 | struct resource *res) |
| 426 | { |
| 427 | const u32 *values; |
| 428 | int len; |
| 429 | |
| 430 | values = dev_read_prop(dev, "bus-range", &len); |
| 431 | if (!values || len < sizeof(*values) * 2) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | res->start = *values++; |
| 435 | res->end = *values; |
| 436 | |
| 437 | return 0; |
| 438 | } |
Dario Binacchi | 836cc9d | 2020-12-30 00:16:26 +0100 | [diff] [blame] | 439 | |
| 440 | int dev_decode_display_timing(const struct udevice *dev, int index, |
| 441 | struct display_timing *config) |
| 442 | { |
| 443 | return ofnode_decode_display_timing(dev_ofnode(dev), index, config); |
| 444 | } |
Marek Behún | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 445 | |
Nikhil M Jain | ff40706 | 2023-01-31 15:35:14 +0530 | [diff] [blame] | 446 | int dev_decode_panel_timing(const struct udevice *dev, |
| 447 | struct display_timing *config) |
| 448 | { |
| 449 | return ofnode_decode_panel_timing(dev_ofnode(dev), config); |
| 450 | } |
| 451 | |
Marek Behún | f4f1ddc | 2022-04-07 00:32:57 +0200 | [diff] [blame] | 452 | ofnode dev_get_phy_node(const struct udevice *dev) |
| 453 | { |
| 454 | return ofnode_get_phy_node(dev_ofnode(dev)); |
| 455 | } |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 456 | |
| 457 | phy_interface_t dev_read_phy_mode(const struct udevice *dev) |
| 458 | { |
| 459 | return ofnode_read_phy_mode(dev_ofnode(dev)); |
| 460 | } |