diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2018-01-08 08:28:53 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-01-08 11:57:25 -0500 |
commit | 70c62cf910aeba7cb79f4ebc7e6c8edbb37a77f6 (patch) | |
tree | 84efcdc7ba8b086498a66cec96ee3668c3845874 /drivers/clocksource/timer-stm32.c | |
parent | f2ed8ef1cea41c7e7e5d52199db9c822951ab101 (diff) |
clocksource/drivers/stm32: Factor out the timer width sorting code
In order to clarify and encapsulate the code for upcoming changes, move the
timer width check into a function and add some documentation.
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-14-git-send-email-daniel.lezcano@linaro.org
[ Spelling fixes. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'drivers/clocksource/timer-stm32.c')
-rw-r--r-- | drivers/clocksource/timer-stm32.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c index 14b7a2b99933..33c7c90412ba 100644 --- a/drivers/clocksource/timer-stm32.c +++ b/drivers/clocksource/timer-stm32.c | |||
@@ -80,9 +80,27 @@ static irqreturn_t stm32_clock_event_handler(int irq, void *dev_id) | |||
80 | return IRQ_HANDLED; | 80 | return IRQ_HANDLED; |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | ||
84 | * stm32_timer_width - Sort out the timer width (32/16) | ||
85 | * @to: a pointer to a timer-of structure | ||
86 | * | ||
87 | * Write the 32-bit max value and read/return the result. If the timer | ||
88 | * is 32 bits wide, the result will be UINT_MAX, otherwise it will | ||
89 | * be truncated by the 16-bit register to USHRT_MAX. | ||
90 | * | ||
91 | * Returns UINT_MAX if the timer is 32 bits wide, USHRT_MAX if it is a | ||
92 | * 16 bits wide. | ||
93 | */ | ||
94 | static u32 __init stm32_timer_width(struct timer_of *to) | ||
95 | { | ||
96 | writel_relaxed(UINT_MAX, timer_of_base(to) + TIM_ARR); | ||
97 | |||
98 | return readl_relaxed(timer_of_base(to) + TIM_ARR); | ||
99 | } | ||
100 | |||
83 | static void __init stm32_clockevent_init(struct timer_of *to) | 101 | static void __init stm32_clockevent_init(struct timer_of *to) |
84 | { | 102 | { |
85 | unsigned long max_delta; | 103 | u32 width = 0; |
86 | int prescaler; | 104 | int prescaler; |
87 | 105 | ||
88 | to->clkevt.name = to->np->full_name; | 106 | to->clkevt.name = to->np->full_name; |
@@ -93,10 +111,8 @@ static void __init stm32_clockevent_init(struct timer_of *to) | |||
93 | to->clkevt.tick_resume = stm32_clock_event_shutdown; | 111 | to->clkevt.tick_resume = stm32_clock_event_shutdown; |
94 | to->clkevt.set_next_event = stm32_clock_event_set_next_event; | 112 | to->clkevt.set_next_event = stm32_clock_event_set_next_event; |
95 | 113 | ||
96 | /* Detect whether the timer is 16 or 32 bits */ | 114 | width = stm32_timer_width(to); |
97 | writel_relaxed(~0U, timer_of_base(to) + TIM_ARR); | 115 | if (width == UINT_MAX) { |
98 | max_delta = readl_relaxed(timer_of_base(to) + TIM_ARR); | ||
99 | if (max_delta == ~0U) { | ||
100 | prescaler = 1; | 116 | prescaler = 1; |
101 | to->clkevt.rating = 250; | 117 | to->clkevt.rating = 250; |
102 | } else { | 118 | } else { |
@@ -115,10 +131,10 @@ static void __init stm32_clockevent_init(struct timer_of *to) | |||
115 | to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ); | 131 | to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ); |
116 | 132 | ||
117 | clockevents_config_and_register(&to->clkevt, | 133 | clockevents_config_and_register(&to->clkevt, |
118 | timer_of_rate(to), 0x1, max_delta); | 134 | timer_of_rate(to), 0x1, width); |
119 | 135 | ||
120 | pr_info("%pOF: STM32 clockevent driver initialized (%d bits)\n", | 136 | pr_info("%pOF: STM32 clockevent driver initialized (%d bits)\n", |
121 | to->np, max_delta == UINT_MAX ? 32 : 16); | 137 | to->np, width == UINT_MAX ? 32 : 16); |
122 | } | 138 | } |
123 | 139 | ||
124 | static int __init stm32_timer_init(struct device_node *node) | 140 | static int __init stm32_timer_init(struct device_node *node) |