public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit@wsystem.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/4] mx25: Add function to set PER clocks
Date: Wed,  3 May 2017 11:59:05 +0200	[thread overview]
Message-ID: <1493805546-3567-3-git-send-email-benoit@wsystem.com> (raw)
In-Reply-To: <1493805546-3567-1-git-send-email-benoit@wsystem.com>

Introduce the imx_set_perclk() function to make it possible to set the
PER clocks.

Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
---
 arch/arm/cpu/arm926ejs/mx25/generic.c  | 19 +++++++++++++++++++
 arch/arm/include/asm/arch-mx25/clock.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/arch/arm/cpu/arm926ejs/mx25/generic.c b/arch/arm/cpu/arm926ejs/mx25/generic.c
index f02cffb..5d9bc6c 100644
--- a/arch/arm/cpu/arm926ejs/mx25/generic.c
+++ b/arch/arm/cpu/arm926ejs/mx25/generic.c
@@ -113,6 +113,25 @@ static ulong imx_get_perclk(int clk)
 	return fref / div;
 }
 
+int imx_set_perclk(enum mxc_clock clk, bool from_upll, unsigned int freq)
+{
+	struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
+	ulong fref = from_upll ? imx_get_upllclk() : imx_get_ahbclk();
+	ulong div = (fref + freq - 1) / freq;
+
+	if (clk > MXC_UART_CLK || !div || --div > CCM_PERCLK_MASK)
+		return -EINVAL;
+
+	clrsetbits_le32(&ccm->pcdr[CCM_PERCLK_REG(clk)],
+			CCM_PERCLK_MASK << CCM_PERCLK_SHIFT(clk),
+			div << CCM_PERCLK_SHIFT(clk));
+	if (from_upll)
+		setbits_le32(&ccm->mcr, 1 << clk);
+	else
+		clrbits_le32(&ccm->mcr, 1 << clk);
+	return 0;
+}
+
 unsigned int mxc_get_clock(enum mxc_clock clk)
 {
 	if (clk >= MXC_CLK_NUM)
diff --git a/arch/arm/include/asm/arch-mx25/clock.h b/arch/arm/include/asm/arch-mx25/clock.h
index 9fdaa9d..7753caf 100644
--- a/arch/arm/include/asm/arch-mx25/clock.h
+++ b/arch/arm/include/asm/arch-mx25/clock.h
@@ -51,6 +51,7 @@ enum mxc_clock {
 	MXC_CLK_NUM
 };
 
+int imx_set_perclk(enum mxc_clock clk, bool from_upll, unsigned int freq);
 unsigned int mxc_get_clock(enum mxc_clock clk);
 
 #define imx_get_uartclk()	mxc_get_clock(MXC_UART_CLK)
-- 
2.7.4

  parent reply	other threads:[~2017-05-03  9:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03  9:59 [U-Boot] [PATCH 1/4] mmc: fsl_esdhc: Allow all supported prescaler values Benoît Thébaudeau
2017-05-03  9:59 ` [U-Boot] [PATCH 2/4] mx25: Fix imx_get_perclk() Benoît Thébaudeau
2017-05-29 11:18   ` Fabio Estevam
2017-05-31  8:50   ` Stefano Babic
2017-05-03  9:59 ` Benoît Thébaudeau [this message]
2017-05-29 11:19   ` [U-Boot] [PATCH 3/4] mx25: Add function to set PER clocks Fabio Estevam
2017-05-31  8:50   ` Stefano Babic
2017-05-03  9:59 ` [U-Boot] [PATCH 4/4] mx25pdk: Set the eSDHC PER clock to 48 MHz Benoît Thébaudeau
2017-05-29 11:20   ` Fabio Estevam
2017-05-31  8:50   ` Stefano Babic
2017-05-29 11:17 ` [U-Boot] [PATCH 1/4] mmc: fsl_esdhc: Allow all supported prescaler values Fabio Estevam
2017-05-31  8:50 ` Stefano Babic

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=1493805546-3567-3-git-send-email-benoit@wsystem.com \
    --to=benoit@wsystem.com \
    --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