Skip to contentSkip to conversation

mfd: lm3533: convert to OF bindings, improve support

PATCH Superseded Svyatoslav Ryhel 4 participants 30 messages May 28 – May 29

Subsystems (6)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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
---

Svyatoslav Ryhel (6):
dt-bindings: leds: Document TI LM3533 LED controller
mfd: lm3533: Convert to use OF bindings
mfd: lm3533: Add support for VIN power supply
mfd: lm3533: Set DMA mask
video: backlight: lm3533_bl: Set initial mapping mode from DT
video: leds: backlight: lm3533: Support getting LED sources from DT

 .../leds/backlight/ti,lm3533-backlight.yaml   |  68 ++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 ++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++
 drivers/iio/light/lm3533-als.c                |  95 +++---
 drivers/leds/leds-lm3533.c                    | 108 +++++--
 drivers/mfd/lm3533-core.c                     | 291 +++++++-----------
 drivers/video/backlight/lm3533_bl.c           | 127 ++++++--
 include/linux/mfd/lm3533.h                    |  53 +---
 8 files changed, 653 insertions(+), 325 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533-leds.yaml
 create mode 100644 Documentation/devicetree/bindings/leds/ti,lm3533.yaml
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/6 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   |  68 +++++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 +++++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++++++++++
 3 files changed, 304 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 +68 -0
new file mode 100644
index 000000000000..866b0fb8ed04
@@ -0,0 +1,68 @@
+# 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
+
+  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 +66 -0

66 lines not on this page · raw message

Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +170 -0

170 lines not on this page · raw message

Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The property `ti,resistor-ohm` does not use the standard DT schema unit suffix (`-ohms`), and its…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The property ti,resistor-ohm does not use the standard DT schema unit suffix (-ohms), and its description contains a typo ('resister'). --

commit 3710ffb632b560bb2fb8a924f794c4e747f0362b
Author: Svyatoslav Ryhel <[email protected]>

dt-bindings: leds: Document TI LM3533 LED controller

This commit documents the LM3533, a complete power source for backlight, keypad, and indicator LEDs in smartphone handsets. The high-voltage inductive boost converter provides power for two series LED strings for the display backlight and keypad functions.

Quoted 6 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +0 -0
new file mode 100644
index 0000000000000..6e12e12be08e5
@@ -0,0 +1,170 @@

[ ... ]

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

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

Quoted 10 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +10 -0
+      compatible:
+        const: ti,lm3533-als
+
+      interrupts:
+        maxItems: 1
+
+      ti,resistor-ohm:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Internal configuration resister value when light sensor is in

[Severity: Low]
This isn't a bug, but should this property use the standard dt-schema unit suffix -ohms instead of -ohm? Standardizing the unit suffix allows dt-schema to automatically infer the property type without needing an explicit reference.

Additionally, is there a typo in the description where it says resister instead of resistor?

Quoted 3 lines
Documentation/devicetree/bindings/leds/ti,lm3533.yaml new file +3 -0
+          Analog Sensor mode and PWM mode is disabled. The expectation is
+          the input is a current from the external analog light sensor and
+          this is used to convert it to a voltage within the target range.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/6
#3 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

In reply to Svyatoslav Ryhel
Quoted 7 lines · On Thu, 28 May 2026 16:51:18 +0300 Svyatoslav Ryhel <[email protected]> wrote:

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.

---

The light sensor binding looks fine to me. I didn't check the rest.

#4 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

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

---
 .../leds/backlight/ti,lm3533-backlight.yaml   |  68 +++++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 +++++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++++++++++
 3 files changed, 304 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 +26 -0
new file mode 100644
index 000000000000..866b0fb8ed04
@@ -0,0 +1,68 @@
+# 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
<snip>
+  ti,pwm-config-mask:

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

Quoted 10 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +10 -0
+    $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

This is optional and the drive implements a default (zero) that is not documented here.

Is zero a sane default from a DT binding point of view?

Daniel.

#5 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

пт, 29 трав. 2026 р. о 12:51 Daniel Thompson <[email protected]> пише:

Quoted 64 lines · Svyatoslav Ryhel
Quoted 48 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.

---
 .../leds/backlight/ti,lm3533-backlight.yaml   |  68 +++++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 +++++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++++++++++
 3 files changed, 304 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 +26 -0
new file mode 100644
index 000000000000..866b0fb8ed04
@@ -0,0 +1,68 @@
+# 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
<snip>
+  ti,pwm-config-mask:

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

Quoted 10 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +10 -0
+    $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

This is optional and the drive implements a default (zero) that is not documented here.

Quoted 2 lines

Is zero a sane default from a DT binding point of view?

Yes, if property is missing then PWM input is disabled which is equivalent to setting all bits to 0.

Quoted 2 lines

Daniel.

#6 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

Quoted 65 lines · Svyatoslav Ryhel

пт, 29 трав. 2026 р. о 12:51 Daniel Thompson <[email protected]> пише:

Quoted 64 lines · Svyatoslav Ryhel
Quoted 48 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.

---
 .../leds/backlight/ti,lm3533-backlight.yaml   |  68 +++++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 +++++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++++++++++
 3 files changed, 304 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 +26 -0
new file mode 100644
index 000000000000..866b0fb8ed04
@@ -0,0 +1,68 @@
+# 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
<snip>
+  ti,pwm-config-mask:

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

Quoted 10 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +10 -0
+    $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

This is optional and the drive implements a default (zero) that is not documented here.

Quoted 5 lines
Quoted 2 lines

Is zero a sane default from a DT binding point of view?

Yes, if property is missing then PWM input is disabled which is equivalent to setting all bits to 0.

So the default should be documented in the bindings?

Daniel.

#7 lore raw

Re: [PATCH v2 1/6] dt-bindings: leds: Document TI LM3533 LED controller

пт, 29 трав. 2026 р. о 13:46 Daniel Thompson <[email protected]> пише:

Quoted 67 lines · Svyatoslav Ryhel
Quoted 65 lines

пт, 29 трав. 2026 р. о 12:51 Daniel Thompson <[email protected]> пише:

Quoted 64 lines · Svyatoslav Ryhel
Quoted 48 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.

---
 .../leds/backlight/ti,lm3533-backlight.yaml   |  68 +++++++
 .../bindings/leds/ti,lm3533-leds.yaml         |  66 +++++++
 .../devicetree/bindings/leds/ti,lm3533.yaml   | 170 ++++++++++++++++++
 3 files changed, 304 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 +26 -0
new file mode 100644
index 000000000000..866b0fb8ed04
@@ -0,0 +1,68 @@
+# 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
<snip>
+  ti,pwm-config-mask:

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

Quoted 10 lines
Documentation/devicetree/bindings/leds/backlight/ti,lm3533-backlight.yaml new file +10 -0
+    $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

This is optional and the drive implements a default (zero) that is not documented here.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Is zero a sane default from a DT binding point of view?

Yes, if property is missing then PWM input is disabled which is equivalent to setting all bits to 0.

So the default should be documented in the bindings?

Ye, sure, I can do that.

Quoted 2 lines

Daniel.

#8 lore raw

PATCH v2 2/6 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. Additionally, optimize functions used only by platform data.

---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +39 -56
index 99f0b903018c..cbd337b73bd9 100644
@@ -16,15 +16,18 @@
 #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/slab.h>
 #include <linux/uaccess.h>
+#include <linux/units.h>
 
 #include <linux/mfd/lm3533.h>
 
 
-#define LM3533_ALS_RESISTOR_MIN			1
-#define LM3533_ALS_RESISTOR_MAX			127
+#define LM3533_ALS_RESISTOR_MIN			1575
+#define LM3533_ALS_RESISTOR_MAX			200000
 #define LM3533_ALS_CHANNEL_CURRENT_MAX		2
 #define LM3533_ALS_THRESH_MAX			3
 #define LM3533_ALS_ZONE_MAX			4
@@ -56,6 +59,9 @@ struct lm3533_als {
 
 	atomic_t zone;
 	struct mutex thresh_mutex;
+
+	bool pwm_mode;
+	u32 r_select;
 };
 
 
@@ -714,59 +720,33 @@ 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)
 {
-	u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-	u8 val;
+	struct device *dev = &als->pdev.dev;
 	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);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-								pwm_mode);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-	int ret;
-
-	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-		dev_err(&als->pdev->dev, "invalid resistor value\n");
-		return -EINVAL;
-	}
-
-	ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set resistor\n");
-		return ret;
-	}
+	device_property_read_u32(dev, "ti,resistor-value-ohm",
+				 &als->r_select);
 
-	return 0;
-}
+	als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+			      LM3533_ALS_RESISTOR_MAX);
+	als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);
 
-static int lm3533_als_setup(struct lm3533_als *als,
-			    const struct lm3533_als_platform_data *pdata)
-{
-	int ret;
+	als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-	ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+	ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+			    LM3533_ALS_INPUT_MODE_MASK : 0,
+			    LM3533_ALS_INPUT_MODE_MASK);
 	if (ret)
-		return ret;
+		return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+				     als->pwm_mode);
 
 	/* ALS input is always high impedance in PWM-mode. */
-	if (!pdata->pwm_mode) {
-		ret = lm3533_als_set_resistor(als, pdata->r_select);
+	if (!als->pwm_mode) {
+		ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+				   (u8)als->r_select);
 		if (ret)
-			return ret;
+			return dev_err_probe(dev, ret, "failed to set resistor\n");
 	}
 
 	return 0;
@@ -828,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;
@@ -838,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;
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
 	indio_dev->channels = lm3533_als_channels;
 	indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
 	indio_dev->name = dev_name(&pdev->dev);
-	iio_device_set_parent(indio_dev, pdev->dev.parent);
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	als = iio_priv(indio_dev);
 	als->lm3533 = lm3533;
 	als->pdev = pdev;
