Skip to contentSkip to conversation

mfd: lm3533: convert to OF bindings, improve support

PATCH Superseded Svyatoslav Ryhel 7 participants 57 messages Jun 17 – Sep 9

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 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

Changes in v4:

- fixed regmap_update_bits val and mask swap in lm3533_als_set_int_mode
- fixed als->irq check in store_thresh_either_en
- removed clamping of r_select in als driver
- added use_of_reg and of_reg for backlight and leds registration
- added intermediate step in asigning props.brightness
- fixed HVLED/LVLED configuration overwriting
- added bounds check for num_leds in leds and backlight driver
- switched to regmap_clean/set/assign/test_bits helpers where appropriate
- dropped extern from header function declartions
- switched lm3533 pointer in cell structures to regmap
- sysfs_create_group > device_add_group
- changes in backlight sysfs were expanded to all properties

Changes in v5:

- aligned driver helpers to use u32
- child nodes parsing linked with 'else if' to ensure there is one call per node
- removed redundant pwm var init for leds
- fixed regmap_test_bits return check
- fixed leds and backlight counting handling
- iterator variables made scoped
- lm3533_als_setup() set to exit after mode set if m0de is pwm
---

Svyatoslav Ryhel (14):
dt-bindings: leds: Document TI LM3533 LED controller
mfd: lm3533: Remove driver specific regmap wrappers
mfd: lm3533: Remove extern from shared functions in the header
mfd: lm3533: Pass only regmap and light sensor presence to child
devices
iio: light: lm3533-als: Remove redundant pdata helpers
mfd: lm3533-core: Remove redundant pdata helpers
mfd: lm3533: Use dev_groups in struct device_driver
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 logic of sysfs functions
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                | 180 ++++-----
 drivers/leds/leds-lm3533.c                    | 184 ++++++---
 drivers/mfd/lm3533-core.c                     | 375 +++++++-----------
 drivers/mfd/lm3533-ctrlbank.c                 |  33 +-
 drivers/video/backlight/lm3533_bl.c           | 232 ++++++-----
 include/linux/mfd/lm3533.h                    |  75 +---
 9 files changed, 821 insertions(+), 563 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.53.0
#1 lore raw

PATCH v5 1/14 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
new file mode 100644
index 000000000000..a25846e9b375
@@ -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.53.0
#2 lore raw

Re: [PATCH v5 01/14] dt-bindings: leds: Document TI LM3533 LED controller

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] DT Schema Validation Failure due to strict property restrictions. - [Low] Ineffective Schema…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] DT Schema Validation Failure due to strict property restrictions.
- [Low] Ineffective Schema Constraints on reg property array.
--

commit 69694c121b5fef16f95b87bbf30e28ee4fb13044
Author: Svyatoslav Ryhel <[email protected]>

dt-bindings: leds: Document TI LM3533 LED controller

Document the LM3533 - a complete power source for backlight, keypad and indicator LEDs in smartphone handsets.

Quoted 5 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +0 -0
new file mode 100644
index 0000000000000..a25846e9b3752

[ ... ]

Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml line 25

Quoted 7 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +7 -0
+properties:
+  compatible:
+    const: ti,lm3533-backlight
+
+  reg:
+    description: Control bank selection (0 = bank A, 1 = bank B).
+    maximum: 1

[Severity: Low]
Are these constraints effective? In Device Tree JSON representations, reg is decoded as an array of arrays of integers (cells).

Numeric validation keywords like maximum are silently ignored when applied directly to arrays instead of being nested under items.

[ ... ]

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml new file +0 -0
new file mode 100644
index 0000000000000..d8dbefef3323e

[ ... ]

Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml line 27

Quoted 9 lines
Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml new file +9 -0
+properties:
+  compatible:
+    const: ti,lm3533-leds
+
+  reg:
+    description:
+      Control bank selection (2 = bank C, 3 = bank D, 4 = bank E, 5 = bank F).
+    minimum: 2
+    maximum: 5

[Severity: Low]
Similar to the reg property in the backlight binding, should these numeric constraints be nested under items? As written, they apply to the array itself and will be ignored during schema validation.

[ ... ]

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +0 -0
new file mode 100644
index 0000000000000..bdc05a9f3d663

[ ... ]

Quoted 7 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +7 -0
+  light-sensor:
+    type: object
+    additionalProperties: false
+
+    properties:
+      compatible:
+        const: ti,lm3533-als

[ ... ]

Quoted 2 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +2 -0
+examples:
+  - |

[ ... ]

Documentation/devicetree/bindings/leds/ti,lm3533.yaml line 163

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +5 -0
+            light-sensor {
+                compatible = "ti,lm3533-als";
+
+                interrupt-parent = <&gpio>;
+                interrupts = <80 IRQ_TYPE_LEVEL_LOW>;

[Severity: Low]
Will this fail make dt_binding_check? The light-sensor definition uses
additionalProperties: false but doesn't explicitly list interrupt-parent in its properties block.

Since the example uses interrupt-parent, it seems this will cause a schema validation failure. Should the schema include interrupt-parent: true, or perhaps drop additionalProperties: false?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v5 01/14] dt-bindings: leds: Document TI LM3533 LED controller

In reply to Svyatoslav Ryhel
Quoted 57 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.

Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +47 -0
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led-controller@36 {
+            compatible = "ti,lm3533";
+            reg = <0x36>;
+
+            enable-gpios = <&gpio 110 GPIO_ACTIVE_HIGH>;
+            vin-supply = <&vdd_3v3_bat>;
+
+            ti,boost-ovp-microvolt = <24000000>;
+            ti,boost-freq-hz = <500000>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            backlight@0 {
+                compatible = "ti,lm3533-backlight";
+                reg = <0>;
+
+                default-brightness = <113>;
+
+                led-max-microamp = <23400>;
+                led-sources = <0 1>;
+            };
+
+            led@2 {
+                compatible = "ti,lm3533-leds";
+                reg = <2>;
+
+                led-max-microamp = <23400>;
+                led-sources = <0 1>;
+            };
+
+            led@4 {
+                compatible = "ti,lm3533-leds";
+                reg = <4>;
+
+                led-max-microamp = <23400>;
+                led-sources = <2>;
+            };

Documentation/devicetree/bindings/leds/ti,lm3533.yaml line 159

Quoted 10 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +10 -0
+
+            led@5 {
+                compatible = "ti,lm3533-leds";
+                reg = <5>;
+
+                led-max-microamp = <23400>;
+                led-sources = <3 4>;
+            };
+
+            light-sensor {

Doesn't the binding (or dts) checker complain about this node not having an address?

Documentation/devicetree/bindings/leds/ti,lm3533.yaml line 169

Quoted 10 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +10 -0
+                compatible = "ti,lm3533-als";
+
+                interrupt-parent = <&gpio>;
+                interrupts = <80 IRQ_TYPE_LEVEL_LOW>;
+
+                ti,pwm-mode;
+            };
+        };
+    };
+...

Johan

#4 lore raw

Re: [PATCH v5 01/14] dt-bindings: leds: Document TI LM3533 LED controller

пт, 3 лип. 2026 р. о 12:49 Johan Hovold <[email protected]> пише:

Quoted 64 lines · Svyatoslav Ryhel
Quoted 62 lines

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.

Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +52 -0
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        led-controller@36 {
+            compatible = "ti,lm3533";
+            reg = <0x36>;
+
+            enable-gpios = <&gpio 110 GPIO_ACTIVE_HIGH>;
+            vin-supply = <&vdd_3v3_bat>;
+
+            ti,boost-ovp-microvolt = <24000000>;
+            ti,boost-freq-hz = <500000>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            backlight@0 {
+                compatible = "ti,lm3533-backlight";
+                reg = <0>;
+
+                default-brightness = <113>;
+
+                led-max-microamp = <23400>;
+                led-sources = <0 1>;
+            };
+
+            led@2 {
+                compatible = "ti,lm3533-leds";
+                reg = <2>;
+
+                led-max-microamp = <23400>;
+                led-sources = <0 1>;
+            };
+
+            led@4 {
+                compatible = "ti,lm3533-leds";
+                reg = <4>;
+
+                led-max-microamp = <23400>;
+                led-sources = <2>;
+            };
+
+            led@5 {
+                compatible = "ti,lm3533-leds";
+                reg = <5>;
+
Quoted 9 lines

Documentation/devicetree/bindings/leds/ti,lm3533.yaml line 159

Quoted 5 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +5 -0
+                led-max-microamp = <23400>;
+                led-sources = <3 4>;
+            };
+
+            light-sensor {

Doesn't the binding (or dts) checker complain about this node not having an address?

No it does not

Quoted 12 lines

Documentation/devicetree/bindings/leds/ti,lm3533.yaml line 169

Quoted 10 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +10 -0
+                compatible = "ti,lm3533-als";
+
+                interrupt-parent = <&gpio>;
+                interrupts = <80 IRQ_TYPE_LEVEL_LOW>;
+
+                ti,pwm-mode;
+            };
+        };
+    };
+...

Johan

#5 lore raw

Re: [PATCH v5 01/14] dt-bindings: leds: Document TI LM3533 LED controller

Quoted 9 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 12:49 Johan Hovold <[email protected]> пише:

Quoted 5 lines
Quoted 1 line

+ light-sensor {

Doesn't the binding (or dts) checker complain about this node not having an address?

No it does not

Thanks for confirming.

Johan

#6 lore raw

PATCH v5 2/14 mfd: lm3533: Remove driver specific regmap wrappers

In reply to Svyatoslav Ryhel

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

---
 drivers/iio/light/lm3533-als.c      | 79 +++++++++++++----------------
 drivers/leds/leds-lm3533.c          | 62 ++++++++--------------
 drivers/mfd/lm3533-core.c           | 73 ++++----------------------
 drivers/mfd/lm3533-ctrlbank.c       | 28 +++++-----
 drivers/video/backlight/lm3533_bl.c | 37 +++++---------
 include/linux/mfd/lm3533.h          | 15 ++----
 6 files changed, 100 insertions(+), 194 deletions(-)
drivers/iio/light/lm3533-als.c +34 -45
index 99f0b903018c..44b104c2d77f 100644
@@ -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");
 
@@ -171,8 +172,8 @@ static int lm3533_als_set_target(struct iio_dev *indio_dev, unsigned channel,
 static int lm3533_als_get_current(struct iio_dev *indio_dev, unsigned channel,
 								int *val)
 {
+	u32 target;
 	u8 zone;
-	u8 target;
 	int ret;
 
 	ret = lm3533_als_get_zone(indio_dev, &zone);
@@ -271,16 +272,10 @@ static irqreturn_t lm3533_als_isr(int irq, void *dev_id)
 static int lm3533_als_set_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;
 	int ret;
 
-	if (enable)
-		val = mask;
-	else
-		val = 0;
-
-	ret = lm3533_update(als->lm3533, LM3533_REG_ALS_ZONE_INFO, val, mask);
+	ret = regmap_assign_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+				 LM3533_ALS_INT_ENABLE_MASK, enable);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to set int mode %d\n",
 								enable);
@@ -293,17 +288,16 @@ static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable)
 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;
 	int ret;
 
-	ret = lm3533_read(als->lm3533, LM3533_REG_ALS_ZONE_INFO, &val);
-	if (ret) {
+	ret = regmap_test_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+			       LM3533_ALS_INT_ENABLE_MASK);
+	if (ret < 0) {
 		dev_err(&indio_dev->dev, "failed to get int mode\n");
 		return ret;
 	}
 
-	*enable = !!(val & mask);
+	*enable = ret;
 
 	return 0;
 }
@@ -316,7 +310,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 +320,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,8 +331,8 @@ 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;
 	u8 reg, reg2;
+	u32 val2;
 	int ret;
 
 	if (nr > LM3533_ALS_THRESH_MAX)
@@ -348,7 +342,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 +357,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 +369,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 +497,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) {
@@ -716,16 +710,10 @@ static const struct attribute_group lm3533_als_attribute_group = {
 
 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 = lm3533_update(als->lm3533, LM3533_REG_ALS_CONF, val, mask);
+	ret = regmap_assign_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+				 LM3533_ALS_INPUT_MODE_MASK, pwm_mode);
 	if (ret) {
 		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
 								pwm_mode);
@@ -744,7 +732,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;
@@ -774,11 +763,11 @@ static int lm3533_als_setup(struct lm3533_als *als,
 
 static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev)
 {
-	u8 mask = LM3533_ALS_INT_ENABLE_MASK;
 	int ret;
 
 	/* Make sure interrupts are disabled. */
-	ret = lm3533_update(als->lm3533, LM3533_REG_ALS_ZONE_INFO, 0, mask);
+	ret = regmap_clear_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+				LM3533_ALS_INT_ENABLE_MASK);
 	if (ret) {
 		dev_err(&als->pdev->dev, "failed to disable interrupts\n");
 		return ret;
@@ -798,10 +787,10 @@ static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev)
 
 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_set_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+			      LM3533_ALS_ENABLE_MASK);
 	if (ret)
 		dev_err(&als->pdev->dev, "failed to enable ALS\n");
 
@@ -810,10 +799,10 @@ static int lm3533_als_enable(struct lm3533_als *als)
 
 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_clear_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+				LM3533_ALS_ENABLE_MASK);
 	if (ret)
 		dev_err(&als->pdev->dev, "failed to disable ALS\n");
 
drivers/leds/leds-lm3533.c +22 -40

180 lines not on this page · raw message

drivers/mfd/lm3533-core.c +11 -62

114 lines not on this page · raw message

drivers/mfd/lm3533-ctrlbank.c +15 -13
index 2537dfade51c..c2b5fd38b81d 100644
@@ -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_set_bits(cb->lm3533->regmap, LM3533_REG_CTRLBANK_ENABLE,
+			      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_clear_bits(cb->lm3533->regmap, LM3533_REG_CTRLBANK_ENABLE,
+				mask);
 	if (ret)
 		dev_err(cb->dev, "failed to disable ctrlbank %d\n", cb->id);
 
@@ -68,7 +70,7 @@ EXPORT_SYMBOL_GPL(lm3533_ctrlbank_disable);
  *
  * imax		5000 - 29800 uA (800 uA step)
  */
-int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u16 imax)
+int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u32 imax)
 {
 	u8 reg;
 	u8 val;
@@ -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");
 
@@ -88,13 +90,13 @@ int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u16 imax)
 }
 EXPORT_SYMBOL_GPL(lm3533_ctrlbank_set_max_current);
 
-int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u8 val)
+int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u32 val)
 {
 	u8 reg;
 	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");
 
@@ -126,7 +128,7 @@ EXPORT_SYMBOL_GPL(lm3533_ctrlbank_get_brightness);
  *   bit 1 - PWM-input enabled in Zone 0
  *   bit 0 - PWM-input enabled
  */
-int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u8 val)
+int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u32 val)
 {
 	u8 reg;
 	int ret;
@@ -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 +13 -24
index babfd3ceec86..cd21c64b6485 100644
@@ -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;
 
@@ -104,7 +105,6 @@ static ssize_t store_als_en(struct device *dev,
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
 	int enable;
-	u8 val;
 	u8 mask;
 	int ret;
 
@@ -113,13 +113,8 @@ static ssize_t store_als_en(struct device *dev,
 
 	mask = 1 << (2 * ctrlbank);
 
-	if (enable)
-		val = mask;
-	else
-		val = 0;
-
-	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
-									mask);
+	ret = regmap_assign_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+				 mask, enable);
 	if (ret)
 		return ret;
 
@@ -130,12 +125,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;
 
@@ -156,7 +151,6 @@ static ssize_t store_linear(struct device *dev,
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	unsigned long linear;
 	u8 mask;
-	u8 val;
 	int ret;
 
 	if (kstrtoul(buf, 0, &linear))
@@ -164,13 +158,8 @@ static ssize_t store_linear(struct device *dev,
 
 	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
 
-	if (linear)
-		val = mask;
-	else
-		val = 0;
-
-	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
-									mask);
+	ret = regmap_assign_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+				 mask, linear);
 	if (ret)
 		return ret;
 
@@ -182,7 +171,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);
@@ -197,10 +186,10 @@ static ssize_t store_pwm(struct device *dev,
 					const char *buf, size_t len)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
-	u8 val;
+	u32 val;
 	int ret;
 
-	if (kstrtou8(buf, 0, &val))
+	if (kstrtou32(buf, 0, &val))
 		return -EINVAL;
 
 	ret = lm3533_ctrlbank_set_pwm(&bl->cb, val);
include/linux/mfd/lm3533.h +5 -10
index 69059a7a2ce5..3463b164d0c1 100644
@@ -85,15 +85,10 @@ struct lm3533_platform_data {
 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_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_set_brightness(struct lm3533_ctrlbank *cb, u32 val);
+extern int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u32 *val);
+extern int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u32 imax);
+extern int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u32 val);
+extern int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u32 *val);
 
 #endif	/* __LINUX_MFD_LM3533_H */
Signature · 1 line
2.53.0
Reviewed-by on v5 2/14
#7 lore raw

Re: [PATCH v5 02/14] mfd: lm3533: Remove driver specific regmap wrappers

Quoted 2 lines · Svyatoslav Ryhel

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

OK, let's go with this variant.

Some side notes below for the record.

...

