• [PATCH v4 0/4] stm32 clocksource driver rework

    From Benjamin Gaignard@21:1/5 to All on Mon Oct 2 22:50:01 2017
    version 4:
    - split patch in 3 parts
    - convert code to timer_of
    - only use 32 bits timers
    - add clocksource support

    version 3:
    - fix comments done by Daniel
    - use timer_of helper functions

    version 2:
    - fix uninitialized variable

    These patches implements clocksource and clockevent by using only one hardware block.
    Getting both clock source and events on the same hardware lead to change quite a lot driver code.
    It also limits usage of clocksource to 32 bits timers because 16 bits ones aren't enough accurate.
    Thanks to timer_fo helpers this series includes minor clean up in structures, function prototypes and driver name.

    Since 16 bits timers become useless it also removes them from stm32f4 and stm32f7 devicetree.

    Benjamin Gaignard (4):
    clocksource: stm32: convert driver to timer_of
    clocksource: stm32: only use 32 bits timers
    clocksource: stm32: add clocksource support
    arm: dts: stm32: remove useless clocksource nodes

    arch/arm/boot/dts/stm32f429.dtsi | 32 ------
    arch/arm/boot/dts/stm32f746.dtsi | 32 ------
    drivers/clocksource/Kconfig | 1 +
    drivers/clocksource/timer-stm32.c | 229 ++++++++++++++++++--------------------
    4 files changed, 112 insertions(+), 182 deletions(-)

    --
    2.7.4

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Benjamin Gaignard@21:1/5 to All on Mon Oct 2 22:50:04 2017
    Convert driver to use timer_of helpers. This allow to remove
    custom proprietary structure.

    Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
    ---
    drivers/clocksource/Kconfig | 1 +
    drivers/clocksource/timer-stm32.c | 162 +++++++++++++-------------------------
    2 files changed, 57 insertions(+), 106 deletions(-)

    diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
    index cc60620..755c0cc 100644
    --- a/drivers/clocksource/Kconfig
    +++ b/drivers/clocksource/Kconfig
    @@ -289,6 +289,7 @@ config CLKSRC_STM32
    bool "Clocksource for STM32 SoCs" if !ARCH_STM32
    depends on OF && ARM && (ARCH_STM32 || COMPILE_TEST)
    select CLKSRC_MMIO
    + select TIMER_OF

    config CLKSRC_MPS2
    bool "Clocksource for MPS2 SoCs" if COMPILE_TEST
    diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
    index 8f24237..abff21c 100644
    --- a/drivers/clocksource/timer-stm32.c
    +++ b/drivers/clocksource/timer-stm32.c
    @@ -17,6 +17,8 @@
    #include <linux/clk.h>
    #include <linux/reset.h>

    +#include "timer-of.h"
    +
    #define TIM_CR1 0x00
    #define TIM_DIER 0x0c
    #define TIM_SR 0x10
    @@ -34,117 +36,84 @@

    #define
  • From Benjamin Gaignard@21:1/5 to All on Mon Oct 2 22:50:07 2017
    Rework driver code to be able to implement clocksource and clockevent
    on the same hardware block.
    Before this patch only the counter of the hardware block was used to
    generate clock events. Now counter will be used to provide a 32 bits
    clock source and a comparator will provide clock events.

    Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
    ---
    drivers/clocksource/timer-stm32.c | 104 ++++++++++++++++++++++++++++----------
    1 file changed, 76 insertions(+), 28 deletions(-)

    diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
    index f7e4eec..fb84252 100644
    --- a/drivers/clocksource/timer-stm32.c
    +++ b/drivers/clocksource/timer-stm32.c
    @@ -16,6 +16,8 @@
    #include <linux/of_irq.h>
    #include <linux/clk.h>
    #include <linux/reset.h>
    +#include <linux/sched_clock.h>
    +#include <linux/slab.h>

    #include "timer-of.h"

    @@ -23,16 +25,16 @@
    #define TIM_DIER 0x0c
    #define TIM_SR 0x10
    #define TIM_EGR 0x14
    +#define TIM_CNT 0x24
    #define TIM_PSC 0x28
    #define TIM_ARR 0x2c
    +#define TIM_CCR1 0x34

    #define TIM_CR1_CEN BIT(0)
    -#define TIM_CR1_OPM BIT(3)
    +#define TIM_CR1_UDIS BIT(1)
    #define TIM_CR1_ARPE BIT(7)

    -#define TIM_DIER_UIE BIT(0)
    -
    -#define TIM_SR_UIF BIT(0)
    +#define TIM_DIER_CC1IE BIT(1)

    #define TIM_EGR_UG BIT(0)

    @@ -40,30 +42,34 @@ static int stm32_clock_event_shutdown(struct c
  • From Benjamin Gaignard@21:1/5 to All on Mon Oct 2 22:50:09 2017
    16 bits hardware are not enough accure to be used.
    Do no allow them to be probed by tested max counter value.

    Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
    ---
    drivers/clocksource/timer-stm32.c | 23 +++++++++--------------
    1 file changed, 9 insertions(+), 14 deletions(-)

    diff --git a/drivers/clocksource/timer-stm32.c b/drivers/clocksource/timer-stm32.c
    index abff21c..f7e4eec 100644
    --- a/drivers/clocksource/timer-stm32.c
    +++ b/drivers/clocksource/timer-stm32.c
    @@ -81,9 +81,9 @@ static irqreturn_t stm32_clock_event_handler(int irq, void *dev_id)
    static int __init stm32_clockevent_init(struct device_node *node)
    {
    struct reset_control *rstc;
    - unsigned long max_delta;
    - int ret, bits, prescaler = 1;
    + unsigned long max_arr;
    struct timer_of *to;
    + int ret;

    to = kzalloc(sizeof(*to), GFP_KERNEL);
    if (!to)
    @@ -113,26 +113,21 @@ static int __init stm32_clockevent_init(struct device_node *node)

    /* Detect whether the timer is 16 or 32 bits */
    writel_relaxed(~0U, timer_of_base(to) + TIM_ARR);
    - max_delta = readl_relaxed(timer_of_base(to) + TIM_ARR);
    - if (max_delta == ~0U) {
    - prescaler = 1;
    - bits = 32;
    - } else {
    - presc
  • From Benjamin Gaignard@21:1/5 to All on Mon Oct 2 22:50:09 2017
    16 bits timers aren't accurate enough to be used as
    clocksource, remove them from stm32f4 and stm32f7 devicetree.

    Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
    ---
    arch/arm/boot/dts/stm32f429.dtsi | 32 --------------------------------
    arch/arm/boot/dts/stm32f746.dtsi | 32 --------------------------------
    2 files changed, 64 deletions(-)

    diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
    index dd7e99b..ac9a3e6 100644
    --- a/arch/arm/boot/dts/stm32f429.dtsi
    +++ b/arch/arm/boot/dts/stm32f429.dtsi
    @@ -108,14 +108,6 @@
    };
    };

    - timer3: timer@40000400 {
    - compatible = "st,stm32-timer";
    - reg = <0x40000400 0x400>;
    - interrupts = <29>;
    - clocks = <&rcc 0 STM32F4_APB1_CLOCK(TIM3)>;
    - status = "disabled";
    - };
    -
    timers3: timers@40000400 {
    #address-cells = <1>;
    #size-cells = <0>;
    @@ -137,14 +129,6 @@
    };
    };

    - timer4: timer@40000800 {
    - compatible = "st,stm32-timer";
    - reg = <0x40000800 0x400>;
    - interrupts = <30>;
    - clocks = <&rcc 0 STM32F4_APB1_CLOCK(TIM4)>;
    - status = "disabled";
    - };
    -
    timers4: timers@40000800 {
    #address-cells = <1>;
    #size-cells