1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2017 Google, Inc
* Written by Simon Glass <sjg@chromium.org>
*/
#include <common.h>
#include <dm.h>
#include <dm/of_access.h>
#include <mapmem.h>
#include <asm/global_data.h>
#include <asm/types.h>
#include <asm/io.h>
#include <linux/ioport.h>
int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp)
{
return ofnode_read_u32(dev_ofnode(dev), propname, outp);
}
int dev_read_u32_default(const struct udevice *dev, const char *propname,
int def)
{
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
u32 *outp)
{
return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
}
u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
int index, u32 def)
{
return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
def);
}
int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp)
{
return ofnode_read_u32(dev_ofnode(dev), propname, (u32 *)outp);
}
int dev_read_s32_default(const struct udevice *dev, const char *propname,
int def)
{
return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
}
int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp)
{
u32 val;
int ret;
ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
if (ret)
return ret;
*outp = val;
return 0;
}
int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp)
{
return ofnode_read_u64(dev_ofnode(dev), propname, outp);
}
u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
u64 def)
{
return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
}
const char *dev_read_string(const struct udevice *dev, const char *propname)
{
return ofnode_read_string(dev_ofnode(dev), propname);
}
bool dev_read_bool(const struct udevice *dev, const char *propname)
{
return ofnode_read_bool(dev_ofnode(dev), propname);
}
ofnode dev_read_subnode(const struct udevice *dev, const char *subnode_name)
{
return ofnode_find_subnode(dev_ofnode(dev), subnode_name);
}
ofnode dev_read_first_subnode(const struct udevice *dev)
{
return ofnode_first_subnode(dev_ofnode(dev));
}
ofnode dev_read_next_subnode(ofnode node)
{
return ofnode_next_subnode(node);
}
int dev_read_size(const struct udevice *dev, const char *propname)
{
return ofnode_read_size(dev_ofnode(dev), propname);
}
fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index)
{
if (ofnode_is_np(dev_ofnode(dev)))
return ofnode_get_addr_index(dev_ofnode(dev), index);
else
return devfdt_get_addr_index(dev, index);
}
fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
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);
}
void *dev_remap_addr_index(const struct udevice *dev, int index)
{
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);
}
fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name)
{
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);
}
fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
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);
}
void *dev_remap_addr_name(const struct udevice *dev, const char *name)
{
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);
}
fdt_addr_t dev_read_addr(const struct udevice *dev)
{
return dev_read_addr_index(dev, 0);
}
void *dev_read_addr_ptr(const struct udevice *dev)
{
fdt_addr_t addr = dev_read_addr(dev);
return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
}
void *dev_remap_addr(const struct udevice *dev)
{
return dev_remap_addr_index(dev, 0);
}
fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *property,
fdt_size_t *sizep)
{
return ofnode_get_addr_size(dev_ofnode(dev), property, sizep);
}
const char *dev_read_name(const struct udevice *dev)
{
return ofnode_get_name(dev_ofnode(dev));
}
int dev_read_stringlist_search(const struct udevice *dev, const char *property,
const char *string)
{
return ofnode_stringlist_search(dev_ofnode(dev), property, string);
}
int dev_read_string_index(const struct udevice *dev, const char *propname,
int index, const char **outp)
{
return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
}
int dev_read_string_count(const struct udevice *dev, const char *propname)
{
return ofnode_read_string_count(dev_ofnode(dev), propname);
}
int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
const char *cells_name, int cell_count,
int index, struct ofnode_phandle_args *out_args)
{
return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
cells_name, cell_count, index,
out_args);
}
int dev_count_phandle_with_args(const struct udevice *dev,
const char *list_name, const char *cells_name,
int cell_count)
{
return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
cells_name, cell_count);
}
int dev_read_addr_cells(const struct udevice *dev)
{
return ofnode_read_addr_cells(dev_ofnode(dev));
}
int dev_read_size_cells(const struct udevice *dev)
{
return ofnode_read_size_cells(dev_ofnode(dev));
}
int dev_read_simple_addr_cells(const struct udevice *dev)
{
return ofnode_read_simple_addr_cells(dev_ofnode(dev));
}
int dev_read_simple_size_cells(const struct udevice *dev)
{
return ofnode_read_simple_size_cells(dev_ofnode(dev));
}
int dev_read_phandle(const struct udevice *dev)
{
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));
}
const void *dev_read_prop(const struct udevice *dev, const char *propname,
int *lenp)
{
return ofnode_get_property(dev_ofnode(dev), propname, lenp);
}
int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
{
return ofnode_get_first_property(dev_ofnode(dev), prop);
}
int dev_read_next_prop(struct ofprop *prop)
{
return ofnode_get_next_property(prop);
}
const void *dev_read_prop_by_prop(struct ofprop *prop,
const char **propname, int *lenp)
{
return ofnode_get_property_by_prop(prop, propname, lenp);
}
int dev_read_alias_seq(const struct udevice *dev, int *devnump)
{
ofnode node = dev_ofnode(dev);
const char *uc_name = dev->uclass->uc_drv->name;
int ret = -ENOTSUPP;
if (ofnode_is_np(node)) {
ret = of_alias_get_id(ofnode_to_np(node), uc_name);
if (ret >= 0) {
*devnump = ret;
ret = 0;
}
} else {
#if CONFIG_IS_ENABLED(OF_CONTROL)
ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
ofnode_to_offset(node), devnump);
#endif
}
return ret;
}
int dev_read_u32_array(const struct udevice *dev, const char *propname,
u32 *out_values, size_t sz)
{
return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
}
const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
const char *propname, size_t sz)
{
return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
}
int dev_read_enabled(const struct udevice *dev)
{
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));
}
int dev_read_resource(const struct udevice *dev, uint index,
struct resource *res)
{
return ofnode_read_resource(dev_ofnode(dev), index, res);
}
int dev_read_resource_byname(const struct udevice *dev, const char *name,
struct resource *res)
{
return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
}
u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr)
{
return ofnode_translate_address(dev_ofnode(dev), in_addr);
}
u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr)
{
return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
}
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);
}
fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
{
ulong addr;
addr = dev_read_addr(dev);
if (addr == FDT_ADDR_T_NONE && !of_live_active())
addr = devfdt_get_addr_pci(dev);
return addr;
}
int dev_get_child_count(const struct udevice *dev)
{
return ofnode_get_child_count(dev_ofnode(dev));
}
int dev_read_pci_bus_range(const struct udevice *dev,
struct resource *res)
{
const u32 *values;
int len;
values = dev_read_prop(dev, "bus-range", &len);
if (!values || len < sizeof(*values) * 2)
return -EINVAL;
res->start = *values++;
res->end = *values;
return 0;
}
int dev_decode_display_timing(const struct udevice *dev, int index,
struct display_timing *config)
{
return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
}
|