-	als->irq = lm3533->irq;
+	als->irq = platform_get_irq_optional(pdev, 0);
+
+	if (als->irq == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
 	atomic_set(&als->zone, 0);
 	mutex_init(&als->thresh_mutex);
 
 	platform_set_drvdata(pdev, indio_dev);
 
-	if (als->irq) {
+	if (als->irq > 0) {
 		ret = lm3533_als_setup_irq(als, indio_dev);
 		if (ret)
 			return ret;
 	}
 
-	ret = lm3533_als_setup(als, pdata);
+	ret = lm3533_als_setup(als);
 	if (ret)
 		goto err_free_irq;
 
@@ -907,9 +883,16 @@ static void lm3533_als_remove(struct platform_device *pdev)
 		free_irq(als->irq, indio_dev);
 }
 
+static const struct of_device_id lm3533_als_match_table[] = {
+	{ .compatible = "ti,lm3533-als" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lm3533_als_match_table);
+
 static struct platform_driver lm3533_als_driver = {
 	.driver	= {
 		.name	= "lm3533-als",
+		.of_match_table = lm3533_als_match_table,
 	},
 	.probe		= lm3533_als_probe,
 	.remove		= lm3533_als_remove,
drivers/leds/leds-lm3533.c +35 -16

121 lines not on this page · raw message

drivers/mfd/lm3533-core.c +96 -172

365 lines not on this page · raw message

drivers/video/backlight/lm3533_bl.c +36 -16

116 lines not on this page · raw message

include/linux/mfd/lm3533.h +6 -45

69 lines not on this page · raw message

Signature · 1 line
2.51.0
#9 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] The `lm3533_cells` array is allocated on the stack but never zero-initialized, causing it to…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] The lm3533_cells array is allocated on the stack but never zero-initialized, causing it to contain random garbage data.
- [High] The cell iterator logic increments the count variable for every child node unconditionally, even if the node does not match any expected compatible strings.
- [Medium] The ALS driver attempts to free an invalid IRQ number on error paths and during device removal when no IRQ is present.
- [Medium] Uninitialized stack memory is printed to the kernel log if fwnode_property_read_u32() fails to read the "reg" property.
- [Low] The patch introduces basic syntax and scoping errors in lm3533_als_setup() that completely prevent compilation.
- [Low] The backlight device tree reg property is validated against the wrong maximum limit in the MFD core.
- [Low] Passing an int * to a function expecting a u32 * causes compiler warnings/errors and breaks the build.
--

commit 9af50d17aae60cc268d70b24e00ddaa3a0500388
Author: Svyatoslav Ryhel <[email protected]>

mfd: lm3533: Convert to use OF bindings

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

Quoted 4 lines
drivers/iio/light/lm3533-als.c +0 -0
index 99f0b903018cf..cbd337b73bd9f 100644

[ ... ]

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -3
@@ -714,59 +720,33 @@ 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)
 {
-	u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-	u8 val;
+	struct device *dev = &als->pdev.dev;

[Severity: Low]
Does this syntax cause a build error? The pointer als->pdev requires the -> operator to access dev, like &als->pdev->dev.

Quoted 38 lines
drivers/iio/light/lm3533-als.c +4 -31
 	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);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-								pwm_mode);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-	int ret;
-
-	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-		dev_err(&als->pdev->dev, "invalid resistor value\n");
-		return -EINVAL;
-	}
-
-	ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set resistor\n");
-		return ret;
-	}
+	device_property_read_u32(dev, "ti,resistor-value-ohm",
+				 &als->r_select);
 
-	return 0;
-}
+	als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+			      LM3533_ALS_RESISTOR_MAX);

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +3 -5
+	als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);
 
-static int lm3533_als_setup(struct lm3533_als *als,
-			    const struct lm3533_als_platform_data *pdata)
-{
-	int ret;
+	als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-	ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+	ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?

[Severity: Low]
Will this fail to compile since lm3533 is undeclared in this scope? It appears this should use als->lm3533 instead.

[ ... ]

Quoted 15 lines
drivers/iio/light/lm3533-als.c +0 -6
@@ -838,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;
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
 	indio_dev->channels = lm3533_als_channels;

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +1 -2
 	indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
 	indio_dev->name = dev_name(&pdev->dev);
-	iio_device_set_parent(indio_dev, pdev->dev.parent);
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	als = iio_priv(indio_dev);
 	als->lm3533 = lm3533;
 	als->pdev = pdev;
-	als->irq = lm3533->irq;
+	als->irq = platform_get_irq_optional(pdev, 0);

[Severity: Medium]
Will this cause problems during error handling or device removal? platform_get_irq_optional() returns negative error codes when no IRQ is present. The existing cleanup paths check if (als->irq) which evaluates to true for negative numbers, causing it to call free_irq() with an invalid IRQ number. Should the cleanup checks be updated to
if (als->irq > 0)?

[ ... ]

Quoted 4 lines
drivers/mfd/lm3533-core.c +0 -0
index 0a2409d00b2e0..8495e91198711 100644

[ ... ]

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

Quoted 6 lines
drivers/mfd/lm3533-core.c +3 -2
-static int lm3533_device_init(struct lm3533 *lm3533)
+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_cells[LM3533_CELLS_MAX];

[Severity: High]
Does this array need to be zero-initialized? Because it's allocated on the stack, fields like num_resources and resources will contain garbage memory. When mfd_add_devices() processes it, could this lead to wild pointer dereferences?

Quoted 35 lines
drivers/mfd/lm3533-core.c +8 -22
+	u32 count = 0, reg;
 	int ret;
 
-	dev_dbg(lm3533->dev, "%s\n", __func__);
-
-	if (!pdata) {
-		dev_err(lm3533->dev, "no platform data\n");
-		return -EINVAL;
+	lm3533_enable(lm3533);
 
-	lm3533->hwen = devm_gpiod_get(lm3533->dev, NULL, GPIOD_OUT_LOW);
-	if (IS_ERR(lm3533->hwen))
-		return dev_err_probe(lm3533->dev, PTR_ERR(lm3533->hwen), "failed to request HWEN GPIO\n");
-	gpiod_set_consumer_name(lm3533->hwen, "lm3533-hwen");
-
-	lm3533_enable(lm3533);
-
-	ret = lm3533_device_setup(lm3533, pdata);
-	if (ret)
+	device_for_each_child_node_scoped(lm3533->dev, child) {
+		if (!fwnode_device_is_available(child))
+			continue;
 
-	lm3533_device_als_init(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;
+		if (count >= LM3533_CELLS_MAX)
+			break;
 
+		if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {

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

Quoted 10 lines
drivers/mfd/lm3533-core.c +8 -0
+			lm3533_cells[count].name = "lm3533-als";
+			lm3533_cells[count].id = PLATFORM_DEVID_NONE;
+			lm3533_cells[count].of_compatible = "ti,lm3533-als";
 
+			lm3533->have_als = true;
+		}
 
+		if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
+			ret = fwnode_property_read_u32(child, "reg", &reg);
+			if (ret || reg > LM3533_HVLED_ID_MAX) {

[Severity: Low]
Is LM3533_HVLED_ID_MAX the correct boundary to check here? The backlight IDs should typically be validated against LM3533_BL_ID_MAX. Since LM3533_HVLED_ID_MAX is 2, it would allow invalid backlight IDs to bypass this check.

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

Quoted 1 line
drivers/mfd/lm3533-core.c +1 -0
+				dev_err(dev, "invalid backlight reg %d\n", reg);

[Severity: Medium]
If fwnode_property_read_u32() returns an error, reg remains uninitialized. Could this print stack garbage memory to the kernel log?

Quoted 16 lines
drivers/mfd/lm3533-core.c +13 -0
+				continue;
+			}
 
+			lm3533_cells[count].name = "lm3533-backlight";
+			lm3533_cells[count].id = reg;
+			lm3533_cells[count].of_compatible = "ti,lm3533-backlight";
 
+			lm3533->have_backlights = true;
+		}
 
+		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 reg %d\n", reg);
+				continue;

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

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

[Severity: High]
Does count increment unconditionally even if the child node didn't match any of the compatible strings? If an unrelated child node is present, it would increment count while leaving the lm3533_cells[count] entirely unpopulated. When mfd_add_devices() is called, this could result in a NULL pointer dereference on the .name field.

[ ... ]

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index babfd3ceec866..42da652df58d9 100644

[ ... ]

Quoted 9 lines
drivers/video/backlight/lm3533_bl.c +5 -0
@@ -295,13 +293,20 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
 	bl->cb.dev = NULL;			/* until registered */
 
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+			      pdev->name, pdev->id);
+	if (!name)
+		return -ENOMEM;
+

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

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +3 -4
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
-	props.brightness = pdata->default_brightness;
-	bd = devm_backlight_device_register(&pdev->dev, pdata->name,
-					pdev->dev.parent, bl, &lm3533_bl_ops,
-					&props);
+	props.brightness = LM3533_BL_MAX_BRIGHTNESS;
+	device_property_read_u32(&pdev->dev, "default-brightness",
+				 &props.brightness);

[Severity: Low]
Will this pass an incompatible pointer type? props.brightness is defined as an int in struct backlight_properties, but device_property_read_u32() expects a u32 pointer. This could cause compiler warnings or errors.

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

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

In reply to Svyatoslav Ryhel
Quoted 3 lines · On Thu, 28 May 2026 16:51:19 +0300 Svyatoslav Ryhel <[email protected]> wrote:

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that as a precursor patch to make the rest much more readable.

Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-	u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-	u8 val;
+	struct device *dev = &als->pdev.dev;
 	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);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-								pwm_mode);
-		return ret;
-	}
-
-	return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-	int ret;
-
-	if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-		dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-		return -EINVAL;
-	}
-
-	ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-	if (ret) {
-		dev_err(&als->pdev->dev, "failed to set resistor\n");
-		return ret;
-	}
+	device_property_read_u32(dev, "ti,resistor-value-ohm",
+				 &als->r_select);

Does this have a default? If so the pattern we've recently be setting on for IIO is

	if (device_property_present(dev, "ti,resistor-value-ohm"))
		ret = device_property_read_u32();
		if (ret) //corrupt property in some fashion
			return ret;
	} else {
		//set default
	}

If there is no default then check it unconditionally.

Quoted 6 lines
drivers/iio/light/lm3533-als.c +3 -2
-	return 0;
-}
+	als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+			      LM3533_ALS_RESISTOR_MAX);
+	als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);

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 +3 -5
 
