Skip to contentSkip to conversation

add TCB driver for sama5d2

PATCH Superseded Clément Léger 2 participants 7 messages Mar 4, 2022

Subsystems (2)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover add TCB driver for sama5d2

When booting under OP-TEE, the SYSC is secured which means the PIT is also not accessible by non-secure world. The TCB 0 however is always available for non-secure world and thus can be used.
This series add a TCB driver and enables it in sama5d2 configs.

---
Changes in v4:
- Add missing interrupts property to tcb node

Changes in v3:
- Remove useless defines
- Add printf in case of unsupported timers specified in device-tree
- Add "syscon" compatible to tcb node

Changes in v2:
- Reworked driver to use existing Linux bindings

Clément Léger (3):
timer: atmel_tcb_timer: add atmel_tcb driver
ARM: dts: at91: sama5d2: add TCB node
configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

 MAINTAINERS                                  |   1 +
 arch/arm/dts/sama5d2.dtsi                    |  16 ++
 configs/sama5d2_icp_mmc_defconfig            |   1 +
 configs/sama5d2_ptc_ek_mmc_defconfig         |   1 +
 configs/sama5d2_ptc_ek_nandflash_defconfig   |   1 +
 configs/sama5d2_xplained_emmc_defconfig      |   1 +
 configs/sama5d2_xplained_mmc_defconfig       |   1 +
 configs/sama5d2_xplained_qspiflash_defconfig |   1 +
 configs/sama5d2_xplained_spiflash_defconfig  |   1 +
 drivers/timer/Kconfig                        |   8 +
 drivers/timer/Makefile                       |   1 +
 drivers/timer/atmel_tcb_timer.c              | 155 +++++++++++++++++++
 12 files changed, 188 insertions(+)
 create mode 100644 drivers/timer/atmel_tcb_timer.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/3 timer: atmel_tcb_timer: add atmel_tcb driver

Add a driver for the timer counter block that can be found on sama5d2. This driver will be used when booting under OP-TEE since the pit timer which is part of the SYSC is secured. Channel 1 & 2 are configured to be chained together which allows to have a 64bits counter.

---
 MAINTAINERS                     |   1 +
 drivers/timer/Kconfig           |   8 ++
 drivers/timer/Makefile          |   1 +
 drivers/timer/atmel_tcb_timer.c | 155 ++++++++++++++++++++++++++++++++
 4 files changed, 165 insertions(+)
 create mode 100644 drivers/timer/atmel_tcb_timer.c
MAINTAINERS +1 -0
index fb171e0c68..73b46c4631 100644
@@ -352,6 +352,7 @@ F:	arch/arm/mach-at91/
 F:	board/atmel/
 F:	drivers/cpu/at91_cpu.c
 F:	drivers/misc/microchip_flexcom.c
+F:	drivers/timer/atmel_tcb_timer.c
 F:	include/dt-bindings/mfd/atmel-flexcom.h
 F:	drivers/timer/mchp-pit64b-timer.c
 
drivers/timer/Kconfig +8 -0
index 8913142654..8fad59b81a 100644
@@ -96,6 +96,14 @@ config ATMEL_PIT_TIMER
 	  it is designed to offer maximum accuracy and efficient management,
 	  even for systems with long response time.
 
+config ATMEL_TCB_TIMER
+	bool "Atmel timer counter support"
+	depends on TIMER
+	depends on ARCH_AT91
+	help
+	  Select this to enable the use of the timer counter as a monotonic
+	  counter.
+
 config CADENCE_TTC_TIMER
 	bool "Cadence TTC (Triple Timer Counter)"
 	depends on TIMER
drivers/timer/Makefile +1 -0
index e2bd530eb0..58da6c1e84 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_ARC_TIMER)	+= arc_timer.o
 obj-$(CONFIG_AST_TIMER)	+= ast_timer.o
 obj-$(CONFIG_ATCPIT100_TIMER) += atcpit100_timer.o
 obj-$(CONFIG_ATMEL_PIT_TIMER) += atmel_pit_timer.o
+obj-$(CONFIG_ATMEL_TCB_TIMER) += atmel_tcb_timer.o
 obj-$(CONFIG_CADENCE_TTC_TIMER)	+= cadence-ttc.o
 obj-$(CONFIG_DESIGNWARE_APB_TIMER)	+= dw-apb-timer.o
 obj-$(CONFIG_MPC83XX_TIMER) += mpc83xx_timer.o
