devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Turquette <mturquette@baylibre.com>
To: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>,
	Vishnu Patekar <vishnupatekar0510@gmail.com>,
	Jean-Francois Moine <moinejf@free.fr>,
	devicetree@vger.kernel.org,
	Andre Przywara <andre.przywara@arm.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	linux-kernel@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>,
	Chen-Yu Tsai <wens@csie.org>, Rob Herring <robh+dt@kernel.org>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 14/15] clk: sunxi-ng: Add H3 clocks
Date: Mon, 27 Jun 2016 17:53:37 -0700	[thread overview]
Message-ID: <146707521689.89261.8354851392822550901@resonance> (raw)
In-Reply-To: <20160626123409.GK4000@lukather>

Quoting Maxime Ripard (2016-06-26 05:34:09)
> On Fri, Jun 24, 2016 at 05:28:37PM -0700, Michael Turquette wrote:
> > Quoting Maxime Ripard (2016-06-07 13:41:53)
> > > +static struct ccu_common *sun8i_h3_ccu_clks[] = {
> > > +       [CLK_PLL_CPUX]          = &pll_cpux_clk.common,
> > > +       [CLK_PLL_AUDIO_BASE]    = &pll_audio_base_clk.common,
> > > +       [CLK_PLL_AUDIO]         = &pll_audio_clk.common,
> > 
> > OK, it looks like you followed the qcom clk driver approach here, which
> > is a nice way to do things. However, as Stephen alluded to in his
> > response to the cover letter, the clk_hw_* api's are an even more
> > friendly interface for clock providers. For example, check out the gxbb
> > clk driver probe:
> > 
> >       static int gxbb_clkc_probe(struct platform_device *pdev)
> >       {
> >               void __iomem *clk_base;
> >               int ret, clkid, i;
> >               struct device *dev = &pdev->dev;
> >       
> >               /*  Generic clocks and PLLs */
> >               clk_base = of_iomap(dev->of_node, 0);
> >               if (!clk_base) {
> >                       pr_err("%s: Unable to map clk base\n", __func__);
> >                       return -ENXIO;
> >               }
> >       
> >               /* Populate base address for PLLs */
> >               for (i = 0; i < ARRAY_SIZE(gxbb_clk_plls); i++)
> >                       gxbb_clk_plls[i]->base = clk_base;
> >       
> >               /* Populate base address for MPLLs */
> >               for (i = 0; i < ARRAY_SIZE(gxbb_clk_mplls); i++)
> >                       gxbb_clk_mplls[i]->base = clk_base;
> > 
> >               ...
> > 
> >               /*
> >                * register all clks
> >                */
> >               for (clkid = 0; clkid < NR_CLKS; clkid++) {
> >                       ret = devm_clk_hw_register(dev, gxbb_hw_onecell_data.hws[clkid]);
> >                       if (ret)
> >                               goto iounmap;
> >               }
> 
> Ok, I'll move the fixed factor clocks out of the common list, and
> initialize the clk_hw_onedata_cell structure to register it.

Cool, thanks! This driver will be one of the early adopters :-)

> 
> > The nice thing about struct ccu_common is that you don't have to walk
> > the list of clocks for each separate clock type like the above probe
> > function does. I'm still thinking of the best way to solve this
> > generically. Maybe add a .base member struct clk_hw? I dunno, and I've
> > resisted the urge to add stuff to struct clk_hw in the past... But I
> > really want to minimize this .probe as much as possible, and I do not
> > want every clock provider driver to be forced to invent something like
> > struct ccu_common every time.
> 
> We'd need a few more things (in this case) at least: the register
> offset and a private field to store our flags.

A bit of mumbling to myself below:

Hmm, upon further reflection, walking the list of ccu clocks is rather
identical to walking the list of each clock type, as I do in the gxbb
driver, where ccu_common is the one and only clock type.

So that in itself is not a big deal and isn't a problem that needs
solving.

What needs solving is a way to populate base addresses for each clock at
runtime in a way that does not *force* you to invent something like
ccu_common if you do not need it.

You would hit this issue if you broke your common gate or divider clocks
out and did not wrap them in the ccu_common structure. I solved this by
overloading the ->reg value of each of the common types as static data,
and then did the following when registering them:

	/* Populate base address for gates */
	for (i = 0; i < ARRAY_SIZE(gxbb_clk_gates); i++)
		gxbb_clk_gates[i]->reg = clk_base +
			(u64)gxbb_clk_gates[i]->reg;

Any thoughts on how to fix this for other common gate types that need
their base addresses populated from an OF node at runtime?

> 
> > Anyways, that is not a blocker for your implementation to be merged,
> > but Stephen's question in patch #4 got me thinking about this
> > again...
> > 
> > The real nice part is the call to devm_clk_hw_register. That uses the
> > new clk_hw_* apis and struct clk_hw_onecell_data, which is initialized
> > statically like so:
> > 
> >       static struct clk_hw_onecell_data gxbb_hw_onecell_data = {
> >               .hws = {
> >                       [CLKID_SYS_PLL]      = &gxbb_sys_pll.hw,
> >                       [CLKID_CPUCLK]        = &gxbb_cpu_clk.hw,
> >                       ...
> >               },
> >               .num = NR_CLKS,
> >       };
> > 
> > Unfortunately I believe it impossible to replace NR_CLKS with some
> > ARRAY_SIZE stuff because C. As Stephen mentioned, please use this method
> > instead.
> 
> That's unfortunate :/

But also not a big deal if you hide clocks from your DT ABI. You can
store NR_CLKS in kernel code, and never expose it to the DT ABI.

> 
> > > diff --git a/include/dt-bindings/clock/sun8i-h3.h b/include/dt-bindings/clock/sun8i-h3.h
> > > new file mode 100644
> > > index 000000000000..96eced56e7a2
> > > --- /dev/null
> > > +++ b/include/dt-bindings/clock/sun8i-h3.h
> > > @@ -0,0 +1,162 @@
> > > +#ifndef _DT_BINDINGS_CLK_SUN8I_H3_H_
> > > +#define _DT_BINDINGS_CLK_SUN8I_H3_H_
> > > +
> > > +#define CLK_PLL_CPUX           0
> > > +#define CLK_PLL_AUDIO_BASE     1
> > > +#define CLK_PLL_AUDIO          2
> > > +#define CLK_PLL_AUDIO_2X       3
> > > +#define CLK_PLL_AUDIO_4X       4
> > 
> > Are you sure you want to expose all of these clocks as part of the ABI?
> > I exposed the bare minimum clocks for the gxbb driver in the DT shared
> > header (we can always add more later) and kept the rest internal to the
> > kernel source.
> 
> I thought about it, but that would require a third array with
> basically the same clocks:
> 
>   * the ccu_common array to patch to set the lock and base pointers,
>   * the list of clocks to register
>   * the clk_hw_onecell_data to deal with the dt binding.

"the list of clocks to register" and "the clk_hw_onecell_data to deal
with the dt binding" are the same array.

You only need two arrays:

1) the ccu_common init data
2) the clk_hw_onecell_data array of clk_hw pointers that points to
clk_hw statically defined in the ccu_common array

