Fix msm timer clearing bugs
cover Fix msm timer clearing bugs
This patchset cleans up some bugs in the msm timer code and overhauls the DT binding. I don't think we'll need to radically change it again, and we haven't shipped any devices with these bindings so we should be ok. The important thing is that the binding is consolidated and more clearly describes the hardware. We can use the compatible field to determine which timers are present and what the register layout is, so we may need to add more compatible fields in the future.
Patches are based on v3.9-rc2. These patches will conflict with my other patch series to remove the local timer API, but the conflict isn't impossible to resolve and we can figure out how to deal with that after review.
Patch 1 is a bug fix which could probably go into 3.9 if desired. Patch 2 overhauls the DT binding to be cleaner, and patch 3 fixes a bug where we don't wait for the timer to be clear before programming it leading to no more ticks.
Stephen Boyd (3):
ARM: msm: Stop counting before reprogramming clockevent
ARM: msm: Rework timer binding to be more general
ARM: msm: Wait for timer clear to complete
.../devicetree/bindings/arm/msm/timer.txt | 41 ++++---- arch/arm/boot/dts/msm8660-surf.dts | 20 ++-- arch/arm/boot/dts/msm8960-cdp.dts | 22 ++-- arch/arm/mach-msm/timer.c | 115 ++++++++++----------- 4 files changed, 90 insertions(+), 108 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH 1/3 ARM: msm: Stop counting before reprogramming clockevent
If the clockevent is forcibly reprogrammed to have a different match value we mistakenly assume the timer is not ticking and program a new match value while the timer is running. Although we clear the timer before programming a new match, it's better to stop the timer before clearing it so that we're sure the proper amount of ticks are counted. Failure to do so can lead to missed ticks and system hangs.
--- arch/arm/mach-msm/timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/mach-msm/timer.c +4 -1
@@ -62,7 +62,10 @@ static int msm_timer_set_next_event(unsigned long cycles, {u32 ctrl =readl_relaxed (event_base +TIMER_ENABLE ); -writel_relaxed (0 , event_base +TIMER_CLEAR ); + ctrl &= ~TIMER_ENABLE_EN ; +writel_relaxed (ctrl, event_base +TIMER_ENABLE ); + +writel_relaxed (ctrl, event_base +TIMER_CLEAR );writel_relaxed (cycles, event_base +TIMER_MATCH_VAL );writel_relaxed (ctrl |TIMER_ENABLE_EN , event_base +TIMER_ENABLE );return 0 ;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH 2/3 ARM: msm: Rework timer binding to be more general
In reply to Stephen BoydThe msm timer binding I wrote is bad. First off, the clock frequency in the binding for the dgt is wrong. Software divides down the input rate by 4 to achieve the rate listed in the binding. We also treat each individual timer as a separate hardware component, when in reality there is one timer block (that may be duplicated per cpu) with multiple timers within it. Depending on the version of the hardware there can be one or two general purpose timers, status and divider control registers, and an entirely different register layout.
In the next patch we'll need to know about the different register layouts so that we can properly check the status register after clearing the count. The current binding makes this complicated because the general purpose timer's reg property doesn't indicate where that status register is, and in fact it is beyond the size of the reg property.
Clean all this up by just having one node for the timer hardware, and describe all the interrupts and clock frequencies supported while having one reg property that covers the entire timer register region. We'll use the compatible field in the future to determine different register layouts and if we should read the status registers, etc.
--- .../devicetree/bindings/arm/msm/timer.txt | 41 ++++++----- arch/arm/boot/dts/msm8660-surf.dts | 20 ++---- arch/arm/boot/dts/msm8960-cdp.dts | 22 +++--- arch/arm/mach-msm/timer.c | 79 +++++++++------------- 4 files changed, 68 insertions(+), 94 deletions(-)
Documentation/devicetree/bindings/arm/msm/timer.txt +20 -21
@@ -3,36 +3,35 @@ Properties: - compatible : Should at least contain "qcom,msm-timer". More specific - properties such as "qcom,msm-gpt" and "qcom,msm-dgt" specify a general - purpose timer and a debug timer respectively. + properties specify which subsystem the timers are paired with. -- interrupts : Interrupt indicating a match event. + "qcom,kpss-timer" - krait subsystem + "qcom,scss-timer" - scorpion subsystem -- reg : Specifies the base address of the timer registers. The second region - specifies an optional register used to configure the clock divider. +- interrupts : Interrupts for the the debug timer, the first general purpose + timer, and optionally a second general purpose timer in that + order. -- clock-frequency : The frequency of the timer in Hz. +- reg : Specifies the base address of the timer registers. + +- clock-frequency : The frequency of the debug timer and the general purpose + timer(s) in Hz in that order. Optional: - cpu-offset : per-cpu offset used when the timer is accessed without the - CPU remapping facilities. The offset is cpu-offset * cpu-nr. + CPU remapping facilities. The offset is + cpu-offset + (0x10000 * cpu-nr). Example: - timer at 200a004 { - compatible = "qcom,msm-gpt", "qcom,msm-timer"; - interrupts = <1 2 0x301>; - reg = <0x0200a004 0x10>; - clock-frequency = <32768>; - cpu-offset = <0x40000>; - }; - - timer at 200a024 { - compatible = "qcom,msm-dgt", "qcom,msm-timer"; - interrupts = <1 3 0x301>; - reg = <0x0200a024 0x10>, - <0x0200a034 0x4>; - clock-frequency = <6750000>; + timer at 200a000 { + compatible = "qcom,scss-timer", "qcom,msm-timer"; + interrupts = <1 1 0x301>, + <1 2 0x301>, + <1 3 0x301>; + reg = <0x0200a000 0x100>; + clock-frequency = <19200000>, + <32768>; cpu-offset = <0x40000>; };
arch/arm/boot/dts/msm8660-surf.dts +7 -13
@@ -16,19 +16,13 @@ }; timer at 2000004 { - compatible = "qcom,msm-gpt", "qcom,msm-timer"; - interrupts = <1 1 0x301>; - reg = <0x02000004 0x10>; - clock-frequency = <32768>; - cpu-offset = <0x40000>; - }; - - timer at 2000024 { - compatible = "qcom,msm-dgt", "qcom,msm-timer"; - interrupts = <1 0 0x301>; - reg = <0x02000024 0x10>, - <0x02000034 0x4>; - clock-frequency = <6750000>; + compatible = "qcom,scss-timer", "qcom,msm-timer"; + interrupts = <1 0 0x301>, + <1 1 0x301>, + <1 2 0x301>; + reg = <0x02000000 0x100>; + clock-frequency = <27000000>, + <32768>; cpu-offset = <0x40000>; };
arch/arm/boot/dts/msm8960-cdp.dts +8 -14
@@ -15,20 +15,14 @@ < 0x02002000 0x1000 >; }; - timer at 200a004 { - compatible = "qcom,msm-gpt", "qcom,msm-timer"; - interrupts = <1 2 0x301>; - reg = <0x0200a004 0x10>; - clock-frequency = <32768>; - cpu-offset = <0x80000>; - }; - - timer at 200a024 { - compatible = "qcom,msm-dgt", "qcom,msm-timer"; - interrupts = <1 1 0x301>; - reg = <0x0200a024 0x10>, - <0x0200a034 0x4>; - clock-frequency = <6750000>; + timer at 200a000 { + compatible = "qcom,kpss-timer", "qcom,msm-timer"; + interrupts = <1 1 0x301>, + <1 2 0x301>, + <1 3 0x301>; + reg = <0x0200a000 0x100>; + clock-frequency = <27000000>, + <32768>; cpu-offset = <0x80000>; };
arch/arm/mach-msm/timer.c +33 -46
151 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH 3/3 ARM: msm: Wait for timer clear to complete
In reply to Stephen BoydWithout looping on the status bit, there is no way to guarantee that a clear of the timer has actually completed. This can cause us to enable the timer before the count has cleared and miss a timer interrupt. To simplify this patch, remove the timer register setup done during timer init, since it's duplicate work that is eventually done in the set_next_event() callback.
--- arch/arm/mach-msm/timer.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-)
arch/arm/mach-msm/timer.c +23 -18
@@ -30,20 +30,22 @@#include "common.h" -#define TIMER_MATCH_VAL 0x0000 -#define TIMER_COUNT_VAL 0x0004 -#define TIMER_ENABLE 0x0008 -#define TIMER_ENABLE_CLR_ON_MATCH_EN BIT(1) -#define TIMER_ENABLE_EN BIT(0) -#define TIMER_CLEAR 0x000C -#define DGT_CLK_CTL 0x10 -#define DGT_CLK_CTL_DIV_4 0x3 +#define TIMER_MATCH_VAL 0x0000 +#define TIMER_COUNT_VAL 0x0004 +#define TIMER_ENABLE 0x0008 +#define TIMER_ENABLE_CLR_ON_MATCH_EN BIT(1) +#define TIMER_ENABLE_EN BIT(0) +#define TIMER_CLEAR 0x000C +#define DGT_CLK_CTL 0x10 +#define DGT_CLK_CTL_DIV_4 0x3 +#define TIMER_STS_GPT0_CLR_PEND BIT(10)#define GPT_HZ 32768#define MSM_DGT_SHIFT 5static void __iomem *event_base; +static void __iomem *sts_base;static irqreturn_t msm_timer_interrupt (int irq,void *dev_id) {
@@ -68,6 +70,11 @@ static int msm_timer_set_next_event(unsigned long cycles,writel_relaxed (ctrl, event_base +TIMER_CLEAR );writel_relaxed (cycles, event_base +TIMER_MATCH_VAL ); + +if (sts_base) +while (readl_relaxed (sts_base) &TIMER_STS_GPT0_CLR_PEND ) +cpu_relax (); +writel_relaxed (ctrl |TIMER_ENABLE_EN , event_base +TIMER_ENABLE );return 0 ; }
@@ -138,9 +145,6 @@ static int __cpuinit msm_local_timer_setup(struct clock_event_device *evt)if (!smp_processor_id ())return 0 ; -writel_relaxed (0 , event_base +TIMER_ENABLE ); -writel_relaxed (0 , event_base +TIMER_CLEAR ); -writel_relaxed (~0 , event_base +TIMER_MATCH_VAL ); evt->irq = msm_clockevent.irq; evt->name ="local_timer" ; evt->features = msm_clockevent.features;
@@ -178,9 +182,6 @@ static void __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,struct clocksource *cs = &msm_clocksource;int res; -writel_relaxed (0 , event_base +TIMER_ENABLE ); -writel_relaxed (0 , event_base +TIMER_CLEAR ); -writel_relaxed (~0 , event_base +TIMER_MATCH_VAL ); ce->cpumask =cpumask_of (0 ); ce->irq = irq;
@@ -275,6 +276,7 @@ void __init msm_dt_timer_init(void)of_node_put (np); event_base = base +0x4 ; + sts_base = base +0x88 ; source_base = cpu0_base +0x24 ; freq /=4 ;writel_relaxed (DGT_CLK_CTL_DIV_4 , source_base +DGT_CLK_CTL );
@@ -283,7 +285,8 @@ void __init msm_dt_timer_init(void) }#endif -static int __init msm_timer_map (phys_addr_t addr,u32 event,u32 source) +static int __init msm_timer_map (phys_addr_t addr,u32 event,u32 source, +u32 sts) {void __iomem *base;
@@ -294,6 +297,8 @@ static int __init msm_timer_map(phys_addr_t addr, u32 event, u32 source) } event_base = base + event; source_base = base + source; +if (sts) + sts_base = base + sts;return 0 ; }
@@ -302,7 +307,7 @@ void __init msm7x01_timer_init(void) {struct clocksource *cs = &msm_clocksource; -if (msm_timer_map (0xc0100000 ,0x0 ,0x10 )) +if (msm_timer_map (0xc0100000 ,0x0 ,0x10 ,0x0 ))return ; cs->read = msm_read_timer_count_shift; cs->mask =CLOCKSOURCE_MASK ((32 -MSM_DGT_SHIFT ));
@@ -313,14 +318,14 @@ void __init msm7x01_timer_init(void)void __init msm7x30_timer_init (void ) { -if (msm_timer_map (0xc0100000 ,0x4 ,0x24 )) +if (msm_timer_map (0xc0100000 ,0x4 ,0x24 ,0x80 ))return ;msm_timer_init (24576000 /4 ,32 ,1 , false); }void __init qsd8x50_timer_init (void ) { -if (msm_timer_map (0xAC100000 ,0x0 ,0x10 )) +if (msm_timer_map (0xAC100000 ,0x0 ,0x10 ,0x34 ))return ;msm_timer_init (19200000 /4 ,32 ,7 , false); }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 15 lines · Stephen Boyd
Patches are based on v3.9-rc2. These patches will conflict with my other patch series to remove the local timer API, but the conflict isn't impossible to resolve and we can figure out how to deal with that after review.
Patch 1 is a bug fix which could probably go into 3.9 if desired. Patch 2 overhauls the DT binding to be cleaner, and patch 3 fixes a bug where we don't wait for the timer to be clear before programming it leading to no more ticks.
Stephen Boyd (3):
ARM: msm: Stop counting before reprogramming clockevent
ARM: msm: Rework timer binding to be more general
ARM: msm: Wait for timer clear to complete
Quoted 5 lines
.../devicetree/bindings/arm/msm/timer.txt | 41 ++++---- arch/arm/boot/dts/msm8660-surf.dts | 20 ++-- arch/arm/boot/dts/msm8960-cdp.dts | 22 ++-- arch/arm/mach-msm/timer.c | 115 ++++++++++----------- 4 files changed, 90 insertions(+), 108 deletions(-)
I've pulled these into msm for/next, so the conflicts will probably show up soon.
David
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation