hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag
Subsystems (2)
cover hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag
As discussed in [1], this series adds the PMBUS_FORCE_PAGE_CHANGE device flag, which makes pmbus_set_page() change the page of a chip with a single page as well, and converts mp2975 to it. The mp2975 driver then accesses the page 3 voltage reference with pmbus_set_page() also in a single rail configuration, instead of writing PAGE directly.
Patch 1 makes pmbus_set_page() invalidate the cached page and phase when changing them fails, so that the next access sends PAGE and PHASE again. Without it, a PAGE write that succeeds, followed by a failed or mismatched read-back, leaves the chip on the requested page while the core caches the previous one, and the same applies to a PAGE or PHASE write accepted by the chip, but reported as failed. This already applies to chips with multiple pages or phases, and would apply to chips using the new flag as well.
Patch 3 depends on commit 00944852275e ("hwmon: (pmbus/mp2975) Get vout fault limits dynamically"), which is in v7.4-rc3, but not in hwmon-next yet. The series is based on v7.4-rc3, and applies to hwmon-next with that commit on top.
Tested on a switch platform carrying twelve MP2975 devices, twenty one rails in total. On a single rail device, the change to page 3 is now issued by the core and read back, while reading a sensor of the rail issues no PAGE command. 400 page 3 excursions on a single rail device, and 800 on a dual rail device, each followed by a read of the other rail, showed no page 3 or other rail register value in place of a sensor value. The limits of all rails matched those reported before the series, and in2_crit of the rail supplying the CPU core voltage followed the CPU between 1145mV and 1725mV. Patch 1 only changes the behavior after a failed transfer, which was not exercised.
[1] https://lore.kernel.org/linux-hwmon/[email protected]/
Felix Radensky (3):
hwmon: (pmbus/core) Invalidate cached page and phase on failed change
hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag
hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE
Documentation/hwmon/pmbus-core.rst | 12 +++++++++++- drivers/hwmon/pmbus/mp2975.c | 29 +++++++++-------------------- drivers/hwmon/pmbus/pmbus_core.c | 9 ++++++++- include/linux/pmbus.h | 11 +++++++++++ 4 files changed, 39 insertions(+), 22 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.34.1
PATCH 1/3 hwmon: (pmbus/core) Invalidate cached page and phase on failed change
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.
--- drivers/hwmon/pmbus/pmbus_core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/pmbus/pmbus_core.c +6 -0
@@ -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);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change
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 --
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 <[email protected]>
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.
Quoted 15 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-0@@ -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 );
drivers/hwmon/pmbus/pmbus_core.c int pmbus_set_page(struct i2c_client *client, int page, int phase) · line 257
Quoted 9 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-0@@ -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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Guenter Roeck
maintainerRe: [PATCH 1/3] hwmon: (pmbus/core) Invalidate cached page and phase on failed change
Hi Felix,
Quoted 57 lines · On 11/21/26 23:48, [email protected] wrote:
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 <[email protected]>hwmon: (pmbus/core) Invalidate cached page and phase on failed change
This commit resets
data->currpageanddata->currphaseto -1 inpmbus_set_page()before issuingPMBUS_PAGEandPMBUS_PHASEcommands so that a failed transfer forces a retry on the next access.Quoted 15 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-0@@ -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 );drivers/hwmon/pmbus/pmbus_core.c int pmbus_set_page(struct i2c_client *client, int page, int phase) · line 257
Quoted 9 lines
drivers/hwmon/pmbus/pmbus_core.c +3
-0@@ -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]
Shoulddata->currpage= page anddata->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; }
Quoted 10 lines
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
0xffon page 0 fails (leaving currphase == -1), an access to page 1 with phase0xffskips thePMBUS_PHASEwrite but sets currphase =0xff. A subsequent access to page 0 with phase0xffthen sees currphase == phase and skips sendingPMBUS_PHASE, accessing the wrong phase on the chip. The same happens for currpage when accessing a page withPMBUS_PAGE_VIRTUALset.
Sashiko has a point here. Previously it didn't matter because currpage/currphase was only modified after the command succeeded. Unless I am missing something, updating both inside the if() blocks does not have any negative impact because the other conditions still have to be true for a value to be written to the chip.
Thanks,
Guenter
PATCH 2/3 hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag
In reply to Felix RadenskyThe 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.
--- 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(-)
Documentation/hwmon/pmbus-core.rst +11 -1
@@ -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 ----------------
drivers/hwmon/pmbus/pmbus_core.c +2 -1
@@ -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 ;
include/linux/pmbus.h +11 -0
@@ -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 */
Signature · 1 line
2.34.1
PATCH 3/3 hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE
In reply to Felix RadenskyThe 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.
--- drivers/hwmon/pmbus/mp2975.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
drivers/hwmon/pmbus/mp2975.c +9 -20
@@ -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;
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has finished reviewing this 3-patch series:
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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]