Vadim Bendebury | f16b082 | 2014-09-29 13:08:24 -0700 | [diff] [blame] | 1 | /* |
| 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 Bendebury | f16b082 | 2014-09-29 13:08:24 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Ionela Voinescu | 1d4c305 | 2015-06-07 23:22:34 +0100 | [diff] [blame] | 16 | #include <arch/cpu.h> |
| 17 | #include <soc/cpu.h> |
Vadim Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 18 | #include <stdint.h> |
Vadim Bendebury | f16b082 | 2014-09-29 13:08:24 -0700 | [diff] [blame] | 19 | #include <timer.h> |
Vadim Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 20 | #include <timestamp.h> |
Vadim Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 21 | |
Ionela Voinescu | 420b0f6 | 2015-01-19 02:39:18 +0000 | [diff] [blame] | 22 | #define PISTACHIO_CLOCK_SWITCH 0xB8144200 |
| 23 | #define MIPS_EXTERN_PLL_BYPASS_MASK 0x00000002 |
| 24 | |
Vadim Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 25 | static 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 Voinescu | 420b0f6 | 2015-01-19 02:39:18 +0000 | [diff] [blame] | 32 | 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 Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 37 | */ |
Ionela Voinescu | 420b0f6 | 2015-01-19 02:39:18 +0000 | [diff] [blame] | 38 | 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 Bendebury | 52a8879 | 2014-11-05 17:50:09 -0800 | [diff] [blame] | 46 | } |
| 47 | return count_mhz_freq; |
| 48 | } |
Vadim Bendebury | f16b082 | 2014-09-29 13:08:24 -0700 | [diff] [blame] | 49 | |
| 50 | void timer_monotonic_get(struct mono_time *mt) |
| 51 | { |
Aaron Durbin | 60391b6 | 2015-08-30 16:04:13 -0500 | [diff] [blame] | 52 | mono_time_set_usecs(mt, read_c0_count() / get_count_mhz_freq()); |
Vadim Bendebury | f16b082 | 2014-09-29 13:08:24 -0700 | [diff] [blame] | 53 | } |