Linux Hardware Monitor development
 help / color / mirror / Atom feed
* [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid()
@ 2026-06-20  7:50 Abdurrahman Hussain
  2026-06-20  7:55 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Abdurrahman Hussain @ 2026-06-20  7:50 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, linux-kernel, Abdurrahman Hussain

pmbus_data2reg_vid() hardcoded the VR11 encoding regardless of the
vrm_version configured by the driver, while pmbus_reg2data_vid()
already switched on it. Any driver that selects a non-VR11 VID mode
and exposes a regulator (or hwmon vout setter) sent dangerously
wrong codes to PMBUS_VOUT_COMMAND -- e.g. an nvidia195mv part asked
for 200 mV got the VR11 clamp to 500 mV encoded as 0xB2, which the
chip interprets as 1080 mV.

Mirror pmbus_reg2data_vid() so writes round-trip with reads.

Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
Assisted-by: Claude:claude-opus-4-7 [Claude Code]
---
 drivers/hwmon/pmbus/pmbus_core.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index e8fdd799c71c..8123a568af40 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1095,9 +1095,27 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data,
 static u16 pmbus_data2reg_vid(struct pmbus_data *data,
 			      struct pmbus_sensor *sensor, s64 val)
 {
-	val = clamp_val(val, 500, 1600);
-
-	return 2 + DIV_ROUND_CLOSEST_ULL((1600LL - val) * 100LL, 625);
+	switch (data->info->vrm_version[sensor->page]) {
+	case vr12:
+		val = clamp_val(val, 250, 1520);
+		return 1 + DIV_ROUND_CLOSEST_ULL(val - 250, 5);
+	case vr13:
+		val = clamp_val(val, 500, 3040);
+		return 1 + DIV_ROUND_CLOSEST_ULL(val - 500, 10);
+	case imvp9:
+		val = clamp_val(val, 200, 2740);
+		return 1 + DIV_ROUND_CLOSEST_ULL(val - 200, 10);
+	case amd625mv:
+		val = clamp_val(val, 200, 1550);
+		return DIV_ROUND_CLOSEST_ULL((1550LL - val) * 100LL, 625);
+	case nvidia195mv:
+		val = clamp_val(val, 195, 1465);
+		return 1 + DIV_ROUND_CLOSEST_ULL(val - 195, 5);
+	case vr11:
+	default:
+		val = clamp_val(val, 500, 1600);
+		return 2 + DIV_ROUND_CLOSEST_ULL((1600LL - val) * 100LL, 625);
+	}
 }
 
 static u16 pmbus_data2reg(struct pmbus_data *data,

---
base-commit: 9ecfb2f7287a967b418ba69f10d45ead0d360593
change-id: 20260620-pmbus-data2reg-vid-fb2db82297e8

Best regards,
--  
Abdurrahman Hussain <abdurrahman@nexthop.ai>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid()
  2026-06-20  7:50 [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid() Abdurrahman Hussain
@ 2026-06-20  7:55 ` sashiko-bot
  2026-06-20 18:25 ` abdurrahman
  2026-06-29 15:41 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-06-20  7:55 UTC (permalink / raw)
  To: Abdurrahman Hussain; +Cc: linux-hwmon

> pmbus_data2reg_vid() hardcoded the VR11 encoding regardless of the
> vrm_version configured by the driver, while pmbus_reg2data_vid()
> already switched on it. Any driver that selects a non-VR11 VID mode
> and exposes a regulator (or hwmon vout setter) sent dangerously
> wrong codes to PMBUS_VOUT_COMMAND -- e.g. an nvidia195mv part asked
> for 200 mV got the VR11 clamp to 500 mV encoded as 0xB2, which the
> chip interprets as 1080 mV.
> 
> Mirror pmbus_reg2data_vid() so writes round-trip with reads.
> 
> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260620-pmbus-data2reg-vid-v1-1-5518030432c4@nexthop.ai?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid()
  2026-06-20  7:50 [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid() Abdurrahman Hussain
  2026-06-20  7:55 ` sashiko-bot
@ 2026-06-20 18:25 ` abdurrahman
  2026-06-29 15:41 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: abdurrahman @ 2026-06-20 18:25 UTC (permalink / raw)
  To: Abdurrahman Hussain; +Cc: linux-hwmon

> pmbus_data2reg_vid() hardcoded the VR11 encoding regardless of the
> vrm_version configured by the driver, while pmbus_reg2data_vid()
> already switched on it. Any driver that selects a non-VR11 VID mode
> and exposes a regulator (or hwmon vout setter) sent dangerously
> wrong codes to PMBUS_VOUT_COMMAND -- e.g. an nvidia195mv part asked
> for 200 mV got the VR11 clamp to 500 mV encoded as 0xB2, which the
> chip interprets as 1080 mV.
> 
> Mirror pmbus_reg2data_vid() so writes round-trip with reads.
> 
> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260620-pmbus-data2reg-vid-v1-1-5518030432c4@nexthop.ai?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid()
  2026-06-20  7:50 [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid() Abdurrahman Hussain
  2026-06-20  7:55 ` sashiko-bot
  2026-06-20 18:25 ` abdurrahman
@ 2026-06-29 15:41 ` Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-06-29 15:41 UTC (permalink / raw)
  To: Abdurrahman Hussain; +Cc: linux-hwmon, linux-kernel

On Sat, Jun 20, 2026 at 12:50:37AM -0700, Abdurrahman Hussain wrote:
> pmbus_data2reg_vid() hardcoded the VR11 encoding regardless of the
> vrm_version configured by the driver, while pmbus_reg2data_vid()
> already switched on it. Any driver that selects a non-VR11 VID mode
> and exposes a regulator (or hwmon vout setter) sent dangerously
> wrong codes to PMBUS_VOUT_COMMAND -- e.g. an nvidia195mv part asked
> for 200 mV got the VR11 clamp to 500 mV encoded as 0xB2, which the
> chip interprets as 1080 mV.
> 
> Mirror pmbus_reg2data_vid() so writes round-trip with reads.
> 
> Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
> Assisted-by: Claude:claude-opus-4-7 [Claude Code]

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-29 15:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-20  7:50 [PATCH] hwmon: (pmbus/core) honor vrm_version in pmbus_data2reg_vid() Abdurrahman Hussain
2026-06-20  7:55 ` sashiko-bot
2026-06-20 18:25 ` abdurrahman
2026-06-29 15:41 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox