time.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. * Copyright (C) 2017 SiFive
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation, version 2.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/clocksource.h>
  15. #include <linux/clockchips.h>
  16. #include <linux/delay.h>
  17. #ifdef CONFIG_RISCV_TIMER
  18. #include <linux/timer_riscv.h>
  19. #endif
  20. #include <asm/sbi.h>
  21. unsigned long riscv_timebase;
  22. DECLARE_PER_CPU(struct clock_event_device, riscv_clock_event);
  23. void riscv_timer_interrupt(void)
  24. {
  25. #ifdef CONFIG_RISCV_TIMER
  26. /*
  27. * FIXME: This needs to be cleaned up along with the rest of the IRQ
  28. * handling cleanup. See irq.c for more details.
  29. */
  30. struct clock_event_device *evdev = this_cpu_ptr(&riscv_clock_event);
  31. evdev->event_handler(evdev);
  32. #endif
  33. }
  34. void __init init_clockevent(void)
  35. {
  36. timer_probe();
  37. csr_set(sie, SIE_STIE);
  38. }
  39. void __init time_init(void)
  40. {
  41. struct device_node *cpu;
  42. u32 prop;
  43. cpu = of_find_node_by_path("/cpus");
  44. if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop))
  45. panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n");
  46. riscv_timebase = prop;
  47. lpj_fine = riscv_timebase / HZ;
  48. init_clockevent();
  49. }