All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver
@ 2026-11-26 13:03 Sander Speetjens
  2026-11-26 13:03 ` [PATCH v5 1/3] soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag Sander Speetjens
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Sander Speetjens @ 2026-11-26 13:03 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Stefan Wahren, Guenter Roeck, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson, Sander Speetjens

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.

Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
Changes in v5:
- Split include into a separate patch 
- Move the firmware registration before the driver
- Link to v4: https://lore.kernel.org/r/20261119-hwmon-da9091-v4-0-0d6e345c3666@gmail.com

Changes in v4:
- Fix sashiko reported bug 
- Link to v3: https://lore.kernel.org/r/20261119-hwmon-da9091-v3-0-15956035d7b5@gmail.com

Changes in v3:
- Fix sashiko reported bugs
- Link to v2: https://lore.kernel.org/r/20261119-hwmon-da9091-v2-0-d6c624272a9e@gmail.com

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/20261117-hwmon-da9091-v1-1-f55f0af9c6a3@gmail.com

---
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                 |  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,
-- 
Sander Speetjens <sander.speetjens@gmail.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v5 1/3] soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag
  2026-11-26 13:03 [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
@ 2026-11-26 13:03 ` Sander Speetjens
  2026-11-26 13:03 ` [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5 Sander Speetjens
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Sander Speetjens @ 2026-11-26 13:03 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Stefan Wahren, Guenter Roeck, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson, Sander Speetjens

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
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
 include/soc/bcm2835/raspberrypi-firmware.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index 20141eb2cb67..90d7b66b96e3 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -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,

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
  2026-11-26 13:03 [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
  2026-11-26 13:03 ` [PATCH v5 1/3] soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag Sander Speetjens
@ 2026-11-26 13:03 ` Sander Speetjens
  2026-12-01 12:40   ` Stefan Wahren
  2026-11-26 13:03 ` [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver Sander Speetjens
  2026-11-26 13:12 ` [PATCH v5 0/3] hwmon: add Raspberry Pi 5 " sashiko-bot
  3 siblings, 1 reply; 9+ messages in thread
From: Sander Speetjens @ 2026-11-26 13:03 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Stefan Wahren, Guenter Roeck, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson, 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.

Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
 drivers/firmware/raspberrypi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
