Skip to contentSkip to conversation

hwmon: add Raspberry Pi 5 PMIC driver

PATCH Superseded Sander Speetjens 3 participants 6 messages Nov 19 – Nov 22

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 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 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 (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]>
#1 lore raw

PATCH v4 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
index c9018fb4b009..41b7da5a19ea 100644
@@ -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
index bd408fc6f876..58b7dff5e636 100644
@@ -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
index dfb6fa4d4492..5dbc6b864f76 100644
@@ -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
index 20141eb2cb67..90d7b66b96e3 100644
@@ -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
#2 lore raw

Re: [PATCH v4 1/2] hwmon: add Raspberry Pi PMIC driver

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

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.

Quoted 8 lines

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

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v4 1/2
#3 lore raw

Re: [PATCH v4 1/2] hwmon: add Raspberry Pi PMIC driver

In reply to Sander Speetjens
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 8 lines
---
  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 +

This patch is making changes in a non-hwmon include file, so I can not apply it, or at least not without an Acked-by: from a maintainer.

Assuming it will be applied through some other tree,

Guenter

#4 lore raw

PATCH v4 2/2 firmware: raspberrypi: Register PMIC hwmon driver on Pi 5

In reply to Sander Speetjens

Register 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
index 68512224e3ce..a694ecc18f9c 100644
@@ -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
#5 lore raw

Re: [PATCH v4 2/2] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

Register 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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2