-static int lm3533_als_setup(struct lm3533_als *als,
-			    const struct lm3533_als_platform_data *pdata)
-{
-	int ret;
+	als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-	ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+	ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+			    LM3533_ALS_INPUT_MODE_MASK : 0,

That's ugly. Better as

	ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
			    als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Though if there wasn't a layer hiding the regmap, it could just have been

	ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
				 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

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

Quoted 12 lines
drivers/iio/light/lm3533-als.c +6 -3
+			    LM3533_ALS_INPUT_MODE_MASK);
 	if (ret)
-		return ret;
+		return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+				     als->pwm_mode);
 
 	/* ALS input is always high impedance in PWM-mode. */
-	if (!pdata->pwm_mode) {
-		ret = lm3533_als_set_resistor(als, pdata->r_select);
+	if (!als->pwm_mode) {
+		ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+				   (u8)als->r_select);

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

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

Quoted 12 lines
drivers/iio/light/lm3533-als.c +1 -2
 		if (ret)
-			return ret;
+			return dev_err_probe(dev, ret, "failed to set resistor\n");
 	}
 
 	return 0;
 
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
 	indio_dev->channels = lm3533_als_channels;
 	indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
 	indio_dev->name = dev_name(&pdev->dev);
-	iio_device_set_parent(indio_dev, pdev->dev.parent);

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

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

Quoted 11 lines
drivers/leds/leds-lm3533.c +2 -1
index 45795f2a1042..d707d43d5526 100644
 
 
 	led->cb.dev = led->cdev.dev;
 
-	ret = lm3533_led_setup(led, pdata);
+	device_property_read_u32(&pdev->dev, "led-max-microamp",
+				 &led->max_current);

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

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

Quoted 2 lines
drivers/leds/leds-lm3533.c +2 -0
+	led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+				 LM3533_LED_MAX_CURRENT_MAX);

I didn't look any further (busy day!)

#11 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

чт, 28 трав. 2026 р. о 17:50 Jonathan Cameron <[email protected]> пише:

Quoted 4 lines

On Thu, 28 May 2026 16:51:19 +0300
Svyatoslav Ryhel <[email protected]> wrote:

Quoted 9 lines
Quoted 3 lines

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that as a precursor patch to make the rest much more readable.

I can add you preferences into this commit, I don't mind.

Quoted 63 lines
Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-     u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-     u8 val;
+     struct device *dev = &als->pdev.dev;
      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);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-                                                             pwm_mode);
-             return ret;
-     }
-
-     return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-     int ret;
-
-     if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-             dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-             return -EINVAL;
-     }
-
-     ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set resistor\n");
-             return ret;
-     }
+     device_property_read_u32(dev, "ti,resistor-value-ohm",
+                              &als->r_select);

Does this have a default? If so the pattern we've recently be setting on for IIO is

Quoted 8 lines
        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

Quoted 14 lines
Quoted 14 lines
drivers/iio/light/lm3533-als.c +4 -6
-     return 0;
-}
+     als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+                           LM3533_ALS_RESISTOR_MAX);
+     als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
+     als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
Quoted 9 lines

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

Quoted 3 lines
drivers/iio/light/lm3533-als.c +2 -1
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+     ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+                         LM3533_ALS_INPUT_MODE_MASK : 0,

That's ugly. Better as

        ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
                            als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Yes sure, just followed 80 char limit.

Quoted 11 lines

Though if there wasn't a layer hiding the regmap, it could just have been

        ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
                                 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

Removing of lm3533_update layer is not the scope of this patchset.

Quoted 14 lines

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

Quoted 13 lines
drivers/iio/light/lm3533-als.c +6 -3
+                         LM3533_ALS_INPUT_MODE_MASK);
      if (ret)
-             return ret;
+             return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+                                  als->pwm_mode);
 
      /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
+     if (!als->pwm_mode) {
+             ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+                                (u8)als->r_select);
Quoted 3 lines

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

Removing of lm3533_write layer is not the scope of this patchset.

Quoted 7 lines
Quoted 6 lines
drivers/iio/light/lm3533-als.c +1 -1
              if (ret)
-                     return ret;
+                     return dev_err_probe(dev, ret, "failed to set resistor\n");
      }
 
      return 0;
Quoted 9 lines

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

Quoted 5 lines
drivers/iio/light/lm3533-als.c +0 -1
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Quoted 7 lines
Quoted 7 lines
drivers/leds/leds-lm3533.c +0 -0
index 45795f2a1042..d707d43d5526 100644
Quoted 9 lines

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

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

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

clamp will ensure that led->max_current will be set to LM3533_LED_MAX_CURRENT_MIN regardless if it it present

Quoted 4 lines

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

Quoted 2 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+                              LM3533_LED_MAX_CURRENT_MAX);

I didn't look any further (busy day!)

maintainer
#12 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

Quoted 12 lines · On Thu, 28 May 2026 18:03:31 +0300 Svyatoslav Ryhel <[email protected]> wrote:

чт, 28 трав. 2026 р. о 17:50 Jonathan Cameron <[email protected]> пише:

Quoted 11 lines
Quoted 3 lines · On Thu, 28 May 2026 16:51:19 +0300 Svyatoslav Ryhel <[email protected]> wrote:

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that

Gah. I write gibberish after too much reviewing. having/helping!

Quoted 77 lines
Quoted 2 lines

as a precursor patch to make the rest much more readable.

I can add you preferences into this commit, I don't mind.

Quoted 63 lines
Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-     u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-     u8 val;
+     struct device *dev = &als->pdev.dev;
      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);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-                                                             pwm_mode);
-             return ret;
-     }
-
-     return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-     int ret;
-
-     if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-             dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-             return -EINVAL;
-     }
-
-     ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set resistor\n");
-             return ret;
-     }
+     device_property_read_u32(dev, "ti,resistor-value-ohm",
+                              &als->r_select);  

Does this have a default? If so the pattern we've recently be setting on for IIO is

Quoted 8 lines
        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

Quoted 3 lines

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

I don't see that default in the binding doc and relying in the 0 being clamped isn't particularly readable - I'd set it explicitly.

Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
drivers/iio/light/lm3533-als.c +3 -2
-     return 0;
-}
+     als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+                           LM3533_ALS_RESISTOR_MAX);
+     als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);

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 +3 -5
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
+     als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+     ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+                         LM3533_ALS_INPUT_MODE_MASK : 0,  

That's ugly. Better as

Quoted 14 lines
Quoted 3 lines
        ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
                            als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Yes sure, just followed 80 char limit.

Quoted 8 lines

Though if there wasn't a layer hiding the regmap, it could just have been

        ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
                                 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch

smashing. (this definitely wasn't my best effort at English!)

Quoted 5 lines
Quoted 3 lines

that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

Removing of lm3533_update layer is not the scope of this patchset.

Understood. I'm fine with just the refactor you are doing brought out as a precursor patch.

Quoted 38 lines
Quoted 15 lines
Quoted 4 lines
drivers/iio/light/lm3533-als.c +1 -0
+                         LM3533_ALS_INPUT_MODE_MASK);
      if (ret)

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +5 -3
-             return ret;
+             return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+                                  als->pwm_mode);
 
      /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
+     if (!als->pwm_mode) {
+             ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+                                (u8)als->r_select);  
Quoted 3 lines

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

Removing of lm3533_write layer is not the scope of this patchset.

Quoted 7 lines
Quoted 6 lines
drivers/iio/light/lm3533-als.c +1 -1
              if (ret)
-                     return ret;
+                     return dev_err_probe(dev, ret, "failed to set resistor\n");
      }
 
      return 0;  
Quoted 9 lines

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

Quoted 5 lines
drivers/iio/light/lm3533-als.c +0 -1
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);  

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

Quoted 4 lines

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Is there any risk anyone was using the canonical path to get to the iio dev? /sys/bus/platform/devices/..../iio\:deviceX
This is technically an ABI change be it a subtle one.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
drivers/leds/leds-lm3533.c +2 -1
index 45795f2a1042..d707d43d5526 100644
 
 
      led->cb.dev = led->cdev.dev;
 
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);  
Quoted 6 lines
Quoted 3 lines

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

clamp will ensure that led->max_current will be set to LM3533_LED_MAX_CURRENT_MIN regardless if it it present

As above, I'd prefer it set explicitly.

Quoted 6 lines
Quoted 5 lines

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

Quoted 3 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+                              LM3533_LED_MAX_CURRENT_MAX);  

I didn't look any further (busy day!)

#13 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

пт, 29 трав. 2026 р. о 12:08 Jonathan Cameron <[email protected]> пише:

Quoted 96 lines
Quoted 12 lines · On Thu, 28 May 2026 18:03:31 +0300 Svyatoslav Ryhel <[email protected]> wrote:

чт, 28 трав. 2026 р. о 17:50 Jonathan Cameron <[email protected]> пише:

Quoted 11 lines
Quoted 3 lines · On Thu, 28 May 2026 16:51:19 +0300 Svyatoslav Ryhel <[email protected]> wrote:

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that

Gah. I write gibberish after too much reviewing. having/helping!

Quoted 77 lines
Quoted 2 lines

as a precursor patch to make the rest much more readable.

I can add you preferences into this commit, I don't mind.

Quoted 71 lines
Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-     u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-     u8 val;
+     struct device *dev = &als->pdev.dev;
      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);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-                                                             pwm_mode);
-             return ret;
-     }
-
-     return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-     int ret;
-
-     if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-             dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-             return -EINVAL;
-     }
-
-     ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set resistor\n");
-             return ret;
-     }
+     device_property_read_u32(dev, "ti,resistor-value-ohm",
+                              &als->r_select);

Does this have a default? If so the pattern we've recently be setting on for IIO is

        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

Quoted 7 lines
Quoted 3 lines

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

I don't see that default in the binding doc and relying in the 0 being clamped isn't particularly readable - I'd set it explicitly.

Oh, ye, my bad. Schema enforces one of props to be present and if pwn is present then resistor is ignored. What if I move resistor reading, clamping and conversion under !als->pwm_mode check? Then resistor must be present and hence must be checked unconditionally.

Additionally, I can comment original lm3533_als_setup with #if 0 #endif then git formatting will be much cleaner and easier to review, and once we all come to result I will just remove entire commented block and Lee can pick clean commits.

