Skip to content

Commit

Permalink
[Feature] Support simple power domain API (RT-Thread#9005)
Browse files Browse the repository at this point in the history
* [Feature] Power domain for device

1.Support device power on/off.
2.Support attach/detach device.
3.Support power domain driver api.

Signed-off-by: GuEe-GUI <[email protected]>

* [DM/platform] Enhanced platform bus

1.Add power domain for device.
2.Support `remove` and `shutdown` bus interface.

Signed-off-by: GuEe-GUI <[email protected]>

---------

Signed-off-by: GuEe-GUI <[email protected]>
  • Loading branch information
GuEe-GUI authored May 30, 2024
1 parent 2cbe8bd commit e7cddf3
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/drivers/core/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if GetDepend(['RT_USING_DEV_BUS']) or GetDepend(['RT_USING_DM']):
src = src + ['bus.c']

if GetDepend(['RT_USING_DM']):
src = src + ['dm.c', 'driver.c', 'numa.c', 'platform.c']
src = src + ['dm.c', 'driver.c', 'numa.c', 'platform.c', 'power_domain.c']

if GetDepend(['RT_USING_DFS']):
src += ['mnt.c'];
Expand Down
46 changes: 46 additions & 0 deletions components/drivers/core/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <drivers/platform.h>
#include <drivers/core/bus.h>
#include <drivers/core/dm.h>
#include <drivers/core/power_domain.h>

static struct rt_bus platform_bus;

Expand Down Expand Up @@ -118,6 +119,15 @@ static rt_err_t platform_probe(rt_device_t dev)
struct rt_ofw_node *np = dev->ofw_node;
#endif

err = rt_dm_power_domain_attach(dev, RT_TRUE);

if (err && err != -RT_EEMPTY)
{
LOG_E("Attach power domain error = %s in device %s", pdev->name, rt_strerror(err));

return err;
}

err = pdrv->probe(pdev);

if (!err)
Expand All @@ -135,16 +145,52 @@ static rt_err_t platform_probe(rt_device_t dev)
{
LOG_W("System not memory in driver %s", pdrv->name);
}

rt_dm_power_domain_detach(dev, RT_TRUE);
}

return err;
}

static rt_err_t platform_remove(rt_device_t dev)
{
struct rt_platform_driver *pdrv = rt_container_of(dev->drv, struct rt_platform_driver, parent);
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);

if (pdrv && pdrv->remove)
{
pdrv->remove(pdev);
}

rt_dm_power_domain_detach(dev, RT_TRUE);
rt_platform_ofw_free(pdev);

return RT_EOK;
}

static rt_err_t platform_shutdown(rt_device_t dev)
{
struct rt_platform_driver *pdrv = rt_container_of(dev->drv, struct rt_platform_driver, parent);
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);

if (pdrv && pdrv->shutdown)
{
pdrv->shutdown(pdev);
}

rt_dm_power_domain_detach(dev, RT_TRUE);
rt_platform_ofw_free(pdev);

return RT_EOK;
}

static struct rt_bus platform_bus =
{
.name = "platform",
.match = platform_match,
.probe = platform_probe,
.remove = platform_remove,
.shutdown = platform_shutdown,
};

static int platform_bus_init(void)
Expand Down
26 changes: 24 additions & 2 deletions components/drivers/core/platform_ofw.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ static struct rt_platform_device *alloc_ofw_platform_device(struct rt_ofw_node *
rt_ofw_node_get(np);
rt_ofw_node_set_flag(np, RT_OFW_F_PLATFORM);

#ifdef RT_USING_OFW
pdev->parent.ofw_node = np;
#endif

ofw_device_rename(&pdev->parent);
}
Expand Down Expand Up @@ -232,3 +230,27 @@ static int platform_ofw_device_probe(void)
return (int)err;
}
INIT_PLATFORM_EXPORT(platform_ofw_device_probe);

rt_err_t rt_platform_ofw_free(struct rt_platform_device *pdev)
{
rt_err_t err = RT_EOK;

if (pdev)
{
struct rt_ofw_node *np = pdev->parent.ofw_node;

if (np)
{
rt_ofw_node_clear_flag(np, RT_OFW_F_PLATFORM);
rt_ofw_node_put(np);

pdev->parent.ofw_node = RT_NULL;
}
}
else
{
err = -RT_EINVAL;
}

return err;
}
Loading

0 comments on commit e7cddf3

Please sign in to comment.