From: Michael Turquette <mturquette@baylibre.com>
To: Martin Sperl <kernel@martin.sperl.org>,
Stephen Boyd <sboyd@codeaurora.org>,
Stephen Warren <swarren@wwwdotorg.org>,
Lee Jones <lee@kernel.org>, Eric Anholt <eric@anholt.net>,
Remi Pommarel <repk@triplefau.lt>,
linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH V2 1/4] clk: bcm2835: avoid the use of BCM2835_CLOCK_COUNT in clk-bcm2835
Date: Thu, 14 Jan 2016 12:23:30 -0800 [thread overview]
Message-ID: <20160114202330.1942.96295@quark.deferred.io> (raw)
In-Reply-To: <56979056.6010407@martin.sperl.org>
Quoting Martin Sperl (2016-01-14 04:11:02)
>
>
> On 14.01.2016 01:13, Michael Turquette wrote:
> > Quoting Michael Turquette (2016-01-13 12:00:12)
> >> Hi Martin,
> >>
> >> Quoting kernel@martin.sperl.org (2016-01-11 11:55:53)
> >>> static int bcm2835_clk_probe(struct platform_device *pdev)
> >>> {
> >>> struct device *dev = &pdev->dev;
> >>> struct clk **clks;
> >>> + size_t clk_cnt;
> >>> struct bcm2835_cprman *cprman;
> >>> struct resource *res;
> >>> + size_t i;
> >>> +
> >>> + /* find the max clock index */
> >>> + clk_cnt = BCM2835_CLOCK_PERI_IMAGE; /* see below */
> >>> + for (i = 0; i < ARRAY_SIZE(bcm2835_register_clocks); i++)
> >>> + clk_cnt = max(clk_cnt, bcm2835_register_clocks[i].index);
> >>> + clk_cnt += 1;
> >>
> >> I'm not sure how this solution is better than using CLOCK_COUNT. Some
> >> other bindings use a max value, NR_CLKS or other sentinel.
> >>
> >> Why did you not choose to set clk_cnt equal to BCM2835_CLOCK_PWM? Why
> >> not initialize it to zero?
> >
> > OK, I just caught up on the asoc/bcm2835 thread.
> >
> > Really the best solution would be to have an array of all of the clks in
> > the driver and just use ARRAY_SIZE on it.
> >
> > For your driver, could you make an array of clk_hw pointers and call
> > devm_clk_register on all of them in a loop? This gets rid of the big
> > pile of explicit calls in bcm2835_clk_probe.
> >
> > You can also get rid of stuff like bcm2835_plla_core_data by just
> > stuffing that data into a single struct initialization. Here is a
> > snippet for how the qcom clk drivers do it:
> >
> > static struct clk_pll gpll0 = {
> > .l_reg = 0x0004,
> > .m_reg = 0x0008,
> > .n_reg = 0x000c,
> > .config_reg = 0x0014,
> > .mode_reg = 0x0000,
> > .status_reg = 0x001c,
> > .status_bit = 17,
> > .clkr.hw.init = &(struct clk_init_data){
> > .name = "gpll0",
> > .parent_names = (const char *[]){ "xo" },
> > .num_parents = 1,
> > .ops = &clk_pll_ops,
> > },
> > };
>
> I did not know you could do that - that could make life easier...
>
> But a quick look shows that this approach probably would require a
> major rewrite of all the methods.
>
> > static int bcm2835_clk_probe(struct platform_device *pdev)
> > {
> > ...
> > for (i = 0; i < num_clks; i++) {
> > clk = devm_clk_register(dev, array_of_clks[i].hw)
> > ...
> > }
>
> I guess I can use a slightly different approach that does not
> require as many changes, that looks like this:
>
> static const struct bcm2835_clk_desc clk_desc_array[] = {
> /* register PLL */
> [BCM2835_PLLA] = REGISTER_PLL(&bcm2835_plla_data),
> ...
> };
> ...
> static int bcm2835_clk_probe(struct platform_device *pdev)
> {
> const size_t asize = ARRAY_SIZE(clk_desc_array);
> ...
> for (i = 0; i < asize; i++) {
> desc = &clk_desc_array[i];
> if (desc)
> clks[i] = desc->clk_register(cprman,
> desc->data);
Interesting. I have been playing with the idea of putting a .register()
callback into struct clk_init_data. Then it would be called by a new
clk_register_desc() top-level registration function.
You've done that here, but you've put the registration function in your
machine-specific struct. Nothing wrong with that.
Do you actually need a machine-specific registration function? Many clk
drivers only use their machine-specific registration functions to
allocate a stuct clk_hw and populate the contents of struct
clk_init_data, which can be done by the framework and reduce duplicate
code in drivers.
(they do this because the basic clk types like clk-divider, clk-gate,
etc do it, and everyone loves to copy/paste that code)
bcm2835 seems to register two clks in the PLL registration function (one
of which is a fixed factor divider), but you could just add those
post-PLL dividers to your array of clk data?
> }
> ...
> }
>
> If we need to order the initialization then we can add some
> priority field to clk_desc_array and iterate over all the priority
> values.
I guess that you can order them in your array? Just start with the root
clocks at the beginning of the array (regardless of "clk type") and walk
through the array registering them.
Regards,
Mike
next prev parent reply other threads:[~2016-01-14 20:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-11 19:55 [PATCH V2 0/4] clk: bcm2835: add additinal clocks and add frac support kernel
2016-01-11 19:55 ` [PATCH V2 1/4] clk: bcm2835: avoid the use of BCM2835_CLOCK_COUNT in clk-bcm2835 kernel
2016-01-13 20:00 ` Michael Turquette
2016-01-14 0:13 ` Michael Turquette
2016-01-14 12:11 ` Martin Sperl
2016-01-14 20:23 ` Michael Turquette [this message]
2016-01-14 21:24 ` Martin Sperl
2016-01-11 19:55 ` [PATCH V2 2/4] clk: bcm2835: enable fractional and mash support kernel
2016-01-13 20:07 ` Michael Turquette
2016-01-11 19:55 ` [PATCH V2 3/4] clk: bcm2835: enable management of PCM clock kernel
[not found] ` <1452542157-2387-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-01-13 20:11 ` Michael Turquette
2016-01-11 19:55 ` [PATCH V2 4/4] clk: bcm2835: add missing 22 HW-clocks kernel
[not found] ` <1452542157-2387-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-01-11 21:01 ` [PATCH V2 0/4] clk: bcm2835: add additinal clocks and add frac support Arnd Bergmann
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=20160114202330.1942.96295@quark.deferred.io \
--to=mturquette@baylibre.com \
--cc=devicetree@vger.kernel.org \
--cc=eric@anholt.net \
--cc=kernel@martin.sperl.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=repk@triplefau.lt \
--cc=sboyd@codeaurora.org \
--cc=swarren@wwwdotorg.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).