Skip to contentSkip to conversation

Re-Send Timer support for ARM Tegra

PATCH Superseded Svyatoslav Ryhel 3 participants 10 messages Jan 17, 2023 – Jan 18, 2023

Subsystems (5)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover Re-Send Timer support for ARM Tegra

- ARM: tegra: remap clock_osc_freq for all Tegra family Enum clock_osc_freq was designed to use only with T20. This patch remaps it to use additional frequencies, added in T30+ SoC while maintaining backwards compatibility with T20.

- drivers: timer: add timer driver for ARMv7 based Tegra devices Add timer support for T20/T30/T114 and T124 based devices. Driver is based on DM, has device tree support and can be used on SPL and early boot stage.

- ARM: tegra: include timer as default option Enable TIMER as default option for add Tegra devices and enable TEGRA_TIMER for TEGRA_ARMV7_COMMON. Additionally enable SPL_TIMER if build as SPL part and drop deprecated configs from common header.

P. S. I have no arm64 Tegra and according to comment in tegra-common.h
Use the Tegra US timer on ARMv7, but the architected timer on ARMv8.

Svyatoslav Ryhel (3):
ARM: tegra: remap clock_osc_freq for all Tegra family
drivers: timer: add timer driver for ARMv7 based Tegra devices
ARM: tegra: include timer as default option

 arch/arm/Kconfig                        |   1 +
 arch/arm/include/asm/arch-tegra/clock.h |   9 +-
 arch/arm/mach-tegra/Kconfig             |   2 +
 arch/arm/mach-tegra/clock.c             |  17 +++-
 arch/arm/mach-tegra/cpu.c               |  70 ++++++++++---
 arch/arm/mach-tegra/tegra114/clock.c    |  13 +--
 arch/arm/mach-tegra/tegra124/clock.c    |  13 +--
 arch/arm/mach-tegra/tegra20/clock.c     |   4 +-
 arch/arm/mach-tegra/tegra210/clock.c    |  22 +----
 arch/arm/mach-tegra/tegra30/clock.c     |  10 +-
 drivers/timer/Kconfig                   |   8 ++
 drivers/timer/Makefile                  |   1 +
 drivers/timer/tegra-timer.c             | 124 ++++++++++++++++++++++++
 drivers/usb/host/ehci-tegra.c           |  46 +++++++--
 include/configs/tegra-common.h          |   6 --
 15 files changed, 267 insertions(+), 79 deletions(-)
 create mode 100644 drivers/timer/tegra-timer.c
Signature · 1 line
2.37.2
#1 lore raw

PATCH v3 1/3 ARM: tegra: remap clock_osc_freq for all Tegra family

Enum clock_osc_freq was designed to use only with T20. This patch remaps it to use additional frequencies, added in T30+ SoC while maintaining backwards compatibility with T20.

---
 arch/arm/include/asm/arch-tegra/clock.h |  9 ++--
 arch/arm/mach-tegra/clock.c             | 17 ++++--
 arch/arm/mach-tegra/cpu.c               | 70 ++++++++++++++++++++-----
 arch/arm/mach-tegra/tegra114/clock.c    | 13 ++---
 arch/arm/mach-tegra/tegra124/clock.c    | 13 ++---
 arch/arm/mach-tegra/tegra20/clock.c     |  4 +-
 arch/arm/mach-tegra/tegra210/clock.c    | 22 ++------
 arch/arm/mach-tegra/tegra30/clock.c     | 10 +---
 drivers/usb/host/ehci-tegra.c           | 46 ++++++++++++----
 9 files changed, 131 insertions(+), 73 deletions(-)
arch/arm/include/asm/arch-tegra/clock.h +5 -4
index 6586015fd2..1dd5d0742c 100644
@@ -13,12 +13,13 @@ struct udevice;
 /* Set of oscillator frequencies supported in the internal API. */
 enum clock_osc_freq {
 	/* All in MHz, so 13_0 is 13.0MHz */
-	CLOCK_OSC_FREQ_13_0,
-	CLOCK_OSC_FREQ_19_2,
-	CLOCK_OSC_FREQ_12_0,
-	CLOCK_OSC_FREQ_26_0,
+	CLOCK_OSC_FREQ_13_0 = 0,
+	CLOCK_OSC_FREQ_16_8,
+	CLOCK_OSC_FREQ_19_2 = 4,
 	CLOCK_OSC_FREQ_38_4,
+	CLOCK_OSC_FREQ_12_0 = 8,
 	CLOCK_OSC_FREQ_48_0,
+	CLOCK_OSC_FREQ_26_0 = 12,
 
 	CLOCK_OSC_FREQ_COUNT,
 };
