Skip to contentSkip to conversation

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

PATCH Superseded Alexis Czezar Torreno 4 participants 24 messages Jul 6 – Jul 20

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Alexis Czezar Torreno

author maintainer
#0 lore raw

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

Patch 1 adds an enable gpio property that should have been included before.

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

Patches 4 and 5 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 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 (5):
dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples
dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties
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         | 36 +++++++++-
 Documentation/hwmon/max20830.rst                   | 27 ++++++--
 drivers/hwmon/pmbus/max20830.c                     | 81 ++++++++++++++++++----
 3 files changed, 124 insertions(+), 20 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 v2 1/5 dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +11 -0
index 1625dd59417f1b3ca689a9c86ca266da913d1217..f3ba6351aa5d657590d92a538910fd6b787e7a3a 100644
@@ -39,6 +39,11 @@ properties:
     description:
       Optional 2.5V to 5.5V LDO input supply.
 
+  enable-gpios:
+    description:
+      GPIO connected to the EN (enable) pin.
+    maxItems: 1
+
   pwr-good-gpios:
     description:
       GPIO connected to the power-good status output pin.
@@ -53,6 +58,8 @@ unevaluatedProperties: false
 
 examples:
   - |
+    #include <dt-bindings/gpio/gpio.h>
+
     i2c {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -61,6 +68,10 @@ examples:
             compatible = "adi,max20830";
             reg = <0x30>;
             vddh-supply = <&vddh>;
+            avdd-supply = <&avdd>;
+            ldoin-supply = <&ldoin>;
+            enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+            pwr-good-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
         };
     };
 ...
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

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

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

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
#3 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

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

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)

How did you address previous feedback?

Best regards,
Krzysztof

author maintainer
#4 lore raw

RE: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Quoted 14 lines · Alexis Czezar Torreno
Quoted 6 lines

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11

+++++++++++

Quoted 2 lines
 1 file changed, 11 insertions(+)

How did you address previous feedback?

Regarding the enable pin, I added this since I know bindings like being complete and saw that I didn't add it the first time I submitted max20830.
I added driver code for the gpio but learned that it wasn't really a use case so I simply dropped the patch for it.

I only added a few words in the commit description and added more entries in the example for v2 this patch.

Regards,
Alexis

maintainer
#5 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Quoted 12 lines · Alexis Czezar
Quoted 12 lines · Alexis Czezar Torreno
Quoted 6 lines

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
  .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11

+++++++++++

Quoted 2 lines
  1 file changed, 11 insertions(+)
Quoted 8 lines
Quoted 2 lines

How did you address previous feedback?

Regarding the enable pin, I added this since I know bindings like being complete and saw that I didn't add it the first time I submitted max20830.
I added driver code for the gpio but learned that it wasn't really a use case so I simply dropped the patch for it.

I guess I am completely missing the point here. I can not imagine a situation where one would want to connect the enable pin to a driver-controlled GPIO pin, or why would one connect the chip's PGOOD output pin to a GPIO input pin and connect that back to the driver.

I think we will need guidance from devicetree maintainers explaining what "complete" means in such a context to avoid having to repeat this discussion for every driver going forward.

Thanks,
Guenter

#6 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Quoted 22 lines · Guenter Roeck
Quoted 12 lines · Alexis Czezar
Quoted 12 lines · Alexis Czezar Torreno
Quoted 6 lines

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
  .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11

+++++++++++

Quoted 2 lines
  1 file changed, 11 insertions(+)
Quoted 8 lines
Quoted 2 lines

How did you address previous feedback?

Regarding the enable pin, I added this since I know bindings like being complete and saw that I didn't add it the first time I submitted max20830.
I added driver code for the gpio but learned that it wasn't really a use case so I simply dropped the patch for it.

Quoted 8 lines

I guess I am completely missing the point here. I can not imagine a situation where one would want to connect the enable pin to a driver-controlled GPIO pin, or why would one connect the chip's PGOOD output pin to a GPIO input pin and connect that back to the driver.

