Blame view
drivers/core/read.c
7.82 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0+ |
47a0fd3ba
|
2 3 4 |
/* * Copyright (c) 2017 Google, Inc * Written by Simon Glass <sjg@chromium.org> |
47a0fd3ba
|
5 |
*/ |
30a90f56c
|
6 7 |
#include <asm/types.h> #include <asm/io.h> |
47a0fd3ba
|
8 9 |
#include <common.h> #include <dm.h> |
8ccc2db6e
|
10 |
#include <mapmem.h> |
47a0fd3ba
|
11 |
#include <dm/of_access.h> |
88b3a37ea
|
12 |
int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp) |
3ab48f622
|
13 14 15 |
{ return ofnode_read_u32(dev_ofnode(dev), propname, outp); } |
88b3a37ea
|
16 17 |
int dev_read_u32_default(const struct udevice *dev, const char *propname, int def) |
47a0fd3ba
|
18 19 20 |
{ return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } |
88b3a37ea
|
21 |
int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp) |
a1b17e4f4
|
22 23 24 |
{ return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp); } |
88b3a37ea
|
25 26 |
int dev_read_s32_default(const struct udevice *dev, const char *propname, int def) |
a1b17e4f4
|
27 28 29 |
{ return ofnode_read_u32_default(dev_ofnode(dev), propname, def); } |
88b3a37ea
|
30 |
int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp) |
a1b17e4f4
|
31 32 33 34 35 36 37 38 39 40 41 |
{ u32 val; int ret; ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); if (ret) return ret; *outp = val; return 0; } |
88b3a37ea
|
42 |
int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp) |
3f3d77158
|
43 44 45 |
{ return ofnode_read_u64(dev_ofnode(dev), propname, outp); } |
88b3a37ea
|
46 47 |
u64 dev_read_u64_default(const struct udevice *dev, const char *propname, u64 def) |
3f3d77158
|
48 49 50 |
{ return ofnode_read_u64_default(dev_ofnode(dev), propname, def); } |
88b3a37ea
|
51 |
const char *dev_read_string(const struct udevice *dev, const char *propname) |
47a0fd3ba
|
52 53 54 |
{ return ofnode_read_string(dev_ofnode(dev), propname); } |
88b3a37ea
|
55 |
bool dev_read_bool(const struct udevice *dev, const char *propname) |
47a0fd3ba
|
56 57 58 |
{ return ofnode_read_bool(dev_ofnode(dev), propname); } |
88b3a37ea
|
59 |
ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name) |
47a0fd3ba
|
60 61 62 |
{ return ofnode_find_subnode(dev_ofnode(dev), subnode_name); } |
88b3a37ea
|
63 |
ofnode dev_read_first_subnode(const struct udevice *dev) |
47a0fd3ba
|
64 65 66 67 68 69 70 71 |
{ return ofnode_first_subnode(dev_ofnode(dev)); } ofnode dev_read_next_subnode(ofnode node) { return ofnode_next_subnode(node); } |
88b3a37ea
|
72 |
int dev_read_size(const struct udevice *dev, const char *propname) |
47a0fd3ba
|
73 74 75 |
{ return ofnode_read_size(dev_ofnode(dev), propname); } |
88b3a37ea
|
76 |
fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index) |
47a0fd3ba
|
77 78 79 80 81 82 |
{ if (ofnode_is_np(dev_ofnode(dev))) return ofnode_get_addr_index(dev_ofnode(dev), index); else return devfdt_get_addr_index(dev, index); } |
88b3a37ea
|
83 |
fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index, |
f5b904796
|
84 85 86 87 88 89 90 |
fdt_size_t *size) { if (ofnode_is_np(dev_ofnode(dev))) return ofnode_get_addr_size_index(dev_ofnode(dev), index, size); else return devfdt_get_addr_size_index(dev, index, size); } |
88b3a37ea
|
91 |
void *dev_remap_addr_index(const struct udevice *dev, int index) |
30a90f56c
|
92 93 94 95 96 97 98 99 |
{ fdt_addr_t addr = dev_read_addr_index(dev, index); if (addr == FDT_ADDR_T_NONE) return NULL; return map_physmem(addr, 0, MAP_NOCACHE); } |
88b3a37ea
|
100 |
fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name) |
795988204
|
101 102 103 104 105 106 107 108 |
{ int index = dev_read_stringlist_search(dev, "reg-names", name); if (index < 0) return FDT_ADDR_T_NONE; else return dev_read_addr_index(dev, index); } |
88b3a37ea
|
109 |
fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name, |
f5b904796
|
110 111 112 113 114 115 116 117 118 |
fdt_size_t *size) { int index = dev_read_stringlist_search(dev, "reg-names", name); if (index < 0) return FDT_ADDR_T_NONE; else return dev_read_addr_size_index(dev, index, size); } |
88b3a37ea
|
119 |
void *dev_remap_addr_name(const struct udevice *dev, const char *name) |
795988204
|
120 121 122 123 124 125 126 127 |
{ fdt_addr_t addr = dev_read_addr_name(dev, name); if (addr == FDT_ADDR_T_NONE) return NULL; return map_physmem(addr, 0, MAP_NOCACHE); } |
88b3a37ea
|
128 |
fdt_addr_t dev_read_addr(const struct udevice *dev) |
47a0fd3ba
|
129 130 131 |
{ return dev_read_addr_index(dev, 0); } |
88b3a37ea
|
132 |
void *dev_read_addr_ptr(const struct udevice *dev) |
c131c8bca
|
133 134 |
{ fdt_addr_t addr = dev_read_addr(dev); |
8ccc2db6e
|
135 |
return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0); |
c131c8bca
|
136 |
} |
88b3a37ea
|
137 |
void *dev_remap_addr(const struct udevice *dev) |
30a90f56c
|
138 139 140 |
{ return dev_remap_addr_index(dev, 0); } |
88b3a37ea
|
141 |
fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *property, |
83a462a5e
|
142 |
fdt_size_t *sizep) |
47a0fd3ba
|
143 144 145 |
{ return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); } |
88b3a37ea
|
146 |
const char *dev_read_name(const struct udevice *dev) |
47a0fd3ba
|
147 148 149 |
{ return ofnode_get_name(dev_ofnode(dev)); } |
88b3a37ea
|
150 |
int dev_read_stringlist_search(const struct udevice *dev, const char *property, |
83a462a5e
|
151 |
const char *string) |
47a0fd3ba
|
152 153 154 |
{ return ofnode_stringlist_search(dev_ofnode(dev), property, string); } |
88b3a37ea
|
155 156 |
int dev_read_string_index(const struct udevice *dev, const char *propname, int index, const char **outp) |
b5a144a50
|
157 158 159 |
{ return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); } |
88b3a37ea
|
160 |
int dev_read_string_count(const struct udevice *dev, const char *propname) |
b5a144a50
|
161 162 163 |
{ return ofnode_read_string_count(dev_ofnode(dev), propname); } |
88b3a37ea
|
164 |
int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name, |
83a462a5e
|
165 166 |
const char *cells_name, int cell_count, int index, struct ofnode_phandle_args *out_args) |
47a0fd3ba
|
167 168 169 170 171 |
{ return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, cells_name, cell_count, index, out_args); } |
88b3a37ea
|
172 173 |
int dev_count_phandle_with_args(const struct udevice *dev, const char *list_name, const char *cells_name) |
ea8cd652a
|
174 175 176 177 |
{ return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, cells_name); } |
88b3a37ea
|
178 |
int dev_read_addr_cells(const struct udevice *dev) |
47a0fd3ba
|
179 180 181 |
{ return ofnode_read_addr_cells(dev_ofnode(dev)); } |
88b3a37ea
|
182 |
int dev_read_size_cells(const struct udevice *dev) |
47a0fd3ba
|
183 184 185 |
{ return ofnode_read_size_cells(dev_ofnode(dev)); } |
88b3a37ea
|
186 |
int dev_read_simple_addr_cells(const struct udevice *dev) |
878d68c0c
|
187 188 189 |
{ return ofnode_read_simple_addr_cells(dev_ofnode(dev)); } |
88b3a37ea
|
190 |
int dev_read_simple_size_cells(const struct udevice *dev) |
878d68c0c
|
191 192 193 |
{ return ofnode_read_simple_size_cells(dev_ofnode(dev)); } |
88b3a37ea
|
194 |
int dev_read_phandle(const struct udevice *dev) |
47a0fd3ba
|
195 196 197 198 199 200 201 202 |
{ ofnode node = dev_ofnode(dev); if (ofnode_is_np(node)) return ofnode_to_np(node)->phandle; else return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); } |
88b3a37ea
|
203 204 |
const void *dev_read_prop(const struct udevice *dev, const char *propname, int *lenp) |
47a0fd3ba
|
205 |
{ |
61e51babd
|
206 |
return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
47a0fd3ba
|
207 |
} |
88b3a37ea
|
208 |
int dev_read_alias_seq(const struct udevice *dev, int *devnump) |
47a0fd3ba
|
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
{ ofnode node = dev_ofnode(dev); const char *uc_name = dev->uclass->uc_drv->name; int ret; if (ofnode_is_np(node)) { ret = of_alias_get_id(ofnode_to_np(node), uc_name); if (ret >= 0) *devnump = ret; } else { ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name, ofnode_to_offset(node), devnump); } return ret; } |
88b3a37ea
|
225 |
int dev_read_u32_array(const struct udevice *dev, const char *propname, |
47a0fd3ba
|
226 227 228 229 |
u32 *out_values, size_t sz) { return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); } |
88b3a37ea
|
230 231 |
const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev, const char *propname, size_t sz) |
47a0fd3ba
|
232 233 234 |
{ return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); } |
f7d6fcf7a
|
235 |
|
88b3a37ea
|
236 |
int dev_read_enabled(const struct udevice *dev) |
f7d6fcf7a
|
237 238 239 240 241 242 243 244 245 |
{ ofnode node = dev_ofnode(dev); if (ofnode_is_np(node)) return of_device_is_available(ofnode_to_np(node)); else return fdtdec_get_is_enabled(gd->fdt_blob, ofnode_to_offset(node)); } |
dcf988525
|
246 |
|
88b3a37ea
|
247 248 |
int dev_read_resource(const struct udevice *dev, uint index, struct resource *res) |
dcf988525
|
249 250 251 |
{ return ofnode_read_resource(dev_ofnode(dev), index, res); } |
7b8b47bd2
|
252 |
|
88b3a37ea
|
253 |
int dev_read_resource_byname(const struct udevice *dev, const char *name, |
7b8b47bd2
|
254 255 256 257 |
struct resource *res) { return ofnode_read_resource_byname(dev_ofnode(dev), name, res); } |
147c60744
|
258 |
|
88b3a37ea
|
259 |
u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr) |
147c60744
|
260 261 262 |
{ return ofnode_translate_address(dev_ofnode(dev), in_addr); } |
83e4c7e9f
|
263 |
|
88b3a37ea
|
264 |
u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr) |
641067fb0
|
265 266 267 |
{ return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); } |
83e4c7e9f
|
268 269 270 271 272 273 274 |
int dev_read_alias_highest_id(const char *stem) { if (of_live_active()) return of_alias_get_highest_id(stem); return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); } |
33c215af4
|
275 |
|
88b3a37ea
|
276 |
fdt_addr_t dev_read_addr_pci(const struct udevice *dev) |
33c215af4
|
277 278 279 280 281 282 283 284 285 |
{ ulong addr; addr = dev_read_addr(dev); if (addr == FDT_ADDR_T_NONE && !of_live_active()) addr = devfdt_get_addr_pci(dev); return addr; } |