Linux Documentation
 help / color / mirror / Atom feed
From: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
To: Guenter Roeck <linux@roeck-us.net>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>
Cc: <linux-hwmon@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
	Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
Subject: [PATCH 6/6] hwmon: (pmbus/max20830): add support for max20830c and max20840c
Date: Tue, 30 Jun 2026 10:46:48 +0800	[thread overview]
Message-ID: <20260630-dev-max20830c-v1-6-a02786bde470@analog.com> (raw)
In-Reply-To: <20260630-dev-max20830c-v1-0-a02786bde470@analog.com>

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.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
---
 Documentation/hwmon/max20830.rst | 27 +++++++++++++---
 drivers/hwmon/pmbus/max20830.c   | 68 ++++++++++++++++++++++++++++------------
 2 files changed, 70 insertions(+), 25 deletions(-)

diff --git a/Documentation/hwmon/max20830.rst b/Documentation/hwmon/max20830.rst
index 936e409dcc5c0898dde27d782308d4a7e1357e73..b850f3b6e40d1f1d0cec944be40af02265aced59 100644
--- a/Documentation/hwmon/max20830.rst
+++ b/Documentation/hwmon/max20830.rst
@@ -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 <alexisczezar.torreno@analog.com>
@@ -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.
diff --git a/drivers/hwmon/pmbus/max20830.c b/drivers/hwmon/pmbus/max20830.c
index a3abd24437e8e7560264aad55fc4f456d30ae235..252c77beb243c5a2d90fcf96941605ff31439383 100644
--- a/drivers/hwmon/pmbus/max20830.c
+++ b/drivers/hwmon/pmbus/max20830.c
@@ -14,7 +14,30 @@
 #include <linux/string.h>
 #include "pmbus.h"
 
-#define MAX20830_IC_DEVICE_ID_LENGTH	9
+struct max20830_chip_info {
+	const char *id_str;
+	u8 id_length;
+};
+
+static const struct max20830_chip_info max20830_chip = {
+	/*
+	 * MAX20830 IC_DEVICE_ID has a byte length of 9 despite being an 8
+	 * character string, as it includes a null terminator. The other
+	 * devices do not include null.
+	 */
+	.id_str = "MAX20830\0",
+	.id_length = 9,
+};
+
+static const struct max20830_chip_info max20830c_chip = {
+	.id_str = "MAX20830C",
+	.id_length = 9,
+};
+
+static const struct max20830_chip_info max20840c_chip = {
+	.id_str = "MAX20840C",
+	.id_length = 9,
+};
 
 struct max20830_data {
 	struct pmbus_driver_info info;
@@ -60,11 +83,14 @@ static struct pmbus_driver_info max20830_info = {
 
 static int max20830_probe(struct i2c_client *client)
 {
+	const struct max20830_chip_info *chip;
 	u8 buf[I2C_SMBUS_BLOCK_MAX + 1] = {};
 	struct max20830_data *data;
 	struct gpio_desc *enable_gpio;
 	int ret;
 
+	chip = i2c_get_match_data(client);
+
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
@@ -90,16 +116,14 @@ 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);
+						    chip->id_length + 1, buf);
 		if (ret < 0)
 			return dev_err_probe(&client->dev, ret,
 					     "Failed to read IC_DEVICE_ID\n");
@@ -108,36 +132,40 @@ static int max20830_probe(struct i2c_client *client)
 		 * match the format of i2c_smbus_read_block_data().
 		 * Also adjust return value to reflect length byte removal.
 		 */
-		memmove(buf, buf + 1, MAX20830_IC_DEVICE_ID_LENGTH);
+		memmove(buf, buf + 1, chip->id_length);
 		ret = ret - 1;
 	}
 
-	/*
-	 * MAX20830 IC_DEVICE_ID sends string data "MAX20830\0".
-	 * Return value should at least be 9 bytes of data.
-	 */
-	if (ret < MAX20830_IC_DEVICE_ID_LENGTH)
+	/* Verify we read the expected number of bytes */
+	if (ret < chip->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",
+				     chip->id_length, ret);
+
+	/* Null-terminate the string */
+	buf[chip->id_length] = '\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 (strncmp(buf, chip->id_str, chip->id_length))
 		return dev_err_probe(&client->dev, -ENODEV,
-				     "Unsupported device: '%s'\n", buf);
+				     "Device mismatch: expected '%s', got '%s'\n",
+				     chip->id_str, buf);
 
-	return pmbus_do_probe(client, &max20830_info);
+	return pmbus_do_probe(client, &data->info);
 }
 
 static const struct i2c_device_id max20830_id[] = {
-	{"max20830"},
+	{ "max20830", (kernel_ulong_t)&max20830_chip },
+	{ "max20830c", (kernel_ulong_t)&max20830c_chip },
+	{ "max20840c", (kernel_ulong_t)&max20840c_chip },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, max20830_id);
 
 static const struct of_device_id max20830_of_match[] = {
-	{ .compatible = "adi,max20830" },
+	{ .compatible = "adi,max20830", .data = &max20830_chip },
+	{ .compatible = "adi,max20830c", .data = &max20830c_chip },
+	{ .compatible = "adi,max20840c", .data = &max20840c_chip },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, max20830_of_match);

-- 
2.34.1


  parent reply	other threads:[~2026-06-30  2:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  2:46 [PATCH 0/6] Add support for MAX20830C and MAX20840C step-down DC-DC switching regulator Alexis Czezar Torreno
2026-06-30  2:46 ` [PATCH 1/6] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property Alexis Czezar Torreno
2026-06-30  7:26   ` Krzysztof Kozlowski
2026-06-30  8:07     ` Torreno, Alexis Czezar
2026-06-30 15:48       ` Guenter Roeck
2026-07-01  1:16         ` Torreno, Alexis Czezar
2026-06-30  2:46 ` [PATCH 2/6] hwmon: (pmbus/max20830): add support for enable GPIO Alexis Czezar Torreno
2026-06-30  3:50   ` Guenter Roeck
2026-06-30  4:51     ` Guenter Roeck
2026-06-30  8:07     ` Torreno, Alexis Czezar
2026-06-30  2:46 ` [PATCH 3/6] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties Alexis Czezar Torreno
2026-06-30  7:39   ` Krzysztof Kozlowski
2026-06-30  2:46 ` [PATCH 4/6] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support Alexis Czezar Torreno
2026-06-30  4:53   ` Guenter Roeck
2026-06-30  8:07     ` Torreno, Alexis Czezar
2026-06-30 15:34       ` Guenter Roeck
2026-07-01  1:16         ` Torreno, Alexis Czezar
2026-06-30  2:46 ` [PATCH 5/6] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support Alexis Czezar Torreno
2026-06-30  7:41   ` Krzysztof Kozlowski
2026-06-30  8:07     ` Torreno, Alexis Czezar
2026-06-30 15:06       ` Guenter Roeck
2026-06-30  2:46 ` Alexis Czezar Torreno [this message]
2026-06-30  3:43   ` [PATCH 6/6] hwmon: (pmbus/max20830): add support for max20830c and max20840c Guenter Roeck
2026-06-30  8:07     ` Torreno, Alexis Czezar
2026-06-30 15:04       ` Guenter Roeck
2026-07-02  2:50         ` Torreno, Alexis Czezar
2026-07-02  4:43           ` Guenter Roeck
2026-07-02  7:28             ` Torreno, Alexis Czezar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260630-dev-max20830c-v1-6-a02786bde470@analog.com \
    --to=alexisczezar.torreno@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox