blob: 3131e5379c966a831a56b6dc6b1e80a33d3fe627 [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
97int dev_read_phandle(struct udevice *dev)
98{
99 ofnode node = dev_ofnode(dev);
100
101 if (ofnode_is_np(node))
102 return ofnode_to_np(node)->phandle;
103 else
104 return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node));
105}
106
107const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp)
108{
109 return ofnode_read_prop(dev_ofnode(dev), propname, lenp);
110}
111
112int dev_read_alias_seq(struct udevice *dev, int *devnump)
113{
114 ofnode node = dev_ofnode(dev);
115 const char *uc_name = dev->uclass->uc_drv->name;
116 int ret;
117
118 if (ofnode_is_np(node)) {
119 ret = of_alias_get_id(ofnode_to_np(node), uc_name);
120 if (ret >= 0)
121 *devnump = ret;
122 } else {
123 ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
124 ofnode_to_offset(node), devnump);
125 }
126
127 return ret;
128}
129
130int dev_read_u32_array(struct udevice *dev, const char *propname,
131 u32 *out_values, size_t sz)
132{
133 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
134}
135
136const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
137 size_t sz)
138{
139 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
140}