Skip to contentSkip to conversation

dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

PATCH In review Naresh Solanki 4 participants 10 messages Jul 5, 2022 – Jul 19, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 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.

---
 .../devicetree/bindings/mfd/max5970.yaml      | 164 ++++++++++++++++++
 1 file changed, 164 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/max5970.yaml
Documentation/devicetree/bindings/mfd/max5970.yaml new file +164 -0
new file mode 100644
index 000000000000..a0cc6a7543b5
@@ -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 driver 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.
+
+  "#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:
+  - $ref: /schemas/regulator/regulator.yaml#
+  - if:
+      properties:
+        compatible:
+          enum:
+            - maxim,max5970
+    then:
+      properties:
+        vss2-supply:
+          description: Supply of the second channel.
+
+        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>;
+            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";
+                };
+            };
+            regulator@3a {
+                    reg = <0x3a>;
+                    vss1-supply = <&p3v3>;
+                    compatible = "maxim,max5978";
+
+                    regulators {
+                            sw0_ref_0: SW0 {
+                                   regulator-compatible = "SW0";
+                                   shunt-resistor-micro-ohms = <12000>;
+                            };
+                    };
+            };
+    };
+
+  - |
+    i2c {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            regulator@3a {
+                    reg = <0x3a>;
+                    vss1-supply = <&p3v3>;
+                    vss2-supply = <&p5v>;
+                    compatible = "maxim,max5970";
+
+                    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.35.3
#1 lore raw

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

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 it's own regulator supply 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' to be present in the devicetree to properly calculate current related values.

You must specify compatible devictree layout:

regulator@3a {
        reg = <0x3a>;
        vss1-supply = <&p3v3>;
        compatible = "maxim,max5978";

        ...

        regulators {
                sw0_ref: SW0 {
                        regulator-compatible = "SW0";
                        shunt-resistor-micro-ohms = <12000>;
                        ...
                }
        }
}

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        |   2 +
 drivers/mfd/max597x.c       | 109 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/max597x.h | 100 +++++++++++++++++++++++++++++++++
 4 files changed, 223 insertions(+)
 create mode 100644 drivers/mfd/max597x.c
 create mode 100644 include/linux/mfd/max597x.h
drivers/mfd/Kconfig +12 -0
index 3b59456f5545..2422ae155118 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 +2 -0
index 858cacf659d6..f5f46b86401f 100644
@@ -95,6 +95,8 @@ obj-$(CONFIG_MFD_MADERA)	+= madera.o
 obj-$(CONFIG_MFD_MADERA_I2C)	+= madera-i2c.o
 obj-$(CONFIG_MFD_MADERA_SPI)	+= madera-spi.o
 
+obj-$(CONFIG_MFD_MAX597X) += max597x.o
+
 obj-$(CONFIG_TPS6105X)		+= tps6105x.o
 obj-$(CONFIG_TPS65010)		+= tps65010.o
 obj-$(CONFIG_TPS6507X)		+= tps6507x.o
drivers/mfd/max597x.c new file +109 -0

109 lines not on this page · raw message

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

100 lines not on this page · raw message

Signature · 1 line
2.35.3
#2 lore raw

PATCH 3/5 regulator: max597x: Add support for max597x regulator

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

max597x is hot swap controller.
This regulator driver controls the same & also configures fault protection features supported by the chip.

---
 drivers/regulator/Kconfig             |  10 +
 drivers/regulator/Makefile            |   1 +
 drivers/regulator/max597x-regulator.c | 506 ++++++++++++++++++++++++++
 3 files changed, 517 insertions(+)
 create mode 100644 drivers/regulator/max597x-regulator.c
drivers/regulator/Kconfig +10 -0
index cbe0f96ca342..775d87a5d59d 100644
@@ -546,6 +546,16 @@ config REGULATOR_MAX1586
 	  regulator via I2C bus. The provided regulator is suitable
 	  for PXA27x chips to control VCC_CORE and VCC_USIM voltages.
 
+config REGULATOR_MAX597X
+	tristate "Maxim 597x power switch and monitor"
+	depends on I2C
+	depends on OF
+	select MFD_MAX597X
+	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.
+
 config REGULATOR_MAX77620
 	tristate "Maxim 77620/MAX20024 voltage regulator"
 	depends on MFD_MAX77620 || COMPILE_TEST
drivers/regulator/Makefile +1 -0
index 8d3ee8b6d41d..4a8a42998561 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o
 obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
 obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
+obj-$(CONFIG_REGULATOR_MAX597X) += max597x-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o
 obj-$(CONFIG_REGULATOR_MAX8649)	+= max8649.o
drivers/regulator/max597x-regulator.c new file +506 -0

506 lines not on this page · raw message

Signature · 1 line
2.35.3
#3 lore raw

Re: [PATCH 3/5] regulator: max597x: Add support for max597x regulator

Quoted 9 lines · Naresh Solanki

From: Patrick Rudolph <[email protected]>

max597x is hot swap controller.
This regulator driver controls the same & also configures fault protection features supported by the chip.

I like the way the IRQ helpers have been used here. It'd be cool to hear how the rest of the system you're dealing with utilize the WARN level events :)

drivers/regulator/max597x-regulator.c line 150

Quoted 13 lines
drivers/regulator/max597x-regulator.c new file +13 -0
+static int max597x_set_ocp(struct regulator_dev *rdev, int lim_uA,
+			   int severity, bool enable)
+{
+	int ret, val, reg;
+	unsigned int vthst, vthfst;
+
+	struct max597x_regulator *data = rdev_get_drvdata(rdev);
+	int rdev_id = rdev_get_id(rdev);
+	/*
+	 * MAX5970 doesn't has enable control for ocp.
+	 * If limit is specified but enable is not set then hold the value in
+	 * variable & later use it when ocp needs to be enabled.
+	 */

Is this a possible scenario? I think that if a non zero limit is given in a "regulator-oc-protection-microamp"-property, then the protection should always be enabled. Am I overlooking something?

Quoted 41 lines
drivers/regulator/max597x-regulator.c new file +41 -0
+	if (lim_uA != 0 && lim_uA != data->lim_uA)
+		data->lim_uA = lim_uA;
+
+	if (severity != REGULATOR_SEVERITY_PROT)
+		return -EINVAL;
+
+	if (enable) {
+
+		/* Calc Vtrip threshold in uV. */
+		vthst =
+		    div_u64(mul_u32_u32(data->shunt_micro_ohms, data->lim_uA),
+			    1000000);
+
+		/*
+		 * As recommended in datasheed, add 20% margin to avoid
+		 * spurious event & passive component tolerance.
+		 */
+		vthst = div_u64(mul_u32_u32(vthst, 120), 100);
+
+		/* Calc fast Vtrip threshold in uV */
+		vthfst = vthst * (MAX5970_FAST2SLOW_RATIO / 100);
+
+		if (vthfst > data->irng) {
+			dev_err(&rdev->dev, "Current limit out of range\n");
+			return -EINVAL;
+		}
+		/* Fast trip threshold to be programmed */
+		val = div_u64(mul_u32_u32(0xFF, vthfst), data->irng);
+	} else
+		/*
+		 * Since there is no option to disable ocp, set limit to max
+		 * value
+		 */
+		val = 0xFF;
+
+	reg = MAX5970_REG_DAC_FAST(rdev_id);
+	ret = regmap_write(rdev->regmap, reg, val);
+
+	return ret;
+}
+

drivers/regulator/max597x-regulator.c line 198

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +9 -0
 
+static int max597x_irq_handler(int irq, struct regulator_irq_data *rid,
+			       unsigned long *dev_mask)
+{
+	struct regulator_err_state *stat;
+	struct max597x_regulator *d = (struct max597x_regulator *)rid->data;
+	int val, ret, i;
+ > +	ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT0, &val);
+	if (ret)
+		return REGULATOR_FAILED_RETRY;

This "read_clear" smells like a race-by-design to me...

Quoted 15 lines
drivers/regulator/max597x-regulator.c new file +15 -0
+
+	*dev_mask = 0;
+	for (i = 0; i < d->num_switches; i++) {
+		stat = &rid->states[i];
+		stat->notifs = 0;
+		stat->errors = 0;
+	}
+
+	for (i = 0; i < d->num_switches; i++) {
+		stat = &rid->states[i];
+
+		if (val & UV_STATUS_CRIT(i)) {
+			*dev_mask |= 1 << i;
+			stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE;
+			stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE;

drivers/regulator/max597x-regulator.c line 309

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +10 -0
+		} else if (val & UV_STATUS_WARN(i)) {
+			*dev_mask |= 1 << i;
+			stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE_WARN;
+			stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE_WARN;
+		}
+	}
+
+	ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT1, &val);
+	if (ret)
+		return REGULATOR_FAILED_RETRY;

