public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko@sntech.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/8] rockchip: clk: rk3188: Allow configuration of the armclk
Date: Mon, 20 Mar 2017 12:40:32 +0100	[thread overview]
Message-ID: <20170320114036.21475-5-heiko@sntech.de> (raw)
In-Reply-To: <20170320114036.21475-1-heiko@sntech.de>

The armclk starts in slow mode (24MHz) on the rk3188, which makes the whole
startup take a lot of time. We therefore want to at least move to the safe
600MHz value we can use with default pmic settings.
This is also the freqency the proprietary sdram-init leaves the cpu at.

For boards that have pmic control later in u-boot, we also add the option
to set the maximum frequency of 1.6GHz, if they so desire.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/arm/include/asm/arch-rockchip/cru_rk3188.h |  1 +
 drivers/clk/rockchip/clk_rk3188.c               | 63 +++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/arch/arm/include/asm/arch-rockchip/cru_rk3188.h b/arch/arm/include/asm/arch-rockchip/cru_rk3188.h
index 74f0fedcc6..f5d6420d04 100644
--- a/arch/arm/include/asm/arch-rockchip/cru_rk3188.h
+++ b/arch/arm/include/asm/arch-rockchip/cru_rk3188.h
@@ -9,6 +9,7 @@
 #define OSC_HZ		(24 * 1000 * 1000)
 
 #define APLL_HZ		(1608 * 1000000)
+#define APLL_SAFE_HZ	(600 * 1000000)
 #define GPLL_HZ		(594 * 1000000)
 #define CPLL_HZ		(384 * 1000000)
 
diff --git a/drivers/clk/rockchip/clk_rk3188.c b/drivers/clk/rockchip/clk_rk3188.c
index 459649f724..d36cf8f3f2 100644
--- a/drivers/clk/rockchip/clk_rk3188.c
+++ b/drivers/clk/rockchip/clk_rk3188.c
@@ -168,6 +168,65 @@ static int rkclk_configure_ddr(struct rk3188_cru *cru, struct rk3188_grf *grf,
 	return 0;
 }
 
+static int rkclk_configure_cpu(struct rk3188_cru *cru, struct rk3188_grf *grf,
+			      unsigned int hz, bool has_bwadj)
+{
+	static const struct pll_div apll_cfg[] = {
+		{.nf = 50, .nr = 1, .no = 2},
+		{.nf = 67, .nr = 1, .no = 1},
+	};
+	int div_core_peri, div_aclk_core, cfg;
+
+	/*
+	 * We support two possible frequencies, the safe 600MHz
+	 * which will work with default pmic settings and will
+	 * be set in SPL to get away from the 24MHz default and
+	 * the maximum of 1.6Ghz, which boards can set if they
+	 * were able to get pmic support for it.
+	 */
+	switch (hz) {
+	case APLL_SAFE_HZ:
+		cfg = 0;
+		div_core_peri = 1;
+		div_aclk_core = 3;
+		break;
+	case APLL_HZ:
+		cfg = 1;
+		div_core_peri = 2;
+		div_aclk_core = 3;
+		break;
+	default:
+		debug("Unsupported ARMCLK frequency");
+		return -EINVAL;
+	}
+
+	/* pll enter slow-mode */
+	rk_clrsetreg(&cru->cru_mode_con, APLL_MODE_MASK << APLL_MODE_SHIFT,
+		     APLL_MODE_SLOW << APLL_MODE_SHIFT);
+
+	rkclk_set_pll(cru, CLK_ARM, &apll_cfg[cfg], has_bwadj);
+
+	/* waiting for pll lock */
+	while (!(readl(&grf->soc_status0) & SOCSTS_APLL_LOCK))
+		udelay(1);
+
+	/* Set divider for peripherals attached to the cpu core. */
+	rk_clrsetreg(&cru->cru_clksel_con[0],
+		CORE_PERI_DIV_MASK << CORE_PERI_DIV_SHIFT,
+		div_core_peri << CORE_PERI_DIV_SHIFT);
+
+	/* set up dependent divisor for aclk_core */
+	rk_clrsetreg(&cru->cru_clksel_con[1],
+		CORE_ACLK_DIV_MASK << CORE_ACLK_DIV_SHIFT,
+		div_aclk_core << CORE_ACLK_DIV_SHIFT);
+
+	/* PLL enter normal-mode */
+	rk_clrsetreg(&cru->cru_mode_con, APLL_MODE_MASK << APLL_MODE_SHIFT,
+		     APLL_MODE_NORMAL << APLL_MODE_SHIFT);
+
+	return hz;
+}
+
 /* Get pll rate by id */
 static uint32_t rkclk_pll_get_rate(struct rk3188_cru *cru,
 				   enum rk_clk_id clk_id)
@@ -435,6 +494,10 @@ static ulong rk3188_clk_set_rate(struct clk *clk, ulong rate)
 	ulong new_rate;
 
 	switch (clk->id) {
+	case PLL_APLL:
+		new_rate = rkclk_configure_cpu(priv->cru, priv->grf, rate,
+					       priv->has_bwadj);
+		break;
 	case CLK_DDR:
 		new_rate = rkclk_configure_ddr(priv->cru, priv->grf, rate,
 					       priv->has_bwadj);
-- 
2.11.0

  parent reply	other threads:[~2017-03-20 11:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20 11:40 [U-Boot] [PATCH 0/8] rockchip: rk3188: fixups and armclk speedup Heiko Stuebner
2017-03-20 11:40 ` [U-Boot] [PATCH 1/8] rockchip: rk3188: sdram: Set correct sdram base Heiko Stuebner
2017-03-24  3:27   ` Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 2/8] rockchip: rk3188: Decode the actual amount of ram Heiko Stuebner
2017-03-24  3:27   ` Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 3/8] rockchip: rk3188: Cleanup some SPL/TPL rename leftovers Heiko Stuebner
2017-03-24  3:27   ` Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` Heiko Stuebner [this message]
2017-03-24  3:27   ` [U-Boot] [PATCH 4/8] rockchip: clk: rk3188: Allow configuration of the armclk Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 5/8] rockchip: rk3188: Setup the armclk in spl Heiko Stuebner
2017-03-24  3:28   ` Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 6/8] rockchip: rk3188: Switch to new i2c IP blocks Heiko Stuebner
2017-03-24  3:28   ` Simon Glass
2017-03-24  7:32     ` Heiko Stübner
2017-03-26  1:17       ` Simon Glass
2017-03-26 13:01         ` Heiko Stuebner
2017-04-01  4:22           ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 7/8] rockchip: i2c: Add compatibles for Rockchip Cortex-A9 socs Heiko Stuebner
2017-03-24  3:28   ` Simon Glass
2017-03-26  2:42     ` Simon Glass
2017-03-20 11:40 ` [U-Boot] [PATCH 8/8] rockchip: Enable pmic options and act8846 driver on rk3188 rock boards Heiko Stuebner
2017-03-24  3:28   ` Simon Glass
2017-03-26 19:13     ` Heiko Stuebner
2017-03-24  3:28 ` [U-Boot] [PATCH 0/8] rockchip: rk3188: fixups and armclk speedup Simon Glass
2017-03-24 16:04   ` Heiko Stuebner
2017-03-27 18:36     ` Simon Glass
2017-03-27 20:11       ` Heiko Stuebner

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=20170320114036.21475-5-heiko@sntech.de \
    --to=heiko@sntech.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