32k timer reorg
Subsystems (4)
cover 32k timer reorg
Here's a short series of patches to reorganize and consolidate the 32k timer code. In particular, conslidate the usage of DM timers and move the OMAP1 specifics into mach-omap1.
Kevin
--
PATCH 1/3 ARM: OMAP: re-organize duplicated 32k-timer code
On OMAP2/3, the gp-timer code can be used for a 32kHz timer simply by setting the source to be the 32k clock instead of sys_clk.
This patch uses the mach-omap2/timer-gp.c code for 32kHz timer on OMAP2, moving the logic into mach-omap2/timer-gp.c, and not using plat-omap/timer32k.c which, for OMAP2, is redundant with the timer-gp code.
Also, if CONFIG_OMAP_32K_TIMER is enabled, the gptimer-based clocksource is not used. Instead the default 32k sync counter is used as the clocksource (see the clocksource in plat-omap/common.c.) This is important for sleep/suspend so there is a valid counter during sleep. Note that the suspend/sleep code needs fixing to check for overflows of this counter.
In addition, the OMAP2/3 details are removed from timer32k.c leaving that with only OMAP1 specifics. A follow-up patch will move it from plat-omap common code to mach-omap1.
--- arch/arm/mach-omap2/Makefile | 4 --- arch/arm/mach-omap2/timer-gp.c | 14 ++++++++++++ arch/arm/plat-omap/Makefile | 2 + arch/arm/plat-omap/timer32k.c | 47 ----------------------------------------- 4 files changed, 18 insertions(+), 49 deletions(-)
arch/arm/mach-omap2/Makefile +1 -3
@@ -4,9 +4,7 @@ # Common support obj-y := irq.o id.o io.o sram-fn.o memory.o prcm.o clock.o mux.o devices.o \ - serial.o gpmc.o - -obj-$(CONFIG_OMAP_MPU_TIMER) += timer-gp.o + serial.o gpmc.o timer-gp.o # Power Management obj-$(CONFIG_PM) += pm.o sleep.o
arch/arm/mach-omap2/timer-gp.c +14 -0
@@ -104,7 +104,11 @@ static void __init omap2_gp_clockevent_i gptimer =omap_dm_timer_request_specific (1 );BUG_ON (gptimer ==NULL ); +#if defined(CONFIG_OMAP_32K_TIMER ) +omap_dm_timer_set_source (gptimer,OMAP_TIMER_SRC_32_KHZ ); +#else omap_dm_timer_set_source (gptimer,OMAP_TIMER_SRC_SYS_CLK ); +#endif tick_rate =clk_get_rate (omap_dm_timer_get_fclk (gptimer)); omap2_gp_timer_irq.dev_id = (void *)gptimer;
@@ -122,6 +126,15 @@ static void __init omap2_gp_clockevent_iclockevents_register_device (&clockevent_gpt); } +#ifdef CONFIG_OMAP_32K_TIMER +/* +* When 32k-timer is enabled, don't use GPTimer for clocksource +* instead, just leave default clocksource which uses the 32k +* sync counter. See clocksource setup in see plat-omap/common.c. +*/ + +static inline void __init omap2_gp_clocksource_init (void ) {} +#else /* * clocksource */
@@ -167,6 +180,7 @@ static void __init omap2_gp_clocksource_if (clocksource_register (&clocksource_gpt)) printk(err2, clocksource_gpt.name); } +#endif static void __init omap2_gp_timer_init (void ) {
arch/arm/plat-omap/Makefile +2 -0
@@ -9,7 +9,9 @@ obj-m := obj-n := obj- := +ifeq ($(CONFIG_ARCH_OMAP1),y) obj-$(CONFIG_OMAP_32K_TIMER) += timer32k.o +endif # OCPI interconnect support for 1710, 1610 and 5912 obj-$(CONFIG_ARCH_OMAP16XX) += ocpi.o
arch/arm/plat-omap/timer32k.c +1 -46
71 lines not on this page · raw message
--
PATCH 2/3 ARM: OMAP: Move 32k-based sched_clock() to common code
In reply to Kevin HilmanSince 32k timer code is moving to OMAP1 specific dir, move the 32k-based sched_clock() into common code where it is based on the 32k sync counter and can be used even when using MPU timer.
While moving change the ticks-to-nsecs conversion to use the helper functions provided by clocksource.h.
Also removed the unused ticks_to_usec, leaving only ticks_to_nsec.
--- arch/arm/plat-omap/common.c | 17 +++++++++++++++++ arch/arm/plat-omap/timer32k.c | 26 -------------------------- 2 files changed, 17 insertions(+), 26 deletions(-)
arch/arm/plat-omap/common.c +17 -0
@@ -213,6 +213,23 @@ static struct clocksource clocksource_32 .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +/* +* Rounds down to nearest nsec. +*/ +unsigned long long omap_32k_ticks_to_nsecs (unsigned long ticks_32k) +{ +return cyc2ns (&clocksource_32k, ticks_32k); +} + +/* +* Returns current time from boot in nsecs. It's OK for this to wrap +* around for now, as it's just a relative time stamp. +*/ +unsigned long long sched_clock (void ) +{ +return omap_32k_ticks_to_nsecs (omap_32k_read ()); +} +static int __init omap_init_clocksource_32k (void ) {static char err[]__initdata =KERN_ERR
arch/arm/plat-omap/timer32k.c +0 -26
@@ -189,32 +189,6 @@ static inline unsigned long omap_32k_synreturn omap_readl (TIMER_32K_SYNCHRONIZED ); } -/* -* Rounds down to nearest usec. Note that this will overflow for larger values. -*/ -static inline unsigned long omap_32k_ticks_to_usecs (unsigned long ticks_32k) -{ -return (ticks_32k *5 *5 *5 *5 *5 *5 ) >>9 ; -} - -/* -* Rounds down to nearest nsec. -*/ -static inline unsigned long long -omap_32k_ticks_to_nsecs (unsigned long ticks_32k) -{ -return (unsigned long long ) ticks_32k *1000 *5 *5 *5 *5 *5 *5 >>9 ; -} - -/* -* Returns current time from boot in nsecs. It's OK for this to wrap -* around for now, as it's just a relative time stamp. -*/ -unsigned long long sched_clock (void ) -{ -return omap_32k_ticks_to_nsecs (omap_32k_sync_timer_read ()); -} -static irqreturn_t omap_32k_timer_interrupt (int irq,void *dev_id) {struct clock_event_device *evt = &clockevent_32k_timer;
--
Re: [PATCH 2/3] ARM: OMAP: Move 32k-based sched_clock() to common code
Quoted 9 lines · Kevin Hilman
Since 32k timer code is moving to OMAP1 specific dir, move the 32k-based
sched_clock()into common code where it is based on the 32k sync counter and can be used even when using MPU timer.While moving change the ticks-to-nsecs conversion to use the helper functions provided by
clocksource.h.Also removed the unused
ticks_to_usec, leaving onlyticks_to_nsec.
Update for OMAP1: Make sched_clock() weak MPU version wins if enabled.
Kevin
PATCH 3/3 ARM: OMAP: Move timer32k to mach-omap1
In reply to Kevin HilmanMove timer32k code to mach-omap1 since OMAP2/3 32k timers are done in gptimer code.
--- arch/arm/mach-omap1/Makefile | 3 arch/arm/mach-omap1/timer32k.c | 209 +++++++++++++++++++++++++++++++++++++++++ arch/arm/plat-omap/Makefile | 4 arch/arm/plat-omap/timer32k.c | 209 ----------------------------------------- 4 files changed, 211 insertions(+), 214 deletions(-)
arch/arm/mach-omap1/Makefile +2 -1
@@ -5,7 +5,8 @@ # Common support obj-y := io.o id.o clock.o irq.o mux.o serial.o devices.o -obj-$(CONFIG_OMAP_MPU_TIMER) += time.o +obj-$(CONFIG_OMAP_MPU_TIMER) += time.o +obj-$(CONFIG_OMAP_32K_TIMER) += timer32k.o # Power Management obj-$(CONFIG_PM) += pm.o sleep.o
arch/arm/mach-omap1/timer32k.c new file +209 -0
209 lines not on this page · raw message
arch/arm/plat-omap/Makefile +0 -4
@@ -9,10 +9,6 @@ obj-m := obj-n := obj- := -ifeq ($(CONFIG_ARCH_OMAP1),y) -obj-$(CONFIG_OMAP_32K_TIMER) += timer32k.o -endif - # OCPI interconnect support for 1710, 1610 and 5912 obj-$(CONFIG_ARCH_OMAP16XX) += ocpi.o
arch/arm/plat-omap/timer32k.c deleted +0 -209
209 lines not on this page · raw message
--
Quoted 3 lines · Kevin Hilman
Here's a short series of patches to reorganize and consolidate the 32k timer code. In particular, conslidate the usage of DM timers and move the OMAP1 specifics into mach-omap1.
I forgot to mention that this was tested on both OMAP1 (OSK) and OMAP2 (2430SDP) in both 32k and MPU timer mode.
Kevin