aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/timer-stm32.c
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2018-01-08 08:28:59 -0500
committerIngo Molnar <mingo@kernel.org>2018-01-08 11:57:26 -0500
commit103bb56a2831bfc7f2d442da9e47f89f37d34952 (patch)
treeb21bd1930ac097fac087ad3a035d002c5e3f43c7 /drivers/clocksource/timer-stm32.c
parent81abdbbffd69fecdac37fe1d2b44a21227ee23d4 (diff)
clocksource/drivers/stm32: Start the timer's counter sooner
As we have a lot of timers on this platform, we can have potentially all the timers enabled in the DT, so we don't want to start the timer for every probe otherwise they will be running for nothing as only one will be used. Start the timer only when setting the mode or when the clocksource is enabled. Tested-by: Benjamin Gaignard <benjamin.gaignard@st.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Benjamin Gaignard <benjamin.gaignard@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1515418139-23276-20-git-send-email-daniel.lezcano@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'drivers/clocksource/timer-stm32.c')
-rw-r--r--drivers/clocksource/timer-stm32.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
index c7d1dae27067..e5cdc3af684c 100644
--- a/drivers/clocksource/timer-stm32.c
+++ b/drivers/clocksource/timer-stm32.c
@@ -101,7 +101,15 @@ static void stm32_clock_event_disable(struct timer_of *to)
101 writel_relaxed(0, timer_of_base(to) + TIM_DIER); 101 writel_relaxed(0, timer_of_base(to) + TIM_DIER);
102} 102}
103 103
104static void stm32_clock_event_enable(struct timer_of *to) 104/**
105 * stm32_timer_start - Start the counter without event
106 * @to: a timer_of structure pointer
107 *
108 * Start the timer in order to have the counter reset and start
109 * incrementing but disable interrupt event when there is a counter
110 * overflow. By default, the counter direction is used as upcounter.
111 */
112static void stm32_timer_start(struct timer_of *to)
105{ 113{
106 writel_relaxed(TIM_CR1_UDIS | TIM_CR1_CEN, timer_of_base(to) + TIM_CR1); 114 writel_relaxed(TIM_CR1_UDIS | TIM_CR1_CEN, timer_of_base(to) + TIM_CR1);
107} 115}
@@ -137,7 +145,7 @@ static int stm32_clock_event_set_periodic(struct clock_event_device *clkevt)
137{ 145{
138 struct timer_of *to = to_timer_of(clkevt); 146 struct timer_of *to = to_timer_of(clkevt);
139 147
140 stm32_clock_event_enable(to); 148 stm32_timer_start(to);
141 149
142 return stm32_clock_event_set_next_event(timer_of_period(to), clkevt); 150 return stm32_clock_event_set_next_event(timer_of_period(to), clkevt);
143} 151}
@@ -146,7 +154,7 @@ static int stm32_clock_event_set_oneshot(struct clock_event_device *clkevt)
146{ 154{
147 struct timer_of *to = to_timer_of(clkevt); 155 struct timer_of *to = to_timer_of(clkevt);
148 156
149 stm32_clock_event_enable(to); 157 stm32_timer_start(to);
150 158
151 return 0; 159 return 0;
152} 160}
@@ -235,6 +243,13 @@ static int __init stm32_clocksource_init(struct timer_of *to)
235 * sched_clock. 243 * sched_clock.
236 */ 244 */
237 if (bits == 32 && !stm32_timer_cnt) { 245 if (bits == 32 && !stm32_timer_cnt) {
246
247 /*
248 * Start immediately the counter as we will be using
249 * it right after.
250 */
251 stm32_timer_start(to);
252
238 stm32_timer_cnt = timer_of_base(to) + TIM_CNT; 253 stm32_timer_cnt = timer_of_base(to) + TIM_CNT;
239 sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to)); 254 sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to));
240 pr_info("%s: STM32 sched_clock registered\n", name); 255 pr_info("%s: STM32 sched_clock registered\n", name);