hwmon: (pmbus) Add PMBUS_FORCE_PAGE_CHANGE flag
Subsystems (2)
v2 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 keeps the page and phase cached by pmbus_set_page() in sync with the chip. It invalidates them when changing them fails, so that the next access sends PAGE and PHASE again, and updates them only when the respective command is sent. Without it, a PAGE or PHASE write accepted by the chip, but reported as failed, or a failed or mismatched PAGE read-back, leaves the chip on a value other than the cached one, and an access to a page without phases updates the cached phase without sending PHASE. 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. On this platform, patch 1 changes the bus traffic only after a failed transfer, which was not exercised.
Changes in v2:
- Patch 1: update the cached page and phase only once the PAGE or PHASE command succeeded, not also when no command is sent, that is for a virtual page, and for a page without phases or with virtual phases (Sashiko)
v1: https://lore.kernel.org/linux-hwmon/[email protected]/
[1] https://lore.kernel.org/linux-hwmon/[email protected]/
Felix Radensky (3):
hwmon: (pmbus/core) Keep cached page and phase in sync with the chip
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 | 15 ++++++++++++--- include/linux/pmbus.h | 11 +++++++++++ 4 files changed, 43 insertions(+), 24 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.34.1
PATCH v2 1/3 hwmon: (pmbus/core) Keep cached page and phase in sync with the chip
pmbus_set_page() caches the page and phase it sets, and skips the PAGE and PHASE commands when the requested value matches the cached one. The cache can get out of sync with the chip though.
If a PAGE write succeeds, while the read-back fails or returns a different page, pmbus_set_page() 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, and the next access to the previous page skips the PAGE command. 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.
In addition, the cached page and phase are updated even if no command is sent, that is for a virtual page, and for a page without phases or with virtual phases. The cached phase then no longer reflects the phase of the chip, and can suppress a PHASE command required for another page, even if a failed phase change had invalidated it. For the page, this only causes a redundant PAGE command, since a virtual page never matches a page of the chip.
Invalidate the cached page and phase before changing them, and update them only once the respective command succeeded, so that the cache only holds values the chip has accepted.
---
v2:
- Update the cached page and phase only once the PAGE or PHASE command succeeded, not also when no command is sent, that is for a virtual page, and for a page without phases or with virtual phases (Sashiko)
- Reword the subject and commit message accordingly
drivers/hwmon/pmbus/pmbus_core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +10 -2
@@ -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 );
@@ -241,19 +244,24 @@ int pmbus_set_page(struct i2c_client *client, int page, int phase)if (rv != page)return -EIO ; + + data->currpage = page; } - data->currpage = page;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);pmbus_update_ts (client,PMBUS_OP_WRITE );if (rv)return rv; + + data->currphase = phase; } - data->currphase = phase;return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] hwmon: (pmbus/core) Keep cached page and phase in sync with the chip
Quoted 20 lines · Felix Radensky
pmbus_set_page()caches the page and phase it sets, and skips the PAGE and PHASE commands when the requested value matches the cached one. The cache can get out of sync with the chip though.If a PAGE write succeeds, while the read-back fails or returns a different page,
pmbus_set_page()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, and the next access to the previous page skips the PAGE command. 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.In addition, the cached page and phase are updated even if no command is sent, that is for a virtual page, and for a page without phases or with virtual phases. The cached phase then no longer reflects the phase of the chip, and can suppress a PHASE command required for another page, even if a failed phase change had invalidated it. For the page, this only causes a redundant PAGE command, since a virtual page never matches a page of the chip.
Quoted 6 lines
Invalidate the cached page and phase before changing them, and update them only once the respective command succeeded, so that the cache only holds values the chip has accepted.
Signed-off-by Felix Radensky <[email protected]>Reviewed-by Vadim Pasternak <[email protected]>
Applied.
Thanks,
Guenter
PATCH v2 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.
---
v2:
- No changes
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
Re: [PATCH v2 2/3] hwmon: (pmbus/core) Add PMBUS_FORCE_PAGE_CHANGE flag
Quoted 14 lines · Felix Radensky
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_CHANGEflag, which makespmbus_set_page()change the page of a chip with a single page as well, so that its driver can access the additional pages withpmbus_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.
Quoted 6 lines
While at it, drop the outdated number of flags from the platform data description in the documentation.
Suggested-by Guenter Roeck <[email protected]>Signed-off-by Felix Radensky <[email protected]>Reviewed-by Vadim Pasternak <[email protected]>
Applied.
Thanks,
Guenter
PATCH v2 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.
---
v2:
- No changes
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
Re: [PATCH v2 3/3] hwmon: (pmbus/mp2975) Use PMBUS_FORCE_PAGE_CHANGE
Quoted 7 lines · Felix Radensky
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.
Quoted 6 lines
Set
PMBUS_FORCE_PAGE_CHANGE, and change the page withpmbus_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 <[email protected]>Reviewed-by Vadim Pasternak <[email protected]>
Applied.
Thanks,
Guenter
[email protected]
AI reviewSashiko has reviewed this 3-patch series and found no issues.
Sashiko has reviewed this 3-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]