public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@mailbox.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>
Cc: linux-clk@vger.kernel.org,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH v2] clk: renesas: cpg-mssr: Read back reset registers to assure values latched
Date: Mon, 22 Sep 2025 18:24:08 +0200	[thread overview]
Message-ID: <196d5c6d-0bd6-4dd5-b3ea-c8166b2bd830@mailbox.org> (raw)
In-Reply-To: <CAMuHMdWncCJQ_5uiATC+JhGr8K2ewO72L0DTWXtcx-OF-P=zVQ@mail.gmail.com>

On 9/22/25 1:35 PM, Geert Uytterhoeven wrote:

Hello Geert,

>> --- a/drivers/clk/renesas/renesas-cpg-mssr.c
>> +++ b/drivers/clk/renesas/renesas-cpg-mssr.c
>> @@ -676,18 +676,31 @@ static int __init cpg_mssr_add_clk_domain(struct device *dev,
>>
>>   #define rcdev_to_priv(x)       container_of(x, struct cpg_mssr_priv, rcdev)
>>
>> -static int cpg_mssr_reset(struct reset_controller_dev *rcdev,
>> -                         unsigned long id)
>> +static int cpg_mssr_writel_with_latch(struct reset_controller_dev *rcdev,
>> +                                     char *func, bool set, unsigned long id)
> 
> This function does a bit more than writel()-with-latch, so please find
> a more suitable name. Or... continue reading.

I did so in V4.

>>   {
>>          struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
>>          unsigned int reg = id / 32;
>>          unsigned int bit = id % 32;
>> +       const u16 reset_reg = set ? priv->reset_regs[reg] : priv->reset_clear_regs[reg];
>>          u32 bitmask = BIT(bit);
>>
>> -       dev_dbg(priv->dev, "reset %u%02u\n", reg, bit);
>> +       if (func)
>> +               dev_dbg(priv->dev, "%s %u%02u\n", func, reg, bit);
>> +
>> +       writel(bitmask, priv->pub.base0 + reset_reg);
>> +       readl(priv->pub.base0 + reset_reg);
>> +
>> +       return 0;
>> +}
> 
> Now, do we want a special de(reset)-with-latch() function (which does
> reduce code duplication), or would a simpler variant be more useful?
> After this, we have three different "dummy read" mechanisms in this
> driver:
> 
>    1. Clock enable/disable and resume on RZ/A:
> 
>           writeb(value, priv->pub.base0 + priv->control_regs[reg]);
> 
>           /* dummy read to ensure write has completed */
>           readb(priv->pub.base0 + priv->control_regs[reg]);
>           barrier_data(priv->pub.base0 + priv->control_regs[reg]);
> 
>    2. Reset handling on R-Car:
> 
>           writel(bitmask, priv->pub.base0 + reset_reg);
>           readl(priv->pub.base0 + reset_reg);
> 
>    3. Reset release on RZ/T2H and RZ/N2H:

Maybe T2H support is not yet upstream , even in next ?

In any case, 2 and 3 could be merged into single write-and-latch function.

>           writel(bitmask, priv->pub.base0 + priv->reset_regs[reg]);
> 
>           /*
>            * To secure processing after release from a module reset, dummy read
>            * the same register at least seven times.
>            */
>           for (i = 0; i < 7; i++)
>                   readl(priv->pub.base0 + priv->reset_regs[reg]);
> 
> So perhaps a simple helper like
> 
>      void writel_with_latch(u32 val, volatile void __iomem *addr, unsigned int n)
>      {
>              writel(val, addr);
>              while (n-- > 0)
>                      readl(addr);
>      }
> 
> ? Do we need barrier_data(), like on RZ/A?

I think so.

> Unfortunately RZ/A uses byte-wide registers, so that one needs another
> copy.
> 
>> +
>> +static int cpg_mssr_reset(struct reset_controller_dev *rcdev,
>> +                         unsigned long id)
>> +{
>> +       struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
> 
> "priv" is unused (no compiler warning on your side?)
I also have [PATCH] clk: renesas: cpg-mssr: Add missing 1ms delay into 
reset toggle callback applied in tree, rebase was not accurate, dropped 
in V4.

  reply	other threads:[~2025-09-22 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18 13:44 [PATCH v2] clk: renesas: cpg-mssr: Read back reset registers to assure values latched Marek Vasut
2025-09-20  4:26 ` Wolfram Sang
2025-09-22 11:35 ` Geert Uytterhoeven
2025-09-22 16:24   ` Marek Vasut [this message]
2025-09-23  7:11     ` Geert Uytterhoeven
2025-09-23  9:08       ` Marek Vasut

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=196d5c6d-0bd6-4dd5-b3ea-c8166b2bd830@mailbox.org \
    --to=marek.vasut@mailbox.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.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