Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 1 | /* |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright 2016 Google Inc. |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 16 | * Alternatively, this software may be distributed under the terms of the |
| 17 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 18 | * Software Foundation. |
| 19 | * |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | */ |
| 32 | |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 33 | #include <assert.h> |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 34 | #include <libpayload.h> |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 35 | |
Julius Werner | 5ec3dea | 2024-02-06 22:52:06 -0800 | [diff] [blame^] | 36 | uint64_t timer_hz(void) |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 37 | { |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 38 | return CONFIG_LP_TIMER_GENERIC_HZ; |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | uint64_t timer_raw_value(void) |
| 42 | { |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 43 | uint64_t cur_tick; |
| 44 | uint32_t count_h; |
| 45 | uint32_t count_l; |
| 46 | |
| 47 | if (!CONFIG_LP_TIMER_GENERIC_HIGH_REG) |
| 48 | return readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_REG)); |
| 49 | |
| 50 | do { |
| 51 | count_h = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_HIGH_REG)); |
| 52 | count_l = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_REG)); |
Paul Kocialkowski | 35562d8 | 2016-12-19 19:22:39 +0100 | [diff] [blame] | 53 | cur_tick = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_HIGH_REG)); |
Julius Werner | 4fda9bd | 2016-05-16 15:39:12 -0700 | [diff] [blame] | 54 | } while (cur_tick != count_h); |
| 55 | |
| 56 | return (cur_tick << 32) + count_l; |
Gabe Black | d4d29a1 | 2014-04-10 02:36:49 -0700 | [diff] [blame] | 57 | } |