linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: Fabrice Gasnier <fabrice.gasnier@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Benjamin Gaignard <benjamin.gaignard@linaro.org>,
	Lee Jones <lee@kernel.org>, Thierry Reding <treding@nvidia.com>
Cc: linux-pwm@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	Trevor Gamblin <tgamblin@baylibre.com>
Subject: [PATCH v2 0/3] pwm: stm32: Three fixes
Date: Fri, 21 Jun 2024 16:37:11 +0200	[thread overview]
Message-ID: <cover.1718979150.git.u.kleine-koenig@baylibre.com> (raw)

Hello,

this series contains two fixes for the .apply() callback and a trivial
change to fix an error message in probe.

(Implicit) v1 can be found at
https://lore.kernel.org/linux-pwm/cover.1718788826.git.u.kleine-koenig@baylibre.com
Changes since then:

 - Improve working of the commit log of patch #2 (as noticed by myself
   after submission of v1)
 - Drop Cc: stable on patch #2, as the faulty commit isn't in a release
   yet.
 - patch #3 is new (but was sent out already separately)
 - Fix .apply in patch #2 for some more corner cases.
 - Added Trevor's Reviewed-by for patch #1. (I didn't apply it to patch
   #2 as this changed since then.)

The issue in patch #2 was found with CONFIG_PWM_DEBUG enabled. The
problematic setting was period = 941244 ns with input clk rate =
208877930 Hz. For this setting these hardware register values were
calculated:

	PSC = 3
	ARR = 0xbffe

resulting in a real period of 941238.741689943 ns. However a request for
941239 ns resulted in

	PSC = 2
	ARR = 0xfffd

which corresponds to 941229.1667195285 Hz. My error in reasoning was
that I thought I'd need

        period_ns * clkrate
   ------------------------------ ≤ max_arr
   NSEC_PER_SEC * (prescaler + 1)

but in fact the necessary equation is

        period_ns * clkrate
   ------------------------------ < max_arr + 1
   NSEC_PER_SEC * (prescaler + 1)

The value of the LHS fraction for the above mentioned request
(period = 941244 ns, clk rate = 208877930) with PSC = 2 is

	941244 * 208877930 / (1000000000 * 3) = 65535.03278164 > 0xffff = max_arr

But as it's still rounded down to 65535 it's a valid configuration.

Best regards
Uwe

Uwe Kleine-König (3):
  pwm: stm32: Refuse too small period requests
  pwm: stm32: Fix calculation of prescaler
  pwm: stm32: Fix error message to not describe the previous error path

 drivers/pwm/pwm-stm32.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)


base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
-- 
2.43.0



             reply	other threads:[~2024-06-21 14:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-21 14:37 Uwe Kleine-König [this message]
2024-06-21 14:37 ` [PATCH v2 1/3] pwm: stm32: Refuse too small period requests Uwe Kleine-König
2024-06-21 14:37 ` [PATCH v2 2/3] pwm: stm32: Fix calculation of prescaler Uwe Kleine-König
2024-06-22 14:07   ` Uwe Kleine-König
2024-06-21 14:37 ` [PATCH v2 3/3] pwm: stm32: Fix error message to not describe the previous error path Uwe Kleine-König

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=cover.1718979150.git.u.kleine-koenig@baylibre.com \
    --to=u.kleine-koenig@baylibre.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=benjamin.gaignard@linaro.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=lee@kernel.org \
    --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=tgamblin@baylibre.com \
    --cc=treding@nvidia.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).