Skip to content

Commit

Permalink
audio: make clock control optional in SOF Zephyr builds
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kv2019i committed Nov 21, 2024
1 parent 69f3b97 commit 215f4d6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/audio/base_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ static int basefw_config(uint32_t *data_offset, char *data)
tuple = tlv_next(tuple);
tlv_value_uint32_set(tuple, IPC4_MEMORY_RECLAIMED_FW_CFG, 1);

#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK
tuple = tlv_next(tuple);
tlv_value_uint32_set(tuple, IPC4_FAST_CLOCK_FREQ_HZ_FW_CFG, CLK_MAX_CPU_HZ);

tuple = tlv_next(tuple);
tlv_value_uint32_set(tuple,
IPC4_SLOW_CLOCK_FREQ_HZ_FW_CFG,
clock_get_freq(CPU_LOWEST_FREQ_IDX));
#endif

tuple = tlv_next(tuple);
tlv_value_uint32_set(tuple, IPC4_DL_MAILBOX_BYTES_FW_CFG, MAILBOX_HOSTBOX_SIZE);
Expand Down Expand Up @@ -220,17 +222,21 @@ static int basefw_register_kcps(bool first_block,
if (!(first_block && last_block))
return IPC4_ERROR_INVALID_PARAM;

#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
/* value of kcps to request on core 0. Can be negative */
if (core_kcps_adjust(0, *(int32_t *)data))
return IPC4_ERROR_INVALID_PARAM;
#endif

return IPC4_SUCCESS;
}

static int basefw_kcps_allocation_request(struct ipc4_resource_kcps *request)
{
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
if (core_kcps_adjust(request->core_id, request->kcps))
return IPC4_ERROR_INVALID_PARAM;
#endif

return IPC4_SUCCESS;
}
Expand Down Expand Up @@ -259,6 +265,7 @@ static int basefw_resource_allocation_request(bool first_block,

static int basefw_power_state_info_get(uint32_t *data_offset, char *data)
{
#if CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
struct sof_tlv *tuple = (struct sof_tlv *)data;
uint32_t core_kcps[CONFIG_CORE_COUNT] = {0};
int core_id;
Expand All @@ -275,6 +282,9 @@ static int basefw_power_state_info_get(uint32_t *data_offset, char *data)
tuple = tlv_next(tuple);
*data_offset = (int)((char *)tuple - data);
return IPC4_SUCCESS;
#else
return IPC4_UNAVAILABLE;
#endif
}

static int basefw_libraries_info_get(uint32_t *data_offset, char *data)
Expand Down
2 changes: 1 addition & 1 deletion src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int pipeline_complete(struct pipeline *p, struct comp_dev *source,
.comp_data = &data,
};

#if !UNIT_TEST && !CONFIG_LIBRARY
#if !UNIT_TEST && !CONFIG_LIBRARY && CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
int __maybe_unused freq = clock_get_freq(cpu_get_id());
#else
int __maybe_unused freq = 0;
Expand Down
10 changes: 8 additions & 2 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,7 @@ zephyr_library_sources(
${SOF_MATH_PATH}/exp_fcn_hifi.c

# SOF library - parts to transition to Zephyr over time
${SOF_LIB_PATH}/clk.c
${SOF_LIB_PATH}/notifier.c
${SOF_LIB_PATH}/cpu-clk-manager.c
${SOF_LIB_PATH}/dma.c
${SOF_LIB_PATH}/dai.c

Expand Down Expand Up @@ -530,6 +528,14 @@ zephyr_library_sources(
lib.c
)

if(NOT CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK)
zephyr_library_sources(${SOF_LIB_PATH}/clk.c)
endif()

zephyr_library_sources_ifdef(CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL
${SOF_LIB_PATH}/cpu-clk-manager.c
)

# Optional math utility
zephyr_library_sources_ifdef(CONFIG_MATH_LUT_SINE_FIXED
${SOF_MATH_PATH}/lut_trig.c
Expand Down
6 changes: 6 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ config SOF_BOOT_TEST
initialized. After that SOF will continue running and be usable as
usual.

config SOF_ZEPHYR_NO_SOF_CLOCK
bool
help
Do not use SOF clk.h interface to set the DSP clock frequency.
Requires implementation of platform/lib/clk.h.

endif
5 changes: 4 additions & 1 deletion zephyr/include/rtos/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#ifndef __ZEPHYR_RTOS_CLK_H__
#define __ZEPHYR_RTOS_CLK_H__

#ifndef CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK

#include <zephyr/kernel.h>

/* TODO remove once drivers upstream */
#define __SOF_LIB_CLK_H__
#include <platform/lib/clk.h>

Expand Down Expand Up @@ -77,4 +78,6 @@ static inline struct clock_info *clocks_get(void)
return sof_get()->clocks;
}

#endif /* CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK */

#endif /* __ZEPHYR_RTOS_CLK_H__ */

0 comments on commit 215f4d6

Please sign in to comment.