Devicetree
 help / color / mirror / Atom feed
From: "Nuno Sá" <nuno.sa@analog.com>
To: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linux-doc@vger.kernel.org
Cc: 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>,
	Randy Dunlap <rdunlap@infradead.org>
Subject: [PATCH v2 2/4] hwmon: (pmbus/core) Add mapping function to pmbus_read_block_data()
Date: Fri, 11 Sep 2026 14:53:38 +0100	[thread overview]
Message-ID: <20260911-hwmon-max20826-support-v2-2-5e30cbd97d84@analog.com> (raw)
In-Reply-To: <20260911-hwmon-max20826-support-v2-0-5e30cbd97d84@analog.com>

This is in preparation for adding support to a device which needs to
use it's own read_block implementation.

The MAX20826 family is one such device. When not in PMBus page mode, each
of its two rails sits at a different I2C address, so selecting the rail
cannot be done through pmbus_set_page() and has to be handled by the
driver.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/hwmon/pmbus/pmbus.h      |  7 +++++++
 drivers/hwmon/pmbus/pmbus_core.c | 24 ++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 920c1102ab6d..5525c048a810 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -461,6 +461,13 @@ struct pmbus_driver_info {
 	int (*read_byte_data)(struct i2c_client *client, int page, int reg);
 	int (*read_word_data)(struct i2c_client *client, int page, int phase,
 			      int reg);
+	/*
+	 * data_buf is at least I2C_SMBUS_BLOCK_MAX bytes long. The callback
+	 * must never return more than I2C_SMBUS_BLOCK_MAX bytes of data and
+	 * returns the number of bytes written into data_buf.
+	 */
+	int (*read_block_data)(struct i2c_client *client, int page, u8 reg,
+			       char *data_buf);
 	int (*write_byte_data)(struct i2c_client *client, int page, int reg,
 			      u8 byte);
 	int (*write_word_data)(struct i2c_client *client, int page, int reg,
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 5f69c1420b4e..5104fd29307b 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -616,6 +616,26 @@ static int pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,
 	return pmbus_read_smbus_i2c_block_data(client, reg, data_buf);
 }
 
+/*
+ * _pmbus_read_block_data() is similar to pmbus_read_block_data(), but checks if
+ * a device specific mapping function exists and calls it if necessary.
+ */
+static int _pmbus_read_block_data(struct i2c_client *client, int page, u8 reg,
+				  char *data_buf)
+{
+	struct pmbus_data *data = i2c_get_clientdata(client);
+	const struct pmbus_driver_info *info = data->info;
+	int status;
+
+	if (info->read_block_data) {
+		status = info->read_block_data(client, page, reg, data_buf);
+		if (status != -ENODATA)
+			return status;
+	}
+
+	return pmbus_read_block_data(client, page, reg, data_buf);
+}
+
 static struct pmbus_sensor *pmbus_find_sensor(struct pmbus_data *data, int page,
 					      int reg)
 {
@@ -761,7 +781,7 @@ static bool __maybe_unused pmbus_check_block_register(struct i2c_client *client,
 	struct pmbus_data *data = i2c_get_clientdata(client);
 	char data_buf[I2C_SMBUS_BLOCK_MAX + 2];
 
-	rv = pmbus_read_block_data(client, page, reg, data_buf);
+	rv = _pmbus_read_block_data(client, page, reg, data_buf);
 	if (rv >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK))
 		rv = pmbus_check_status_cml(client);
 	if (rv < 0 && (data->flags & PMBUS_READ_STATUS_AFTER_FAILED_CHECK))
@@ -3679,7 +3699,7 @@ static ssize_t pmbus_debugfs_block_read(struct file *file, char __user *buf,
 	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
 
 	scoped_guard(pmbus_lock, client) {
-		rc = pmbus_read_block_data(client, entry->page, entry->reg, data);
+		rc = _pmbus_read_block_data(client, entry->page, entry->reg, data);
 		if (rc < 0)
 			return rc;
 	}

-- 
2.55.0


  parent reply	other threads:[~2026-09-11 13:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 13:53 [PATCH v2 0/4] hwmon: (pmbus) Add support for MAX20826 and similar devices Nuno Sá
2026-09-11 13:53 ` [PATCH v2 1/4] hwmon: (pmbus/core) increase number of phases and add new mask Nuno Sá
2026-09-11 14:09   ` sashiko-bot
2026-09-11 14:32     ` Guenter Roeck
2026-09-12 14:20   ` Guenter Roeck
2026-09-11 13:53 ` Nuno Sá [this message]
2026-09-11 13:59   ` [PATCH v2 2/4] hwmon: (pmbus/core) Add mapping function to pmbus_read_block_data() sashiko-bot
2026-09-12 14:21   ` Guenter Roeck
2026-09-11 13:53 ` [PATCH v2 3/4] dt-bindings: hwmon/pmbus: Document MAX20826 and similar devices Nuno Sá
2026-09-11 14:00   ` sashiko-bot
2026-09-12 10:21   ` Conor Dooley
2026-09-12 14:21   ` Guenter Roeck
2026-09-11 13:53 ` [PATCH v2 4/4] hwmon: (pmbus) add support for " Nuno Sá
2026-09-12 14:22   ` Guenter Roeck

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=20260911-hwmon-max20826-support-v2-2-5e30cbd97d84@analog.com \
    --to=nuno.sa@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=rdunlap@infradead.org \
    --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