Skip to content

[Feature] Support simple power domain API #9005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading