hwmon: add Raspberry Pi 5 PMIC driver
Subsystems (4)
v3 cover hwmon: add Raspberry Pi 5 PMIC driver
This patch adds an hwmon driver for the PMIC used on the Raspberry Pi 5.
The PMIC exposes a set of voltage, current and temperature sensors. Access is only available through the VideoCore firmware mailbox interface; there is no direct register access from the ARM side.
A structured property tag (0x0003009f) was recently added to the firmware. It returns the ADC values in binary form (index + length + array of values), which is much cleaner for a kernel driver than parsing the text output of the existing gencmd interface.
The driver follows the same instantiation pattern as the Raspberry Pi 5 RTC driver: the raspberrypi-firmware driver creates a platform device at runtime, and this driver binds to it. All channels are read in a single mailbox call and a short refresh-on-read cache is used.
The sensors are exposed through the standard hwmon sysfs interface so tools such as sensors, collectd and node-exporter work without modification.
Dependencies:
- Raspberry Pi firmware that implements property 0x0003009f
- CONFIG_RASPBERRYPI_FIRMWARE
Tested on a Raspberry Pi 5 with recent firmware.
---
Changes in v3:
- Fix sashiko reported bugs
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Add documenation
- Split firmware in a separate patch
- Remove DA9091 mention
- Remove extra lock
- Use 64-bit jiffies
- Remove lookup function
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Sander Speetjens (2):
hwmon: add Raspberry Pi PMIC driver
firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
Documentation/hwmon/index.rst | 1 + Documentation/hwmon/raspberrypi-pmic-hwmon.rst | 49 ++++ drivers/firmware/raspberrypi.c | 21 ++ drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/raspberrypi-pmic-hwmon.c | 296 +++++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 1 + 7 files changed, 380 insertions(+)
---
base-commit: 7d51eba9dfa7d30abab0b75570e9f7605366e45b
change-id: 20261117-hwmon-da9091-7aeeac6d8ef8
Best regards,
Signature · 1 line
Sander Speetjens <[email protected]>
PATCH v3 1/2 hwmon: add Raspberry Pi PMIC driver
Add a hwmon driver for the PMIC found on the Raspberry Pi 5. The PMIC exposes voltages, currents and temperatures exclusively through the VideoCore firmware mailbox interface (property 0x0003009f).
Requires a sufficiently recent Raspberry Pi firmware that implements the structured PMIC ADC property.
The driver:
- is instantiated at runtime by the raspberrypi-firmware driver (same pattern as the Pi 5 RTC driver)
- reads all channels in a single batch mailbox call
- uses a short refresh-on-read cache
- exposes the sensors via the standard hwmon sysfs interface
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/raspberrypi-pmic-hwmon.rst | 49 ++++ drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/raspberrypi-pmic-hwmon.c | 296 +++++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 1 + 6 files changed, 359 insertions(+)
Documentation/hwmon/index.rst +1 -0
@@ -245,6 +245,7 @@ Hardware Monitoring Kernel Drivers q54sj108a2 qnap-mcu-hwmon raspberrypi-hwmon + raspberrypi-pmic-hwmon sbrmi sbtsi_temp sch5627
Documentation/hwmon/raspberrypi-pmic-hwmon.rst new file +49 -0
49 lines not on this page · raw message
drivers/hwmon/Kconfig +11 -0
@@ -2076,6 +2076,17 @@ config SENSORS_RASPBERRYPI_HWMON This driver can also be built as a module. If so, the module will be called raspberrypi-hwmon. +config SENSORS_RASPBERRYPI_PMIC + tristate "Raspberry Pi PMIC monitor" + depends on RASPBERRYPI_FIRMWARE || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE) + help + If you say yes here you get support for the PMIC + voltage, current and temperature sensors on the Raspberry Pi 5, + accessed via the firmware mailbox interface. + + This driver can also be built as a module. If so, the module + will be called raspberrypi-pmic-hwmon. + config SENSORS_SL28CPLD tristate "Kontron sl28cpld hardware monitoring driver" depends on MFD_SL28CPLD || COMPILE_TEST
drivers/hwmon/Makefile +1 -0
@@ -214,6 +214,7 @@ obj-$(CONFIG_SENSORS_PT5161L) += pt5161l.o obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o obj-$(CONFIG_SENSORS_QNAP_MCU_HWMON) += qnap-mcu-hwmon.o obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o +obj-$(CONFIG_SENSORS_RASPBERRYPI_PMIC) += raspberrypi-pmic-hwmon.o obj-$(CONFIG_SENSORS_SBTSI) += sbtsi_temp.o obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o
drivers/hwmon/raspberrypi-pmic-hwmon.c new file +296 -0
296 lines not on this page · raw message
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
@@ -84,6 +84,7 @@ enum rpi_firmware_property_tag {RPI_FIRMWARE_GET_REBOOT_FLAGS =0x00030064 ,RPI_FIRMWARE_NOTIFY_DISPLAY_DONE =0x00030066 ,RPI_FIRMWARE_GET_RTC_REG =0x00030087 , +RPI_FIRMWARE_GET_PMIC_ADC =0x0003009f ,RPI_FIRMWARE_SET_CLOCK_STATE =0x00038001 ,RPI_FIRMWARE_SET_CLOCK_RATE =0x00038002 , RPI_FIRMWARE_SET_VOLTAGE = 0x00038003,
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v3 1/2] hwmon: add Raspberry Pi PMIC driver
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] hwmon: raspberrypi-pmic-hwmon: invalid hyphenated name in rpi_pmic_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] hwmon: raspberrypi-pmic-hwmon: invalid hyphenated name in rpi_pmic_probe()
--
commit bf488e2ad9a7e713389ee9ed507b4faae9e4ba88
Author: Sander Speetjens <[email protected]>
hwmon: add Raspberry Pi PMIC driver
This commit adds a hwmon driver for the Raspberry Pi 5 PMIC that reads voltages, currents and temperatures via the VideoCore firmware mailbox interface.
Quoted 5 lines
drivers/hwmon/raspberrypi-pmic-hwmon.c new file +0
-0
[ ... ]
Quoted 15 lines
drivers/hwmon/raspberrypi-pmic-hwmon.c new file +15
-0+static int rpi_pmic_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rpi_pmic_data *data; +struct rpi_firmware *fw; +struct device *hwmon_dev; +int ret; + + fw =devm_rpi_firmware_get (dev, dev->parent->of_node); +if (!fw) +return -EPROBE_DEFER ; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ;
drivers/hwmon/raspberrypi-pmic-hwmon.c line 274
Quoted 10 lines
drivers/hwmon/raspberrypi-pmic-hwmon.c new file +10
-0+ + data->fw = fw; + + ret =rpi_pmic_update (data); +if (ret) +return -ENODEV ; + + hwmon_dev = +devm_hwmon_device_register_with_info (dev, +"rpi-pmic" , data, &rpi_pmic_chip_info,NULL );
[Severity: Medium]
Should the hwmon chip name use an underscore ("rpi_pmic") instead of a hyphen?
__hwmon_device_register() rejects '-' in the name attribute with a dev_warn() ("hwmon: 'rpi-pmic' is not a valid name attribute, please fix") because userspace tools such as libsensors use '-' as a delimiter when parsing chip names.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/2 firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
In reply to Sander SpeetjensRegister the raspberrypi-pmic-hwmon platform device on BCM2712-based Raspberry Pi 5 systems, including the BCM2712 D0 revision.
Store the registered device in the firmware state and unregister it during driver removal
to ensure proper resource cleanup.
--- drivers/firmware/raspberrypi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/firmware/raspberrypi.c +21 -0
@@ -34,6 +34,7 @@ struct rpi_firmware {struct platform_device *hwmon_dev;struct platform_device *clk_dev; +struct platform_device *pmic_dev;struct platform_device *rtc_dev; };
@@ -249,6 +250,23 @@ static void rpi_register_clk_driver(struct device *dev, struct rpi_firmware *fw) fw->clk_dev = pdev; } +static void rpi_register_pmic_driver (struct device *dev,struct rpi_firmware *fw) +{ +struct platform_device *pdev; + +/* Only present on Pi 5 (bcm2712) */ +if (!(of_machine_is_compatible ("brcm,bcm2712" ) || +of_machine_is_compatible ("brcm,bcm2712-d0" ))) +return ; + + pdev =platform_device_register_data (dev,"raspberrypi-pmic-hwmon" , +-1 ,NULL ,0 ); +if (IS_ERR (pdev)) +return ; + + fw->pmic_dev = pdev; +} +static void rpi_register_rtc_driver (struct device *dev,struct rpi_firmware *fw) {struct platform_device *pdev;
@@ -371,6 +389,7 @@ static int rpi_firmware_probe(struct platform_device *pdev)rpi_firmware_print_firmware_revision (fw);rpi_register_hwmon_driver (dev, fw);rpi_register_clk_driver (dev, fw); +rpi_register_pmic_driver (dev, fw);rpi_register_rtc_driver (dev, fw);rpi_register_reboot_mode (dev, fw);
@@ -395,6 +414,8 @@ static void rpi_firmware_remove(struct platform_device *pdev) fw->hwmon_dev =NULL ;platform_device_unregister (fw->clk_dev); fw->clk_dev =NULL ; +platform_device_unregister (fw->pmic_dev); + fw->pmic_dev =NULL ;platform_device_unregister (fw->rtc_dev); fw->rtc_dev =NULL ;
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v3 2/2] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] hwmon: raspberrypi-pmic: invalid hyphen in hwmon name in rpi_pmic_probe() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] hwmon: raspberrypi-pmic: invalid hyphen in hwmon name in rpi_pmic_probe()
--
commit 9f0a6e3ed58944e55b16d88389defd31010b2d46
Author: Sander Speetjens <[email protected]>
firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
This commit registers and unregisters the raspberrypi-pmic-hwmon platform device on BCM2712-based Raspberry Pi 5 systems.
Quoted 4 lines
drivers/firmware/raspberrypi.c +0
-0
[ ... ]
Quoted 5 lines
drivers/firmware/raspberrypi.c +1
-0@@ -249,6 +250,23 @@ static void rpi_register_clk_driver(struct device *dev, struct rpi_firmware *fw) fw->clk_dev = pdev; } +static void rpi_register_pmic_driver (struct device *dev,struct rpi_firmware *fw)
drivers/firmware/raspberrypi.c static void rpi_register_clk_driver(struct device *dev, struct rpi_firmware *fw) · line 263
Quoted 10 lines
drivers/firmware/raspberrypi.c +10
-0+{ +struct platform_device *pdev; + +/* Only present on Pi 5 (bcm2712) */ +if (!(of_machine_is_compatible ("brcm,bcm2712" ) || +of_machine_is_compatible ("brcm,bcm2712-d0" ))) +return ; + + pdev =platform_device_register_data (dev,"raspberrypi-pmic-hwmon" , +-1 ,NULL ,0 );
[Severity: Medium]
Does registering the "raspberrypi-pmic-hwmon" device trigger a hwmon warning at boot because rpi_pmic_probe() registers a hwmon device with a hyphen in its name?
drivers/hwmon/raspberrypi-pmic-hwmon.c:rpi_pmic_probe() {
...
hwmon_dev =
devm_hwmon_device_register_with_info(dev,
"rpi-pmic", data, &rpi_pmic_chip_info, NULL);
...
}__hwmon_device_register() rejects '-' in hwmon chip names with a dev_warn() ("hwmon: 'rpi-pmic' is not a valid name attribute, please fix") because userspace tools such as libsensors use '-' as a chip-name delimiter.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2