Skip to contentSkip to conversation

ARM: davinci: convert dm365 to using the new clocksource driver

PATCH Superseded Bartosz Golaszewski 3 participants 9 messages Dec 13, 2019 – Dec 19, 2019

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ARM: davinci: convert dm365 to using the new clocksource driver

From: Bartosz Golaszewski <[email protected]>

This is a follow-up to the big series converting DaVinci to using a proper clocksource driver. Last time we couldn't merge the entire series because of a bug that only appears on dm365 Soc when using ancient u-boot.

This series contains a workaround for this problem, a patch finally converting the platform as well as a removal of all obsolete code.

Bartosz Golaszewski (3):
clocksource: davinci: work around a clocksource problem on dm365 SoC
ARM: davinci: dm365: switch to using the clocksource driver
ARM: davinci: remove legacy timer support

 arch/arm/mach-davinci/Makefile              |   3 +-
 arch/arm/mach-davinci/devices-da8xx.c       |   1 -
 arch/arm/mach-davinci/devices.c             |  19 -
 arch/arm/mach-davinci/dm365.c               |  22 +-
 arch/arm/mach-davinci/include/mach/common.h |  17 -
 arch/arm/mach-davinci/include/mach/time.h   |  33 --
 arch/arm/mach-davinci/time.c                | 400 --------------------
 drivers/clocksource/timer-davinci.c         |   8 +-
 8 files changed, 22 insertions(+), 481 deletions(-)
 delete mode 100644 arch/arm/mach-davinci/include/mach/time.h
 delete mode 100644 arch/arm/mach-davinci/time.c
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/3 clocksource: davinci: work around a clocksource problem on dm365 SoC

From: Bartosz Golaszewski <[email protected]>

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 - just cache the enable bits for tim34.

---
 drivers/clocksource/timer-davinci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-davinci.c +6 -2
index 62745c962049..1c22443acaeb 100644
@@ -64,6 +64,8 @@ static struct {
 	unsigned int tim_off;
 } davinci_clocksource;
 
