linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Abel Vesa <abel.vesa@nxp.com>
To: Stephen Boyd <sboyd@kernel.org>
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>,
	Anson Huang <anson.huang@nxp.com>,
	"A.s. Dong" <aisheng.dong@nxp.com>,
	Fabio Estevam <fabio.estevam@nxp.com>,
	Lucas Stach <l.stach@pengutronix.de>,
	Rob Herring <robh@kernel.org>,
	Sascha Hauer <kernel@pengutronix.de>,
	dl-linux-imx <linux-imx@nxp.com>, Abel Vesa <abelvesa@linux.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Michael Turquette <mturquette@baylibre.com>,
	open list <linux-kernel@vger.kernel.org>,
	"moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" 
	<linux-arm-kernel@lists.infradead.org>,
	"open list:COMMON CLK FRAMEWORK" <linux-clk@vger.kernel.org>
Subject: Re: [PATCH v9 2/5] clk: imx: add fractional PLL output clock
Date: Wed, 7 Nov 2018 12:25:59 +0000	[thread overview]
Message-ID: <20181107122558.mlul4keytay4lrtc@fsr-ub1664-175> (raw)
In-Reply-To: <153980638471.5275.2935268205764106887@swboyd.mtv.corp.google.com>

On Wed, Oct 17, 2018 at 12:59:44PM -0700, Stephen Boyd wrote:
> Quoting Abel Vesa (2018-09-24 03:39:54)
> > From: Lucas Stach <l.stach@pengutronix.de>
> > 
> > This is a new clock type introduced on i.MX8.
> 
> Ok, what's the clock type? Add another sentence please.
> 

Added in the next version a link with the pdf describing the hardware
and specified in the commit message that is a fractional clock.

> > 
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
> [..]
> > diff --git a/drivers/clk/imx/clk-frac-pll.c b/drivers/clk/imx/clk-frac-pll.c
> > new file mode 100644
> > index 0000000..030df76
> > --- /dev/null
> > +++ b/drivers/clk/imx/clk-frac-pll.c
> > @@ -0,0 +1,215 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright 2018 NXP.
> > + */
> > +
> > +#include <linux/clk-provider.h>
> > +#include <linux/err.h>
> > +#include <linux/io.h>
> > +#include <linux/iopoll.h>
> > +#include <linux/jiffies.h>
> 
> Is this used for something?
>

Removed in the next version.

