Skip to contentSkip to conversation

Add support for MAX20830 PMBUS

PATCH Superseded Alexis Czezar Torreno 4 participants 7 messages Apr 17 – May 1

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alexis Czezar Torreno

author maintainer
#0 lore raw

v3 cover Add support for MAX20830 PMBUS

This series adds support for the Analog Devices MAX20830 step-down switching regulator with PMBus interface.

The MAX20830 provides 2.7V to 16V input, 0.4V to 5.8V output, and up to 30A output current. It supports monitoring of input/output voltage, output current, and temperature via PMBus.

Datasheet: https://www.analog.com/en/products/max20830.html

---
Changes in v3:
- bindings:
- Added pwr-good-gpios property
- driver:
- Zero initialized IC_DEVICE_ID buffer
- added ret < len for validation of actual read bytes
- added comments clarifying block length format and null terminator placement
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- bindings:
- did not add interrupt, smbalert pin does not exist in device.
- added allof with ref to regulator.yaml
- changed additionalprop to unevaluatedprop
- device node name in example changed to regulator
- driver:
- max20830.rst: Added missing in2_alarm
- max20830.c:
- added missing quotes in MODULE_IMPORT_NS
- added comment on why i2c_smbus_read_i2c_block_data is used
- first byte of buffer used as length instead of the return value
- "unsupported device" log now does not print first byte of buffer
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexis Czezar Torreno (2):
dt-bindings: hwmon: pmbus: add max20830
hwmon: (pmbus/max20830) add driver for max20830

 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 66 ++++++++++++++++
 Documentation/hwmon/index.rst                      |  1 +
 Documentation/hwmon/max20830.rst                   | 49 ++++++++++++
 MAINTAINERS                                        |  9 +++
 drivers/hwmon/pmbus/Kconfig                        |  9 +++
 drivers/hwmon/pmbus/Makefile                       |  1 +
 drivers/hwmon/pmbus/max20830.c                     | 88 ++++++++++++++++++++++
 7 files changed, 223 insertions(+)

---
base-commit: fb447217c59a13b2fff22d94de2498c185cd9032
change-id: 20260414-dev_max20830-9460b92cf6aa

Best regards,

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

PATCH v3 1/2 dt-bindings: hwmon: pmbus: add max20830

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

---
 .../bindings/hwmon/pmbus/adi,max20830.yaml         | 66 ++++++++++++++++++++++
 MAINTAINERS                                        |  7 +++
 2 files changed, 73 insertions(+)
Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml new file +66 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1625dd59417f1b3ca689a9c86ca266da913d1217
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/pmbus/adi,max20830.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX20830 Step-Down Switching Regulator with PMBus
+
+maintainers:
+  - Alexis Czezar Torreno <[email protected]>
+
+description: |
+  The MAX20830 is a fully integrated step-down DC-DC switching regulator with
+  PMBus interface. It provides 2.7V to 16V input, 0.4V to 5.8V adjustable
+  output, and up to 30A output current. It allows monitoring of input/output
+  voltage, output current and temperature through the PMBus serial interface.
+  Datasheet:
+    https://www.analog.com/en/products/max20830.html
+
+allOf:
+  - $ref: /schemas/regulator/regulator.yaml#
+
+properties:
+  compatible:
+    const: adi,max20830
+
+  reg:
+    maxItems: 1
+
+  vddh-supply:
+    description:
+      Phandle to the regulator that provides the VDDH power supply.
+
+  avdd-supply:
+    description:
+      Phandle to the regulator that provides the AVDD power supply.
+
+  ldoin-supply:
+    description:
+      Optional 2.5V to 5.5V LDO input supply.
+
+  pwr-good-gpios:
+    description:
+      GPIO connected to the power-good status output pin.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - vddh-supply
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        regulator@30 {
+            compatible = "adi,max20830";
+            reg = <0x30>;
+            vddh-supply = <&vddh>;
+        };
+    };
+...
MAINTAINERS +7 -0
index 0a3991c10ade20dd79cc7d1bf2a1d307ba6bd19d..031c743e979521a92ed9ac67915c178ce31727bd 100644
@@ -15579,6 +15579,13 @@ F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max17616.yaml
 F:	Documentation/hwmon/max17616.rst
 F:	drivers/hwmon/pmbus/max17616.c
 
+MAX20830 HARDWARE MONITOR DRIVER
+M:	Alexis Czezar Torreno <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
 L:	[email protected]
Signature · 1 line
2.34.1
Acked-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: hwmon: pmbus: add max20830

Quoted 4 lines · Alexis Czezar Torreno

Add device tree documentation for MAX20830 step-down DC-DC switching regulator with PMBus interface.

pw-bot: not-applicable

In the future, please relax a bit with new revisions, particularly during the merge window when nothing is gonna get applied and there's no urgency.

author maintainer
#3 lore raw

PATCH v3 2/2 hwmon: (pmbus/max20830) add driver for max20830

