* [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change
2026-11-22 7:33 [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
@ 2026-11-22 7:33 ` Felix Radensky
2026-11-22 7:48 ` sashiko-bot
2026-11-22 7:33 ` [PATCH 2/3] hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Felix Radensky @ 2026-11-22 7:33 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Vadim Pasternak, Felix Radensky, linux-hwmon, linux-doc
pmbus_set_page() writes PAGE, and reads it back to verify the change. If
the write succeeds, while the read-back fails or returns a different
page, it returns an error without updating the cached page. The chip can
then be on the requested page, while the core still caches the previous
one. The next access to the previous page skips the PAGE command, and
accesses the chip on the wrong page, until a different page is
requested.
The same applies to a PAGE or PHASE write which returns an error after
the chip has accepted it, such as on a late NAK, a PEC error or an
adapter timeout.
Invalidate the cached page and phase before changing them, and set them
only once the change succeeded, so that PAGE and PHASE are sent again on
the next access after a failed change.
Signed-off-by: Felix Radensky <fradensky@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
---
drivers/hwmon/pmbus/pmbus_core.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 82dac2c6c579..dae56e2e6f21 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -227,6 +227,9 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL) &&
data->info->pages > 1 && page != data->currpage) {
+ /* A failed page change can leave the chip on any page */
+ data->currpage = -1;
+
pmbus_wait(client);
rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
pmbus_update_ts(client, PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE);
@@ -246,6 +249,9 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
if (data->info->phases[page] && data->currphase != phase &&
!(data->info->func[page] & PMBUS_PHASE_VIRTUAL)) {
+ /* A failed phase change can leave the chip on any phase */
+ data->currphase = -1;
+
pmbus_wait(client);
rv = i2c_smbus_write_byte_data(client, PMBUS_PHASE,
phase);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change
2026-11-22 7:33 ` [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change Felix Radensky
@ 2026-11-22 7:48 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-22 7:48 UTC (permalink / raw)
To: Felix Radensky; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] hwmon: (pmbus/core) pmbus_set_page() updates cache outside
conditional blocks
--
commit 03751a48b86432f4503eb9a4970150b29ef4ab2c
Author: Felix Radensky <fradensky@nvidia.com>
hwmon: (pmbus/core) Invalidate cached page and phase on failed change
This commit resets data->currpage and data->currphase to -1 in
pmbus_set_page() before issuing PMBUS_PAGE and PMBUS_PHASE commands so
that a failed transfer forces a retry on the next access.
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 82dac2c6c579f..dae56e2e6f21f 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -227,6 +227,9 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
>
> if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL) &&
> data->info->pages > 1 && page != data->currpage) {
> + /* A failed page change can leave the chip on any page */
> + data->currpage = -1;
> +
> pmbus_wait(client);
> rv = i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
> pmbus_update_ts(client, PMBUS_OP_WRITE | PMBUS_OP_PAGE_CHANGE);
> @@ -246,6 +249,9 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
>
> if (data->info->phases[page] && data->currphase != phase &&
> !(data->info->func[page] & PMBUS_PHASE_VIRTUAL)) {
> + /* A failed phase change can leave the chip on any phase */
> + data->currphase = -1;
> +
> pmbus_wait(client);
> rv = i2c_smbus_write_byte_data(client, PMBUS_PHASE,
> phase);
[Severity: Medium]
Should data->currpage = page and data->currphase = phase be moved inside
their respective conditional blocks?
Because both assignments remain outside the if blocks:
drivers/hwmon/pmbus/pmbus_core.c:pmbus_set_page() {
...
data->currpage = page;
if (data->info->phases[page] && data->currphase != phase &&
!(data->info->func[page] & PMBUS_PHASE_VIRTUAL)) {
...
}
data->currphase = phase;
}
any call that skips the SMBus write still overwrites the cached value
(including an invalidated -1) without programming the chip. For example,
on a multi-page device where page 0 has phases and page 1 has
info->phases[1] == 0 (such as tps53681), if a phase change to 0xff on page
0 fails (leaving currphase == -1), an access to page 1 with phase 0xff
skips the PMBUS_PHASE write but sets currphase = 0xff. A subsequent access
to page 0 with phase 0xff then sees currphase == phase and skips sending
PMBUS_PHASE, accessing the wrong phase on the chip. The same happens for
currpage when accessing a page with PMBUS_PAGE_VIRTUAL set.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122073322.1712843-1-fradensky@nvidia.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag
2026-11-22 7:33 [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
2026-11-22 7:33 ` [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change Felix Radensky
@ 2026-11-22 7:33 ` Felix Radensky
2026-11-22 7:33 ` [PATCH 3/3] hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE Felix Radensky
2026-11-22 7:48 ` [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: Felix Radensky @ 2026-11-22 7:33 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Vadim Pasternak, Felix Radensky, linux-hwmon, linux-doc
The PMBus core driver only changes the page of chips with more than one
page, and neither writes nor verifies the page of a chip with a single
page. Some chips with a single page provide manufacturer specific
registers on additional pages. Their drivers write PAGE directly to
access them, and have to change back to the page the core expects on
their own. If changing back fails, the core accesses the chip on the
wrong page.
Add the PMBUS_FORCE_PAGE_CHANGE flag, which makes pmbus_set_page()
change the page of a chip with a single page as well, so that its driver
can access the additional pages with pmbus_set_page(). The page change
is then read back, and a failed page change is repeated on the next
access, as for chips with multiple pages.
While at it, drop the outdated number of flags from the platform data
description in the documentation.
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Felix Radensky <fradensky@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
---
Documentation/hwmon/pmbus-core.rst | 12 +++++++++++-
drivers/hwmon/pmbus/pmbus_core.c | 3 ++-
include/linux/pmbus.h | 11 +++++++++++
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/Documentation/hwmon/pmbus-core.rst b/Documentation/hwmon/pmbus-core.rst
index fdfb23773148..bca387518b6a 100644
--- a/Documentation/hwmon/pmbus-core.rst
+++ b/Documentation/hwmon/pmbus-core.rst
@@ -298,7 +298,7 @@ PMBus driver platform data
==========================
PMBus platform data is defined in include/linux/pmbus.h. Platform data
-currently provides a flags field with four bits used::
+currently provides a flags field with the following bits::
#define PMBUS_SKIP_STATUS_CHECK BIT(0)
@@ -316,6 +316,8 @@ currently provides a flags field with four bits used::
#define PMBUS_VOUT_PROTECTED BIT(7)
+ #define PMBUS_FORCE_PAGE_CHANGE BIT(8)
+
struct pmbus_platform_data {
u32 flags; /* Device specific flags */
@@ -388,6 +390,14 @@ PMBUS_VOUT_PROTECTED
Set if the chip VOUT_COMMAND command is protected and protection is not
determined by the standard WRITE_PROTECT command.
+PMBUS_FORCE_PAGE_CHANGE
+
+The PMBus core driver only changes the page of chips with more than one
+page. Some chips with a single page provide manufacturer specific registers
+on additional pages. Set this flag so that the PMBus core driver changes the
+page of such chips as well, which lets the chip driver access the additional
+pages with pmbus_set_page().
+
Module parameter
----------------
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index dae56e2e6f21..822a092984c7 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -226,7 +226,8 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)
return 0;
if (!(data->info->func[page] & PMBUS_PAGE_VIRTUAL) &&
- data->info->pages > 1 && page != data->currpage) {
+ (data->info->pages > 1 || (data->flags & PMBUS_FORCE_PAGE_CHANGE)) &&
+ page != data->currpage) {
/* A failed page change can leave the chip on any page */
data->currpage = -1;
diff --git a/include/linux/pmbus.h b/include/linux/pmbus.h
index 884040e1383b..b3bc4cced461 100644
--- a/include/linux/pmbus.h
+++ b/include/linux/pmbus.h
@@ -87,6 +87,17 @@
*/
#define PMBUS_VOUT_PROTECTED BIT(7)
+/*
+ * PMBUS_FORCE_PAGE_CHANGE
+ *
+ * The PMBus core driver only changes the page of chips with more than one
+ * page. Some chips with a single page provide manufacturer specific registers
+ * on additional pages. Set this flag so that the PMBus core driver changes the
+ * page of such chips as well, which lets the chip driver access the additional
+ * pages with pmbus_set_page().
+ */
+#define PMBUS_FORCE_PAGE_CHANGE BIT(8)
+
struct pmbus_platform_data {
u32 flags; /* Device specific flags */
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE
2026-11-22 7:33 [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
2026-11-22 7:33 ` [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change Felix Radensky
2026-11-22 7:33 ` [PATCH 2/3] hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
@ 2026-11-22 7:33 ` Felix Radensky
2026-11-22 7:48 ` [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: Felix Radensky @ 2026-11-22 7:33 UTC (permalink / raw)
To: Guenter Roeck; +Cc: Vadim Pasternak, Felix Radensky, linux-hwmon, linux-doc
The voltage reference, from which the vout fault limits are derived, is
read on page 3. In a single rail configuration the driver writes PAGE
directly for it, since the PMBus core does not change the page of a chip
with a single page. If changing back to the rail page fails, the core
reads page 3 registers in place of the rail registers, until the next
voltage reference read changes the page again.
Set PMBUS_FORCE_PAGE_CHANGE, and change the page with pmbus_set_page()
in both configurations. The page change is then read back, and a failed
change is repeated on the next access, as for two rails.
Signed-off-by: Felix Radensky <fradensky@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
---
drivers/hwmon/pmbus/mp2975.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c
index 2ad6b7d831c8..4eba171ab87b 100644
--- a/drivers/hwmon/pmbus/mp2975.c
+++ b/drivers/hwmon/pmbus/mp2975.c
@@ -11,6 +11,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/pmbus.h>
#include "pmbus.h"
@@ -105,6 +106,7 @@ struct mp2975_driver_info {
struct mp2975_data {
struct pmbus_driver_info info;
+ struct pmbus_platform_data pdata;
enum chips chip_id;
int vout_scale;
int max_phases[MP2975_PAGE_NUM];
@@ -457,37 +459,20 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret);
}
-/*
- * Let the PMBus core change the page, so that the page it caches matches the
- * device. The core does not issue PAGE commands for a single rail
- * configuration, thus change the page directly then.
- */
-static int
-mp2975_page_set(struct i2c_client *client, struct mp2975_data *data, int page)
-{
- if (data->info.pages > 1)
- return pmbus_set_page(client, page, 0xff);
-
- return i2c_smbus_write_byte_data(client, PMBUS_PAGE, page);
-}
-
-/*
- * Voltage reference is available on page 3 only. The callers read a register
- * of the rail through the core first, thus the core caches the rail page.
- */
+/* Voltage reference is available on page 3 only. */
static int
mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data, int page)
{
int ret, vref;
- ret = mp2975_page_set(client, data, 3);
+ ret = pmbus_set_page(client, 3, 0xff);
if (ret < 0)
return ret;
vref = i2c_smbus_read_word_data(client, page ? MP2975_MFR_READ_VREF_R2 :
MP2975_MFR_READ_VREF_R1);
- ret = mp2975_page_set(client, data, page);
+ ret = pmbus_set_page(client, page, 0xff);
if (ret < 0)
return ret;
@@ -1072,6 +1057,10 @@ static int mp2975_probe(struct i2c_client *client)
if (ret)
return ret;
+ /* Page 3 is accessed in a single rail configuration as well. */
+ data->pdata.flags = PMBUS_FORCE_PAGE_CHANGE;
+ client->dev.platform_data = &data->pdata;
+
ret = pmbus_do_probe(client, info);
if (ret)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag
2026-11-22 7:33 [PATCH 0/3] hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag Felix Radensky
` (2 preceding siblings ...)
2026-11-22 7:33 ` [PATCH 3/3] hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE Felix Radensky
@ 2026-11-22 7:48 ` sashiko-bot
3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-22 7:48 UTC (permalink / raw)
To: Felix Radensky; +Cc: linux-hwmon
Sashiko has finished reviewing this 3-patch series:
- Patches 2 and 3: no issues found.
- Patch 1 ("hwmon: (pmbus/core) Invalidate cached page and phase..."): 1
potential issue (1 Medium)
A detailed review has been sent as a separate reply to patch 1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122073322.1712843-1-fradensky@nvidia.com
^ permalink raw reply [flat|nested] 6+ messages in thread