time.h 1.1 KB

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