[Deepin-Kernel-SIG] [linux 6.18.y] [FROMLIST] hwmon: raspberrypi: Add voltage input support#1777
Conversation
Reviewer's GuideExtends the raspberrypi-hwmon driver to expose Raspberry Pi firmware voltage channels via the hwmon "in" interface, with per-channel visibility, labels, and preservation of the existing undervoltage alarm, plus matching documentation updates. Sequence diagram for Raspberry Pi hwmon voltage read pathsequenceDiagram
participant hwmon_core
participant rpi_hwmon_driver
participant rpi_firmware
hwmon_core->>rpi_hwmon_driver: rpi_read(hwmon_in, hwmon_in_input, channel, val)
alt channel 0..3
rpi_hwmon_driver->>rpi_hwmon_driver: rpi_firmware_get_voltage(data, volt_id, val)
rpi_hwmon_driver->>rpi_firmware: rpi_firmware_property(fw, RPI_FIRMWARE_GET_VOLTAGE, packet, sizeof(packet))
rpi_firmware-->>rpi_hwmon_driver: packet.value (microvolts)
rpi_hwmon_driver->>rpi_hwmon_driver: le32_to_cpu(packet.value) / 1000
rpi_hwmon_driver-->>hwmon_core: val (millivolts)
else channel 0, hwmon_in_lcrit_alarm
hwmon_core->>rpi_hwmon_driver: rpi_read(hwmon_in, hwmon_in_lcrit_alarm, 0, val)
rpi_hwmon_driver->>rpi_hwmon_driver: data->last_throttled & UNDERVOLTAGE_STICKY_BIT
rpi_hwmon_driver-->>hwmon_core: val (alarm bit)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The probe path repeats the same rpi_firmware_get_voltage() pattern for each voltage ID; consider iterating over an array of {id, bit} pairs to set valid_inputs in a loop for better readability and easier future extension.
- rpi_is_visible() always exposes the in0_lcrit_alarm attribute regardless of whether the core voltage channel was successfully marked valid in probe; consider tying visibility of the alarm to valid_inputs (or always marking channel 0 valid) so the interface is consistent when core voltage is unavailable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The probe path repeats the same rpi_firmware_get_voltage() pattern for each voltage ID; consider iterating over an array of {id, bit} pairs to set valid_inputs in a loop for better readability and easier future extension.
- rpi_is_visible() always exposes the in0_lcrit_alarm attribute regardless of whether the core voltage channel was successfully marked valid in probe; consider tying visibility of the alarm to valid_inputs (or always marking channel 0 valid) so the interface is consistent when core voltage is unavailable.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
Extends the raspberrypi-hwmon driver to expose firmware-reported voltage rails via the hwmon in*_input and in*_label interfaces, while keeping the existing undervoltage sticky alarm as in0_lcrit_alarm.
Changes:
- Add voltage reading support (core + SDRAM rails) and expose them as
in0..in3hwmon channels with labels. - Add per-channel visibility logic to only create sysfs nodes for firmware-supported voltage IDs.
- Update
Documentation/hwmon/raspberrypi-hwmon.rstto describe the new sysfs entries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| drivers/hwmon/raspberrypi-hwmon.c | Adds voltage channels/labels, firmware voltage property reads, and dynamic visibility gating. |
| Documentation/hwmon/raspberrypi-hwmon.rst | Documents the new in*_input / in*_label attributes and conditional exposure behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static int rpi_firmware_get_voltage(struct rpi_hwmon_data *data, u32 id, | ||
| long *val) | ||
| { | ||
| struct rpi_firmware_get_voltage_request packet = | ||
| RPI_FIRMWARE_GET_VOLTAGE_REQUEST(id); | ||
| int ret; |
| case hwmon_in_lcrit_alarm: | ||
| if (channel == 0) { | ||
| *val = !!(data->last_throttled & UNDERVOLTAGE_STICKY_BIT); | ||
| return 0; |
Extend the raspberrypi-hwmon driver to expose firmware-provided voltage measurements through the hwmon subsystem. The driver now exports the following voltage inputs: - in0_input (core) - in1_input (sdram_c) - in2_input (sdram_i) - in3_input (sdram_p) Voltage values returned by firmware are converted from microvolts to millivolts as expected by the hwmon subsystem. Update the documentation related to it. The existing undervoltage sticky alarm handling is preserved and associated with the first voltage channel. Tested in - - Raspberry Pi 3b+ (Linux raspberrypi 6.12.75+rpt-rpi-v8 deepin-community#1 SMP PREEMPT Debian 1:6.12.75-1+rpt1 (2026-03-11) aarch64 GNU/Linux) Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Link: https://lore.kernel.org/r/20260517080445.103962-3-chakrabortyshubham66@gmail.com [groeck: Added missing empty line after declaration] Signed-off-by: Guenter Roeck <linux@roeck-us.net> Link: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git/commit/?h=hwmon-next&id=9656ebcce062f845e5f5586129227e3c6fba4b6b Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
09d02a8 to
06f4526
Compare
Extend the raspberrypi-hwmon driver to expose firmware-provided voltage measurements through the hwmon subsystem.
The driver now exports the following voltage inputs:
Voltage values returned by firmware are converted from microvolts to millivolts as expected by the hwmon subsystem.
Update the documentation related to it.
The existing undervoltage sticky alarm handling is preserved and associated with the first voltage channel.
Tested in -
Reviewed-by: Florian Fainelli florian.fainelli@broadcom.com
Link: https://lore.kernel.org/r/20260517080445.103962-3-chakrabortyshubham66@gmail.com
[groeck: Added missing empty line after declaration]
Summary by Sourcery
Extend the Raspberry Pi hwmon driver to expose firmware-provided voltage channels as standard hwmon inputs with labels while preserving undervoltage alarm reporting.
New Features:
Enhancements:
Documentation: