Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / riscv / kernel / time.c
blob2463fcca719eb2e461ab8f1972b8b057cb05b0a0
1 /*
2 * Copyright (C) 2012 Regents of the University of California
3 * Copyright (C) 2017 SiFive
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.
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.
15 #include <linux/clocksource.h>
16 #include <linux/clockchips.h>
17 #include <linux/delay.h>
19 #ifdef CONFIG_RISCV_TIMER
20 #include <linux/timer_riscv.h>
21 #endif
23 #include <asm/sbi.h>
25 unsigned long riscv_timebase;
27 DECLARE_PER_CPU(struct clock_event_device, riscv_clock_event);
29 void riscv_timer_interrupt(void)
31 #ifdef CONFIG_RISCV_TIMER
33 * FIXME: This needs to be cleaned up along with the rest of the IRQ
34 * handling cleanup. See irq.c for more details.
36 struct clock_event_device *evdev = this_cpu_ptr(&riscv_clock_event);
38 evdev->event_handler(evdev);
39 #endif
42 void __init init_clockevent(void)
44 timer_probe();
45 csr_set(sie, SIE_STIE);
48 void __init time_init(void)
50 struct device_node *cpu;
51 u32 prop;
53 cpu = of_find_node_by_path("/cpus");
54 if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop))
55 panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n");
56 riscv_timebase = prop;
58 lpj_fine = riscv_timebase / HZ;
60 init_clockevent();