In reply to Alexis Czezar Torreno

Add support for MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

---
 Documentation/hwmon/index.rst    |  1 +
 Documentation/hwmon/max20830.rst | 49 ++++++++++++++++++++++
 MAINTAINERS                      |  2 +
 drivers/hwmon/pmbus/Kconfig      |  9 ++++
 drivers/hwmon/pmbus/Makefile     |  1 +
 drivers/hwmon/pmbus/max20830.c   | 88 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 150 insertions(+)
Documentation/hwmon/index.rst +1 -0
index 8b655e5d6b68b90c697a52c7bf526e81d370caf7..56f7eb761be76dd627a2f34135abad05203b0582 100644
@@ -158,6 +158,7 @@ Hardware Monitoring Kernel Drivers
    max197
    max20730
    max20751
+   max20830
    max31722
    max31730
    max31760
Documentation/hwmon/max20830.rst new file +49 -0

49 lines not on this page · raw message

MAINTAINERS +2 -0
index 031c743e979521a92ed9ac67915c178ce31727bd..d6a6745e2dae29c3b8f80bbe61c54a2f5ecd9f47 100644
@@ -15585,6 +15585,8 @@ L:	[email protected]
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/hwmon/pmbus/adi,max20830.yaml
+F:	Documentation/hwmon/max20830.rst
+F:	drivers/hwmon/pmbus/max20830.c
 
 MAX2175 SDR TUNER DRIVER
 M:	Ramesh Shanmugasundaram <[email protected]>
drivers/hwmon/pmbus/Kconfig +9 -0
index 8f4bff375ecbc355f5ed3400855c2852ec2aa5ef..987705bf45b75b7b91ccc469247909f3c3f53d77 100644
@@ -365,6 +365,15 @@ config SENSORS_MAX20751
 	  This driver can also be built as a module. If so, the module will
 	  be called max20751.
 
+config SENSORS_MAX20830
+	tristate "Analog Devices MAX20830"
+	help
+	  If you say yes here you get hardware monitoring support for Analog
+	  Devices MAX20830.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called max20830.
+
 config SENSORS_MAX31785
 	tristate "Maxim MAX31785 and compatibles"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index 7129b62bc00f8a2e98de14004997752a856dfda2..bc52f930e0825a902a0dd1c9e2b44f2e8d577c35 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_SENSORS_MAX16601)	+= max16601.o
 obj-$(CONFIG_SENSORS_MAX17616)	+= max17616.o
 obj-$(CONFIG_SENSORS_MAX20730)	+= max20730.o
 obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
+obj-$(CONFIG_SENSORS_MAX20830)	+= max20830.o
 obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
 obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
 obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
drivers/hwmon/pmbus/max20830.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v3 2/2] hwmon: (pmbus/max20830) add driver for max20830

Sashiko AI review found 3 potential issue(s): - [High] Unconditional requirement of I2C block read breaks support for standard SMBus controllers. - [High] Incorrect parsing of SMBus block read…

Sashiko AI review found 3 potential issue(s):
- [High] Unconditional requirement of I2C block read breaks support for standard SMBus controllers.
- [High] Incorrect parsing of SMBus block read ByteCount leads to probe failure or short-read acceptance.
- [Low] Pointer sign mismatch warning in strncmp().
--

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

hwmon: (pmbus/max20830) add driver for max20830

Adds support for the MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

Quoted 5 lines
drivers/hwmon/pmbus/max20830.c new file +0 -0
new file mode 100644
index 0000000000000..b1c6985067d7c

[ ... ]

drivers/hwmon/pmbus/max20830.c line 33

Quoted 9 lines
drivers/hwmon/pmbus/max20830.c new file +9 -0
+static int max20830_probe(struct i2c_client *client)
+{
+	u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = {};
+	u8 len;
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_I2C_BLOCK))
+		return -ENODEV;

Does unconditionally requiring I2C_FUNC_SMBUS_READ_I2C_BLOCK break compatibility with standard PC/server SMBus controllers (like Intel i801 or AMD piix4)?

These controllers support I2C_FUNC_SMBUS_READ_BLOCK_DATA but may not support arbitrary I2C block reads. Since PMBus is an SMBus-based protocol, should the code prefer standard i2c_smbus_read_block_data() and only fall back to I2C block reads if native SMBus block read functionality is missing?

Quoted 5 lines
drivers/hwmon/pmbus/max20830.c new file +5 -0
+
+	/*
+	 * Use i2c_smbus_read_i2c_block_data() instead of
+	 * i2c_smbus_read_block_data() to support I2C controllers
+	 * which do not support SMBus block reads.

drivers/hwmon/pmbus/max20830.c line 48

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+	 */
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to read IC_DEVICE_ID\n");
+
+	/* First byte is the block length (including itself). */
+	len = buf[0];
+	if (len != 9 || ret < len)

Is this byte count check and length calculation correct? The SMBus specification states that the ByteCount specifies the number of data bytes and does not include itself.