+static unsigned int davinci_clocksource_tim32_mode;
+
 static struct davinci_clockevent *
 to_davinci_clockevent(struct clock_event_device *clockevent)
 {
@@ -94,7 +96,7 @@ 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 <<
+	tcr |= davinci_clocksource_tim32_mode <<
 		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
 
 	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
@@ -107,7 +109,7 @@ 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 <<
+	tcr |= davinci_clocksource_tim32_mode <<
 		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
 
 	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
@@ -206,6 +208,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_tim32_mode = DAVINCI_TIMER_ENAMODE_PERIODIC;
 }
 
 /*
Signature · 1 line
2.23.0
#2 lore raw

Re: [PATCH 1/3] clocksource: davinci: work around a clocksource problem on dm365 SoC

Quoted 7 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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.

Quoted 5 lines

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 - just cache the enable bits for tim34.

I had a hard time groking this code. See suggested changes below for something that would make the intention more clear (to me at least).

Quoted 11 lines
---
  drivers/clocksource/timer-davinci.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/clocksource/timer-davinci.c +0 -0
index 62745c962049..1c22443acaeb 100644

drivers/clocksource/timer-davinci.c static struct { · line 67

Quoted 4 lines
drivers/clocksource/timer-davinci.c +1 -0
@@ -64,6 +64,8 @@ static struct {
  	unsigned int tim_off;
  } davinci_clocksource;
 
+static unsigned int davinci_clocksource_tim32_mode;

static unsigned bool davinci_clocksource_initialized;

drivers/clocksource/timer-davinci.c static void davinci_tim12_shutdown(void __iomem *base) · line 100

Quoted 11 lines
drivers/clocksource/timer-davinci.c +2 -1
+
  static struct davinci_clockevent *
  to_davinci_clockevent(struct clock_event_device *clockevent)
  {
@@ -94,7 +96,7 @@ 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 <<
+	tcr |= davinci_clocksource_tim32_mode <<
  		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
	if (davinci_clocksource_initialized)
		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
			DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;

drivers/clocksource/timer-davinci.c static void davinci_tim12_set_oneshot(void __iomem *base) · line 113

Quoted 9 lines
drivers/clocksource/timer-davinci.c +1 -1
  	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
@@ -107,7 +109,7 @@ 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 <<
+	tcr |= davinci_clocksource_tim32_mode <<
  		DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
	if (davinci_clocksource_initialized)
		tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
			DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;

drivers/clocksource/timer-davinci.c static void davinci_clocksource_init_tim34(void __iomem *base) · line 212

Quoted 8 lines
drivers/clocksource/timer-davinci.c +2 -0
  	writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
@@ -206,6 +208,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_tim32_mode = DAVINCI_TIMER_ENAMODE_PERIODIC;
	davinci_clocksource_initialized  = true;

drivers/clocksource/timer-davinci.c static void davinci_clocksource_init_tim34(void __iomem *base) · line 215

Quoted 4 lines
drivers/clocksource/timer-davinci.c +0 -0
  }
 
  /*

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

Re: [PATCH 1/3] clocksource: davinci: work around a clocksource problem on dm365 SoC

pon., 16 gru 2019 o 18:58 David Lechner <[email protected]> napisał(a):

Quoted 6 lines
Quoted 3 lines

+static unsigned int davinci_clocksource_tim32_mode;

static unsigned bool davinci_clocksource_initialized;

Quoted 15 lines

drivers/clocksource/timer-davinci.c static void davinci_tim12_shutdown(void __iomem *base) · line 100

Quoted 11 lines
drivers/clocksource/timer-davinci.c +2 -1
+
  static struct davinci_clockevent *
  to_davinci_clockevent(struct clock_event_device *clockevent)
  {
@@ -94,7 +96,7 @@ 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 <<
+     tcr |= davinci_clocksource_tim32_mode <<
              DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
        if (davinci_clocksource_initialized)
                tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
                        DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;

I thought about doing this initially, but then figured this code would be called a lot, so why not avoid branching and just store the right value? Alternatively we can do:

    if (likely(davinci_clocksource_initialized)
        ....

Bart

#4 lore raw

Re: [PATCH 1/3] clocksource: davinci: work around a clocksource problem on dm365 SoC

Quoted 23 lines · Bartosz Golaszewski

pon., 16 gru 2019 o 18:58 David Lechner <[email protected]> napisał(a):

Quoted 6 lines
Quoted 3 lines

+static unsigned int davinci_clocksource_tim32_mode;

static unsigned bool davinci_clocksource_initialized;

Quoted 15 lines

drivers/clocksource/timer-davinci.c static void davinci_tim12_shutdown(void __iomem *base) · line 100

Quoted 11 lines
drivers/clocksource/timer-davinci.c +2 -1
+
   static struct davinci_clockevent *
   to_davinci_clockevent(struct clock_event_device *clockevent)
   {
@@ -94,7 +96,7 @@ 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 <<
+     tcr |= davinci_clocksource_tim32_mode <<
               DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
         if (davinci_clocksource_initialized)
                 tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
                         DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
Quoted 7 lines

I thought about doing this initially, but then figured this code would be called a lot, so why not avoid branching and just store the right value? Alternatively we can do:

     if (likely(davinci_clocksource_initialized)
         ....

Unless there is a measurable performance difference, I think it would be better with if/likely.

#5 lore raw

Re: [PATCH 1/3] clocksource: davinci: work around a clocksource problem on dm365 SoC

In reply to Bartosz Golaszewski

Hi Bart,

Quoted 7 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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.

Quoted 7 lines

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 - just cache the enable bits for tim34.

Timer Global Control Register (TGCR) has bits to reset both halves of timer. Does placing both halves in reset, waiting a bit (say 10ms) and then taking them out of reset help solve the this problem?

Also, there are LPSCs controlling the timers. As an experiment, can you see if using LPSC_STATE_SWRSTDISABLE instead of LPSC_STATE_DISABLE in davinci_lpsc_clk_disable() and then doing a clk_disable() + clk_enable() on timer can get the timer out of this bad state.

We need some way for Linux to start on a clean state after bootloader is done. And trying to reset the timer before use seems to be a better way to accomplish it.

I assume the original code was just lucky in not hitting this case?

Thanks,
Sekhar

#6 lore raw

Re: [PATCH 1/3] clocksource: davinci: work around a clocksource problem on dm365 SoC

śr., 18 gru 2019 o 10:28 Sekhar Nori <[email protected]> napisał(a):

Quoted 14 lines

Hi Bart,

Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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.

Quoted 9 lines
Quoted 4 lines

I've been unable to figure out why that is, but a workaround for this is straightforward - just cache the enable bits for tim34.

Timer Global Control Register (TGCR) has bits to reset both halves of timer. Does placing both halves in reset, waiting a bit (say 10ms) and then taking them out of reset help solve the this problem?

No, it doesn't change anything. On u-boot present on my dm365-evm, tim34 is not in reset when we get to linux, while tim12 is in reset, but putting tim34 in reset in linux doesn't seem to change anything.

Quoted 4 lines

Also, there are LPSCs controlling the timers. As an experiment, can you see if using LPSC_STATE_SWRSTDISABLE instead of LPSC_STATE_DISABLE in davinci_lpsc_clk_disable() and then doing a clk_disable() + clk_enable() on timer can get the timer out of this bad state.

I tried several combinations of this e.g. normal prepare_enable -> disable -> enable, disable -> enable, disable -> delay -> enable etc. and neither worked.

Quoted 7 lines

We need some way for Linux to start on a clean state after bootloader is done. And trying to reset the timer before use seems to be a better way to accomplish it.

I assume the original code was just lucky in not hitting this case?

I guess so. It used to re-read the registers instead of assuming certain values. When I did it too, there was no problem, it's only when we dropped re-reading that this must have appeared.

Bart

#7 lore raw

PATCH 2/3 ARM: davinci: dm365: switch to using the clocksource driver

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

We now have a proper clocksource driver for davinci. Switch the dm365 platform to using it.

---
 arch/arm/mach-davinci/dm365.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
arch/arm/mach-davinci/dm365.c +15 -7
index 9fc5c73cc0be..c1e0d46996e4 100644
@@ -35,7 +35,8 @@
 #include <mach/cputype.h>
 #include <mach/mux.h>
 #include <mach/serial.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "asp.h"
 #include "davinci.h"
@@ -660,10 +661,16 @@ static struct davinci_id dm365_ids[] = {
 	},
 };
 
-static struct davinci_timer_info dm365_timer_info = {
-	.timers		= davinci_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+/*
+ * Bottom half of timer0 is used for clockevent, top half is used for
+ * clocksource.
+ */
+static const struct davinci_timer_cfg dm365_timer_cfg = {
+	.reg = DEFINE_RES_IO(DAVINCI_TIMER0_BASE, SZ_128),
+	.irq = {
+		DEFINE_RES_IRQ(DAVINCI_INTC_IRQ(IRQ_TINT0_TINT12)),
+		DEFINE_RES_IRQ(DAVINCI_INTC_IRQ(IRQ_TINT0_TINT34)),
+	},
 };
 
 #define DM365_UART1_BASE	(IO_PHYS + 0x106000)
