From: tomasz.figa@gmail.com (Tomasz Figa)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 3/6] clk: samsung: Add set_rate() clk_ops for PLL35xx
Date: Wed, 12 Jun 2013 23:04:33 +0200 [thread overview]
Message-ID: <18811812.9vb6COn4ou@flatron> (raw)
In-Reply-To: <1370272196-4346-4-git-send-email-yadi.brar@samsung.com>
On Monday 03 of June 2013 20:39:53 Yadwinder Singh Brar wrote:
> This patch add set_rate() and round_rate() for PLL35xx
>
> Reviewed-by: Doug Anderson <dianders@chromium.org>
> Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
> ---
> drivers/clk/samsung/clk-pll.c | 104
> ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 103
> insertions(+), 1 deletions(-)
>
> diff --git a/drivers/clk/samsung/clk-pll.c
> b/drivers/clk/samsung/clk-pll.c index cba73a4..319b52b 100644
> --- a/drivers/clk/samsung/clk-pll.c
> +++ b/drivers/clk/samsung/clk-pll.c
> @@ -27,6 +27,37 @@ struct samsung_clk_pll {
> #define pll_writel(pll, val, offset) \
> __raw_writel(val, (void __iomem *)(pll->base + (offset)));
>
> +static const struct samsung_pll_rate_table *samsung_get_pll_settings(
> + struct samsung_clk_pll *pll, unsigned long
rate)
> +{
> + const struct samsung_pll_rate_table *rate_table = pll-
>rate_table;
> + int i;
> +
> + for (i = 0; i < pll->rate_count; i++) {
> + if (rate == rate_table[i].rate)
> + return &rate_table[i];
> + }
> +
> + return NULL;
> +}
> +
> +static long samsung_pll_round_rate(struct clk_hw *hw,
> + unsigned long drate, unsigned long *prate)
> +{
> + struct samsung_clk_pll *pll = to_clk_pll(hw);
> + const struct samsung_pll_rate_table *rate_table = pll->rate_table;
> + int i;
> +
> + /* Assumming rate_table is in descending order */
> + for (i = 0; i < pll->rate_count; i++) {
> + if (drate >= rate_table[i].rate)
> + return rate_table[i].rate;
> + }
> +
> + /* return minimum supported value */
> + return rate_table[i - 1].rate;
> +}
> +
> /*
> * PLL35xx Clock Type
> */
> @@ -34,12 +65,17 @@ struct samsung_clk_pll {
> #define PLL35XX_CON0_OFFSET (0x100)
> #define PLL35XX_CON1_OFFSET (0x104)
>
> +/* Maximum lock time can be 270 * PDIV cycles */
> +#define PLL35XX_LOCK_FACTOR (270)
> +
> #define PLL35XX_MDIV_MASK (0x3FF)
> #define PLL35XX_PDIV_MASK (0x3F)
> #define PLL35XX_SDIV_MASK (0x7)
> +#define PLL35XX_LOCK_STAT_MASK (0x1)
> #define PLL35XX_MDIV_SHIFT (16)
> #define PLL35XX_PDIV_SHIFT (8)
> #define PLL35XX_SDIV_SHIFT (0)
> +#define PLL35XX_LOCK_STAT_SHIFT (29)
>
> static unsigned long samsung_pll35xx_recalc_rate(struct clk_hw *hw,
> unsigned long parent_rate)
> @@ -59,8 +95,72 @@ static unsigned long
> samsung_pll35xx_recalc_rate(struct clk_hw *hw, return (unsigned
> long)fvco;
> }
>
> +static inline bool samsung_pll35xx_mp_change(
> + const struct samsung_pll_rate_table *rate, u32 pll_con)
> +{
> + u32 old_mdiv, old_pdiv;
> +
> + old_mdiv = (pll_con >> PLL35XX_MDIV_SHIFT) & PLL35XX_MDIV_MASK;
> + old_pdiv = (pll_con >> PLL35XX_PDIV_SHIFT) & PLL35XX_PDIV_MASK;
> +
> + return (rate->mdiv != old_mdiv || rate->pdiv != old_pdiv);
> +}
> +
> +static int samsung_pll35xx_set_rate(struct clk_hw *hw, unsigned long
> drate, + unsigned long prate)
> +{
> + struct samsung_clk_pll *pll = to_clk_pll(hw);
> + const struct samsung_pll_rate_table *rate;
> + u32 tmp;
> +
> + /* Get required rate settings from table */
> + rate = samsung_get_pll_settings(pll, drate);
> + if (!rate) {
> + pr_err("%s: Invalid rate : %lu for pll clk %s\n",
__func__,
> + drate, __clk_get_name(hw->clk));
> + return -EINVAL;
> + }
> +
> + tmp = pll_readl(pll, PLL35XX_CON0_OFFSET);
> +
> + if (!(samsung_pll35xx_mp_change(rate, tmp))) {
> + /* If only s change, change just s value only*/
> + tmp &= ~(PLL35XX_SDIV_MASK << PLL35XX_SDIV_SHIFT);
> + tmp |= rate->sdiv << PLL35XX_SDIV_SHIFT;
> + pll_writel(pll, tmp, PLL35XX_CON0_OFFSET);
I'd use the same coding style here as in case of PLL36xx, i.e. add return
0 and move following code outside else.
This makes the code a bit more linear and lowers indentation level.
Otherwise looks good.
Reviewed-by: Tomasz Figa <t.figa@samsung.com>
Best regards,
Tomasz
> + } else {
> + /* Set PLL lock time. */
> + pll_writel(pll, rate->pdiv * PLL35XX_LOCK_FACTOR,
> + PLL35XX_LOCK_OFFSET);
> +
> + /* Change PLL PMS values */
> + tmp &= ~((PLL35XX_MDIV_MASK << PLL35XX_MDIV_SHIFT) |
> + (PLL35XX_PDIV_MASK << PLL35XX_PDIV_SHIFT)
|
> + (PLL35XX_SDIV_MASK <<
PLL35XX_SDIV_SHIFT));
> + tmp |= (rate->mdiv << PLL35XX_MDIV_SHIFT) |
> + (rate->pdiv << PLL35XX_PDIV_SHIFT) |
> + (rate->sdiv << PLL35XX_SDIV_SHIFT);
> + pll_writel(pll, tmp, PLL35XX_CON0_OFFSET);
> +
> + /* wait_lock_time */
> + do {
> + cpu_relax();
> + tmp = pll_readl(pll, PLL35XX_CON0_OFFSET);
> + } while (!(tmp & (PLL35XX_LOCK_STAT_MASK
> + << PLL35XX_LOCK_STAT_SHIFT)));
> + }
> +
> + return 0;
> +}
> +
> static const struct clk_ops samsung_pll35xx_clk_ops = {
> .recalc_rate = samsung_pll35xx_recalc_rate,
> + .round_rate = samsung_pll_round_rate,
> + .set_rate = samsung_pll35xx_set_rate,
> +};
> +
> +static const struct clk_ops samsung_pll35xx_clk_min_ops = {
> + .recalc_rate = samsung_pll35xx_recalc_rate,
> };
>
> struct clk * __init samsung_clk_register_pll35xx(const char *name,
> @@ -79,7 +179,6 @@ struct clk * __init
> samsung_clk_register_pll35xx(const char *name, }
>
> init.name = name;
> - init.ops = &samsung_pll35xx_clk_ops;
> init.flags = CLK_GET_RATE_NOCACHE;
> init.parent_names = &pname;
> init.num_parents = 1;
> @@ -88,6 +187,9 @@ struct clk * __init
> samsung_clk_register_pll35xx(const char *name, pll->rate_count =
> rate_count;
> pll->rate_table = kmemdup(rate_table, rate_count *
> sizeof(struct samsung_pll_rate_table),
GFP_KERNEL);
> + init.ops = &samsung_pll35xx_clk_ops;
> + } else {
> + init.ops = &samsung_pll35xx_clk_min_ops;
> }
>
> pll->hw.init = &init;
next prev parent reply other threads:[~2013-06-12 21:04 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 15:09 [PATCH v4 0/6] Add generic set_rate clk_ops for PLL35xx and PLL36xx for samsung SoCs Yadwinder Singh Brar
2013-06-03 15:09 ` [PATCH v4 1/6] clk: samsung: Use clk->base instead of directly using clk->con0 for PLL3xxx Yadwinder Singh Brar
2013-06-12 20:33 ` Doug Anderson
2013-06-12 20:35 ` Doug Anderson
2013-06-12 21:19 ` Tomasz Figa
2013-06-12 21:50 ` Doug Anderson
2013-06-12 22:02 ` Andrew Bresticker
2013-06-13 7:02 ` Yadwinder Singh Brar
2013-06-13 9:30 ` Tomasz Figa
2013-06-13 18:35 ` Yadwinder Singh Brar
2013-06-13 18:43 ` Tomasz Figa
2013-06-13 19:12 ` Yadwinder Singh Brar
2013-06-03 15:09 ` [PATCH v4 2/6] clk: samsung: Add support to register rate_table " Yadwinder Singh Brar
2013-06-12 20:43 ` Doug Anderson
2013-06-12 21:25 ` Tomasz Figa
2013-06-03 15:09 ` [PATCH v4 3/6] clk: samsung: Add set_rate() clk_ops for PLL35xx Yadwinder Singh Brar
2013-06-12 21:04 ` Tomasz Figa [this message]
2013-06-03 15:09 ` [PATCH v4 4/6] clk: samsung: Add set_rate() clk_ops for PLL36xx Yadwinder Singh Brar
2013-06-12 21:06 ` Tomasz Figa
2013-06-03 15:09 ` [PATCH v4 5/6] clk: samsung: Reorder MUX registration for mout_vpllsrc Yadwinder Singh Brar
2013-06-12 21:06 ` Tomasz Figa
2013-06-03 15:09 ` [PATCH v4 6/6] clk: samsung: Add EPLL and VPLL freq table for exynos5250 SoC Yadwinder Singh Brar
2013-06-12 20:52 ` Doug Anderson
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=18811812.9vb6COn4ou@flatron \
--to=tomasz.figa@gmail.com \
--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).