Skip to contentSkip to conversation

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

PATCH Superseded Bartosz Golaszewski 3 participants 6 messages Dec 24, 2019 – Jan 10, 2020

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

From: Bartosz Golaszewski <[email protected]>

Hi Sekhar,

I'm resending this (with fixes) as other solutions have failed and I think that this is a correct thing to do after all. In the end: with this patch we do bring the clock to a defined state before enabling it.

Let me know what you think about it.

---

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.

v1 -> v2:
- simplify patch 1/3 by using a boolean flag instead of caching the value bits for TIM34

Bartosz Golaszewski (3):
clocksource: davinci: only enable tim34 in periodic mode once it's
initialized
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         |  13 +-
 8 files changed, 25 insertions(+), 483 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 v2 1/3 clocksource: davinci: only enable tim34 in periodic mode once it's initialized

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 - don't enable the tim34 timer in periodic mode until it's properly initialized.

---
 drivers/clocksource/timer-davinci.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/clocksource/timer-davinci.c +9 -4
index 62745c962049..2801f21bb0e2 100644
@@ -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;
 }
 
 /*
Signature · 1 line
2.23.0
#5 lore raw

PATCH v2 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
#4 lore raw

PATCH v2 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
#2 lore raw

Re: [PATCH v2 1/3] clocksource: davinci: only enable tim34 in periodic mode once it's initialized

In reply to Bartosz Golaszewski
Quoted 56 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.

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.

---
 drivers/clocksource/timer-davinci.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/clocksource/timer-davinci.c +7 -4
index 62745c962049..2801f21bb0e2 100644
@@ -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);
 }

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

Quoted 6 lines
drivers/clocksource/timer-davinci.c +2 -0
@@ -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 ?

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#3 lore raw

Re: [PATCH v2 1/3] clocksource: davinci: only enable tim34 in periodic mode once it's initialized

pt., 10 sty 2020 o 00:12 Daniel Lezcano <[email protected]> napisał(a):

Quoted 12 lines · Bartosz Golaszewski
Quoted 10 lines

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 8 lines
Quoted 5 lines

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.

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