|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/drivers/clock_control/nrf_clock_control.h> |
| 8 | +#include <zephyr/kernel.h> |
| 9 | +#include <zephyr/logging/log.h> |
| 10 | + |
| 11 | +LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); |
| 12 | + |
| 13 | +#if CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_64_MHZ |
| 14 | +#define GLOBAL_HSFLL_MIN_FREQ_HZ 64000000 |
| 15 | +#elif CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_128_MHZ |
| 16 | +#define GLOBAL_HSFLL_MIN_FREQ_HZ 128000000 |
| 17 | +#elif CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_256_MHZ |
| 18 | +#define GLOBAL_HSFLL_MIN_FREQ_HZ 256000000 |
| 19 | +#else |
| 20 | +#define GLOBAL_HSFLL_MIN_FREQ_HZ 320000000 |
| 21 | +#endif |
| 22 | + |
| 23 | +#define GLOBAL_HSFLL_REQUEST_TIMEOUT_US \ |
| 24 | + (CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS * USEC_PER_SEC) |
| 25 | + |
| 26 | +static struct onoff_client cli; |
| 27 | +static const struct device *global_hsfll = DEVICE_DT_GET(DT_NODELABEL(hsfll120)); |
| 28 | +static const struct nrf_clock_spec spec = { |
| 29 | + .frequency = GLOBAL_HSFLL_MIN_FREQ_HZ, |
| 30 | +}; |
| 31 | + |
| 32 | +static int nordicsemi_nrf54h_global_hsfll_init(void) |
| 33 | +{ |
| 34 | + int ret; |
| 35 | + int res; |
| 36 | + bool completed; |
| 37 | + |
| 38 | + sys_notify_init_spinwait(&cli.notify); |
| 39 | + |
| 40 | + ret = nrf_clock_control_request(global_hsfll, &spec, &cli); |
| 41 | + if (ret) { |
| 42 | + return ret; |
| 43 | + } |
| 44 | + |
| 45 | + res = -EIO; |
| 46 | + completed = WAIT_FOR(sys_notify_fetch_result(&cli.notify, &res) == 0, |
| 47 | + GLOBAL_HSFLL_REQUEST_TIMEOUT_US, |
| 48 | + k_msleep(1)); |
| 49 | + |
| 50 | + if (!completed) { |
| 51 | + LOG_ERR("%s request timed out", "Restrict global HSFLL"); |
| 52 | + return -EIO; |
| 53 | + } |
| 54 | + |
| 55 | + if (res) { |
| 56 | + LOG_ERR("%s request failed: (res=%i)", "Restrict global HSFLL", res); |
| 57 | + return res; |
| 58 | + } |
| 59 | + |
| 60 | + LOG_INF("%s to %uHz", "Restrict global HSFLL", GLOBAL_HSFLL_MIN_FREQ_HZ); |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +SYS_INIT(nordicsemi_nrf54h_global_hsfll_init, POST_KERNEL, 99); |
0 commit comments