arch/arm/mach-tegra/clock.c +14 -3
index 77c8ad978e..11bffc1701 100644
@@ -28,16 +28,23 @@
 static unsigned pll_rate[CLOCK_ID_COUNT];
 
 /*
- * The oscillator frequency is fixed to one of four set values. Based on this
+ * The oscillator frequency is fixed to one of seven set values. Based on this
  * the other clocks are set up appropriately.
  */
 static unsigned osc_freq[CLOCK_OSC_FREQ_COUNT] = {
 	13000000,
+	16800000,
+	       0,
+	       0,
 	19200000,
-	12000000,
-	26000000,
 	38400000,
+	       0,
+	       0,
+	12000000,
 	48000000,
+	       0,
+	       0,
+	26000000,
 };
 
 /* return 1 if a peripheral ID is in range */
@@ -766,6 +773,7 @@ void tegra30_set_up_pllp(void)
 	 */
 	switch (clock_get_osc_freq()) {
 	case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
+	case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
 		clock_set_rate(CLOCK_ID_PERIPH, 408, 12, 0, 8);
 		clock_set_rate(CLOCK_ID_CGENERAL, 456, 12, 1, 8);
 		break;
@@ -776,10 +784,13 @@ void tegra30_set_up_pllp(void)
 		break;
 
 	case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
+	case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
 		clock_set_rate(CLOCK_ID_PERIPH, 408, 13, 0, 8);
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
 		break;
+
 	case CLOCK_OSC_FREQ_19_2:
+	case CLOCK_OSC_FREQ_38_4:
 	default:
 		/*
 		 * These are not supported. It is too early to print a
arch/arm/mach-tegra/cpu.c +56 -14

123 lines not on this page · raw message

arch/arm/mach-tegra/tegra114/clock.c +5 -8
index 703a2314e7..143f86863f 100644
@@ -459,8 +459,7 @@ struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = {
 
 /*
  * Get the oscillator frequency, from the corresponding hardware configuration
- * field. Note that T30/T114 support 3 new higher freqs, but we map back
- * to the old T20 freqs. Support for the higher oscillators is TBD.
+ * field. Note that T30+ supports 3 new higher freqs.
  */
 enum clock_osc_freq clock_get_osc_freq(void)
 {
@@ -469,12 +468,7 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	u32 reg;
 
 	reg = readl(&clkrst->crc_osc_ctrl);
-	reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
-
-	if (reg & 1)				/* one of the newer freqs */
-		printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg);
-
-	return reg >> 2;	/* Map to most common (T20) freqs */
+	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
 }
 
 /* Returns a pointer to the clock source register for a peripheral */
@@ -674,6 +668,7 @@ void clock_early_init(void)
 	 */
 	switch (clock_get_osc_freq()) {
 	case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
+	case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
 		break;
@@ -684,10 +679,12 @@ void clock_early_init(void)
 		break;
 
 	case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
+	case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
 		break;
 	case CLOCK_OSC_FREQ_19_2:
+	case CLOCK_OSC_FREQ_38_4:
 	default:
 		/*
 		 * These are not supported. It is too early to print a
arch/arm/mach-tegra/tegra124/clock.c +5 -8
index bbfe184652..da38b26c27 100644
@@ -601,8 +601,7 @@ struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = {
 
 /*
  * Get the oscillator frequency, from the corresponding hardware configuration
- * field. Note that Tegra30+ support 3 new higher freqs, but we map back
- * to the old T20 freqs. Support for the higher oscillators is TBD.
+ * field. Note that T30+ supports 3 new higher freqs.
  */
 enum clock_osc_freq clock_get_osc_freq(void)
 {
@@ -611,12 +610,7 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	u32 reg;
 
 	reg = readl(&clkrst->crc_osc_ctrl);
-	reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
-
-	if (reg & 1)				/* one of the newer freqs */
-		printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg);
-
-	return reg >> 2;	/* Map to most common (T20) freqs */
+	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
 }
 
 /* Returns a pointer to the clock source register for a peripheral */
