Skip to contentSkip to conversation

Support for Samsung S2MU005 PMIC and its sub-devices

PATCH Superseded Kaustabh Chakraborty 8 participants 37 messages Jan 25 – Feb 23

Subsystems (10)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support for Samsung S2MU005 PMIC and its sub-devices

S2MU005 is an MFD chip manufactured by Samsung Electronics. This is found in various devices manufactured by Samsung and others, including all Exynos 7870 devices. It is known to have the following features:

1. Two LED channels with adjustable brightness for use as a torch, or a flash strobe.
2. An RGB LED with 8-bit channels. Usually programmed as a notification indicator.
3. An MUIC, which works with USB micro-B (and USB-C?). For the micro-B variant though, it measures the ID-GND resistance using an internal ADC.
4. A charger device, which reports if charger is online, voltage, resistance, etc.

This patch series implements a lot of these features. Naturally, this series touches upon a lot of subsystems. The 'parent' is the MFD driver, so the subsystems have some form of dependency to the MFD driver, so they are not separable.

Here are the subsystems corresponding to the patch numbers:
dt-bindings - 01, 02, 03, 04, 05

mfd         - 05, 06, 07
led         - 01, 02, 08, 09, 10
extcon      - 03, 11
power       - 04, 12

---
Changes in v2:
- Drop [v1 06/13], instead use regmap_irq_chip::get_irq_regs()
- Remove references to driver in devicetree commits (Conor Dooley)
- Propagate errors of sec_pmic_store_rev() (André Draszik)
- Fix documentation language errors (Randy Dunlap)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kaustabh Chakraborty (12):
dt-bindings: leds: document Samsung S2M series PMIC flash LED device
dt-bindings: leds: document Samsung S2M series PMIC RGB LED device
dt-bindings: extcon: document Samsung S2M series PMIC extcon device
dt-bindings: power: supply: document Samsung S2M series PMIC charger device
dt-bindings: mfd: s2mps11: add documentation for S2MU005 PMIC
mfd: sec: add support for S2MU005 PMIC
mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support
leds: flash: add support for Samsung S2M series PMIC flash LED device
leds: rgb: add support for Samsung S2M series PMIC RGB LED device
Documentation: leds: document pattern behavior of Samsung S2M series PMIC RGB LEDs
extcon: add support for Samsung S2M series PMIC extcon devices
power: supply: add support for Samsung S2M series PMIC charger device

 .../bindings/extcon/samsung,s2mu005-muic.yaml      |  35 ++
 .../bindings/leds/samsung,s2mu005-flash.yaml       |  52 +++
 .../bindings/leds/samsung,s2mu005-rgb.yaml         |  34 ++
 .../devicetree/bindings/mfd/samsung,s2mps11.yaml   | 103 ++++-
 .../power/supply/samsung,s2mu005-charger.yaml      |  35 ++
 Documentation/leds/index.rst                       |   1 +
 Documentation/leds/leds-s2m-rgb.rst                |  60 +++
 drivers/extcon/Kconfig                             |  10 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-s2m.c                        | 351 ++++++++++++++++
 drivers/leds/flash/Kconfig                         |  12 +
 drivers/leds/flash/Makefile                        |   1 +
 drivers/leds/flash/leds-s2m-flash.c                | 410 ++++++++++++++++++
 drivers/leds/rgb/Kconfig                           |  11 +
 drivers/leds/rgb/Makefile                          |   1 +
 drivers/leds/rgb/leds-s2m-rgb.c                    | 460 +++++++++++++++++++++
 drivers/mfd/sec-common.c                           |  57 ++-
 drivers/mfd/sec-i2c.c                              |  12 +
 drivers/mfd/sec-irq.c                              |  74 ++++
 drivers/power/supply/Kconfig                       |  11 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/s2m-charger.c                 | 213 ++++++++++
 include/linux/mfd/samsung/core.h                   |   2 +
 include/linux/mfd/samsung/irq.h                    |  66 +++
 include/linux/mfd/samsung/s2mu005.h                | 328 +++++++++++++++
 25 files changed, 2330 insertions(+), 11 deletions(-)

---
base-commit: ca3a02fda4da8e2c1cb6baee5d72352e9e2cfaea
change-id: 20251112-s2mu005-pmic-0c67fa6bac3c

Best regards,

Signature · 1 line
Kaustabh Chakraborty <[email protected]>
#1 lore raw

PATCH v2 1/12 dt-bindings: leds: document Samsung S2M series PMIC flash LED device

Certain Samsung S2M series PMICs have a flash LED controller with two LED channels, and with torch and flash control modes. Document the devicetree schema for the device.

---
 .../bindings/leds/samsung,s2mu005-flash.yaml       | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-flash.yaml new file +52 -0
new file mode 100644
index 0000000000000..36051ab20509f
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-flash.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Flash and Torch LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC flash LED has two led channels (typically
+  as back and front camera flashes), with support for both torch and
+  flash modes.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-flash
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^led@[0-1]$":
+    type: object
+    $ref: common.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        enum: [0, 1]
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 2/12 dt-bindings: leds: document Samsung S2M series PMIC RGB LED device

In reply to Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a three-channel LED device with independent brightness control for each channel, typically used as status indicators in mobile phones. Document the devicetree schema from this device.

---
 .../bindings/leds/samsung,s2mu005-rgb.yaml         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +34 -0
new file mode 100644
index 0000000000000..6806b6d869ff7
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-rgb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RGB LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC RGB LED is a three-channel LED device with
+  8-bit brightness control for each channel, typically used as status
+  indicators in mobile phones.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-rgb
+
+required:
+  - compatible
+
+unevaluatedProperties: false
Signature · 1 line
2.52.0
maintainer
#3 lore raw

Re: [PATCH v2 02/12] dt-bindings: leds: document Samsung S2M series PMIC RGB LED device

Quoted 30 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a three-channel LED device with independent brightness control for each channel, typically used as status indicators in mobile phones. Document the devicetree schema from this device.

---
 .../bindings/leds/samsung,s2mu005-rgb.yaml         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +14 -0
new file mode 100644
index 0000000000000..6806b6d869ff7
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-rgb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RGB LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC RGB LED is a three-channel LED device with
+  8-bit brightness control for each channel, typically used as status

Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml line 24

Quoted 10 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +10 -0
+  indicators in mobile phones.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: common.yaml#

This looks a bit lacking. Don't you need 3 child nodes for each or reference to the multi-color schema?

Quoted 14 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-rgb
+
+required:
+  - compatible
+
+unevaluatedProperties: false
Signature · 2 lines
-- 
2.52.0
#4 lore raw

Re: [PATCH v2 02/12] dt-bindings: leds: document Samsung S2M series PMIC RGB LED device

Quoted 36 lines · Rob Herring
Quoted 35 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a three-channel LED device with independent brightness control for each channel, typically used as status indicators in mobile phones. Document the devicetree schema from this device.

---
 .../bindings/leds/samsung,s2mu005-rgb.yaml         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +19 -0
new file mode 100644
index 0000000000000..6806b6d869ff7
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-rgb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RGB LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC RGB LED is a three-channel LED device with
+  8-bit brightness control for each channel, typically used as status
+  indicators in mobile phones.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
Quoted 8 lines

Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml line 24

Quoted 5 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +5 -0
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: common.yaml#

This looks a bit lacking. Don't you need 3 child nodes for each or reference to the multi-color schema?

	rgb {
		compatible = "samsung,s2mu005-rgb";
		label = "notification:rgb:indicator";
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_INDICATOR;
		linux,default-trigger = "pattern";
	};
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-rgb
+
+required:
+  - compatible
+
+unevaluatedProperties: false
Signature · 2 lines
-- 
2.52.0
#5 lore raw

Re: [PATCH v2 02/12] dt-bindings: leds: document Samsung S2M series PMIC RGB LED device

Quoted 46 lines · Kaustabh Chakraborty
Quoted 36 lines · Rob Herring
Quoted 35 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a three-channel LED device with independent brightness control for each channel, typically used as status indicators in mobile phones. Document the devicetree schema from this device.

---
 .../bindings/leds/samsung,s2mu005-rgb.yaml         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +19 -0
new file mode 100644
index 0000000000000..6806b6d869ff7
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-rgb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RGB LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC RGB LED is a three-channel LED device with
+  8-bit brightness control for each channel, typically used as status
+  indicators in mobile phones.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
Quoted 8 lines

Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml line 24

Quoted 5 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +5 -0
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: common.yaml#

This looks a bit lacking. Don't you need 3 child nodes for each or reference to the multi-color schema?

Quoted 8 lines
	rgb {
		compatible = "samsung,s2mu005-rgb";
		label = "notification:rgb:indicator";
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_INDICATOR;
		linux,default-trigger = "pattern";
	};

Message got deleted somehow? Anyways, the device has three channels but a single LED, but is controlled by a single driver interface only. The channels are not independent.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +10 -0
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-rgb
+
+required:
+  - compatible
+
+unevaluatedProperties: false
Signature · 2 lines
-- 
2.52.0
#6 lore raw

Re: [PATCH v2 02/12] dt-bindings: leds: document Samsung S2M series PMIC RGB LED device

In reply to Kaustabh Chakraborty

Hi Kaustabh,

Quoted 46 lines · Kaustabh Chakraborty
Quoted 36 lines · Rob Herring
Quoted 35 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a three-channel LED device with independent brightness control for each channel, typically used as status indicators in mobile phones. Document the devicetree schema from this device.

---
  .../bindings/leds/samsung,s2mu005-rgb.yaml         | 34 ++++++++++++++++++++++
  1 file changed, 34 insertions(+)
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +19 -0
new file mode 100644
index 0000000000000..6806b6d869ff7
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/samsung,s2mu005-rgb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RGB LED Controller for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC RGB LED is a three-channel LED device with
+  8-bit brightness control for each channel, typically used as status
+  indicators in mobile phones.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
Quoted 8 lines

Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml line 24

Quoted 5 lines
Documentation/devicetree/bindings/leds/samsung,s2mu005-rgb.yaml new file +5 -0
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: common.yaml#

This looks a bit lacking. Don't you need 3 child nodes for each or reference to the multi-color schema?

Quoted 7 lines
	rgb {
		compatible = "samsung,s2mu005-rgb";
		label = "notification:rgb:indicator";
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_INDICATOR;
		linux,default-trigger = "pattern";
	};

Having label together with color and function doesn't make sense. Please read label documentation in [0].

[0] Documentation/devicetree/bindings/leds/common.yaml

Signature · 2 lines
Best regards,
Jacek Anaszewski
#7 lore raw

PATCH v2 3/12 dt-bindings: extcon: document Samsung S2M series PMIC extcon device

In reply to Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a MUIC device which reports various cable states by measuring the ID-GND resistance with an internal ADC. Document the devicetree schema for this device.

---
 .../bindings/extcon/samsung,s2mu005-muic.yaml      | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +35 -0
new file mode 100644
index 0000000000000..05828b7b5be13
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/extcon/samsung,s2mu005-muic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Extcon Device for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC extcon device is a USB port accessory
+  detector. It reports multiple states depending on the ID-GND
+  resistance measured by an internal ADC.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-muic
+
+  port:
+    $ref: /schemas/graph.yaml#/properties/port
+
+required:
+  - compatible
+  - port
+
+additionalProperties: false
Signature · 1 line
2.52.0
maintainer
#8 lore raw

Re: [PATCH v2 03/12] dt-bindings: extcon: document Samsung S2M series PMIC extcon device

Quoted 18 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a MUIC device which reports various cable states by measuring the ID-GND resistance with an internal ADC. Document the devicetree schema for this device.

---
 .../bindings/extcon/samsung,s2mu005-muic.yaml      | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +3 -0
new file mode 100644
index 0000000000000..05828b7b5be13
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +10 -0
+$id: http://devicetree.org/schemas/extcon/samsung,s2mu005-muic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Extcon Device for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC extcon device is a USB port accessory

extcon is a Linuxism. Use usb-connector binding.

Quoted 6 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +6 -0
+  detector. It reports multiple states depending on the ID-GND
+  resistance measured by an internal ADC.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+

Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +10 -0
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-muic
+
+  port:
+    $ref: /schemas/graph.yaml#/properties/port

What does the port connect to?

Quoted 10 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +6 -0
+
+required:
+  - compatible
+  - port
+
+additionalProperties: false
Signature · 2 lines
-- 
2.52.0
#9 lore raw

Re: [PATCH v2 03/12] dt-bindings: extcon: document Samsung S2M series PMIC extcon device

Quoted 42 lines · Rob Herring
Quoted 18 lines · Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a MUIC device which reports various cable states by measuring the ID-GND resistance with an internal ADC. Document the devicetree schema for this device.

---
 .../bindings/extcon/samsung,s2mu005-muic.yaml      | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +3 -0
new file mode 100644
index 0000000000000..05828b7b5be13
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +10 -0
+$id: http://devicetree.org/schemas/extcon/samsung,s2mu005-muic.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Extcon Device for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC extcon device is a USB port accessory

extcon is a Linuxism. Use usb-connector binding.

Quoted 10 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +10 -0
+  detector. It reports multiple states depending on the ID-GND
+  resistance measured by an internal ADC.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+properties:
Quoted 8 lines

Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml line 29

Quoted 6 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +6 -0
+  compatible:
+    enum:
+      - samsung,s2mu005-muic
+
+  port:
+    $ref: /schemas/graph.yaml#/properties/port

What does the port connect to?

I have it connected to the USB PHY in device tree.

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/extcon/samsung,s2mu005-muic.yaml new file +6 -0
+
+required:
+  - compatible
+  - port
+
+additionalProperties: false
Signature · 2 lines
-- 
2.52.0
#10 lore raw

PATCH v2 4/12 dt-bindings: power: supply: document Samsung S2M series PMIC charger device

In reply to Kaustabh Chakraborty

Certain Samsung S2M series PMICs have a battery charger device which, among other things, manages power interfacing of the USB port. It may supply power, as done in USB OTG operation mode, or it may accept power and redirect it to the battery fuelgauge for charging. Document this device.

---
 .../power/supply/samsung,s2mu005-charger.yaml      | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
Documentation/devicetree/bindings/power/supply/samsung,s2mu005-charger.yaml new file +35 -0
new file mode 100644
index 0000000000000..9159a15e77c61
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/samsung,s2mu005-charger.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Battery Charger for Samsung S2M series PMICs
+
+maintainers:
+  - Kaustabh Chakraborty <[email protected]>
+
+description: |
+  The Samsung S2M series PMIC battery charger manages power interfacing
+  of the USB port. It may supply power, as done in USB OTG operation
+  mode, or it may accept power and redirect it to the battery fuelgauge
+  for charging.
+
+  This is a part of device tree bindings for S2M and S5M family of Power
+  Management IC (PMIC).
+
+  See also Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml for
+  additional information and example.
+
+allOf:
+  - $ref: power-supply.yaml#
+
+properties:
+  compatible:
+    enum:
+      - samsung,s2mu005-charger
+
+required:
+  - compatible
+
+unevaluatedProperties: false
Signature · 1 line
2.52.0
#11 lore raw

PATCH v2 5/12 dt-bindings: mfd: s2mps11: add documentation for S2MU005 PMIC

In reply to Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

Since regulators are not supported by this device, unmark this property as required and instead set this in a per-device basis for ones which need it.

Add the compatible and documentation for the S2MU005 PMIC. Also, add an example for nodes for supported sub-devices, i.e. charger, extcon, flash, and rgb.

---
 .../devicetree/bindings/mfd/samsung,s2mps11.yaml   | 103 ++++++++++++++++++++-
 1 file changed, 102 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml +102 -1
index 31d544a9c05ca..aef634ca2e36f 100644
@@ -27,12 +27,28 @@ properties:
       - samsung,s2mps15-pmic
       - samsung,s2mpu02-pmic
       - samsung,s2mpu05-pmic
+      - samsung,s2mu005-pmic
 
   clocks:
     $ref: /schemas/clock/samsung,s2mps11.yaml
     description:
       Child node describing clock provider.
 
+  charger:
+    $ref: /schemas/power/supply/samsung,s2m-charger.yaml
+    description:
+      Child node describing battery charger device.
+
+  extcon:
+    $ref: /schemas/extcon/samsung,s2m-muic.yaml
+    description:
+      Child node describing extcon device.
+
+  flash:
+    $ref: /schemas/leds/samsung,s2m-flash.yaml
+    description:
+      Child node describing flash LEDs.
+
   interrupts:
     maxItems: 1
 
@@ -44,6 +60,11 @@ properties:
     description:
       List of child nodes that specify the regulators.
 
+  rgb:
+    $ref: /schemas/leds/samsung,s2m-rgb.yaml
+    description:
+      Child node describing RGB LEDs.
+
   samsung,s2mps11-acokb-ground:
     description: |
       Indicates that ACOKB pin of S2MPS11 PMIC is connected to the ground so
@@ -65,7 +86,6 @@ properties:
 
 required:
   - compatible
-  - regulators
 
 additionalProperties: false
 
@@ -105,6 +125,8 @@ allOf:
         regulators:
           $ref: /schemas/regulator/samsung,s2mps11.yaml
         samsung,s2mps11-wrstbi-ground: false
+      required:
+        - regulators
 
   - if:
       properties:
@@ -116,6 +138,8 @@ allOf:
         regulators:
           $ref: /schemas/regulator/samsung,s2mps13.yaml
         samsung,s2mps11-acokb-ground: false
+      required:
+        - regulators
 
   - if:
       properties:
@@ -128,6 +152,8 @@ allOf:
           $ref: /schemas/regulator/samsung,s2mps14.yaml
         samsung,s2mps11-acokb-ground: false
         samsung,s2mps11-wrstbi-ground: false
+      required:
+        - regulators
 
   - if:
       properties:
@@ -140,6 +166,8 @@ allOf:
           $ref: /schemas/regulator/samsung,s2mps15.yaml
         samsung,s2mps11-acokb-ground: false
         samsung,s2mps11-wrstbi-ground: false
+      required:
+        - regulators
 
   - if:
       properties:
@@ -152,6 +180,8 @@ allOf:
           $ref: /schemas/regulator/samsung,s2mpu02.yaml
         samsung,s2mps11-acokb-ground: false
         samsung,s2mps11-wrstbi-ground: false
+      required:
+        - regulators
 
   - if:
       properties:
@@ -164,6 +194,18 @@ allOf:
           $ref: /schemas/regulator/samsung,s2mpu05.yaml
         samsung,s2mps11-acokb-ground: false
         samsung,s2mps11-wrstbi-ground: false
+      required:
+        - regulators
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: samsung,s2mu005-pmic
+    then:
+      properties:
+        samsung,s2mps11-acokb-ground: false
+        samsung,s2mps11-wrstbi-ground: false
 
 examples:
   - |
@@ -305,3 +347,62 @@ examples:
             };
         };
     };
+
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/leds/common.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@3d {
+            compatible = "samsung,s2mu005-pmic";
+            reg = <0x3d>;
+            interrupt-parent = <&gpa2>;
+            interrupts = <7 IRQ_TYPE_LEVEL_LOW>;
+
+            charger {
+                compatible = "samsung,s2mu005-charger";
+                monitored-battery = <&battery>;
+            };
+
+            extcon {
+                compatible = "samsung,s2mu005-muic";
+
+                port {
+                    muic_to_usb: endpoint {
+                        remote-endpoint = <&usb_to_muic>;
+                    };
+                };
+            };
+
+            flash {
+                compatible = "samsung,s2mu005-flash";
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                led@0 {
+                    reg = <0>;
+                    label = "back-cam:white:flash";
+                    color = <LED_COLOR_ID_WHITE>;
+                    function = LED_FUNCTION_FLASH;
+                };
+
+                led@1 {
+                    reg = <1>;
+                    label = "front-cam:white:flash";
+                    color = <LED_COLOR_ID_WHITE>;
+                    function = LED_FUNCTION_FLASH;
+                };
+            };
+
+            rgb {
+                compatible = "samsung,s2mu005-rgb";
+                label = "notification:rgb:indicator";
+                color = <LED_COLOR_ID_RGB>;
+                function = LED_FUNCTION_INDICATOR;
+                linux,default-trigger = "pattern";
+            };
+        };
+    };
Signature · 1 line
2.52.0
#12 lore raw

Re: [PATCH v2 05/12] dt-bindings: mfd: s2mps11: add documentation for S2MU005 PMIC

Quoted 7 lines · Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

Since regulators are not supported by this device, unmark this property as required and instead set this in a per-device basis for ones which need it.

Quoted 9 lines

Add the compatible and documentation for the S2MU005 PMIC. Also, add an example for nodes for supported sub-devices, i.e. charger, extcon, flash, and rgb.

---
 .../devicetree/bindings/mfd/samsung,s2mps11.yaml   | 103 ++++++++++++++++++++-
 1 file changed, 102 insertions(+), 1 deletion(-)

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/samsung,s2mps11.yaml: Unresolvable reference: /schemas/power/supply/samsung,s2m-charger.yaml Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 428, in get_or_retrieve
resource = registry._retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 426, in retrieve

    return DRAFT201909.create_resource(self.schemas[uri])
                                       ~~~~~~~~~~~~^^^^^