drivers/leds/leds-lm3533.c static ssize_t store_als_en(struct device *dev, · line 473

Quoted 2 lines
drivers/leds/leds-lm3533.c +0 -0
 	struct lm3533_led *led = to_lm3533_led(led_cdev);
 	unsigned enable;

Oh, besides using the old way of declaring unsigned int, it most likely just needs to be kstrtobool().

drivers/leds/leds-lm3533.c static ssize_t store_als_en(struct device *dev, · line 478

Quoted 7 lines
drivers/leds/leds-lm3533.c +0 -2
 	u8 reg;
-	u8 mask;
-	u8 val;
 	int ret;
 
 	if (kstrtouint(buf, 0, &enable))
 		return -EINVAL;

We should unshadow error codes (it may return more than -EINVAL).

Quoted 8 lines
drivers/leds/leds-lm3533.c +0 -6
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
-	mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
 
-	if (enable)
-		val = mask;
-	else
-		val = 0;
-

...

drivers/leds/leds-lm3533.c static ssize_t store_pwm(struct device *dev, · line 562

Quoted 3 lines
drivers/leds/leds-lm3533.c +1 -1
-	if (kstrtou8(buf, 0, &val))
+	if (kstrtou32(buf, 0, &val))
 		return -EINVAL;

Like in the previous case we should unshadow error codes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw

Re: [PATCH v5 02/14] mfd: lm3533: Remove driver specific regmap wrappers

Quoted 22 lines · Andy Shevchenko
Quoted 2 lines · Svyatoslav Ryhel

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

OK, let's go with this variant.

Some side notes below for the record.

...

drivers/leds/leds-lm3533.c static ssize_t store_als_en(struct device *dev, · line 473

Quoted 2 lines
drivers/leds/leds-lm3533.c +0 -0
 	struct lm3533_led *led = to_lm3533_led(led_cdev);
 	unsigned enable;

Oh, besides using the old way of declaring unsigned int, it most likely just needs to be kstrtobool().

Quoted 5 lines
drivers/leds/leds-lm3533.c +0 -2
 	u8 reg;
-	u8 mask;
-	u8 val;
 	int ret;
Quoted 4 lines

drivers/leds/leds-lm3533.c static ssize_t store_als_en(struct device *dev, · line 478

Quoted 2 lines
drivers/leds/leds-lm3533.c +0 -0
 	if (kstrtouint(buf, 0, &enable))
 		return -EINVAL;

We should unshadow error codes (it may return more than -EINVAL).

Right, this masks -ERANGE.

We should fix that.

Quoted 22 lines
Quoted 8 lines
drivers/leds/leds-lm3533.c +0 -6
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
-	mask = LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK;
 
-	if (enable)
-		val = mask;
-	else
-		val = 0;
-

...

drivers/leds/leds-lm3533.c static ssize_t store_pwm(struct device *dev, · line 562

Quoted 3 lines
drivers/leds/leds-lm3533.c +1 -1
-	if (kstrtou8(buf, 0, &val))
+	if (kstrtou32(buf, 0, &val))
 		return -EINVAL;

Like in the previous case we should unshadow error codes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 1 line
Lee Jones
#9 lore raw

Re: [PATCH v5 02/14] mfd: lm3533: Remove driver specific regmap wrappers

In reply to Svyatoslav Ryhel
Quoted 2 lines · Svyatoslav Ryhel

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

The commit message should explain why you think this is a good idea.

Based on a quick look you lose the errnos that were logged on errors and also the register debugging provided by those helpers.

Johan

#10 lore raw

Re: [PATCH v5 02/14] mfd: lm3533: Remove driver specific regmap wrappers

пт, 3 лип. 2026 р. о 12:44 Johan Hovold <[email protected]> пише:

Quoted 7 lines · Svyatoslav Ryhel
Quoted 2 lines

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

The commit message should explain why you think this is a good idea.

Removing custom wrappers over standard regmap helpers is always a good idea, that is self explanatory.

Quoted 3 lines

Based on a quick look you lose the errnos that were logged on errors and also the register debugging provided by those helpers.

That is not true, regmap helpers will provide logging and you should not include debug stuff into the final submitted driver unless you have a extremely valid justification for this, debug logs should have been removed once the driver development was completed.

Quoted 1 line

Johan

#11 lore raw

Re: [PATCH v5 02/14] mfd: lm3533: Remove driver specific regmap wrappers

Quoted 11 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 12:44 Johan Hovold <[email protected]> пише:

Quoted 7 lines · Svyatoslav Ryhel
Quoted 2 lines

Remove driver-specific regmap wrappers in favor of using regmap helpers directly.

The commit message should explain why you think this is a good idea.

Removing custom wrappers over standard regmap helpers is always a good idea, that is self explanatory.

No, and especially not if you're removing functionality.

Quoted 8 lines
Quoted 3 lines

Based on a quick look you lose the errnos that were logged on errors and also the register debugging provided by those helpers.

That is not true, regmap helpers will provide logging and you should not include debug stuff into the final submitted driver unless you have a extremely valid justification for this, debug logs should have been removed once the driver development was completed.

The regmap logging is a compile-time thing (added after the driver was merged), and not equivalent to what the driver provides currently.

The driver also currently relies on these helpers for logging errnos.

Johan

#12 lore raw

PATCH v5 3/14 mfd: lm3533: Remove extern from shared functions in the header

In reply to Svyatoslav Ryhel

Using 'extern' is not required, drop them.

---
 include/linux/mfd/lm3533.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
include/linux/mfd/lm3533.h +8 -8
index 3463b164d0c1..c4c38876c09b 100644
@@ -82,13 +82,13 @@ struct lm3533_platform_data {
 	int num_leds;
 };
 
-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, u32 val);
-extern int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u32 *val);
-extern int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u32 imax);
-extern int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u32 val);
-extern int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u32 *val);
+int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb);
+int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb);
+
+int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u32 val);
+int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u32 *val);
+int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u32 imax);
+int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u32 val);
+int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u32 *val);
 
 #endif	/* __LINUX_MFD_LM3533_H */
Signature · 1 line
2.53.0
#13 lore raw

PATCH v5 4/14 mfd: lm3533: Pass only regmap and light sensor presence to child devices

In reply to Svyatoslav Ryhel

Instead of passing the entire lm3533 core data structure, only pass the regmap and the light sensor presence flag to child devices.

---
 drivers/iio/light/lm3533-als.c      | 32 ++++++++++++++---------------
 drivers/leds/leds-lm3533.c          | 32 ++++++++++++++++-------------
 drivers/mfd/lm3533-ctrlbank.c       | 14 ++++++-------
 drivers/video/backlight/lm3533_bl.c | 19 +++++++++--------
 include/linux/mfd/lm3533.h          |  2 +-
 5 files changed, 53 insertions(+), 46 deletions(-)