... and same here...

Quoted 9 lines
drivers/regulator/max597x-regulator.c new file +9 -0
+
+	for (i = 0; i < d->num_switches; i++) {
+		stat = &rid->states[i];
+
+		if (val & OV_STATUS_CRIT(i)) {
+			*dev_mask |= 1 << i;
+			stat->notifs |= REGULATOR_EVENT_REGULATION_OUT;
+			stat->errors |= REGULATOR_ERROR_REGULATION_OUT;
+		} else if (val & OV_STATUS_WARN(i)) {

drivers/regulator/max597x-regulator.c line 328

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +10 -0
+			*dev_mask |= 1 << i;
+			stat->notifs |= REGULATOR_EVENT_OVER_VOLTAGE_WARN;
+			stat->errors |= REGULATOR_ERROR_OVER_VOLTAGE_WARN;
+		}
+	}
+
+	ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT2, &val);
+	if (ret)
+		return REGULATOR_FAILED_RETRY;
+

... and here. I wonder if the reason for "clearing" would be worth commenting?

Quoted 33 lines
drivers/regulator/max597x-regulator.c new file +33 -0
+	for (i = 0; i < d->num_switches; i++) {
+		stat = &rid->states[i];
+
+		if (val & OC_STATUS_WARN(i)) {
+			*dev_mask |= 1 << i;
+			stat->notifs |= REGULATOR_EVENT_OVER_CURRENT_WARN;
+			stat->errors |= REGULATOR_ERROR_OVER_CURRENT_WARN;
+		}
+	}
+
+	ret = regmap_read(d->regmap, MAX5970_REG_STATUS0, &val);
+	if (ret)
+		return REGULATOR_FAILED_RETRY;
+
+	for (i = 0; i < d->num_switches; i++) {
+		stat = &rid->states[i];
+
+		if ((val & MAX5970_CB_IFAULTF(i))
+		    || (val & MAX5970_CB_IFAULTS(i))) {
+			*dev_mask |= 1 << i;
+			stat->notifs |=
+			    REGULATOR_EVENT_OVER_CURRENT |
+			    REGULATOR_EVENT_DISABLE;
+			stat->errors |=
+			    REGULATOR_ERROR_OVER_CURRENT | REGULATOR_ERROR_FAIL;
+
+			/* Clear the sub-IRQ status */
+			regulator_disable_regmap(stat->rdev);
+		}
+	}
+	return 0;
+}
+
Signature · 8 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