I think we will need guidance from devicetree maintainers explaining what "complete" means in such a context to avoid having to repeat this discussion for every driver going forward.

I think complete means all reasonable hardware resources/properties, regardless whether current OS implementation uses them or not. That's why if there is enable-gpios which is not used by Linux but could be in the future, then it should be documented.

However if you claim that enable-gpios will absolutely NEVER be used by Linux or bootloader or any other DT bindings user (*BSD, Barebox, U-boot etc), then I would skip it, just like we do not describe many other parts which simply have no use for the software.

IOW, DTS is description of non-discoverable hardware for the software. We do not describe hardware for the sake of description, to mirror schematics. That's not the goal. The goal is to make some software happy, even if this is a future software implementation.

What is the case here - I rely on your guidance whether enable-gpios can EVER be used by software. If there is a chance, then IMO property could stay.

Also, no harm will be done if we skip this property and we add it later in the future when actual use appears. Maybe no need to spend time on discussing such triviality and instead just skip it.

Best regards,
Krzysztof

maintainer
#7 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Quoted 42 lines · Krzysztof Kozlowski
Quoted 22 lines · Guenter Roeck
Quoted 12 lines · Alexis Czezar
Quoted 12 lines · Alexis Czezar Torreno
Quoted 6 lines

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
   .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11

+++++++++++

Quoted 2 lines
   1 file changed, 11 insertions(+)
Quoted 8 lines
Quoted 2 lines

How did you address previous feedback?

Regarding the enable pin, I added this since I know bindings like being complete and saw that I didn't add it the first time I submitted max20830.
I added driver code for the gpio but learned that it wasn't really a use case so I simply dropped the patch for it.

Quoted 8 lines

I guess I am completely missing the point here. I can not imagine a situation where one would want to connect the enable pin to a driver-controlled GPIO pin, or why would one connect the chip's PGOOD output pin to a GPIO input pin and connect that back to the driver.

I think we will need guidance from devicetree maintainers explaining what "complete" means in such a context to avoid having to repeat this discussion for every driver going forward.

I think complete means all reasonable hardware resources/properties, regardless whether current OS implementation uses them or not. That's why if there is enable-gpios which is not used by Linux but could be in the future, then it should be documented.

However if you claim that enable-gpios will absolutely NEVER be used by Linux or bootloader or any other DT bindings user (*BSD, Barebox, U-boot etc), then I would skip it, just like we do not describe many other parts which simply have no use for the software.

Quoted 9 lines

IOW, DTS is description of non-discoverable hardware for the software. We do not describe hardware for the sake of description, to mirror schematics. That's not the goal. The goal is to make some software happy, even if this is a future software implementation.

What is the case here - I rely on your guidance whether enable-gpios can EVER be used by software. If there is a chance, then IMO property could stay.

Unfortunately, as it turns out, some of the chips handled by this driver do _not_ implement software-override for the enable pin (or at least so I am told; the chip datasheets are not public). Given that, we will have to support the enable pin property.

Sorry, I was not aware of this detail.

Guenter

author maintainer
#8 lore raw

RE: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

Quoted 40 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

How did you address previous feedback?

Regarding the enable pin, I added this since I know bindings like being complete and saw that I didn't add it the first time I submitted

max20830.

Quoted 23 lines
Quoted 4 lines
Quoted 3 lines

I added driver code for the gpio but learned that it wasn't really a use case so I simply dropped the patch for it.

Quoted 8 lines

I guess I am completely missing the point here. I can not imagine a situation where one would want to connect the enable pin to a driver-controlled GPIO pin, or why would one connect the chip's PGOOD output pin to a GPIO input pin and connect that back to the driver.

I think we will need guidance from devicetree maintainers explaining what "complete" means in such a context to avoid having to repeat this discussion for every driver going forward.

I think complete means all reasonable hardware resources/properties, regardless whether current OS implementation uses them or not. That's why if there is enable-gpios which is not used by Linux but could be in the future, then it should be documented.

