devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>, <lee@kernel.org>,
	<ukleinek@kernel.org>, <alexandre.torgue@foss.st.com>,
	<robh@kernel.org>, <krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<jic23@kernel.org>, <tglx@linutronix.de>
Cc: <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 v3 4/8] clocksource: stm32-lptimer: add support for stm32mp25
Date: Thu, 13 Mar 2025 18:04:25 +0100	[thread overview]
Message-ID: <c0aec002-7889-4ec5-a438-e7e90d8da13f@foss.st.com> (raw)
In-Reply-To: <83283a94-6833-4d7d-8d89-6ba42b43b96c@linaro.org>

On 3/7/25 16:12, Daniel Lezcano wrote:
> On 05/03/2025 10:49, 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. Read the LPTIM_VERR register to properly manage the enable
>> state, before accessing IER.
>>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
>> ---
>> 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 | 26 ++++++++++++++++++++++----
>>   1 file changed, 22 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/clocksource/timer-stm32-lp.c
>> b/drivers/clocksource/timer-stm32-lp.c
>> index a4c95161cb22..96d975adf7a4 100644
>> --- a/drivers/clocksource/timer-stm32-lp.c
>> +++ b/drivers/clocksource/timer-stm32-lp.c
>> @@ -25,6 +25,7 @@ struct stm32_lp_private {
>>       struct clock_event_device clkevt;
>>       unsigned long period;
>>       struct device *dev;
>> +    bool ier_wr_enabled;    /* Enables LPTIMER before writing into
>> IER register */
>>   };
>>     static struct stm32_lp_private*
>> @@ -37,8 +38,15 @@ static int stm32_clkevent_lp_shutdown(struct
>> clock_event_device *clkevt)
>>   {
>>       struct stm32_lp_private *priv = to_priv(clkevt);
>>   -    regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>> +    /* Disable LPTIMER either before or after writing IER register
>> (else, keep it enabled) */
>> +    if (!priv->ier_wr_enabled)
>> +        regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>> +
>>       regmap_write(priv->reg, STM32_LPTIM_IER, 0);
>> +
> 
> Why not encapsulate the function ?
> 
>     regmap_write_ier(struct stm32_lp_private *priv, int value)
>     {
> 
>         /* A comment ... */
>         if (!priv->ier_wr_enabled)
>             regmap_write(priv->reg, STM32_LPTIM_CR, 0);
> 
>         regmap_write(priv->reg, STM32_LPTIM_IER, value);
> 
>         if (!priv->ier_wr_enabled)
>             regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
>     }

Hi Daniel,

Thanks for your suggestion.

I've tried various factorization but can't really find something pretty
and easy to read.

I think I'll rather implement some dedicated ops in V4, for stm32mp25,
based on compatible data.
This would allow straight forward sequence, without dangling with enable
bit / flags. I also need to add some checks on new status flags. So this
will avoid to add complexity on existing routines.

Best Regards,
Fabrice

> 
> 
>> +    if (priv->ier_wr_enabled)
>> +        regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>> +
> 
>>       /* clear pending flags */
>>       regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF);
>>   @@ -51,12 +59,21 @@ static int stm32_clkevent_lp_set_timer(unsigned
>> long evt,
>>   {
>>       struct stm32_lp_private *priv = to_priv(clkevt);
>>   -    /* disable LPTIMER to be able to write into IER register*/
>> -    regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>> +    if (!priv->ier_wr_enabled) {
>> +        /* Disable LPTIMER to be able to write into IER register */
>> +        regmap_write(priv->reg, STM32_LPTIM_CR, 0);
>> +    } else {
>> +        /* Enable LPTIMER to be able to write into IER register */
>> +        regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
>> +    }
>> +
>>       /* enable ARR interrupt */
>>       regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
>> +
>>       /* enable LPTIMER to be able to write into ARR register */
>> -    regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
>> +    if (!priv->ier_wr_enabled)
>> +        regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
>> +
>>       /* set next event counter */
>>       regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
>>   @@ -151,6 +168,7 @@ static int stm32_clkevent_lp_probe(struct
>> platform_device *pdev)
>>           return -ENOMEM;
>>         priv->reg = ddata->regmap;
>> +    priv->ier_wr_enabled = ddata->version == STM32_LPTIM_VERR_23;
>>       ret = clk_prepare_enable(ddata->clk);
>>       if (ret)
>>           return -EINVAL;
> 
> 

  reply	other threads:[~2025-03-13 17:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05  9:49 [PATCH v3 0/8] Add STM32MP25 LPTIM support: MFD, PWM, IIO, counter, clocksource Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 1/8] dt-bindings: mfd: stm32-lptimer: add support for stm32mp25 Fabrice Gasnier
2025-03-05 16:47   ` Rob Herring (Arm)
2025-03-05  9:49 ` [PATCH v3 2/8] " Fabrice Gasnier
2025-03-13 16:40   ` Lee Jones
2025-03-13 17:07     ` Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 3/8] iio: trigger: " Fabrice Gasnier
2025-03-05 14:45   ` Jonathan Cameron
2025-03-06  8:40     ` Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 4/8] clocksource: " Fabrice Gasnier
2025-03-07 15:12   ` Daniel Lezcano
2025-03-13 17:04     ` Fabrice Gasnier [this message]
2025-03-05  9:49 ` [PATCH v3 5/8] pwm: stm32-lp: " Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 6/8] arm64: defconfig: enable STM32 LP timer clockevent driver Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 7/8] arm64: dts: st: add low-power timer nodes on stm32mp251 Fabrice Gasnier
2025-03-05  9:49 ` [PATCH v3 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=c0aec002-7889-4ec5-a438-e7e90d8da13f@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;
as well as URLs for NNTP newsgroup(s).