Discuss - Estimate - Plan - Report and finally accomplish this:
void do_work(int time) __attribute__ ((const));
#4 lore raw

Re: [PATCH 3/5] regulator: max597x: Add support for max597x regulator

Quoted 4 lines

I like the way the IRQ helpers have been used here. It'd be cool to hear how the rest of the system you're dealing with utilize the WARN level events :)

Userspace applications would receive sysfs notify for these events in realtime (there is another patch that enables sysfs notify on regulator events) This will enable taking necessary action if the regulator is not in good state.

Quoted 9 lines
Quoted 9 lines
drivers/regulator/max597x-regulator.c new file +9 -0
+static int max597x_set_ocp(struct regulator_dev *rdev, int lim_uA,
+                        int severity, bool enable)
+{
+     int ret, val, reg;
+     unsigned int vthst, vthfst;
+
+     struct max597x_regulator *data = rdev_get_drvdata(rdev);
+     int rdev_id = rdev_get_id(rdev);
+     /*
Quoted 9 lines

drivers/regulator/max597x-regulator.c line 150

Quoted 4 lines
drivers/regulator/max597x-regulator.c new file +4 -0
+      * MAX5970 doesn't has enable control for ocp.
+      * If limit is specified but enable is not set then hold the value in
+      * variable & later use it when ocp needs to be enabled.
+      */

Is this a possible scenario? I think that if a non zero limit is given in a "regulator-oc-protection-microamp"-property, then the protection should always be enabled. Am I overlooking something?

Yes in the current scenario, if non-zero ocp is provided then protection should always be enabled.
But since there is an enable switch in function call, I felt like it should be addressed in this way.

Quoted 12 lines

drivers/regulator/max597x-regulator.c line 284

Quoted 9 lines
drivers/regulator/max597x-regulator.c new file +9 -0
+static int max597x_irq_handler(int irq, struct regulator_irq_data *rid,
+                            unsigned long *dev_mask)
+{
+     struct regulator_err_state *stat;
+     struct max597x_regulator *d = (struct max597x_regulator *)rid->data;
+     int val, ret, i;
+ > + ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT0, &val);
+     if (ret)
+             return REGULATOR_FAILED_RETRY;

This "read_clear" smells like a race-by-design to me...

I'm not sure what best way would be to address this but if Under/Over Voltage & Over current scenario
occurs then the interrupt line remains low until things are normal. The fault register bit can be clear only if output is normal or power cycled.

Quoted 95 lines
Quoted 15 lines
drivers/regulator/max597x-regulator.c new file +15 -0
+
+     *dev_mask = 0;
+     for (i = 0; i < d->num_switches; i++) {
+             stat = &rid->states[i];
+             stat->notifs = 0;
+             stat->errors = 0;
+     }
+
+     for (i = 0; i < d->num_switches; i++) {
+             stat = &rid->states[i];
+
+             if (val & UV_STATUS_CRIT(i)) {
+                     *dev_mask |= 1 << i;
+                     stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE;
+                     stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE;

drivers/regulator/max597x-regulator.c line 309

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +10 -0
+             } else if (val & UV_STATUS_WARN(i)) {
+                     *dev_mask |= 1 << i;
+                     stat->notifs |= REGULATOR_EVENT_UNDER_VOLTAGE_WARN;
+                     stat->errors |= REGULATOR_ERROR_UNDER_VOLTAGE_WARN;
+             }
+     }
+
+     ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT1, &val);
+     if (ret)
+             return REGULATOR_FAILED_RETRY;