However if you claim that enable-gpios will absolutely NEVER be used by Linux or bootloader or any other DT bindings user (*BSD, Barebox, U-boot etc), then I would skip it, just like we do not describe many other parts which simply have no use for the software.

Quoted 9 lines

IOW, DTS is description of non-discoverable hardware for the software. We do not describe hardware for the sake of description, to mirror schematics. That's not the goal. The goal is to make some software happy, even if this is a future software implementation.

What is the case here - I rely on your guidance whether enable-gpios can EVER be used by software. If there is a chance, then IMO property could stay.

Quoted 7 lines

Unfortunately, as it turns out, some of the chips handled by this driver do _not_ implement software-override for the enable pin (or at least so I am told; the chip datasheets are not public). Given that, we will have to support the enable pin property.

Sorry, I was not aware of this detail.

Just to straighten possible mix up of parts/submissions (sad they all start with 'max20')

The parts that have no software override for the enable pin are MAX20912, MAX20916 and other chips that we would be submitting with it (as the original submitter deferred to us to submit our series instead + the datasheet)

This series deal with MAX20830, and MAX20830C/MAX20840C.
In relation to the discussion above about the enable-gpio and "completeness", the parts here don't have anything special to their enables.
With the clarification that the DTS goal isn't just to describe for the sake of mirroring schematics, then this patch I believe can be dropped as well.

Can drop in v3 after the other patches gets reviewed.

Thanks again for the clarification!,
Alexis

maintainer
#9 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

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

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

I still do not see the point of these properties. The driver can extract the power good information from its registers, and it can set the enable value from there as well. It does not need either.
In practice the power good output is likely to be connected to an LED or to the enable pin of another power controller. Neither would need devicetree properties.

Again, please provide a use case. The mere presence of these pins (which exist on pretty much all PMBus chips) does not warrant devicetree properties for them.

Thanks,
Guenter

Quoted 40 lines
---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +11 -0
index 1625dd59417f1b3ca689a9c86ca266da913d1217..f3ba6351aa5d657590d92a538910fd6b787e7a3a 100644
@@ -39,6 +39,11 @@ properties:
     description:
       Optional 2.5V to 5.5V LDO input supply.
 
+  enable-gpios:
+    description:
+      GPIO connected to the EN (enable) pin.
+    maxItems: 1
+
   pwr-good-gpios:
     description:
       GPIO connected to the power-good status output pin.
@@ -53,6 +58,8 @@ unevaluatedProperties: false
 
 examples:
   - |
+    #include <dt-bindings/gpio/gpio.h>
+
     i2c {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -61,6 +68,10 @@ examples:
             compatible = "adi,max20830";
             reg = <0x30>;
             vddh-supply = <&vddh>;
+            avdd-supply = <&avdd>;
+            ldoin-supply = <&ldoin>;
+            enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
+            pwr-good-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
         };
     };
...
Reviewed-by on v2 1/5
#10 lore raw

Re: [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples

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

Adding an entry for the MAX20830 EN (enable) pin. This pin exist but was not included before. Also edited examples entry to be more complete.

---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml         | 11 +++++++++++
 1 file changed, 11 insertions(+)

Best regards,
Krzysztof

author maintainer
#11 lore raw

PATCH v2 2/5 dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties

In reply to 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.

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.

---
 .../devicetree/bindings/hwmon/pmbus/adi,max20830.yaml   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml +17 -0
index f3ba6351aa5d657590d92a538910fd6b787e7a3a..3d62c03abdc30c8aada303bad263e972219b33a4 100644
@@ -49,11 +49,26 @@ 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:
@@ -72,6 +87,8 @@ examples:
             ldoin-supply = <&ldoin>;
             enable-gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
             pwr-good-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
+            adi,vout-rfb1-ohms = <10000>;
+            adi,vout-rfb2-ohms = <2000>;
         };
     };
 ...
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v2 2/5] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 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.

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.

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=2
author maintainer
#13 lore raw

