Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/sof/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct clock_info {
const struct freq_table *freqs;
uint32_t default_freq_idx;
uint32_t current_freq_idx;
uint32_t lowest_freq_idx; /* lowest possible clock */
uint32_t notification_id;
uint32_t notification_mask;
spinlock_t lock;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/apollolake/include/platform/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#define CPU_HPRO_FREQ_IDX 2

#define CPU_LOWEST_FREQ_IDX CPU_LPRO_FREQ_IDX

#if CONFIG_CAVS_LPRO_ONLY
#define CPU_DEFAULT_IDX CPU_LPRO_FREQ_IDX
#else
Expand Down
2 changes: 2 additions & 0 deletions src/platform/cannonlake/include/platform/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#define CPU_HPRO_FREQ_IDX 1

#define CPU_LOWEST_FREQ_IDX CPU_LPRO_FREQ_IDX

#if CONFIG_CAVS_LPRO_ONLY
#define CPU_DEFAULT_IDX CPU_LPRO_FREQ_IDX
#else
Expand Down
2 changes: 2 additions & 0 deletions src/platform/icelake/include/platform/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#define CPU_HPRO_FREQ_IDX 1

#define CPU_LOWEST_FREQ_IDX CPU_LPRO_FREQ_IDX

#if CONFIG_CAVS_LPRO_ONLY
#define CPU_DEFAULT_IDX CPU_LPRO_FREQ_IDX
#else
Expand Down
58 changes: 43 additions & 15 deletions src/platform/intel/cavs/lib/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,43 +154,47 @@ static inline int get_current_freq_idx(int clock)
return clk_info->current_freq_idx;
}

static inline int get_lowest_freq_idx(int clock)
{
struct clock_info *clk_info = clocks_get() + clock;

return clk_info->lowest_freq_idx;
}

static void platform_clock_low_power_mode(int clock, bool enable)
{
int current_freq_idx = get_current_freq_idx(clock);
int freq_idx = *cache_to_uncache(&active_freq_idx);

if (enable && current_freq_idx != CPU_LPRO_FREQ_IDX)
/* LPRO requests are fast, but requests for other ROs
* can take a lot of time. That's why it's better to
* not release active clock just for waiti,
* so they can be switched without delay on wake up.
*/
select_cpu_clock(CPU_LPRO_FREQ_IDX, false);
if (enable && current_freq_idx > CPU_LPRO_FREQ_IDX)
select_cpu_clock(CPU_LPRO_FREQ_IDX, true);
else if (!enable && current_freq_idx != freq_idx)
select_cpu_clock(freq_idx, false);
select_cpu_clock(freq_idx, true);
}

void platform_clock_on_waiti(void)
{
struct pm_runtime_data *prd = pm_runtime_data_get();
uint32_t flags;
int freq_idx;
int lowest_freq_idx;
bool pm_is_active;

/* hold the prd->lock for possible active_freq_idx switching */
spin_lock_irq(&prd->lock, flags);

freq_idx = *cache_to_uncache(&active_freq_idx);
lowest_freq_idx = get_lowest_freq_idx(CLK_CPU(cpu_get_id()));
pm_is_active = pm_runtime_is_active(PM_RUNTIME_DSP, PLATFORM_PRIMARY_CORE_ID);

if (pm_is_active) {
/* set HPRO clock if not already enabled */
if (freq_idx != CPU_HPRO_FREQ_IDX)
set_cpu_current_freq_idx(CPU_HPRO_FREQ_IDX, true);
} else {
/* set LPRO clock if not already enabled */
if (freq_idx != CPU_LPRO_FREQ_IDX)
set_cpu_current_freq_idx(CPU_LPRO_FREQ_IDX, true);
/* set lowest clock if not already enabled */
if (freq_idx != lowest_freq_idx)
set_cpu_current_freq_idx(lowest_freq_idx, true);
}

spin_unlock_irq(&prd->lock, flags);
Expand All @@ -201,7 +205,7 @@ void platform_clock_on_waiti(void)

void platform_clock_on_wakeup(void)
{
/* check if LPRO->HPRO switching back is needed */
/* check if HPRO switching back is needed */
pm_runtime_get(CORE_HP_CLK, cpu_get_id());
}

Expand Down Expand Up @@ -232,6 +236,13 @@ static inline int get_current_freq_idx(int clock)
return clk_info->current_freq_idx;
}

