From: Thierry Reding <thierry.reding-RM9K5IK7kjKj5M59NBduVrNAH6kLmebB@public.gmane.org>
To: Lucas Stach <dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
Mark Zhang <nvmarkzhang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH] ARM: tegra: dynamically calculate pll_d parameters
Date: Tue, 18 Dec 2012 07:58:57 +0100 [thread overview]
Message-ID: <20121218065857.GA5151@avionic-0098.adnet.avionic-design.de> (raw)
In-Reply-To: <1355767103-5303-1-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]
On Mon, Dec 17, 2012 at 06:58:23PM +0100, Lucas Stach wrote:
[...]
> +static int tegra20_plld_clk_set_rate(struct clk_hw *hw, unsigned long rate,
> + unsigned long parent_rate)
> +{
> + struct clk_tegra *c = to_clk_tegra(hw);
> + unsigned long input_rate = parent_rate;
> + u64 n = 0;
> + int m_max, m_min, m = 0;
> + u32 val, rem = 0;
> + u8 cpcon = 0;
> +
> + m_max = input_rate / c->u.pll.cf_min;
> + m_min = (input_rate / c->u.pll.cf_max) + 1;
> +
> + for (m = m_min; m <= m_max; m++) {
> + n = (u64)rate * m;
> + rem = do_div(n, input_rate);
> + if (!rem)
> + break;
> + }
> +
> + if (rem)
> + return -EINVAL;
This code is common to both .round_rate() and .set_rate() so maybe you
should factor it out.
> +
> + c->mul = n;
> + c->div = n;
> +
> + val = clk_readl(c->reg + PLL_BASE);
> + val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
> + PLL_BASE_DIVM_MASK);
> + val |= (m << PLL_BASE_DIVM_SHIFT) | (n << PLL_BASE_DIVN_SHIFT);
> + clk_writel(val, c->reg + PLL_BASE);
> +
> + if (n <= 50)
> + cpcon = 2;
> + else if (n <= 300)
> + cpcon = 4;
> + else if (n <= 600)
> + cpcon = 8;
> + else if (n <= 1000)
> + cpcon = 12;
> +
> + val = clk_readl(c->reg + PLL_MISC(c));
> + val &= ~PLL_MISC_CPCON_MASK;
> + val |= cpcon << PLL_MISC_CPCON_SHIFT;
> + clk_writel(val, c->reg + PLL_MISC(c));
> +
> +
There's a gratuitous blank line here.
Other than that this algorithm looks pretty much like what I came up
with in an earlier prototype. One difference is that I used an
additional outer loop for the p-divider. Taking that into account should
allow even more frequencies to be matched.
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-12-18 6:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-17 17:58 [PATCH] ARM: tegra: dynamically calculate pll_d parameters Lucas Stach
[not found] ` <1355767103-5303-1-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org>
2012-12-17 22:01 ` Stephen Warren
[not found] ` <50CF963E.7020506-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-12-17 22:16 ` Lucas Stach
2012-12-18 5:45 ` Prashant Gaikwad
2012-12-18 6:58 ` Thierry Reding [this message]
[not found] ` <20121218065857.GA5151-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org>
2012-12-18 8:40 ` Lucas Stach
2012-12-18 8:36 ` Mark Zhang
[not found] ` <50D02B0F.4020307-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-12-18 9:19 ` Lucas Stach
2012-12-18 16:40 ` Stephen Warren
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=20121218065857.GA5151@avionic-0098.adnet.avionic-design.de \
--to=thierry.reding-rm9k5ik7kjkj5m59nbduvrnah6klmebb@public.gmane.org \
--cc=dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=nvmarkzhang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.