1 // SPDX-License-Identifier: GPL-2.0
2 /***************************************************************************/
5 * sltimers.c -- generic ColdFire slice timer support.
7 * Copyright (C) 2009-2010, Philippe De Muyter <phdm@macqel.be>
9 * timers.c -- generic ColdFire hardware timer support.
10 * Copyright (C) 1999-2008, Greg Ungerer <gerg@snapgear.com>
13 /***************************************************************************/
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/sched.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
20 #include <linux/profile.h>
21 #include <linux/clocksource.h>
23 #include <asm/traps.h>
24 #include <asm/machdep.h>
25 #include <asm/coldfire.h>
26 #include <asm/mcfslt.h>
27 #include <asm/mcfsim.h>
29 /***************************************************************************/
31 #ifdef CONFIG_HIGHPROFILE
34 * By default use Slice Timer 1 as the profiler clock timer.
36 #define PA(a) (MCFSLT_TIMER1 + (a))
39 * Choose a reasonably fast profile timer. Make it an odd value to
40 * try and get good coverage of kernel operations.
42 #define PROFILEHZ 1013
44 irqreturn_t
mcfslt_profile_tick(int irq
, void *dummy
)
46 /* Reset Slice Timer 1 */
47 __raw_writel(MCFSLT_SSR_BE
| MCFSLT_SSR_TE
, PA(MCFSLT_SSR
));
49 profile_tick(CPU_PROFILING
);
53 static struct irqaction mcfslt_profile_irq
= {
54 .name
= "profile timer",
56 .handler
= mcfslt_profile_tick
,
59 void mcfslt_profile_init(void)
61 printk(KERN_INFO
"PROFILE: lodging TIMER 1 @ %dHz as profile timer\n",
64 setup_irq(MCF_IRQ_PROFILER
, &mcfslt_profile_irq
);
66 /* Set up TIMER 2 as high speed profile clock */
67 __raw_writel(MCF_BUSCLK
/ PROFILEHZ
- 1, PA(MCFSLT_STCNT
));
68 __raw_writel(MCFSLT_SCR_RUN
| MCFSLT_SCR_IEN
| MCFSLT_SCR_TEN
,
73 #endif /* CONFIG_HIGHPROFILE */
75 /***************************************************************************/
78 * By default use Slice Timer 0 as the system clock timer.
80 #define TA(a) (MCFSLT_TIMER0 + (a))
82 static u32 mcfslt_cycles_per_jiffy
;
83 static u32 mcfslt_cnt
;
85 static irq_handler_t timer_interrupt
;
87 static irqreturn_t
mcfslt_tick(int irq
, void *dummy
)
89 /* Reset Slice Timer 0 */
90 __raw_writel(MCFSLT_SSR_BE
| MCFSLT_SSR_TE
, TA(MCFSLT_SSR
));
91 mcfslt_cnt
+= mcfslt_cycles_per_jiffy
;
92 return timer_interrupt(irq
, dummy
);
95 static struct irqaction mcfslt_timer_irq
= {
98 .handler
= mcfslt_tick
,
101 static u64
mcfslt_read_clk(struct clocksource
*cs
)
106 local_irq_save(flags
);
107 scnt
= __raw_readl(TA(MCFSLT_SCNT
));
109 if (__raw_readl(TA(MCFSLT_SSR
)) & MCFSLT_SSR_TE
) {
110 cycles
+= mcfslt_cycles_per_jiffy
;
111 scnt
= __raw_readl(TA(MCFSLT_SCNT
));
113 local_irq_restore(flags
);
115 /* subtract because slice timers count down */
116 return cycles
+ ((mcfslt_cycles_per_jiffy
- 1) - scnt
);
119 static struct clocksource mcfslt_clk
= {
122 .read
= mcfslt_read_clk
,
123 .mask
= CLOCKSOURCE_MASK(32),
124 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
127 void hw_timer_init(irq_handler_t handler
)
129 mcfslt_cycles_per_jiffy
= MCF_BUSCLK
/ HZ
;
131 * The coldfire slice timer (SLT) runs from STCNT to 0 included,
132 * then STCNT again and so on. It counts thus actually
133 * STCNT + 1 steps for 1 tick, not STCNT. So if you want
134 * n cycles, initialize STCNT with n - 1.
136 __raw_writel(mcfslt_cycles_per_jiffy
- 1, TA(MCFSLT_STCNT
));
137 __raw_writel(MCFSLT_SCR_RUN
| MCFSLT_SCR_IEN
| MCFSLT_SCR_TEN
,
139 /* initialize mcfslt_cnt knowing that slice timers count down */
140 mcfslt_cnt
= mcfslt_cycles_per_jiffy
;
142 timer_interrupt
= handler
;
143 setup_irq(MCF_IRQ_TIMER
, &mcfslt_timer_irq
);
145 clocksource_register_hz(&mcfslt_clk
, MCF_BUSCLK
);
147 #ifdef CONFIG_HIGHPROFILE
148 mcfslt_profile_init();