2 * Copyright (C) Maxime Coquelin 2015
3 * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com>
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>
12 #include <linux/of_address.h>
13 #include <linux/clk.h>
14 #include <linux/bitops.h>
19 #define SYST_CALIB 0x0c
21 #define SYST_CSR_ENABLE BIT(0)
23 #define SYSTICK_LOAD_RELOAD_MASK 0x00FFFFFF
25 static int __init
system_timer_of_register(struct device_node
*np
)
27 struct clk
*clk
= NULL
;
32 base
= of_iomap(np
, 0);
34 pr_warn("system-timer: invalid base address\n");
38 ret
= of_property_read_u32(np
, "clock-frequency", &rate
);
40 clk
= of_clk_get(np
, 0);
46 ret
= clk_prepare_enable(clk
);
50 rate
= clk_get_rate(clk
);
57 writel_relaxed(SYSTICK_LOAD_RELOAD_MASK
, base
+ SYST_RVR
);
58 writel_relaxed(SYST_CSR_ENABLE
, base
+ SYST_CSR
);
60 ret
= clocksource_mmio_init(base
+ SYST_CVR
, "arm_system_timer", rate
,
61 200, 24, clocksource_mmio_readl_down
);
63 pr_err("failed to init clocksource (%d)\n", ret
);
70 pr_info("ARM System timer initialized as clocksource\n");
75 clk_disable_unprepare(clk
);
80 pr_warn("ARM System timer register failed (%d)\n", ret
);
85 TIMER_OF_DECLARE(arm_systick
, "arm,armv7m-systick",
86 system_timer_of_register
);