PATCH v2 3/5 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 | 54 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/max20830.c +53 -1
index cb2c23672166d641852199ca07eb716924f4f286..5aad4448054fc55bb0a87920d89f96bc28fda072 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,45 @@
 
 #define MAX20830_IC_DEVICE_ID_LENGTH	9
 
+struct max20830_data {
+	struct pmbus_driver_info info;
+	u32 vout_rfb1;
+	u32 vout_rfb2;
+};
+
+/*
+ * Driver currently only supports READ_VOUT for monitoring that needs scaling to
+ * convert from feedback voltage to actual output voltage.
+ *
+ * vout_actual = vout_fb × (1 + RFB1/RFB2)
+ *
+ * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with feedback
+ * voltage. If regulator support is added, VOUT_COMMAND values would need
+ * to be adjusted accordingly.
+ */
+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;
+
+	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)
+			ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data->vout_rfb1 +
+						    data->vout_rfb2), data->vout_rfb2);
+		return ret;
+	default:
+		return -ENODATA;
+	}
+}
+
 static struct pmbus_driver_info max20830_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +64,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 +130,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
#14 lore raw

Re: [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Scaled `PMBUS_READ_VOUT` value can exceed the 16-bit capacity of the PMBus `LINEAR16` format…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Scaled PMBUS_READ_VOUT value can exceed the 16-bit capacity of the PMBus LINEAR16 format, causing silent truncation and incorrect voltage reporting.
- [High] Missing software scaling for VOUT limit attributes and missing .write_word_data callback causes hardware limits to be programmed completely out of bounds. --

commit 19e6041d100f0e80c9e49784d17900b141e3ea61
Author: Alexis Czezar Torreno <[email protected]>

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

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
drivers/hwmon/pmbus/max20830.c +0 -0
index cb2c23672166d..5aad4448054fc 100644

[ ... ]

Quoted 28 lines
drivers/hwmon/pmbus/max20830.c +24 -0
@@ -14,6 +15,45 @@
 
 #define MAX20830_IC_DEVICE_ID_LENGTH	9
 
+struct max20830_data {
+	struct pmbus_driver_info info;
+	u32 vout_rfb1;
+	u32 vout_rfb2;
+};
+
+/*
+ * Driver currently only supports READ_VOUT for monitoring that needs scaling to
+ * convert from feedback voltage to actual output voltage.
+ *
+ * vout_actual = vout_fb × (1 + RFB1/RFB2)
+ *
+ * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with feedback
+ * voltage. If regulator support is added, VOUT_COMMAND values would need
+ * to be adjusted accordingly.
+ */
+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;
+
+	switch (reg) {

drivers/hwmon/pmbus/max20830.c line 51

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+	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)
+			ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data->vout_rfb1 +
+						    data->vout_rfb2), data->vout_rfb2);
+		return ret;

[Severity: High]
Does this returned value need bounds checking?

If a large resistor divider is used, the scaled PMBus word calculated here can exceed 0xFFFF. The generic PMBus core function pmbus_reg2data_linear() will cast this returned value to a u16, silently wrapping the value modulo 65536 and resulting in wildly incorrect telemetry (e.g., reporting 2V instead of 12V).

Should this be clamped using clamp_val(ret, 0, 0xffff)?

drivers/hwmon/pmbus/max20830.c line 55

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

[Severity: High]
Will returning -ENODATA bypass software scaling for VOUT limit attributes?

The driver sets PMBUS_HAVE_VOUT below, which exposes hardware VOUT limits (like inX_max or inX_lcrit). Because only PMBUS_READ_VOUT is intercepted here, the core will read those limits unscaled from the hardware.

