1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007 Michal Simek
5 * Michal SIMEK <monstr@monstr.eu>
13 #include <asm/microblaze_timer.h>
14 #include <asm/microblaze_intc.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 volatile int timestamp = 0;
19 microblaze_timer_t *tmr;
21 ulong get_timer (ulong base)
24 return timestamp - base;
25 return timestamp++ - base;
28 void __udelay(unsigned long usec)
34 while ((get_timer(0) - i) < (usec / 1000))
39 #ifndef CONFIG_SPL_BUILD
40 static void timer_isr(void *arg)
43 tmr->control = tmr->control | TIMER_INTERRUPT;
51 const void *blob = gd->fdt_blob;
55 debug("TIMER: Initialization\n");
57 /* Do not init before relocation */
58 if (!(gd->flags & GD_FLG_RELOC))
61 node = fdt_node_offset_by_compatible(blob, node,
62 "xlnx,xps-timer-1.00.a");
64 fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
65 if (base == FDT_ADDR_T_NONE)
68 debug("TIMER: Base addr %lx\n", base);
69 tmr = (microblaze_timer_t *)base;
71 ret = fdtdec_get_int_array(blob, node, "interrupts",
72 cell, ARRAY_SIZE(cell));
77 debug("TIMER: IRQ %x\n", irq);
79 preload = fdtdec_get_int(blob, node, "clock-frequency", 0);
80 preload /= CONFIG_SYS_HZ;
85 if (tmr && preload && irq >= 0) {
86 tmr->loadreg = preload;
87 tmr->control = TIMER_INTERRUPT | TIMER_RESET;
88 tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
89 TIMER_RELOAD | TIMER_DOWN_COUNT;
91 ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
95 /* No problem if timer is not found/initialized */
106 * This function is derived from PowerPC code (read timebase as long long).
107 * On Microblaze it just returns the timer value.
109 unsigned long long get_ticks(void)
115 * This function is derived from PowerPC code (timebase clock frequency).
116 * On Microblaze it returns the number of timer ticks per second.
118 ulong get_tbclk(void)
120 return CONFIG_SYS_HZ;