tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / soc / broadcom / cygnus / timer.c
blob78d996fb37f712f1fc4b21fb2d89262e658d1cd8
1 /*
2 * This file is part of the coreboot project.
4 * Copyright 2015 Google Inc.
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.
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.
16 #include <arch/io.h>
17 #include <delay.h>
18 #include <soc/addressmap.h>
19 #include <timer.h>
21 #define TIMER_GLB_TIM_CTRL_PRESC_MASK 0x0000FF00
22 #define TIMER_GLB_TIM_CTRL_TIM_EN 0x00000001
23 #define TIMER_GLB_TIM_CTRL_PRESC 0x0
25 * arm clk is 1GHz, periph_clk=arm_clk/2, tick per usec.
26 * arm clk is set by the bootrom. See util/broadcom/unauth.cfg for details.
28 #define PERIPH_CLOCK 500
29 #define CLOCKS_PER_USEC (PERIPH_CLOCK / \
30 (((TIMER_GLB_TIM_CTRL_PRESC & TIMER_GLB_TIM_CTRL_PRESC_MASK) >> 8) + 1))
32 struct cygnus_timer {
33 u32 gtim_glob_low;
34 u32 gtim_glob_hi;
35 u32 gtim_glob_ctrl;
38 static struct cygnus_timer * const timer_ptr =
39 (void *)IPROC_PERIPH_GLB_TIM_REG_BASE;
41 static inline uint64_t timer_raw_value(void)
43 uint64_t cur_tick;
44 uint32_t count_h;
45 uint32_t count_l;
47 do {
48 count_h = read32(&timer_ptr->gtim_glob_hi);
49 count_l = read32(&timer_ptr->gtim_glob_low);
50 cur_tick = read32(&timer_ptr->gtim_glob_hi);
51 } while (cur_tick != count_h);
53 return (cur_tick << 32) + count_l;
56 void timer_monotonic_get(struct mono_time *mt)
58 mono_time_set_usecs(mt, timer_raw_value() / CLOCKS_PER_USEC);
61 void init_timer(void)
63 write32(&timer_ptr->gtim_glob_ctrl, TIMER_GLB_TIM_CTRL_PRESC);
64 write32(&timer_ptr->gtim_glob_low, 0);
65 write32(&timer_ptr->gtim_glob_hi, 0);
66 write32(&timer_ptr->gtim_glob_ctrl, TIMER_GLB_TIM_CTRL_TIM_EN);