blob: 36293ba3263843349c92eca89b43856669da4e57 [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>
10#include <dm/of_access.h>
11
12int dev_read_u32_default(struct udevice *dev, const char *propname, int def)
13{
14 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
15}
16
17const char *dev_read_string(struct udevice *dev, const char *propname)
18{
19 return ofnode_read_string(dev_ofnode(dev), propname);
20}
21
22bool dev_read_bool(struct udevice *dev, const char *propname)
23{
24 return ofnode_read_bool(dev_ofnode(dev), propname);
25}
26
27ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name)
28{
29 return ofnode_find_subnode(dev_ofnode(dev), subnode_name);
30}
31
32ofnode dev_read_first_subnode(struct udevice *dev)
33{
34 return ofnode_first_subnode(dev_ofnode(dev));
35}
36
37ofnode dev_read_next_subnode(ofnode node)
38{
39 return ofnode_next_subnode(node);
40}
41
42int dev_read_size(struct udevice *dev, const char *propname)
43{
44 return ofnode_read_size(dev_ofnode(dev), propname);
45}
46
47fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
48{
49 if (ofnode_is_np(dev_ofnode(dev)))
50 return ofnode_get_addr_index(dev_ofnode(dev), index);
51 else
52 return devfdt_get_addr_index(dev, index);
53}
54
55fdt_addr_t dev_read_addr(struct udevice *dev)
56{
57 return dev_read_addr_index(dev, 0);
58}
59
60fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property,
61 fdt_size_t *sizep)
62{
63 return ofnode_get_addr_size(dev_ofnode(dev), property, sizep);
64}
65
66const char *dev_read_name(struct udevice *dev)
67{
68 return ofnode_get_name(dev_ofnode(dev));
69}
70
71int dev_read_stringlist_search(struct udevice *dev, const char *property,
72 const char *string)
73{
74 return ofnode_stringlist_search(dev_ofnode(dev), property, string);
75}
76
77int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
78 const char *cells_name, int cell_count,
79 int index,
80 struct ofnode_phandle_args *out_args)
81{
82 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
83 cells_name, cell_count, index,
84 out_args);
85}
86
87int dev_read_addr_cells(struct udevice *dev)
88{
89 return ofnode_read_addr_cells(dev_ofnode(dev));
90}
91
92int dev_read_size_cells(struct udevice *dev)
93{
94 return ofnode_read_size_cells(dev_ofnode(dev));
95}
96
Simon Glass4191dc12017-06-12 06:21:31 -060097int dev_read_simple_addr_cells(struct udevice *dev)
98{
99 return ofnode_read_simple_addr_cells(dev_ofnode(dev));
100}
101
102int dev_read_simple_size_cells(struct udevice *dev)
103{
104 return ofnode_read_simple_size_cells(dev_ofnode(dev));
105}
106
Simon Glasscfdae5c2017-05-18 20:09:04 -0600107int dev_read_phandle(struct udevice *dev)
108{
109 ofnode node = dev_ofnode(dev);
110
111 if (ofnode_is_np(node))
112 return ofnode_to_np(node)->phandle;
113 else
114 return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node));
115}
116
117const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
118{
119 return ofnode_read_prop(dev_ofnode(dev), propname, lenp);
120}
121
122int dev_read_alias_seq(struct udevice *dev, int *devnump)
123{
124 ofnode node = dev_ofnode(dev);
125 const char *uc_name = dev->uclass->uc_drv->name;
126 int ret;
127
128 if (ofnode_is_np(node)) {
129 ret = of_alias_get_id(ofnode_to_np(node), uc_name);
130 if (ret >= 0)
131 *devnump = ret;
132 } else {
133 ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
134 ofnode_to_offset(node), devnump);
135 }
136
137 return ret;
138}
139
140int dev_read_u32_array(struct udevice *dev, const char *propname,
141 u32 *out_values, size_t sz)
142{
143 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
144}
145
146const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
147 size_t sz)
148{
149 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
150}
Simon Glassfa031f82017-06-12 06:21:30 -0600151
152int dev_read_enabled(struct udevice *dev)
153{
154 ofnode node = dev_ofnode(dev);
155
156 if (ofnode_is_np(node))
157 return of_device_is_available(ofnode_to_np(node));
158 else
159 return fdtdec_get_is_enabled(gd->fdt_blob,
160 ofnode_to_offset(node));
161}