17
17
#include <drivers/platform.h>
18
18
#include <drivers/core/dm.h>
19
19
20
+ #include "../ofw/ofw_internal.h"
21
+
20
22
static const struct rt_ofw_node_id platform_ofw_ids [] =
21
23
{
22
24
{ .compatible = "simple-bus" , },
@@ -35,11 +37,32 @@ static const struct rt_ofw_node_id platform_ofw_ids[] =
35
37
#endif
36
38
{ /* sentinel */ }
37
39
};
40
+ static struct rt_platform_device * alloc_ofw_platform_device (struct rt_ofw_node * np )
41
+ {
42
+ struct rt_platform_device * pdev = rt_platform_device_alloc (np -> name );
43
+
44
+ if (pdev )
45
+ {
46
+ /* inc reference of dt-node */
47
+ rt_ofw_node_get (np );
48
+ rt_ofw_node_set_flag (np , RT_OFW_F_PLATFORM );
49
+
50
+ #ifdef RT_USING_OFW
51
+ pdev -> parent .ofw_node = np ;
52
+ #endif
53
+ }
54
+ else
55
+ {
56
+ LOG_E ("Alloc device fail for %s" , rt_ofw_node_full_name (np ));
57
+ }
58
+
59
+ return pdev ;
60
+ }
38
61
39
62
static rt_err_t platform_ofw_device_probe_once (struct rt_ofw_node * parent_np )
40
63
{
41
64
rt_err_t err = RT_EOK ;
42
- struct rt_ofw_node * np , * child ;
65
+ struct rt_ofw_node * np ;
43
66
struct rt_platform_device * pdev ;
44
67
45
68
rt_ofw_foreach_available_child_node (parent_np , np )
@@ -48,6 +71,8 @@ static rt_err_t platform_ofw_device_probe_once(struct rt_ofw_node *parent_np)
48
71
struct rt_ofw_node_id * id ;
49
72
struct rt_ofw_prop * compat_prop = RT_NULL ;
50
73
74
+ LOG_D ("%s found in %s" , np -> full_name , parent_np -> full_name );
75
+
51
76
/* Is system node or have driver */
52
77
if (rt_ofw_node_test_flag (np , RT_OFW_F_SYSTEM ) ||
53
78
rt_ofw_node_test_flag (np , RT_OFW_F_READLY ))
@@ -66,54 +91,91 @@ static rt_err_t platform_ofw_device_probe_once(struct rt_ofw_node *parent_np)
66
91
67
92
id = rt_ofw_prop_match (compat_prop , platform_ofw_ids );
68
93
69
- if (id && ( child = rt_ofw_get_next_child ( np , RT_NULL )) )
94
+ if (id && np -> child )
70
95
{
71
96
/* scan next level */
72
- err = platform_ofw_device_probe_once (child );
73
-
74
- rt_ofw_node_put (child );
97
+ err = platform_ofw_device_probe_once (np );
75
98
76
99
if (err )
77
100
{
101
+ rt_ofw_node_put (np );
78
102
LOG_E ("%s bus probe fail" , np -> full_name );
79
103
80
104
break ;
81
105
}
82
106
}
83
107
84
- pdev = rt_platform_device_alloc (np -> name );
108
+ pdev = alloc_ofw_platform_device (np );
85
109
86
110
if (!pdev )
87
111
{
112
+ rt_ofw_node_put (np );
88
113
err = - RT_ENOMEM ;
89
114
90
115
break ;
91
116
}
92
117
93
- /* inc reference of dt-node */
94
- rt_ofw_node_get (np );
95
- rt_ofw_node_set_flag (np , RT_OFW_F_PLATFORM );
96
-
97
- pdev -> parent .ofw_node = np ;
118
+ pdev -> dev_id = ofw_alias_node_id (np );
119
+ LOG_D ("%s register to bus" , np -> full_name );
98
120
99
121
rt_platform_device_register (pdev );
100
122
}
101
123
102
124
return err ;
103
125
}
104
126
127
+ rt_err_t rt_platform_ofw_device_probe_child (struct rt_ofw_node * np )
128
+ {
129
+ rt_err_t err ;
130
+ struct rt_ofw_node * parent = rt_ofw_get_parent (np );
131
+
132
+ if (parent && rt_strcmp (parent -> name , "/" ) &&
133
+ rt_ofw_get_prop (np , "compatible" , RT_NULL ) &&
134
+ !rt_ofw_node_test_flag (np , RT_OFW_F_PLATFORM ))
135
+ {
136
+ struct rt_platform_device * pdev = alloc_ofw_platform_device (np );
137
+
138
+ if (pdev )
139
+ {
140
+ err = rt_platform_device_register (pdev );
141
+ }
142
+ else
143
+ {
144
+ err = - RT_ENOMEM ;
145
+ }
146
+ }
147
+ else
148
+ {
149
+ err = - RT_EINVAL ;
150
+ }
151
+
152
+ rt_ofw_node_put (parent );
153
+
154
+ return err ;
155
+ }
156
+
105
157
static int platform_ofw_device_probe (void )
106
158
{
107
159
rt_err_t err = RT_EOK ;
108
- struct rt_ofw_node * root_np ;
109
-
110
- root_np = rt_ofw_find_node_by_path ("/" );
160
+ struct rt_ofw_node * node ;
111
161
112
- if (root_np )
162
+ if (ofw_node_root )
113
163
{
114
- err = platform_ofw_device_probe_once (root_np );
164
+ err = platform_ofw_device_probe_once (ofw_node_root );
115
165
116
- rt_ofw_node_put (root_np );
166
+ rt_ofw_node_put (ofw_node_root );
167
+
168
+ if ((node = rt_ofw_find_node_by_path ("/firmware" )))
169
+ {
170
+ platform_ofw_device_probe_once (node );
171
+ rt_ofw_node_put (node );
172
+ }
173
+
174
+ if ((node = rt_ofw_get_child_by_compatible (ofw_node_chosen , "simple-framebuffer" )))
175
+ {
176
+ platform_ofw_device_probe_once (node );
177
+ rt_ofw_node_put (node );
178
+ }
117
179
}
118
180
else
119
181
{
0 commit comments