@@ -854,6 +848,7 @@ void clock_early_init(void)
 	 */
 	switch (clock_get_osc_freq()) {
 	case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
+	case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
 		break;
@@ -864,10 +859,12 @@ void clock_early_init(void)
 		break;
 
 	case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
+	case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
 		break;
 	case CLOCK_OSC_FREQ_19_2:
+	case CLOCK_OSC_FREQ_38_4:
 	default:
 		/*
 		 * These are not supported. It is too early to print a
arch/arm/mach-tegra/tegra20/clock.c +3 -1
index 3b50a81194..8c127430aa 100644
@@ -399,7 +399,9 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	u32 reg;
 
 	reg = readl(&clkrst->crc_osc_ctrl);
-	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
+	reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
+
+	return reg << 2;
 }
 
 /* Returns a pointer to the clock source register for a peripheral */
arch/arm/mach-tegra/tegra210/clock.c +4 -18
index 10c2478df7..330753f2ad 100644
@@ -672,8 +672,7 @@ struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = {
 
 /*
  * Get the oscillator frequency, from the corresponding hardware configuration
- * field. Note that Tegra30+ support 3 new higher freqs, but we map back
- * to the old T20 freqs. Support for the higher oscillators is TBD.
+ * field. Note that T30+ supports 3 new higher freqs.
  */
 enum clock_osc_freq clock_get_osc_freq(void)
 {
@@ -682,22 +681,7 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	u32 reg;
 
 	reg = readl(&clkrst->crc_osc_ctrl);
-	reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
-	/*
-	 * 0 = 13MHz, 1 = 16.8MHz, 4 = 19.2MHz, 5 = 38.4MHz,
-	 * 8 = 12MHz, 9 = 48MHz,  12 = 26MHz
-	 */
-	if (reg == 5) {
-		debug("OSC_FREQ is 38.4MHz (%d) ...\n", reg);
-		/* Map it to the 5th CLOCK_OSC_ enum, i.e. 4 */
-		return 4;
-	}
-
-	/*
-	 * Map to most common (T20) freqs (except 38.4, handled above):
-	 *  13/16.8 = 0, 19.2 = 1, 12/48 = 2, 26 = 3
-	 */
-	return reg >> 2;
+	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
 }
 
 /* Returns a pointer to the clock source register for a peripheral */
@@ -986,6 +970,7 @@ void clock_early_init(void)
 	 */
 	switch (clock_get_osc_freq()) {
 	case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
+	case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
 		break;
@@ -996,6 +981,7 @@ void clock_early_init(void)
 		break;
 
 	case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
+	case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
 		clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
 		clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
 		break;
arch/arm/mach-tegra/tegra30/clock.c +2 -8
index 54855d6be7..04ad5c504d 100644
@@ -439,8 +439,7 @@ struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = {
 
 /*
  * Get the oscillator frequency, from the corresponding hardware configuration
- * field. Note that T30 supports 3 new higher freqs, but we map back
- * to the old T20 freqs. Support for the higher oscillators is TBD.
+ * field. Note that T30+ supports 3 new higher freqs.
  */
 enum clock_osc_freq clock_get_osc_freq(void)
 {
@@ -449,12 +448,7 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	u32 reg;
 
 	reg = readl(&clkrst->crc_osc_ctrl);
-	reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
-
-	if (reg & 1)			/* one of the newer freqs */
-		printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg);
-
-	return reg >> 2;	/* Map to most common (T20) freqs */
+	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
 }
 
 /* Returns a pointer to the clock source register for a peripheral */
drivers/usb/host/ehci-tegra.c +37 -9

79 lines not on this page · raw message

Signature · 1 line
2.37.2
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] ARM: tegra: remap clock_osc_freq for all Tegra family

Quoted 10 lines · Svyatoslav Ryhel

Enum clock_osc_freq was designed to use only with T20. This patch remaps it to use additional frequencies, added in T30+ SoC while maintaining backwards compatibility with T20.

Quoted 12 lines
---
 arch/arm/include/asm/arch-tegra/clock.h |  9 ++--
 arch/arm/mach-tegra/clock.c             | 17 ++++--
 arch/arm/mach-tegra/cpu.c               | 70 ++++++++++++++++++++-----
 arch/arm/mach-tegra/tegra114/clock.c    | 13 ++---
 arch/arm/mach-tegra/tegra124/clock.c    | 13 ++---
 arch/arm/mach-tegra/tegra20/clock.c     |  4 +-
 arch/arm/mach-tegra/tegra210/clock.c    | 22 ++------
 arch/arm/mach-tegra/tegra30/clock.c     | 10 +---
 drivers/usb/host/ehci-tegra.c           | 46 ++++++++++++----
 9 files changed, 131 insertions(+), 73 deletions(-)
#3 lore raw

PATCH v3 2/3 drivers: timer: add timer driver for ARMv7 based Tegra devices

In reply to Svyatoslav Ryhel

Add timer support for T20/T30/T114 and T124 based devices. Driver is based on DM, has device tree support and can be used on SPL and early boot stage.

---
 drivers/timer/Kconfig       |   8 +++
 drivers/timer/Makefile      |   1 +
 drivers/timer/tegra-timer.c | 124 ++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/timer/tegra-timer.c
drivers/timer/Kconfig +8 -0
index 6d6665005c..f32bd16227 100644
@@ -252,6 +252,14 @@ config STM32_TIMER
 	  Select this to enable support for the timer found on
 	  STM32 devices.
 
+config TEGRA_TIMER
+	bool "Tegra timer support"
+	depends on TIMER
+	select TIMER_EARLY
+	help
+	  Select this to enable support for the timer found on
+	  Tegra devices.
+
 config X86_TSC_TIMER
 	bool "x86 Time-Stamp Counter (TSC) timer support"
 	depends on TIMER && X86
drivers/timer/Makefile +1 -0
index 6470fd5426..3c92113fc6 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_SP804_TIMER)	+= sp804_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
 obj-$(CONFIG_ARM_GLOBAL_TIMER)	+= arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)	+= stm32_timer.o
