blob: 017907cfb8d98edf794af63c4366d3f2a93bd079 [file] [log] [blame]
Stephen Warren45b8ae62012-08-05 16:07:21 +00001/*
2 * (C) Copyright 2012 Stephen Warren
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <common.h>
18#include <asm/io.h>
19#include <asm/arch/timer.h>
20
Stephen Warren37c1efa2013-03-27 18:43:23 +000021ulong get_timer_us(ulong base)
Stephen Warren45b8ae62012-08-05 16:07:21 +000022{
23 struct bcm2835_timer_regs *regs =
24 (struct bcm2835_timer_regs *)BCM2835_TIMER_PHYSADDR;
25
26 return readl(&regs->clo) - base;
27}
28
Stephen Warren37c1efa2013-03-27 18:43:23 +000029ulong get_timer(ulong base)
30{
31 ulong us = get_timer_us(0);
32 us /= (1000000 / CONFIG_SYS_HZ);
33 us -= base;
34 return us;
35}
36
Stephen Warren45b8ae62012-08-05 16:07:21 +000037unsigned long long get_ticks(void)
38{
39 return get_timer(0);
40}
41
42ulong get_tbclk(void)
43{
44 return CONFIG_SYS_HZ;
45}
46
47void __udelay(unsigned long usec)
48{
49 ulong endtime;
50 signed long diff;
51
Stephen Warren37c1efa2013-03-27 18:43:23 +000052 endtime = get_timer_us(0) + usec;
Stephen Warren45b8ae62012-08-05 16:07:21 +000053
54 do {
Stephen Warren37c1efa2013-03-27 18:43:23 +000055 ulong now = get_timer_us(0);
Stephen Warren45b8ae62012-08-05 16:07:21 +000056 diff = endtime - now;
57 } while (diff >= 0);
58}