drivers/timer/atmel_tcb_timer.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/3 ARM: dts: at91: sama5d2: add TCB node

In reply to Clément Léger

Add the device-tree node to describe the TCB timer.

---
 arch/arm/dts/sama5d2.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/dts/sama5d2.dtsi +16 -0
index 038cd73c03..54f3dd4c62 100644
@@ -700,6 +700,22 @@
 				clocks = <&h32ck>;
 			};
 
+			tcb0: timer@f800c000 {
+				compatible = "atmel,sama5d2-tcb", "simple-mfd",
+					     "syscon";
+				reg = <0xf800c000 0x100>;
+				interrupts = <35 IRQ_TYPE_LEVEL_HIGH 0>;
+				clocks = <&tcb0_clk>, <&tcb0_gclk>, <&clk32k>;
+				clock-names = "t0_clk", "gclk", "slow_clk";
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				timer0: timer@0 {
+					compatible = "atmel,tcb-timer";
+					reg = <0>, <1>;
+				};
+			};
+
 			watchdog@f8048040 {
 				compatible = "atmel,sama5d4-wdt";
 				reg = <0xf8048040 0x10>;
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v4 2/3] ARM: dts: at91: sama5d2: add TCB node

Quoted 12 lines · Clément Léger

Add the device-tree node to describe the TCB timer.

---
 arch/arm/dts/sama5d2.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/dts/sama5d2.dtsi +0 -0
index 038cd73c03..54f3dd4c62 100644

arch/arm/dts/sama5d2.dtsi line 707

Quoted 8 lines
arch/arm/dts/sama5d2.dtsi +5 -0
@@ -700,6 +700,22 @@
 				clocks = <&h32ck>;
 			};
 
+			tcb0: timer@f800c000 {
+				compatible = "atmel,sama5d2-tcb", "simple-mfd",
+					     "syscon";
+				reg = <0xf800c000 0x100>;
+				interrupts = <35 IRQ_TYPE_LEVEL_HIGH 0>;

And I forgot to include the file which defines IRQ_TYPE_LEVEL_HIGH. Will need a V5 I guess.

Quoted 14 lines
arch/arm/dts/sama5d2.dtsi +11 -0
+				clocks = <&tcb0_clk>, <&tcb0_gclk>, <&clk32k>;
+				clock-names = "t0_clk", "gclk", "slow_clk";
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				timer0: timer@0 {
+					compatible = "atmel,tcb-timer";
+					reg = <0>, <1>;
+				};
+			};
+
 			watchdog@f8048040 {
 				compatible = "atmel,sama5d4-wdt";
 				reg = <0xf8048040 0x10>;
Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#4 lore raw

Re: [PATCH v4 2/3] ARM: dts: at91: sama5d2: add TCB node

Quoted 18 lines · Clément Léger
Quoted 15 lines · Clément Léger

Add the device-tree node to describe the TCB timer.

---
 arch/arm/dts/sama5d2.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/dts/sama5d2.dtsi +0 -0
index 038cd73c03..54f3dd4c62 100644
@@ -700,6 +700,22 @@
 				clocks = <&h32ck>;
 			};
 
Quoted 8 lines

arch/arm/dts/sama5d2.dtsi line 707

Quoted 5 lines
arch/arm/dts/sama5d2.dtsi +5 -0
+			tcb0: timer@f800c000 {
+				compatible = "atmel,sama5d2-tcb", "simple-mfd",
+					     "syscon";
+				reg = <0xf800c000 0x100>;
+				interrupts = <35 IRQ_TYPE_LEVEL_HIGH 0>;  

And I forgot to include the file which defines IRQ_TYPE_LEVEL_HIGH. Will need a V5 I guess.

By the way, this will also yield the following warning:

arch/arm/dts/at91-sama5d2_xplained.dtb: Warning (interrupts_property):
/ahb/apb/timer@f800c000: Missing interrupt-parent

Because indeed, there is no interrupt controller declared at all in this device-tree. What can I do about that ?

Quoted 18 lines
Quoted 15 lines
arch/arm/dts/sama5d2.dtsi +11 -0
+				clocks = <&tcb0_clk>, <&tcb0_gclk>, <&clk32k>;
+				clock-names = "t0_clk", "gclk", "slow_clk";
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				timer0: timer@0 {
+					compatible = "atmel,tcb-timer";
+					reg = <0>, <1>;
+				};
+			};
+
 			watchdog@f8048040 {
 				compatible = "atmel,sama5d4-wdt";
 				reg = <0xf8048040 0x10>;  
Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#5 lore raw

Re: [PATCH v4 2/3] ARM: dts: at91: sama5d2: add TCB node

Quoted 30 lines · Clément Léger
Quoted 18 lines · Clément Léger
Quoted 15 lines · Clément Léger

Add the device-tree node to describe the TCB timer.

---
  arch/arm/dts/sama5d2.dtsi | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
arch/arm/dts/sama5d2.dtsi +0 -0
index 038cd73c03..54f3dd4c62 100644
@@ -700,6 +700,22 @@
                             clocks = <&h32ck>;
                     };
 
