mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 08/14] ARM: i.MX: implement pllv2 set/round_rate support
Date: Wed,  7 May 2014 10:04:38 +0200	[thread overview]
Message-ID: <1399449884-19089-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1399449884-19089-1-git-send-email-s.hauer@pengutronix.de>

Code straight from the kernel.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/clk-pllv2.c | 66 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/arch/arm/mach-imx/clk-pllv2.c b/arch/arm/mach-imx/clk-pllv2.c
index 7e087c1..a2b016f 100644
--- a/arch/arm/mach-imx/clk-pllv2.c
+++ b/arch/arm/mach-imx/clk-pllv2.c
@@ -136,8 +136,74 @@ static unsigned long clk_pllv2_recalc_rate(struct clk *clk,
 	return __clk_pllv2_recalc_rate(parent_rate, dp_ctl, dp_op, dp_mfd, dp_mfn);
 }
 
+static int __clk_pllv2_set_rate(unsigned long rate, unsigned long parent_rate,
+		u32 *dp_op, u32 *dp_mfd, u32 *dp_mfn)
+{
+	u32 reg;
+	long mfi, pdf, mfn, mfd = 999999;
+	u64 temp64;
+	unsigned long quad_parent_rate;
+
+	quad_parent_rate = 4 * parent_rate;
+	pdf = mfi = -1;
+	while (++pdf < 16 && mfi < 5)
+		mfi = rate * (pdf+1) / quad_parent_rate;
+	if (mfi > 15)
+		return -EINVAL;
+	pdf--;
+
+	temp64 = rate * (pdf + 1) - quad_parent_rate * mfi;
+	do_div(temp64, quad_parent_rate / 1000000);
+	mfn = (long)temp64;
+
+	reg = mfi << 4 | pdf;
+
+	*dp_op = reg;
+	*dp_mfd = mfd;
+	*dp_mfn = mfn;
+
+	return 0;
+}
+
+static int clk_pllv2_set_rate(struct clk *clk, unsigned long rate,
+		unsigned long parent_rate)
+{
+	struct clk_pllv2 *pll = container_of(clk, struct clk_pllv2, clk);
+	void __iomem *pllbase;
+	u32 dp_ctl, dp_op, dp_mfd, dp_mfn;
+	int ret;
+
+	pllbase = pll->reg;
+
+	ret = __clk_pllv2_set_rate(rate, parent_rate, &dp_op, &dp_mfd, &dp_mfn);
+	if (ret)
+		return ret;
+
+	dp_ctl = __raw_readl(pllbase + MXC_PLL_DP_CTL);
+	/* use dpdck0_2 */
+	__raw_writel(dp_ctl | 0x1000L, pllbase + MXC_PLL_DP_CTL);
+
+	__raw_writel(dp_op, pllbase + MXC_PLL_DP_OP);
+	__raw_writel(dp_mfd, pllbase + MXC_PLL_DP_MFD);
+	__raw_writel(dp_mfn, pllbase + MXC_PLL_DP_MFN);
+
+	return 0;
+}
+
+static long clk_pllv2_round_rate(struct clk *clk, unsigned long rate,
+		unsigned long *prate)
+{
+	u32 dp_op, dp_mfd, dp_mfn;
+
+	__clk_pllv2_set_rate(rate, *prate, &dp_op, &dp_mfd, &dp_mfn);
+	return __clk_pllv2_recalc_rate(*prate, MXC_PLL_DP_CTL_DPDCK0_2_EN,
+			dp_op, dp_mfd, dp_mfn);
+}
+
 struct clk_ops clk_pllv2_ops = {
 	.recalc_rate = clk_pllv2_recalc_rate,
+	.round_rate = clk_pllv2_round_rate,
+	.set_rate = clk_pllv2_set_rate,
 };
 
 struct clk *imx_clk_pllv2(const char *name, const char *parent,
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-05-07  8:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07  8:04 [PATCH 01/14] pinctrl: i.MX iomux-v3: Print more context in error message Sascha Hauer
2014-05-07  8:04 ` [PATCH 02/14] ARM: i.MX: bbu: remove dcd arguments from bbu registration Sascha Hauer
2014-05-07  8:04 ` [PATCH 03/14] ARM: tqma53: Add barebox_update support Sascha Hauer
2014-05-07  8:04 ` [PATCH 04/14] ARM: i.MX53: Use clock number defines from dt-bindings Sascha Hauer
2014-05-07  8:04 ` [PATCH 05/14] ARM: tqma53: Add phy_type property to usb ports Sascha Hauer
2014-05-07  8:04 ` [PATCH 06/14] ARM: i.MX53: Add pwm support Sascha Hauer
2014-05-07  8:04 ` [PATCH 07/14] ARM: i.MX53 tqma53: Set model from devicetree Sascha Hauer
2014-05-07  8:04 ` Sascha Hauer [this message]
2014-05-07  8:04 ` [PATCH 09/14] video: i.MX IPUv3: remove debug leftover Sascha Hauer
2014-05-07  8:04 ` [PATCH 10/14] video: i.MX IPUv3: Print error as string Sascha Hauer
2014-05-07  8:04 ` [PATCH 11/14] video: i.MX IPUv3: Implement i.MX5 IPU reset support Sascha Hauer
2014-05-07  8:04 ` [PATCH 12/14] video: i.MX IPUv3 ldb: implement i.MX53 support Sascha Hauer
2014-05-07  8:04 ` [PATCH 13/14] ARM: i.MX5: Add IPU clocks Sascha Hauer
2014-05-07  8:04 ` [PATCH 14/14] ARM: dts: i.MX53: Add ipu alias Sascha Hauer

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=1399449884-19089-8-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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