drivers/hwmon/pmbus/max20830.c static struct pmbus_driver_info max20830_info = { · line 67

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +2 -0
+
 static struct pmbus_driver_info max20830_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +64,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,

[Severity: High]
Does this struct also need a .write_word_data callback?

Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall through to the PMBus core, which writes the scaled PMBus word directly into the hardware's limit register. Because the hardware expects limits in the unscaled feedback voltage range, the written value will be completely out of bounds.

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

Re: [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Quoted 5 lines · On 7/5/26 19:21, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Scaled PMBUS_READ_VOUT value can exceed the 16-bit capacity of the PMBus LINEAR16 format, causing silent truncation and incorrect voltage reporting.
- [High] Missing software scaling for VOUT limit attributes and missing .write_word_data callback causes hardware limits to be programmed completely out of bounds. --

Please comment on Sashiko's findings and either fix or explain in comments why the issues do not apply.

Thanks,
Guenter

Quoted 101 lines

commit 19e6041d100f0e80c9e49784d17900b141e3ea61
Author: Alexis Czezar Torreno <[email protected]>

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

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
drivers/hwmon/pmbus/max20830.c +0 -0
index cb2c23672166d..5aad4448054fc 100644

[ ... ]

Quoted 28 lines
drivers/hwmon/pmbus/max20830.c +24 -0
@@ -14,6 +15,45 @@
 
  #define MAX20830_IC_DEVICE_ID_LENGTH	9
 
+struct max20830_data {
+	struct pmbus_driver_info info;
+	u32 vout_rfb1;
+	u32 vout_rfb2;
+};
+
+/*
+ * Driver currently only supports READ_VOUT for monitoring that needs scaling to
+ * convert from feedback voltage to actual output voltage.
+ *
+ * vout_actual = vout_fb × (1 + RFB1/RFB2)
+ *
+ * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with feedback
+ * voltage. If regulator support is added, VOUT_COMMAND values would need
+ * to be adjusted accordingly.
+ */
+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;
+
+	switch (reg) {

drivers/hwmon/pmbus/max20830.c line 51

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+	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)
+			ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data->vout_rfb1 +
+						    data->vout_rfb2), data->vout_rfb2);
+		return ret;

[Severity: High]
Does this returned value need bounds checking?

If a large resistor divider is used, the scaled PMBus word calculated here can exceed 0xFFFF. The generic PMBus core function pmbus_reg2data_linear() will cast this returned value to a u16, silently wrapping the value modulo 65536 and resulting in wildly incorrect telemetry (e.g., reporting 2V instead of 12V).

Should this be clamped using clamp_val(ret, 0, 0xffff)?

drivers/hwmon/pmbus/max20830.c line 55

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

[Severity: High]
Will returning -ENODATA bypass software scaling for VOUT limit attributes?

The driver sets PMBUS_HAVE_VOUT below, which exposes hardware VOUT limits (like inX_max or inX_lcrit). Because only PMBUS_READ_VOUT is intercepted here, the core will read those limits unscaled from the hardware.

drivers/hwmon/pmbus/max20830.c static struct pmbus_driver_info max20830_info = { · line 67

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +2 -0
+
  static struct pmbus_driver_info max20830_info = {
  	.pages = 1,
  	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +64,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,

[Severity: High]
Does this struct also need a .write_word_data callback?

Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall through to the PMBus core, which writes the scaled PMBus word directly into the hardware's limit register. Because the hardware expects limits in the unscaled feedback voltage range, the written value will be completely out of bounds.

author maintainer
#16 lore raw

RE: [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

In reply to [email protected]
Quoted 39 lines
Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +9 -0
+
+/*
+ * Driver currently only supports READ_VOUT for monitoring that needs
+scaling to
+ * convert from feedback voltage to actual output voltage.
+ *
+ * vout_actual = vout_fb × (1 + RFB1/RFB2)
+ *
+ * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with

drivers/hwmon/pmbus/max20830.c

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+feedback
+ * voltage. If regulator support is added, VOUT_COMMAND values would
+need
+ * to be adjusted accordingly.
+ */
+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);

Quoted 14 lines
drivers/hwmon/pmbus/max20830.c +11 -0
+	int ret;
+
+	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)
+			ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data-

vout_rfb1 +

(quoted diff) +1 -0
+						    data->vout_rfb2), data-

