diff --git a/components/drivers/core/platform_ofw.c b/components/drivers/core/platform_ofw.c index 3a5554f235..5b8fa92b67 100644 --- a/components/drivers/core/platform_ofw.c +++ b/components/drivers/core/platform_ofw.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "../ofw/ofw_internal.h" @@ -161,6 +162,7 @@ static rt_err_t platform_ofw_device_probe_once(struct rt_ofw_node *parent_np) } pdev->dev_id = ofw_alias_node_id(np); + np->dev = &pdev->parent; LOG_D("%s register to bus", np->full_name); rt_platform_device_register(pdev); @@ -199,6 +201,53 @@ rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np) return err; } +rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np) +{ + rt_err_t err; + + if (np) + { + struct rt_device *dev = np->dev; + + if (dev) + { + /* Was create */ + if (dev->drv) + { + /* Was probe OK */ + err = RT_EOK; + } + else + { + err = rt_bus_reload_driver_device(dev->bus, dev); + } + } + else + { + struct rt_platform_device *pdev = alloc_ofw_platform_device(np); + + if (pdev) + { + pdev->dev_id = ofw_alias_node_id(np); + np->dev = &pdev->parent; + LOG_D("%s register to bus", np->full_name); + + err = rt_platform_device_register(pdev); + } + else + { + err = -RT_ENOMEM; + } + } + } + else + { + err = -RT_EINVAL; + } + + return err; +} + static int platform_ofw_device_probe(void) { rt_err_t err = RT_EOK; diff --git a/components/drivers/include/drivers/ofw.h b/components/drivers/include/drivers/ofw.h index aec5ba451a..3f23017b57 100644 --- a/components/drivers/include/drivers/ofw.h +++ b/components/drivers/include/drivers/ofw.h @@ -37,6 +37,7 @@ struct rt_ofw_node /* phandles range from 1 to 2^32-2 (0xfffffffe) */ rt_phandle phandle; + struct rt_device *dev; struct rt_ofw_prop *props; struct rt_ofw_node *parent; struct rt_ofw_node *child; diff --git a/components/drivers/include/drivers/platform.h b/components/drivers/include/drivers/platform.h index ba927fee7d..c4a497d0a1 100644 --- a/components/drivers/include/drivers/platform.h +++ b/components/drivers/include/drivers/platform.h @@ -45,6 +45,7 @@ rt_err_t rt_platform_driver_register(struct rt_platform_driver *pdrv); rt_err_t rt_platform_device_register(struct rt_platform_device *pdev); rt_err_t rt_platform_ofw_device_probe_child(struct rt_ofw_node *np); +rt_err_t rt_platform_ofw_request(struct rt_ofw_node *np); rt_err_t rt_platform_ofw_free(struct rt_platform_device *pdev); #define RT_PLATFORM_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, platform, BUILIN)