2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-01-15 19:37:34 +00:00
|
|
|
/*
|
2012-03-26 21:49:07 +00:00
|
|
|
* (C) Copyright 2007, 2012 Freescale Semiconductor, Inc.
|
2008-01-15 19:37:34 +00:00
|
|
|
* TsiChung Liew (Tsi-Chung.Liew@freescale.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:41 +00:00
|
|
|
#include <irq_func.h>
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
#include <asm/timer.h>
|
|
|
|
#include <asm/immap.h>
|
2012-03-26 21:49:07 +00:00
|
|
|
#include <asm/io.h>
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
static ulong timestamp;
|
|
|
|
|
|
|
|
#if defined(CONFIG_SLTTMR)
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_UDELAY_BASE
|
2008-01-15 19:37:34 +00:00
|
|
|
# error "uDelay base not defined!"
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if !defined(CONFIG_SYS_TMR_BASE) || !defined(CONFIG_SYS_INTR_BASE) || !defined(CONFIG_SYS_TMRINTR_NO) || !defined(CONFIG_SYS_TMRINTR_MASK)
|
2008-01-15 19:37:34 +00:00
|
|
|
# error "TMR_BASE, INTR_BASE, TMRINTR_NO or TMRINTR_MASk not defined!"
|
|
|
|
#endif
|
|
|
|
extern void dtimer_intr_setup(void);
|
|
|
|
|
2009-11-24 13:09:21 +00:00
|
|
|
void __udelay(unsigned long usec)
|
2008-01-15 19:37:34 +00:00
|
|
|
{
|
2012-03-26 21:49:07 +00:00
|
|
|
slt_t *timerp = (slt_t *) (CONFIG_SYS_UDELAY_BASE);
|
2008-01-15 19:37:34 +00:00
|
|
|
u32 now, freq;
|
|
|
|
|
|
|
|
/* 1 us period */
|
2008-10-16 13:01:15 +00:00
|
|
|
freq = CONFIG_SYS_TIMER_PRESCALER;
|
2008-01-15 19:37:34 +00:00
|
|
|
|
2012-03-26 21:49:07 +00:00
|
|
|
/* Disable */
|
|
|
|
out_be32(&timerp->cr, 0);
|
|
|
|
out_be32(&timerp->tcnt, usec * freq);
|
|
|
|
out_be32(&timerp->cr, SLT_CR_TEN);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
2012-03-26 21:49:07 +00:00
|
|
|
now = in_be32(&timerp->cnt);
|
2008-01-15 19:37:34 +00:00
|
|
|
while (now != 0)
|
2012-03-26 21:49:07 +00:00
|
|
|
now = in_be32(&timerp->cnt);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
2012-03-26 21:49:07 +00:00
|
|
|
setbits_be32(&timerp->sr, SLT_SR_ST);
|
|
|
|
out_be32(&timerp->cr, 0);
|
2008-01-15 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dtimer_interrupt(void *not_used)
|
|
|
|
{
|
2012-03-26 21:49:07 +00:00
|
|
|
slt_t *timerp = (slt_t *) (CONFIG_SYS_TMR_BASE);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
/* check for timer interrupt asserted */
|
2008-10-16 13:01:15 +00:00
|
|
|
if ((CONFIG_SYS_TMRPND_REG & CONFIG_SYS_TMRINTR_MASK) == CONFIG_SYS_TMRINTR_PEND) {
|
2012-03-26 21:49:07 +00:00
|
|
|
setbits_be32(&timerp->sr, SLT_SR_ST);
|
2008-01-15 19:37:34 +00:00
|
|
|
timestamp++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 02:02:32 +00:00
|
|
|
int timer_init(void)
|
2008-01-15 19:37:34 +00:00
|
|
|
{
|
2012-03-26 21:49:07 +00:00
|
|
|
slt_t *timerp = (slt_t *) (CONFIG_SYS_TMR_BASE);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
timestamp = 0;
|
|
|
|
|
2012-03-26 21:49:07 +00:00
|
|
|
/* disable timer */
|
|
|
|
out_be32(&timerp->cr, 0);
|
|
|
|
out_be32(&timerp->tcnt, 0);
|
|
|
|
/* clear status */
|
|
|
|
out_be32(&timerp->sr, SLT_SR_BE | SLT_SR_ST);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
/* initialize and enable timer interrupt */
|
2008-10-16 13:01:15 +00:00
|
|
|
irq_install_handler(CONFIG_SYS_TMRINTR_NO, dtimer_interrupt, 0);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
/* Interrupt every ms */
|
2012-03-26 21:49:07 +00:00
|
|
|
out_be32(&timerp->tcnt, 1000 * CONFIG_SYS_TIMER_PRESCALER);
|
2008-01-15 19:37:34 +00:00
|
|
|
|
|
|
|
dtimer_intr_setup();
|
|
|
|
|
|
|
|
/* set a period of 1us, set timer mode to restart and
|
|
|
|
enable timer and interrupt */
|
2012-03-26 21:49:07 +00:00
|
|
|
out_be32(&timerp->cr, SLT_CR_RUN | SLT_CR_IEN | SLT_CR_TEN);
|
2011-08-19 02:02:32 +00:00
|
|
|
return 0;
|
2008-01-15 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulong get_timer(ulong base)
|
|
|
|
{
|
|
|
|
return (timestamp - base);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SLTTMR */
|