Quoted 39 lines
Quoted 22 lines
Quoted 22 lines
Quoted 9 lines
drivers/iio/light/lm3533-als.c +3 -2
-     return 0;
-}
+     als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+                           LM3533_ALS_RESISTOR_MAX);
+     als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);

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 +3 -5
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
+     als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+     ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+                         LM3533_ALS_INPUT_MODE_MASK : 0,

That's ugly. Better as

Quoted 14 lines
Quoted 3 lines
        ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
                            als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Yes sure, just followed 80 char limit.

Quoted 8 lines

Though if there wasn't a layer hiding the regmap, it could just have been

        ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
                                 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch

smashing. (this definitely wasn't my best effort at English!)

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

Removing of lm3533_update layer is not the scope of this patchset.

Understood. I'm fine with just the refactor you are doing brought out as a precursor patch.

I have looked into removing wrappers too. That seems to be less a hassle that I anticipated, so I will include regmap switch in the v2.

Quoted 38 lines
Quoted 38 lines
Quoted 15 lines
Quoted 4 lines
drivers/iio/light/lm3533-als.c +1 -0
+                         LM3533_ALS_INPUT_MODE_MASK);
      if (ret)

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +5 -3
-             return ret;
+             return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+                                  als->pwm_mode);
 
      /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
+     if (!als->pwm_mode) {
+             ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+                                (u8)als->r_select);
Quoted 3 lines

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

Removing of lm3533_write layer is not the scope of this patchset.

Quoted 16 lines

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

Quoted 12 lines
drivers/iio/light/lm3533-als.c +1 -2
              if (ret)
-                     return ret;
+                     return dev_err_probe(dev, ret, "failed to set resistor\n");
      }
 
      return 0;
 
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

Quoted 9 lines
Quoted 4 lines

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Is there any risk anyone was using the canonical path to get to the iio dev? /sys/bus/platform/devices/..../iio\:deviceX
This is technically an ABI change be it a subtle one.

Linux kernel has no users of this driver, and it is in "stale" state for more then 2 years (maybe even longer). I have cc'd Johan Hovold.

https://lore.kernel.org/lkml/[email protected]/

This this 2 y. o. discussion and there were no actions ore movements. I assume this driver in its current form has no more users. This does not mean that it cannot be revived though.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/leds/leds-lm3533.c +2 -1
index 45795f2a1042..d707d43d5526 100644
 
 
      led->cb.dev = led->cdev.dev;
 
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

clamp will ensure that led->max_current will be set to LM3533_LED_MAX_CURRENT_MIN regardless if it it present

As above, I'd prefer it set explicitly.

I understand your position and I am not denying it for ALS part, but LEDs don't belong to IIO subsystem and different subsystem maintainers may have drastically different preferences and requirements (ugh, PTSD in its full glory).

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

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

Quoted 3 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+                              LM3533_LED_MAX_CURRENT_MAX);

I didn't look any further (busy day!)

maintainer
#14 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

Quoted 101 lines · On Fri, 29 May 2026 12:39:56 +0300 Svyatoslav Ryhel <[email protected]> wrote:

пт, 29 трав. 2026 р. о 12:08 Jonathan Cameron <[email protected]> пише:

Quoted 100 lines
Quoted 12 lines · On Thu, 28 May 2026 18:03:31 +0300 Svyatoslav Ryhel <[email protected]> wrote:

чт, 28 трав. 2026 р. о 17:50 Jonathan Cameron <[email protected]> пише:

Quoted 11 lines
Quoted 3 lines · On Thu, 28 May 2026 16:51:19 +0300 Svyatoslav Ryhel <[email protected]> wrote:

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that

Gah. I write gibberish after too much reviewing. having/helping!

Quoted 80 lines
Quoted 2 lines

as a precursor patch to make the rest much more readable.

I can add you preferences into this commit, I don't mind.

Quoted 63 lines
Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-     u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-     u8 val;
+     struct device *dev = &als->pdev.dev;
      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);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-                                                             pwm_mode);
-             return ret;
-     }
-
-     return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-     int ret;
-
-     if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-             dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-             return -EINVAL;
-     }
-
-     ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set resistor\n");
-             return ret;
-     }
+     device_property_read_u32(dev, "ti,resistor-value-ohm",
+                              &als->r_select);  

Does this have a default? If so the pattern we've recently be setting on for IIO is

Quoted 8 lines
        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

Quoted 8 lines
Quoted 3 lines

I don't see that default in the binding doc and relying in the 0 being clamped isn't particularly readable - I'd set it explicitly.

Oh, ye, my bad. Schema enforces one of props to be present and if pwn is present then resistor is ignored. What if I move resistor reading, clamping and conversion under !als->pwm_mode check? Then resistor must be present and hence must be checked unconditionally.

Sounds good.

Quoted 5 lines

Additionally, I can comment original lm3533_als_setup with #if 0 #endif then git formatting will be much cleaner and easier to review, and once we all come to result I will just remove entire commented block and Lee can pick clean commits.

No don't do that. If you flatten the two helpers as a precursor patch then the changes in here will be easier to review anyway.

Quoted 44 lines
Quoted 44 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
drivers/iio/light/lm3533-als.c +3 -2
-     return 0;
-}
+     als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+                           LM3533_ALS_RESISTOR_MAX);
+     als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);

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 +3 -5
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
+     als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+     ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+                         LM3533_ALS_INPUT_MODE_MASK : 0,  

That's ugly. Better as

Quoted 14 lines
Quoted 3 lines
        ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
                            als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Yes sure, just followed 80 char limit.

Quoted 8 lines

Though if there wasn't a layer hiding the regmap, it could just have been

        ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
                                 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch

smashing. (this definitely wasn't my best effort at English!)

Quoted 4 lines
Quoted 3 lines

that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Removing of lm3533_update layer is not the scope of this patchset.

Understood. I'm fine with just the refactor you are doing brought out as a precursor patch.

I have looked into removing wrappers too. That seems to be less a hassle that I anticipated, so I will include regmap switch in the v2.

Ah ok. Even better.

Quoted 49 lines
Quoted 39 lines
Quoted 39 lines
Quoted 16 lines
Quoted 5 lines
drivers/iio/light/lm3533-als.c +1 -0
+                         LM3533_ALS_INPUT_MODE_MASK);
      if (ret)

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +5 -3
-             return ret;
+             return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+                                  als->pwm_mode);
 
      /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
+     if (!als->pwm_mode) {
+             ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+                                (u8)als->r_select);  
Quoted 3 lines

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

Removing of lm3533_write layer is not the scope of this patchset.

Quoted 16 lines

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

Quoted 12 lines
drivers/iio/light/lm3533-als.c +1 -2
              if (ret)
-                     return ret;
+                     return dev_err_probe(dev, ret, "failed to set resistor\n");
      }
 
      return 0;  
 
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);  

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

Quoted 9 lines
Quoted 4 lines

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Is there any risk anyone was using the canonical path to get to the iio dev? /sys/bus/platform/devices/..../iio\:deviceX
This is technically an ABI change be it a subtle one.

Quoted 8 lines

Linux kernel has no users of this driver, and it is in "stale" state for more then 2 years (maybe even longer). I have cc'd Johan Hovold.

https://lore.kernel.org/lkml/[email protected]/

This this 2 y. o. discussion and there were no actions ore movements. I assume this driver in its current form has no more users. This does not mean that it cannot be revived though.

So, just to check, are you a user of this code or is this more trying to help out with old code?

Jonathan

Quoted 38 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
drivers/leds/leds-lm3533.c +2 -1
index 45795f2a1042..d707d43d5526 100644
 
 
      led->cb.dev = led->cdev.dev;
 
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);  
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

clamp will ensure that led->max_current will be set to LM3533_LED_MAX_CURRENT_MIN regardless if it it present

As above, I'd prefer it set explicitly.

I understand your position and I am not denying it for ALS part, but LEDs don't belong to IIO subsystem and different subsystem maintainers may have drastically different preferences and requirements (ugh, PTSD in its full glory).

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

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

Quoted 3 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+                              LM3533_LED_MAX_CURRENT_MAX);  

I didn't look any further (busy day!)

#15 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

пт, 29 трав. 2026 р. о 13:48 Jonathan Cameron <[email protected]> пише:

Quoted 117 lines
Quoted 101 lines · On Fri, 29 May 2026 12:39:56 +0300 Svyatoslav Ryhel <[email protected]> wrote:

пт, 29 трав. 2026 р. о 12:08 Jonathan Cameron <[email protected]> пише:

Quoted 100 lines
Quoted 12 lines · On Thu, 28 May 2026 18:03:31 +0300 Svyatoslav Ryhel <[email protected]> wrote:

чт, 28 трав. 2026 р. о 17:50 Jonathan Cameron <[email protected]> пише:

Quoted 11 lines
Quoted 3 lines · On Thu, 28 May 2026 16:51:19 +0300 Svyatoslav Ryhel <[email protected]> wrote:

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

At least the IIO ones would have made much the same amount of sense for dt, just that they weren't having in the first place. I'd prefer that

Gah. I write gibberish after too much reviewing. having/helping!

Quoted 80 lines
Quoted 2 lines

as a precursor patch to make the rest much more readable.

I can add you preferences into this commit, I don't mind.

Quoted 63 lines
Quoted 2 lines

I only looked in detail at the iio bit. A few changes requested.

Quoted 46 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----
 5 files changed, 212 insertions(+), 305 deletions(-)
drivers/iio/light/lm3533-als.c +2 -24
index 99f0b903018c..cbd337b73bd9 100644
@@ -714,59 +720,33 @@ 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)
 {
-     u8 mask = LM3533_ALS_INPUT_MODE_MASK;
-     u8 val;
+     struct device *dev = &als->pdev.dev;
      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);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set input mode %d\n",
