Skip to content

Commit cefe6d6

Browse files
GuEe-GUIRbb666
authored andcommitted
[DM/FEATURE] Support driver depends fix auto
We need a API to fix the driver load auto when a second driver get it in probe process that we can not be careful of the driver-to-driver's depends in different SoC. Signed-off-by: GuEe-GUI <[email protected]>
1 parent 1bef42c commit cefe6d6

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

components/drivers/core/platform_ofw.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <drivers/ofw_io.h>
1818
#include <drivers/ofw_fdt.h>
1919
#include <drivers/platform.h>
20+
#include <drivers/core/bus.h>
2021
#include <drivers/core/dm.h>
2122

2223
#include "../ofw/ofw_internal.h"
@@ -161,6 +162,7 @@ static rt_err_t platform_ofw_device_probe_once(struct rt_ofw_node *parent_np)
161162
}
162163

163164
pdev->dev_id = ofw_alias_node_id(np);
165+
np->dev = &pdev->parent;
164166
LOG_D("%s register to bus", np->full_name);
165167

166168
rt_platform_device_register(pdev);
@@ -199,6 +201,53 @@ rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np)
199201
return err;
200202
}
201203

204+
rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np)
205+
{
206+
rt_err_t err;
207+
208+
if (np)
209+
{
210+
struct rt_device *dev = np->dev;
211+
212+
if (dev)
213+
{
214+
/* Was create */
215+
if (dev->drv)
216+
{
217+
/* Was probe OK */
218+
err = RT_EOK;
219+
}
220+
else
221+
{
222+
err = rt_bus_reload_driver_device(dev->bus, dev);
223+
}
224+
}
225+
else
226+
{
227+
struct rt_platform_device *pdev = alloc_ofw_platform_device(np);
228+
229+
if (pdev)
230+
{
231+
pdev->dev_id = ofw_alias_node_id(np);
232+
np->dev = &pdev->parent;
233+
LOG_D("%s register to bus", np->full_name);
234+
235+
err = rt_platform_device_register(pdev);
236+
}
237+
else
238+
{
239+
err = -RT_ENOMEM;
240+
}
241+
}
242+
}
243+
else
244+
{
245+
err = -RT_EINVAL;
246+
}
247+
248+
return err;
249+
}
250+
202251
static int platform_ofw_device_probe(void)
203252
{
204253
rt_err_t err = RT_EOK;

components/drivers/include/drivers/ofw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct rt_ofw_node
3737
/* phandles range from 1 to 2^32-2 (0xfffffffe) */
3838
rt_phandle phandle;
3939

40+
struct rt_device *dev;
4041
struct rt_ofw_prop *props;
4142
struct rt_ofw_node *parent;
4243
struct rt_ofw_node *child;

components/drivers/include/drivers/platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ rt_err_t rt_platform_driver_register(struct rt_platform_driver *pdrv);
4545
rt_err_t rt_platform_device_register(struct rt_platform_device *pdev);
4646

4747
rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np);
48+
rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np);
4849
rt_err_t rt_platform_ofw_free(struct rt_platform_device *pdev);
4950

5051
#define RT_PLATFORM_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, platform, BUILIN)

0 commit comments

Comments
 (0)