KeyError: 'http://devicetree.org/schemas/power/supply/samsung,s2m-charger.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 682, in lookup
retrieved = self._registry.get_or_retrieve(uri)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 435, in get_or_retrieve
raise exceptions.Unretrievable(ref=uri) from error
referencing.exceptions.Unretrievable: 'http://devicetree.org/schemas/power/supply/samsung,s2m-charger.yaml'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 462, in _validate_reference
resolved = self._resolver.lookup(ref)
File "/usr/local/lib/python3.13/dist-packages/referencing/_core.py", line 686, in lookup
raise exceptions.Unresolvable(ref=ref) from error
referencing.exceptions.Unresolvable: /schemas/power/supply/samsung,s2m-charger.yaml

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/dt-validate", line 8, in <module>

    sys.exit(main())
             ~~~~^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 158, in main
    sg.check_dtb(filename)
    ~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 95, in check_dtb
    self.check_subtree(dt, subtree, False, "/", "/", filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 88, in check_subtree
    self.check_subtree(tree, value, disabled, name, fullname + name, filename)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 83, in check_subtree
    self.check_node(tree, subtree, disabled, nodename, fullname, filename)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/dtb_validate.py", line 34, in check_node
    for error in self.validator.iter_errors(node, filter=match_schema_file,
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                            compatible_match=compatible_match):
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/dtschema/validator.py", line 448, in iter_errors
    for error in self.DtValidator(schema, registry=self.registry).iter_errors(instance):
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 383, in iter_errors
    for error in errors:
                 ^^^^^^
  File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 296, in properties
    yield from validator.descend(
    ...<4 lines>...
    )

File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 431, in descend
for error in errors:
^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/_keywords.py", line 275, in ref
yield from validator._validate_reference(ref=ref, instance=instance)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/dist-packages/jsonschema/validators.py", line 464, in _validate_reference
raise exceptions._WrappedReferencingError(err) from err
jsonschema.exceptions._WrappedReferencingError: Unresolvable: /schemas/power/supply/samsung,s2m-charger.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.kernel.org/project/devicetree/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#13 lore raw

PATCH v2 6/12 mfd: sec: add support for S2MU005 PMIC

In reply to Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

S2MU005's interrupt registers can be properly divided into three regmap IRQ chips, one each for the charger, flash LEDs, and the MUIC.

Add initial support for S2MU005 in the PMIC driver, along with it's three interrupt chips.

---
 drivers/mfd/sec-common.c            |  16 ++
 drivers/mfd/sec-i2c.c               |  12 ++
 drivers/mfd/sec-irq.c               |  74 ++++++++
 include/linux/mfd/samsung/core.h    |   1 +
 include/linux/mfd/samsung/irq.h     |  66 ++++++++
 include/linux/mfd/samsung/s2mu005.h | 328 ++++++++++++++++++++++++++++++++++++
 6 files changed, 497 insertions(+)
drivers/mfd/sec-common.c +16 -0
index 0021f9ae8484f..bc2a1f2c6dc7a 100644
@@ -99,6 +99,18 @@ static const struct mfd_cell s2mpu05_devs[] = {
 	MFD_CELL_RES("s2mps15-rtc", s2mpu05_rtc_resources),
 };
 
+static const struct resource s2mu005_muic_resources[] = {
+	DEFINE_RES_IRQ_NAMED(S2MU005_IRQ_MUIC_ATTACH, "attach"),
+	DEFINE_RES_IRQ_NAMED(S2MU005_IRQ_MUIC_DETACH, "detach"),
+};
+
+static const struct mfd_cell s2mu005_devs[] = {
+	MFD_CELL_OF("s2mu005-charger", NULL, NULL, 0, 0, "samsung,s2mu005-charger"),
+	MFD_CELL_OF("s2mu005-flash", NULL, NULL, 0, 0, "samsung,s2mu005-flash"),
+	MFD_CELL_OF("s2mu005-muic", s2mu005_muic_resources, NULL, 0, 0, "samsung,s2mu005-muic"),
+	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
+};
+
 static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
 {
 	unsigned int val;
@@ -235,6 +247,10 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
 		sec_devs = s2mpu05_devs;
 		num_sec_devs = ARRAY_SIZE(s2mpu05_devs);
 		break;
+	case S2MU005:
+		sec_devs = s2mu005_devs;
+		num_sec_devs = ARRAY_SIZE(s2mu005_devs);
+		break;
 	default:
 		return dev_err_probe(sec_pmic->dev, -EINVAL,
 				     "Unsupported device type %d\n",
drivers/mfd/sec-i2c.c +12 -0
index 3132b849b4bc4..3f1d70cc3292b 100644
@@ -17,6 +17,7 @@
 #include <linux/mfd/samsung/s2mps14.h>
 #include <linux/mfd/samsung/s2mps15.h>
 #include <linux/mfd/samsung/s2mpu02.h>
+#include <linux/mfd/samsung/s2mu005.h>
 #include <linux/mfd/samsung/s5m8767.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
@@ -130,6 +131,11 @@ static const struct regmap_config s2mpu05_regmap_config = {
 	.val_bits = 8,
 };
 
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};
+
 static const struct regmap_config s5m8767_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -203,6 +209,11 @@ static const struct sec_pmic_i2c_platform_data s2mpu05_data = {
 	.device_type = S2MPU05,
 };
 
+static const struct sec_pmic_i2c_platform_data s2mu005_data = {
+	.regmap_cfg = &s2mu005_regmap_config,
+	.device_type = S2MU005,
+};
+
 static const struct sec_pmic_i2c_platform_data s5m8767_data = {
 	.regmap_cfg = &s5m8767_regmap_config,
 	.device_type = S5M8767X,
@@ -217,6 +228,7 @@ static const struct of_device_id sec_pmic_i2c_of_match[] = {
 	{ .compatible = "samsung,s2mps15-pmic", .data = &s2mps15_data, },
 	{ .compatible = "samsung,s2mpu02-pmic", .data = &s2mpu02_data, },
 	{ .compatible = "samsung,s2mpu05-pmic", .data = &s2mpu05_data, },
+	{ .compatible = "samsung,s2mu005-pmic", .data = &s2mu005_data, },
 	{ .compatible = "samsung,s5m8767-pmic", .data = &s5m8767_data, },
 	{ },
 };
drivers/mfd/sec-irq.c +74 -0

98 lines not on this page · raw message

include/linux/mfd/samsung/core.h +1 -0
index c7c3c8cd8d5f9..43e0c5e55f5d3 100644
@@ -46,6 +46,7 @@ enum sec_device_type {
 	S2MPS15X,
 	S2MPU02,
 	S2MPU05,
+	S2MU005,
 };
 
 /**
include/linux/mfd/samsung/irq.h +66 -0

72 lines not on this page · raw message

include/linux/mfd/samsung/s2mu005.h new file +328 -0

328 lines not on this page · raw message

Signature · 1 line
2.52.0
#14 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

kernel test robot noticed the following build errors:

Hi Kaustabh,

kernel test robot noticed the following build errors:

[auto build test ERROR on ca3a02fda4da8e2c1cb6baee5d72352e9e2cfaea]

url:    https://github.com/intel-lab-lkp/linux/commits/Kaustabh-Chakraborty/dt-bindings-leds-document-Samsung-S2M-series-PMIC-flash-LED-device/20260126-031457
base:   ca3a02fda4da8e2c1cb6baee5d72352e9e2cfaea
patch link:    https://lore.kernel.org/r/20260126-s2mu005-pmic-v2-6-78f1a75f547a%40disroot.org
patch subject: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC
config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20260127/[email protected]/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260127/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/mfd/sec-irq.c:218:7: error: expression is not an integer constant expression
           case irqf_regs[0]:
                ^~~~~~~~~~~~
   drivers/mfd/sec-irq.c:218:7: note: initializer of 'irqf_regs' is not a constant expression
   drivers/mfd/sec-irq.c:204:21: note: declared here
           const unsigned int irqf_regs[] = {
                              ^
   drivers/mfd/sec-irq.c:220:7: error: expression is not an integer constant expression
           case mask_regs[0]:
                ^~~~~~~~~~~~
   drivers/mfd/sec-irq.c:220:7: note: initializer of 'mask_regs' is not a constant expression
   drivers/mfd/sec-irq.c:210:21: note: declared here
           const unsigned int mask_regs[] = {
                              ^

2 errors generated.

vim +218 drivers/mfd/sec-irq.c

200
201 static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data,
202 unsigned int base, int index)
203 {
204 const unsigned int irqf_regs[] = {
205 S2MU005_REG_CHGR_INT1,
206 S2MU005_REG_FLED_INT1,
207 S2MU005_REG_MUIC_INT1,
208 S2MU005_REG_MUIC_INT2,
209 };
210 const unsigned int mask_regs[] = {
211 S2MU005_REG_CHGR_INT1M,
212 S2MU005_REG_FLED_INT1M,
213 S2MU005_REG_MUIC_INT1M,
214 S2MU005_REG_MUIC_INT2M,
215 };
216
217 switch (base) {

 > 218		case irqf_regs[0]:

219 return irqf_regs[index];
220 case mask_regs[0]:
221 return mask_regs[index];
222 }
223
224 return base;
225 }
226

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#15 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

In reply to Kaustabh Chakraborty

Hi,

Quoted 69 lines · Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

S2MU005's interrupt registers can be properly divided into three regmap IRQ chips, one each for the charger, flash LEDs, and the MUIC.

Add initial support for S2MU005 in the PMIC driver, along with it's three interrupt chips.

---
 drivers/mfd/sec-common.c            |  16 ++ drivers/mfd/sec-i2c.c               |  12 ++ drivers/mfd/sec-irq.c               |  74 ++++++++ include/linux/mfd/samsung/core.h    |   1 + include/linux/mfd/samsung/irq.h     |  66 ++++++++ include/linux/mfd/samsung/s2mu005.h | 328 ++++++++++++++++++++++++++++++++++++

 6 files changed, 497 insertions(+)
drivers/mfd/sec-common.c +0 -0
index 0021f9ae8484f..bc2a1f2c6dc7a 100644
@@ -99,6 +99,18 @@ static const struct mfd_cell s2mpu05_devs[] = {
  	MFD_CELL_RES("s2mps15-rtc", s2mpu05_rtc_resources),
  };

drivers/mfd/sec-common.c +12 -0
+static const struct resource s2mu005_muic_resources[] = {
+	DEFINE_RES_IRQ_NAMED(S2MU005_IRQ_MUIC_ATTACH, "attach"),
+	DEFINE_RES_IRQ_NAMED(S2MU005_IRQ_MUIC_DETACH, "detach"),
+};
+
+static const struct mfd_cell s2mu005_devs[] = {
+	MFD_CELL_OF("s2mu005-charger", NULL, NULL, 0, 0, "samsung,s2mu005-charger"),
+	MFD_CELL_OF("s2mu005-flash", NULL, NULL, 0, 0, "samsung,s2mu005-flash"),
+	MFD_CELL_OF("s2mu005-muic", s2mu005_muic_resources, NULL, 0, 0, "samsung,s2mu005-muic"),
+	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
+};
+

 static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic) {
  unsigned int val;

drivers/mfd/sec-common.c +4 -0
@@ -235,6 +247,10 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
  		sec_devs = s2mpu05_devs;
  		num_sec_devs = ARRAY_SIZE(s2mpu05_devs);
  		break;
+	case S2MU005:
+		sec_devs = s2mu005_devs;
+		num_sec_devs = ARRAY_SIZE(s2mu005_devs);
+		break;

  default:
  return dev_err_probe(sec_pmic->dev, -EINVAL, "Unsupported device type %d\n",

drivers/mfd/sec-i2c.c +1 -0
index 3132b849b4bc4..3f1d70cc3292b 100644
@@ -17,6 +17,7 @@
  #include <linux/mfd/samsung/s2mps14.h>
  #include <linux/mfd/samsung/s2mps15.h>
  #include <linux/mfd/samsung/s2mpu02.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/mfd/samsung/s5m8767.h>
  #include <linux/mod_devicetable.h>
  #include <linux/module.h>
@@ -130,6 +131,11 @@ static const struct regmap_config s2mpu05_regmap_config = {
  	.val_bits = 8,
  };

drivers/mfd/sec-i2c.c static const struct regmap_config s2mpu05_regmap_config = { · line 137

Quoted 4 lines
drivers/mfd/sec-i2c.c +4 -0
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};

No cache? And what is the .max_register value?

Quoted 365 lines

+
 static const struct regmap_config s5m8767_regmap_config = { .reg_bits = 8,
  .val_bits = 8,

drivers/mfd/sec-i2c.c +0 -0
@@ -203,6 +209,11 @@ static const struct sec_pmic_i2c_platform_data s2mpu05_data = {
  	.device_type = S2MPU05,
  };

drivers/mfd/sec-i2c.c +5 -0
+static const struct sec_pmic_i2c_platform_data s2mu005_data = {
+	.regmap_cfg = &s2mu005_regmap_config,
+	.device_type = S2MU005,
+};
+

 static const struct sec_pmic_i2c_platform_data s5m8767_data = { .regmap_cfg = &s5m8767_regmap_config, .device_type = S5M8767X,

drivers/mfd/sec-i2c.c +1 -0
@@ -217,6 +228,7 @@ static const struct of_device_id sec_pmic_i2c_of_match[] = {
  	{ .compatible = "samsung,s2mps15-pmic", .data = &s2mps15_data, },
  	{ .compatible = "samsung,s2mpu02-pmic", .data = &s2mpu02_data, },
  	{ .compatible = "samsung,s2mpu05-pmic", .data = &s2mpu05_data, },
+	{ .compatible = "samsung,s2mu005-pmic", .data = &s2mu005_data, },
  	{ .compatible = "samsung,s5m8767-pmic", .data = &s5m8767_data, },
  	{ },
  };
drivers/mfd/sec-irq.c +1 -0
index 4c0faf4c99893..44a1eb074a082 100644
@@ -15,6 +15,7 @@
  #include <linux/mfd/samsung/s2mps14.h>
  #include <linux/mfd/samsung/s2mpu02.h>
  #include <linux/mfd/samsung/s2mpu05.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/mfd/samsung/s5m8767.h>
  #include <linux/regmap.h>
  #include "sec-core.h"
@@ -164,6 +165,65 @@ static const struct regmap_irq s2mpu05_irqs[] = {
  	REGMAP_IRQ_REG(S2MPU05_IRQ_TSD, 2, S2MPU05_IRQ_TSD_MASK),
  };

drivers/mfd/sec-irq.c +59 -0
+static const struct regmap_irq s2mu005_irqs[] = {
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_DETBAT, 0, S2MU005_IRQ_CHGR_DETBAT_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_BAT, 0, S2MU005_IRQ_CHGR_BAT_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_IVR, 0, S2MU005_IRQ_CHGR_IVR_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_EVENT, 0, S2MU005_IRQ_CHGR_EVENT_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_CHG, 0, S2MU005_IRQ_CHGR_CHG_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_VMID, 0, S2MU005_IRQ_CHGR_VMID_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_WCIN, 0, S2MU005_IRQ_CHGR_WCIN_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_CHGR_VBUS, 0, S2MU005_IRQ_CHGR_VBUS_MASK),
+
+	REGMAP_IRQ_REG(S2MU005_IRQ_FLED_LBPROT, 1, S2MU005_IRQ_FLED_LBPROT_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_FLED_OPENCH2, 1, S2MU005_IRQ_FLED_OPENCH2_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_FLED_OPENCH1, 1, S2MU005_IRQ_FLED_OPENCH1_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_FLED_SHORTCH2, 1, S2MU005_IRQ_FLED_SHORTCH2_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_FLED_SHORTCH1, 1, S2MU005_IRQ_FLED_SHORTCH1_MASK),
+
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_ATTACH, 2, S2MU005_IRQ_MUIC_ATTACH_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_DETACH, 2, S2MU005_IRQ_MUIC_DETACH_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_KP, 2, S2MU005_IRQ_MUIC_KP_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_LKP, 2, S2MU005_IRQ_MUIC_LKP_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_LKR, 2, S2MU005_IRQ_MUIC_LKR_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_RIDCHG, 2, S2MU005_IRQ_MUIC_RIDCHG_MASK),
+
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_VBUSON, 3, S2MU005_IRQ_MUIC_VBUSON_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_RSVD, 3, S2MU005_IRQ_MUIC_RSVD_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_ADC, 3, S2MU005_IRQ_MUIC_ADC_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_STUCK, 3, S2MU005_IRQ_MUIC_STUCK_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_STUCKRCV, 3, S2MU005_IRQ_MUIC_STUCKRCV_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_MHDL, 3, S2MU005_IRQ_MUIC_MHDL_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_AVCHG, 3, S2MU005_IRQ_MUIC_AVCHG_MASK),
+	REGMAP_IRQ_REG(S2MU005_IRQ_MUIC_VBUSOFF, 3, S2MU005_IRQ_MUIC_VBUSOFF_MASK),
+};
+
+static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data,
+					unsigned int base, int index)
+{
+	const unsigned int irqf_regs[] = {
+		S2MU005_REG_CHGR_INT1,
+		S2MU005_REG_FLED_INT1,
+		S2MU005_REG_MUIC_INT1,
+		S2MU005_REG_MUIC_INT2,
+	};
+	const unsigned int mask_regs[] = {
+		S2MU005_REG_CHGR_INT1M,
+		S2MU005_REG_FLED_INT1M,
+		S2MU005_REG_MUIC_INT1M,
+		S2MU005_REG_MUIC_INT2M,
+	};
+
+	switch (base) {
+	case irqf_regs[0]:
+		return irqf_regs[index];
+	case mask_regs[0]:
+		return mask_regs[index];
+	}
+
+	return base;
+}
+

 static const struct regmap_irq s5m8767_irqs[] = { REGMAP_IRQ_REG(S5M8767_IRQ_PWRR, 0, S5M8767_IRQ_PWRR_MASK), REGMAP_IRQ_REG(S5M8767_IRQ_PWRF, 0, S5M8767_IRQ_PWRF_MASK),

drivers/mfd/sec-irq.c +0 -0
@@ -259,6 +319,17 @@ static const struct regmap_irq_chip s2mpu05_irq_chip = {
  	.ack_base = S2MPU05_REG_INT1,
  };

drivers/mfd/sec-irq.c +11 -0
+static const struct regmap_irq_chip s2mu005_irq_chip = {
+	.name = "s2mu005",
+	.irqs = s2mu005_irqs,
+	.num_irqs = ARRAY_SIZE(s2mu005_irqs),
+	.num_regs = 4,
+	.status_base = S2MU005_REG_CHGR_INT1,
+	.mask_base = S2MU005_REG_CHGR_INT1M,
+	.ack_base = S2MU005_REG_CHGR_INT1,
+	.get_irq_reg = s2mu005_irq_get_reg,
+};
+

 static const struct regmap_irq_chip s5m8767_irq_chip = { .name = "s5m8767",
  .irqs = s5m8767_irqs,

drivers/mfd/sec-irq.c +0 -0
@@ -358,6 +429,9 @@ struct regmap_irq_chip_data *sec_irq_init(struct sec_pmic_dev *sec_pmic)

  case S2MPU05:
  sec_irq_chip = &s2mpu05_irq_chip;
  break;

drivers/mfd/sec-irq.c +3 -0
+	case S2MU005:
+		sec_irq_chip = &s2mu005_irq_chip;
+		break;

  default:
  return dev_err_ptr_probe(sec_pmic->dev, -EINVAL, "Unsupported device type %d\n", sec_pmic->device_type);

include/linux/mfd/samsung/core.h +1 -0
index c7c3c8cd8d5f9..43e0c5e55f5d3 100644
@@ -46,6 +46,7 @@ enum sec_device_type {
  	S2MPS15X,
  	S2MPU02,
  	S2MPU05,
+	S2MU005,
  };


 /**

include/linux/mfd/samsung/irq.h +0 -0
index 8402a5f8e18ab..936369a733a1c 100644
@@ -303,6 +303,72 @@ enum s2mpu05_irq {
  #define S2MPU05_IRQ_INT140C_MASK	BIT(1)
  #define S2MPU05_IRQ_TSD_MASK		BIT(2)

include/linux/mfd/samsung/irq.h +66 -0
+enum s2mu005_irq {
+	S2MU005_IRQ_CHGR_DETBAT,
+	S2MU005_IRQ_CHGR_BAT,
+	S2MU005_IRQ_CHGR_IVR,
+	S2MU005_IRQ_CHGR_EVENT,
+	S2MU005_IRQ_CHGR_CHG,
+	S2MU005_IRQ_CHGR_VMID,
+	S2MU005_IRQ_CHGR_WCIN,
+	S2MU005_IRQ_CHGR_VBUS,
+
+	S2MU005_IRQ_FLED_LBPROT,
+	S2MU005_IRQ_FLED_OPENCH2,
+	S2MU005_IRQ_FLED_OPENCH1,
+	S2MU005_IRQ_FLED_SHORTCH2,
+	S2MU005_IRQ_FLED_SHORTCH1,
+
+	S2MU005_IRQ_MUIC_ATTACH,
+	S2MU005_IRQ_MUIC_DETACH,
+	S2MU005_IRQ_MUIC_KP,
+	S2MU005_IRQ_MUIC_LKP,
+	S2MU005_IRQ_MUIC_LKR,
+	S2MU005_IRQ_MUIC_RIDCHG,
+
+	S2MU005_IRQ_MUIC_VBUSON,
+	S2MU005_IRQ_MUIC_RSVD,
+	S2MU005_IRQ_MUIC_ADC,
+	S2MU005_IRQ_MUIC_STUCK,
+	S2MU005_IRQ_MUIC_STUCKRCV,
+	S2MU005_IRQ_MUIC_MHDL,
+	S2MU005_IRQ_MUIC_AVCHG,
+	S2MU005_IRQ_MUIC_VBUSOFF,
+
+	S2MU005_IRQ_NR,
+};
+
+#define S2MU005_IRQ_CHGR_DETBAT_MASK	BIT(0)
+#define S2MU005_IRQ_CHGR_BAT_MASK	BIT(1)
+#define S2MU005_IRQ_CHGR_IVR_MASK	BIT(2)
+#define S2MU005_IRQ_CHGR_EVENT_MASK	BIT(3)
+#define S2MU005_IRQ_CHGR_CHG_MASK	BIT(4)
+#define S2MU005_IRQ_CHGR_VMID_MASK	BIT(5)
+#define S2MU005_IRQ_CHGR_WCIN_MASK	BIT(6)
+#define S2MU005_IRQ_CHGR_VBUS_MASK	BIT(7)
+
+#define S2MU005_IRQ_FLED_LBPROT_MASK		BIT(2)
+#define S2MU005_IRQ_FLED_OPENCH2_MASK		BIT(4)
+#define S2MU005_IRQ_FLED_OPENCH1_MASK		BIT(5)
+#define S2MU005_IRQ_FLED_SHORTCH2_MASK		BIT(6)
+#define S2MU005_IRQ_FLED_SHORTCH1_MASK		BIT(7)
+
+#define S2MU005_IRQ_MUIC_ATTACH_MASK		BIT(0)
+#define S2MU005_IRQ_MUIC_DETACH_MASK		BIT(1)
+#define S2MU005_IRQ_MUIC_KP_MASK		BIT(2)
+#define S2MU005_IRQ_MUIC_LKP_MASK		BIT(3)
+#define S2MU005_IRQ_MUIC_LKR_MASK		BIT(4)
+#define S2MU005_IRQ_MUIC_RIDCHG_MASK		BIT(5)
+
+#define S2MU005_IRQ_MUIC_VBUSON_MASK		BIT(0)
+#define S2MU005_IRQ_MUIC_RSVD_MASK		BIT(1)
+#define S2MU005_IRQ_MUIC_ADC_MASK		BIT(2)
+#define S2MU005_IRQ_MUIC_STUCK_MASK		BIT(3)
+#define S2MU005_IRQ_MUIC_STUCKRCV_MASK		BIT(4)
+#define S2MU005_IRQ_MUIC_MHDL_MASK		BIT(5)
+#define S2MU005_IRQ_MUIC_AVCHG_MASK		BIT(6)
+#define S2MU005_IRQ_MUIC_VBUSOFF_MASK		BIT(7)
+

 enum s5m8767_irq {
  S5M8767_IRQ_PWRR,
  S5M8767_IRQ_PWRF,

include/linux/mfd/samsung/s2mu005.h new file +140 -0
new file mode 100644
index 0000000000000..32ad35dda661d
@@ -0,0 +1,328 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd
+ * Copyright (c) 2025 Kaustabh Chakraborty <[email protected]>
+ */
+
+#ifndef __LINUX_MFD_S2MU005_H
+#define __LINUX_MFD_S2MU005_H
+
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+
+/* S2MU005 registers */
+enum s2mu005_reg {
+	S2MU005_REG_CHGR_INT1,
+	S2MU005_REG_CHGR_INT1M,
+
+	S2MU005_REG_FLED_INT1,
+	S2MU005_REG_FLED_INT1M,
+
+	S2MU005_REG_MUIC_INT1,
+	S2MU005_REG_MUIC_INT2,
+	S2MU005_REG_MUIC_INT1M,
+	S2MU005_REG_MUIC_INT2M,
+
+	S2MU005_REG_CHGR_STATUS0,
+	S2MU005_REG_CHGR_STATUS1,
+	S2MU005_REG_CHGR_STATUS2,
+	S2MU005_REG_CHGR_STATUS3,
+	S2MU005_REG_CHGR_STATUS4,
+	S2MU005_REG_CHGR_STATUS5,
+	S2MU005_REG_CHGR_CTRL0,
+	S2MU005_REG_CHGR_CTRL1,
+	S2MU005_REG_CHGR_CTRL2,
+	S2MU005_REG_CHGR_CTRL3,
+	S2MU005_REG_CHGR_CTRL4,
+	S2MU005_REG_CHGR_CTRL5,
+	S2MU005_REG_CHGR_CTRL6,
+	S2MU005_REG_CHGR_CTRL7,
+	S2MU005_REG_CHGR_CTRL8,
+	S2MU005_REG_CHGR_CTRL9,
+	S2MU005_REG_CHGR_CTRL10,
+	S2MU005_REG_CHGR_CTRL11,
+	S2MU005_REG_CHGR_CTRL12,
+	S2MU005_REG_CHGR_CTRL13,
+	S2MU005_REG_CHGR_CTRL14,
+	S2MU005_REG_CHGR_CTRL15,
+	S2MU005_REG_CHGR_CTRL16,
+	S2MU005_REG_CHGR_CTRL17,
+	S2MU005_REG_CHGR_CTRL18,
+	S2MU005_REG_CHGR_CTRL19,
+	S2MU005_REG_CHGR_TEST0,
+	S2MU005_REG_CHGR_TEST1,
+	S2MU005_REG_CHGR_TEST2,
+	S2MU005_REG_CHGR_TEST3,
+	S2MU005_REG_CHGR_TEST4,
+	S2MU005_REG_CHGR_TEST5,
+	S2MU005_REG_CHGR_TEST6,
+	S2MU005_REG_CHGR_TEST7,
+	S2MU005_REG_CHGR_TEST8,
+	S2MU005_REG_CHGR_TEST9,
+	S2MU005_REG_CHGR_TEST10,
+
+	S2MU005_REG_FLED_STATUS,
+	S2MU005_REG_FLED_CH0_CTRL0,
+	S2MU005_REG_FLED_CH0_CTRL1,
+	S2MU005_REG_FLED_CH0_CTRL2,
+	S2MU005_REG_FLED_CH0_CTRL3,
+	S2MU005_REG_FLED_CH1_CTRL0,
+	S2MU005_REG_FLED_CH1_CTRL1,
+	S2MU005_REG_FLED_CH1_CTRL2,
+	S2MU005_REG_FLED_CH1_CTRL3,
+	S2MU005_REG_FLED_CTRL0,
+	S2MU005_REG_FLED_CTRL1,
+	S2MU005_REG_FLED_CTRL2,
+	S2MU005_REG_FLED_CTRL3,
+	S2MU005_REG_FLED_CTRL4,
+	S2MU005_REG_FLED_CTRL5,
+	S2MU005_REG_FLED_CTRL6,
+
+	S2MU005_REG_RGB_EN,
+	S2MU005_REG_RGB_CH0_CTRL,
+	S2MU005_REG_RGB_CH1_CTRL,
+	S2MU005_REG_RGB_CH2_CTRL,
+	S2MU005_REG_RGB_CH0_RAMP,
+	S2MU005_REG_RGB_CH0_STAY,
+	S2MU005_REG_RGB_CH1_RAMP,
+	S2MU005_REG_RGB_CH1_STAY,
+	S2MU005_REG_RGB_CH2_RAMP,
+	S2MU005_REG_RGB_CH2_STAY,
+	S2MU005_REG_RGB_TEST0,
+	S2MU005_REG_RGB_CTRL0,
+
+	S2MU005_REG_MUIC_ADC,
+	S2MU005_REG_MUIC_DEV1,
+	S2MU005_REG_MUIC_DEV2,
+	S2MU005_REG_MUIC_DEV3,
+	S2MU005_REG_MUIC_BUTTON1,
+	S2MU005_REG_MUIC_BUTTON2,
+	S2MU005_REG_MUIC_RESET,
+	S2MU005_REG_MUIC_CHGTYPE,
+	S2MU005_REG_MUIC_DEVAPPLE,
+	S2MU005_REG_MUIC_BCDRESCAN,
+	S2MU005_REG_MUIC_TEST1,
+	S2MU005_REG_MUIC_TEST2,
+	S2MU005_REG_MUIC_TEST3,
+
+	S2MU005_REG_ID = 0x73,
+
+	S2MU005_REG_MUIC_CTRL1 = 0xb2,
+	S2MU005_REG_MUIC_TIMERSET1,
+	S2MU005_REG_MUIC_TIMERSET2,
+	S2MU005_REG_MUIC_SWCTRL,
+	S2MU005_REG_MUIC_TIMERSET3,
+	S2MU005_REG_MUIC_CTRL2,
+	S2MU005_REG_MUIC_CTRL3,
+
+	S2MU005_REG_MUIC_LDOADC_L = 0xbf,
+	S2MU005_REG_MUIC_LDOADC_H,
+};
+
+#define S2MU005_REG_FLED_CH_CTRL0(x)	(S2MU005_REG_FLED_CH0_CTRL0 + 4 * (x))
+#define S2MU005_REG_FLED_CH_CTRL1(x)	(S2MU005_REG_FLED_CH0_CTRL1 + 4 * (x))
+#define S2MU005_REG_FLED_CH_CTRL2(x)	(S2MU005_REG_FLED_CH0_CTRL2 + 4 * (x))
+#define S2MU005_REG_FLED_CH_CTRL3(x)	(S2MU005_REG_FLED_CH0_CTRL3 + 4 * (x))
+
+#define S2MU005_REG_RGB_CH_CTRL(x)	(S2MU005_REG_RGB_CH0_CTRL + 1 * (x))
+#define S2MU005_REG_RGB_CH_RAMP(x)	(S2MU005_REG_RGB_CH0_RAMP + 2 * (x))
+#define S2MU005_REG_RGB_CH_STAY(x)	(S2MU005_REG_RGB_CH0_STAY + 2 * (x))
+
+/* S2MU005_REG_CHGR_STATUS0 */
+#define S2MU005_CHGR_VBUS		BIT(7)
+#define S2MU005_CHGR_WCIN		BIT(6)
+#define S2MU005_CHGR_VMID		BIT(5)
+#define S2MU005_CHGR_CHG		BIT(4)
+#define S2MU005_CHGR_STAT		GENMASK(3, 0)
+
+#define S2MU005_CHGR_STAT_DONE		FIELD_PREP(S2MU005_CHGR_STAT, 8)
+#define S2MU005_CHGR_STAT_TOPOFF	FIELD_PREP(S2MU005_CHGR_STAT, 7)
+#define S2MU005_CHGR_STAT_DONE_FLAG	FIELD_PREP(S2MU005_CHGR_STAT, 6)

include/linux/mfd/samsung/s2mu005.h line 150

Quoted 10 lines
include/linux/mfd/samsung/s2mu005.h new file +10 -0
+#define S2MU005_CHGR_STAT_CV		FIELD_PREP(S2MU005_CHGR_STAT, 5)
+#define S2MU005_CHGR_STAT_CC		FIELD_PREP(S2MU005_CHGR_STAT, 4)
+#define	S2MU005_CHGR_STAT_COOL_CHG	FIELD_PREP(S2MU005_CHGR_STAT, 3)
+#define S2MU005_CHGR_STAT_PRE_CHG	FIELD_PREP(S2MU005_CHGR_STAT, 2)
+
+/* S2MU005_REG_CHGR_STATUS1 */
+#define S2MU005_CHGR_DETBAT		BIT(7)
+#define S2MU005_CHGR_VBUSOVP		GENMASK(6, 4)
+
+#define S2MU005_CHGR_VBUS_OVP_OVERVOLT	FIELD_PREP(S2MU005_CHGR_OVP, 2)

With definitions like these you can't compare to FIELD_GET on the register value anymore, i.e. this doesn't work:

reg = readl();
val = FIELD_GET(S2MU005_CHGR_VBUSOVP, reg);
if (val == S2MU005_CHGR_VBUS_OVP_OVERVOLT)
...

or FIELD_PREP() or FIELD_MODIFY() won't work as expected.

I would expect such code to work using usual semantics.

Just define your field values without FIELD_PREP(), e.g.

#define S2MU005_CHGR_VBUS_OVP_OVERVOLT 2

Cheers,
Andre'

Quoted 178 lines
include/linux/mfd/samsung/s2mu005.h new file +178 -0
+
+/* S2MU005_REG_CHGR_STATUS2 */
+#define S2MU005_CHGR_BAT		GENMASK(6, 4)
+
+#define	S2MU005_CHGR_BAT_VOLT_DET	FIELD_PREP(S2MU005_CHGR_BAT, 7)
+#define S2MU005_CHGR_BAT_FAST_CHG_DET	FIELD_PREP(S2MU005_CHGR_BAT, 6)
+#define	S2MU005_CHGR_BAT_COOL_CHG_DET	FIELD_PREP(S2MU005_CHGR_BAT, 5)
+#define S2MU005_CHGR_BAT_LOW_CHG	FIELD_PREP(S2MU005_CHGR_BAT, 2)
+#define S2MU005_CHGR_BAT_SELF_DISCHG	FIELD_PREP(S2MU005_CHGR_BAT, 1)
+#define S2MU005_CHGR_BAT_OVP_DET	FIELD_PREP(S2MU005_CHGR_BAT, 0)
+
+/* S2MU005_REG_CHGR_STATUS3 */
+#define S2MU005_CHGR_EVT		GENMASK(3, 0)
+
+#define S2MU005_CHGR_EVT_WDT_RST	FIELD_PREP(S2MU005_CHGR_EVT, 6)
+#define S2MU005_CHGR_EVT_WDT_SUSP	FIELD_PREP(S2MU005_CHGR_EVT, 5)
+#define S2MU005_CHGR_EVT_VSYS_VUVLO	FIELD_PREP(S2MU005_CHGR_EVT, 4)
+#define S2MU005_CHGR_EVT_VSYS_VOVP	FIELD_PREP(S2MU005_CHGR_EVT, 3)
+#define S2MU005_CHGR_EVT_THERM_FOLDBACK	FIELD_PREP(S2MU005_CHGR_EVT, 2)
+#define S2MU005_CHGR_EVT_THERM_SHUTDOWN	FIELD_PREP(S2MU005_CHGR_EVT, 1)
+
+/* S2MU005_REG_CHGR_CTRL0 */
+#define S2MU005_CHGR_CHG_EN		BIT(4)
+#define S2MU005_CHGR_OP_MODE		GENMASK(2, 0)
+
+#define S2MU005_CHGR_OP_MODE_OTG	FIELD_PREP(S2MU005_CHGR_OP_MODE, BIT(2))
+#define S2MU005_CHGR_OP_MODE_CHG	FIELD_PREP(S2MU005_CHGR_OP_MODE, BIT(1))
+
+/* S2MU005_REG_CHGR_CTRL1 */
+#define S2MU005_CHGR_VIN_DROP		GENMASK(6, 4)
+
+/* S2MU005_REG_CHGR_CTRL2 */
+#define S2MU005_CHGR_IN_CURR_LIM	GENMASK(5, 0)
+
+/* S2MU005_REG_CHGR_CTRL4 */
+#define S2MU005_CHGR_OTG_OCP_ON		BIT(5)
+#define S2MU005_CHGR_OTG_OCP_OFF	BIT(4)
+#define S2MU005_CHGR_OTG_OCP		GENMASK(3, 2)
+
+/* S2MU005_REG_CHGR_CTRL5 */
+#define S2MU005_CHGR_VMID_BOOST		GENMASK(4, 0)
+
+/* S2MU005_REG_CHGR_CTRL6 */
+#define S2MU005_CHGR_COOL_CHG_CURR	GENMASK(5, 0)
+
+/* S2MU005_REG_CHGR_CTRL7 */
+#define S2MU005_CHGR_FAST_CHG_CURR	GENMASK(5, 0)
+
+/* S2MU005_REG_CHGR_CTRL8 */
+#define S2MU005_CHGR_VF_VBAT		GENMASK(6, 1)
+
+/* S2MU005_REG_CHGR_CTRL10 */
+#define S2MU005_CHGR_TOPOFF_CURR(x)	(GENMASK(3, 0) << 4 * (x))
+
+/* S2MU005_REG_CHGR_CTRL11 */
+#define S2MU005_CHGR_OSC_BOOST		GENMASK(6, 5)
+#define S2MU005_CHGR_OSC_BUCK		GENMASK(4, 3)
+
+/* S2MU005_REG_CHGR_CTRL12 */
+#define S2MU005_CHGR_WDT		GENMASK(2, 0)
+
+#define S2MU005_CHGR_WDT_ON		FIELD_PREP(S2MU005_CHGR_WDT, BIT(2))
+#define S2MU005_CHGR_WDT_OFF		FIELD_PREP(S2MU005_CHGR_WDT, BIT(1))
+
+/* S2MU005_REG_CHGR_CTRL15 */
+#define S2MU005_CHGR_OTG_EN		GENMASK(3, 2)
+
+/* S2MU005_REG_FLED_STATUS */
+#define S2MU005_FLED_FLASH_STATUS(x)	(BIT(7) >> 2 * (x))
+#define S2MU005_FLED_TORCH_STATUS(x)	(BIT(6) >> 2 * (x))
+
+/* S2MU005_REG_FLED_CHx_CTRL0 */
+#define S2MU005_FLED_FLASH_IOUT		GENMASK(3, 0)
+
+/* S2MU005_REG_FLED_CHx_CTRL1 */
+#define S2MU005_FLED_TORCH_IOUT		GENMASK(3, 0)
+
+/* S2MU005_REG_FLED_CHx_CTRL2 */
+#define S2MU005_FLED_TORCH_TIMEOUT	GENMASK(3, 0)
+
+/* S2MU005_REG_FLED_CHx_CTRL3 */
+#define S2MU005_FLED_FLASH_TIMEOUT	GENMASK(3, 0)
+
+/* S2MU005_REG_FLED_CTRL1 */
+#define S2MU005_FLED_CH_EN		BIT(7)
+
+/*
+ * S2MU005_REG_FLED_CTRL4 - Rev. EVT0
+ * S2MU005_REG_FLED_CTRL6 - Rev. EVT1 and later
+ */
+#define S2MU005_FLED_FLASH_EN(x)	(GENMASK(7, 6) >> 4 * (x))
+#define S2MU005_FLED_TORCH_EN(x)	(GENMASK(5, 4) >> 4 * (x))
+
+/* S2MU005_REG_RGB_EN */
+#define S2MU005_RGB_RESET		BIT(6)
+#define S2MU005_RGB_SLOPE		GENMASK(5, 0)
+
+#define S2MU005_RGB_SLOPE_CONST		(BIT(4) | BIT(2) | BIT(0))
+#define S2MU005_RGB_SLOPE_SMOOTH	(BIT(5) | BIT(3) | BIT(1))
+
+/* S2MU005_REG_RGB_CHx_RAMP */
+#define S2MU005_RGB_CH_RAMP_UP		GENMASK(7, 4)
+#define S2MU005_RGB_CH_RAMP_DN		GENMASK(3, 0)
+
+/* S2MU005_REG_RGB_CHx_STAY */
+#define S2MU005_RGB_CH_STAY_HI		GENMASK(7, 4)
+#define S2MU005_RGB_CH_STAY_LO		GENMASK(3, 0)
+
+/* S2MU005_REG_MUIC_DEV1 */
+#define S2MU005_MUIC_OTG		BIT(7)
+#define S2MU005_MUIC_DCP		BIT(6)
+#define S2MU005_MUIC_CDP		BIT(5)
+#define S2MU005_MUIC_T1_T2_CHG		BIT(4)
+#define S2MU005_MUIC_UART		BIT(3)
+#define S2MU005_MUIC_SDP		BIT(2)
+#define S2MU005_MUIC_LANHUB		BIT(1)
+#define S2MU005_MUIC_AUDIO		BIT(0)
+
+/* S2MU005_REG_MUIC_DEV2 */
+#define S2MU005_MUIC_SDP_1P8S		BIT(7)
+#define S2MU005_MUIC_AV			BIT(6)
+#define S2MU005_MUIC_TTY		BIT(5)
+#define S2MU005_MUIC_PPD		BIT(4)
+#define S2MU005_MUIC_JIG_UART_OFF	BIT(3)
+#define S2MU005_MUIC_JIG_UART_ON	BIT(2)
+#define S2MU005_MUIC_JIG_USB_OFF	BIT(1)
+#define S2MU005_MUIC_JIG_USB_ON		BIT(0)
+
+/* S2MU005_REG_MUIC_DEV3 */
+#define S2MU005_MUIC_U200_CHG		BIT(7)
+#define S2MU005_MUIC_VBUS_AV		BIT(4)
+#define S2MU005_MUIC_VBUS_R255		BIT(1)
+#define S2MU005_MUIC_MHL		BIT(0)
+
+/* S2MU005_REG_MUIC_DEVAPPLE */
+#define S2MU005_MUIC_APPLE_CHG_0P5A	BIT(7)
+#define S2MU005_MUIC_APPLE_CHG_1P0A	BIT(6)
+#define S2MU005_MUIC_APPLE_CHG_2P0A	BIT(5)
+#define S2MU005_MUIC_APPLE_CHG_2P4A	BIT(4)
+#define S2MU005_MUIC_SDP_DCD_OUT	BIT(3)
+#define S2MU005_MUIC_RID_WAKEUP		BIT(2)
+#define S2MU005_MUIC_VBUS_WAKEUP	BIT(1)
+#define S2MU005_MUIC_BCV1P2_OR_OPEN	BIT(0)
+
+/* S2MU005_REG_ID */
+#define S2MU005_ID_MASK			GENMASK(3, 0)
+#define S2MU005_ID_SHIFT		0
+
+/* S2MU005_REG_MUIC_SWCTRL */
+#define S2MU005_MUIC_DM_DP		GENMASK(7, 2)
+#define S2MU005_MUIC_JIG		BIT(0)
+
+#define S2MU005_MUIC_DM_DP_UART		FIELD_PREP(S2MU005_MUIC_DM_DP, 0x12)
+#define S2MU005_MUIC_DM_DP_USB		FIELD_PREP(S2MU005_MUIC_DM_DP, 0x09)
+
+/* S2MU005_REG_MUIC_CTRL1 */
+#define S2MU005_MUIC_OPEN		BIT(4)
+#define S2MU005_MUIC_RAW_DATA		BIT(3)
+#define S2MU005_MUIC_MAN_SW		BIT(2)
+#define S2MU005_MUIC_WAIT		BIT(1)
+#define S2MU005_MUIC_IRQ		BIT(0)
+
+/* S2MU005_REG_MUIC_CTRL3 */
+#define S2MU005_MUIC_ONESHOT_ADC	BIT(2)
+
+/* S2MU005_REG_MUIC_LDOADC_L and S2MU005_REG_MUIC_LDOADC_H */
+#define S2MU005_MUIC_VSET		GENMASK(4, 0)
+
+#define S2MU005_MUIC_VSET_3P0V		FIELD_PREP(S2MU005_MUIC_VSET, 0x1f)
+#define S2MU005_MUIC_VSET_2P6V		FIELD_PREP(S2MU005_MUIC_VSET, 0x0e)
+#define S2MU005_MUIC_VSET_2P4V		FIELD_PREP(S2MU005_MUIC_VSET, 0x0c)
+#define S2MU005_MUIC_VSET_2P2V		FIELD_PREP(S2MU005_MUIC_VSET, 0x0a)
+#define S2MU005_MUIC_VSET_2P0V		FIELD_PREP(S2MU005_MUIC_VSET, 0x08)
+#define S2MU005_MUIC_VSET_1P5V		FIELD_PREP(S2MU005_MUIC_VSET, 0x03)
+#define S2MU005_MUIC_VSET_1P4V		FIELD_PREP(S2MU005_MUIC_VSET, 0x02)
+#define S2MU005_MUIC_VSET_1P2V		FIELD_PREP(S2MU005_MUIC_VSET, 0x00)
+
+#endif	/* __LINUX_MFD_S2MU005_H */
#16 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

Quoted 22 lines · André Draszik

Hi,

Quoted 19 lines · Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

S2MU005's interrupt registers can be properly divided into three regmap IRQ chips, one each for the charger, flash LEDs, and the MUIC.

Add initial support for S2MU005 in the PMIC driver, along with it's three interrupt chips.

---
 drivers/mfd/sec-common.c            |  16 ++ drivers/mfd/sec-i2c.c               |  12 ++ drivers/mfd/sec-irq.c               |  74 ++++++++ include/linux/mfd/samsung/core.h    |   1 + include/linux/mfd/samsung/irq.h     |  66 ++++++++ include/linux/mfd/samsung/s2mu005.h | 328 ++++++++++++++++++++++++++++++++++++

 6 files changed, 497 insertions(+)

[...]

Quoted 14 lines
Quoted 14 lines
drivers/mfd/sec-i2c.c +1 -0
index 3132b849b4bc4..3f1d70cc3292b 100644
@@ -17,6 +17,7 @@
  #include <linux/mfd/samsung/s2mps14.h>
  #include <linux/mfd/samsung/s2mps15.h>
  #include <linux/mfd/samsung/s2mpu02.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/mfd/samsung/s5m8767.h>
  #include <linux/mod_devicetable.h>
  #include <linux/module.h>
@@ -130,6 +131,11 @@ static const struct regmap_config s2mpu05_regmap_config = {
  	.val_bits = 8,
Quoted 9 lines

drivers/mfd/sec-i2c.c static const struct regmap_config s2mpu05_regmap_config = { · line 137

Quoted 6 lines
drivers/mfd/sec-i2c.c +0 -0
  };

drivers/mfd/sec-i2c.c +4 -0
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};

No cache? And what is the .max_register value?

This was in the previous revision, but I ended up removing it because (at least I thought at that time) interfered with interrupts firing in some way. The actual issue was unrelated, so I will add it back.

However, there is also another thing I see in logs:

sec-pmic-i2c 2-003d: using zero-initialized flat cache, this may cause unexpected behavior

This is due to REGCACHE_FLAT, I am not sure if I should just ignore this.

maintainer
#17 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

Quoted 54 lines · Kaustabh Chakraborty
Quoted 22 lines · André Draszik

Hi,

Quoted 19 lines · Kaustabh Chakraborty

Samsung's S2MU005 PMIC includes subdevices for a charger, an MUIC (Micro USB Interface Controller), and flash and RGB LED controllers.

S2MU005's interrupt registers can be properly divided into three regmap IRQ chips, one each for the charger, flash LEDs, and the MUIC.

Add initial support for S2MU005 in the PMIC driver, along with it's three interrupt chips.

---
 drivers/mfd/sec-common.c            |  16 ++ drivers/mfd/sec-i2c.c               |  12 ++ drivers/mfd/sec-irq.c               |  74 ++++++++ include/linux/mfd/samsung/core.h    |   1 + include/linux/mfd/samsung/irq.h     |  66 ++++++++ include/linux/mfd/samsung/s2mu005.h | 328 ++++++++++++++++++++++++++++++++++++

 6 files changed, 497 insertions(+)

[...]

Quoted 14 lines
Quoted 14 lines
drivers/mfd/sec-i2c.c +1 -0
index 3132b849b4bc4..3f1d70cc3292b 100644
@@ -17,6 +17,7 @@
  #include <linux/mfd/samsung/s2mps14.h>
  #include <linux/mfd/samsung/s2mps15.h>
  #include <linux/mfd/samsung/s2mpu02.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/mfd/samsung/s5m8767.h>
  #include <linux/mod_devicetable.h>
  #include <linux/module.h>
@@ -130,6 +131,11 @@ static const struct regmap_config s2mpu05_regmap_config = {
  	.val_bits = 8,
Quoted 9 lines

drivers/mfd/sec-i2c.c static const struct regmap_config s2mpu05_regmap_config = { · line 137

Quoted 6 lines
drivers/mfd/sec-i2c.c +0 -0
  };

drivers/mfd/sec-i2c.c +4 -0
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};

No cache? And what is the .max_register value?

This was in the previous revision, but I ended up removing it because (at least I thought at that time) interfered with interrupts firing in some way. The actual issue was unrelated, so I will add it back.

Quoted 6 lines

However, there is also another thing I see in logs:

sec-pmic-i2c 2-003d: using zero-initialized flat cache, this may cause unexpected behavior

This is due to REGCACHE_FLAT, I am not sure if I should just ignore this.

I think the error might be because you should also specify num_reg_defaults_raw:

.max_register = xxx,
.num_reg_defaults_raw = xxx + 1,

Cheers,
Andre'

#18 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

In reply to Kaustabh Chakraborty

Hi,

Quoted 14 lines · Kaustabh Chakraborty
Quoted 8 lines · André Draszik

drivers/mfd/sec-i2c.c static const struct regmap_config s2mpu05_regmap_config = { · line 137

Quoted 4 lines · Kaustabh Chakraborty
drivers/mfd/sec-i2c.c +4 -0
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};

No cache? And what is the .max_register value?

This was in the previous revision, but I ended up removing it because (at least I thought at that time) interfered with interrupts firing in some way. The actual issue was unrelated, so I will add it back.

Quoted 7 lines

However, there is also another thing I see in logs:

sec-pmic-i2c 2-003d: using zero-initialized flat cache, this may cause unexpected behavior

This is due to REGCACHE_FLAT, I am not sure if I should just ignore this.

Sorry to be late to the party, but I'm somewhat responsible for that warning, so allow me to chime in :-)

What you are might have been seeing is REGCACHE_FLAT giving you "cached" values of 0x0, while the hardware actually has something else. This can cause omitted writes, existing (bootloader) config to overwritten, etc.

As André suggested, using .num_reg_defaults_raw is a possibility, but then you have to remember that the register defaults are taken to be what the hardware state is at that moment, including pre-probe changes. These defaults are used to seed the cache (so far, so good), but this may break the contract of regmap_sync() if you ever want to use that after actually resetting the PMIC.

If you want to use the flat cache, I would suggest you use REGCACHE_FLAT_S, which will track what has already been read from/written to hardware. You will also need to specifiy .max_register.

I see the other regmap_config-s in this driver also use REGCACHE_FLAT, so you may want to consider switching those over as well if these are also showing the new warning.

Best,
Sander

#19 lore raw

Re: [PATCH v2 06/12] mfd: sec: add support for S2MU005 PMIC

Quoted 38 lines · Sander Vanheule

Hi,

Quoted 14 lines · Kaustabh Chakraborty
Quoted 8 lines · André Draszik

drivers/mfd/sec-i2c.c static const struct regmap_config s2mpu05_regmap_config = { · line 137

Quoted 4 lines · Kaustabh Chakraborty
drivers/mfd/sec-i2c.c +4 -0
+static const struct regmap_config s2mu005_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};

No cache? And what is the .max_register value?

This was in the previous revision, but I ended up removing it because (at least I thought at that time) interfered with interrupts firing in some way. The actual issue was unrelated, so I will add it back.

Quoted 7 lines

However, there is also another thing I see in logs:

sec-pmic-i2c 2-003d: using zero-initialized flat cache, this may cause unexpected behavior

This is due to REGCACHE_FLAT, I am not sure if I should just ignore this.

Sorry to be late to the party, but I'm somewhat responsible for that warning, so allow me to chime in :-)

What you are might have been seeing is REGCACHE_FLAT giving you "cached" values of 0x0, while the hardware actually has something else. This can cause omitted writes, existing (bootloader) config to overwritten, etc.

As André suggested, using .num_reg_defaults_raw is a possibility, but then you have to remember that the register defaults are taken to be what the hardware state is at that moment, including pre-probe changes. These defaults are used to seed the cache (so far, so good), but this may break the contract of regmap_sync() if you ever want to use that after actually resetting the PMIC.

Quoted 3 lines

If you want to use the flat cache, I would suggest you use REGCACHE_FLAT_S, which will track what has already been read from/written to hardware. You will also need to specifiy .max_register.

I had figured that out by going through the logs, thanks. :)

Quoted 8 lines

I see the other regmap_config-s in this driver also use REGCACHE_FLAT, so you may want to consider switching those over as well if these are also showing the new warning.

Best,
Sander

#20 lore raw

PATCH 1/1 mfd: sec-irq: fix non-constant case labels in s2mu005_irq_get_reg

In reply to Kaustabh Chakraborty

Case labels must be compile-time constants, but the original implementation used array element values like irqf_regs[0], causing a compilation error:

drivers/mfd/sec-irq.c:218:9: error: case label does not reduce to an integer constant

Replace array-based case labels with explicit S2MU005_REG_* defines for all four interrupt status and mask registers, preserving the original logic.

This addresses an issue in the S2MU005 PMIC support patches [1].

---
 drivers/mfd/sec-irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mfd/sec-irq.c +8 -2
index 44a1eb074a08..73a611ba0502 100644
@@ -215,9 +215,15 @@ static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data,
 	};
 
 	switch (base) {
-	case irqf_regs[0]:
+	case S2MU005_REG_CHGR_INT1:
+	case S2MU005_REG_FLED_INT1:
+	case S2MU005_REG_MUIC_INT1:
+	case S2MU005_REG_MUIC_INT2:
 		return irqf_regs[index];
-	case mask_regs[0]:
+	case S2MU005_REG_CHGR_INT1M:
+	case S2MU005_REG_FLED_INT1M:
+	case S2MU005_REG_MUIC_INT1M:
+	case S2MU005_REG_MUIC_INT2M:
 		return mask_regs[index];
 	}
 
Signature · 1 line
2.53.0
#21 lore raw

Re: [PATCH FIX] mfd: sec-irq: fix non-constant case labels in s2mu005_irq_get_reg

Quoted 1 line · On Mon, 9 Feb 2026 05:03:58 +0100 Łukasz Lebiedziński <[email protected]> wrote:

Case labels must be compile-time constants,

They must be 'integer constant expressions' which it stronger than 'compile time constant'.

Quoted 4 lines

but the original
implementation used array element values like irqf_regs[0], causing a compilation error:

Quoted 8 lines

drivers/mfd/sec-irq.c:218:9: error: case label does not reduce to an integer constant

Replace array-based case labels with explicit S2MU005_REG_* defines for all four interrupt status and mask registers, preserving the original logic.

This addresses an issue in the S2MU005 PMIC support patches [1].

Makes one wonder how the patches were tested.

Quoted 18 lines
---
 drivers/mfd/sec-irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mfd/sec-irq.c +2 -1
index 44a1eb074a08..73a611ba0502 100644
@@ -215,9 +215,15 @@ static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data,
 	};
 
 	switch (base) {
-	case irqf_regs[0]:
+	case S2MU005_REG_CHGR_INT1:
+	case S2MU005_REG_FLED_INT1:

drivers/mfd/sec-irq.c static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data, · line 228

Quoted 10 lines
drivers/mfd/sec-irq.c +6 -1
+	case S2MU005_REG_MUIC_INT1:
+	case S2MU005_REG_MUIC_INT2:
 		return irqf_regs[index];
-	case mask_regs[0]:
+	case S2MU005_REG_CHGR_INT1M:
+	case S2MU005_REG_FLED_INT1M:
+	case S2MU005_REG_MUIC_INT1M:
+	case S2MU005_REG_MUIC_INT2M:
 		return mask_regs[index];
 	}