drivers/iio/light/lm3533-als.c +16 -16
index 44b104c2d77f..a9af8e2b965f 100644
@@ -49,7 +49,7 @@
 
 
 struct lm3533_als {
-	struct lm3533 *lm3533;
+	struct regmap *regmap;
 	struct platform_device *pdev;
 
 	unsigned long flags;
@@ -73,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 = regmap_read(als->lm3533->regmap, reg, &val);
+	ret = regmap_read(als->regmap, reg, &val);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to read adc\n");
 		return ret;
@@ -90,7 +90,7 @@ static int _lm3533_als_get_zone(struct iio_dev *indio_dev, u8 *zone)
 	u32 val;
 	int ret;
 
-	ret = regmap_read(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO, &val);
+	ret = regmap_read(als->regmap, LM3533_REG_ALS_ZONE_INFO, &val);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to read zone\n");
 		return ret;
@@ -141,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 = regmap_read(als->lm3533->regmap, reg, val);
+	ret = regmap_read(als->regmap, reg, val);
 	if (ret)
 		dev_err(&indio_dev->dev, "failed to get target current\n");
 
@@ -162,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 = regmap_write(als->lm3533->regmap, reg, val);
+	ret = regmap_write(als->regmap, reg, val);
 	if (ret)
 		dev_err(&indio_dev->dev, "failed to set target current\n");
 
@@ -274,7 +274,7 @@ static int lm3533_als_set_int_mode(struct iio_dev *indio_dev, int enable)
 	struct lm3533_als *als = iio_priv(indio_dev);
 	int ret;
 
-	ret = regmap_assign_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+	ret = regmap_assign_bits(als->regmap, LM3533_REG_ALS_ZONE_INFO,
 				 LM3533_ALS_INT_ENABLE_MASK, enable);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to set int mode %d\n",
@@ -290,7 +290,7 @@ static int lm3533_als_get_int_mode(struct iio_dev *indio_dev, int *enable)
 	struct lm3533_als *als = iio_priv(indio_dev);
 	int ret;
 
-	ret = regmap_test_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+	ret = regmap_test_bits(als->regmap, LM3533_REG_ALS_ZONE_INFO,
 			       LM3533_ALS_INT_ENABLE_MASK);
 	if (ret < 0) {
 		dev_err(&indio_dev->dev, "failed to get int mode\n");
@@ -320,7 +320,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 = regmap_read(als->lm3533->regmap, reg, val);
+	ret = regmap_read(als->regmap, reg, val);
 	if (ret)
 		dev_err(&indio_dev->dev, "failed to get threshold\n");
 
@@ -342,7 +342,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 = regmap_read(als->lm3533->regmap, reg2, &val2);
+	ret = regmap_read(als->regmap, reg2, &val2);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to get threshold\n");
 		goto out;
@@ -357,7 +357,7 @@ static int lm3533_als_set_threshold(struct iio_dev *indio_dev, unsigned nr,
 		goto out;
 	}
 
-	ret = regmap_write(als->lm3533->regmap, reg, val);
+	ret = regmap_write(als->regmap, reg, val);
 	if (ret) {
 		dev_err(&indio_dev->dev, "failed to set threshold\n");
 		goto out;
@@ -712,7 +712,7 @@ static int lm3533_als_set_input_mode(struct lm3533_als *als, bool pwm_mode)
 {
 	int ret;
 
-	ret = regmap_assign_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+	ret = regmap_assign_bits(als->regmap, LM3533_REG_ALS_CONF,
 				 LM3533_ALS_INPUT_MODE_MASK, pwm_mode);
 	if (ret) {
 		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
@@ -732,7 +732,7 @@ static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
 		return -EINVAL;
 	}
 
-	ret = regmap_write(als->lm3533->regmap, LM3533_REG_ALS_RESISTOR_SELECT,
+	ret = regmap_write(als->regmap, LM3533_REG_ALS_RESISTOR_SELECT,
 			   val);
 	if (ret) {
 		dev_err(&als->pdev->dev, "failed to set resistor\n");
@@ -766,7 +766,7 @@ static int lm3533_als_setup_irq(struct lm3533_als *als, void *dev)
 	int ret;
 
 	/* Make sure interrupts are disabled. */
-	ret = regmap_clear_bits(als->lm3533->regmap, LM3533_REG_ALS_ZONE_INFO,
+	ret = regmap_clear_bits(als->regmap, LM3533_REG_ALS_ZONE_INFO,
 				LM3533_ALS_INT_ENABLE_MASK);
 	if (ret) {
 		dev_err(&als->pdev->dev, "failed to disable interrupts\n");
@@ -789,7 +789,7 @@ static int lm3533_als_enable(struct lm3533_als *als)
 {
 	int ret;
 
-	ret = regmap_set_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+	ret = regmap_set_bits(als->regmap, LM3533_REG_ALS_CONF,
 			      LM3533_ALS_ENABLE_MASK);
 	if (ret)
 		dev_err(&als->pdev->dev, "failed to enable ALS\n");
@@ -801,7 +801,7 @@ static int lm3533_als_disable(struct lm3533_als *als)
 {
 	int ret;
 
-	ret = regmap_clear_bits(als->lm3533->regmap, LM3533_REG_ALS_CONF,
+	ret = regmap_clear_bits(als->regmap, LM3533_REG_ALS_CONF,
 				LM3533_ALS_ENABLE_MASK);
 	if (ret)
 		dev_err(&als->pdev->dev, "failed to disable ALS\n");
@@ -845,7 +845,7 @@ static int lm3533_als_probe(struct platform_device *pdev)
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	als = iio_priv(indio_dev);
-	als->lm3533 = lm3533;
+	als->regmap = lm3533->regmap;
 	als->pdev = pdev;
 	als->irq = lm3533->irq;
 	atomic_set(&als->zone, 0);
drivers/leds/leds-lm3533.c +18 -14
index 335c758071f3..0cb0585eb960 100644
@@ -42,13 +42,15 @@
 
 
 struct lm3533_led {
-	struct lm3533 *lm3533;
+	struct regmap *regmap;
 	struct lm3533_ctrlbank cb;
 	struct led_classdev cdev;
 	int id;
 
 	struct mutex mutex;
 	unsigned long flags;
+
+	bool have_als;
 };
 
 
@@ -96,7 +98,7 @@ static int lm3533_led_pattern_enable(struct lm3533_led *led, int enable)
 	pattern = lm3533_led_get_pattern(led);
 	mask = 1 << (2 * pattern);
 
-	ret = regmap_assign_bits(led->lm3533->regmap,
+	ret = regmap_assign_bits(led->regmap,
 				 LM3533_REG_PATTERN_ENABLE, mask, enable);
 	if (ret) {
 		dev_err(led->cdev.dev, "failed to enable pattern %d (%d)\n",
@@ -255,7 +257,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 = regmap_write(led->lm3533->regmap, reg, val);
+	ret = regmap_write(led->regmap, reg, val);
 	if (ret)
 		dev_err(led->cdev.dev, "failed to set delay (%02x)\n", reg);
 
@@ -336,7 +338,7 @@ static ssize_t show_risefalltime(struct device *dev,
 	u32 val;
 
 	reg = lm3533_led_get_pattern_reg(led, base);
-	ret = regmap_read(led->lm3533->regmap, reg, &val);
+	ret = regmap_read(led->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -371,7 +373,7 @@ static ssize_t store_risefalltime(struct device *dev,
 		return -EINVAL;
 
 	reg = lm3533_led_get_pattern_reg(led, base);
-	ret = regmap_write(led->lm3533->regmap, reg, val);
+	ret = regmap_write(led->regmap, reg, val);
 	if (ret)
 		return ret;
 
@@ -405,7 +407,7 @@ static ssize_t show_als_channel(struct device *dev,
 	int ret;
 
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
-	ret = regmap_read(led->lm3533->regmap, reg, &val);
+	ret = regmap_read(led->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -437,7 +439,7 @@ static ssize_t store_als_channel(struct device *dev,
 	mask = LM3533_REG_CTRLBANK_BCONF_ALS_CHANNEL_MASK;
 	val = channel - 1;
 
-	ret = regmap_update_bits(led->lm3533->regmap, reg, mask, val);
+	ret = regmap_update_bits(led->regmap, reg, mask, val);
 	if (ret)
 		return ret;
 
@@ -455,7 +457,7 @@ static ssize_t show_als_en(struct device *dev,
 	int ret;
 
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
-	ret = regmap_read(led->lm3533->regmap, reg, &val);
+	ret = regmap_read(led->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -479,7 +481,7 @@ static ssize_t store_als_en(struct device *dev,
 
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
 
-	ret = regmap_assign_bits(led->lm3533->regmap, reg,
+	ret = regmap_assign_bits(led->regmap, reg,
 				 LM3533_REG_CTRLBANK_BCONF_ALS_EN_MASK, enable);
 	if (ret)
 		return ret;
@@ -498,7 +500,7 @@ static ssize_t show_linear(struct device *dev,
 	int ret;
 
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
-	ret = regmap_read(led->lm3533->regmap, reg, &val);
+	ret = regmap_read(led->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -525,7 +527,7 @@ static ssize_t store_linear(struct device *dev,
 
 	reg = lm3533_led_get_lv_reg(led, LM3533_REG_CTRLBANK_BCONF_BASE);
 
-	ret = regmap_assign_bits(led->lm3533->regmap, reg,
+	ret = regmap_assign_bits(led->regmap, reg,
 				 LM3533_REG_CTRLBANK_BCONF_MAPPING_MASK, linear);
 	if (ret)
 		return ret;
@@ -597,7 +599,7 @@ static umode_t lm3533_led_attr_is_visible(struct kobject *kobj,
 
 	if (attr == &dev_attr_als_channel.attr ||
 					attr == &dev_attr_als_en.attr) {
-		if (!led->lm3533->have_als)
+		if (!led->have_als)
 			mode = 0;
 	}
 
@@ -654,7 +656,9 @@ static int lm3533_led_probe(struct platform_device *pdev)
 	if (!led)
 		return -ENOMEM;
 
-	led->lm3533 = lm3533;
+	led->regmap = lm3533->regmap;
+	led->have_als = lm3533->have_als;
+
 	led->cdev.name = pdata->name;
 	led->cdev.default_trigger = pdata->default_trigger;
 	led->cdev.brightness_set_blocking = lm3533_led_set;
@@ -670,7 +674,7 @@ static int lm3533_led_probe(struct platform_device *pdev)
 	 * registration so use parent device (for error reporting) until
 	 * registered.
 	 */
-	led->cb.lm3533 = lm3533;
+	led->cb.regmap = lm3533->regmap;
 	led->cb.id = lm3533_led_get_ctrlbank_id(led);
 	led->cb.dev = lm3533->dev;
 
drivers/mfd/lm3533-ctrlbank.c +7 -7
index c2b5fd38b81d..91e13cfa3cf0 100644
@@ -39,7 +39,7 @@ int lm3533_ctrlbank_enable(struct lm3533_ctrlbank *cb)
 	dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
 
 	mask = 1 << cb->id;
-	ret = regmap_set_bits(cb->lm3533->regmap, LM3533_REG_CTRLBANK_ENABLE,
+	ret = regmap_set_bits(cb->regmap, LM3533_REG_CTRLBANK_ENABLE,
 			      mask);
 	if (ret)
 		dev_err(cb->dev, "failed to enable ctrlbank %d\n", cb->id);
@@ -56,7 +56,7 @@ int lm3533_ctrlbank_disable(struct lm3533_ctrlbank *cb)
 	dev_dbg(cb->dev, "%s - %d\n", __func__, cb->id);
 
 	mask = 1 << cb->id;
-	ret = regmap_clear_bits(cb->lm3533->regmap, LM3533_REG_CTRLBANK_ENABLE,
+	ret = regmap_clear_bits(cb->regmap, LM3533_REG_CTRLBANK_ENABLE,
 				mask);
 	if (ret)
 		dev_err(cb->dev, "failed to disable ctrlbank %d\n", cb->id);
@@ -82,7 +82,7 @@ int lm3533_ctrlbank_set_max_current(struct lm3533_ctrlbank *cb, u32 imax)
 	val = (imax - LM3533_MAX_CURRENT_MIN) / LM3533_MAX_CURRENT_STEP;
 
 	reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_MAX_CURRENT_BASE);
-	ret = regmap_write(cb->lm3533->regmap, reg, val);
+	ret = regmap_write(cb->regmap, reg, val);
 	if (ret)
 		dev_err(cb->dev, "failed to set max current\n");
 
@@ -96,7 +96,7 @@ int lm3533_ctrlbank_set_brightness(struct lm3533_ctrlbank *cb, u32 val)
 	int ret;
 
 	reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_BRIGHTNESS_BASE);
-	ret = regmap_write(cb->lm3533->regmap, reg, val);
+	ret = regmap_write(cb->regmap, reg, val);
 	if (ret)
 		dev_err(cb->dev, "failed to set brightness\n");
 
@@ -110,7 +110,7 @@ int lm3533_ctrlbank_get_brightness(struct lm3533_ctrlbank *cb, u32 *val)
 	int ret;
 
 	reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_BRIGHTNESS_BASE);
-	ret = regmap_read(cb->lm3533->regmap, reg, val);
+	ret = regmap_read(cb->regmap, reg, val);
 	if (ret)
 		dev_err(cb->dev, "failed to get brightness\n");
 
@@ -137,7 +137,7 @@ int lm3533_ctrlbank_set_pwm(struct lm3533_ctrlbank *cb, u32 val)
 		return -EINVAL;
 
 	reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_PWM_BASE);
-	ret = regmap_write(cb->lm3533->regmap, reg, val);
+	ret = regmap_write(cb->regmap, reg, val);
 	if (ret)
 		dev_err(cb->dev, "failed to set PWM mask\n");
 
@@ -151,7 +151,7 @@ int lm3533_ctrlbank_get_pwm(struct lm3533_ctrlbank *cb, u32 *val)
 	int ret;
 
 	reg = lm3533_ctrlbank_get_reg(cb, LM3533_REG_PWM_BASE);
-	ret = regmap_read(cb->lm3533->regmap, reg, val);
+	ret = regmap_read(cb->regmap, reg, val);
 	if (ret)
 		dev_err(cb->dev, "failed to get PWM mask\n");
 
drivers/video/backlight/lm3533_bl.c +11 -8
index cd21c64b6485..4d6f68033480 100644
@@ -24,10 +24,12 @@
 
 
 struct lm3533_bl {
-	struct lm3533 *lm3533;
+	struct regmap *regmap;
 	struct lm3533_ctrlbank cb;
 	struct backlight_device *bd;
 	int id;
+
+	bool have_als;
 };
 
 
@@ -88,7 +90,7 @@ static ssize_t show_als_en(struct device *dev,
 	bool enable;
 	int ret;
 
-	ret = regmap_read(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
+	ret = regmap_read(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
 	if (ret)
 		return ret;
 
@@ -113,7 +115,7 @@ static ssize_t store_als_en(struct device *dev,
 
 	mask = 1 << (2 * ctrlbank);
 
-	ret = regmap_assign_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+	ret = regmap_assign_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
 				 mask, enable);
 	if (ret)
 		return ret;
@@ -130,7 +132,7 @@ static ssize_t show_linear(struct device *dev,
 	int linear;
 	int ret;
 
-	ret = regmap_read(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
+	ret = regmap_read(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
 	if (ret)
 		return ret;
 
@@ -158,7 +160,7 @@ static ssize_t store_linear(struct device *dev,
 
 	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
 
-	ret = regmap_assign_bits(bl->lm3533->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+	ret = regmap_assign_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
 				 mask, linear);
 	if (ret)
 		return ret;
@@ -223,7 +225,7 @@ static umode_t lm3533_bl_attr_is_visible(struct kobject *kobj,
 
 	if (attr == &dev_attr_als_channel.attr ||
 					attr == &dev_attr_als_en.attr) {
-		if (!bl->lm3533->have_als)
+		if (!bl->have_als)
 			mode = 0;
 	}
 
@@ -277,10 +279,11 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	if (!bl)
 		return -ENOMEM;
 
-	bl->lm3533 = lm3533;
+	bl->regmap = lm3533->regmap;
+	bl->have_als = lm3533->have_als;
 	bl->id = pdev->id;
 
-	bl->cb.lm3533 = lm3533;
+	bl->cb.regmap = lm3533->regmap;
 	bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
 	bl->cb.dev = NULL;			/* until registered */
 
include/linux/mfd/lm3533.h +1 -1
index c4c38876c09b..74cfb52c3bd1 100644
@@ -33,7 +33,7 @@ struct lm3533 {
 };
 
 struct lm3533_ctrlbank {
-	struct lm3533 *lm3533;
+	struct regmap *regmap;
 	struct device *dev;
 	int id;
 };
Signature · 1 line
2.53.0
#14 lore raw

Re: [PATCH v5 04/14] mfd: lm3533: Pass only regmap and light sensor presence to child devices

Quoted 2 lines · Svyatoslav Ryhel

Instead of passing the entire lm3533 core data structure, only pass the regmap and the light sensor presence flag to child devices.

Again, why?

Johan

#15 lore raw

Re: [PATCH v5 04/14] mfd: lm3533: Pass only regmap and light sensor presence to child devices

пт, 3 лип. 2026 р. о 12:50 Johan Hovold <[email protected]> пише:

Quoted 7 lines · Svyatoslav Ryhel
Quoted 2 lines

Instead of passing the entire lm3533 core data structure, only pass the regmap and the light sensor presence flag to child devices.

Again, why?

Because none of the child cells needs entire parents private structure, regmap is all that is used.

Quoted 1 line

Johan

#16 lore raw

Re: [PATCH v5 04/14] mfd: lm3533: Pass only regmap and light sensor presence to child devices

Quoted 11 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 12:50 Johan Hovold <[email protected]> пише:

Quoted 7 lines · Svyatoslav Ryhel
Quoted 2 lines

Instead of passing the entire lm3533 core data structure, only pass the regmap and the light sensor presence flag to child devices.

Again, why?

Because none of the child cells needs entire parents private structure, regmap is all that is used.

Just because you can do something doesn't necessarily mean you should.

Johan

#17 lore raw

PATCH v5 5/14 iio: light: lm3533-als: Remove redundant pdata helpers

In reply to Svyatoslav Ryhel

The 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 | 56 ++++++++++------------------------
 1 file changed, 16 insertions(+), 40 deletions(-)
drivers/iio/light/lm3533-als.c +16 -40
index a9af8e2b965f..69bac1b202f1 100644
@@ -708,55 +708,31 @@ 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)
+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 = regmap_assign_bits(als->regmap, LM3533_REG_ALS_CONF,
-				 LM3533_ALS_INPUT_MODE_MASK, pwm_mode);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-								pwm_mode);
-		return ret;
-	}
-
-	return 0;
-}
+				 LM3533_ALS_INPUT_MODE_MASK, pdata->pwm_mode);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+				     pdata->pwm_mode);
 
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-	int ret;
+	/* Bail out when in PWM-mode */
+	if (pdata->pwm_mode)
+		return 0;
 
-	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-		dev_err(&als->pdev->dev, "invalid resistor value\n");
-		return -EINVAL;
-	}
+	if (pdata->r_select < LM3533_ALS_RESISTOR_MIN ||
+	    pdata->r_select > LM3533_ALS_RESISTOR_MAX)
+		return dev_err_probe(dev, -EINVAL,
+				     "invalid resistor value\n");
 
 	ret = regmap_write(als->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)
-{
-	int ret;
-
-	ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+			   pdata->r_select);
 	if (ret)
-		return ret;
-
-	/* ALS input is always high impedance in PWM-mode. */
-	if (!pdata->pwm_mode) {
-		ret = lm3533_als_set_resistor(als, pdata->r_select);
-		if (ret)
-			return ret;
-	}
+		return dev_err_probe(dev, ret, "failed to set resistor\n");
 
 	return 0;
 }
Signature · 1 line
2.53.0
maintainer Reviewed-by on v5 5/14
#18 lore raw

Re: [PATCH v5 05/14] iio: light: lm3533-als: Remove redundant pdata helpers

Quoted 5 lines · On Wed, 17 Jun 2026 11:00:22 +0300 Svyatoslav Ryhel <[email protected]> wrote:

The 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.

LGTM

#19 lore raw

Re: [PATCH v5 05/14] iio: light: lm3533-als: Remove redundant pdata helpers

In reply to Svyatoslav Ryhel
Quoted 3 lines · Svyatoslav Ryhel

The 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.

That's a debatable claim.

Quoted 19 lines
---
 drivers/iio/light/lm3533-als.c | 56 ++++++++++------------------------
 1 file changed, 16 insertions(+), 40 deletions(-)
drivers/iio/light/lm3533-als.c +1 -7
index a9af8e2b965f..69bac1b202f1 100644
 
-static int lm3533_als_setup(struct lm3533_als *als,
-			    const struct lm3533_als_platform_data *pdata)
-{
-	int ret;
-
-	ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+			   pdata->r_select);
 	if (ret)
-		return ret;

drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 738

Quoted 10 lines
drivers/iio/light/lm3533-als.c +1 -7
-
-	/* ALS input is always high impedance in PWM-mode. */
-	if (!pdata->pwm_mode) {
-		ret = lm3533_als_set_resistor(als, pdata->r_select);
-		if (ret)
-			return ret;
-	}
+		return dev_err_probe(dev, ret, "failed to set resistor\n");
 	return 0;
 }

There's nothing hard to read about the above. To the contrary the logic is more obvious this way.

You also remove the high-impedance comment for no good reason.

Johan

#20 lore raw

Re: [PATCH v5 05/14] iio: light: lm3533-als: Remove redundant pdata helpers

пт, 3 лип. 2026 р. о 12:55 Johan Hovold <[email protected]> пише:

Quoted 8 lines · Svyatoslav Ryhel
Quoted 3 lines

The 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.

That's a debatable claim.

Adding helpers to wrap custom regmap wrappers seems redundant twice.

Quoted 33 lines
Quoted 19 lines
---
 drivers/iio/light/lm3533-als.c | 56 ++++++++++------------------------
 1 file changed, 16 insertions(+), 40 deletions(-)
drivers/iio/light/lm3533-als.c +1 -7
index a9af8e2b965f..69bac1b202f1 100644
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
-
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+                        pdata->r_select);
      if (ret)
-             return ret;

drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 738

Quoted 10 lines
drivers/iio/light/lm3533-als.c +1 -7
-
-     /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
-             if (ret)
-                     return ret;
-     }
+             return dev_err_probe(dev, ret, "failed to set resistor\n");
      return 0;
 }

There's nothing hard to read about the above. To the contrary the logic is more obvious this way.

Quoted 2 lines

You also remove the high-impedance comment for no good reason.

Removing one level of indentations without obscuring readability is always a good idea.

Quoted 1 line

Johan

#21 lore raw

Re: [PATCH v5 05/14] iio: light: lm3533-als: Remove redundant pdata helpers

Quoted 45 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 12:55 Johan Hovold <[email protected]> пише:

Quoted 8 lines · Svyatoslav Ryhel
Quoted 3 lines

The 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.

That's a debatable claim.

Adding helpers to wrap custom regmap wrappers seems redundant twice.

Quoted 33 lines
Quoted 19 lines
---
 drivers/iio/light/lm3533-als.c | 56 ++++++++++------------------------
 1 file changed, 16 insertions(+), 40 deletions(-)
drivers/iio/light/lm3533-als.c +1 -7
index a9af8e2b965f..69bac1b202f1 100644
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
-
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+                        pdata->r_select);
      if (ret)
-             return ret;

drivers/iio/light/lm3533-als.c static const struct attribute_group lm3533_als_attribute_group = { · line 738

Quoted 10 lines
drivers/iio/light/lm3533-als.c +1 -7
-
-     /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
-             if (ret)
-                     return ret;
-     }
+             return dev_err_probe(dev, ret, "failed to set resistor\n");
      return 0;
 }

There's nothing hard to read about the above. To the contrary the logic is more obvious this way.

Quoted 5 lines
Quoted 2 lines

You also remove the high-impedance comment for no good reason.

Removing one level of indentations without obscuring readability is always a good idea.

Again, no. You're obscuring the current logic which is perfectly fine as is.

Johan

#22 lore raw

PATCH v5 6/14 mfd: lm3533-core: Remove redundant pdata helpers

In reply to Svyatoslav Ryhel

The 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
index f9bdc0a1d9be..45e7f7481aa0 100644
@@ -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.53.0
#23 lore raw

Re: [PATCH v5 06/14] mfd: lm3533-core: Remove redundant pdata helpers

Quoted 4 lines · Svyatoslav Ryhel

The 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.

Again, this isn't needed. Why are you removing abstraction that improve readability?

Johan

#24 lore raw

Re: [PATCH v5 06/14] mfd: lm3533-core: Remove redundant pdata helpers

пт, 3 лип. 2026 р. о 12:57 Johan Hovold <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel
Quoted 4 lines

The 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.

Again, this isn't needed. Why are you removing abstraction that improve readability?

Adding helpers to wrap custom regmap wrappers seems redundant. Regmap operations are pretty self explanatory without need in one-time-use helpers.

Quoted 1 line

Johan

#25 lore raw

Re: [PATCH v5 06/14] mfd: lm3533-core: Remove redundant pdata helpers

Quoted 8 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 12:57 Johan Hovold <[email protected]> пише:

Quoted 7 lines · Svyatoslav Ryhel
Quoted 4 lines

The 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.

Quoted 7 lines
Quoted 3 lines

Again, this isn't needed. Why are you removing abstraction that improve readability?

Adding helpers to wrap custom regmap wrappers seems redundant. Regmap operations are pretty self explanatory without need in one-time-use helpers.

They are clearly not as easy to read so this obscures what is being done and makes lm3533_device_init() harder to read.

Johan

maintainer
#26 lore raw

Re: [PATCH v5 06/14] mfd: lm3533-core: Remove redundant pdata helpers

In reply to Svyatoslav Ryhel
Quoted 11 lines · On Wed, 17 Jun 2026 11:00:23 +0300 Svyatoslav Ryhel <[email protected]> wrote:

The 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.

static int lm3533_device_init(struct lm3533 *lm3533) {

drivers/mfd/lm3533-core.c +0 -0
 	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);

drivers/mfd/lm3533-core.c static int lm3533_device_init(struct lm3533 *lm3533) · line 401

Quoted 8 lines
drivers/mfd/lm3533-core.c +3 -2
@@ -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);

As you are touching this maybe get rid of the shifts and have one source of info on where the field lies in the register.

				 FIELD_PREP(LM3533_BOOST_FREQ_MASK, pdata->boost_freq));
Quoted 15 lines
drivers/mfd/lm3533-core.c +11 -0
+	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);
#27 lore raw

Re: [PATCH v5 06/14] mfd: lm3533-core: Remove redundant pdata helpers

ср, 22 лип. 2026 р. о 04:25 Jonathan Cameron <[email protected]> пише:

Quoted 27 lines
Quoted 11 lines · On Wed, 17 Jun 2026 11:00:23 +0300 Svyatoslav Ryhel <[email protected]> wrote:

The 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.

static int lm3533_device_init(struct lm3533 *lm3533)

 {
      struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);

drivers/mfd/lm3533-core.c static int lm3533_device_init(struct lm3533 *lm3533) · line 401

Quoted 8 lines
drivers/mfd/lm3533-core.c +3 -2
@@ -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);

As you are touching this maybe get rid of the shifts and have one source of info on where the field lies in the register.

Quoted 2 lines
                                 FIELD_PREP(LM3533_BOOST_FREQ_MASK, pdata->boost_freq));

Very decent suggestion, thanks!

Quoted 16 lines
Quoted 15 lines
drivers/mfd/lm3533-core.c +11 -0
+     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);
#28 lore raw

PATCH v5 7/14 mfd: lm3533: Use dev_groups in struct device_driver

In reply to Svyatoslav Ryhel

Instead of creating and removing the device sysfs attributes directly during probe and remove of the driver, respectively, use dev_groups in struct device_driver to point to the attribute definitions and let the core take care of creating and removing them.

No intentional functional impact.

---
 drivers/mfd/lm3533-core.c           | 16 ++++++----------
 drivers/video/backlight/lm3533_bl.c | 22 ++++++++--------------
 2 files changed, 14 insertions(+), 24 deletions(-)
drivers/mfd/lm3533-core.c +6 -10
index 45e7f7481aa0..b03a3ae96c10 100644
@@ -296,6 +296,11 @@ static struct attribute_group lm3533_attribute_group = {
 	.attrs		= lm3533_attributes
 };
 
+static const struct attribute_group *lm3533_attribute_groups[] = {
+	&lm3533_attribute_group,
+	NULL,
+};
+
 static int lm3533_device_als_init(struct lm3533 *lm3533)
 {
 	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
@@ -416,16 +421,8 @@ static int lm3533_device_init(struct lm3533 *lm3533)
 	lm3533_device_bl_init(lm3533);
 	lm3533_device_led_init(lm3533);
 
-	ret = sysfs_create_group(&lm3533->dev->kobj, &lm3533_attribute_group);
-	if (ret < 0) {
-		dev_err(lm3533->dev, "failed to create sysfs attributes\n");
-		goto err_unregister;
-	}
-
 	return 0;
 
-err_unregister:
-	mfd_remove_devices(lm3533->dev);
 err_disable:
 	lm3533_disable(lm3533);
 
@@ -436,8 +433,6 @@ static void lm3533_device_exit(struct lm3533 *lm3533)
 {
 	dev_dbg(lm3533->dev, "%s\n", __func__);
 
-	sysfs_remove_group(&lm3533->dev->kobj, &lm3533_attribute_group);
-
 	mfd_remove_devices(lm3533->dev);
 	lm3533_disable(lm3533);
 }
@@ -532,6 +527,7 @@ MODULE_DEVICE_TABLE(i2c, lm3533_i2c_ids);
 static struct i2c_driver lm3533_i2c_driver = {
 	.driver = {
 		   .name = "lm3533",
+		   .dev_groups = lm3533_attribute_groups,
 	},
 	.id_table	= lm3533_i2c_ids,
 	.probe		= lm3533_i2c_probe,
drivers/video/backlight/lm3533_bl.c +8 -14
index 4d6f68033480..9ef171d3aaea 100644
@@ -237,6 +237,11 @@ static struct attribute_group lm3533_bl_attribute_group = {
 	.attrs		= lm3533_bl_attributes
 };
 
+static const struct attribute_group *lm3533_bl_attribute_groups[] = {
+	&lm3533_bl_attribute_group,
+	NULL,
+};
+
 static int lm3533_bl_setup(struct lm3533_bl *bl,
 					struct lm3533_bl_platform_data *pdata)
 {
@@ -304,28 +309,17 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, bl);
 
-	ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to create sysfs attributes\n");
-		return ret;
-	}
-
 	backlight_update_status(bd);
 
 	ret = lm3533_bl_setup(bl, pdata);
 	if (ret)
-		goto err_sysfs_remove;
+		return ret;
 
 	ret = lm3533_ctrlbank_enable(&bl->cb);
 	if (ret)
-		goto err_sysfs_remove;
+		return ret;
 
 	return 0;
-
-err_sysfs_remove:
-	sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
-
-	return ret;
 }
 
 static void lm3533_bl_remove(struct platform_device *pdev)
@@ -339,7 +333,6 @@ static void lm3533_bl_remove(struct platform_device *pdev)
 	bd->props.brightness = 0;
 
 	lm3533_ctrlbank_disable(&bl->cb);
-	sysfs_remove_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -377,6 +370,7 @@ static struct platform_driver lm3533_bl_driver = {
 	.driver = {
 		.name	= "lm3533-backlight",
 		.pm	= &lm3533_bl_pm_ops,
+		.dev_groups = lm3533_bl_attribute_groups,
 	},
 	.probe		= lm3533_bl_probe,
 	.remove		= lm3533_bl_remove,
Signature · 1 line
2.53.0
#29 lore raw

Re: [PATCH v5 07/14] mfd: lm3533: Use dev_groups in struct device_driver

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unintentional user-space ABI breakage by moving custom sysfs attributes from the backlight class…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unintentional user-space ABI breakage by moving custom sysfs attributes from the backlight class device to the platform device. --

commit b4eaddced56809e9f87ffe143724f151f0e7013e
Author: Svyatoslav Ryhel <[email protected]>

mfd: lm3533: Use dev_groups in struct device_driver

Instead of creating and removing the device sysfs attributes directly during probe and remove of the driver, respectively, use dev_groups in struct device_driver to point to the attribute definitions and let the core take care of creating and removing them.

No intentional functional impact.

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index 4d6f680334802..9ef171d3aaeab 100644

[ ... ]

Quoted 11 lines
drivers/video/backlight/lm3533_bl.c +0 -6
@@ -304,28 +309,17 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, bl);
 
-	ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to create sysfs attributes\n");
-		return ret;
-	}
-
 	backlight_update_status(bd);

[ ... ]

drivers/video/backlight/lm3533_bl.c static struct platform_driver lm3533_bl_driver = { · line 373

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +1 -0
@@ -377,6 +370,7 @@ static struct platform_driver lm3533_bl_driver = {
 	.driver = {
 		.name	= "lm3533-backlight",
 		.pm	= &lm3533_bl_pm_ops,
+		.dev_groups = lm3533_bl_attribute_groups,

[Severity: High]
Does moving these attributes to the platform driver break the userspace ABI?

The old code explicitly created custom sysfs attributes on the backlight device's kobject (&bd->dev.kobj), placing them in the backlight class directory, for example under /sys/class/backlight/<name>/.

By attaching the attribute groups to the platform driver via .dev_groups, the driver core will now create these attributes on the parent platform device instead.

Since the commit message states there is no intentional functional impact, could this path change accidentally break userspace tools or udev rules that expect to find these custom attributes inside the backlight class directory?

Quoted 3 lines
drivers/video/backlight/lm3533_bl.c +0 -0
 	},
 	.probe		= lm3533_bl_probe,
 	.remove		= lm3533_bl_remove,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#30 lore raw

Re: [PATCH v5 07/14] mfd: lm3533: Use dev_groups in struct device_driver

In reply to Svyatoslav Ryhel
Quoted 6 lines · Svyatoslav Ryhel

Instead of creating and removing the device sysfs attributes directly during probe and remove of the driver, respectively, use dev_groups in struct device_driver to point to the attribute definitions and let the core take care of creating and removing them.

No intentional functional impact.

And thanks for doing that!

...

drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 302

Quoted 7 lines
drivers/mfd/lm3533-core.c +4 -0
 	.attrs		= lm3533_attributes
 };
 
+static const struct attribute_group *lm3533_attribute_groups[] = {
+	&lm3533_attribute_group,
+	NULL,
+};

We have ATTRIBUTE_GROUPS() macro.

...

Quoted 1 line

+++ b/drivers/video/backlight/lm3533_bl.c

Same as per above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#31 lore raw

Re: [PATCH v5 07/14] mfd: lm3533: Use dev_groups in struct device_driver

Quoted 1 line · Andy Shevchenko

On Wed, Jun 17, 2026 at 11:00:24AM +0300, Svyatoslav Ryhel wrote:

...

Quoted 9 lines

drivers/mfd/lm3533-core.c static struct attribute_group lm3533_attribute_group = { · line 302

Quoted 7 lines
drivers/mfd/lm3533-core.c +4 -0
 	.attrs		= lm3533_attributes
 };
 
+static const struct attribute_group *lm3533_attribute_groups[] = {
+	&lm3533_attribute_group,
+	NULL,
+};

We have ATTRIBUTE_GROUPS() macro.

Okay, it uses is_visible, so __ATTRIBUTE_GROUPS() that we can still use.

...

Quoted 3 lines
Quoted 1 line

+++ b/drivers/video/backlight/lm3533_bl.c

Same as per above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v5 7/14
#32 lore raw

Re: [PATCH v5 07/14] mfd: lm3533: Use dev_groups in struct device_driver

In reply to Svyatoslav Ryhel
Quoted 8 lines · Svyatoslav Ryhel

Instead of creating and removing the device sysfs attributes directly during probe and remove of the driver, respectively, use dev_groups in struct device_driver to point to the attribute definitions and let the core take care of creating and removing them.

No intentional functional impact.

#33 lore raw

PATCH v5 8/14 mfd: lm3533: Convert to use OF bindings

In reply to 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      |  67 +++++---
 drivers/leds/leds-lm3533.c          |  50 ++++--
 drivers/mfd/lm3533-core.c           | 236 ++++++++++++----------------
 drivers/mfd/lm3533-ctrlbank.c       |   5 -
 drivers/video/backlight/lm3533_bl.c |  55 +++++--
 include/linux/mfd/lm3533.h          |  52 +-----
 6 files changed, 220 insertions(+), 245 deletions(-)
drivers/iio/light/lm3533-als.c +42 -25
index 69bac1b202f1..80f8fa700263 100644
@@ -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_OHMS		1575
+#define LM3533_ALS_RESISTOR_MAX_OHMS		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;
+
+	u32 r_select;
+	bool pwm_mode;
 };
 
 
@@ -403,7 +409,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;
@@ -425,7 +431,7 @@ static ssize_t store_thresh_either_en(struct device *dev,
 	u8 zone;
 	int ret;
 
-	if (!als->irq)
+	if (als->irq <= 0)
 		return -EBUSY;
 
 	if (kstrtoul(buf, 0, &enable))
@@ -708,29 +714,38 @@ 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_assign_bits(als->regmap, LM3533_REG_ALS_CONF,
-				 LM3533_ALS_INPUT_MODE_MASK, pdata->pwm_mode);
+				 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);
 	if (ret)
 		return dev_err_probe(dev, ret, "failed to set input mode %d\n",
-				     pdata->pwm_mode);
+				     als->pwm_mode);
 
 	/* Bail out when in PWM-mode */
-	if (pdata->pwm_mode)
+	if (als->pwm_mode)
 		return 0;
 
-	if (pdata->r_select < LM3533_ALS_RESISTOR_MIN ||
-	    pdata->r_select > LM3533_ALS_RESISTOR_MAX)
+	ret = device_property_read_u32(dev, "ti,resistor-ohms",
+				       &als->r_select);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to ger resistor value\n");
+
+	if (als->r_select < LM3533_ALS_RESISTOR_MIN_OHMS ||
+	    als->r_select > LM3533_ALS_RESISTOR_MAX_OHMS)
 		return dev_err_probe(dev, -EINVAL,
 				     "invalid resistor value\n");
 
+	als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);
+
 	ret = regmap_write(als->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");
 
@@ -793,7 +808,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;
@@ -803,12 +817,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;
@@ -817,25 +825,27 @@ 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->regmap = lm3533->regmap;
 	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;
 
@@ -854,7 +864,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;
@@ -868,13 +878,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 +34 -16

120 lines not on this page · raw message

drivers/mfd/lm3533-core.c +99 -137

312 lines not on this page · raw message

drivers/mfd/lm3533-ctrlbank.c +0 -5
index 91e13cfa3cf0..3aab8ece4e8c 100644
@@ -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 +38 -17

124 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.53.0
#34 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `default-brightness` property is read from the Device Tree as a `u32` without being clamped…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The default-brightness property is read from the Device Tree as a u32 without being clamped to LM3533_BL_MAX_BRIGHTNESS (255). --

commit ea75baf449ff637e79d3393f0fdd68b3fcf947de
Author: Svyatoslav Ryhel <[email protected]>

mfd: lm3533: Convert to use OF bindings

This commit removes platform data support and transitions the driver to use Device Tree bindings for its configuration.

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index 9ef171d3aaeab..2c24647fc17a4 100644

[ ... ]

Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +3 -0
@@ -292,13 +291,21 @@ 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)

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 305

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +6 -1
+		return -ENOMEM;
+
+	device_property_read_u32(&pdev->dev, "default-brightness",
+				 &default_brightness);
+
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
-	props.brightness = pdata->default_brightness;
+	props.brightness = default_brightness;

[Severity: Medium]
Should default_brightness be clamped to LM3533_BL_MAX_BRIGHTNESS before being assigned to props.brightness?

The transition to Device Tree bindings introduces reading default-brightness as a u32. In the previous platform data implementation, default_brightness was a u8, which inherently restricted it to a 0-255 range.

If a Device Tree provides a value greater than 255, it will be implicitly truncated to an 8-bit unsigned integer when passed to the hardware writing functions (for instance, 256 would wrap around to 0). This would cause the backlight to turn off instead of setting it to the expected maximum brightness.

Does it make sense to clamp default_brightness similar to how led-max-microamp is clamped later in this function?

Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +3 -3
-	bd = devm_backlight_device_register(&pdev->dev, pdata->name,
-					pdev->dev.parent, bl, &lm3533_bl_ops,
-					&props);
+
+	bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev,
+					    bl, &lm3533_bl_ops, &props);

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#35 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

In reply to Svyatoslav Ryhel
Quoted 34 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      |  67 +++++---
 drivers/leds/leds-lm3533.c          |  50 ++++--
 drivers/mfd/lm3533-core.c           | 236 ++++++++++++----------------
 drivers/mfd/lm3533-ctrlbank.c       |   5 -
 drivers/video/backlight/lm3533_bl.c |  55 +++++--
 include/linux/mfd/lm3533.h          |  52 +-----
 6 files changed, 220 insertions(+), 245 deletions(-)

static int lm3533_als_probe(struct platform_device *pdev) {

drivers/iio/light/lm3533-als.c +0 -7
-	const struct lm3533_als_platform_data *pdata;
 	struct lm3533 *lm3533;
 	struct lm3533_als *als;
 	struct iio_dev *indio_dev;
@@ -803,12 +817,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;

drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 820

Quoted 4 lines
drivers/iio/light/lm3533-als.c +0 -1
@@ -817,25 +825,27 @@ 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);

Why are you reparenting the iio device here?

That's an ABI break.

drivers/iio/light/lm3533-als.c static void lm3533_als_remove(struct platform_device *pdev) · line 897

Quoted 13 lines
drivers/iio/light/lm3533-als.c +7 -0
+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,

You should also remove the platform module alias below.

Quoted 74 lines
drivers/leds/leds-lm3533.c +8 -13
index 0cb0585eb960..ed810c23f30f 100644
@@ -10,8 +10,10 @@
 #include <linux/module.h>
 #include <linux/leds.h>
 #include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
@@ -50,6 +52,9 @@ struct lm3533_led {
 	struct mutex mutex;
 	unsigned long flags;
 
+	u32 max_current;
+	u32 pwm;
+
 	bool have_als;
 };
 
@@ -616,22 +621,20 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
 	NULL
 };
 
-static int lm3533_led_setup(struct lm3533_led *led,
-					struct lm3533_led_platform_data *pdata)
+static int lm3533_led_setup(struct lm3533_led *led)
 {
 	int ret;
 
-	ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current);
+	ret = lm3533_ctrlbank_set_max_current(&led->cb, led->max_current);
 	if (ret)
 		return ret;
 
-	return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm);
+	return lm3533_ctrlbank_set_pwm(&led->cb, led->pwm);
 }
 
 static int lm3533_led_probe(struct platform_device *pdev)
 {
 	struct lm3533 *lm3533;
-	struct lm3533_led_platform_data *pdata;
 	struct lm3533_led *led;
 	int ret;
 
@@ -641,12 +644,6 @@ static int lm3533_led_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;
-	}
-
 	if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) {
 		dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id);
 		return -EINVAL;
@@ -659,8 +656,6 @@ static int lm3533_led_probe(struct platform_device *pdev)
 	led->regmap = lm3533->regmap;
 	led->have_als = lm3533->have_als;
 
-	led->cdev.name = pdata->name;
-	led->cdev.default_trigger = pdata->default_trigger;
 	led->cdev.brightness_set_blocking = lm3533_led_set;
 	led->cdev.brightness_get = lm3533_led_get;
 	led->cdev.blink_set = lm3533_led_blink_set;

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 667

Quoted 5 lines
drivers/leds/leds-lm3533.c +2 -0
@@ -668,6 +663,15 @@ static int lm3533_led_probe(struct platform_device *pdev)
 	led->cdev.groups = lm3533_led_attribute_groups;
 	led->id = pdev->id;
 
+	led->cdev.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+					pdev->name, led->id);

Is "led-2", etc. unique enough here?

Quoted 11 lines
drivers/leds/leds-lm3533.c +7 -0
+	if (!led->cdev.name)
+		return -ENOMEM;
+
+	led->cdev.default_trigger = "none";
+	device_property_read_string(&pdev->dev, "linux,default-trigger",
+				    &led->cdev.default_trigger);
+
 	mutex_init(&led->mutex);
 
 	/* The class framework makes a callback to get brightness during

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 687

Quoted 5 lines
drivers/leds/leds-lm3533.c +1 -1
@@ -680,15 +684,22 @@ static int lm3533_led_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, led);
 
-	ret = led_classdev_register(pdev->dev.parent, &led->cdev);
+	ret = led_classdev_register(&pdev->dev, &led->cdev);

Here too you appear to be reparenting the class devices.

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 689

Quoted 3 lines
drivers/leds/leds-lm3533.c +1 -1
 	if (ret) {
-		dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id);
+		dev_err(&pdev->dev, "failed to register LED %d\n", led->id);

This does not seem to be necessary.

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 698

Quoted 10 lines
drivers/leds/leds-lm3533.c +4 -1
 		return ret;
 	}
 
 	led->cb.dev = led->cdev.dev;
 
-	ret = lm3533_led_setup(led, pdata);
+	device_property_read_u32(&pdev->dev, "led-max-microamp",
+				 &led->max_current);
+	led->max_current = clamp(led->max_current, LM3533_MAX_CURRENT_MIN,
+				 LM3533_MAX_CURRENT_MAX);

Why clamp instead of having lm3533_led_setup() fail below?

Quoted 14 lines
drivers/leds/leds-lm3533.c +7 -0
+
+	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);
+
+	ret = lm3533_led_setup(led);
 	if (ret)
 		goto err_deregister;
 
@@ -725,9 +736,16 @@ static void lm3533_led_shutdown(struct platform_device *pdev)
 	lm3533_led_set(&led->cdev, LED_OFF);		/* disable blink */
 }
 
+static const struct of_device_id lm3533_led_match_table[] = {
+	{ .compatible = "ti,lm3533-leds" },
+	{ }

drivers/leds/leds-lm3533.c static void lm3533_led_shutdown(struct platform_device *pdev) · line 751

Quoted 10 lines
drivers/leds/leds-lm3533.c +4 -0
+};
+MODULE_DEVICE_TABLE(of, lm3533_led_match_table);
+
 static struct platform_driver lm3533_led_driver = {
 	.driver = {
 		.name = "lm3533-leds",
+		.of_match_table = lm3533_led_match_table,
 	},
 	.probe		= lm3533_led_probe,
 	.remove		= lm3533_led_remove,

Remove platform alias below as well.

Quoted 165 lines
drivers/mfd/lm3533-core.c +8 -115
index b03a3ae96c10..a5aa7da9668b 100644
@@ -14,19 +14,26 @@
 #include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/units.h>
 
 #include <linux/mfd/lm3533.h>
 
 
 #define LM3533_BOOST_OVP_MASK		0x06
 #define LM3533_BOOST_OVP_SHIFT		1
+#define LM3533_BOOST_OVP_MIN		(16 * MICRO)
+#define LM3533_BOOST_OVP_MAX		(40 * MICRO)
 
 #define LM3533_BOOST_FREQ_MASK		0x01
 #define LM3533_BOOST_FREQ_SHIFT		0
+#define LM3533_BOOST_FREQ_MIN		(500 * HZ_PER_KHZ)
+#define LM3533_BOOST_FREQ_MAX		(1000 * HZ_PER_KHZ)
 
 #define LM3533_BL_ID_MASK		1
 #define LM3533_LED_ID_MASK		3
@@ -35,6 +42,7 @@
 
 #define LM3533_HVLED_ID_MAX		2
 #define LM3533_LVLED_ID_MAX		5
+#define LM3533_CELLS_MAX		7
 
 #define LM3533_REG_OUTPUT_CONF1		0x10
 #define LM3533_REG_OUTPUT_CONF2		0x11
@@ -42,44 +50,6 @@
 
 #define LM3533_REG_MAX			0xb2
 
-
-static struct mfd_cell lm3533_als_devs[] = {
-	{
-		.name	= "lm3533-als",
-		.id	= -1,
-	},
-};
-
-static struct mfd_cell lm3533_bl_devs[] = {
-	{
-		.name	= "lm3533-backlight",
-		.id	= 0,
-	},
-	{
-		.name	= "lm3533-backlight",
-		.id	= 1,
-	},
-};
-
-static struct mfd_cell lm3533_led_devs[] = {
-	{
-		.name	= "lm3533-leds",
-		.id	= 0,
-	},
-	{
-		.name	= "lm3533-leds",
-		.id	= 1,
-	},
-	{
-		.name	= "lm3533-leds",
-		.id	= 2,
-	},
-	{
-		.name	= "lm3533-leds",
-		.id	= 3,
-	},
-};
-
 /*
  * HVLED output config -- output hvled controlled by backlight bl
  */
@@ -301,125 +271,91 @@ static const struct attribute_group *lm3533_attribute_groups[] = {
 	NULL,
 };
 
-static int lm3533_device_als_init(struct lm3533 *lm3533)
-{
-	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-	int ret;
-
-	if (!pdata->als)
-		return 0;
-
-	lm3533_als_devs[0].platform_data = pdata->als;
-	lm3533_als_devs[0].pdata_size = sizeof(*pdata->als);
-
-	ret = mfd_add_devices(lm3533->dev, 0, lm3533_als_devs, 1, NULL,
-			      0, NULL);
-	if (ret) {
-		dev_err(lm3533->dev, "failed to add ALS device\n");
-		return ret;
-	}
-
-	lm3533->have_als = 1;
-
-	return 0;
-}
-
-static int lm3533_device_bl_init(struct lm3533 *lm3533)
-{
-	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-	int i;
-	int ret;
-
-	if (!pdata->backlights || pdata->num_backlights == 0)
-		return 0;
-
-	if (pdata->num_backlights > ARRAY_SIZE(lm3533_bl_devs))
-		pdata->num_backlights = ARRAY_SIZE(lm3533_bl_devs);
-
-	for (i = 0; i < pdata->num_backlights; ++i) {
-		lm3533_bl_devs[i].platform_data = &pdata->backlights[i];
-		lm3533_bl_devs[i].pdata_size = sizeof(pdata->backlights[i]);
-	}
-
-	ret = mfd_add_devices(lm3533->dev, 0, lm3533_bl_devs,
-			      pdata->num_backlights, NULL, 0, NULL);
-	if (ret) {
-		dev_err(lm3533->dev, "failed to add backlight devices\n");
-		return ret;
-	}
-
-	lm3533->have_backlights = 1;
-
-	return 0;
-}
-
-static int lm3533_device_led_init(struct lm3533 *lm3533)
-{
-	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-	int i;
-	int ret;
-
-	if (!pdata->leds || pdata->num_leds == 0)
-		return 0;
-
-	if (pdata->num_leds > ARRAY_SIZE(lm3533_led_devs))
-		pdata->num_leds = ARRAY_SIZE(lm3533_led_devs);
-
-	for (i = 0; i < pdata->num_leds; ++i) {
-		lm3533_led_devs[i].platform_data = &pdata->leds[i];
-		lm3533_led_devs[i].pdata_size = sizeof(pdata->leds[i]);
-	}
-
-	ret = mfd_add_devices(lm3533->dev, 0, lm3533_led_devs,
-			      pdata->num_leds, NULL, 0, NULL);
-	if (ret) {
-		dev_err(lm3533->dev, "failed to add LED devices\n");
-		return ret;
-	}
-
-	lm3533->have_leds = 1;

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 278

Quoted 10 lines
drivers/mfd/lm3533-core.c +3 -5
-
-	return 0;
-}
-
 static int lm3533_device_init(struct lm3533 *lm3533)
 {
-	struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
+	struct device *dev = lm3533->dev;
+	struct mfd_cell *lm3533_devices;
+	u32 count = 0, reg, nchilds;

Don't mix multiple declarations with initialisation like this.

Quoted 14 lines
drivers/mfd/lm3533-core.c +6 -5
 	int ret;
 
-	dev_dbg(lm3533->dev, "%s\n", __func__);
+	nchilds = device_get_child_node_count(dev);
+	if (!nchilds || nchilds > LM3533_CELLS_MAX)
+		return dev_err_probe(dev, -ENODEV,
+				     "num of child nodes is not supported\n");
 
-	if (!pdata) {
-		dev_err(lm3533->dev, "no platform data\n");
-		return -EINVAL;
-	}
+	lm3533_devices = devm_kcalloc(dev, nchilds, sizeof(*lm3533_devices),
+				      GFP_KERNEL);

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 293

Quoted 10 lines
drivers/mfd/lm3533-core.c +5 -4
+	if (!lm3533_devices)
+		return -ENOMEM;
 
-	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");
+	device_for_each_child_node_scoped(dev, child) {
+		if (count >= nchilds)
+			break;

How could count be larger than nchilds?

Quoted 31 lines
drivers/mfd/lm3533-core.c +31 -0
+
+		if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
+			lm3533_devices[count].name = "lm3533-als";
+			lm3533_devices[count].of_compatible = "ti,lm3533-als";
+			lm3533_devices[count].id = PLATFORM_DEVID_NONE;
+
+			lm3533->have_als = true;
+			count++;
+		} else if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
+			ret = fwnode_property_read_u32(child, "reg", &reg);
+			if (ret || reg >= LM3533_HVLED_ID_MAX) {
+				dev_err(dev, "invalid backlight node %pfw\n", child);
+				continue;
+			}
+
+			lm3533_devices[count].name = "lm3533-backlight";
+			lm3533_devices[count].of_compatible = "ti,lm3533-backlight";
+			lm3533_devices[count].id = reg;
+			lm3533_devices[count].of_reg = reg;
+			lm3533_devices[count].use_of_reg = true;
+
+			lm3533->have_backlights = true;
+			count++;
+		} else if (fwnode_device_is_compatible(child, "ti,lm3533-leds")) {
+			ret = fwnode_property_read_u32(child, "reg", &reg);
+			if (ret || reg < LM3533_HVLED_ID_MAX ||
+			    reg > LM3533_LVLED_ID_MAX) {
+				dev_err(dev, "invalid LED node %pfw\n", child);
+				continue;
+			}
+

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 334

Quoted 10 lines
drivers/mfd/lm3533-core.c +10 -0
+			lm3533_devices[count].name = "lm3533-leds";
+			lm3533_devices[count].of_compatible = "ti,lm3533-leds";
+			lm3533_devices[count].id = reg - LM3533_HVLED_ID_MAX;
+			lm3533_devices[count].of_reg = reg;
+			lm3533_devices[count].use_of_reg = true;
+
+			lm3533->have_leds = true;
+			count++;
+		}
+	}

Why do you need the above at all? Shouldn't you be able to just use of_platform_populate().

Quoted 35 lines
drivers/mfd/lm3533-core.c +9 -7
 	lm3533_enable(lm3533);
 
 	ret = regmap_update_bits(lm3533->regmap, LM3533_REG_BOOST_PWM,
 				 LM3533_BOOST_FREQ_MASK,
-				 pdata->boost_freq << LM3533_BOOST_FREQ_SHIFT);
+				 lm3533->boost_freq << LM3533_BOOST_FREQ_SHIFT);
 	if (ret) {
-		dev_err(lm3533->dev, "failed to set boost frequency\n");
+		dev_err(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);
+				 lm3533->boost_ovp << LM3533_BOOST_OVP_SHIFT);
 	if (ret) {
-		dev_err(lm3533->dev, "failed to set boost ovp\n");
+		dev_err(dev, "failed to set boost ovp\n");
 		goto err_disable;
 	}
 
-	lm3533_device_als_init(lm3533);
-	lm3533_device_bl_init(lm3533);
-	lm3533_device_led_init(lm3533);
+	ret = mfd_add_devices(dev, 0, lm3533_devices, count, NULL, 0, NULL);
+	if (ret) {
+		dev_err(dev, "failed to add MFD devices: %d\n", ret);
+		goto err_disable;
+	}
 
 	return 0;
 

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 448

Quoted 10 lines
drivers/mfd/lm3533-core.c +6 -1
@@ -504,7 +440,26 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
 		return PTR_ERR(lm3533->regmap);
 
 	lm3533->dev = &i2c->dev;
-	lm3533->irq = i2c->irq;
+
+	lm3533->hwen = devm_gpiod_get_optional(lm3533->dev, "enable",
+					       GPIOD_OUT_LOW);
+	if (IS_ERR(lm3533->hwen))
+		return dev_err_probe(lm3533->dev, PTR_ERR(lm3533->hwen),
+				     "failed to get HWEN GPIO\n");

Please use brackets around multline statements for readability throughout.

Quoted 4 lines
drivers/mfd/lm3533-core.c +4 -0
+
+	device_property_read_u32(lm3533->dev, "ti,boost-ovp-microvolt",
+				 &lm3533->boost_ovp);
+

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 462

Quoted 10 lines
drivers/mfd/lm3533-core.c +10 -0
+	lm3533->boost_ovp = clamp(lm3533->boost_ovp, LM3533_BOOST_OVP_MIN,
+				  LM3533_BOOST_OVP_MAX);
+	lm3533->boost_ovp = lm3533->boost_ovp / (8 * MICRO) - 2;
+
+	device_property_read_u32(lm3533->dev, "ti,boost-freq-hz",
+				 &lm3533->boost_freq);
+
+	lm3533->boost_freq = clamp(lm3533->boost_freq, LM3533_BOOST_FREQ_MIN,
+				   LM3533_BOOST_FREQ_MAX);
+	lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;

Again, why clamp instead of failing probe?

Quoted 108 lines
drivers/mfd/lm3533-core.c +7 -0
 	return lm3533_device_init(lm3533);
 }
@@ -518,6 +473,12 @@ static void lm3533_i2c_remove(struct i2c_client *i2c)
 	lm3533_device_exit(lm3533);
 }
 
+static const struct of_device_id lm3533_match_table[] = {
+	{ .compatible = "ti,lm3533" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lm3533_match_table);
+
 static const struct i2c_device_id lm3533_i2c_ids[] = {
 	{ "lm3533" },
 	{ }
@@ -528,6 +489,7 @@ static struct i2c_driver lm3533_i2c_driver = {
 	.driver = {
 		   .name = "lm3533",
 		   .dev_groups = lm3533_attribute_groups,
+		   .of_match_table = lm3533_match_table,
 	},
 	.id_table	= lm3533_i2c_ids,
 	.probe		= lm3533_i2c_probe,
drivers/mfd/lm3533-ctrlbank.c +0 -5
index 91e13cfa3cf0..3aab8ece4e8c 100644
@@ -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 +10 -11
index 9ef171d3aaea..2c24647fc17a 100644
@@ -9,7 +9,9 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/backlight.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -29,6 +31,9 @@ struct lm3533_bl {
 	struct backlight_device *bd;
 	int id;
 
+	u32 max_current;
+	u32 pwm;
+
 	bool have_als;
 };
 
@@ -242,25 +247,25 @@ static const struct attribute_group *lm3533_bl_attribute_groups[] = {
 	NULL,
 };
 
-static int lm3533_bl_setup(struct lm3533_bl *bl,
-					struct lm3533_bl_platform_data *pdata)
+static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
 	int ret;
 
-	ret = lm3533_ctrlbank_set_max_current(&bl->cb, pdata->max_current);
+	ret = lm3533_ctrlbank_set_max_current(&bl->cb, bl->max_current);
 	if (ret)
 		return ret;
 
-	return lm3533_ctrlbank_set_pwm(&bl->cb, pdata->pwm);
+	return lm3533_ctrlbank_set_pwm(&bl->cb, bl->pwm);
 }
 
 static int lm3533_bl_probe(struct platform_device *pdev)
 {
 	struct lm3533 *lm3533;
-	struct lm3533_bl_platform_data *pdata;
 	struct lm3533_bl *bl;
 	struct backlight_device *bd;
 	struct backlight_properties props;
+	char *name = NULL;
+	u32 default_brightness = LM3533_BL_MAX_BRIGHTNESS;
 	int ret;
 
 	dev_dbg(&pdev->dev, "%s\n", __func__);
@@ -269,12 +274,6 @@ static int lm3533_bl_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;
-	}
-
 	if (pdev->id < 0 || pdev->id >= LM3533_HVCTRLBANK_COUNT) {
 		dev_err(&pdev->dev, "illegal backlight id %d\n", pdev->id);
 		return -EINVAL;

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 295

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +2 -0
@@ -292,13 +291,21 @@ 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);

Unique enough (e.g. backlight-0)?

Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +6 -0
+	if (!name)
+		return -ENOMEM;
+
+	device_property_read_u32(&pdev->dev, "default-brightness",
+				 &default_brightness);
+
 	memset(&props, 0, sizeof(props));

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 308

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +4 -4
 	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 = default_brightness;
+
+	bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev,
+					    bl, &lm3533_bl_ops, &props);

Here too you are reparenting, which results in an ABI break.

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 322

Quoted 12 lines
drivers/video/backlight/lm3533_bl.c +4 -1
 	if (IS_ERR(bd)) {
 		dev_err(&pdev->dev, "failed to register backlight device\n");
 		return PTR_ERR(bd);
@@ -309,12 +316,19 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, bl);
 
-	backlight_update_status(bd);
+	device_property_read_u32(&pdev->dev, "led-max-microamp",
+				 &bl->max_current);
+	bl->max_current = clamp(bl->max_current, LM3533_MAX_CURRENT_MIN,
+				LM3533_MAX_CURRENT_MAX);

Clamping instead of failing.

Quoted 22 lines
drivers/video/backlight/lm3533_bl.c +10 -1
-	ret = lm3533_bl_setup(bl, pdata);
+	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &bl->pwm);
+
+	ret = lm3533_bl_setup(bl);
 	if (ret)
 		return ret;
 
+	backlight_update_status(bd);
+
 	ret = lm3533_ctrlbank_enable(&bl->cb);
 	if (ret)
 		return ret;
@@ -366,11 +380,18 @@ static void lm3533_bl_shutdown(struct platform_device *pdev)
 	lm3533_ctrlbank_disable(&bl->cb);
 }
 
+static const struct of_device_id lm3533_bl_match_table[] = {
+	{ .compatible = "ti,lm3533-backlight" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lm3533_bl_match_table);

drivers/video/backlight/lm3533_bl.c static void lm3533_bl_shutdown(struct platform_device *pdev) · line 397

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +2 -0
+
 static struct platform_driver lm3533_bl_driver = {
 	.driver = {
 		.name	= "lm3533-backlight",
 		.pm	= &lm3533_bl_pm_ops,
 		.dev_groups = lm3533_bl_attribute_groups,
+		.of_match_table = lm3533_bl_match_table,
 	},
 	.probe		= lm3533_bl_probe,
 	.remove		= lm3533_bl_remove,

Drop platform module alias below.

Johan

#36 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

пт, 3 лип. 2026 р. о 14:03 Johan Hovold <[email protected]> пише:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 24 lines

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      |  67 +++++---
 drivers/leds/leds-lm3533.c          |  50 ++++--
 drivers/mfd/lm3533-core.c           | 236 ++++++++++++----------------
 drivers/mfd/lm3533-ctrlbank.c       |   5 -
 drivers/video/backlight/lm3533_bl.c |  55 +++++--
 include/linux/mfd/lm3533.h          |  52 +-----
 6 files changed, 220 insertions(+), 245 deletions(-)

static int lm3533_als_probe(struct platform_device *pdev) {

drivers/iio/light/lm3533-als.c +0 -1
-     const struct lm3533_als_platform_data *pdata;
      struct lm3533 *lm3533;
      struct lm3533_als *als;
      struct iio_dev *indio_dev;
@@ -803,12 +817,6 @@ static int lm3533_als_probe(struct platform_device *pdev)
      if (!lm3533)
              return -EINVAL;
 
Quoted 17 lines
Quoted 10 lines
drivers/iio/light/lm3533-als.c +0 -6
-     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;

drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 820

Quoted 4 lines
drivers/iio/light/lm3533-als.c +0 -1
@@ -817,25 +825,27 @@ 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);

Why are you reparenting the iio device here?

Because every cell has its own binding now and using phandle to parent when device has its own node is not a good practice.

Quoted 2 lines

That's an ABI break.

This driver does not have any active users in the kernel and no activity for more then 2 years.

Quoted 7 lines
Quoted 7 lines
drivers/iio/light/lm3533-als.c +6 -0
+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 = {
Quoted 9 lines

drivers/iio/light/lm3533-als.c static void lm3533_als_remove(struct platform_device *pdev) · line 897

Quoted 6 lines
drivers/iio/light/lm3533-als.c +1 -0
      .driver = {
              .name   = "lm3533-als",
+             .of_match_table = lm3533_als_match_table,
      },
      .probe          = lm3533_als_probe,
      .remove         = lm3533_als_remove,

You should also remove the platform module alias below.

Why?

Quoted 77 lines
Quoted 77 lines
drivers/leds/leds-lm3533.c +8 -13
index 0cb0585eb960..ed810c23f30f 100644
@@ -10,8 +10,10 @@
 #include <linux/module.h>
 #include <linux/leds.h>
 #include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
@@ -50,6 +52,9 @@ struct lm3533_led {
      struct mutex mutex;
      unsigned long flags;
 
+     u32 max_current;
+     u32 pwm;
+
      bool have_als;
 };
 
@@ -616,22 +621,20 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
      NULL
 };
 
-static int lm3533_led_setup(struct lm3533_led *led,
-                                     struct lm3533_led_platform_data *pdata)
+static int lm3533_led_setup(struct lm3533_led *led)
 {
      int ret;
 
-     ret = lm3533_ctrlbank_set_max_current(&led->cb, pdata->max_current);
+     ret = lm3533_ctrlbank_set_max_current(&led->cb, led->max_current);
      if (ret)
              return ret;
 
-     return lm3533_ctrlbank_set_pwm(&led->cb, pdata->pwm);
+     return lm3533_ctrlbank_set_pwm(&led->cb, led->pwm);
 }
 
 static int lm3533_led_probe(struct platform_device *pdev)
 {
      struct lm3533 *lm3533;
-     struct lm3533_led_platform_data *pdata;
      struct lm3533_led *led;
      int ret;
 
@@ -641,12 +644,6 @@ static int lm3533_led_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;
-     }
-
      if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) {
              dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id);
              return -EINVAL;
@@ -659,8 +656,6 @@ static int lm3533_led_probe(struct platform_device *pdev)
      led->regmap = lm3533->regmap;
      led->have_als = lm3533->have_als;
 
-     led->cdev.name = pdata->name;
-     led->cdev.default_trigger = pdata->default_trigger;
      led->cdev.brightness_set_blocking = lm3533_led_set;
      led->cdev.brightness_get = lm3533_led_get;
      led->cdev.blink_set = lm3533_led_blink_set;
@@ -668,6 +663,15 @@ static int lm3533_led_probe(struct platform_device *pdev)
      led->cdev.groups = lm3533_led_attribute_groups;
      led->id = pdev->id;
 
Quoted 5 lines

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 667

Quoted 2 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->cdev.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+                                     pdev->name, led->id);

Is "led-2", etc. unique enough here?

lm3533-leds-2

Quoted 19 lines
Quoted 11 lines
drivers/leds/leds-lm3533.c +7 -0
+     if (!led->cdev.name)
+             return -ENOMEM;
+
+     led->cdev.default_trigger = "none";
+     device_property_read_string(&pdev->dev, "linux,default-trigger",
+                                 &led->cdev.default_trigger);
+
      mutex_init(&led->mutex);
 
      /* The class framework makes a callback to get brightness during

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 687

Quoted 5 lines
drivers/leds/leds-lm3533.c +1 -1
@@ -680,15 +684,22 @@ static int lm3533_led_probe(struct platform_device *pdev)
 
      platform_set_drvdata(pdev, led);
 
-     ret = led_classdev_register(pdev->dev.parent, &led->cdev);
+     ret = led_classdev_register(&pdev->dev, &led->cdev);

Here too you appear to be reparenting the class devices.

Quoted 6 lines

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 689

Quoted 3 lines
drivers/leds/leds-lm3533.c +1 -1
      if (ret) {
-             dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id);
+             dev_err(&pdev->dev, "failed to register LED %d\n", led->id);

This does not seem to be necessary.

Agreed.

Quoted 5 lines
Quoted 5 lines
drivers/leds/leds-lm3533.c +0 -0
              return ret;
      }
 
      led->cb.dev = led->cdev.dev;
 
Quoted 8 lines

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 698

Quoted 5 lines
drivers/leds/leds-lm3533.c +4 -1
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);
+     led->max_current = clamp(led->max_current, LM3533_MAX_CURRENT_MIN,
+                              LM3533_MAX_CURRENT_MAX);

Why clamp instead of having lm3533_led_setup() fail below?

According to OF schema default lower margin is set to LM3533_MAX_CURRENT_MIN so clamping seems a good option here, even though it will clamp max value.

Quoted 11 lines
Quoted 11 lines
drivers/leds/leds-lm3533.c +4 -0
+
+     device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);
+
+     ret = lm3533_led_setup(led);
      if (ret)
              goto err_deregister;
 
@@ -725,9 +736,16 @@ static void lm3533_led_shutdown(struct platform_device *pdev)
      lm3533_led_set(&led->cdev, LED_OFF);            /* disable blink */
 }
 
