1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2016 Intel Corporation. All rights reserved. 4 * 5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 6 * Janusz Jankowski <janusz.jankowski@linux.intel.com> 7 */ 8 9 #ifndef __SOF_LIB_CLK_H__ 10 #define __SOF_LIB_CLK_H__ 11 12 #include <platform/lib/clk.h> 13 #include <sof/sof.h> 14 #include <sof/spinlock.h> 15 #include <stdbool.h> 16 #include <stdint.h> 17 18 struct timer; 19 20 #define CLOCK_NOTIFY_PRE 0 21 #define CLOCK_NOTIFY_POST 1 22 23 struct clock_notify_data { 24 uint32_t old_freq; 25 uint32_t old_ticks_per_msec; 26 uint32_t freq; 27 uint32_t ticks_per_msec; 28 uint32_t message; 29 }; 30 31 struct freq_table { 32 uint32_t freq; 33 uint32_t ticks_per_msec; 34 }; 35 36 struct clock_info { 37 uint32_t freqs_num; 38 const struct freq_table *freqs; 39 uint32_t default_freq_idx; 40 uint32_t current_freq_idx; 41 uint32_t lowest_freq_idx; /* lowest possible clock */ 42 uint32_t notification_id; 43 uint32_t notification_mask; 44 spinlock_t lock; 45 46 /* persistent change clock value in active state */ 47 int (*set_freq)(int clock, int freq_idx); 48 49 /* temporary change clock - don't modify default clock settings */ 50 void (*low_power_mode)(int clock, bool enable); 51 }; 52 53 uint32_t clock_get_freq(int clock); 54 55 void clock_set_freq(int clock, uint32_t hz); 56 57 void clock_low_power_mode(int clock, bool enable); 58 59 uint64_t clock_ms_to_ticks(int clock, uint64_t ms); 60 61 uint64_t clock_us_to_ticks(int clock, uint64_t us); 62 63 uint64_t clock_ticks_per_sample(int clock, uint32_t sample_rate); 64 65 void platform_timer_set_delta(struct timer *timer, uint64_t ns); 66 clocks_get(void)67static inline struct clock_info *clocks_get(void) 68 { 69 return sof_get()->clocks; 70 } 71 72 #endif /* __SOF_LIB_CLK_H__ */ 73