time.c 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/clockchips.h>
  8. #include <linux/clocksource.h>
  9. #include <linux/delay.h>
  10. #include <asm/sbi.h>
  11. #include <asm/processor.h>
  12. #include <asm/timex.h>
  13. unsigned long riscv_timebase __ro_after_init;
  14. EXPORT_SYMBOL_GPL(riscv_timebase);
  15. void __init time_init(void)
  16. {
  17. struct device_node *cpu;
  18. u32 prop;
  19. cpu = of_find_node_by_path("/cpus");
  20. if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop))
  21. panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n");
  22. of_node_put(cpu);
  23. riscv_timebase = prop;
  24. lpj_fine = riscv_timebase / HZ;
  25. of_clk_init(NULL);
  26. timer_probe();
  27. tick_setup_hrtimer_broadcast();
  28. }
  29. void clocksource_arch_init(struct clocksource *cs)
  30. {
  31. #ifdef CONFIG_GENERIC_GETTIMEOFDAY
  32. cs->vdso_clock_mode = VDSO_CLOCKMODE_ARCHTIMER;
  33. #else
  34. cs->vdso_clock_mode = VDSO_CLOCKMODE_NONE;
  35. #endif
  36. }