From 3110b17134ee2ca1c42f37ff43b2988a45a0b42b Mon Sep 17 00:00:00 2001 From: matt Date: Sat, 29 Jun 2013 20:43:33 +0000 Subject: [PATCH] Move am335x_sys_clk() and am335x_cpu_clk() here. --- sys/arch/arm/omap/am335x_prcm.c | 34 +++++++++++++++++++++++++++++++-- sys/arch/arm/omap/am335x_prcm.h | 6 +++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/sys/arch/arm/omap/am335x_prcm.c b/sys/arch/arm/omap/am335x_prcm.c index 43e435c588c4..75c95e9f961b 100644 --- a/sys/arch/arm/omap/am335x_prcm.c +++ b/sys/arch/arm/omap/am335x_prcm.c @@ -1,4 +1,4 @@ -/* $NetBSD: am335x_prcm.c,v 1.3 2013/06/29 20:21:41 matt Exp $ */ +/* $NetBSD: am335x_prcm.c,v 1.4 2013/06/29 20:43:33 matt Exp $ */ /* * TI OMAP Power, Reset, and Clock Management on the AM335x @@ -34,14 +34,16 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: am335x_prcm.c,v 1.3 2013/06/29 20:21:41 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: am335x_prcm.c,v 1.4 2013/06/29 20:43:33 matt Exp $"); #include #include #include #include +#include #include +#include #define AM335X_CLKCTRL_MODULEMODE_MASK __BITS(0, 1) #define AM335X_CLKCTRL_MODULEMODE_DISABLED 0 @@ -216,3 +218,31 @@ SYSCTL_SETUP(sysctl_am335x_machdep_setup, "sysctl am335x machdep subtree setup") mpu_current_frequency_sysctl_helper, 0, NULL, 0 CTL_CREATE, CTL_EOL); } + +void +am335x_sys_clk(bus_space_handle_t ctlmode_ioh) +{ + static const uint32_t sys_clks[4] = { + [0] = 19200000, [1] = 24000000, [2] = 25000000, [3] = 26000000 + }; + + const uint32_t control_status = bus_space_read_4(&omap_bs_tag, + ctlmode_ioh, CTLMOD_CONTROL_STATUS); + omap_sys_clk = sys_clks[__SHIFTOUT(control_status, CTLMOD_CONTROL_STATUS_SYSBOOT1)]; +} + +void +am335x_cpu_clk(void) +{ + const bus_size_t cm_wkup = AM335X_PRCM_CM_WKUP; + const uint32_t clksel = prcm_read_4(cm_wkup, AM335X_PRCM_CM_CLKSEL_DPLL_MPU); + const uint32_t div_m2 = prcm_read_4(cm_wkup, AM335X_PRCM_CM_DIV_M2_DPLL_MPU); + const uint32_t m = __SHIFTOUT(clksel, AM335X_PRCM_CM_CLKSEL_DPLL_MULT); + const uint32_t n = __SHIFTOUT(clksel, AM335X_PRCM_CM_CLKSEL_DPLL_DIV); + const uint32_t m2 = __SHIFTOUT(div_m2, AM335X_PRCM_CM_DIV_M2_DPLL_CLKOUT_DIV); + /* XXX This ignores CM_CLKSEL_DPLL_MPU[DPLL_REGM4XEN]. */ + curcpu()->ci_data.cpu_cc_freq = (m * ((uint64_t)omap_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, + omap_sys_clk, m, n, n+1, m2); +} diff --git a/sys/arch/arm/omap/am335x_prcm.h b/sys/arch/arm/omap/am335x_prcm.h index 590dd226847d..c7cd876ea936 100644 --- a/sys/arch/arm/omap/am335x_prcm.h +++ b/sys/arch/arm/omap/am335x_prcm.h @@ -1,4 +1,4 @@ -/* $NetBSD: am335x_prcm.h,v 1.4 2013/06/29 20:21:41 matt Exp $ */ +/* $NetBSD: am335x_prcm.h,v 1.5 2013/06/29 20:43:33 matt Exp $ */ /* * TI OMAP Power, Reset, and Clock Management on the AM335x @@ -83,6 +83,10 @@ struct omap_module { #define RST_GLOBAL_WARM_SW __BIT(0) #define RST_GLOBAL_COLD_SW __BIT(1) +#ifdef _KERNEL void prcm_mpu_pll_config(u_int); +void am335x_sys_clk(bus_space_handle_t); +void am335x_cpu_clk(void); +#endif #endif /* _ARM_OMAP_AM335X_PRCM_H_ */