Re: [PATCH v5 3/3] hwmon: add Raspberry Pi PMIC driver
From: Stefan Wahren
Date: Tue Dec 01 2026 - 13:25:02 EST
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).
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).+static int rpi_pmic_probe(struct platform_device *pdev)I think it would be helpful to log this case.
+{
+ 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;
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.
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).
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.
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@xxxxxxxxx>");
+MODULE_DESCRIPTION("Raspberry Pi 5 PMIC hwmon driver");
+MODULE_LICENSE("GPL");