-                                                             pwm_mode);
-             return ret;
-     }
-
-     return 0;
-}
-
-static int lm3533_als_set_resistor(struct lm3533_als *als, u8 val)
-{
-     int ret;
-
-     if (val < LM3533_ALS_RESISTOR_MIN || val > LM3533_ALS_RESISTOR_MAX) {
-             dev_err(&als->pdev->dev, "invalid resistor value\n");

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +2 -8
-             return -EINVAL;
-     }
-
-     ret = lm3533_write(als->lm3533, LM3533_REG_ALS_RESISTOR_SELECT, val);
-     if (ret) {
-             dev_err(&als->pdev->dev, "failed to set resistor\n");
-             return ret;
-     }
+     device_property_read_u32(dev, "ti,resistor-value-ohm",
+                              &als->r_select);

Does this have a default? If so the pattern we've recently be setting on for IIO is

Quoted 8 lines
        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

Quoted 8 lines
Quoted 3 lines

I don't see that default in the binding doc and relying in the 0 being clamped isn't particularly readable - I'd set it explicitly.

Oh, ye, my bad. Schema enforces one of props to be present and if pwn is present then resistor is ignored. What if I move resistor reading, clamping and conversion under !als->pwm_mode check? Then resistor must be present and hence must be checked unconditionally.

Sounds good.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Additionally, I can comment original lm3533_als_setup with #if 0 #endif then git formatting will be much cleaner and easier to review, and once we all come to result I will just remove entire commented block and Lee can pick clean commits.

No don't do that. If you flatten the two helpers as a precursor patch then the changes in here will be easier to review anyway.

By "flatten the two helpers" you mean incorporate lm3533_als_set_input_mode and lm3533_als_set_resistor into lm3533_als_setup first and then convert it to use DT? I am asking, just to be sure.

Quoted 107 lines
Quoted 44 lines
Quoted 44 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
drivers/iio/light/lm3533-als.c +3 -2
-     return 0;
-}
+     als->r_select = clamp(als->r_select, LM3533_ALS_RESISTOR_MIN,
+                           LM3533_ALS_RESISTOR_MAX);
+     als->r_select = DIV_ROUND_UP(2 * MICRO, 10 * als->r_select);

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 +3 -5
 
-static int lm3533_als_setup(struct lm3533_als *als,
-                         const struct lm3533_als_platform_data *pdata)
-{
-     int ret;
+     als->pwm_mode = device_property_read_bool(dev, "ti,pwm-mode");
 
-     ret = lm3533_als_set_input_mode(als, pdata->pwm_mode);
+     ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF, als->pwm_mode ?
+                         LM3533_ALS_INPUT_MODE_MASK : 0,

That's ugly. Better as

Quoted 14 lines
Quoted 3 lines
        ret = lm3533_update(lm3533, LM3533_REG_ALS_CONF,
                            als->pwm_mode ? LM3533_ALS_INPUT_MODE_MASK : 0,

Yes sure, just followed 80 char limit.

Quoted 8 lines

Though if there wasn't a layer hiding the regmap, it could just have been

        ret = regmap_assign_bits(lm3533->regmap, LM3533_REG_ALS_CONF,
                                 LM3533_ALS_INPUT_MODE_MASK, als->pwm_mode);;

which would have been nicer.

I'm not particularly keen on the swashing of the helpers being in a patch

smashing. (this definitely wasn't my best effort at English!)

Quoted 4 lines
Quoted 3 lines

that is about switching the binding type as feels largely unrelated. Should really have been a precursor, easier to review patch.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Removing of lm3533_update layer is not the scope of this patchset.

Understood. I'm fine with just the refactor you are doing brought out as a precursor patch.

I have looked into removing wrappers too. That seems to be less a hassle that I anticipated, so I will include regmap switch in the v2.

Ah ok. Even better.

Quoted 52 lines
Quoted 39 lines
Quoted 39 lines
Quoted 16 lines
Quoted 5 lines
drivers/iio/light/lm3533-als.c +1 -0
+                         LM3533_ALS_INPUT_MODE_MASK);
      if (ret)

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

Quoted 10 lines
drivers/iio/light/lm3533-als.c +5 -3
-             return ret;
+             return dev_err_probe(dev, ret, "failed to set input mode %d\n",
+                                  als->pwm_mode);
 
      /* ALS input is always high impedance in PWM-mode. */
-     if (!pdata->pwm_mode) {
-             ret = lm3533_als_set_resistor(als, pdata->r_select);
+     if (!als->pwm_mode) {
+             ret = lm3533_write(lm3533, LM3533_REG_ALS_RESISTOR_SELECT,
+                                (u8)als->r_select);
Quoted 3 lines

Same applies here. Mostly an unrelated change as the only thing switching that is related to the patch is one parameter.

Removing of lm3533_write layer is not the scope of this patchset.

Quoted 16 lines

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

Quoted 12 lines
drivers/iio/light/lm3533-als.c +1 -2
              if (ret)
-                     return ret;
+                     return dev_err_probe(dev, ret, "failed to set resistor\n");
      }
 
      return 0;
 
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

Quoted 9 lines
Quoted 4 lines

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Is there any risk anyone was using the canonical path to get to the iio dev? /sys/bus/platform/devices/..../iio\:deviceX
This is technically an ABI change be it a subtle one.

Linux kernel has no users of this driver, and it is in "stale" state for more then 2 years (maybe even longer). I have cc'd Johan Hovold.

Quoted 9 lines
Quoted 5 lines

https://lore.kernel.org/lkml/[email protected]/

This this 2 y. o. discussion and there were no actions ore movements. I assume this driver in its current form has no more users. This does not mean that it cannot be revived though.

So, just to check, are you a user of this code or is this more trying to help out with old code?

I am not insane enough to get myself into all this conversion if I did not need it. This is one of 2 remaining gaps in support of LG P880/P895 I own and support. I would really like to finally mainline all the patches I have locally since maintaining them becomes quite troublesome with time and additional patches layering on top.

Quoted 41 lines

Jonathan

Quoted 38 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
drivers/leds/leds-lm3533.c +2 -1
index 45795f2a1042..d707d43d5526 100644
 
 
      led->cb.dev = led->cdev.dev;
 
-     ret = lm3533_led_setup(led, pdata);
+     device_property_read_u32(&pdev->dev, "led-max-microamp",
+                              &led->max_current);
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'd prefer explicit setting of the default to be visible before this, or the property_present pattern I mention in the IIO review above.

clamp will ensure that led->max_current will be set to LM3533_LED_MAX_CURRENT_MIN regardless if it it present

As above, I'd prefer it set explicitly.

I understand your position and I am not denying it for ALS part, but LEDs don't belong to IIO subsystem and different subsystem maintainers may have drastically different preferences and requirements (ugh, PTSD in its full glory).

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

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

Quoted 3 lines
drivers/leds/leds-lm3533.c +2 -0
+     led->max_current = clamp(led->max_current, LM3533_LED_MAX_CURRENT_MIN,
+                              LM3533_LED_MAX_CURRENT_MAX);

I didn't look any further (busy day!)

maintainer
#16 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

Quoted 31 lines
Quoted 31 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 9 lines
        if (device_property_present(dev, "ti,resistor-value-ohm"))
                ret = device_property_read_u32();
                if (ret) //corrupt property in some fashion
                        return ret;
        } else {
                //set default
        }

If there is no default then check it unconditionally.

default value is LM3533_ALS_RESISTOR_MIN and if no property is present clamp will ensure that als->r_select will be set to LM3533_ALS_RESISTOR_MIN

Quoted 8 lines
Quoted 3 lines

I don't see that default in the binding doc and relying in the 0 being clamped isn't particularly readable - I'd set it explicitly.

Oh, ye, my bad. Schema enforces one of props to be present and if pwn is present then resistor is ignored. What if I move resistor reading, clamping and conversion under !als->pwm_mode check? Then resistor must be present and hence must be checked unconditionally.

Sounds good.

Quoted 5 lines

Additionally, I can comment original lm3533_als_setup with #if 0 #endif then git formatting will be much cleaner and easier to review, and once we all come to result I will just remove entire commented block and Lee can pick clean commits.

Quoted 9 lines
Quoted 3 lines

No don't do that. If you flatten the two helpers as a precursor patch then the changes in here will be easier to review anyway.

By "flatten the two helpers" you mean incorporate lm3533_als_set_input_mode and lm3533_als_set_resistor into lm3533_als_setup first and then convert it to use DT? I am asking, just to be sure.

yes

Quoted 33 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

Review static int lm3533_als_probe(struct platform_device *pdev) · line 855

Quoted 5 lines
(quoted diff) +0 -1
@@ -852,25 +825,28 @@ static int lm3533_als_probe(struct platform_device *pdev)
      indio_dev->channels = lm3533_als_channels;
      indio_dev->num_channels = ARRAY_SIZE(lm3533_als_channels);
      indio_dev->name = dev_name(&pdev->dev);
-     iio_device_set_parent(indio_dev, pdev->dev.parent);  

I'm not sure why this was there in the first place. Hence not sure if it is safe to remove.

Quoted 9 lines
Quoted 4 lines

This is directly related to OF conversion. The iio_device_set_parent bound indio_dev to parent, and it causes problems with OF now since als output has its own node and binding it to parent if wrong. Same story for backlight and leds btw.

Is there any risk anyone was using the canonical path to get to the iio dev? /sys/bus/platform/devices/..../iio\:deviceX
This is technically an ABI change be it a subtle one.

Linux kernel has no users of this driver, and it is in "stale" state for more then 2 years (maybe even longer). I have cc'd Johan Hovold.

Quoted 9 lines
Quoted 5 lines

https://lore.kernel.org/lkml/[email protected]/

This this 2 y. o. discussion and there were no actions ore movements. I assume this driver in its current form has no more users. This does not mean that it cannot be revived though.

So, just to check, are you a user of this code or is this more trying to help out with old code?

Quoted 5 lines

I am not insane enough to get myself into all this conversion if I did not need it. This is one of 2 remaining gaps in support of LG P880/P895 I own and support. I would really like to finally mainline all the patches I have locally since maintaining them becomes quite troublesome with time and additional patches layering on top.

Excellent! There are some odd people out there who do start on this sort of thing despite no personal use case :)

Jonathan

#17 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

In reply to Svyatoslav Ryhel
Quoted 3 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. Additionally, optimize functions used only by platform data.

The last sentence is a little vague and makes us have to hunt for the changes in a relatively large patch. If it is referring to the change to common up the init and update code then it's would better to say that explicitly!

Quoted 7 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----

Just one comment for backlight, below:

Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index babfd3ceec86..42da652df58d 100644
@@ -295,13 +293,20 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
 	bl->cb.dev = NULL;			/* until registered */

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

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +5 -1
 
+	name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+			      pdev->name, pdev->id);
+	if (!name)
+		return -ENOMEM;
+
 	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_RAW;
 	props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