vout_rfb2);

Review

Quoted 1 line
(quoted diff) +1 -0
+		return ret;

[Severity: High]
Does this returned value need bounds checking?

Quoted 8 lines

If a large resistor divider is used, the scaled PMBus word calculated here can exceed 0xFFFF. The generic PMBus core function pmbus_reg2data_linear() will cast this returned value to a u16, silently wrapping the value modulo 65536 and resulting in wildly incorrect telemetry (e.g., reporting 2V instead of 12V).

Should this be clamped using clamp_val(ret, 0, 0xffff)?

Good Call, will clamp this as suggested.

Quoted 8 lines

drivers/hwmon/pmbus/max20830.c line 55

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

[Severity: High]
Will returning -ENODATA bypass software scaling for VOUT limit attributes?

Quoted 4 lines

The driver sets PMBUS_HAVE_VOUT below, which exposes hardware VOUT limits (like inX_max or inX_lcrit). Because only PMBUS_READ_VOUT is intercepted here, the core will read those limits unscaled from the hardware.

Not applicable - no limit registers exist or are exposed.

Quoted 13 lines

drivers/hwmon/pmbus/max20830.c static struct pmbus_driver_info max20830_info = { · line 67

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +2 -0
+
 static struct pmbus_driver_info max20830_info = {
 	.pages = 1,
 	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +64,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,

[Severity: High]
Does this struct also need a .write_word_data callback?

Quoted 6 lines

Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall through to the PMBus core, which writes the scaled PMBus word directly into the hardware's limit register. Because the hardware expects limits in the unscaled feedback voltage range, the written value will be completely out of bounds.

Not applicable. No writable VOUT registers are exposed. MAX20830 has no limit registers to write to. also regulator support is not implemented.

Quoted 7 lines

--
Sashiko AI review ·
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20260706-dev-
max20830c-v2-0- [email protected]?part=3__;Iw!!A3Ni8CS0y2Y!9BBLoE4ditcREIvsDD7 _VDDKjsS7XgrV0udXIgvBZeCRChzDWWsu7TY8ybr5VBPG4VQlLnDS6EQmu6fhfLx CpKUl28ZSE04$

maintainer
#17 lore raw

Re: [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Quoted 85 lines · Alexis Czezar
Quoted 39 lines
Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +9 -0
+
+/*
+ * Driver currently only supports READ_VOUT for monitoring that needs
+scaling to
+ * convert from feedback voltage to actual output voltage.
+ *
+ * vout_actual = vout_fb × (1 + RFB1/RFB2)
+ *
+ * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with

drivers/hwmon/pmbus/max20830.c

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c +10 -0
+feedback
+ * voltage. If regulator support is added, VOUT_COMMAND values would
+need
+ * to be adjusted accordingly.
+ */
+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);

Quoted 14 lines
drivers/hwmon/pmbus/max20830.c +11 -0
+	int ret;
+
+	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)
+			ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data-

vout_rfb1 +

(quoted diff) +1 -0
+						    data->vout_rfb2), data-

vout_rfb2);

Review

Quoted 1 line
(quoted diff) +1 -0
+		return ret;

[Severity: High]
Does this returned value need bounds checking?

Quoted 8 lines

If a large resistor divider is used, the scaled PMBus word calculated here can exceed 0xFFFF. The generic PMBus core function pmbus_reg2data_linear() will cast this returned value to a u16, silently wrapping the value modulo 65536 and resulting in wildly incorrect telemetry (e.g., reporting 2V instead of 12V).

Should this be clamped using clamp_val(ret, 0, 0xffff)?

Good Call, will clamp this as suggested.

Quoted 8 lines

drivers/hwmon/pmbus/max20830.c line 55

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

[Severity: High]
Will returning -ENODATA bypass software scaling for VOUT limit attributes?

Quoted 4 lines

