Skip to contentSkip to conversation

timer: add SP804 DM_TIMER driver (and use it)

PATCH In review Andre Przywara 2 participants 7 messages Oct 20, 2022 – Nov 3, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover timer: add SP804 DM_TIMER driver (and use it)

Some boards were using an ARM SP804 timer IP, but were driving that using hardcoded addresses and input frequencies, using the CONFIG_SYS_TIMER_* macros. This is deprecated and scheduled for removal.

This series adds a DM_TIMER compliant SP804 driver in patch 1, and lets the Highbank board use that (patch 3).
Since the Highbank DT somewhat hides the timer base fixed-clock inside a subnode, we need some simple-bus like driver in patch 2 to help the driver find the timer frequency.

The SP804 driver should be usable by other SoCs using the SP804 timer, but I don't have any to test it there.

Cheers,
Andre

Andre Przywara (3):
timer: add SP804 UCLASS timer driver
highbank: scan into hb_sregs DT subnodes
highbank: switch to use the Arm SP804 DM_TIMER driver

 arch/arm/Kconfig            |   2 +
 board/highbank/Makefile     |   2 +-
 board/highbank/hb_sregs.c   |  45 +++++++++++++++
 drivers/timer/Kconfig       |   6 ++
 drivers/timer/Makefile      |   1 +
 drivers/timer/sp804_timer.c | 108 ++++++++++++++++++++++++++++++++++++
 include/configs/highbank.h  |   4 --
 7 files changed, 163 insertions(+), 5 deletions(-)
 create mode 100644 board/highbank/hb_sregs.c
 create mode 100644 drivers/timer/sp804_timer.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 timer: add SP804 UCLASS timer driver

The "Arm Ltd. Dual-Timer Module (SP804)" is a simple 32-bit count-down timer IP with interrupt functionality, and is used in some SoCs from various vendors.

Add a simple DM compliant timer driver, to allow users of the SP804 to switch to DM_TIMER.

This relies on the input clock to be accessible via the DM clock framework, which should be fine as we probably look at fixed-clock's here anyway.
We re-program the control register in the probe() function, but keep the divider in place, in case this has been set to something on purpose before.

The TRM for the timer IP can be found here:
https://developer.arm.com/documentation/ddi0271/latest

---
 drivers/timer/Kconfig       |   6 ++
 drivers/timer/Makefile      |   1 +
 drivers/timer/sp804_timer.c | 108 ++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 drivers/timer/sp804_timer.c
drivers/timer/Kconfig +6 -0
index fd8745ffc2e..22da516f045 100644
@@ -230,6 +230,12 @@ config SANDBOX_TIMER
 	  Select this to enable an emulated timer for sandbox. It gets
 	  time from host os.
 
+config SP804_TIMER
+	bool "ARM SP804 timer support"
+	depends on TIMER
+	help
+	  ARM SP804 dual timer IP support
+
 config STI_TIMER
 	bool "STi timer support"
 	depends on TIMER
drivers/timer/Makefile +1 -0
index 7bfb7749e97..ec332943876 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_RENESAS_OSTM_TIMER) += ostm_timer.o
 obj-$(CONFIG_RISCV_TIMER) += riscv_timer.o
 obj-$(CONFIG_ROCKCHIP_TIMER) += rockchip_timer.o
 obj-$(CONFIG_SANDBOX_TIMER)	+= sandbox_timer.o
+obj-$(CONFIG_SP804_TIMER)	+= sp804_timer.o
 obj-$(CONFIG_$(SPL_)SIFIVE_CLINT) += sifive_clint_timer.o
 obj-$(CONFIG_STI_TIMER)		+= sti-timer.o
 obj-$(CONFIG_STM32_TIMER)	+= stm32_timer.o
drivers/timer/sp804_timer.c new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/3] timer: add SP804 UCLASS timer driver

Quoted 14 lines · Andre Przywara

The "Arm Ltd. Dual-Timer Module (SP804)" is a simple 32-bit count-down timer IP with interrupt functionality, and is used in some SoCs from various vendors.

Add a simple DM compliant timer driver, to allow users of the SP804 to switch to DM_TIMER.

This relies on the input clock to be accessible via the DM clock framework, which should be fine as we probably look at fixed-clock's here anyway.
We re-program the control register in the probe() function, but keep the divider in place, in case this has been set to something on purpose before.

Quoted 4 lines

The TRM for the timer IP can be found here:
https://developer.arm.com/documentation/ddi0271/latest

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH 2/3 highbank: scan into hb_sregs DT subnodes

In reply to Andre Przywara

The DT used for Calxeda Highbank and Midway systems exposes a "system registers" block, modeled as a DT subnode.
This includes several clocks, including the two fixed clocks for the main oscillator and timer.

