summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuEe-GUI <[email protected]>2024-10-24 11:56:31 +0800
committerRbb666 <[email protected]>2024-11-18 15:03:23 +0800
commitcefe6d63805b89fb96aea69eb8e14fa12260192a (patch)
treec7ff3705ce4f35683f7b493314bdbbfed500b9d3
parent1bef42c64c2db3608814207a580e27e2673a4148 (diff)
[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]>
-rw-r--r--components/drivers/core/platform_ofw.c49
-rw-r--r--components/drivers/include/drivers/ofw.h1
-rw-r--r--components/drivers/include/drivers/platform.h1
3 files changed, 51 insertions, 0 deletions
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 <drivers/ofw_io.h>
#include <drivers/ofw_fdt.h>
#include <drivers/platform.h>
+#include <drivers/core/bus.h>
#include <drivers/core/dm.h>
#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)