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> |
| 11 | #include <asm/types.h> |
| 12 | #include <asm/io.h> |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 13 | #include <linux/ioport.h> |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 14 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 15 | 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] | 16 | { |
| 17 | return ofnode_read_u32(dev_ofnode(dev), propname, outp); |
| 18 | } |
| 19 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 20 | int dev_read_u32_default(const struct udevice *dev, const char *propname, |
| 21 | int def) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 22 | { |
| 23 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 24 | } |
| 25 | |
Dario Binacchi | 81d80b5 | 2020-03-29 18:04:41 +0200 | [diff] [blame] | 26 | int dev_read_u32_index(struct udevice *dev, const char *propname, int index, |
| 27 | u32 *outp) |
| 28 | { |
| 29 | return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp); |
| 30 | } |
| 31 | |
| 32 | u32 dev_read_u32_index_default(struct udevice *dev, const char *propname, |
| 33 | int index, u32 def) |
| 34 | { |
| 35 | return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index, |
| 36 | def); |
| 37 | } |
| 38 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 39 | 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] | 40 | { |
| 41 | return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); |
| 42 | } |
| 43 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 44 | int dev_read_s32_default(const struct udevice *dev, const char *propname, |
| 45 | int def) |
Simon Glass | 6df01f9 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 46 | { |
| 47 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 48 | } |
| 49 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 50 | 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] | 51 | { |
| 52 | u32 val; |
| 53 | int ret; |
| 54 | |
| 55 | ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); |
| 56 | if (ret) |
| 57 | return ret; |
| 58 | *outp = val; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 63 | 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] | 64 | { |
| 65 | return ofnode_read_u64(dev_ofnode(dev), propname, outp); |
| 66 | } |
| 67 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 68 | u64 dev_read_u64_default(const struct udevice *dev, const char *propname, |
| 69 | u64 def) |
T Karthik Reddy | 478860d | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 70 | { |
| 71 | return ofnode_read_u64_default(dev_ofnode(dev), propname, def); |
| 72 | } |
| 73 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 74 | const char *dev_read_string(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 75 | { |
| 76 | return ofnode_read_string(dev_ofnode(dev), propname); |
| 77 | } |
| 78 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 79 | bool dev_read_bool(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 80 | { |
| 81 | return ofnode_read_bool(dev_ofnode(dev), propname); |
| 82 | } |
| 83 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 84 | ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 85 | { |
| 86 | return ofnode_find_subnode(dev_ofnode(dev), subnode_name); |
| 87 | } |
| 88 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 89 | ofnode dev_read_first_subnode(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 90 | { |
| 91 | return ofnode_first_subnode(dev_ofnode(dev)); |
| 92 | } |
| 93 | |
| 94 | ofnode dev_read_next_subnode(ofnode node) |
| 95 | { |
| 96 | return ofnode_next_subnode(node); |
| 97 | } |
| 98 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 99 | int dev_read_size(const struct udevice *dev, const char *propname) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 100 | { |
| 101 | return ofnode_read_size(dev_ofnode(dev), propname); |
| 102 | } |
| 103 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 104 | 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] | 105 | { |
| 106 | if (ofnode_is_np(dev_ofnode(dev))) |
| 107 | return ofnode_get_addr_index(dev_ofnode(dev), index); |
| 108 | else |
| 109 | return devfdt_get_addr_index(dev, index); |
| 110 | } |
| 111 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 112 | 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] | 113 | fdt_size_t *size) |
| 114 | { |
| 115 | if (ofnode_is_np(dev_ofnode(dev))) |
| 116 | return ofnode_get_addr_size_index(dev_ofnode(dev), index, size); |
| 117 | else |
| 118 | return devfdt_get_addr_size_index(dev, index, size); |
| 119 | } |
| 120 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 121 | 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] | 122 | { |
| 123 | fdt_addr_t addr = dev_read_addr_index(dev, index); |
| 124 | |
| 125 | if (addr == FDT_ADDR_T_NONE) |
| 126 | return NULL; |
| 127 | |
| 128 | return map_physmem(addr, 0, MAP_NOCACHE); |
| 129 | } |
| 130 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 131 | 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] | 132 | { |
| 133 | int index = dev_read_stringlist_search(dev, "reg-names", name); |
| 134 | |
| 135 | if (index < 0) |
| 136 | return FDT_ADDR_T_NONE; |
| 137 | else |
| 138 | return dev_read_addr_index(dev, index); |
| 139 | } |
| 140 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 141 | 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] | 142 | fdt_size_t *size) |
| 143 | { |
| 144 | int index = dev_read_stringlist_search(dev, "reg-names", name); |
| 145 | |
| 146 | if (index < 0) |
| 147 | return FDT_ADDR_T_NONE; |
| 148 | else |
| 149 | return dev_read_addr_size_index(dev, index, size); |
| 150 | } |
| 151 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 152 | 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] | 153 | { |
| 154 | fdt_addr_t addr = dev_read_addr_name(dev, name); |
| 155 | |
| 156 | if (addr == FDT_ADDR_T_NONE) |
| 157 | return NULL; |
| 158 | |
| 159 | return map_physmem(addr, 0, MAP_NOCACHE); |
| 160 | } |
| 161 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 162 | fdt_addr_t dev_read_addr(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 163 | { |
| 164 | return dev_read_addr_index(dev, 0); |
| 165 | } |
| 166 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 167 | void *dev_read_addr_ptr(const struct udevice *dev) |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 168 | { |
| 169 | fdt_addr_t addr = dev_read_addr(dev); |
| 170 | |
Sean Anderson | 42db70b | 2020-06-24 06:41:13 -0400 | [diff] [blame] | 171 | return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr; |
Philipp Tomsich | 7719b39 | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 174 | void *dev_remap_addr(const struct udevice *dev) |
Álvaro Fernández Rojas | 67036129 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 175 | { |
| 176 | return dev_remap_addr_index(dev, 0); |
| 177 | } |
| 178 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 179 | fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *property, |
Mario Six | 6eac222 | 2018-01-15 11:07:18 +0100 | [diff] [blame] | 180 | fdt_size_t *sizep) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 181 | { |
| 182 | return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); |
| 183 | } |
| 184 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 185 | const char *dev_read_name(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 186 | { |
| 187 | return ofnode_get_name(dev_ofnode(dev)); |
| 188 | } |
| 189 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 190 | int dev_read_stringlist_search(const struct udevice *dev, const char *property, |
Mario Six | 6eac222 | 2018-01-15 11:07:18 +0100 | [diff] [blame] | 191 | const char *string) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 192 | { |
| 193 | return ofnode_stringlist_search(dev_ofnode(dev), property, string); |
| 194 | } |
| 195 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 196 | int dev_read_string_index(const struct udevice *dev, const char *propname, |
| 197 | int index, const char **outp) |
Jean-Jacques Hiblot | 8365ebd | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 198 | { |
| 199 | return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); |
| 200 | } |
| 201 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 202 | 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] | 203 | { |
| 204 | return ofnode_read_string_count(dev_ofnode(dev), propname); |
| 205 | } |
| 206 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 207 | 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] | 208 | const char *cells_name, int cell_count, |
| 209 | int index, struct ofnode_phandle_args *out_args) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 210 | { |
| 211 | return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, |
| 212 | cells_name, cell_count, index, |
| 213 | out_args); |
| 214 | } |
| 215 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 216 | int dev_count_phandle_with_args(const struct udevice *dev, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 217 | const char *list_name, const char *cells_name, |
| 218 | int cell_count) |
Patrice Chotard | 99503c1 | 2017-11-29 09:06:10 +0100 | [diff] [blame] | 219 | { |
| 220 | return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, |
Patrick Delaunay | d776a84 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 221 | cells_name, cell_count); |
Patrice Chotard | 99503c1 | 2017-11-29 09:06:10 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 224 | int dev_read_addr_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 225 | { |
| 226 | return ofnode_read_addr_cells(dev_ofnode(dev)); |
| 227 | } |
| 228 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 229 | int dev_read_size_cells(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 230 | { |
| 231 | return ofnode_read_size_cells(dev_ofnode(dev)); |
| 232 | } |
| 233 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 234 | int dev_read_simple_addr_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 235 | { |
| 236 | return ofnode_read_simple_addr_cells(dev_ofnode(dev)); |
| 237 | } |
| 238 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 239 | int dev_read_simple_size_cells(const struct udevice *dev) |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 240 | { |
| 241 | return ofnode_read_simple_size_cells(dev_ofnode(dev)); |
| 242 | } |
| 243 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 244 | int dev_read_phandle(const struct udevice *dev) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 245 | { |
| 246 | ofnode node = dev_ofnode(dev); |
| 247 | |
| 248 | if (ofnode_is_np(node)) |
| 249 | return ofnode_to_np(node)->phandle; |
| 250 | else |
| 251 | return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); |
| 252 | } |
| 253 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 254 | const void *dev_read_prop(const struct udevice *dev, const char *propname, |
| 255 | int *lenp) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 256 | { |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 257 | return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 258 | } |
| 259 | |
Patrick Delaunay | caee155 | 2020-01-13 11:34:56 +0100 | [diff] [blame] | 260 | int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop) |
| 261 | { |
| 262 | return ofnode_get_first_property(dev_ofnode(dev), prop); |
| 263 | } |
| 264 | |
| 265 | int dev_read_next_prop(struct ofprop *prop) |
| 266 | { |
| 267 | return ofnode_get_next_property(prop); |
| 268 | } |
| 269 | |
| 270 | const void *dev_read_prop_by_prop(struct ofprop *prop, |
| 271 | const char **propname, int *lenp) |
| 272 | { |
| 273 | return ofnode_get_property_by_prop(prop, propname, lenp); |
| 274 | } |
| 275 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 276 | int dev_read_alias_seq(const struct udevice *dev, int *devnump) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 277 | { |
| 278 | ofnode node = dev_ofnode(dev); |
| 279 | const char *uc_name = dev->uclass->uc_drv->name; |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 280 | int ret = -ENOTSUPP; |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 281 | |
| 282 | if (ofnode_is_np(node)) { |
| 283 | ret = of_alias_get_id(ofnode_to_np(node), uc_name); |
| 284 | if (ret >= 0) |
| 285 | *devnump = ret; |
| 286 | } else { |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 287 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 288 | ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name, |
| 289 | ofnode_to_offset(node), devnump); |
Marcel Ziswiler | 65c2bf6 | 2019-05-20 02:44:57 +0200 | [diff] [blame] | 290 | #endif |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 296 | int dev_read_u32_array(const struct udevice *dev, const char *propname, |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 297 | u32 *out_values, size_t sz) |
| 298 | { |
| 299 | return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); |
| 300 | } |
| 301 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 302 | const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, |
| 303 | const char *propname, size_t sz) |
Simon Glass | cfdae5c | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 304 | { |
| 305 | return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); |
| 306 | } |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 307 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 308 | int dev_read_enabled(const struct udevice *dev) |
Simon Glass | fa031f8 | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 309 | { |
| 310 | ofnode node = dev_ofnode(dev); |
| 311 | |
| 312 | if (ofnode_is_np(node)) |
| 313 | return of_device_is_available(ofnode_to_np(node)); |
| 314 | else |
| 315 | return fdtdec_get_is_enabled(gd->fdt_blob, |
| 316 | ofnode_to_offset(node)); |
| 317 | } |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 318 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 319 | int dev_read_resource(const struct udevice *dev, uint index, |
| 320 | struct resource *res) |
Simon Glass | f7bfcc4 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 321 | { |
| 322 | return ofnode_read_resource(dev_ofnode(dev), index, res); |
| 323 | } |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 324 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 325 | int dev_read_resource_byname(const struct udevice *dev, const char *name, |
Masahiro Yamada | 4dada2c | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 326 | struct resource *res) |
| 327 | { |
| 328 | return ofnode_read_resource_byname(dev_ofnode(dev), name, res); |
| 329 | } |
Mario Six | aefac06 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 330 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 331 | 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] | 332 | { |
| 333 | return ofnode_translate_address(dev_ofnode(dev), in_addr); |
| 334 | } |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 335 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 336 | 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] | 337 | { |
| 338 | return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); |
| 339 | } |
| 340 | |
Michal Simek | d0e30a0 | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 341 | int dev_read_alias_highest_id(const char *stem) |
| 342 | { |
| 343 | if (of_live_active()) |
| 344 | return of_alias_get_highest_id(stem); |
| 345 | |
| 346 | return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); |
| 347 | } |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 348 | |
Simon Glass | 2f9a612 | 2020-01-27 08:49:40 -0700 | [diff] [blame] | 349 | fdt_addr_t dev_read_addr_pci(const struct udevice *dev) |
Simon Glass | 23b2759 | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 350 | { |
| 351 | ulong addr; |
| 352 | |
| 353 | addr = dev_read_addr(dev); |
| 354 | if (addr == FDT_ADDR_T_NONE && !of_live_active()) |
| 355 | addr = devfdt_get_addr_pci(dev); |
| 356 | |
| 357 | return addr; |
| 358 | } |
developer | d93c8b4 | 2020-05-02 11:35:09 +0200 | [diff] [blame] | 359 | |
| 360 | int dev_get_child_count(const struct udevice *dev) |
| 361 | { |
| 362 | return ofnode_get_child_count(dev_ofnode(dev)); |
| 363 | } |
Stefan Roese | 0a9ecc5 | 2020-08-05 13:56:11 +0200 | [diff] [blame] | 364 | |
| 365 | int dev_read_pci_bus_range(const struct udevice *dev, |
| 366 | struct resource *res) |
| 367 | { |
| 368 | const u32 *values; |
| 369 | int len; |
| 370 | |
| 371 | values = dev_read_prop(dev, "bus-range", &len); |
| 372 | if (!values || len < sizeof(*values) * 2) |
| 373 | return -EINVAL; |
| 374 | |
| 375 | res->start = *values++; |
| 376 | res->end = *values; |
| 377 | |
| 378 | return 0; |
| 379 | } |