+obj-$(CONFIG_TEGRA_TIMER)	+= tegra-timer.o
 obj-$(CONFIG_X86_TSC_TIMER)	+= tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)		+= mtk_timer.o
 obj-$(CONFIG_MCHP_PIT64B_TIMER)	+= mchp-pit64b-timer.o
drivers/timer/tegra-timer.c new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.37.2
#4 lore raw

Re: [PATCH v3 2/3] drivers: timer: add timer driver for ARMv7 based Tegra devices

Hi Svyatoslav,

Quoted 80 lines · Svyatoslav Ryhel

Add timer support for T20/T30/T114 and T124 based devices. Driver is based on DM, has device tree support and can be used on SPL and early boot stage.

---
 drivers/timer/Kconfig       |   8 +++
 drivers/timer/Makefile      |   1 +
 drivers/timer/tegra-timer.c | 124 ++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/timer/tegra-timer.c
drivers/timer/Kconfig +8 -0
index 6d6665005c..f32bd16227 100644
@@ -252,6 +252,14 @@ config STM32_TIMER
          Select this to enable support for the timer found on
          STM32 devices.
 
+config TEGRA_TIMER
+       bool "Tegra timer support"
+       depends on TIMER
+       select TIMER_EARLY
+       help
+         Select this to enable support for the timer found on
+         Tegra devices.
+
 config X86_TSC_TIMER
        bool "x86 Time-Stamp Counter (TSC) timer support"
        depends on TIMER && X86
drivers/timer/Makefile +1 -0
index 6470fd5426..3c92113fc6 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_SP804_TIMER)     += sp804_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
 obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)      += stm32_timer.o
+obj-$(CONFIG_TEGRA_TIMER)      += tegra-timer.o
 obj-$(CONFIG_X86_TSC_TIMER)    += tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)                += mtk_timer.o
 obj-$(CONFIG_MCHP_PIT64B_TIMER)        += mchp-pit64b-timer.o
