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.
18 #include <soc/addressmap.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))
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)
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
);
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
);