time.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  7. #include <linux/clockchips.h>
  8. #include <linux/clocksource.h>
  9. #include <asm/loongarch.h>
  10. extern u64 cpu_clock_freq;
  11. extern u64 const_clock_freq;
  12. extern void save_counter(void);
  13. extern void sync_counter(void);
  14. static inline unsigned int calc_const_freq(void)
  15. {
  16. unsigned int res;
  17. unsigned int base_freq;
  18. unsigned int cfm, cfd;
  19. res = read_cpucfg(LOONGARCH_CPUCFG2);
  20. if (!(res & CPUCFG2_LLFTP))
  21. return 0;
  22. base_freq = read_cpucfg(LOONGARCH_CPUCFG4);
  23. res = read_cpucfg(LOONGARCH_CPUCFG5);
  24. cfm = res & 0xffff;
  25. cfd = (res >> 16) & 0xffff;
  26. if (!base_freq || !cfm || !cfd)
  27. return 0;
  28. return (base_freq * cfm / cfd);
  29. }
  30. /*
  31. * Initialize the calling CPU's timer interrupt as clockevent device
  32. */
  33. extern int constant_clockevent_init(void);
  34. extern int constant_clocksource_init(void);
  35. static inline void clockevent_set_clock(struct clock_event_device *cd,
  36. unsigned int clock)
  37. {
  38. clockevents_calc_mult_shift(cd, clock, 4);
  39. }
  40. #endif /* _ASM_TIME_H */