Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology |
| 4 | * Author: Fuxin Zhang, zhangfx@lemote.com |
| 5 | * |
Wu Zhangjin | f7a904d | 2010-01-04 17:16:51 +0800 | [diff] [blame] | 6 | * Copyright (C) 2009 Lemote Inc. |
| 7 | * Author: Wu Zhangjin, wuzhangjin@gmail.com |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 8 | */ |
Jiaxun Yang | a746f50 | 2020-04-20 21:45:25 +0800 | [diff] [blame] | 9 | |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 10 | #include <asm/time.h> |
Huacai Chen | e292ccd | 2014-11-04 14:15:31 +0800 | [diff] [blame] | 11 | #include <asm/hpet.h> |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 12 | |
Wu Zhangjin | 5e983ff | 2009-07-02 23:23:03 +0800 | [diff] [blame] | 13 | #include <loongson.h> |
Qing Zhang | 95b56e8 | 2021-03-15 15:50:00 +0800 | [diff] [blame] | 14 | #include <linux/clk.h> |
| 15 | #include <linux/of_clk.h> |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 16 | |
| 17 | void __init plat_time_init(void) |
| 18 | { |
Qing Zhang | 95b56e8 | 2021-03-15 15:50:00 +0800 | [diff] [blame] | 19 | struct clk *clk; |
| 20 | struct device_node *np; |
| 21 | |
| 22 | if (loongson_sysconf.fw_interface == LOONGSON_DTB) { |
| 23 | of_clk_init(NULL); |
| 24 | |
| 25 | np = of_get_cpu_node(0, NULL); |
| 26 | if (!np) { |
| 27 | pr_err("Failed to get CPU node\n"); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | clk = of_clk_get(np, 0); |
| 32 | if (IS_ERR(clk)) { |
| 33 | pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk)); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | cpu_clock_freq = clk_get_rate(clk); |
| 38 | clk_put(clk); |
| 39 | } |
| 40 | |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 41 | /* setup mips r4k timer */ |
| 42 | mips_hpt_frequency = cpu_clock_freq / 2; |
Wu Zhangjin | 916daba | 2009-11-17 01:32:57 +0800 | [diff] [blame] | 43 | |
Huacai Chen | e292ccd | 2014-11-04 14:15:31 +0800 | [diff] [blame] | 44 | #ifdef CONFIG_RS780_HPET |
| 45 | setup_hpet_timer(); |
Huacai Chen | e292ccd | 2014-11-04 14:15:31 +0800 | [diff] [blame] | 46 | #endif |
Wu Zhangjin | bd92aa0 | 2009-07-02 23:22:36 +0800 | [diff] [blame] | 47 | } |