That looks as though it ought to be an if statement (or two).

David

Quoted 1 line
#22 lore raw

Re: [PATCH FIX] mfd: sec-irq: fix non-constant case labels in s2mu005_irq_get_reg

In reply to Łukasz Lebiedziński
Quoted 6 lines · Łukasz Lebiedziński

Case labels must be compile-time constants, but the original implementation used array element values like irqf_regs[0], causing a compilation error:

drivers/mfd/sec-irq.c:218:9: error: case label does not reduce to an integer constant

This was already reported by lkp bot, and I have fixed it locally already. Weirdly, I don't get this error somehow.

Quoted 18 lines

Replace array-based case labels with explicit S2MU005_REG_* defines for all four interrupt status and mask registers, preserving the original logic.

This addresses an issue in the S2MU005 PMIC support patches [1].

---
 drivers/mfd/sec-irq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/mfd/sec-irq.c +0 -0
index 44a1eb074a08..73a611ba0502 100644

drivers/mfd/sec-irq.c static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data, · line 221

Quoted 8 lines
drivers/mfd/sec-irq.c +4 -1
@@ -215,9 +215,15 @@ static unsigned int s2mu005_irq_get_reg(struct regmap_irq_chip_data *data,
 	};
 
 	switch (base) {
-	case irqf_regs[0]:
+	case S2MU005_REG_CHGR_INT1:
+	case S2MU005_REG_FLED_INT1:
+	case S2MU005_REG_MUIC_INT1:
+	case S2MU005_REG_MUIC_INT2:

We're checking the base register here, so all other than the first one is redundant.

Quoted 9 lines
drivers/mfd/sec-irq.c +4 -1
 		return irqf_regs[index];
-	case mask_regs[0]:
+	case S2MU005_REG_CHGR_INT1M:
+	case S2MU005_REG_FLED_INT1M:
+	case S2MU005_REG_MUIC_INT1M:
+	case S2MU005_REG_MUIC_INT2M:
 		return mask_regs[index];
 	}
 