@@ -723,7 +730,6 @@ static const struct davinci_soc_info davinci_soc_info_dm365 = {
 	.pinmux_base		= DAVINCI_SYSTEM_MODULE_BASE,
 	.pinmux_pins		= dm365_pins,
 	.pinmux_pins_num	= ARRAY_SIZE(dm365_pins),
-	.timer_info		= &dm365_timer_info,
 	.emac_pdata		= &dm365_emac_pdata,
 	.sram_dma		= 0x00010000,
 	.sram_len		= SZ_32K,
@@ -771,6 +777,7 @@ void __init dm365_init_time(void)
 {
 	void __iomem *pll1, *pll2, *psc;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DM365_REF_FREQ);
 
@@ -789,7 +796,8 @@ void __init dm365_init_time(void)
 		return;
 	}
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &dm365_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 void __init dm365_register_clocks(void)
Signature · 1 line
2.23.0
#8 lore raw

PATCH 3/3 ARM: davinci: remove legacy timer support

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

All platforms have now been switched to the new clocksource driver. Remove the old code and various no longer needed bits and pieces.

---
 arch/arm/mach-davinci/Makefile              |   3 +-
 arch/arm/mach-davinci/devices-da8xx.c       |   1 -
 arch/arm/mach-davinci/devices.c             |  19 -
 arch/arm/mach-davinci/include/mach/common.h |  17 -
 arch/arm/mach-davinci/include/mach/time.h   |  33 --
 arch/arm/mach-davinci/time.c                | 400 --------------------
 6 files changed, 1 insertion(+), 472 deletions(-)
 delete mode 100644 arch/arm/mach-davinci/include/mach/time.h
 delete mode 100644 arch/arm/mach-davinci/time.c
arch/arm/mach-davinci/Makefile +1 -2
index a03d8443ef08..58838a9de651 100644
@@ -7,8 +7,7 @@
 ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include
 
 # Common objects
