Skip to content

Commit 43c34bb

Browse files
kv2019ilgirdwood
authored andcommitted
audio: make clock control optional in SOF Zephyr builds
Mark the few places in generic SOF code where SOF clock control interface is used. These cases are few as most usage has traditionally been in XTOS drivers and platform code. In Zephyr builds these are not used, making the clock interface mostly unnecessary. The one bigger exception is CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL feature for dynamically adjusting the DSP clock frequency based on IPC messages and audio pipeline configuration. This is an optional feature not used by all targets, so the requirement to have a clock abstraction implemented, should also be optional. Remaining uses are for IPC4 base firmware attributes and some informational use in logging. None of these are e.g. required by SOF Linux driver for any essential functionality, so can be disabled without side-effects. As the rtos/clk.h interfaces are still used in many places in platform code, this patch adds a new transition tool in form of CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK Kconfig option. This allows to incrementally transition targets to not use the clock framework. In longer term, the remaining uses will be transitioned to use Zephyr clock-control.h directly Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 4032f17 commit 43c34bb

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/audio/base_fw.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ static int basefw_config(uint32_t *data_offset, char *data)
5858
tuple = tlv_next(tuple);
5959
tlv_value_uint32_set(tuple, IPC4_MEMORY_RECLAIMED_FW_CFG, 1);
6060

61+
#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK
6162
tuple = tlv_next(tuple);
6263
tlv_value_uint32_set(tuple, IPC4_FAST_CLOCK_FREQ_HZ_FW_CFG, CLK_MAX_CPU_HZ);
6364

6465
tuple = tlv_next(tuple);
6566
tlv_value_uint32_set(tuple,
6667
IPC4_SLOW_CLOCK_FREQ_HZ_FW_CFG,
6768
clock_get_freq(CPU_LOWEST_FREQ_IDX));
69+
#endif
6870

6971
tuple = tlv_next(tuple);
7072
tlv_value_uint32_set(tuple, IPC4_DL_MAILBOX_BYTES_FW_CFG, MAILBOX_HOSTBOX_SIZE);
@@ -220,17 +222,21 @@ static int basefw_register_kcps(bool first_block,
220222
if (!(first_block && last_block))
221223
return IPC4_ERROR_INVALID_PARAM;
222224

225+
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
223226
/* value of kcps to request on core 0. Can be negative */
224227
if (core_kcps_adjust(0, *(int32_t *)data))
225228
return IPC4_ERROR_INVALID_PARAM;
229+
#endif
226230

227231
return IPC4_SUCCESS;
228232
}
229233

230234
static int basefw_kcps_allocation_request(struct ipc4_resource_kcps *request)
231235
{
236+
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
232237
if (core_kcps_adjust(request->core_id, request->kcps))
233238
return IPC4_ERROR_INVALID_PARAM;
239+
#endif
234240

235241
return IPC4_SUCCESS;
236242
}
@@ -259,6 +265,7 @@ static int basefw_resource_allocation_request(bool first_block,
259265

260266
static int basefw_power_state_info_get(uint32_t *data_offset, char *data)
261267
{
268+
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
262269
struct sof_tlv *tuple = (struct sof_tlv *)data;
263270
uint32_t core_kcps[CONFIG_CORE_COUNT] = {0};
264271
int core_id;
@@ -275,6 +282,9 @@ static int basefw_power_state_info_get(uint32_t *data_offset, char *data)
275282
tuple = tlv_next(tuple);
276283
*data_offset = (int)((char *)tuple - data);
277284
return IPC4_SUCCESS;
285+
#else
286+
return IPC4_UNAVAILABLE;
287+
#endif
278288
}
279289

280290
static int basefw_libraries_info_get(uint32_t *data_offset, char *data)

src/audio/pipeline/pipeline-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int pipeline_complete(struct pipeline *p, struct comp_dev *source,
282282
.comp_data = &data,
283283
};
284284

285-
#if !UNIT_TEST && !CONFIG_LIBRARY
285+
#if !UNIT_TEST && !CONFIG_LIBRARY && CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
286286
int __maybe_unused freq = clock_get_freq(cpu_get_id());
287287
#else
288288
int __maybe_unused freq = 0;

zephyr/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,7 @@ zephyr_library_sources(
490490
${SOF_MATH_PATH}/exp_fcn_hifi.c
491491

492492
# SOF library - parts to transition to Zephyr over time
493-
${SOF_LIB_PATH}/clk.c
494493
${SOF_LIB_PATH}/notifier.c
495-
${SOF_LIB_PATH}/cpu-clk-manager.c
496494
${SOF_LIB_PATH}/dma.c
497495
${SOF_LIB_PATH}/dai.c
498496

@@ -530,6 +528,14 @@ zephyr_library_sources(
530528
lib.c
531529
)
532530

531+
if(NOT CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK)
532+
zephyr_library_sources(${SOF_LIB_PATH}/clk.c)
533+
endif()
534+
535+
zephyr_library_sources_ifdef(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
536+
${SOF_LIB_PATH}/cpu-clk-manager.c
537+
)
538+
533539
# Optional math utility
534540
zephyr_library_sources_ifdef(CONFIG_MATH_LUT_SINE_FIXED
535541
${SOF_MATH_PATH}/lut_trig.c

zephyr/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ config SOF_BOOT_TEST
7676
initialized. After that SOF will continue running and be usable as
7777
usual.
7878

79+
config SOF_ZEPHYR_NO_SOF_CLOCK
80+
bool
81+
help
82+
Do not use SOF clk.h interface to set the DSP clock frequency.
83+
Requires implementation of platform/lib/clk.h.
84+
7985
endif

zephyr/include/rtos/clk.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#ifndef __ZEPHYR_RTOS_CLK_H__
77
#define __ZEPHYR_RTOS_CLK_H__
88

9+
#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK
10+
911
#include <zephyr/kernel.h>
1012

11-
/* TODO remove once drivers upstream */
1213
#define __SOF_LIB_CLK_H__
1314
#include <platform/lib/clk.h>
1415

@@ -77,4 +78,6 @@ static inline struct clock_info *clocks_get(void)
7778
return sof_get()->clocks;
7879
}
7980

81+
#endif /* CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK */
82+
8083
#endif /* __ZEPHYR_RTOS_CLK_H__ */

0 commit comments

Comments
 (0)