blob: be5f20f7c266660e9858619d1fa2a57658ecd078 [file] [log] [blame]
huang linc14b54d2016-03-02 18:38:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 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
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
huang linc14b54d2016-03-02 18:38:40 +080017#include <delay.h>
18#include <soc/timer.h>
19#include <stdint.h>
20#include <timer.h>
21
22static uint64_t timer_raw_value(void)
23{
24 uint64_t value0;
25 uint64_t value1;
26
27 value0 = (uint64_t)read32(&timer0_ptr->timer_cur_value0);
28 value1 = (uint64_t)read32(&timer0_ptr->timer_cur_value1);
29
30 return value0 | value1<<32;
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
38void init_timer(void)
39{
40 write32(&timer0_ptr->timer_load_count0, TIMER_LOAD_VAL);
41 write32(&timer0_ptr->timer_load_count1, TIMER_LOAD_VAL);
42 write32(&timer0_ptr->timer_load_count2, 0);
43 write32(&timer0_ptr->timer_load_count3, 0);
44 write32(&timer0_ptr->timer_ctrl_reg, 1);
45}