index 68512224e3ce..a694ecc18f9c 100644
--- a/drivers/firmware/raspberrypi.c
+++ b/drivers/firmware/raspberrypi.c
@@ -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;
 

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver
  2026-11-26 13:03 [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
  2026-11-26 13:03 ` [PATCH v5 1/3] soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag Sander Speetjens
  2026-11-26 13:03 ` [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5 Sander Speetjens
@ 2026-11-26 13:03 ` Sander Speetjens
  2026-12-01 13:02   ` Stefan Wahren
  2026-11-26 13:12 ` [PATCH v5 0/3] hwmon: add Raspberry Pi 5 " sashiko-bot
  3 siblings, 1 reply; 9+ messages in thread
From: Sander Speetjens @ 2026-11-26 13:03 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Stefan Wahren, Guenter Roeck, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson, 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

Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
---
 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 +++++++++++++++++++++++++
 5 files changed, 358 insertions(+)

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index c9018fb4b009..41b7da5a19ea 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -245,6 +245,7 @@ Hardware Monitoring Kernel Drivers
    q54sj108a2
    qnap-mcu-hwmon
    raspberrypi-hwmon
+   raspberrypi-pmic-hwmon
    sbrmi
    sbtsi_temp
    sch5627
diff --git a/Documentation/hwmon/raspberrypi-pmic-hwmon.rst b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
new file mode 100644
index 000000000000..000d85359515
--- /dev/null
+++ b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
@@ -0,0 +1,49 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver raspberrypi-pmic-hwmon
+=======================================
+
+Supported boards:
+
+  * Raspberry Pi 5 Model B
+  * Raspberry Pi Compute Module 5
+  * Raspberry Pi 500
+  * Raspberry Pi 500+
+
+Author: Sander Speetjens <sander.speetjens@gmail.com>
+
+Description
+-----------
+
+The Raspberry Pi 5 uses a PMIC that monitors supply voltages,
+currents and internal temperatures. These sensors are accessed
+via the VideoCore firmware mailbox (property 0x0003009f).
+
+This driver registers with the firmware device at runtime and exposes
+the ADC readings through the standard hwmon sysfs interface. All
+channels are read in a single mailbox transaction and cached for a
+short interval so concurrent or repeated sysfs reads do not generate
+excessive firmware traffic.
+
+Sysfs entries
+-------------
+
+======================= ======================================================
+curr[1-12]_input	Current in milliamps
+curr[1-12]_label	Current rail name
+in[0-13]_input		Voltage in millivolts
+in[0-13]_label		Voltage rail name
+temp[1-9]_input		Temperature in millidegrees Celsius
+temp[1-9]_label		Temperature sensor name
+======================= ======================================================
+
+Current and voltage labels follow the firmware naming (e.g. 3V3_SYS,
+VDD_CORE, EXT5V, BATT). Temperature labels are TEMP1–TEMP8 and TEMP_BG
+(bandgap reference).
+
+Notes
+-----
+
+The driver depends on Raspberry Pi firmware that implements the
+structured PMIC ADC property (0x0003009f). Older firmware will cause
+probe to fail when the property is unavailable.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index bd408fc6f876..58b7dff5e636 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -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
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index dfb6fa4d4492..5dbc6b864f76 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -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
diff --git a/drivers/hwmon/raspberrypi-pmic-hwmon.c b/drivers/hwmon/raspberrypi-pmic-hwmon.c
new file mode 100644
index 000000000000..ce1f6bf0d70e
--- /dev/null
+++ b/drivers/hwmon/raspberrypi-pmic-hwmon.c
@@ -0,0 +1,296 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Raspberry Pi 5 PMIC hwmon driver
+ *
+ * Reads voltages, currents and temperatures through the VideoCore
+ * firmware mailbox property
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/hwmon.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+#define RPI_PMIC_NUM_CHANNELS	35	/* 0..34 */
+#define RPI_PMIC_CACHE_MS	500
+
+struct rpi_pmic_data {
+	struct rpi_firmware *fw;
+	u32 values[RPI_PMIC_NUM_CHANNELS];
+	u64 last_update;
+};
+
+struct rpi_pmic_adc_msg {
+	__le32 index;
+	__le32 length;
+	__le32 values[RPI_PMIC_NUM_CHANNELS];
+} __packed;
+
+static const char * const rpi_pmic_labels[RPI_PMIC_NUM_CHANNELS] = {
+	/* Currents 0-7 */
+	[0]  = "3V7_WL_SW",
+	[1]  = "3V3_SYS",
+	[2]  = "1V8_SYS",
+	[3]  = "DDR_VDD2",
+	[4]  = "DDR_VDDQ",
+	[5]  = "1V1_SYS",
+	[6]  = "0V8_SW",
+	[7]  = "VDD_CORE",
+	/* Voltages 8-15 */
+	[8]  = "3V7_WL_SW",
+	[9]  = "3V3_SYS",
+	[10] = "1V8_SYS",
+	[11] = "DDR_VDD2",
+	[12] = "DDR_VDDQ",
+	[13] = "1V1_SYS",
+	[14] = "0V8_SW",
+	[15] = "VDD_CORE",
+	/* More currents / voltages */
+	[16] = "0V8_AON",
+	[17] = "3V3_DAC",
+	[18] = "3V3_ADC",
+	[19] = "0V8_AON",
+	[20] = "3V3_DAC",
+	[21] = "3V3_ADC",
+	[22] = "HDMI",
+	[23] = "HDMI",
+	[24] = "EXT5V",
+	[25] = "BATT",
+	/* Temperatures 26-34 (µ°C) */
+	[26] = "TEMP1",
+	[27] = "TEMP2",
+	[28] = "TEMP3",
+	[29] = "TEMP4",
+	[30] = "TEMP5",
+	[31] = "TEMP6",
+	[32] = "TEMP7",
+	[33] = "TEMP8",
+	[34] = "TEMP_BG",
+};
+
+/* Firmware ADC indices for each hwmon channel */
+static const u8 rpi_pmic_curr_idx[] = {
+	0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 22
+};
+
+static const u8 rpi_pmic_in_idx[] = {
+	8, 9, 10, 11, 12, 13, 14, 15, 19, 20, 21, 23, 24, 25
+};
+
+static const u8 rpi_pmic_temp_idx[] = {
+	26, 27, 28, 29, 30, 31, 32, 33, 34
+};
+
+static int rpi_pmic_update(struct rpi_pmic_data *data)
+{
+	struct rpi_pmic_adc_msg msg = {
+		.index  = cpu_to_le32(0),
+		.length = cpu_to_le32(RPI_PMIC_NUM_CHANNELS),
+	};
+	int ret;
+	unsigned int i;
+
+	ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_PMIC_ADC,
+				    &msg, sizeof(msg));
+	if (ret)
+		return ret;
+
+	/* Sanity-check the response */
+	if (le32_to_cpu(msg.length) != RPI_PMIC_NUM_CHANNELS)
+		return -EIO;
+
+	for (i = 0; i < RPI_PMIC_NUM_CHANNELS; i++)
+		data->values[i] = le32_to_cpu(msg.values[i]);
+
+	data->last_update = get_jiffies_64();
+	return 0;
+}
+
+static int rpi_pmic_read(struct device *dev, enum hwmon_sensor_types type,
+			 u32 attr, int channel, long *val)
+{
+	struct rpi_pmic_data *data = dev_get_drvdata(dev);
+	int ret = 0;
+
+	if (time_after64(get_jiffies_64(),
+			 data->last_update + msecs_to_jiffies(RPI_PMIC_CACHE_MS))) {
+		ret = rpi_pmic_update(data);
+		if (ret)
+			goto out;
+	}
+
+	switch (type) {
+	case hwmon_in:
+		*val = data->values[rpi_pmic_in_idx[channel]] / 1000;	/* µV → mV */
+		break;
+	case hwmon_curr:
+		*val = data->values[rpi_pmic_curr_idx[channel]] / 1000;	/* µA → mA */
+		break;
+	case hwmon_temp:
+		*val = data->values[rpi_pmic_temp_idx[channel]] / 1000;	/* µ°C → m°C */
+		break;
+	default:
+		ret = -EOPNOTSUPP;
+	}
+
+out:
+	return ret;
+}
+
+static int rpi_pmic_read_string(struct device *dev,
+				enum hwmon_sensor_types type, u32 attr,
+				int channel, const char **str)
+{
+	size_t idx;
+
+	switch (type) {
+	case hwmon_in:
+		idx = rpi_pmic_in_idx[channel];
+		break;
+	case hwmon_curr:
+		idx = rpi_pmic_curr_idx[channel];
+		break;
+	case hwmon_temp:
+		idx = rpi_pmic_temp_idx[channel];
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	*str = rpi_pmic_labels[idx];
+	return 0;
+}
+
+static umode_t rpi_pmic_is_visible(const void *data,
+				   enum hwmon_sensor_types type,
+				   u32 attr, int channel)
+{
+	switch (type) {
+	case hwmon_in:
+		if (channel < ARRAY_SIZE(rpi_pmic_in_idx) &&
+		    (attr == hwmon_in_input || attr == hwmon_in_label))
+			return 0444;
+		break;
+	case hwmon_curr:
+		if (channel < ARRAY_SIZE(rpi_pmic_curr_idx) &&
+		    (attr == hwmon_curr_input || attr == hwmon_curr_label))
+			return 0444;
+		break;
+	case hwmon_temp:
+		if (channel < ARRAY_SIZE(rpi_pmic_temp_idx) &&
+		    (attr == hwmon_temp_input || attr == hwmon_temp_label))
+			return 0444;
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+static const struct hwmon_ops rpi_pmic_ops = {
+	.is_visible	= rpi_pmic_is_visible,
+	.read		= rpi_pmic_read,
+	.read_string	= rpi_pmic_read_string,
+};
+
+static const struct hwmon_channel_info * const rpi_pmic_info[] = {
+	HWMON_CHANNEL_INFO(in,
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/*  8 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/*  9 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 10 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 11 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 12 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 13 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 14 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 15 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 19 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 20 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 21 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 23 */
+			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 24 */
+			   HWMON_I_INPUT | HWMON_I_LABEL	/* 25 */
+	),
+	HWMON_CHANNEL_INFO(curr,
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  0 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  1 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  2 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  3 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  4 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  5 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  6 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  7 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 16 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 17 */
+			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 18 */
+			   HWMON_C_INPUT | HWMON_C_LABEL	/* 22 */
+	),
+	HWMON_CHANNEL_INFO(temp,
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 26 TEMP1 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 27 TEMP2 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 28 TEMP3 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 29 TEMP4 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 30 TEMP5 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 31 TEMP6 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 32 TEMP7 */
+			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 33 TEMP8 */
+			   HWMON_T_INPUT | HWMON_T_LABEL	/* 34 TEMP_BG */
+	),
+	NULL
+};
+
+static const struct hwmon_chip_info rpi_pmic_chip_info = {
+	.ops	= &rpi_pmic_ops,
+	.info	= rpi_pmic_info,
+};
+
+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;
+
+	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);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static const struct platform_device_id rpi_pmic_id[] = {
+	{ "raspberrypi-pmic-hwmon", },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, rpi_pmic_id);
+
+static struct platform_driver rpi_pmic_driver = {
+	.probe = rpi_pmic_probe,
+	.driver = {
+		.name = "raspberrypi-pmic-hwmon",
+	},
+	.id_table = rpi_pmic_id,
+};
+module_platform_driver(rpi_pmic_driver);
+
+MODULE_AUTHOR("Sander Speetjens <sander.speetjens@gmail.com>");
+MODULE_DESCRIPTION("Raspberry Pi 5 PMIC hwmon driver");
+MODULE_LICENSE("GPL");

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver
  2026-11-26 13:03 [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
                   ` (2 preceding siblings ...)
  2026-11-26 13:03 ` [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver Sander Speetjens
@ 2026-11-26 13:12 ` sashiko-bot
  3 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26 13:12 UTC (permalink / raw)
  To: Sander Speetjens; +Cc: linux-hwmon

Sashiko has reviewed this 3-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-hwmon-da9091-v5-0-0c3570ba9133@gmail.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5
  2026-11-26 13:03 ` [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5 Sander Speetjens
@ 2026-12-01 12:40   ` Stefan Wahren
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Wahren @ 2026-12-01 12:40 UTC (permalink / raw)
  To: Sander Speetjens, Florian Fainelli,
	Broadcom internal kernel review list, Guenter Roeck, Ray Jui,
	Scott Branden, Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson

Hi Sander,

Am 26.11.26 um 14:03 schrieb 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.
>
> Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
> ---
>   drivers/firmware/raspberrypi.c | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
>
> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index 68512224e3ce..a694ecc18f9c 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
> @@ -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;
since the PMIC hwmon driver rely on the recently added 
RPI_FIRMWARE_GET_PMIC_ADC, I suggest to check the function of the 
firmware tag before registering the driver just like the other hwmon 
driver does. I don't know the behavior on non-Pi 5 platforms, but maybe 
this also could replace these of_machine_is_compatible() checks?

Best regards

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver
  2026-11-26 13:03 ` [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver Sander Speetjens
@ 2026-12-01 13:02   ` Stefan Wahren
  2026-12-01 17:21     ` Guenter Roeck
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Wahren @ 2026-12-01 13:02 UTC (permalink / raw)
  To: Sander Speetjens, Florian Fainelli,
	Broadcom internal kernel review list, Guenter Roeck, Ray Jui,
	Scott Branden, Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson

Hi Sander,

Am 26.11.26 um 14:03 schrieb 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
>
> Acked-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
> ---
>   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 +++++++++++++++++++++++++
>   5 files changed, 358 insertions(+)
>
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index c9018fb4b009..41b7da5a19ea 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -245,6 +245,7 @@ Hardware Monitoring Kernel Drivers
>      q54sj108a2
>      qnap-mcu-hwmon
>      raspberrypi-hwmon
> +   raspberrypi-pmic-hwmon
>      sbrmi
>      sbtsi_temp
>      sch5627
> diff --git a/Documentation/hwmon/raspberrypi-pmic-hwmon.rst b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
> new file mode 100644
> index 000000000000..000d85359515
> --- /dev/null
> +++ b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
> @@ -0,0 +1,49 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +Kernel driver raspberrypi-pmic-hwmon
> +=======================================
> +
> +Supported boards:
> +
> +  * Raspberry Pi 5 Model B
> +  * Raspberry Pi Compute Module 5
> +  * Raspberry Pi 500
> +  * Raspberry Pi 500+
> +
> +Author: Sander Speetjens <sander.speetjens@gmail.com>
> +
> +Description
> +-----------
> +
> +The Raspberry Pi 5 uses a PMIC that monitors supply voltages,
> +currents and internal temperatures. These sensors are accessed
> +via the VideoCore firmware mailbox (property 0x0003009f).
> +
> +This driver registers with the firmware device at runtime and exposes
> +the ADC readings through the standard hwmon sysfs interface. All
> +channels are read in a single mailbox transaction and cached for a
> +short interval so concurrent or repeated sysfs reads do not generate
> +excessive firmware traffic.
> +
> +Sysfs entries
> +-------------
> +
> +======================= ======================================================
> +curr[1-12]_input	Current in milliamps
> +curr[1-12]_label	Current rail name
> +in[0-13]_input		Voltage in millivolts
> +in[0-13]_label		Voltage rail name
> +temp[1-9]_input		Temperature in millidegrees Celsius
> +temp[1-9]_label		Temperature sensor name
> +======================= ======================================================
> +
> +Current and voltage labels follow the firmware naming (e.g. 3V3_SYS,
> +VDD_CORE, EXT5V, BATT). Temperature labels are TEMP1–TEMP8 and TEMP_BG
> +(bandgap reference).
> +
> +Notes
> +-----
> +
> +The driver depends on Raspberry Pi firmware that implements the
> +structured PMIC ADC property (0x0003009f). Older firmware will cause
> +probe to fail when the property is unavailable.
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index bd408fc6f876..58b7dff5e636 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -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
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index dfb6fa4d4492..5dbc6b864f76 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -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
> diff --git a/drivers/hwmon/raspberrypi-pmic-hwmon.c b/drivers/hwmon/raspberrypi-pmic-hwmon.c
> new file mode 100644
> index 000000000000..ce1f6bf0d70e
> --- /dev/null
> +++ b/drivers/hwmon/raspberrypi-pmic-hwmon.c
> @@ -0,0 +1,296 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Raspberry Pi 5 PMIC hwmon driver
> + *
> + * Reads voltages, currents and temperatures through the VideoCore
> + * firmware mailbox property
> + */
> +
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/hwmon.h>
> +#include <linux/jiffies.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <soc/bcm2835/raspberrypi-firmware.h>
> +
> +#define RPI_PMIC_NUM_CHANNELS	35	/* 0..34 */
> +#define RPI_PMIC_CACHE_MS	500
> +
> +struct rpi_pmic_data {
> +	struct rpi_firmware *fw;
> +	u32 values[RPI_PMIC_NUM_CHANNELS];
> +	u64 last_update;
> +};
> +
> +struct rpi_pmic_adc_msg {
> +	__le32 index;
> +	__le32 length;
> +	__le32 values[RPI_PMIC_NUM_CHANNELS];
> +} __packed;
> +
> +static const char * const rpi_pmic_labels[RPI_PMIC_NUM_CHANNELS] = {
> +	/* Currents 0-7 */
> +	[0]  = "3V7_WL_SW",
> +	[1]  = "3V3_SYS",
> +	[2]  = "1V8_SYS",
> +	[3]  = "DDR_VDD2",
> +	[4]  = "DDR_VDDQ",
> +	[5]  = "1V1_SYS",
> +	[6]  = "0V8_SW",
> +	[7]  = "VDD_CORE",
> +	/* Voltages 8-15 */
> +	[8]  = "3V7_WL_SW",
> +	[9]  = "3V3_SYS",
> +	[10] = "1V8_SYS",
> +	[11] = "DDR_VDD2",
> +	[12] = "DDR_VDDQ",
> +	[13] = "1V1_SYS",
> +	[14] = "0V8_SW",
> +	[15] = "VDD_CORE",
> +	/* More currents / voltages */
> +	[16] = "0V8_AON",
> +	[17] = "3V3_DAC",
> +	[18] = "3V3_ADC",
> +	[19] = "0V8_AON",
> +	[20] = "3V3_DAC",
> +	[21] = "3V3_ADC",
> +	[22] = "HDMI",
> +	[23] = "HDMI",
> +	[24] = "EXT5V",
> +	[25] = "BATT",
> +	/* Temperatures 26-34 (µ°C) */
> +	[26] = "TEMP1",
> +	[27] = "TEMP2",
> +	[28] = "TEMP3",
> +	[29] = "TEMP4",
> +	[30] = "TEMP5",
> +	[31] = "TEMP6",
> +	[32] = "TEMP7",
> +	[33] = "TEMP8",
> +	[34] = "TEMP_BG",
> +};
> +
> +/* Firmware ADC indices for each hwmon channel */
> +static const u8 rpi_pmic_curr_idx[] = {
> +	0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 22
> +};
> +
> +static const u8 rpi_pmic_in_idx[] = {
> +	8, 9, 10, 11, 12, 13, 14, 15, 19, 20, 21, 23, 24, 25
> +};
> +
> +static const u8 rpi_pmic_temp_idx[] = {
> +	26, 27, 28, 29, 30, 31, 32, 33, 34
> +};
> +
> +static int rpi_pmic_update(struct rpi_pmic_data *data)
> +{
> +	struct rpi_pmic_adc_msg msg = {
> +		.index  = cpu_to_le32(0),
> +		.length = cpu_to_le32(RPI_PMIC_NUM_CHANNELS),
> +	};
> +	int ret;
> +	unsigned int i;
> +
> +	ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_PMIC_ADC,
> +				    &msg, sizeof(msg));
> +	if (ret)
> +		return ret;
> +
> +	/* Sanity-check the response */
> +	if (le32_to_cpu(msg.length) != RPI_PMIC_NUM_CHANNELS)
> +		return -EIO;
Maybe we should log this mismatch once?
> +
> +	for (i = 0; i < RPI_PMIC_NUM_CHANNELS; i++)
> +		data->values[i] = le32_to_cpu(msg.values[i]);
> +
> +	data->last_update = get_jiffies_64();
> +	return 0;
> +}
> +
> +static int rpi_pmic_read(struct device *dev, enum hwmon_sensor_types type,
> +			 u32 attr, int channel, long *val)
> +{
> +	struct rpi_pmic_data *data = dev_get_drvdata(dev);
> +	int ret = 0;
> +
> +	if (time_after64(get_jiffies_64(),
> +			 data->last_update + msecs_to_jiffies(RPI_PMIC_CACHE_MS))) {
> +		ret = rpi_pmic_update(data);
> +		if (ret)
> +			goto out;
In case we don't want to log this case, we can eliminate ret and the goto.
> +	}
> +
> +	switch (type) {
> +	case hwmon_in:
> +		*val = data->values[rpi_pmic_in_idx[channel]] / 1000;	/* µV → mV */
> +		break;
> +	case hwmon_curr:
> +		*val = data->values[rpi_pmic_curr_idx[channel]] / 1000;	/* µA → mA */
> +		break;
> +	case hwmon_temp:
> +		*val = data->values[rpi_pmic_temp_idx[channel]] / 1000;	/* µ°C → m°C */
> +		break;
> +	default:
> +		ret = -EOPNOTSUPP;
> +	}
> +
> +out:
> +	return ret;
> +}
> +
> +static int rpi_pmic_read_string(struct device *dev,
> +				enum hwmon_sensor_types type, u32 attr,
> +				int channel, const char **str)
> +{
> +	size_t idx;
> +
> +	switch (type) {
> +	case hwmon_in:
> +		idx = rpi_pmic_in_idx[channel];
> +		break;
> +	case hwmon_curr:
> +		idx = rpi_pmic_curr_idx[channel];
> +		break;
> +	case hwmon_temp:
> +		idx = rpi_pmic_temp_idx[channel];
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	*str = rpi_pmic_labels[idx];
> +	return 0;
> +}
> +
> +static umode_t rpi_pmic_is_visible(const void *data,
> +				   enum hwmon_sensor_types type,
> +				   u32 attr, int channel)
> +{
> +	switch (type) {
> +	case hwmon_in:
> +		if (channel < ARRAY_SIZE(rpi_pmic_in_idx) &&
> +		    (attr == hwmon_in_input || attr == hwmon_in_label))
> +			return 0444;
> +		break;
> +	case hwmon_curr:
> +		if (channel < ARRAY_SIZE(rpi_pmic_curr_idx) &&
> +		    (attr == hwmon_curr_input || attr == hwmon_curr_label))
> +			return 0444;
> +		break;
> +	case hwmon_temp:
> +		if (channel < ARRAY_SIZE(rpi_pmic_temp_idx) &&
> +		    (attr == hwmon_temp_input || attr == hwmon_temp_label))
> +			return 0444;
> +		break;
> +	default:
> +		break;
> +	}
> +	return 0;
> +}
> +
> +static const struct hwmon_ops rpi_pmic_ops = {
> +	.is_visible	= rpi_pmic_is_visible,
> +	.read		= rpi_pmic_read,
> +	.read_string	= rpi_pmic_read_string,
> +};
> +
> +static const struct hwmon_channel_info * const rpi_pmic_info[] = {
> +	HWMON_CHANNEL_INFO(in,
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/*  8 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/*  9 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 10 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 11 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 12 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 13 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 14 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 15 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 19 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 20 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 21 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 23 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL,	/* 24 */
> +			   HWMON_I_INPUT | HWMON_I_LABEL	/* 25 */
> +	),
> +	HWMON_CHANNEL_INFO(curr,
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  0 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  1 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  2 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  3 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  4 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  5 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  6 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/*  7 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 16 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 17 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL,	/* 18 */
> +			   HWMON_C_INPUT | HWMON_C_LABEL	/* 22 */
> +	),
> +	HWMON_CHANNEL_INFO(temp,
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 26 TEMP1 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 27 TEMP2 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 28 TEMP3 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 29 TEMP4 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 30 TEMP5 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 31 TEMP6 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 32 TEMP7 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL,	/* 33 TEMP8 */
> +			   HWMON_T_INPUT | HWMON_T_LABEL	/* 34 TEMP_BG */
> +	),
> +	NULL
> +};
> +
> +static const struct hwmon_chip_info rpi_pmic_chip_info = {
> +	.ops	= &rpi_pmic_ops,
> +	.info	= rpi_pmic_info,
> +};
> +
> +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;
> +
> +	data->fw = fw;
> +
> +	ret = rpi_pmic_update(data);
> +	if (ret)
> +		return -ENODEV;
I think it would be helpful to log this case.
> +
> +	hwmon_dev =
> +		devm_hwmon_device_register_with_info(dev,
> +						     "rpi_pmic", data, &rpi_pmic_chip_info, NULL);
> +
> +	return PTR_ERR_OR_ZERO(hwmon_dev);
> +}
> +
> +static const struct platform_device_id rpi_pmic_id[] = {
> +	{ "raspberrypi-pmic-hwmon", },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(platform, rpi_pmic_id);
> +
> +static struct platform_driver rpi_pmic_driver = {
> +	.probe = rpi_pmic_probe,
> +	.driver = {
> +		.name = "raspberrypi-pmic-hwmon",
> +	},
> +	.id_table = rpi_pmic_id,
> +};
> +module_platform_driver(rpi_pmic_driver);
> +
> +MODULE_AUTHOR("Sander Speetjens <sander.speetjens@gmail.com>");
> +MODULE_DESCRIPTION("Raspberry Pi 5 PMIC hwmon driver");
> +MODULE_LICENSE("GPL");
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver
  2026-12-01 13:02   ` Stefan Wahren
@ 2026-12-01 17:21     ` Guenter Roeck
  2026-12-01 18:24       ` Stefan Wahren
  0 siblings, 1 reply; 9+ messages in thread
From: Guenter Roeck @ 2026-12-01 17:21 UTC (permalink / raw)
  To: Stefan Wahren, Sander Speetjens, Florian Fainelli,
	Broadcom internal kernel review list, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson

On 12/1/26 05:02, Stefan Wahren wrote:
> Hi Sander,
> 
> Am 26.11.26 um 14:03 schrieb 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
>>
>> Acked-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Sander Speetjens <sander.speetjens@gmail.com>
>> ---
>>   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 +++++++++++++++++++++++++
>>   5 files changed, 358 insertions(+)
>>
>> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
>> index c9018fb4b009..41b7da5a19ea 100644
>> --- a/Documentation/hwmon/index.rst
>> +++ b/Documentation/hwmon/index.rst
>> @@ -245,6 +245,7 @@ Hardware Monitoring Kernel Drivers
>>      q54sj108a2
>>      qnap-mcu-hwmon
>>      raspberrypi-hwmon
>> +   raspberrypi-pmic-hwmon
>>      sbrmi
>>      sbtsi_temp
>>      sch5627
>> diff --git a/Documentation/hwmon/raspberrypi-pmic-hwmon.rst b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
>> new file mode 100644
>> index 000000000000..000d85359515
>> --- /dev/null
>> +++ b/Documentation/hwmon/raspberrypi-pmic-hwmon.rst
>> @@ -0,0 +1,49 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +Kernel driver raspberrypi-pmic-hwmon
>> +=======================================
>> +
>> +Supported boards:
>> +
>> +  * Raspberry Pi 5 Model B
>> +  * Raspberry Pi Compute Module 5
>> +  * Raspberry Pi 500
>> +  * Raspberry Pi 500+
>> +
>> +Author: Sander Speetjens <sander.speetjens@gmail.com>
>> +
>> +Description
>> +-----------
>> +
>> +The Raspberry Pi 5 uses a PMIC that monitors supply voltages,
>> +currents and internal temperatures. These sensors are accessed
>> +via the VideoCore firmware mailbox (property 0x0003009f).
>> +
>> +This driver registers with the firmware device at runtime and exposes
>> +the ADC readings through the standard hwmon sysfs interface. All
>> +channels are read in a single mailbox transaction and cached for a
>> +short interval so concurrent or repeated sysfs reads do not generate
>> +excessive firmware traffic.
>> +
>> +Sysfs entries
>> +-------------
>> +
>> +======================= ======================================================
>> +curr[1-12]_input    Current in milliamps
>> +curr[1-12]_label    Current rail name
>> +in[0-13]_input        Voltage in millivolts
>> +in[0-13]_label        Voltage rail name
>> +temp[1-9]_input        Temperature in millidegrees Celsius
>> +temp[1-9]_label        Temperature sensor name
>> +======================= ======================================================
>> +
>> +Current and voltage labels follow the firmware naming (e.g. 3V3_SYS,
>> +VDD_CORE, EXT5V, BATT). Temperature labels are TEMP1–TEMP8 and TEMP_BG
>> +(bandgap reference).
>> +
>> +Notes
>> +-----
>> +
>> +The driver depends on Raspberry Pi firmware that implements the
>> +structured PMIC ADC property (0x0003009f). Older firmware will cause
>> +probe to fail when the property is unavailable.
>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>> index bd408fc6f876..58b7dff5e636 100644
>> --- a/drivers/hwmon/Kconfig
>> +++ b/drivers/hwmon/Kconfig
>> @@ -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
>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>> index dfb6fa4d4492..5dbc6b864f76 100644
>> --- a/drivers/hwmon/Makefile
>> +++ b/drivers/hwmon/Makefile
>> @@ -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
>> diff --git a/drivers/hwmon/raspberrypi-pmic-hwmon.c b/drivers/hwmon/raspberrypi-pmic-hwmon.c
>> new file mode 100644
>> index 000000000000..ce1f6bf0d70e
>> --- /dev/null
>> +++ b/drivers/hwmon/raspberrypi-pmic-hwmon.c
>> @@ -0,0 +1,296 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Raspberry Pi 5 PMIC hwmon driver
>> + *
>> + * Reads voltages, currents and temperatures through the VideoCore
>> + * firmware mailbox property
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/hwmon.h>
>> +#include <linux/jiffies.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +#include <soc/bcm2835/raspberrypi-firmware.h>
>> +
>> +#define RPI_PMIC_NUM_CHANNELS    35    /* 0..34 */
>> +#define RPI_PMIC_CACHE_MS    500
>> +
>> +struct rpi_pmic_data {
>> +    struct rpi_firmware *fw;
>> +    u32 values[RPI_PMIC_NUM_CHANNELS];
>> +    u64 last_update;
>> +};
>> +
>> +struct rpi_pmic_adc_msg {
>> +    __le32 index;
>> +    __le32 length;
>> +    __le32 values[RPI_PMIC_NUM_CHANNELS];
>> +} __packed;
>> +
>> +static const char * const rpi_pmic_labels[RPI_PMIC_NUM_CHANNELS] = {
>> +    /* Currents 0-7 */
>> +    [0]  = "3V7_WL_SW",
>> +    [1]  = "3V3_SYS",
>> +    [2]  = "1V8_SYS",
>> +    [3]  = "DDR_VDD2",
>> +    [4]  = "DDR_VDDQ",
>> +    [5]  = "1V1_SYS",
>> +    [6]  = "0V8_SW",
>> +    [7]  = "VDD_CORE",
>> +    /* Voltages 8-15 */
>> +    [8]  = "3V7_WL_SW",
>> +    [9]  = "3V3_SYS",
>> +    [10] = "1V8_SYS",
>> +    [11] = "DDR_VDD2",
>> +    [12] = "DDR_VDDQ",
>> +    [13] = "1V1_SYS",
>> +    [14] = "0V8_SW",
>> +    [15] = "VDD_CORE",
>> +    /* More currents / voltages */
>> +    [16] = "0V8_AON",
>> +    [17] = "3V3_DAC",
>> +    [18] = "3V3_ADC",
>> +    [19] = "0V8_AON",
>> +    [20] = "3V3_DAC",
>> +    [21] = "3V3_ADC",
>> +    [22] = "HDMI",
>> +    [23] = "HDMI",
>> +    [24] = "EXT5V",
>> +    [25] = "BATT",
>> +    /* Temperatures 26-34 (µ°C) */
>> +    [26] = "TEMP1",
>> +    [27] = "TEMP2",
>> +    [28] = "TEMP3",
>> +    [29] = "TEMP4",
>> +    [30] = "TEMP5",
>> +    [31] = "TEMP6",
>> +    [32] = "TEMP7",
>> +    [33] = "TEMP8",
>> +    [34] = "TEMP_BG",
>> +};
>> +
>> +/* Firmware ADC indices for each hwmon channel */
>> +static const u8 rpi_pmic_curr_idx[] = {
>> +    0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 22
>> +};
>> +
>> +static const u8 rpi_pmic_in_idx[] = {
>> +    8, 9, 10, 11, 12, 13, 14, 15, 19, 20, 21, 23, 24, 25
>> +};
>> +
>> +static const u8 rpi_pmic_temp_idx[] = {
>> +    26, 27, 28, 29, 30, 31, 32, 33, 34
>> +};
>> +
>> +static int rpi_pmic_update(struct rpi_pmic_data *data)
>> +{
>> +    struct rpi_pmic_adc_msg msg = {
>> +        .index  = cpu_to_le32(0),
>> +        .length = cpu_to_le32(RPI_PMIC_NUM_CHANNELS),
>> +    };
>> +    int ret;
>> +    unsigned int i;
>> +
>> +    ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_PMIC_ADC,
>> +                    &msg, sizeof(msg));
>> +    if (ret)
>> +        return ret;
>> +
>> +    /* Sanity-check the response */
>> +    if (le32_to_cpu(msg.length) != RPI_PMIC_NUM_CHANNELS)
>> +        return -EIO;
> Maybe we should log this mismatch once?
>> +
>> +    for (i = 0; i < RPI_PMIC_NUM_CHANNELS; i++)
>> +        data->values[i] = le32_to_cpu(msg.values[i]);
>> +
>> +    data->last_update = get_jiffies_64();
>> +    return 0;
>> +}
>> +
>> +static int rpi_pmic_read(struct device *dev, enum hwmon_sensor_types type,
>> +             u32 attr, int channel, long *val)
>> +{
>> +    struct rpi_pmic_data *data = dev_get_drvdata(dev);
>> +    int ret = 0;
>> +
>> +    if (time_after64(get_jiffies_64(),
>> +             data->last_update + msecs_to_jiffies(RPI_PMIC_CACHE_MS))) {
>> +        ret = rpi_pmic_update(data);
>> +        if (ret)
>> +            goto out;
> In case we don't want to log this case, we can eliminate ret and the goto.

Any error would likely be persistent. The function call is triggered from
userspace. Thus in turn would result in log spam. No log spam, please.

>> +    }
>> +
>> +    switch (type) {
>> +    case hwmon_in:
>> +        *val = data->values[rpi_pmic_in_idx[channel]] / 1000;    /* µV → mV */
>> +        break;
>> +    case hwmon_curr:
>> +        *val = data->values[rpi_pmic_curr_idx[channel]] / 1000;    /* µA → mA */
>> +        break;
>> +    case hwmon_temp:
>> +        *val = data->values[rpi_pmic_temp_idx[channel]] / 1000;    /* µ°C → m°C */
>> +        break;
>> +    default:
>> +        ret = -EOPNOTSUPP;

Missing break;


>> +    }
>> +
>> +out:
>> +    return ret;

That really hurts. Code like that should be forbidden.

>> +}
>> +
>> +static int rpi_pmic_read_string(struct device *dev,
>> +                enum hwmon_sensor_types type, u32 attr,
>> +                int channel, const char **str)
>> +{
>> +    size_t idx;
>> +
>> +    switch (type) {
>> +    case hwmon_in:
>> +        idx = rpi_pmic_in_idx[channel];
>> +        break;
>> +    case hwmon_curr:
>> +        idx = rpi_pmic_curr_idx[channel];
>> +        break;
>> +    case hwmon_temp:
>> +        idx = rpi_pmic_temp_idx[channel];
>> +        break;
>> +    default:
>> +        return -EOPNOTSUPP;
>> +    }
>> +
>> +    *str = rpi_pmic_labels[idx];
>> +    return 0;
>> +}
>> +
>> +static umode_t rpi_pmic_is_visible(const void *data,
>> +                   enum hwmon_sensor_types type,
>> +                   u32 attr, int channel)
>> +{
>> +    switch (type) {
>> +    case hwmon_in:
>> +        if (channel < ARRAY_SIZE(rpi_pmic_in_idx) &&
>> +            (attr == hwmon_in_input || attr == hwmon_in_label))
>> +            return 0444;
>> +        break;
>> +    case hwmon_curr:
>> +        if (channel < ARRAY_SIZE(rpi_pmic_curr_idx) &&
>> +            (attr == hwmon_curr_input || attr == hwmon_curr_label))
>> +            return 0444;
>> +        break;
>> +    case hwmon_temp:
>> +        if (channel < ARRAY_SIZE(rpi_pmic_temp_idx) &&
>> +            (attr == hwmon_temp_input || attr == hwmon_temp_label))
>> +            return 0444;
>> +        break;
>> +    default:
>> +        break;
>> +    }
>> +    return 0;
>> +}
>> +
>> +static const struct hwmon_ops rpi_pmic_ops = {
>> +    .is_visible    = rpi_pmic_is_visible,
>> +    .read        = rpi_pmic_read,
>> +    .read_string    = rpi_pmic_read_string,
>> +};
>> +
>> +static const struct hwmon_channel_info * const rpi_pmic_info[] = {
>> +    HWMON_CHANNEL_INFO(in,
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /*  8 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /*  9 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 10 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 11 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 12 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 13 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 14 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 15 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 19 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 20 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 21 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 23 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL,    /* 24 */
>> +               HWMON_I_INPUT | HWMON_I_LABEL    /* 25 */
>> +    ),
>> +    HWMON_CHANNEL_INFO(curr,
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  0 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  1 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  2 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  3 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  4 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  5 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  6 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /*  7 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /* 16 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /* 17 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL,    /* 18 */
>> +               HWMON_C_INPUT | HWMON_C_LABEL    /* 22 */
>> +    ),
>> +    HWMON_CHANNEL_INFO(temp,
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 26 TEMP1 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 27 TEMP2 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 28 TEMP3 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 29 TEMP4 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 30 TEMP5 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 31 TEMP6 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 32 TEMP7 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL,    /* 33 TEMP8 */
>> +               HWMON_T_INPUT | HWMON_T_LABEL    /* 34 TEMP_BG */
>> +    ),
>> +    NULL
>> +};
>> +
>> +static const struct hwmon_chip_info rpi_pmic_chip_info = {
>> +    .ops    = &rpi_pmic_ops,
>> +    .info    = rpi_pmic_info,
>> +};
>> +
>> +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;
>> +
>> +    data->fw = fw;
>> +
>> +    ret = rpi_pmic_update(data);
>> +    if (ret)
>> +        return -ENODEV;
> I think it would be helpful to log this case.

Only if you can guarantee that the probe function is never called
on systems not supporting the functionality. Logging noise due to
unsupported devices/systems/chips is not acceptable.

The function returns an error if the rpi_firmware_property() call
fails, which does suggest that the driver may probe even if the
functionality is not supported. That in turn suggests that an error
message here would not be acceptable.

Guenter

>> +
>> +    hwmon_dev =
>> +        devm_hwmon_device_register_with_info(dev,
>> +                             "rpi_pmic", data, &rpi_pmic_chip_info, NULL);
>> +
>> +    return PTR_ERR_OR_ZERO(hwmon_dev);
>> +}
>> +
>> +static const struct platform_device_id rpi_pmic_id[] = {
>> +    { "raspberrypi-pmic-hwmon", },
>> +    { }
>> +};
>> +MODULE_DEVICE_TABLE(platform, rpi_pmic_id);
>> +
>> +static struct platform_driver rpi_pmic_driver = {
>> +    .probe = rpi_pmic_probe,
>> +    .driver = {
>> +        .name = "raspberrypi-pmic-hwmon",
>> +    },
>> +    .id_table = rpi_pmic_id,
>> +};
>> +module_platform_driver(rpi_pmic_driver);
>> +
>> +MODULE_AUTHOR("Sander Speetjens <sander.speetjens@gmail.com>");
>> +MODULE_DESCRIPTION("Raspberry Pi 5 PMIC hwmon driver");
>> +MODULE_LICENSE("GPL");
>>
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver
  2026-12-01 17:21     ` Guenter Roeck
@ 2026-12-01 18:24       ` Stefan Wahren
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Wahren @ 2026-12-01 18:24 UTC (permalink / raw)
  To: Guenter Roeck, Sander Speetjens, Florian Fainelli,
	Broadcom internal kernel review list, Ray Jui, Scott Branden,
	Jonathan Corbet, Shuah Khan, Randy Dunlap
  Cc: linux-kernel, linux-rpi-kernel, linux-arm-kernel, linux-hwmon,
	linux-doc, Peter Robinson

Hi Guenter,

Am 01.12.26 um 18:21 schrieb Guenter Roeck:
> On 12/1/26 05:02, Stefan Wahren wrote:
>> Hi Sander,
>>
>> Am 26.11.26 um 14:03 schrieb 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).
>>>
...
>>> +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;
>>> +
>>> +    data->fw = fw;
>>> +
>>> +    ret = rpi_pmic_update(data);
>>> +    if (ret)
>>> +        return -ENODEV;
>> I think it would be helpful to log this case.
>
> Only if you can guarantee that the probe function is never called
> on systems not supporting the functionality. Logging noise due to
> unsupported devices/systems/chips is not acceptable.
Yes, the PMIC hwmon driver is only registered in case it's only a 
Raspberry Pi 5 and the specific firmware property is supported (see 
patch 2).
>
> The function returns an error if the rpi_firmware_property() call
> fails, which does suggest that the driver may probe even if the
> functionality is not supported. That in turn suggests that an error
> message here would not be acceptable.
Unfortunately there is another error case possible, which I was 
concerned. In case rpi_firmware_property succeed, but the returned data 
doesn't match (e.g. newer firmware version or something else).

So dev_warn_once(dev, "PMIC ADC length mismatch: got %u, expected %u\n" 
within rpi_pmic_update() is enough / okay?

Best regards
>
> Guenter
>
>>> +
>>> +    hwmon_dev =
>>> +        devm_hwmon_device_register_with_info(dev,
>>> +                             "rpi_pmic", data, &rpi_pmic_chip_info, 
>>> NULL);
>>> +
>>> +    return PTR_ERR_OR_ZERO(hwmon_dev);
>>> +}
>>> +
>>> +static const struct platform_device_id rpi_pmic_id[] = {
>>> +    { "raspberrypi-pmic-hwmon", },
>>> +    { }
>>> +};
>>> +MODULE_DEVICE_TABLE(platform, rpi_pmic_id);
>>> +
>>> +static struct platform_driver rpi_pmic_driver = {
>>> +    .probe = rpi_pmic_probe,
>>> +    .driver = {
>>> +        .name = "raspberrypi-pmic-hwmon",
>>> +    },
>>> +    .id_table = rpi_pmic_id,
>>> +};
>>> +module_platform_driver(rpi_pmic_driver);
>>> +
>>> +MODULE_AUTHOR("Sander Speetjens <sander.speetjens@gmail.com>");
>>> +MODULE_DESCRIPTION("Raspberry Pi 5 PMIC hwmon driver");
>>> +MODULE_LICENSE("GPL");
>>>
>>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-01 18:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 13:03 [PATCH v5 0/3] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
2026-11-26 13:03 ` [PATCH v5 1/3] soc: bcm2835: raspberrypi-firmware: Add PMIC ADC property tag Sander Speetjens
2026-11-26 13:03 ` [PATCH v5 2/3] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5 Sander Speetjens
2026-12-01 12:40   ` Stefan Wahren
2026-11-26 13:03 ` [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver Sander Speetjens
2026-12-01 13:02   ` Stefan Wahren
2026-12-01 17:21     ` Guenter Roeck
2026-12-01 18:24       ` Stefan Wahren
2026-11-26 13:12 ` [PATCH v5 0/3] hwmon: add Raspberry Pi 5 " sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.