2019-06-02 03:14:06 +08:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2016-09-21 22:57:22 +08:00
|
|
|
*
|
2019-06-02 03:14:06 +08:00
|
|
|
* Copyright(c) 2016 Intel Corporation. All rights reserved.
|
2016-09-21 22:57:22 +08:00
|
|
|
*
|
|
|
|
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
|
2019-11-14 20:59:22 +08:00
|
|
|
* Janusz Jankowski <janusz.jankowski@linux.intel.com>
|
2016-09-21 22:57:22 +08:00
|
|
|
*/
|
|
|
|
|
2019-07-17 02:31:41 +08:00
|
|
|
#ifndef __SOF_LIB_CLK_H__
|
|
|
|
#define __SOF_LIB_CLK_H__
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2019-07-17 02:31:41 +08:00
|
|
|
#include <platform/lib/clk.h>
|
2020-01-09 16:46:16 +08:00
|
|
|
#include <sof/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;
|
2022-01-19 21:15:03 +08:00
|
|
|
struct k_spinlock lock;
|
2020-07-08 02:49:22 +08:00
|
|
|
|
|
|
|
/* persistent change clock value in active state */
|
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);
|
|
|
|
|
2018-10-08 18:36:43 +08:00
|
|
|
uint64_t clock_ms_to_ticks(int clock, uint64_t ms);
|
2016-09-21 22:57:22 +08:00
|
|
|
|
2021-05-17 16:31:53 +08:00
|
|
|
uint64_t clock_us_to_ticks(int clock, uint64_t us);
|
|
|
|
|
2022-03-11 20:19:10 +08:00
|
|
|
uint64_t clock_ns_to_ticks(int clock, uint64_t ns);
|
|
|
|
|
2020-10-23 10:53:53 +08:00
|
|
|
uint64_t clock_ticks_per_sample(int clock, uint32_t sample_rate);
|
|
|
|
|
2020-01-09 16:46:16 +08:00
|
|
|
static inline struct clock_info *clocks_get(void)
|
|
|
|
{
|
|
|
|
return sof_get()->clocks;
|
|
|
|
}
|
|
|
|
|
2019-07-17 02:31:41 +08:00
|
|
|
#endif /* __SOF_LIB_CLK_H__ */
|