jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Rockchip Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 20 | #include <arch/io.h> |
jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 21 | #include <delay.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 22 | #include <soc/timer.h> |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 23 | #include <stdint.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 24 | #include <timer.h> |
jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 25 | |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 26 | static uint64_t timer_raw_value(void) |
| 27 | { |
| 28 | uint64_t value0; |
| 29 | uint64_t value1; |
| 30 | |
| 31 | value0 = (uint64_t)read32(&timer7_ptr->timer_curr_value0); |
| 32 | value1 = (uint64_t)read32(&timer7_ptr->timer_curr_value1); |
| 33 | value0 = value0 | value1<<32; |
| 34 | return value0; |
| 35 | } |
| 36 | |
| 37 | void timer_monotonic_get(struct mono_time *mt) |
| 38 | { |
| 39 | mono_time_set_usecs(mt, timer_raw_value() / clocks_per_usec); |
| 40 | } |
| 41 | |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 42 | void init_timer(void) |
jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 43 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 44 | write32(&timer7_ptr->timer_load_count0, TIMER_LOAD_VAL); |
| 45 | write32(&timer7_ptr->timer_load_count1, TIMER_LOAD_VAL); |
| 46 | write32(&timer7_ptr->timer_ctrl_reg, 1); |
jinkun.hong | ac490b8 | 2014-06-22 20:40:39 -0700 | [diff] [blame] | 47 | } |