upstream u-boot with additional patches for our devices/boards:
https://lists.denx.de/pipermail/u-boot/2017-March/282789.html (AXP crashes) ;
Gbit ethernet patch for some LIME2 revisions ;
with SPI flash support
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
3.2 KiB
160 lines
3.2 KiB
18 years ago
|
/*
|
||
|
* U-boot - interrupts.c Interrupt related routines
|
||
|
*
|
||
17 years ago
|
* Copyright (c) 2005-2008 Analog Devices Inc.
|
||
18 years ago
|
*
|
||
|
* 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.
|
||
|
*
|
||
17 years ago
|
* Licensed under the GPL-2 or later.
|
||
18 years ago
|
*/
|
||
|
|
||
|
#include <common.h>
|
||
|
#include <config.h>
|
||
15 years ago
|
#include <watchdog.h>
|
||
18 years ago
|
#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).
|
||
17 years ago
|
* On Blackfin it just returns the timer value.
|
||
18 years ago
|
*/
|
||
|
unsigned long long get_ticks(void)
|
||
|
{
|
||
|
return get_timer(0);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* This function is derived from PowerPC code (timebase clock frequency).
|
||
17 years ago
|
* On Blackfin it returns the number of timer ticks per second.
|
||
18 years ago
|
*/
|
||
|
ulong get_tbclk(void)
|
||
|
{
|
||
|
ulong tbclk;
|
||
|
|
||
16 years ago
|
tbclk = CONFIG_SYS_HZ;
|
||
18 years ago
|
return tbclk;
|
||
|
}
|
||
|
|
||
|
void enable_interrupts(void)
|
||
|
{
|
||
17 years ago
|
local_irq_restore(int_flag);
|
||
18 years ago
|
}
|
||
|
|
||
|
int disable_interrupts(void)
|
||
|
{
|
||
17 years ago
|
local_irq_save(int_flag);
|
||
18 years ago
|
return 1;
|
||
|
}
|
||
|
|
||
15 years ago
|
void __udelay(unsigned long usec)
|
||
18 years ago
|
{
|
||
|
unsigned long delay, start, stop;
|
||
|
unsigned long cclk;
|
||
|
cclk = (CONFIG_CCLK_HZ);
|
||
|
|
||
|
while (usec > 1) {
|
||
15 years ago
|
WATCHDOG_RESET();
|
||
|
|
||
18 years ago
|
/*
|
||
|
* 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;
|
||
|
}
|
||
|
|
||
17 years ago
|
asm volatile (" %0 = CYCLES;" : "=r" (start));
|
||
18 years ago
|
do {
|
||
17 years ago
|
asm volatile (" %0 = CYCLES; " : "=r" (stop));
|
||
18 years ago
|
} while (stop - start < delay);
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
17 years ago
|
#define MAX_TIM_LOAD 0xFFFFFFFF
|
||
|
int timer_init(void)
|
||
18 years ago
|
{
|
||
15 years ago
|
bfin_write_TCNTL(0x1);
|
||
16 years ago
|
CSYNC();
|
||
15 years ago
|
bfin_write_TSCALE(0x0);
|
||
|
bfin_write_TCOUNT(MAX_TIM_LOAD);
|
||
|
bfin_write_TPERIOD(MAX_TIM_LOAD);
|
||
|
bfin_write_TCNTL(0x7);
|
||
16 years ago
|
CSYNC();
|
||
18 years ago
|
|
||
|
timestamp = 0;
|
||
|
last_time = 0;
|
||
17 years ago
|
|
||
|
return 0;
|
||
18 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* 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 */
|
||
15 years ago
|
ulong clocks = (MAX_TIM_LOAD - bfin_read_TCOUNT());
|
||
18 years ago
|
|
||
|
/*
|
||
|
* 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);
|
||
|
|
||
|
/*
|
||
17 years ago
|
* Find the number of millisonds that
|
||
|
* got elapsed before this TCOUNT cycle
|
||
18 years ago
|
*/
|
||
|
milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
|
||
|
|
||
|
return (milisec - base);
|
||
|
}
|
||
17 years ago
|
|
||
|
void reset_timer(void)
|
||
|
{
|
||
16 years ago
|
timer_init();
|
||
17 years ago
|
}
|