2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-03-11 12:42:58 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2007 Michal Simek
|
|
|
|
*
|
|
|
|
* Michal SIMEK <monstr@monstr.eu>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-02-15 11:10:32 +00:00
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-11-14 19:57:30 +00:00
|
|
|
#include <time.h>
|
2007-03-11 12:42:58 +00:00
|
|
|
#include <asm/microblaze_timer.h>
|
2007-05-07 15:22:25 +00:00
|
|
|
#include <asm/microblaze_intc.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2007-03-11 12:42:58 +00:00
|
|
|
|
2016-02-15 11:10:32 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2007-03-11 12:42:58 +00:00
|
|
|
volatile int timestamp = 0;
|
2012-06-29 11:46:54 +00:00
|
|
|
microblaze_timer_t *tmr;
|
2007-03-11 12:42:58 +00:00
|
|
|
|
|
|
|
ulong get_timer (ulong base)
|
|
|
|
{
|
2012-06-29 11:46:54 +00:00
|
|
|
if (tmr)
|
|
|
|
return timestamp - base;
|
|
|
|
return timestamp++ - base;
|
2007-03-11 12:42:58 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 11:42:28 +00:00
|
|
|
void __udelay(unsigned long usec)
|
|
|
|
{
|
2012-06-29 11:46:54 +00:00
|
|
|
u32 i;
|
2012-06-29 11:42:28 +00:00
|
|
|
|
2012-06-29 11:46:54 +00:00
|
|
|
if (tmr) {
|
|
|
|
i = get_timer(0);
|
|
|
|
while ((get_timer(0) - i) < (usec / 1000))
|
|
|
|
;
|
|
|
|
}
|
2012-06-29 11:42:28 +00:00
|
|
|
}
|
|
|
|
|
2014-01-21 06:30:37 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2012-06-29 11:46:54 +00:00
|
|
|
static void timer_isr(void *arg)
|
2007-03-11 12:42:58 +00:00
|
|
|
{
|
|
|
|
timestamp++;
|
|
|
|
tmr->control = tmr->control | TIMER_INTERRUPT;
|
|
|
|
}
|
|
|
|
|
2010-04-16 09:37:41 +00:00
|
|
|
int timer_init (void)
|
2007-03-11 12:42:58 +00:00
|
|
|
{
|
2012-06-29 11:46:54 +00:00
|
|
|
int irq = -1;
|
|
|
|
u32 preload = 0;
|
|
|
|
u32 ret = 0;
|
2016-02-15 11:10:32 +00:00
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
int node = 0;
|
|
|
|
u32 cell[2];
|
|
|
|
|
|
|
|
debug("TIMER: Initialization\n");
|
|
|
|
|
2018-07-11 12:08:26 +00:00
|
|
|
/* Do not init before relocation */
|
|
|
|
if (!(gd->flags & GD_FLG_RELOC))
|
|
|
|
return 0;
|
|
|
|
|
2016-02-15 11:10:32 +00:00
|
|
|
node = fdt_node_offset_by_compatible(blob, node,
|
|
|
|
"xlnx,xps-timer-1.00.a");
|
|
|
|
if (node != -1) {
|
|
|
|
fdt_addr_t base = fdtdec_get_addr(blob, node, "reg");
|
|
|
|
if (base == FDT_ADDR_T_NONE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
debug("TIMER: Base addr %lx\n", base);
|
|
|
|
tmr = (microblaze_timer_t *)base;
|
|
|
|
|
|
|
|
ret = fdtdec_get_int_array(blob, node, "interrupts",
|
|
|
|
cell, ARRAY_SIZE(cell));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
irq = cell[0];
|
|
|
|
debug("TIMER: IRQ %x\n", irq);
|
|
|
|
|
|
|
|
preload = fdtdec_get_int(blob, node, "clock-frequency", 0);
|
|
|
|
preload /= CONFIG_SYS_HZ;
|
|
|
|
} else {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2012-06-29 11:46:54 +00:00
|
|
|
if (tmr && preload && irq >= 0) {
|
|
|
|
tmr->loadreg = preload;
|
|
|
|
tmr->control = TIMER_INTERRUPT | TIMER_RESET;
|
|
|
|
tmr->control = TIMER_ENABLE | TIMER_ENABLE_INTR |\
|
|
|
|
TIMER_RELOAD | TIMER_DOWN_COUNT;
|
|
|
|
timestamp = 0;
|
|
|
|
ret = install_interrupt_handler (irq, timer_isr, (void *)tmr);
|
|
|
|
if (ret)
|
|
|
|
tmr = NULL;
|
|
|
|
}
|
|
|
|
/* No problem if timer is not found/initialized */
|
2010-04-16 09:37:41 +00:00
|
|
|
return 0;
|
2007-03-11 12:42:58 +00:00
|
|
|
}
|
2014-01-21 06:30:37 +00:00
|
|
|
#else
|
|
|
|
int timer_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2012-02-22 21:39:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (read timebase as long long).
|
|
|
|
* On Microblaze it just returns the timer value.
|
|
|
|
*/
|
|
|
|
unsigned long long get_ticks(void)
|
|
|
|
{
|
|
|
|
return get_timer(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (timebase clock frequency).
|
|
|
|
* On Microblaze it returns the number of timer ticks per second.
|
|
|
|
*/
|
|
|
|
ulong get_tbclk(void)
|
|
|
|
{
|
|
|
|
return CONFIG_SYS_HZ;
|
|
|
|
}
|