|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | #include <stdint.h>
|
| 8 | +#include <stdio.h> |
| 9 | +#include <string.h> |
8 | 10 | #include <zephyr/fatal.h>
|
9 |
| - |
| 11 | +#include <zephyr/logging/log.h> |
10 | 12 | #include "soc.h"
|
| 13 | +#include "zephyr/sys/util_macro.h" |
| 14 | +#include <zephyr/device.h> |
11 | 15 | #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); |
12 | 20 |
|
13 | 21 | unsigned int z_soc_irq_get_active(void)
|
14 | 22 | {
|
@@ -53,3 +61,57 @@ void soc_early_init_hook(void)
|
53 | 61 | {
|
54 | 62 | k3_unlock_all_ctrl_partitions();
|
55 | 63 | }
|
| 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