static inline int get_lowest_freq_idx(int clock)
{
struct clock_info *clk_info = clocks_get() + clock;

return clk_info->lowest_freq_idx;
}

static void platform_clock_low_power_mode(int clock, bool enable)
{
}
Expand All @@ -241,22 +252,24 @@ void platform_clock_on_waiti(void)
struct pm_runtime_data *prd = pm_runtime_data_get();
uint32_t flags;
int freq_idx;
int lowest_freq_idx;
bool pm_is_active;

/* hold the prd->lock for possible active_freq_idx switching */
spin_lock_irq(&prd->lock, flags);

freq_idx = *cache_to_uncache(&active_freq_idx);
lowest_freq_idx = get_lowest_freq_idx(CLK_CPU(cpu_get_id()));
pm_is_active = pm_runtime_is_active(PM_RUNTIME_DSP, PLATFORM_PRIMARY_CORE_ID);

if (pm_is_active) {
/* set HPRO clock if not already enabled */
if (freq_idx != CPU_HPRO_FREQ_IDX)
set_cpu_current_freq_idx(CPU_HPRO_FREQ_IDX, true);
} else {
/* set LPRO clock if not already enabled */
if (freq_idx != CPU_LPRO_FREQ_IDX)
set_cpu_current_freq_idx(CPU_LPRO_FREQ_IDX, true);
/* set lowest clock if not already enabled */
if (freq_idx != lowest_freq_idx)
set_cpu_current_freq_idx(lowest_freq_idx, true);
}

spin_unlock_irq(&prd->lock, flags);
Expand Down Expand Up @@ -292,17 +305,32 @@ static int clock_platform_set_cpu_freq(int clock, int freq_idx)

