David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Regents of the University of California |
| 4 | * Copyright (C) 2017 SiFive |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 7 | #include <linux/of_clk.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8 | #include <linux/clocksource.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <asm/sbi.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11 | #include <asm/processor.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12 | |
| 13 | unsigned long riscv_timebase; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14 | EXPORT_SYMBOL_GPL(riscv_timebase); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15 | |
| 16 | void __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 Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 24 | of_node_put(cpu); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | riscv_timebase = prop; |
| 26 | |
| 27 | lpj_fine = riscv_timebase / HZ; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 28 | |
| 29 | of_clk_init(NULL); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 30 | timer_probe(); |
| 31 | } |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 32 | |
| 33 | void 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 | } |