drivers/timer/tegra-timer.c new file +24 -0
new file mode 100644
index 0000000000..cda460921f
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Svyatoslav Ryhel <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/tegra.h>
+
+#define TEGRA_OSC_CLK_ENB_L_SET                (NV_PA_CLK_RST_BASE + 0x320)
+#define TEGRA_OSC_SET_CLK_ENB_TMR      BIT(5)
+
+#define TEGRA_TIMER_USEC_CNTR          (NV_PA_TMRUS_BASE + 0)
+#define TEGRA_TIMER_USEC_CFG           (NV_PA_TMRUS_BASE + 4)
+
+#define TEGRA_TIMER_RATE               1000000 /* 1 MHz */
+
+u64 notrace timer_early_get_count(void)
+{

drivers/timer/tegra-timer.c line 34

Quoted 10 lines
drivers/timer/tegra-timer.c new file +10 -0
+       /* At this stage raw timer is used */
+       return readl(TEGRA_TIMER_USEC_CNTR);
+}
+
+unsigned long notrace timer_early_get_rate(void)
+{
+       return TEGRA_TIMER_RATE;
+}
+
+#if CONFIG_IS_ENABLED(BOOTSTAGE)

You shouldn't need the #ifdef as the code will just be dropped by the linker if not used.

drivers/timer/tegra-timer.c line 40

Quoted 6 lines
drivers/timer/tegra-timer.c new file +6 -0
+ulong timer_get_boot_us(void)
+{
+       u64 ticks = 0;
+       int ret;
+
+       ret = dm_timer_init();

You can't call this here since tracing and bootstage won't work (they need the timer before driver model starts) . You can check gd->timer and use the early one or the driver model one.

Quoted 5 lines
drivers/timer/tegra-timer.c new file +5 -0
+       if (!ret)
+               timer_get_count(gd->timer, &ticks);
+       else
+               ticks = timer_early_get_count();
+

drivers/timer/tegra-timer.c line 55

Quoted 10 lines
drivers/timer/tegra-timer.c new file +10 -0
+       return ticks;
+}
+#endif
+
+static notrace u64 tegra_timer_get_count(struct udevice *dev)
+{
+       u32 val = timer_early_get_count();
+       return timer_conv_64(val);
+}
+

[..]

Regards,
Simon

#5 lore raw

Re: [PATCH v3 2/3] drivers: timer: add timer driver for ARMv7 based Tegra devices

вт, 17 січ. 2023 р. о 22:30 Simon Glass <[email protected]> пише:

Quoted 89 lines

Hi Svyatoslav,

Quoted 85 lines · Svyatoslav Ryhel

Add timer support for T20/T30/T114 and T124 based devices. Driver is based on DM, has device tree support and can be used on SPL and early boot stage.

---
 drivers/timer/Kconfig       |   8 +++
 drivers/timer/Makefile      |   1 +
 drivers/timer/tegra-timer.c | 124 ++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/timer/tegra-timer.c
drivers/timer/Kconfig +8 -0
index 6d6665005c..f32bd16227 100644
@@ -252,6 +252,14 @@ config STM32_TIMER
          Select this to enable support for the timer found on
          STM32 devices.
 
+config TEGRA_TIMER
+       bool "Tegra timer support"
+       depends on TIMER
+       select TIMER_EARLY
+       help
+         Select this to enable support for the timer found on
+         Tegra devices.
+
 config X86_TSC_TIMER
        bool "x86 Time-Stamp Counter (TSC) timer support"
        depends on TIMER && X86
drivers/timer/Makefile +1 -0
index 6470fd5426..3c92113fc6 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_SP804_TIMER)     += sp804_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
 obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
 obj-$(CONFIG_STM32_TIMER)      += stm32_timer.o
+obj-$(CONFIG_TEGRA_TIMER)      += tegra-timer.o
 obj-$(CONFIG_X86_TSC_TIMER)    += tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)                += mtk_timer.o
 obj-$(CONFIG_MCHP_PIT64B_TIMER)        += mchp-pit64b-timer.o
drivers/timer/tegra-timer.c new file +29 -0
new file mode 100644
index 0000000000..cda460921f
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Svyatoslav Ryhel <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/tegra.h>
+
+#define TEGRA_OSC_CLK_ENB_L_SET                (NV_PA_CLK_RST_BASE + 0x320)
+#define TEGRA_OSC_SET_CLK_ENB_TMR      BIT(5)
+
+#define TEGRA_TIMER_USEC_CNTR          (NV_PA_TMRUS_BASE + 0)
+#define TEGRA_TIMER_USEC_CFG           (NV_PA_TMRUS_BASE + 4)
+
+#define TEGRA_TIMER_RATE               1000000 /* 1 MHz */
+
+u64 notrace timer_early_get_count(void)
+{
+       /* At this stage raw timer is used */
+       return readl(TEGRA_TIMER_USEC_CNTR);
+}
+
+unsigned long notrace timer_early_get_rate(void)
Quoted 8 lines