void platform_clock_init(struct sof *sof)
{
uint32_t platform_lowest_clock = CPU_LOWEST_FREQ_IDX;
int i;

sof->clocks =
cache_to_uncache((struct clock_info *)platform_clocks_info);

#if CAVS_VERSION == CAVS_VERSION_2_5
/*
* Check HW version clock capabilities
* Try to request WOV_CRO clock, if it fails use LPRO clock
*/

shim_write(SHIM_CLKCTL, shim_read(SHIM_CLKCTL) | SHIM_CLKCTL_WOV_CRO_REQUEST);
Comment thread
abonislawski marked this conversation as resolved.
Resolved
if (shim_read(SHIM_CLKCTL) & SHIM_CLKCTL_WOV_CRO_REQUEST)
shim_write(SHIM_CLKCTL, shim_read(SHIM_CLKCTL) & ~SHIM_CLKCTL_WOV_CRO_REQUEST);
else
platform_lowest_clock = CPU_LPRO_FREQ_IDX;
#endif

for (i = 0; i < CONFIG_CORE_COUNT; i++) {
sof->clocks[i] = (struct clock_info) {
.freqs_num = NUM_CPU_FREQ,
.freqs = cpu_freq,
.default_freq_idx = CPU_DEFAULT_IDX,
.current_freq_idx = CPU_DEFAULT_IDX,
.lowest_freq_idx = platform_lowest_clock,
.notification_id = NOTIFIER_ID_CPU_FREQ,
.notification_mask = NOTIFIER_TARGET_CORE_MASK(i),
.set_freq = clock_platform_set_cpu_freq,
Expand Down
2 changes: 2 additions & 0 deletions src/platform/suecreek/include/platform/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#define CPU_HPRO_FREQ_IDX 1

#define CPU_LOWEST_FREQ_IDX CPU_LPRO_FREQ_IDX

#if CONFIG_CAVS_LPRO_ONLY
#define CPU_DEFAULT_IDX CPU_LPRO_FREQ_IDX
#else
Expand Down
10 changes: 7 additions & 3 deletions src/platform/tigerlake/include/platform/lib/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

#define CLK_MAX_CPU_HZ 400000000

#define CPU_LPRO_FREQ_IDX 0
#define CPU_WOVCRO_FREQ_IDX 0

#define CPU_HPRO_FREQ_IDX 1
#define CPU_LPRO_FREQ_IDX 1

#define CPU_HPRO_FREQ_IDX 2

#define CPU_LOWEST_FREQ_IDX CPU_WOVCRO_FREQ_IDX

#if CONFIG_CAVS_LPRO_ONLY
#define CPU_DEFAULT_IDX CPU_LPRO_FREQ_IDX
Expand All @@ -28,7 +32,7 @@

#define SSP_DEFAULT_IDX 1

#define NUM_CPU_FREQ 2
#define NUM_CPU_FREQ 3

#define NUM_SSP_FREQ 3

Expand Down
7 changes: 7 additions & 0 deletions src/platform/tigerlake/include/platform/lib/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
/** \brief Request HP RING Oscillator Clock */
#define SHIM_CLKCTL_RHROSCC BIT(31)

/** \brief Request WOVCRO Clock */
#define SHIM_CLKCTL_WOV_CRO_REQUEST BIT(4)

/** \brief Request XTAL Oscillator Clock */
#define SHIM_CLKCTL_RXOSCC BIT(30)

Expand All @@ -130,6 +133,7 @@
/** \brief Oscillator Clock Select*/
#define SHIM_CLKCTL_OCS_HP_RING BIT(2)
#define SHIM_CLKCTL_OCS_LP_RING 0
#define SHIM_CLKCTL_WOVCROSC BIT(3)

/** \brief LP Memory Clock Select */
#define SHIM_CLKCTL_LMCS_DIV2 0
Expand Down Expand Up @@ -172,6 +176,9 @@
/** \brief HP RING Oscillator Clock Status */
#define SHIM_CLKSTS_HROSCCS BIT(31)

/** \brief WOVCRO Clock Status */
#define SHIM_CLKSTS_WOV_CRO BIT(4)

/** \brief XTAL Oscillator Clock Status */
#define SHIM_CLKSTS_XOSCCS BIT(30)

Expand Down
6 changes: 5 additions & 1 deletion src/platform/tigerlake/lib/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
#include <sof/lib/clk.h>

const struct freq_table platform_cpu_freq[] = {
{ 38400000, 38400 },
{ 120000000, 120000 },
{ CLK_MAX_CPU_HZ, 400000 },
};

const uint32_t cpu_freq_enc[] = {
SHIM_CLKCTL_WOVCROSC | SHIM_CLKCTL_WOV_CRO_REQUEST |
SHIM_CLKCTL_HMCS_DIV2 | SHIM_CLKCTL_LMCS_DIV4,
SHIM_CLKCTL_RLROSCC | SHIM_CLKCTL_OCS_LP_RING |
SHIM_CLKCTL_HMCS_DIV2 | SHIM_CLKCTL_LMCS_DIV4,
SHIM_CLKCTL_RHROSCC | SHIM_CLKCTL_OCS_HP_RING |
SHIM_CLKCTL_HMCS_DIV2 | SHIM_CLKCTL_LMCS_DIV4,
};

const uint32_t cpu_freq_status_mask[] = {
SHIM_CLKSTS_WOV_CRO,
SHIM_CLKSTS_LROSCCS,
SHIM_CLKSTS_HROSCCS,
SHIM_CLKSTS_HROSCCS
};

STATIC_ASSERT(NUM_CPU_FREQ == ARRAY_SIZE(platform_cpu_freq),
Expand Down