aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clocksource/timer-stm32.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clocksource/timer-stm32.c')
-rw-r--r--drivers/clocksource/timer-stm32.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
index 33c7c90412ba..928ac281f937 100644
--- a/drivers/clocksource/timer-stm32.c
+++ b/drivers/clocksource/timer-stm32.c
@@ -37,6 +37,9 @@
37 37
38#define TIM_EGR_UG BIT(0) 38#define TIM_EGR_UG BIT(0)
39 39
40#define TIM_PSC_MAX USHRT_MAX
41#define TIM_PSC_CLKRATE 10000
42
40static int stm32_clock_event_shutdown(struct clock_event_device *clkevt) 43static int stm32_clock_event_shutdown(struct clock_event_device *clkevt)
41{ 44{
42 struct timer_of *to = to_timer_of(clkevt); 45 struct timer_of *to = to_timer_of(clkevt);
@@ -116,7 +119,14 @@ static void __init stm32_clockevent_init(struct timer_of *to)
116 prescaler = 1; 119 prescaler = 1;
117 to->clkevt.rating = 250; 120 to->clkevt.rating = 250;
118 } else { 121 } else {
119 prescaler = 1024; 122 prescaler = DIV_ROUND_CLOSEST(timer_of_rate(to),
123 TIM_PSC_CLKRATE);
124 /*
125 * The prescaler register is an u16, the variable
126 * can't be greater than TIM_PSC_MAX, let's cap it in
127 * this case.
128 */
129 prescaler = prescaler < TIM_PSC_MAX ? prescaler : TIM_PSC_MAX;
120 to->clkevt.rating = 100; 130 to->clkevt.rating = 100;
121 } 131 }
122 writel_relaxed(0, timer_of_base(to) + TIM_ARR); 132 writel_relaxed(0, timer_of_base(to) + TIM_ARR);