1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007, 2012 Freescale Semiconductor, Inc.
4 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
10 #include <asm/timer.h>
11 #include <asm/immap.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 static ulong timestamp;
18 #if defined(CONFIG_SLTTMR)
19 #ifndef CONFIG_SYS_UDELAY_BASE
20 # error "uDelay base not defined!"
23 #if !defined(CONFIG_SYS_TMR_BASE) || !defined(CONFIG_SYS_INTR_BASE) || !defined(CONFIG_SYS_TMRINTR_NO) || !defined(CONFIG_SYS_TMRINTR_MASK)
24 # error "TMR_BASE, INTR_BASE, TMRINTR_NO or TMRINTR_MASk not defined!"
26 extern void dtimer_intr_setup(void);
28 void __udelay(unsigned long usec)
30 slt_t *timerp = (slt_t *) (CONFIG_SYS_UDELAY_BASE);
34 freq = CONFIG_SYS_TIMER_PRESCALER;
37 out_be32(&timerp->cr, 0);
38 out_be32(&timerp->tcnt, usec * freq);
39 out_be32(&timerp->cr, SLT_CR_TEN);
41 now = in_be32(&timerp->cnt);
43 now = in_be32(&timerp->cnt);
45 setbits_be32(&timerp->sr, SLT_SR_ST);
46 out_be32(&timerp->cr, 0);
49 void dtimer_interrupt(void *not_used)
51 slt_t *timerp = (slt_t *) (CONFIG_SYS_TMR_BASE);
53 /* check for timer interrupt asserted */
54 if ((CONFIG_SYS_TMRPND_REG & CONFIG_SYS_TMRINTR_MASK) == CONFIG_SYS_TMRINTR_PEND) {
55 setbits_be32(&timerp->sr, SLT_SR_ST);
63 slt_t *timerp = (slt_t *) (CONFIG_SYS_TMR_BASE);
68 out_be32(&timerp->cr, 0);
69 out_be32(&timerp->tcnt, 0);
71 out_be32(&timerp->sr, SLT_SR_BE | SLT_SR_ST);
73 /* initialize and enable timer interrupt */
74 irq_install_handler(CONFIG_SYS_TMRINTR_NO, dtimer_interrupt, 0);
76 /* Interrupt every ms */
77 out_be32(&timerp->tcnt, 1000 * CONFIG_SYS_TIMER_PRESCALER);
81 /* set a period of 1us, set timer mode to restart and
82 enable timer and interrupt */
83 out_be32(&timerp->cr, SLT_CR_RUN | SLT_CR_IEN | SLT_CR_TEN);
87 ulong get_timer(ulong base)
89 return (timestamp - base);
92 #endif /* CONFIG_SLTTMR */