[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <wah57av7ypb42zcaosx7n64j6qmmcq5ylhgnde2brbiy6o7sun@7rqkr6ke3g5k>
Date: Sun, 30 Nov 2025 09:39:08 +0100
From: Uwe Kleine-König <ukleinek@...nel.org>
To: Biju <biju.das.au@...il.com>
Cc: Philipp Zabel <p.zabel@...gutronix.de>,
Biju Das <biju.das.jz@...renesas.com>, linux-pwm@...r.kernel.org, linux-kernel@...r.kernel.org,
Geert Uytterhoeven <geert+renesas@...der.be>, Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@...renesas.com>,
linux-renesas-soc@...r.kernel.org, linux-pm@...r.kernel.org
Subject: Re: [PATCH v3 6/8] pwm: rzg2l-gpt: Add suspend/resume support
On Tue, Sep 23, 2025 at 03:45:10PM +0100, Biju wrote:
> +static int rzg2l_gpt_suspend(struct device *dev)
> +{
> + struct pwm_chip *chip = dev_get_drvdata(dev);
> + struct rzg2l_gpt_chip *rzg2l_gpt = to_rzg2l_gpt_chip(chip);
> + unsigned int i;
> +
> + for (i = 0; i < RZG2L_MAX_HW_CHANNELS; i++) {
> + if (!rzg2l_gpt->channel_enable_count[i])
> + continue;
> +
> + rzg2l_gpt->hw_cache[i].gtpr = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTPR(i));
> + rzg2l_gpt->hw_cache[i].gtccr[0] = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCCR(i, 0));
> + rzg2l_gpt->hw_cache[i].gtccr[1] = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCCR(i, 1));
> + rzg2l_gpt->hw_cache[i].gtcr = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTCR(i));
> + rzg2l_gpt->hw_cache[i].gtior = rzg2l_gpt_read(rzg2l_gpt, RZG2L_GTIOR(i));
> + }
> +
> + clk_disable_unprepare(rzg2l_gpt->clk);
> + clk_disable_unprepare(rzg2l_gpt->bus_clk);
> + reset_control_assert(rzg2l_gpt->rst_s);
> + reset_control_assert(rzg2l_gpt->rst);
> +
> + return 0;
> +}
> +
> +static int rzg2l_gpt_resume(struct device *dev)
> +{
> + struct pwm_chip *chip = dev_get_drvdata(dev);
> + struct rzg2l_gpt_chip *rzg2l_gpt = to_rzg2l_gpt_chip(chip);
> + unsigned int i;
> + int ret;
> +
> + ret = reset_control_deassert(rzg2l_gpt->rst);
> + if (ret)
> + return ret;
> +
> + ret = reset_control_deassert(rzg2l_gpt->rst_s);
> + if (ret)
> + goto fail_reset;
> +
> + ret = clk_prepare_enable(rzg2l_gpt->bus_clk);
> + if (ret)
> + goto fail_reset_all;
> +
> + ret = clk_prepare_enable(rzg2l_gpt->clk);
> + if (ret)
> + goto fail_bus_clk;
> +
> + for (i = 0; i < RZG2L_MAX_HW_CHANNELS; i++) {
> + if (!rzg2l_gpt->channel_enable_count[i])
> + continue;
> +
> + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTPR(i), rzg2l_gpt->hw_cache[i].gtpr);
> + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTCCR(i, 0), rzg2l_gpt->hw_cache[i].gtccr[0]);
> + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTCCR(i, 1), rzg2l_gpt->hw_cache[i].gtccr[1]);
> + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTCR(i), rzg2l_gpt->hw_cache[i].gtcr);
> + rzg2l_gpt_write(rzg2l_gpt, RZG2L_GTIOR(i), rzg2l_gpt->hw_cache[i].gtior);
> + }
> +
> + return 0;
> +fail_bus_clk:
> + clk_disable_unprepare(rzg2l_gpt->bus_clk);
> +fail_reset_all:
> + reset_control_assert(rzg2l_gpt->rst_s);
> +fail_reset:
> + reset_control_assert(rzg2l_gpt->rst);
> + return ret;
I wonder what happens if these calls in the error path fail. I think the
correct way would be to track the actual state to handle the state on
the next invokation for .resume() properly. But note that suspend/resume
is a somewhat blind spot for me, so I'm unsure here. (And I'm aware that
most resume callbacks don't cope cleanly here.)
I added linux-pm to Cc:, maybe someone can speak up about the
expectations here?
Best regards
Uwe
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists