From: Sangyun Kim <sangyun.kim@snu.ac.kr>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
claudiu.beznea@tuxon.dev, linux-pwm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] pwm: atmel-tcb: Cache clock rates and mark chip as atomic
Date: Wed, 22 Apr 2026 13:49:40 +0900 [thread overview]
Message-ID: <20260422044940.tse3ek7jlv3x2dbt@nunu> (raw)
In-Reply-To: <aedfEzeRH5tH0-Fb@monoceros>
On Tue, Apr 21, 2026 at 01:40:55 PM +0200, Uwe Kleine-König wrote:
>Hello Sangyun,
Hi Uwe,
Thanks for the review.
>
>On Sun, Apr 19, 2026 at 05:08:38PM +0900, Sangyun Kim wrote:
>> @@ -438,16 +441,33 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
>> if (err)
>> goto err_gclk;
>>
>> + err = clk_rate_exclusive_get(tcbpwmc->clk);
>> + if (err)
>> + goto err_disable_clk;
>> +
>> + err = clk_rate_exclusive_get(tcbpwmc->slow_clk);
>> + if (err)
>> + goto err_clk_unlock;
>> +
>> + tcbpwmc->rate = clk_get_rate(tcbpwmc->clk);
>> + tcbpwmc->slow_rate = clk_get_rate(tcbpwmc->slow_clk);
>> +
>
>Only one concern left: clk_get_rate() should only be called on enabled
>clocks. I don't know the architecture details and how expensive it is to
>have .clk enabled (or if it's enabled anyhow).
>
>If you're ok, I'd squash the following diff into your patch:
That makes sense. clk_get_rate() should indeed only be used on enabled
clocks, and your change is the simplest way to ensure correctness while
respecting the clk API constraints. I’m happy with squashing your diff
into my patch.
>
>diff --git a/drivers/pwm/pwm-atmel-tcb.c b/drivers/pwm/pwm-atmel-tcb.c
>index 1a2832f1ace2..3d30aeab507e 100644
>--- a/drivers/pwm/pwm-atmel-tcb.c
>+++ b/drivers/pwm/pwm-atmel-tcb.c
>@@ -437,13 +437,17 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
> tcbpwmc->channel = channel;
> tcbpwmc->width = config->counter_width;
>
>- err = clk_prepare_enable(tcbpwmc->slow_clk);
>+ err = clk_prepare_enable(tcbpwmc->clk);
> if (err)
> goto err_gclk;
>
>+ err = clk_prepare_enable(tcbpwmc->slow_clk);
>+ if (err)
>+ goto err_disable_clk;;
>+
> err = clk_rate_exclusive_get(tcbpwmc->clk);
> if (err)
>- goto err_disable_clk;
>+ goto err_disable_slow_clk;
>
> err = clk_rate_exclusive_get(tcbpwmc->slow_clk);
> if (err)
>@@ -469,6 +473,9 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
> clk_rate_exclusive_put(tcbpwmc->clk);
>
> err_disable_clk:
>+ clk_disable_unprepare(tcbpwmc->clk);
>+
>+err_disable_slow_clk:
> clk_disable_unprepare(tcbpwmc->slow_clk);
>
> err_gclk:
>@@ -492,6 +499,7 @@ static void atmel_tcb_pwm_remove(struct platform_device *pdev)
>
> clk_rate_exclusive_put(tcbpwmc->slow_clk);
> clk_rate_exclusive_put(tcbpwmc->clk);
>+ clk_disable_unprepare(tcbpwmc->clk);
> clk_disable_unprepare(tcbpwmc->slow_clk);
> clk_put(tcbpwmc->gclk);
> clk_put(tcbpwmc->clk);
>
>
>This has the downside that clk is kept enabled the whole driver
>lifetime, but that's the easiest way to make your fix honor the clk API
>constraints. This allows to fast-track the patch fixing the sleeping
>function called from invalid context issue and the optimisation can then
>be addressed with more time during the next development cycles.
Keeping the clock enabled for the driver lifetime is acceptable for now
to fast-track the fix, and we can revisit potential optimizations in a
follow-up patch.
Thanks again for the suggestion.
>
>Best regards
>Uwe
Best regards,
Sangyun
next prev parent reply other threads:[~2026-04-22 4:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 9:34 [PATCH] pwm: atmel-tcb: Fix sleeping function called from invalid context Sangyun Kim
2026-04-15 15:12 ` Uwe Kleine-König
2026-04-19 8:08 ` [PATCH v2] pwm: atmel-tcb: Cache clock rates and mark chip as atomic Sangyun Kim
2026-04-21 11:40 ` Uwe Kleine-König
2026-04-22 4:49 ` Sangyun Kim [this message]
2026-04-24 10:46 ` Uwe Kleine-König
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=20260422044940.tse3ek7jlv3x2dbt@nunu \
--to=sangyun.kim@snu.ac.kr \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=ukleinek@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