linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Thierry Reding" <thierry.reding@gmail.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	<linux-pwm@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>, <kernel@pengutronix.de>
Subject: Re: [PATCH 4/5] pwm: stm32: Implement .get_state()
Date: Tue, 14 Nov 2023 14:26:57 +0100	[thread overview]
Message-ID: <09b09170-697e-44ac-aae1-581ba29481bf@foss.st.com> (raw)
In-Reply-To: <20231019200658.1754190-11-u.kleine-koenig@pengutronix.de>

On 10/19/23 22:07, Uwe Kleine-König wrote:
> From: Philipp Zabel <p.zabel@pengutronix.de>
> 
> Implement the &pwm_ops->get_state callback so drivers can inherit PWM
> state set by the bootloader.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> [ukl: split off from a patch that also fixes clk enable count in .probe()]
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/pwm-stm32.c | 42 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 

Hi Uwe,

You can add my:
Reviewed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Thanks,
Fabrice

> diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> index cc6cae07c02c..68239567a564 100644
> --- a/drivers/pwm/pwm-stm32.c
> +++ b/drivers/pwm/pwm-stm32.c
> @@ -471,8 +471,50 @@ static int stm32_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *pwm,
>  	return ret;
>  }
>  
> +static int stm32_pwm_get_state(struct pwm_chip *chip,
> +			       struct pwm_device *pwm, struct pwm_state *state)
> +{
> +	struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
> +	int ch = pwm->hwpwm;
> +	unsigned long rate;
> +	u32 ccer, psc, arr, ccr;
> +	u64 dty, prd;
> +	int ret;
> +
> +	mutex_lock(&priv->lock);
> +
> +	ret = regmap_read(priv->regmap, TIM_CCER, &ccer);
> +	if (ret)
> +		goto out;
> +
> +	state->enabled = ccer & (TIM_CCER_CC1E << (ch * 4));
> +	state->polarity = (ccer & (TIM_CCER_CC1P << (ch * 4))) ?
> +			  PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL;
> +	ret = regmap_read(priv->regmap, TIM_PSC, &psc);
> +	if (ret)
> +		goto out;
> +	ret = regmap_read(priv->regmap, TIM_ARR, &arr);
> +	if (ret)
> +		goto out;
> +	ret = regmap_read(priv->regmap, TIM_CCR1 + 4 * ch, &ccr);
> +	if (ret)
> +		goto out;
> +
> +	rate = clk_get_rate(priv->clk);
> +
> +	prd = (u64)NSEC_PER_SEC * (psc + 1) * (arr + 1);
> +	state->period = DIV_ROUND_UP_ULL(prd, rate);
> +	dty = (u64)NSEC_PER_SEC * (psc + 1) * ccr;
> +	state->duty_cycle = DIV_ROUND_UP_ULL(dty, rate);
> +
> +out:
> +	mutex_unlock(&priv->lock);
> +	return ret;
> +}
> +
>  static const struct pwm_ops stm32pwm_ops = {
>  	.apply = stm32_pwm_apply_locked,
> +	.get_state = stm32_pwm_get_state,
>  	.capture = IS_ENABLED(CONFIG_DMA_ENGINE) ? stm32_pwm_capture : NULL,
>  };
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-11-14 13:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 20:06 [PATCH 0/5] pwm: stm32: Cleanups, get_state() and proper hw take over Uwe Kleine-König
2023-10-19 20:07 ` [PATCH 1/5] pwm: stm32: Replace write_ccrx with regmap_write Uwe Kleine-König
2023-11-14 13:26   ` Fabrice Gasnier
2023-10-19 20:07 ` [PATCH 2/5] pwm: stm32: Make ch parameter unsigned Uwe Kleine-König
2023-11-14 13:26   ` Fabrice Gasnier
2023-10-19 20:07 ` [PATCH 3/5] pwm: stm32: Use hweight32 in stm32_pwm_detect_channels Uwe Kleine-König
2023-11-14 13:26   ` Fabrice Gasnier
2023-10-19 20:07 ` [PATCH 4/5] pwm: stm32: Implement .get_state() Uwe Kleine-König
2023-11-14 13:26   ` Fabrice Gasnier [this message]
2023-10-19 20:07 ` [PATCH 5/5] pwm: stm32: Fix enable count for clk in .probe() Uwe Kleine-König
2023-11-14 13:35   ` Fabrice Gasnier
2023-11-14 21:20     ` Uwe Kleine-König
2023-11-15  9:02       ` Fabrice Gasnier
2023-11-15 21:01         ` Uwe Kleine-König
2023-11-16 15:05           ` Fabrice Gasnier
2023-11-28 17:49 ` [PATCH 0/5] pwm: stm32: Cleanups, get_state() and proper hw take over Thierry Reding

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=09b09170-697e-44ac-aae1-581ba29481bf@foss.st.com \
    --to=fabrice.gasnier@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).