Skip to contentSkip to conversation

mfd: max597x: Add support for max597x

PATCH Superseded Naresh Solanki 3 participants 10 messages Nov 3, 2022

Subsystems (2)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover mfd: max597x: Add support for max597x

max597x is multifunction device with hot swap controller, fault protection & upto four indication leds.

max5978 has single hot swap controller whereas max5970 has two hot swap controllers.

Changes in V6:
- Update missing vendor prefix
- Update indentation in example
Changes in V5:
- Fix dt schema error
Changes in V4:
- Add NULL entry for of_device_id
- Memory allocation check
Changes in V3:
- Address code review comment
Changes in V2:
- Update depends in Kconfig.

Marcello Sylvester Bauer (1):
dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Patrick Rudolph (1):
mfd: max597x: Add support for MAX5970 and MAX5978

 .../bindings/mfd/maxim,max5970.yaml           | 164 ++++++++++++++++++
 drivers/mfd/Kconfig                           |  12 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/max597x.c                         |  92 ++++++++++
 include/linux/mfd/max597x.h                   | 103 +++++++++++
 5 files changed, 372 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/maxim,max5970.yaml
 create mode 100644 drivers/mfd/max597x.c
 create mode 100644 include/linux/mfd/max597x.h

base-commit: 6b780408be034213edfb5946889882cb29f8f159

Signature · 1 line
2.37.3
#1 lore raw

PATCH v6 1/2 dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

From: Marcello Sylvester Bauer <[email protected]>

The MAX597x is a hot swap controller with configurable fault protection. It also has 10bit ADC for current & voltage measurements.

---
 .../bindings/mfd/maxim,max5970.yaml           | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/maxim,max5970.yaml
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +164 -0
new file mode 100644
index 000000000000..fc9d6d3647b3
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/max5970.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Regulator for MAX5970 smart switch from Maxim Integrated.
+
+maintainers:
+  - Patrick Rudolph <[email protected]>
+
+description: |
+  The smart switch provides no output regulation, but independent fault protection
+  and voltage and current sensing.
+  Programming is done through I2C bus.
+
+  Datasheets:
+    https://datasheets.maximintegrated.com/en/ds/MAX5970.pdf
+    https://datasheets.maximintegrated.com/en/ds/MAX5978.pdf
+
+properties:
+  compatible:
+    enum:
+      - maxim,max5970
+      - maxim,max5978
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  leds:
+    type: object
+    description:
+      Properties for single channel.
+
+    patternProperties:
+      "^led@[0-3]$":
+        $ref: /schemas/leds/common.yaml#
+        type: object
+
+    additionalProperties: true
+
+  vss1-supply:
+    description: Supply of the first channel.
+
+  vss2-supply:
+    description: Supply of the first channel.
+
+  "#io-channel-cells":
+    const: 1
+
+  regulators:
+    type: object
+    description:
+      Properties for single channel.
+
+    patternProperties:
+      "^(sw[0-1])$":
+        $ref: /schemas/regulator/regulator.yaml#
+        type: object
+
+      shunt-resistor-micro-ohms:
+        description: |
+          The value of curent sense resistor in microohms.
+          Must be specified for each channel.
+
+    additionalProperties: true
+
+required:
+  - compatible
+  - reg
+  - regulators
+  - vss1-supply
+
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          enum:
+            - maxim,max5970
+    then:
+      properties:
+        io-channels:
+          items:
+            - description: voltage first channel
+            - description: current first channel
+            - description: voltage second channel
+            - description: current second channel
+          description: |
+            Voltage and current for first and second channel.
+      required:
+        - vss2-supply
+    else:
+      properties:
+        io-channels:
+          items:
+            - description: voltage first channel
+            - description: current first channel
+          description: |
+            Voltage and current for first channel.
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        regulator@3a {
+           compatible = "maxim,max5978";
+           reg = <0x3a>;
+           vss1-supply = <&p3v3>;
+
+           regulators {
+               sw0_ref_0: SW0 {
+                      regulator-compatible = "SW0";
+                      shunt-resistor-micro-ohms = <12000>;
+               };
+           };
+
+           leds {
+               #address-cells = <1>;
+               #size-cells = <0>;
+               led@0 {
+                   reg = <0>;
+                   label = "led0";
+                   default-state = "on";
+               };
+               led@1 {
+                   reg = <1>;
+                   label = "led1";
+                   default-state = "on";
+               };
+           };
+        };
+    };
+
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        regulator@3a {
+            compatible = "maxim,max5970";
+            reg = <0x3a>;
+            vss1-supply = <&p3v3>;
+            vss2-supply = <&p5v>;
+
+            regulators {
+                sw0_ref_1: SW0 {
+                    regulator-compatible = "SW0";
+                    shunt-resistor-micro-ohms = <12000>;
+                };
+                sw1_ref_1: SW1 {
+                    regulator-compatible = "SW1";
+                    shunt-resistor-micro-ohms = <10000>;
+                };
+            };
+        };
+    };
+...
Signature · 1 line
2.37.3
maintainer
#2 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Quoted 5 lines · Naresh Solanki

From: Marcello Sylvester Bauer <[email protected]>

The MAX597x is a hot swap controller with configurable fault protection. It also has 10bit ADC for current & voltage measurements.

Quoted 8 lines
---
 .../bindings/mfd/maxim,max5970.yaml           | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/maxim,max5970.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
./Documentation/devicetree/bindings/mfd/maxim,max5970.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/mfd/maxim,max5970.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

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.

#3 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

In reply to Naresh Solanki
Quoted 19 lines · Naresh Solanki

From: Marcello Sylvester Bauer <[email protected]>

The MAX597x is a hot swap controller with configurable fault protection. It also has 10bit ADC for current & voltage measurements.

---
 .../bindings/mfd/maxim,max5970.yaml           | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/maxim,max5970.yaml
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +0 -0
new file mode 100644
index 000000000000..fc9d6d3647b3

Documentation/devicetree/bindings/mfd/maxim,max5970.yaml line 4

Quoted 4 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +4 -0
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/max5970.yaml#

Does not look like you tested the bindings. Please run make dt_binding_check (see Documentation/devicetree/bindings/writing-schema.rst for instructions).

Quoted 63 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +63 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Regulator for MAX5970 smart switch from Maxim Integrated.
+
+maintainers:
+  - Patrick Rudolph <[email protected]>
+
+description: |
+  The smart switch provides no output regulation, but independent fault protection
+  and voltage and current sensing.
+  Programming is done through I2C bus.
+
+  Datasheets:
+    https://datasheets.maximintegrated.com/en/ds/MAX5970.pdf
+    https://datasheets.maximintegrated.com/en/ds/MAX5978.pdf
+
+properties:
+  compatible:
+    enum:
+      - maxim,max5970
+      - maxim,max5978
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  leds:
+    type: object
+    description:
+      Properties for single channel.
+
+    patternProperties:
+      "^led@[0-3]$":
+        $ref: /schemas/leds/common.yaml#
+        type: object
+
+    additionalProperties: true
+
+  vss1-supply:
+    description: Supply of the first channel.
+
+  vss2-supply:
+    description: Supply of the first channel.
+
+  "#io-channel-cells":
+    const: 1
+
+  regulators:
+    type: object
+    description:
+      Properties for single channel.
+
+    patternProperties:
+      "^(sw[0-1])$":
+        $ref: /schemas/regulator/regulator.yaml#
+        type: object
+
+      shunt-resistor-micro-ohms:
+        description: |
+          The value of curent sense resistor in microohms.
+          Must be specified for each channel.

Documentation/devicetree/bindings/mfd/maxim,max5970.yaml line 77

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +10 -0
+
+    additionalProperties: true
+
+required:
+  - compatible
+  - reg
+  - regulators
+  - vss1-supply
+
+

Just one blank line.

Quoted 31 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +31 -0
+allOf:
+  - if:
+      properties:
+        compatible:
+          enum:
+            - maxim,max5970
+    then:
+      properties:
+        io-channels:
+          items:
+            - description: voltage first channel
+            - description: current first channel
+            - description: voltage second channel
+            - description: current second channel
+          description: |
+            Voltage and current for first and second channel.
+      required:
+        - vss2-supply
+    else:
+      properties:
+        io-channels:
+          items:
+            - description: voltage first channel
+            - description: current first channel
+          description: |
+            Voltage and current for first channel.
+
+additionalProperties: false
+
+examples:
+  - |

