[coreboot-gerrit] New patch to review for coreboot: 6c6e369 cygnus: add timer functions

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Apr 16 15:22:19 CEST 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9766

-gerrit

commit 6c6e369e6bb8d7482e290dd72f1c3c30a94599d6
Author: Daisuke Nojiri <dnojiri at chromium.org>
Date:   Wed Feb 4 17:23:53 2015 -0800

    cygnus: add timer functions
    
    this implements udelay.
    
    BUG=chrome-os-partner:36011
    BRANCH=broadcom-firmware
    TEST=measured 10 sec of delay by stopwatch
    
    Change-Id: I833b71fac98a871bff71478221a55e1ca15c13df
    Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
    Original-Commit-Id: 137456e63931052f80247b72f98f958afdba8a27
    Original-Signed-off-by: Daisuke Nojiri <dnojiri at chromium.org>
    Original-Change-Id: Ib5e33a19421eae900800fce94e9fd51bc2c665c4
    Original-Reviewed-on: https://chromium-review.googlesource.com/251302
    Original-Reviewed-by: Julius Werner <jwerner at chromium.org>
---
 src/soc/broadcom/cygnus/Makefile.inc             |  8 +--
 src/soc/broadcom/cygnus/include/soc/addressmap.h | 26 +++++++++
 src/soc/broadcom/cygnus/monotonic_timer.c        | 24 --------
 src/soc/broadcom/cygnus/timer.c                  | 71 ++++++++++++++++++++++++
 4 files changed, 101 insertions(+), 28 deletions(-)

diff --git a/src/soc/broadcom/cygnus/Makefile.inc b/src/soc/broadcom/cygnus/Makefile.inc
index ed1d2fb..6b547e2 100644
--- a/src/soc/broadcom/cygnus/Makefile.inc
+++ b/src/soc/broadcom/cygnus/Makefile.inc
@@ -20,20 +20,20 @@
 bootblock-y += bootblock.c
 bootblock-y += cbmem.c
 bootblock-y += i2c.c
-bootblock-y += monotonic_timer.c
+bootblock-y += timer.c
 bootblock-$(CONFIG_SPI_FLASH) += spi.c
 ifeq ($(CONFIG_BOOTBLOCK_CONSOLE),y)
 bootblock-$(CONFIG_DRIVERS_UART) += ns16550.c
 endif
 
 verstage-y += i2c.c
-verstage-y += monotonic_timer.c
+verstage-y += timer.c
 verstage-$(CONFIG_SPI_FLASH) += spi.c
 verstage-$(CONFIG_DRIVERS_UART) += ns16550.c
 
 romstage-y += cbmem.c
 romstage-y += i2c.c
-romstage-y += monotonic_timer.c
+romstage-y += timer.c
 romstage-y += romstage.c
 romstage-y += sdram.c
 romstage-$(CONFIG_SPI_FLASH) += spi.c
@@ -41,7 +41,7 @@ romstage-$(CONFIG_DRIVERS_UART) += ns16550.c
 
 ramstage-y += cbmem.c
 ramstage-y += i2c.c
-ramstage-y += monotonic_timer.c
+ramstage-y += timer.c
 ramstage-$(CONFIG_SPI_FLASH) += spi.c
 ramstage-$(CONFIG_DRIVERS_UART) += ns16550.c
 
diff --git a/src/soc/broadcom/cygnus/include/soc/addressmap.h b/src/soc/broadcom/cygnus/include/soc/addressmap.h
new file mode 100644
index 0000000..ef6a709
--- /dev/null
+++ b/src/soc/broadcom/cygnus/include/soc/addressmap.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __SOC_BROADCOM_CYGNUS_ADDRESSMAP_H__
+#define __SOC_BROADCOM_CYGNUS_ADDRESSMAP_H__
+
+#define IPROC_PERIPH_BASE		0x19020000
+#define IPROC_PERIPH_GLB_TIM_REG_BASE	(IPROC_PERIPH_BASE + 0x200)
+
+#endif	/* __SOC_BROADCOM_CYGNUS_ADDRESSMAP_H__ */
diff --git a/src/soc/broadcom/cygnus/monotonic_timer.c b/src/soc/broadcom/cygnus/monotonic_timer.c
deleted file mode 100644
index 67694f9..0000000
--- a/src/soc/broadcom/cygnus/monotonic_timer.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright 2015 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.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <timer.h>
-
-void timer_monotonic_get(struct mono_time *mt)
-{
-}
diff --git a/src/soc/broadcom/cygnus/timer.c b/src/soc/broadcom/cygnus/timer.c
new file mode 100644
index 0000000..5116389
--- /dev/null
+++ b/src/soc/broadcom/cygnus/timer.c
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <arch/io.h>
+#include <delay.h>
+#include <soc/addressmap.h>
+#include <timer.h>
+
+#define TIMER_GLB_TIM_CTRL_PRESC_MASK	0x0000FF00
+#define TIMER_GLB_TIM_CTRL_TIM_EN	0x00000001
+#define TIMER_GLB_TIM_CTRL_PRESC	0x0
+/*
+ * arm clk is 1GHz, periph_clk=arm_clk/2, tick per usec.
+ * arm clk is set by the bootrom. See util/broadcom/unauth.cfg for details.
+ */
+#define PERIPH_CLOCK			500
+#define CLOCKS_PER_USEC	(PERIPH_CLOCK / \
+	(((TIMER_GLB_TIM_CTRL_PRESC & TIMER_GLB_TIM_CTRL_PRESC_MASK) >> 8) + 1))
+
+struct cygnus_timer {
+	u32 gtim_glob_low;
+	u32 gtim_glob_hi;
+	u32 gtim_glob_ctrl;
+};
+
+static struct cygnus_timer * const timer_ptr =
+		(void *)IPROC_PERIPH_GLB_TIM_REG_BASE;
+
+static inline uint64_t timer_raw_value(void)
+{
+	uint64_t cur_tick;
+	uint32_t count_h;
+	uint32_t count_l;
+
+	do {
+		count_h = readl(&timer_ptr->gtim_glob_hi);
+		count_l = readl(&timer_ptr->gtim_glob_low);
+		cur_tick = readl(&timer_ptr->gtim_glob_hi);
+	} while (cur_tick != count_h);
+
+	return (cur_tick << 32) + count_l;
+}
+
+void timer_monotonic_get(struct mono_time *mt)
+{
+	mono_time_set_usecs(mt, timer_raw_value() / CLOCKS_PER_USEC);
+}
+
+void init_timer(void)
+{
+	writel(TIMER_GLB_TIM_CTRL_PRESC, &timer_ptr->gtim_glob_ctrl);
+	writel(0, &timer_ptr->gtim_glob_low);
+	writel(0, &timer_ptr->gtim_glob_hi);
+	writel(TIMER_GLB_TIM_CTRL_TIM_EN, &timer_ptr->gtim_glob_ctrl);
+}



More information about the coreboot-gerrit mailing list