mfd: lm3533: convert to OF bindings, improve support
Subsystems (6)
v3 cover mfd: lm3533: convert to OF bindings, improve support
Convert LM3533 to OF bindings, add missing VIN supply, add support for setting mapping mode and LED sources based on device tree.
---
Changes in v2:
schema
- maximum led sources for leds set to 4
- anyOf > oneOf in ALS
- improved ALS descriptions
- adjusted example
drivers
- dropped devm convertion of irq and mfd helpers
- all als configuration moved into lm3533_als_setup
- added regulator/consumer.h
- lm3533_bl_setup set before sysfs_create_group in backlight
- added check if LVLED is valid
- LM3533_REG_OUTPUT_CONF1 > LM3533_REG_OUTPUT_CONF2 for LVLED4 and LVLED5
Changes in v3:
- ohm -> ohms
- added default PWM mask to schema
- added commit removing driver regmap wrappers
- added commits which flatten pdata helpers
- adjusted check if als->irq > 0 since als->irq can be negative if error/missing
- added count for children defined in device tree and mfd_cell is allocated via devm_kcalloc to be able to contain all of them
- fixed backlight boundary check
- fixed count increased unconditionally
- dev_err returns node name instead of reg value
- LM3533_MAX_CURRENT_* defines moved to common header since they are used to clamp current values read from the tree
- mapping mode commit splitted into 2 (sysfs logic improvement > mode from DT)
- backlight mode configuration set before sysfs group is created
- fixed LVLED check on LEDs setup
- added check if HVLED is valid
- fixed wrong err_sysfs_remove goto in lm3533_bl
- added commit implementing backlight_scale property
---
Svyatoslav Ryhel (11):
dt-bindings: leds: Document TI LM3533 LED controller
mfd: lm3533: Remove driver specific regmap wrappers
iio: light: lm3533-als: Remove redundant pdata helpers
mfd: lm3533-core: Remove redundant pdata helpers
mfd: lm3533: Convert to use OF bindings
mfd: lm3533: Add support for VIN power supply
mfd: lm3533: Set DMA mask
video: backlight: lm3533_bl: Improve linear sysfs logic
video: backlight: lm3533_bl: Set initial mapping mode from DT
video: backlight: lm3533_bl: Implement backlight_scale property
video: leds: backlight: lm3533: Support getting LED sources from DT
.../leds/backlight/ti,lm3533-backlight.yaml | 69 ++++ .../bindings/leds/ti,lm3533-leds.yaml | 67 ++++ .../devicetree/bindings/leds/ti,lm3533.yaml | 169 ++++++++ drivers/iio/light/lm3533-als.c | 159 ++++---- drivers/leds/leds-lm3533.c | 142 +++++-- drivers/mfd/lm3533-core.c | 361 +++++++----------- drivers/mfd/lm3533-ctrlbank.c | 27 +- drivers/video/backlight/lm3533_bl.c | 153 ++++++-- include/linux/mfd/lm3533.h | 62 +-- 9 files changed, 758 insertions(+), 451 deletions(-) create mode 100644 Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533.yaml
Signature · 1 line
2.51.0
PATCH v3 1/11 dt-bindings: leds: Document TI LM3533 LED controller
Document the LM3533 - a complete power source for backlight, keypad and indicator LEDs in smartphone handsets. The high-voltage inductive boost converter provides the power for two series LED strings display backlight and keypad functions.
--- .../leds/backlight/ti,lm3533-backlight.yaml | 69 +++++++ .../bindings/leds/ti,lm3533-leds.yaml | 67 +++++++ .../devicetree/bindings/leds/ti,lm3533.yaml | 169 ++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533.yaml
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/backlight/ti,lm3533-backlight.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI LM3533 high voltage series LED strings + +description: + This is part of the TI LM3533 MFD device. It represents two high voltage series + LED strings for display backlight controlled by the TI LM3533. + +maintainers: + - Svyatoslav Ryhel <[email protected]> + +allOf: + - $ref: /schemas/leds/backlight/common.yaml# + +properties: + compatible: + const: ti,lm3533-backlight + + reg: + description: Control bank selection (0 = bank A, 1 = bank B). + maximum: 1 + + led-max-microamp: + description: maximum current in uA with a 800 uA step. + minimum: 5000 + maximum: 29800 + default: 5000 + + led-sources: + description: | + HVLED strings associated with this control bank: + 0 - HVLED1 + 1 - HVLED2 + minItems: 1 + maxItems: 2 + items: + maximum: 1 + + ti,pwm-config-mask: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Control Bank PWM Configuration Register mask that allows to configure + PWM input in Zones 0-4 + BIT(0) - PWM Input is enabled + BIT(1) - PWM Input is enabled in Zone 0 + BIT(2) - PWM Input is enabled in Zone 1 + BIT(3) - PWM Input is enabled in Zone 2 + BIT(4) - PWM Input is enabled in Zone 3 + BIT(5) - PWM Input is enabled in Zone 4 + default: 0 + + ti,linear-mapping-mode: + description: + Enable linear mapping mode. If disabled, then it will use exponential + mapping mode in which the ramp up/down appears to have a more uniform + transition to the human eye. + type: boolean + +required: + - compatible + - reg + +unevaluatedProperties: false + +# see ti,lm3533.yaml for an example
Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml new file +67 -0
67 lines not on this page · raw message
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH v3 01/11] dt-bindings: leds: Document TI LM3533 LED controller
Quoted 7 lines · Svyatoslav Ryhel
Document the LM3533 - a complete power source for backlight, keypad and indicator LEDs in smartphone handsets. The high-voltage inductive boost converter provides the power for two series LED strings display backlight and keypad functions.
Signed-off-by Svyatoslav Ryhel <[email protected]>
Daniel.
PATCH v3 2/11 mfd: lm3533: Remove driver specific regmap wrappers
In reply to Svyatoslav RyhelRemove driver-specific regmap wrappers in favor of using regmap helpers directly. The wrappers are mostly equivalent to the standard helpers, with two exceptions: regmap_read requires an unsigned int pointer, and regmap_update_bits has the mask and value arguments swapped. These differences were accounted for and adjusted accordingly.
--- drivers/iio/light/lm3533-als.c | 57 ++++++++++++---------- drivers/leds/leds-lm3533.c | 34 +++++++------- drivers/mfd/lm3533-core.c | 73 +++++------------------------ drivers/mfd/lm3533-ctrlbank.c | 22 +++++---- drivers/video/backlight/lm3533_bl.c | 21 +++++---- include/linux/mfd/lm3533.h | 8 +--- 6 files changed, 86 insertions(+), 129 deletions(-)
drivers/iio/light/lm3533-als.c +32 -25
@@ -17,6 +17,7 @@#include <linux/mutex.h> #include <linux/mfd/core.h> #include <linux/platform_device.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -64,7 +65,7 @@ static int lm3533_als_get_adc(struct iio_dev *indio_dev, bool average, {struct lm3533_als *als =iio_priv (indio_dev);u8 reg; -u8 val; +u32 val;int ret;if (average)
@@ -72,7 +73,7 @@ static int lm3533_als_get_adc(struct iio_dev *indio_dev, bool average,else reg =LM3533_REG_ALS_READ_ADC_RAW ; - ret =lm3533_read (als->lm3533, reg, &val); + ret =regmap_read (als->lm3533->regmap, reg, &val);if (ret) {dev_err (&indio_dev->dev,"failed to read adc\n" );return ret;
@@ -86,10 +87,10 @@ static int lm3533_als_get_adc(struct iio_dev *indio_dev, bool average,static int _lm3533_als_get_zone (struct iio_dev *indio_dev,u8 *zone) {struct lm3533_als *als =iio_priv (indio_dev); -u8 val; +u32 val;int ret; - ret =lm3533_read (als->lm3533,LM3533_REG_ALS_ZONE_INFO , &val); + ret =regmap_read (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , &val);if (ret) {dev_err (&indio_dev->dev,"failed to read zone\n" );return ret;
@@ -127,7 +128,7 @@ static inline u8 lm3533_als_get_target_reg(unsigned channel, unsigned zone) }static int lm3533_als_get_target (struct iio_dev *indio_dev,unsigned channel, -unsigned zone,u8 *val) +unsigned zone,u32 *val) {struct lm3533_als *als =iio_priv (indio_dev);u8 reg;
@@ -140,7 +141,7 @@ static int lm3533_als_get_target(struct iio_dev *indio_dev, unsigned channel,return -EINVAL ; reg =lm3533_als_get_target_reg (channel, zone); - ret =lm3533_read (als->lm3533, reg, val); + ret =regmap_read (als->lm3533->regmap, reg, val);if (ret)dev_err (&indio_dev->dev,"failed to get target current\n" );
@@ -161,7 +162,7 @@ static int lm3533_als_set_target(struct iio_dev *indio_dev, unsigned channel,return -EINVAL ; reg =lm3533_als_get_target_reg (channel, zone); - ret =lm3533_write (als->lm3533, reg, val); + ret =regmap_write (als->lm3533->regmap, reg, val);if (ret)dev_err (&indio_dev->dev,"failed to set target current\n" );
@@ -172,7 +173,7 @@ static int lm3533_als_get_current(struct iio_dev *indio_dev, unsigned channel, int *val) {u8 zone; -u8 target; +u32 target;int ret; ret =lm3533_als_get_zone (indio_dev, &zone);
@@ -280,7 +281,8 @@ static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable)else val =0 ; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + val, mask);if (ret) {dev_err (&indio_dev->dev,"failed to set int mode %d\n" , enable);
@@ -294,10 +296,10 @@ static int lm3533_als_get_int_mode(struct iio_dev *indio_dev, int *enable) {struct lm3533_als *als =iio_priv (indio_dev);u8 mask =LM3533_ALS_INT_ENABLE_MASK ; -u8 val; +u32 val;int ret; - ret =lm3533_read (als->lm3533,LM3533_REG_ALS_ZONE_INFO , &val); + ret =regmap_read (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , &val);if (ret) {dev_err (&indio_dev->dev,"failed to get int mode\n" );return ret;
@@ -316,7 +318,7 @@ static inline u8 lm3533_als_get_threshold_reg(unsigned nr, bool raising) }static int lm3533_als_get_threshold (struct iio_dev *indio_dev,unsigned nr, -bool raising,u8 *val) +bool raising,u32 *val) {struct lm3533_als *als =iio_priv (indio_dev);u8 reg;
@@ -326,7 +328,7 @@ static int lm3533_als_get_threshold(struct iio_dev *indio_dev, unsigned nr,return -EINVAL ; reg =lm3533_als_get_threshold_reg (nr, raising); - ret =lm3533_read (als->lm3533, reg, val); + ret =regmap_read (als->lm3533->regmap, reg, val);if (ret)dev_err (&indio_dev->dev,"failed to get threshold\n" );
@@ -337,7 +339,7 @@ static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr, bool raising, u8 val) {struct lm3533_als *als =iio_priv (indio_dev); -u8 val2; +u32 val2;u8 reg, reg2;int ret;
@@ -348,7 +350,7 @@ static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr, reg2 =lm3533_als_get_threshold_reg (nr, !raising);mutex_lock (&als->thresh_mutex); - ret =lm3533_read (als->lm3533, reg2, &val2); + ret =regmap_read (als->lm3533->regmap, reg2, &val2);if (ret) {dev_err (&indio_dev->dev,"failed to get threshold\n" ); goto out;
@@ -363,7 +365,7 @@ static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr, goto out; } - ret =lm3533_write (als->lm3533, reg, val); + ret =regmap_write (als->lm3533->regmap, reg, val);if (ret) {dev_err (&indio_dev->dev,"failed to set threshold\n" ); goto out;
@@ -375,11 +377,11 @@ static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr, }static int lm3533_als_get_hysteresis (struct iio_dev *indio_dev,unsigned nr, -u8 *val) +u32 *val) {struct lm3533_als *als =iio_priv (indio_dev); -u8 falling; -u8 raising; +u32 falling; +u32 raising;int ret;if (nr >LM3533_ALS_THRESH_MAX )
@@ -503,7 +505,7 @@ static ssize_t show_als_attr(struct device *dev, {struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct lm3533_als_attribute *als_attr =to_lm3533_als_attr (attr); -u8 val; +u32 val;int ret;switch (als_attr->type) {
@@ -725,7 +727,8 @@ static int lm3533_als_set_input_mode(struct lm3533_als *als, bool pwm_mode)else val =0 ;/* analog input */ - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, val);if (ret) {dev_err (&als->pdev->dev,"failed to set input mode %d\n" , pwm_mode);
@@ -744,7 +747,8 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)return -EINVAL ; } - ret =lm3533_write (als->lm3533,LM3533_REG_ALS_RESISTOR_SELECT , val); + ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , + val);if (ret) {dev_err (&als->pdev->dev,"failed to set resistor\n" );return ret;
@@ -778,7 +782,8 @@ static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev)int ret;/* Make sure interrupts are disabled. */ - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + mask,0 );if (ret) {dev_err (&als->pdev->dev,"failed to disable interrupts\n" );return ret;
@@ -801,7 +806,8 @@ static int lm3533_als_enable(struct lm3533_als *als)u8 mask =LM3533_ALS_ENABLE_MASK ;int ret; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , mask, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, mask);if (ret)dev_err (&als->pdev->dev,"failed to enable ALS\n" );
@@ -813,7 +819,8 @@ static int lm3533_als_disable(struct lm3533_als *als)u8 mask =LM3533_ALS_ENABLE_MASK ;int ret; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask,0 );if (ret)dev_err (&als->pdev->dev,"failed to disable ALS\n" );
drivers/leds/leds-lm3533.c +18 -16
@@ -12,6 +12,7 @@#include <linux/mfd/core.h> #include <linux/mutex.h> #include <linux/platform_device.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <linux/mfd/lm3533.h>
@@ -101,7 +102,8 @@ static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable)else val =0 ; - ret =lm3533_update (led->lm3533,LM3533_REG_PATTERN_ENABLE , val, mask); + ret =regmap_update_bits (led->lm3533->regmap, +LM3533_REG_PATTERN_ENABLE , mask, val);if (ret) {dev_err (led->cdev.dev,"failed to enable pattern %d (%d)\n" , pattern, enable);
@@ -131,7 +133,7 @@ static int lm3533_led_set(struct led_classdev *cdev,static enum led_brightness lm3533_led_get (struct led_classdev *cdev) {struct lm3533_led *led =to_lm3533_led (cdev); -u8 val; +u32 val;int ret; ret =lm3533_ctrlbank_get_brightness (&led->cb, &val);
@@ -259,7 +261,7 @@ static u8 lm3533_led_delay_set(struct lm3533_led *led, u8 base,dev_dbg (led->cdev.dev,"%s - %lu: %u (0x%02x)\n" , __func__, *delay, t, val); reg =lm3533_led_get_pattern_reg (led, base); - ret =lm3533_write (led->lm3533, reg, val); + ret =regmap_write (led->lm3533->regmap, reg, val);if (ret)dev_err (led->cdev.dev,"failed to set delay (%02x)\n" , reg);
@@ -337,10 +339,10 @@ static ssize_t show_risefalltime(struct device *dev,struct lm3533_led *led =to_lm3533_led (led_cdev);ssize_t ret;u8 reg; -u8 val; +u32 val; reg =lm3533_led_get_pattern_reg (led, base); - ret =lm3533_read (led->lm3533, reg, &val); + ret =regmap_read (led->lm3533->regmap, reg, &val);if (ret)return ret;
@@ -375,7 +377,7 @@ static ssize_t store_risefalltime(struct device *dev,return -EINVAL ; reg =lm3533_led_get_pattern_reg (led, base); - ret =lm3533_write (led->lm3533, reg, val); + ret =regmap_write (led->lm3533->regmap, reg, val);if (ret)return ret;
@@ -405,11 +407,11 @@ static ssize_t show_als_channel(struct device *dev,struct lm3533_led *led =to_lm3533_led (led_cdev);unsigned channel;u8 reg; -u8 val; +u32 val;int ret; reg =lm3533_led_get_lv_reg (led,LM3533_REG_CTRLBANK_BCONF_BASE ); - ret =lm3533_read (led->lm3533, reg, &val); + ret =regmap_read (led->lm3533->regmap, reg, &val);if (ret)return ret;
@@ -441,7 +443,7 @@ static ssize_t store_als_channel(struct device *dev, mask =LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK ; val = channel -1 ; - ret =lm3533_update (led->lm3533, reg, val, mask); + ret =regmap_update_bits (led->lm3533->regmap, reg, mask, val);if (ret)return ret;
@@ -455,11 +457,11 @@ static ssize_t show_als_en(struct device *dev,struct lm3533_led *led =to_lm3533_led (led_cdev);bool enable;u8 reg; -u8 val; +u32 val;int ret; reg =lm3533_led_get_lv_reg (led,LM3533_REG_CTRLBANK_BCONF_BASE ); - ret =lm3533_read (led->lm3533, reg, &val); + ret =regmap_read (led->lm3533->regmap, reg, &val);if (ret)return ret;
@@ -491,7 +493,7 @@ static ssize_t store_als_en(struct device *dev,else val =0 ; - ret =lm3533_update (led->lm3533, reg, val, mask); + ret =regmap_update_bits (led->lm3533->regmap, reg, mask, val);if (ret)return ret;
@@ -504,12 +506,12 @@ static ssize_t show_linear(struct device *dev,struct led_classdev *led_cdev =dev_get_drvdata (dev);struct lm3533_led *led =to_lm3533_led (led_cdev);u8 reg; -u8 val; +u32 val;int linear;int ret; reg =lm3533_led_get_lv_reg (led,LM3533_REG_CTRLBANK_BCONF_BASE ); - ret =lm3533_read (led->lm3533, reg, &val); + ret =regmap_read (led->lm3533->regmap, reg, &val);if (ret)return ret;
@@ -544,7 +546,7 @@ static ssize_t store_linear(struct device *dev,else val =0 ; - ret =lm3533_update (led->lm3533, reg, val, mask); + ret =regmap_update_bits (led->lm3533->regmap, reg, mask, val);if (ret)return ret;
@@ -557,7 +559,7 @@ static ssize_t show_pwm(struct device *dev, {struct led_classdev *led_cdev =dev_get_drvdata (dev);struct lm3533_led *led =to_lm3533_led (led_cdev); -u8 val; +u32 val;int ret; ret =lm3533_ctrlbank_get_pwm (&led->cb, &val);
drivers/mfd/lm3533-core.c +11 -62
114 lines not on this page · raw message
drivers/mfd/lm3533-ctrlbank.c +12 -10
@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/module.h> +#include <linux/regmap.h> #include <linux/mfd/lm3533.h>
@@ -38,8 +39,8 @@ int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb)dev_dbg (cb->dev,"%s - %d\n" , __func__, cb->id); mask =1 << cb->id; - ret =lm3533_update (cb->lm3533,LM3533_REG_CTRLBANK_ENABLE , - mask, mask); + ret =regmap_update_bits (cb->lm3533->regmap,LM3533_REG_CTRLBANK_ENABLE , + mask, mask);if (ret)dev_err (cb->dev,"failed to enable ctrlbank %d\n" , cb->id);
@@ -55,7 +56,8 @@ int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb)dev_dbg (cb->dev,"%s - %d\n" , __func__, cb->id); mask =1 << cb->id; - ret =lm3533_update (cb->lm3533,LM3533_REG_CTRLBANK_ENABLE ,0 , mask); + ret =regmap_update_bits (cb->lm3533->regmap,LM3533_REG_CTRLBANK_ENABLE , + mask,0 );if (ret)dev_err (cb->dev,"failed to disable ctrlbank %d\n" , cb->id);
@@ -80,7 +82,7 @@ int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u16 imax) val = (imax -LM3533_MAX_CURRENT_MIN ) /LM3533_MAX_CURRENT_STEP ; reg =lm3533_ctrlbank_get_reg (cb,LM3533_REG_MAX_CURRENT_BASE ); - ret =lm3533_write (cb->lm3533, reg, val); + ret =regmap_write (cb->lm3533->regmap, reg, val);if (ret)dev_err (cb->dev,"failed to set max current\n" );
@@ -94,7 +96,7 @@ int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val)int ret; reg =lm3533_ctrlbank_get_reg (cb,LM3533_REG_BRIGHTNESS_BASE ); - ret =lm3533_write (cb->lm3533, reg, val); + ret =regmap_write (cb->lm3533->regmap, reg, val);if (ret)dev_err (cb->dev,"failed to set brightness\n" );
@@ -102,13 +104,13 @@ int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val) }EXPORT_SYMBOL_GPL (lm3533_ctrlbank_set_brightness); -int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u8 *val) +int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u32 *val) {u8 reg;int ret; reg =lm3533_ctrlbank_get_reg (cb,LM3533_REG_BRIGHTNESS_BASE ); - ret =lm3533_read (cb->lm3533, reg, val); + ret =regmap_read (cb->lm3533->regmap, reg, val);if (ret)dev_err (cb->dev,"failed to get brightness\n" );
@@ -135,7 +137,7 @@ int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val)return -EINVAL ; reg =lm3533_ctrlbank_get_reg (cb,LM3533_REG_PWM_BASE ); - ret =lm3533_write (cb->lm3533, reg, val); + ret =regmap_write (cb->lm3533->regmap, reg, val);if (ret)dev_err (cb->dev,"failed to set PWM mask\n" );
@@ -143,13 +145,13 @@ int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val) }EXPORT_SYMBOL_GPL (lm3533_ctrlbank_set_pwm); -int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u8 *val) +int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u32 *val) {u8 reg;int ret; reg =lm3533_ctrlbank_get_reg (cb,LM3533_REG_PWM_BASE ); - ret =lm3533_read (cb->lm3533, reg, val); + ret =regmap_read (cb->lm3533->regmap, reg, val);if (ret)dev_err (cb->dev,"failed to get PWM mask\n" );
drivers/video/backlight/lm3533_bl.c +11 -10
@@ -11,6 +11,7 @@#include <linux/init.h> #include <linux/platform_device.h> #include <linux/backlight.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <linux/mfd/lm3533.h>
@@ -45,7 +46,7 @@ static int lm3533_bl_update_status(struct backlight_device *bd)static int lm3533_bl_get_brightness (struct backlight_device *bd) {struct lm3533_bl *bl =bl_get_data (bd); -u8 val; +u32 val;int ret; ret =lm3533_ctrlbank_get_brightness (&bl->cb, &val);
@@ -82,12 +83,12 @@ static ssize_t show_als_en(struct device *dev, {struct lm3533_bl *bl =dev_get_drvdata (dev);int ctrlbank =lm3533_bl_get_ctrlbank_id (bl); -u8 val; +u32 val;u8 mask;bool enable;int ret; - ret =lm3533_read (bl->lm3533,LM3533_REG_CTRLBANK_AB_BCONF , &val); + ret =regmap_read (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , &val);if (ret)return ret;
@@ -118,8 +119,8 @@ static ssize_t store_als_en(struct device *dev,else val =0 ; - ret =lm3533_update (bl->lm3533,LM3533_REG_CTRLBANK_AB_BCONF , val, - mask); + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , + mask, val);if (ret)return ret;
@@ -130,12 +131,12 @@ static ssize_t show_linear(struct device *dev, struct device_attribute *attr, char *buf) { struct lm3533_bl *bl = dev_get_drvdata(dev); -u8 val; +u32 val;u8 mask;int linear;int ret; - ret =lm3533_read (bl->lm3533,LM3533_REG_CTRLBANK_AB_BCONF , &val); + ret =regmap_read (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , &val);if (ret)return ret;
@@ -169,8 +170,8 @@ static ssize_t store_linear(struct device *dev,else val =0 ; - ret =lm3533_update (bl->lm3533,LM3533_REG_CTRLBANK_AB_BCONF , val, - mask); + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , + mask, val);if (ret)return ret;
@@ -182,7 +183,7 @@ static ssize_t show_pwm(struct device *dev, char *buf) {struct lm3533_bl *bl =dev_get_drvdata (dev); -u8 val; +u32 val;int ret; ret =lm3533_ctrlbank_get_pwm (&bl->cb, &val);
include/linux/mfd/lm3533.h +2 -6
@@ -86,14 +86,10 @@ extern int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb);extern int lm3533_ctrlbank_disable (struct lm3533_ctrlbank *cb);extern int lm3533_ctrlbank_set_brightness (struct lm3533_ctrlbank *cb,u8 val); -extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u8 *val); +extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u32 *val);extern int lm3533_ctrlbank_set_max_current (struct lm3533_ctrlbank *cb,u16 imax);extern int lm3533_ctrlbank_set_pwm (struct lm3533_ctrlbank *cb,u8 val); -extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u8 *val); - -extern int lm3533_read (struct lm3533 *lm3533,u8 reg,u8 *val); -extern int lm3533_write (struct lm3533 *lm3533,u8 reg,u8 val); -extern int lm3533_update (struct lm3533 *lm3533,u8 reg,u8 val,u8 mask); +extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u32 *val);#endif /* __LINUX_MFD_LM3533_H */
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v3 02/11] mfd: lm3533: Remove driver specific regmap wrappers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incorrect argument order for `regmap_update_bits` silently prevents disabling interrupts. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect argument order for regmap_update_bits silently prevents disabling interrupts. --
commit 02ae49c5dba8ff55717ce569312b1ed0ac85b17f
Author: Svyatoslav Ryhel <[email protected]>
mfd: lm3533: Remove driver specific regmap wrappers
This commit replaces custom wrapper functions for regmap access with standard regmap helpers across the lm3533 MFD driver and its sub-device drivers. The commit message notes that regmap_update_bits requires the mask and value arguments to be swapped compared to the old wrappers.
Quoted 4 lines
drivers/iio/light/lm3533-als.c +0
-0
[ ... ]
drivers/iio/light/lm3533-als.c static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable) · line 285
Quoted 7 lines
drivers/iio/light/lm3533-als.c +2
-1@@ -280,7 +281,8 @@ static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable)else val =0 ; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + val, mask);
[Severity: High]
Are the mask and val arguments swapped in this regmap_update_bits() call?
The commit message mentions that regmap_update_bits() has the mask and value arguments swapped compared to the old wrapper, but in this instance they are passed as val, then mask.
If enable is false, val is 0. Calling regmap_update_bits() with 0 as the bitmask will modify zero bits, which fails to clear the interrupt enable bit. Could this cause an unhandled interrupt storm when the interrupt is disabled via sysfs, or when the driver is removed and free_irq() is called while the level-triggered IRQ line remains asserted?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 02/11] mfd: lm3533: Remove driver specific regmap wrappers
In reply to Svyatoslav RyhelQuoted 5 lines · Svyatoslav Ryhel
Remove driver-specific regmap wrappers in favor of using regmap helpers directly. The wrappers are mostly equivalent to the standard helpers, with two exceptions:
regmap_readrequires an unsigned int pointer, andregmap_update_bitshas the mask and value arguments swapped. These differences were accounted for and adjusted accordingly.
We refer to functions as func(), exempli gratia, regmap_read().
...
drivers/iio/light/lm3533-als.c static int lm3533_als_get_current(struct iio_dev *indio_dev, unsigned channel, · line 177
Quoted 7 lines
static int lm3533_als_get_current(struct
iio_dev*indio_dev, unsigned channel,drivers/iio/light/lm3533-als.c +1
-1int *val) {u8 zone; -u8 target; +u32 target;int ret;
While at it, move towards reversed xmas tree order
u32 target; u8 zone; int ret;
...
drivers/iio/light/lm3533-als.c static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable) · line 285
Quoted 3 lines
drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + val, mask);
It's better to replace this to use _set_bits()/_clear_bits() or even move from the above conditional (not in this context) to _assign_bits().
...
drivers/iio/light/lm3533-als.c static int lm3533_als_set_input_mode(struct lm3533_als *als, bool pwm_mode) · line 731
Quoted 6 lines
drivers/iio/light/lm3533-als.c +2
-1else val =0 ;/* analog input */ - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, val);
Ditto.
Quoted 3 lines
drivers/iio/light/lm3533-als.c +0
-0if (ret) {dev_err (&als->pdev->dev,"failed to set input mode %d\n" , pwm_mode);
...
drivers/iio/light/lm3533-als.c static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev) · line 786
Quoted 4 lines
drivers/iio/light/lm3533-als.c +2
-1/* Make sure interrupts are disabled. */ - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + mask,0 );
_clear_bits().
Quoted 3 lines
drivers/iio/light/lm3533-als.c +0
-0if (ret) {dev_err (&als->pdev->dev,"failed to disable interrupts\n" );return ret;
...
drivers/iio/light/lm3533-als.c static int lm3533_als_enable(struct lm3533_als *als) · line 810
Quoted 6 lines
drivers/iio/light/lm3533-als.c +2
-1u8 mask =LM3533_ALS_ENABLE_MASK ;int ret; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , mask, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, mask);
_set_bits()
Quoted 3 lines
drivers/iio/light/lm3533-als.c +0
-0if (ret)dev_err (&als->pdev->dev,"failed to enable ALS\n" );
...
drivers/iio/light/lm3533-als.c static int lm3533_als_disable(struct lm3533_als *als) · line 823
Quoted 6 lines
drivers/iio/light/lm3533-als.c +2
-1u8 mask =LM3533_ALS_ENABLE_MASK ;int ret; - ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask,0 );
_clear_bits()
Quoted 2 lines
drivers/iio/light/lm3533-als.c +0
-0if (ret)dev_err (&als->pdev->dev,"failed to disable ALS\n" );
...
drivers/leds/leds-lm3533.c static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable) · line 106
Quoted 6 lines
drivers/leds/leds-lm3533.c +2
-1else val =0 ; - ret =lm3533_update (led->lm3533,LM3533_REG_PATTERN_ENABLE , val, mask); + ret =regmap_update_bits (led->lm3533->regmap, +LM3533_REG_PATTERN_ENABLE , mask, val);
_assign_bits() and so on...
Quoted 3 lines
drivers/leds/leds-lm3533.c +0
-0if (ret) {dev_err (led->cdev.dev,"failed to enable pattern %d (%d)\n" , pattern, enable);
...
include/linux/mfd/lm3533.h extern int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb); · line 89
Quoted 3 lines
extern int
lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val);include/linux/mfd/lm3533.h +1
-1-extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u8 *val); +extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u32 *val);
We don't need to keep 'extern' for ages.
Quoted 9 lines
extern int lm3533_ctrlbank_set_max_current(struct
lm3533_ctrlbank*cb,include/linux/mfd/lm3533.h +1
-5u16 imax);extern int lm3533_ctrlbank_set_pwm (struct lm3533_ctrlbank *cb,u8 val); -extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u8 *val); - -extern int lm3533_read (struct lm3533 *lm3533,u8 reg,u8 *val); -extern int lm3533_write (struct lm3533 *lm3533,u8 reg,u8 val); -extern int lm3533_update (struct lm3533 *lm3533,u8 reg,u8 val,u8 mask); +extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u32 *val);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 02/11] mfd: lm3533: Remove driver specific regmap wrappers
вт, 2 черв. 2026 р. о 11:05 Andy Shevchenko <[email protected]> пише:
Quoted 10 lines · Svyatoslav Ryhel
Quoted 5 lines
Remove driver-specific regmap wrappers in favor of using regmap helpers directly. The wrappers are mostly equivalent to the standard helpers, with two exceptions:
regmap_readrequires an unsigned int pointer, andregmap_update_bitshas the mask and value arguments swapped. These differences were accounted for and adjusted accordingly.We refer to functions as
func(), exempli gratia,regmap_read().
Noted.
Quoted 10 lines
...
drivers/iio/light/lm3533-als.c static int lm3533_als_get_current(struct iio_dev *indio_dev, unsigned channel, · line 177
Quoted 7 lines
static int lm3533_als_get_current(struct
iio_dev*indio_dev, unsigned channel,
int *val){ u8 zone;drivers/iio/light/lm3533-als.c +1
-1-u8 target; +u32 target;int ret;
Quoted 6 lines
While at it, move towards reversed xmas tree order
u32 target; u8 zone; int ret;
Noted.
Quoted 10 lines
...
drivers/iio/light/lm3533-als.c static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable) · line 285
Quoted 3 lines
drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + val, mask);It's better to replace this to use _set_bits()/_clear_bits() or even move from the above conditional (not in this context) to
_assign_bits().
I will take a look.
Quoted 72 lines
...
drivers/iio/light/lm3533-als.c static int lm3533_als_set_input_mode(struct lm3533_als *als, bool pwm_mode) · line 731
Quoted 6 lines
else
val = 0; /* analog input */drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , val, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, val);Ditto.
Quoted 3 lines
if (ret) { dev_err(&als->pdev->dev, "failed to set input mode %d\n", pwm_mode);...
drivers/iio/light/lm3533-als.c static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev) · line 786
Quoted 4 lines
/* Make sure interrupts are disabled. */drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_ZONE_INFO ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_ZONE_INFO , + mask,0 );
_clear_bits().Quoted 3 lines
if (ret) { dev_err(&als->pdev->dev, "failed to disable interrupts\n"); return ret;...
drivers/iio/light/lm3533-als.c static int lm3533_als_enable(struct lm3533_als *als) · line 810
Quoted 6 lines
u8 mask = LM3533_ALS_ENABLE_MASK; int ret;drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF , mask, mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask, mask);
_set_bits()Quoted 3 lines
if (ret) dev_err(&als->pdev->dev, "failed to enable ALS\n");...
drivers/iio/light/lm3533-als.c static int lm3533_als_disable(struct lm3533_als *als) · line 823
Quoted 6 lines
u8 mask = LM3533_ALS_ENABLE_MASK; int ret;drivers/iio/light/lm3533-als.c +2
-1- ret =lm3533_update (als->lm3533,LM3533_REG_ALS_CONF ,0 , mask); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , + mask,0 );
_clear_bits()Quoted 2 lines
if (ret) dev_err(&als->pdev->dev, "failed to disable ALS\n");...
drivers/leds/leds-lm3533.c static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable) · line 106
Quoted 6 lines
else val = 0;drivers/leds/leds-lm3533.c +2
-1- ret =lm3533_update (led->lm3533,LM3533_REG_PATTERN_ENABLE , val, mask); + ret =regmap_update_bits (led->lm3533->regmap, +LM3533_REG_PATTERN_ENABLE , mask, val);
_assign_bits()and so on...Quoted 3 lines
if (ret) { dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n", pattern, enable);
Quoted 8 lines
...
include/linux/mfd/lm3533.h extern int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb); · line 89
Quoted 3 lines
extern int
lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val);include/linux/mfd/lm3533.h +1
-1-extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u8 *val); +extern int lm3533_ctrlbank_get_brightness (struct lm3533_ctrlbank *cb,u32 *val);We don't need to keep 'extern' for ages.
I will no inflate this patchset further
Quoted 15 lines
include/linux/mfd/lm3533.h extern int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb); · line 93
Quoted 9 lines
extern int lm3533_ctrlbank_set_max_current(struct
lm3533_ctrlbank*cb,u16 imax);extern int
lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val);include/linux/mfd/lm3533.h +1
-5-extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u8 *val); - -extern int lm3533_read (struct lm3533 *lm3533,u8 reg,u8 *val); -extern int lm3533_write (struct lm3533 *lm3533,u8 reg,u8 val); -extern int lm3533_update (struct lm3533 *lm3533,u8 reg,u8 val,u8 mask); +extern int lm3533_ctrlbank_get_pwm (struct lm3533_ctrlbank *cb,u32 *val);--
With Best Regards,
Andy Shevchenko
PATCH v3 3/11 iio: light: lm3533-als: Remove redundant pdata helpers
In reply to Svyatoslav RyhelThe lm3533_als_set_input_mode and lm3533_als_set_resistor functions are used only in lm3533_als_setup. Incorporate their code into lm3533_als_setup directly to simplify driver readability.
--- drivers/iio/light/lm3533-als.c | 61 +++++++++------------------------- 1 file changed, 16 insertions(+), 45 deletions(-)
drivers/iio/light/lm3533-als.c +16 -45
@@ -716,61 +716,32 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_set_input_mode (struct lm3533_als *als,bool pwm_mode) -{ -u8 mask =LM3533_ALS_INPUT_MODE_MASK ; -u8 val; -int ret; - -if (pwm_mode) - val = mask;/* pwm input */ -else - val =0 ;/* analog input */ - - ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , - mask, val); -if (ret) { -dev_err (&als->pdev->dev,"failed to set input mode %d\n" , - pwm_mode); -return ret; - } - -return 0 ; -} - -static int lm3533_als_set_resistor (struct lm3533_als *als,u8 val) -{ -int ret; - -if (val <LM3533_ALS_RESISTOR_MIN || val >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } - - ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - val); -if (ret) { -dev_err (&als->pdev->dev,"failed to set resistor\n" ); -return ret; - } - -return 0 ; -} -static int lm3533_als_setup (struct lm3533_als *als,const struct lm3533_als_platform_data *pdata) { +struct device *dev = &als->pdev->dev;int ret; - ret =lm3533_als_set_input_mode (als, pdata->pwm_mode); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF , +LM3533_ALS_INPUT_MODE_MASK , + pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret) -return ret; +return dev_err_probe (dev, ret,"failed to set input mode %d\n" , + pdata->pwm_mode); +/* ALS input is always high impedance in PWM-mode. */ if (!pdata->pwm_mode) { - ret =lm3533_als_set_resistor (als, pdata->r_select); +if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || + pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { +dev_err (&als->pdev->dev,"invalid resistor value\n" ); +return -EINVAL ; + } + + ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , + pdata->r_select);if (ret) -return ret; +return dev_err_probe (dev, ret,"failed to set resistor\n" ); }return 0 ;
Signature · 1 line
2.51.0
Re: [PATCH v3 03/11] iio: light: lm3533-als: Remove redundant pdata helpers
Quoted 3 lines · Svyatoslav Ryhel
The
lm3533_als_set_input_modeandlm3533_als_set_resistorfunctions are used only inlm3533_als_setup. Incorporate their code intolm3533_als_setupdirectly to simplify driver readability.
Same comments as per previous patch.
I stop my review here as it seems may be more of this.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v3 03/11] iio: light: lm3533-als: Remove redundant pdata helpers
In reply to Svyatoslav RyhelQuoted 3 lines · On Mon, 1 Jun 2026 18:18:23 +0300 Svyatoslav Ryhel <[email protected]> wrote:
The
lm3533_als_set_input_modeandlm3533_als_set_resistorfunctions are used only inlm3533_als_setup. Incorporate their code intolm3533_als_setupdirectly to simplify driver readability.
Minor stuff inline.
Quoted 10 lines
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/lm3533-als.c | 61 +++++++++------------------------- 1 file changed, 16 insertions(+), 45 deletions(-)drivers/iio/light/lm3533-als.c +0
-0
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 725
Quoted 9 lines
drivers/iio/light/lm3533-als.c +2
-1static int lm3533_als_setup (struct lm3533_als *als,const struct lm3533_als_platform_data *pdata) { +struct device *dev = &als->pdev->dev;int ret; - ret =lm3533_als_set_input_mode (als, pdata->pwm_mode); + ret = regmap_update_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
Maybe a local struct regmap pointer given dereferenced in a couple of places.
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 727
Quoted 2 lines
drivers/iio/light/lm3533-als.c +2
-0+LM3533_ALS_INPUT_MODE_MASK , + pdata->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0);
Andy raised this in previous patch but in the interests of being specific regmap_assign_bits() is going to be cleaner here.
Quoted 23 lines
drivers/iio/light/lm3533-als.c +12
-3if (ret) -return ret; +return dev_err_probe (dev, ret,"failed to set input mode %d\n" , + pdata->pwm_mode); +/* ALS input is always high impedance in PWM-mode. */ if (!pdata->pwm_mode) { - ret =lm3533_als_set_resistor (als, pdata->r_select); +if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || + pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { +dev_err (&als->pdev->dev,"invalid resistor value\n" ); +return -EINVAL ; + } + + ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , + pdata->r_select);if (ret) -return ret; +return dev_err_probe (dev, ret,"failed to set resistor\n" ); }return 0 ;
Re: [PATCH v3 03/11] iio: light: lm3533-als: Remove redundant pdata helpers
вт, 2 черв. 2026 р. о 16:42 Jonathan Cameron <[email protected]> пише:
Quoted 27 lines
Quoted 3 lines · On Mon, 1 Jun 2026 18:18:23 +0300 Svyatoslav Ryhel <[email protected]> wrote:
The
lm3533_als_set_input_modeandlm3533_als_set_resistorfunctions are used only inlm3533_als_setup. Incorporate their code intolm3533_als_setupdirectly to simplify driver readability.Minor stuff inline.
Quoted 17 lines
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/iio/light/lm3533-als.c | 61 +++++++++------------------------- 1 file changed, 16 insertions(+), 45 deletions(-)drivers/iio/light/lm3533-als.c +1
-0static int lm3533_als_setup (struct lm3533_als *als,const struct lm3533_als_platform_data *pdata) { +struct device *dev = &als->pdev->dev;int ret;
Quoted 5 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 725
Quoted 2 lines
drivers/iio/light/lm3533-als.c +1
-1- ret =lm3533_als_set_input_mode (als, pdata->pwm_mode); + ret = regmap_update_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,Maybe a local struct regmap pointer given dereferenced in a couple of places.
sure, why not
Quoted 6 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 727
Quoted 2 lines
drivers/iio/light/lm3533-als.c +2
-0+LM3533_ALS_INPUT_MODE_MASK , + pdata->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0);Andy raised this in previous patch but in the interests of being specific
regmap_assign_bits()is going to be cleaner here.
I am currently adjusting accordingly.
Quoted 24 lines
Quoted 23 lines
if (ret)
drivers/iio/light/lm3533-als.c +12
-3-return ret; +return dev_err_probe (dev, ret,"failed to set input mode %d\n" , + pdata->pwm_mode); +/* ALS input is always high impedance in PWM-mode. */ if (!pdata->pwm_mode) { - ret =lm3533_als_set_resistor (als, pdata->r_select); +if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || + pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { +dev_err (&als->pdev->dev,"invalid resistor value\n" ); +return -EINVAL ; + } + + ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , + pdata->r_select);if (ret) -return ret; +return dev_err_probe (dev, ret,"failed to set resistor\n" ); }return 0 ;
PATCH v3 4/11 mfd: lm3533-core: Remove redundant pdata helpers
In reply to Svyatoslav RyhelThe lm3533_set_boost_freq and lm3533_set_boost_ovp functions are used only in lm3533_device_setup, which in turn is only called by lm3533_device_init. Incorporate their code directly into lm3533_device_init to simplify driver readability.
--- drivers/mfd/lm3533-core.c | 57 ++++++++++----------------------------- 1 file changed, 14 insertions(+), 43 deletions(-)
drivers/mfd/lm3533-core.c +14 -43
@@ -80,35 +80,6 @@ static struct mfd_cell lm3533_led_devs[] = { }, }; -static int lm3533_set_boost_freq (struct lm3533 *lm3533, -enum lm3533_boost_freq freq) -{ -int ret; - - ret =regmap_update_bits (lm3533->regmap,LM3533_REG_BOOST_PWM , -LM3533_BOOST_FREQ_MASK , - freq <<LM3533_BOOST_FREQ_SHIFT ); -if (ret) -dev_err (lm3533->dev,"failed to set boost frequency\n" ); - -return ret; -} - - -static int lm3533_set_boost_ovp (struct lm3533 *lm3533, -enum lm3533_boost_ovp ovp) -{ -int ret; - - ret =regmap_update_bits (lm3533->regmap,LM3533_REG_BOOST_PWM , -LM3533_BOOST_OVP_MASK , - ovp <<LM3533_BOOST_OVP_SHIFT ); -if (ret) -dev_err (lm3533->dev,"failed to set boost ovp\n" ); - -return ret; -} -/* * HVLED output config -- output hvled controlled by backlight bl */
@@ -406,18 +377,6 @@ static int lm3533_device_led_init(struct lm3533 *lm3533)return 0 ; } -static int lm3533_device_setup (struct lm3533 *lm3533, -struct lm3533_platform_data *pdata) -{ -int ret; - - ret =lm3533_set_boost_freq (lm3533, pdata->boost_freq); -if (ret) -return ret; - -return lm3533_set_boost_ovp (lm3533, pdata->boost_ovp); -} -static int lm3533_device_init (struct lm3533 *lm3533) {struct lm3533_platform_data *pdata =dev_get_platdata (lm3533->dev);
@@ -437,9 +396,21 @@ static int lm3533_device_init(struct lm3533 *lm3533)lm3533_enable (lm3533); - ret =lm3533_device_setup (lm3533, pdata); -if (ret) + ret =regmap_update_bits (lm3533->regmap,LM3533_REG_BOOST_PWM , +LM3533_BOOST_FREQ_MASK , + pdata->boost_freq <<LM3533_BOOST_FREQ_SHIFT ); +if (ret) { +dev_err (lm3533->dev,"failed to set boost frequency\n" ); goto err_disable; + } + + ret =regmap_update_bits (lm3533->regmap,LM3533_REG_BOOST_PWM , +LM3533_BOOST_OVP_MASK , + pdata->boost_ovp <<LM3533_BOOST_OVP_SHIFT ); +if (ret) { +dev_err (lm3533->dev,"failed to set boost ovp\n" ); + goto err_disable; + }lm3533_device_als_init (lm3533);lm3533_device_bl_init (lm3533);
Signature · 1 line
2.51.0
PATCH v3 5/11 mfd: lm3533: Convert to use OF bindings
In reply to Svyatoslav RyhelSince there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
--- drivers/iio/light/lm3533-als.c | 69 +++++---- drivers/leds/leds-lm3533.c | 51 ++++-- drivers/mfd/lm3533-core.c | 232 ++++++++++++---------------- drivers/mfd/lm3533-ctrlbank.c | 5 - drivers/video/backlight/lm3533_bl.c | 58 ++++--- include/linux/mfd/lm3533.h | 52 +------ 6 files changed, 222 insertions(+), 245 deletions(-)
drivers/iio/light/lm3533-als.c +41 -28
@@ -16,16 +16,19 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/mfd/core.h> +#include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/units.h> #include <linux/mfd/lm3533.h> -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 +#define LM3533_ALS_RESISTOR_MIN 1575 +#define LM3533_ALS_RESISTOR_MAX 200000#define LM3533_ALS_CHANNEL_CURRENT_MAX 2#define LM3533_ALS_THRESH_MAX 3#define LM3533_ALS_ZONE_MAX 4
@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };
@@ -411,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,int enable;int ret; -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_get_int_mode (indio_dev, &enable);if (ret)return ret;
@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {struct device *dev = &als->pdev->dev;int ret; + als->pwm_mode =device_property_read_bool (dev,"ti,pwm-mode" ); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF ,LM3533_ALS_INPUT_MODE_MASK , - pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 ); + als->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret)return dev_err_probe (dev, ret,"failed to set input mode %d\n" , - pdata->pwm_mode); - + als->pwm_mode);/* ALS input is always high impedance in PWM-mode. */ -if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select); +if (ret) +return dev_err_probe (dev, ret, +"failed to ger resistor value\n" ); + + als->r_select =clamp (als->r_select,LM3533_ALS_RESISTOR_MIN , +LM3533_ALS_RESISTOR_MAX ); + als->r_select =DIV_ROUND_UP (2 *MICRO ,10 * als->r_select); ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - pdata->r_select); + als->r_select);if (ret)return dev_err_probe (dev, ret,"failed to set resistor\n" ); }
@@ -806,7 +816,6 @@ static const struct iio_info lm3533_als_info = {static int lm3533_als_probe (struct platform_device *pdev) { -const struct lm3533_als_platform_data *pdata;struct lm3533 *lm3533;struct lm3533_als *als;struct iio_dev *indio_dev;
@@ -816,12 +825,6 @@ static int lm3533_als_probe(struct platform_device *pdev)if (!lm3533)return -EINVAL ; - pdata =dev_get_platdata (&pdev->dev); -if (!pdata) { -dev_err (&pdev->dev,"no platform data\n" ); -return -EINVAL ; - } - indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*als));if (!indio_dev)return -ENOMEM ;
@@ -830,25 +833,28 @@ static int lm3533_als_probe(struct platform_device *pdev) indio_dev->channels = lm3533_als_channels; indio_dev->num_channels =ARRAY_SIZE (lm3533_als_channels); indio_dev->name =dev_name (&pdev->dev); -iio_device_set_parent (indio_dev, pdev->dev.parent); indio_dev->modes =INDIO_DIRECT_MODE ; als =iio_priv (indio_dev); als->lm3533 = lm3533; als->pdev = pdev; - als->irq = lm3533->irq; + als->irq =platform_get_irq_optional (pdev,0 ); + +if (als->irq == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +atomic_set (&als->zone,0 );mutex_init (&als->thresh_mutex);platform_set_drvdata (pdev, indio_dev); -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_setup_irq (als, indio_dev);if (ret)return ret; } - ret =lm3533_als_setup (als, pdata); + ret =lm3533_als_setup (als);if (ret) goto err_free_irq;
@@ -867,7 +873,7 @@ static int lm3533_als_probe(struct platform_device *pdev) err_disable:lm3533_als_disable (als); err_free_irq: -if (als->irq) +if (als->irq >0 )free_irq (als->irq, indio_dev);return ret;
@@ -881,13 +887,20 @@ static void lm3533_als_remove(struct platform_device *pdev)lm3533_als_set_int_mode (indio_dev, false);iio_device_unregister (indio_dev);lm3533_als_disable (als); -if (als->irq) +if (als->irq >0 )free_irq (als->irq, indio_dev); } +static const struct of_device_id lm3533_als_match_table[] = { + { .compatible ="ti,lm3533-als" }, + { } +}; +MODULE_DEVICE_TABLE (of, lm3533_als_match_table); +static struct platform_driver lm3533_als_driver = { .driver = { .name ="lm3533-als" , + .of_match_table = lm3533_als_match_table, }, .probe = lm3533_als_probe, .remove = lm3533_als_remove,
drivers/leds/leds-lm3533.c +35 -16
121 lines not on this page · raw message
drivers/mfd/lm3533-core.c +100 -132
317 lines not on this page · raw message
drivers/mfd/lm3533-ctrlbank.c +0 -5
@@ -13,11 +13,6 @@#include <linux/mfd/lm3533.h> - -#define LM3533_MAX_CURRENT_MIN 5000 -#define LM3533_MAX_CURRENT_MAX 29800 -#define LM3533_MAX_CURRENT_STEP 800 -#define LM3533_PWM_MAX 0x3f#define LM3533_REG_PWM_BASE 0x14
drivers/video/backlight/lm3533_bl.c +39 -19
128 lines not on this page · raw message
include/linux/mfd/lm3533.h +7 -45
70 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Out-of-bounds array write in `lm3533_devices` when a DT child node matches multiple compatible…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Out-of-bounds array write in lm3533_devices when a DT child node matches multiple compatible strings.
- [High] The ALS driver expects the 'ti,resistor-value-ohms' property, but the DT binding defines 'ti,resistor-ohms'.
- [Medium] Skipped child nodes with invalid 'reg' properties will cause 'mfd_add_devices' to assign the wrong OF node to subsequent valid subdevices.
- [Medium] The check if (!als->irq) in store_thresh_either_en fails to handle negative error codes returned by platform_get_irq_optional, allowing invalid IRQ configuration.
- [Low] Incompatible pointer type passed to device_property_read_u32(), violating strict C typing.
--
commit 91427aa1400cfc0dbe1f634ca4391a5aa41811ec
Author: Svyatoslav Ryhel <[email protected]>
Subject: mfd: lm3533: Convert to use OF bindings
This commit converts the LM3533 driver stack from using platform data to using Device Tree bindings. It updates the core, als, backlight, and led drivers to parse properties directly from the device hierarchy.
Quoted 4 lines
drivers/iio/light/lm3533-als.c +0
-0
[ ... ]
Quoted 8 lines
drivers/iio/light/lm3533-als.c +1
-2@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {
[ ... ]
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 742
Quoted 9 lines
drivers/iio/light/lm3533-als.c +3
-6-if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select);
[Severity: High]
Does this use the wrong property name? The device tree binding requires "ti,resistor-ohms", but this attempts to read "ti,resistor-value-ohms". If a conformant DT is provided, this read will fail and unconditionally abort the driver probe when not in PWM mode.
Quoted 3 lines
drivers/iio/light/lm3533-als.c +3
-0+if (ret) +return dev_err_probe (dev, ret, +"failed to ger resistor value\n" );
[ ... ]
Quoted 5 lines
drivers/iio/light/lm3533-als.c +0
-1@@ -830,25 +833,28 @@ static int lm3533_als_probe(struct platform_device *pdev) indio_dev->channels = lm3533_als_channels; indio_dev->num_channels =ARRAY_SIZE (lm3533_als_channels); indio_dev->name =dev_name (&pdev->dev); -iio_device_set_parent (indio_dev, pdev->dev.parent);
drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 844
Quoted 10 lines
drivers/iio/light/lm3533-als.c +4
-1indio_dev->modes =INDIO_DIRECT_MODE ; als =iio_priv (indio_dev); als->lm3533 = lm3533; als->pdev = pdev; - als->irq = lm3533->irq; + als->irq =platform_get_irq_optional (pdev,0 ); + +if (als->irq == -EPROBE_DEFER ) +return -EPROBE_DEFER ;
[Severity: Medium]
Since platform_get_irq_optional() returns a negative error code (like -ENXIO) when an IRQ is absent, does the existing check in store_thresh_either_en() need to be updated as well?
Because store_thresh_either_en() still checks:
if (!als->irq)
return -EBUSY;A negative error code will bypass this check, allowing userspace to enable the interrupt mode via sysfs without a registered interrupt handler.
Quoted 3 lines
drivers/iio/light/lm3533-als.c +1
-0+atomic_set (&als->zone,0 );mutex_init (&als->thresh_mutex);
[ ... ]
Quoted 4 lines
drivers/mfd/lm3533-core.c +0
-0
[ ... ]
Quoted 3 lines
drivers/mfd/lm3533-core.c +1
-1-static int lm3533_device_init (struct lm3533 *lm3533) +static int lm3533_device_init (struct lm3533 *lm3533) {
[ ... ]
Quoted 23 lines
drivers/mfd/lm3533-core.c +13
-7+ lm3533_devices =devm_kcalloc (dev, nchilds,sizeof (*lm3533_devices), +GFP_KERNEL ); +if (!lm3533_devices) +return -ENOMEM ; - lm3533->have_leds =1 ; +device_for_each_child_node_scoped (lm3533->dev, child) { +if (!fwnode_device_is_available (child)) +continue ; -return 0 ; -} +if (count >= nchilds) +break ; -static int lm3533_device_init (struct lm3533 *lm3533) -{ -struct lm3533_platform_data *pdata =dev_get_platdata (lm3533->dev); -int ret; +if (fwnode_device_is_compatible (child,"ti,lm3533-als" )) { + lm3533_devices[count].name ="lm3533-als" ; + lm3533_devices[count].id =PLATFORM_DEVID_NONE ; + lm3533_devices[count].of_compatible ="ti,lm3533-als" ;
drivers/mfd/lm3533-core.c
Quoted 10 lines
drivers/mfd/lm3533-core.c +4
-4-dev_dbg (lm3533->dev,"%s\n" , __func__); + lm3533->have_als = true; + count++; + } -if (!pdata) { -dev_err (lm3533->dev,"no platform data\n" ); -return -EINVAL ; +if (fwnode_device_is_compatible (child,"ti,lm3533-backlight" )) {
[Severity: High]
Can a malformed device tree node cause a buffer overflow here? Since these are independent if-statements rather than mutually exclusive else-if blocks, a single node containing multiple matching compatible strings could execute multiple blocks in the same iteration. Because the bounds check against nchilds is only at the top of the loop, this would unconditionally increment count and write out of bounds of the lm3533_devices array.
Quoted 6 lines
drivers/mfd/lm3533-core.c +6
-0+ ret =fwnode_property_read_u32 (child,"reg" , ®); +if (ret || reg >=LM3533_HVLED_ID_MAX ) { +dev_err (dev,"invalid backlight node %s\n" , +fwnode_get_name (child)); +continue ; + }
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = {
Quoted 10 lines
drivers/mfd/lm3533-core.c +3
-6- lm3533->hwen =devm_gpiod_get (lm3533->dev,NULL ,GPIOD_OUT_LOW ); -if (IS_ERR (lm3533->hwen)) -return dev_err_probe (lm3533->dev,PTR_ERR (lm3533->hwen),"failed to request HWEN GPIO\n" ); -gpiod_set_consumer_name (lm3533->hwen,"lm3533-hwen" ); - -lm3533_enable (lm3533); + lm3533_devices[count].name ="lm3533-backlight" ; + lm3533_devices[count].id = reg; + lm3533_devices[count].of_compatible ="ti,lm3533-backlight" ;
[Severity: Medium]
Will this assignment cause mfd_add_devices() to map the wrong OF node to subdevices if an earlier node was skipped? Since cell->use_of_reg = true and cell->of_reg = reg are not being set here, mfd_match_of_node_to_dev() will simply assign the first available matching OF node to the first requested mfd_cell. If an earlier invalid node was skipped, the subdevice may read configurations from the wrong DT node.
Quoted 7 lines
drivers/mfd/lm3533-core.c +3
-3- ret =regmap_update_bits (lm3533->regmap,LM3533_REG_BOOST_PWM , -LM3533_BOOST_FREQ_MASK , - pdata->boost_freq <<LM3533_BOOST_FREQ_SHIFT ); + lm3533->have_backlights = true; + count++; + }
[ ... ]
Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0
-0
[ ... ]
Quoted 9 lines
drivers/video/backlight/lm3533_bl.c +5
-0@@ -296,13 +294,20 @@ static int lm3533_bl_probe(struct platform_device *pdev) bl->cb.id =lm3533_bl_get_ctrlbank_id (bl); bl->cb.dev =NULL ;/* until registered */ + name =devm_kasprintf (&pdev->dev,GFP_KERNEL ,"%s-%d" , + pdev->name, pdev->id); +if (!name) +return -ENOMEM ; +
drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 307
Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +3
-4memset (&props,0 ,sizeof (props)); props.type =BACKLIGHT_RAW ; props.max_brightness =LM3533_BL_MAX_BRIGHTNESS ; - props.brightness = pdata->default_brightness; - bd =devm_backlight_device_register (&pdev->dev, pdata->name, - pdev->dev.parent, bl, &lm3533_bl_ops, - &props); + props.brightness =LM3533_BL_MAX_BRIGHTNESS ; +device_property_read_u32 (&pdev->dev,"default-brightness" , + &props.brightness);
[Severity: Low]
Does passing &props.brightness violate strict C typing here? The brightness field in struct backlight_properties is an int, but device_property_read_u32() strictly expects a u32 pointer. This could cause build failures on modern kernel trees that have -Werror=incompatible-pointer-types enabled.
Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +3
-0+ + bd =devm_backlight_device_register (&pdev->dev, name, &pdev->dev, + bl, &lm3533_bl_ops, &props);if (IS_ERR (bd)) {dev_err (&pdev->dev,"failed to register backlight device\n" );return PTR_ERR (bd);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
In reply to Svyatoslav RyhelQuoted 2 lines · Svyatoslav Ryhel
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
...
drivers/iio/light/lm3533-als.c struct lm3533_als { · line 66
Quoted 8 lines
drivers/iio/light/lm3533-als.c +3
-0@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };
Have you run pahole? Does it agree with the layout you made here?
...
drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev)
Quoted 4 lines
drivers/iio/light/lm3533-als.c +2
-1- als->irq = lm3533->irq; + als->irq =platform_get_irq_optional (pdev,0 ); +
Redundant blank line.
drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 844
Quoted 2 lines
drivers/iio/light/lm3533-als.c +2
-0+if (als->irq == -EPROBE_DEFER ) +return -EPROBE_DEFER ;
What about other error codes when IRQ is found by can't be retrieved for some reasons? IIRC we check against ENXIO in similar cases
als->irq = platform_get_irq_optional(pdev, 0); if (als->irq == -ENXIO) als->irq = 0; if (als->irq < 0) return als->irq;
...
drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 716
Quoted 1 line
drivers/leds/leds-lm3533.c +1
-0+ led->pwm =0 ;
Isn't it 0 by zalloc ?
Quoted 1 line
drivers/leds/leds-lm3533.c +1
-0+device_property_read_u32 (&pdev->dev,"ti,pwm-config-mask" , &led->pwm);
...
drivers/mfd/lm3533-core.c line 36
Quoted 4 lines
#define
LM3533_BOOST_FREQ_MASK0x01
#defineLM3533_BOOST_FREQ_SHIFT0drivers/mfd/lm3533-core.c +2
-0+#define LM3533_BOOST_FREQ_MIN 500000 +#define LM3533_BOOST_FREQ_MAX 1000000
HZ_PER_KHZ (since you included units.h)?
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 279
Quoted 4 lines
drivers/mfd/lm3533-core.c +4
-0+ nchilds =device_get_child_node_count (dev); +if (!nchilds || nchilds >LM3533_CELLS_MAX ) { +dev_err (dev,"num of child nodes is not supported\n" ); +return -ENODEV ;
Why not dev_err_probe() here and elsewhere? It looks inconsistent with this patch.
Quoted 1 line
}
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 308
Quoted 4 lines
drivers/mfd/lm3533-core.c +3
-0+device_for_each_child_node_scoped (lm3533->dev, child) { +if (!fwnode_device_is_available (child)) +continue ;
Do we need this check?
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 324
Quoted 2 lines
drivers/mfd/lm3533-core.c +2
-0+dev_err (dev,"invalid LED node %s\n" , +fwnode_get_name (child));
%pfw
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 361
Quoted 1 line
drivers/mfd/lm3533-core.c +1
-0+ ret =sysfs_create_group (&dev->kobj, &lm3533_attribute_group);
No way. You should use .dev_groups.
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 365
Quoted 4 lines
drivers/mfd/lm3533-core.c +2
-0+if (ret) { +dev_err (dev,"failed to create sysfs attributes\n" ); goto err_unregister; }
...
Can you think on how to split this change to smaller steps? I believe it's possible.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
вт, 2 черв. 2026 р. о 11:24 Andy Shevchenko <[email protected]> пише:
Quoted 9 lines · Svyatoslav Ryhel
Quoted 2 lines
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
...
Quoted 2 lines
(quoted diff) +0
-0@@ -57,6 +60,9 @@ struct lm3533_als {
Quoted 9 lines
drivers/iio/light/lm3533-als.c struct lm3533_als { · line 66
Quoted 6 lines
drivers/iio/light/lm3533-als.c +3
-0atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };Have you run
pahole? Does it agree with the layout you made here?
Noted.
Quoted 9 lines
...
drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev)
Quoted 4 lines
drivers/iio/light/lm3533-als.c +2
-1- als->irq = lm3533->irq; + als->irq =platform_get_irq_optional (pdev,0 ); +Redundant blank line.
Simplifies code perception, whatever.
Quoted 6 lines
drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 844
Quoted 2 lines
drivers/iio/light/lm3533-als.c +2
-0+if (als->irq == -EPROBE_DEFER ) +return -EPROBE_DEFER ;What about other error codes when IRQ is found by can't be retrieved for some reasons? IIRC we check against ENXIO in similar cases
Then we treat it as no IRQ. Original implementation cares only if IRQ is present or no.
Quoted 11 lines
als->irq = platform_get_irq_optional(pdev, 0); if (als->irq == -ENXIO) als->irq = 0; if (als->irq < 0) return als->irq;...
Quoted 1 line
+
led->pwm= 0;Isn't it 0 by zalloc ?
It is, thanks.
Quoted 12 lines
Quoted 2 lines
+
device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);...
drivers/mfd/lm3533-core.c line 36
Quoted 4 lines
#define
LM3533_BOOST_FREQ_MASK0x01
#defineLM3533_BOOST_FREQ_SHIFT0drivers/mfd/lm3533-core.c +2
-0+#define LM3533_BOOST_FREQ_MIN 500000 +#define LM3533_BOOST_FREQ_MAX 1000000
HZ_PER_KHZ(since you includedunits.h)?
500 * HZ_PER_KHZ
1000 * HZ_PER_KHZ
You meant this? Sure.
Quoted 10 lines
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 279
Quoted 4 lines
drivers/mfd/lm3533-core.c +4
-0+ nchilds =device_get_child_node_count (dev); +if (!nchilds || nchilds >LM3533_CELLS_MAX ) { +dev_err (dev,"num of child nodes is not supported\n" ); +return -ENODEV ;Why not
dev_err_probe()here and elsewhere? It looks inconsistent with this patch.
I must have overlooked it, thanks. WDYM elsewhere, this is the only occurance.
Quoted 11 lines
Quoted 1 line
}...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 308
Quoted 4 lines
drivers/mfd/lm3533-core.c +3
-0+device_for_each_child_node_scoped (lm3533->dev, child) { +if (!fwnode_device_is_available (child)) +continue ;Do we need this check?
This is nice to have if the node is disabled. If we assume that there are no disabled nodes, I can remove it.
Quoted 7 lines
...
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 324
Quoted 2 lines
drivers/mfd/lm3533-core.c +2
-0+dev_err (dev,"invalid LED node %s\n" , +fwnode_get_name (child));%pfw
Noted.
Quoted 6 lines
...
Quoted 1 line
+ ret =
sysfs_create_group(&dev->kobj, &lm3533_attribute_group);No way. You should use .dev_groups.
I did not change how driver does this, just swapped lm3533->dev to dev. I will set is back as it was.
Quoted 10 lines
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 365
Quoted 4 lines
drivers/mfd/lm3533-core.c +2
-0+if (ret) { +dev_err (dev,"failed to create sysfs attributes\n" ); goto err_unregister; }...
Can you think on how to split this change to smaller steps? I believe it's possible.
No, I am done with tinkering with this patchset. It is broken enough and it has inflated enough.
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
Quoted 2 lines · Svyatoslav Ryhel
вт, 2 черв. 2026 р. о 11:24 Andy Shevchenko <[email protected]> пише:
Quoted 1 line · Svyatoslav Ryhel
...
Quoted 9 lines
Quoted 6 lines
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 308
Quoted 4 lines
drivers/mfd/lm3533-core.c +3
-0+device_for_each_child_node_scoped (lm3533->dev, child) { +if (!fwnode_device_is_available (child)) +continue ;Do we need this check?
This is nice to have if the node is disabled. If we assume that there are no disabled nodes, I can remove it.
It's already implied. See
static struct fwnode_handle *of_fwnode_get_next_child_node(const struct fwnode_handle *fwnode, struct fwnode_handle *child)
{
return of_fwnode_handle(of_get_next_available_child(to_of_node(fwnode), to_of_node(child)));
}And I believe it's written somewhere in the documentation (if not, feel free to patch that).
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+ ret =
sysfs_create_group(&dev->kobj, &lm3533_attribute_group);No way. You should use .dev_groups.
I did not change how driver does this, just swapped
lm3533->devto dev. I will set is back as it was.
This is a serious race condition that needs to be addressed. Since you are touching this driver the fixes against known issues probably are the first things that have to be done.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/lm3533-core.c +2
-0+if (ret) { +dev_err (dev,"failed to create sysfs attributes\n" ); goto err_unregister; }
...
Quoted 5 lines
Quoted 2 lines
Can you think on how to split this change to smaller steps? I believe it's possible.
No, I am done with tinkering with this patchset. It is broken enough and it has inflated enough.
Probably you don't want this to be reviewed then? I believe other kernel developers and maintainers will ask you the same.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
вт, 2 черв. 2026 р. о 14:05 Andy Shevchenko <[email protected]> пише:
Quoted 20 lines · Svyatoslav Ryhel
Quoted 2 lines
вт, 2 черв. 2026 р. о 11:24 Andy Shevchenko <[email protected]> пише:
Quoted 1 line · Svyatoslav Ryhel
...
Quoted 9 lines
Quoted 6 lines
drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 308
Quoted 4 lines
drivers/mfd/lm3533-core.c +3
-0+device_for_each_child_node_scoped (lm3533->dev, child) { +if (!fwnode_device_is_available (child)) +continue ;Do we need this check?
This is nice to have if the node is disabled. If we assume that there are no disabled nodes, I can remove it.
It's already implied. See
Quoted 9 lines
static struct
fwnode_handle*of_fwnode_get_next_child_node(const struct fwnode_handle *fwnode, struct fwnode_handle *child){ return of_fwnode_handle(of_get_next_available_child(to_of_node(fwnode), to_of_node(child))); }And I believe it's written somewhere in the documentation (if not, feel free to patch that).
Very nice. Thank you.
Quoted 4 lines
...
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+ ret =
sysfs_create_group(&dev->kobj, &lm3533_attribute_group);
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
No way. You should use .dev_groups.
I did not change how driver does this, just swapped
lm3533->devto dev. I will set is back as it was.This is a serious race condition that needs to be addressed. Since you are touching this driver the fixes against known issues probably are the first things that have to be done.
Fine, I will have a look.
Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mfd/lm3533-core.c +2
-0+if (ret) { +dev_err (dev,"failed to create sysfs attributes\n" ); goto err_unregister; }...
Quoted 5 lines
Quoted 2 lines
Can you think on how to split this change to smaller steps? I believe it's possible.
No, I am done with tinkering with this patchset. It is broken enough and it has inflated enough.
Probably you don't want this to be reviewed then? I believe other kernel developers and maintainers will ask you the same.
--
With Best Regards,
Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
In reply to Svyatoslav RyhelQuoted 79 lines · On Mon, 1 Jun 2026 18:18:25 +0300 Svyatoslav Ryhel <[email protected]> wrote:
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
Signed-off-by Svyatoslav Ryhel <[email protected]>index
52136ca1abc9..55b35467a722100644drivers/iio/light/lm3533-als.c +14
-13@@ -16,16 +16,19 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/mfd/core.h> +#include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/units.h> #include <linux/mfd/lm3533.h> -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 +#define LM3533_ALS_RESISTOR_MIN 1575 +#define LM3533_ALS_RESISTOR_MAX 200000#define LM3533_ALS_CHANNEL_CURRENT_MAX 2#define LM3533_ALS_THRESH_MAX 3#define LM3533_ALS_ZONE_MAX 4@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };@@ -411,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,int enable;int ret; -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_get_int_mode (indio_dev, &enable);if (ret)return ret;@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {struct device *dev = &als->pdev->dev;int ret; + als->pwm_mode =device_property_read_bool (dev,"ti,pwm-mode" ); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF ,LM3533_ALS_INPUT_MODE_MASK , - pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 ); + als->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret)return dev_err_probe (dev, ret,"failed to set input mode %d\n" , - pdata->pwm_mode); - + als->pwm_mode);/* ALS input is always high impedance in PWM-mode. */ -if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ;
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 748
Quoted 10 lines
drivers/iio/light/lm3533-als.c +9
-1- } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select); +if (ret) +return dev_err_probe (dev, ret, +"failed to ger resistor value\n" ); + + als->r_select =clamp (als->r_select,LM3533_ALS_RESISTOR_MIN , +LM3533_ALS_RESISTOR_MAX );
If we are getting garbage from DT I think I'd rather error out that paper over that problem. So similar to before, check valid value and if not fail probe so that hopefully someone goes and fixes it!
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 749
Quoted 1 line
drivers/iio/light/lm3533-als.c +1
-0+ als->r_select =DIV_ROUND_UP (2 *MICRO ,10 * als->r_select);
Why do we need this when we didn't before? The range checks are the same so it smells like it shouldn't need transforming. I'd also rather we didn't do rewriting of the meaning of r_select like this. Just use a local variable for the intermediate result.
Quoted 6 lines
drivers/iio/light/lm3533-als.c +1
-1ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - pdata->r_select); + als->r_select);if (ret)return dev_err_probe (dev, ret,"failed to set resistor\n" );
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
вт, 2 черв. 2026 р. о 16:46 Jonathan Cameron <[email protected]> пише:
Quoted 89 lines
Quoted 85 lines · On Mon, 1 Jun 2026 18:18:25 +0300 Svyatoslav Ryhel <[email protected]> wrote:
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
Signed-off-by Svyatoslav Ryhel <[email protected]>index
52136ca1abc9..55b35467a722100644drivers/iio/light/lm3533-als.c +19
-14@@ -16,16 +16,19 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/mfd/core.h> +#include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/units.h> #include <linux/mfd/lm3533.h> -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 +#define LM3533_ALS_RESISTOR_MIN 1575 +#define LM3533_ALS_RESISTOR_MAX 200000#define LM3533_ALS_CHANNEL_CURRENT_MAX 2#define LM3533_ALS_THRESH_MAX 3#define LM3533_ALS_ZONE_MAX 4@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };@@ -411,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,int enable;int ret; -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_get_int_mode (indio_dev, &enable);if (ret)return ret;@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {struct device *dev = &als->pdev->dev;int ret; + als->pwm_mode =device_property_read_bool (dev,"ti,pwm-mode" ); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF ,LM3533_ALS_INPUT_MODE_MASK , - pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 ); + als->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret)return dev_err_probe (dev, ret,"failed to set input mode %d\n" , - pdata->pwm_mode); - + als->pwm_mode);/* ALS input is always high impedance in PWM-mode. */ -if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select); +if (ret) + return dev_err_probe(dev, ret,
Quoted 9 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 748
Quoted 4 lines
drivers/iio/light/lm3533-als.c +4
-0+ "failed to ger resistor value\n"); + + als->r_select =clamp (als->r_select,LM3533_ALS_RESISTOR_MIN , +LM3533_ALS_RESISTOR_MAX );If we are getting garbage from DT I think I'd rather error out that paper over that problem. So similar to before, check valid value and if not fail probe so that hopefully someone goes and fixes it!
sure
Quoted 6 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 749
Quoted 1 line
drivers/iio/light/lm3533-als.c +1
-0+ als->r_select =DIV_ROUND_UP (2 *MICRO ,10 * als->r_select);Why do we need this when we didn't before? The range checks are the same so it smells like it shouldn't need transforming. I'd also rather we didn't do rewriting of the meaning of
r_selectlike this. Just use a local variable for the intermediate result.
before pdata passed resistor value as actual register value, not we are getting the actual resistance in ohms from the tree and must convert it into register value.
Quoted 6 lines
Quoted 6 lines
drivers/iio/light/lm3533-als.c +1
-1ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - pdata->r_select); + als->r_select);if (ret)return dev_err_probe (dev, ret,"failed to set resistor\n" );
Jonathan Cameron
maintainerRe: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
Quoted 109 lines · On Tue, 2 Jun 2026 16:50:16 +0300 Svyatoslav Ryhel <[email protected]> wrote:
вт, 2 черв. 2026 р. о 16:46 Jonathan Cameron <[email protected]> пише:
Quoted 89 lines
Quoted 85 lines · On Mon, 1 Jun 2026 18:18:25 +0300 Svyatoslav Ryhel <[email protected]> wrote:
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
Signed-off-by Svyatoslav Ryhel <[email protected]>index
52136ca1abc9..55b35467a722100644drivers/iio/light/lm3533-als.c +19
-14@@ -16,16 +16,19 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/mfd/core.h> +#include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/units.h> #include <linux/mfd/lm3533.h> -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 +#define LM3533_ALS_RESISTOR_MIN 1575 +#define LM3533_ALS_RESISTOR_MAX 200000#define LM3533_ALS_CHANNEL_CURRENT_MAX 2#define LM3533_ALS_THRESH_MAX 3#define LM3533_ALS_ZONE_MAX 4@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };@@ -411,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,int enable;int ret; -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_get_int_mode (indio_dev, &enable);if (ret)return ret;@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {struct device *dev = &als->pdev->dev;int ret; + als->pwm_mode =device_property_read_bool (dev,"ti,pwm-mode" ); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF ,LM3533_ALS_INPUT_MODE_MASK , - pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 ); + als->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret)return dev_err_probe (dev, ret,"failed to set input mode %d\n" , - pdata->pwm_mode); - + als->pwm_mode);/* ALS input is always high impedance in PWM-mode. */ -if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select); +if (ret) + return dev_err_probe(dev, ret,Quoted 9 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 748
Quoted 4 lines
drivers/iio/light/lm3533-als.c +4
-0+ "failed to ger resistor value\n"); + + als->r_select =clamp (als->r_select,LM3533_ALS_RESISTOR_MIN , +LM3533_ALS_RESISTOR_MAX );If we are getting garbage from DT I think I'd rather error out that paper over that problem. So similar to before, check valid value and if not fail probe so that hopefully someone goes and fixes it!
sure
Quoted 6 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 749
Quoted 1 line
drivers/iio/light/lm3533-als.c +1
-0+ als->r_select =DIV_ROUND_UP (2 *MICRO ,10 * als->r_select);Why do we need this when we didn't before? The range checks are the same so it smells like it shouldn't need transforming. I'd also rather we didn't do rewriting of the meaning of
r_selectlike this. Just use a local variable for the intermediate result.
Quoted 3 lines
before pdata passed resistor value as actual register value, not we are getting the actual resistance in ohms from the tree and must convert it into register value.
ah. I missed the change of values. Can you make them explicitly now _OHMS or something along those lines rather than reusing the macro name for a different thing.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/iio/light/lm3533-als.c +1
-1ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - pdata->r_select); + als->r_select);if (ret)return dev_err_probe (dev, ret,"failed to set resistor\n" );
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
вт, 2 черв. 2026 р. о 17:20 Jonathan Cameron <[email protected]> пише:
Quoted 113 lines
Quoted 109 lines · On Tue, 2 Jun 2026 16:50:16 +0300 Svyatoslav Ryhel <[email protected]> wrote:
вт, 2 черв. 2026 р. о 16:46 Jonathan Cameron <[email protected]> пише:
Quoted 89 lines
Quoted 85 lines · On Mon, 1 Jun 2026 18:18:25 +0300 Svyatoslav Ryhel <[email protected]> wrote:
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
Signed-off-by Svyatoslav Ryhel <[email protected]>index
52136ca1abc9..55b35467a722100644drivers/iio/light/lm3533-als.c +19
-14@@ -16,16 +16,19 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/mfd/core.h> +#include <linux/mod_devicetable.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/units.h> #include <linux/mfd/lm3533.h> -#define LM3533_ALS_RESISTOR_MIN 1 -#define LM3533_ALS_RESISTOR_MAX 127 +#define LM3533_ALS_RESISTOR_MIN 1575 +#define LM3533_ALS_RESISTOR_MAX 200000#define LM3533_ALS_CHANNEL_CURRENT_MAX 2#define LM3533_ALS_THRESH_MAX 3#define LM3533_ALS_ZONE_MAX 4@@ -57,6 +60,9 @@ struct lm3533_als {atomic_t zone;struct mutex thresh_mutex; + +bool pwm_mode; +u32 r_select; };@@ -411,7 +417,7 @@ static ssize_t show_thresh_either_en(struct device *dev,int enable;int ret; -if (als->irq) { +if (als->irq >0 ) { ret =lm3533_als_get_int_mode (indio_dev, &enable);if (ret)return ret;@@ -716,30 +722,34 @@ static const struct attribute_group lm3533_als_attribute_group = { .attrs = lm3533_als_attributes }; -static int lm3533_als_setup (struct lm3533_als *als, -const struct lm3533_als_platform_data *pdata) +static int lm3533_als_setup (struct lm3533_als *als) {struct device *dev = &als->pdev->dev;int ret; + als->pwm_mode =device_property_read_bool (dev,"ti,pwm-mode" ); + ret =regmap_update_bits (als->lm3533->regmap,LM3533_REG_ALS_CONF ,LM3533_ALS_INPUT_MODE_MASK , - pdata->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 ); + als->pwm_mode ?LM3533_ALS_INPUT_MODE_MASK :0 );if (ret)return dev_err_probe (dev, ret,"failed to set input mode %d\n" , - pdata->pwm_mode); - + als->pwm_mode);/* ALS input is always high impedance in PWM-mode. */ -if (!pdata->pwm_mode) { -if (pdata->r_select <LM3533_ALS_RESISTOR_MIN || - pdata->r_select >LM3533_ALS_RESISTOR_MAX ) { -dev_err (&als->pdev->dev,"invalid resistor value\n" ); -return -EINVAL ; - } +if (!als->pwm_mode) { + ret =device_property_read_u32 (dev,"ti,resistor-value-ohms" , + &als->r_select); +if (ret) + return dev_err_probe(dev, ret,Quoted 9 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 748
Quoted 4 lines
drivers/iio/light/lm3533-als.c +4
-0+ "failed to ger resistor value\n"); + + als->r_select =clamp (als->r_select,LM3533_ALS_RESISTOR_MIN , +LM3533_ALS_RESISTOR_MAX );If we are getting garbage from DT I think I'd rather error out that paper over that problem. So similar to before, check valid value and if not fail probe so that hopefully someone goes and fixes it!
sure
Quoted 6 lines
drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 749
Quoted 1 line
drivers/iio/light/lm3533-als.c +1
-0+ als->r_select =DIV_ROUND_UP (2 *MICRO ,10 * als->r_select);Why do we need this when we didn't before? The range checks are the same so it smells like it shouldn't need transforming. I'd also rather we didn't do rewriting of the meaning of
r_selectlike this. Just use a local variable for the intermediate result.
Quoted 7 lines
Quoted 3 lines
before pdata passed resistor value as actual register value, not we are getting the actual resistance in ohms from the tree and must convert it into register value.
ah. I missed the change of values. Can you make them explicitly now
_OHMSor something along those lines rather than reusing the macro name for a different thing.
Acknowledged.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/iio/light/lm3533-als.c +1
-1ret =regmap_write (als->lm3533->regmap,LM3533_REG_ALS_RESISTOR_SELECT , - pdata->r_select); + als->r_select);if (ret)return dev_err_probe (dev, ret,"failed to set resistor\n" );
Re: [PATCH v3 05/11] mfd: lm3533: Convert to use OF bindings
In reply to Svyatoslav RyhelQuoted 4 lines · Svyatoslav Ryhel
Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.
Signed-off-by Svyatoslav Ryhel <[email protected]>
Daniel.
PATCH v3 6/11 mfd: lm3533: Add support for VIN power supply
In reply to Svyatoslav RyhelAdd support for 2.7V-5.5V VIN power supply.
--- drivers/mfd/lm3533-core.c | 23 +++++++++++++++++++++-- include/linux/mfd/lm3533.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/mfd/lm3533-core.c +21 -2
@@ -17,6 +17,7 @@#include <linux/mod_devicetable.h> #include <linux/property.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -113,14 +114,25 @@ static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led)return ret; } -static void lm3533_enable (struct lm3533 *lm3533) +static int lm3533_enable (struct lm3533 *lm3533) { +int ret; + + ret =regulator_enable (lm3533->vin_supply); +if (ret) { +dev_err (lm3533->dev,"failed to enable vin power supply\n" ); +return ret; + } +gpiod_set_value (lm3533->hwen,1 ); + +return 0 ; }static void lm3533_disable (struct lm3533 *lm3533) {gpiod_set_value (lm3533->hwen,0 ); +regulator_disable (lm3533->vin_supply); }enum lm3533_attribute_type {
@@ -334,7 +346,9 @@ static int lm3533_device_init(struct lm3533 *lm3533) } } -lm3533_enable (lm3533); + ret =lm3533_enable (lm3533); +if (ret) +return ret; ret = regmap_update_bits(lm3533->regmap, LM3533_REG_BOOST_PWM, LM3533_BOOST_FREQ_MASK,
@@ -458,6 +472,11 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)return dev_err_probe (lm3533->dev,PTR_ERR (lm3533->hwen),"failed to get HWEN GPIO\n" ); + lm3533->vin_supply =devm_regulator_get (lm3533->dev,"vin" ); +if (IS_ERR (lm3533->vin_supply)) +return dev_err_probe (lm3533->dev,PTR_ERR (lm3533->vin_supply), +"failed to get vin-supply\n" ); +device_property_read_u32 (lm3533->dev,"ti,boost-ovp-microvolt" , &lm3533->boost_ovp);
include/linux/mfd/lm3533.h +2 -0
@@ -22,6 +22,7 @@struct device ;struct gpio_desc ;struct regmap ; +struct regulator ;struct lm3533 {struct device *dev;
@@ -29,6 +30,7 @@ struct lm3533 {struct regmap *regmap;struct gpio_desc *hwen; +struct regulator *vin_supply;u32 boost_ovp;u32 boost_freq;
Signature · 1 line
2.51.0
PATCH v3 7/11 mfd: lm3533: Set DMA mask
In reply to Svyatoslav RyhelMissing coherent_dma_mask assigning triggers the following warning in dmesg:
[ 3.287872] platform lm3533-backlight.0: DMA mask not set
Since this warning might be elevated to an error in the future, set coherent_dma_mask to zero because both the core and cells do not utilize DMA.
--- drivers/mfd/lm3533-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mfd/lm3533-core.c +4 -0
@@ -491,6 +491,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c) LM3533_BOOST_FREQ_MAX); lm3533->boost_freq = lm3533->boost_freq / (500 *KILO ) -1 ; +/* LM3533 and child devices do not use DMA */ + i2c->dev.coherent_dma_mask =0 ; + i2c->dev.dma_mask = &i2c->dev.coherent_dma_mask; +return lm3533_device_init (lm3533); }
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v3 07/11] mfd: lm3533: Set DMA mask
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Out-of-bounds write in lm3533_device_init when processing child nodes with multiple compatible strings. --
commit d3029bf43673fb0132c36c4614c542e46d64f393
Author: Svyatoslav Ryhel <[email protected]>
mfd: lm3533: Set DMA mask
This commit sets the coherent_dma_mask and dma_mask to 0 during the i2c probe. This resolves a warning about missing DMA mask assignments, as neither the core nor child devices use DMA.
Quoted 4 lines
drivers/mfd/lm3533-core.c +0
-0
[ ... ]
drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 498
Quoted 9 lines
drivers/mfd/lm3533-core.c +4
-0@@ -491,6 +491,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c) LM3533_BOOST_FREQ_MAX); lm3533->boost_freq = lm3533->boost_freq / (500 *KILO ) -1 ; +/* LM3533 and child devices do not use DMA */ + i2c->dev.coherent_dma_mask =0 ; + i2c->dev.dma_mask = &i2c->dev.coherent_dma_mask; +return lm3533_device_init (lm3533);
[Severity: High]
This is a pre-existing issue, but can the child node iteration in lm3533_device_init() overflow the lm3533_devices array?
The lm3533_devices array is allocated based on nchilds. Inside the iteration loop, independent if statements check the compatible strings:
drivers/mfd/lm3533-core.c:lm3533_device_init() {
...
if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
lm3533_devices[count].name = "lm3533-als";
...
count++;
}
if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
...
lm3533_devices[count].name = "lm3533-backlight";
...
count++;
}
...
}Since the bounds check if (count >= nchilds) is only performed once at the beginning of the loop, a single child node containing multiple matching compatible strings (e.g., "ti,lm3533-als" and "ti,lm3533-backlight") would increment count multiple times per iteration.
Could this bypass the bounds check and cause an out-of-bounds write?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v3 8/11 video: backlight: lm3533_bl: Improve linear sysfs logic
In reply to Svyatoslav RyhelSimplify the sysfs logic of the linear property by switching to a macro and a ternary operator.
--- drivers/video/backlight/lm3533_bl.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
drivers/video/backlight/lm3533_bl.c +6 -13
@@ -23,6 +23,7 @@#define LM3533_BL_MAX_BRIGHTNESS 255#define LM3533_REG_CTRLBANK_AB_BCONF 0x1a +#define CTRLBANK_AB_BCONF_MODE (n) BIT(2 * (n) + 1)struct lm3533_bl {
@@ -136,8 +137,9 @@ static ssize_t show_linear(struct device *dev, struct device_attribute *attr, char *buf) { struct lm3533_bl *bl = dev_get_drvdata(dev); +int id =lm3533_bl_get_ctrlbank_id (bl); +u8 mask =CTRLBANK_AB_BCONF_MODE (id);u32 val; -u8 mask;int linear;int ret;
@@ -145,8 +147,6 @@ static ssize_t show_linear(struct device *dev,if (ret)return ret; - mask =1 << (2 *lm3533_bl_get_ctrlbank_id (bl) +1 ); -if (val & mask) linear =1 ;else
@@ -160,23 +160,16 @@ static ssize_t store_linear(struct device *dev, const char *buf, size_t len) {struct lm3533_bl *bl =dev_get_drvdata (dev); +int id =lm3533_bl_get_ctrlbank_id (bl);unsigned long linear; -u8 mask; -u8 val;int ret;if (kstrtoul (buf,0 , &linear))return -EINVAL ; - mask =1 << (2 *lm3533_bl_get_ctrlbank_id (bl) +1 ); - -if (linear) - val = mask; -else - val =0 ; - ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , - mask, val); +CTRLBANK_AB_BCONF_MODE (id), + linear ?CTRLBANK_AB_BCONF_MODE (id) :0 );if (ret)return ret;
Signature · 1 line
2.51.0
Re: [PATCH v3 08/11] video: backlight: lm3533_bl: Improve linear sysfs logic
Quoted 2 lines · Svyatoslav Ryhel
Simplify the sysfs logic of the linear property by switching to a macro and a ternary operator.
...
drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, · line 168
Quoted 2 lines
drivers/video/backlight/lm3533_bl.c +0
-0if (kstrtoul (buf,0 , &linear))return -EINVAL ;
Besides _assign_bits() in the below, side note here to unshadow error codes:
ret = kstrtoul(buf, 0, &linear); if (ret) return ret;
(obviously in a separate change).
...
Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +2
-1ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , - mask, val); +CTRLBANK_AB_BCONF_MODE (id), + linear ?CTRLBANK_AB_BCONF_MODE (id) :0 );if (ret)return ret;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 08/11] video: backlight: lm3533_bl: Improve linear sysfs logic
вт, 2 черв. 2026 р. о 11:09 Andy Shevchenko <[email protected]> пише:
Quoted 10 lines · Svyatoslav Ryhel
Quoted 2 lines
Simplify the sysfs logic of the linear property by switching to a macro and a ternary operator.
...
Quoted 2 lines
if (kstrtoul(buf, 0, &linear)) return -EINVAL;
Quoted 7 lines
Besides
_assign_bits()in the below, side note here to unshadow error codes:ret = kstrtoul(buf, 0, &linear); if (ret) return ret;(obviously in a separate change).
Won't happen in this patches.
Quoted 15 lines
...
drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, · line 174
Quoted 6 lines
ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,drivers/video/backlight/lm3533_bl.c +2
-1- mask, val); +CTRLBANK_AB_BCONF_MODE (id), + linear ? CTRLBANK_AB_BCONF_MODE(id) : 0);if (ret)return ret;--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 08/11] video: backlight: lm3533_bl: Improve linear sysfs logic
Quoted 2 lines · Svyatoslav Ryhel
вт, 2 черв. 2026 р. о 11:09 Andy Shevchenko <[email protected]> пише:
Quoted 1 line · Svyatoslav Ryhel
...
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
if (kstrtoul(buf, 0, &linear)) return -EINVAL;Besides
_assign_bits()in the below, side note here to unshadow error codes:
Quoted 7 lines
Quoted 5 lines
ret = kstrtoul(buf, 0, &linear); if (ret) return ret;(obviously in a separate change).
Won't happen in this patches.
You mean both suggestions or you are talking about kstrotoul() only? If it's only about the latter, it's fine with me, but _assign_bits() makes sense to do in this patch as you already change the parameters enough to make it better.
...
Quoted 6 lines
Quoted 6 lines
drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, · line 174
Quoted 6 lines
ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,drivers/video/backlight/lm3533_bl.c +2
-1- mask, val); +CTRLBANK_AB_BCONF_MODE (id), + linear ? CTRLBANK_AB_BCONF_MODE(id) : 0);if (ret)return ret;
^^^ left for the context.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 08/11] video: backlight: lm3533_bl: Improve linear sysfs logic
вт, 2 черв. 2026 р. о 14:07 Andy Shevchenko <[email protected]> пише:
Quoted 16 lines · Svyatoslav Ryhel
Quoted 2 lines
вт, 2 черв. 2026 р. о 11:09 Andy Shevchenko <[email protected]> пише:
Quoted 1 line · Svyatoslav Ryhel
...
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
if (kstrtoul(buf, 0, &linear)) return -EINVAL;Besides
_assign_bits()in the below, side note here to unshadow error codes:ret = kstrtoul(buf, 0, &linear); if (ret) return ret;
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
(obviously in a separate change).
Won't happen in this patches.
You mean both suggestions or you are talking about
kstrotoul()only? If it's only about the latter, it's fine with me, but_assign_bits()makes sense to do in this patch as you already change the parameters enough to make it better.
only kstrotoul()
Quoted 16 lines
...
Quoted 6 lines
Quoted 6 lines
drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, · line 174
Quoted 6 lines
ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,drivers/video/backlight/lm3533_bl.c +2
-1- mask, val); +CTRLBANK_AB_BCONF_MODE (id), + linear ? CTRLBANK_AB_BCONF_MODE(id) : 0);if (ret)return ret;^^^ left for the context.
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 08/11] video: backlight: lm3533_bl: Improve linear sysfs logic
In reply to Svyatoslav RyhelQuoted 4 lines · Svyatoslav Ryhel
Simplify the sysfs logic of the linear property by switching to a macro and a ternary operator.
Signed-off-by Svyatoslav Ryhel <[email protected]>
With the change to regmap_assign_bits():
Daniel.
PATCH v3 9/11 video: backlight: lm3533_bl: Set initial mapping mode from DT
In reply to Svyatoslav RyhelAdd support to obtain the initial mapping mode from DT instead of leaving it unconfigured.
--- drivers/video/backlight/lm3533_bl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/video/backlight/lm3533_bl.c +11 -0
@@ -34,6 +34,7 @@ struct lm3533_bl {u32 max_current;u32 pwm; +bool linear; };
@@ -247,8 +248,15 @@ static struct attribute_group lm3533_bl_attribute_group = {static int lm3533_bl_setup (struct lm3533_bl *bl) { +int id =lm3533_bl_get_ctrlbank_id (bl);int ret; + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , +CTRLBANK_AB_BCONF_MODE (id), + bl->linear ?CTRLBANK_AB_BCONF_MODE (id) :0 ); +if (ret) +return ret; + ret =lm3533_ctrlbank_set_max_current (&bl->cb, bl->max_current);if (ret)return ret;
@@ -299,6 +307,9 @@ static int lm3533_bl_probe(struct platform_device *pdev)device_property_read_u32 (&pdev->dev,"default-brightness" , &props.brightness); + bl->linear =device_property_read_bool (&pdev->dev, +"ti,linear-mapping-mode" ); + bd =devm_backlight_device_register (&pdev->dev, name, &pdev->dev, bl, &lm3533_bl_ops, &props);if (IS_ERR (bd)) {
Signature · 1 line
2.51.0
Re: [PATCH v3 09/11] video: backlight: lm3533_bl: Set initial mapping mode from DT
Quoted 21 lines · Svyatoslav Ryhel
Add support to obtain the initial mapping mode from DT instead of leaving it unconfigured.
Signed-off-by Svyatoslav Ryhel <[email protected]>--- drivers/video/backlight/lm3533_bl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/video/backlight/lm3533_bl.c +1
-0@@ -34,6 +34,7 @@ struct lm3533_bl {u32 max_current;u32 pwm; +bool linear; };
drivers/video/backlight/lm3533_bl.c static struct attribute_group lm3533_bl_attribute_group = { · line 256
Quoted 9 lines
drivers/video/backlight/lm3533_bl.c +4
-0@@ -247,8 +248,15 @@ static struct attribute_group lm3533_bl_attribute_group = {static int lm3533_bl_setup (struct lm3533_bl *bl) { +int id =lm3533_bl_get_ctrlbank_id (bl);int ret; + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_CTRLBANK_AB_BCONF , +CTRLBANK_AB_BCONF_MODE (id), + bl->linear ?CTRLBANK_AB_BCONF_MODE (id) :0 );
I guess this is another candidate for regmap_assign_bits() but with that change:
Daniel.
PATCH v3 10/11 video: backlight: lm3533_bl: Implement backlight_scale property
In reply to Svyatoslav RyhelSince the device supports linear and non-linear modes, implement the backlight_scale property to describe this state.
--- drivers/video/backlight/lm3533_bl.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/video/backlight/lm3533_bl.c +6 -0
@@ -161,6 +161,7 @@ static ssize_t store_linear(struct device *dev, const char *buf, size_t len) {struct lm3533_bl *bl =dev_get_drvdata (dev); +struct backlight_device *bd = bl->bd;int id =lm3533_bl_get_ctrlbank_id (bl);unsigned long linear;int ret;
@@ -174,6 +175,9 @@ static ssize_t store_linear(struct device *dev,if (ret)return ret; + bd->props.scale = linear ?BACKLIGHT_SCALE_LINEAR : +BACKLIGHT_SCALE_NON_LINEAR ; +return len; }
@@ -309,6 +313,8 @@ static int lm3533_bl_probe(struct platform_device *pdev) bl->linear =device_property_read_bool (&pdev->dev,"ti,linear-mapping-mode" ); + props.scale = bl->linear ?BACKLIGHT_SCALE_LINEAR : +BACKLIGHT_SCALE_NON_LINEAR ; bd =devm_backlight_device_register (&pdev->dev, name, &pdev->dev, bl, &lm3533_bl_ops, &props);
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v3 10/11] video: backlight: lm3533_bl: Implement backlight_scale property
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Unprotected concurrent modification of hardware register and `bd->props.scale` causes state…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unprotected concurrent modification of hardware register and bd->props.scale causes state desynchronization. --
commit 8adaee77dd01ba44b6fdadefc561f4ab4fed6761
Author: Svyatoslav Ryhel <[email protected]>
video: backlight: lm3533_bl: Implement backlight_scale property
This commit implements the backlight_scale property to describe the linear and non-linear modes supported by the device.
Quoted 13 lines
drivers/video/backlight/lm3533_bl.c +1
-0@@ -161,6 +161,7 @@ static ssize_t store_linear(struct device *dev, const char *buf, size_t len) {struct lm3533_bl *bl =dev_get_drvdata (dev); +struct backlight_device *bd = bl->bd;int id =lm3533_bl_get_ctrlbank_id (bl);unsigned long linear;int ret;
drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, · line 179
Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +2
-0@@ -174,6 +175,9 @@ static ssize_t store_linear(struct device *dev,if (ret)return ret; + bd->props.scale = linear ?BACKLIGHT_SCALE_LINEAR : +BACKLIGHT_SCALE_NON_LINEAR ;
[Severity: Medium]
Is it possible for the hardware state and the software state in bd->props.scale to become desynchronized here?
Because sysfs writes can execute concurrently, could an interleaved execution of store_linear() by two different threads result in a race condition where the states diverge?
For example:
Thread 1 writes linear=1
Thread 1 updates hardware via regmap_update_bits()
Thread 2 writes linear=0
Thread 2 updates hardware via regmap_update_bits() Thread 2 updates bd->props.scale = BACKLIGHT_SCALE_NON_LINEAR
Thread 1 updates bd->props.scale = BACKLIGHT_SCALE_LINEAR
Would wrapping this update sequence in a lock ensure the hardware and software states remain consistent?
Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +1
-0+return len; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH v3 10/11] video: backlight: lm3533_bl: Implement backlight_scale property
In reply to Svyatoslav RyhelQuoted 4 lines · Svyatoslav Ryhel
Since the device supports linear and non-linear modes, implement the
backlight_scaleproperty to describe this state.Signed-off-by Svyatoslav Ryhel <[email protected]>
Thanks!
Daniel.
PATCH v3 11/11 video: leds: backlight: lm3533: Support getting LED sources from DT
In reply to Svyatoslav RyhelAdd Control Bank to HVLED/LVLED muxing support based on the led-sources defined in the device tree.
--- drivers/leds/leds-lm3533.c | 55 ++++++++++++++++++++++++++++- drivers/video/backlight/lm3533_bl.c | 40 ++++++++++++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-)
drivers/leds/leds-lm3533.c +54 -1
@@ -7,6 +7,7 @@* Author: Johan Hovold <[email protected]> */ +#include <linux/bits.h> #include <linux/module.h> #include <linux/leds.h> #include <linux/mfd/core.h>
@@ -27,6 +28,12 @@#define LM3533_ALS_CHANNEL_LV_MIN 1#define LM3533_ALS_CHANNEL_LV_MAX 2 +#define LM3533_REG_OUTPUT_CONF1 0x10 +#define OUTPUT_CONF1_MASK GENMASK(7, 2) +#define OUTPUT_CONF1_SHIFT 2 +#define LM3533_REG_OUTPUT_CONF2 0x11 +#define OUTPUT_CONF2_MASK GENMASK(3, 0) +#define OUTPUT_CONF2_SHIFT 6#define LM3533_REG_CTRLBANK_BCONF_BASE 0x1b#define LM3533_REG_PATTERN_ENABLE 0x28#define LM3533_REG_PATTERN_LOW_TIME_BASE 0x71
@@ -54,6 +61,9 @@ struct lm3533_led {u32 max_current;u32 pwm; + +int num_leds; +u32 leds[LM3533_LVCTRLBANK_MAX ]; };
@@ -641,7 +651,33 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {static int lm3533_led_setup (struct lm3533_led *led) { -int ret; +u32 output_cfg_shift =0 ; +u32 output_cfg_val =0 ; +int ret, i; + +if (led->num_leds) { +for (i =0 ; i < led->num_leds; i++) { +if (led->leds[i] >=LM3533_LVCTRLBANK_MAX ) +continue ; + + output_cfg_shift = led->leds[i] *2 ; + output_cfg_val |= led->id << output_cfg_shift; + } + +/* LVLED1, LVLED2 and LVLED3 */ + ret =regmap_update_bits (led->lm3533->regmap,LM3533_REG_OUTPUT_CONF1 , +OUTPUT_CONF1_MASK , + output_cfg_val <<OUTPUT_CONF1_SHIFT ); +if (ret) +return ret; + +/* LVLED4 and LVLED5 */ + ret =regmap_update_bits (led->lm3533->regmap,LM3533_REG_OUTPUT_CONF2 , +OUTPUT_CONF2_MASK , + output_cfg_val >>OUTPUT_CONF2_SHIFT ); +if (ret) +return ret; + } ret =lm3533_ctrlbank_set_max_current (&led->cb, led->max_current);if (ret)
@@ -716,6 +752,23 @@ static int lm3533_led_probe(struct platform_device *pdev) led->pwm =0 ;device_property_read_u32 (&pdev->dev,"ti,pwm-config-mask" , &led->pwm); + led->num_leds =device_property_count_u32 (&pdev->dev,"led-sources" ); + +/* +* If led-sources property is not set then either this Control Bank uses +* its default LVLED or is not linked to any LVLED at all. +*/ +if (led->num_leds >0 && led->num_leds <=LM3533_LVCTRLBANK_MAX ) { + ret =device_property_read_u32_array (&pdev->dev,"led-sources" , + led->leds, led->num_leds); +if (ret) { +dev_err (&pdev->dev,"failed to get led-sources\n" ); + goto err_deregister; + } + }else { + led->num_leds =0 ; + } + ret =lm3533_led_setup (led);if (ret) goto err_deregister;
drivers/video/backlight/lm3533_bl.c +39 -1
@@ -7,6 +7,7 @@* Author: Johan Hovold <[email protected]> */ +#include <linux/bits.h> #include <linux/module.h> #include <linux/init.h> #include <linux/mod_devicetable.h>
@@ -22,6 +23,8 @@#define LM3533_HVCTRLBANK_COUNT 2#define LM3533_BL_MAX_BRIGHTNESS 255 +#define LM3533_REG_OUTPUT_CONF1 0x10 +#define OUTPUT_CONF1_MASK GENMASK(1, 0)#define LM3533_REG_CTRLBANK_AB_BCONF 0x1a#define CTRLBANK_AB_BCONF_MODE (n) BIT(2 * (n) + 1)
@@ -35,6 +38,9 @@ struct lm3533_bl {u32 max_current;u32 pwm;bool linear; + +int num_leds; +u32 led_strings[LM3533_HVCTRLBANK_COUNT ]; };
@@ -253,7 +259,8 @@ static struct attribute_group lm3533_bl_attribute_group = {static int lm3533_bl_setup (struct lm3533_bl *bl) {int id =lm3533_bl_get_ctrlbank_id (bl); -int ret; +u32 output_cfg_val =0 ; +int ret, i; ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF, CTRLBANK_AB_BCONF_MODE(id),
@@ -261,6 +268,20 @@ static int lm3533_bl_setup(struct lm3533_bl *bl)if (ret)return ret; +if (bl->num_leds) { +for (i =0 ; i < bl->num_leds; i++) { +if (bl->led_strings[i] >=LM3533_HVCTRLBANK_COUNT ) +continue ; + + output_cfg_val |= id << bl->led_strings[i]; + } + + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_OUTPUT_CONF1 , +OUTPUT_CONF1_MASK , output_cfg_val); +if (ret) +return ret; + } + ret =lm3533_ctrlbank_set_max_current (&bl->cb, bl->max_current);if (ret)return ret;
@@ -336,6 +357,23 @@ static int lm3533_bl_probe(struct platform_device *pdev) bl->pwm =0 ;device_property_read_u32 (&pdev->dev,"ti,pwm-config-mask" , &bl->pwm); + bl->num_leds =device_property_count_u32 (&pdev->dev,"led-sources" ); + +/* +* If led-sources property is not set then either this Control Bank uses +* its default HVLED or is not linked to any HVLED at all. +*/ +if (bl->num_leds >0 && bl->num_leds <=LM3533_HVCTRLBANK_COUNT ) { + ret =device_property_read_u32_array (&pdev->dev,"led-sources" , + bl->led_strings, + bl->num_leds); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"failed to get led-sources\n" ); + }else { + bl->num_leds =0 ; + } + ret =lm3533_bl_setup (bl);if (ret)return ret;
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH v3 11/11] video: leds: backlight: lm3533: Support getting LED sources from DT
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Register Overwrite Logic Error in LED and Backlight Setup - [Medium] Silent failure when…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Register Overwrite Logic Error in LED and Backlight Setup
- [Medium] Silent failure when led-sources exceeds maximum supported items --
commit d198a595bf518d4b23e00515d642947b56c4b197
Author: Svyatoslav Ryhel <[email protected]>
video: leds: backlight: lm3533: Support getting LED sources from DT
Add Control Bank to HVLED/LVLED muxing support based on the led-sources defined in the device tree.
Quoted 4 lines
drivers/leds/leds-lm3533.c +0
-0
[ ... ]
Quoted 12 lines
drivers/leds/leds-lm3533.c +7
-1@@ -641,7 +651,33 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {static int lm3533_led_setup (struct lm3533_led *led) { -int ret; +u32 output_cfg_shift =0 ; +u32 output_cfg_val =0 ; +int ret, i; + +if (led->num_leds) { +for (i =0 ; i < led->num_leds; i++) { +if (led->leds[i] >=LM3533_LVCTRLBANK_MAX )
drivers/leds/leds-lm3533.c static const struct attribute_group *lm3533_led_attribute_groups[] = { · line 670
Quoted 10 lines
drivers/leds/leds-lm3533.c +10
-0+continue ; + + output_cfg_shift = led->leds[i] *2 ; + output_cfg_val |= led->id << output_cfg_shift; + } + +/* LVLED1, LVLED2 and LVLED3 */ + ret =regmap_update_bits (led->lm3533->regmap,LM3533_REG_OUTPUT_CONF1 , +OUTPUT_CONF1_MASK , + output_cfg_val <<OUTPUT_CONF1_SHIFT );
[Severity: High]
Does this code inadvertently clear configurations for other LED strings?
Because OUTPUT_CONF1_MASK is a static broad mask (GENMASK(7, 2)), the call to regmap_update_bits() clears all LVLED1-3 fields that are not part of the current output_cfg_val.
If multiple control banks are probed sequentially, it seems the later probe will overwrite and break the hardware routing of previously configured banks. Should the mask be dynamically generated based on the specific strings being configured in led-sources instead of updating all bits?
Quoted 12 lines
drivers/leds/leds-lm3533.c +10
-0+if (ret) +return ret; + +/* LVLED4 and LVLED5 */ + ret =regmap_update_bits (led->lm3533->regmap,LM3533_REG_OUTPUT_CONF2 , +OUTPUT_CONF2_MASK , + output_cfg_val >>OUTPUT_CONF2_SHIFT ); +if (ret) +return ret; + } ret =lm3533_ctrlbank_set_max_current (&led->cb, led->max_current);
[ ... ]
Quoted 10 lines
drivers/leds/leds-lm3533.c +6
-0@@ -716,6 +752,23 @@ static int lm3533_led_probe(struct platform_device *pdev) led->pwm =0 ;device_property_read_u32 (&pdev->dev,"ti,pwm-config-mask" , &led->pwm); + led->num_leds =device_property_count_u32 (&pdev->dev,"led-sources" ); + +/* +* If led-sources property is not set then either this Control Bank uses +* its default LVLED or is not linked to any LVLED at all. +*/
drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 770
Quoted 10 lines
drivers/leds/leds-lm3533.c +10
-0+if (led->num_leds >0 && led->num_leds <=LM3533_LVCTRLBANK_MAX ) { + ret =device_property_read_u32_array (&pdev->dev,"led-sources" , + led->leds, led->num_leds); +if (ret) { +dev_err (&pdev->dev,"failed to get led-sources\n" ); + goto err_deregister; + } + }else { + led->num_leds =0 ; + }
[Severity: Medium]
Will this silently ignore out-of-bounds configurations?
If the user provides a device tree with more items than the hardware supports (e.g., led->num_leds > LM3533_LVCTRLBANK_MAX), the check fails and the code falls through to the else block.
Setting led->num_leds = 0 treats the oversized array as if the property was entirely omitted, masking the error. Would it be better to explicitly return an error like -EINVAL to alert the user of an invalid configuration?
Quoted 4 lines
drivers/leds/leds-lm3533.c +1
-0+ ret =lm3533_led_setup (led);if (ret) goto err_deregister;
[ ... ]
Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0
-0
[ ... ]
Quoted 14 lines
drivers/video/backlight/lm3533_bl.c +2
-1@@ -253,7 +259,8 @@ static struct attribute_group lm3533_bl_attribute_group = {static int lm3533_bl_setup (struct lm3533_bl *bl) {int id =lm3533_bl_get_ctrlbank_id (bl); -int ret; +u32 output_cfg_val =0 ; +int ret, i; ret = regmap_update_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF, CTRLBANK_AB_BCONF_MODE(id),@@ -261,6 +268,20 @@ static int lm3533_bl_setup(struct lm3533_bl *bl)if (ret)return ret;
drivers/video/backlight/lm3533_bl.c static int lm3533_bl_setup(struct lm3533_bl *bl) · line 280
Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +10
-0+if (bl->num_leds) { +for (i =0 ; i < bl->num_leds; i++) { +if (bl->led_strings[i] >=LM3533_HVCTRLBANK_COUNT ) +continue ; + + output_cfg_val |= id << bl->led_strings[i]; + } + + ret =regmap_update_bits (bl->lm3533->regmap,LM3533_REG_OUTPUT_CONF1 , +OUTPUT_CONF1_MASK , output_cfg_val);
[Severity: High]
Can this similarly clobber the other backlight control bank?
Since OUTPUT_CONF1_MASK is GENMASK(1, 0), it unconditionally updates all HVLED routing fields at once. Configuring one backlight bank will overwrite the configuration of the other bank.
Could the mask be limited only to the bits modified by the current bank?
Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +4
-0+if (ret) +return ret; + } + ret =lm3533_ctrlbank_set_max_current (&bl->cb, bl->max_current);
[ ... ]
Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +6
-0@@ -336,6 +357,23 @@ static int lm3533_bl_probe(struct platform_device *pdev) bl->pwm =0 ;device_property_read_u32 (&pdev->dev,"ti,pwm-config-mask" , &bl->pwm); + bl->num_leds =device_property_count_u32 (&pdev->dev,"led-sources" ); + +/* +* If led-sources property is not set then either this Control Bank uses +* its default HVLED or is not linked to any HVLED at all. +*/
drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 375
Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +10
-0+if (bl->num_leds >0 && bl->num_leds <=LM3533_HVCTRLBANK_COUNT ) { + ret =device_property_read_u32_array (&pdev->dev,"led-sources" , + bl->led_strings, + bl->num_leds); +if (ret) +return dev_err_probe (&pdev->dev, ret, +"failed to get led-sources\n" ); + }else { + bl->num_leds =0 ; + }
[Severity: Medium]
Does this have the same silent failure behavior as the LED probe?
If bl->num_leds > LM3533_HVCTRLBANK_COUNT, it falls back to the else block setting bl->num_leds = 0 without producing an error, ignoring the invalid device tree array.
Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +1
-0+ ret =lm3533_bl_setup (bl);if (ret)return ret;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11