Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | int timer_init(void) |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
Stephen Warren | 37c1efa | 2013-03-27 18:43:23 +0000 | [diff] [blame^] | 26 | ulong get_timer_us(ulong base) |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 27 | { |
| 28 | struct bcm2835_timer_regs *regs = |
| 29 | (struct bcm2835_timer_regs *)BCM2835_TIMER_PHYSADDR; |
| 30 | |
| 31 | return readl(®s->clo) - base; |
| 32 | } |
| 33 | |
Stephen Warren | 37c1efa | 2013-03-27 18:43:23 +0000 | [diff] [blame^] | 34 | ulong get_timer(ulong base) |
| 35 | { |
| 36 | ulong us = get_timer_us(0); |
| 37 | us /= (1000000 / CONFIG_SYS_HZ); |
| 38 | us -= base; |
| 39 | return us; |
| 40 | } |
| 41 | |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 42 | unsigned long long get_ticks(void) |
| 43 | { |
| 44 | return get_timer(0); |
| 45 | } |
| 46 | |
| 47 | ulong get_tbclk(void) |
| 48 | { |
| 49 | return CONFIG_SYS_HZ; |
| 50 | } |
| 51 | |
| 52 | void __udelay(unsigned long usec) |
| 53 | { |
| 54 | ulong endtime; |
| 55 | signed long diff; |
| 56 | |
Stephen Warren | 37c1efa | 2013-03-27 18:43:23 +0000 | [diff] [blame^] | 57 | endtime = get_timer_us(0) + usec; |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 58 | |
| 59 | do { |
Stephen Warren | 37c1efa | 2013-03-27 18:43:23 +0000 | [diff] [blame^] | 60 | ulong now = get_timer_us(0); |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 61 | diff = endtime - now; |
| 62 | } while (diff >= 0); |
| 63 | } |