1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
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)
21 unsigned int base_freq
;
22 unsigned int cfm
, cfd
;
24 res
= read_cpucfg(LOONGARCH_CPUCFG2
);
25 if (!(res
& CPUCFG2_LLFTP
))
28 base_freq
= read_cpucfg(LOONGARCH_CPUCFG4
);
29 res
= read_cpucfg(LOONGARCH_CPUCFG5
);
31 cfd
= (res
>> 16) & 0xffff;
33 if (!base_freq
|| !cfm
|| !cfd
)
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
,
48 clockevents_calc_mult_shift(cd
, clock
, 4);
51 #endif /* _ASM_TIME_H */