-	props.brightness = pdata->default_brightness;

Given the big changes to the driver is there any chance of putting a good value in props.scale (BACKLIGHT_SCALE_LINEAR or BACKLIGHT_SCALE_NON_LINEAR)?

If the difference between 50% and 100% *looks* like 50% then the scale is non-linear (since humn perception of brightness is not linear).

Daniel.

#18 lore raw

Re: [PATCH v2 2/6] mfd: lm3533: Convert to use OF bindings

пт, 29 трав. 2026 р. о 14:00 Daniel Thompson <[email protected]> пише:

Quoted 11 lines · Svyatoslav Ryhel
Quoted 3 lines

Since there are no users of this driver via platform data, remove the platform data support and switch to using Device Tree bindings. Additionally, optimize functions used only by platform data.

The last sentence is a little vague and makes us have to hunt for the changes in a relatively large patch. If it is referring to the change to common up the init and update code then it's would better to say that explicitly!

If I understood Jonathan properly, the last sentence will get its own patch.

Quoted 32 lines
Quoted 7 lines
---
 drivers/iio/light/lm3533-als.c      |  95 ++++------
 drivers/leds/leds-lm3533.c          |  51 ++++--
 drivers/mfd/lm3533-core.c           | 268 ++++++++++------------------
 drivers/video/backlight/lm3533_bl.c |  52 ++++--
 include/linux/mfd/lm3533.h          |  51 +-----

Just one comment for backlight, below:

Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index babfd3ceec86..42da652df58d 100644
@@ -295,13 +293,20 @@ static int lm3533_bl_probe(struct platform_device *pdev)
      bl->cb.id = lm3533_bl_get_ctrlbank_id(bl);
      bl->cb.dev = NULL;                      /* until registered */

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

Quoted 10 lines
drivers/video/backlight/lm3533_bl.c +5 -1
 
+     name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d",
+                           pdev->name, pdev->id);
+     if (!name)
+             return -ENOMEM;
+
      memset(&props, 0, sizeof(props));
      props.type = BACKLIGHT_RAW;
      props.max_brightness = LM3533_BL_MAX_BRIGHTNESS;
-     props.brightness = pdata->default_brightness;

Given the big changes to the driver is there any chance of putting a good value in props.scale (BACKLIGHT_SCALE_LINEAR or BACKLIGHT_SCALE_NON_LINEAR)?

Quoted 3 lines

If the difference between 50% and 100% *looks* like 50% then the scale is non-linear (since humn perception of brightness is not linear).

Yes! But not in this patch. This patchset has a dedicated patch implementing linear and non-linear configuration from tree which may include this configuration as well. No guarantees though, but I will keep in mind this request. Thanks!

Quoted 2 lines

Daniel.

#19 lore raw

PATCH v2 3/6 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 8495e9119871..519f8c16a3f3 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>
@@ -164,14 +165,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 {
@@ -324,7 +336,9 @@ static int lm3533_device_init(struct lm3533 *lm3533)
 	u32 count = 0, reg;
 	int ret;
 
-	lm3533_enable(lm3533);
+	ret = lm3533_enable(lm3533);
+	if (ret)
+		return ret;
 
 	device_for_each_child_node_scoped(lm3533->dev, child) {
 		if (!fwnode_device_is_available(child))
@@ -493,6 +507,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 3aa962d4c747..d751773fc92d 100644
@@ -21,6 +21,7 @@
 struct device;
 struct gpio_desc;
 struct regmap;
+struct regulator;
 
 struct lm3533 {
 	struct device *dev;
@@ -28,6 +29,7 @@ struct lm3533 {
 	struct regmap *regmap;
 
 	struct gpio_desc *hwen;
+	struct regulator *vin_supply;
 
 	u32 boost_ovp;
 	u32 boost_freq;
Signature · 1 line
2.51.0
#20 lore raw

Re: [PATCH v2 3/6] mfd: lm3533: Add support for VIN power supply

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The lm3533_cells array is allocated on the stack without initialization, leading to memory corruption and kernel panics. --

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

mfd: lm3533: Add support for VIN power supply

This commit adds support for a 2.7V-5.5V vin power supply to the lm3533 core driver. It acquires the regulator in the probe function and toggles it during the enable and disable sequences.

Quoted 4 lines
drivers/mfd/lm3533-core.c +0 -0
index 8495e91198711..519f8c16a3f35 100644

[ ... ]

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

Quoted 11 lines
drivers/mfd/lm3533-core.c +3 -1
@@ -324,7 +336,9 @@ static int lm3533_device_init(struct lm3533 *lm3533)
 	u32 count = 0, reg;
 	int ret;
 
-	lm3533_enable(lm3533);
+	ret = lm3533_enable(lm3533);
+	if (ret)
+		return ret;
 
 	device_for_each_child_node_scoped(lm3533->dev, child) {
 		if (!fwnode_device_is_available(child))

[Severity: High]
This isn't a bug introduced by this patch, but it was introduced earlier in this patch series (in "mfd: lm3533: Convert to use OF bindings") and remains unfixed.

Does this code pass uninitialized stack memory to the mfd core?

In lm3533_device_init(), the array is declared on the stack without zero initialization:

	struct mfd_cell lm3533_cells[LM3533_CELLS_MAX];

When processing the child nodes, only specific fields like name, id, and of_compatible are assigned. All other fields in the mfd_cell structs, such as pdata_size, resources, and num_resources, remain populated with uninitialized stack garbage.

When this array is passed to mfd_add_devices(), the mfd core processes these garbage values. If pdata_size contains a non-zero garbage value, mfd_add_device() will call kmemdup() on the garbage platform_data pointer, which could result in an immediate kernel panic.

Furthermore, if an available child node does not match any of the supported compatible strings, count is still incremented:

	device_for_each_child_node_scoped(lm3533->dev, child) {
		...
		if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
			...
		}
		...
		count++;
	}

Could this cause a completely uninitialized cell (with a garbage name pointer) to be processed? This could also lead to a crash during mfd registration.

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

PATCH v2 4/6 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 519f8c16a3f3..3cfdebf5fb52 100644
@@ -526,6 +526,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
 				   LM3533_BOOST_FREQ_MAX);
 	lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;
 
+	/* LM3533 and child devices do not use DMA */
+	i2c->dev.coherent_dma_mask = 0;
+	i2c->dev.dma_mask = &i2c->dev.coherent_dma_mask;
+
 	return lm3533_device_init(lm3533);
 }
 
Signature · 1 line
2.51.0
#22 lore raw

Re: [PATCH v2 4/6] mfd: lm3533: Set DMA mask

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The `lm3533_cells` array is allocated on the stack without being zero-initialized, and an…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The lm3533_cells array is allocated on the stack without being zero-initialized, and an unconditional count++ leads to uninitialized elements being passed to the MFD core, risking memory corruption or kernel panics.
- [Medium] An off-by-one error in the validation of the backlight reg property allows it to overlap with the LED reg address space.
--

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

mfd: lm3533: Set DMA mask

Missing coherent_dma_mask assigning triggers a warning in dmesg. This sets coherent_dma_mask to zero because both the core and cells do not utilize dma.

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

Quoted 13 lines
drivers/mfd/lm3533-core.c +4 -0
index 519f8c16a3f35..3cfdebf5fb52b 100644
@@ -526,6 +526,10 @@ static int lm3533_i2c_probe(struct i2c_client *i2c)
 				   LM3533_BOOST_FREQ_MAX);
 	lm3533->boost_freq = lm3533->boost_freq / (500 * KILO) - 1;
 
+	/* LM3533 and child devices do not use DMA */
+	i2c->dev.coherent_dma_mask = 0;
+	i2c->dev.dma_mask = &i2c->dev.coherent_dma_mask;
+
 	return lm3533_device_init(lm3533);

[Severity: High]
Does this call to lm3533_device_init() pass uninitialized elements to the mfd core? Looking at lm3533_device_init(), the lm3533_cells array is allocated on the stack without zero-initialization.

If a child node is present in the device tree that does not match any of the recognized compatible strings, the iteration loop skips the initialization blocks but still unconditionally executes count++, leaving the array element with stack garbage:

drivers/mfd/lm3533-core.c:lm3533_device_init() {
    struct mfd_cell lm3533_cells[LM3533_CELLS_MAX];
    u32 count = 0, reg;
    ...
    device_for_each_child_node_scoped(lm3533->dev, child) {
        if (!fwnode_device_is_available(child))
            continue;

        if (count >= LM3533_CELLS_MAX)
            break;

        if (fwnode_device_is_compatible(child, "ti,lm3533-als")) {
            ...
        }
        if (fwnode_device_is_compatible(child, "ti,lm3533-backlight")) {
            ...
        }
        if (fwnode_device_is_compatible(child, "ti,lm3533-leds")) {
            ...
        }

        count++;
    }
    ...
    ret = mfd_add_devices(dev, 0, lm3533_cells, count, NULL, 0, NULL);
}

When this array is passed to mfd_add_devices(), the mfd core will attempt to dereference a garbage pointer for the device name. Can this cause memory corruption or a kernel panic?

[Severity: Medium]
Can an invalid backlight reg value overlap with the LED reg address space? Looking at lm3533_device_init(), the validation allows reg = 2 to be accepted for a backlight:

drivers/mfd/lm3533-core.c:lm3533_device_init() {
        ...
        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 reg %d\n", reg);
                continue;
            }
        ...
}

LM3533_HVLED_ID_MAX is 2. This incorrectly allows reg = 2 to be accepted for a backlight, assigning it an ID of 2, even though the backlight driver only supports 2 control banks (IDs 0 and 1).

While the backlight child driver safely returns -EINVAL during probe when it encounters ID 2, should this check be reg >= LM3533_HVLED_ID_MAX to reject invalid device tree configurations early in the core driver?

Quoted 1 line
drivers/mfd/lm3533-core.c +0 -0
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#23 lore raw

PATCH v2 5/6 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. Additionally, update the linear sysfs code, which uses a similar coding pattern.

