2 * (C) Copyright 2007 Michal Simek
4 * Michal SIMEK <monstr@monstr.eu>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/microblaze_timer.h>
11 #include <asm/microblaze_intc.h>
13 volatile int timestamp = 0;
14 microblaze_timer_t *tmr;
16 ulong get_timer (ulong base)
19 return timestamp - base;
20 return timestamp++ - base;
23 void __udelay(unsigned long usec)
29 while ((get_timer(0) - i) < (usec / 1000))
32 for (i = 0; i < (usec * XILINX_CLOCK_FREQ / 10000000); i++)
37 #ifndef CONFIG_SPL_BUILD
38 static void timer_isr(void *arg)
41 tmr->control = tmr->control | TIMER_INTERRUPT;
50 #if defined(CONFIG_SYS_TIMER_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
51 preload = XILINX_CLOCK_FREQ / CONFIG_SYS_HZ;
52 irq = CONFIG_SYS_TIMER_0_IRQ;
53 tmr = (microblaze_timer_t *) (CONFIG_SYS_TIMER_0_ADDR);
56 if (tmr && preload && irq >= 0) {
57 tmr->loadreg = preload;
58 tmr->control = TIMER_INTERRUPT | TIMER_RESET;
59 tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
60 TIMER_RELOAD | TIMER_DOWN_COUNT;
62 ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
66 /* No problem if timer is not found/initialized */
77 * This function is derived from PowerPC code (read timebase as long long).
78 * On Microblaze it just returns the timer value.
80 unsigned long long get_ticks(void)
86 * This function is derived from PowerPC code (timebase clock frequency).
87 * On Microblaze it returns the number of timer ticks per second.