drivers/timer/tegra-timer.c line 34

Quoted 5 lines
drivers/timer/tegra-timer.c new file +5 -0
+{
+       return TEGRA_TIMER_RATE;
+}
+
+#if CONFIG_IS_ENABLED(BOOTSTAGE)

You shouldn't need the #ifdef as the code will just be dropped by the linker if not used.

Hello Simon! Thank you for your review!
Will do in V4

Quoted 11 lines

drivers/timer/tegra-timer.c line 40

Quoted 7 lines
drivers/timer/tegra-timer.c new file +6 -0
+ulong timer_get_boot_us(void)
+{
+       u64 ticks = 0;
+       int ret;
+
+       ret = dm_timer_init();

You can't call this here since tracing and bootstage won't work (they need the timer before driver model starts) . You can check gd->timer and use the early one or the driver model one.

Timer is tricky because it has to be active one of the first.
I consider using here early version unconditionally would be the best option. Will update in V4

Best regards, Svyatoslav R.

Quoted 20 lines
Quoted 6 lines
drivers/timer/tegra-timer.c new file +5 -0
+       if (!ret)
+               timer_get_count(gd->timer, &ticks);
+       else
+               ticks = timer_early_get_count();
+

drivers/timer/tegra-timer.c line 55

Quoted 10 lines
drivers/timer/tegra-timer.c new file +10 -0
+       return ticks;
+}
+#endif
+
+static notrace u64 tegra_timer_get_count(struct udevice *dev)
+{
+       u32 val = timer_early_get_count();
+       return timer_conv_64(val);
+}
+

[..]

Regards,
Simon

#6 lore raw

PATCH v3 3/3 ARM: tegra: include timer as default option

In reply to Svyatoslav Ryhel

Enable TIMER as default option for add Tegra devices and enable TEGRA_TIMER for TEGRA_ARMV7_COMMON. Additionally enable SPL_TIMER if build as SPL part and drop deprecated configs from common header.

---
 arch/arm/Kconfig               | 1 +
 arch/arm/mach-tegra/Kconfig    | 2 ++
 include/configs/tegra-common.h | 6 ------
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/arm/Kconfig +1 -0
index 3f68d0988b..4fce820350 100644
@@ -1334,6 +1334,7 @@ config ARCH_TEGRA
 	select GPIO_EXTRA_HEADER
 	imply DISTRO_DEFAULTS
 	imply FAT_WRITE
+	imply SPL_TIMER if SPL
 
 config ARCH_VEXPRESS64
 	bool "Support ARMv8 Arm Ltd. VExpress based boards and models"
arch/arm/mach-tegra/Kconfig +2 -0
index 1bef2fb233..173be3c439 100644
@@ -62,6 +62,7 @@ config TEGRA_COMMON
 	select MISC
 	select OF_CONTROL
 	select SPI
+	select TIMER
 	imply CMD_DM
 	imply CRC32_VERIFY
 
@@ -87,6 +88,7 @@ config TEGRA_ARMV7_COMMON
 	select TEGRA_NO_BPMP
 	select TEGRA_PINCTRL
 	select TEGRA_PMC
+	select TEGRA_TIMER
 
 config TEGRA_ARMV8_COMMON
 	bool "Tegra 64-bit common options"
include/configs/tegra-common.h +0 -6
index 2915db7f8b..390a2387ea 100644
@@ -15,12 +15,6 @@
 
 #include <asm/arch/tegra.h>		/* get chip and board defs */
 
