mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-07-18 17:18:01 +09:00
Tegra2: Add microsecond timer function
These functions provide access to the high resolution microsecond timer and tidy up a global variable in the code. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
1c85752258
commit
39d3416f0a
@ -38,13 +38,12 @@
|
|||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <asm/arch/tegra2.h>
|
#include <asm/arch/tegra2.h>
|
||||||
|
#include <asm/arch/timer.h>
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
||||||
struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
|
|
||||||
|
|
||||||
/* counter runs at 1MHz */
|
/* counter runs at 1MHz */
|
||||||
#define TIMER_CLK (1000000)
|
#define TIMER_CLK 1000000
|
||||||
#define TIMER_LOAD_VAL 0xffffffff
|
#define TIMER_LOAD_VAL 0xffffffff
|
||||||
|
|
||||||
/* timer without interrupts */
|
/* timer without interrupts */
|
||||||
@ -57,10 +56,10 @@ ulong get_timer(ulong base)
|
|||||||
void __udelay(unsigned long usec)
|
void __udelay(unsigned long usec)
|
||||||
{
|
{
|
||||||
long tmo = usec * (TIMER_CLK / 1000) / 1000;
|
long tmo = usec * (TIMER_CLK / 1000) / 1000;
|
||||||
unsigned long now, last = readl(&timer_base->cntr_1us);
|
unsigned long now, last = timer_get_us();
|
||||||
|
|
||||||
while (tmo > 0) {
|
while (tmo > 0) {
|
||||||
now = readl(&timer_base->cntr_1us);
|
now = timer_get_us();
|
||||||
if (last > now) /* count up timer overflow */
|
if (last > now) /* count up timer overflow */
|
||||||
tmo -= TIMER_LOAD_VAL - last + now;
|
tmo -= TIMER_LOAD_VAL - last + now;
|
||||||
else
|
else
|
||||||
@ -74,7 +73,7 @@ ulong get_timer_masked(void)
|
|||||||
ulong now;
|
ulong now;
|
||||||
|
|
||||||
/* current tick value */
|
/* current tick value */
|
||||||
now = readl(&timer_base->cntr_1us) / (TIMER_CLK / CONFIG_SYS_HZ);
|
now = timer_get_us() / (TIMER_CLK / CONFIG_SYS_HZ);
|
||||||
|
|
||||||
if (now >= gd->lastinc) /* normal mode (non roll) */
|
if (now >= gd->lastinc) /* normal mode (non roll) */
|
||||||
/* move stamp forward with absolute diff ticks */
|
/* move stamp forward with absolute diff ticks */
|
||||||
@ -103,3 +102,10 @@ ulong get_tbclk(void)
|
|||||||
{
|
{
|
||||||
return CONFIG_SYS_HZ;
|
return CONFIG_SYS_HZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long timer_get_us(void)
|
||||||
|
{
|
||||||
|
struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
|
||||||
|
|
||||||
|
return readl(&timer_base->cntr_1us);
|
||||||
|
}
|
||||||
|
30
arch/arm/include/asm/arch-tegra2/timer.h
Normal file
30
arch/arm/include/asm/arch-tegra2/timer.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011 The Chromium OS Authors.
|
||||||
|
* See file CREDITS for list of people who contributed to this
|
||||||
|
* project.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||||
|
* MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Tegra2 timer functions */
|
||||||
|
|
||||||
|
#ifndef _TEGRA2_TIMER_H
|
||||||
|
#define _TEGRA2_TIMER_H
|
||||||
|
|
||||||
|
/* returns the current monotonic timer value in microseconds */
|
||||||
|
unsigned long timer_get_us(void);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user