(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

leds: st1202: Scale pattern brightness to the 12-bit PWM range

The LED1202 PWM registers are 12 bits wide, but st1202_led_pattern_set() writes the 8-bit brightness value carried by struct led_pattern into them unscaled. A pattern step asking for full brightness therefore drives the channel at 255 out of 4095, about 6% duty cycle, so a pattern is dimmer than the same brightness set directly. Scale the value to the full PWM range before programming it. Scale against max_brightness rather than the register maximum. The LED core takes max_brightness from the DT max-brightness property, so a board can declare a ceiling below full scale, and the pattern trigger already rejects steps above it. Scaling against a hardcoded 255 would leave such a board unable to reach its own declared maximum from the pattern path while the brightness path reaches it. Scaling divides by max_brightness. The LED core replaces a zero max-brightness from the device tree with LED_FULL, so the divisor should never be zero, but the helper returns zero rather than rely on that. max_brightness is capped at U8_MAX, the driver's own maximum, so a device tree declaring more than the part supports is treated as full scale. struct led_pattern brightness is signed, so clamp both ends and floor a negative value to LED_OFF rather than let it wrap. Document that a step is relative to max_brightness, since the range given in the documentation no longer holds when the device tree sets max-brightness. Fixes: 259230378c65 ("leds: Add LED1202 I2C driver") Signed-off-by: Manuel Fombuena <fombuena@outlook.com> Assisted-by: LLM Link: https://patch.msgid.link/GV1PR08MB8497B938D3592582E17CB757C5BA2@GV1PR08MB8497.eurprd08.prod.outlook.com Signed-off-by: Lee Jones <lee@kernel.org>


Author Manuel Fombuena Committer Lee Jones Date Commit Parent 119a7d37
+20 -1
2 changed files
+20 -1
2 changed files