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
|
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Fri, 20 Dec 2019 12:27:02 +0100
Subject: [PATCH] of: Add of_bus_n_xxx_cells()
Added straight from the Kernel.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 46 ++++++++++++++++++++++++++++------------------
include/of.h | 12 ++++++++++++
2 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 98ef5fc0d421..e1d3707d01ee 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -78,36 +78,46 @@ static struct device_node *of_aliases;
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
-int of_n_addr_cells(struct device_node *np)
+int of_bus_n_addr_cells(struct device_node *np)
{
- const __be32 *ip;
+ u32 cells;
+
+ for (; np; np = np->parent)
+ if (!of_property_read_u32(np, "#address-cells", &cells))
+ return cells;
- do {
- if (np->parent)
- np = np->parent;
- ip = of_get_property(np, "#address-cells", NULL);
- if (ip)
- return be32_to_cpup(ip);
- } while (np->parent);
/* No #address-cells property for the root node */
return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
}
+
+int of_n_addr_cells(struct device_node *np)
+{
+ if (np->parent)
+ np = np->parent;
+
+ return of_bus_n_addr_cells(np);
+}
EXPORT_SYMBOL(of_n_addr_cells);
-int of_n_size_cells(struct device_node *np)
+int of_bus_n_size_cells(struct device_node *np)
{
- const __be32 *ip;
+ u32 cells;
+
+ for (; np; np = np->parent)
+ if (!of_property_read_u32(np, "#size-cells", &cells))
+ return cells;
- do {
- if (np->parent)
- np = np->parent;
- ip = of_get_property(np, "#size-cells", NULL);
- if (ip)
- return be32_to_cpup(ip);
- } while (np->parent);
/* No #size-cells property for the root node */
return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
}
+
+int of_n_size_cells(struct device_node *np)
+{
+ if (np->parent)
+ np = np->parent;
+
+ return of_bus_n_size_cells(np);
+}
EXPORT_SYMBOL(of_n_size_cells);
struct property *of_find_property(const struct device_node *np,
diff --git a/include/of.h b/include/of.h
index 98ddf795cbb4..fb49f40c12a0 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,7 +113,9 @@ struct device_node *of_unflatten_dtb_const(const void *infdt);
struct cdev;
#ifdef CONFIG_OFTREE
+extern int of_bus_n_addr_cells(struct device_node *np);
extern int of_n_addr_cells(struct device_node *np);
+extern int of_bus_n_size_cells(struct device_node *np);
extern int of_n_size_cells(struct device_node *np);
extern struct property *of_find_property(const struct device_node *np,
@@ -330,11 +332,21 @@ static inline struct device_d *of_platform_device_create(struct device_node *np,
return NULL;
}
+static inline int of_bus_n_addr_cells(struct device_node *np)
+{
+ return 0;
+}
+
static inline int of_n_addr_cells(struct device_node *np)
{
return 0;
}
+static inline int of_bus_n_size_cells(struct device_node *np)
+{
+ return 0;
+}
+
static inline int of_n_size_cells(struct device_node *np)
{
return 0;
|