From: Mason <slash.tmp@free.fr>
To: Stephen Boyd <sboyd@codeaurora.org>,
Michael Turquette <mturquette@baylibre.com>
Cc: linux-clk <linux-clk@vger.kernel.org>,
Sebastian Frias <sf84@laposte.net>
Subject: Re: [PATCH RFC] tango4 clk rewrite
Date: Fri, 26 Feb 2016 11:51:27 +0100 [thread overview]
Message-ID: <56D02E2F.1010908@free.fr> (raw)
In-Reply-To: <20160225220803.GK4847@codeaurora.org>
Hello Stephen,
Thanks for taking a look. Hope either you or Michael will be
available to discuss some of the issues you raised.
On 25/02/2016 23:08, Stephen Boyd wrote:
> On 02/12, Mason wrote:
>
>> +#define FATAL(cond) if (cond) panic("Unsupported clkgen setup!\n")
>
> Please just use BUG_ON instead.
The issue (from my POV) is that, AFAICT, BUG_ON() can be disabled.
If one compiles a CONFIG_BUG=n kernel, then BUG_ON() is a NOP, right?
But, if the firmware set the clock generator up in a way not supported
by the driver, then bad things will happen, should the kernel be allowed
to proceed, so panic() here seems necessary.
>> +#define PLL_N(v) extract(v, 0, 7)
>> +#define PLL_K(v) extract(v, 13, 3)
>> +#define PLL_M(v) extract(v, 16, 3)
>> +#define PLL_ISEL(v) extract(v, 24, 3)
>
> I would have left it like it is, but made it lower case to
> signify "function" and not "constant".
OK, I can change the function-macros to lower case.
> #define pll_n(val) ((val) & 0x7f)
> #define pll_k(val) (((val) >> 13) & 0x7)
> #define pll_m(val) (((val) >> 16) & 0x7)
> #define pll_isel(val) (((val) >> 24) & 0x7)
>
> Note how I didn't use _another_ macro to make writing the
> shifting and anding logic common. That's because I'd like to know
> what the pll_n "function" does without having to go through
> another macro that does little but obscure the code.
My rationale was: the documentation specifies offset and width
for the fields. And the code should mirror the documentation
(leaving the arithmetic to the compiler).
BTW, my preferred version used bit-fields:
#define REG(name, ...) union name { struct { u32 __VA_ARGS__; }; u32 val; }
REG(SYS_clkgen_pll, N:7, :6, K:3, M:3, :5, Isel:3, :3, T:1, B:1);
But you wrote:
"This is new to me. Using bitfields like this is not really a good
idea though. Please just use masks, shifts, etc. instead."
IMHO, this is one place where bit-fields /are/ in fact useful.
> And to make things even clearer, maybe calling them
> extract_pll_n(), extract_pll_k(), etc. would make it clear from
> the calls sites that we're extracting the pll n and pll k values
> without having to look at the macro definitions.
OK, I can change the names.
>> + div = (1 << 28) + readl_relaxed(base + idx*8);
>
> Please add spaces around '*'. Also, just do it on two lines.
>
> div = 1 << 28;
> div += readl_relaxed(base + idx * 8)
Is that because of the function-like macro?
>> + FATAL(readl_relaxed(base + CPUCLK_DIV) & BIT(23));
>> + FATAL(readl_relaxed(base + SYSCLK_DIV) & BIT(23));
>
> BUG_ON would read much better here. Plus a comment on what
> BIT(23) means or a macro definition of it would make it clear
> what we're testing for.
There is a problem if BUG_ON() is a NOP.
I can indeed define BIT(23) as BYPASS_ENABLE.
Thanks again for reviewing, hope to hear back from you.
Regards.
next prev parent reply other threads:[~2016-02-26 10:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-12 16:58 [PATCH RFC] tango4 clk rewrite Mason
2016-02-25 22:08 ` Stephen Boyd
2016-02-26 10:51 ` Mason [this message]
2016-02-26 14:52 ` [PATCH v2] clk: tango4: improve clkgen driver Mason
2016-04-04 9:21 ` [PATCH v3] " Mason
2016-04-13 20:44 ` Mason
2016-04-16 0:16 ` Stephen Boyd
2016-04-16 8:35 ` Mason
2016-05-03 0:36 ` Stephen Boyd
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=56D02E2F.1010908@free.fr \
--to=slash.tmp@free.fr \
--cc=linux-clk@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@codeaurora.org \
--cc=sf84@laposte.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.