libpayload: adopt upstream changes to generic timer driver

There was some ongoing development on the generic timer driver after it
was merged into CrOS libpayload, so fetch that.

BUG=none
BRANCH=none
TEST=none
CQ-DEPEND=CL:427823

Change-Id: I78c38eb8c8a3aca66a08e702978a7290a26fd3d7
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/427822
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
This commit is contained in:
Patrick Georgi 2017-01-12 20:48:58 +01:00 committed by chrome-bot
commit 5846d248fb

View file

@ -1,24 +1,39 @@
/*
* This file is part of the coreboot project.
* This file is part of the libpayload project.
*
* Copyright 2016 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.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 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.
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <assert.h>
#include <libpayload.h>
static uint32_t *low_reg = (void *)CONFIG_LP_TIMER_GENERIC_REG;
static uint32_t *high_reg = (void *)CONFIG_LP_TIMER_GENERIC_HIGH_REG;
uint64_t timer_hz(void)
{
/* libc/time.c currently requires all timers to be at least 1MHz. */
@ -32,13 +47,13 @@ uint64_t timer_raw_value(void)
uint32_t count_h;
uint32_t count_l;
if (!high_reg)
return readl(low_reg);
if (!CONFIG_LP_TIMER_GENERIC_HIGH_REG)
return readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_REG));
do {
count_h = readl(high_reg);
count_l = readl(low_reg);
cur_tick = readl(high_reg);
count_h = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_HIGH_REG));
count_l = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_REG));
cur_tick = readl(phys_to_virt(CONFIG_LP_TIMER_GENERIC_REG));
} while (cur_tick != count_h);
return (cur_tick << 32) + count_l;