| 
 | 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 | +#include <nrfs_backend_ipc_service.h>  | 
 | 11 | + | 
 | 12 | +LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);  | 
 | 13 | + | 
 | 14 | +#define GLOBAL_HSFLL_MIN_FREQ_HZ \  | 
 | 15 | +	CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_HZ  | 
 | 16 | + | 
 | 17 | +#define NRFS_BACKEND_TIMEOUT \  | 
 | 18 | +	K_MSEC(CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS)  | 
 | 19 | + | 
 | 20 | +#define GLOBAL_HSFLL_REQUEST_TIMEOUT_MS \  | 
 | 21 | +	CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS  | 
 | 22 | + | 
 | 23 | +static struct onoff_client cli;  | 
 | 24 | +static const struct device *global_hsfll = DEVICE_DT_GET(DT_NODELABEL(hsfll120));  | 
 | 25 | +static const struct nrf_clock_spec spec = {  | 
 | 26 | +	.frequency = GLOBAL_HSFLL_MIN_FREQ_HZ,  | 
 | 27 | +};  | 
 | 28 | + | 
 | 29 | +static int nordicsemi_nrf54h_global_hsfll_init(void)  | 
 | 30 | +{  | 
 | 31 | +	int ret;  | 
 | 32 | +	int res;  | 
 | 33 | +	bool completed;  | 
 | 34 | + | 
 | 35 | +	nrfs_backend_wait_for_connection(NRFS_BACKEND_TIMEOUT);  | 
 | 36 | + | 
 | 37 | +	sys_notify_init_spinwait(&cli.notify);  | 
 | 38 | + | 
 | 39 | +	ret = nrf_clock_control_request(global_hsfll, &spec, &cli);  | 
 | 40 | +	if (ret) {  | 
 | 41 | +		return ret;  | 
 | 42 | +	}  | 
 | 43 | + | 
 | 44 | +	res = -EIO;  | 
 | 45 | +	completed = WAIT_FOR(sys_notify_fetch_result(&cli.notify, &res) == 0,  | 
 | 46 | +			     GLOBAL_HSFLL_REQUEST_TIMEOUT_MS,  | 
 | 47 | +			     k_msleep(1));  | 
 | 48 | + | 
 | 49 | +	if (!completed || res) {  | 
 | 50 | +		LOG_ERR("Failed to restrict global HSFLL frequency");  | 
 | 51 | +		return -EIO;  | 
 | 52 | +	}  | 
 | 53 | + | 
 | 54 | +	return 0;  | 
 | 55 | +}  | 
 | 56 | + | 
 | 57 | +SYS_INIT(nordicsemi_nrf54h_global_hsfll_init, POST_KERNEL, 99);  | 
0 commit comments