Fixes for timer-ti-dm systimer posted mode
cover Fixes for timer-ti-dm systimer posted mode
Hi all,
Here are few timer-ti-dm fixes. The first fix corrects the status bit check order for posted mode. The other two are minor fixes noticed while reviewing and testing the code.
Regards,
Tony
Tony Lindgren (3):
clocksource/drivers/timer-ti-dm: Fix posted mode status check order clocksource/drivers/timer-ti-dm: Remove extra of_node_put() clocksource/drivers/timer-ti-dm: Add missing set_state_oneshot_stopped
drivers/clocksource/timer-ti-dm-systimer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
Signature · 1 line
2.30.1
PATCH 1/3 clocksource/drivers/timer-ti-dm: Fix posted mode status check order
When the timer is configured in posted mode, we need to check the write- posted status register (TWPS) before writing to the register.
We now check TWPS after the write starting with commit 52762fbd1c47 ("clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support").
For example, in the TRM for am571x the following is documented in chapter "22.2.4.13.1.1 Write Posting Synchronization Mode":
"For each register, a status bit is provided in the timer write-posted
status (TWPS) register. In this mode, it is mandatory that software check this status bit before any write access. If a write is attempted to a register with a previous access pending, the previous access is discarded without notice."
The regression happened when I updated the code to use standard read/write accessors for the driver instead of using __omap_dm_timer_load_start(). We have__omap_dm_timer_load_start() check the TWPS status correctly using __omap_dm_timer_write().
--- drivers/clocksource/timer-ti-dm-systimer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clocksource/timer-ti-dm-systimer.c +6 -6
@@ -449,13 +449,13 @@ static int dmtimer_set_next_event(unsigned long cycles,struct dmtimer_systimer *t = &clkevt->t;void __iomem *pend = t->base + t->pend; -writel_relaxed (0xffffffff - cycles, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (0xffffffff - cycles, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);return 0 ; }
@@ -490,18 +490,18 @@ static int dmtimer_set_periodic(struct clock_event_device *evt)dmtimer_clockevent_shutdown (evt);/* Looks like we need to first set the load value separately */ -writel_relaxed (clkevt->period, t->base + t->load);while (readl_relaxed (pend) &WP_TLDR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->load); -writel_relaxed (clkevt->period, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , - t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , + t->base + t->ctrl);return 0 ; }
Signature · 1 line
2.30.1
Re: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix posted mode status check order
Quoted 33 lines · Tony Lindgren
When the timer is configured in posted mode, we need to check the write- posted status register (TWPS) before writing to the register.
We now check TWPS after the write starting with commit
52762fbd1c47("clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support").For example, in the TRM for am571x the following is documented in chapter "22.2.4.13.1.1 Write Posting Synchronization Mode":
"For each register, a status bit is provided in the timer write-posted
status (TWPS) register. In this mode, it is mandatory that software check this status bit before any write access. If a write is attempted to a register with a previous access pending, the previous access is discarded without notice."The regression happened when I updated the code to use standard read/write accessors for the driver instead of using
__omap_dm_timer_load_start(). Wehave__omap_dm_timer_load_start()check the TWPS status correctly using__omap_dm_timer_write().Fixes 52762fbd1c47 ("clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support")Signed-off-by Tony Lindgren <[email protected]>--- drivers/clocksource/timer-ti-dm-systimer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/clocksource/timer-ti-dm-systimer.c +0
-0@@ -449,13 +449,13 @@ static int dmtimer_set_next_event(unsigned long cycles,struct dmtimer_systimer *t = &clkevt->t;void __iomem *pend = t->base + t->pend;
drivers/clocksource/timer-ti-dm-systimer.c static int dmtimer_set_next_event(unsigned long cycles, · line 458
Quoted 10 lines
drivers/clocksource/timer-ti-dm-systimer.c +2
-2-writel_relaxed (0xffffffff - cycles, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (0xffffffff - cycles, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);
It seems static [and inline] helper here could be better solution. no?
Quoted 27 lines
drivers/clocksource/timer-ti-dm-systimer.c +4
-4return 0 ; }@@ -490,18 +490,18 @@ static int dmtimer_set_periodic(struct clock_event_device *evt)dmtimer_clockevent_shutdown (evt);/* Looks like we need to first set the load value separately */ -writel_relaxed (clkevt->period, t->base + t->load);while (readl_relaxed (pend) &WP_TLDR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->load); -writel_relaxed (clkevt->period, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , - t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , + t->base + t->ctrl);return 0 ; }
Signature · 7 lines
Best regards, grygorii _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix posted mode status check order
Quoted 3 lines · Grygorii Strashko
Quoted 2 lines · Tony Lindgren
When the timer is configured in posted mode, we need to check the write- posted status register (TWPS) before writing to the register.
...
Quoted 7 lines
Quoted 7 lines
drivers/clocksource/timer-ti-dm-systimer.c +0
-1@@ -449,13 +449,13 @@ static int dmtimer_set_next_event(unsigned long cycles,struct dmtimer_systimer *t = &clkevt->t;void __iomem *pend = t->base + t->pend; -writel_relaxed (0xffffffff - cycles, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )
Quoted 8 lines
drivers/clocksource/timer-ti-dm-systimer.c static int dmtimer_set_next_event(unsigned long cycles, · line 458
Quoted 6 lines
drivers/clocksource/timer-ti-dm-systimer.c +2
-1cpu_relax (); +writel_relaxed (0xffffffff - cycles, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);It seems static [and inline] helper here could be better solution. no?
Well we wanted to get rid of the confusing macros. And in this case I suspect we can eventually do just one read of the pending register for the registers used mask rather than check the status separately multiple times. But that needs to be carefully tested and is not a fix :)
Regards,
Tony
Re: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix posted mode status check order
Quoted 22 lines · Tony Lindgren
Quoted 3 lines · Grygorii Strashko
Quoted 2 lines · Tony Lindgren
When the timer is configured in posted mode, we need to check the write- posted status register (TWPS) before writing to the register.
...
Quoted 7 lines
Quoted 7 lines
drivers/clocksource/timer-ti-dm-systimer.c +0
-1@@ -449,13 +449,13 @@ static int dmtimer_set_next_event(unsigned long cycles,struct dmtimer_systimer *t = &clkevt->t;void __iomem *pend = t->base + t->pend; -writel_relaxed (0xffffffff - cycles, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )Quoted 8 lines
drivers/clocksource/timer-ti-dm-systimer.c static int dmtimer_set_next_event(unsigned long cycles, · line 458
Quoted 6 lines
drivers/clocksource/timer-ti-dm-systimer.c +2
-1cpu_relax (); +writel_relaxed (0xffffffff - cycles, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);It seems static [and inline] helper here could be better solution. no?
Quoted 4 lines
Well we wanted to get rid of the confusing macros. And in this case I suspect we can eventually do just one read of the pending register for the registers used mask rather than check the status separately multiple times. But that needs to be carefully tested and is not a fix :)
Might work.
Signature · 2 lines
Best regards, grygorii
[tip: timers/core] clocksource/drivers/timer-ti-dm: Fix posted mode status check order
In reply to Tony LindgrenThe following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 212709926c5493a566ca4086ad4f4b0d4e66b553 Gitweb: https://git.kernel.org/tip/212709926c5493a566ca4086ad4f4b0d4e66b553 Author: Tony Lindgren <[email protected]> AuthorDate: Thu, 04 Mar 2021 09:21:33 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Apr 2021 13:23:41 +02:00
clocksource/drivers/timer-ti-dm: Fix posted mode status check order
When the timer is configured in posted mode, we need to check the write- posted status register (TWPS) before writing to the register.
We now check TWPS after the write starting with commit 52762fbd1c47 ("clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support").
For example, in the TRM for am571x the following is documented in chapter "22.2.4.13.1.1 Write Posting Synchronization Mode":
"For each register, a status bit is provided in the timer write-posted
status (TWPS) register. In this mode, it is mandatory that software check this status bit before any write access. If a write is attempted to a register with a previous access pending, the previous access is discarded without notice."
The regression happened when I updated the code to use standard read/write accessors for the driver instead of using __omap_dm_timer_load_start(). We have__omap_dm_timer_load_start() check the TWPS status correctly using __omap_dm_timer_write().
--- drivers/clocksource/timer-ti-dm-systimer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/clocksource/timer-ti-dm-systimer.c +6 -6
@@ -449,13 +449,13 @@ static int dmtimer_set_next_event(unsigned long cycles,struct dmtimer_systimer *t = &clkevt->t;void __iomem *pend = t->base + t->pend; -writel_relaxed (0xffffffff - cycles, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (0xffffffff - cycles, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_ST , t->base + t->ctrl);return 0 ; }
@@ -490,18 +490,18 @@ static int dmtimer_set_periodic(struct clock_event_device *evt)dmtimer_clockevent_shutdown (evt);/* Looks like we need to first set the load value separately */ -writel_relaxed (clkevt->period, t->base + t->load);while (readl_relaxed (pend) &WP_TLDR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->load); -writel_relaxed (clkevt->period, t->base + t->counter);while (readl_relaxed (pend) &WP_TCRR )cpu_relax (); +writel_relaxed (clkevt->period, t->base + t->counter); -writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , - t->base + t->ctrl);while (readl_relaxed (pend) &WP_TCLR )cpu_relax (); +writel_relaxed (OMAP_TIMER_CTRL_AR |OMAP_TIMER_CTRL_ST , + t->base + t->ctrl);return 0 ; }
PATCH 2/3 clocksource/drivers/timer-ti-dm: Remove extra of_node_put()
In reply to Tony LindgrenWe have of_translate_address() already do of_node_put() as needed. I probably looked at __of_translate_address() earlier by accident that of_translate_address() uses.
--- drivers/clocksource/timer-ti-dm-systimer.c | 2 -- 1 file changed, 2 deletions(-)
drivers/clocksource/timer-ti-dm-systimer.c +0 -2
@@ -265,7 +265,6 @@ static void __init dmtimer_systimer_assign_alwon(void) pa == 0x48318000)continue ; -of_node_put (np);break ; } }
@@ -300,7 +299,6 @@ static u32 __init dmtimer_systimer_find_first_available(void)continue ; } -of_node_put (np);break ; } }
Signature · 1 line
2.30.1
Re: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Remove extra of_node_put()
Quoted 3 lines · Tony Lindgren
We have
of_translate_address()already doof_node_put()as needed. I probably looked at__of_translate_address()earlier by accident thatof_translate_address()uses.
I do not see of_node_put() in of_translate_address() and
__of_translate_address() is doing of_node_get(dev);
?
Quoted 27 lines
Fixes 52762fbd1c47 ("clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support")Signed-off-by Tony Lindgren <[email protected]>--- drivers/clocksource/timer-ti-dm-systimer.c | 2 -- 1 file changed, 2 deletions(-)drivers/clocksource/timer-ti-dm-systimer.c +0
-2@@ -265,7 +265,6 @@ static void __init dmtimer_systimer_assign_alwon(void) pa == 0x48318000)continue ; -of_node_put (np);break ; } }@@ -300,7 +299,6 @@ static u32 __init dmtimer_systimer_find_first_available(void)continue ; } -of_node_put (np);break ; } }
Signature · 2 lines
Best regards, grygorii
Re: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Remove extra of_node_put()
Quoted 10 lines · Grygorii Strashko
Quoted 3 lines · Tony Lindgren
We have
of_translate_address()already doof_node_put()as needed. I probably looked at__of_translate_address()earlier by accident thatof_translate_address()uses.I do not see
of_node_put()inof_translate_address()and
__of_translate_address()is doingof_node_get(dev);
?
Oh right.. this is confusing.. Yeah we can ignore this patch. We should have the use count set for only the system timer(s) we claim.
Regards,
Tony
Re: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Remove extra of_node_put()
Hi,
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Grygorii Strashko
Quoted 3 lines · Tony Lindgren
We have
of_translate_address()already doof_node_put()as needed. I probably looked at__of_translate_address()earlier by accident thatof_translate_address()uses.
Quoted 7 lines
Quoted 3 lines
I do not see
of_node_put()inof_translate_address()and
__of_translate_address()is doingof_node_get(dev);
?Oh right.. this is confusing.. Yeah we can ignore this patch. We should have the use count set for only the system timer(s) we claim.
Daniel, would you like me to repost this series with this patch dropped?
Regards,
Tony
Re: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Remove extra of_node_put()
Quoted 15 lines · Tony Lindgren
Hi,
Quoted 12 lines · Tony Lindgren
Quoted 10 lines · Grygorii Strashko
Quoted 3 lines · Tony Lindgren
We have
of_translate_address()already doof_node_put()as needed. I probably looked at__of_translate_address()earlier by accident thatof_translate_address()uses.I do not see
of_node_put()inof_translate_address()and
__of_translate_address()is doingof_node_get(dev);
?
Quoted 5 lines
Quoted 3 lines
Oh right.. this is confusing.. Yeah we can ignore this patch. We should have the use count set for only the system timer(s) we claim.
Daniel, would you like me to repost this series with this patch dropped?
No, it is ok. I will take care of not picking it.
Thanks
-- Daniel
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
PATCH 3/3 clocksource/drivers/timer-ti-dm: Add missing set_state_oneshot_stopped
In reply to Tony LindgrenTo avoid spurious timer interrupts when KTIME_MAX is used, we need to configure set_state_oneshot_stopped(). Although implementing this is optional, it still affects things like power management for the extra timer interrupt.
For more information, please see commit 8fff52fd5093 ("clockevents:
Introduce CLOCK_EVT_STATE_ONESHOT_STOPPED state") and commit cf8c5009ee37 ("clockevents/drivers/arm_arch_timer: Implement ->set_state_oneshot_stopped()").
--- drivers/clocksource/timer-ti-dm-systimer.c | 1 + 1 file changed, 1 insertion(+)
drivers/clocksource/timer-ti-dm-systimer.c +1 -0
@@ -552,6 +552,7 @@ static int __init dmtimer_clockevent_init(struct device_node *np) dev->set_state_shutdown = dmtimer_clockevent_shutdown; dev->set_state_periodic = dmtimer_set_periodic; dev->set_state_oneshot = dmtimer_clockevent_shutdown; + dev->set_state_oneshot_stopped = dmtimer_clockevent_shutdown; dev->tick_resume = dmtimer_clockevent_shutdown; dev->cpumask = cpu_possible_mask;
Signature · 1 line
2.30.1
[tip: timers/core] clocksource/drivers/timer-ti-dm: Add missing set_state_oneshot_stopped
The following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: ac4daf737674b4d29e19b7c300caff3bcf7160d8 Gitweb: https://git.kernel.org/tip/ac4daf737674b4d29e19b7c300caff3bcf7160d8 Author: Tony Lindgren <[email protected]> AuthorDate: Thu, 04 Mar 2021 09:21:35 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 08 Apr 2021 13:23:47 +02:00
clocksource/drivers/timer-ti-dm: Add missing set_state_oneshot_stopped
To avoid spurious timer interrupts when KTIME_MAX is used, we need to configure set_state_oneshot_stopped(). Although implementing this is optional, it still affects things like power management for the extra timer interrupt.
For more information, please see commit 8fff52fd5093 ("clockevents:
Introduce CLOCK_EVT_STATE_ONESHOT_STOPPED state") and commit cf8c5009ee37 ("clockevents/drivers/arm_arch_timer: Implement ->set_state_oneshot_stopped()").
--- drivers/clocksource/timer-ti-dm-systimer.c | 1 + 1 file changed, 1 insertion(+)
drivers/clocksource/timer-ti-dm-systimer.c +1 -0
@@ -554,6 +554,7 @@ static int __init dmtimer_clockevent_init(struct device_node *np) dev->set_state_shutdown = dmtimer_clockevent_shutdown; dev->set_state_periodic = dmtimer_set_periodic; dev->set_state_oneshot = dmtimer_clockevent_shutdown; + dev->set_state_oneshot_stopped = dmtimer_clockevent_shutdown; dev->tick_resume = dmtimer_clockevent_shutdown; dev->cpumask = cpu_possible_mask;