> > +#include <linux/slab.h>
> > +#include <linux/bitfield.h>
> > +
> > +#include "clk.h"
> [...]
> > +
> > +static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
> > +                                        unsigned long parent_rate)
> > +{
> > +       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
> > +       u32 val, divff, divfi, divq;
> > +       u64 temp64;
> > +
> > +       val = readl_relaxed(pll->base + PLL_CFG0);
> > +       divq = ((val & PLL_OUTPUT_DIV_MASK) + 1) * 2;
> > +       val = readl_relaxed(pll->base + PLL_CFG1);
> > +       divff = FIELD_GET(PLL_FRAC_DIV_MASK, val);
> > +       divfi = (val & PLL_INT_DIV_MASK);
> 
> Nitpick: Drop useless parenthesis please.
> 

Removed in the next version.

> > +
> > +       temp64 = (u64)parent_rate * 8;
> > +       temp64 *= divff;
> > +       do_div(temp64, PLL_FRAC_DENOM);
> > +       temp64 /= divq;
> > +
> > +       return parent_rate * 8 * (divfi + 1) / divq + (unsigned long)temp64;
> > +}
> > +
> > +static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
> > +                              unsigned long *prate)
> > +{
> > +       unsigned long parent_rate = *prate;
> > +       u32 divff, divfi;
> > +       u64 temp64;
> > +
> > +       parent_rate *= 8;
> 
> And parent_rate can't overflow if it's a u32? Maybe it could be a u64 so
> that we don't need casting later on in this function.
> 

Fixed in the next version.

> > +       rate *= 2;
> > +       divfi = rate / parent_rate;
> > +       temp64 = (u64)(rate - divfi * parent_rate);
> > +       temp64 *= PLL_FRAC_DENOM;
> > +       do_div(temp64, parent_rate);
> > +       divff = temp64;
> > +
> > +       temp64 = (u64)parent_rate;
> > +       temp64 *= divff;
> > +       do_div(temp64, PLL_FRAC_DENOM);
> > +
> > +       return (parent_rate * divfi + (unsigned long)temp64) / 2;
> > +}
> > +
> > +/*
> > + * To simplify the clock calculation, we can keep the 'PLL_OUTPUT_VAL' at zero
> > + * (means the PLL output will be divided by 2). So the PLL output can use
> > + * the below formula:
> > + * pllout = parent_rate * 8 / 2 * DIVF_VAL;
> > + * where DIVF_VAL = 1 + DIVFI + DIVFF / 2^24.
> > + */
> > +static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
> > +                           unsigned long parent_rate)
> > +{
> > +       struct clk_frac_pll *pll = to_clk_frac_pll(hw);
> > +       u32 val, divfi, divff;
> > +       u64 temp64;
> > +       int ret;
> > +
> > +       parent_rate *= 8;
> > +       rate *= 2;
> > +       divfi = rate / parent_rate;
> > +       temp64 = (u64) (rate - divfi * parent_rate);
> > +       temp64 *= PLL_FRAC_DENOM;
> > +       do_div(temp64, parent_rate);
> > +       divff = temp64;
> > +
> > +       val = readl_relaxed(pll->base + PLL_CFG1);
> > +       val &= ~(PLL_FRAC_DIV_MASK | PLL_INT_DIV_MASK);
> > +       val |= ((divff << 7) | (divfi - 1));
> 
> Nitpick: Drop the extra parenthesis please.
> 

Removed in the next version.

> > +       writel_relaxed(val, pll->base + PLL_CFG1);
> > +
> > +       val = readl_relaxed(pll->base + PLL_CFG0);
> > +       val &= ~0x1f;
> > +       writel_relaxed(val, pll->base + PLL_CFG0);
> > +
> > +       /* Set the NEV_DIV_VAL to reload the DIVFI and DIVFF */
> > +       val = readl_relaxed(pll->base + PLL_CFG0);
> > +       val |= PLL_NEWDIV_VAL;
> > +       writel_relaxed(val, pll->base + PLL_CFG0);
> > +
> > +       ret = clk_wait_ack(pll);
> > +
> > +       /* clear the NEV_DIV_VAL */
> > +       val = readl_relaxed(pll->base + PLL_CFG0);
> > +       val &= ~PLL_NEWDIV_VAL;
> > +       writel_relaxed(val, pll->base + PLL_CFG0);
> > +
> > +       return ret;
> > +}
> > +
> > +static const struct clk_ops clk_frac_pll_ops = {
> > +       .prepare        = clk_pll_prepare,
> > +       .unprepare      = clk_pll_unprepare,
> > +       .is_prepared    = clk_pll_is_prepared,
> > +       .recalc_rate    = clk_pll_recalc_rate,
> > +       .round_rate     = clk_pll_round_rate,
> > +       .set_rate       = clk_pll_set_rate,
> > +};
> > +
> > +struct clk *imx_clk_frac_pll(const char *name, const char *parent_name,
> > +                            void __iomem *base)
> > +{
> > +       struct clk_init_data init;
> > +       struct clk_frac_pll *pll;
> > +       struct clk *clk;
> > +
> > +       pll = kzalloc(sizeof(*pll), GFP_KERNEL);
> > +       if (!pll)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       pll->base = base;
> > +       init.name = name;
> > +       init.ops = &clk_frac_pll_ops;
> > +       init.flags = 0;
> > +       init.parent_names = &parent_name;
> > +       init.num_parents = 1;
> > +
> > +       pll->hw.init = &init;
> > +
> > +       clk = clk_register(NULL, &pll->hw);
> 
> clk_hw based please.
> 

Fixed in the next version.

> > +       if (IS_ERR(clk))
> > +               kfree(pll);
> > +
> > +       return clk;
> > +}

-- 

  reply	other threads:[~2018-11-07 12:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1537785597-26499-1-git-send-email-abel.vesa@nxp.com>
2018-09-24 10:39 ` [PATCH v9 1/5] dt-bindings: add binding for i.MX8MQ CCM Abel Vesa
2018-10-17 20:00   ` Stephen Boyd
2018-09-24 10:39 ` [PATCH v9 2/5] clk: imx: add fractional PLL output clock Abel Vesa
2018-10-17 19:59   ` Stephen Boyd
2018-11-07 12:25     ` Abel Vesa [this message]
2018-09-24 10:39 ` [PATCH v9 3/5] clk: imx: add SCCG PLL type Abel Vesa
2018-10-17 19:55   ` Stephen Boyd
2018-11-07 11:54     ` Abel Vesa
2018-11-07 19:01       ` Stephen Boyd
2018-11-07 20:26         ` Abel Vesa
2018-11-08  0:18           ` Stephen Boyd
2018-11-08 12:29             ` Abel Vesa
2018-11-08 18:28               ` Stephen Boyd
2018-11-10 16:05                 ` A.s. Dong
2018-11-13 14:25                   ` Shawn Guo
2018-11-14 23:21                     ` Stephen Boyd
2018-09-24 10:39 ` [PATCH v9 4/5] clk: imx: add imx composite clock Abel Vesa
2018-09-25 16:42   ` Fabio Estevam
2018-09-26  6:47     ` Sascha Hauer
2018-09-26 12:02       ` Fabio Estevam
2018-10-17 19:51   ` Stephen Boyd
2018-10-18  9:57     ` Abel Vesa
2018-09-24 10:39 ` [PATCH v9 5/5] clk: imx: add clock driver for i.MX8MQ CCM Abel Vesa
2018-10-17 19:44   ` Stephen Boyd
2018-11-07 12:09     ` Abel Vesa

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=20181107122558.mlul4keytay4lrtc@fsr-ub1664-175 \
    --to=abel.vesa@nxp.com \
    --cc=abelvesa@linux.com \
    --cc=aisheng.dong@nxp.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=anson.huang@nxp.com \
    --cc=fabio.estevam@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=l.stach@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=shawnguo@kernel.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).