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