1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007 Michal Simek
5 * Michal SIMEK <monstr@monstr.eu>
11 #include <asm/microblaze_timer.h>
12 #include <asm/microblaze_intc.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 volatile int timestamp = 0;
17 microblaze_timer_t *tmr;
19 ulong get_timer (ulong base)
22 return timestamp - base;
23 return timestamp++ - base;
26 void __udelay(unsigned long usec)
32 while ((get_timer(0) - i) < (usec / 1000))
37 #ifndef CONFIG_SPL_BUILD
38 static void timer_isr(void *arg)
41 tmr->control = tmr->control | TIMER_INTERRUPT;
49 const void *blob = gd->fdt_blob;
53 debug("TIMER: Initialization\n");
55 /* Do not init before relocation */
56 if (!(gd->flags & GD_FLG_RELOC))
59 node = fdt_node_offset_by_compatible(blob, node,
60 "xlnx,xps-timer-1.00.a");
62 fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
63 if (base == FDT_ADDR_T_NONE)
66 debug("TIMER: Base addr %lx\n", base);
67 tmr = (microblaze_timer_t *)base;
69 ret = fdtdec_get_int_array(blob, node, "interrupts",
70 cell, ARRAY_SIZE(cell));
75 debug("TIMER: IRQ %x\n", irq);
77 preload = fdtdec_get_int(blob, node, "clock-frequency", 0);
78 preload /= CONFIG_SYS_HZ;
83 if (tmr && preload && irq >= 0) {
84 tmr->loadreg = preload;
85 tmr->control = TIMER_INTERRUPT | TIMER_RESET;
86 tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
87 TIMER_RELOAD | TIMER_DOWN_COUNT;
89 ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
93 /* No problem if timer is not found/initialized */
104 * This function is derived from PowerPC code (read timebase as long long).
105 * On Microblaze it just returns the timer value.
107 unsigned long long get_ticks(void)
113 * This function is derived from PowerPC code (timebase clock frequency).
114 * On Microblaze it returns the number of timer ticks per second.
116 ulong get_tbclk(void)
118 return CONFIG_SYS_HZ;