-/* Use the Tegra US timer on ARMv7, but the architected timer on ARMv8. */
-#ifndef CONFIG_ARM64
-#define CONFIG_SYS_TIMER_RATE		1000000
-#define CONFIG_SYS_TIMER_COUNTER	NV_PA_TMRUS_BASE
-#endif
-
 /* Environment */
 
 /*
Signature · 1 line
2.37.2
#7 lore raw

RE: [PATCH v3 3/3] ARM: tegra: include timer as default option

Svyatoslav,

I was able to apply the first 2 patches OK to TOT u-boot-tegra/master, but not the this one (file offsets seem wrong). PTAL.

I also would like someone who's using or has used T20/T30 lately to take a look, as I haven't had any interaction with those boards or builds for years, and don't know that I can rule on the fitness of these patches. Once they get ACK'd by someone that's still using T20/T30, I can apply them and get a PR in to TomR.

Thanks,

Tom

-----Original Message-----
From: Svyatoslav Ryhel <[email protected]>
Sent: Tuesday, January 17, 2023 9:53 AM
To: Bharat Gooty <[email protected]>; Rayagonda Kokatanur <[email protected]>; Tom Warren <[email protected]>; Marek Vasut <[email protected]>; Svyatoslav Ryhel <[email protected]>; Maxim Schwalm <[email protected]>; Heinrich Schuchardt <[email protected]>; Michal Simek <[email protected]>; Stefan Roese <[email protected]>; Eugen Hristev <[email protected]>; Michael Walle <[email protected]>; Simon Glass <[email protected]>; Jim Liu <[email protected]>; William Zhang <[email protected]>; Rick Chen <[email protected]>; Stefan Herbrechtsmeier <[email protected]>; Andre Przywara <[email protected]>; Jaehoon Chung <[email protected]>
Cc: [email protected]
Subject: [PATCH v3 3/3] ARM: tegra: include timer as default option

External email: Use caution opening links or attachments

Enable TIMER as default option for add Tegra devices and enable TEGRA_TIMER for TEGRA_ARMV7_COMMON. Additionally enable SPL_TIMER if build as SPL part and drop deprecated configs from common header.

---
 arch/arm/Kconfig               | 1 +
 arch/arm/mach-tegra/Kconfig    | 2 ++
 include/configs/tegra-common.h | 6 ------
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/arm/Kconfig +1 -0
@@ -1334,6 +1334,7 @@ config ARCH_TEGRA
        select GPIO_EXTRA_HEADER
        imply DISTRO_DEFAULTS
        imply FAT_WRITE
+       imply SPL_TIMER if SPL
 
 config ARCH_VEXPRESS64
        bool "Support ARMv8 Arm Ltd. VExpress based boards and models"
arch/arm/mach-tegra/Kconfig +2 -0
@@ -62,6 +62,7 @@ config TEGRA_COMMON
        select MISC
        select OF_CONTROL
        select SPI
+       select TIMER
        imply CMD_DM
        imply CRC32_VERIFY
 
@@ -87,6 +88,7 @@ config TEGRA_ARMV7_COMMON
        select TEGRA_NO_BPMP
        select TEGRA_PINCTRL
        select TEGRA_PMC
+       select TEGRA_TIMER
 
 config TEGRA_ARMV8_COMMON
        bool "Tegra 64-bit common options"
include/configs/tegra-common.h +0 -6
@@ -15,12 +15,6 @@
 
 #include <asm/arch/tegra.h>            /* get chip and board defs */
 