Quoted 16 lines

drivers/leds/leds-lm3533.c static void lm3533_led_shutdown(struct platform_device *pdev) · line 751

Quoted 13 lines
drivers/leds/leds-lm3533.c +7 -0
+static const struct of_device_id lm3533_led_match_table[] = {
+     { .compatible = "ti,lm3533-leds" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, lm3533_led_match_table);
+
 static struct platform_driver lm3533_led_driver = {
      .driver = {
              .name = "lm3533-leds",
+             .of_match_table = lm3533_led_match_table,
      },
      .probe          = lm3533_led_probe,
      .remove         = lm3533_led_remove,

Remove platform alias below as well.

Why?

Quoted 169 lines
Quoted 169 lines
drivers/mfd/lm3533-core.c +8 -119
index b03a3ae96c10..a5aa7da9668b 100644
@@ -14,19 +14,26 @@
 #include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/units.h>
 
 #include <linux/mfd/lm3533.h>
 
 
 #define LM3533_BOOST_OVP_MASK                0x06
 #define LM3533_BOOST_OVP_SHIFT               1
+#define LM3533_BOOST_OVP_MIN         (16 * MICRO)
+#define LM3533_BOOST_OVP_MAX         (40 * MICRO)
 
 #define LM3533_BOOST_FREQ_MASK               0x01
 #define LM3533_BOOST_FREQ_SHIFT              0
+#define LM3533_BOOST_FREQ_MIN                (500 * HZ_PER_KHZ)
+#define LM3533_BOOST_FREQ_MAX                (1000 * HZ_PER_KHZ)
 
 #define LM3533_BL_ID_MASK            1
 #define LM3533_LED_ID_MASK           3
@@ -35,6 +42,7 @@
 
 #define LM3533_HVLED_ID_MAX          2
 #define LM3533_LVLED_ID_MAX          5
+#define LM3533_CELLS_MAX             7
 
 #define LM3533_REG_OUTPUT_CONF1              0x10
 #define LM3533_REG_OUTPUT_CONF2              0x11
@@ -42,44 +50,6 @@
 
 #define LM3533_REG_MAX                       0xb2
 
-
-static struct mfd_cell lm3533_als_devs[] = {
-     {
-             .name   = "lm3533-als",
-             .id     = -1,
-     },
-};
-
-static struct mfd_cell lm3533_bl_devs[] = {
-     {
-             .name   = "lm3533-backlight",
-             .id     = 0,
-     },
-     {
-             .name   = "lm3533-backlight",
-             .id     = 1,
-     },
-};
-
-static struct mfd_cell lm3533_led_devs[] = {
-     {
-             .name   = "lm3533-leds",
-             .id     = 0,
-     },
-     {
-             .name   = "lm3533-leds",
-             .id     = 1,
-     },
-     {
-             .name   = "lm3533-leds",
-             .id     = 2,
-     },
-     {
-             .name   = "lm3533-leds",
-             .id     = 3,
-     },
-};
-
 /*
  * HVLED output config -- output hvled controlled by backlight bl
  */
@@ -301,125 +271,91 @@ static const struct attribute_group *lm3533_attribute_groups[] = {
      NULL,
 };
 
-static int lm3533_device_als_init(struct lm3533 *lm3533)
-{
-     struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-     int ret;
-
-     if (!pdata->als)
-             return 0;
-
-     lm3533_als_devs[0].platform_data = pdata->als;
-     lm3533_als_devs[0].pdata_size = sizeof(*pdata->als);
-
-     ret = mfd_add_devices(lm3533->dev, 0, lm3533_als_devs, 1, NULL,
-                           0, NULL);
-     if (ret) {
-             dev_err(lm3533->dev, "failed to add ALS device\n");
-             return ret;
-     }
-
-     lm3533->have_als = 1;
-
-     return 0;
-}
-
-static int lm3533_device_bl_init(struct lm3533 *lm3533)
-{
-     struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-     int i;
-     int ret;
-
-     if (!pdata->backlights || pdata->num_backlights == 0)
-             return 0;
-
-     if (pdata->num_backlights > ARRAY_SIZE(lm3533_bl_devs))
-             pdata->num_backlights = ARRAY_SIZE(lm3533_bl_devs);
-
-     for (i = 0; i < pdata->num_backlights; ++i) {
-             lm3533_bl_devs[i].platform_data = &pdata->backlights[i];
-             lm3533_bl_devs[i].pdata_size = sizeof(pdata->backlights[i]);
-     }
-
-     ret = mfd_add_devices(lm3533->dev, 0, lm3533_bl_devs,
-                           pdata->num_backlights, NULL, 0, NULL);
-     if (ret) {
-             dev_err(lm3533->dev, "failed to add backlight devices\n");
-             return ret;
-     }
-
-     lm3533->have_backlights = 1;
-
-     return 0;
-}
-
-static int lm3533_device_led_init(struct lm3533 *lm3533)
-{
-     struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
-     int i;
-     int ret;
-
-     if (!pdata->leds || pdata->num_leds == 0)
-             return 0;
-
-     if (pdata->num_leds > ARRAY_SIZE(lm3533_led_devs))
-             pdata->num_leds = ARRAY_SIZE(lm3533_led_devs);
-
-     for (i = 0; i < pdata->num_leds; ++i) {
-             lm3533_led_devs[i].platform_data = &pdata->leds[i];
-             lm3533_led_devs[i].pdata_size = sizeof(pdata->leds[i]);
-     }
-
-     ret = mfd_add_devices(lm3533->dev, 0, lm3533_led_devs,
-                           pdata->num_leds, NULL, 0, NULL);
-     if (ret) {
-             dev_err(lm3533->dev, "failed to add LED devices\n");
-             return ret;
-     }
-
-     lm3533->have_leds = 1;
-
-     return 0;
-}
-
Quoted 9 lines

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 278

Quoted 6 lines
drivers/mfd/lm3533-core.c +3 -1
 static int lm3533_device_init(struct lm3533 *lm3533)
 {
-     struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
+     struct device *dev = lm3533->dev;
+     struct mfd_cell *lm3533_devices;
+     u32 count = 0, reg, nchilds;

Don't mix multiple declarations with initialisation like this.

Checkpatch does not complain on style issue, hence this is not prohibited.

Quoted 25 lines
Quoted 14 lines
drivers/mfd/lm3533-core.c +6 -5
      int ret;
 
-     dev_dbg(lm3533->dev, "%s\n", __func__);
+     nchilds = device_get_child_node_count(dev);
+     if (!nchilds || nchilds > LM3533_CELLS_MAX)
+             return dev_err_probe(dev, -ENODEV,
+                                  "num of child nodes is not supported\n");
 
-     if (!pdata) {
-             dev_err(lm3533->dev, "no platform data\n");
-             return -EINVAL;
-     }
+     lm3533_devices = devm_kcalloc(dev, nchilds, sizeof(*lm3533_devices),
+                                   GFP_KERNEL);

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 293

Quoted 10 lines
drivers/mfd/lm3533-core.c +5 -4
+     if (!lm3533_devices)
+             return -ENOMEM;
 
-     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");
+     device_for_each_child_node_scoped(dev, child) {
+             if (count >= nchilds)
+                     break;
Quoted 2 lines

How could count be larger than nchilds?

Only if the tree is malformed, hence this check was added.

Quoted 36 lines
Quoted 36 lines
drivers/mfd/lm3533-core.c +36 -0
+
+             if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
+                     lm3533_devices[count].name = "lm3533-als";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-als";
+                     lm3533_devices[count].id = PLATFORM_DEVID_NONE;
+
+                     lm3533->have_als = true;
+                     count++;
+             } else if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
+                     ret = fwnode_property_read_u32(child, "reg", &reg);
+                     if (ret || reg >= LM3533_HVLED_ID_MAX) {
+                             dev_err(dev, "invalid backlight node %pfw\n", child);
+                             continue;
+                     }
+
+                     lm3533_devices[count].name = "lm3533-backlight";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-backlight";
+                     lm3533_devices[count].id = reg;
+                     lm3533_devices[count].of_reg = reg;
+                     lm3533_devices[count].use_of_reg = true;
+
+                     lm3533->have_backlights = true;
+                     count++;
+             } else if (fwnode_device_is_compatible(child, "ti,lm3533-leds")) {
+                     ret = fwnode_property_read_u32(child, "reg", &reg);
+                     if (ret || reg < LM3533_HVLED_ID_MAX ||
+                         reg > LM3533_LVLED_ID_MAX) {
+                             dev_err(dev, "invalid LED node %pfw\n", child);
+                             continue;
+                     }
+
+                     lm3533_devices[count].name = "lm3533-leds";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-leds";
+                     lm3533_devices[count].id = reg - LM3533_HVLED_ID_MAX;
+                     lm3533_devices[count].of_reg = reg;
+                     lm3533_devices[count].use_of_reg = true;
Quoted 9 lines

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 334

Quoted 5 lines
drivers/mfd/lm3533-core.c +5 -0
+
+                     lm3533->have_leds = true;
+                     count++;
+             }
+     }

Why do you need the above at all? Shouldn't you be able to just use of_platform_populate().

of_platform_populate() is not a part of mfd framework.

Quoted 37 lines
Quoted 37 lines
drivers/mfd/lm3533-core.c +9 -7
      lm3533_enable(lm3533);
 
      ret = regmap_update_bits(lm3533->regmap, LM3533_REG_BOOST_PWM,
                               LM3533_BOOST_FREQ_MASK,
-                              pdata->boost_freq << LM3533_BOOST_FREQ_SHIFT);
+                              lm3533->boost_freq << LM3533_BOOST_FREQ_SHIFT);
      if (ret) {
-             dev_err(lm3533->dev, "failed to set boost frequency\n");
+             dev_err(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);
+                              lm3533->boost_ovp << LM3533_BOOST_OVP_SHIFT);
      if (ret) {
-             dev_err(lm3533->dev, "failed to set boost ovp\n");
+             dev_err(dev, "failed to set boost ovp\n");
              goto err_disable;
      }
 
-     lm3533_device_als_init(lm3533);
-     lm3533_device_bl_init(lm3533);
-     lm3533_device_led_init(lm3533);
+     ret = mfd_add_devices(dev, 0, lm3533_devices, count, NULL, 0, NULL);
+     if (ret) {
+             dev_err(dev, "failed to add MFD devices: %d\n", ret);
+             goto err_disable;
+     }
 
      return 0;
 
@@ -504,7 +440,26 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
              return PTR_ERR(lm3533->regmap);
 
Quoted 12 lines

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 448

Quoted 8 lines
drivers/mfd/lm3533-core.c +6 -1
      lm3533->dev = &i2c->dev;
-     lm3533->irq = i2c->irq;
+
+     lm3533->hwen = devm_gpiod_get_optional(lm3533->dev, "enable",
+                                            GPIOD_OUT_LOW);
+     if (IS_ERR(lm3533->hwen))
+             return dev_err_probe(lm3533->dev, PTR_ERR(lm3533->hwen),
+                                  "failed to get HWEN GPIO\n");

Please use brackets around multline statements for readability throughout.

Checkpatch does not complain on style issue, hence this is not prohibited.

Quoted 8 lines
Quoted 8 lines
drivers/mfd/lm3533-core.c +8 -0
+
+     device_property_read_u32(lm3533->dev, "ti,boost-ovp-microvolt",
+                              &lm3533->boost_ovp);
+
+     lm3533->boost_ovp = clamp(lm3533->boost_ovp, LM3533_BOOST_OVP_MIN,
+                               LM3533_BOOST_OVP_MAX);
+     lm3533->boost_ovp = lm3533->boost_ovp / (8 * MICRO) - 2;
+
Quoted 9 lines

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 462

