···11+/* SPDX-License-Identifier: GPL-2.0 */22+/*33+ * Copyright (C) 2020-2022 Loongson Technology Corporation Limited44+ */55+#ifndef _ASM_TIME_H66+#define _ASM_TIME_H77+88+#include <linux/clockchips.h>99+#include <linux/clocksource.h>1010+#include <asm/loongarch.h>1111+1212+extern u64 cpu_clock_freq;1313+extern u64 const_clock_freq;1414+1515+extern void sync_counter(void);1616+1717+static inline unsigned int calc_const_freq(void)1818+{1919+ unsigned int res;2020+ unsigned int base_freq;2121+ unsigned int cfm, cfd;2222+2323+ res = read_cpucfg(LOONGARCH_CPUCFG2);2424+ if (!(res & CPUCFG2_LLFTP))2525+ return 0;2626+2727+ base_freq = read_cpucfg(LOONGARCH_CPUCFG4);2828+ res = read_cpucfg(LOONGARCH_CPUCFG5);2929+ cfm = res & 0xffff;3030+ cfd = (res >> 16) & 0xffff;3131+3232+ if (!base_freq || !cfm || !cfd)3333+ return 0;3434+3535+ return (base_freq * cfm / cfd);3636+}3737+3838+/*3939+ * Initialize the calling CPU's timer interrupt as clockevent device4040+ */4141+extern int constant_clockevent_init(void);4242+extern int constant_clocksource_init(void);4343+4444+static inline void clockevent_set_clock(struct clock_event_device *cd,4545+ unsigned int clock)4646+{4747+ clockevents_calc_mult_shift(cd, clock, 4);4848+}4949+5050+#endif /* _ASM_TIME_H */
+33
arch/loongarch/include/asm/timex.h
···11+/* SPDX-License-Identifier: GPL-2.0 */22+/*33+ * Copyright (C) 2020-2022 Loongson Technology Corporation Limited44+ */55+#ifndef _ASM_TIMEX_H66+#define _ASM_TIMEX_H77+88+#ifdef __KERNEL__99+1010+#include <linux/compiler.h>1111+1212+#include <asm/cpu.h>1313+#include <asm/cpu-features.h>1414+1515+/*1616+ * Standard way to access the cycle counter.1717+ * Currently only used on SMP for scheduling.1818+ *1919+ * We know that all SMP capable CPUs have cycle counters.2020+ */2121+2222+typedef unsigned long cycles_t;2323+2424+#define get_cycles get_cycles2525+2626+static inline cycles_t get_cycles(void)2727+{2828+ return drdtime();2929+}3030+3131+#endif /* __KERNEL__ */3232+3333+#endif /* _ASM_TIMEX_H */