[v2,1/3] clocksource: davinci: only enable tim34 in periodic mode once it's initialized
diff mbox series

Message ID 20191224100328.13608-2-brgl@bgdev.pl
State New
Headers show
Series
  • ARM: davinci: convert dm365 to using the new clocksource driver
Related show

Commit Message

Bartosz Golaszewski Dec. 24, 2019, 10:03 a.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

The DM365 platform has a strange quirk (only present when using ancient
u-boot - mainline u-boot v2013.01 and later works fine) where if we
enable the second half of the timer in periodic mode before we do its
initialization - the time won't start flowing and we can't boot.

When using more recent u-boot, we can enable the timer, then reinitialize
it and all works fine.

I've been unable to figure out why that is, but a workaround for this
is straightforward - don't enable the tim34 timer in periodic mode until
it's properly initialized.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/clocksource/timer-davinci.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Daniel Lezcano Jan. 9, 2020, 11:12 p.m. UTC | #1
On 24/12/2019 11:03, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> The DM365 platform has a strange quirk (only present when using ancient
> u-boot - mainline u-boot v2013.01 and later works fine) where if we
> enable the second half of the timer in periodic mode before we do its
> initialization - the time won't start flowing and we can't boot.
> 
> When using more recent u-boot, we can enable the timer, then reinitialize
> it and all works fine.
> 
> I've been unable to figure out why that is, but a workaround for this
> is straightforward - don't enable the tim34 timer in periodic mode until
> it's properly initialized.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/clocksource/timer-davinci.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> index 62745c962049..2801f21bb0e2 100644
> --- a/drivers/clocksource/timer-davinci.c
> +++ b/drivers/clocksource/timer-davinci.c
> @@ -62,6 +62,7 @@ static struct {
>  	struct clocksource dev;
>  	void __iomem *base;
>  	unsigned int tim_off;
> +	bool initialized;
>  } davinci_clocksource;
>  
>  static struct davinci_clockevent *
> @@ -94,8 +95,9 @@ static void davinci_tim12_shutdown(void __iomem *base)
>  	 * halves. In this case TIM34 runs in periodic mode and we must
>  	 * not modify it.
>  	 */
> -	tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
> -		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
> +	if (likely(davinci_clocksource.initialized))
> +		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
> +		       DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
>  
>  	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
>  }
> @@ -107,8 +109,9 @@ static void davinci_tim12_set_oneshot(void __iomem *base)
>  	tcr = DAVINCI_TIMER_ENAMODE_ONESHOT <<
>  		DAVINCI_TIMER_ENAMODE_SHIFT_TIM12;
>  	/* Same as above. */
> -	tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
> -		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
> +	if (likely(davinci_clocksource.initialized))
> +		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
> +		       DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
>  
>  	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
>  }
> @@ -206,6 +209,8 @@ static void davinci_clocksource_init_tim34(void __iomem *base)
>  	writel_relaxed(0x0, base + DAVINCI_TIMER_REG_TIM34);
>  	writel_relaxed(UINT_MAX, base + DAVINCI_TIMER_REG_PRD34);
>  	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
> +
> +	davinci_clocksource.initialized = true;
>  }

Why not move clockevents_config_and_register() after
davinci_clocksource_init_tim34() is called ?
Bartosz Golaszewski Jan. 10, 2020, 5:05 p.m. UTC | #2
pt., 10 sty 2020 o 00:12 Daniel Lezcano <daniel.lezcano@linaro.org> napisaƂ(a):
>
> On 24/12/2019 11:03, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > The DM365 platform has a strange quirk (only present when using ancient
> > u-boot - mainline u-boot v2013.01 and later works fine) where if we
> > enable the second half of the timer in periodic mode before we do its
> > initialization - the time won't start flowing and we can't boot.
> >
> > When using more recent u-boot, we can enable the timer, then reinitialize
> > it and all works fine.
> >
> > I've been unable to figure out why that is, but a workaround for this
> > is straightforward - don't enable the tim34 timer in periodic mode until
> > it's properly initialized.
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Why not move clockevents_config_and_register() after
> davinci_clocksource_init_tim34() is called ?

Ha! Yes, that works too. I'll send a v3 shortly.

Bart

Patch
diff mbox series

diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
index 62745c962049..2801f21bb0e2 100644
--- a/drivers/clocksource/timer-davinci.c
+++ b/drivers/clocksource/timer-davinci.c
@@ -62,6 +62,7 @@  static struct {
 	struct clocksource dev;
 	void __iomem *base;
 	unsigned int tim_off;
+	bool initialized;
 } davinci_clocksource;
 
 static struct davinci_clockevent *
@@ -94,8 +95,9 @@  static void davinci_tim12_shutdown(void __iomem *base)
 	 * halves. In this case TIM34 runs in periodic mode and we must
 	 * not modify it.
 	 */
-	tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
-		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
+	if (likely(davinci_clocksource.initialized))
+		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
+		       DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
 
 	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
 }
@@ -107,8 +109,9 @@  static void davinci_tim12_set_oneshot(void __iomem *base)
 	tcr = DAVINCI_TIMER_ENAMODE_ONESHOT <<
 		DAVINCI_TIMER_ENAMODE_SHIFT_TIM12;
 	/* Same as above. */
-	tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
-		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
+	if (likely(davinci_clocksource.initialized))
+		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
+		       DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
 
 	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
 }
@@ -206,6 +209,8 @@  static void davinci_clocksource_init_tim34(void __iomem *base)
 	writel_relaxed(0x0, base + DAVINCI_TIMER_REG_TIM34);
 	writel_relaxed(UINT_MAX, base + DAVINCI_TIMER_REG_PRD34);
 	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
+
+	davinci_clocksource.initialized = true;
 }
 
 /*