Skip to contentSkip to conversation

Add support for MAX20830C and MAX20840C step-down DC-DC switching regulator

PATCH Applied Alexis Czezar Torreno 3 participants 15 messages Jul 30

Subsystems (4)
lore
Share & tools
lore

Alexis Czezar Torreno

author maintainer
#0 lore raw

v5 cover Add support for MAX20830C and MAX20840C step-down DC-DC switching regulator

This series adds a few features before adding support to MAX20830C and MAX20840C.

Patches 1 and 2 adds new resistor feedback properties that is needed to properly scale VOUT

Patches 3 and 4 adds support for devices MAX20830C and MAX20840C.

MAX20830C and MAX20840 are step-down DC-DC switching regulator with PMBus interface. MAX20830C is a different packaging for MAX20830, and MAX20840C supports 40A regulation compared to MAX20830 that is only 30A.

---
Changes in v5:
- Patch 2/4: added comment about not supporting limit registers
- Patch 4/4:
- removed max20830c/40c entries in i2c_device_id
- created an array to help scale adding of new variants
- edited Kconfig to note new compatibles
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Patch 1/4:
- Added missing #include for gpio
- Removed review tag, patch edited to complete examples
- Patch 2/4:
- casted feedback resistors to u64 to avoid possible overflow
during scaling
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Dropped patch that add EN-GPIO property in DTS
- discussed to be skippable until an actual use-case arise
- Patch 1/4:
- Carried over the completed examples from previously dropped patch
- Kept the review tag as the carried info from the dropped patched
was also reviewed.
- Patch 2/4:
- added clamping to read_vout during scaling
- improved comments regarding future regulator support
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Patch 1/5: completing example
- Dropped patch adding GPIO enable in driver (no use case)
- Patch 3/5: added notes on READ_VOUT and related VOUT commands
- Patch 4/5: removed comment on fallback
- Patch 5/5: simplified device ID check handling
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexis Czezar Torreno (4):
dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties and complete examples
hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support
dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support
hwmon: (pmbus/max20830): add support for max20830c and max20840c

 .../bindings/hwmon/pmbus/adi,max20830.yaml         |  30 +++++-
 Documentation/hwmon/max20830.rst                   |  27 +++++-
 drivers/hwmon/pmbus/Kconfig                        |   4 +-
 drivers/hwmon/pmbus/max20830.c                     | 101 ++++++++++++++++++---
 4 files changed, 140 insertions(+), 22 deletions(-)

---
base-commit: 1a42625604046790ea8ec61c2a749bbf76b28943
change-id: 20260630-dev-max20830c-9d38d8b0a765

Best regards,

Signature · 1 line
Alexis Czezar Torreno <[email protected]>
author maintainer
#1 lore raw

PATCH v5 1/4 dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties and complete examples

Add adi,vout-rfb1-ohms and adi,vout-rfb2-ohms properties to support external voltage divider configuration for VOUT sensing. When the desired output voltage is higher than VREF, a resistor divider (RFB1 and RFB2) is required to reach the intended value.

The properties use a dependency constraint to ensure both resistors are specified together, or neither. This prevents misconfiguration where only one resistor value is provided.

This patch also adds missing entries in the examples.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +22 -0
index 1625dd59417f1b3ca689a9c86ca266da913d1217..01b7275f5b3419cf1b791ed8f9b7ae56cd2961b5 100644
@@ -44,15 +44,32 @@ properties:
       GPIO connected to the power-good status output pin.
     maxItems: 1
 
+  adi,vout-rfb1-ohms:
+    description:
+      Top feedback resistor (RFB1) value in ohms for VOUT sensing divider.
+      When the desired output voltage is higher than VREF, a resistor divider
+      is required. VOUT = VREF × (1 + RFB1/RFB2)
+
+  adi,vout-rfb2-ohms:
+    description:
+      Bottom feedback resistor (RFB2) value in ohms for VOUT sensing divider.
+      Datasheet recommends that RFB2 does not exceed 2.5kΩ.
+
 required:
   - compatible
   - reg
   - vddh-supply
 
+dependencies:
+  adi,vout-rfb1-ohms: ['adi,vout-rfb2-ohms']
+  adi,vout-rfb2-ohms: ['adi,vout-rfb1-ohms']
+
 unevaluatedProperties: false
 
 examples:
   - |
+    #include <dt-bindings/gpio/gpio.h>
+
     i2c {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -61,6 +78,11 @@ examples:
             compatible = "adi,max20830";
             reg = <0x30>;
             vddh-supply = <&vddh>;
+            avdd-supply = <&avdd>;
+            ldoin-supply = <&ldoin>;
+            pwr-good-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
+            adi,vout-rfb1-ohms = <10000>;
+            adi,vout-rfb2-ohms = <2000>;
         };
     };
 ...
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/4] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties and complete examples

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Add adi,vout-rfb1-ohms and adi,vout-rfb2-ohms properties to support external voltage divider configuration for VOUT sensing. When the desired output voltage is higher than VREF, a resistor divider (RFB1 and RFB2) is required to reach the intended value.

Quoted 8 lines

The properties use a dependency constraint to ensure both resistors are specified together, or neither. This prevents misconfiguration where only one resistor value is provided.

This patch also adds missing entries in the examples.

Sashiko has reviewed this patch and found no issues. It looks great!

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

Re: [PATCH v5 1/4] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties and complete examples

In reply to Alexis Czezar Torreno
Quoted 5 lines · Alexis Czezar Torreno

Add adi,vout-rfb1-ohms and adi,vout-rfb2-ohms properties to support external voltage divider configuration for VOUT sensing. When the desired output voltage is higher than VREF, a resistor divider (RFB1 and RFB2) is required to reach the intended value.

Quoted 8 lines

The properties use a dependency constraint to ensure both resistors are specified together, or neither. This prevents misconfiguration where only one resistor value is provided.

This patch also adds missing entries in the examples.

Applied.

Thanks,
Guenter

author maintainer
#4 lore raw

PATCH v5 2/4 hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

In reply to Alexis Czezar Torreno

Implement support for external voltage divider scaling using the adi,vout-rfb1-ohms and adi,vout-rfb2-ohms device tree properties.

When the desired output voltage exceeds VREF, a resistor divider (RFB1 and RFB2) is used to scale down the feedback voltage. The driver reads these resistor values from device tree and applies the scaling formula: VOUT_actual = VOUT_measured × (1 + RFB1/RFB2)

The properties are optional. If not specified, the driver assumes no voltage divider is present and reports the raw VOUT reading.

---
 drivers/hwmon/pmbus/max20830.c | 65 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/max20830.c +64 -1
index cb2c23672166d641852199ca07eb716924f4f286..ddead72a8db5d6f8491cbfbf356db0f8de64da03 100644
@@ -7,6 +7,7 @@
 
 #include <linux/errno.h>
 #include <linux/i2c.h>
+#include <linux/math64.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/string.h>
@@ -14,6 +15,56 @@
 
 #define MAX20830_IC_DEVICE_ID_LENGTH	9
 
