From: Marek Vasut <marex@denx.de>
To: Frank Li <Frank.li@nxp.com>
Cc: "Fabio Estevam" <festevam@gmail.com>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, pratikmanvar09@gmail.com,
francesco@dolcini.it, "Clark Wang" <xiaoning.wang@nxp.com>,
"Jun Li" <jun.li@nxp.com>
Subject: Re: [PATCH v2 3/3] pwm: imx27: workaround of the pwm output bug when decrease the duty cycle
Date: Mon, 9 Sep 2024 22:16:58 +0200 [thread overview]
Message-ID: <2d17752c-8a78-4b6d-9767-f4de884ec795@denx.de> (raw)
In-Reply-To: <Zt9PcsUg4CdMbpov@lizhi-Precision-Tower-5810>
On 9/9/24 9:41 PM, Frank Li wrote:
Hi,
[...]
>>> I will add it at next version. But I found a problem of your method,
>>> especially when period is quite long, for example 2s. Assume FIFO is empty.
>>> [old, old, new] will be written to FIFO, new value will takes 2s-6s to make
>>> new value effect.
>>
>> You're right, for long PWM periods, the application of changes will take
>> longer.
>>
>> As far as I can tell, the method implemented in this patch may still suffer
>> from the problem in case of short PWM periods, is that correct ? I think the
>> writesl() might help cover some of that.
>
> No way can fix very short periods problem because period was shorter then
> register write speed.
What kind of period are we talking about here ? Since the FIFO has 4
slots, I would expect way 4-8 MHz to be fixable still ?
> The register write go through ips bus, which is
> quit slow. writesl is equal to writel_relaxed and avoid a dmb(). This will
> be over1M hz and user generally use pwm around hz to khz.
I just had a look at the implementation of writel_relaxed() and yes,
this is basically a 'str', good point.
>> Maybe for longer PWM periods (like 500ms and longer?) where we can be sure
>> the FIFO won't quickly consume the written data and underflow, we can do
>> writesl() with only two longwords {old_sar, new_sar}, first longword to make
>> sure the FIFO is not empty, second word with the new PWMSAR value ? That
>> could speed the update up ?
>
> We should use this patch's method to read MX3_PWMCNR, if close enough,
> write two data into fifo instead of wait for new peroid start.
Can we guarantee that there would never be any scheduling or other delay
between the readout of PWMCNR and write of the FIFO, one which would
trigger an underflow ?
>>> The currect method, most time, the new value will effect at next period.
>> Yes, right, I think we may have to handle the longer PWM periods somehow
>> differently.
>>
>> I would like to avoid local_irq_save()/readl_poll_timeout_atomic() if
>> possible and let the hardware help avoid this, which I think is possible
>> with creative loading of the FIFO with data, hence the writesl() idea.
>
> I think it hard to avoid local_irq_save() even use writesl(), writesl is
> not atomic, if irq happen after first raw_write, FIFO may be empty at
> next write.
>
> actually, here have problem
>
> val = FIELD_GET(MX3_PWMSR_FIFOAV, readl_relaxed(imx->mmio_base + MX3_PWMSR));
> ^^^ if irq happen here, schedule happen, when schedule back,
>
> FIFOAV value in hardware may less than MX3_PWMSR_FIFOAV_2WORDS, but
> previous read it bigger than MX3_PWMSR_FIFOAV_2WORDS, the below check
> will be false and skip workaround.
>
> if (duty_cycles < imx->duty_cycle && val < MX3_PWMSR_FIFOAV_2WORDS) {
>
>
> See patch v4
> https://lore.kernel.org/imx/20240909193855.2394830-1-Frank.Li@nxp.com/T/#u
> It should be little bit better.
I think the v4 is indeed better, thanks.
prev parent reply other threads:[~2024-09-09 20:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 20:29 [PATCH v2 0/3] pwm: imx: add 32k clock for 8qm/qxp and workaround a chip issue Frank Li
2024-07-15 20:29 ` [PATCH v2 1/3] dt-bindings: pwm: imx: Add optional clock '32k' Frank Li
2024-07-16 16:04 ` Conor Dooley
2024-07-15 20:29 ` [PATCH v2 2/3] pwm: imx27: Add 32k clock for pwm in i.MX8QXP MIPI subsystem Frank Li
2024-07-16 18:49 ` Christophe JAILLET
2024-07-15 20:29 ` [PATCH v2 3/3] pwm: imx27: workaround of the pwm output bug when decrease the duty cycle Frank Li
2024-09-05 17:12 ` Fabio Estevam
2024-09-05 18:26 ` Marek Vasut
2024-09-05 18:54 ` Frank Li
2024-09-05 19:01 ` Marek Vasut
2024-09-05 20:37 ` Frank Li
2024-09-06 4:33 ` Marek Vasut
2024-09-09 19:41 ` Frank Li
2024-09-09 20:16 ` Marek Vasut [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=2d17752c-8a78-4b6d-9767-f4de884ec795@denx.de \
--to=marex@denx.de \
--cc=Frank.li@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=francesco@dolcini.it \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pratikmanvar09@gmail.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=ukleinek@kernel.org \
--cc=xiaoning.wang@nxp.com \
/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).