pmbus: PMBus 1.x framework, CLI, regulator and thermal support
Subsystems (2)
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.
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 | 19 + arch/Kconfig.nxp | 4 + arch/sandbox/dts/test.dts | 10 + board/nxp/common/vid.c | 104 ++- 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 | 636 +++++++++++++ .../regulator/lltc,ltc3882.yaml | 91 ++ .../regulator/mps,mpq8785.yaml | 105 +++ doc/device-tree-bindings/regulator/pmbus.yaml | 65 ++ .../regulator/renesas,isl68233.yaml | 105 +++ 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 | 666 +++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 876 ++++++++++++++++++ test/dm/Makefile | 1 + test/dm/pmbus.c | 247 +++++ 31 files changed, 4982 insertions(+), 55 deletions(-) create mode 100644 cmd/pmbus.c create mode 100644 doc/develop/pmbus.rst create mode 100644 doc/device-tree-bindings/regulator/lltc,ltc3882.yaml create mode 100644 doc/device-tree-bindings/regulator/mps,mpq8785.yaml create mode 100644 doc/device-tree-bindings/regulator/pmbus.yaml create mode 100644 doc/device-tree-bindings/regulator/renesas,isl68233.yaml 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-v4
PATCH 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.
---
MAINTAINERS | 9 + cmd/Kconfig | 14 + cmd/Makefile | 1 + cmd/pmbus.c | 816 +++++++++++++++++ doc/develop/index.rst | 1 + doc/develop/pmbus.rst | 636 +++++++++++++ doc/device-tree-bindings/regulator/pmbus.yaml | 65 ++ include/pmbus.h | 629 +++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 859 ++++++++++++++++++ 11 files changed, 3047 insertions(+) create mode 100644 cmd/pmbus.c create mode 100644 doc/develop/pmbus.rst create mode 100644 doc/device-tree-bindings/regulator/pmbus.yaml create mode 100644 include/pmbus.h create mode 100644 lib/pmbus.c
MAINTAINERS +9 -0
@@ -1580,6 +1580,15 @@ 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: doc/device-tree-bindings/regulator/pmbus.yaml +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 +636 -0
636 lines not on this page · raw message
doc/device-tree-bindings/regulator/pmbus.yaml new file +65 -0
65 lines not on this page · raw message
include/pmbus.h new file +629 -0
629 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 +859 -0
776 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 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.
---
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
@@ -1586,6 +1586,9 @@ S: Maintained F: cmd/pmbus.c F: doc/develop/pmbus.rst F: doc/device-tree-bindings/regulator/pmbus.yaml +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 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.
Adaapted from Linux code.
---
MAINTAINERS | 2 + .../regulator/mps,mpq8785.yaml | 105 ++++ drivers/power/regulator/Kconfig | 9 + drivers/power/regulator/Makefile | 1 + drivers/power/regulator/mpq8785.c | 494 ++++++++++++++++++ 5 files changed, 611 insertions(+) create mode 100644 doc/device-tree-bindings/regulator/mps,mpq8785.yaml create mode 100644 drivers/power/regulator/mpq8785.c
MAINTAINERS +2 -0
@@ -1585,7 +1585,9 @@ M: Vincent Jardin <[email protected]> S: Maintained F: cmd/pmbus.c F: doc/develop/pmbus.rst +F: doc/device-tree-bindings/regulator/mps,mpq8785.yaml F: doc/device-tree-bindings/regulator/pmbus.yaml +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
doc/device-tree-bindings/regulator/mps,mpq8785.yaml new file +105 -0
105 lines not on this page · raw message
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 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.
---
MAINTAINERS | 2 + arch/Kconfig.nxp | 4 + board/nxp/common/vid.c | 104 +++++++++-------- board/nxp/common/vid.h | 15 ++- .../regulator/lltc,ltc3882.yaml | 91 +++++++++++++++ .../regulator/renesas,isl68233.yaml | 105 ++++++++++++++++++ 6 files changed, 266 insertions(+), 55 deletions(-) create mode 100644 doc/device-tree-bindings/regulator/lltc,ltc3882.yaml create mode 100644 doc/device-tree-bindings/regulator/renesas,isl68233.yaml
MAINTAINERS +2 -0
@@ -1585,8 +1585,10 @@ M: Vincent Jardin <[email protected]> S: Maintained F: cmd/pmbus.c F: doc/develop/pmbus.rst +F: doc/device-tree-bindings/regulator/lltc,ltc3882.yaml F: doc/device-tree-bindings/regulator/mps,mpq8785.yaml F: doc/device-tree-bindings/regulator/pmbus.yaml +F: doc/device-tree-bindings/regulator/renesas,isl68233.yaml F: drivers/power/regulator/mpq8785.c F: drivers/power/regulator/pmbus_generic.c F: drivers/power/regulator/pmbus_helper.c
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 +55 -49
174 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) || \
doc/device-tree-bindings/regulator/lltc,ltc3882.yaml new file +91 -0
91 lines not on this page · raw message
doc/device-tree-bindings/regulator/renesas,isl68233.yaml new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 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.
---
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
@@ -1593,6 +1593,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 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.
---
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
@@ -1593,6 +1593,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
Quoted 15 lines · Vincent Jardin
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 sharedUCLASS_REGULATORadapter plus a catch-all driver for compliant chips, add the MPS MPQ8785 per-chip driver
- a generic PMBus die-temperatureUCLASS_THERMALbridge
- 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.
[snip]
Quoted 4 lines
.../regulator/lltc,ltc3882.yaml | 91 ++ .../regulator/mps,mpq8785.yaml | 105 +++ doc/device-tree-bindings/regulator/pmbus.yaml | 65 ++ .../regulator/renesas,isl68233.yaml | 105 +++
We should be using, and referencing, the unmodified versions of these files in dts/upstream instead, thanks.
Signature · 1 line
Tom
Hi Tom,
Quoted 8 lines
[snip]
Quoted 4 lines
.../regulator/lltc,ltc3882.yaml | 91 ++ .../regulator/mps,mpq8785.yaml | 105 +++ doc/device-tree-bindings/regulator/pmbus.yaml | 65 ++ .../regulator/renesas,isl68233.yaml | 105 +++We should be using, and referencing, the unmodified versions of these files in dts/upstream instead, thanks.
thanks for this feedback, I did miss it.
I sent a v2 using the upstream yaml files.
Best regards,
Vincent
PS: the v2 was sent thru 2 waves since I had some smtp issues.
PATCH 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*"
---
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
@@ -1597,6 +1597,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
A message that is not in the archive (sent off-list or not yet received): "<[email protected]
v2 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 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 | 104 +-- 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 | 666 ++++++++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 876 ++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/pmbus.c | 247 +++++++ 27 files changed, 4609 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-v5
PATCH v2 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 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 | 629 +++++++++++++++++++++++++++++++ lib/Kconfig | 16 + lib/Makefile | 1 + lib/pmbus.c | 859 ++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2978 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 +629 -0
629 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 +859 -0
845 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.
Re: [PATCH v2 1/7] pmbus: add PMBus 1.x framework, CLI, and binding
Quoted 6 lines · Vincent Jardin
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_REGULATORadapter and per-chip drivers.
...
cmd/pmbus.c line 434
Quoted 5 lines
cmd/pmbus.c new file +5
-0+case PMBUS_MFR_REVISION : { +char s[PMBUS_MFR_STRING_MAX ]; + +if (pmbus_read_string (chip, reg, s,sizeof (s), + act->info ? false : false) >=0 )
Should be true : false or false: true?
Quoted 3 lines
cmd/pmbus.c new file +3
-0+printf (" %02xh %-15s s=\"%s\"\n" , + reg, pmbus_reg_syms[i].name, s); +
...
Quoted 12 lines
lib/pmbus.c new file +12
-0+int pmbus_read_string (struct udevice *dev,u8 cmd,char *out,int outsz, +bool reverse_bytes) +{ +u8 raw[PMBUS_MFR_STRING_MAX ]; +int ret, len, i; + +if (outsz <2 ) +return -EINVAL ; + +/* Stage 1: read the length byte. */ + ret =dm_i2c_read (dev, cmd, raw,1 ); +if (ret)
lib/pmbus.c line 268
Quoted 10 lines
lib/pmbus.c new file +10
-0+return ret; + + len = raw[0 ]; +if (len <=0 || len > (int )sizeof (raw)) +return -EBADMSG ; +if (len > outsz -1 ) + len = outsz -1 ; + +/* Stage 2: reread length + payload (some controllers mandate this). */ + ret =dm_i2c_read (dev, cmd, raw, len +1 );
When len is 16, len + 1 bytes are read, so corrupt u8 raw[].
lib/pmbus.c line 232
Quoted 3 lines
lib/pmbus.c new file +3
-0+if (ret) +return ret; +
Regards
Peng
Re: [PATCH v2 1/7] pmbus: add PMBus 1.x framework, CLI, and binding
Hi Peng,
Below some feedbacks on you reviews. More will be provided into a v3.
Quoted 4 lines
cmd/pmbus.c line 434
Quoted 2 lines
cmd/pmbus.c new file +2
-0+if (pmbus_read_string (chip, reg, s,sizeof (s), + act->info ? false : false) >=0 )Should be true : false or false: true?
hmm ;) it is a leftover, I'll clean it.
Quoted 3 lines
lib/pmbus.c line 268
Quoted 1 line
lib/pmbus.c new file +1
-0+ ret =dm_i2c_read (dev, cmd, raw, len +1 );When len is 16, len + 1 bytes are read, so corrupt u8 raw[].
right, I'll improve it for v3, thanks for detecting it.
best regards,
Vincent
PATCH v2 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 v2 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.
Adaapted from Linux code.
---
(no changes since v1)
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
Re: [PATCH v2 3/7] power: regulator: add MPS MPQ8785 PMBus regulator driver
Quoted 7 lines · Vincent Jardin
Per-chip
UCLASS_REGULATORdriver for the MPS MPQ8785 / MPM3695 / MPM3695-25 / MPM82504 family, layered on the sharedpmbus_helperadapter. Runs Linux'smpq8785_identify()VOUT_MODEswitch (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 MPSADDR_VBOOTwindows onMFR_IDfailure so a die-revision address shift just works.
Per reading the driver, only one MPS[X] is supported here. Are there cases that need multiple MPS?
Quoted 6 lines
Publishes the pmbus mps last|clear last|clear force vendor extension subcommands (NVM
PROTECTION_LASTread and clear) whenCMD_PMBUSis enabled.Adaapted from Linux code.
Typo.
Quoted 4 lines
Signed-off-by Vincent Jardin <[email protected]>---
Regards
Peng
Re: [PATCH v2 3/7] power: regulator: add MPS MPQ8785 PMBus regulator driver
Hi Peng,
Thanks for your comments, see below.
Quoted 2 lines
Per reading the driver, only one MPS[X] is supported here. Are there cases that need multiple MPS?
No, mulitiple MPS can be used and are supported, eaching having its own i2c/bus addresses/DT node. For instance, you'd need a MPS for the lx2160 and another MPS for an ASIC.
What is somehow unique is the CLI concept of "active" chip:
'pmbus dev'
selects one deviec for the following subcommands (telemetry, status, dump, etc...).
In fact, it follows the same way than i2c dev or mmc dev that I get inspired from.
Quoted 3 lines
Quoted 1 line
Adaapted from Linux code.
Typo.
Thanks, it'll be fixed into the v3 serie.
best regards,
Vincent
PATCH v2 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.
---
(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(-)
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 +55 -49
174 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
Re: [PATCH v2 4/7] board: nxp: vid: introduce PMBus framework support
Quoted 117 lines · Vincent Jardin
Wire
board/nxp/common/vid.cinto 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.cis 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.cprovides.The intent is to make
vid.can consumer of the new PMBus.Compatibility with the former support:
- CLI unchanged:
vdd_overrideandvdd_readkeep 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()andpmbus_data2reg_linear16()implement the PMBus 1.3 Part II mantissa/exponent.Signed-off-by Vincent Jardin <[email protected]>---
(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(-)arch/Kconfig.nxp +0
-0@@ -242,24 +242,28 @@ config VOL_MONITOR_IR36021_SETconfig
VOL_MONITOR_LTC3882_READ
bool "Enable the LTC3882 voltage monitor read"arch/Kconfig.nxp +1
-0+ select PMBUShelp
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"arch/Kconfig.nxp +1
-0+ select PMBUShelp
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"arch/Kconfig.nxp +1
-0+ select PMBUShelp
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"arch/Kconfig.nxp +1
-0+ select PMBUShelp
This option enables ISL68233 voltage monitor set functionality. It is used by the common VID driver.board/nxp/common/vid.c +15
-6@@ -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 ; }
...
Quoted 13 lines
board/nxp/common/vid.c +13
-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; + }
Quoted 1 line
return vout - board_vdd_drop_compensation();
When vid_read_vout_mode() returns 0, the return value here seems not correct.
Quoted 1 line
}
Regards,
Peng
Re: [PATCH v2 4/7] board: nxp: vid: introduce PMBus framework support
Hi Peng,
Quoted 2 lines
When
vid_read_vout_mode()returns 0, the return value here seems not correct.
thanks ! , fixed for the v3
PATCH v2 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 v2 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
PATCH v2 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