From: Thierry Reding <thierry.reding@gmail.com>
To: Thomas Hebb <tommyhebb@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Antoine Tenart <antoine.tenart@free-electrons.com>,
sebastian.hesselbarth@gmail.com, Jisheng.Zhang@synaptics.com,
"open list:PWM SUBSYSTEM" <linux-pwm@vger.kernel.org>
Subject: Re: [PATCH v2] pwm: berlin: Don't use broken prescaler values
Date: Mon, 9 Jul 2018 18:57:24 +0200 [thread overview]
Message-ID: <20180709165724.GB26651@ulmo> (raw)
In-Reply-To: <a4e1449967f3dbc95770b9ac2bbc1fd116e3cac7.1528306926.git.tommyhebb@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2096 bytes --]
On Wed, Jun 06, 2018 at 01:42:10PM -0400, Thomas Hebb wrote:
> The Berlin PWM driver is currently broken on at least BG2CD. The
> symptoms manifest as a very non-linear and erratic mapping from the duty
> cycle configured in software to the duty cycle produced by hardware.
>
> The cause of the bug is software's configuration of the prescaler, and
> in particular its usage of the six prescaler values between the minimum
> value of 1 and the maximum value of 4096. As it turns out, these six
> values do not actually slow down the PWM clock; rather, they emulate
> slowing down the clock by internally multiplying the value of TCNT.
>
> This would be a fine trick, if not for the fact that the internal,
> scaled TCNT value has no extra bits beyond the 16 already exposed to
> software in the register. What this means is that, for a prescaler of 4,
> the software must ensure that the top two bits of TCNT are not set,
> because hardware will chop them off; for a prescaler of 8, the top three
> bits must not be set, and so forth. Software does not currently ensure
> this, resulting in a TCNT several orders of magnitude lower than
> intended any time one of those six prescalers are selected.
>
> Because hardware chops off the high bits in its internal shift, the
> middle six prescalers don't actually allow *anything* that the first
> doesn't. In fact, they are strictly worse than the first, since the
> internal shift of TCNT prevents software from setting the low bits,
> decreasing the resolution, without providing any extra high bits.
>
> By skipping the useless prescalers entirely, this patch both fixes the
> driver's behavior and increases its performance (since, when the 4096
> prescaler is selected, it now does only a single shift rather than the
> seven successive divisions it did before).
>
> Tested on BG2CD.
>
> Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
> ---
> drivers/pwm/pwm-berlin.c | 45 ++++++++++++++++++++++------------------
> 1 file changed, 25 insertions(+), 20 deletions(-)
Applied, thanks.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2018-07-09 16:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-06 17:42 [PATCH v2] pwm: berlin: Don't use broken prescaler values Thomas Hebb
2018-07-09 16:57 ` Thierry Reding [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=20180709165724.GB26651@ulmo \
--to=thierry.reding@gmail.com \
--cc=Jisheng.Zhang@synaptics.com \
--cc=antoine.tenart@free-electrons.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=tommyhebb@gmail.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).