Files
system76-coreboot/src/soc/broadcom/cygnus/timer.c
Julius Werner 2f37bd6551 arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:

@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)

BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)

Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-04-21 08:22:28 +02:00

72 lines
2.1 KiB
C

/*
* This file is part of the coreboot project.
*
* Copyright 2015 Google Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <arch/io.h>
#include <delay.h>
#include <soc/addressmap.h>
#include <timer.h>
#define TIMER_GLB_TIM_CTRL_PRESC_MASK 0x0000FF00
#define TIMER_GLB_TIM_CTRL_TIM_EN 0x00000001
#define TIMER_GLB_TIM_CTRL_PRESC 0x0
/*
* arm clk is 1GHz, periph_clk=arm_clk/2, tick per usec.
* arm clk is set by the bootrom. See util/broadcom/unauth.cfg for details.
*/
#define PERIPH_CLOCK 500
#define CLOCKS_PER_USEC (PERIPH_CLOCK / \
(((TIMER_GLB_TIM_CTRL_PRESC & TIMER_GLB_TIM_CTRL_PRESC_MASK) >> 8) + 1))
struct cygnus_timer {
u32 gtim_glob_low;
u32 gtim_glob_hi;
u32 gtim_glob_ctrl;
};
static struct cygnus_timer * const timer_ptr =
(void *)IPROC_PERIPH_GLB_TIM_REG_BASE;
static inline uint64_t timer_raw_value(void)
{
uint64_t cur_tick;
uint32_t count_h;
uint32_t count_l;
do {
count_h = read32(&timer_ptr->gtim_glob_hi);
count_l = read32(&timer_ptr->gtim_glob_low);
cur_tick = read32(&timer_ptr->gtim_glob_hi);
} while (cur_tick != count_h);
return (cur_tick << 32) + count_l;
}
void timer_monotonic_get(struct mono_time *mt)
{
mono_time_set_usecs(mt, timer_raw_value() / CLOCKS_PER_USEC);
}
void init_timer(void)
{
write32(&timer_ptr->gtim_glob_ctrl, TIMER_GLB_TIM_CTRL_PRESC);
write32(&timer_ptr->gtim_glob_low, 0);
write32(&timer_ptr->gtim_glob_hi, 0);
write32(&timer_ptr->gtim_glob_ctrl, TIMER_GLB_TIM_CTRL_TIM_EN);
}