... and same here...

Quoted 9 lines
drivers/regulator/max597x-regulator.c new file +9 -0
+
+     for (i = 0; i < d->num_switches; i++) {
+             stat = &rid->states[i];
+
+             if (val & OV_STATUS_CRIT(i)) {
+                     *dev_mask |= 1 << i;
+                     stat->notifs |= REGULATOR_EVENT_REGULATION_OUT;
+                     stat->errors |= REGULATOR_ERROR_REGULATION_OUT;
+             } else if (val & OV_STATUS_WARN(i)) {

drivers/regulator/max597x-regulator.c line 328

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +10 -0
+                     *dev_mask |= 1 << i;
+                     stat->notifs |= REGULATOR_EVENT_OVER_VOLTAGE_WARN;
+                     stat->errors |= REGULATOR_ERROR_OVER_VOLTAGE_WARN;
+             }
+     }
+
+     ret = max597x_regmap_read_clear(d->regmap, MAX5970_REG_FAULT2, &val);
+     if (ret)
+             return REGULATOR_FAILED_RETRY;
+

... and here. I wonder if the reason for "clearing" would be worth commenting?

Quoted 23 lines
drivers/regulator/max597x-regulator.c new file +23 -0
+     for (i = 0; i < d->num_switches; i++) {
+             stat = &rid->states[i];
+
+             if (val & OC_STATUS_WARN(i)) {
+                     *dev_mask |= 1 << i;
+                     stat->notifs |= REGULATOR_EVENT_OVER_CURRENT_WARN;
+                     stat->errors |= REGULATOR_ERROR_OVER_CURRENT_WARN;
+             }
+     }
+
+     ret = regmap_read(d->regmap, MAX5970_REG_STATUS0, &val);
+     if (ret)
+             return REGULATOR_FAILED_RETRY;
+
+     for (i = 0; i < d->num_switches; i++) {
+             stat = &rid->states[i];
+
+             if ((val & MAX5970_CB_IFAULTF(i))
+                 || (val & MAX5970_CB_IFAULTS(i))) {
+                     *dev_mask |= 1 << i;
+                     stat->notifs |=
+                         REGULATOR_EVENT_OVER_CURRENT |
+                         REGULATOR_EVENT_DISABLE;

drivers/regulator/max597x-regulator.c line 361

Quoted 10 lines
drivers/regulator/max597x-regulator.c new file +10 -0
+                     stat->errors |=
+                         REGULATOR_ERROR_OVER_CURRENT | REGULATOR_ERROR_FAIL;
+
+                     /* Clear the sub-IRQ status */
+                     regulator_disable_regmap(stat->rdev);
+             }
+     }
+     return 0;
+}
+