Documentation/devicetree/bindings/mfd/maxim,max5970.yaml line 118

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +10 -0
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        regulator@3a {
+           compatible = "maxim,max5978";
+           reg = <0x3a>;
+           vss1-supply = <&p3v3>;
+
+           regulators {
+               sw0_ref_0: SW0 {

No improvements here.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Hi Krzysztof,

Quoted 5 lines · Krzysztof Kozlowski
Quoted 5 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +5 -0
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
Quoted 8 lines

Documentation/devicetree/bindings/mfd/maxim,max5970.yaml line 118

Quoted 7 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +7 -0
+        regulator@3a {
+           compatible = "maxim,max5978";
+           reg = <0x3a>;
+           vss1-supply = <&p3v3>;
+
+           regulators {
+               sw0_ref_0: SW0 {

No improvements here.

I've addressed 4 space indentation, bindings are matched, compatible is moved to first, then reg then the rest.

#5 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Quoted 16 lines · Naresh Solanki

Hi Krzysztof,

Quoted 5 lines · Krzysztof Kozlowski
Quoted 5 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +5 -0
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
Quoted 8 lines

Documentation/devicetree/bindings/mfd/maxim,max5970.yaml line 118

Quoted 7 lines
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml new file +7 -0
+        regulator@3a {
+           compatible = "maxim,max5978";
+           reg = <0x3a>;
+           vss1-supply = <&p3v3>;
+
+           regulators {
+               sw0_ref_0: SW0 {

No improvements here.

Quoted 2 lines

I've addressed 4 space indentation, bindings are matched, compatible is moved to first, then reg then the rest.

OK, so indeed there are improvements.

Yet still you did not improve the warnings coming from the binding - this does not match your binding. Test the binding and you will see big fat warning.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Quoted 5 lines · Krzysztof Kozlowski

OK, so indeed there are improvements.

Yet still you did not improve the warnings coming from the binding - this does not match your binding. Test the binding and you will see big fat warning.

Not sure what I've missed but below is the output:
make dt_binding_check -j1 V=1
make -f ./scripts/Makefile.build obj=scripts/basic
make -f ./scripts/Makefile.build obj=scripts/dtc
make -f ./scripts/Makefile.build obj=Documentation/devicetree/bindings
dt-extract-example
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml > Documentation/devicetree/bindings/mfd/maxim,max5970.example.dts
gcc -E
-Wp,-MMD,Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.pre.tmp -nostdinc -I./scripts/dtc/include-prefixes -undef -D__DTS__ -x assembler-with-cpp -o Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.dts.tmp Documentation/devicetree/bindings/mfd/maxim,max5970.example.dts ; ./scripts/dtc/dtc -o Documentation/devicetree/bindings/mfd/maxim,max5970.example.dtb -b 0 -iDocumentation/devicetree/bindings/mfd/ -i./scripts/dtc/include-prefixes -Wno-avoid_unnecessary_addr_size -Wno-graph_child_address -Wno-interrupt_provider -Wno-unique_unit_address -Wunique_unit_address_if_enabled -d Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.dtc.tmp Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.dts.tmp ; cat Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.pre.tmp Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.dtc.tmp > Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d ; dt-validate -u ./Documentation/devicetree/bindings -p ./Documentation/devicetree/bindings/processed-schema.json Documentation/devicetree/bindings/mfd/maxim,max5970.example.dtb || true

Didn't get any error or warning on example. Made sure python package dt-schema is updated as well.

#7 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Quoted 33 lines · Naresh Solanki
Quoted 5 lines · Krzysztof Kozlowski

OK, so indeed there are improvements.

Yet still you did not improve the warnings coming from the binding - this does not match your binding. Test the binding and you will see big fat warning.

Not sure what I've missed but below is the output:
make dt_binding_check -j1 V=1
make -f ./scripts/Makefile.build obj=scripts/basic
make -f ./scripts/Makefile.build obj=scripts/dtc
make -f ./scripts/Makefile.build obj=Documentation/devicetree/bindings
dt-extract-example
Documentation/devicetree/bindings/mfd/maxim,max5970.yaml > Documentation/devicetree/bindings/mfd/maxim,max5970.example.dts
gcc -E

(quoted diff) +0 -2
-Wp,-MMD,Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.pre.tmp 
-nostdinc -I./scripts/dtc/include-prefixes -undef -D__DTS__ -x 

assembler-with-cpp -o Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.dts.tmp Documentation/devicetree/bindings/mfd/maxim,max5970.example.dts ; ./scripts/dtc/dtc -o Documentation/devicetree/bindings/mfd/maxim,max5970.example.dtb -b 0

(quoted diff) +0 -4
-iDocumentation/devicetree/bindings/mfd/ 
-i./scripts/dtc/include-prefixes -Wno-avoid_unnecessary_addr_size 
-Wno-graph_child_address -Wno-interrupt_provider 
-Wno-unique_unit_address -Wunique_unit_address_if_enabled -d 

Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.dtc.tmp Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.dts.tmp ; cat Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.pre.tmp Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d.dtc.tmp

Quoted 7 lines
Quoted 1 line

Documentation/devicetree/bindings/mfd/.maxim_max5970.example.dtb.d ;

dt-validate -u ./Documentation/devicetree/bindings -p ./Documentation/devicetree/bindings/processed-schema.json Documentation/devicetree/bindings/mfd/maxim,max5970.example.dtb || true

Didn't get any error or warning on example. Made sure python package dt-schema is updated as well.

Eh, true, but you have there "additionalProperties: true" which are not allowed. This must be false and about leds I commented. False must be in all other places as well.

Best regards,
Krzysztof

#8 lore raw

Re: [PATCH v6 1/2] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

Quoted 3 lines · Krzysztof Kozlowski

Eh, true, but you have there "additionalProperties: true" which are not allowed. This must be false and about leds I commented. False must be in all other places as well.

Will fix in V8.

Thanks

#9 lore raw

PATCH v6 2/2 mfd: max597x: Add support for MAX5970 and MAX5978

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

Implement a regulator driver with IRQ support for fault management. Written against documentation [1] and [2] and tested on real hardware.

Every channel has its own regulator supplies nammed 'vss1-supply' and 'vss2-supply'. The regulator supply is used to determine the output voltage, as the smart switch provides no output regulation. The driver requires the 'shunt-resistor-micro-ohms' property to be present in Device Tree to properly calculate current related values.

Datasheet links:
1: https://datasheets.maximintegrated.com/en/ds/MAX5970.pdf
2: https://datasheets.maximintegrated.com/en/ds/MAX5978.pdf

---
 drivers/mfd/Kconfig         |  12 +++++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/max597x.c       |  92 ++++++++++++++++++++++++++++++++
 include/linux/mfd/max597x.h | 103 ++++++++++++++++++++++++++++++++++++
 4 files changed, 208 insertions(+)
 create mode 100644 drivers/mfd/max597x.c
 create mode 100644 include/linux/mfd/max597x.h
drivers/mfd/Kconfig +12 -0
index 8b93856de432..416fe7986b7b 100644
@@ -253,6 +253,18 @@ config MFD_MADERA_SPI
 	  Support for the Cirrus Logic Madera platform audio SoC
 	  core functionality controlled via SPI.
 
+config MFD_MAX597X
+	tristate "Maxim 597x Power Switch and Monitor"
+	depends on I2C
+	depends on OF
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  This driver controls a Maxim 5970/5978 switch via I2C bus.
+	  The MAX5970/5978 is a smart switch with no output regulation, but
+	  fault protection and voltage and current monitoring capabilities.
+	  Also it supports upto 4 indication LEDs.
+
 config MFD_CS47L15
 	bool "Cirrus Logic CS47L15"
 	select PINCTRL_CS47L15
drivers/mfd/Makefile +1 -0
index 7ed3ef4a698c..819d711fa748 100644
@@ -161,6 +161,7 @@ obj-$(CONFIG_MFD_DA9063)	+= da9063.o
 obj-$(CONFIG_MFD_DA9150)	+= da9150-core.o
 
 obj-$(CONFIG_MFD_MAX14577)	+= max14577.o
+obj-$(CONFIG_MFD_MAX597X)	+= max597x.o
 obj-$(CONFIG_MFD_MAX77620)	+= max77620.o
 obj-$(CONFIG_MFD_MAX77650)	+= max77650.o
 obj-$(CONFIG_MFD_MAX77686)	+= max77686.o
drivers/mfd/max597x.c new file +92 -0

92 lines not on this page · raw message

include/linux/mfd/max597x.h new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.37.3