aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/timer-marco.c
diff options
context:
space:
mode:
authorYanchang Li <yl22@csr.com>2014-11-11 07:42:52 -0500
committerDaniel Lezcano <daniel.lezcano@linaro.org>2014-11-19 05:19:20 -0500
commitef89af1f4380b922bdadd31c9e49829a022f55ae (patch)
tree3854ceb317c69a6e7583b029aeb0a5b72e01c039 /drivers/clocksource/timer-marco.c
parent867f667fb9c6734e06cc24e96fc7f06a7e772084 (diff)
clocksource: sirf: Remove hard-coded clock rate
The customers may want to adjust the whole PLL and dividers according to different user scenerios, and this causes the parent clock of sirf clocksource not be divided exactly by the current hard-coded 1MHz clock rate. This patch removes the hard-coded rate and makes the clocksource driver more adaptive to the external changes. Signed-off-by: Yanchang Li <yl22@csr.com> Signed-off-by: Barry Song <Baohua.Song@csr.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Diffstat (limited to 'drivers/clocksource/timer-marco.c')
-rw-r--r--drivers/clocksource/timer-marco.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/drivers/clocksource/timer-marco.c b/drivers/clocksource/timer-marco.c
index caf7a2030461..361a789d4bee 100644
--- a/drivers/clocksource/timer-marco.c
+++ b/drivers/clocksource/timer-marco.c
@@ -20,8 +20,6 @@
20#include <linux/of_address.h> 20#include <linux/of_address.h>
21#include <linux/sched_clock.h> 21#include <linux/sched_clock.h>
22 22
23#define MARCO_CLOCK_FREQ 1000000
24
25#define SIRFSOC_TIMER_32COUNTER_0_CTRL 0x0000 23#define SIRFSOC_TIMER_32COUNTER_0_CTRL 0x0000
26#define SIRFSOC_TIMER_32COUNTER_1_CTRL 0x0004 24#define SIRFSOC_TIMER_32COUNTER_1_CTRL 0x0004
27#define SIRFSOC_TIMER_MATCH_0 0x0018 25#define SIRFSOC_TIMER_MATCH_0 0x0018
@@ -40,6 +38,8 @@
40 38
41#define SIRFSOC_TIMER_REG_CNT 6 39#define SIRFSOC_TIMER_REG_CNT 6
42 40
41static unsigned long marco_timer_rate;
42
43static const u32 sirfsoc_timer_reg_list[SIRFSOC_TIMER_REG_CNT] = { 43static const u32 sirfsoc_timer_reg_list[SIRFSOC_TIMER_REG_CNT] = {
44 SIRFSOC_TIMER_WATCHDOG_EN, 44 SIRFSOC_TIMER_WATCHDOG_EN,
45 SIRFSOC_TIMER_32COUNTER_0_CTRL, 45 SIRFSOC_TIMER_32COUNTER_0_CTRL,
@@ -195,7 +195,7 @@ static int sirfsoc_local_timer_setup(struct clock_event_device *ce)
195 ce->rating = 200; 195 ce->rating = 200;
196 ce->set_mode = sirfsoc_timer_set_mode; 196 ce->set_mode = sirfsoc_timer_set_mode;
197 ce->set_next_event = sirfsoc_timer_set_next_event; 197 ce->set_next_event = sirfsoc_timer_set_next_event;
198 clockevents_calc_mult_shift(ce, MARCO_CLOCK_FREQ, 60); 198 clockevents_calc_mult_shift(ce, marco_timer_rate, 60);
199 ce->max_delta_ns = clockevent_delta2ns(-2, ce); 199 ce->max_delta_ns = clockevent_delta2ns(-2, ce);
200 ce->min_delta_ns = clockevent_delta2ns(2, ce); 200 ce->min_delta_ns = clockevent_delta2ns(2, ce);
201 ce->cpumask = cpumask_of(cpu); 201 ce->cpumask = cpumask_of(cpu);
@@ -257,7 +257,6 @@ static void __init sirfsoc_clockevent_init(void)
257/* initialize the kernel jiffy timer source */ 257/* initialize the kernel jiffy timer source */
258static void __init sirfsoc_marco_timer_init(struct device_node *np) 258static void __init sirfsoc_marco_timer_init(struct device_node *np)
259{ 259{
260 unsigned long rate;
261 u32 timer_div; 260 u32 timer_div;
262 struct clk *clk; 261 struct clk *clk;
263 262
@@ -266,16 +265,12 @@ static void __init sirfsoc_marco_timer_init(struct device_node *np)
266 265
267 BUG_ON(clk_prepare_enable(clk)); 266 BUG_ON(clk_prepare_enable(clk));
268 267
269 rate = clk_get_rate(clk); 268 marco_timer_rate = clk_get_rate(clk);
270
271 BUG_ON(rate < MARCO_CLOCK_FREQ);
272 BUG_ON(rate % MARCO_CLOCK_FREQ);
273 269
274 /* Initialize the timer dividers */ 270 /* timer dividers: 0, not divided */
275 timer_div = rate / MARCO_CLOCK_FREQ - 1; 271 writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_CTRL);
276 writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_CTRL); 272 writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_0_CTRL);
277 writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_0_CTRL); 273 writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_1_CTRL);
278 writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_1_CTRL);
279 274
280 /* Initialize timer counters to 0 */ 275 /* Initialize timer counters to 0 */
281 writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_LOAD_LO); 276 writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_LOAD_LO);
@@ -288,7 +283,7 @@ static void __init sirfsoc_marco_timer_init(struct device_node *np)
288 /* Clear all interrupts */ 283 /* Clear all interrupts */
289 writel_relaxed(0xFFFF, sirfsoc_timer_base + SIRFSOC_TIMER_INTR_STATUS); 284 writel_relaxed(0xFFFF, sirfsoc_timer_base + SIRFSOC_TIMER_INTR_STATUS);
290 285
291 BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, MARCO_CLOCK_FREQ)); 286 BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, marco_timer_rate));
292 287
293 sirfsoc_clockevent_init(); 288 sirfsoc_clockevent_init();
294} 289}