ast2600 timer support
Joel Stanley
maintainercover ast2600 timer support
In order to use high resolution timers, an ARMv7 system needs an additional clocksource that is not the arch timer.
The other option is to set the always-on property in the arch timer. This has been discouraged in the past[1].
I propose we enable the aspeed timer in the openbmc tree, and work out how to proceed longer term upstream. I've submitted the timer changes upstream as we can have driver support regardless as to weather we use it.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Joel Stanley (4):
ARM: dts: aspeed-g6: Add timer description
clocksource: fttmr010: Parametrise shutdown
clocksource: fttmr010: Set interrupt and shutdown
clocksource: fttmr010: Add support for ast2600
arch/arm/boot/dts/aspeed-g6.dtsi | 15 ++++++ drivers/clocksource/timer-fttmr010.c | 68 ++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 15 deletions(-)
Signature · 1 line
2.24.0.rc1
Joel Stanley
maintainerPATCH 1/4 ARM: dts: aspeed-g6: Add timer description
The AST2600 has 8 32-bit timers on the APB bus.
--- arch/arm/boot/dts/aspeed-g6.dtsi | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/boot/dts/aspeed-g6.dtsi +15 -0
@@ -310,6 +310,21 @@ status = "disabled"; }; + timer: timer@1e782000 { + compatible = "aspeed,ast2600-timer"; + reg = <0x1e782000 0x90>; + interrupts-extended = <&gic GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 22 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&syscon ASPEED_CLK_APB1>; + clock-names = "PCLK"; + }; + uart1: serial@1e783000 { compatible = "ns16550a"; reg = <0x1e783000 0x20>;
Signature · 1 line
2.24.0.rc1
Re: [PATCH linux dev-5.3 1/4] ARM: dts: aspeed-g6: Add timer description
Quoted 3 lines · Joel Stanley
The AST2600 has 8 32-bit timers on the APB bus.
Signed-off-by Joel Stanley <[email protected]>
Quoted 21 lines
--- arch/arm/boot/dts/aspeed-g6.dtsi | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm/boot/dts/aspeed-g6.dtsi +8
-0@@ -310,6 +310,21 @@ status = "disabled"; }; + timer: timer@1e782000 { + compatible = "aspeed,ast2600-timer"; + reg = <0x1e782000 0x90>; + interrupts-extended = <&gic GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>,
arch/arm/boot/dts/aspeed-g6.dtsi line 330
Quoted 10 lines
arch/arm/boot/dts/aspeed-g6.dtsi +7
-0+ <&gic GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 22 IRQ_TYPE_LEVEL_HIGH>, + <&gic GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&syscon ASPEED_CLK_APB1>; + clock-names = "PCLK"; + }; + uart1: serial@1e783000 { compatible = "ns16550a"; reg = <0x1e783000 0x20>;
x
Joel Stanley
maintainerPATCH 2/4 clocksource: fttmr010: Parametrise shutdown
In reply to Joel StanleyIn preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.
--- drivers/clocksource/timer-fttmr010.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clocksource/timer-fttmr010.c +8 -11
@@ -97,6 +97,7 @@ struct fttmr010 {bool is_aspeed;u32 t1_enable_val;struct clock_event_device clkevt; +int (*timer_shutdown)(struct clock_event_device *evt);#ifdef CONFIG_ARM struct delay_timer delay_timer;#endif
@@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);if (fttmr010->is_aspeed) {/*
@@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);/* Setup counter start from 0 or ~0 */ writel (0 , fttmr010->base +TIMER1_COUNT );
@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);/* Setup timer to fire at 1/HZ intervals. */ if (fttmr010->is_aspeed) {
@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->tick_rate); } + fttmr010->timer_shutdown = fttmr010_timer_shutdown; +/* * Setup clockevent timer (interrupt-driven) on timer 1. */
@@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->clkevt.features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event; - fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown; + fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown; fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic; fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot; - fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown; + fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown; fttmr010->clkevt.cpumask =cpumask_of (0 ); fttmr010->clkevt.irq = irq; clockevents_config_and_register(&fttmr010->clkevt,
Signature · 1 line
2.24.0.rc1
Re: [PATCH linux dev-5.3 2/4] clocksource: fttmr010: Parametrise shutdown
Quoted 5 lines · Joel Stanley
In preparation for supporting the ast2600 which uses a different method to clear bits in the control register, use a callback for performing the shutdown sequence.
Signed-off-by Joel Stanley <[email protected]>
Quoted 72 lines
--- drivers/clocksource/timer-fttmr010.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/clocksource/timer-fttmr010.c +8
-11@@ -97,6 +97,7 @@ struct fttmr010 {bool is_aspeed;u32 t1_enable_val;struct clock_event_device clkevt; +int (*timer_shutdown)(struct clock_event_device *evt);#ifdef CONFIG_ARM struct delay_timer delay_timer;#endif @@ -140,9 +141,7 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);if (fttmr010->is_aspeed) {/* @@ -183,9 +182,7 @@ static int fttmr010_timer_set_oneshot(struct clock_event_device *evt)u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);/* Setup counter start from 0 or ~0 */ writel (0 , fttmr010->base +TIMER1_COUNT );@@ -211,9 +208,7 @@ static int fttmr010_timer_set_periodic(struct clock_event_device *evt)u32 cr;/* Stop */ - cr =readl (fttmr010->base +TIMER_CR ); - cr &= ~fttmr010->t1_enable_val; -writel (cr, fttmr010->base +TIMER_CR ); + fttmr010->timer_shutdown (evt);/* Setup timer to fire at 1/HZ intervals. */ if (fttmr010->is_aspeed) {@@ -350,6 +345,8 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->tick_rate); } + fttmr010->timer_shutdown = fttmr010_timer_shutdown; +/* * Setup clockevent timer (interrupt-driven) on timer 1. */ @@ -370,10 +367,10 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->clkevt.features =CLOCK_EVT_FEAT_PERIODIC |CLOCK_EVT_FEAT_ONESHOT ; fttmr010->clkevt.set_next_event = fttmr010_timer_set_next_event; - fttmr010->clkevt.set_state_shutdown = fttmr010_timer_shutdown; + fttmr010->clkevt.set_state_shutdown = fttmr010->timer_shutdown; fttmr010->clkevt.set_state_periodic = fttmr010_timer_set_periodic; fttmr010->clkevt.set_state_oneshot = fttmr010_timer_set_oneshot; - fttmr010->clkevt.tick_resume = fttmr010_timer_shutdown; + fttmr010->clkevt.tick_resume = fttmr010->timer_shutdown; fttmr010->clkevt.cpumask =cpumask_of (0 ); fttmr010->clkevt.irq = irq; clockevents_config_and_register(&fttmr010->clkevt,
Joel Stanley
maintainerPATCH 3/4 clocksource: fttmr010: Set interrupt and shutdown
In reply to Joel StanleyIn preparation for supporting the ast2600, pass the shutdown and interrupt functions to the common init callback.
--- drivers/clocksource/timer-fttmr010.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/clocksource/timer-fttmr010.c +12 -5
@@ -244,7 +244,10 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } -static int __init fttmr010_common_init (struct device_node *np,bool is_aspeed) +static int __init fttmr010_common_init (struct device_node *np, +bool is_aspeed, +int (*timer_shutdown)(struct clock_event_device *), +irq_handler_t handler) {struct fttmr010 *fttmr010;int irq;
@@ -345,7 +348,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->tick_rate); } - fttmr010->timer_shutdown = fttmr010_timer_shutdown; + fttmr010->timer_shutdown = timer_shutdown;/* * Setup clockevent timer (interrupt-driven) on timer 1.
@@ -354,7 +357,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)writel (0 , fttmr010->base +TIMER1_LOAD );writel (0 , fttmr010->base +TIMER1_MATCH1 );writel (0 , fttmr010->base +TIMER1_MATCH2 ); - ret =request_irq (irq, fttmr010_timer_interrupt,IRQF_TIMER , + ret =request_irq (irq, handler,IRQF_TIMER ,"FTTMR010-TIMER1" , &fttmr010->clkevt);if (ret) {pr_err ("FTTMR010-TIMER1 no IRQ\n" );
@@ -403,12 +406,16 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)static __init int aspeed_timer_init (struct device_node *np) { -return fttmr010_common_init (np, true); +return fttmr010_common_init (np, true, + fttmr010_timer_shutdown, + fttmr010_timer_interrupt); }static __init int fttmr010_timer_init (struct device_node *np) { -return fttmr010_common_init (np, false); +return fttmr010_common_init (np, false, + fttmr010_timer_shutdown, + fttmr010_timer_interrupt); }TIMER_OF_DECLARE (fttmr010,"faraday,fttmr010" , fttmr010_timer_init);
Signature · 1 line
2.24.0.rc1
Re: [PATCH linux dev-5.3 3/4] clocksource: fttmr010: Set interrupt and shutdown
Quoted 4 lines · Joel Stanley
In preparation for supporting the ast2600, pass the shutdown and interrupt functions to the common init callback.
Signed-off-by Joel Stanley <[email protected]>
Quoted 9 lines
--- drivers/clocksource/timer-fttmr010.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/clocksource/timer-fttmr010.c +0
-0
drivers/clocksource/timer-fttmr010.c static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id) · line 250
Quoted 8 lines
drivers/clocksource/timer-fttmr010.c +4
-1@@ -244,7 +244,10 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } -static int __init fttmr010_common_init (struct device_node *np,bool is_aspeed) +static int __init fttmr010_common_init (struct device_node *np, +bool is_aspeed, +int (*timer_shutdown)(struct clock_event_device *), +irq_handler_t handler)
may be rename handler -> irq_handler. This is minor, just better for readability.
C.
Quoted 41 lines
drivers/clocksource/timer-fttmr010.c +8
-4{struct fttmr010 *fttmr010;int irq;@@ -345,7 +348,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed) fttmr010->tick_rate); } - fttmr010->timer_shutdown = fttmr010_timer_shutdown; + fttmr010->timer_shutdown = timer_shutdown;/* * Setup clockevent timer (interrupt-driven) on timer 1. @@ -354,7 +357,7 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)writel (0 , fttmr010->base +TIMER1_LOAD );writel (0 , fttmr010->base +TIMER1_MATCH1 );writel (0 , fttmr010->base +TIMER1_MATCH2 ); - ret =request_irq (irq, fttmr010_timer_interrupt,IRQF_TIMER , + ret =request_irq (irq, handler,IRQF_TIMER ,"FTTMR010-TIMER1" , &fttmr010->clkevt);if (ret) {pr_err ("FTTMR010-TIMER1 no IRQ\n" );@@ -403,12 +406,16 @@ static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed)static __init int aspeed_timer_init (struct device_node *np) { -return fttmr010_common_init (np, true); +return fttmr010_common_init (np, true, + fttmr010_timer_shutdown, + fttmr010_timer_interrupt); }static __init int fttmr010_timer_init (struct device_node *np) { -return fttmr010_common_init (np, false); +return fttmr010_common_init (np, false, + fttmr010_timer_shutdown, + fttmr010_timer_interrupt); }TIMER_OF_DECLARE (fttmr010,"faraday,fttmr010" , fttmr010_timer_init);
Joel Stanley
maintainerPATCH 4/4 clocksource: fttmr010: Add support for ast2600
In reply to Joel StanleyThe ast2600 has some minor differences to previous versions. The interrupt handler must acknowledge the timer interrupt in a status register. Secondly the control register becomes write to set only, requiring the use of a separate set to clear register.
--- drivers/clocksource/timer-fttmr010.c | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/clocksource/timer-fttmr010.c +34 -0
@@ -37,6 +37,11 @@#define TIMER3_MATCH2 (0x2c)#define TIMER_CR (0x30) +/* +Control register set to clear for ast2600 only. +*/ +#define TIMER_CR_CLR (0x3c) +/* * Control register (TMC30) bit fields for fttmr010/gemini/moxart timers. */
@@ -163,6 +168,16 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,return 0 ; } +static int ast2600_timer_shutdown (struct clock_event_device *evt) +{ +struct fttmr010 *fttmr010 =to_fttmr010 (evt); + +/* Stop */ +writel (fttmr010->t1_enable_val, fttmr010->base +TIMER_CR_CLR ); + +return 0 ; +} +static int fttmr010_timer_shutdown (struct clock_event_device *evt) {struct fttmr010 *fttmr010 =to_fttmr010 (evt);
@@ -244,6 +259,17 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +static irqreturn_t ast2600_timer_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = dev_id; +struct fttmr010 *fttmr010 =to_fttmr010 (evt); + +writel (0x1 , fttmr010->base +TIMER_INTR_STATE ); + + evt->event_handler (evt); +return IRQ_HANDLED ; +} + static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed, int (*timer_shutdown)(struct clock_event_device *),
@@ -404,6 +430,13 @@ static int __init fttmr010_common_init(struct device_node *np,return ret; } +static __init int ast2600_timer_init (struct device_node *np) +{ +return fttmr010_common_init (np, true, + ast2600_timer_shutdown, + ast2600_timer_interrupt); +} +static __init int aspeed_timer_init (struct device_node *np) { return fttmr010_common_init(np, true,
@@ -423,3 +456,4 @@ TIMER_OF_DECLARE(gemini, "cortina,gemini-timer", fttmr010_timer_init);TIMER_OF_DECLARE (moxart,"moxa,moxart-timer" , fttmr010_timer_init);TIMER_OF_DECLARE (ast2400,"aspeed,ast2400-timer" , aspeed_timer_init);TIMER_OF_DECLARE (ast2500,"aspeed,ast2500-timer" , aspeed_timer_init); +TIMER_OF_DECLARE (ast2600,"aspeed,ast2600-timer" , ast2600_timer_init);
Signature · 1 line
2.24.0.rc1
Re: [PATCH linux dev-5.3 4/4] clocksource: fttmr010: Add support for ast2600
Quoted 6 lines · Joel Stanley
The ast2600 has some minor differences to previous versions. The interrupt handler must acknowledge the timer interrupt in a status register. Secondly the control register becomes write to set only, requiring the use of a separate set to clear register.
Signed-off-by Joel Stanley <[email protected]>
Quoted 75 lines
--- drivers/clocksource/timer-fttmr010.c | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)drivers/clocksource/timer-fttmr010.c +34
-0@@ -37,6 +37,11 @@#define TIMER3_MATCH2 (0x2c)#define TIMER_CR (0x30) +/* +Control register set to clear for ast2600 only. +*/ +#define TIMER_CR_CLR (0x3c) +/* * Control register (TMC30) bit fields for fttmr010/gemini/moxart timers. */ @@ -163,6 +168,16 @@ static int fttmr010_timer_set_next_event(unsigned long cycles,return 0 ; } +static int ast2600_timer_shutdown (struct clock_event_device *evt) +{ +struct fttmr010 *fttmr010 =to_fttmr010 (evt); + +/* Stop */ +writel (fttmr010->t1_enable_val, fttmr010->base +TIMER_CR_CLR ); + +return 0 ; +} +static int fttmr010_timer_shutdown (struct clock_event_device *evt) {struct fttmr010 *fttmr010 =to_fttmr010 (evt);@@ -244,6 +259,17 @@ static irqreturn_t fttmr010_timer_interrupt(int irq, void *dev_id)return IRQ_HANDLED ; } +static irqreturn_t ast2600_timer_interrupt (int irq,void *dev_id) +{ +struct clock_event_device *evt = dev_id; +struct fttmr010 *fttmr010 =to_fttmr010 (evt); + +writel (0x1 , fttmr010->base +TIMER_INTR_STATE ); + + evt->event_handler (evt); +return IRQ_HANDLED ; +} + static int __init fttmr010_common_init(struct device_node *np, bool is_aspeed, int (*timer_shutdown)(struct clock_event_device *),@@ -404,6 +430,13 @@ static int __init fttmr010_common_init(struct device_node *np,return ret; } +static __init int ast2600_timer_init (struct device_node *np) +{ +return fttmr010_common_init (np, true, + ast2600_timer_shutdown, + ast2600_timer_interrupt); +} +static __init int aspeed_timer_init (struct device_node *np) { return fttmr010_common_init(np, true,@@ -423,3 +456,4 @@ TIMER_OF_DECLARE(gemini, "cortina,gemini-timer", fttmr010_timer_init);TIMER_OF_DECLARE (moxart,"moxa,moxart-timer" , fttmr010_timer_init);TIMER_OF_DECLARE (ast2400,"aspeed,ast2400-timer" , aspeed_timer_init);TIMER_OF_DECLARE (ast2500,"aspeed,ast2500-timer" , aspeed_timer_init); +TIMER_OF_DECLARE (ast2600,"aspeed,ast2600-timer" , ast2600_timer_init);