Quoted 6 lines
drivers/mfd/lm3533-core.c +6 -0
+     device_property_read_u32(lm3533->dev, "ti,boost-freq-hz",
+                              &lm3533->boost_freq);
+
+     lm3533->boost_freq = clamp(lm3533->boost_freq, LM3533_BOOST_FREQ_MIN,
+                                LM3533_BOOST_FREQ_MAX);
+     lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;

Again, why clamp instead of failing probe?

According to OF schema default lower margin is set to LM3533_BOOST_FREQ_MIN so clamping seems a good option here, even though it will clamp max value.

Quoted 111 lines
Quoted 111 lines
drivers/mfd/lm3533-core.c +7 -0
      return lm3533_device_init(lm3533);
 }
@@ -518,6 +473,12 @@ static void lm3533_i2c_remove(struct i2c_client *i2c)
      lm3533_device_exit(lm3533);
 }
 
+static const struct of_device_id lm3533_match_table[] = {
+     { .compatible = "ti,lm3533" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, lm3533_match_table);
+
 static const struct i2c_device_id lm3533_i2c_ids[] = {
      { "lm3533" },
      { }
@@ -528,6 +489,7 @@ static struct i2c_driver lm3533_i2c_driver = {
      .driver = {
                 .name = "lm3533",
                 .dev_groups = lm3533_attribute_groups,
+                .of_match_table = lm3533_match_table,
      },
      .id_table       = lm3533_i2c_ids,
      .probe          = lm3533_i2c_probe,
drivers/mfd/lm3533-ctrlbank.c +0 -5
index 91e13cfa3cf0..3aab8ece4e8c 100644
@@ -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 +10 -11
index 9ef171d3aaea..2c24647fc17a 100644
@@ -9,7 +9,9 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/backlight.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
@@ -29,6 +31,9 @@ struct lm3533_bl {
      struct backlight_device *bd;
      int id;
 
+     u32 max_current;
+     u32 pwm;
+
      bool have_als;
 };
 
@@ -242,25 +247,25 @@ static const struct attribute_group *lm3533_bl_attribute_groups[] = {
      NULL,
 };
 
-static int lm3533_bl_setup(struct lm3533_bl *bl,
-                                     struct lm3533_bl_platform_data *pdata)
+static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
      int ret;
 
-     ret = lm3533_ctrlbank_set_max_current(&bl->cb, pdata->max_current);
+     ret = lm3533_ctrlbank_set_max_current(&bl->cb, bl->max_current);
      if (ret)
              return ret;
 
-     return lm3533_ctrlbank_set_pwm(&bl->cb, pdata->pwm);
+     return lm3533_ctrlbank_set_pwm(&bl->cb, bl->pwm);
 }
 
 static int lm3533_bl_probe(struct platform_device *pdev)
 {
      struct lm3533 *lm3533;
-     struct lm3533_bl_platform_data *pdata;
      struct lm3533_bl *bl;
      struct backlight_device *bd;
      struct backlight_properties props;
+     char *name = NULL;
+     u32 default_brightness = LM3533_BL_MAX_BRIGHTNESS;
      int ret;
 
      dev_dbg(&pdev->dev, "%s\n", __func__);
@@ -269,12 +274,6 @@ static int lm3533_bl_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;
-     }
-
      if (pdev->id < 0 || pdev->id >= LM3533_HVCTRLBANK_COUNT) {
              dev_err(&pdev->dev, "illegal backlight id %d\n", pdev->id);
              return -EINVAL;
@@ -292,13 +291,21 @@ static int lm3533_bl_probe(struct platform_device *pdev)
      bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
      bl->cb.dev = NULL;                      /* until registered */
 
Quoted 5 lines

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 295

Quoted 2 lines
drivers/video/backlight/lm3533_bl.c +2 -0
+     name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+                           pdev->name, pdev->id);

Unique enough (e.g. backlight-0)?

lm3533-backlight-0

Quoted 71 lines
Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +6 -0
+     if (!name)
+             return -ENOMEM;
+
+     device_property_read_u32(&pdev->dev, "default-brightness",
+                              &default_brightness);
+
      memset(&props, 0, sizeof(props));

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 308

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +4 -4
      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 = default_brightness;
+
+     bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev,
+                                         bl, &lm3533_bl_ops, &props);

Here too you are reparenting, which results in an ABI break.

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 322

Quoted 12 lines
drivers/video/backlight/lm3533_bl.c +4 -1
      if (IS_ERR(bd)) {
              dev_err(&pdev->dev, "failed to register backlight device\n");
              return PTR_ERR(bd);
@@ -309,12 +316,19 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 
      platform_set_drvdata(pdev, bl);
 
-     backlight_update_status(bd);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &bl->max_current);
+     bl->max_current = clamp(bl->max_current, LM3533_MAX_CURRENT_MIN,
+                             LM3533_MAX_CURRENT_MAX);

Clamping instead of failing.

Quoted 22 lines
drivers/video/backlight/lm3533_bl.c +10 -1
-     ret = lm3533_bl_setup(bl, pdata);
+     device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &bl->pwm);
+
+     ret = lm3533_bl_setup(bl);
      if (ret)
              return ret;
 
+     backlight_update_status(bd);
+
      ret = lm3533_ctrlbank_enable(&bl->cb);
      if (ret)
              return ret;
@@ -366,11 +380,18 @@ static void lm3533_bl_shutdown(struct platform_device *pdev)
      lm3533_ctrlbank_disable(&bl->cb);
 }
 
