pmbus: PMBus 1.x framework, CLI, regulator and thermal support
Subsystems (2)
v3 cover pmbus: PMBus 1.x framework, CLI, regulator and thermal support
This series adds U-Boot's PMBus 1.x support as a small boot-time layer (not a hwmon clone):
- a decoder + transport library and the pmbus CLI command
- a shared UCLASS_REGULATOR adapter plus a catch-all driver for compliant chips, add the MPS MPQ8785 per-chip driver
- a generic PMBus die-temperature UCLASS_THERMAL bridge
- migration of the shared NXP VID rail-trim code to this framework
- a sandbox PMBus chip emulator and "ut dm pmbus" unit tests that exercise most subcommand of the CLI.
The goal is to identify PMBus regulators at boot, print telemetry and decode chip alerts before the kernel takes over - no polling, no sysfs, no fan loops. Linux owns the runtime side.
Changes in v3:
- pmbus_read_string(): fix 1 byte stack overflow
- pmbus dump: print MFR_ID/MODEL/REVISION with the proper byte order
- typo: Adaapted -> Adapted
- vid_read_vout_mode(): avoid confusions error vs mode.
Changes in v2:
- Apply Tom Rini's v1 review: drop the local DT binding YAML files
Vincent Jardin (7):
pmbus: add PMBus 1.x framework, CLI, and binding
power: regulator: add generic PMBus UCLASS_REGULATOR adapter
power: regulator: add MPS MPQ8785 PMBus regulator driver
board: nxp: vid: introduce PMBus framework support
thermal: pmbus: add PMBus die-temp driver
test: dm: pmbus: add a sandbox PMBus chip emulator
test: dm: pmbus: test pmbus command and framework
MAINTAINERS | 15 + arch/Kconfig.nxp | 4 + arch/sandbox/dts/test.dts | 10 + board/nxp/common/vid.c | 110 +-- board/nxp/common/vid.h | 15 +- cmd/Kconfig | 14 + cmd/Makefile | 1 + cmd/pmbus.c | 816 ++++++++++++++++++++++ configs/sandbox_defconfig | 6 + doc/develop/index.rst | 1 + doc/develop/pmbus.rst | 633 +++++++++++++++++ drivers/power/regulator/Kconfig | 43 ++ drivers/power/regulator/Makefile | 4 + drivers/power/regulator/mpq8785.c | 494 +++++++++++++ drivers/power/regulator/pmbus_generic.c | 90 +++ drivers/power/regulator/pmbus_helper.c | 315 +++++++++ drivers/power/regulator/pmbus_helper.h | 90 +++ drivers/power/regulator/sandbox_pmbus.c | 160 +++++ drivers/thermal/Kconfig | 8 + drivers/thermal/Makefile | 1 + drivers/thermal/pmbus_thermal.c | 33 + include/pmbus.h | 667 ++++++++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 877 ++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/pmbus.c | 247 +++++++ 27 files changed, 4617 insertions(+), 55 deletions(-) create mode 100644 cmd/pmbus.c create mode 100644 doc/develop/pmbus.rst create mode 100644 drivers/power/regulator/mpq8785.c create mode 100644 drivers/power/regulator/pmbus_generic.c create mode 100644 drivers/power/regulator/pmbus_helper.c create mode 100644 drivers/power/regulator/pmbus_helper.h create mode 100644 drivers/power/regulator/sandbox_pmbus.c create mode 100644 drivers/thermal/pmbus_thermal.c create mode 100644 include/pmbus.h create mode 100644 lib/pmbus.c create mode 100644 test/dm/pmbus.c
Signature · 4 lines
2.43.0 base-commit: f605dcee103c897b6f1a8873549a36949bd4e2a1 branch: for-upstream/pmbus-v6
PATCH v3 1/7 pmbus: add PMBus 1.x framework, CLI, and binding
Add U-Boot's PMBus 1.x layer: the decoder/transport library, the pmbus CLI command and a generic DT binding.
The subsequent commits provide the UCLASS_REGULATOR adapter and per-chip drivers.
U-Boot's PMBus support is not a hwmon clone of Linux's drivers/hwmon/pmbus/. Linux owns the runtime side (polling, sysfs, alert IRQs, fan loops). U-Boot owns the boot-time side in order to,
- identify the PMBus regulators a board carries: MFR_ID/ MFR_MODEL/MFR_REVISION + sanity checks.
- print telemetry (VIN/VOUT/IIN/IOUT/POUT/TEMP) so an operator can confirm rail voltages and faults before the kernel
- decode any chip alerts (STATUS_VOUT/STATUS_IOUT/STATUS_INPUT/ STATUS_TEMPERATURE/STATUS_CML) so a boot log shows why the previous boot failed or the board had been power cycled because of an outage (typically over temperature or under current).
Out of scope by design: no periodic polling, no sysfs, no fan-speed control loop, no PMBUS_VIRT_* sensor virtualisation, no caching. If a use case needs any of those, the answer should be "wait until Linux comes up". It shall remain a thin layer.
The constants and structural shape (command codes, status bit names, sensor-class enum, format enum, struct pmbus_driver_info) are mirrored from Linux drivers/hwmon/pmbus/pmbus.h verbatim. The decoders/encoders are reimplemented from the PMBus 1.3 specification because the surrounding hwmon context (struct pmbus_data, sysfs caching, hwmon publication) does not apply.
The main benefits:
- One framework + CLI for any board carrying PMBus regulators:
no per-board PMBus implementation required anymore.
- Boards call pmbus_print_telemetry() / pmbus_print_status_word() directly from boot init for a snapshot, sharing all decode + format-dispatch with the CLI.
- Linux-compatible constants and DT binding so porting an existing drivers/hwmon/pmbus/ chip is mechanical.
- Boot-time AVS/VID rail trim reuses the same decoders and encoders as the CLI and the regulator path: no duplicate math.
---
Changes in v3:
- pmbus_read_string(): fix 1 byte stack overflow
- pmbus dump: print MFR_ID/MODEL/REVISION with the proper byte order
Changes in v2:
- Apply Tom Rini's v1 review: drop the local DT binding YAML files
MAINTAINERS | 8 + cmd/Kconfig | 14 + cmd/Makefile | 1 + cmd/pmbus.c | 816 +++++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + doc/develop/pmbus.rst | 633 +++++++++++++++++++++++++++++++ include/pmbus.h | 630 +++++++++++++++++++++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 860 ++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2980 insertions(+) create mode 100644 cmd/pmbus.c create mode 100644 doc/develop/pmbus.rst create mode 100644 include/pmbus.h create mode 100644 lib/pmbus.c
MAINTAINERS +8 -0
@@ -1580,6 +1580,14 @@ S: Maintained F: cmd/pci_mps.c F: test/cmd/pci_mps.c +PMBUS +M: Vincent Jardin <[email protected]> +S: Maintained +F: cmd/pmbus.c +F: doc/develop/pmbus.rst +F: include/pmbus.h +F: lib/pmbus.c + POWER M: Jaehoon Chung <[email protected]> M: Peng Fan <[email protected]>
cmd/Kconfig +14 -0
@@ -2715,6 +2715,20 @@ config CMD_PMIC - pmic write address - write byte to register at address The only one change for this command is 'dev' subcommand. +config CMD_PMBUS + bool "pmbus device interrogation and control command" + depends on PMBUS + help + Enable the pmbus U-Boot CLI command. Provides identification, + decoded telemetry, STATUS_* decoding, raw register read/write, + CLEAR_FAULTS, and VOUT_COMMAND set/get against any PMBus 1.x + compliant device selectable via 'pmbus dev <bus>:<addr>'. + + Per chip drivers and board files publish vendor extensions in + the 'pmbus <vendor> ...' namespace. + + See doc/develop/pmbus.rst for the full usage reference. + config CMD_REGULATOR bool "Enable Driver Model REGULATOR command" depends on DM_REGULATOR
cmd/Makefile +1 -0
@@ -228,6 +228,7 @@ obj-$(CONFIG_CMD_AXI) += axi.o obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o # Power +obj-$(CONFIG_CMD_PMBUS) += pmbus.o obj-$(CONFIG_CMD_PMIC) += pmic.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o
cmd/pmbus.c new file +816 -0
816 lines not on this page · raw message
doc/develop/index.rst +1 -0
@@ -50,6 +50,7 @@ Implementation logging makefiles menus + pmbus printf smbios spl
doc/develop/pmbus.rst new file +633 -0
633 lines not on this page · raw message
include/pmbus.h new file +630 -0
630 lines not on this page · raw message
lib/Kconfig +16 -0
@@ -283,6 +283,22 @@ config PANIC_HANG development since you can try to debug the conditions that lead to the situation. +config PMBUS + bool "PMBus 1.x decoder and transport helpers" + depends on DM_I2C + help + Enable include/pmbus.h and lib/pmbus.c: standard PMBus 1.x + command codes, LINEAR11, LINEAR16, and DIRECT numeric format + decoders, the two stage SMBus block read helper used for + MFR_ID, MFR_MODEL, and MFR_REVISION reads, and the table + driven STATUS_* bit print helper. + + This is the substrate for any pre kernel PMBus consumer in + U-Boot (board/nxp/common/vid.c rail trim, board local telemetry + diagnostics, future per chip regulator drivers under + drivers/power/regulator/). It is not a hwmon clone. See + doc/develop/pmbus.rst for the policy notes. + config REGEX bool "Enable regular expression support" default y if NET_LEGACY
lib/Makefile +1 -0
@@ -53,6 +53,7 @@ obj-y += rc4.o obj-$(CONFIG_RBTREE) += rbtree.o obj-$(CONFIG_BITREVERSE) += bitrev.o obj-y += list_sort.o +obj-$(CONFIG_PMBUS) += pmbus.o endif obj-$(CONFIG_$(PHASE_)TPM) += tpm-common.o
lib/pmbus.c new file +860 -0
844 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.43.0
Part of the diff is not shown here. View the raw message.
PATCH v3 2/7 power: regulator: add generic PMBus UCLASS_REGULATOR adapter
In reply to Vincent JardinPMBus regulators differ in numeric formats and quirks, not in how they are driven. Share that common behaviour as a regulator-uclass adapter so chip drivers and the pmbus CLI do not each reimplement the decode and transport, and add a catch-all driver on compatible = "pmbus" for compliant chips that have no dedicated driver yet.
Gated by CONFIG_DM_REGULATOR_PMBUS_HELPER andCONFIG_DM_REGULATOR_PMBUS_GENERIC.
---
(no changes since v1)
MAINTAINERS | 3 + drivers/power/regulator/Kconfig | 24 ++ drivers/power/regulator/Makefile | 2 + drivers/power/regulator/pmbus_generic.c | 90 +++++++ drivers/power/regulator/pmbus_helper.c | 315 ++++++++++++++++++++++++ drivers/power/regulator/pmbus_helper.h | 90 +++++++ include/pmbus.h | 37 +++ lib/pmbus.c | 17 ++ 8 files changed, 578 insertions(+) create mode 100644 drivers/power/regulator/pmbus_generic.c create mode 100644 drivers/power/regulator/pmbus_helper.c create mode 100644 drivers/power/regulator/pmbus_helper.h
MAINTAINERS +3 -0
@@ -1585,6 +1585,9 @@ M: Vincent Jardin <[email protected]> S: Maintained F: cmd/pmbus.c F: doc/develop/pmbus.rst +F: drivers/power/regulator/pmbus_generic.c +F: drivers/power/regulator/pmbus_helper.c +F: drivers/power/regulator/pmbus_helper.h F: include/pmbus.h F: lib/pmbus.c
drivers/power/regulator/Kconfig +24 -0
@@ -557,3 +557,27 @@ config DM_REGULATOR_MT6359 MediaTek MT6359 PMIC. This driver supports the control of different power rails of device through regulator interface. + +config DM_REGULATOR_PMBUS_HELPER + bool "Shared regulator helpers for PMBus chip drivers" + depends on DM_REGULATOR && PMBUS && DM_I2C + help + Provide shared get_value / set_value / get_enable / set_enable + operations for UCLASS_REGULATOR drivers that bind PMBus 1.x + compliant voltage regulators. Per chip drivers + (mps,mpq8785, lltc,ltc3882, ...) consume this helper to avoid + duplicating the LINEAR16 / DIRECT decoder dispatch and the + VOUT_MODE / VOUT_COMMAND / OPERATION transport sequences. + +config DM_REGULATOR_PMBUS_GENERIC + bool "Generic PMBus 1.x regulator driver (compatible=\"pmbus\")" + depends on DM_REGULATOR_PMBUS_HELPER + help + Catch all UCLASS_REGULATOR driver bound to compatible = "pmbus". + Auto detects the VOUT numeric format from the chip's VOUT_MODE + register and exposes telemetry plus voltage set / get against + the standard PMBus 1.x command codes. Use this for PMBus + compliant chips that have no per chip driver yet; promote to a + per chip driver only when chip specific quirks (vendor + registers, VID coercion, ADDR pin auto promotion, non standard + m / b / R coefficients) need handling.
drivers/power/regulator/Makefile +2 -0
@@ -49,3 +49,5 @@ obj-$(CONFIG_REGULATOR_RZG2L_USBPHY) += rzg2l-usbphy-regulator.o obj-$(CONFIG_$(PHASE_)DM_REGULATOR_CPCAP) += cpcap_regulator.o obj-$(CONFIG_DM_REGULATOR_MT6357) += mt6357_regulator.o obj-$(CONFIG_DM_REGULATOR_MT6359) += mt6359_regulator.o +obj-$(CONFIG_DM_REGULATOR_PMBUS_HELPER) += pmbus_helper.o +obj-$(CONFIG_DM_REGULATOR_PMBUS_GENERIC) += pmbus_generic.o
drivers/power/regulator/pmbus_generic.c new file +90 -0
90 lines not on this page · raw message
drivers/power/regulator/pmbus_helper.c new file +315 -0
315 lines not on this page · raw message
drivers/power/regulator/pmbus_helper.h new file +90 -0
90 lines not on this page · raw message
include/pmbus.h +37 -0
@@ -464,6 +464,43 @@ bool pmbus_word_command_supported(struct udevice *dev, u8 reg);void pmbus_print_telemetry (struct udevice *chip);void pmbus_print_status_word (struct udevice *chip); +/* +* Regulator -> thermal bridge. +* +* Read READ_TEMPERATURE_1 (8Dh) from a UCLASS_REGULATOR device that +* was bound by a pmbus_helper based chip driver, decode it through +* the chip's pmbus_driver_info (so the MPS DIRECT 1 degC/LSB quirk +* and the standard LINEAR11 encoding are both handled), select the +* regulator's PAGE first on multi rail parts, and return the result +* in millidegrees Celsius. +* +* This is what the generic drivers/thermal/pmbus_thermal.c companion +* calls on its parent; keeping the decode here avoids exposing the +* regulator-private pmbus_regulator_priv layout to other subsystems. +* +* Returns 0 on success, or a negative errno (-ENODEV if reg is not a +* probed pmbus regulator, -EIO on bus error). +*/ +int pmbus_regulator_read_temp (struct udevice *reg_dev,int *temp_mc); + +/* +* Look up the pmbus_driver_info of a probed UCLASS_REGULATOR device at +* (bus_seq, addr) that is driven by a pmbus_helper based chip driver +* (mpq8785, pmbus_generic, ...). Probes the device so its identify +* hook has run and format[] is populated, then returns its +* driver_info. Returns NULL if no such regulator is bound at that +* address, if the device is not a pmbus regulator, or if +* CONFIG_DM_REGULATOR_PMBUS_HELPER is disabled. +* +* Lets pmbus_set_active() -- and thus the pmbus CLI and the board +* boot snapshots -- reuse the rich, VOUT_MODE detected driver_info of +* a DT bound generic / chip regulator when the device is selected by +* raw <bus>:<addr> (which has no chip-match registry entry and would +* otherwise fall back to blanket LINEAR16 / LINEAR11 decoding). +*/ +const struct pmbus_driver_info *pmbus_regulator_info_by_addr (int bus_seq, +u8 addr); +/* * Status bit name decoding. *
lib/pmbus.c +17 -0
@@ -761,6 +761,23 @@ int pmbus_set_active(int bus_seq, u8 addr) sizeof(pmbus_active_state.vendor)); } +/* +* No MFR_ID chip-match (a spec compliant part with no per chip +* driver, e.g. a Flex / Delta PSU): if a generic / chip +* UCLASS_REGULATOR is bound at this address, reuse its +* VOUT_MODE detected driver_info so telemetry decodes through +* the right per class formats instead of the blanket +* LINEAR16 / LINEAR11 fallback. +*/ +if (CONFIG_IS_ENABLED (DM_REGULATOR_PMBUS_HELPER ) && + !pmbus_active_state.info) { +const struct pmbus_driver_info *di = +pmbus_regulator_info_by_addr (bus_seq, addr); + +if (di) + pmbus_active_state.info = di; + } +/* * MFR_MODEL / MFR_REVISION are best effort. Use the same byte * order the matched chip declared; if nothing matched, use the
Signature · 1 line
2.43.0
PATCH v3 3/7 power: regulator: add MPS MPQ8785 PMBus regulator driver
In reply to Vincent JardinPer-chip UCLASS_REGULATOR driver for the MPS MPQ8785 / MPM3695 / MPM3695-25 / MPM82504 family, layered on the shared pmbus_helper adapter. Runs Linux's mpq8785_identify() VOUT_MODE switch (LINEAR16 vs DIRECT m=64 R=1) at probe time, applies the optional mps,vout-fb-divider-ratio-permille DT property, and walks the documented MPS ADDR_VBOOT windows on MFR_ID failure so a die-revision address shift just works.
Publishes the pmbus mps last|clear last|clear force vendor extension subcommands (NVM PROTECTION_LAST read and clear) when CMD_PMBUS is enabled.
Adapted from Linux code.
---
Changes in v3:
- typo: Adaapted -> Adapted
MAINTAINERS | 1 + drivers/power/regulator/Kconfig | 9 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/mpq8785.c | 494 ++++++++++++++++++++++++++++++ 4 files changed, 505 insertions(+) create mode 100644 drivers/power/regulator/mpq8785.c
MAINTAINERS +1 -0
@@ -1585,6 +1585,7 @@ M: Vincent Jardin <[email protected]> S: Maintained F: cmd/pmbus.c F: doc/develop/pmbus.rst +F: drivers/power/regulator/mpq8785.c F: drivers/power/regulator/pmbus_generic.c F: drivers/power/regulator/pmbus_helper.c F: drivers/power/regulator/pmbus_helper.h
drivers/power/regulator/Kconfig +9 -0
@@ -581,3 +581,12 @@ config DM_REGULATOR_PMBUS_GENERIC per chip driver only when chip specific quirks (vendor registers, VID coercion, ADDR pin auto promotion, non standard m / b / R coefficients) need handling. + +config DM_REGULATOR_MPQ8785 + bool "MPS MPQ8785 / MPM3695 / MPM82504 PMBus voltage regulator" + depends on DM_REGULATOR_PMBUS_HELPER + help + Driver for the Monolithic Power Systems MPQ8785 family of + digital multiphase voltage regulators with PMBus. Supports + MPM3695, MPM3695-25, MPM82504, and MPQ8785. Adapted from the + Linux drivers/hwmon/pmbus/mpq8785.c reference.
drivers/power/regulator/Makefile +1 -0
@@ -51,3 +51,4 @@ obj-$(CONFIG_DM_REGULATOR_MT6357) += mt6357_regulator.o obj-$(CONFIG_DM_REGULATOR_MT6359) += mt6359_regulator.o obj-$(CONFIG_DM_REGULATOR_PMBUS_HELPER) += pmbus_helper.o obj-$(CONFIG_DM_REGULATOR_PMBUS_GENERIC) += pmbus_generic.o +obj-$(CONFIG_DM_REGULATOR_MPQ8785) += mpq8785.o
drivers/power/regulator/mpq8785.c new file +494 -0
494 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 4/7 board: nxp: vid: introduce PMBus framework support
In reply to Vincent JardinWire 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.
---
Changes in v3:
- vid_read_vout_mode(): avoid confusions error vs mode.
arch/Kconfig.nxp | 4 ++ board/nxp/common/vid.c | 110 +++++++++++++++++++++++------------------ board/nxp/common/vid.h | 15 +++--- 3 files changed, 74 insertions(+), 55 deletions(-)
arch/Kconfig.nxp +4 -0
@@ -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.
board/nxp/common/vid.c +61 -49
180 lines not on this page · raw message
board/nxp/common/vid.h +9 -6
@@ -22,8 +22,9 @@#define IR_VDD_STEP_UP 5/* LTC3882 */ -#define PMBUS_CMD_WRITE_PROTECT 0x10/* +* PMBUS_WRITE_PROTECT (10h) provided by <pmbus.h> +* * WRITE_PROTECT command supported values * 0x80: Disable all writes except WRITE_PROTECT, PAGE, * STORE_USER_ALL and MFR_EE_UNLOCK commands.
@@ -51,12 +52,14 @@#define VDD_MV_MAX 925#endif -/* PM Bus commands code for LTC3882*/ +/* +* PM Bus commands code for LTC3882. PMBUS_PAGE / PMBUS_READ_VOUT / +* PMBUS_VOUT_MODE / PMBUS_VOUT_COMMAND are provided by <pmbus.h>. +* PMBUS_CMD_PAGE_PLUS_WRITE (05h) is the LTC3882 SMBus block write +* transaction not in <pmbus.h>'s standard subset, so keep its +* definition here. +*/ #define PWM_CHANNEL0 0x0 -#define PMBUS_CMD_PAGE 0x0 -#define PMBUS_CMD_READ_VOUT 0x8B -#define PMBUS_CMD_VOUT_MODE 0x20 -#define PMBUS_CMD_VOUT_COMMAND 0x21#define PMBUS_CMD_PAGE_PLUS_WRITE 0x05 #if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS) || \
Signature · 1 line
2.43.0
PATCH v3 5/7 thermal: pmbus: add PMBus die-temp driver
In reply to Vincent JardinThe driver is a thin UCLASS_THERMAL: its get_temp reads the temperature of its parent regulator through the pmbus helper (READ_TEMPERATURE_1), without any chip-specific code.
---
(no changes since v1)
MAINTAINERS | 1 + drivers/thermal/Kconfig | 8 ++++++++ drivers/thermal/Makefile | 1 + drivers/thermal/pmbus_thermal.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 drivers/thermal/pmbus_thermal.c
MAINTAINERS +1 -0
@@ -1589,6 +1589,7 @@ F: drivers/power/regulator/mpq8785.c F: drivers/power/regulator/pmbus_generic.c F: drivers/power/regulator/pmbus_helper.c F: drivers/power/regulator/pmbus_helper.h +F: drivers/thermal/pmbus_thermal.c F: include/pmbus.h F: lib/pmbus.c
drivers/thermal/Kconfig +8 -0
@@ -55,4 +55,12 @@ config TI_LM74_THERMAL Enable thermal support for the Texas Instruments LM74 chip. The driver supports reading CPU temperature. +config PMBUS_THERMAL + bool "Generic PMBus temperature" + depends on DM_REGULATOR_PMBUS_HELPER + help + Expose the die-temperature reading of any PMBus voltage + regulator bound by a pmbus_helper based chip driver + as a UCLASS_THERMAL device. + endif # if DM_THERMAL
drivers/thermal/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-$(CONFIG_RCAR_GEN3_THERMAL) += rcar_gen3_thermal.o obj-$(CONFIG_SANDBOX) += thermal_sandbox.o obj-$(CONFIG_TI_DRA7_THERMAL) += ti-bandgap.o obj-$(CONFIG_TI_LM74_THERMAL) += ti-lm74.o +obj-$(CONFIG_PMBUS_THERMAL) += pmbus_thermal.o
drivers/thermal/pmbus_thermal.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2026 Free Mobile - Vincent Jardin +* +* Generic UCLASS_THERMAL companion for PMBus voltage regulators. +* +* Works with any chip bound by a pmbus_helper based regulator driver +* (drivers/power/regulator/<chip>.c calling +* pmbus_regulator_probe_common()). It auto-spawns one +* of these thermal devices per regulator. +* +* The reading is the chip's READ_TEMPERATURE_1 (PMBus 0x8D), decoded +* through the parent's pmbus_driver_info. +*/ + +#include <dm.h> +#include <pmbus.h> +#include <thermal.h> + +static int pmbus_thermal_get_temp (struct udevice *dev,int *temp) +{ +return pmbus_regulator_read_temp (dev_get_parent (dev), temp); +} + +static const struct dm_thermal_ops pmbus_thermal_ops = { + .get_temp = pmbus_thermal_get_temp, +}; + +U_BOOT_DRIVER (pmbus_thermal) = { + .name ="pmbus_thermal" , + .id =UCLASS_THERMAL , + .ops = &pmbus_thermal_ops, +};
Signature · 1 line
2.43.0
PATCH v3 6/7 test: dm: pmbus: add a sandbox PMBus chip emulator
In reply to Vincent JardinAdd a UCLASS_I2C_EMUL driver that emulates a PMBus 1.x compliant chip behind the sandbox I2C bus, plus the test.dts wiring and sandbox defconfig that bind it to the generic PMBus regulator (compatible = "pmbus"). This design is a stub only: it lets the follow-up dm unit test drive lib/pmbus.c, the generic regulator and the pmbus CLI command with no real hardware.
The emulator models a flat per-command 16-bit register file and the three identification block strings (MFR_ID / MFR_MODEL / MFR_REVISION). READ_IIN and READ_POUT are deliberately left unimplemented (the chip NAKs them) so the telemetry printer's "(not supported)" path is exercised, mirroring a real buck that only calibrates a subset of the sensor classes.
---
(no changes since v1)
MAINTAINERS | 1 + arch/sandbox/dts/test.dts | 10 ++ configs/sandbox_defconfig | 6 + drivers/power/regulator/Kconfig | 10 ++ drivers/power/regulator/Makefile | 1 + drivers/power/regulator/sandbox_pmbus.c | 160 ++++++++++++++++++++++++ 6 files changed, 188 insertions(+) create mode 100644 drivers/power/regulator/sandbox_pmbus.c
MAINTAINERS +1 -0
@@ -1589,6 +1589,7 @@ F: drivers/power/regulator/mpq8785.c F: drivers/power/regulator/pmbus_generic.c F: drivers/power/regulator/pmbus_helper.c F: drivers/power/regulator/pmbus_helper.h +F: drivers/power/regulator/sandbox_pmbus.c F: drivers/thermal/pmbus_thermal.c F: include/pmbus.h F: lib/pmbus.c
arch/sandbox/dts/test.dts +10 -0
@@ -1027,6 +1027,9 @@ emul1: emull { compatible = "sandbox,i2c-rtc-emul"; }; + emul_pmbus: emul-pmbus { + compatible = "sandbox,i2c-pmbus"; + }; }; sandbox_pmic: sandbox_pmic@40 {
@@ -1038,6 +1041,13 @@ reg = <0x41>; sandbox,emul = <&emul_pmic1>; }; + + pmbus@70 { + reg = <0x70>; + compatible = "pmbus"; + regulator-name = "sandbox-pmbus-vout"; + sandbox,emul = <&emul_pmbus>; + }; }; i3c0 {
configs/sandbox_defconfig +6 -0
@@ -392,3 +392,9 @@ CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +CONFIG_PMBUS=y +CONFIG_CMD_PMBUS=y +CONFIG_DM_REGULATOR_PMBUS_HELPER=y +CONFIG_DM_REGULATOR_PMBUS_GENERIC=y +CONFIG_SANDBOX_PMBUS=y +CONFIG_PMBUS_THERMAL=y
drivers/power/regulator/Kconfig +10 -0
@@ -590,3 +590,13 @@ config DM_REGULATOR_MPQ8785 digital multiphase voltage regulators with PMBus. Supports MPM3695, MPM3695-25, MPM82504, and MPQ8785. Adapted from the Linux drivers/hwmon/pmbus/mpq8785.c reference. + +config SANDBOX_PMBUS + bool "Sandbox PMBus 1.x chip emulator" + depends on SANDBOX && PMBUS && DM_I2C + help + Emulate a PMBus 1.x compliant chip behind a sandbox I2C bus so + the PMBus framework (lib/pmbus.c), the generic regulator + (DM_REGULATOR_PMBUS_GENERIC) and the pmbus CLI command can be + exercised by the dm unit tests with no real hardware. Only + useful for testing; say N on real boards.
drivers/power/regulator/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-$(CONFIG_DM_REGULATOR_MT6359) += mt6359_regulator.o obj-$(CONFIG_DM_REGULATOR_PMBUS_HELPER) += pmbus_helper.o obj-$(CONFIG_DM_REGULATOR_PMBUS_GENERIC) += pmbus_generic.o obj-$(CONFIG_DM_REGULATOR_MPQ8785) += mpq8785.o +obj-$(CONFIG_SANDBOX_PMBUS) += sandbox_pmbus.o
drivers/power/regulator/sandbox_pmbus.c new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 6/7] test: dm: pmbus: add a sandbox PMBus chip emulator
Hi Vincent,
Quoted 28 lines · Vincent Jardin
test: dm: pmbus: add a sandbox PMBus chip emulator
Add a
UCLASS_I2C_EMULdriver that emulates a PMBus 1.x compliant chip behind the sandbox I2C bus, plus thetest.dtswiring and sandbox defconfig that bind it to the generic PMBus regulator (compatible = 'pmbus'). This design is a stub only: it lets the follow-up dm unit test drivelib/pmbus.c, the generic regulator and the pmbus CLI command with no real hardware.The emulator models a flat per-command 16-bit register file and the three identification block strings (
MFR_ID/MFR_MODEL/MFR_REVISION).READ_IINandREAD_POUTare deliberately left unimplemented (the chip NAKs them) so the telemetry printer's "(not supported)" path is exercised, mirroring a real buck that only calibrates a subset of the sensor classes.Signed-off-by Vincent Jardin <[email protected]>
MAINTAINERS| 1 +arch/sandbox/dts/test.dts | 10 ++ configs/sandbox_defconfig | 6 ++ drivers/power/regulator/Kconfig | 10 ++ drivers/power/regulator/Makefile | 1 + drivers/power/regulator/sandbox_pmbus.c | 160 ++++++++++++++++++++++++++++++++ 6 files changed, 188 insertions(+)
configs/sandbox_defconfig CONFIG_UTHREAD=y · line 403
Quoted 9 lines
configs/sandbox_defconfig +6
-0@@ -395,3 +395,9 @@ CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +CONFIG_PMBUS=y +CONFIG_CMD_PMBUS=y +CONFIG_DM_REGULATOR_PMBUS_HELPER=y +CONFIG_DM_REGULATOR_PMBUS_GENERIC=y +CONFIG_SANDBOX_PMBUS=y +CONFIG_PMBUS_THERMAL=y
Please run 'make sandbox_defconfig savedefconfig' and copy the result back - these are appended rather than merged into Kconfig order. Tom does this sync from time to time, but having it approximately right will simplify that.
Quoted 7 lines
drivers/power/regulator/sandbox_pmbus.c +5
-0@@ -0,0 +1,160 @@ +static int sandbox_pmbus_read (struct sandbox_pmbus_priv *priv,u8 cmd, +u8 *buf,int len) +{ +const char *str =pmbus_emul_string (cmd); +int i;
drivers/power/regulator/sandbox_pmbus.c line 15
Quoted 10 lines
drivers/power/regulator/sandbox_pmbus.c +10
-0+ +if (str) { +int slen =strlen (str); + +/* Block payload: [length][bytes...]. */ + buf[0 ] = (u8 )slen; +for (i =1 ; i < len; i++) + buf[i] = (i -1 < slen) ? (u8 )str[i -1 ] :0 ; +return 0 ; + }
Two things. Please guard buf[0] with 'if (len < 1) return -EINVAL;' so a zero-length block read cannot walk off the buffer. Also, if a caller asks for fewer bytes than slen + 1 you still report the full length in buf[0] but return a truncated payload; either cap slen to len - 1 or reject the short read, otherwise the length byte lies.
drivers/power/regulator/sandbox_pmbus.c line 1
Quoted 3 lines
drivers/power/regulator/sandbox_pmbus.c +1
-0@@ -0,0 +1,160 @@ +sandbox_pmbus_support (priv,PMBUS_CAPABILITY ,0xb0 );
CAPABILITY 0xb0 advertises PEC (bit 7) and SMBALERT#, but the emulator does not implement PEC. Please either drop the PEC bit or add a comment noting the emulator is deliberately lying about it.
With those fixed:
Regards,
Simon
PATCH v3 7/7 test: dm: pmbus: test pmbus command and framework
In reply to Vincent JardinAdd dm unit tests that drive every pmbus subcommand handler against the sandbox PMBus chip emulator:
dev (select by bus:addr and by regulator-name), list, info, telemetry, status, dump, read, write, clear, vout, scan and help.
Tested using:
./u-boot -T -c "ut dm pmbus*"
---
(no changes since v1)
MAINTAINERS | 1 + test/dm/Makefile | 1 + test/dm/pmbus.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 test/dm/pmbus.c
MAINTAINERS +1 -0
@@ -1593,6 +1593,7 @@ F: drivers/power/regulator/sandbox_pmbus.c F: drivers/thermal/pmbus_thermal.c F: include/pmbus.h F: lib/pmbus.c +F: test/dm/pmbus.c POWER M: Jaehoon Chung <[email protected]>
test/dm/Makefile +1 -0
@@ -95,6 +95,7 @@ obj-$(CONFIG_PINCONF) += pinmux.o endif obj-$(CONFIG_POWER_DOMAIN) += power-domain.o obj-$(CONFIG_ACPI_PMC) += pmc.o +obj-$(CONFIG_CMD_PMBUS) += pmbus.o obj-$(CONFIG_DM_PMIC) += pmic.o obj-$(CONFIG_DM_PWM) += pwm.o obj-$(CONFIG_ARM_FFA_TRANSPORT) += ffa.o
test/dm/pmbus.c new file +247 -0
247 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 7/7] test: dm: pmbus: test pmbus command and framework
Hi Vincent,
Quoted 9 lines · Vincent Jardin
test: dm: pmbus: test pmbus command and framework
Add dm unit tests that drive every pmbus subcommand handler against the sandbox PMBus chip emulator:
dev (select by bus:addr and by regulator-name), list, info, telemetry, status, dump, read, write, clear, vout, scan and help.Tested using:
Quoted 8 lines
./u-boot -T -c "ut dm pmbus*"
Signed-off-by Vincent Jardin <[email protected]>
MAINTAINERS| 1 +test/dm/Makefile | 1 + test/dm/pmbus.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+)
I'll leave the biggest pmbus question to others, but this looks good. BTW you should not need the console_record_reset() calls at the end of functions, nor the 0x before what should be already-hex values in the commands.
Regards,
Simon