time.c 902 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. * Copyright (C) 2017 SiFive
  5. */
  6. #include <linux/of_clk.h>
  7. #include <linux/clocksource.h>
  8. #include <linux/delay.h>
  9. #include <asm/sbi.h>
  10. #include <asm/processor.h>
  11. unsigned long riscv_timebase;
  12. EXPORT_SYMBOL_GPL(riscv_timebase);
  13. void __init time_init(void)
  14. {
  15. struct device_node *cpu;
  16. u32 prop;
  17. cpu = of_find_node_by_path("/cpus");
  18. if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop))
  19. panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n");
  20. of_node_put(cpu);
  21. riscv_timebase = prop;
  22. lpj_fine = riscv_timebase / HZ;
  23. of_clk_init(NULL);
  24. timer_probe();
  25. }
  26. void clocksource_arch_init(struct clocksource *cs)
  27. {
  28. #ifdef CONFIG_GENERIC_GETTIMEOFDAY
  29. cs->vdso_clock_mode = VDSO_CLOCKMODE_ARCHTIMER;
  30. #else
  31. cs->vdso_clock_mode = VDSO_CLOCKMODE_NONE;
  32. #endif
  33. }