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>
15 #include <linux/delay.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 volatile int timestamp = 0;
20 microblaze_timer_t *tmr;
22 ulong get_timer (ulong base)
25 return timestamp - base;
26 return timestamp++ - base;
29 void __udelay(unsigned long usec)
35 while ((get_timer(0) - i) < (usec / 1000))
40 #ifndef CONFIG_SPL_BUILD
41 static void timer_isr(void *arg)
44 tmr->control = tmr->control | TIMER_INTERRUPT;
52 const void *blob = gd->fdt_blob;
56 debug("TIMER: Initialization\n");
58 /* Do not init before relocation */
59 if (!(gd->flags & GD_FLG_RELOC))
62 node = fdt_node_offset_by_compatible(blob, node,
63 "xlnx,xps-timer-1.00.a");
65 fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
66 if (base == FDT_ADDR_T_NONE)
69 debug("TIMER: Base addr %lx\n", base);
70 tmr = (microblaze_timer_t *)base;
72 ret = fdtdec_get_int_array(blob, node, "interrupts",
73 cell, ARRAY_SIZE(cell));
78 debug("TIMER: IRQ %x\n", irq);
80 preload = fdtdec_get_int(blob, node, "clock-frequency", 0);
81 preload /= CONFIG_SYS_HZ;
86 if (tmr && preload && irq >= 0) {
87 tmr->loadreg = preload;
88 tmr->control = TIMER_INTERRUPT | TIMER_RESET;
89 tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
90 TIMER_RELOAD | TIMER_DOWN_COUNT;
92 ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
96 /* No problem if timer is not found/initialized */
107 * This function is derived from PowerPC code (read timebase as long long).
108 * On Microblaze it just returns the timer value.
110 unsigned long long get_ticks(void)
116 * This function is derived from PowerPC code (timebase clock frequency).
117 * On Microblaze it returns the number of timer ticks per second.
119 ulong get_tbclk(void)
121 return CONFIG_SYS_HZ;