Quoted 8 lines

arch/arm/dts/sama5d2.dtsi line 707

Quoted 5 lines
arch/arm/dts/sama5d2.dtsi +5 -0
+                   tcb0: timer@f800c000 {
+                           compatible = "atmel,sama5d2-tcb", "simple-mfd",
+                                        "syscon";
+                           reg = <0xf800c000 0x100>;
+                           interrupts = <35 IRQ_TYPE_LEVEL_HIGH 0>;

And I forgot to include the file which defines IRQ_TYPE_LEVEL_HIGH. Will need a V5 I guess.

Quoted 7 lines

By the way, this will also yield the following warning:

arch/arm/dts/at91-sama5d2_xplained.dtb: Warning (interrupts_property):
/ahb/apb/timer@f800c000: Missing interrupt-parent

Because indeed, there is no interrupt controller declared at all in this device-tree. What can I do about that ?

I know. You have to add the interrupt controller.
That's why I wanted to avoid having interrupts as mandatory, but it looks it's not possible.

Quoted 27 lines
Quoted 19 lines
Quoted 6 lines
arch/arm/dts/sama5d2.dtsi +4 -0
+                           clocks = <&tcb0_clk>, <&tcb0_gclk>, <&clk32k>;
+                           clock-names = "t0_clk", "gclk", "slow_clk";
+                           #address-cells = <1>;
+                           #size-cells = <0>;

arch/arm/dts/sama5d2.dtsi line 721

Quoted 10 lines
arch/arm/dts/sama5d2.dtsi +7 -0
+
+                           timer0: timer@0 {
+                                   compatible = "atmel,tcb-timer";
+                                   reg = <0>, <1>;
+                           };
+                   };
+
                     watchdog@f8048040 {
                             compatible = "atmel,sama5d4-wdt";
                             reg = <0xf8048040 0x10>;

--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com

#6 lore raw

PATCH v4 3/3 configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

In reply to Clément Léger

This will allow using the TCB timer instead of the PIT one when running under OP-TEE.

---
 configs/sama5d2_icp_mmc_defconfig            | 1 +
 configs/sama5d2_ptc_ek_mmc_defconfig         | 1 +
 configs/sama5d2_ptc_ek_nandflash_defconfig   | 1 +
 configs/sama5d2_xplained_emmc_defconfig      | 1 +
 configs/sama5d2_xplained_mmc_defconfig       | 1 +
 configs/sama5d2_xplained_qspiflash_defconfig | 1 +
 configs/sama5d2_xplained_spiflash_defconfig  | 1 +
 7 files changed, 7 insertions(+)
configs/sama5d2_icp_mmc_defconfig +1 -0
index 7761a57e0c..2eb2e92110 100644
@@ -83,5 +83,6 @@ CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 # CONFIG_EFI_LOADER_HII is not set
configs/sama5d2_ptc_ek_mmc_defconfig +1 -0
index 9f458e100b..2a77f72734 100644
@@ -72,6 +72,7 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_ptc_ek_nandflash_defconfig +1 -0
index 6460ff3dad..790e79019c 100644
@@ -72,6 +72,7 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_emmc_defconfig +1 -0
index 844a9cde64..dfe120051f 100644
@@ -91,6 +91,7 @@ CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_mmc_defconfig +1 -0
index 0de0636587..910ff5c141 100644
@@ -93,6 +93,7 @@ CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_qspiflash_defconfig +1 -0
index a6e002e59e..158ec4c70e 100644
@@ -92,6 +92,7 @@ CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_spiflash_defconfig +1 -0
index 676385fe55..5d946d06cf 100644
@@ -96,6 +96,7 @@ CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
 CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
Signature · 1 line
2.34.1