+struct max20830_data {
+	struct pmbus_driver_info info;
+	u32 vout_rfb1;
+	u32 vout_rfb2;
+};
+
+/*
+ * MAX20830 only supports READ_VOUT for VOUT monitoring.
+ *
+ * Limit registers (VOUT_OV_WARN_LIMIT, VOUT_OV_FAULT_LIMIT, etc.) are not
+ * supported by this driver and return -ENODATA. This means sysfs attributes
+ * like in1_max, in1_crit, etc. will not be available. Only in1_input (the
+ * scaled output voltage) is supported.
+ *
+ * MAX20830 uses an external resistor divider for voltage sensing:
+ * - VOUT_COMMAND and VOUT_MAX set the reference voltage at the feedback pin
+ * - READ_VOUT reports the feedback voltage, which needs to be scaled for actual
+ *   output voltage
+ *
+ * Scaling formula: vout_actual = vout_fb × (1 + RFB1 / RFB2)
+ *
+ * If regulator support is added in the future, some adjustments are needed to
+ * ensure correct feedback voltages are set.
+ */
+static int max20830_read_word_data(struct i2c_client *client, int page,
+				   int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	const struct max20830_data *data = container_of(info, struct max20830_data, info);
+	int ret;
+	u64 temp;
+
+	switch (reg) {
+	case PMBUS_READ_VOUT:
+		ret = pmbus_read_word_data(client, page, phase, reg);
+		if (ret < 0)
+			return ret;
+
+		/* Apply voltage divider scaling if resistors are non-zero */
+		if (data->vout_rfb1 && data->vout_rfb2) {
+			temp = (u64)data->vout_rfb1 + (u64)data->vout_rfb2;
+			temp = DIV_ROUND_CLOSEST_ULL((u64)ret * temp, data->vout_rfb2);
+			ret = clamp_val(temp, 0, 0xFFFF);
+		}
+		return ret;
+	default:
+		return -ENODATA;
+	}
+}
+
 static struct pmbus_driver_info max20830_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +75,25 @@ static struct pmbus_driver_info max20830_info = {
 		PMBUS_HAVE_TEMP |
 		PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
 		PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
+	.read_word_data = max20830_read_word_data,
 };
 
 static int max20830_probe(struct i2c_client *client)
 {
 	u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = {};
+	struct max20830_data *data;
 	int ret;
 
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->info = max20830_info;
+
+	/* Read optional voltage divider resistor values */
+	device_property_read_u32(&client->dev, "adi,vout-rfb1-ohms", &data->vout_rfb1);
+	device_property_read_u32(&client->dev, "adi,vout-rfb2-ohms", &data->vout_rfb2);
+
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA) &&
 	    !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
 		return -ENODEV;
@@ -78,7 +141,7 @@ static int max20830_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, -ENODEV,
 				     "Unsupported device: '%s'\n", buf);
 