#23 lore raw

PATCH v2 7/12 mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support

In reply to Kaustabh Chakraborty

The device revision matters in cases when in some PMICs, the correct register offsets very in different revisions. Instead of just debug printing the value, store it in the driver data struct.

Unlike other devices, S2MU005 has its hardware revision ID in register offset 0x73. Allow handling different devices and add support for S2MU005.

---
 drivers/mfd/sec-common.c         | 41 ++++++++++++++++++++++++++++++----------
 include/linux/mfd/samsung/core.h |  1 +
 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/mfd/sec-common.c +31 -10
index bc2a1f2c6dc7a..069a1ba9aa1f1 100644
@@ -16,6 +16,7 @@
 #include <linux/mfd/samsung/irq.h>
 #include <linux/mfd/samsung/s2mps11.h>
 #include <linux/mfd/samsung/s2mps13.h>
+#include <linux/mfd/samsung/s2mu005.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/pm.h>
@@ -111,17 +112,38 @@ static const struct mfd_cell s2mu005_devs[] = {
 	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
 };
 
-static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
+static int sec_pmic_store_rev(struct sec_pmic_dev *sec_pmic)
 {
-	unsigned int val;
+	unsigned int reg, mask, shift;
+	int ret;
 
-	/* For s2mpg1x, the revision is in a different regmap */
-	if (sec_pmic->device_type == S2MPG10)
-		return;
+	switch (sec_pmic->device_type) {
+	case S2MPG10:
+		/* For s2mpg1x, the revision is in a different regmap */
+		return 0;
+	case S2MU005:
+		reg = S2MU005_REG_ID;
+		mask = S2MU005_ID_MASK;
+		shift = S2MU005_ID_SHIFT;
+		break;
+	default:
+		/* For other device types, the REG_ID is always the first register. */
+		reg = S2MPS11_REG_ID;
+		mask = ~0;
+		shift = 0;
+	}
+
+	ret = regmap_read(sec_pmic->regmap_pmic, reg, &sec_pmic->revision);
+	if (ret) {
+		dev_err(sec_pmic->dev, "Failed to read PMIC revision (%d)\n", ret);
+		return ret;
+	}
+
+	sec_pmic->revision &= mask;
+	sec_pmic->revision >>= shift;
 
-	/* For each device type, the REG_ID is always the first register */
-	if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
-		dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
+	dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", sec_pmic->revision);
+	return 0;
 }
 
 static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)
@@ -262,9 +284,8 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
 		return ret;
 
 	sec_pmic_configure(sec_pmic);
-	sec_pmic_dump_rev(sec_pmic);
 
-	return ret;
+	return sec_pmic_store_rev(sec_pmic);
 }
 EXPORT_SYMBOL_GPL(sec_pmic_probe);
 
include/linux/mfd/samsung/core.h +1 -0
index 43e0c5e55f5d3..56aa33d7e3d60 100644
@@ -70,6 +70,7 @@ struct sec_pmic_dev {
 
 	int device_type;
 	int irq;
+	unsigned int revision;
 };
 
 struct sec_platform_data {
Signature · 1 line
2.52.0
maintainer
#24 lore raw

Re: [PATCH v2 07/12] mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support

Hi Kaustabh,

Quoted 2 lines · Kaustabh Chakraborty

The device revision matters in cases when in some PMICs, the correct register offsets very in different revisions. Instead of just debug

s/very/vary

Quoted 1 line

printing the value, store it in the driver data struct.

Please mention that you're not doing that for s2mpg1x, though.

Quoted 88 lines

Unlike other devices, S2MU005 has its hardware revision ID in register offset 0x73. Allow handling different devices and add support for S2MU005.

---
 drivers/mfd/sec-common.c         | 41 ++++++++++++++++++++++++++++++---------- include/linux/mfd/samsung/core.h |  1 +

 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/mfd/sec-common.c +1 -0
index bc2a1f2c6dc7a..069a1ba9aa1f1 100644
@@ -16,6 +16,7 @@
  #include <linux/mfd/samsung/irq.h>
  #include <linux/mfd/samsung/s2mps11.h>
  #include <linux/mfd/samsung/s2mps13.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/module.h>
  #include <linux/of.h>
  #include <linux/pm.h>
@@ -111,17 +112,38 @@ static const struct mfd_cell s2mu005_devs[] = {
  	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
  };

drivers/mfd/sec-common.c +1 -1
-static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
+static int sec_pmic_store_rev(struct sec_pmic_dev *sec_pmic)

 {

drivers/mfd/sec-common.c +2 -1
-	unsigned int val;
+	unsigned int reg, mask, shift;
+	int ret;

drivers/mfd/sec-common.c +24 -3
-	/* For s2mpg1x, the revision is in a different regmap */
-	if (sec_pmic->device_type == S2MPG10)
-		return;
+	switch (sec_pmic->device_type) {
+	case S2MPG10:
+		/* For s2mpg1x, the revision is in a different regmap */
+		return 0;
+	case S2MU005:
+		reg = S2MU005_REG_ID;
+		mask = S2MU005_ID_MASK;
+		shift = S2MU005_ID_SHIFT;
+		break;
+	default:
+		/* For other device types, the REG_ID is always the first register. */
+		reg = S2MPS11_REG_ID;
+		mask = ~0;
+		shift = 0;
+	}
+
+	ret = regmap_read(sec_pmic->regmap_pmic, reg, &sec_pmic->revision);
+	if (ret) {
+		dev_err(sec_pmic->dev, "Failed to read PMIC revision (%d)\n", ret);
+		return ret;
+	}
+
+	sec_pmic->revision &= mask;
+	sec_pmic->revision >>= shift;

drivers/mfd/sec-common.c +2 -3
-	/* For each device type, the REG_ID is always the first register */
-	if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
-		dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
+	dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", sec_pmic->revision);
+	return 0;

 }

 static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)

drivers/mfd/sec-common.c +0 -0
@@ -262,9 +284,8 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
  		return ret;


  sec_pmic_configure(sec_pmic);

drivers/mfd/sec-common.c +0 -1
-	sec_pmic_dump_rev(sec_pmic);

drivers/mfd/sec-common.c +1 -1
-	return ret;
+	return sec_pmic_store_rev(sec_pmic);

 }
 EXPORT_SYMBOL_GPL(sec_pmic_probe);

include/linux/mfd/samsung/core.h +0 -0
index 43e0c5e55f5d3..56aa33d7e3d60 100644
@@ -70,6 +70,7 @@ struct sec_pmic_dev {


  int device_type;
  int irq;

include/linux/mfd/samsung/core.h struct sec_pmic_dev { · line 73

Quoted 1 line
include/linux/mfd/samsung/core.h +1 -0
+	unsigned int revision;

kerneldoc needs to be updated.

Given the LED driver is the only driver & device so far which needs the PMIC revision, maybe for now that driver could determine the revision itself instead of adding this new member for everybody?

Cheers,
Andre'

Quoted 3 lines

 };

 struct sec_platform_data {

#25 lore raw

Re: [PATCH v2 07/12] mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support

Quoted 95 lines · André Draszik

Hi Kaustabh,

Quoted 2 lines · Kaustabh Chakraborty

The device revision matters in cases when in some PMICs, the correct register offsets very in different revisions. Instead of just debug

s/very/vary

Quoted 1 line

printing the value, store it in the driver data struct.

Please mention that you're not doing that for s2mpg1x, though.

Quoted 83 lines

Unlike other devices, S2MU005 has its hardware revision ID in register offset 0x73. Allow handling different devices and add support for S2MU005.

---
 drivers/mfd/sec-common.c         | 41 ++++++++++++++++++++++++++++++---------- include/linux/mfd/samsung/core.h |  1 +

 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/mfd/sec-common.c +1 -0
index bc2a1f2c6dc7a..069a1ba9aa1f1 100644
@@ -16,6 +16,7 @@
  #include <linux/mfd/samsung/irq.h>
  #include <linux/mfd/samsung/s2mps11.h>
  #include <linux/mfd/samsung/s2mps13.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/module.h>
  #include <linux/of.h>
  #include <linux/pm.h>
@@ -111,17 +112,38 @@ static const struct mfd_cell s2mu005_devs[] = {
  	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
  };

drivers/mfd/sec-common.c +1 -1
-static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
+static int sec_pmic_store_rev(struct sec_pmic_dev *sec_pmic)

 {

drivers/mfd/sec-common.c +2 -1
-	unsigned int val;
+	unsigned int reg, mask, shift;
+	int ret;

drivers/mfd/sec-common.c +24 -3
-	/* For s2mpg1x, the revision is in a different regmap */
-	if (sec_pmic->device_type == S2MPG10)
-		return;
+	switch (sec_pmic->device_type) {
+	case S2MPG10:
+		/* For s2mpg1x, the revision is in a different regmap */
+		return 0;
+	case S2MU005:
+		reg = S2MU005_REG_ID;
+		mask = S2MU005_ID_MASK;
+		shift = S2MU005_ID_SHIFT;
+		break;
+	default:
+		/* For other device types, the REG_ID is always the first register. */
+		reg = S2MPS11_REG_ID;
+		mask = ~0;
+		shift = 0;
+	}
+
+	ret = regmap_read(sec_pmic->regmap_pmic, reg, &sec_pmic->revision);
+	if (ret) {
+		dev_err(sec_pmic->dev, "Failed to read PMIC revision (%d)\n", ret);
+		return ret;
+	}
+
+	sec_pmic->revision &= mask;
+	sec_pmic->revision >>= shift;

drivers/mfd/sec-common.c +2 -3
-	/* For each device type, the REG_ID is always the first register */
-	if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
-		dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
+	dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", sec_pmic->revision);
+	return 0;

 }

 static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)

drivers/mfd/sec-common.c +0 -0
@@ -262,9 +284,8 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
  		return ret;


  sec_pmic_configure(sec_pmic);

drivers/mfd/sec-common.c +0 -1
-	sec_pmic_dump_rev(sec_pmic);

drivers/mfd/sec-common.c +1 -1
-	return ret;
+	return sec_pmic_store_rev(sec_pmic);

 }
 EXPORT_SYMBOL_GPL(sec_pmic_probe);

