Skip to content

Commit 64b2246

Browse files
softwareckinashif
authored andcommitted
soc: adsp: clk: Add multiple clock sources support for dai
Added a new function to check whether a clock source is supported by a platform and to retrieve its frequency. Signed-off-by: Adrian Warecki <[email protected]>
1 parent 1a4bc75 commit 64b2246

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

soc/xtensa/intel_adsp/common/clk.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,42 @@ void adsp_clock_init(void)
100100
platform_cpu_clocks[i].lowest_freq = platform_lowest_freq_idx;
101101
}
102102
}
103+
104+
struct adsp_clock_source_desc adsp_clk_src_info[ADSP_CLOCK_SOURCE_COUNT] = {
105+
#ifndef CONFIG_DAI_DMIC_HW_IOCLK
106+
[ADSP_CLOCK_SOURCE_XTAL_OSC] = { DT_PROP(DT_NODELABEL(sysclk), clock_frequency) },
107+
#else
108+
/* Temporarily use the values from the configuration until set xtal frequency via ipc
109+
* support is added.
110+
*/
111+
[ADSP_CLOCK_SOURCE_XTAL_OSC] = { CONFIG_DAI_DMIC_HW_IOCLK },
112+
#endif
113+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(audioclk), okay)
114+
[ADSP_CLOCK_SOURCE_AUDIO_CARDINAL] = { DT_PROP(DT_NODELABEL(audioclk), clock_frequency) },
115+
#endif
116+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllclk), okay)
117+
[ADSP_CLOCK_SOURCE_AUDIO_PLL_FIXED] = { DT_PROP(DT_NODELABEL(pllclk), clock_frequency) },
118+
#endif
119+
[ADSP_CLOCK_SOURCE_MLCK_INPUT] = { 0 },
120+
#ifdef ADSP_CLOCK_HAS_WOVCRO
121+
[ADSP_CLOCK_SOURCE_WOV_RING_OSC] = { DT_PROP(DT_NODELABEL(sysclk), clock_frequency) },
122+
#endif
123+
};
124+
125+
bool adsp_clock_source_is_supported(int source)
126+
{
127+
if (source < 0 || source >= ADSP_CLOCK_SOURCE_COUNT) {
128+
return false;
129+
}
130+
131+
return !!adsp_clk_src_info[source].frequency;
132+
}
133+
134+
uint32_t adsp_clock_source_frequency(int source)
135+
{
136+
if (source < 0 || source >= ADSP_CLOCK_SOURCE_COUNT) {
137+
return 0;
138+
}
139+
140+
return adsp_clk_src_info[source].frequency;
141+
}

soc/xtensa/intel_adsp/common/include/adsp_clk.h

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,57 @@ struct adsp_cpu_clock_info *adsp_cpu_clocks_get(void);
4242
#define ADSP_CLKCTL CAVS_SHIM.clkctl
4343
#endif
4444

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)
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)
4848

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)
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)
5151

52-
#define ADSP_CPU_CLOCK_FREQ(name) DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_clk_##name)
52+
#define ADSP_CPU_CLOCK_FREQ(name) DT_PROP(DT_NODELABEL(clkctl), adsp_clkctl_clk_##name)
5353

54-
#if DT_PROP(DT_NODELABEL(clkctl), wovcro_supported)
55-
#define ADSP_CLOCK_HAS_WOVCRO
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+
63+
/* Clock sources used by dai */
64+
#define ADSP_CLOCK_SOURCE_XTAL_OSC 0
65+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(audioclk), okay)
66+
#define ADSP_CLOCK_SOURCE_AUDIO_CARDINAL 1
67+
#endif
68+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(pllclk), okay)
69+
#define ADSP_CLOCK_SOURCE_AUDIO_PLL_FIXED 2
5670
#endif
5771

58-
#define ADSP_CPU_CLOCK_FREQ_LPRO ADSP_CPU_CLOCK_FREQ(lpro)
59-
#define ADSP_CPU_CLOCK_FREQ_HPRO ADSP_CPU_CLOCK_FREQ(hpro)
60-
#ifdef ADSP_CLOCK_HAS_WOVCRO
61-
#define ADSP_CPU_CLOCK_FREQ_WOVCRO ADSP_CPU_CLOCK_FREQ(wovcro)
72+
#define ADSP_CLOCK_SOURCE_MLCK_INPUT 3
73+
#if ADSP_CLOCK_HAS_WOVCRO
74+
#define ADSP_CLOCK_SOURCE_WOV_RING_OSC 4
6275
#endif
76+
#define ADSP_CLOCK_SOURCE_COUNT 5
77+
78+
struct adsp_clock_source_desc {
79+
uint32_t frequency;
80+
};
81+
82+
/** @brief Check if clock source is supported
83+
*
84+
* @param freq Clock frequency index
85+
*
86+
* @return true if clock source is supported
87+
*/
88+
bool adsp_clock_source_is_supported(int source);
89+
90+
/** @brief Get clock source frequency
91+
*
92+
* @param freq Clock frequency index
93+
*
94+
* @return frequency on success, 0 on error
95+
*/
96+
uint32_t adsp_clock_source_frequency(int source);
6397

6498
#endif /* ZEPHYR_SOC_INTEL_ADSP_CAVS_CLK_H_ */

0 commit comments

Comments
 (0)