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 <[email protected]>

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/[email protected]?part=9

Reply via email to