1 /* 2 * Copyright (c) 2022 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef ZEPHYR_SOC_INTEL_ADSP_CAVS_CLK_H_ 7 #define ZEPHYR_SOC_INTEL_ADSP_CAVS_CLK_H_ 8 9 #include <stdint.h> 10 #include <adsp_shim.h> 11 12 struct adsp_cpu_clock_info { 13 uint32_t default_freq; 14 uint32_t current_freq; 15 uint32_t lowest_freq; 16 }; 17 18 void adsp_clock_init(void); 19 20 /** @brief Set cAVS clock frequency 21 * 22 * Set xtensa core clock speed. 23 * 24 * @param freq Clock frequency index to be set 25 * 26 * @return 0 on success, -EINVAL if freq_idx is not valid 27 */ 28 int adsp_clock_set_cpu_freq(uint32_t freq_idx); 29 30 /** @brief Get list of cAVS clock information 31 * 32 * Returns an array of clock information, one for each core. 33 * 34 * @return array with clock information 35 */ 36 struct adsp_cpu_clock_info *adsp_cpu_clocks_get(void); 37 38 /* Device tree defined constants */ 39 #ifdef CONFIG_SOC_SERIES_INTEL_ADSP_ACE 40 #define ADSP_CLKCTL ACE_DfPMCCU.dfclkctl 41 #else 42 #define ADSP_CLKCTL CAVS_SHIM.clkctl 43 #endif 44 45 #define ADSP_CPU_CLOCK_FREQ_ENC DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_freq_enc) 46 #define ADSP_CPU_CLOCK_FREQ_MASK DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_freq_mask) 47 #define ADSP_CPU_CLOCK_FREQ_LEN DT_PROP_LEN(DT_NODELABEL(clkctl), adsp_clkctl_freq_enc) 48 49 #define ADSP_CPU_CLOCK_FREQ_DEFAULT DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_freq_default) 50 #define ADSP_CPU_CLOCK_FREQ_LOWEST DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_freq_lowest) 51 52 #define ADSP_CPU_CLOCK_FREQ(name) DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_clk_##name) 53 54 #define ADSP_CLOCK_HAS_WOVCRO DT_PROP(DT_NODELABEL(clkctl), wovcro_supported) 55 56 #define ADSP_CPU_CLOCK_FREQ_LPRO ADSP_CPU_CLOCK_FREQ(lpro) 57 #define ADSP_CPU_CLOCK_FREQ_HPRO ADSP_CPU_CLOCK_FREQ(hpro) 58 #if ADSP_CLOCK_HAS_WOVCRO 59 #define ADSP_CPU_CLOCK_FREQ_WOVCRO ADSP_CPU_CLOCK_FREQ(wovcro) 60 #endif 61 62 #define ADSP_CPU_CLOCK_FREQ_IPLL ADSP_CPU_CLOCK_FREQ(ipll) 63 64 65 /* Clock sources used by dai */ 66 #define ADSP_CLOCK_SOURCE_XTAL_OSC 0 67 #if DT_NODE_HAS_STATUS(DT_NODELABEL(audioclk), okay) 68 #define ADSP_CLOCK_SOURCE_AUDIO_CARDINAL 1 69 #endif 70 #if DT_NODE_HAS_STATUS(DT_NODELABEL(pllclk), okay) 71 #define ADSP_CLOCK_SOURCE_AUDIO_PLL_FIXED 2 72 #endif 73 74 #define ADSP_CLOCK_SOURCE_MLCK_INPUT 3 75 #if ADSP_CLOCK_HAS_WOVCRO 76 #define ADSP_CLOCK_SOURCE_WOV_RING_OSC 4 77 #endif 78 #define ADSP_CLOCK_SOURCE_COUNT 5 79 80 struct adsp_clock_source_desc { 81 uint32_t frequency; 82 }; 83 84 /** @brief Check if clock source is supported 85 * 86 * @param freq Clock frequency index 87 * 88 * @return true if clock source is supported 89 */ 90 bool adsp_clock_source_is_supported(int source); 91 92 /** @brief Get clock source frequency 93 * 94 * @param freq Clock frequency index 95 * 96 * @return frequency on success, 0 on error 97 */ 98 uint32_t adsp_clock_source_frequency(int source); 99 100 #endif /* ZEPHYR_SOC_INTEL_ADSP_CAVS_CLK_H_ */ 101