---
 drivers/video/backlight/lm3533_bl.c | 50 ++++++++++++++++-------------
 1 file changed, 27 insertions(+), 23 deletions(-)
drivers/video/backlight/lm3533_bl.c +27 -23
index 42da652df58d..c03d0d1667e4 100644
@@ -22,6 +22,7 @@
 #define LM3533_BL_MAX_BRIGHTNESS	255
 
 #define LM3533_REG_CTRLBANK_AB_BCONF	0x1a
+#define   CTRLBANK_AB_BCONF_MODE(n)	BIT(2 * (n) + 1)
 
 
 struct lm3533_bl {
@@ -32,6 +33,7 @@ struct lm3533_bl {
 
 	u32 max_current;
 	u32 pwm;
+	bool linear;
 };
 
 
@@ -135,8 +137,9 @@ static ssize_t show_linear(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
+	int id = lm3533_bl_get_ctrlbank_id(bl);
+	u8 mask = CTRLBANK_AB_BCONF_MODE(id);
 	u8 val;
-	u8 mask;
 	int linear;
 	int ret;
 
@@ -144,8 +147,6 @@ static ssize_t show_linear(struct device *dev,
 	if (ret)
 		return ret;
 
-	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
-
 	if (val & mask)
 		linear = 1;
 	else
@@ -159,23 +160,16 @@ static ssize_t store_linear(struct device *dev,
 					const char *buf, size_t len)
 {
 	struct lm3533_bl *bl = dev_get_drvdata(dev);
+	int id = lm3533_bl_get_ctrlbank_id(bl);
 	unsigned long linear;
-	u8 mask;
-	u8 val;
 	int ret;
 
 	if (kstrtoul(buf, 0, &linear))
 		return -EINVAL;
 
-	mask = 1 << (2 * lm3533_bl_get_ctrlbank_id(bl) + 1);
-
-	if (linear)
-		val = mask;
-	else
-		val = 0;
-
-	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF, val,
-									mask);
+	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF,
+			    linear ? CTRLBANK_AB_BCONF_MODE(id) : 0,
+			    CTRLBANK_AB_BCONF_MODE(id));
 	if (ret)
 		return ret;
 
@@ -253,8 +247,15 @@ static struct attribute_group lm3533_bl_attribute_group = {
 
 static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
+	int id = lm3533_bl_get_ctrlbank_id(bl);
 	int ret;
 
+	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF,
+			    bl->linear ? CTRLBANK_AB_BCONF_MODE(id) : 0,
+			    CTRLBANK_AB_BCONF_MODE(id));
+	if (ret)
+		return ret;
+
 	ret = lm3533_ctrlbank_set_max_current(&bl->cb, bl->max_current);
 	if (ret)
 		return ret;
@@ -317,14 +318,6 @@ 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);
-
 	device_property_read_u32(&pdev->dev, "led-max-microamp",
 				 &bl->max_current);
 	bl->max_current = clamp(bl->max_current, LM3533_LED_MAX_CURRENT_MIN,
@@ -333,9 +326,20 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->pwm = 0;
 	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &bl->pwm);
 
+	bl->linear = device_property_read_bool(&pdev->dev,
+					       "ti,linear-mapping-mode");
+
 	ret = lm3533_bl_setup(bl);
 	if (ret)
-		goto err_sysfs_remove;
+		return ret;
+
+	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_ctrlbank_enable(&bl->cb);
 	if (ret)
Signature · 1 line
2.51.0
#24 lore raw

Re: [PATCH v2 5/6] video: backlight: lm3533_bl: Set initial mapping mode from DT

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The backlight device is exposed to userspace before its hardware initialization is complete. --

commit 106cefce156b039f4639eecee3b1a98c82987da6
Author: Svyatoslav Ryhel <[email protected]>

video: backlight: lm3533_bl: Set initial mapping mode from DT

This commit adds support to obtain the initial mapping mode from DT instead of leaving it unconfigured. It also updates the linear sysfs code.

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index 42da652df58d9..c03d0d1667e42 100644

[ ... ]

Quoted 16 lines
drivers/video/backlight/lm3533_bl.c +0 -8
@@ -317,14 +318,6 @@ 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);
-
 	device_property_read_u32(&pdev->dev, "led-max-microamp",
 				 &bl->max_current);
 	bl->max_current = clamp(bl->max_current, LM3533_LED_MAX_CURRENT_MIN,

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

Quoted 7 lines
drivers/video/backlight/lm3533_bl.c +3 -0
@@ -333,9 +326,20 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->pwm = 0;
 	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &bl->pwm);
 
+	bl->linear = device_property_read_bool(&pdev->dev,
+					       "ti,linear-mapping-mode");
+
 	ret = lm3533_bl_setup(bl);

[Severity: High]
This is a pre-existing issue, but I noticed a potential race condition here with devm_backlight_device_register() being called earlier in this function.

When devm_backlight_device_register() is called, it creates the device in sysfs, exposes standard attributes like brightness, and immediately fires a KOBJ_ADD uevent.

Could a userspace daemon like systemd-backlight react to this uevent and write a saved brightness value concurrently with the rest of this probe function?

If that happens, it would trigger lm3533_bl_ops.update_status, which calls lm3533_ctrlbank_set_brightness() to configure the hardware to drive the LEDs.

Because the driver has not yet read device tree limits like led-max-microamp and applied them via lm3533_bl_setup() and lm3533_ctrlbank_set_max_current(), could driving the LEDs before configuring the hardware's maximum safe current limit result in physical hardware damage?

Quoted 11 lines
drivers/video/backlight/lm3533_bl.c +9 -1
 	if (ret)
-		goto err_sysfs_remove;
+		return ret;
+
+	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);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#25 lore raw

Re: [PATCH v2 5/6] video: backlight: lm3533_bl: Set initial mapping mode from DT

In reply to Svyatoslav Ryhel
Quoted 3 lines · Svyatoslav Ryhel

Add support to obtain the initial mapping mode from DT instead of leaving it unconfigured. Additionally, update the linear sysfs code, which uses a similar coding pattern.

Words like "additionally" in a patch description can be a sign the patch should actually be two patches. In this case the patch would be a lot easier to read if you cleaned up the linear sysfs code (patch N) and then added the new DT logic (patch N+1).

Daniel.

#26 lore raw

Re: [PATCH v2 5/6] video: backlight: lm3533_bl: Set initial mapping mode from DT

пт, 29 трав. 2026 р. о 14:10 Daniel Thompson <[email protected]> пише:

Quoted 11 lines · Svyatoslav Ryhel
Quoted 3 lines

Add support to obtain the initial mapping mode from DT instead of leaving it unconfigured. Additionally, update the linear sysfs code, which uses a similar coding pattern.

Words like "additionally" in a patch description can be a sign the patch should actually be two patches. In this case the patch would be a lot easier to read if you cleaned up the linear sysfs code (patch N) and then added the new DT logic (patch N+1).

I looked into this in reverse. My goal was to add DT logic I don't case how sysfs works. My code matched with what sysfs does I just included sysfs change as well. I might better drop sysfs changes entirely since with such pace this patchset will inflate from 6 to 15 and beyond.

Quoted 2 lines

Daniel.

#27 lore raw

Re: [PATCH v2 5/6] video: backlight: lm3533_bl: Set initial mapping mode from DT

Quoted 13 lines · Svyatoslav Ryhel

пт, 29 трав. 2026 р. о 14:10 Daniel Thompson <[email protected]> пише:

Quoted 11 lines · Svyatoslav Ryhel
Quoted 3 lines

Add support to obtain the initial mapping mode from DT instead of leaving it unconfigured. Additionally, update the linear sysfs code, which uses a similar coding pattern.

Words like "additionally" in a patch description can be a sign the patch should actually be two patches. In this case the patch would be a lot easier to read if you cleaned up the linear sysfs code (patch N) and then added the new DT logic (patch N+1).

Quoted 5 lines

I looked into this in reverse. My goal was to add DT logic I don't case how sysfs works. My code matched with what sysfs does I just included sysfs change as well. I might better drop sysfs changes entirely since with such pace this patchset will inflate from 6 to 15 and beyond.

Not sure about that. The clean up is good and introducing the new BIT(2 * n + 1) macro does need to be used pervasively or there's no point in adding it.

Daniel.

#28 lore raw

PATCH v2 6/6 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          | 55 ++++++++++++++++++++++++++++-
 drivers/video/backlight/lm3533_bl.c | 37 ++++++++++++++++++-
 2 files changed, 90 insertions(+), 2 deletions(-)
drivers/leds/leds-lm3533.c +54 -1
index d707d43d5526..07390bba9a48 100644
@@ -7,6 +7,7 @@
  * Author: Johan Hovold <[email protected]>
  */
 
+#include <linux/bits.h>
 #include <linux/module.h>
 #include <linux/leds.h>
 #include <linux/mfd/core.h>
@@ -26,6 +27,12 @@
 #define LM3533_ALS_CHANNEL_LV_MIN	1
 #define LM3533_ALS_CHANNEL_LV_MAX	2
 
+#define LM3533_REG_OUTPUT_CONF1			0x10
+#define   OUTPUT_CONF1_MASK			GENMASK(7, 2)
+#define   OUTPUT_CONF1_SHIFT			2
+#define LM3533_REG_OUTPUT_CONF2			0x11
+#define   OUTPUT_CONF2_MASK			GENMASK(3, 0)
+#define   OUTPUT_CONF2_SHIFT			6
 #define LM3533_REG_CTRLBANK_BCONF_BASE		0x1b
 #define LM3533_REG_PATTERN_ENABLE		0x28
 #define LM3533_REG_PATTERN_LOW_TIME_BASE	0x71
@@ -53,6 +60,9 @@ struct lm3533_led {
 
 	u32 max_current;
 	u32 pwm;
+
+	int num_leds;
+	u32 leds[LM3533_LVCTRLBANK_MAX];
 };
 
 