--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

Discuss - Estimate - Plan - Report and finally accomplish this:
void do_work(int time) __attribute__ ((const));

maintainer
#5 lore raw

Re: [PATCH 3/5] regulator: max597x: Add support for max597x regulator

Quoted 7 lines · Naresh Solanki
Quoted 3 lines

I like the way the IRQ helpers have been used here. It'd be cool to hear how the rest of the system you're dealing with utilize the WARN level events :)

Userspace applications would receive sysfs notify for these events in realtime (there is another patch that enables sysfs notify on regulator events) This will enable taking necessary action if the regulator is not in good state.

Right, the question is more what the action that might be taken is.

#6 lore raw

PATCH 4/5 iio: max597x: Add support for max597x

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

max597x has 10bit ADC for voltage & current monitoring. Use iio framework to expose the same in sysfs.

---
 drivers/iio/adc/Kconfig       |   9 ++
 drivers/iio/adc/Makefile      |   1 +
 drivers/iio/adc/max597x-iio.c | 156 ++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/iio/adc/max597x-iio.c
drivers/iio/adc/Kconfig +9 -0
index 48ace7412874..d4676eefb60f 100644
@@ -683,6 +683,15 @@ config MAX1363
 	  To compile this driver as a module, choose M here: the module will be
 	  called max1363.
 
+config MAX597X_IIO
+	tristate "Maxim 597x power switch and monitor"
+	depends on I2C
+	depends on OF
+	select MFD_MAX597X
+	help
+	  This driver exposes Maxim 5970/5978 voltage/current monitoring
+	  interface using iio framework.
+
 config MAX9611
 	tristate "Maxim max9611/max9612 ADC driver"
 	depends on I2C
drivers/iio/adc/Makefile +1 -0
index 39d806f6d457..f8cb5a30a946 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_MAX11100) += max11100.o
 obj-$(CONFIG_MAX1118) += max1118.o
 obj-$(CONFIG_MAX1241) += max1241.o
 obj-$(CONFIG_MAX1363) += max1363.o
+obj-$(CONFIG_MAX597X_IIO) += max597x-iio.o
 obj-$(CONFIG_MAX9611) += max9611.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_MCP3422) += mcp3422.o
drivers/iio/adc/max597x-iio.c new file +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.35.3
#7 lore raw

PATCH 5/5 leds: max597x: Add support for max597x

In reply to Naresh Solanki

From: Patrick Rudolph <[email protected]>

max597x is hot swap controller with indication led support. This driver uses DT property to configure led during boot time & also provide the led control in sysfs.

---
 drivers/leds/Kconfig        |  10 +++
 drivers/leds/Makefile       |   1 +
 drivers/leds/leds-max597x.c | 130 ++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 drivers/leds/leds-max597x.c
drivers/leds/Kconfig +10 -0
index a49979f41eee..682748097276 100644
@@ -598,6 +598,16 @@ config LEDS_ADP5520
 	  To compile this driver as a module, choose M here: the module will
 	  be called leds-adp5520.
 