-	return pmbus_do_probe(client, &max20830_info);
+	return pmbus_do_probe(client, &data->info);
 }
 
 static const struct i2c_device_id max20830_id[] = {
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v5 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Returning -ENODATA does not mask unsupported PMBus limit registers, incorrectly exposing…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Returning -ENODATA does not mask unsupported PMBus limit registers, incorrectly exposing unscaled limit attributes if the hardware responds. --

--- Patch [2]: [PATCH v5 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support --- commit 852e7cf36da1bb5ec1c29eff09bb747755762b5b
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

This commit adds support for external voltage divider scaling in the max20830 driver. It reads resistor values from device tree properties and applies a scaling formula to VOUT readings to report the actual output voltage.

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c +0 -0

[ ... ]

Quoted 1 line
drivers/hwmon/pmbus/max20830.c +0 -0
@@ -14,6 +15,56 @@

[ ... ]

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+static int max20830_read_word_data(struct i2c_client *client, int page,
+				   int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	const struct max20830_data *data = container_of(info, struct max20830_data, info);
+	int ret;
+	u64 temp;
+
+	switch (reg) {
+	case PMBUS_READ_VOUT:

[ ... ]

drivers/hwmon/pmbus/max20830.c line 64

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c +3 -0
+		return ret;
+	default:
+		return -ENODATA;

[Severity: Medium]
Does returning -ENODATA here actually mask the unsupported limit registers as intended?

In the PMBus core framework, returning -ENODATA from the driver's read callback is treated as a signal to fall back to a standard I2C read. It does not block the attribute.

If the hardware responds to the limit register reads over standard I2C, the PMBus core will still create the sysfs attributes. Because scaling is only applied to PMBUS_READ_VOUT in this patch, these exposed limit attributes (e.g., in1_max) would report raw, unscaled feedback voltages, while in1_input reports scaled actual voltages, creating an inconsistent interface.

Should this return -ENXIO instead, which explicitly tells the PMBus core that the register is unsupported and prevents the sysfs attributes from being created?

Quoted 2 lines
drivers/hwmon/pmbus/max20830.c +2 -0
+	}
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#6 lore raw

Re: [PATCH v5 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Quoted 49 lines · On 7/29/26 18:14, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Returning -ENODATA does not mask unsupported PMBus limit registers, incorrectly exposing unscaled limit attributes if the hardware responds. --

--- Patch [2]: [PATCH v5 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support --- commit 852e7cf36da1bb5ec1c29eff09bb747755762b5b
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

This commit adds support for external voltage divider scaling in the max20830 driver. It reads resistor values from device tree properties and applies a scaling formula to VOUT readings to report the actual output voltage.

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c +0 -0

[ ... ]

Quoted 1 line
drivers/hwmon/pmbus/max20830.c +0 -0
@@ -14,6 +15,56 @@

[ ... ]

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+static int max20830_read_word_data(struct i2c_client *client, int page,
+				   int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	const struct max20830_data *data = container_of(info, struct max20830_data, info);
+	int ret;
+	u64 temp;
+
+	switch (reg) {
+	case PMBUS_READ_VOUT:

[ ... ]

drivers/hwmon/pmbus/max20830.c line 64

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c +3 -0
+		return ret;
+	default:
+		return -ENODATA;

[Severity: Medium]
Does returning -ENODATA here actually mask the unsupported limit registers as intended?

In the PMBus core framework, returning -ENODATA from the driver's read callback is treated as a signal to fall back to a standard I2C read. It does not block the attribute.

If the hardware responds to the limit register reads over standard I2C, the PMBus core will still create the sysfs attributes. Because scaling is only applied to PMBUS_READ_VOUT in this patch, these exposed limit attributes (e.g., in1_max) would report raw, unscaled feedback voltages, while in1_input reports scaled actual voltages, creating an inconsistent interface.

Quoted 4 lines

Should this return -ENXIO instead, which explicitly tells the PMBus core that the register is unsupported and prevents the sysfs attributes from being created?
That would require explicitly listing either all supported or all unsupported

attributes. Let's not do that unless it is really necessary.

Guenter

maintainer Applied
#7 lore raw

Re: [PATCH v5 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

In reply to Alexis Czezar Torreno
Quoted 8 lines · Alexis Czezar Torreno

Implement support for external voltage divider scaling using the adi,vout-rfb1-ohms and adi,vout-rfb2-ohms device tree properties.

When the desired output voltage exceeds VREF, a resistor divider (RFB1 and RFB2) is used to scale down the feedback voltage. The driver reads these resistor values from device tree and applies the scaling formula: VOUT_actual = VOUT_measured × (1 + RFB1/RFB2)

Quoted 4 lines

The properties are optional. If not specified, the driver assumes no voltage divider is present and reports the raw VOUT reading.

Applied.

Thanks,
Guenter

Quoted 108 lines
---
 drivers/hwmon/pmbus/max20830.c | 65 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/max20830.c +64 -1
index cb2c23672166d641852199ca07eb716924f4f286..ddead72a8db5d6f8491cbfbf356db0f8de64da03 100644
@@ -7,6 +7,7 @@
 
 #include <linux/errno.h>
 #include <linux/i2c.h>
+#include <linux/math64.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/string.h>
@@ -14,6 +15,56 @@
 
 #define MAX20830_IC_DEVICE_ID_LENGTH	9
 
+struct max20830_data {
+	struct pmbus_driver_info info;
+	u32 vout_rfb1;
+	u32 vout_rfb2;
+};
+
+/*
+ * MAX20830 only supports READ_VOUT for VOUT monitoring.
+ *
+ * Limit registers (VOUT_OV_WARN_LIMIT, VOUT_OV_FAULT_LIMIT, etc.) are not
+ * supported by this driver and return -ENODATA. This means sysfs attributes
+ * like in1_max, in1_crit, etc. will not be available. Only in1_input (the
+ * scaled output voltage) is supported.
+ *
+ * MAX20830 uses an external resistor divider for voltage sensing:
+ * - VOUT_COMMAND and VOUT_MAX set the reference voltage at the feedback pin
+ * - READ_VOUT reports the feedback voltage, which needs to be scaled for actual
+ *   output voltage
+ *
+ * Scaling formula: vout_actual = vout_fb × (1 + RFB1 / RFB2)
+ *
+ * If regulator support is added in the future, some adjustments are needed to
+ * ensure correct feedback voltages are set.
+ */
+static int max20830_read_word_data(struct i2c_client *client, int page,
+				   int phase, int reg)
+{
+	const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
+	const struct max20830_data *data = container_of(info, struct max20830_data, info);
+	int ret;
+	u64 temp;
+
+	switch (reg) {
+	case PMBUS_READ_VOUT:
+		ret = pmbus_read_word_data(client, page, phase, reg);
+		if (ret < 0)
+			return ret;
+
+		/* Apply voltage divider scaling if resistors are non-zero */
+		if (data->vout_rfb1 && data->vout_rfb2) {
+			temp = (u64)data->vout_rfb1 + (u64)data->vout_rfb2;
+			temp = DIV_ROUND_CLOSEST_ULL((u64)ret * temp, data->vout_rfb2);
+			ret = clamp_val(temp, 0, 0xFFFF);
+		}
+		return ret;
+	default:
+		return -ENODATA;
+	}
+}
+
 static struct pmbus_driver_info max20830_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +75,25 @@ static struct pmbus_driver_info max20830_info = {
 		PMBUS_HAVE_TEMP |
 		PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
 		PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
+	.read_word_data = max20830_read_word_data,
 };
 
 static int max20830_probe(struct i2c_client *client)
 {
 	u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = {};
+	struct max20830_data *data;
 	int ret;
 
+	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->info = max20830_info;
+
+	/* Read optional voltage divider resistor values */
+	device_property_read_u32(&client->dev, "adi,vout-rfb1-ohms", &data->vout_rfb1);
+	device_property_read_u32(&client->dev, "adi,vout-rfb2-ohms", &data->vout_rfb2);
+
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA) &&
 	    !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
 		return -ENODEV;
@@ -78,7 +141,7 @@ static int max20830_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, -ENODEV,
 				     "Unsupported device: '%s'\n", buf);
 
-	return pmbus_do_probe(client, &max20830_info);
+	return pmbus_do_probe(client, &data->info);
 }
 
 static const struct i2c_device_id max20830_id[] = {
author maintainer
#8 lore raw

PATCH v5 3/4 dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support

In reply to Alexis Czezar Torreno

Add compatible strings for variants of MAX20830 which are MAX20830C and MAX20840C. These devices have the same register functionality with MAX20830 but with a longer IC_DEVICE_ID.

---
 Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +7 -1
index 01b7275f5b3419cf1b791ed8f9b7ae56cd2961b5..cc50a4ee44a27bd5b14d6b56afe87f807adcb9e2 100644
@@ -22,7 +22,13 @@ allOf:
 
 properties:
   compatible:
-    const: adi,max20830
+    oneOf:
+      - const: adi,max20830
+      - items:
+          - enum:
+              - adi,max20830c
+              - adi,max20840c
+          - const: adi,max20830
 
   reg:
     maxItems: 1
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v5 3/4] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The dt-bindings introduce `adi,max20840c` with a fallback to `adi,max20830`, asserting…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The dt-bindings introduce adi,max20840c with a fallback to adi,max20830, asserting compatibility, but the existing max20830 driver explicitly rejects MAX20840C hardware during probe due to a strict IC_DEVICE_ID string check. --

--- Patch [3]: [PATCH v5 3/4] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support --- commit 6c40a5eeb4c4be3695032dfafd53c9b3d0333b47
Author: Alexis Czezar Torreno <[email protected]>

dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support

This commit adds compatible strings for MAX20830C and MAX20840C to the MAX20830 PMBus hardware monitoring driver bindings. It uses a fallback to adi,max20830 for the new variants.

Quoted 6 lines
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +0 -0
index 01b7275f5b341..cc50a4ee44a27 100644
@@ -22,7 +22,13 @@ allOf:
 

Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml allOf: · line 31

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +7 -1
 properties:
   compatible:
-    const: adi,max20830
+    oneOf:
+      - const: adi,max20830
+      - items:
+          - enum:
+              - adi,max20830c
+              - adi,max20840c
+          - const: adi,max20830

[Severity: Medium]
Will the existing driver actually be able to probe the MAX20840C hardware using this fallback?

Looking at max20830_probe() in drivers/hwmon/pmbus/max20830.c, there is a strict device ID string check:

drivers/hwmon/pmbus/max20830.c:max20830_probe() {
    ...
	if (strncmp(buf, "MAX20830", MAX20830_IC_DEVICE_ID_LENGTH - 1))
		return dev_err_probe(&client->dev, -ENODEV,
				     "Unsupported device: '%s'\n", buf);
    ...
}

Will this actively reject a MAX20840C device since its ID presumably starts with "MAX20840"?

Additionally, the commit message mentions a longer IC_DEVICE_ID, but the I2C block read in max20830_probe() hardcodes the read length:

drivers/hwmon/pmbus/max20830.c:max20830_probe() {
    ...
		ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
						    MAX20830_IC_DEVICE_ID_LENGTH + 1,
						    buf);
    ...
}

Will the longer ID be truncated before validation?

Quoted 3 lines
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +0 -0
   reg:
     maxItems: 1
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Applied
#10 lore raw

Re: [PATCH v5 3/4] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support

In reply to Alexis Czezar Torreno
Quoted 6 lines · Alexis Czezar Torreno

Add compatible strings for variants of MAX20830 which are MAX20830C and MAX20840C. These devices have the same register functionality with MAX20830 but with a longer IC_DEVICE_ID.

Applied.

Thanks,
Guenter

author maintainer
#11 lore raw

PATCH v5 4/4 hwmon: (pmbus/max20830): add support for max20830c and max20840c

In reply to Alexis Czezar Torreno

Add support for MAX20830C and MAX20840 step-down DC-DC switching regulator with PMBus interface. MAX20830C is a different packaging for MAX20830, and MAX20840C supports 40A regulation compared to MAX20830 that is only 30A.

---
 Documentation/hwmon/max20830.rst | 27 ++++++++++++++++++++++-----
 drivers/hwmon/pmbus/Kconfig      |  4 ++--
 drivers/hwmon/pmbus/max20830.c   | 36 +++++++++++++++++++++++-------------
 3 files changed, 47 insertions(+), 20 deletions(-)
Documentation/hwmon/max20830.rst +22 -5
index 936e409dcc5c0898dde27d782308d4a7e1357e73..b850f3b6e40d1f1d0cec944be40af02265aced59 100644
@@ -13,6 +13,22 @@ Supported chips:
 
     Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/max20830.pdf
 
+  * Analog Devices MAX20830C
+
+    Prefix: 'max20830c'
+
+    Addresses scanned: -
+
+    Datasheet:
+
+  * Analog Devices MAX20840C
+
+    Prefix: 'max20840c'
+
+    Addresses scanned: -
+
+    Datasheet:
+
 Author:
 
   - Alexis Czezar Torreno <[email protected]>
@@ -21,12 +37,13 @@ Author:
 Description
 -----------
 
-This driver supports hardware monitoring for Analog Devices MAX20830
-Step-Down Switching Regulator with PMBus Interface.
+This driver supports hardware monitoring for Analog Devices MAX20830, MAX20830C
+and MAX20840C. These are Step-Down Switching Regulator with PMBus Interface.
 
-The MAX20830 is a 2.7V to 16V, 30A fully integrated step-down DC-DC switching
-regulator. Through the PMBus interface, the device can monitor input/output
-voltages, output current and temperature.
+MAX20830, and MAX20830C are 2.7V to 16V, 30A fully integrated step-down DC-DC
+switching regulators. MAX20840C is similar but can reach 40A. Through the PMBus
+interface, these devices can monitor input/output voltages, output current and
+temperature.
 
 The driver is a client driver to the core PMBus driver. Please see
 Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
drivers/hwmon/pmbus/Kconfig +2 -2
index ae003a6eac30a7b0a022c5f7f467d8f81736c3f7..5d435e81fc808c42576e5d1733f8a3e1ef32c023 100644
@@ -394,10 +394,10 @@ config SENSORS_MAX20751
 	  be called max20751.
 
 config SENSORS_MAX20830
-	tristate "Analog Devices MAX20830"
+	tristate "Analog Devices MAX20830 and compatibles"
 	help
 	  If you say yes here you get hardware monitoring support for Analog
-	  Devices MAX20830.
+	  Devices MAX20830, MAX20830C, and MAX20840C.
 
 	  This driver can also be built as a module. If so, the module will
 	  be called max20830.
drivers/hwmon/pmbus/max20830.c +23 -13
index ddead72a8db5d6f8491cbfbf356db0f8de64da03..94433deda0113aa7bf0fc2b3f7807553f3014320 100644
@@ -21,6 +21,12 @@ struct max20830_data {
 	u32 vout_rfb2;
 };
 
+static const char * const supported_chip_ids[] = {
+	"MAX20830",
+	"MAX20830C",
+	"MAX20840C",
+};
+
 /*
  * MAX20830 only supports READ_VOUT for VOUT monitoring.
  *
@@ -82,7 +88,7 @@ static int max20830_probe(struct i2c_client *client)
 {
 	u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = {};
 	struct max20830_data *data;
-	int ret;
+	int i, ret;
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -104,13 +110,12 @@ static int max20830_probe(struct i2c_client *client)
 	 * which do not support SMBus block reads.
 	 */
 	if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
-		/* Reads 9 Data bytes from MAX20830 */
 		ret = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, buf);
 		if (ret < 0)
 			return dev_err_probe(&client->dev, ret,
 					     "Failed to read IC_DEVICE_ID\n");
 	} else {
-		/* Reads 1 length byte + 9 Data bytes from MAX20830 */
+		/* Reads 1 length byte + data bytes */
 		ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
 						    MAX20830_IC_DEVICE_ID_LENGTH + 1,
 						    buf);
@@ -126,20 +131,25 @@ static int max20830_probe(struct i2c_client *client)
 		ret = ret - 1;
 	}
 
-	/*
-	 * MAX20830 IC_DEVICE_ID sends string data "MAX20830\0".
-	 * Return value should at least be 9 bytes of data.
-	 */
+	/* Verify we read the expected number of bytes */
 	if (ret < MAX20830_IC_DEVICE_ID_LENGTH)
 		return dev_err_probe(&client->dev, -ENODEV,
-				     "IC_DEVICE_ID too short: expected at least 9 bytes, got %d\n",
-				     ret);
+				     "IC_DEVICE_ID too short: expected %d bytes, got %d\n",
+				     MAX20830_IC_DEVICE_ID_LENGTH, ret);
+
+	/* Null-terminate the string */
+	buf[ret] = '\0';
+
+	/* Verify the device ID matches what we expect */
+	for (i = 0; i < ARRAY_SIZE(supported_chip_ids); i++) {
+		if (!strcmp(buf, supported_chip_ids[i]))
+			break;
+	}
 
-	/* 9 bytes of data, buf[0]-buf[7] = "MAX20830", buf[8] = '\0' */
-	buf[MAX20830_IC_DEVICE_ID_LENGTH - 1] = '\0';
-	if (strncmp(buf, "MAX20830", MAX20830_IC_DEVICE_ID_LENGTH - 1))
+	/* No match found - unsupported device */
+	if (i == ARRAY_SIZE(supported_chip_ids))
 		return dev_err_probe(&client->dev, -ENODEV,
-				     "Unsupported device: '%s'\n", buf);
+				     "Unsupported device: '%*pE'\n", ret, buf);
 
 	return pmbus_do_probe(client, &data->info);
 }
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v5 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch adds support for MAX20830C and MAX20840C devices but fails to add their corresponding…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch adds support for MAX20830C and MAX20840C devices but fails to add their corresponding compatible strings and I2C IDs to the driver's match tables. --