The driver sets PMBUS_HAVE_VOUT below, which exposes hardware VOUT limits (like inX_max or inX_lcrit). Because only PMBUS_READ_VOUT is intercepted here, the core will read those limits unscaled from the hardware.

Not applicable - no limit registers exist or are exposed.

Quoted 13 lines

drivers/hwmon/pmbus/max20830.c static struct pmbus_driver_info max20830_info = { · line 67

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c +2 -0
+
  static struct pmbus_driver_info max20830_info = {
  	.pages = 1,
  	.format[PSC_VOLTAGE_IN] = linear,
@@ -24,13 +64,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,

[Severity: High]
Does this struct also need a .write_word_data callback?

Quoted 6 lines

Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall through to the PMBus core, which writes the scaled PMBus word directly into the hardware's limit register. Because the hardware expects limits in the unscaled feedback voltage range, the written value will be completely out of bounds.

Quoted 3 lines

Not applicable. No writable VOUT registers are exposed. MAX20830 has no limit registers to write to. also regulator support is not implemented.

Please add a comment to the code explaining this (if you dod not do that already), to remind patch authors that there is additional work to do if regulator support is added.

Thanks,
Guenter

Quoted 7 lines
Quoted 7 lines

--
Sashiko AI review ·
https://urldefense.com/v3/__https://sashiko.dev/*/patchset/20260706-dev-
max20830c-v2-0- [email protected]?part=3__;Iw!!A3Ni8CS0y2Y!9BBLoE4ditcREIvsDD7 _VDDKjsS7XgrV0udXIgvBZeCRChzDWWsu7TY8ybr5VBPG4VQlLnDS6EQmu6fhfLx CpKUl28ZSE04$

author maintainer
#18 lore raw

RE: [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines

drivers/hwmon/pmbus/max20830.c static struct pmbus_driver_info max20830_info = { · line 67

Quoted 10 lines

+
static struct pmbus_driver_info max20830_info = {
.pages = 1,
.format[PSC_VOLTAGE_IN] = linear, @@ -24,13 +64,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,

drivers/hwmon/pmbus/max20830.c +1 -0
+	.read_word_data = max20830_read_word_data,

[Severity: High]
Does this struct also need a .write_word_data callback?

Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall through to the PMBus core, which writes the scaled PMBus word directly into the hardware's limit register. Because the hardware expects limits in the unscaled feedback voltage range, the written value will be completely out of bounds.

Quoted 8 lines
Quoted 3 lines

Not applicable. No writable VOUT registers are exposed. MAX20830 has no limit registers to write to. also regulator support is not implemented.

Please add a comment to the code explaining this (if you dod not do that already), to remind patch authors that there is additional work to do if regulator support is added.

Already added but will further clarify the comments I wrote.

Regards,
Alexis

author maintainer
#19 lore raw

PATCH v2 4/5 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 3d62c03abdc30c8aada303bad263e972219b33a4..826be4d818908becc1e185e640a3b684c6df004c 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
#20 lore raw

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

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

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.

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=4
author maintainer
#22 lore raw

PATCH v2 5/5 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/max20830.c   | 27 ++++++++++++++-------------
 2 files changed, 36 insertions(+), 18 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/max20830.c +14 -13
index 5aad4448054fc55bb0a87920d89f96bc28fda072..88fc45447792b1fea7691dee9fb385238c5d82c1 100644
@@ -93,13 +93,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);
@@ -115,26 +114,28 @@ 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';
 
-	/* 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))
+	/* Verify the device ID matches what we expect */
+	if ((strcmp(buf, "MAX20830") && strcmp(buf, "MAX20830C") &&
+	    strcmp(buf, "MAX20840C")))
 		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);
 }
 
 static const struct i2c_device_id max20830_id[] = {
-	{"max20830"},
+	{ "max20830" },
+	{ "max20830c" },
+	{ "max20840c" },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, max20830_id);
Signature · 1 line
2.34.1
#23 lore raw

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

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

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.

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=5