[PATCH 3/4] clk: renesas: rzv2h: Re-assert reset on deassert timeout

Tommaso Merciai posted 4 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 3/4] clk: renesas: rzv2h: Re-assert reset on deassert timeout
Posted by Tommaso Merciai 1 month, 2 weeks ago
Prevent issues during reset deassertion by re-asserting the reset if a
timeout occurs when trying to deassert. This ensures the reset line is in a
known state and improves reliability for hardware that may not immediately
clear the reset monitor bit.

Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 drivers/clk/renesas/rzv2h-cpg.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/renesas/rzv2h-cpg.c b/drivers/clk/renesas/rzv2h-cpg.c
index 58ccbae0f904..469f40894c43 100644
--- a/drivers/clk/renesas/rzv2h-cpg.c
+++ b/drivers/clk/renesas/rzv2h-cpg.c
@@ -854,6 +854,7 @@ static int __rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
 	u32 mask = BIT(priv->resets[id].reset_bit);
 	u8 monbit = priv->resets[id].mon_bit;
 	u32 value = mask << 16;
+	int ret;
 
 	dev_dbg(rcdev->dev, "%s id:%ld offset:0x%x\n",
 		assert ? "assert" : "deassert", id, reg);
@@ -865,9 +866,16 @@ static int __rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
 	reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
 	mask = BIT(monbit);
 
-	return readl_poll_timeout_atomic(priv->base + reg, value,
-					 assert ? (value & mask) : !(value & mask),
-					 10, 200);
+	ret = readl_poll_timeout_atomic(priv->base + reg, value,
+					assert ? (value & mask) : !(value & mask),
+					10, 200);
+	if (ret && !assert) {
+		dev_warn(rcdev->dev, "deassert timeout, re-asserting reset id %ld\n", id);
+		value = mask << 16;
+		writel(value, priv->base + GET_RST_OFFSET(priv->resets[id].reset_index));
+	}
+
+	return ret;
 }
 
 static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
-- 
2.43.0
Re: [PATCH 3/4] clk: renesas: rzv2h: Re-assert reset on deassert timeout
Posted by Geert Uytterhoeven 1 month ago
Hi Tommaso,

On Wed, 20 Aug 2025 at 12:05, Tommaso Merciai
<tommaso.merciai.xr@bp.renesas.com> wrote:
> Prevent issues during reset deassertion by re-asserting the reset if a
> timeout occurs when trying to deassert. This ensures the reset line is in a
> known state and improves reliability for hardware that may not immediately
> clear the reset monitor bit.
>
> Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>

Thanks for your patch!

> --- a/drivers/clk/renesas/rzv2h-cpg.c
> +++ b/drivers/clk/renesas/rzv2h-cpg.c
> @@ -865,9 +866,16 @@ static int __rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
>         reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
>         mask = BIT(monbit);
>
> -       return readl_poll_timeout_atomic(priv->base + reg, value,
> -                                        assert ? (value & mask) : !(value & mask),
> -                                        10, 200);
> +       ret = readl_poll_timeout_atomic(priv->base + reg, value,
> +                                       assert ? (value & mask) : !(value & mask),
> +                                       10, 200);
> +       if (ret && !assert) {
> +               dev_warn(rcdev->dev, "deassert timeout, re-asserting reset id %ld\n", id);
> +               value = mask << 16;
> +               writel(value, priv->base + GET_RST_OFFSET(priv->resets[id].reset_index));
> +       }

Same questions as for the previous patch:
Is this an issue you've seen during actual use?
Would it make sense to print warnings on assertion timeouts, too?

> +
> +       return ret;
>  }
>
>  static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

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
Re: [PATCH 3/4] clk: renesas: rzv2h: Re-assert reset on deassert timeout
Posted by Tommaso Merciai 1 month ago
Hi Geert,
Thanks for your review!

On Tue, Sep 02, 2025 at 02:19:16PM +0200, Geert Uytterhoeven wrote:
> Hi Tommaso,
> 
> On Wed, 20 Aug 2025 at 12:05, Tommaso Merciai
> <tommaso.merciai.xr@bp.renesas.com> wrote:
> > Prevent issues during reset deassertion by re-asserting the reset if a
> > timeout occurs when trying to deassert. This ensures the reset line is in a
> > known state and improves reliability for hardware that may not immediately
> > clear the reset monitor bit.
> >
> > Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> 
> Thanks for your patch!
> 
> > --- a/drivers/clk/renesas/rzv2h-cpg.c
> > +++ b/drivers/clk/renesas/rzv2h-cpg.c
> > @@ -865,9 +866,16 @@ static int __rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
> >         reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
> >         mask = BIT(monbit);
> >
> > -       return readl_poll_timeout_atomic(priv->base + reg, value,
> > -                                        assert ? (value & mask) : !(value & mask),
> > -                                        10, 200);
> > +       ret = readl_poll_timeout_atomic(priv->base + reg, value,
> > +                                       assert ? (value & mask) : !(value & mask),
> > +                                       10, 200);
> > +       if (ret && !assert) {
> > +               dev_warn(rcdev->dev, "deassert timeout, re-asserting reset id %ld\n", id);
> > +               value = mask << 16;
> > +               writel(value, priv->base + GET_RST_OFFSET(priv->resets[id].reset_index));
> > +       }
> 
> Same questions as for the previous patch:
> Is this an issue you've seen during actual use?
> Would it make sense to print warnings on assertion timeouts, too?

Same here.

Thank & Regards,
Tommaso

> 
> > +
> > +       return ret;
> >  }
> >
> >  static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
> 
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> 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