From: s.hauer@pengutronix.de (Sascha Hauer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] ARM: imx6q: add pll round_rate support
Date: Wed, 14 Mar 2012 09:52:28 +0100 [thread overview]
Message-ID: <20120314085228.GM3852@pengutronix.de> (raw)
In-Reply-To: <1331713379-8437-2-git-send-email-richard.zhao@linaro.org>
On Wed, Mar 14, 2012 at 04:22:58PM +0800, Richard Zhao wrote:
> Signed-off-by: Richard Zhao <richard.zhao@linaro.org>
> ---
> arch/arm/mach-imx/clock-imx6q.c | 85 +++++++++++++++++++++++++++++++++-----
> 1 files changed, 73 insertions(+), 12 deletions(-)
>
> diff --git a/arch/arm/mach-imx/clock-imx6q.c b/arch/arm/mach-imx/clock-imx6q.c
> index e4e4f5e..3d5dc56 100644
> --- a/arch/arm/mach-imx/clock-imx6q.c
> +++ b/arch/arm/mach-imx/clock-imx6q.c
> @@ -519,6 +519,18 @@ static int pll1_sys_set_rate(struct clk *clk, unsigned long rate)
> return 0;
> }
>
> +static unsigned long pll1_sys_round_rate(struct clk *clk, unsigned long rate)
> +{
> + u32 div;
> + unsigned long parent_rate = clk_get_rate(clk->parent);
> +
> + rate = rate < FREQ_650M ? FREQ_650M : rate;
> + rate = rate > FREQ_1300M ? FREQ_1300M : rate;
> +
> + div = rate * 2 / parent_rate;
> + return parent_rate * div / 2;
> +}
> +
> static unsigned long pll8_enet_get_rate(struct clk *clk)
> {
> u32 div = (readl_relaxed(PLL8_ENET) & BM_PLL_ENET_DIV_SELECT) >>
> @@ -567,6 +579,20 @@ static int pll8_enet_set_rate(struct clk *clk, unsigned long rate)
> return 0;
> }
>
> +static unsigned long pll8_enet_round_rate(struct clk *clk, unsigned long rate)
> +{
> + if (rate >= 125000000)
> + rate = 125000000;
> + else if (rate >= 100000000)
> + rate = 100000000;
> + else if (rate >= 50000000)
> + rate = 50000000;
> + else
> + rate = 25000000;
> + return rate;
> +}
> +
> +
> static unsigned long pll_av_get_rate(struct clk *clk)
> {
> void __iomem *reg = (clk == &pll4_audio) ? PLL4_AUDIO : PLL5_VIDEO;
> @@ -606,6 +632,25 @@ static int pll_av_set_rate(struct clk *clk, unsigned long rate)
> return 0;
> }
>
> +static unsigned long pll_av_round_rate(struct clk *clk, unsigned long rate)
> +{
> + unsigned long parent_rate = clk_get_rate(clk->parent);
> + u32 div;
> + u32 mfn, mfd = 1000000;
> + s64 temp64;
> +
> + rate = rate < FREQ_650M ? FREQ_650M : rate;
> + rate = rate > FREQ_1300M ? FREQ_1300M : rate;
> +
> + div = rate / parent_rate;
> + temp64 = (u64) (parent_rate - (div * parent_rate));
> + temp64 *= mfd;
> + do_div(temp64, parent_rate);
> + mfn = temp64;
> +
> + return (parent_rate * div) + ((parent_rate / mfd) * mfn);
> +}
> +
> static void __iomem *pll_get_div_reg_bit(struct clk *clk, u32 *bp, u32 *bm)
> {
> void __iomem *reg;
> @@ -662,18 +707,33 @@ static int pll_set_rate(struct clk *clk, unsigned long rate)
> return 0;
> }
>
> -#define pll2_bus_get_rate pll_get_rate
> -#define pll2_bus_set_rate pll_set_rate
> -#define pll3_usb_otg_get_rate pll_get_rate
> -#define pll3_usb_otg_set_rate pll_set_rate
> -#define pll7_usb_host_get_rate pll_get_rate
> -#define pll7_usb_host_set_rate pll_set_rate
> -#define pll4_audio_get_rate pll_av_get_rate
> -#define pll4_audio_set_rate pll_av_set_rate
> -#define pll5_video_get_rate pll_av_get_rate
> -#define pll5_video_set_rate pll_av_set_rate
> -#define pll6_mlb_get_rate NULL
> -#define pll6_mlb_set_rate NULL
> +static unsigned long pll_round_rate(struct clk *clk, unsigned long rate)
> +{
> + if (rate >= FREQ_528M)
> + rate = FREQ_528M;
> + else
> + rate = FREQ_480M;
> + return rate;
> +}
> +
> +#define pll2_bus_get_rate pll_get_rate
> +#define pll2_bus_set_rate pll_set_rate
> +#define pll2_bus_round_rate pll_round_rate
> +#define pll3_usb_otg_get_rate pll_get_rate
> +#define pll3_usb_otg_set_rate pll_set_rate
> +#define pll3_usb_otg_round_rate pll_round_rate
> +#define pll7_usb_host_get_rate pll_get_rate
> +#define pll7_usb_host_set_rate pll_set_rate
> +#define pll7_usb_host_round_rate pll_round_rate
> +#define pll4_audio_get_rate pll_av_get_rate
> +#define pll4_audio_set_rate pll_av_set_rate
> +#define pll4_audio_round_rate pll_av_round_rate
> +#define pll5_video_get_rate pll_av_get_rate
> +#define pll5_video_set_rate pll_av_set_rate
> +#define pll5_video_round_rate pll_av_round_rate
> +#define pll6_mlb_get_rate NULL
> +#define pll6_mlb_set_rate NULL
> +#define pll6_mlb_round_rate NULL
>
> #define DEF_PLL(name) \
> static struct clk name = { \
> @@ -681,6 +741,7 @@ static int pll_set_rate(struct clk *clk, unsigned long rate)
> .disable = pll_disable, \
> .get_rate = name##_get_rate, \
> .set_rate = name##_set_rate, \
> + .round_rate = name##_round_rate, \
I hope this ## stuff is gone soon with the generic clock framework. It
is so ugly and inefficient.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2012-03-14 8:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-14 8:22 [PATCH 0/2] improve imx6q arm_clk set rate Richard Zhao
2012-03-14 8:22 ` [PATCH 1/2] ARM: imx6q: add pll round_rate support Richard Zhao
2012-03-14 8:52 ` Sascha Hauer [this message]
2012-03-15 14:46 ` Richard Zhao
2012-03-15 15:00 ` Sascha Hauer
2012-03-15 15:07 ` Shawn Guo
2012-03-15 15:15 ` Richard Zhao
2012-03-15 18:50 ` Sascha Hauer
2012-03-16 1:10 ` Richard Zhao
2012-03-17 12:28 ` Sascha Hauer
2012-03-19 1:51 ` Richard Zhao
2012-03-19 2:48 ` Shawn Guo
2012-03-19 8:31 ` Sascha Hauer
2012-03-19 1:54 ` Richard Zhao
2012-03-14 8:22 ` [PATCH 2/2] ARM: imx6q: change pll1 rate when change arm_clk rate Richard Zhao
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=20120314085228.GM3852@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).