From: Geert Uytterhoeven <geert@linux-m68k.org>
To: claudiu beznea <claudiu.beznea@tuxon.dev>,
mturquette@baylibre.com, sboyd@kernel.org
Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, ulf.hansson@linaro.org,
linus.walleij@linaro.org, gregkh@linuxfoundation.org,
jirislaby@kernel.org, magnus.damm@gmail.com,
catalin.marinas@arm.com, will@kernel.org,
prabhakar.mahadev-lad.rj@bp.renesas.com,
biju.das.jz@bp.renesas.com, quic_bjorande@quicinc.com,
arnd@arndb.de, konrad.dybcio@linaro.org,
neil.armstrong@linaro.org, nfraprado@collabora.com,
rafal@milecki.pl, wsa+renesas@sang-engineering.com,
linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mmc@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-serial@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Subject: Re: [PATCH 18/37] clk: renesas: rzg2l: refactor sd mux driver
Date: Fri, 15 Sep 2023 10:06:27 +0200 [thread overview]
Message-ID: <CAMuHMdWvuP1M2vu9+Kptj-5AkxbtPVeymm5r_02JQbyXdA7F=g@mail.gmail.com> (raw)
In-Reply-To: <1ef2d7d4-93d4-969d-6618-3b81926418d5@tuxon.dev>
Hi Claudiu,
On Fri, Sep 15, 2023 at 9:30 AM claudiu beznea <claudiu.beznea@tuxon.dev> wrote:
> On 14.09.2023 18:18, Geert Uytterhoeven wrote:
> > On Tue, Sep 12, 2023 at 6:52 AM Claudiu <claudiu.beznea@tuxon.dev> wrote:
> >> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> >>
> >> Refactor SD MUX driver to be able to reuse the same code on RZ/G3S.
> >> RZ/G2{L, UL} has a limitation with regards to switching the clock source
> >> for SD MUX (MUX clock source has to be switched to 266MHz before switching
> >> b/w 533MHz and 400MHz). This limitation has been introduced as a clock
> >> notifier that is registered on platform based initialization data thus the
> >> SD MUX code could be reused on RZ/G3S.
> >>
> >> As both RZ/G2{L, UL} and RZ/G3S has specific bits in specific registers
> >> to check if the clock switching has been done, this configuration (register
> >> offset, register bits and bits width) is now passed though
> >> struct cpg_core_clk::sconf (status configuration) from platform specific
> >> initialization code.
> >>
> >> Along with struct cpg_core_clk::sconf the mux table indexes is also
> >
> > indices are
> >
> >> passed from platform specific initialization code.
> >
> > Please also mention the passing of the mux flags, which is added so
> > you can pass CLK_SET_PARENT_GATE for G3S_SEL_PLL4 later.
>
> Ok.
>
> >
> >> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> >
> >> --- a/drivers/clk/renesas/r9a07g043-cpg.c
> >> +++ b/drivers/clk/renesas/r9a07g043-cpg.c
> >> @@ -21,6 +21,10 @@
> >> #define G2UL_SEL_SDHI0 SEL_PLL_PACK(G2UL_CPG_PL2SDHI_DSEL, 0, 2)
> >> #define G2UL_SEL_SDHI1 SEL_PLL_PACK(G2UL_CPG_PL2SDHI_DSEL, 4, 2)
> >>
> >> +/* Clock status configuration. */
> >> +#define G2UL_SEL_SDHI0_STS SEL_PLL_PACK(CPG_CLKSTATUS, 28, 1)
> >> +#define G2UL_SEL_SDHI1_STS SEL_PLL_PACK(CPG_CLKSTATUS, 29, 1)
> >
> > Just like in [PATCH 17/37], there is no real need for the "G2UL_"-prefix.
>
> Ok, I ususlly tend to guard everything with a proper namespace.
Sure, in many cases, that makes good sense.
In this case, not having the prefix makes it easier to compare clock tables:
soc-dts-diff -b drivers/clk/renesas/r9a07g04[34]-cpg.c
(soc-dts-diff ignores the SoC part number, and can be found at
https://github.com/geertu/linux-scripts)
> >> +int rzg2l_cpg_sd_mux_clk_notifier(struct notifier_block *nb, unsigned long event,
> >> + void *data)
> >> +{
> >> + struct clk_notifier_data *cnd = data;
> >> + struct clk_hw *hw = __clk_get_hw(cnd->clk);
> >> + struct clk_hw_data *clk_hw_data = to_clk_hw_data(hw);
> >> + struct rzg2l_cpg_priv *priv = clk_hw_data->priv;
> >> + u32 off = GET_REG_OFFSET(clk_hw_data->conf);
> >> + u32 shift = GET_SHIFT(clk_hw_data->conf);
> >> + const u32 clk_src_266 = 3;
> >> + unsigned long flags;
> >> + u32 bitmask;
> >> + int ret;
> >> +
> >> + if (event != PRE_RATE_CHANGE || (cnd->new_rate / MEGA == 266))
> >> + return 0;
> >> +
> >> + spin_lock_irqsave(&priv->rmw_lock, flags);
> >> +
> >> + /*
> >> + * As per the HW manual, we should not directly switch from 533 MHz to
> >> + * 400 MHz and vice versa. To change the setting from 2’b01 (533 MHz)
> >> + * to 2’b10 (400 MHz) or vice versa, Switch to 2’b11 (266 MHz) first,
> >> + * and then switch to the target setting (2’b01 (533 MHz) or 2’b10
> >> + * (400 MHz)).
> >> + * Setting a value of '0' to the SEL_SDHI0_SET or SEL_SDHI1_SET clock
> >> + * switching register is prohibited.
> >> + * The clock mux has 3 input clocks(533 MHz, 400 MHz, and 266 MHz), and
> >> + * the index to value mapping is done by adding 1 to the index.
> >> + */
> >> + bitmask = (GENMASK(GET_WIDTH(clk_hw_data->conf) - 1, 0) << shift) << 16;
> >> + writel(bitmask | (clk_src_266 << shift), priv->base + off);
> >> +
> >> + /* Wait for the update done. */
> >> + ret = rzg2l_cpg_wait_clk_update_done(priv->base, clk_hw_data->sconf);
> >> +
> >> + spin_unlock_irqrestore(&priv->rmw_lock, flags);
> >> +
> >> + if (ret)
> >> + dev_err(priv->dev, "failed to switch to safe clk source\n");
> >> +
> >> + return ret;
> >> +}
> >> +
> >> +static int rzg2l_register_notifier(struct clk_hw *hw, const struct cpg_core_clk *core,
> >> + struct rzg2l_cpg_priv *priv)
> >> +{
> >> + struct notifier_block *nb;
> >> +
> >> + if (!core->notifier)
> >> + return 0;
> >> +
> >> + nb = devm_kzalloc(priv->dev, sizeof(*nb), GFP_KERNEL);
> >> + if (!nb)
> >> + return -ENOMEM;
> >> +
> >> + nb->notifier_call = core->notifier;
> >> +
> >> + return clk_notifier_register(hw->clk, nb);
> >> +}
> >
> > I am not sure a notifier is the best solution. Basically on RZ/G2L,
> > when changing the parent clock, you need to switch to a fixed
> > intermediate parent first.
> > What about just replacing the fixed clk_src_266 in the old
> > rzg2l_cpg_sd_mux_clk_set_parent() by a (signed) integer in
> > sd_mux_hw_data (specified in DEF_SD_MUX()), representing the index
> > of the intermediate clock?
> > -1 would mean an intermediate parent is not needed.
>
> That should work too but .set_rate() will be bulky for both mux and div.
>
> The idea was to have the .set_rate() common to the mux and the platform
> specificities implemented as notifiers and only the needed platforms to
> instantiate the notifier. And the same approach to be used by the divider
> (patch "[PATCH 19/37] clk: renesas: rzg2l: add a divider clock for RZ/G3S")
>
> With this it looked to me that the final code is more compact .set_rate
> being simple and platform specificities being implemented in notifier
> (valid for both MUX and DIV). The infrastructure is already there for
> notifier to be called before .set_rate().
TBH, I am not that familiar with clock notifiers, so I could use some
guidance from the clock maintainers.
Mike/Stephen: Are clock notifiers the right approach, here and in
[PATCH 19.37]?
> >> --- a/drivers/clk/renesas/rzg2l-cpg.h
> >> +++ b/drivers/clk/renesas/rzg2l-cpg.h
> >> @@ -272,4 +278,9 @@ extern const struct rzg2l_cpg_info r9a07g044_cpg_info;
> >> extern const struct rzg2l_cpg_info r9a07g054_cpg_info;
> >> extern const struct rzg2l_cpg_info r9a09g011_cpg_info;
> >>
> >> +int rzg2l_cpg_sd_mux_clk_notifier(struct notifier_block *nb, unsigned long event, void *data);
> >> +
> >> +/* Macros to be used in platform specific initialization code. */
> >> +#define SD_MUX_NOTIF (&rzg2l_cpg_sd_mux_clk_notifier)
> >
> > Any specific reason you are adding this macro?
>
> It looked to me like a better name to be used in platform specific drivers.
>
> > What is wrong with using &rzg2l_cpg_sd_mux_clk_notifier directly?
>
> Nothing, just that it is a longer than SD_MUX_NOTIF.
It adds another level of indirection for the casual reviewer, and needs
replacement when an SoC arrives that needs a different SD mux notifier.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
next prev parent reply other threads:[~2023-09-15 8:06 UTC|newest]
Thread overview: 118+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 4:51 [PATCH 00/37] Add new Renesas RZ/G3S SoC and RZ/G3S SMARC EVK Claudiu
2023-09-12 4:51 ` [PATCH 01/37] dt-bindings: serial: renesas,scif: document r9a08g045 support Claudiu
2023-09-12 16:00 ` Rob Herring
2023-09-14 9:35 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 02/37] dt-bindings: soc: renesas: document Renesas RZ/G3S SoC variants Claudiu
2023-09-12 16:01 ` Rob Herring
2023-09-14 9:49 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 03/37] dt-bindings: soc: renesas: renesas,rzg2l-sysc: document RZ/G3S SoC Claudiu
2023-09-12 16:01 ` Rob Herring
2023-09-14 9:49 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 04/37] soc: renesas: identify " Claudiu
2023-09-14 9:49 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 05/37] soc: renesas: remove blank lines Claudiu
2023-09-14 9:49 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 06/37] clk: renesas: rzg2l: wait for status bit of SD mux before continuing Claudiu
2023-09-14 11:42 ` Geert Uytterhoeven
2023-09-15 5:35 ` claudiu beznea
2023-09-12 4:51 ` [PATCH 07/37] clk: renesas: rzg2l: lock around writes to mux register Claudiu
2023-09-14 12:13 ` Geert Uytterhoeven
2023-09-15 5:46 ` claudiu beznea
2023-09-12 4:51 ` [PATCH 08/37] clk: renesas: rzg2l: trust value returned by hardware Claudiu
2023-09-12 16:43 ` Sergey Shtylyov
2023-09-14 12:18 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 09/37] clk: renesas: rzg2l: fix computation formula Claudiu
2023-09-14 12:55 ` Geert Uytterhoeven
2023-09-26 11:47 ` claudiu beznea
2023-09-26 14:44 ` Geert Uytterhoeven
2023-09-27 8:00 ` Geert Uytterhoeven
2023-09-28 4:55 ` claudiu beznea
2023-09-12 4:51 ` [PATCH 10/37] clk: renesas: rzg2l: use core->name for clock name Claudiu
2023-09-14 13:04 ` Geert Uytterhoeven
2023-09-15 5:47 ` claudiu beznea
2023-09-18 8:03 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 11/37] clk: renesas: rzg2l: simplify a bit the logic in rzg2l_mod_clock_endisable() Claudiu
2023-09-14 13:06 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 12/37] clk: renesas: rzg2l: reduce the critical area Claudiu
2023-09-14 13:12 ` Geert Uytterhoeven
2023-09-15 5:51 ` claudiu beznea
2023-09-15 7:05 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 13/37] clk: renesas: rzg2l: use FIELD_GET() for PLL register fields Claudiu
2023-09-14 13:19 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 14/37] clk: renesas: rzg2l: use u32 for flag and mux_flags Claudiu
2023-09-14 13:29 ` Geert Uytterhoeven
2023-09-18 8:03 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 15/37] clk: renesas: rzg2l: add support for RZ/G3S PLL Claudiu
2023-09-14 13:58 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 16/37] clk: renesas: rzg2l: add struct clk_hw_data Claudiu
2023-09-14 15:17 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 17/37] clk: renesas: rzg2l: remove CPG_SDHI_DSEL from generic header Claudiu
2023-09-14 15:18 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 18/37] clk: renesas: rzg2l: refactor sd mux driver Claudiu
2023-09-14 15:18 ` Geert Uytterhoeven
2023-09-15 7:30 ` claudiu beznea
2023-09-15 8:06 ` Geert Uytterhoeven [this message]
2023-09-12 4:51 ` [PATCH 19/37] clk: renesas: rzg2l: add a divider clock for RZ/G3S Claudiu
2023-09-12 4:51 ` [PATCH 20/37] dt-bindings: clock: renesas,rzg2l-cpg: document RZ/G3S SoC Claudiu
2023-09-12 16:02 ` Rob Herring
2023-09-15 11:58 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 21/37] dt-bindings: clock: add r9a08g045 CPG clocks and resets definitions Claudiu
2023-09-12 16:03 ` Rob Herring
2023-09-14 15:26 ` Geert Uytterhoeven
2023-09-15 7:24 ` Krzysztof Kozlowski
2023-09-15 7:38 ` Geert Uytterhoeven
2023-09-15 7:42 ` Krzysztof Kozlowski
2023-09-15 11:59 ` Geert Uytterhoeven
2023-09-28 4:54 ` claudiu beznea
2023-09-28 7:25 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 22/37] clk: renesas: add minimal boot support for RZ/G3S SoC Claudiu
2023-09-15 12:52 ` Geert Uytterhoeven
2023-09-18 6:20 ` claudiu beznea
2023-09-18 7:00 ` Geert Uytterhoeven
2023-09-18 7:50 ` claudiu beznea
2023-09-18 9:05 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 23/37] pinctrl: renesas: rzg2l: index all registers based on port offset Claudiu
2023-09-20 13:20 ` Geert Uytterhoeven
2023-09-20 13:43 ` Lad, Prabhakar
2023-09-12 4:51 ` [PATCH 24/37] pinctrl: renesas: rzg2l: adapt for different SD, PWPR register offsets Claudiu
2023-09-21 12:07 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 25/37] pinctrl: renesas: rzg2l: adapt function number for RZ/G3S Claudiu
2023-09-21 12:51 ` Geert Uytterhoeven
2023-09-26 9:55 ` claudiu beznea
2023-09-26 14:23 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 26/37] pinctrl: renesas: rzg2l: move ds and oi to SoC specific configuration Claudiu
2023-09-21 12:54 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 27/37] pinctrl: renesas: rzg2l: add support for different ds values on different groups Claudiu
2023-09-21 13:07 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 28/37] pinctrl: renesas: rzg2l: make struct rzg2l_pinctrl_data::dedicated_pins constant Claudiu
2023-09-21 13:08 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 29/37] dt-bindings: pinctrl: renesas: document RZ/G3S SoC Claudiu
2023-09-12 16:13 ` Rob Herring
2023-09-21 15:00 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 30/37] pinctrl: renesas: rzg2l: add support for " Claudiu
2023-09-21 14:58 ` Geert Uytterhoeven
2023-09-26 10:58 ` claudiu beznea
2023-09-26 14:29 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 31/37] dt-bindings: mmc: renesas,sdhi: Document RZ/G3S support Claudiu
2023-09-12 16:13 ` Rob Herring
2023-09-14 14:47 ` Ulf Hansson
2023-09-14 15:35 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 32/37] arm64: dts: renesas: add initial DTSI for RZ/G3S SoC Claudiu
2023-09-15 13:17 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 33/37] arm64: dts: renesas: rzg3l-smarc-som: add initial support for RZ/G3S SMARC Carrier-II SoM Claudiu
2023-09-15 14:28 ` Geert Uytterhoeven
2023-09-18 6:02 ` claudiu beznea
2023-09-12 4:51 ` [PATCH 34/37] arm64: dts: renesas: rzg3s-smarc: add initial device tree for RZ SMARC Carrier-II board Claudiu
2023-09-15 14:32 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 35/37] dt-bindings: arm: renesas: document SMARC Carrier-II EVK Claudiu
2023-09-12 16:16 ` Rob Herring
2023-09-13 5:32 ` claudiu beznea
2023-09-13 15:16 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 36/37] arm64: dts: renesas: r9a08g045s33-smarc: add initial device tree for RZ/G3S SMARC EVK board Claudiu
2023-09-21 15:02 ` Geert Uytterhoeven
2023-09-12 4:51 ` [PATCH 37/37] arm64: defconfig: enable RZ/G3S (R9A08G045) SoC Claudiu
2023-09-15 14:34 ` Geert Uytterhoeven
2023-09-12 8:55 ` [PATCH 00/37] Add new Renesas RZ/G3S SoC and RZ/G3S SMARC EVK Linus Walleij
2023-09-12 9:03 ` Geert Uytterhoeven
2023-09-12 9:05 ` Linus Walleij
2023-09-13 5:40 ` claudiu beznea
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='CAMuHMdWvuP1M2vu9+Kptj-5AkxbtPVeymm5r_02JQbyXdA7F=g@mail.gmail.com' \
--to=geert@linux-m68k.org \
--cc=arnd@arndb.de \
--cc=biju.das.jz@bp.renesas.com \
--cc=catalin.marinas@arm.com \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mturquette@baylibre.com \
--cc=neil.armstrong@linaro.org \
--cc=nfraprado@collabora.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=quic_bjorande@quicinc.com \
--cc=rafal@milecki.pl \
--cc=robh+dt@kernel.org \
--cc=sboyd@kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=will@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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).