blob: 8e84236018574c8fe80684f74e1bc062f6760eeb [file] [log] [blame]
Vadim Bendeburyf16b0822014-09-29 13:08:24 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google 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.
Vadim Bendeburyf16b0822014-09-29 13:08:24 -070014 */
15
Ionela Voinescu1d4c3052015-06-07 23:22:34 +010016#include <arch/cpu.h>
17#include <soc/cpu.h>
Vadim Bendebury52a88792014-11-05 17:50:09 -080018#include <stdint.h>
Vadim Bendeburyf16b0822014-09-29 13:08:24 -070019#include <timer.h>
Vadim Bendebury52a88792014-11-05 17:50:09 -080020#include <timestamp.h>
Vadim Bendebury52a88792014-11-05 17:50:09 -080021
Ionela Voinescu420b0f62015-01-19 02:39:18 +000022#define PISTACHIO_CLOCK_SWITCH 0xB8144200
23#define MIPS_EXTERN_PLL_BYPASS_MASK 0x00000002
24
Vadim Bendebury52a88792014-11-05 17:50:09 -080025static int get_count_mhz_freq(void)
26{
27 static unsigned count_mhz_freq;
28
29 if (!count_mhz_freq) {
30 if (IMG_PLATFORM_ID() != IMG_PLATFORM_ID_SILICON)
31 count_mhz_freq = 25; /* FPGA board */
Ionela Voinescu420b0f62015-01-19 02:39:18 +000032 else {
33 /* If MIPS PLL external bypass bit is set, it means
34 * that the MIPS PLL is already set up to work at a
35 * frequency of 550 MHz; otherwise, the crystal is
36 * used with a frequency of 52 MHz
Vadim Bendebury52a88792014-11-05 17:50:09 -080037 */
Ionela Voinescu420b0f62015-01-19 02:39:18 +000038 if (read32(PISTACHIO_CLOCK_SWITCH) &
39 MIPS_EXTERN_PLL_BYPASS_MASK)
40 /* Half MIPS PLL freq. */
41 count_mhz_freq = 275;
42 else
43 /* Half Xtal freq. */
44 count_mhz_freq = 26;
45 }
Vadim Bendebury52a88792014-11-05 17:50:09 -080046 }
47 return count_mhz_freq;
48}
Vadim Bendeburyf16b0822014-09-29 13:08:24 -070049
50void timer_monotonic_get(struct mono_time *mt)
51{
Aaron Durbin60391b62015-08-30 16:04:13 -050052 mono_time_set_usecs(mt, read_c0_count() / get_count_mhz_freq());
Vadim Bendeburyf16b0822014-09-29 13:08:24 -070053}