2 * Copyright (C) Maxime Coquelin 2015
4 * License terms: GNU General Public License (GPL), version 2
7 #include <linux/kernel.h>
8 #include <linux/clocksource.h>
9 #include <linux/clockchips.h>
11 #include <linux/of_address.h>
12 #include <linux/clk.h>
13 #include <linux/bitops.h>
18 #define SYST_CALIB 0x0c
20 #define SYST_CSR_ENABLE BIT(0)
22 #define SYSTICK_LOAD_RELOAD_MASK 0x00FFFFFF
24 static void __init system_timer_of_register(struct device_node *np)
26 struct clk *clk = NULL;
31 base = of_iomap(np, 0);
33 pr_warn("system-timer: invalid base address\n");
37 ret = of_property_read_u32(np, "clock-frequency", &rate);
39 clk = of_clk_get(np, 0);
43 ret = clk_prepare_enable(clk);
47 rate = clk_get_rate(clk);
52 writel_relaxed(SYSTICK_LOAD_RELOAD_MASK, base + SYST_RVR);
53 writel_relaxed(SYST_CSR_ENABLE, base + SYST_CSR);
55 ret = clocksource_mmio_init(base + SYST_CVR, "arm_system_timer", rate,
56 200, 24, clocksource_mmio_readl_down);
58 pr_err("failed to init clocksource (%d)\n", ret);
65 pr_info("ARM System timer initialized as clocksource\n");
70 clk_disable_unprepare(clk);
75 pr_warn("ARM System timer register failed (%d)\n", ret);
78 CLOCKSOURCE_OF_DECLARE(arm_systick, "arm,armv7m-systick",
79 system_timer_of_register);