+static const struct of_device_id lm3533_bl_match_table[] = {
+     { .compatible = "ti,lm3533-backlight" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, lm3533_bl_match_table);

drivers/video/backlight/lm3533_bl.c static void lm3533_bl_shutdown(struct platform_device *pdev) · line 397

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +2 -0
+
 static struct platform_driver lm3533_bl_driver = {
      .driver = {
              .name   = "lm3533-backlight",
              .pm     = &lm3533_bl_pm_ops,
              .dev_groups = lm3533_bl_attribute_groups,
+             .of_match_table = lm3533_bl_match_table,
      },
      .probe          = lm3533_bl_probe,
      .remove         = lm3533_bl_remove,

Drop platform module alias below.

Johan

maintainer
#37 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

Quoted 11 lines · On Tue, 14 Jul 2026 16:57:01 +0300 Svyatoslav Ryhel <[email protected]> wrote:

пт, 3 лип. 2026 р. о 14:03 Johan Hovold <[email protected]> пише:

Quoted 10 lines · Svyatoslav Ryhel
Quoted 7 lines

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.

      indio_dev->name = dev_name(&pdev->dev);

- iio_device_set_parent(indio_dev, pdev->dev.parent);

Quoted 5 lines
Quoted 2 lines

Why are you reparenting the iio device here?

Because every cell has its own binding now and using phandle to parent when device has its own node is not a good practice.

It is however a good point. So should at very least the ABI break should be called out in the patch description with a brief mention of what the path change actually is.

Quoted 6 lines
Quoted 3 lines

That's an ABI break.

This driver does not have any active users in the kernel and no activity for more then 2 years.

...

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ u32 count = 0, reg, nchilds;

Don't mix multiple declarations with initialisation like this.

Checkpatch does not complain on style issue, hence this is not prohibited.

Prohibition vs taste. I fully agree with John on this one! Those mixes are messy and hard to read.

Checkpatch is a helpful tool but there are both rules and preferred style things it does not catch.

Jonathan

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
      int ret;
#38 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

ср, 22 лип. 2026 р. о 04:30 Jonathan Cameron <[email protected]> пише:

Quoted 18 lines
Quoted 14 lines · On Tue, 14 Jul 2026 16:57:01 +0300 Svyatoslav Ryhel <[email protected]> wrote:

пт, 3 лип. 2026 р. о 14:03 Johan Hovold <[email protected]> пише:

Quoted 12 lines · Svyatoslav Ryhel
Quoted 7 lines

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings.

      indio_dev->name = dev_name(&pdev->dev);

- iio_device_set_parent(indio_dev, pdev->dev.parent);

Why are you reparenting the iio device here?

Quoted 7 lines
Quoted 2 lines

Because every cell has its own binding now and using phandle to parent when device has its own node is not a good practice.

It is however a good point. So should at very least the ABI break should be called out in the patch description with a brief mention of what the path change actually is.

Ok, this is a good idea to add chapter into commit description.

Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

That's an ABI break.

This driver does not have any active users in the kernel and no activity for more then 2 years.

...

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+ u32 count = 0, reg, nchilds;

Don't mix multiple declarations with initialisation like this.

Quoted 8 lines
Quoted 1 line

Checkpatch does not complain on style issue, hence this is not prohibited.

Prohibition vs taste. I fully agree with John on this one! Those mixes are messy and hard to read.

Checkpatch is a helpful tool but there are both rules and preferred style things it does not catch.

Ok, fine.

Quoted 5 lines

Jonathan

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
      int ret;
#39 lore raw

Re: [PATCH v5 08/14] mfd: lm3533: Convert to use OF bindings

In reply to Svyatoslav Ryhel
Quoted 45 lines · Svyatoslav Ryhel

пт, 3 лип. 2026 р. о 14:03 Johan Hovold <[email protected]> пише:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 24 lines

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      |  67 +++++---
 drivers/leds/leds-lm3533.c          |  50 ++++--
 drivers/mfd/lm3533-core.c           | 236 ++++++++++++----------------
 drivers/mfd/lm3533-ctrlbank.c       |   5 -
 drivers/video/backlight/lm3533_bl.c |  55 +++++--
 include/linux/mfd/lm3533.h          |  52 +-----
 6 files changed, 220 insertions(+), 245 deletions(-)

static int lm3533_als_probe(struct platform_device *pdev) {

drivers/iio/light/lm3533-als.c +0 -1
-     const struct lm3533_als_platform_data *pdata;
      struct lm3533 *lm3533;
      struct lm3533_als *als;
      struct iio_dev *indio_dev;
@@ -803,12 +817,6 @@ static int lm3533_als_probe(struct platform_device *pdev)
      if (!lm3533)
              return -EINVAL;
 
Quoted 17 lines
Quoted 10 lines
drivers/iio/light/lm3533-als.c +0 -6
-     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;

drivers/iio/light/lm3533-als.c static int lm3533_als_probe(struct platform_device *pdev) · line 820

Quoted 4 lines
drivers/iio/light/lm3533-als.c +0 -1
@@ -817,25 +825,27 @@ 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);

Why are you reparenting the iio device here?

Quoted 8 lines

Because every cell has its own binding now and using phandle to parent when device has its own node is not a good practice.

Quoted 2 lines

That's an ABI break.

This driver does not have any active users in the kernel and no activity for more then 2 years.

We have never required board files to be upstream.

And a working driver does not need to be changed every year.

In any case, something like this at a minimum needs to be highlighted in the commit message.

Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
drivers/iio/light/lm3533-als.c +6 -0
+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 = {
Quoted 9 lines

drivers/iio/light/lm3533-als.c static void lm3533_als_remove(struct platform_device *pdev) · line 897

Quoted 6 lines
drivers/iio/light/lm3533-als.c +1 -0
      .driver = {
              .name   = "lm3533-als",
+             .of_match_table = lm3533_als_match_table,
      },
      .probe          = lm3533_als_probe,
      .remove         = lm3533_als_remove,

You should also remove the platform module alias below.

Quoted 1 line

Why?

Because your change makes it obsolete. The driver now only supports OF probing.

Quoted 29 lines
Quoted 9 lines

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 687

Quoted 6 lines
drivers/leds/leds-lm3533.c +1 -1
@@ -680,15 +684,22 @@ static int lm3533_led_probe(struct platform_device *pdev)
 
      platform_set_drvdata(pdev, led);
 
-     ret = led_classdev_register(pdev->dev.parent, &led->cdev);
+     ret = led_classdev_register(&pdev->dev, &led->cdev);

Here too you appear to be reparenting the class devices.

Quoted 6 lines

drivers/leds/leds-lm3533.c static int lm3533_led_probe(struct platform_device *pdev) · line 689

Quoted 3 lines
drivers/leds/leds-lm3533.c +1 -1
      if (ret) {
-             dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id);
+             dev_err(&pdev->dev, "failed to register LED %d\n", led->id);

This does not seem to be necessary.

Agreed.

Quoted 11 lines
Quoted 10 lines
drivers/leds/leds-lm3533.c +4 -1
              return ret;
      }
 
      led->cb.dev = led->cdev.dev;
 
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);
+     led->max_current = clamp(led->max_current, LM3533_MAX_CURRENT_MIN,
+                              LM3533_MAX_CURRENT_MAX);
Quoted 6 lines
Quoted 2 lines

Why clamp instead of having lm3533_led_setup() fail below?

According to OF schema default lower margin is set to LM3533_MAX_CURRENT_MIN so clamping seems a good option here, even though it will clamp max value.

Just let it fail to probe. The driver already have the necessary checks.

Quoted 28 lines
Quoted 11 lines
Quoted 11 lines
drivers/leds/leds-lm3533.c +4 -0
+
+     device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);
+
+     ret = lm3533_led_setup(led);
      if (ret)
              goto err_deregister;
 
@@ -725,9 +736,16 @@ static void lm3533_led_shutdown(struct platform_device *pdev)
      lm3533_led_set(&led->cdev, LED_OFF);            /* disable blink */
 }
 
Quoted 16 lines

drivers/leds/leds-lm3533.c static void lm3533_led_shutdown(struct platform_device *pdev) · line 751

Quoted 13 lines
drivers/leds/leds-lm3533.c +7 -0
+static const struct of_device_id lm3533_led_match_table[] = {
+     { .compatible = "ti,lm3533-leds" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, lm3533_led_match_table);
+
 static struct platform_driver lm3533_led_driver = {
      .driver = {
              .name = "lm3533-leds",
+             .of_match_table = lm3533_led_match_table,
      },
      .probe          = lm3533_led_probe,
      .remove         = lm3533_led_remove,

Remove platform alias below as well.

Quoted 1 line

Why?

Same reason as above.

Quoted 11 lines
Quoted 9 lines

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 278

Quoted 6 lines

static int lm3533_device_init(struct lm3533 *lm3533) {

drivers/mfd/lm3533-core.c +3 -1
-     struct lm3533_platform_data *pdata = dev_get_platdata(lm3533->dev);
+     struct device *dev = lm3533->dev;
+     struct mfd_cell *lm3533_devices;
+     u32 count = 0, reg, nchilds;

Don't mix multiple declarations with initialisation like this.

Checkpatch does not complain on style issue, hence this is not prohibited.

Checkpatch does not define good style.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
      int ret;
drivers/mfd/lm3533-core.c +11 -9
-     dev_dbg(lm3533->dev, "%s\n", __func__);
+     nchilds = device_get_child_node_count(dev);
+     if (!nchilds || nchilds > LM3533_CELLS_MAX)
+             return dev_err_probe(dev, -ENODEV,
+                                  "num of child nodes is not supported\n");
 
-     if (!pdata) {
-             dev_err(lm3533->dev, "no platform data\n");
-             return -EINVAL;
-     }
+     lm3533_devices = devm_kcalloc(dev, nchilds, sizeof(*lm3533_devices),
+                                   GFP_KERNEL);
+     if (!lm3533_devices)
+             return -ENOMEM;
 
-     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");
+     device_for_each_child_node_scoped(dev, child) {
+             if (count >= nchilds)
+                     break;
Quoted 4 lines
Quoted 2 lines

How could count be larger than nchilds?

Only if the tree is malformed, hence this check was added.

But you've just retrieved nchilds by parsing the tree and counting the child nodes. So how can count possibly be larger than nchilds here?

Quoted 46 lines
Quoted 36 lines
Quoted 36 lines
drivers/mfd/lm3533-core.c +36 -0
+
+             if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
+                     lm3533_devices[count].name = "lm3533-als";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-als";
+                     lm3533_devices[count].id = PLATFORM_DEVID_NONE;
+
+                     lm3533->have_als = true;
+                     count++;
+             } else if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
+                     ret = fwnode_property_read_u32(child, "reg", &reg);
+                     if (ret || reg >= LM3533_HVLED_ID_MAX) {
+                             dev_err(dev, "invalid backlight node %pfw\n", child);
+                             continue;
+                     }
+
+                     lm3533_devices[count].name = "lm3533-backlight";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-backlight";
+                     lm3533_devices[count].id = reg;
+                     lm3533_devices[count].of_reg = reg;
+                     lm3533_devices[count].use_of_reg = true;
+
+                     lm3533->have_backlights = true;
+                     count++;
+             } else if (fwnode_device_is_compatible(child, "ti,lm3533-leds")) {
+                     ret = fwnode_property_read_u32(child, "reg", &reg);
+                     if (ret || reg < LM3533_HVLED_ID_MAX ||
+                         reg > LM3533_LVLED_ID_MAX) {
+                             dev_err(dev, "invalid LED node %pfw\n", child);
+                             continue;
+                     }
+
+                     lm3533_devices[count].name = "lm3533-leds";
+                     lm3533_devices[count].of_compatible = "ti,lm3533-leds";
+                     lm3533_devices[count].id = reg - LM3533_HVLED_ID_MAX;
+                     lm3533_devices[count].of_reg = reg;
+                     lm3533_devices[count].use_of_reg = true;
Quoted 9 lines

drivers/mfd/lm3533-core.c static const struct attribute_group *lm3533_attribute_groups[] = { · line 334

Quoted 5 lines
drivers/mfd/lm3533-core.c +5 -0
+
+                     lm3533->have_leds = true;
+                     count++;
+             }
+     }

Why do you need the above at all? Shouldn't you be able to just use of_platform_populate().

Quoted 1 line

of_platform_populate() is not a part of mfd framework.

We have several MFD drivers using of_platform_populate().

Quoted 50 lines
Quoted 37 lines
Quoted 37 lines
      lm3533_enable(lm3533);

      ret = regmap_update_bits(lm3533->regmap, LM3533_REG_BOOST_PWM,
                               LM3533_BOOST_FREQ_MASK,
drivers/mfd/lm3533-core.c +9 -7
-                              pdata->boost_freq << LM3533_BOOST_FREQ_SHIFT);
+                              lm3533->boost_freq << LM3533_BOOST_FREQ_SHIFT);
      if (ret) {
-             dev_err(lm3533->dev, "failed to set boost frequency\n");
+             dev_err(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);
+                              lm3533->boost_ovp << LM3533_BOOST_OVP_SHIFT);
      if (ret) {
-             dev_err(lm3533->dev, "failed to set boost ovp\n");
+             dev_err(dev, "failed to set boost ovp\n");
              goto err_disable;
      }
 
-     lm3533_device_als_init(lm3533);
-     lm3533_device_bl_init(lm3533);
-     lm3533_device_led_init(lm3533);
+     ret = mfd_add_devices(dev, 0, lm3533_devices, count, NULL, 0, NULL);
+     if (ret) {
+             dev_err(dev, "failed to add MFD devices: %d\n", ret);
+             goto err_disable;
+     }
 
      return 0;
@@ -504,7 +440,26 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
              return PTR_ERR(lm3533->regmap);
 
Quoted 12 lines

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 448

Quoted 8 lines
drivers/mfd/lm3533-core.c +6 -1
      lm3533->dev = &i2c->dev;
-     lm3533->irq = i2c->irq;
+
+     lm3533->hwen = devm_gpiod_get_optional(lm3533->dev, "enable",
+                                            GPIOD_OUT_LOW);
+     if (IS_ERR(lm3533->hwen))
+             return dev_err_probe(lm3533->dev, PTR_ERR(lm3533->hwen),
+                                  "failed to get HWEN GPIO\n");

Please use brackets around multline statements for readability throughout.

Quoted 1 line

Checkpatch does not complain on style issue, hence this is not prohibited.

Checkpatch is irrelevant.

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
drivers/mfd/lm3533-core.c +8 -0
+
+     device_property_read_u32(lm3533->dev, "ti,boost-ovp-microvolt",
+                              &lm3533->boost_ovp);
+
+     lm3533->boost_ovp = clamp(lm3533->boost_ovp, LM3533_BOOST_OVP_MIN,
+                               LM3533_BOOST_OVP_MAX);
+     lm3533->boost_ovp = lm3533->boost_ovp / (8 * MICRO) - 2;
+
Quoted 9 lines

drivers/mfd/lm3533-core.c static int lm3533_i2c_probe(struct i2c_client *i2c) · line 462

Quoted 6 lines
drivers/mfd/lm3533-core.c +6 -0
+     device_property_read_u32(lm3533->dev, "ti,boost-freq-hz",
+                              &lm3533->boost_freq);
+
+     lm3533->boost_freq = clamp(lm3533->boost_freq, LM3533_BOOST_FREQ_MIN,
+                                LM3533_BOOST_FREQ_MAX);
+     lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;

Again, why clamp instead of failing probe?

Quoted 3 lines

According to OF schema default lower margin is set to LM3533_BOOST_FREQ_MIN so clamping seems a good option here, even though it will clamp max value.

Just let the driver fail to probe as the sanity checks are already there.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/mfd/lm3533-core.c +0 -0
      return lm3533_device_init(lm3533);
 }
@@ -518,6 +473,12 @@ static void lm3533_i2c_remove(struct i2c_client *i2c)
      lm3533_device_exit(lm3533);
 }
 
Quoted 9 lines
Quoted 9 lines

drivers/mfd/lm3533-core.c static void lm3533_i2c_remove(struct i2c_client *i2c) · line 484

Quoted 9 lines
drivers/mfd/lm3533-core.c +6 -0
+static const struct of_device_id lm3533_match_table[] = {
+     { .compatible = "ti,lm3533" },
+     { }
+};
+MODULE_DEVICE_TABLE(of, lm3533_match_table);
+
 static const struct i2c_device_id lm3533_i2c_ids[] = {
      { "lm3533" },
      { }

Shouldn't you drop i2c probing now as well?

Quoted 8 lines
Quoted 8 lines

drivers/mfd/lm3533-core.c static struct i2c_driver lm3533_i2c_driver = { · line 495

Quoted 8 lines
drivers/mfd/lm3533-core.c +1 -0
@@ -528,6 +489,7 @@ static struct i2c_driver lm3533_i2c_driver = {
      .driver = {
                 .name = "lm3533",
                 .dev_groups = lm3533_attribute_groups,
+                .of_match_table = lm3533_match_table,
      },
      .id_table       = lm3533_i2c_ids,
      .probe          = lm3533_i2c_probe,

Johan

#40 lore raw

PATCH v5 9/14 mfd: lm3533: Add support for VIN power supply

In reply to Svyatoslav Ryhel

Add 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
index a5aa7da9668b..4b5d94e9ed27 100644
@@ -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 {
@@ -333,7 +345,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,
@@ -447,6 +461,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
index 5710e88da45d..8f72dd41e8f0 100644
@@ -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.53.0
#41 lore raw

Re: [PATCH v5 09/14] mfd: lm3533: Add support for VIN power supply

Quoted 5 lines · Svyatoslav Ryhel

Add support for 2.7V-5.5V VIN power supply.

drivers/mfd/lm3533-core.c +0 -1
-static void lm3533_enable(struct lm3533 *lm3533)

drivers/mfd/lm3533-core.c static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led) · line 126

Quoted 10 lines
drivers/mfd/lm3533-core.c +9 -0
+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;
+	}
+

No delay needed?

drivers/mfd/lm3533-core.c static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led) · line 130

Quoted 4 lines
drivers/mfd/lm3533-core.c +2 -0
 	gpiod_set_value(lm3533->hwen, 1);
+
+	return 0;
 }

Johan

#42 lore raw

Re: [PATCH v5 09/14] mfd: lm3533: Add support for VIN power supply

пт, 3 лип. 2026 р. о 14:09 Johan Hovold <[email protected]> пише:

Quoted 6 lines · Svyatoslav Ryhel
Quoted 3 lines

Add support for 2.7V-5.5V VIN power supply.

Quoted 14 lines

drivers/mfd/lm3533-core.c static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led) · line 126

Quoted 11 lines
drivers/mfd/lm3533-core.c +9 -1
-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;
+     }
+

No delay needed?

I have not found any in the datasheet, if you are aware of the delay duration needed please elaborate.

Quoted 6 lines

drivers/mfd/lm3533-core.c static int lm3533_set_lvled_config(struct lm3533 *lm3533, u8 lvled, u8 led) · line 130

Quoted 4 lines
      gpiod_set_value(lm3533->hwen, 1);
drivers/mfd/lm3533-core.c +2 -0
+
+     return 0;
 }

Johan

#43 lore raw

PATCH v5 10/14 mfd: lm3533: Set DMA mask

In reply to Svyatoslav Ryhel

Missing 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
index 4b5d94e9ed27..db8581d1b073 100644
@@ -480,6 +480,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.53.0
#44 lore raw

