Linux IIO development
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: <lee@kernel.org>, <alexandre.torgue@foss.st.com>,
	<daniel.lezcano@linaro.org>, <tglx@linutronix.de>
Cc: <krzk+dt@kernel.org>, <jic23@kernel.org>, <conor+dt@kernel.org>,
	<ukleinek@kernel.org>, <robh@kernel.org>,
	<catalin.marinas@arm.com>, <will@kernel.org>,
	<devicetree@vger.kernel.org>, <wbg@kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>,
	<linux-pwm@vger.kernel.org>, <olivier.moysan@foss.st.com>
Subject: Re: [PATCH v4 4/8] clocksource: stm32-lptimer: add support for stm32mp25
Date: Tue, 8 Apr 2025 16:48:50 +0200	[thread overview]
Message-ID: <d66bd978-820a-4700-92c2-ba52d7db4efb@foss.st.com> (raw)
In-Reply-To: <20250314171451.3497789-5-fabrice.gasnier@foss.st.com>

On 3/14/25 18:14, Fabrice Gasnier wrote:
> On stm32mp25, DIER (former IER) must only be modified when the lptimer
> is enabled. On earlier SoCs, it must be only be modified when it is
> disabled. There's also a new DIEROK flag, to ensure register access
> has completed.
> Add a new "set_evt" routine to be used on stm32mp25, called depending
> on the version register, read by the MFD core (LPTIM_VERR).
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
> ---
> Changes in V4:
> - Daniel suggests to encapsulate IER write into a separate function
>   that manages the enabling/disabling of the LP timer. In addition,
>   DIEROK and ARROK flags checks have been added. So adopt a new routine
>   to set the event into ARR register and enable the interrupt.

Hi all, Daniel,

Does anybody else have additional remarks on this driver ?

I think Lee is waiting for review, before merging the MFD part (at least).

Best Regards,
Thanks,
Fabrice

> Changes in V2:
> - rely on fallback compatible as no specific .data is associated to the
>   driver. Use version data from MFD core.
> - Added interrupt enable register access update in (missed in V1)
> ---
>  drivers/clocksource/timer-stm32-lp.c | 51 +++++++++++++++++++++++++---
>  1 file changed, 47 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-stm32-lp.c b/drivers/clocksource/timer-stm32-lp.c
> index 928da2f6de69..e58932300fb4 100644
> --- a/drivers/clocksource/timer-stm32-lp.c
> +++ b/drivers/clocksource/timer-stm32-lp.c
> @@ -27,6 +27,7 @@ struct stm32_lp_private {
>  	u32 psc;
>  	struct device *dev;
>  	struct clk *clk;
> +	u32 version;
>  };
>  
>  static struct stm32_lp_private*
> @@ -47,12 +48,37 @@ static int stm32_clkevent_lp_shutdown(struct clock_event_device *clkevt)
>  	return 0;
>  }
>  
> -static int stm32_clkevent_lp_set_timer(unsigned long evt,
> -				       struct clock_event_device *clkevt,
> -				       int is_periodic)
> +static int stm32mp25_clkevent_lp_set_evt(struct stm32_lp_private *priv, unsigned long evt)
>  {
> -	struct stm32_lp_private *priv = to_priv(clkevt);
> +	int ret;
> +	u32 val;
> +
> +	/* Enable LPTIMER to be able to write into IER and ARR registers */
> +	regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
> +	/* set next event counter */
> +	regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
> +	/* enable ARR interrupt */
> +	regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
> +
> +	/* Poll DIEROK and ARROK to ensure register access has completed */
> +	ret = regmap_read_poll_timeout_atomic(priv->reg, STM32_LPTIM_ISR, val,
> +					      (val & STM32_LPTIM_DIEROK_ARROK) ==
> +					      STM32_LPTIM_DIEROK_ARROK,
> +					      10, 500);
> +	if (ret) {
> +		dev_err(priv->dev, "access to LPTIM timed out\n");
> +		/* Disable LPTIMER */
> +		regmap_write(priv->reg, STM32_LPTIM_CR, 0);
> +		return ret;
> +	}
> +	/* Clear DIEROK and ARROK flags */
> +	regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_DIEROKCF_ARROKCF);
> +
> +	return 0;
> +}
>  
> +static void stm32_clkevent_lp_set_evt(struct stm32_lp_private *priv, unsigned long evt)
> +{
>  	/* disable LPTIMER to be able to write into IER register*/
>  	regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>  	/* enable ARR interrupt */
> @@ -61,6 +87,22 @@ static int stm32_clkevent_lp_set_timer(unsigned long evt,
>  	regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
>  	/* set next event counter */
>  	regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
> +}
> +
> +static int stm32_clkevent_lp_set_timer(unsigned long evt,
> +				       struct clock_event_device *clkevt,
> +				       int is_periodic)
> +{
> +	struct stm32_lp_private *priv = to_priv(clkevt);
> +	int ret;
> +
> +	if (priv->version == STM32_LPTIM_VERR_23) {
> +		ret = stm32mp25_clkevent_lp_set_evt(priv, evt);
> +		if (ret)
> +			return ret;
> +	} else {
> +		stm32_clkevent_lp_set_evt(priv, evt);
> +	}
>  
>  	/* start counter */
>  	if (is_periodic)
> @@ -176,6 +218,7 @@ static int stm32_clkevent_lp_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	priv->reg = ddata->regmap;
> +	priv->version = ddata->version;
>  	priv->clk = ddata->clk;
>  	ret = clk_prepare_enable(priv->clk);
>  	if (ret)

  reply	other threads:[~2025-04-08 14:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 17:14 [PATCH v4 0/8] Add STM32MP25 LPTIM support: MFD, PWM, IIO, counter, clocksource Fabrice Gasnier
2025-03-14 17:14 ` [PATCH v4 1/8] dt-bindings: mfd: stm32-lptimer: add support for stm32mp25 Fabrice Gasnier
2025-03-14 17:14 ` [PATCH v4 2/8] " Fabrice Gasnier
2025-04-04 14:40   ` Lee Jones
2025-04-24 13:01     ` Lee Jones
2025-04-25 12:50       ` Fabrice Gasnier
2025-03-14 17:14 ` [PATCH v4 3/8] iio: trigger: " Fabrice Gasnier
2025-03-15 12:56   ` Jonathan Cameron
2025-03-27 16:36     ` Fabrice Gasnier
2025-03-31 10:04       ` Jonathan Cameron
2025-03-14 17:14 ` [PATCH v4 4/8] clocksource: " Fabrice Gasnier
2025-04-08 14:48   ` Fabrice Gasnier [this message]
2025-03-14 17:14 ` [PATCH v4 5/8] pwm: stm32-lp: " Fabrice Gasnier
2025-04-04 15:07   ` Uwe Kleine-König
2025-03-14 17:14 ` [PATCH v4 6/8] arm64: defconfig: enable STM32 LP timer clockevent driver Fabrice Gasnier
2025-03-14 17:14 ` [PATCH v4 7/8] arm64: dts: st: add low-power timer nodes on stm32mp251 Fabrice Gasnier
2025-03-14 17:14 ` [PATCH v4 8/8] arm64: dts: st: use lptimer3 as tick broadcast source on stm32mp257f-ev1 Fabrice Gasnier

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=d66bd978-820a-4700-92c2-ba52d7db4efb@foss.st.com \
    --to=fabrice.gasnier@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=olivier.moysan@foss.st.com \
    --cc=robh@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=ukleinek@kernel.org \
    --cc=wbg@kernel.org \
    --cc=will@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