Skip to content

Commit e32d2a9

Browse files
committed
soc: ti: Turns on power domains in soc layer
Turns on all the power domains for devices with a power-domain device tree property in the soc layer. Supported for the R5f0_0 core on the AM243x EVM. Signed-off-by: Dave Joseph <[email protected]>
1 parent 965bcd6 commit e32d2a9

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

boards/ti/am243x_evm/am243x_evm_am2434_r5f0_0_defconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ CONFIG_UART_CONSOLE=y
1515

1616
# Enable MPU
1717
CONFIG_ARM_MPU=y
18+
19+
#Enable runtime power management
20+
CONFIG_PM_DEVICE=y
21+
CONFIG_POWER_DOMAIN=y
22+
CONFIG_PM=y
23+
CONFIG_PM_DEVICE_RUNTIME=y
24+
25+
#Enable clock control
26+
CONFIG_CLOCK_CONTROL=y

soc/ti/k3/am6x/r5/soc.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
*/
66

77
#include <stdint.h>
8+
#include <stdio.h>
9+
#include <string.h>
810
#include <zephyr/fatal.h>
9-
11+
#include <zephyr/logging/log.h>
1012
#include "soc.h"
13+
#include "zephyr/sys/util_macro.h"
14+
#include <zephyr/device.h>
1115
#include <common/ctrl_partitions.h>
16+
#include <zephyr/pm/device_runtime.h>
17+
#include <zephyr/drivers/clock_control.h>
18+
#include <zephyr/drivers/clock_control/tisci_clock_control.h>
19+
LOG_MODULE_REGISTER(soc, LOG_LEVEL_DBG);
1220

1321
unsigned int z_soc_irq_get_active(void)
1422
{
@@ -53,3 +61,57 @@ void soc_early_init_hook(void)
5361
{
5462
k3_unlock_all_ctrl_partitions();
5563
}
64+
65+
#if defined(CONFIG_POWER_DOMAIN)
66+
int soc_power_domain_init(void)
67+
{
68+
LOG_INF("Starting power domain initialization\n");
69+
70+
int error_count = 0;
71+
72+
#define CHECK_NODE_POWER_DOMAIN(child) \
73+
COND_CODE_1 (DT_NODE_HAS_PROP(child, power_domains),( { \
74+
const struct device *dev_##child = \
75+
DEVICE_DT_GET(DT_PHANDLE(child, power_domains)); \
76+
LOG_INF("Turning on power domain: %s\n", dev_##child->name); \
77+
int err = pm_device_runtime_get(dev_##child); \
78+
if (err < 0) { \
79+
LOG_INF("Failed to get power domain: %s\n", dev_##child->name); \
80+
error_count++; \
81+
} \
82+
}),(/* Do nothing */) )
83+
84+
DT_FOREACH_CHILD(DT_ROOT, CHECK_NODE_POWER_DOMAIN);
85+
86+
return error_count;
87+
}
88+
SYS_INIT(soc_power_domain_init, POST_KERNEL, 0);
89+
#endif /* CONFIG_POWER_DOMAIN */
90+
91+
#if defined(CONFIG_CLOCK_CONTROL)
92+
int soc_clock_init(void)
93+
{
94+
LOG_INF("Starting clock initialization\n");
95+
96+
int error_count = 0;
97+
98+
#define CHECK_NODE_CLOCK(child) \
99+
COND_CODE_1(DT_NODE_HAS_PROP(child, clocks), \
100+
({ \
101+
const struct device *dev_##child = TISCI_GET_CLOCK(child); \
102+
struct tisci_clock_config req_##child = TISCI_GET_CLOCK_DETAILS(child); \
103+
uint64_t freq_##child = DT_PROP(child, clock_frequency); \
104+
if (clock_control_set_rate(dev_##child, &req_##child, &freq_##child)) { \
105+
printf("Failed to set clock rate for %s\n", dev_##child->name); \
106+
error_count++; \
107+
} \
108+
}), \
109+
(/* Do nothing */) \
110+
)
111+
112+
DT_FOREACH_CHILD(DT_ROOT, CHECK_NODE_CLOCK);
113+
114+
return error_count;
115+
}
116+
SYS_INIT(soc_clock_init, POST_KERNEL, 0);
117+
#endif /* CONFIG_CLOCK_CONTROL */

0 commit comments

Comments
 (0)