2010-09-20 15:11:11 +04:00
/***************************************************************************/
/*
* sltimers . c - - generic ColdFire slice timer support .
*
* Copyright ( C ) 2009 - 2010 , Philippe De Muyter < phdm @ macqel . be >
* based on
* timers . c - - generic ColdFire hardware timer support .
* Copyright ( C ) 1999 - 2008 , Greg Ungerer < gerg @ snapgear . com >
*/
/***************************************************************************/
# include <linux/kernel.h>
# include <linux/init.h>
# include <linux/sched.h>
# include <linux/interrupt.h>
# include <linux/irq.h>
# include <linux/profile.h>
# include <linux/clocksource.h>
# include <asm/io.h>
# include <asm/traps.h>
# include <asm/machdep.h>
# include <asm/coldfire.h>
# include <asm/mcfslt.h>
# include <asm/mcfsim.h>
/***************************************************************************/
# ifdef CONFIG_HIGHPROFILE
/*
* By default use Slice Timer 1 as the profiler clock timer .
*/
2012-09-17 10:51:20 +04:00
# define PA(a) (MCFSLT_TIMER1 + (a))
2010-09-20 15:11:11 +04:00
/*
* Choose a reasonably fast profile timer . Make it an odd value to
* try and get good coverage of kernel operations .
*/
# define PROFILEHZ 1013
irqreturn_t mcfslt_profile_tick ( int irq , void * dummy )
{
/* Reset Slice Timer 1 */
__raw_writel ( MCFSLT_SSR_BE | MCFSLT_SSR_TE , PA ( MCFSLT_SSR ) ) ;
if ( current - > pid )
profile_tick ( CPU_PROFILING ) ;
return IRQ_HANDLED ;
}
static struct irqaction mcfslt_profile_irq = {
. name = " profile timer " ,
2013-09-07 09:43:08 +04:00
. flags = IRQF_TIMER ,
2010-09-20 15:11:11 +04:00
. handler = mcfslt_profile_tick ,
} ;
void mcfslt_profile_init ( void )
{
printk ( KERN_INFO " PROFILE: lodging TIMER 1 @ %dHz as profile timer \n " ,
PROFILEHZ ) ;
setup_irq ( MCF_IRQ_PROFILER , & mcfslt_profile_irq ) ;
/* Set up TIMER 2 as high speed profile clock */
__raw_writel ( MCF_BUSCLK / PROFILEHZ - 1 , PA ( MCFSLT_STCNT ) ) ;
__raw_writel ( MCFSLT_SCR_RUN | MCFSLT_SCR_IEN | MCFSLT_SCR_TEN ,
PA ( MCFSLT_SCR ) ) ;
}
# endif /* CONFIG_HIGHPROFILE */
/***************************************************************************/
/*
* By default use Slice Timer 0 as the system clock timer .
*/
2012-09-17 10:51:20 +04:00
# define TA(a) (MCFSLT_TIMER0 + (a))
2010-09-20 15:11:11 +04:00
static u32 mcfslt_cycles_per_jiffy ;
static u32 mcfslt_cnt ;
2012-01-23 09:34:58 +04:00
static irq_handler_t timer_interrupt ;
2010-09-20 15:11:11 +04:00
static irqreturn_t mcfslt_tick ( int irq , void * dummy )
{
/* Reset Slice Timer 0 */
__raw_writel ( MCFSLT_SSR_BE | MCFSLT_SSR_TE , TA ( MCFSLT_SSR ) ) ;
mcfslt_cnt + = mcfslt_cycles_per_jiffy ;
2012-01-23 09:34:58 +04:00
return timer_interrupt ( irq , dummy ) ;
2010-09-20 15:11:11 +04:00
}
static struct irqaction mcfslt_timer_irq = {
. name = " timer " ,
2013-09-07 09:43:08 +04:00
. flags = IRQF_TIMER ,
2010-09-20 15:11:11 +04:00
. handler = mcfslt_tick ,
} ;
2016-12-21 22:32:01 +03:00
static u64 mcfslt_read_clk ( struct clocksource * cs )
2010-09-20 15:11:11 +04:00
{
unsigned long flags ;
2011-11-16 09:09:02 +04:00
u32 cycles , scnt ;
2010-09-20 15:11:11 +04:00
local_irq_save ( flags ) ;
scnt = __raw_readl ( TA ( MCFSLT_SCNT ) ) ;
cycles = mcfslt_cnt ;
2011-11-16 09:09:02 +04:00
if ( __raw_readl ( TA ( MCFSLT_SSR ) ) & MCFSLT_SSR_TE ) {
cycles + = mcfslt_cycles_per_jiffy ;
scnt = __raw_readl ( TA ( MCFSLT_SCNT ) ) ;
}
2010-09-20 15:11:11 +04:00
local_irq_restore ( flags ) ;
2011-03-31 05:57:33 +04:00
/* subtract because slice timers count down */
2011-11-16 09:09:02 +04:00
return cycles + ( ( mcfslt_cycles_per_jiffy - 1 ) - scnt ) ;
2010-09-20 15:11:11 +04:00
}
static struct clocksource mcfslt_clk = {
. name = " slt " ,
. rating = 250 ,
. read = mcfslt_read_clk ,
. mask = CLOCKSOURCE_MASK ( 32 ) ,
. flags = CLOCK_SOURCE_IS_CONTINUOUS ,
} ;
2012-01-23 09:34:58 +04:00
void hw_timer_init ( irq_handler_t handler )
2010-09-20 15:11:11 +04:00
{
mcfslt_cycles_per_jiffy = MCF_BUSCLK / HZ ;
/*
* The coldfire slice timer ( SLT ) runs from STCNT to 0 included ,
* then STCNT again and so on . It counts thus actually
* STCNT + 1 steps for 1 tick , not STCNT . So if you want
* n cycles , initialize STCNT with n - 1.
*/
__raw_writel ( mcfslt_cycles_per_jiffy - 1 , TA ( MCFSLT_STCNT ) ) ;
__raw_writel ( MCFSLT_SCR_RUN | MCFSLT_SCR_IEN | MCFSLT_SCR_TEN ,
TA ( MCFSLT_SCR ) ) ;
/* initialize mcfslt_cnt knowing that slice timers count down */
mcfslt_cnt = mcfslt_cycles_per_jiffy ;
2012-01-23 09:34:58 +04:00
timer_interrupt = handler ;
2010-09-20 15:11:11 +04:00
setup_irq ( MCF_IRQ_TIMER , & mcfslt_timer_irq ) ;
2011-10-25 22:46:10 +04:00
clocksource_register_hz ( & mcfslt_clk , MCF_BUSCLK ) ;
2010-09-20 15:11:11 +04:00
# ifdef CONFIG_HIGHPROFILE
mcfslt_profile_init ( ) ;
# endif
}