Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "H. Nikolaus Schaller" <hns@goldelico.com>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
	linux-sound@vger.kernel.org, robh@kernel.org,
	conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v2 09/20] pwm: twl: Support 64-cycle PWM frame
Date: Tue, 24 Nov 2026 07:37:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-230650@kernel.org> (raw)
In-Reply-To: <59fa3a5ee1a0d0bf13c85c08160c5acdaa95b7a4.1795505160.git.hns@goldelico.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] pwm: twl: 64-cycle mode in twl_pwm_config() scales and clamps
  to 127 not 63
--

commit 9c38629d98d044b0860bfc5ea8bf71a8a5b8a626
Author: H. Nikolaus Schaller <hns@goldelico.com>

pwm: twl: Support 64-cycle PWM frame

This commit adds support for the ti,twl4030-pwm-frame-64 device tree
property to select a 64-clock-cycle PWM frame on TWL4030.

> diff --git a/drivers/pwm/pwm-twl.c b/drivers/pwm/pwm-twl.c
> index 99c1caf4f19c8..70567d5805f43 100644
> --- a/drivers/pwm/pwm-twl.c
> +++ b/drivers/pwm/pwm-twl.c
[ ... ]
> @@ -56,13 +60,35 @@ static inline struct twl_pwm_chip *to_twl(struct pwm_chip *chip)
>  	return pwmchip_get_drvdata(chip);
>  }
>  
> +/*
> + * Note: this hardware (and driver) does not honor arbitrary periods.
> + * Only the duty ratio is implemented; the frame length is either
> + * 128 clock cycles (default) or - if selected through device tree -
> + * 64 clock cycles. Consumers requiring an accurate period must verify
> + * the actually provided period.
> + */
>  static int twl_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  			  u64 duty_ns, u64 period_ns)
>  {
> +	struct twl_pwm_chip *twl = to_twl(chip);
>  	int duty_cycle = DIV64_U64_ROUND_UP(duty_ns * TWL_PWM_MAX, period_ns) + 1;
> +	bool frame_64 = twl_class_is_4030() && twl->twl4030_frame_64;
>  	u8 pwm_config[2] = { 1, 0 };
>  	int base, ret;
>  
> +	if (frame_64)
> +		pwm_config[0] |= TWL4030_PWM_ON_FRAME_64;
> +
> +	/*
> +	 * In the 64-cycle frame the OFF counter wraps at 64. A requested
> +	 * duty_cycle of 64 (full duty) would therefore wrap to a constant
> +	 * high output. Saturate to the largest value that still produces
> +	 * a low pulse (OFF = 63, approximately 62/64 high) instead.
> +	 * This also applies to full-duty requests from PWM consumers.
> +	 */
> +	if (frame_64 && duty_cycle > TWL_PWM_MAX)
> +		duty_cycle = TWL_PWM_MAX;

[Severity: High]
Does twl_pwm_config() scale and clamp duty_cycle against 127 instead of 63
when frame_64 is enabled?

TWL_PWM_MAX is defined as 0x7f (127), which is the counter limit for the
128-cycle frame.  In 64-cycle mode, scaling duty_ns by TWL_PWM_MAX and
clamping to TWL_PWM_MAX produces pwm_config[1] values up to 127 rather
than 63.  As a result, the 6-bit OFF counter wraps around at roughly 50%
requested duty cycle (reaching OFF = 64 -> 0 and OFF = 65 -> 1, which
matches ON = 1 for constant high output) and repeats the duty ramp a
second time across the upper half of the range.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795505160.git.hns@goldelico.com?part=9

  reply	other threads:[~2026-11-24  7:37 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  7:25 [PATCH v2 00/20] ARM: omap3: pandora: Modernize audio and backlight to use Device Tree to finally remove pdata-quirks H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 01/20] dt-bindings: gpio: twl4030: Document REGEN GPIO H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 02/20] gpio: twl4030: Support " H. Nikolaus Schaller
2026-11-24  7:43   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 03/20] ASoC: twl4030: Allow APLL rate selection through set_sysclk() H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 04/20] dt-bindings: sound: pcm1754: Describe PCM1773 H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 05/20] ASoC: codecs: pcm1754: Add PCM1773 support H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 06/20] dt-bindings: sound: Document OpenPandora sound card H. Nikolaus Schaller
2026-11-24  7:40   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 07/20] ASoC: ti: omap3pandora: Convert sound card to DT H. Nikolaus Schaller
2026-11-24  7:45   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 08/20] dt-bindings: mfd: twl4030: Document 64-cycle PWM H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 09/20] pwm: twl: Support 64-cycle PWM frame H. Nikolaus Schaller
2026-11-24  7:37   ` sashiko-bot [this message]
2026-11-24  7:25 ` [PATCH v2 10/20] dt-bindings: backlight: pwm: Document enable guard H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 11/20] backlight: pwm: Support enable guard period H. Nikolaus Schaller
2026-11-24  7:36   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 12/20] drm/panel: td043mtea1: Attach DT backlight H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 13/20] ARM: dts: omap3pandora: Disable unused DMA channels H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 14/20] ARM: dts: omap3-pandora: Model LCD power enable dependencies H. Nikolaus Schaller
2026-11-24  7:45   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 15/20] ARM: dts: omap3pandora: Enable audio interfaces H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 16/20] ARM: dts: omap3pandora: Describe PCM1773 H. Nikolaus Schaller
2026-11-24  7:40   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 17/20] ARM: dts: omap3pandora: Describe sound card H. Nikolaus Schaller
2026-11-24  7:47   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 18/20] ARM: dts: omap3pandora: Switch backlight to PWM H. Nikolaus Schaller
2026-11-24  7:46   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 19/20] backlight: Remove legacy Pandora driver H. Nikolaus Schaller
2026-11-24  7:26 ` [PATCH v2 20/20] ARM: OMAP2+: Remove Pandora platform-data quirks H. Nikolaus Schaller

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=sashiko-outbox-230650@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hns@goldelico.com \
    --cc=lee@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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