aboutsummaryrefslogtreecommitdiff
path: root/drivers/clocksource/timer-stm32.c
AgeCommit message (Collapse)AuthorFilesLines
2018-06-12clocksource/drivers/stm32: Fix error return codeJulia Lawall1-1/+3
Return an error code on failure. Problem found using Coccinelle. Signed-off-by: Julia Lawall <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Daniel Lezcano <[email protected]> Cc: [email protected] Cc: Maxime Coquelin <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/[email protected]
2018-01-08clocksource/drivers/stm32: Start the timer's counter soonerDaniel Lezcano1-3/+18
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 <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Add the timer delay callbackDaniel Lezcano1-0/+13
Add the timer delay callback, that saves us ~90ms of boot time. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Add clocksource functionalityBenjamin Gaignard1-0/+37
The scene is set for the clocksource functionality, let's add it for this driver. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Factor out more of the clockevent codeDaniel Lezcano1-25/+82
In order to prepare the clocksource code, let's factor out the clockevent code, split the prescaler and timer width code into separate functions. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ Small edits. ] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Add oneshot modeBenjamin Gaignard1-12/+44
The stm32 timer block is able to have a counter and a comparator. Instead of using the auto-reload register for periodic events, we switch to oneshot mode by using the comparator register. The timer is able to generate an interrupt when the counter overflows but we don't want that as this counter will be use as a clocksource in the next patches. So it is disabled by the UDIS bit of the control register. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Compute a prescaler value with a targeted rateBenjamin Gaignard1-1/+11
The prescaler value is arbitrarily set to 1024 without any regard to the timer frequency. For 32-bit timers, there is no need to set a prescaler value as they wrap in an acceptable interval and give the opportunity to have precise timers on this platform. However, for 16-bit timers a prescaler value is needed if we don't want to wrap too often per second which is inefficient and adds more and more error margin. With a targeted clock of 10MHz, the 16 bits are precise enough whatever the timer frequency is as we will compute the prescaler. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Factor out the timer width sorting codeDaniel Lezcano1-7/+23
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 <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] [ Spelling fixes. ] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Use the node name as timer nameDaniel Lezcano1-1/+1
As there are different timers on the stm32, use the node name for the timer name in order to give the indication of which timer the kernel is using. /proc/timer_list gives all the information with the right name, otherwise we end up digging in the kernel log and /proc/interrupt to do the connection between the used timer. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Convert the driver to timer_of primitivesBenjamin Gaignard1-114/+73
Convert the driver to use the timer_of() helpers. This allows the removal of a custom private structure, factors out and simplifies the code. [Daniel Lezcano]: Respin against the critical fix patch and massaged the changelog. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2018-01-08clocksource/drivers/stm32: Fix kernel panic with multiple timersDaniel Lezcano1-1/+6
The current code hides a couple of bugs: - The global variable 'clock_event_ddata' is overwritten each time the init function is invoked. This is fixed with a kmemdup() instead of assigning the global variable. That prevents a memory corruption when several timers are defined in the DT. - The clockevent's event_handler is NULL if the time framework does not select the clockevent when registering it, this is fine but the init code generates in any case an interrupt leading to dereference this NULL pointer. The stm32 timer works with shadow registers, a mechanism to cache the registers. When a change is done in one buffered register, we need to artificially generate an event to force the timer to copy the content of the register to the shadowed register. The auto-reload register (ARR) is one of the shadowed register as well as the prescaler register (PSC), so in order to force the copy, we issue an event which in turn leads to an interrupt and the NULL dereference. This is fixed by inverting two lines where we clear the status register before enabling the update event interrupt. As this kernel crash is resulting from the combination of these two bugs, the fixes are grouped into a single patch. Tested-by: Benjamin Gaignard <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Benjamin Gaignard <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
2017-08-31clocksource: Convert to using %pOF instead of full_nameRob Herring1-4/+4
Now that we have a custom printf format specifier, convert users of full_name to use %pOF instead. This is preparation to remove storing of the full path string for each node. Signed-off-by: Rob Herring <[email protected]> Cc: Daniel Lezcano <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Marc Gonzalez <[email protected]> Cc: Maxime Coquelin <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: [email protected] Acked-by: Marc Gonzalez <[email protected]> Acked-by: Alexandre TORGUE <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]>
2017-06-14clocksource/drivers: Rename CLOCKSOURCE_OF_DECLARE to TIMER_OF_DECLAREDaniel Lezcano1-1/+1
The CLOCKSOURCE_OF_DECLARE macro is used widely for the timers to declare the clocksource at early stage. However, this macro is also used to initialize the clockevent if any, or the clockevent only. It was originally suggested to declare another macro to initialize a clockevent, so in order to separate the two entities even they belong to the same IP. This was not accepted because of the impact on the DT where splitting a clocksource/clockevent definition does not make sense as it is a Linux concept not a hardware description. On the other side, the clocksource has not interrupt declared while the clockevent has, so it is easy from the driver to know if the description is for a clockevent or a clocksource, IOW it could be implemented at the driver level. So instead of dealing with a named clocksource macro, let's use a more generic one: TIMER_OF_DECLARE. The patch has not functional changes. Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Heiko Stuebner <[email protected]> Acked-by: Neil Armstrong <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Acked-by: Matthias Brugger <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
2016-06-28clocksources: Switch back to the clksrc tableDaniel Lezcano1-1/+1
All the clocksource drivers's init function are now converted to return an error code. CLOCKSOURCE_OF_DECLARE is no longer used as well as the clksrc-of table. Let's convert back the names: - CLOCKSOURCE_OF_DECLARE_RET => CLOCKSOURCE_OF_DECLARE - clksrc-of-ret => clksrc-of Signed-off-by: Daniel Lezcano <[email protected]> For exynos_mct and samsung_pwm_timer: Acked-by: Krzysztof Kozlowski <[email protected]> For arch/arc: Acked-by: Vineet Gupta <[email protected]> For mediatek driver: Acked-by: Matthias Brugger <[email protected]> For the Rockchip-part Acked-by: Heiko Stuebner <[email protected]> For STi : Acked-by: Patrice Chotard <[email protected]> For the mps2-timer.c and versatile.c changes: Acked-by: Liviu Dudau <[email protected]> For the OXNAS part : Acked-by: Neil Armstrong <[email protected]> For LPC32xx driver: Acked-by: Sylvain Lemieux <[email protected]> For Broadcom Kona timer change: Acked-by: Ray Jui <[email protected]> For Sun4i and Sun5i: Acked-by: Chen-Yu Tsai <[email protected]> For Meson6: Acked-by: Carlo Caione <[email protected]> For Keystone: Acked-by: Santosh Shilimkar <[email protected]> For NPS: Acked-by: Noam Camus <[email protected]> For bcm2835: Acked-by: Eric Anholt <[email protected]>
2016-06-28clocksource/drivers/stm32: Convert init function to return errorDaniel Lezcano1-4/+6
The init functions do not return any error. They behave as the following: - panic, thus leading to a kernel crash while another timer may work and make the system boot up correctly or - print an error and let the caller unaware if the state of the system Change that by converting the init functions to return an error conforming to the CLOCKSOURCE_OF_RET prototype. Proper error handling (rollback, errno value) will be changed later case by case, thus this change just return back an error or success in the init function. Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Maxime Coquelin <[email protected]>
2015-08-10clockevents/drivers/stm32: Migrate to new 'set-state' interfaceViresh Kumar1-13/+17
Migrate stm32 driver to the new 'set-state' interface provided by clockevents core, the earlier 'set-mode' interface is marked obsolete now. This also enables us to implement callbacks for new states of clockevent devices, for example: ONESHOT_STOPPED. Cc: Maxime Coquelin <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Tested-by: Maxime Coquelin <[email protected]> Acked-by: Maxime Coquelin <[email protected]>
2015-06-02clockevents/drivers/timer-stm32: Fix build warning spotted by kbuild test robotMaxime Coquelin1-2/+2
This patch fixes below warning spotted by kbuild test robot when building with ARCH=powerpc: drivers/clocksource/timer-stm32.c: In function 'stm32_clockevent_init': >> drivers/clocksource/timer-stm32.c:140:9: warning: large integer implicitly truncated to unsigned type [-Woverflow] writel_relaxed(~0UL, data->base + TIM_ARR); The fix consists in using 0U instead of 0UL. Reported-by: kbuild test robot <[email protected]> Signed-off-by: Maxime Coquelin <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]>
2015-06-02clockevents/drivers: Add STM32 Timer driverMaxime Coquelin1-0/+184
STM32 MCUs feature 16 and 32 bits general purpose timers with prescalers. The drivers detects whether the time is 16 or 32 bits, and applies a 1024 prescaler value if it is 16 bits. Reviewed-by: Linus Walleij <[email protected]> Tested-by: Chanwoo Choi <[email protected]> Signed-off-by: Maxime Coquelin <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]>