devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: Mike Turquette <mturquette@linaro.org>,
	Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	Russell King <linux@arm.linux.org.uk>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Kamil Lulko <rev13@wp.pl>, Andreas Farber <afaerber@suse.de>,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, patches@linaro.org,
	linaro-kernel@lists.linaro.org
Subject: Re: [RFC PATCH 2/3] clk: stm32: Add clock driver for STM32F4[23]xxx devices
Date: Fri, 05 Jun 2015 10:36:27 +0100	[thread overview]
Message-ID: <55716D9B.4040209@linaro.org> (raw)
In-Reply-To: <20150604220725.GT676@codeaurora.org>

On 04/06/15 23:07, Stephen Boyd wrote:
> On 05/22, Daniel Thompson wrote:
>> +
>> +#include <linux/clk.h>
>
> Are you using this include?
>
>> +#include <linux/clkdev.h>
>
> Are you using this include?

Not very much?

Turns out I was relying on these to get kzalloc() defined but there are 
better headers for me to use for that!

>
>> +#include <linux/err.h>
>> +#include <linux/io.h>
>> +#include <linux/clk-provider.h>
>> +#include <linux/spinlock.h>
>> +#include <linux/of.h>
>> +#include <linux/of_address.h>
>> +
>> +#include <linux/debugfs.h>
>
> Are you using this include?

No (this is already gone in v2).


