Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch derive cpu freq from cbus regs
details: https://anonhg.NetBSD.org/src/rev/c8b0ef3f7f0a
branches: trunk
changeset: 336385:c8b0ef3f7f0a
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Feb 27 19:57:10 2015 +0000
description:
derive cpu freq from cbus regs
diffstat:
sys/arch/arm/amlogic/amlogic_board.c | 88 ++++++++++++++++++++++++++++++-
sys/arch/arm/amlogic/amlogic_crureg.h | 50 +++++++++++++++++
sys/arch/arm/amlogic/amlogic_reg.h | 3 +-
sys/arch/evbarm/amlogic/amlogic_machdep.c | 10 +--
4 files changed, 140 insertions(+), 11 deletions(-)
diffs (223 lines):
diff -r f52fb015f95a -r c8b0ef3f7f0a sys/arch/arm/amlogic/amlogic_board.c
--- a/sys/arch/arm/amlogic/amlogic_board.c Fri Feb 27 19:56:07 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_board.c Fri Feb 27 19:57:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_board.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */
+/* $NetBSD: amlogic_board.c,v 1.2 2015/02/27 19:57:10 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
#include "opt_amlogic.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.1 2015/02/07 17:20:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_board.c,v 1.2 2015/02/27 19:57:10 jmcneill Exp $");
#define _ARM32_BUS_DMA_PRIVATE
#include <sys/param.h>
@@ -43,6 +43,7 @@
#include <arm/cpufunc.h>
#include <arm/amlogic/amlogic_reg.h>
+#include <arm/amlogic/amlogic_crureg.h>
#include <arm/amlogic/amlogic_var.h>
bus_space_handle_t amlogic_core_bsh;
@@ -53,6 +54,14 @@
_BUS_DMATAG_FUNCS,
};
+#define CBUS_READ(x) \
+ bus_space_read_4(&amlogic_bs_tag, amlogic_core_bsh, (x))
+
+static uint32_t amlogic_get_rate_xtal(void);
+static uint32_t amlogic_get_rate_sys(void);
+static uint32_t amlogic_get_rate_a9(void);
+
+
void
amlogic_bootstrap(void)
{
@@ -62,4 +71,79 @@
AMLOGIC_CORE_SIZE, 0, &amlogic_core_bsh);
if (error)
panic("%s: failed to map CORE registers: %d", __func__, error);
+
+ curcpu()->ci_data.cpu_cc_freq = amlogic_get_rate_a9();
}
+
+static uint32_t
+amlogic_get_rate_xtal(void)
+{
+ uint32_t ctlreg0;
+
+ ctlreg0 = CBUS_READ(PREG_CTLREG0_ADDR_REG);
+
+ return __SHIFTOUT(ctlreg0, PREG_CTLREG0_ADDR_CLKRATE) * 1000000;
+}
+
+static uint32_t
+amlogic_get_rate_sys(void)
+{
+ uint32_t cntl;
+ uint64_t clk;
+ u_int mul, div, od;
+
+ clk = amlogic_get_rate_xtal();
+ cntl = CBUS_READ(HHI_SYS_PLL_CNTL_REG);
+ mul = __SHIFTOUT(cntl, HHI_SYS_PLL_CNTL_MUL);
+ div = __SHIFTOUT(cntl, HHI_SYS_PLL_CNTL_DIV);
+ od = __SHIFTOUT(cntl, HHI_SYS_PLL_CNTL_OD);
+
+ clk *= mul;
+ clk /= div;
+ clk >>= od;
+
+ return (uint32_t)clk;
+}
+
+static uint32_t
+amlogic_get_rate_a9(void)
+{
+ uint32_t cntl0, cntl1;
+ uint32_t rate = 0;
+
+ cntl0 = CBUS_READ(HHI_SYS_CPU_CLK_CNTL0_REG);
+ if (cntl0 & HHI_SYS_CPU_CLK_CNTL0_CLKSEL) {
+ switch (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_PLLSEL)) {
+ case 0:
+ rate = amlogic_get_rate_xtal();
+ break;
+ case 1:
+ rate = amlogic_get_rate_sys();
+ break;
+ case 2:
+ rate = 1250000000;
+ break;
+ }
+ } else {
+ rate = amlogic_get_rate_xtal();
+ }
+
+ KASSERTMSG(rate != 0, "couldn't determine A9 rate");
+
+ switch (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_SOUTSEL)) {
+ case 0:
+ break;
+ case 1:
+ rate /= 2;
+ break;
+ case 2:
+ rate /= 3;
+ break;
+ case 3:
+ cntl1 = CBUS_READ(HHI_SYS_CPU_CLK_CNTL1_REG);
+ rate /= (__SHIFTOUT(cntl1, HHI_SYS_CPU_CLK_CNTL1_SDIV) + 1);
+ break;
+ }
+
+ return rate;
+}
diff -r f52fb015f95a -r c8b0ef3f7f0a sys/arch/arm/amlogic/amlogic_crureg.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_crureg.h Fri Feb 27 19:57:10 2015 +0000
@@ -0,0 +1,50 @@
+/* $NetBSD: amlogic_crureg.h,v 1.1 2015/02/27 19:57:10 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+#ifndef _ARM_AMLOGIC_CRUREG_H
+#define _ARM_AMLOGIC_CRUREG_H
+
+#define CBUS_REG(n) ((n) << 2)
+
+#define HHI_SYS_CPU_CLK_CNTL1_REG CBUS_REG(0x1057)
+#define HHI_SYS_CPU_CLK_CNTL1_SDIV __BITS(29,20)
+
+#define HHI_SYS_CPU_CLK_CNTL0_REG CBUS_REG(0x1067)
+#define HHI_SYS_CPU_CLK_CNTL0_CLKSEL __BIT(7)
+#define HHI_SYS_CPU_CLK_CNTL0_SOUTSEL __BITS(3,2)
+#define HHI_SYS_CPU_CLK_CNTL0_PLLSEL __BITS(1,0)
+
+#define HHI_SYS_PLL_CNTL_REG CBUS_REG(0x10c0)
+#define HHI_SYS_PLL_CNTL_MUL __BITS(8,0)
+#define HHI_SYS_PLL_CNTL_DIV __BITS(14,9)
+#define HHI_SYS_PLL_CNTL_OD __BITS(17,16)
+
+#define PREG_CTLREG0_ADDR_REG CBUS_REG(0x2000)
+#define PREG_CTLREG0_ADDR_CLKRATE __BITS(9,4)
+
+#endif /* _ARM_AMLOGIC_CRUREG_H */
diff -r f52fb015f95a -r c8b0ef3f7f0a sys/arch/arm/amlogic/amlogic_reg.h
--- a/sys/arch/arm/amlogic/amlogic_reg.h Fri Feb 27 19:56:07 2015 +0000
+++ b/sys/arch/arm/amlogic/amlogic_reg.h Fri Feb 27 19:57:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_reg.h,v 1.1 2015/02/07 17:20:17 jmcneill Exp $ */
+/* $NetBSD: amlogic_reg.h,v 1.2 2015/02/27 19:57:10 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -35,6 +35,7 @@
#define AMLOGIC_CORE_SIZE 0x10200000
#define AMLOGIC_CORE_VBASE 0xe0000000
+#define AMLOGIC_CBUS_OFFSET 0x01100000
#define AMLOGIC_UART0_OFFSET 0x01102130
#define AMLOGIC_UART1_OFFSET 0x01102137
#define AMLOGIC_UART2_OFFSET 0x011021c0
diff -r f52fb015f95a -r c8b0ef3f7f0a sys/arch/evbarm/amlogic/amlogic_machdep.c
--- a/sys/arch/evbarm/amlogic/amlogic_machdep.c Fri Feb 27 19:56:07 2015 +0000
+++ b/sys/arch/evbarm/amlogic/amlogic_machdep.c Fri Feb 27 19:57:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amlogic_machdep.c,v 1.3 2015/02/27 18:00:29 jmcneill Exp $ */
+/* $NetBSD: amlogic_machdep.c,v 1.4 2015/02/27 19:57:10 jmcneill Exp $ */
/*
* Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,7 +125,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.3 2015/02/27 18:00:29 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amlogic_machdep.c,v 1.4 2015/02/27 19:57:10 jmcneill Exp $");
#include "opt_machdep.h"
#include "opt_ddb.h"
@@ -435,12 +435,6 @@
db_trap_callback = amlogic_db_trap;
-#if notyet
- curcpu()->ci_data.cpu_cc_freq = amlogic_cpu_get_rate();
-#else
- curcpu()->ci_data.cpu_cc_freq = 1000000;
-#endif
-
return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
}
Home |
Main Index |
Thread Index |
Old Index