Re: [PATCH v5 10/14] mfd: lm3533: Set DMA mask

Quoted 8 lines · Svyatoslav Ryhel

Missing 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.

IIUC this warning is introduced by the OF conversion and should therefore be moved before it as a preparatory patch.

But you need to describe the problem in more detail here as this looks fishy.

Johan

#45 lore raw

PATCH v5 11/14 video: backlight: lm3533_bl: Improve logic of sysfs functions

In reply to Svyatoslav Ryhel

Simplify the sysfs logic of properties by switching to macros and proper regmap helpers.

---
 drivers/video/backlight/lm3533_bl.c | 62 ++++++++++-------------------
 1 file changed, 22 insertions(+), 40 deletions(-)
drivers/video/backlight/lm3533_bl.c +22 -40
index 2c24647fc17a..9eb0db640948 100644
@@ -23,6 +23,8 @@
 #define LM3533_BL_MAX_BRIGHTNESS	255
 
 #define LM3533_REG_CTRLBANK_AB_BCONF	0x1a
+#define   CTRLBANK_AB_BCONF_ALS(n)	BIT(2 * (n))
+#define   CTRLBANK_AB_BCONF_MODE(n)	BIT(2 * (n) + 1)
 
 
 struct lm3533_bl {
@@ -85,88 +87,68 @@ static ssize_t show_als_channel(struct device *dev,
 	return scnprintf(buf, PAGE_SIZE, "%u\n", channel);
 }
 
-static ssize_t show_als_en(struct device *dev,
-				struct device_attribute *attr, char *buf)
+static ssize_t show_als_en(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
-	u32 val;
-	u8 mask;
-	bool enable;
 	int ret;
 
-	ret = regmap_read(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
-	if (ret)
+	ret = regmap_test_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+			       CTRLBANK_AB_BCONF_ALS(ctrlbank));
+	if (ret < 0)
 		return ret;
 
-	mask = 1 << (2 * ctrlbank);
-	enable = val & mask;
-
-	return scnprintf(buf, PAGE_SIZE, "%d\n", enable);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
 }
 
-static ssize_t store_als_en(struct device *dev,
-					struct device_attribute *attr,
-					const char *buf, size_t len)
+static ssize_t store_als_en(struct device *dev, struct device_attribute *attr,
+			    const char *buf, size_t len)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
 	int enable;
-	u8 mask;
 	int ret;
 
 	if (kstrtoint(buf, 0, &enable))
 		return -EINVAL;
 
-	mask = 1 << (2 * ctrlbank);
-
 	ret = regmap_assign_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
-				 mask, enable);
+				 CTRLBANK_AB_BCONF_ALS(ctrlbank), enable);
 	if (ret)
 		return ret;
 
 	return len;
 }
 
-static ssize_t show_linear(struct device *dev,
-				struct device_attribute *attr, char *buf)
+static ssize_t show_linear(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
-	u32 val;
-	u8 mask;
-	int linear;
+	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
 	int ret;
 
-	ret = regmap_read(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF, &val);
-	if (ret)
+	ret = regmap_test_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+			       CTRLBANK_AB_BCONF_MODE(ctrlbank));
+	if (ret < 0)
 		return ret;
 
-	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
-
-	if (val & mask)
-		linear = 1;
-	else
-		linear = 0;
-
-	return scnprintf(buf, PAGE_SIZE, "%x\n", linear);
+	return scnprintf(buf, PAGE_SIZE, "%x\n", ret);
 }
 
-static ssize_t store_linear(struct device *dev,
-					struct device_attribute *attr,
-					const char *buf, size_t len)
+static ssize_t store_linear(struct device *dev, struct device_attribute *attr,
+			    const char *buf, size_t len)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
+	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
 	unsigned long linear;
-	u8 mask;
 	int ret;
 
 	if (kstrtoul(buf, 0, &linear))
 		return -EINVAL;
 
-	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
-
 	ret = regmap_assign_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
-				 mask, linear);
+				 CTRLBANK_AB_BCONF_MODE(ctrlbank), linear);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.53.0
#46 lore raw

Re: [PATCH v5 11/14] video: backlight: lm3533_bl: Improve logic of sysfs functions

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Sysfs attributes were inadvertently moved from the backlight class device to the platform…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Sysfs attributes were inadvertently moved from the backlight class device to the platform device, breaking userspace ABI. --

commit b4eaddced56809e9f87ffe143724f151f0e7013e
Author: Svyatoslav Ryhel <[email protected]>

mfd: lm3533: Use dev_groups in struct device_driver

This commit replaces manual sysfs attribute creation during probe and removal in favor of using dev_groups in struct device_driver. The goal is to let the core handle the creation and removal of these attributes automatically.

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index 4d6f680334802..9ef171d3aaeab 100644

[ ... ]

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_probe(struct platform_device *pdev) · line 307

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +0 -1
@@ -304,28 +309,17 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, bl);
 
-	ret = sysfs_create_group(&bd->dev.kobj, &lm3533_bl_attribute_group);

[Severity: Critical]
By removing this manual sysfs_create_group() call and moving it to the platform driver's dev_groups, will this change the location of the sysfs attributes?

The original code registers the attributes on the backlight class device's kobject (&bd->dev.kobj), meaning they appear under /sys/class/backlight/<name>/.

Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +0 -5
-	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to create sysfs attributes\n");
-		return ret;
-	}
-
 	backlight_update_status(bd);

[ ... ]

drivers/video/backlight/lm3533_bl.c static struct platform_driver lm3533_bl_driver = { · line 373

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +1 -0
@@ -377,6 +370,7 @@ static struct platform_driver lm3533_bl_driver = {
 	.driver = {
 		.name	= "lm3533-backlight",
 		.pm	= &lm3533_bl_pm_ops,
+		.dev_groups = lm3533_bl_attribute_groups,

[Severity: Critical]
Does moving the attributes to the platform driver's dev_groups inadvertently register them on the platform device instead of the backlight class device?

This means attributes like als_channel, als_en, and linear would now be exposed under /sys/bus/platform/devices/lm3533-backlight.<id>/ instead of their previous location.

Will this break backward compatibility for userspace tools relying on the standard backlight path?

Quoted 3 lines
drivers/video/backlight/lm3533_bl.c +0 -0
 	},
 	.probe		= lm3533_bl_probe,
 	.remove		= lm3533_bl_remove,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#47 lore raw

PATCH v5 12/14 video: backlight: lm3533_bl: Set initial mapping mode from DT

In reply to Svyatoslav Ryhel

Add support to obtain the initial mapping mode from DT instead of leaving it unconfigured.

---
 drivers/video/backlight/lm3533_bl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/video/backlight/lm3533_bl.c +10 -0
index 9eb0db640948..d003d5802508 100644
@@ -37,6 +37,7 @@ struct lm3533_bl {
 	u32 pwm;
 
 	bool have_als;
+	bool linear;
 };
 
 
@@ -231,8 +232,14 @@ static const struct attribute_group *lm3533_bl_attribute_groups[] = {
 
 static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
+	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
 	int ret;
 
+	ret = regmap_assign_bits(bl->regmap, LM3533_REG_CTRLBANK_AB_BCONF,
+				 CTRLBANK_AB_BCONF_MODE(ctrlbank), bl->linear);
+	if (ret)
+		return ret;
+
 	ret = lm3533_ctrlbank_set_max_current(&bl->cb, bl->max_current);
 	if (ret)
 		return ret;
@@ -286,6 +293,9 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
 	props.brightness = default_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.53.0
#48 lore raw

PATCH v5 13/14 video: backlight: lm3533_bl: Implement backlight_scale property

In reply to Svyatoslav Ryhel

Since 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
index d003d5802508..c99fc68cb669 100644
@@ -142,6 +142,7 @@ static ssize_t store_linear(struct device *dev, struct device_attribute *attr,
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
+	struct backlight_device *bd = bl->bd;
 	unsigned long linear;
 	int ret;
 
@@ -153,6 +154,9 @@ static ssize_t store_linear(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		return ret;
 
+	bd->props.scale = linear ? BACKLIGHT_SCALE_LINEAR :
+				   BACKLIGHT_SCALE_NON_LINEAR;
+
 	return len;
 }
 
@@ -295,6 +299,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.53.0
#49 lore raw

Re: [PATCH v5 13/14] video: backlight: lm3533_bl: Implement backlight_scale property

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Race condition in `store_linear` leading to hardware and software state mismatch. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Race condition in store_linear leading to hardware and software state mismatch. --

commit 52a62eb2455ff3beba4492c4d5e3f63ad2e5e71d
Author: Svyatoslav Ryhel <[email protected]>
video: backlight: lm3533_bl: Implement backlight_scale property

This commit implements the backlight_scale property for the lm3533_bl driver. It describes whether the backlight operates in linear or non-linear mode based on the device state.

Quoted 12 lines
drivers/video/backlight/lm3533_bl.c +1 -0
@@ -142,6 +142,7 @@ static ssize_t store_linear(struct device *dev, struct device_attribute *attr,
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
 	int ctrlbank = lm3533_bl_get_ctrlbank_id(bl);
+	struct backlight_device *bd = bl->bd;
 	unsigned long linear;
 	int ret;
 

drivers/video/backlight/lm3533_bl.c static ssize_t store_linear(struct device *dev, struct device_attribute *attr, · line 158

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +2 -0
@@ -153,6 +154,9 @@ static ssize_t store_linear(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		return ret;
 
+	bd->props.scale = linear ? BACKLIGHT_SCALE_LINEAR :
+				   BACKLIGHT_SCALE_NON_LINEAR;

[Severity: Medium]
Could this allow the hardware state and the software property to diverge during concurrent writes?

Since kernfs does not serialize concurrent writes to sysfs files, if two threads write contradictory values at the same time, the regmap updates and the bd->props.scale updates could interleave. This might result in the hardware being configured in one mode while bd->props.scale incorrectly reports the opposite mode.

Would it make sense to protect this update sequence with a lock to ensure both the hardware and software properties are updated atomically?

Quoted 3 lines
drivers/video/backlight/lm3533_bl.c +1 -0
+
 	return len;
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#50 lore raw

PATCH v5 14/14 video: leds: backlight: lm3533: Support getting LED sources from DT

In reply to Svyatoslav Ryhel

Add Control Bank to HVLED/LVLED muxing support based on the led-sources defined in the device tree.

---
 drivers/leds/leds-lm3533.c          | 60 +++++++++++++++++++++++++++++
 drivers/video/backlight/lm3533_bl.c | 45 ++++++++++++++++++++++
 2 files changed, 105 insertions(+)
drivers/leds/leds-lm3533.c +60 -0
index ed810c23f30f..9e07953814fd 100644
@@ -27,6 +27,11 @@
 #define LM3533_ALS_CHANNEL_LV_MIN	1
 #define LM3533_ALS_CHANNEL_LV_MAX	2
 
+#define LM3533_REG_OUTPUT_CONF1			0x10
+#define   OUTPUT_CONF1_SHIFT			2
+#define   OUTPUT_LVLED_MASK			0x3
+#define LM3533_REG_OUTPUT_CONF2			0x11
+#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
@@ -55,6 +60,9 @@ struct lm3533_led {
 	u32 max_current;
 	u32 pwm;
 
+	int num_leds;
+	u32 leds[LM3533_LVCTRLBANK_MAX];
+
 	bool have_als;
 };
 
@@ -623,8 +631,36 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
 
 static int lm3533_led_setup(struct lm3533_led *led)
 {
+	u32 output_cfg_shift = 0;
+	u32 output_cfg_val = 0;
+	u32 output_cfg_mask = 0;
 	int ret;
 
+	if (led->num_leds) {
+		for (int 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;
+			output_cfg_mask |= OUTPUT_LVLED_MASK << output_cfg_shift;
+		}
+
+		/* LVLED1, LVLED2 and LVLED3 */
+		ret = regmap_update_bits(led->regmap, LM3533_REG_OUTPUT_CONF1,
+					 output_cfg_mask << OUTPUT_CONF1_SHIFT,
+					 output_cfg_val << OUTPUT_CONF1_SHIFT);
+		if (ret)
+			return ret;
+
+		/* LVLED4 and LVLED5 */
+		ret = regmap_update_bits(led->regmap, LM3533_REG_OUTPUT_CONF2,
+					 output_cfg_mask >> OUTPUT_CONF2_SHIFT,
+					 output_cfg_val >> OUTPUT_CONF2_SHIFT);
+		if (ret)
+			return ret;
+	}
+
 	ret = lm3533_ctrlbank_set_max_current(&led->cb, led->max_current);
 	if (ret)
 		return ret;
@@ -699,6 +735,30 @@ static int lm3533_led_probe(struct platform_device *pdev)
 
 	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);
 
+	/*
+	 * 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.
+	 */
+	led->num_leds = device_property_count_u32(&pdev->dev, "led-sources");
+	if (led->num_leds > LM3533_LVCTRLBANK_MAX) {
+		dev_err(&pdev->dev, "num of LED sources exceeds max %d: %d\n",
+			LM3533_LVCTRLBANK_MAX, led->num_leds);
+		ret = -EINVAL;
+		goto err_deregister;
+	}
+
+	if (led->num_leds < 0)
+		led->num_leds = 0;
+
+	if (led->num_leds > 0) {
+		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;
+		}
+	}
+
 	ret = lm3533_led_setup(led);
 	if (ret)
 		goto err_deregister;
drivers/video/backlight/lm3533_bl.c +45 -0

81 lines not on this page · raw message

Signature · 1 line
2.53.0
#51 lore raw

Re: [PATCH v5 14/14] video: leds: backlight: lm3533: Support getting LED sources from DT

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Out-of-bounds bitmask shift causes regcache pollution and unnecessary I2C bus writes for…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Out-of-bounds bitmask shift causes regcache pollution and unnecessary I2C bus writes for LM3533_REG_OUTPUT_CONF1. --

commit a74553be2d2b60a05a193e9dc35527d3d4a425da
Author: Svyatoslav Ryhel <[email protected]>

video: leds: backlight: lm3533: Support getting LED sources from DT

This commit adds 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
index ed810c23f30f3..9e07953814fdd 100644

[ ... ]

Quoted 13 lines
drivers/leds/leds-lm3533.c +7 -0
@@ -623,8 +631,36 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
 
 static int lm3533_led_setup(struct lm3533_led *led)
 {
+	u32 output_cfg_shift = 0;
+	u32 output_cfg_val = 0;
+	u32 output_cfg_mask = 0;
 	int ret;
 
+	if (led->num_leds) {
+		for (int i = 0; i < led->num_leds; i++) {
+			if (led->leds[i] >= LM3533_LVCTRLBANK_MAX)
+				continue;

drivers/leds/leds-lm3533.c static const struct attribute_group *lm3533_led_attribute_groups[] = { · line 652

Quoted 10 lines
drivers/leds/leds-lm3533.c +10 -0
+
+			output_cfg_shift = led->leds[i] * 2;
+			output_cfg_val |= led->id << output_cfg_shift;
+			output_cfg_mask |= OUTPUT_LVLED_MASK << output_cfg_shift;
+		}
+
+		/* LVLED1, LVLED2 and LVLED3 */
+		ret = regmap_update_bits(led->regmap, LM3533_REG_OUTPUT_CONF1,
+					 output_cfg_mask << OUTPUT_CONF1_SHIFT,
+					 output_cfg_val << OUTPUT_CONF1_SHIFT);

[Severity: Low]
Can this shift cause bits to fall outside the 8-bit register width?

When led-sources specifies LVLED4 or LVLED5, output_cfg_mask accumulates bits that, when shifted left by OUTPUT_CONF1_SHIFT (which is 2), will exceed 8 bits (for example, forming masks like 0x300 or 0xC00).

Because regmap_update_bits operates on unsigned int internally, these out-of-bounds bits are applied to the cached register value. This causes the internal comparison (tmp != orig) to incorrectly evaluate to true, triggering an unnecessary I2C write.

Although the I2C subsystem harmlessly truncates the value to 8 bits so the hardware state is not corrupted, does it make sense to apply an explicit 8-bit mask (e.g., & 0xFF) before passing the shifted mask and value to regmap_update_bits() to prevent regcache pollution and redundant bus traffic?

Quoted 10 lines
drivers/leds/leds-lm3533.c +10 -0
+		if (ret)
+			return ret;
+
+		/* LVLED4 and LVLED5 */
+		ret = regmap_update_bits(led->regmap, LM3533_REG_OUTPUT_CONF2,
+					 output_cfg_mask >> OUTPUT_CONF2_SHIFT,
+					 output_cfg_val >> OUTPUT_CONF2_SHIFT);
+		if (ret)
+			return ret;
+	}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
maintainer
#53 lore raw
In reply to Svyatoslav Ryhel
Quoted 6 lines · Svyatoslav Ryhel

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:

Quoted 12 lines

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

This set looks good to me now.

Let me know when you have all of the Acks and I'll merge it via MFD.

Signature · 1 line
Lee Jones
#54 lore raw

чт, 2 лип. 2026 р. о 19:18 Lee Jones <[email protected]> пише:

Quoted 22 lines · Svyatoslav Ryhel
Quoted 7 lines

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:

Quoted 12 lines

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

Quoted 4 lines

This set looks good to me now.

Let me know when you have all of the Acks and I'll merge it via MFD.

Hello there!

Jonathan and Daniel added their Reviewed-by for IIO and backlight subsystems, so I assume that should be all required.

Best regards,
Svyatoslav R.

Quoted 2 lines

--
Lee Jones

#55 lore raw
In reply to Lee Jones

чт, 2 лип. 2026 р. о 19:18 Lee Jones <[email protected]> пише:

Quoted 22 lines · Svyatoslav Ryhel
Quoted 7 lines

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:

Quoted 12 lines

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

Quoted 4 lines

This set looks good to me now.

Let me know when you have all of the Acks and I'll merge it via MFD.

Hello Lee! Is there any unresolved blockers for picking this patch set?

Quoted 2 lines

--
Lee Jones

maintainer
#56 lore raw
Quoted 23 lines · Svyatoslav Ryhel

чт, 2 лип. 2026 р. о 19:18 Lee Jones <[email protected]> пише:

Quoted 22 lines · Svyatoslav Ryhel
Quoted 19 lines

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

Quoted 6 lines
Quoted 4 lines

This set looks good to me now.

Let me know when you have all of the Acks and I'll merge it via MFD.

Hello Lee! Is there any unresolved blockers for picking this patch set?

I can't see that clearly. Please apply all of the trailers (you can probably make this easier on yourself by using b4) and submit as a [RESEND].

Signature · 1 line
Lee Jones