include/linux/mfd/samsung/core.h +0 -1
index 43e0c5e55f5d3..56aa33d7e3d60 100644
--- a/include/linux/mfd/samsung/core.h
Quoted 8 lines

include/linux/mfd/samsung/core.h struct sec_pmic_dev { · line 73

Quoted 6 lines

+++ b/include/linux/mfd/samsung/core.h

include/linux/mfd/samsung/core.h +0 -0
@@ -70,6 +70,7 @@ struct sec_pmic_dev {


  int device_type;
  int irq;

include/linux/mfd/samsung/core.h +1 -0
+	unsigned int revision;

kerneldoc needs to be updated.

Seems like it needs cleanup anyway, I will send a patch for that separately (if this patch gets dropped in the next rev, see below).

Quoted 4 lines

Given the LED driver is the only driver & device so far which needs the PMIC revision, maybe for now that driver could determine the revision itself instead of adding this new member for everybody?

Hmm, implementing that would make this patch redundant. I'll do so.

Quoted 7 lines

Cheers,
Andre'

Quoted 3 lines

 };

 struct sec_platform_data {

#26 lore raw

Re: [PATCH v2 07/12] mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support

Quoted 109 lines · Kaustabh Chakraborty
Quoted 95 lines · André Draszik

Hi Kaustabh,

Quoted 2 lines · Kaustabh Chakraborty

The device revision matters in cases when in some PMICs, the correct register offsets very in different revisions. Instead of just debug

s/very/vary

Quoted 1 line

printing the value, store it in the driver data struct.

Please mention that you're not doing that for s2mpg1x, though.

Quoted 83 lines

Unlike other devices, S2MU005 has its hardware revision ID in register offset 0x73. Allow handling different devices and add support for S2MU005.

---
 drivers/mfd/sec-common.c         | 41 ++++++++++++++++++++++++++++++---------- include/linux/mfd/samsung/core.h |  1 +

 2 files changed, 32 insertions(+), 10 deletions(-)
drivers/mfd/sec-common.c +1 -0
index bc2a1f2c6dc7a..069a1ba9aa1f1 100644
@@ -16,6 +16,7 @@
  #include <linux/mfd/samsung/irq.h>
  #include <linux/mfd/samsung/s2mps11.h>
  #include <linux/mfd/samsung/s2mps13.h>
+#include <linux/mfd/samsung/s2mu005.h>
  #include <linux/module.h>
  #include <linux/of.h>
  #include <linux/pm.h>
@@ -111,17 +112,38 @@ static const struct mfd_cell s2mu005_devs[] = {
  	MFD_CELL_OF("s2mu005-rgb", NULL, NULL, 0, 0, "samsung,s2mu005-rgb"),
  };

drivers/mfd/sec-common.c +1 -1
-static void sec_pmic_dump_rev(struct sec_pmic_dev *sec_pmic)
+static int sec_pmic_store_rev(struct sec_pmic_dev *sec_pmic)

 {

drivers/mfd/sec-common.c +2 -1
-	unsigned int val;
+	unsigned int reg, mask, shift;
+	int ret;

drivers/mfd/sec-common.c +24 -3
-	/* For s2mpg1x, the revision is in a different regmap */
-	if (sec_pmic->device_type == S2MPG10)
-		return;
+	switch (sec_pmic->device_type) {
+	case S2MPG10:
+		/* For s2mpg1x, the revision is in a different regmap */
+		return 0;
+	case S2MU005:
+		reg = S2MU005_REG_ID;
+		mask = S2MU005_ID_MASK;
+		shift = S2MU005_ID_SHIFT;
+		break;
+	default:
+		/* For other device types, the REG_ID is always the first register. */
+		reg = S2MPS11_REG_ID;
+		mask = ~0;
+		shift = 0;
+	}
+
+	ret = regmap_read(sec_pmic->regmap_pmic, reg, &sec_pmic->revision);
+	if (ret) {
+		dev_err(sec_pmic->dev, "Failed to read PMIC revision (%d)\n", ret);
+		return ret;
+	}
+
+	sec_pmic->revision &= mask;
+	sec_pmic->revision >>= shift;

drivers/mfd/sec-common.c +2 -3
-	/* For each device type, the REG_ID is always the first register */
-	if (!regmap_read(sec_pmic->regmap_pmic, S2MPS11_REG_ID, &val))
-		dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", val);
+	dev_dbg(sec_pmic->dev, "Revision: 0x%x\n", sec_pmic->revision);
+	return 0;

 }

 static void sec_pmic_configure(struct sec_pmic_dev *sec_pmic)

drivers/mfd/sec-common.c +0 -0
@@ -262,9 +284,8 @@ int sec_pmic_probe(struct device *dev, int device_type, unsigned int irq,
  		return ret;


  sec_pmic_configure(sec_pmic);

drivers/mfd/sec-common.c +0 -1
-	sec_pmic_dump_rev(sec_pmic);

drivers/mfd/sec-common.c +1 -1
-	return ret;
+	return sec_pmic_store_rev(sec_pmic);

 }
 EXPORT_SYMBOL_GPL(sec_pmic_probe);

include/linux/mfd/samsung/core.h +0 -1
index 43e0c5e55f5d3..56aa33d7e3d60 100644
--- a/include/linux/mfd/samsung/core.h
Quoted 8 lines

include/linux/mfd/samsung/core.h struct sec_pmic_dev { · line 73

Quoted 6 lines

+++ b/include/linux/mfd/samsung/core.h

include/linux/mfd/samsung/core.h +0 -0
@@ -70,6 +70,7 @@ struct sec_pmic_dev {


  int device_type;
  int irq;

include/linux/mfd/samsung/core.h +1 -0
+	unsigned int revision;

kerneldoc needs to be updated.

Seems like it needs cleanup anyway, I will send a patch for that separately (if this patch gets dropped in the next rev, see below).

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

Given the LED driver is the only driver & device so far which needs the PMIC revision, maybe for now that driver could determine the revision itself instead of adding this new member for everybody?

Hmm, implementing that would make this patch redundant. I'll do so.

It however seems weird to not handle it here; we're already reading the revision value; it also makes sense to store it in the MFD driver itself.

Either way, the patch won't be redundant, because the reading part at least needs to be implemented here.

Quoted 8 lines
Quoted 8 lines

Cheers,
Andre'

Quoted 3 lines

 };

 struct sec_platform_data {

#27 lore raw

PATCH v2 8/12 leds: flash: add support for Samsung S2M series PMIC flash LED device

In reply to Kaustabh Chakraborty

Add support for flash LEDs found in certain Samsung S2M series PMICs. The device has two channels for LEDs, typically for the back and front cameras in mobile devices. Both channels can be independently controlled, and can be operated in torch or flash modes.

The driver includes initial support for the S2MU005 PMIC flash LEDs.

---
 drivers/leds/flash/Kconfig          |  12 ++
 drivers/leds/flash/Makefile         |   1 +
 drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++
 3 files changed, 423 insertions(+)
drivers/leds/flash/Kconfig +12 -0
index 5e08102a67841..be62e05277429 100644
@@ -114,6 +114,18 @@ config LEDS_RT8515
 	  To compile this driver as a module, choose M here: the module
 	  will be called leds-rt8515.
 
+config LEDS_S2M_FLASH
+	tristate "Samsung S2M series PMICs flash/torch LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	select REGMAP_IRQ
+	help
+	  This option enables support for the flash/torch LEDs found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. It has
+	  a LED channel dedicated for every physical LED. The LEDs can
+	  be controlled in flash and torch modes.
+
 config LEDS_SGM3140
 	tristate "LED support for the SGM3140"
 	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
drivers/leds/flash/Makefile +1 -0
index 712fb737a428e..44e6c1b4beb37 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o
 obj-$(CONFIG_LEDS_QCOM_FLASH)	+= leds-qcom-flash.o
 obj-$(CONFIG_LEDS_RT4505)	+= leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515)	+= leds-rt8515.o
+obj-$(CONFIG_LEDS_S2M_FLASH)	+= leds-s2m-flash.o
 obj-$(CONFIG_LEDS_SGM3140)	+= leds-sgm3140.o
 obj-$(CONFIG_LEDS_SY7802)	+= leds-sy7802.o
 obj-$(CONFIG_LEDS_TPS6131X)	+= leds-tps6131x.o
drivers/leds/flash/leds-s2m-flash.c new file +410 -0

410 lines not on this page · raw message

Signature · 1 line
2.52.0
maintainer
#28 lore raw

Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

Hi,

Quoted 71 lines · Kaustabh Chakraborty

Add support for flash LEDs found in certain Samsung S2M series PMICs. The device has two channels for LEDs, typically for the back and front cameras in mobile devices. Both channels can be independently controlled, and can be operated in torch or flash modes.

The driver includes initial support for the S2MU005 PMIC flash LEDs.

---
 drivers/leds/flash/Kconfig          |  12 ++ drivers/leds/flash/Makefile         |   1 + drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++

 3 files changed, 423 insertions(+)
drivers/leds/flash/Kconfig +0 -0
index 5e08102a67841..be62e05277429 100644
@@ -114,6 +114,18 @@ config LEDS_RT8515

    To compile this driver as a module, choose M here: the module will be called leds-rt8515.

drivers/leds/flash/Kconfig +12 -0
+config LEDS_S2M_FLASH
+	tristate "Samsung S2M series PMICs flash/torch LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	select REGMAP_IRQ
+	help
+	  This option enables support for the flash/torch LEDs found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. It has
+	  a LED channel dedicated for every physical LED. The LEDs can
+	  be controlled in flash and torch modes.
+

 config LEDS_SGM3140
  tristate "LED support for the SGM3140"
  depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS

drivers/leds/flash/Makefile +0 -0
index 712fb737a428e..44e6c1b4beb37 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o

 obj-$(CONFIG_LEDS_QCOM_FLASH) += leds-qcom-flash.o
 obj-$(CONFIG_LEDS_RT4505) += leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515) += leds-rt8515.o
+obj-$(CONFIG_LEDS_S2M_FLASH) += leds-s2m-flash.o
 obj-$(CONFIG_LEDS_SGM3140) += leds-sgm3140.o
 obj-$(CONFIG_LEDS_SY7802) += leds-sy7802.o
 obj-$(CONFIG_LEDS_TPS6131X) += leds-tps6131x.o

drivers/leds/flash/leds-s2m-flash.c new file +16 -0
new file mode 100644
index 0000000000000..1be2745c475bf
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Flash and Torch LED Driver for Samsung S2M series PMICs.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd
+ * Copyright (c) 2025 Kaustabh Chakraborty <[email protected]>
+ */
+
+#include <linux/container_of.h>
+#include <linux/led-class-flash.h>
+#include <linux/mfd/samsung/core.h>
+#include <linux/mfd/samsung/s2mu005.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>

drivers/leds/flash/leds-s2m-flash.c line 26

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+#include <media/v4l2-flash-led-class.h>
+
+#define MAX_CHANNELS	2
+
+struct s2m_fled {
+	struct device *dev;
+	struct regmap *regmap;
+	struct led_classdev_flash cdev;
+	struct v4l2_flash *v4l2_flash;
+	struct mutex lock;

Please add a (brief) comment describing what the mutex protects.

Quoted 82 lines
drivers/leds/flash/leds-s2m-flash.c new file +82 -0
+	const struct s2m_fled_spec *spec;
+	unsigned int pmic_revision;
+	u8 channel;
+	u8 flash_brightness;
+	u8 flash_timeout;
+};
+
+struct s2m_fled_spec {
+	u8 num_channels;
+	u32 torch_max_brightness;
+	u32 flash_min_current_ua;
+	u32 flash_max_current_ua;
+	u32 flash_min_timeout_us;
+	u32 flash_max_timeout_us;
+	int (*torch_brightness_set_blocking)(struct led_classdev *led_cdev,
+					     enum led_brightness brightness);
+	const struct led_flash_ops *flash_ops;
+};
+
+static struct led_classdev_flash *to_cdev_flash(struct led_classdev *cdev)
+{
+	return container_of(cdev, struct led_classdev_flash, led_cdev);
+}
+
+static struct s2m_fled *to_led_priv(struct led_classdev_flash *cdev)
+{
+	return container_of(cdev, struct s2m_fled, cdev);
+}
+
+static int s2m_fled_flash_brightness_set(struct led_classdev_flash *cdev,
+					 u32 brightness)
+{
+	struct s2m_fled *priv = to_led_priv(cdev);
+	struct led_flash_setting *setting = &cdev->brightness;
+
+	priv->flash_brightness = (brightness - setting->min) / setting->step;
+
+	return 0;
+}
+
+static int s2m_fled_flash_timeout_set(struct led_classdev_flash *cdev,
+				      u32 timeout)
+{
+	struct s2m_fled *priv = to_led_priv(cdev);
+	struct led_flash_setting *setting = &cdev->timeout;
+
+	priv->flash_timeout = (timeout - setting->min) / setting->step;
+
+	return 0;
+}
+
+#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
+static int s2m_fled_flash_external_strobe_set(struct v4l2_flash *v4l2_flash,
+					      bool enable)
+{
+	struct s2m_fled *priv = to_led_priv(v4l2_flash->fled_cdev);
+
+	mutex_lock(&priv->lock);
+
+	priv->cdev.ops->strobe_set(&priv->cdev, enable);
+
+	mutex_unlock(&priv->lock);
+
+	return 0;
+}
+
+static const struct v4l2_flash_ops s2m_fled_v4l2_flash_ops = {
+	.external_strobe_set = s2m_fled_flash_external_strobe_set,
+};
+#else
+static const struct v4l2_flash_ops s2m_fled_v4l2_flash_ops;
+#endif
+
+static int s2mu005_fled_torch_brightness_set(struct led_classdev *cdev,
+					     enum led_brightness value)
+{
+	struct s2m_fled *priv = to_led_priv(to_cdev_flash(cdev));
+	struct regmap *regmap = priv->regmap;
+	u8 channel = priv->channel;
+	unsigned int reg_enable;
+	int ret;
+

drivers/leds/flash/leds-s2m-flash.c line 118

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	mutex_lock(&priv->lock);
+
+	/*
+	 * Get the LED enable register address. Revision EVT0 has the
+	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
+	 */
+	if (priv->pmic_revision == 0)
+		reg_enable = S2MU005_REG_FLED_CTRL4;
+	else
+		reg_enable = S2MU005_REG_FLED_CTRL6;

You could REG_FIELD() and friends for this and everywhere else with similar if / else.

Quoted 153 lines
drivers/leds/flash/leds-s2m-flash.c new file +153 -0
+
+	if (value == LED_OFF) {
+		ret = regmap_clear_bits(regmap, reg_enable,
+					S2MU005_FLED_TORCH_EN(channel));
+		if (ret < 0)
+			dev_err(priv->dev, "failed to disable torch LED\n");
+		goto unlock;
+	}
+
+	ret = regmap_update_bits(regmap, S2MU005_REG_FLED_CH_CTRL1(channel),
+				 S2MU005_FLED_TORCH_IOUT,
+				 FIELD_PREP(S2MU005_FLED_TORCH_IOUT, value - 1));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to set torch current\n");
+		goto unlock;
+	}
+
+	ret = regmap_set_bits(regmap, reg_enable, S2MU005_FLED_TORCH_EN(channel));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to enable torch LED\n");
+		goto unlock;
+	}
+
+unlock:
+	mutex_unlock(&priv->lock);
+
+	return ret;
+}
+
+static int s2mu005_fled_flash_strobe_set(struct led_classdev_flash *cdev,
+					 bool state)
+{
+	struct s2m_fled *priv = to_led_priv(cdev);
+	struct regmap *regmap = priv->regmap;
+	u8 channel = priv->channel;
+	unsigned int reg_enable;
+	int ret;
+
+	mutex_lock(&priv->lock);
+
+	/*
+	 * Get the LED enable register address. Revision EVT0 has the
+	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
+	 */
+	if (priv->pmic_revision == 0)
+		reg_enable = S2MU005_REG_FLED_CTRL4;
+	else
+		reg_enable = S2MU005_REG_FLED_CTRL6;
+
+	ret = regmap_clear_bits(regmap, reg_enable, S2MU005_FLED_FLASH_EN(channel));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to disable flash LED\n");
+		goto unlock;
+	}
+
+	if (!state)
+		goto unlock;
+
+	ret = regmap_update_bits(regmap, S2MU005_REG_FLED_CH_CTRL0(channel),
+				 S2MU005_FLED_FLASH_IOUT,
+				 FIELD_PREP(S2MU005_FLED_FLASH_IOUT,
+					    priv->flash_brightness));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to set flash brightness\n");
+		goto unlock;
+	}
+
+	ret = regmap_update_bits(regmap, S2MU005_REG_FLED_CH_CTRL3(channel),
+				 S2MU005_FLED_FLASH_TIMEOUT,
+				 FIELD_PREP(S2MU005_FLED_FLASH_TIMEOUT,
+					    priv->flash_timeout));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to set flash timeout\n");
+		goto unlock;
+	}
+
+	ret = regmap_set_bits(regmap, reg_enable, S2MU005_FLED_FLASH_EN(channel));
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to enable flash LED\n");
+		goto unlock;
+	}
+
+unlock:
+	mutex_unlock(&priv->lock);
+
+	return 0;
+}
+
+static int s2mu005_fled_flash_strobe_get(struct led_classdev_flash *cdev,
+					 bool *state)
+{
+	struct s2m_fled *priv = to_led_priv(cdev);
+	struct regmap *regmap = priv->regmap;
+	u8 channel = priv->channel;
+	u32 val;
+	int ret;
+
+	mutex_lock(&priv->lock);
+
+	ret = regmap_read(regmap, S2MU005_REG_FLED_STATUS, &val);
+	if (ret < 0) {
+		dev_err(priv->dev, "failed to fetch LED status");
+		goto unlock;
+	}
+
+	*state = !!(val & S2MU005_FLED_FLASH_STATUS(channel));
+
+unlock:
+	mutex_unlock(&priv->lock);
+
+	return ret;
+}
+
+static const struct led_flash_ops s2mu005_fled_flash_ops = {
+	.flash_brightness_set = s2m_fled_flash_brightness_set,
+	.timeout_set = s2m_fled_flash_timeout_set,
+	.strobe_set = s2mu005_fled_flash_strobe_set,
+	.strobe_get = s2mu005_fled_flash_strobe_get,
+};
+
+static const struct s2m_fled_spec s2mu005_fled_spec = {
+	.num_channels = 2,
+	.torch_max_brightness = 16,
+	.flash_min_current_ua = 25000,
+	.flash_max_current_ua = 375000, /* 400000 causes flickering */
+	.flash_min_timeout_us = 62000,
+	.flash_max_timeout_us = 992000,
+	.torch_brightness_set_blocking = s2mu005_fled_torch_brightness_set,
+	.flash_ops = &s2mu005_fled_flash_ops,
+};
+
+static int s2m_fled_init_channel(struct device *dev, struct fwnode_handle *fwnp,
+				 struct s2m_fled *priv)
+{
+	struct led_classdev *led = &priv->cdev.led_cdev;
+	struct led_init_data init_data = {};
+	struct v4l2_flash_config v4l2_cfg = {};
+	int ret;
+
+	led->max_brightness = priv->spec->torch_max_brightness;
+	led->brightness_set_blocking = priv->spec->torch_brightness_set_blocking;
+	led->flags |= LED_DEV_CAP_FLASH;
+
+	priv->cdev.timeout.min = priv->spec->flash_min_timeout_us;
+	priv->cdev.timeout.step = priv->spec->flash_min_timeout_us;
+	priv->cdev.timeout.max = priv->spec->flash_max_timeout_us;
+	priv->cdev.timeout.val = priv->spec->flash_max_timeout_us;
+
+	priv->cdev.brightness.min = priv->spec->flash_min_current_ua;
+	priv->cdev.brightness.step = priv->spec->flash_min_current_ua;
+	priv->cdev.brightness.max = priv->spec->flash_max_current_ua;
+	priv->cdev.brightness.val = priv->spec->flash_max_current_ua;
+

drivers/leds/flash/leds-s2m-flash.c line 281

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	s2m_fled_flash_timeout_set(&priv->cdev, priv->cdev.timeout.val);
+	s2m_fled_flash_brightness_set(&priv->cdev, priv->cdev.brightness.val);
+
+	priv->cdev.ops = priv->spec->flash_ops;
+
+	init_data.fwnode = fwnp;
+	ret = devm_led_classdev_flash_register_ext(dev, &priv->cdev, &init_data);
+	if (ret < 0) {
+		dev_err(dev, "failed to create LED flash device\n");
+		return ret;

dev_err_probe()?

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+	}
+
+	v4l2_cfg.intensity.min = priv->spec->flash_min_current_ua;
+	v4l2_cfg.intensity.step = priv->spec->flash_min_current_ua;
+	v4l2_cfg.intensity.max = priv->spec->flash_max_current_ua;

drivers/leds/flash/leds-s2m-flash.c line 296

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	v4l2_cfg.intensity.val = priv->spec->flash_max_current_ua;
+
+	v4l2_cfg.has_external_strobe = true;
+
+	priv->v4l2_flash = v4l2_flash_init(dev, fwnp, &priv->cdev,
+					   &s2m_fled_v4l2_flash_ops, &v4l2_cfg);
+	if (IS_ERR(priv->v4l2_flash)) {
+		dev_err(dev, "failed to create V4L2 flash device\n");
+		v4l2_flash_release(priv->v4l2_flash);
+		return PTR_ERR(priv->v4l2_flash);

dev_err_probe()?

drivers/leds/flash/leds-s2m-flash.c line 300

Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+	}
+
+	return devm_add_action_or_reset(dev, (void *)v4l2_flash_release,
+					priv->v4l2_flash);

maybe add dev_err_probe() here, and drop the extra message in s2m_fled_probe().

Quoted 53 lines
drivers/leds/flash/leds-s2m-flash.c new file +53 -0
+}
+
+static int s2m_fled_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sec_pmic_dev *pmic_drvdata = dev_get_drvdata(dev->parent);
+	struct s2m_fled *priv;
+	struct fwnode_handle *child;
+	struct regmap *regmap;
+	const struct s2m_fled_spec *spec;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv) * MAX_CHANNELS, GFP_KERNEL);
+	if (!priv)
+		return dev_err_probe(dev, -ENOMEM, "failed to allocate driver private\n");
+
+	platform_set_drvdata(pdev, priv);
+	regmap = pmic_drvdata->regmap_pmic;
+
+	switch (platform_get_device_id(pdev)->driver_data) {
+	case S2MU005:
+		spec = &s2mu005_fled_spec;
+		/* Enable the LED channels. */
+		ret = regmap_set_bits(regmap, S2MU005_REG_FLED_CTRL1,
+				      S2MU005_FLED_CH_EN);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "failed to enable LED channels\n");
+		break;
+	default:
+		return dev_err_probe(dev, -ENODEV,
+				     "device type %d is not supported by driver\n",
+				     pmic_drvdata->device_type);
+	}
+
+	device_for_each_child_node(dev, child) {
+		u32 reg;
+
+		if (fwnode_property_read_u32(child, "reg", &reg))
+			goto next_child;
+
+		if (reg >= spec->num_channels) {
+			dev_warn(dev, "channel %d is non-existent\n", reg);
+			goto next_child;
+		}
+
+		if (priv[reg].dev) {
+			dev_warn(dev, "duplicate node for channel %d\n", reg);
+			goto next_child;
+		}
+
+		priv[reg].dev = dev;
+		priv[reg].regmap = regmap;
+		priv[reg].channel = (u8)reg;

drivers/leds/flash/leds-s2m-flash.c line 363

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+		priv[reg].spec = spec;
+		priv[reg].pmic_revision = pmic_drvdata->revision;
+
+		ret = devm_mutex_init(dev, &priv[reg].lock);
+		if (ret)
+			return dev_err_probe(dev, ret, "failed to create mutex lock\n");
+
+		ret = s2m_fled_init_channel(dev, child, &priv[reg]);
+		if (ret < 0)
+			dev_warn(dev, "channel init failed (%d)\n", ret);

s2m_fled_init_channel() already prints a message on (most) errors, and then there's another one here. Also, is it really OK to continue ignoring the error?

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+
+next_child:
+		fwnode_handle_put(child);
+	}
+