--- Patch [4]: [PATCH v5 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c --- commit f53870a8f52f5aa8dbc791f9a7e148eeab915f24
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830): add support for max20830c and max20840c

Add support for MAX20830C and MAX20840 step-down DC-DC switching regulator with PMBus interface. MAX20830C is a different packaging for MAX20830, and MAX20840C supports 40A regulation compared to MAX20830 that is only 30A.

drivers/hwmon/pmbus/max20830.c struct max20830_data { · line 28

Quoted 13 lines
drivers/hwmon/pmbus/max20830.c +5 -0
index ddead72a8db5d..94433deda0113 100644
@@ -21,6 +21,12 @@ struct max20830_data {
 	u32 vout_rfb2;
 };
 
+static const char * const supported_chip_ids[] = {
+	"MAX20830",
+	"MAX20830C",
+	"MAX20840C",
+};

[Severity: High]
While the new chips are added to the internal string matching list here, does the driver also need to add these to max20830_id and max20830_of_match?

Without the new compatible strings in these tables, won't the devices fail to bind to the driver when instantiated via Device Tree?

For reference, the existing tables at the bottom of the driver only have entries for the original chip:

static const struct i2c_device_id max20830_id[] = {
	{"max20830"},
	{ }
};
static const struct of_device_id max20830_of_match[] = {
	{ .compatible = "adi,max20830" },
	{ }
};
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
maintainer
#13 lore raw

Re: [PATCH v5 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c

Quoted 32 lines · On 7/29/26 18:14, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch adds support for MAX20830C and MAX20840C devices but fails to add their corresponding compatible strings and I2C IDs to the driver's match tables. --

--- Patch [4]: [PATCH v5 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c --- commit f53870a8f52f5aa8dbc791f9a7e148eeab915f24
Author: Alexis Czezar Torreno <[email protected]>

hwmon: (pmbus/max20830): add support for max20830c and max20840c

Add support for MAX20830C and MAX20840 step-down DC-DC switching regulator with PMBus interface. MAX20830C is a different packaging for MAX20830, and MAX20840C supports 40A regulation compared to MAX20830 that is only 30A.

drivers/hwmon/pmbus/max20830.c struct max20830_data { · line 28

Quoted 13 lines
drivers/hwmon/pmbus/max20830.c +5 -0
index ddead72a8db5d..94433deda0113 100644
@@ -21,6 +21,12 @@ struct max20830_data {
  	u32 vout_rfb2;
  };
 
+static const char * const supported_chip_ids[] = {
+	"MAX20830",
+	"MAX20830C",
+	"MAX20840C",
+};

[Severity: High]
While the new chips are added to the internal string matching list here, does the driver also need to add these to max20830_id and max20830_of_match?

Quoted 6 lines

Without the new compatible strings in these tables, won't the devices fail to bind to the driver when instantiated via Device Tree?

For reference, the existing tables at the bottom of the driver only have entries for the original chip:

Sashiko is getting a bit confused. Patch is ok as-is.

Guenter

Quoted 10 lines
static const struct i2c_device_id max20830_id[] = {
	{"max20830"},
	{ }
};
static const struct of_device_id max20830_of_match[] = {
	{ .compatible = "adi,max20830" },
	{ }
};
maintainer Applied
#14 lore raw

Re: [PATCH v5 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c

In reply to Alexis Czezar Torreno
Quoted 6 lines · Alexis Czezar Torreno

Add support for MAX20830C and MAX20840 step-down DC-DC switching regulator with PMBus interface. MAX20830C is a different packaging for MAX20830, and MAX20840C supports 40A regulation compared to MAX20830 that is only 30A.

Applied.

Thanks,
Guenter