>> +static long clk_apb_mul_round_rate(struct clk_hw *hw, unsigned long rate,
>> +				   unsigned long *prate)
>> +{
>> +	struct clk_apb_mul *am = to_clk_apb_mul(hw);
>> +	unsigned long mult = 1;
>> +
>> +	if (readl(base + STM32F4_RCC_CFGR) & BIT(am->bit_idx))
>> +		mult *= 2;
>
> Isn't this the same as mult = 2? I guess we could rely on the
> compiler to figure out this one.

I'll fix this.


>> +
>> +	if (__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT) {
>> +		unsigned long best_parent = rate / mult;
>> +
>> +		*prate =
>> +		    __clk_round_rate(__clk_get_parent(hw->clk), best_parent);
>> +	}
>> +
>> +	return *prate * mult;
>> +}
>> +
>> +static int clk_apb_mul_set_rate(struct clk_hw *hw, unsigned long rate,
>> +				 unsigned long parent_rate)
>> +{
>
> Why don't we need to do anything here?

This clock cannot change its own rate. It is very nearly a fixed factor 
clock but with the additional quirk that the "fixed" factor changes 
depending upon the rate of the parent clock.

This is the same implementation as clk-fixed-factor. I concluded that it 
returns success because round rate should always result in the set rate 
for this clock being a nop.


>> +	return 0;
>> +}
>> +
>> +static struct clk_ops clk_apb_mul_factor_ops = {
>
> const?

Makes sense...

You want a patch for clk-fixed-factor too?


>> +struct clk *clk_register_apb_mul(struct device *dev, const char *name,
>> +				 const char *parent_name, unsigned long flags,
>> +				 u8 bit_idx)
>> +{
>> +	struct clk_apb_mul *am;
>> +	struct clk_init_data init;
>> +	struct clk *clk;
>> +
>> +	am = kzalloc(sizeof(*am), GFP_KERNEL);
>> +	if (!am)
>> +		return ERR_PTR(-ENOMEM);
>> +
>> +	am->bit_idx = bit_idx;
>> +	am->hw.init = &init;
>> +
>> +	init.name = name;
>> +	init.ops = &clk_apb_mul_factor_ops;
>> +	init.flags = flags | CLK_IS_BASIC;
>
> Is it basic?

Tough question.

The absence of this flag appears grants arch code permission to use 
secret backdoors to do "weird stuff" but making special assumptions 
about the type of the clock. This clock keeps its implementation private 
so noone outside the compilation unit can usefully cast it.

However, it also looks like only omap2 is the only platform that makes 
these special assumptions so when this code is run on STM32 there is 
nothing to actually consume the CLK_IS_BASIC flag at runtime.

In other words the flag is useless but, I think, also correctly applied.

I'd be happy to remove it if anyone disagrees with the guesswork above.

Alternatively, I could write a patch to *invert* CLK_IS_BASIC and rename 
it CLK_CASTABLE on the grounds that only the people doing "weird stuff" 
should have to care about this flag at all. Any interest in that?


>> +	init.parent_names = &parent_name;
>> +	init.num_parents = 1;
>> +
>> +	clk = clk_register(dev, &am->hw);
>> +
>> +	if (IS_ERR(clk))
>> +		kfree(am);
>> +
>> +	return clk;
>> +}
>> +
>> +static const char __initdata *sys_parents[] =   { "hsi", NULL, "pll" };
>
> __initdata goes after the []

Thanks. I'll fix this.

  reply	other threads:[~2015-06-05  9:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22 20:41 [RFC PATCH 0/3] clk: stm32: Add clock driver for STM32F4[23]xxx devices Daniel Thompson
2015-05-22 20:41 ` [RFC PATCH 2/3] " Daniel Thompson
2015-06-04 22:07   ` Stephen Boyd
2015-06-05  9:36     ` Daniel Thompson [this message]
2015-06-06  0:10       ` Stephen Boyd
2015-05-22 20:41 ` [RFC PATCH 3/3] ARM: dts: stm32f429: Adopt STM32F4 clock driver Daniel Thompson
2015-05-26 16:41 ` [RFC PATCH 0/3] clk: stm32: Add clock driver for STM32F4[23]xxx devices Maxime Coquelin
     [not found]   ` <CALszF6BTu_8SCE9hEiLYuvQg8J9eG5xktaVV7_LvnG3r20+wtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-27  8:36     ` Daniel Thompson
     [not found] ` <1432327273-6810-1-git-send-email-daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-05-22 20:41   ` [RFC PATCH 1/3] dt-bindings: Document the STM32F4 clock bindings Daniel Thompson
2015-05-30  7:54   ` [PATCH v2 0/4] clk: stm32: Add clock driver for STM32F4[23]xxx devices Daniel Thompson
2015-05-30  7:54     ` [PATCH v2 1/4] ARM: stm32: Enable clock source Daniel Thompson
     [not found]     ` <1432972448-10332-1-git-send-email-daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-05-30  7:54       ` [PATCH v2 2/4] dt-bindings: Document the STM32F4 clock bindings Daniel Thompson
     [not found]         ` <1432972448-10332-3-git-send-email-daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-05-30  9:21           ` Maxime Coquelin
     [not found]             ` <55698104.2070205-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-01  7:46               ` Daniel Thompson
2015-05-30  7:54       ` [PATCH v2 3/4] clk: stm32: Add clock driver for STM32F4[23]xxx devices Daniel Thompson
2015-05-30  9:15         ` Maxime Coquelin
     [not found]           ` <55697FCE.9040003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-01  7:18             ` Daniel Thompson
2015-05-30  7:54       ` [PATCH v2 4/4] ARM: dts: stm32f429: Adopt STM32F4 clock driver Daniel Thompson
2015-05-30  9:38         ` Maxime Coquelin
2015-05-30  8:40     ` [PATCH v2 0/4] clk: stm32: Add clock driver for STM32F4[23]xxx devices Maxime Coquelin
2015-06-10 20:09   ` [PATCH v3 0/3] " Daniel Thompson
     [not found]     ` <1433966978-24422-1-git-send-email-daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-06-10 20:09       ` [PATCH v3 1/3] dt-bindings: Document the STM32F4 clock bindings Daniel Thompson
2015-06-12  7:25         ` Maxime Coquelin
2015-06-22 22:47         ` Stephen Boyd
2015-06-10 20:09       ` [PATCH v3 2/3] clk: stm32: Add clock driver for STM32F4[23]xxx devices Daniel Thompson
2015-06-22 22:48         ` Stephen Boyd
     [not found]         ` <1433966978-24422-3-git-send-email-daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-06-22 23:21           ` Stephen Boyd
     [not found]             ` <20150622232114.GK22132-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-06-23  8:25               ` Daniel Thompson
2015-06-10 20:09     ` [PATCH v3 3/3] ARM: dts: stm32f429: Adopt STM32F4 clock driver Daniel Thompson
2015-07-07  9:38       ` Maxime Coquelin
2015-06-22 22:48     ` [PATCH v3 0/3] clk: stm32: Add clock driver for STM32F4[23]xxx devices Stephen Boyd
     [not found]       ` <20150622224832.GI22132-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-06-23  8:22         ` Daniel Thompson
2015-06-23  9:24           ` Maxime Coquelin

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=55716D9B.4040209@linaro.org \
    --to=daniel.thompson@linaro.org \
    --cc=afaerber@suse.de \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mturquette@linaro.org \
    --cc=patches@linaro.org \
    --cc=pawel.moll@arm.com \
    --cc=rev13@wp.pl \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.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).