From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 06/12] arm, am335x: Enable Spread Spectrum for the MPU
Date: Tue, 7 Jun 2016 08:31:19 +0200 [thread overview]
Message-ID: <1465281085-10481-7-git-send-email-hs@denx.de> (raw)
In-Reply-To: <1465281085-10481-1-git-send-email-hs@denx.de>
Enable Spread Spectrum for the MPU by calculating the required
values and setting the registers accordingly.
Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
---
Changes in v3: None
Changes in v2:
- add Reviewed-by from Tom Rini
arch/arm/cpu/armv7/am33xx/clock_am33xx.c | 73 ++++++++++++++++++++++++++++++++
arch/arm/include/asm/arch-am33xx/clock.h | 1 +
arch/arm/include/asm/arch-am33xx/cpu.h | 3 +-
3 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/arch/arm/cpu/armv7/am33xx/clock_am33xx.c b/arch/arm/cpu/armv7/am33xx/clock_am33xx.c
index 92142c8..7b841b2 100644
--- a/arch/arm/cpu/armv7/am33xx/clock_am33xx.c
+++ b/arch/arm/cpu/armv7/am33xx/clock_am33xx.c
@@ -159,3 +159,76 @@ void enable_basic_clocks(void)
/* Select the Master osc 24 MHZ as Timer2 clock source */
writel(0x1, &cmdpll->clktimer2clk);
}
+
+/*
+ * Enable Spread Spectrum for the MPU by calculating the required
+ * values and setting the registers accordingly.
+ * @param permille The spreading in permille (10th of a percent)
+ */
+void set_mpu_spreadspectrum(int permille)
+{
+ u32 multiplier_m;
+ u32 predivider_n;
+ u32 cm_clksel_dpll_mpu;
+ u32 cm_clkmode_dpll_mpu;
+ u32 ref_clock;
+ u32 pll_bandwidth;
+ u32 mod_freq_divider;
+ u32 exponent;
+ u32 mantissa;
+ u32 delta_m_step;
+
+ printf("Enabling Spread Spectrum of %d permille for MPU\n",
+ permille);
+
+ /* Read PLL parameter m and n */
+ cm_clksel_dpll_mpu = readl(&cmwkup->clkseldpllmpu);
+ multiplier_m = (cm_clksel_dpll_mpu >> 8) & 0x3FF;
+ predivider_n = cm_clksel_dpll_mpu & 0x7F;
+
+ /*
+ * Calculate reference clock (clock after pre-divider),
+ * its max. PLL bandwidth,
+ * and resulting mod_freq_divider
+ */
+ ref_clock = V_OSCK / (predivider_n + 1);
+ pll_bandwidth = ref_clock / 70;
+ mod_freq_divider = ref_clock / (4 * pll_bandwidth);
+
+ /* Calculate Mantissa/Exponent */
+ exponent = 0;
+ mantissa = mod_freq_divider;
+ while ((mantissa > 127) && (exponent < 7)) {
+ exponent++;
+ mantissa /= 2;
+ }
+ if (mantissa > 127)
+ mantissa = 127;
+
+ mod_freq_divider = mantissa << exponent;
+
+ /*
+ * Calculate Modulation steps
+ * As we use Downspread only, the spread is twice the value of
+ * permille, so Div2!
+ * As it takes the value in percent, divide by ten!
+ */
+ delta_m_step = ((u32)((multiplier_m * permille) / 10 / 2)) << 18;
+ delta_m_step /= 100;
+ delta_m_step /= mod_freq_divider;
+ if (delta_m_step > 0xFFFFF)
+ delta_m_step = 0xFFFFF;
+
+ /* Setup Spread Spectrum */
+ writel(delta_m_step, &cmwkup->sscdeltamstepdllmpu);
+ writel((exponent << 8) | mantissa, &cmwkup->sscmodfreqdivdpllmpu);
+ cm_clkmode_dpll_mpu = readl(&cmwkup->clkmoddpllmpu);
+ /* clear all SSC flags */
+ cm_clkmode_dpll_mpu &= ~(0xF << CM_CLKMODE_DPLL_SSC_EN_SHIFT);
+ /* enable SSC with Downspread only */
+ cm_clkmode_dpll_mpu |= CM_CLKMODE_DPLL_SSC_EN_MASK |
+ CM_CLKMODE_DPLL_SSC_DOWNSPREAD_MASK;
+ writel(cm_clkmode_dpll_mpu, &cmwkup->clkmoddpllmpu);
+ while (!(readl(&cmwkup->clkmoddpllmpu) & 0x2000))
+ ;
+}
diff --git a/arch/arm/include/asm/arch-am33xx/clock.h b/arch/arm/include/asm/arch-am33xx/clock.h
index 7c6be4c..acf3fd5 100644
--- a/arch/arm/include/asm/arch-am33xx/clock.h
+++ b/arch/arm/include/asm/arch-am33xx/clock.h
@@ -117,4 +117,5 @@ void enable_basic_clocks(void);
void do_enable_clocks(u32 *const *, u32 *const *, u8);
void do_disable_clocks(u32 *const *, u32 *const *, u8);
+void set_mpu_spreadspectrum(int permille);
#endif
diff --git a/arch/arm/include/asm/arch-am33xx/cpu.h b/arch/arm/include/asm/arch-am33xx/cpu.h
index e950b96..62bca8c 100644
--- a/arch/arm/include/asm/arch-am33xx/cpu.h
+++ b/arch/arm/include/asm/arch-am33xx/cpu.h
@@ -99,7 +99,8 @@ struct cm_wkuppll {
unsigned int timer0clkctrl; /* offset 0x10 */
unsigned int resv2[3];
unsigned int idlestdpllmpu; /* offset 0x20 */
- unsigned int resv3[2];
+ unsigned int sscdeltamstepdllmpu; /* off 0x24 */
+ unsigned int sscmodfreqdivdpllmpu; /* off 0x28 */
unsigned int clkseldpllmpu; /* offset 0x2c */
unsigned int resv4[1];
unsigned int idlestdpllddr; /* offset 0x34 */
--
2.5.5
next prev parent reply other threads:[~2016-06-07 6:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 6:31 [U-Boot] [PATCH v3 00/12] am335x: add support for the am335x based bosch shc board Heiko Schocher
2016-06-07 6:31 ` [U-Boot] [PATCH v3 01/12] common: bootdelay: move CONFIG_BOOTDELAY into a Kconfig option Heiko Schocher
2016-06-08 2:54 ` Viresh Kumar
2016-06-08 8:52 ` Igor Grinberg
2016-06-09 18:02 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 02/12] tests: py: disable main_signon check for printenv cmd Heiko Schocher
2016-06-09 18:02 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 03/12] power, tps65217: add some defines Heiko Schocher
2016-06-09 18:02 ` [U-Boot] [U-Boot,v3,03/12] " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 04/12] arm, am335x: add some missing GPIO register definitions Heiko Schocher
2016-06-09 18:02 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 05/12] am335x: add some missing CM_CLKMODE_DPLL_SSC macros Heiko Schocher
2016-06-09 18:02 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` Heiko Schocher [this message]
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, 06/12] arm, am335x: Enable Spread Spectrum for the MPU Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 07/12] bootstage: call show_boot_progress also in SPL Heiko Schocher
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 08/12] mmc: revert mmc: Handle switch error status bit in MMC card status Heiko Schocher
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 09/12] mmc: omap_hsmmc: enable 8bit interface for eMMC for AM33xx Heiko Schocher
2016-06-08 8:53 ` Igor Grinberg
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 10/12] armv7: omap-common: make SPL board_mmc_init() weak Heiko Schocher
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 11/12] doc, spl, am335x: update am335x-network Heiko Schocher
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
2016-06-07 6:31 ` [U-Boot] [PATCH v3 12/12] am335x, shc: add support for the am335x based bosch shc board Heiko Schocher
2016-06-09 18:03 ` [U-Boot] [U-Boot, v3, " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465281085-10481-7-git-send-email-hs@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox