hwmon: add Raspberry Pi 5 PMIC driver
Subsystems (4)
v7 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 v7:
- Fix check in firmware
- Remove initial error log in probe
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- Add a check before registering the driver
- Log mismatched msg len once
- Remove goto
- Add a log for the initial mbox call
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Split include into a separate patch
- Move the firmware registration before the driver
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Fix sashiko reported bug
- Link to v3: https://lore.kernel.org/r/[email protected]
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 (3):
soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag
firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
hwmon: add Raspberry Pi PMIC driver
Documentation/hwmon/index.rst | 1 + Documentation/hwmon/raspberrypi-pmic-hwmon.rst | 49 ++++ drivers/firmware/raspberrypi.c | 28 +++ drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/raspberrypi-pmic-hwmon.c | 298 +++++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 1 + 7 files changed, 389 insertions(+)
---
base-commit: 7d51eba9dfa7d30abab0b75570e9f7605366e45b
change-id: 20261117-hwmon-da9091-7aeeac6d8ef8
Best regards,
Signature · 1 line
Sander Speetjens <[email protected]>
PATCH v7 1/3 soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag
Add RPI_FIRMWARE_GET_PMIC_ADC (0x0003009f) to the firmware property tag enum.
Recent Raspberry Pi firmware exposes a structured mailbox property that returns PMIC ADC readings (voltages, currents and temperatures) in binary form[1]. This is required by the upcoming hwmon driver for the DA9091 PMIC on Raspberry Pi 5.
[1] https://forums.raspberrypi.com/viewtopic.php?p=2391319
--- include/soc/bcm2835/raspberrypi-firmware.h | 1 + 1 file changed, 1 insertion(+)
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
PATCH v7 2/3 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/firmware/raspberrypi.c +28 -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,30 @@ 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; +u32 packet[3 ] = {0 ,1 ,0 }; +int ret; + +/* Only present on Pi 5 (bcm2712) */ +if (!(of_machine_is_compatible ("brcm,bcm2712" ) || +of_machine_is_compatible ("brcm,bcm2712-d0" ))) +return ; + + ret =rpi_firmware_property (fw,RPI_FIRMWARE_GET_PMIC_ADC , + &packet,sizeof (packet)); +if (ret) +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 +396,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 +421,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
PATCH v7 3/3 hwmon: add Raspberry Pi PMIC driver
In reply to Sander SpeetjensAdd 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 | 298 +++++++++++++++++++++++++ 5 files changed, 360 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 +298 -0
298 lines not on this page · raw message
Signature · 1 line
2.56.1
Re: [PATCH v7 3/3] hwmon: add Raspberry Pi PMIC driver
Quoted 15 lines · Sander Speetjens
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
Quoted 2 lines
Reviewed-by Stefan Wahren <[email protected]>Signed-off-by Sander Speetjens <[email protected]>
Thanks,
Guenter
[email protected]
AI reviewSashiko has reviewed this 3-patch series and found no issues.
Sashiko has reviewed this 3-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]