-obj-y 					:= time.o serial.o usb.o \
-					   common.o sram.o
+obj-y 					:= serial.o usb.o common.o sram.o
 
 obj-$(CONFIG_DAVINCI_MUX)		+= mux.o
 
arch/arm/mach-davinci/devices-da8xx.c +0 -1
index 2d69e704f7f6..feb206bdf6e1 100644
@@ -21,7 +21,6 @@
 #include <mach/common.h>
 #include <mach/cputype.h>
 #include <mach/da8xx.h>
-#include <mach/time.h>
 
 #include "asp.h"
 #include "cpuidle.h"
arch/arm/mach-davinci/devices.c +0 -19
index 3e447d468845..d912d62a0eca 100644
@@ -17,7 +17,6 @@
 #include <mach/hardware.h>
 #include <mach/cputype.h>
 #include <mach/mux.h>
-#include <mach/time.h>
 
 #include "davinci.h"
 #include "irqs.h"
@@ -303,21 +302,3 @@ int davinci_gpio_register(struct resource *res, int size, void *pdata)
 	davinci_gpio_device.dev.platform_data = pdata;
 	return platform_device_register(&davinci_gpio_device);
 }
-
-/*-------------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------------*/
-
-struct davinci_timer_instance davinci_timer_instance[2] = {
-	{
-		.base		= DAVINCI_TIMER0_BASE,
-		.bottom_irq	= DAVINCI_INTC_IRQ(IRQ_TINT0_TINT12),
-		.top_irq	= DAVINCI_INTC_IRQ(IRQ_TINT0_TINT34),
-	},
-	{
-		.base		= DAVINCI_TIMER1_BASE,
-		.bottom_irq	= DAVINCI_INTC_IRQ(IRQ_TINT1_TINT12),
-		.top_irq	= DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34),
-	},
-};
-
arch/arm/mach-davinci/include/mach/common.h +0 -17
index 9526e5da0d33..139b83de011d 100644
@@ -22,22 +22,6 @@
 #define DAVINCI_INTC_START		NR_IRQS
 #define DAVINCI_INTC_IRQ(_irqnum)	(DAVINCI_INTC_START + (_irqnum))
 
-void davinci_timer_init(struct clk *clk);
-
-struct davinci_timer_instance {
-	u32		base;
-	u32		bottom_irq;
-	u32		top_irq;
-	unsigned long	cmp_off;
-	unsigned int	cmp_irq;
-};
-
-struct davinci_timer_info {
-	struct davinci_timer_instance	*timers;
-	unsigned int			clockevent_id;
-	unsigned int			clocksource_id;
-};
-
 struct davinci_gpio_controller;
 
 /*
@@ -58,7 +42,6 @@ struct davinci_soc_info {
 	u32				pinmux_base;
 	const struct mux_config		*pinmux_pins;
 	unsigned long			pinmux_pins_num;
-	struct davinci_timer_info	*timer_info;
 	int				gpio_type;
 	u32				gpio_base;
 	unsigned			gpio_num;
arch/arm/mach-davinci/include/mach/time.h deleted +0 -33
deleted file mode 100644
index ba913736990f..000000000000
@@ -1,33 +0,0 @@
-/*
- * Local header file for DaVinci time code.
- *
- * Author: Kevin Hilman, MontaVista Software, Inc. <[email protected]>
- *
- * 2007 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-#ifndef __ARCH_ARM_MACH_DAVINCI_TIME_H
-#define __ARCH_ARM_MACH_DAVINCI_TIME_H
-
-#define DAVINCI_TIMER1_BASE		(IO_PHYS + 0x21800)
-
-enum {
-	T0_BOT,
-	T0_TOP,
-	T1_BOT,
-	T1_TOP,
-	NUM_TIMERS
-};
-
-#define IS_TIMER1(id)		(id & 0x2)
-#define IS_TIMER0(id)		(!IS_TIMER1(id))
-#define IS_TIMER_TOP(id)	((id & 0x1))
-#define IS_TIMER_BOT(id)	(!IS_TIMER_TOP(id))
-
-#define ID_TO_TIMER(id)		(IS_TIMER1(id) != 0)
-
-extern struct davinci_timer_instance davinci_timer_instance[];
-
-#endif /* __ARCH_ARM_MACH_DAVINCI_TIME_H */
arch/arm/mach-davinci/time.c deleted +0 -400

400 lines not on this page · raw message

Signature · 1 line
2.23.0