And then only expose the clocks that you want via the shared header in
the DT include chroot. See:

https://git.kernel.org/cgit/linux/kernel/git/clk/linux.git/diff/drivers/clk/meson/gxbb.h?h=clk-s905&id=738f66d3211d7ae0cd0012ba6457dac9a03bfd6b

https://git.kernel.org/cgit/linux/kernel/git/clk/linux.git/diff/include/dt-bindings/clock/gxbb-clkc.h?h=clk-s905&id=738f66d3211d7ae0cd0012ba6457dac9a03bfd6b

In summary, there is only one array of "clocks to be registered", and we
limit DT exposure via the shared header. Again, your choice to expose
whatever you want via DT, but I thought I'd explain my approach
(especially b/c the SoC I'm hacking on has incomplete docs).

Regards,
Mike

> 
> That seems a bit overkill.
> 
> Thanks!
> Maxime
> 
> -- 
> Maxime Ripard, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com

  reply	other threads:[~2016-06-28  0:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07 20:41 [PATCH v2 00/15] clk: sunxi: introduce "modern" clock support Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 01/15] dt-bindings: sunxi: Add CCU binding documentation Maxime Ripard
2016-06-08  1:37   ` Chen-Yu Tsai
2016-06-07 20:41 ` [PATCH v2 02/15] clk: sunxi-ng: Add common infrastructure Maxime Ripard
2016-06-09  7:39   ` Jean-Francois Moine
2016-06-07 20:41 ` [PATCH v2 03/15] clk: sunxi-ng: Add fractional lib Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 04/15] clk: sunxi-ng: Add fixed factor clock support Maxime Ripard
2016-06-21  1:15   ` Stephen Boyd
2016-06-21  9:24     ` Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 05/15] clk: sunxi-ng: Add gate " Maxime Ripard
2016-06-09  7:39   ` Jean-Francois Moine
2016-06-07 20:41 ` [PATCH v2 06/15] clk: sunxi-ng: Add mux " Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 07/15] clk: sunxi-ng: Add phase " Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 08/15] clk: sunxi-ng: Add divider Maxime Ripard
2016-06-09  7:40   ` Jean-Francois Moine
     [not found]   ` <20160607204154.31967-9-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-11  8:27     ` Jean-Francois Moine
2016-06-07 20:41 ` [PATCH v2 09/15] clk: sunxi-ng: Add M-P factor clock support Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 10/15] clk: sunxi-ng: Add N-K-factor " Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 11/15] clk: sunxi-ng: Add N-M-factor " Maxime Ripard
2016-06-09  7:41   ` Jean-Francois Moine
2016-06-27 20:29     ` Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 12/15] clk: sunxi-ng: Add N-K-M Factor clock Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 13/15] clk: sunxi-ng: Add N-K-M-P factor clock Maxime Ripard
2016-06-21  1:42   ` Stephen Boyd
2016-06-07 20:41 ` [PATCH v2 14/15] clk: sunxi-ng: Add H3 clocks Maxime Ripard
2016-06-09  7:42   ` Jean-Francois Moine
2016-06-25  0:28   ` Michael Turquette
2016-06-26 12:34     ` Maxime Ripard
2016-06-28  0:53       ` Michael Turquette [this message]
2016-06-28  8:32         ` Maxime Ripard
2016-06-07 20:41 ` [PATCH v2 15/15] ARM: dt: sun8i: switch the H3 to the new CCU driver Maxime Ripard
     [not found] ` <20160607204154.31967-1-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-21  1:48   ` [PATCH v2 00/15] clk: sunxi: introduce "modern" clock support Stephen Boyd
2016-06-26 16:24     ` Maxime Ripard
2016-06-21  9:40 ` Jean-Francois Moine
2016-06-21 14:47   ` Maxime Ripard
2016-06-21 18:29     ` Jean-Francois Moine
2016-06-27 20:46       ` Maxime Ripard

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=146707521689.89261.8354851392822550901@resonance \
    --to=mturquette@baylibre.com \
    --cc=andre.przywara@arm.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=moinejf@free.fr \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    --cc=vishnupatekar0510@gmail.com \
    --cc=wens@csie.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).