drivers/leds/flash/leds-s2m-flash.c line 378

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	return 0;
+}
+
+static const struct platform_device_id s2m_fled_id_table[] = {
+	{ "s2mu005-flash", S2MU005 },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(platform, s2m_fled_id_table);
+
+#ifdef CONFIG_OF

I believe the general recommendation is to not use ifdef CONFIG_OF

Cheers,
Andre

Quoted 32 lines
drivers/leds/flash/leds-s2m-flash.c new file +32 -0
+/*
+ * Device is instantiated through parent MFD device and device matching
+ * is done through platform_device_id.
+ *
+ * However if device's DT node contains proper compatible and driver is
+ * built as a module, then the *module* matching will be done through DT
+ * aliases. This requires of_device_id table. In the same time this will
+ * not change the actual *device* matching so do not add .of_match_table.
+ */
+static const struct of_device_id s2m_fled_of_match_table[] = {
+	{
+		.compatible = "samsung,s2mu005-flash",
+		.data = (void *)S2MU005,
+	}, {
+		/* sentinel */
+	},
+};
+MODULE_DEVICE_TABLE(of, s2m_fled_of_match_table);
+#endif
+
+static struct platform_driver s2m_fled_driver = {
+	.driver = {
+		.name = "s2m-flash",
+	},
+	.probe = s2m_fled_probe,
+	.id_table = s2m_fled_id_table,
+};
+module_platform_driver(s2m_fled_driver);
+
+MODULE_DESCRIPTION("Flash/Torch LED Driver For Samsung S2M Series PMICs");
+MODULE_AUTHOR("Kaustabh Chakraborty <[email protected]>");
+MODULE_LICENSE("GPL");
#29 lore raw

Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

Quoted 78 lines · André Draszik

Hi,

Quoted 75 lines · Kaustabh Chakraborty

Add support for flash LEDs found in certain Samsung S2M series PMICs. The device has two channels for LEDs, typically for the back and front cameras in mobile devices. Both channels can be independently controlled, and can be operated in torch or flash modes.

The driver includes initial support for the S2MU005 PMIC flash LEDs.

---
 drivers/leds/flash/Kconfig          |  12 ++ drivers/leds/flash/Makefile         |   1 + drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++

 3 files changed, 423 insertions(+)
drivers/leds/flash/Kconfig +0 -0
index 5e08102a67841..be62e05277429 100644
@@ -114,6 +114,18 @@ config LEDS_RT8515

    To compile this driver as a module, choose M here: the module will be called leds-rt8515.

drivers/leds/flash/Kconfig +12 -0
+config LEDS_S2M_FLASH
+	tristate "Samsung S2M series PMICs flash/torch LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	select REGMAP_IRQ
+	help
+	  This option enables support for the flash/torch LEDs found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. It has
+	  a LED channel dedicated for every physical LED. The LEDs can
+	  be controlled in flash and torch modes.
+

 config LEDS_SGM3140
  tristate "LED support for the SGM3140"
  depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS

drivers/leds/flash/Makefile +0 -0
index 712fb737a428e..44e6c1b4beb37 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o

 obj-$(CONFIG_LEDS_QCOM_FLASH) += leds-qcom-flash.o
 obj-$(CONFIG_LEDS_RT4505) += leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515) += leds-rt8515.o
+obj-$(CONFIG_LEDS_S2M_FLASH) += leds-s2m-flash.o
 obj-$(CONFIG_LEDS_SGM3140) += leds-sgm3140.o
 obj-$(CONFIG_LEDS_SY7802) += leds-sy7802.o
 obj-$(CONFIG_LEDS_TPS6131X) += leds-tps6131x.o

drivers/leds/flash/leds-s2m-flash.c new file +20 -0
new file mode 100644
index 0000000000000..1be2745c475bf
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Flash and Torch LED Driver for Samsung S2M series PMICs.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd
+ * Copyright (c) 2025 Kaustabh Chakraborty <[email protected]>
+ */
+
+#include <linux/container_of.h>
+#include <linux/led-class-flash.h>
+#include <linux/mfd/samsung/core.h>
+#include <linux/mfd/samsung/s2mu005.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <media/v4l2-flash-led-class.h>
+
+#define MAX_CHANNELS	2
+
Quoted 8 lines

drivers/leds/flash/leds-s2m-flash.c line 26

Quoted 6 lines
drivers/leds/flash/leds-s2m-flash.c new file +6 -0
+struct s2m_fled {
+	struct device *dev;
+	struct regmap *regmap;
+	struct led_classdev_flash cdev;
+	struct v4l2_flash *v4l2_flash;
+	struct mutex lock;

Please add a (brief) comment describing what the mutex protects.

The mutex object prevents the concurrent access of flash control registers by the LED and V4L2 subsystems. -- will add this.

Quoted 4 lines
Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+
+	/*
+	 * Get the LED enable register address. Revision EVT0 has the
+	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
Quoted 9 lines

drivers/leds/flash/leds-s2m-flash.c line 118

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+	 */
+	if (priv->pmic_revision == 0)
+		reg_enable = S2MU005_REG_FLED_CTRL4;
+	else
+		reg_enable = S2MU005_REG_FLED_CTRL6;

You could REG_FIELD() and friends for this and everywhere else with similar if / else.

REG_FIELD(), from what I understood, is for selecting a bit field inside a single register. However this code chooses between two separate registers. I believe your interpretation was incorrect? Please clarify.

Quoted 119 lines
Quoted 22 lines
drivers/leds/flash/leds-s2m-flash.c new file +22 -0
+static int s2m_fled_init_channel(struct device *dev, struct fwnode_handle *fwnp,
+				 struct s2m_fled *priv)
+{
+	struct led_classdev *led = &priv->cdev.led_cdev;
+	struct led_init_data init_data = {};
+	struct v4l2_flash_config v4l2_cfg = {};
+	int ret;
+
+	led->max_brightness = priv->spec->torch_max_brightness;
+	led->brightness_set_blocking = priv->spec->torch_brightness_set_blocking;
+	led->flags |= LED_DEV_CAP_FLASH;
+
+	priv->cdev.timeout.min = priv->spec->flash_min_timeout_us;
+	priv->cdev.timeout.step = priv->spec->flash_min_timeout_us;
+	priv->cdev.timeout.max = priv->spec->flash_max_timeout_us;
+	priv->cdev.timeout.val = priv->spec->flash_max_timeout_us;
+
+	priv->cdev.brightness.min = priv->spec->flash_min_current_ua;
+	priv->cdev.brightness.step = priv->spec->flash_min_current_ua;
+	priv->cdev.brightness.max = priv->spec->flash_max_current_ua;
+	priv->cdev.brightness.val = priv->spec->flash_max_current_ua;
+

drivers/leds/flash/leds-s2m-flash.c line 281

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	s2m_fled_flash_timeout_set(&priv->cdev, priv->cdev.timeout.val);
+	s2m_fled_flash_brightness_set(&priv->cdev, priv->cdev.brightness.val);
+
+	priv->cdev.ops = priv->spec->flash_ops;
+
+	init_data.fwnode = fwnp;
+	ret = devm_led_classdev_flash_register_ext(dev, &priv->cdev, &init_data);
+	if (ret < 0) {
+		dev_err(dev, "failed to create LED flash device\n");
+		return ret;

dev_err_probe()?

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+	}
+
+	v4l2_cfg.intensity.min = priv->spec->flash_min_current_ua;
+	v4l2_cfg.intensity.step = priv->spec->flash_min_current_ua;
+	v4l2_cfg.intensity.max = priv->spec->flash_max_current_ua;

drivers/leds/flash/leds-s2m-flash.c line 296

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+	v4l2_cfg.intensity.val = priv->spec->flash_max_current_ua;
+
+	v4l2_cfg.has_external_strobe = true;
+
+	priv->v4l2_flash = v4l2_flash_init(dev, fwnp, &priv->cdev,
+					   &s2m_fled_v4l2_flash_ops, &v4l2_cfg);
+	if (IS_ERR(priv->v4l2_flash)) {
+		dev_err(dev, "failed to create V4L2 flash device\n");
+		v4l2_flash_release(priv->v4l2_flash);
+		return PTR_ERR(priv->v4l2_flash);

dev_err_probe()?

drivers/leds/flash/leds-s2m-flash.c line 300

Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+	}
+
+	return devm_add_action_or_reset(dev, (void *)v4l2_flash_release,
+					priv->v4l2_flash);

maybe add dev_err_probe() here, and drop the extra message in s2m_fled_probe().

Quoted 59 lines
drivers/leds/flash/leds-s2m-flash.c new file +59 -0
+}
+
+static int s2m_fled_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sec_pmic_dev *pmic_drvdata = dev_get_drvdata(dev->parent);
+	struct s2m_fled *priv;
+	struct fwnode_handle *child;
+	struct regmap *regmap;
+	const struct s2m_fled_spec *spec;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv) * MAX_CHANNELS, GFP_KERNEL);
+	if (!priv)
+		return dev_err_probe(dev, -ENOMEM, "failed to allocate driver private\n");
+
+	platform_set_drvdata(pdev, priv);
+	regmap = pmic_drvdata->regmap_pmic;
+
+	switch (platform_get_device_id(pdev)->driver_data) {
+	case S2MU005:
+		spec = &s2mu005_fled_spec;
+		/* Enable the LED channels. */
+		ret = regmap_set_bits(regmap, S2MU005_REG_FLED_CTRL1,
+				      S2MU005_FLED_CH_EN);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "failed to enable LED channels\n");
+		break;
+	default:
+		return dev_err_probe(dev, -ENODEV,
+				     "device type %d is not supported by driver\n",
+				     pmic_drvdata->device_type);
+	}
+
+	device_for_each_child_node(dev, child) {
+		u32 reg;
+
+		if (fwnode_property_read_u32(child, "reg", &reg))
+			goto next_child;
+
+		if (reg >= spec->num_channels) {
+			dev_warn(dev, "channel %d is non-existent\n", reg);
+			goto next_child;
+		}
+
+		if (priv[reg].dev) {
+			dev_warn(dev, "duplicate node for channel %d\n", reg);
+			goto next_child;
+		}
+
+		priv[reg].dev = dev;
+		priv[reg].regmap = regmap;
+		priv[reg].channel = (u8)reg;
+		priv[reg].spec = spec;
+		priv[reg].pmic_revision = pmic_drvdata->revision;
+
+		ret = devm_mutex_init(dev, &priv[reg].lock);
+		if (ret)
+			return dev_err_probe(dev, ret, "failed to create mutex lock\n");
Quoted 9 lines

drivers/leds/flash/leds-s2m-flash.c line 363

Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+
+		ret = s2m_fled_init_channel(dev, child, &priv[reg]);
+		if (ret < 0)
+			dev_warn(dev, "channel init failed (%d)\n", ret);

s2m_fled_init_channel() already prints a message on (most) errors, and then there's another one here. Also, is it really OK to continue ignoring the error?

The LED channels are supposed to be independent, so if one fails, the others may still work.

But errors in s2m_fled_init_channel() is not-hardware related, so this reasoning doesn't make sense. So I shall implement your changes.

maintainer
#30 lore raw

Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

Quoted 105 lines · Kaustabh Chakraborty
Quoted 78 lines · André Draszik

Hi,

Quoted 75 lines · Kaustabh Chakraborty

Add support for flash LEDs found in certain Samsung S2M series PMICs. The device has two channels for LEDs, typically for the back and front cameras in mobile devices. Both channels can be independently controlled, and can be operated in torch or flash modes.

The driver includes initial support for the S2MU005 PMIC flash LEDs.

---
 drivers/leds/flash/Kconfig          |  12 ++ drivers/leds/flash/Makefile         |   1 + drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++

 3 files changed, 423 insertions(+)
drivers/leds/flash/Kconfig +0 -0
index 5e08102a67841..be62e05277429 100644
@@ -114,6 +114,18 @@ config LEDS_RT8515

    To compile this driver as a module, choose M here: the module will be called leds-rt8515.

drivers/leds/flash/Kconfig +12 -0
+config LEDS_S2M_FLASH
+	tristate "Samsung S2M series PMICs flash/torch LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	select REGMAP_IRQ
+	help
+	  This option enables support for the flash/torch LEDs found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. It has
+	  a LED channel dedicated for every physical LED. The LEDs can
+	  be controlled in flash and torch modes.
+

 config LEDS_SGM3140
  tristate "LED support for the SGM3140"
  depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS

drivers/leds/flash/Makefile +0 -0
index 712fb737a428e..44e6c1b4beb37 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o

 obj-$(CONFIG_LEDS_QCOM_FLASH) += leds-qcom-flash.o
 obj-$(CONFIG_LEDS_RT4505) += leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515) += leds-rt8515.o