-/* Use the Tegra US timer on ARMv7, but the architected timer on ARMv8. */ -#ifndef CONFIG_ARM64
-#define CONFIG_SYS_TIMER_RATE          1000000
-#define CONFIG_SYS_TIMER_COUNTER       NV_PA_TMRUS_BASE
-#endif
-
 /* Environment */
 
 /*
--

2.37.2

#8 lore raw

Re: [PATCH v3 3/3] ARM: tegra: include timer as default option

вт, 17 січ. 2023 р. о 22:08 Tom Warren <[email protected]> пише:

Quoted 5 lines

Svyatoslav,

I was able to apply the first 2 patches OK to TOT u-boot-tegra/master, but not the this one (file offsets seem wrong). PTAL.

Thank you very much for your review. This patchset was prepared and being re-send for 3-4 month, a week or so ago u-boot faced major kconfig rework, including tegra section. I will adjust this commit in v4.

Quoted 3 lines

I also would like someone who's using or has used T20/T30 lately to take a look, as I haven't had any interaction with those boards or builds for years, and don't know that I can rule on the fitness of these patches. Once they get ACK'd by someone that's still using T20/T30, I can apply them and get a PR in to TomR.

That would be quite hard to achieve. It seems that I am maintaining the biggest group of developers and users of T20/T30 (pmOS on Transformers). So far we have tested these patches for 4 month on all T20/T30 Asus Transformers, Google Nexus 7 2012, LG Optimus 4X HD and Optimus Vu, HTC One X, Surface RT. This should be representative for ventana, cardhu, kai and enterprise dev boards. Though it is up to you.

Quoted 5 lines

Thanks,

Tom

P. S. I would like you to be aware that I am willing to mainline a few more patch sets to improve Tegra 2 and Tegra 3 along with bringing many new Tegra based devices into mainline u-boot (estimated total commit number around 50). Devices I would like to add are roughly those I have named above.
Best regards, Svyatoslav R.

Quoted 68 lines

-----Original Message-----
From: Svyatoslav Ryhel <[email protected]>
Sent: Tuesday, January 17, 2023 9:53 AM
To: Bharat Gooty <[email protected]>; Rayagonda Kokatanur <[email protected]>; Tom Warren <[email protected]>; Marek Vasut <[email protected]>; Svyatoslav Ryhel <[email protected]>; Maxim Schwalm <[email protected]>; Heinrich Schuchardt <[email protected]>; Michal Simek <[email protected]>; Stefan Roese <[email protected]>; Eugen Hristev <[email protected]>; Michael Walle <[email protected]>; Simon Glass <[email protected]>; Jim Liu <[email protected]>; William Zhang <[email protected]>; Rick Chen <[email protected]>; Stefan Herbrechtsmeier <[email protected]>; Andre Przywara <[email protected]>; Jaehoon Chung <[email protected]>
Cc: [email protected]
Subject: [PATCH v3 3/3] ARM: tegra: include timer as default option

External email: Use caution opening links or attachments

Enable TIMER as default option for add Tegra devices and enable TEGRA_TIMER for TEGRA_ARMV7_COMMON. Additionally enable SPL_TIMER if build as SPL part and drop deprecated configs from common header.

---
 arch/arm/Kconfig               | 1 +
 arch/arm/mach-tegra/Kconfig    | 2 ++
 include/configs/tegra-common.h | 6 ------
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/arm/Kconfig +1 -0
@@ -1334,6 +1334,7 @@ config ARCH_TEGRA
        select GPIO_EXTRA_HEADER
        imply DISTRO_DEFAULTS
        imply FAT_WRITE
+       imply SPL_TIMER if SPL
 
 config ARCH_VEXPRESS64
        bool "Support ARMv8 Arm Ltd. VExpress based boards and models"
arch/arm/mach-tegra/Kconfig +2 -0
@@ -62,6 +62,7 @@ config TEGRA_COMMON
        select MISC
        select OF_CONTROL
        select SPI
+       select TIMER
        imply CMD_DM
        imply CRC32_VERIFY
 
@@ -87,6 +88,7 @@ config TEGRA_ARMV7_COMMON
        select TEGRA_NO_BPMP
        select TEGRA_PINCTRL
        select TEGRA_PMC
+       select TEGRA_TIMER
 
 config TEGRA_ARMV8_COMMON
        bool "Tegra 64-bit common options"
include/configs/tegra-common.h +0 -6
@@ -15,12 +15,6 @@
 
 #include <asm/arch/tegra.h>            /* get chip and board defs */
 
-/* Use the Tegra US timer on ARMv7, but the architected timer on ARMv8. */ -#ifndef CONFIG_ARM64
-#define CONFIG_SYS_TIMER_RATE          1000000
-#define CONFIG_SYS_TIMER_COUNTER       NV_PA_TMRUS_BASE
-#endif
-
 /* Environment */
 
 /*
--

2.37.2

Reviewed-by on v3 3/3
#9 lore raw

Re: [PATCH v3 3/3] ARM: tegra: include timer as default option

In reply to Svyatoslav Ryhel
Quoted 6 lines · Svyatoslav Ryhel

Enable TIMER as default option for add Tegra devices and enable TEGRA_TIMER for TEGRA_ARMV7_COMMON. Additionally enable SPL_TIMER if build as SPL part and drop deprecated configs from common header.

Quoted 7 lines
---
 arch/arm/Kconfig               | 1 +
 arch/arm/mach-tegra/Kconfig    | 2 ++
 include/configs/tegra-common.h | 6 ------
 3 files changed, 3 insertions(+), 6 deletions(-)