@@ -639,7 +649,33 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
 
 static int lm3533_led_setup(struct lm3533_led *led)
 {
-	int ret;
+	u32 output_cfg_shift = 0;
+	u32 output_cfg_val = 0;
+	int ret, i;
+
+	if (led->num_leds) {
+		for (i = 0; i < led->num_leds; i++) {
+			if (led->leds[i] > LM3533_LVCTRLBANK_MAX)
+				continue;
+
+			output_cfg_shift = led->leds[i] * 2;
+			output_cfg_val |= led->id << output_cfg_shift;
+		}
+
+		/* LVLED1, LVLED2 and LVLED3 */
+		ret = lm3533_update(led->lm3533, LM3533_REG_OUTPUT_CONF1,
+				    output_cfg_val << OUTPUT_CONF1_SHIFT,
+				    OUTPUT_CONF1_MASK);
+		if (ret)
+			return ret;
+
+		/* LVLED4 and LVLED5 */
+		ret = lm3533_update(led->lm3533, LM3533_REG_OUTPUT_CONF2,
+				    output_cfg_val >> OUTPUT_CONF2_SHIFT,
+				    OUTPUT_CONF2_MASK);
+		if (ret)
+			return ret;
+	}
 
 	ret = lm3533_ctrlbank_set_max_current(&led->cb, led->max_current);
 	if (ret)
@@ -714,6 +750,23 @@ static int lm3533_led_probe(struct platform_device *pdev)
 	led->pwm = 0;
 	device_property_read_u32(&pdev->dev, "ti,pwm-config-mask", &led->pwm);
 
+	led->num_leds = device_property_count_u32(&pdev->dev, "led-sources");
+
+	/*
+	 * If led-sources property is not set then either this Control Bank uses
+	 * its default LVLED or is not linked to any LVLED at all.
+	 */
+	if (led->num_leds > 0 && led->num_leds <= LM3533_LVCTRLBANK_MAX) {
+		ret = device_property_read_u32_array(&pdev->dev, "led-sources",
+						     led->leds, led->num_leds);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to get led-sources\n");
+			goto err_deregister;
+		}
+	} else {
+		led->num_leds = 0;
+	}
+
 	ret = lm3533_led_setup(led);
 	if (ret)
 		goto err_deregister;
drivers/video/backlight/lm3533_bl.c +36 -1
index c03d0d1667e4..82b46a531dd2 100644
@@ -7,6 +7,7 @@
  * Author: Johan Hovold <[email protected]>
  */
 
+#include <linux/bits.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/mod_devicetable.h>
@@ -21,6 +22,8 @@
 #define LM3533_HVCTRLBANK_COUNT		2
 #define LM3533_BL_MAX_BRIGHTNESS	255
 
+#define LM3533_REG_OUTPUT_CONF1		0x10
+#define   OUTPUT_CONF1_MASK		GENMASK(1, 0)
 #define LM3533_REG_CTRLBANK_AB_BCONF	0x1a
 #define   CTRLBANK_AB_BCONF_MODE(n)	BIT(2 * (n) + 1)
 
@@ -34,6 +37,9 @@ struct lm3533_bl {
 	u32 max_current;
 	u32 pwm;
 	bool linear;
+
+	u32 num_leds;
+	u32 led_strings[LM3533_HVCTRLBANK_COUNT];
 };
 
 
@@ -248,7 +254,8 @@ static struct attribute_group lm3533_bl_attribute_group = {
 static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
 	int id = lm3533_bl_get_ctrlbank_id(bl);
-	int ret;
+	u32 output_cfg_val = 0;
+	int ret, i;
 
 	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF,
 			    bl->linear ? CTRLBANK_AB_BCONF_MODE(id) : 0,
@@ -256,6 +263,16 @@ static int lm3533_bl_setup(struct lm3533_bl *bl)
 	if (ret)
 		return ret;
 
+	if (bl->num_leds) {
+		for (i = 0; i < bl->num_leds; i++)
+			output_cfg_val |= id << bl->led_strings[i];
+
+		ret = lm3533_update(bl->lm3533, LM3533_REG_OUTPUT_CONF1,
+				    output_cfg_val, OUTPUT_CONF1_MASK);
+		if (ret)
+			return ret;
+	}
+
 	ret = lm3533_ctrlbank_set_max_current(&bl->cb, bl->max_current);
 	if (ret)
 		return ret;
@@ -329,6 +346,24 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->linear = device_property_read_bool(&pdev->dev,
 					       "ti,linear-mapping-mode");
 
+	bl->num_leds = device_property_count_u32(&pdev->dev, "led-sources");
+
+	/*
+	 * If led-sources property is not set then either this Control Bank uses
+	 * its default HVLED or is not linked to any HVLED at all.
+	 */
+	if (bl->num_leds > 0 && bl->num_leds <= LM3533_HVCTRLBANK_COUNT) {
+		ret = device_property_read_u32_array(&pdev->dev, "led-sources",
+						     bl->led_strings,
+						     bl->num_leds);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to get led-sources\n");
+			goto err_sysfs_remove;
+		}
+	} else {
+		bl->num_leds = 0;
+	}
+
 	ret = lm3533_bl_setup(bl);
 	if (ret)
 		return ret;
Signature · 1 line
2.51.0
#29 lore raw

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

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Hardcoded register masks clobber sibling device configurations. - [Medium] Missing bounds…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Hardcoded register masks clobber sibling device configurations.
- [Medium] Missing bounds validation on device tree shift values causes undefined behavior.
- [Medium] Premature sysfs group removal in error path triggers kernel warnings.
- [Low] Incorrect boundary check allows an out-of-bounds LVLED index.
- [Low] Improper handling of negative error codes from device property count via unsigned wrapping. --

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

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

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

Quoted 4 lines
drivers/leds/leds-lm3533.c +0 -0
index d707d43d55260..07390bba9a48c 100644

[ ... ]

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

Quoted 12 lines
drivers/leds/leds-lm3533.c +7 -1
@@ -639,7 +649,33 @@ static const struct attribute_group *lm3533_led_attribute_groups[] = {
 
 static int lm3533_led_setup(struct lm3533_led *led)
 {
-	int ret;
+	u32 output_cfg_shift = 0;
+	u32 output_cfg_val = 0;
+	int ret, i;
+
+	if (led->num_leds) {
+		for (i = 0; i < led->num_leds; i++) {
+			if (led->leds[i] > LM3533_LVCTRLBANK_MAX)

[Severity: Low]
Is this boundary check correct? LM3533_LVCTRLBANK_MAX appears to be 5, so using greater-than allows an index of 5 to pass.

Since there are only 5 LV LEDs mapped to indices 0 through 4, would an index of 5 result in calculating a bit shift for a non-existent LVLED6?

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

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

[Severity: High]
If a mask like OUTPUT_CONF1_MASK is used for lm3533_update() and it covers all LEDs, will it unconditionally clear the configuration bits for any LEDs not assigned to the current bank?

For example, if Bank 0 configures one LED and then Bank 1 configures another, does the second update overwrite and clear the first one's configuration since the mask is static? Should the register mask be dynamically generated based on the LEDs actually being configured?

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

[ ... ]

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +0 -0
index c03d0d1667e42..82b46a531dd27 100644

[ ... ]

Quoted 11 lines
drivers/video/backlight/lm3533_bl.c +2 -1
@@ -248,7 +254,8 @@ static struct attribute_group lm3533_bl_attribute_group = {
 static int lm3533_bl_setup(struct lm3533_bl *bl)
 {
 	int id = lm3533_bl_get_ctrlbank_id(bl);
-	int ret;
+	u32 output_cfg_val = 0;
+	int ret, i;
 
 	ret = lm3533_update(bl->lm3533, LM3533_REG_CTRLBANK_AB_BCONF,
 			    bl->linear ? CTRLBANK_AB_BCONF_MODE(id) : 0,

drivers/video/backlight/lm3533_bl.c static int lm3533_bl_setup(struct lm3533_bl *bl) · line 268

Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +3 -0
@@ -256,6 +263,16 @@ static int lm3533_bl_setup(struct lm3533_bl *bl)
 	if (ret)
 		return ret;
 
+	if (bl->num_leds) {
+		for (i = 0; i < bl->num_leds; i++)
+			output_cfg_val |= id << bl->led_strings[i];

[Severity: Medium]
Since the values from bl->led_strings arrays are read directly from the device tree property without bounds checking, could a malformed device tree provide a value of 32 or greater and cause an out-of-bounds bitwise shift here?

Quoted 6 lines
drivers/video/backlight/lm3533_bl.c +6 -0
+
+		ret = lm3533_update(bl->lm3533, LM3533_REG_OUTPUT_CONF1,
+				    output_cfg_val, OUTPUT_CONF1_MASK);
+		if (ret)
+			return ret;
+	}

[ ... ]

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

Quoted 5 lines
drivers/video/backlight/lm3533_bl.c +1 -0
@@ -329,6 +346,24 @@ static int lm3533_bl_probe(struct platform_device *pdev)
 	bl->linear = device_property_read_bool(&pdev->dev,
 					       "ti,linear-mapping-mode");
 
+	bl->num_leds = device_property_count_u32(&pdev->dev, "led-sources");

[Severity: Low]
Looking at the struct definition, bl->num_leds is declared as a u32.

If device_property_count_u32() returns a negative error code like -EINVAL, does that get implicitly cast to a very large positive unsigned integer?

The subsequent bounds check would safely fail, but could this be avoided by using an int for the count, similar to what is done in lm3533_led_probe()?

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

Quoted 12 lines
drivers/video/backlight/lm3533_bl.c +12 -0
+
+	/*
+	 * If led-sources property is not set then either this Control Bank uses
+	 * its default HVLED or is not linked to any HVLED at all.
+	 */
+	if (bl->num_leds > 0 && bl->num_leds <= LM3533_HVCTRLBANK_COUNT) {
+		ret = device_property_read_u32_array(&pdev->dev, "led-sources",
+						     bl->led_strings,
+						     bl->num_leds);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to get led-sources\n");
+			goto err_sysfs_remove;

[Severity: Medium]
If device_property_read_u32_array() fails, this jumps to err_sysfs_remove.

Looking at lm3533_bl_probe(), sysfs_create_group() is called later in the probe sequence.

Does calling sysfs_remove_group() on an uncreated sysfs group here trigger a kernel warning? Should the error path at this stage simply return the error code instead?

Quoted 4 lines
drivers/video/backlight/lm3533_bl.c +4 -0
+		}
+	} else {
+		bl->num_leds = 0;
+	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6