Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / loongarch / include / asm / time.h
blob037a2d1b8ff4cc8ca1ccc3e98f4cbe8c8ed2cedb
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4 */
5 #ifndef _ASM_TIME_H
6 #define _ASM_TIME_H
8 #include <linux/clockchips.h>
9 #include <linux/clocksource.h>
10 #include <asm/loongarch.h>
12 extern u64 cpu_clock_freq;
13 extern u64 const_clock_freq;
15 extern void save_counter(void);
16 extern void sync_counter(void);
18 static inline unsigned int calc_const_freq(void)
20 unsigned int res;
21 unsigned int base_freq;
22 unsigned int cfm, cfd;
24 res = read_cpucfg(LOONGARCH_CPUCFG2);
25 if (!(res & CPUCFG2_LLFTP))
26 return 0;
28 base_freq = read_cpucfg(LOONGARCH_CPUCFG4);
29 res = read_cpucfg(LOONGARCH_CPUCFG5);
30 cfm = res & 0xffff;
31 cfd = (res >> 16) & 0xffff;
33 if (!base_freq || !cfm || !cfd)
34 return 0;
36 return (base_freq * cfm / cfd);
40 * Initialize the calling CPU's timer interrupt as clockevent device
42 extern int constant_clockevent_init(void);
43 extern int constant_clocksource_init(void);
45 static inline void clockevent_set_clock(struct clock_event_device *cd,
46 unsigned int clock)
48 clockevents_calc_mult_shift(cd, clock, 4);
51 #endif /* _ASM_TIME_H */