clocksource: SuperH TMU Timer driver
Subsystems (2)
PATCH 1/1 clocksource: SuperH TMU Timer driver
From: Magnus Damm <[email protected]>
This patch adds a TMU driver for the SuperH architecture.
The TMU driver is a platform driver with early platform support to allow using a TMU channel as clockevent or clocksource during system bootup or later.
Clocksource or clockevent can be selected. Both periodic and oneshot clockevents are supported.
---
Tested on a Migo-R board with sh7722.
Applies on top of the MTU2 patches. Clocksource operation requires the following patch:
"clocksource: setup mult_orig in clocksource_enable()"
arch/sh/Kconfig | 12 + drivers/clocksource/Makefile | 1 drivers/clocksource/sh_tmu.c | 461 ++++++++++++++++++++++++++++++++++++++++++ include/linux/sh_tmu.h | 13 + 4 files changed, 487 insertions(+)
arch/sh/Kconfig +12 -0
@@ -116,6 +116,9 @@ config SYS_SUPPORTS_CMT config SYS_SUPPORTS_MTU2 bool +config SYS_SUPPORTS_TMU + bool + config STACKTRACE_SUPPORT def_bool y
@@ -470,6 +473,15 @@ config SH_TMU help This enables the use of the TMU as the system timer. +config SH_TIMER_TMU + bool "TMU timer driver" + depends on !SH_TMU && SYS_SUPPORTS_TMU + default y + select GENERIC_TIME + select GENERIC_CLOCKEVENTS + help + This enables the build of the TMU timer driver. + config SH_TIMER_CMT bool "CMT timer driver" depends on SYS_SUPPORTS_CMT
drivers/clocksource/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o +obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o
drivers/clocksource/sh_tmu.c new file +461 -0
461 lines not on this page · raw message
include/linux/sh_tmu.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __SH_TMU_H__ +#define __SH_TMU_H__ + +struct sh_tmu_config { +char *name; +unsigned long channel_offset; +int timer_bit; +char *clk; +unsigned long clockevent_rating; +unsigned long clocksource_rating; +}; + +#endif /* __SH_TMU_H__ */
Hi Magnus, could you provide an answer to my question on SH-TMU?
Quoted 63 lines · Magnus Damm
From: Magnus Damm <[email protected]>
This patch adds a TMU driver for the SuperH architecture.
The TMU driver is a platform driver with early platform support to allow using a TMU channel as clockevent or clocksource during system bootup or later.
Clocksource or clockevent can be selected. Both periodic and oneshot clockevents are supported.
Signed-off-by Magnus Damm <[email protected]>---
Tested on a Migo-R board with sh7722.
Applies on top of the MTU2 patches. Clocksource operation requires the following patch:
"clocksource: setupmult_originclocksource_enable()"arch/sh/Kconfig | 12 + drivers/clocksource/Makefile | 1 drivers/clocksource/sh_tmu.c | 461 ++++++++++++++++++++++++++++++++++++++++++ include/linux/sh_tmu.h | 13 + 4 files changed, 487 insertions(+)arch/sh/Kconfig +12
-0@@ -116,6 +116,9 @@ config SYS_SUPPORTS_CMT config SYS_SUPPORTS_MTU2 bool +config SYS_SUPPORTS_TMU + bool + config STACKTRACE_SUPPORT def_bool y@@ -470,6 +473,15 @@ config SH_TMU help This enables the use of the TMU as the system timer. +config SH_TIMER_TMU + bool "TMU timer driver" + depends on !SH_TMU && SYS_SUPPORTS_TMU + default y + select GENERIC_TIME + select GENERIC_CLOCKEVENTS + help + This enables the build of the TMU timer driver. + config SH_TIMER_CMT bool "CMT timer driver" depends on SYS_SUPPORTS_CMTdrivers/clocksource/Makefile +1
-0@@ -4,3 +4,4 @@ obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o +obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.odrivers/clocksource/sh_tmu.c new file +0
-0@@ -0,0 +1,461 @@
(snip...)
Quoted 13 lines
drivers/clocksource/sh_tmu.c new file +13
-0+static void sh_tmu_set_next (struct sh_tmu_priv *p,unsigned long delta, +int periodic) +{ +/* stop timer */ +sh_tmu_start_stop_ch (p,0 ); + +/* acknowledge interrupt */ +sh_tmu_read (p,TCR ); + +/* enable interrupt */ +sh_tmu_write (p,TCR ,0x0020 ); + +/* reload delta value in case of periodic timer */
drivers/clocksource/sh_tmu.c line 167
Quoted 10 lines
drivers/clocksource/sh_tmu.c new file +10
-0+if (periodic) +sh_tmu_write (p,TCOR , delta); +else +sh_tmu_write (p,TCOR ,0 ); + +sh_tmu_write (p,TCNT , delta); + +/* start timer */ +sh_tmu_start_stop_ch (p,1 ); +}
In some occasions, qemu-sh prints out a lot of warnings on timer with this message : 'Timer with period zero. disabling.'
I made some investigation, and found that the warnings are printed after zero value is set to TCOR. I checked SH7785 hardware manual, but could not find any description what happens when zero value set to TCOR.
According to the code above, I guess that TMU works as a non-periodic one-shot timer when the TCOR value is zero. Is it right?
Regards,
Shin-ichiro KAWASAKI
Hi Kawasaki-san,
2009/5/30 Shin-ichiro KAWASAKI <[email protected]>:
Quoted 13 lines
Hi Magnus, could you provide an answer to my question on SH-TMU?
Quoted 9 lines · Magnus Damm
From: Magnus Damm <[email protected]>
This patch adds a TMU driver for the SuperH architecture.
+ /* reload delta value in case of periodic timer */
+ if (periodic)
+sh_tmu_write(p, TCOR, delta);
+ else
+sh_tmu_write(p, TCOR, 0);
Quoted 7 lines
In some occasions, qemu-sh prints out a lot of warnings on timer with this message : 'Timer with period zero. disabling.'
I made some investigation, and found that the warnings are printed after zero value is set to TCOR. I checked SH7785 hardware manual, but could not find any description what happens when zero value set to TCOR.
Thanks for investigating. I read a few SH manuals before converting the old driver, but I couldn't find any description of zero value. Same as you.
The idea with zero value TCOR comes from the old driver. It may be there for some historical reason, or it may just be plain wrong. I've sometimes seen interrupt bursts with the old tmu driver which may be related.
Quoted 2 lines
According to the code above, I guess that TMU works as a non-periodic one-shot timer when the TCOR value is zero. Is it right?
Yes, you are correct.
Maybe we should disable the timer channel in a different way. I'm open to suggestions. =)
Cheers,
/ magnus
Quoted 6 lines · Magnus Damm
2009/5/30 Shin-ichiro KAWASAKI <[email protected]>:
Quoted 4 lines
I made some investigation, and found that the warnings are printed after zero value is set to TCOR. ?I checked SH7785 hardware manual, but could not find any description what happens when zero value set to TCOR.
Quoted 9 lines
Thanks for investigating. I read a few SH manuals before converting the old driver, but I couldn't find any description of zero value. Same as you.
The idea with zero value TCOR comes from the old driver. It may be there for some historical reason, or it may just be plain wrong. I've sometimes seen interrupt bursts with the old tmu driver which may be related.
It was mostly there just because it worked and seemed like a reasonable thing to do, and because no one had any better ideas on what to do in that situation. But yes, technically the behaviour is undefined, and so finding something slightly more precise is a good idea.
Quoted 15 lines · Paul Mundt
Quoted 5 lines · Magnus Damm
2009/5/30 Shin-ichiro KAWASAKI <[email protected]>:
Quoted 4 lines
I made some investigation, and found that the warnings are printed after zero value is set to TCOR. ?I checked SH7785 hardware manual, but could not find any description what happens when zero value set to TCOR.
Quoted 9 lines
Thanks for investigating. I read a few SH manuals before converting the old driver, but I couldn't find any description of zero value. Same as you.
The idea with zero value TCOR comes from the old driver. It may be there for some historical reason, or it may just be plain wrong. I've sometimes seen interrupt bursts with the old tmu driver which may be related.
Quoted 4 lines
It was mostly there just because it worked and seemed like a reasonable thing to do, and because no one had any better ideas on what to do in that situation. But yes, technically the behaviour is undefined, and so finding something slightly more precise is a good idea.
Thank you for your explanations, Magnus, Paul!
It has got clearer for me.
I guess there are two solutions.
i) Add one-shot timer feature to qemu-sh's TMU emulation. (Even though this feature is not documented.)
ii) Modify sh-linux TMU driver not to set zero value to TCOR.
(A status will be added to sh_tmu_priv.)
I'll consider on both of them, but that will take a week or so. Any help from others will be appreciated.
Regards,
Shin-ichiro KAWASAKI
Quoted 26 lines · Shin-ichiro KAWASAKI
Quoted 15 lines · Paul Mundt
Quoted 5 lines · Magnus Damm
2009/5/30 Shin-ichiro KAWASAKI <[email protected]>:
Quoted 4 lines
I made some investigation, and found that the warnings are printed after zero value is set to TCOR. ?I checked SH7785 hardware manual, but could not find any description what happens when zero value set to TCOR.
Quoted 9 lines
Thanks for investigating. I read a few SH manuals before converting the old driver, but I couldn't find any description of zero value. Same as you.
The idea with zero value TCOR comes from the old driver. It may be there for some historical reason, or it may just be plain wrong. I've sometimes seen interrupt bursts with the old tmu driver which may be related.
Quoted 4 lines
It was mostly there just because it worked and seemed like a reasonable thing to do, and because no one had any better ideas on what to do in that situation. But yes, technically the behaviour is undefined, and so finding something slightly more precise is a good idea.
Thank you for your explanations, Magnus, Paul!
It has got clearer for me.I guess there are two solutions.
Quoted 7 lines
i) Add one-shot timer feature to qemu-sh's TMU emulation. (Even though this feature is not documented.)
ii) Modify sh-linux TMU driver not to set zero value to TCOR.
(A status will be added tosh_tmu_priv.)I'll consider on both of them, but that will take a week or so. Any help from others will be appreciated.
Here's the patch which suggests TMU driver modification.
It does,
- Sets maximum value 0xffffffff to TCOR instead of zero. Then after one shot interrupt, next count down runs for a while (around seconds?)
- Stops the timer in the one shot interrupt handler. Then next count down does not reach to zero.
This patch assumes that while TMU counting down from 0xffffffff, the interrupt handler finishes the task to stop the timer.
I confirmed that the timer warnings from qemu-sh disappear with this patch. No test is done with real hardware.
I'm not familiar with linux clock framework.
Any comments are welcome.
Regards,
Shin-ichiro KAWASAKI
drivers/clocksource/sh_tmu.c +0 -0
@@ -158,7 +158,7 @@ static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta,
if (periodic) sh_tmu_write(p, TCOR, delta); else
- sh_tmu_write(p, TCOR, 0);
+ sh_tmu_write(p, TCOR, 0xffffffff);
sh_tmu_write(p, TCNT, delta);
@@ -171,9 +171,10 @@ static irqreturn_t sh_tmu_interrupt(int irq, void *dev_id)
struct sh_tmu_priv *p = dev_id;
/* disable or acknowledge interrupt */
- if (p->ced.mode = CLOCK_EVT_MODE_ONESHOT)
+ if (p->ced.mode = CLOCK_EVT_MODE_ONESHOT) {
+ sh_tmu_start_stop_ch(p, 0);
sh_tmu_write(p, TCR, 0x0000);
- else
+ } else
sh_tmu_write(p, TCR, 0x0020);
/* notify clockevent layer */