blob: 0b07eda525cef47f242d43597dd5595cf446feed [file] [log] [blame]
jinkun.hongac490b82014-06-22 20:40:39 -07001/*
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.
jinkun.hongac490b82014-06-22 20:40:39 -070014 */
15
Julius Werner7a453eb2014-10-20 13:14:55 -070016#include <arch/io.h>
jinkun.hongac490b82014-06-22 20:40:39 -070017#include <delay.h>
Julius Werner7a453eb2014-10-20 13:14:55 -070018#include <soc/timer.h>
Julius Werner8d978a82014-12-08 13:16:03 -080019#include <stdint.h>
Julius Werner7a453eb2014-10-20 13:14:55 -070020#include <timer.h>
jinkun.hongac490b82014-06-22 20:40:39 -070021
Julius Werner8d978a82014-12-08 13:16:03 -080022static uint64_t timer_raw_value(void)
23{
24 uint64_t value0;
25 uint64_t value1;
26
27 value0 = (uint64_t)read32(&timer7_ptr->timer_curr_value0);
28 value1 = (uint64_t)read32(&timer7_ptr->timer_curr_value1);
29 value0 = value0 | value1<<32;
30 return value0;
31}
32
33void timer_monotonic_get(struct mono_time *mt)
34{
35 mono_time_set_usecs(mt, timer_raw_value() / clocks_per_usec);
36}
37
Julius Werner44cf8702014-12-08 13:39:14 -080038void init_timer(void)
jinkun.hongac490b82014-06-22 20:40:39 -070039{
Julius Werner2f37bd62015-02-19 14:51:15 -080040 write32(&timer7_ptr->timer_load_count0, TIMER_LOAD_VAL);
41 write32(&timer7_ptr->timer_load_count1, TIMER_LOAD_VAL);
42 write32(&timer7_ptr->timer_ctrl_reg, 1);
jinkun.hongac490b82014-06-22 20:40:39 -070043}