leds: Add powerdown gpio for is31fl32xx
Subsystems (2)
v6 cover leds: Add powerdown gpio for is31fl32xx
This patch series primarily adds the powerdown-gpios support for the IS31FL32xx controller.It also includes a fix and dt-bindings updates derived from previous attempts [1].
Patch 1 and patch 2 are based on a previous attempt [1]. The driver-related updates in patch 2 have already been merged.
Patch 3 and Patch 4 add support for the powerdown-gpios property, which corresponds to the SDB pin of the IS31FL32xx series chips. This pin is used to enter and exit the hardware powerdown mode.
Patch 5 fixes errors introduced by previous changes. It impacts the brightness control function of the IS31FL3236.
Patch 6 resolves regression caused by prior changes, and fixes the 22kHz PWM output functionality for IS31FL3236A.
[1] https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Add fix for 22kHz PWM output regression on IS31FL3236A
- Correct typo in vendor prefix for Integrated Silicon Solution
- Restore hardware shutdown state upon driver removal
- Link to v5: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Adjust the unit-address in dt-binding to hex addresses, and remove unnecessary if/then constraints.
- Link to v4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Fixed compilation build errors due to missing header files
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Replace shutdown-gpios with powerdown-gpios, follow gpio-consumer-common binding.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Fix $id mismatch with file name in dt-binding.
- Link to v1: https://lore.kernel.org/all/[email protected]/
Jun Yan (6):
dt-bindings: leds: issi,is31fl32xx: convert the binding to yaml
dt-bindings: leds: issi,is31fl32xx: add support for is31fl3236a
dt-bindings: leds: issi,is31fl32xx: Add powerdown-gpios property
leds: is31fl32xx: Add powerdown pin for hardware shutdown mode
leds: is31fl32xx: Fix missing brightness_steps for is31fl3236
leds: is31fl32xx: Move pwm frequency setting to init_regs()
.../bindings/leds/issi,is31fl32xx.yaml | 187 ++++++++++++++++++ .../bindings/leds/leds-is31fl32xx.txt | 53 ----- drivers/leds/leds-is31fl32xx.c | 36 ++-- 3 files changed, 211 insertions(+), 65 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/issi,is31fl32xx.yaml delete mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt
Signature · 1 line
2.54.0
PATCH v6 1/6 dt-bindings: leds: issi,is31fl32xx: convert the binding to yaml
Convert leds-is31fl32xx to DT schema format.
--- .../bindings/leds/issi,is31fl32xx.yaml | 151 ++++++++++++++++++ .../bindings/leds/leds-is31fl32xx.txt | 53 ------ 2 files changed, 151 insertions(+), 53 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/issi,is31fl32xx.yaml delete mode 100644 Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt
Documentation/devicetree/bindings/leds/issi,is31fl32xx.yaml new file +151 -0
@@ -0,0 +1,151 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/issi,is31fl32xx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: IS31FL32xx and Si-En SN32xx LED controller + +maintainers: + - Lucca Fachinetti <[email protected]> + - Pavel Machek <[email protected]> + - Jun Yan <[email protected]> + +description: | + The IS31FL32xx/SN32xx family of LED drivers are I2C devices with multiple + constant-current channels, each with independent 256-level PWM control. + Each LED is represented as a sub-node of the device. + + For more product information please see the links below: + https://www.lumissil.com/assets/pdf/core/IS31FL3216_DS.pdf + https://www.lumissil.com/assets/pdf/core/IS31FL3218_DS.pdf + https://www.lumissil.com/assets/pdf/core/IS31FL3235_DS.pdf + https://www.lumissil.com/assets/pdf/core/IS31FL3236_DS.pdf + https://www.lumissil.com/assets/pdf/core/IS31FL3293_DS.pdf + +properties: + compatible: + enum: + - issi,is31fl3216 + - issi,is31fl3218 + - issi,is31fl3235 + - issi,is31fl3236 + - issi,is31fl3293 + - si-en,sn3216 + - si-en,sn3218 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^led@([1-9a-f]|1[0-9a-f]|2[0-4])$": + type: object + $ref: common.yaml# + unevaluatedProperties: false + + properties: + reg: + description: + LED channel number (1..N) + minimum: 1 + maximum: 36 + + required: + - reg + +allOf: + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3293 + then: + patternProperties: + "^led@": + properties: + reg: + maximum: 3 + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3216 + - si-en,sn3216 + then: + patternProperties: + "^led@": + properties: + reg: + maximum: 16 + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3218 + - si-en,sn3218 + then: + patternProperties: + "^led@": + properties: + reg: + maximum: 18 + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3235 + then: + patternProperties: + "^led@": + properties: + reg: + maximum: 28 + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + led-controller@3c { + compatible = "issi,is31fl3236"; + reg = <0x3c>; + #address-cells = <1>; + #size-cells = <0>; + + led@1 { + reg = <1>; + color = <LED_COLOR_ID_RED>; + function = LED_FUNCTION_STATUS; + }; + + led@5 { + reg = <5>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_POWER; + linux,default-trigger = "default-on"; + }; + }; + }; +... +
Documentation/devicetree/bindings/leds/leds-is31fl32xx.txt deleted +0 -53
53 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v6 2/6 dt-bindings: leds: issi,is31fl32xx: add support for is31fl3236a
In reply to Jun YanAdd an additional and optional control property for setting the output PWM frequency to 22kHz that exists on is31fl3236a. The default is 3kHz and this option puts the operational frequency outside of the audible range.
--- .../bindings/leds/issi,is31fl32xx.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/leds/issi,is31fl32xx.yaml +24 -0
@@ -21,6 +21,7 @@ description: | https://www.lumissil.com/assets/pdf/core/IS31FL3218_DS.pdf https://www.lumissil.com/assets/pdf/core/IS31FL3235_DS.pdf https://www.lumissil.com/assets/pdf/core/IS31FL3236_DS.pdf + https://www.lumissil.com/assets/pdf/core/IS31FL3236A_DS.pdf https://www.lumissil.com/assets/pdf/core/IS31FL3293_DS.pdf properties:
@@ -30,6 +31,7 @@ properties: - issi,is31fl3218 - issi,is31fl3235 - issi,is31fl3236 + - issi,is31fl3236a - issi,is31fl3293 - si-en,sn3216 - si-en,sn3218
@@ -37,6 +39,12 @@ properties: reg: maxItems: 1 + issi,22khz-pwm: + type: boolean + description: + When present, the chip's PWM will operate at ~22kHz as opposed + to ~3kHz to move the operating frequency out of the audible range. + "#address-cells": const: 1
@@ -60,6 +68,22 @@ patternProperties: - reg allOf: + - if: + properties: + compatible: + contains: + enum: + - issi,is31fl3216 + - issi,is31fl3218 + - issi,is31fl3235 + - issi,is31fl3236 + - issi,is31fl3293 + - si-en,sn3216 + - si-en,sn3218 + then: + properties: + issi,22khz-pwm: false + - if: properties: compatible:
Signature · 1 line
2.54.0
PATCH v6 3/6 dt-bindings: leds: issi,is31fl32xx: Add powerdown-gpios property
In reply to Jun YanThe IS31FL32XX series features an SDB shutdown pin.
Driving it low (active low) places the chip into hardware shutdown mode for power saving, while all register contents are preserved and registers are not reset.
Add powerdown-gpios property to describe the GPIO connected to the SDB pin of IS31FL32XX series LED controllers.
--- .../devicetree/bindings/leds/issi,is31fl32xx.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/leds/issi,is31fl32xx.yaml +12 -0
@@ -45,6 +45,15 @@ properties: When present, the chip's PWM will operate at ~22kHz as opposed to ~3kHz to move the operating frequency out of the audible range. + powerdown-gpios: + maxItems: 1 + description: + GPIO connected to the chip's SDB pin. + Driving this GPIO low places the chip into hardware shutdown mode + for power saving. All register contents are preserved and registers + are not reset during shutdown. The chip exits hardware shutdown mode + when the SDB pin is pulled high. + "#address-cells": const: 1
@@ -145,6 +154,7 @@ additionalProperties: false examples: - | + #include <dt-bindings/gpio/gpio.h> #include <dt-bindings/leds/common.h> i2c {
@@ -157,6 +167,8 @@ examples: #address-cells = <1>; #size-cells = <0>; + powerdown-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; + led@1 { reg = <1>; color = <LED_COLOR_ID_RED>;
Signature · 1 line
2.54.0
PATCH v6 4/6 leds: is31fl32xx: Add powerdown pin for hardware shutdown mode
In reply to Jun YanThe IS31FL32XX series features an SDB shutdown pin. Driving it low (active low) places the chip into hardware shutdown mode for power saving, while all register contents are preserved and registers are not reset.
Deassert/assert the pin accordingly during probe() and remove() to manage hardware shutdown mode.
--- drivers/leds/leds-is31fl32xx.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/leds/leds-is31fl32xx.c +14 -1
@@ -10,6 +10,7 @@*/ #include <linux/device.h> +#include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/kernel.h> #include <linux/leds.h>
@@ -60,6 +61,7 @@ struct is31fl32xx_led_data {struct is31fl32xx_priv {const struct is31fl32xx_chipdef *cdef;struct i2c_client *client; +struct gpio_desc *powerdown_gpio;unsigned int num_leds;struct is31fl32xx_led_data leds[]; };
@@ -421,6 +423,14 @@ static int is31fl32xx_parse_dt(struct device *dev,const struct is31fl32xx_chipdef *cdef = priv->cdef;int ret =0 ; +/* Driving this GPIO line low takes the chip out of shutdown, +* as it is flagged as GPIO_ACTIVE_LOW in provider (such as the device tree). +*/ + priv->powerdown_gpio =devm_gpiod_get_optional (dev,"powerdown" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->powerdown_gpio)) +return dev_err_probe (dev,PTR_ERR (priv->powerdown_gpio), +"Failed to get powerdown gpio\n" ); +if ((cdef->output_frequency_setting_reg !=IS31FL32XX_REG_NONE ) &&of_property_read_bool (dev_of_node (dev),"issi,22khz-pwm" )) {
@@ -609,6 +619,9 @@ static void is31fl32xx_remove(struct i2c_client *client)if (ret)dev_err (&client->dev,"Failed to reset registers on removal (%pe)\n" ,ERR_PTR (ret)); + +if (priv->powerdown_gpio) +gpiod_set_value (priv->powerdown_gpio,1 ); }/*
@@ -643,4 +656,4 @@ module_i2c_driver(is31fl32xx_driver);MODULE_AUTHOR ("David Rivshin <[email protected]>" );MODULE_DESCRIPTION ("ISSI IS31FL32xx LED driver" ); -MODULE_LICENSE ("GPL v2" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v6 4/6] leds: is31fl32xx: Add powerdown pin for hardware shutdown mode
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Improper teardown ordering causes I2C writes to fail during LED unregistration.
- [Medium] Hardware is left powered on indefinitely if probe() fails.
- [Medium] Using a non-sleeping GPIO API triggers a kernel warning if the GPIO is on a sleepable controller.
Pre-existing issues:
- [High] Premature user-space and trigger exposure creates a race condition that overwrites LED state. --
commit 50d65262dc7ba9a3a04390c06e026bf8715319ba
Author: Jun Yan <[email protected]>
leds: is31fl32xx: Add powerdown pin for hardware shutdown mode
This patch adds support for the SDB shutdown pin on the IS31FL32XX series. It takes the chip out of shutdown mode by driving the pin low during probe, and asserts the pin during remove to put the chip back into shutdown mode.
Quoted 4 lines
drivers/leds/leds-is31fl32xx.c +0
-0
[ ... ]
drivers/leds/leds-is31fl32xx.c static int is31fl32xx_parse_dt(struct device *dev, · line 429
Quoted 8 lines
drivers/leds/leds-is31fl32xx.c +4
-0@@ -421,6 +423,14 @@ static int is31fl32xx_parse_dt(struct device *dev,const struct is31fl32xx_chipdef *cdef = priv->cdef;int ret =0 ; +/* Driving this GPIO line low takes the chip out of shutdown, +* as it is flagged as GPIO_ACTIVE_LOW in provider (such as the device tree). +*/ + priv->powerdown_gpio =devm_gpiod_get_optional (dev,"powerdown" ,GPIOD_OUT_LOW );
[Severity: Medium]
If the probe process fails after this point, does the hardware stay powered on indefinitely?
devres will release the GPIO descriptor but won't revert the physical output state, leaving the chip permanently active.
[Severity: High]
This isn't a bug introduced by this patch, but does this function prematurely expose the LEDs to userspace?
is31fl32xx_parse_dt() registers the LEDs using devm_led_classdev_register_ext(), making them instantly visible to userspace and applying default triggers. This happens before the driver calls is31fl32xx_init_regs() later in probe(), which performs an I2C reset of all registers.
Consequently, any brightness set by a default trigger or a fast userspace process in the intervening window will be completely overwritten and lost.
Quoted 5 lines
drivers/leds/leds-is31fl32xx.c +4
-0+if (IS_ERR (priv->powerdown_gpio)) +return dev_err_probe (dev,PTR_ERR (priv->powerdown_gpio), +"Failed to get powerdown gpio\n" ); + if ((cdef->output_frequency_setting_reg != IS31FL32XX_REG_NONE) &&
[ ... ]
drivers/leds/leds-is31fl32xx.c static void is31fl32xx_remove(struct i2c_client *client) · line 624
Quoted 7 lines
drivers/leds/leds-is31fl32xx.c +3
-0@@ -609,6 +619,9 @@ static void is31fl32xx_remove(struct i2c_client *client)if (ret)dev_err (&client->dev,"Failed to reset registers on removal (%pe)\n" ,ERR_PTR (ret)); + +if (priv->powerdown_gpio) +gpiod_set_value (priv->powerdown_gpio,1 );
[Severity: High]
Does this premature powerdown cause I2C writes to fail during LED unregistration?
The driver registers LEDs using devm_led_classdev_register_ext(), meaning devres handles unregistration after the driver's remove() hook completes. During unregistration, the LED subsystem turns off the LEDs by calling the driver's brightness callback, which performs I2C writes.
If the chip is powered down here, those writes will fail and cause kernel log spam. Could the power-down action be managed via devm_add_action_or_reset() after device registration to ensure it executes after the LEDs are cleanly unregistered?
[Severity: Medium]
Since this remove function runs in a sleepable context, could this trigger a gpiolib warning?
If the powerdown GPIO is connected to a sleepable controller (like an I2C or SPI GPIO expander), calling the non-sleeping gpiod_set_value() will trigger a warning within the gpiolib core. Should this use gpiod_set_value_cansleep() instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v6 5/6 leds: is31fl32xx: Fix missing brightness_steps for is31fl3236
In reply to Jun YanAdd missing brightness_steps for is31fl3236 to fix brightness control.
--- drivers/leds/leds-is31fl32xx.c | 1 + 1 file changed, 1 insertion(+)
drivers/leds/leds-is31fl32xx.c +1 -0
@@ -491,6 +491,7 @@ static const struct is31fl32xx_chipdef is31fl3236_cdef = { .pwm_register_base = 0x01, .led_control_register_base = 0x26, .enable_bits_per_led_control_register = 1, + .brightness_steps = 256, };static const struct is31fl32xx_chipdef is31fl3236a_cdef = {
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v6 5/6] leds: is31fl32xx: Fix missing brightness_steps for is31fl3236
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect use of max() instead of min() or clamp() for the current limit in is31fl3293_reset() breaks the led-max-microamp property.
- [High] Probe initialization order executes a hardware reset after registering LEDs, wiping out default-state and triggers.
- [High] The is31fl3293_cdef chip definition fails to initialize output_frequency_setting_reg, risking unintended register writes. --
commit 9f50d96174e82f3726c13d291274dd1b30aa1744
Author: Jun Yan <[email protected]>
leds: is31fl32xx: Fix missing brightness_steps for is31fl3236
Add missing brightness_steps for is31fl3236 to fix brightness control.
drivers/leds/leds-is31fl32xx.c static const struct is31fl32xx_chipdef is31fl3236_cdef = { · line 495
Quoted 10 lines
drivers/leds/leds-is31fl32xx.c +1
-0@@ -491,6 +491,7 @@ static const struct is31fl32xx_chipdef is31fl3236_cdef = { .pwm_register_base = 0x01, .led_control_register_base = 0x26, .enable_bits_per_led_control_register = 1, + .brightness_steps = 256, };
[Severity: High]
This isn't a bug introduced by this patch, but I noticed a problem with the probe initialization order in is31fl32xx_probe():
drivers/leds/leds-is31fl32xx.c:is31fl32xx_probe() {
...
ret = is31fl32xx_parse_dt(dev, priv);
if (ret)
return ret;
ret = is31fl32xx_init_regs(priv);
if (ret)
return ret;
...
}Could this order execute a hardware reset after registering the LEDs?
It looks like is31fl32xx_parse_dt() invokes devm_led_classdev_register_ext(), which processes default-state and triggers by writing to PWM registers. If is31fl32xx_init_regs() is called immediately after, it seems it would wipe out those initial states by issuing a hardware reset command to the chip.
[Severity: High]
This is a pre-existing issue, but looking at the is31fl3293_cdef definition in the same file:
static const struct is31fl32xx_chipdef is31fl3293_cdef = {
.channels = 3,
.shutdown_reg = IS31FL32XX_REG_NONE,
.pwm_update_reg = 0x28,
.pwm_update_value = 0xc5,
.global_control_reg = IS31FL32XX_REG_NONE,
.reset_reg = IS31FL32XX_REG_NONE,
.pwm_register_base = 0x19,
.led_control_register_base = IS31FL32XX_REG_NONE,
.brightness_steps = 4096,
.reset_func = is31fl3293_reset,
.sw_shutdown_func = is31fl3293_software_shutdown,
};Does this omit the initialization of .output_frequency_setting_reg?
Since it zero-initializes instead of using IS31FL32XX_REG_NONE, if the issi,22khz-pwm property is present, would the driver incorrectly assume the register is supported and write 0x01 to register 0x00?
[Severity: High]
This isn't a bug introduced by this patch, but the is31fl3293_reset() function appears to use max() incorrectly:
drivers/leds/leds-is31fl32xx.c:is31fl3293_reset() {
...
for (i = 0; i < priv->num_leds; i++) {
struct is31fl32xx_led_data *led_data = &priv->leds[i];
int current_level_reg = IS31FL3293_CL_REG + led_data->channel - 1;
int microamp = max(led_data->max_microamp, IS31FL3293_MAX_MICROAMP);
int current_level = (microamp * 0xff) / IS31FL3293_MAX_MICROAMP;
ret = is31fl32xx_write(priv, current_level_reg, current_level);
...
}Will this calculation force the current to never be less than IS31FL3293_MAX_MICROAMP?
It seems like this ignores intentionally lower led-max-microamp limits set in the device tree. Furthermore, if max_microamp exceeds the maximum, current_level would exceed 0xFF, which would get silently truncated when passed to is31fl32xx_write(). Should this code use min() or clamp() instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v6 6/6 leds: is31fl32xx: Move pwm frequency setting to init_regs()
In reply to Jun YanCommit a18983b95a61 ("leds: is31fl32xx: Add support for is31fl3293") swapped the order of is31fl32xx_parse_dt() and is31fl32xx_init_regs().
This causes the PWM frequency configuration programmed in is31fl32xx_parse_dt() to be overwritten by the register reset operation performed in is31fl32xx_init_regs().
Move the PWM frequency setting logic from is31fl32xx_parse_dt() to is31fl32xx_init_regs() and separates device tree parsing from hardware initialization.
--- drivers/leds/leds-is31fl32xx.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/leds/leds-is31fl32xx.c +10 -12
@@ -63,6 +63,7 @@ struct is31fl32xx_priv {struct i2c_client *client;struct gpio_desc *powerdown_gpio;unsigned int num_leds; +bool pwm_22khz;struct is31fl32xx_led_data leds[]; };
@@ -346,6 +347,14 @@ static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv)if (ret)return ret; +if ((cdef->output_frequency_setting_reg !=IS31FL32XX_REG_NONE ) && + priv->pwm_22khz) { + ret =is31fl32xx_write (priv, cdef->output_frequency_setting_reg, +IS31FL32XX_PWM_FREQUENCY_22KHZ ); +if (ret) +return ret; + } +/* * Set enable bit for all channels. * We will control state with PWM registers alone.
@@ -420,7 +429,6 @@ static struct is31fl32xx_led_data *is31fl32xx_find_led_data(static int is31fl32xx_parse_dt (struct device *dev,struct is31fl32xx_priv *priv) { -const struct is31fl32xx_chipdef *cdef = priv->cdef;int ret =0 ;/* Driving this GPIO line low takes the chip out of shutdown,
@@ -431,17 +439,7 @@ static int is31fl32xx_parse_dt(struct device *dev,return dev_err_probe (dev,PTR_ERR (priv->powerdown_gpio),"Failed to get powerdown gpio\n" ); -if ((cdef->output_frequency_setting_reg !=IS31FL32XX_REG_NONE ) && -of_property_read_bool (dev_of_node (dev),"issi,22khz-pwm" )) { - - ret =is31fl32xx_write (priv, cdef->output_frequency_setting_reg, -IS31FL32XX_PWM_FREQUENCY_22KHZ ); - -if (ret) { -dev_err (dev,"Failed to write output PWM frequency register\n" ); -return ret; - } - } + priv->pwm_22khz =of_property_read_bool (dev_of_node (dev),"issi,22khz-pwm" );for_each_available_child_of_node_scoped (dev_of_node (dev), child) {struct led_init_data init_data = {};
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v6 6/6] leds: is31fl32xx: Move pwm frequency setting to init_regs()
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] LED class devices are registered before hardware initialization completes, causing race conditions and state loss.
- [High] Missing initialization of output_frequency_setting_reg for IS31FL3293 causes erroneous I2C writes to register 0x00.
- [High] The current limit calculation in is31fl3293_reset() incorrectly uses max() instead of min(), risking hardware damage.
- [High] Concurrent brightness updates on different channels can cause torn multi-byte PWM writes and visible glitches. --
commit 7b1ac7769467fbaf4418cb18df93e48ba5bbff75
Author: Jun Yan <[email protected]>
leds: is31fl32xx: Move pwm frequency setting to init_regs()
Commit a18983b95a61 swapped the order of is31fl32xx_parse_dt() and is31fl32xx_init_regs(). This patch moves the PWM frequency setting logic from is31fl32xx_parse_dt() to is31fl32xx_init_regs() to prevent the configuration from being overwritten by the register reset operation.
Quoted 4 lines
drivers/leds/leds-is31fl32xx.c +0
-0
[ ... ]
drivers/leds/leds-is31fl32xx.c static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) · line 349
Quoted 4 lines
drivers/leds/leds-is31fl32xx.c +0
-0@@ -346,6 +347,14 @@ static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv)if (ret)return ret;
[Severity: High]
This isn't a bug introduced by this patch, but is the current limit calculation in is31fl3293_reset() risking hardware damage?
The function calculates the operating current limit using max(led_data->max_microamp, IS31FL3293_MAX_MICROAMP). If the device tree requests a lower limit like 5000 microamps, max() will override it to 20000 microamps, potentially overdriving the LED hardware.
Furthermore, if a limit larger than 20mA is requested, the calculated value exceeds 255. When passed to the 8-bit is31fl32xx_write(), it will silently truncate and result in an unpredictable current limit setting.
Should this logic use min() instead to safely enforce the hardware constraint?
drivers/leds/leds-is31fl32xx.c static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) · line 351
Quoted 2 lines
drivers/leds/leds-is31fl32xx.c +2
-0+if ((cdef->output_frequency_setting_reg !=IS31FL32XX_REG_NONE ) && + priv->pwm_22khz) {
[Severity: High]
This is a pre-existing issue, but does this check work correctly for the IS31FL3293 chip?
The is31fl3293_cdef structure omits the initialization of .output_frequency_setting_reg, so it defaults to 0x00. Since IS31FL32XX_REG_NONE is 0xFF, this condition evaluates to true.
If the device tree contains the "issi,22khz-pwm" property for an IS31FL3293 device, will the driver incorrectly write the 22kHz setting to register 0x00?
Quoted 6 lines
drivers/leds/leds-is31fl32xx.c +6
-0+ ret =is31fl32xx_write (priv, cdef->output_frequency_setting_reg, +IS31FL32XX_PWM_FREQUENCY_22KHZ ); +if (ret) +return ret; + } +
[ ... ]
drivers/leds/leds-is31fl32xx.c static struct is31fl32xx_led_data *is31fl32xx_find_led_data( · line 432
Quoted 6 lines
drivers/leds/leds-is31fl32xx.c +0
-1@@ -420,7 +429,6 @@ static struct is31fl32xx_led_data *is31fl32xx_find_led_data(static int is31fl32xx_parse_dt (struct device *dev,struct is31fl32xx_priv *priv) { -const struct is31fl32xx_chipdef *cdef = priv->cdef;int ret =0 ;
[Severity: High]
This is a pre-existing issue, but does the current driver initialization flow expose LEDs to userspace before the hardware is ready?
In is31fl32xx_probe(), is31fl32xx_parse_dt() is called before is31fl32xx_init_regs(). is31fl32xx_parse_dt() registers the LED devices via devm_led_classdev_register_ext(), making them available to userspace and the kernel LED subsystem immediately.
If default triggers or userspace actions configure the PWM registers before is31fl32xx_init_regs() runs, wouldn't the subsequent hardware reset wipe out those user configurations?
[ ... ]
drivers/leds/leds-is31fl32xx.c static int is31fl32xx_parse_dt(struct device *dev, · line 442
Quoted 12 lines
drivers/leds/leds-is31fl32xx.c +1
-11-if ((cdef->output_frequency_setting_reg !=IS31FL32XX_REG_NONE ) && -of_property_read_bool (dev_of_node (dev),"issi,22khz-pwm" )) { - - ret =is31fl32xx_write (priv, cdef->output_frequency_setting_reg, -IS31FL32XX_PWM_FREQUENCY_22KHZ ); - -if (ret) { -dev_err (dev,"Failed to write output PWM frequency register\n" ); -return ret; - } - } + priv->pwm_22khz =of_property_read_bool (dev_of_node (dev),"issi,22khz-pwm" );
[Severity: High]
This is a pre-existing issue, but are concurrent brightness updates susceptible to torn multi-byte PWM writes?
The is31fl32xx_brightness_set() function lacks driver-level locking. For chips like IS31FL3293 that require two consecutive I2C writes (low byte then high byte) per channel, could concurrent updates break the atomicity of the 12-bit PWM update?
For example, if Thread A writes the low byte for LED 1, and Thread B concurrently writes the high byte for LED 2 and triggers the Update register, could the chip latch LED 1's new low byte with its old high byte?
Does this sequence require a mutex to serialize the multi-byte PWM write?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6