+config LEDS_MAX597X
+	tristate "Maxim 597x leds"
+	depends on I2C
+	depends on OF
+	depends on LEDS_CLASS
+	select MFD_MAX597X
+	help
+	  This driver controls a Maxim 5970/5978 indication led via I2C bus.
+	  The MAX5970/5978 is a smart switch with 4 indication leds
+
 config LEDS_MC13783
 	tristate "LED Support for MC13XXX PMIC"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 4fd2f92cd198..c44b0e9559ab 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_LEDS_LP8501)		+= leds-lp8501.o
 obj-$(CONFIG_LEDS_LP8788)		+= leds-lp8788.o
 obj-$(CONFIG_LEDS_LP8860)		+= leds-lp8860.o
 obj-$(CONFIG_LEDS_LT3593)		+= leds-lt3593.o
+obj-$(CONFIG_LEDS_MAX597X)		+= leds-max597x.o
 obj-$(CONFIG_LEDS_MAX77650)		+= leds-max77650.o
 obj-$(CONFIG_LEDS_MAX8997)		+= leds-max8997.o
 obj-$(CONFIG_LEDS_MC13783)		+= leds-mc13783.o
drivers/leds/leds-max597x.c new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.35.3
#8 lore raw

Re: [PATCH 5/5] leds: max597x: Add support for max597x

Hi!

Quoted 7 lines
drivers/leds/Kconfig +0 -0
index a49979f41eee..682748097276 100644
@@ -598,6 +598,16 @@ config LEDS_ADP5520
 	  To compile this driver as a module, choose M here: the module will
 	  be called leds-adp5520.

drivers/leds/Kconfig config LEDS_ADP5520 · line 609

Quoted 10 lines
drivers/leds/Kconfig +9 -0
 
+config LEDS_MAX597X
+	tristate "Maxim 597x leds"
+	depends on I2C
+	depends on OF
+	depends on LEDS_CLASS
+	select MFD_MAX597X
+	help
+	  This driver controls a Maxim 5970/5978 indication led via I2C bus.
+	  The MAX5970/5978 is a smart switch with 4 indication leds

led->LED.

Add "to compile this driver as a module, choose M here: the module will be called ..".

Add "." at end of sentence.

drivers/leds/Kconfig line 3

Quoted 5 lines
drivers/leds/Kconfig +4 -0
+++ b/drivers/leds/leds-max597x.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device driver for regulators in MAX5970 and MAX5978 IC

?

drivers/leds/Kconfig line 11

Quoted 8 lines
drivers/leds/Kconfig +8 -0
+static int max597x_led_set_brightness(struct led_classdev *cdev,
+				      enum led_brightness brightness)
+{
+	struct max597x_led *led = cdev->driver_data;
+	int ret;
+
+	if (!led || !led->regmap)
+		return -1;

-ERRNO.

drivers/leds/Kconfig line 17

Quoted 6 lines
drivers/leds/Kconfig +6 -0
+static int max597x_led_probe(struct platform_device *pdev)
+{
+
+
+	struct max597x_data *max597x = dev_get_drvdata(pdev->dev.parent);
+	struct device_node *np = dev_of_node(pdev->dev.parent);

Delete empty lines.

drivers/leds/Kconfig line 22

Quoted 5 lines
drivers/leds/Kconfig +5 -0
+	struct device_node *led_node;
+	struct device_node *child;
+	int ret = 0;
+
+

One empty line would be enough.

drivers/leds/Kconfig line 26

Quoted 4 lines
drivers/leds/Kconfig +4 -0
+module_platform_driver(max597x_led_driver);
+
+
+MODULE_AUTHOR("Patrick Rudolph <[email protected]>");

One empty line would be enough.

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
maintainer
#9 lore raw

Re: (subset) [PATCH 1/5] dt-bindings: mfd: Add bindings for MAX5970 and MAX5978

In reply to Naresh Solanki
Quoted 6 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.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[3/5] regulator: max597x: Add support for max597x regulator

      commit: 38493f008deb435577361d4c4cdd69f7bb30f4b9

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark