2007-03-20 10:16:24 +00:00
|
|
|
/*
|
2016-02-06 03:30:11 +00:00
|
|
|
* U-Boot - interrupts.c Interrupt related routines
|
2007-03-20 10:16:24 +00:00
|
|
|
*
|
2008-03-30 19:46:13 +00:00
|
|
|
* Copyright (c) 2005-2008 Analog Devices Inc.
|
2007-03-20 10:16:24 +00:00
|
|
|
*
|
|
|
|
* This file is based on interrupts.c
|
|
|
|
* Copyright 1996 Roman Zippel
|
|
|
|
* Copyright 1999 D. Jeff Dionne <jeff@uclinux.org>
|
|
|
|
* Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
|
|
|
|
* Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
|
|
|
|
* Copyright 2003 Metrowerks/Motorola
|
|
|
|
* Copyright 2003 Bas Vermeulen <bas@buyways.nl>,
|
|
|
|
* BuyWays B.V. (www.buyways.nl)
|
|
|
|
*
|
|
|
|
* (C) Copyright 2000-2004
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2008-03-30 19:46:13 +00:00
|
|
|
* Licensed under the GPL-2 or later.
|
2007-03-20 10:16:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <config.h>
|
2009-10-09 06:24:33 +00:00
|
|
|
#include <watchdog.h>
|
2007-03-20 10:16:24 +00:00
|
|
|
#include <asm/blackfin.h>
|
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
static ulong timestamp;
|
|
|
|
static ulong last_time;
|
|
|
|
static int int_flag;
|
|
|
|
|
|
|
|
int irq_flags; /* needed by asm-blackfin/system.h */
|
|
|
|
|
|
|
|
/* Functions just to satisfy the linker */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (read timebase as long long).
|
2008-03-30 19:46:13 +00:00
|
|
|
* On Blackfin it just returns the timer value.
|
2007-03-20 10:16:24 +00:00
|
|
|
*/
|
|
|
|
unsigned long long get_ticks(void)
|
|
|
|
{
|
|
|
|
return get_timer(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (timebase clock frequency).
|
2008-03-30 19:46:13 +00:00
|
|
|
* On Blackfin it returns the number of timer ticks per second.
|
2007-03-20 10:16:24 +00:00
|
|
|
*/
|
|
|
|
ulong get_tbclk(void)
|
|
|
|
{
|
2016-09-06 13:17:38 +00:00
|
|
|
return CONFIG_SYS_HZ;
|
2007-03-20 10:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void enable_interrupts(void)
|
|
|
|
{
|
2008-03-30 19:46:13 +00:00
|
|
|
local_irq_restore(int_flag);
|
2007-03-20 10:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int disable_interrupts(void)
|
|
|
|
{
|
2008-03-30 19:46:13 +00:00
|
|
|
local_irq_save(int_flag);
|
2007-03-20 10:16:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-11-24 13:09:21 +00:00
|
|
|
void __udelay(unsigned long usec)
|
2007-03-20 10:16:24 +00:00
|
|
|
{
|
|
|
|
unsigned long delay, start, stop;
|
|
|
|
unsigned long cclk;
|
|
|
|
cclk = (CONFIG_CCLK_HZ);
|
|
|
|
|
|
|
|
while (usec > 1) {
|
2009-10-09 06:24:33 +00:00
|
|
|
WATCHDOG_RESET();
|
|
|
|
|
2007-03-20 10:16:24 +00:00
|
|
|
/*
|
|
|
|
* how many clock ticks to delay?
|
|
|
|
* - request(in useconds) * clock_ticks(Hz) / useconds/second
|
|
|
|
*/
|
|
|
|
if (usec < 1000) {
|
|
|
|
delay = (usec * (cclk / 244)) >> 12;
|
|
|
|
usec = 0;
|
|
|
|
} else {
|
|
|
|
delay = (1000 * (cclk / 244)) >> 12;
|
|
|
|
usec -= 1000;
|
|
|
|
}
|
|
|
|
|
2008-03-30 19:46:13 +00:00
|
|
|
asm volatile (" %0 = CYCLES;" : "=r" (start));
|
2007-03-20 10:16:24 +00:00
|
|
|
do {
|
2008-03-30 19:46:13 +00:00
|
|
|
asm volatile (" %0 = CYCLES; " : "=r" (stop));
|
2007-03-20 10:16:24 +00:00
|
|
|
} while (stop - start < delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-30 19:46:13 +00:00
|
|
|
#define MAX_TIM_LOAD 0xFFFFFFFF
|
|
|
|
int timer_init(void)
|
2007-03-20 10:16:24 +00:00
|
|
|
{
|
2009-11-12 23:42:53 +00:00
|
|
|
bfin_write_TCNTL(0x1);
|
2009-05-19 08:40:08 +00:00
|
|
|
CSYNC();
|
2009-11-12 23:42:53 +00:00
|
|
|
bfin_write_TSCALE(0x0);
|
|
|
|
bfin_write_TCOUNT(MAX_TIM_LOAD);
|
|
|
|
bfin_write_TPERIOD(MAX_TIM_LOAD);
|
|
|
|
bfin_write_TCNTL(0x7);
|
2009-05-19 08:40:08 +00:00
|
|
|
CSYNC();
|
2007-03-20 10:16:24 +00:00
|
|
|
|
|
|
|
timestamp = 0;
|
|
|
|
last_time = 0;
|
2008-03-30 19:46:13 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-03-20 10:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Any network command or flash
|
|
|
|
* command is started get_timer shall
|
|
|
|
* be called before TCOUNT gets reset,
|
|
|
|
* to implement the accurate timeouts.
|
|
|
|
*
|
|
|
|
* How ever milliconds doesn't return
|
|
|
|
* the number that has been elapsed from
|
|
|
|
* the last reset.
|
|
|
|
*
|
|
|
|
* As get_timer is used in the u-boot
|
|
|
|
* only for timeouts this should be
|
|
|
|
* sufficient
|
|
|
|
*/
|
|
|
|
ulong get_timer(ulong base)
|
|
|
|
{
|
|
|
|
ulong milisec;
|
|
|
|
|
|
|
|
/* Number of clocks elapsed */
|
2009-11-12 23:42:53 +00:00
|
|
|
ulong clocks = (MAX_TIM_LOAD - bfin_read_TCOUNT());
|
2007-03-20 10:16:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find if the TCOUNT is reset
|
|
|
|
* timestamp gives the number of times
|
|
|
|
* TCOUNT got reset
|
|
|
|
*/
|
|
|
|
if (clocks < last_time)
|
|
|
|
timestamp++;
|
|
|
|
last_time = clocks;
|
|
|
|
|
|
|
|
/* Get the number of milliseconds */
|
|
|
|
milisec = clocks / (CONFIG_CCLK_HZ / 1000);
|
|
|
|
|
|
|
|
/*
|
2008-03-30 19:46:13 +00:00
|
|
|
* Find the number of millisonds that
|
|
|
|
* got elapsed before this TCOUNT cycle
|
2007-03-20 10:16:24 +00:00
|
|
|
*/
|
|
|
|
milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
|
|
|
|
|
|
|
|
return (milisec - base);
|
|
|
|
}
|