So far U-Boot was ignorant of this special construct (a "clocks" node within the "hb-sregs" node), as it didn't need the PLL clocks in there. But that also meant we lost the fixed clocks, which form the base for the UART baudrate generator and also the SP804 timer.

To allow the generic PL011 and SP804 driver to read the clock rate, add a simple bus driver, which triggers the DT node discovery inside this special node. As we only care about the fixed clocks (we don't have drivers for the PLLs anyway), just ignore the address translation (for now).

The binding is described in bindings/arm/calxeda/hb-sregs.yaml, the DT snippet in question looks like:

=======================

	sregs@fff3c000 {
		compatible = "calxeda,hb-sregs";
		reg = <0xfff3c000 0x1000>;

		clocks {
			#address-cells = <1>;
			#size-cells = <0>;

			osc: oscillator {
				#clock-cells = <0>;
				compatible = "fixed-clock";
				clock-frequency = <33333000>;
			};
			....
		};
	};

=======================

---
 board/highbank/Makefile   |  2 +-
 board/highbank/hb_sregs.c | 45 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 board/highbank/hb_sregs.c
board/highbank/Makefile +1 -1
index 57f7f2e2a65..9e432119849 100644
@@ -3,4 +3,4 @@
 # (C) Copyright 2000-2006
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
-obj-y	:= highbank.o ahci.o
+obj-y	:= highbank.o ahci.o hb_sregs.o
board/highbank/hb_sregs.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/3] highbank: scan into hb_sregs DT subnodes

Quoted 36 lines · Andre Przywara

The DT used for Calxeda Highbank and Midway systems exposes a "system registers" block, modeled as a DT subnode.
This includes several clocks, including the two fixed clocks for the main oscillator and timer.

So far U-Boot was ignorant of this special construct (a "clocks" node within the "hb-sregs" node), as it didn't need the PLL clocks in there. But that also meant we lost the fixed clocks, which form the base for the UART baudrate generator and also the SP804 timer.

To allow the generic PL011 and SP804 driver to read the clock rate, add a simple bus driver, which triggers the DT node discovery inside this special node. As we only care about the fixed clocks (we don't have drivers for the PLLs anyway), just ignore the address translation (for now).

The binding is described in bindings/arm/calxeda/hb-sregs.yaml, the DT snippet in question looks like:

=======================

	sregs@fff3c000 {
		compatible = "calxeda,hb-sregs";
		reg = <0xfff3c000 0x1000>;

		clocks {
			#address-cells = <1>;
			#size-cells = <0>;

			osc: oscillator {
				#clock-cells = <0>;
				compatible = "fixed-clock";
				clock-frequency = <33333000>;
			};
			....
		};
	};
Quoted 3 lines

=======================

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#5 lore raw

PATCH 3/3 highbank: switch to use the Arm SP804 DM_TIMER driver

In reply to Andre Przywara

So far the Calxeda machines were using the CONFIG_SYS_TIMER_* macros to simply hardcode the address of the counter register of the SP804 timer. This method is deprecated and scheduled for removal.

Use the newly introduced SP804 DM_TIMER driver to provide timer functionality on Highbank and Midway machines. The base address and base frequency are taken from the devicetree.

---
 arch/arm/Kconfig           | 2 ++
 include/configs/highbank.h | 4 ----
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/arm/Kconfig +2 -0
index 2e833940525..3269d0c5196 100644
@@ -793,6 +793,8 @@ config ARCH_HIGHBANK
 	select AHCI
 	select DM_ETH
 	select PHYS_64BIT
+	select TIMER
+	select SP804_TIMER
 	imply OF_HAS_PRIOR_STAGE
 
 config ARCH_INTEGRATOR
include/configs/highbank.h +0 -4
index bb6cc957261..5e2b50bbac1 100644
@@ -8,10 +8,6 @@
 
 #define CONFIG_SYS_BOOTMAPSZ		(16 << 20)
 
-#define CONFIG_SYS_TIMER_RATE		(150000000/256)
-#define CONFIG_SYS_TIMER_COUNTER	(0xFFF34000 + 0x4)
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-
 #define CONFIG_PL011_CLOCK		150000000
 
 /*
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH 3/3] highbank: switch to use the Arm SP804 DM_TIMER driver

Quoted 9 lines · Andre Przywara

So far the Calxeda machines were using the CONFIG_SYS_TIMER_* macros to simply hardcode the address of the counter register of the SP804 timer. This method is deprecated and scheduled for removal.

Use the newly introduced SP804 DM_TIMER driver to provide timer functionality on Highbank and Midway machines. The base address and base frequency are taken from the devicetree.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom