tree: drop last paragraph of GPL copyright header
[coreboot.git] / payloads / libpayload / drivers / timer / img_pistachio.c
blob070998faa9dd5a26af7cbf089607cc404cb7e89c
1 /*
2 * This file is part of the libpayload project.
4 * Copyright (C) 2014 Imagination Technologies
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 <libpayload.h>
17 #include <arch/cpu.h>
19 uint64_t timer_hz(void)
21 return lib_sysinfo.cpu_khz * 1000;
24 uint64_t timer_raw_value(void)
26 static uint64_t total_ticks = 0;
27 uint8_t overflow = 0;
28 uint32_t current_ticks = read_c0_count() * 2;
30 /* It assumes only one overflow happened since the last call */
31 if (current_ticks <= (uint32_t)total_ticks)
32 overflow = 1;
33 /* The least significant part(32 bits) of total_ticks will always
34 * become equal to current ticks */
35 total_ticks = (((total_ticks >> 32) + overflow) << 32) +
36 current_ticks;
37 return total_ticks;