+obj-$(CONFIG_LEDS_S2M_FLASH) += leds-s2m-flash.o
 obj-$(CONFIG_LEDS_SGM3140) += leds-sgm3140.o
 obj-$(CONFIG_LEDS_SY7802) += leds-sy7802.o
 obj-$(CONFIG_LEDS_TPS6131X) += leds-tps6131x.o

drivers/leds/flash/leds-s2m-flash.c new file +20 -0
new file mode 100644
index 0000000000000..1be2745c475bf
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Flash and Torch LED Driver for Samsung S2M series PMICs.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd
+ * Copyright (c) 2025 Kaustabh Chakraborty <[email protected]>
+ */
+
+#include <linux/container_of.h>
+#include <linux/led-class-flash.h>
+#include <linux/mfd/samsung/core.h>
+#include <linux/mfd/samsung/s2mu005.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <media/v4l2-flash-led-class.h>
+
+#define MAX_CHANNELS	2
+
Quoted 8 lines

drivers/leds/flash/leds-s2m-flash.c line 26

Quoted 6 lines
drivers/leds/flash/leds-s2m-flash.c new file +6 -0
+struct s2m_fled {
+	struct device *dev;
+	struct regmap *regmap;
+	struct led_classdev_flash cdev;
+	struct v4l2_flash *v4l2_flash;
+	struct mutex lock;

Please add a (brief) comment describing what the mutex protects.

The mutex object prevents the concurrent access of flash control registers by the LED and V4L2 subsystems. -- will add this.

Quoted 4 lines
Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+
+	/*
+	 * Get the LED enable register address. Revision EVT0 has the
+	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
Quoted 9 lines

drivers/leds/flash/leds-s2m-flash.c line 118

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+	 */
+	if (priv->pmic_revision == 0)
+		reg_enable = S2MU005_REG_FLED_CTRL4;
+	else
+		reg_enable = S2MU005_REG_FLED_CTRL6;

You could REG_FIELD() and friends for this and everywhere else with similar if / else.

Quoted 3 lines

REG_FIELD(), from what I understood, is for selecting a bit field inside a single register. However this code chooses between two separate registers. I believe your interpretation was incorrect? Please clarify.

The first argument to REG_FIELD is the register itself, so reg fields can be used to describe this difference. See e.g. drivers/leds/rgb/leds-mt6370-rgb.c Of course, you could have a member variable instead to hold the register index if all bits are the same in both revisions. Either way would avoid having to constantly check the revision during runtime.

Cheers,
Andre'

#31 lore raw

Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

Quoted 110 lines · André Draszik
Quoted 105 lines · Kaustabh Chakraborty
Quoted 78 lines · André Draszik

Hi,

Quoted 75 lines · Kaustabh Chakraborty

Add support for flash LEDs found in certain Samsung S2M series PMICs. The device has two channels for LEDs, typically for the back and front cameras in mobile devices. Both channels can be independently controlled, and can be operated in torch or flash modes.

The driver includes initial support for the S2MU005 PMIC flash LEDs.

---
 drivers/leds/flash/Kconfig          |  12 ++ drivers/leds/flash/Makefile         |   1 + drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++

 3 files changed, 423 insertions(+)
drivers/leds/flash/Kconfig +0 -0
index 5e08102a67841..be62e05277429 100644
@@ -114,6 +114,18 @@ config LEDS_RT8515

    To compile this driver as a module, choose M here: the module will be called leds-rt8515.

drivers/leds/flash/Kconfig +12 -0
+config LEDS_S2M_FLASH
+	tristate "Samsung S2M series PMICs flash/torch LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	select REGMAP_IRQ
+	help
+	  This option enables support for the flash/torch LEDs found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. It has
+	  a LED channel dedicated for every physical LED. The LEDs can
+	  be controlled in flash and torch modes.
+

 config LEDS_SGM3140
  tristate "LED support for the SGM3140"
  depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS

drivers/leds/flash/Makefile +0 -0
index 712fb737a428e..44e6c1b4beb37 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o

 obj-$(CONFIG_LEDS_QCOM_FLASH) += leds-qcom-flash.o
 obj-$(CONFIG_LEDS_RT4505) += leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515) += leds-rt8515.o
+obj-$(CONFIG_LEDS_S2M_FLASH) += leds-s2m-flash.o
 obj-$(CONFIG_LEDS_SGM3140) += leds-sgm3140.o
 obj-$(CONFIG_LEDS_SY7802) += leds-sy7802.o
 obj-$(CONFIG_LEDS_TPS6131X) += leds-tps6131x.o

drivers/leds/flash/leds-s2m-flash.c new file +20 -0
new file mode 100644
index 0000000000000..1be2745c475bf
@@ -0,0 +1,410 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Flash and Torch LED Driver for Samsung S2M series PMICs.
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd
+ * Copyright (c) 2025 Kaustabh Chakraborty <[email protected]>
+ */
+
+#include <linux/container_of.h>
+#include <linux/led-class-flash.h>
+#include <linux/mfd/samsung/core.h>
+#include <linux/mfd/samsung/s2mu005.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <media/v4l2-flash-led-class.h>
+
+#define MAX_CHANNELS	2
+
Quoted 8 lines

drivers/leds/flash/leds-s2m-flash.c line 26

Quoted 6 lines
drivers/leds/flash/leds-s2m-flash.c new file +6 -0
+struct s2m_fled {
+	struct device *dev;
+	struct regmap *regmap;
+	struct led_classdev_flash cdev;
+	struct v4l2_flash *v4l2_flash;
+	struct mutex lock;

Please add a (brief) comment describing what the mutex protects.

The mutex object prevents the concurrent access of flash control registers by the LED and V4L2 subsystems. -- will add this.

Quoted 4 lines
Quoted 4 lines
drivers/leds/flash/leds-s2m-flash.c new file +4 -0
+
+	/*
+	 * Get the LED enable register address. Revision EVT0 has the
+	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
Quoted 9 lines

drivers/leds/flash/leds-s2m-flash.c line 118

Quoted 5 lines
drivers/leds/flash/leds-s2m-flash.c new file +5 -0
+	 */
+	if (priv->pmic_revision == 0)
+		reg_enable = S2MU005_REG_FLED_CTRL4;
+	else
+		reg_enable = S2MU005_REG_FLED_CTRL6;

You could REG_FIELD() and friends for this and everywhere else with similar if / else.

Quoted 3 lines

REG_FIELD(), from what I understood, is for selecting a bit field inside a single register. However this code chooses between two separate registers. I believe your interpretation was incorrect? Please clarify.

Quoted 5 lines

The first argument to REG_FIELD is the register itself, so reg fields can be used to describe this difference. See e.g. drivers/leds/rgb/leds-mt6370-rgb.c Of course, you could have a member variable instead to hold the register index if all bits are the same in both revisions. Either way would avoid having to constantly check the revision during runtime.

Wow, this is a great way of abstraction, thanks. I will try to implement this in all drivers, let's see.

Quoted 3 lines

Cheers,
Andre'

maintainer
#32 lore raw

Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device

In reply to Kaustabh Chakraborty

Hi,

On Mon, 2026-01-26 at 00:37 +0530, Kaustabh Chakraborty wrote:

[...]

Quoted 3 lines
drivers/leds/flash/leds-s2m-flash.c new file +0 -0
new file mode 100644
index 0000000000000..1be2745c475bf

[...]

Quoted 7 lines
drivers/leds/flash/leds-s2m-flash.c new file +7 -0
+
+static int s2m_fled_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sec_pmic_dev *pmic_drvdata = dev_get_drvdata(dev->parent);
+	struct s2m_fled *priv;
+	struct fwnode_handle *child;

[...]

drivers/leds/flash/leds-s2m-flash.c line 335

Quoted 2 lines
drivers/leds/flash/leds-s2m-flash.c new file +2 -0
+
+	device_for_each_child_node(dev, child) {

If you switch to device_for_each_child_node_scoped(), you can get rid of the goto and the struct fwnode_handle *child declaration at the top, and you plug your leak in your early error return a few lines below.

Quoted 25 lines
drivers/leds/flash/leds-s2m-flash.c new file +25 -0
+		u32 reg;
+
+		if (fwnode_property_read_u32(child, "reg", &reg))
+			goto next_child;
+
+		if (reg >= spec->num_channels) {
+			dev_warn(dev, "channel %d is non-existent\n", reg);
+			goto next_child;
+		}
+
+		if (priv[reg].dev) {
+			dev_warn(dev, "duplicate node for channel %d\n", reg);
+			goto next_child;
+		}
+
+		priv[reg].dev = dev;
+		priv[reg].regmap = regmap;
+		priv[reg].channel = (u8)reg;
+		priv[reg].spec = spec;
+		priv[reg].pmic_revision = pmic_drvdata->revision;
+
+		ret = devm_mutex_init(dev, &priv[reg].lock);
+		if (ret)
+			return dev_err_probe(dev, ret, "failed to create mutex lock\n");
+

drivers/leds/flash/leds-s2m-flash.c line 370

Quoted 10 lines
drivers/leds/flash/leds-s2m-flash.c new file +10 -0
+		ret = s2m_fled_init_channel(dev, child, &priv[reg]);
+		if (ret < 0)
+			dev_warn(dev, "channel init failed (%d)\n", ret);
+
+next_child:
+		fwnode_handle_put(child);
+	}
+
+	return 0;
+}

Cheers,
Andre'

#33 lore raw

PATCH v2 9/12 leds: rgb: add support for Samsung S2M series PMIC RGB LED device

In reply to Kaustabh Chakraborty

Add support for the RGB LEDs found in certain Samsung S2M series PMICs. The device has three LED channels, controlled as a single device. These LEDs are typically used as status indicators in mobile phones.

The driver includes initial support for the S2MU005 PMIC RGB LEDs.

---
 drivers/leds/rgb/Kconfig        |  11 +
 drivers/leds/rgb/Makefile       |   1 +
 drivers/leds/rgb/leds-s2m-rgb.c | 460 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 472 insertions(+)
drivers/leds/rgb/Kconfig +11 -0
index 222d943d826aa..e38ba1bd434e9 100644
@@ -62,6 +62,17 @@ config LEDS_QCOM_LPG
 
 	  If compiled as a module, the module will be named leds-qcom-lpg.
 
+config LEDS_S2M_RGB
+	tristate "Samsung S2M series PMICs RGB LED support"
+	depends on LEDS_CLASS
+	depends on MFD_SEC_CORE
+	select REGMAP_IRQ
+	help
+	  This option enables support for the S2MU005 RGB LEDs. These
+	  devices have three LED channels, with 8-bit brightness control
+	  for each channel. It's usually found in mobile phones as
+	  status indicators.
+
 config LEDS_MT6370_RGB
 	tristate "LED Support for MediaTek MT6370 PMIC"
 	depends on MFD_MT6370
drivers/leds/rgb/Makefile +1 -0
index a501fd27f1793..fc9d38fa60e1d 100644
@@ -5,4 +5,5 @@ obj-$(CONFIG_LEDS_KTD202X)		+= leds-ktd202x.o
 obj-$(CONFIG_LEDS_NCP5623)		+= leds-ncp5623.o
 obj-$(CONFIG_LEDS_PWM_MULTICOLOR)	+= leds-pwm-multicolor.o
 obj-$(CONFIG_LEDS_QCOM_LPG)		+= leds-qcom-lpg.o
+obj-$(CONFIG_LEDS_S2M_RGB)		+= leds-s2m-rgb.o
 obj-$(CONFIG_LEDS_MT6370_RGB)		+= leds-mt6370-rgb.o
drivers/leds/rgb/leds-s2m-rgb.c new file +460 -0

460 lines not on this page · raw message

Signature · 1 line
2.52.0
#34 lore raw

PATCH v2 10/12 Documentation: leds: document pattern behavior of Samsung S2M series PMIC RGB LEDs

In reply to Kaustabh Chakraborty

Add documentation to describe how hardware patterns (as defined by the documentation of led-class-multicolor) are parsed and implemented by the Samsung S2M series PMIC RGB LED driver.

---
 Documentation/leds/index.rst        |  1 +
 Documentation/leds/leds-s2m-rgb.rst | 60 +++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
Documentation/leds/index.rst +1 -0
index 76fae171039c6..05d8e8517a807 100644
@@ -27,6 +27,7 @@ LEDs
    leds-lp55xx
    leds-mlxcpld
    leds-mt6370-rgb
+   leds-s2m-rgb
    leds-sc27xx
    leds-st1202
    leds-qcom-lpg
Documentation/leds/leds-s2m-rgb.rst new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.52.0
#35 lore raw

PATCH v2 11/12 extcon: add support for Samsung S2M series PMIC extcon devices

In reply to Kaustabh Chakraborty

Add a driver for MUIC devices found in certain Samsung S2M series PMICs These are USB port accessory detectors. These devices report multiple cable states depending on the ID-GND resistance measured by an internal ADC.

The driver includes initial support for the S2MU005 PMIC extcon.

---
 drivers/extcon/Kconfig      |  10 ++
 drivers/extcon/Makefile     |   1 +
 drivers/extcon/extcon-s2m.c | 351 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 362 insertions(+)
drivers/extcon/Kconfig +10 -0
index 68d9df7d2dae0..19c712e591955 100644
@@ -183,6 +183,16 @@ config EXTCON_RT8973A
 	  and switch that is optimized to protect low voltage system
 	  from abnormal high input voltage (up to 28V).
 
+config EXTCON_S2M
+	tristate "Samsung S2M series PMIC EXTCON support"
+	depends on MFD_SEC_CORE
+	select REGMAP_IRQ
+	help
+	  This option enables support for MUIC devices found in certain
+	  Samsung S2M series PMICs, such as the S2MU005. These devices
+	  have internal ADCs measuring the ID-GND resistance, thereby
+	  can be used as a USB port accessory detector.
+
 config EXTCON_SM5502
 	tristate "Silicon Mitus SM5502/SM5504/SM5703 EXTCON support"
 	depends on I2C
drivers/extcon/Makefile +1 -0
index 6482f2bfd6611..e3939786f3474 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_PTN5150)	+= extcon-ptn5150.o
 obj-$(CONFIG_EXTCON_QCOM_SPMI_MISC) += extcon-qcom-spmi-misc.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
+obj-$(CONFIG_EXTCON_S2M)	+= extcon-s2m.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
 obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
 obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o
drivers/extcon/extcon-s2m.c new file +351 -0

351 lines not on this page · raw message

Signature · 1 line
2.52.0
#36 lore raw

PATCH v2 12/12 power: supply: add support for Samsung S2M series PMIC charger device

In reply to Kaustabh Chakraborty

Add a driver for charger controllers found in certain Samsung S2M series PMICs. The driver has very basic support for the device, with only charger online reporting working.

The driver includes initial support for the S2MU005 PMIC charger.

---
 drivers/power/supply/Kconfig       |  11 ++
 drivers/power/supply/Makefile      |   1 +
 drivers/power/supply/s2m-charger.c | 213 +++++++++++++++++++++++++++++++++++++
 3 files changed, 225 insertions(+)
drivers/power/supply/Kconfig +11 -0
index 92f9f7aae92f2..b9a6bdf014586 100644
@@ -229,6 +229,17 @@ config BATTERY_SAMSUNG_SDI
 	  Say Y to enable support for Samsung SDI battery data.
 	  These batteries are used in Samsung mobile phones.
 
+config CHARGER_S2M
+	tristate "Samsung S2M series PMIC battery charger support"
+	depends on EXTCON_S2M
+	depends on MFD_SEC_CORE
+	select REGMAP_IRQ
+	help
+	  This option enables support for charger devices found in
+	  certain Samsung S2M series PMICs, such as the S2MU005. These
+	  devices provide USB power supply information and also required
+	  for USB OTG role switching.
+
 config BATTERY_COLLIE
 	tristate "Sharp SL-5500 (collie) battery"
 	depends on SA1100_COLLIE && MCP_UCB1200
drivers/power/supply/Makefile +1 -0
index 4b79d5abc49a7..795ef40d95311 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_BATTERY_PMU)	+= pmu_battery.o
 obj-$(CONFIG_BATTERY_QCOM_BATTMGR)	+= qcom_battmgr.o
 obj-$(CONFIG_BATTERY_OLPC)	+= olpc_battery.o
 obj-$(CONFIG_BATTERY_SAMSUNG_SDI)	+= samsung-sdi-battery.o
+obj-$(CONFIG_CHARGER_S2M)	+= s2m-charger.o
 obj-$(CONFIG_BATTERY_COLLIE)	+= collie_battery.o
 obj-$(CONFIG_BATTERY_INGENIC)	+= ingenic-battery.o
 obj-$(CONFIG_BATTERY_INTEL_DC_TI) += intel_dc_ti_battery.o
drivers/power/supply/s2m-charger.c new file +213 -0

213 lines not on this page · raw message

Signature · 1 line
2.52.0