If a spec-compliant device returns a ByteCount of 8 for the 8-character string MAX20830, won't the len != 9 check incorrectly abort with -ENODEV?

Additionally, does ret < len correctly validate the read size? If ret is 9 (1 length byte + 8 data bytes), the check ret < len (9 < 9) evaluates to false, passing the check. However, a ByteCount of 9 means 9 data bytes were intended (10 total bytes).

Should this validation check be ret < len + 1 instead to avoid silently overwriting a missing 9th data byte?

drivers/hwmon/pmbus/max20830.c line 55

Quoted 7 lines
drivers/hwmon/pmbus/max20830.c new file +7 -0
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "IC_DEVICE_ID length mismatch: reported %u, read %d\n",
+				     len, ret);
+
+	/* Data is at buf[1..8], so null terminator goes at buf[9]. */
+	buf[len] = '\0';
+	if (strncmp(buf + 1, "MAX20830", 8))

This isn't a bug, but buf is defined as a u8 array and strncmp() expects a const char pointer. Does this trigger a -Wpointer-sign compiler warning?

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

Re: [PATCH v3 2/2] hwmon: (pmbus/max20830) add driver for max20830

In reply to Alexis Czezar Torreno

,

Quoted 6 lines · Alexis Czezar Torreno

Add support for MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

---

...

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+
+	/*
+	 * Use i2c_smbus_read_i2c_block_data() instead of
+	 * i2c_smbus_read_block_data() to support I2C controllers
+	 * which do not support SMBus block reads.
+	 */
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,

drivers/hwmon/pmbus/max20830.c line 53

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+				     "Failed to read IC_DEVICE_ID\n");
+
+	/* First byte is the block length (including itself). */
+	len = buf[0];
+	if (len != 9 || ret < len)
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "IC_DEVICE_ID length mismatch: reported %u, read %d\n",
+				     len, ret);
+
+	/* Data is at buf[1..8], so null terminator goes at buf[9]. */

I ended up checking the kernel code. As it turns out, i2c_smbus_read_i2c_block_data does _not_ return the length in byte 0. It returns the first byte of the actual data, and the length as return value. See i2c_smbus_read_i2c_block_data() in drivers/i2c/i2c-core-smbus.c.

So this can not work as written. Something like

        if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BLOCK_DATA))
                ret = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, data_buf);
        else
                ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
						    I2C_SMBUS_BLOCK_MAX, buf);

should do, assuming that support for I2C_FUNC_SMBUS_BLOCK_DATA and/or I2C_FUNC_SMBUS_READ_I2C_BLOCK was checked before.

Thanks,
Guenter

author maintainer
#6 lore raw

RE: [PATCH v3 2/2] hwmon: (pmbus/max20830) add driver for max20830

Quoted 47 lines · Alexis Czezar Torreno
Quoted 6 lines

Add support for MAX20830 step-down DC-DC switching regulator with PMBus interface. It allows monitoring of input/output voltage, output current and temperature through the PMBus serial interface.

---

...

Quoted 7 lines
drivers/hwmon/pmbus/max20830.c new file +7 -0
+
+	/*
+	 * Use i2c_smbus_read_i2c_block_data() instead of
+	 * i2c_smbus_read_block_data() to support I2C controllers
+	 * which do not support SMBus block reads.
+	 */
+	ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,

drivers/hwmon/pmbus/max20830.c

Quoted 10 lines
drivers/hwmon/pmbus/max20830.c new file +10 -0
+					    I2C_SMBUS_BLOCK_MAX, buf);
+	if (ret < 0)
+		return dev_err_probe(&client->dev, ret,
+				     "Failed to read IC_DEVICE_ID\n");
+
+	/* First byte is the block length (including itself). */
+	len = buf[0];
+	if (len != 9 || ret < len)
+		return dev_err_probe(&client->dev, -ENODEV,
+				     "IC_DEVICE_ID length mismatch: reported

%u, read %d\n",

drivers/hwmon/pmbus/max20830.c line 53

Quoted 3 lines
drivers/hwmon/pmbus/max20830.c new file +3 -0
+				     len, ret);
+
+	/* Data is at buf[1..8], so null terminator goes at buf[9]. */

I ended up checking the kernel code. As it turns out, i2c_smbus_read_i2c_block_data does _not_ return the length in byte 0. It returns the first byte of the actual data, and the length as return value. See i2c_smbus_read_i2c_block_data() in drivers/i2c/i2c-core-smbus.c.

So this can not work as written. Something like

        if (i2c_check_functionality(client->adapter,

I2C_FUNC_SMBUS_BLOCK_DATA))
ret = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID,
data_buf);
else
ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
I2C_SMBUS_BLOCK_MAX,
buf);

Quoted 3 lines

should do, assuming that support for I2C_FUNC_SMBUS_BLOCK_DATA and/or I2C_FUNC_SMBUS_READ_I2C_BLOCK was checked before.

Oh, ok will check this difference out. Thanks