Skip to content

Commit e7cddf3

Browse files
authored
[Feature] Support simple power domain API (#9005)
* [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]>
1 parent 2cbe8bd commit e7cddf3

File tree

10 files changed

+725
-3
lines changed

10 files changed

+725
-3
lines changed

components/drivers/core/SConscript

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if GetDepend(['RT_USING_DEV_BUS']) or GetDepend(['RT_USING_DM']):
88
src = src + ['bus.c']
99

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

1313
if GetDepend(['RT_USING_DFS']):
1414
src += ['mnt.c'];

components/drivers/core/platform.c

+46
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <drivers/platform.h>
1919
#include <drivers/core/bus.h>
2020
#include <drivers/core/dm.h>
21+
#include <drivers/core/power_domain.h>
2122

2223
static struct rt_bus platform_bus;
2324

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

122+
err = rt_dm_power_domain_attach(dev, RT_TRUE);
123+
124+
if (err && err != -RT_EEMPTY)
125+
{
126+
LOG_E("Attach power domain error = %s in device %s", pdev->name, rt_strerror(err));
127+
128+
return err;
129+
}
130+
121131
err = pdrv->probe(pdev);
122132

123133
if (!err)
@@ -135,16 +145,52 @@ static rt_err_t platform_probe(rt_device_t dev)
135145
{
136146
LOG_W("System not memory in driver %s", pdrv->name);
137147
}
148+
149+
rt_dm_power_domain_detach(dev, RT_TRUE);
138150
}
139151

140152
return err;
141153
}
142154

155+
static rt_err_t platform_remove(rt_device_t dev)
156+
{
157+
struct rt_platform_driver *pdrv = rt_container_of(dev->drv, struct rt_platform_driver, parent);
158+
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);
159+
160+
if (pdrv && pdrv->remove)
161+
{
162+
pdrv->remove(pdev);
163+
}
164+
165+
rt_dm_power_domain_detach(dev, RT_TRUE);
166+
rt_platform_ofw_free(pdev);
167+
168+
return RT_EOK;
169+
}
170+
171+
static rt_err_t platform_shutdown(rt_device_t dev)
172+
{
173+
struct rt_platform_driver *pdrv = rt_container_of(dev->drv, struct rt_platform_driver, parent);
174+
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);
175+
176+
if (pdrv && pdrv->shutdown)
177+
{
178+
pdrv->shutdown(pdev);
179+
}
180+
181+
rt_dm_power_domain_detach(dev, RT_TRUE);
182+
rt_platform_ofw_free(pdev);
183+
184+
return RT_EOK;
185+
}
186+
143187
static struct rt_bus platform_bus =
144188
{
145189
.name = "platform",
146190
.match = platform_match,
147191
.probe = platform_probe,
192+
.remove = platform_remove,
193+
.shutdown = platform_shutdown,
148194
};
149195

150196
static int platform_bus_init(void)

components/drivers/core/platform_ofw.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ static struct rt_platform_device *alloc_ofw_platform_device(struct rt_ofw_node *
9292
rt_ofw_node_get(np);
9393
rt_ofw_node_set_flag(np, RT_OFW_F_PLATFORM);
9494

95-
#ifdef RT_USING_OFW
9695
pdev->parent.ofw_node = np;
97-
#endif
9896

9997
ofw_device_rename(&pdev->parent);
10098
}
@@ -232,3 +230,27 @@ static int platform_ofw_device_probe(void)
232230
return (int)err;
233231
}
234232
INIT_PLATFORM_EXPORT(platform_ofw_device_probe);
233+
234+
rt_err_t rt_platform_ofw_free(struct rt_platform_device *pdev)
235+
{
236+
rt_err_t err = RT_EOK;
237+
238+
if (pdev)
239+
{
240+
struct rt_ofw_node *np = pdev->parent.ofw_node;
241+
242+
if (np)
243+
{
244+
rt_ofw_node_clear_flag(np, RT_OFW_F_PLATFORM);
245+
rt_ofw_node_put(np);
246+
247+
pdev->parent.ofw_node = RT_NULL;
248+
}
249+
}
250+
else
251+
{
252+
err = -RT_EINVAL;
253+
}
254+
255+
return err;
256+
}

0 commit comments

Comments
 (0)