2019-06-02 03:14:06 +08:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-09-21 22:57:22 +08:00
|
|
|
*
|
2022-09-03 01:23:19 +08:00
|
|
|
* Copyright(c) 2022 Intel Corporation. All rights reserved.
|
2016-09-21 22:57:22 +08:00
|
|
|
*/
|
|
|
|
|
2022-09-03 01:23:19 +08:00
|
|
|
#ifndef __ZEPHYR_RTOS_CLK_H__
|
|
|
|
#define __ZEPHYR_RTOS_CLK_H__
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2022-09-03 01:23:19 +08:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
|
|
|
|
/* TODO remove once drivers upstream */
|
|
|
|
#define __SOF_LIB_CLK_H__
|
2019-07-17 02:31:41 +08:00
|
|
|
#include <platform/lib/clk.h>
|
2022-09-03 01:23:19 +08:00
|
|
|
|
|
|
|
/* TODO: most of the below is tied to the CLK drivers that need wrapped */
|
2023-02-22 01:05:47 +08:00
|
|
|
#include <rtos/sof.h>
|
2022-08-19 21:10:56 +08:00
|
|
|
#include <rtos/spinlock.h>
|
2020-07-08 02:49:22 +08:00
|
|
|
#include <stdbool.h>
|
2019-07-15 17:27:29 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
struct timer;
|
2016-09-21 22:57:22 +08:00
|
|
|
|
|
|
|
#define CLOCK_NOTIFY_PRE 0
|
|
|
|
#define CLOCK_NOTIFY_POST 1
|
|
|
|
|
|
|
|
struct clock_notify_data {
|
|
|
|
uint32_t old_freq;
|
2018-09-21 21:09:06 +08:00
|
|
|
uint32_t old_ticks_per_msec;
|
2016-09-21 22:57:22 +08:00
|
|
|
uint32_t freq;
|
2018-09-21 21:09:06 +08:00
|
|
|
uint32_t ticks_per_msec;
|
2019-10-30 15:49:17 +08:00
|
|
|
uint32_t message;
|
2016-09-21 22:57:22 +08:00
|
|
|
};
|
|
|
|
|
2018-10-08 18:36:43 +08:00
|
|
|
struct freq_table {
|
|
|
|
uint32_t freq;
|
|
|
|
uint32_t ticks_per_msec;
|
|
|
|
};
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2019-11-14 20:59:22 +08:00
|
|
|
struct clock_info {
|
|
|
|
uint32_t freqs_num;
|
2019-12-11 23:06:02 +08:00
|
|
|
const struct freq_table *freqs;
|
2019-11-14 20:59:22 +08:00
|
|
|
uint32_t default_freq_idx;
|
2019-12-11 23:26:55 +08:00
|
|
|
uint32_t current_freq_idx;
|
2020-09-15 22:02:58 +08:00
|
|
|
uint32_t lowest_freq_idx; /* lowest possible clock */
|
2019-11-14 20:59:22 +08:00
|
|
|
uint32_t notification_id;
|
|
|
|
uint32_t notification_mask;
|
2020-07-08 02:49:22 +08:00
|
|
|
|
2023-02-28 22:05:07 +08:00
|
|
|
/* persistent change clock value in active state, caller must hold clk_lock */
|
2019-11-14 20:59:22 +08:00
|
|
|
int (*set_freq)(int clock, int freq_idx);
|
2020-07-08 02:49:22 +08:00
|
|
|
|
|
|
|
/* temporary change clock - don't modify default clock settings */
|
|
|
|
void (*low_power_mode)(int clock, bool enable);
|
2019-11-14 20:59:22 +08:00
|
|
|
};
|
2019-07-11 20:31:19 +08:00
|
|
|
|
2019-05-08 00:31:12 +08:00
|
|
|
uint32_t clock_get_freq(int clock);
|
|
|
|
|
2018-11-20 17:44:36 +08:00
|
|
|
void clock_set_freq(int clock, uint32_t hz);
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2020-07-08 02:49:22 +08:00
|
|
|
void clock_low_power_mode(int clock, bool enable);
|
|
|
|
|
2020-10-23 10:53:53 +08:00
|
|
|
uint64_t clock_ticks_per_sample(int clock, uint32_t sample_rate);
|
|
|
|
|
2023-02-28 22:05:07 +08:00
|
|
|
extern struct k_spinlock clk_lock;
|
|
|
|
|
|
|
|
static inline k_spinlock_key_t clock_lock(void)
|
|
|
|
{
|
|
|
|
return k_spin_lock(&clk_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clock_unlock(k_spinlock_key_t key)
|
|
|
|
{
|
|
|
|
k_spin_unlock(&clk_lock, key);
|
|
|
|
}
|
|
|
|
|
2020-01-09 16:46:16 +08:00
|
|
|
static inline struct clock_info *clocks_get(void)
|
|
|
|
{
|
|
|
|
return sof_get()->clocks;
|
|
|
|
}
|
|
|
|
|
2022-09-03 01:23:19 +08:00
|
|
|
#endif /* __ZEPHYR_RTOS_CLK_H__ */
|