Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Detect the AM335x CPU frequency on the beaglebone.



details:   https://anonhg.NetBSD.org/src/rev/1153492a49ba
branches:  trunk
changeset: 783222:1153492a49ba
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Dec 11 19:24:38 2012 +0000

description:
Detect the AM335x CPU frequency on the beaglebone.

diffstat:

 sys/arch/arm/omap/omap2_reg.h           |  16 ++++++++++++++--
 sys/arch/evbarm/beagle/beagle_machdep.c |  33 +++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 4 deletions(-)

diffs (112 lines):

diff -r a538908e4f23 -r 1153492a49ba sys/arch/arm/omap/omap2_reg.h
--- a/sys/arch/arm/omap/omap2_reg.h     Tue Dec 11 19:21:05 2012 +0000
+++ b/sys/arch/arm/omap/omap2_reg.h     Tue Dec 11 19:24:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: omap2_reg.h,v 1.12 2012/12/11 01:54:42 khorben Exp $ */
+/* $NetBSD: omap2_reg.h,v 1.13 2012/12/11 19:24:38 riastradh Exp $ */
 
 /*
  * Copyright (c) 2007 Microsoft
@@ -129,7 +129,7 @@
 #define OMAP2_CM_BASE                  (OMAP4430_L4_CORE_BASE + 0x04000)
 #endif
 #ifdef TI_AM335X
-#define OMAP2_CM_BASE                  TI_AM335X_L4_WAKEUP_BASE
+#define OMAP2_CM_BASE                  (TI_AM335X_L4_WAKEUP_BASE + 0x200000)
 #endif
 #ifdef TI_DM37XX
 #define OMAP2_CM_BASE                  0x48004000
@@ -316,6 +316,18 @@
 #define        OMAP4_CM_CLKSEL_DPLL_MPU_DPLL_DIV       __BITS(6,0)
 
 #define        OMAP4_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_DIV        __BITS(4,0)
+
+#define        TI_AM335X_CM_CLKSEL_DPLL_MPU                    0x2c
+#define          TI_AM335X_CM_CLKSEL_DPLL_MPU_DPLL_BYP_CLKSEL  __BIT(23)
+#define          TI_AM335X_CM_CLKSEL_DPLL_MPU_DPLL_MULT        __BITS(18,8)
+#define          TI_AM335X_CM_CLKSEL_DPLL_MPU_DPLL_DIV         __BITS(6,0)
+
+#define        TI_AM335X_CM_DIV_M2_DPLL_MPU                            0xa8
+#define          TI_AM335X_CM_DIV_M2_DPLL_MPU_ST_DPLL_CLKOUT           __BIT(9)
+#define          TI_AM335X_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_GATE_CTRL    __BIT(8)
+#define          TI_AM335X_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_DIVCHACK     __BIT(5)
+#define          TI_AM335X_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_DIV          __BITS(4,0)
+
 /*
  * Power Management registers base, offsets, and size
  */
diff -r a538908e4f23 -r 1153492a49ba sys/arch/evbarm/beagle/beagle_machdep.c
--- a/sys/arch/evbarm/beagle/beagle_machdep.c   Tue Dec 11 19:21:05 2012 +0000
+++ b/sys/arch/evbarm/beagle/beagle_machdep.c   Tue Dec 11 19:24:38 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: beagle_machdep.c,v 1.23 2012/12/11 01:54:43 khorben Exp $ */
+/*     $NetBSD: beagle_machdep.c,v 1.24 2012/12/11 19:24:38 riastradh Exp $ */
 
 /*
  * Machine dependent functions for kernel setup for TI OSK5912 board.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.23 2012/12/11 01:54:43 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: beagle_machdep.c,v 1.24 2012/12/11 19:24:38 riastradh Exp $");
 
 #include "opt_machdep.h"
 #include "opt_ddb.h"
@@ -173,6 +173,9 @@
 #include <arm/omap/omap_var.h>
 #include <arm/omap/omap_wdtvar.h>
 #include <arm/omap/omap2_prcm.h>
+#ifdef TI_AM335X
+#  include <arm/omap/am335x_prcm.h>
+#endif
 
 #include <evbarm/include/autoconf.h>
 #include <evbarm/beagle/beagle.h>
@@ -213,6 +216,9 @@
 #if defined(OMAP_4430)
 static void omap4_cpu_clk(void);
 #endif
+#if defined(TI_AM335X)
+static void am335x_cpu_clk(void);
+#endif
 
 bs_protos(bs_notimpl);
 
@@ -375,6 +381,9 @@
 #if defined(OMAP_4430)
        omap4_cpu_clk();                // find our CPU speed.
 #endif
+#if defined(TI_AM335X)
+       am335x_cpu_clk();
+#endif
        /* Heads up ... Setup the CPU / MMU / TLB functions. */
        if (set_cpufuncs())
                panic("cpu not recognized!");
@@ -589,6 +598,26 @@
 }
 #endif /* OMAP_4400 */
 
+#if defined(TI_AM335X)
+void
+am335x_cpu_clk(void)
+{
+       const vaddr_t cm_base = OMAP2_CM_BASE - OMAP_L4_CORE_BASE + OMAP_L4_CORE_VBASE;
+       const vaddr_t cm_wkup_base = cm_base + AM335X_PRCM_CM_WKUP;
+       const uint32_t sys_clk = 24000000;
+       const uint32_t clksel_dpll_mpu = *(volatile uint32_t *)(cm_wkup_base + TI_AM335X_CM_CLKSEL_DPLL_MPU);
+       const uint32_t div_m2_dpll_mpu = *(volatile uint32_t *)(cm_wkup_base + TI_AM335X_CM_DIV_M2_DPLL_MPU);
+       const uint32_t m = __SHIFTOUT(clksel_dpll_mpu, TI_AM335X_CM_CLKSEL_DPLL_MPU_DPLL_MULT);
+       const uint32_t n = __SHIFTOUT(clksel_dpll_mpu, TI_AM335X_CM_CLKSEL_DPLL_MPU_DPLL_DIV);
+       const uint32_t m2 = __SHIFTOUT(div_m2_dpll_mpu, TI_AM335X_CM_DIV_M2_DPLL_MPU_DPLL_CLKOUT_DIV);
+       /* XXX This ignores CM_CLKSEL_DPLL_MPU[DPLL_REGM4XEN].  */
+       curcpu()->ci_data.cpu_cc_freq = ((m * (sys_clk / (n + 1))) / m2);
+       printf("%s: %"PRIu64": sys_clk=%u m=%u n=%u (%u) m2=%u\n",
+           __func__, curcpu()->ci_data.cpu_cc_freq,
+           sys_clk, m, n, n+1, m2);
+}
+#endif
+
 void
 beagle_device_register(device_t self, void *aux)
 {



Home | Main Index | Thread Index | Old Index