blob: 8a5cf99c07762403ebd55ba6f54e03005e28b7e4 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright (C) 2012 Regents of the University of California
4 * Copyright (C) 2017 SiFive
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00005 */
6
Olivier Deprez0e641232021-09-23 10:07:05 +02007#include <linux/of_clk.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008#include <linux/clocksource.h>
9#include <linux/delay.h>
10#include <asm/sbi.h>
David Brazdil0f672f62019-12-10 10:32:29 +000011#include <asm/processor.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012
13unsigned long riscv_timebase;
David Brazdil0f672f62019-12-10 10:32:29 +000014EXPORT_SYMBOL_GPL(riscv_timebase);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000015
16void __init time_init(void)
17{
18 struct device_node *cpu;
19 u32 prop;
20
21 cpu = of_find_node_by_path("/cpus");
22 if (!cpu || of_property_read_u32(cpu, "timebase-frequency", &prop))
23 panic(KERN_WARNING "RISC-V system with no 'timebase-frequency' in DTS\n");
David Brazdil0f672f62019-12-10 10:32:29 +000024 of_node_put(cpu);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025 riscv_timebase = prop;
26
27 lpj_fine = riscv_timebase / HZ;
Olivier Deprez0e641232021-09-23 10:07:05 +020028
29 of_clk_init(NULL);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000030 timer_probe();
31}
Olivier Deprez157378f2022-04-04 15:47:50 +020032
33void clocksource_arch_init(struct clocksource *cs)
34{
35#ifdef CONFIG_GENERIC_GETTIMEOFDAY
36 cs->vdso_clock_mode = VDSO_CLOCKMODE_ARCHTIMER;
37#else
38 cs->vdso_clock_mode = VDSO_CLOCKMODE_NONE;
39#endif
40}