blob: 0322cbf33008e91153d2d34904b0ccabe1083f11 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasscfdae5c2017-05-18 20:09:04 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glasscfdae5c2017-05-18 20:09:04 -06005 */
6
7#include <common.h>
8#include <dm.h>
Simon Glassc47a3882017-09-28 06:35:15 -06009#include <mapmem.h>
Simon Glasscfdae5c2017-05-18 20:09:04 -060010#include <dm/of_access.h>
11
Masahiro Yamada71d115f2017-12-30 02:00:05 +090012int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp)
13{
14 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
15}
16
Simon Glasscfdae5c2017-05-18 20:09:04 -060017int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
18{
19 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
20}
21
22const char *dev_read_string(struct udevice *dev, const char *propname)
23{
24 return ofnode_read_string(dev_ofnode(dev), propname);
25}
26
27bool dev_read_bool(struct udevice *dev, const char *propname)
28{
29 return ofnode_read_bool(dev_ofnode(dev), propname);
30}
31
32ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name)
33{
34 return ofnode_find_subnode(dev_ofnode(dev), subnode_name);
35}
36
37ofnode dev_read_first_subnode(struct udevice *dev)
38{
39 return ofnode_first_subnode(dev_ofnode(dev));
40}
41
42ofnode dev_read_next_subnode(ofnode node)
43{
44 return ofnode_next_subnode(node);
45}
46
47int dev_read_size(struct udevice *dev, const char *propname)
48{
49 return ofnode_read_size(dev_ofnode(dev), propname);
50}
51
52fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
53{
54 if (ofnode_is_np(dev_ofnode(dev)))
55 return ofnode_get_addr_index(dev_ofnode(dev), index);
56 else
57 return devfdt_get_addr_index(dev, index);
58}
59
60fdt_addr_t dev_read_addr(struct udevice *dev)
61{
62 return dev_read_addr_index(dev, 0);
63}
64
Philipp Tomsich7719b392017-09-11 22:04:12 +020065void *dev_read_addr_ptr(struct udevice *dev)
66{
67 fdt_addr_t addr = dev_read_addr(dev);
68
Simon Glassc47a3882017-09-28 06:35:15 -060069 return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0);
Philipp Tomsich7719b392017-09-11 22:04:12 +020070}
71
Simon Glasscfdae5c2017-05-18 20:09:04 -060072fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property,
Mario Six6eac2222018-01-15 11:07:18 +010073 fdt_size_t *sizep)
Simon Glasscfdae5c2017-05-18 20:09:04 -060074{
75 return ofnode_get_addr_size(dev_ofnode(dev), property, sizep);
76}
77
78const char *dev_read_name(struct udevice *dev)
79{
80 return ofnode_get_name(dev_ofnode(dev));
81}
82
83int dev_read_stringlist_search(struct udevice *dev, const char *property,
Mario Six6eac2222018-01-15 11:07:18 +010084 const char *string)
Simon Glasscfdae5c2017-05-18 20:09:04 -060085{
86 return ofnode_stringlist_search(dev_ofnode(dev), property, string);
87}
88
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +020089int dev_read_string_index(struct udevice *dev, const char *propname, int index,
90 const char **outp)
91{
92 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
93}
94
95int dev_read_string_count(struct udevice *dev, const char *propname)
96{
97 return ofnode_read_string_count(dev_ofnode(dev), propname);
98}
99
Simon Glasscfdae5c2017-05-18 20:09:04 -0600100int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
Mario Six6eac2222018-01-15 11:07:18 +0100101 const char *cells_name, int cell_count,
102 int index, struct ofnode_phandle_args *out_args)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600103{
104 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
105 cells_name, cell_count, index,
106 out_args);
107}
108
Patrice Chotard99503c12017-11-29 09:06:10 +0100109int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
110 const char *cells_name)
111{
112 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
113 cells_name);
114}
115
Simon Glasscfdae5c2017-05-18 20:09:04 -0600116int dev_read_addr_cells(struct udevice *dev)
117{
118 return ofnode_read_addr_cells(dev_ofnode(dev));
119}
120
121int dev_read_size_cells(struct udevice *dev)
122{
123 return ofnode_read_size_cells(dev_ofnode(dev));
124}
125
Simon Glass4191dc12017-06-12 06:21:31 -0600126int dev_read_simple_addr_cells(struct udevice *dev)
127{
128 return ofnode_read_simple_addr_cells(dev_ofnode(dev));
129}
130
131int dev_read_simple_size_cells(struct udevice *dev)
132{
133 return ofnode_read_simple_size_cells(dev_ofnode(dev));
134}
135
Simon Glasscfdae5c2017-05-18 20:09:04 -0600136int dev_read_phandle(struct udevice *dev)
137{
138 ofnode node = dev_ofnode(dev);
139
140 if (ofnode_is_np(node))
141 return ofnode_to_np(node)->phandle;
142 else
143 return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node));
144}
145
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900146const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600147{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900148 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600149}
150
151int dev_read_alias_seq(struct udevice *dev, int *devnump)
152{
153 ofnode node = dev_ofnode(dev);
154 const char *uc_name = dev->uclass->uc_drv->name;
155 int ret;
156
157 if (ofnode_is_np(node)) {
158 ret = of_alias_get_id(ofnode_to_np(node), uc_name);
159 if (ret >= 0)
160 *devnump = ret;
161 } else {
162 ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
163 ofnode_to_offset(node), devnump);
164 }
165
166 return ret;
167}
168
169int dev_read_u32_array(struct udevice *dev, const char *propname,
170 u32 *out_values, size_t sz)
171{
172 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
173}
174
175const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
176 size_t sz)
177{
178 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
179}
Simon Glassfa031f82017-06-12 06:21:30 -0600180
181int dev_read_enabled(struct udevice *dev)
182{
183 ofnode node = dev_ofnode(dev);
184
185 if (ofnode_is_np(node))
186 return of_device_is_available(ofnode_to_np(node));
187 else
188 return fdtdec_get_is_enabled(gd->fdt_blob,
189 ofnode_to_offset(node));
190}
Simon Glassf7bfcc42017-07-25 08:29:55 -0600191
192int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
193{
194 return ofnode_read_resource(dev_ofnode(dev), index, res);
195}
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900196
197int dev_read_resource_byname(struct udevice *dev, const char *name,
198 struct resource *res)
199{
200 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
201}
Mario Sixaefac062018-01-15 11:07:19 +0100202
203u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
204{
205 return ofnode_translate_address(dev_ofnode(dev), in_addr);
206}