From: Mikko Perttunen <mperttunen@nvidia.com>
To: "Thierry Reding" <thierry.reding@kernel.org>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>
Cc: linux-pwm@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH v1 6/6] pwm: tegra: Implement .get_state()
Date: Wed, 15 Jul 2026 14:09:27 +0900 [thread overview]
Message-ID: <nEQu20cHS-K6rBZ3Lhz3eQ@nvidia.com> (raw)
In-Reply-To: <33b13f17d7135923d08e2ff40c867803e19609b9.1784030076.git.ukleinek@kernel.org>
On Tuesday, July 14, 2026 9:02 PM Uwe Kleine-König wrote:
> The registers of the PWM IP are readable. Use that to implement the
> .get_state() callback.
I swear I was going to implement this after the Tegra264 series was
accepted, but I don't mind this way either.. :)
>
> Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
> ---
> drivers/pwm/pwm-tegra.c | 48 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index 8e5e7e37f4ff..79bfc7589db8 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
> @@ -309,8 +309,56 @@ static int tegra_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> return err;
> }
>
> +static int tegra_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,(((1 << pc->soc->scale_width) - 1))
> + struct pwm_state *state)
> +{
> + struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
> + int rc;
> + u32 val;
> +
> + rc = pm_runtime_resume_and_get(pwmchip_parent(chip));
> + if (rc)
> + return rc;
> +
> + val = tegra_pwm_readl(pwm, pc->soc->enable_reg);
> + if (val & TEGRA_PWM_ENABLE) {
> + u32 scale, pwm0;
> +
> + if (pc->soc->enable_reg != TEGRA_PWM_CSR_0)
> + val = tegra_pwm_readl(pwm, TEGRA_PWM_CSR_0);
> +
> + scale = (val >> TEGRA_PWM_SCALE_SHIFT) & (((1 << pc->soc->scale_width) - 1));
There's one unnecessary pair of parentheses.
> + pwm0 = (val >> TEGRA_PWM_DUTY_SHIFT) & (2 * TEGRA_PWM_DEPTH - 1);
> +
> + if (pwm0 > TEGRA_PWM_DEPTH)
> + pwm0 = TEGRA_PWM_DEPTH;
> +
> + /*
> + * scale + 1 is at most 1 << 17, TEGRA_PWM_DEPTH is 256, so the
> + * multiplication for .period doesn't overflow a u64. With
> + * pwm0 ≤ TEGRA_PWM_DEPTH, .duty_cycle is also fine.
> + */
> + *state = (struct pwm_state){
> + .period = DIV64_U64_ROUND_UP((u64)(scale + 1) * TEGRA_PWM_DEPTH * NSEC_PER_SEC, pc->clk_rate),
> + .duty_cycle = DIV64_U64_ROUND_UP((u64)(scale + 1) * pwm0 * NSEC_PER_SEC, pc->clk_rate),
> + .polarity = PWM_POLARITY_NORMAL,
> + .enabled = true,
> + };
> +
> + } else {
> + *state = (struct pwm_state){
> + .enabled = false,
> + };
> + }
> +
> + pm_runtime_put(pwmchip_parent(chip));
> +
> + return 0;
> +}
> +
> static const struct pwm_ops tegra_pwm_ops = {
> .apply = tegra_pwm_apply,
> + .get_state = tegra_pwm_get_state,
> };
>
> static int tegra_pwm_probe(struct platform_device *pdev)
> --
> 2.55.0.11.g153666a7d9bb
>
>
Reviewed-by: Mikko Perttunen <mperttunen@nvidia.com>
prev parent reply other threads:[~2026-07-15 5:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 12:02 [PATCH v1 0/6] pwm: tegra: Cleanups and .get_state() Uwe Kleine-König
2026-07-14 12:02 ` [PATCH v1 1/6] pwm: tegra: Check for match_data being NULL Uwe Kleine-König
2026-07-15 4:11 ` Mikko Perttunen
2026-07-14 12:02 ` [PATCH v1 2/6] pwm: tegra: Make use of dev_err_probe() Uwe Kleine-König
2026-07-15 4:17 ` Mikko Perttunen
2026-07-14 12:02 ` [PATCH v1 3/6] pwm: tegra: Use devm function for pm_runtime_enable() Uwe Kleine-König
2026-07-15 4:31 ` Mikko Perttunen
2026-07-14 12:02 ` [PATCH v1 4/6] pwm: tegra: Simplify using devm_reset_control_get_exclusive_deasserted() Uwe Kleine-König
2026-07-14 12:12 ` Philipp Zabel
2026-07-14 14:07 ` Uwe Kleine-König
2026-07-15 4:50 ` Mikko Perttunen
2026-07-14 12:02 ` [PATCH v1 5/6] pwm: tegra: Simplify using devm_pwmchip_add() Uwe Kleine-König
2026-07-14 12:02 ` [PATCH v1 6/6] pwm: tegra: Implement .get_state() Uwe Kleine-König
2026-07-15 5:09 ` Mikko Perttunen [this message]
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=nEQu20cHS-K6rBZ3Lhz3eQ@nvidia.com \
--to=mperttunen@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=thierry.reding@kernel.org \
--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