blob: aba8747708723888e011f5b7b5e57976bbe6ddbb [file] [log] [blame]
Simon Glasscfdae5c2017-05-18 20:09:04 -06001/*
2 * Copyright (c) 2017 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
Simon Glassc47a3882017-09-28 06:35:15 -060010#include <mapmem.h>
Simon Glasscfdae5c2017-05-18 20:09:04 -060011#include <dm/of_access.h>
12
13int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
14{
15 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
16}
17
18const char *dev_read_string(struct udevice *dev, const char *propname)
19{
20 return ofnode_read_string(dev_ofnode(dev), propname);
21}
22
23bool dev_read_bool(struct udevice *dev, const char *propname)
24{
25 return ofnode_read_bool(dev_ofnode(dev), propname);
26}
27
28ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name)
29{
30 return ofnode_find_subnode(dev_ofnode(dev), subnode_name);
31}
32
33ofnode dev_read_first_subnode(struct udevice *dev)
34{
35 return ofnode_first_subnode(dev_ofnode(dev));
36}
37
38ofnode dev_read_next_subnode(ofnode node)
39{
40 return ofnode_next_subnode(node);
41}
42
43int dev_read_size(struct udevice *dev, const char *propname)
44{
45 return ofnode_read_size(dev_ofnode(dev), propname);
46}
47
48fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
49{
50 if (ofnode_is_np(dev_ofnode(dev)))
51 return ofnode_get_addr_index(dev_ofnode(dev), index);
52 else
53 return devfdt_get_addr_index(dev, index);
54}
55
56fdt_addr_t dev_read_addr(struct udevice *dev)
57{
58 return dev_read_addr_index(dev, 0);
59}
60
Philipp Tomsich7719b392017-09-11 22:04:12 +020061void *dev_read_addr_ptr(struct udevice *dev)
62{
63 fdt_addr_t addr = dev_read_addr(dev);
64
Simon Glassc47a3882017-09-28 06:35:15 -060065 return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0);
Philipp Tomsich7719b392017-09-11 22:04:12 +020066}
67
Simon Glasscfdae5c2017-05-18 20:09:04 -060068fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property,
Mario Six6eac2222018-01-15 11:07:18 +010069 fdt_size_t *sizep)
Simon Glasscfdae5c2017-05-18 20:09:04 -060070{
71 return ofnode_get_addr_size(dev_ofnode(dev), property, sizep);
72}
73
74const char *dev_read_name(struct udevice *dev)
75{
76 return ofnode_get_name(dev_ofnode(dev));
77}
78
79int dev_read_stringlist_search(struct udevice *dev, const char *property,
Mario Six6eac2222018-01-15 11:07:18 +010080 const char *string)
Simon Glasscfdae5c2017-05-18 20:09:04 -060081{
82 return ofnode_stringlist_search(dev_ofnode(dev), property, string);
83}
84
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +020085int dev_read_string_index(struct udevice *dev, const char *propname, int index,
86 const char **outp)
87{
88 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
89}
90
91int dev_read_string_count(struct udevice *dev, const char *propname)
92{
93 return ofnode_read_string_count(dev_ofnode(dev), propname);
94}
95
Simon Glasscfdae5c2017-05-18 20:09:04 -060096int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
Mario Six6eac2222018-01-15 11:07:18 +010097 const char *cells_name, int cell_count,
98 int index, struct ofnode_phandle_args *out_args)
Simon Glasscfdae5c2017-05-18 20:09:04 -060099{
100 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
101 cells_name, cell_count, index,
102 out_args);
103}
104
Patrice Chotard99503c12017-11-29 09:06:10 +0100105int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
106 const char *cells_name)
107{
108 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
109 cells_name);
110}
111
Simon Glasscfdae5c2017-05-18 20:09:04 -0600112int dev_read_addr_cells(struct udevice *dev)
113{
114 return ofnode_read_addr_cells(dev_ofnode(dev));
115}
116
117int dev_read_size_cells(struct udevice *dev)
118{
119 return ofnode_read_size_cells(dev_ofnode(dev));
120}
121
Simon Glass4191dc12017-06-12 06:21:31 -0600122int dev_read_simple_addr_cells(struct udevice *dev)
123{
124 return ofnode_read_simple_addr_cells(dev_ofnode(dev));
125}
126
127int dev_read_simple_size_cells(struct udevice *dev)
128{
129 return ofnode_read_simple_size_cells(dev_ofnode(dev));
130}
131
Simon Glasscfdae5c2017-05-18 20:09:04 -0600132int dev_read_phandle(struct udevice *dev)
133{
134 ofnode node = dev_ofnode(dev);
135
136 if (ofnode_is_np(node))
137 return ofnode_to_np(node)->phandle;
138 else
139 return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node));
140}
141
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900142const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600143{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900144 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600145}
146
147int dev_read_alias_seq(struct udevice *dev, int *devnump)
148{
149 ofnode node = dev_ofnode(dev);
150 const char *uc_name = dev->uclass->uc_drv->name;
151 int ret;
152
153 if (ofnode_is_np(node)) {
154 ret = of_alias_get_id(ofnode_to_np(node), uc_name);
155 if (ret >= 0)
156 *devnump = ret;
157 } else {
158 ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
159 ofnode_to_offset(node), devnump);
160 }
161
162 return ret;
163}
164
165int dev_read_u32_array(struct udevice *dev, const char *propname,
166 u32 *out_values, size_t sz)
167{
168 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
169}
170
171const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
172 size_t sz)
173{
174 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
175}
Simon Glassfa031f82017-06-12 06:21:30 -0600176
177int dev_read_enabled(struct udevice *dev)
178{
179 ofnode node = dev_ofnode(dev);
180
181 if (ofnode_is_np(node))
182 return of_device_is_available(ofnode_to_np(node));
183 else
184 return fdtdec_get_is_enabled(gd->fdt_blob,
185 ofnode_to_offset(node));
186}
Simon Glassf7bfcc42017-07-25 08:29:55 -0600187
188int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
189{
190 return ofnode_read_resource(dev_ofnode(dev), index, res);
191}
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900192
193int dev_read_resource_byname(struct udevice *dev, const char *name,
194 struct resource *res)
195{
196 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
197}