[PATCH v2 4/7] board: nxp: vid: introduce PMBus framework support

Peng Fan peng.fan at oss.nxp.com
Mon Jul 6 05:41:12 CEST 2026


On Thu, Jul 02, 2026 at 10:15:42PM +0200, Vincent Jardin wrote:
>Wire board/nxp/common/vid.c into the <pmbus.h> framework so the legacy
>NXP AVS path stops carrying its own duplicate copy of the PMBus
>protocol and instead consumes the shared constants, decoders, and
>transport helpers.
>
>vid.c is the legacy NXP AVS/pre-kernel voltage-trim path for lx2160 CPUs.
>It does PMBus to whichever core-rail voltage monitor the board carries:
>LTC3882 or ISL68233 are selected with
>CONFIG_VOL_MONITOR_LTC3882_*/CONFIG_VOL_MONITOR_ISL68233_*.
>
>Before this change the file kept its own local PMBUS_CMD_* command-code
>defines, its own inline LINEAR16 mantissa/exponent math, and called
>into I2C through the I2C_READ/I2C_WRITE NXP wrappers in
>board/nxp/common/i2c_common.{c,h} which is a parallel implementation of
>exactly what <pmbus.h> + lib/pmbus.c provides.
>
>The intent is to make vid.c an consumer of the new PMBus.
>
>Compatibility with the former support:
>
>  - CLI unchanged: vdd_override and vdd_read keep their existing
>    semantics, return codes, and diagnostic output.
>
>  - I2C transport unchanged on the wire: the framework's pmbus_*
>    helpers call dm_i2c_read/dm_i2c_write: the same DM I2C
>    backing that vid.c's former I2C_READ/I2C_WRITE macros already
>    routed through on DM_I2C.
>
>  - Numeric decode is bit-equivalent: pmbus_reg2data_linear16() and
>    pmbus_data2reg_linear16() implement the PMBus 1.3 Part II
>    mantissa/exponent.
>
>Signed-off-by: Vincent Jardin <vjardin at free.fr>
>---
>
>(no changes since v1)
>
> arch/Kconfig.nxp       |   4 ++
> board/nxp/common/vid.c | 104 ++++++++++++++++++++++-------------------
> board/nxp/common/vid.h |  15 +++---
> 3 files changed, 68 insertions(+), 55 deletions(-)
>
>diff --git a/arch/Kconfig.nxp b/arch/Kconfig.nxp
>index ef9087d0197..152692e3230 100644
>--- a/arch/Kconfig.nxp
>+++ b/arch/Kconfig.nxp
>@@ -242,24 +242,28 @@ config VOL_MONITOR_IR36021_SET
> 
> config VOL_MONITOR_LTC3882_READ
> 	bool "Enable the LTC3882 voltage monitor read"
>+	select PMBUS
> 	help
> 	 This option enables LTC3882 voltage monitor read
> 	 functionality. It is used by the common VID driver.
> 
> config VOL_MONITOR_LTC3882_SET
> 	bool "Enable the LTC3882 voltage monitor set"
>+	select PMBUS
> 	help
> 	 This option enables LTC3882 voltage monitor set
> 	 functionality. It is used by the common VID driver.
> 
> config VOL_MONITOR_ISL68233_READ
> 	bool "Enable the ISL68233 voltage monitor read"
>+	select PMBUS
> 	help
> 	 This option enables ISL68233 voltage monitor read
> 	 functionality. It is used by the common VID driver.
> 
> config VOL_MONITOR_ISL68233_SET
> 	bool "Enable the ISL68233 voltage monitor set"
>+	select PMBUS
> 	help
> 	 This option enables ISL68233 voltage monitor set
> 	 functionality. It is used by the common VID driver.
>diff --git a/board/nxp/common/vid.c b/board/nxp/common/vid.c
>index 84cb43fad56..a91d6c9381a 100644
>--- a/board/nxp/common/vid.c
>+++ b/board/nxp/common/vid.c
>@@ -11,6 +11,7 @@
> #include <i2c.h>
> #include <irq_func.h>
> #include <log.h>
>+#include <pmbus.h>
> #include <vsprintf.h>
> #include <asm/io.h>
> #ifdef CONFIG_FSL_LSCH2
>@@ -260,45 +261,38 @@ static int read_voltage_from_IR(int i2caddress)
>  */
> #define VOUT_WARNING "VID: VOUT_MODE exponent has resolution worse than 1 V!\n"
> 
>-/* Checks the PMBus voltage monitor for the format used for voltage values */
>-static int get_pmbus_multiplier(DEVICE_HANDLE_T dev)
>+/*
>+ * Read VOUT_MODE for downstream LINEAR16 decode/encode through the
>+ * tree level <pmbus.h> helpers (pmbus_reg2data_linear16,
>+ * pmbus_data2reg_linear16). Returns the raw VOUT_MODE byte on
>+ * success, or 0 on bus error. Emits VOUT_WARNING on Linear mode
>+ * chips with a non negative exponent (resolution >= 1 V is unusable
>+ * for sub volt SoC rails) and an informational note on the
>+ * unsupported VID format.
>+ */
>+static u8 vid_read_vout_mode(DEVICE_HANDLE_T dev)
> {
>-	u8 mode;
>-	int exponent, multiplier, ret;
>+	u8 mode = 0;
>+	int ret;
> 
>-	ret = I2C_READ(dev, PMBUS_CMD_VOUT_MODE, &mode, sizeof(mode));
>+	ret = pmbus_read_byte(dev, PMBUS_VOUT_MODE, &mode);
> 	if (ret) {
> 		printf("VID: unable to determine voltage multiplier\n");
>-		return 1;
>+		return 0;
> 	}
> 
...
>+	/*
>+	 * Decode LINEAR16 via the tree level helper from <pmbus.h>. For
>+	 * non Linear VOUT_MODE settings the helper returns 0; fall back
>+	 * to the historic mV pass through so existing LSCH boards keep.
>+	 */
>+	vout_mode = vid_read_vout_mode(dev);
>+	if ((vout_mode & PB_VOUT_MODE_MODE_MASK) == PB_VOUT_MODE_LINEAR) {
>+		s64 uv = pmbus_reg2data_linear16(vcode, vout_mode);
>+
>+		vout = (int)((uv + 500) / 1000);	/* round to mV */
>+	} else {
>+		vout = (int)vcode;
>+	}
> 	return vout - board_vdd_drop_compensation();

When vid_read_vout_mode() returns 0, the return value here seems
not correct.

> }

Regards,
Peng


More information about the U-Boot mailing list