Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] backlight: pwm_bl: guard period runs before pwm_backlight_power_on() - [Medium] backlight: pwm_bl: guard pulse triggers before compute_duty_cycle() - [Medium] backlight: pwm_bl: unchecked post-guard pwm_apply_might_sleep() - [Low] backlight: pwm_bl: unused linux/minmax.h include added --
commit e05803a769b6dbbf7722b07888a63c3cd2737641 Author: H. Nikolaus Schaller <[email protected]> backlight: pwm: Support enable guard period This commit adds support for a pwm-enable-guard-period-us device tree property to apply a full duty cycle for a guard interval when enabling the PWM from a disabled or zero-duty state. Link: https://patchwork.kernel.org/project/linux-omap/patch/f897f695c0e1e128d7ebb41be8dfdce4d634f552.1783749722.git....@goldelico.com/#27124981 > diff --git a/drivers/video/backlight/pwm_bl.c > b/drivers/video/backlight/pwm_bl.c > index 3ad71ee3657af..1d0a463710926 100644 > --- a/drivers/video/backlight/pwm_bl.c > +++ b/drivers/video/backlight/pwm_bl.c > @@ -7,6 +7,7 @@ > > #include <linux/delay.h> > #include <linux/gpio/consumer.h> > +#include <linux/minmax.h> [Severity: Low] This isn't a bug, but linux/minmax.h does not appear to be used by anything in this change. [ ... ] > @@ -93,11 +98,39 @@ static int pwm_backlight_update_status(struct > backlight_device *bl) > struct pwm_bl_data *pb = bl_get_data(bl); > int brightness = backlight_get_brightness(bl); > struct pwm_state state; > + int ret; > > if (pb->notify) > brightness = pb->notify(pb->dev, brightness); > > if (brightness > 0) { > + pwm_get_state(pb->pwm, &state); > + > + /* > + * Some LED drivers detect a one-wire control mode during > + * a startup window (e.g. TI TPS61160/TPS61161, using > + * the duration of low intervals on CTRL). Request full > + * duty for the guard interval before normal dimming. > + * The PWM provider may approximate full duty. > + * > + * Apply the guard if the previous PWM state was disabled > + * or had zero duty cycle. > + */ > + if (pb->enable_guard_period_us && > + (!state.enabled || !state.duty_cycle)) { > + struct pwm_state guard = state; > + > + guard.duty_cycle = guard.period; > + guard.enabled = true; > + ret = pwm_apply_might_sleep(pb->pwm, &guard); > + if (ret) > + return ret; > + > + usleep_range(pb->enable_guard_period_us, > + pb->enable_guard_period_us + > + PWM_BL_GUARD_SLACK_US); > + } [Severity: Medium] Does checking brightness > 0 before calling compute_duty_cycle() cause a full-brightness flash when a non-zero brightness level maps to a duty cycle of 0? When pb->lth_brightness is 0 and a low non-zero brightness index maps to 0 in pb->levels[] (or truncates to 0 in compute_duty_cycle()), the guard block drives the PWM at 100% duty cycle for pb->enable_guard_period_us before programming state.duty_cycle = 0. Because state.duty_cycle remains 0, subsequent updates at low brightness repeat the full-duty flash and delay. In addition, if the target duty cycle is already equal to state.period, the guard block sleeps and then applies the same full duty cycle a second time. > + > pwm_get_state(pb->pwm, &state); > state.duty_cycle = compute_duty_cycle(pb, brightness, &state); > state.enabled = true; [Severity: Medium] Does running the guard interval before pwm_backlight_power_on(pb) leave the LED driver unpowered or disabled while the guard pulse is on the line? drivers/video/backlight/pwm_bl.c:pwm_backlight_update_status() { ... pwm_get_state(pb->pwm, &state); state.duty_cycle = compute_duty_cycle(pb, brightness, &state); state.enabled = true; pwm_apply_might_sleep(pb->pwm, &state); pwm_backlight_power_on(pb); ... } When a board also uses power-supply or enable-gpios, the full-duty guard waveform and its usleep_range() delay finish and the PWM is already switched to the dimmed duty cycle before pwm_backlight_power_on() enables pb->power_supply or asserts pb->enable_gpio. The LED driver IC powers up only after normal PWM dimming has begun, bypassing the startup guard window. [Severity: Medium] What happens if the guard pwm_apply_might_sleep() succeeds, but the post-guard pwm_apply_might_sleep() that sets the dimmed duty cycle fails? Because the second call's return value is ignored, a transient failure on that update leaves the PWM hardware running at 100% duty cycle from the guard step while pwm_backlight_power_on() turns the backlight on and pwm_backlight_update_status() returns 0. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=11
