hwmon: Add fan tachometer support for Raspberry Pi RP1
Subsystems (6)
cover hwmon: Add fan tachometer support for Raspberry Pi RP1
Hi,
This patch series adds fan tachometer / RPM monitoring support for the Raspberry Pi RP1 southbridge found on the Raspberry Pi 5. Please note that the patchset in [1] is a prerequisite for this one.
On the Raspberry Pi RP1, the active cooling fan speed is controlled via the RP1 PWM controller. In addition to generating PWM signals, the RP1 monitors fan tachometer pulses. The pulse measurement and RPM calculation are performed autonomously by the RP1's onboard Cortex-M microcontroller core, which periodically writes the computed RPM value directly into dedicated MMIO registers located within the RP1 PWM hardware block.
During earlier discussions, Uwe Kleine-König explicitly indicated a preference to keep the core PWM controller driver (drivers/pwm/pwm-rp1.c) focused strictly on PWM duties, rather than bloating it by registering an hwmon device directly from within the PWM driver (see [2]).
Because the Linux PWM subsystem currently lacks a generic framework or consumer API for reporting hardware-calculated tachometer readings, this series implements a standalone hwmon driver (rp1-fan) using the following structure:
- The PWM driver exposes and exports rp1_pwm_read_tachometer() within a dedicated symbol namespace ('RP1_PWM') to read the RPM value from the MMIO block.
- A companion DT binding (raspberrypi,rp1-fan.yaml) introduces a vendor property, 'raspberrypi,pwm-tachometer', to link the fan node to the PWM controller node without overloading or abusing the standard 'pwms' property.
- The rp1-fan hwmon driver parses this phandle, establishes a device link for proper runtime and unbind dependency management, and registers the standard hwmon 'fan1_input' sysfs attribute.
An alternative architectural approach to the DT phandle + exported helper method would be to model the tachometer as a child device using the auxiliary bus framework (drivers/base/auxiliary.c). In that model, the RP1 PWM driver would instantiate an auxiliary device for the tachometer, and the hwmon driver would bind to that auxiliary bus device without requiring a separate DT node.
However, adopting the auxiliary bus would require a more significant rework and refactoring of the existing RP1 PWM driver.
I'd appreciate any feedback on whether the current companion driver with a dedicated DT property is acceptable, or if an auxiliary bus-based refactoring of the PWM driver is the preferred upstream path.
Patch Breakdown
---------------
Patch 1: pwm: rp1: Export helper to read fan tachometer RPM Patch 2: dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding Patch 3: hwmon: Add driver for Raspberry Pi RP1 fan tachometer Patch 4: arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
Thanks,
Andrea
LINKS:
[1] - https://lore.kernel.org/all/[email protected]/
[2] - https://lore.kernel.org/all/adLTwOTbkJ0VQXy6@monoceros/
Andrea della Porta (4):
pwm: rp1: Export helper to read fan tachometer RPM
dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding
hwmon: Add driver for Raspberry Pi RP1 fan tachometer
arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
.../bindings/hwmon/raspberrypi,rp1-fan.yaml | 39 +++++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/rp1-fan.rst | 41 ++++++ MAINTAINERS | 1 + .../boot/dts/broadcom/bcm2712-rpi-5-b.dts | 5 + drivers/hwmon/Kconfig | 11 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/rp1-hwmon.c | 136 ++++++++++++++++++ drivers/pwm/pwm-rp1.c | 27 ++++ include/soc/bcm2835/raspberrypi-pwm-rp1.h | 10 ++ 10 files changed, 272 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/raspberrypi,rp1-fan.yaml create mode 100644 Documentation/hwmon/rp1-fan.rst create mode 100644 drivers/hwmon/rp1-hwmon.c create mode 100644 include/soc/bcm2835/raspberrypi-pwm-rp1.h
Signature · 1 line
2.35.3
RFC PATCH 1/4 pwm: rp1: Export helper to read fan tachometer RPM
On the Raspberry Pi RP1 southbridge, the internal PWM controller hardware block houses a register associated with fan tachometer monitoring. The tachometer pulses are measured by firmware running on the RP1 Cortex-M core, which periodically writes the calculated RPM values directly into dedicated MMIO registers within the PWM block.
Because the Linux PWM framework currently does not provide an abstraction or API to report hardware-calculated tachometer readings to consumer drivers, a direct accessor is needed by the companion hwmon fan driver to read these values.
Add and export rp1_pwm_read_tachometer() to allow consumer drivers to retrieve the fan speed from the PWM MMIO registers. To prevent polluting the global kernel symbol namespace and restrict access to intended consumers, export the function under the 'RP1_PWM' symbol namespace.
--- drivers/pwm/pwm-rp1.c | 27 +++++++++++++++++++++++ include/soc/bcm2835/raspberrypi-pwm-rp1.h | 10 +++++++++ 2 files changed, 37 insertions(+) create mode 100644 include/soc/bcm2835/raspberrypi-pwm-rp1.h
drivers/pwm/pwm-rp1.c +27 -0
@@ -49,6 +49,7 @@#include <linux/pwm.h> #include <linux/units.h> #include <linux/spinlock.h> +#include <soc/bcm2835/raspberrypi-pwm-rp1.h> #define RP1_PWM_GLB_CTRL 0x000#define RP1_PWM_GLB_CTRL_CHANNEL_ENABLE (chan) BIT(chan)
@@ -286,6 +287,32 @@ static const struct pwm_ops rp1_pwm_ops = { .write_waveform = rp1_pwm_write_waveform, }; +int rp1_pwm_read_tachometer (struct device *dev) +{ +struct pwm_chip *chip; +struct rp1_pwm *rp1; + +if (!dev) +return -EINVAL ; + +if (!of_device_is_compatible (dev_of_node (dev),"raspberrypi,rp1-pwm" )) +return -EINVAL ; + + chip =dev_get_drvdata (dev); +if (!chip) +return -ENODEV ; + + rp1 =pwmchip_get_drvdata (chip); +if (!rp1) +return -ENODEV ; + +if (!rp1->clk_enabled) +return -EBUSY ; + +return (int )readl (rp1->base +RP1_PWM_PHASE (2 )); +} +EXPORT_SYMBOL_NS_GPL (rp1_pwm_read_tachometer,"RP1_PWM" ); +static int rp1_pwm_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
include/soc/bcm2835/raspberrypi-pwm-rp1.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __SOC_RASPBERRY_PWM_RP1_H__ +#define __SOC_RASPBERRY_PWM_RP1_H__ + +#include <linux/device.h> + +int rp1_pwm_read_tachometer (struct device *dev); + +#endif /* __SOC_RASPBERRY_PWM_RP1_H__ */
Signature · 1 line
2.35.3
RFC PATCH 2/4 dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding
In reply to Andrea della PortaThe Raspberry Pi RP1 is a multi-function southbridge used on the Raspberry Pi 5. Its internal PWM controller block includes a built-in hardware tachometer logic, which calculates the fan RPM by measuring the tachometer pulses. The computed RPM is updated by the internal Cortex-M firmware into specific MMIO registers within the PWM block.
Currently, the Linux PWM subsystem lacks a standard API to report hardware-calculated tachometer values back to consumer drivers. To avoid abusing the standard 'pwms' property, this binding introduces a custom property, 'raspberrypi,pwm-tachometer', to link the standalone hwmon fan driver to the RP1 PWM controller node. This enables reading the tachometer MMIO registers and exposing the RPM via sysfs.
---
For the rationale behind this design, please see the cover letter
.../bindings/hwmon/raspberrypi,rp1-fan.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/raspberrypi,rp1-fan.yaml
Documentation/devicetree/bindings/hwmon/raspberrypi,rp1-fan.yaml new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/raspberrypi,rp1-fan.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Raspberry Pi RP1 fan tachometer + +maintainers: + - Andrea della Porta <[email protected]> + +description: | + Hardware monitoring driver for the fan connected to the Raspberry Pi RP1 + southbridge. The RP1 PWM controller hardware contains a built-in tachometer + logic that calculates the fan RPM. This binding links the fan to the PWM + controller to read the tachometer values. + +properties: + compatible: + const: raspberrypi,rp1-fan + + raspberrypi,pwm-tachometer: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the RP1 PWM controller node that contains the tachometer + registers for this fan. + +required: + - compatible + - raspberrypi,pwm-tachometer + +additionalProperties: false + +examples: + - | + fan { + compatible = "raspberrypi,rp1-fan"; + raspberrypi,pwm-tachometer = <&rp1_pwm1>; + };
Signature · 1 line
2.35.3
RFC PATCH 3/4 hwmon: Add driver for Raspberry Pi RP1 fan tachometer
In reply to Andrea della PortaAdd a hardware monitoring driver to support the fan tachometer on the Raspberry Pi RP1 southbridge, found on the Raspberry Pi 5.
The RP1 PWM controller block contains specific MMIO registers that hold the current fan speed in RPM. These registers are periodically updated by the RP1 internal firmware based on the tachometer pulses.
Since the Linux PWM subsystem does not currently offer a framework for exposing integrated hardware tachometer readings, this driver is implemented as a standalone hwmon device. It parses the 'raspberrypi,pwm-tachometer' DT property to find the supplier PWM device, establishes a device link to ensure proper lifecycle management, and uses RP1-specific PWM functions to retrieve the RPM values.
Provides the standard hwmon sysfs attribute 'fan1_input'.
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/rp1-fan.rst | 41 ++++++++++ MAINTAINERS | 1 + drivers/hwmon/Kconfig | 11 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/rp1-hwmon.c | 136 ++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 Documentation/hwmon/rp1-fan.rst create mode 100644 drivers/hwmon/rp1-hwmon.c
Documentation/hwmon/index.rst +1 -0
@@ -235,6 +235,7 @@ Hardware Monitoring Kernel Drivers q54sj108a2 qnap-mcu-hwmon raspberrypi-hwmon + rp1-fan sbrmi sbtsi_temp sch5627
Documentation/hwmon/rp1-fan.rst new file +41 -0
41 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -22819,6 +22819,7 @@ M: Andrea della Porta <[email protected]> S: Maintained F: arch/arm64/boot/dts/broadcom/rp1*.dts* F: drivers/clk/clk-rp1.c +F: drivers/hwmon/rp1-hwmon.c F: drivers/misc/rp1/ F: drivers/pinctrl/pinctrl-rp1.c
drivers/hwmon/Kconfig +11 -0
@@ -1981,6 +1981,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_RP1_FAN + tristate "Raspberry Pi RP1 PWM Fan Support" + depends on OF + depends on PWM_RASPBERRYPI_RP1 || COMPILE_TEST + help + If you say yes here you get support for reading the fan tachometer + from Raspberry Pi RP1. + + This driver can also be built as a module. If so, the module + will be called rp1-hwmon. + config SENSORS_SL28CPLD tristate "Kontron sl28cpld hardware monitoring driver" depends on MFD_SL28CPLD || COMPILE_TEST
drivers/hwmon/Makefile +1 -0
@@ -207,6 +207,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_RP1_FAN) += rp1-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/rp1-hwmon.c new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
2.35.3
Uwe Kleine-König
maintainerRe: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer
Hello,
Quoted 7 lines · Andrea della Porta
Add a hardware monitoring driver to support the fan tachometer on the Raspberry Pi RP1 southbridge, found on the Raspberry Pi 5.
The RP1 PWM controller block contains specific MMIO registers that hold the current fan speed in RPM. These registers are periodically updated by the RP1 internal firmware based on the tachometer pulses.
Quoted 6 lines
Since the Linux PWM subsystem does not currently offer a framework for exposing integrated hardware tachometer readings, this driver is implemented as a standalone hwmon device. It parses the 'raspberrypi,pwm-tachometer' DT property to find the supplier PWM device, establishes a device link to ensure proper lifecycle management, and uses RP1-specific PWM functions to retrieve the RPM values.
I wonder if the tachometer readout should be a counter driver? That would allow this driver to not be specific to the RP1 hardware.
Best regards
Uwe
Re: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer
Hi Uwe,
Quoted 17 lines · Uwe Kleine-König
Hello,
Quoted 7 lines · Andrea della Porta
Add a hardware monitoring driver to support the fan tachometer on the Raspberry Pi RP1 southbridge, found on the Raspberry Pi 5.
The RP1 PWM controller block contains specific MMIO registers that hold the current fan speed in RPM. These registers are periodically updated by the RP1 internal firmware based on the tachometer pulses.
Quoted 6 lines
Since the Linux PWM subsystem does not currently offer a framework for exposing integrated hardware tachometer readings, this driver is implemented as a standalone hwmon device. It parses the 'raspberrypi,pwm-tachometer' DT property to find the supplier PWM device, establishes a device link to ensure proper lifecycle management, and uses RP1-specific PWM functions to retrieve the RPM values.
Quoted 2 lines
I wonder if the tachometer readout should be a counter driver? That would allow this driver to not be specific to the RP1 hardware.
I suspect the counter driver won't work with userspace daemons (e.g. fancontrol) which use hwmon as an interface.
OTOH this driver is indeed specific to the RP1 driver: the fan rpm are read from the same registers range and hw of teh PWM controller.
Regards,
Andrea
Quoted 3 lines
Best regards
Uwe
Uwe Kleine-König
maintainerRe: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer
In reply to Andrea della Portadrivers/hwmon/rp1-hwmon.c line 9
Quoted 2 lines · Andrea della Porta
drivers/hwmon/rp1-hwmon.c new file +2
-0+#include <linux/platform_device.h> +#include <linux/mod_devicetable.h>
Irrespective of how this patch set evolves: Please don't add new includes for <linux/mod_devicetable.h>. <linux/platform_device.h> already provides of_device_id without introducing a batch of unneeded dependencies.
Best regards
Uwe
Re: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer
Quoted 8 lines · Uwe Kleine-König
drivers/hwmon/rp1-hwmon.c line 9
Quoted 2 lines · Andrea della Porta
drivers/hwmon/rp1-hwmon.c new file +2
-0+#include <linux/platform_device.h> +#include <linux/mod_devicetable.h> Irrespective of how this patch set evolves: Please don't add new includes for <
linux/mod_devicetable.h>. <linux/platform_device.h> already providesof_device_idwithout introducing a batch of unneeded dependencies.
Ack.
Quoted 3 lines
Best regards
Uwe
kernel test robot
build botRe: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer
In reply to Andrea della Portakernel test robot noticed the following build errors:
Hi Andrea,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on linux-review/Andrea-della-Porta/dt-bindings-pwm-Add-Raspberry-Pi-RP1-PWM-controller/20260929-150211]
url: https://github.com/intel-lab-lkp/linux/commits/Andrea-della-Porta/pwm-rp1-Export-helper-to-read-fan-tachometer-RPM/20261023-121554 base: https://github.com/intel-lab-lkp/linux Andrea-della-Porta/dt-bindings-pwm-Add-Raspberry-Pi-RP1-PWM-controller/20260929-150211 patch link: https://lore.kernel.org/r/0d2249a66732bfce38a2260bee08cd1ba4097e51.1792748690.git.andrea.porta%40suse.com patch subject: [PATCH RFC 3/4] hwmon: Add driver for Raspberry Pi RP1 fan tachometer config: xtensa-randconfig-1001-20261028 (https://download.01.org/0day-ci/archive/20261029/[email protected]/config) compiler: xtensa-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261029/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
xtensa-linux-ld: drivers/hwmon/rp1-hwmon.o: in function `rp1_fan_put_device':
>> rp1-hwmon.c:(.text+0x40): undefined reference to `rp1_pwm_read_tachometer'
xtensa-linux-ld: drivers/hwmon/rp1-hwmon.o: in function `rp1_fan_read':
rp1-hwmon.c:(.text+0x52): undefined reference to `rp1_pwm_read_tachometer'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
RFC PATCH 4/4 arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
In reply to Andrea della PortaAdd the hwmon fan node for the Raspberry Pi 5 to expose the cooling fan speed (RPM) to userspace.
The fan tachometer is managed internally by the RP1 PWM controller. This node uses the 'raspberrypi,pwm-tachometer' property to link the rp1-fan hwmon driver to the existing RP1 PWM controller, enabling RPM reporting via sysfs.
--- arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts +5 -0
@@ -16,6 +16,11 @@ / { aliases { ethernet0 = &rp1_eth; }; + + fan-tach { + compatible = "raspberrypi,rp1-fan"; + raspberrypi,pwm-tachometer = <&rp1_pwm1>; + }; }; &pcie2 {
Signature · 1 line
2.35.3
Guenter Roeck
maintainerQuoted 48 lines · Andrea della Porta
Hi,
This patch series adds fan tachometer / RPM monitoring support for the Raspberry Pi RP1 southbridge found on the Raspberry Pi 5. Please note that the patchset in [1] is a prerequisite for this one.
On the Raspberry Pi RP1, the active cooling fan speed is controlled via the RP1 PWM controller. In addition to generating PWM signals, the RP1 monitors fan tachometer pulses. The pulse measurement and RPM calculation are performed autonomously by the RP1's onboard Cortex-M microcontroller core, which periodically writes the computed RPM value directly into dedicated MMIO registers located within the RP1 PWM hardware block.
During earlier discussions, Uwe Kleine-König explicitly indicated a preference to keep the core PWM controller driver (
drivers/pwm/pwm-rp1.c) focused strictly on PWM duties, rather than bloating it by registering an hwmon device directly from within the PWM driver (see [2]).Because the Linux PWM subsystem currently lacks a generic framework or consumer API for reporting hardware-calculated tachometer readings, this series implements a standalone hwmon driver (rp1-fan) using the following structure:
(quoted diff) +0
-3- The PWM driver exposes and exports rp1_pwm_read_tachometer() within a dedicated symbol namespace ('RP1_PWM') to read the RPM value from the MMIO block. - A companion DT binding (raspberrypi,rp1-fan.yaml) introduces a vendor property, 'raspberrypi,pwm-tachometer', to link the fan node to the PWM controller node without overloading or abusing the standard 'pwms' property. - The rp1-fan hwmon driver parses this phandle, establishes a device link for proper runtime and unbind dependency management, and registers the standard hwmon 'fan1_input' sysfs attribute.An alternative architectural approach to the DT phandle + exported helper method would be to model the tachometer as a child device using the auxiliary bus framework (
drivers/base/auxiliary.c). In that model, the RP1 PWM driver would instantiate an auxiliary device for the tachometer, and the hwmon driver would bind to that auxiliary bus device without requiring a separate DT node.However, adopting the auxiliary bus would require a more significant rework and refactoring of the existing RP1 PWM driver.
I'd appreciate any feedback on whether the current companion driver with a dedicated DT property is acceptable, or if an auxiliary bus-based refactoring of the PWM driver is the preferred upstream path.
Quoted 5 lines
Patch Breakdown
---------------
Patch 1: pwm: rp1: Export helper to read fan tachometer RPM Patch 2: dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding Patch 3: hwmon: Add driver for Raspberry Pi RP1 fan tachometer
This seems conceptually wrong.
Have you considered implementing the hwmon driver as auxiliary driver and accessing the register in question through regmap ?
Quoted 16 lines
Patch 4: arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
Thanks,
AndreaLINKS:
[1] - https://lore.kernel.org/all/[email protected]/
[2] - https://lore.kernel.org/all/adLTwOTbkJ0VQXy6@monoceros/Andrea della Porta (4):
pwm: rp1: Export helper to read fan tachometer RPM
dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding
hwmon: Add driver for Raspberry Pi RP1 fan tachometer
arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
Quoted 9 lines
.../bindings/hwmon/raspberrypi,rp1-fan.yaml | 39 +++++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/rp1-fan.rst | 41 ++++++ MAINTAINERS | 1 + .../boot/dts/broadcom/bcm2712-rpi-5-b.dts | 5 + drivers/hwmon/Kconfig | 11 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/rp1-hwmon.c | 136 ++++++++++++++++++ drivers/pwm/pwm-rp1.c | 27 ++++
Either case, there is no such driver in mainline or linux-next.
Guenter
Quoted 7 lines
include/soc/bcm2835/raspberrypi-pwm-rp1.h | 10 ++ 10 files changed, 272 insertions(+)create mode 100644
Documentation/devicetree/bindings/hwmon/raspberrypi,rp1-fan.yamlcreate mode 100644Documentation/hwmon/rp1-fan.rst
create mode 100644drivers/hwmon/rp1-hwmon.c
create mode 100644include/soc/bcm2835/raspberrypi-pwm-rp1.h
Hi Guenter,
Quoted 55 lines · Guenter Roeck
Quoted 48 lines · Andrea della Porta
Hi,
This patch series adds fan tachometer / RPM monitoring support for the Raspberry Pi RP1 southbridge found on the Raspberry Pi 5. Please note that the patchset in [1] is a prerequisite for this one.
On the Raspberry Pi RP1, the active cooling fan speed is controlled via the RP1 PWM controller. In addition to generating PWM signals, the RP1 monitors fan tachometer pulses. The pulse measurement and RPM calculation are performed autonomously by the RP1's onboard Cortex-M microcontroller core, which periodically writes the computed RPM value directly into dedicated MMIO registers located within the RP1 PWM hardware block.
During earlier discussions, Uwe Kleine-König explicitly indicated a preference to keep the core PWM controller driver (
drivers/pwm/pwm-rp1.c) focused strictly on PWM duties, rather than bloating it by registering an hwmon device directly from within the PWM driver (see [2]).Because the Linux PWM subsystem currently lacks a generic framework or consumer API for reporting hardware-calculated tachometer readings, this series implements a standalone hwmon driver (rp1-fan) using the following structure:
(quoted diff) +0
-3- The PWM driver exposes and exports rp1_pwm_read_tachometer() within a dedicated symbol namespace ('RP1_PWM') to read the RPM value from the MMIO block. - A companion DT binding (raspberrypi,rp1-fan.yaml) introduces a vendor property, 'raspberrypi,pwm-tachometer', to link the fan node to the PWM controller node without overloading or abusing the standard 'pwms' property. - The rp1-fan hwmon driver parses this phandle, establishes a device link for proper runtime and unbind dependency management, and registers the standard hwmon 'fan1_input' sysfs attribute.An alternative architectural approach to the DT phandle + exported helper method would be to model the tachometer as a child device using the auxiliary bus framework (
drivers/base/auxiliary.c). In that model, the RP1 PWM driver would instantiate an auxiliary device for the tachometer, and the hwmon driver would bind to that auxiliary bus device without requiring a separate DT node.However, adopting the auxiliary bus would require a more significant rework and refactoring of the existing RP1 PWM driver.
I'd appreciate any feedback on whether the current companion driver with a dedicated DT property is acceptable, or if an auxiliary bus-based refactoring of the PWM driver is the preferred upstream path.
Quoted 5 lines
Patch Breakdown
---------------
Patch 1: pwm: rp1: Export helper to read fan tachometer RPM Patch 2: dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding Patch 3: hwmon: Add driver for Raspberry Pi RP1 fan tachometer
Quoted 4 lines
This seems conceptually wrong.
Have you considered implementing the hwmon driver as auxiliary driver and accessing the register in question through regmap ?
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 27 lines
Quoted 17 lines
Patch 4: arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer node
Thanks,
AndreaLINKS:
[1] - https://lore.kernel.org/all/[email protected]/
[2] - https://lore.kernel.org/all/adLTwOTbkJ0VQXy6@monoceros/Andrea della Porta (4):
pwm: rp1: Export helper to read fan tachometer RPM
dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding
hwmon: Add driver for Raspberry Pi RP1 fan tachometer
arm64: dts: broadcom: bcm2712-rpi-5-b: Add RP1 fan tachometer nodeQuoted 9 lines
.../bindings/hwmon/raspberrypi,rp1-fan.yaml | 39 +++++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/rp1-fan.rst | 41 ++++++ MAINTAINERS | 1 + .../boot/dts/broadcom/bcm2712-rpi-5-b.dts | 5 + drivers/hwmon/Kconfig | 11 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/rp1-hwmon.c | 136 ++++++++++++++++++ drivers/pwm/pwm-rp1.c | 27 ++++
Quoted 1 line
Either case, there is no such driver in mainline or linux-next.
As stated in the cover letter, the pwm driver comes from the prerequisite in [1].
Many thanks,
Andrea
Quoted 11 lines
Guenter
Quoted 7 lines
include/soc/bcm2835/raspberrypi-pwm-rp1.h | 10 ++ 10 files changed, 272 insertions(+)create mode 100644
Documentation/devicetree/bindings/hwmon/raspberrypi,rp1-fan.yamlcreate mode 100644Documentation/hwmon/rp1-fan.rst
create mode 100644drivers/hwmon/rp1-hwmon.c
create mode 100644include/soc/bcm2835/raspberrypi-pwm-rp1.h
Guenter Roeck
maintainerQuoted 83 lines · Andrea della Porta
Hi Guenter,
Quoted 55 lines · Guenter Roeck
Quoted 48 lines · Andrea della Porta
Hi,
This patch series adds fan tachometer / RPM monitoring support for the Raspberry Pi RP1 southbridge found on the Raspberry Pi 5. Please note that the patchset in [1] is a prerequisite for this one.
On the Raspberry Pi RP1, the active cooling fan speed is controlled via the RP1 PWM controller. In addition to generating PWM signals, the RP1 monitors fan tachometer pulses. The pulse measurement and RPM calculation are performed autonomously by the RP1's onboard Cortex-M microcontroller core, which periodically writes the computed RPM value directly into dedicated MMIO registers located within the RP1 PWM hardware block.
During earlier discussions, Uwe Kleine-König explicitly indicated a preference to keep the core PWM controller driver (
drivers/pwm/pwm-rp1.c) focused strictly on PWM duties, rather than bloating it by registering an hwmon device directly from within the PWM driver (see [2]).Because the Linux PWM subsystem currently lacks a generic framework or consumer API for reporting hardware-calculated tachometer readings, this series implements a standalone hwmon driver (rp1-fan) using the following structure:
(quoted diff) +0
-3- The PWM driver exposes and exports rp1_pwm_read_tachometer() within a dedicated symbol namespace ('RP1_PWM') to read the RPM value from the MMIO block. - A companion DT binding (raspberrypi,rp1-fan.yaml) introduces a vendor property, 'raspberrypi,pwm-tachometer', to link the fan node to the PWM controller node without overloading or abusing the standard 'pwms' property. - The rp1-fan hwmon driver parses this phandle, establishes a device link for proper runtime and unbind dependency management, and registers the standard hwmon 'fan1_input' sysfs attribute.An alternative architectural approach to the DT phandle + exported helper method would be to model the tachometer as a child device using the auxiliary bus framework (
drivers/base/auxiliary.c). In that model, the RP1 PWM driver would instantiate an auxiliary device for the tachometer, and the hwmon driver would bind to that auxiliary bus device without requiring a separate DT node.However, adopting the auxiliary bus would require a more significant rework and refactoring of the existing RP1 PWM driver.
I'd appreciate any feedback on whether the current companion driver with a dedicated DT property is acceptable, or if an auxiliary bus-based refactoring of the PWM driver is the preferred upstream path.
Quoted 5 lines
Patch Breakdown
---------------
Patch 1: pwm: rp1: Export helper to read fan tachometer RPM Patch 2: dt-bindings: hwmon: Add Raspberry Pi RP1 fan binding Patch 3: hwmon: Add driver for Raspberry Pi RP1 fan tachometerQuoted 4 lines
This seems conceptually wrong.
Have you considered implementing the hwmon driver as auxiliary driver and accessing the register in question through regmap ?
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
Guenter
Quoted 30 lines · Guenter Roeck
Quoted 22 lines · Andrea della Porta
Hi Guenter,
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 5 lines
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
I agree on the auxiliary driver part. However, I don't think EXPORT_SYMBOL_NS is an issue, and regmap is not the right fit here:
- Previous version of the PWM1 patch series publish regmap using of_syscon_register_regmap, but this cannot be undone -- which needs to happen on PWM device unbind (the RP1 PWM device is itself platform device, but RP1 chip itself is PCIe device which must be removable).
- The tachometer register is not its own separate register, but rather (re)using the phase control register. The phase control is not implemented in the RP1 PWM driver on the list yet, so this is currently a simple register read -- I can see that RP1 PWM driver need to take special care to about the tachometer reading if the phase control is implemented.
For the two reasons above, I think the way that tachometer is read should really be an implementation detail of the PWM driver and not for the hwmon driver to worry about, so I suggested using EXPORT_SYMBOL_NS.
- EXPORT_SYMBOL_NS is the documented way for exposing functionality from parent device to auxiliary drivers: https://docs.kernel.org/driver-api/auxiliary_bus.html
Best,
Gary
Guenter Roeck
maintainerQuoted 51 lines · Gary Guo
Quoted 30 lines · Guenter Roeck
Quoted 22 lines · Andrea della Porta
Hi Guenter,
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 5 lines
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
I agree on the auxiliary driver part. However, I don't think
EXPORT_SYMBOL_NSis an issue, and regmap is not the right fit here:- Previous version of the PWM1 patch series publish regmap using
of_syscon_register_regmap, but this cannot be undone -- which needs to happen on PWM device unbind (the RP1 PWM device is itself platform device, but RP1 chip itself is PCIe device which must be removable).- The tachometer register is not its own separate register, but rather (re)using the phase control register. The phase control is not implemented in the RP1 PWM driver on the list yet, so this is currently a simple register read -- I can see that RP1 PWM driver need to take special care to about the tachometer reading if the phase control is implemented.
Quoted 7 lines
For the two reasons above, I think the way that tachometer is read should really be an implementation detail of the PWM driver and not for the hwmon driver to worry about, so I suggested using
EXPORT_SYMBOL_NS.-
EXPORT_SYMBOL_NSis the documented way for exposing functionality from parent device to auxiliary drivers: https://docs.kernel.org/driver-api/auxiliary_bus.html
Let's agree to disagree, and keep the code in the pwm subsystem.
Thanks,
Guenter
Quoted 56 lines · Guenter Roeck
Quoted 55 lines · Gary Guo
Quoted 30 lines · Guenter Roeck
Quoted 22 lines · Andrea della Porta
Hi Guenter,
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 5 lines
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
I agree on the auxiliary driver part. However, I don't think
EXPORT_SYMBOL_NSis an issue, and regmap is not the right fit here:- Previous version of the PWM1 patch series publish regmap using
of_syscon_register_regmap, but this cannot be undone -- which needs to happen on PWM device unbind (the RP1 PWM device is itself platform device, but RP1 chip itself is PCIe device which must be removable).- The tachometer register is not its own separate register, but rather (re)using the phase control register. The phase control is not implemented in the RP1 PWM driver on the list yet, so this is currently a simple register read -- I can see that RP1 PWM driver need to take special care to about the tachometer reading if the phase control is implemented.
For the two reasons above, I think the way that tachometer is read should really be an implementation detail of the PWM driver and not for the hwmon driver to worry about, so I suggested using
EXPORT_SYMBOL_NS.
Quoted 5 lines
Quoted 3 lines
-
EXPORT_SYMBOL_NSis the documented way for exposing functionality from parent device to auxiliary drivers: https://docs.kernel.org/driver-api/auxiliary_bus.htmlLet's agree to disagree, and keep the code in the pwm subsystem.
And auxiliary bus it will be. I propose the following:
- drivers/pwm/pwm-rp1.c: create an auxiliary device for the fan. The function to read the RPM will not be exported, but a function pointer will be passed through the private data to the fan driver. No need for regmap. To be taken by Uwe.
- drivers/hwmon/rp1-hwmon.c: The auxiliary driver is probed against the device registered by the pwm driver. No imported function. To be taken by Guenter.
In this way, we decouple the two drivers and we leverage the auxiliary bus paradigm. Also, no DT node needed for the fan.
Do we all agree on this approach?
Thanks,
Andrea
Quoted 3 lines
Thanks,
Guenter
Hi,
Quoted 69 lines · Andrea della Porta
Quoted 56 lines · Guenter Roeck
Quoted 55 lines · Gary Guo
Quoted 30 lines · Guenter Roeck
Quoted 22 lines · Andrea della Porta
Hi Guenter,
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 5 lines
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
I agree on the auxiliary driver part. However, I don't think
EXPORT_SYMBOL_NSis an issue, and regmap is not the right fit here:- Previous version of the PWM1 patch series publish regmap using
of_syscon_register_regmap, but this cannot be undone -- which needs to happen on PWM device unbind (the RP1 PWM device is itself platform device, but RP1 chip itself is PCIe device which must be removable).- The tachometer register is not its own separate register, but rather (re)using the phase control register. The phase control is not implemented in the RP1 PWM driver on the list yet, so this is currently a simple register read -- I can see that RP1 PWM driver need to take special care to about the tachometer reading if the phase control is implemented.
For the two reasons above, I think the way that tachometer is read should really be an implementation detail of the PWM driver and not for the hwmon driver to worry about, so I suggested using
EXPORT_SYMBOL_NS.Quoted 5 lines
Quoted 3 lines
-
EXPORT_SYMBOL_NSis the documented way for exposing functionality from parent device to auxiliary drivers: https://docs.kernel.org/driver-api/auxiliary_bus.htmlLet's agree to disagree, and keep the code in the pwm subsystem.
And auxiliary bus it will be. I propose the following:
-
drivers/pwm/pwm-rp1.c: create an auxiliary device for the fan. The function to read the RPM will not be exported, but a function pointer will be passed through the private data to the fan driver. No need for regmap. To be taken by Uwe.
Quoted 7 lines
-
drivers/hwmon/rp1-hwmon.c: The auxiliary driver is probed against the device registered by the pwm driver. No imported function. To be taken by Guenter.In this way, we decouple the two drivers and we leverage the auxiliary bus paradigm. Also, no DT node needed for the fan.
Do we all agree on this approach?
A gentle reminder about this inquiry. Before refactoring both the PWM and the fan driver I'd like to be sure that the proposed approach is at least acceptable.
Many thanks,
Andrea
Quoted 7 lines
Thanks,
AndreaQuoted 3 lines
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 75 lines · Andrea della Porta
Hi,
Quoted 72 lines · Andrea della Porta
Quoted 56 lines · Guenter Roeck
Quoted 55 lines · Gary Guo
Quoted 30 lines · Guenter Roeck
Quoted 22 lines · Andrea della Porta
Hi Guenter,
Yes, I also proposed that in the cover letter because auxbus seems also a viable solution.
The current implementation is a consequence to the discussion about the companion PWM driver, from here (and the revisions that followed):
https://lore.kernel.org/all/[email protected]/
To give a short and hopefully coherent view of the decisions, here's a breakdown:
- first proposal: PWM driver + fan hwmon (to read the RPM), all in the same driver
- V2: Uwe preferred to split the PWM driver from the hwmon one, so the hwmon was dropped from teh PWM driver in favor of a future (fan) driver. To accomplish this, I moved from readl/writel to regmap + syscon.
- V8: Gary proposed to export a function to read the fan RPM as a viable solution. As a result, the regmap/syscon was dropped as it was no longer needed and the function has been exported from the PWM driver
Quoted 6 lines
- new patchset for fan driver: the now independent hwmon moodle just call the exported function from thw PWM driver.
If the auxiliary bus is indeed the preferred approach, I'd like to ensure we are all aligned, as this would also require refactoring the PWM driver.
Quoted 5 lines
Let's say it that way: If you don't want to implement the auxiliary driver, and you insist using the exported function, I would prefer for you to go back to the first solution. The one thing I really dislike is conceptually broken code, and I consider the current approach broken. Your call, but the one thing I won't accept is the code with the exported function.
I agree on the auxiliary driver part. However, I don't think
EXPORT_SYMBOL_NSis an issue, and regmap is not the right fit here:- Previous version of the PWM1 patch series publish regmap using
of_syscon_register_regmap, but this cannot be undone -- which needs to happen on PWM device unbind (the RP1 PWM device is itself platform device, but RP1 chip itself is PCIe device which must be removable).- The tachometer register is not its own separate register, but rather (re)using the phase control register. The phase control is not implemented in the RP1 PWM driver on the list yet, so this is currently a simple register read -- I can see that RP1 PWM driver need to take special care to about the tachometer reading if the phase control is implemented.
For the two reasons above, I think the way that tachometer is read should really be an implementation detail of the PWM driver and not for the hwmon driver to worry about, so I suggested using
EXPORT_SYMBOL_NS.Quoted 5 lines
Quoted 3 lines
-
EXPORT_SYMBOL_NSis the documented way for exposing functionality from parent device to auxiliary drivers: https://docs.kernel.org/driver-api/auxiliary_bus.htmlLet's agree to disagree, and keep the code in the pwm subsystem.
And auxiliary bus it will be. I propose the following:
-
drivers/pwm/pwm-rp1.c: create an auxiliary device for the fan. The function to read the RPM will not be exported, but a function pointer will be passed through the private data to the fan driver. No need for regmap. To be taken by Uwe.-
drivers/hwmon/rp1-hwmon.c: The auxiliary driver is probed against the device registered by the pwm driver. No imported function. To be taken by Guenter.
Quoted 8 lines
Quoted 4 lines
In this way, we decouple the two drivers and we leverage the auxiliary bus paradigm. Also, no DT node needed for the fan.
Do we all agree on this approach?
A gentle reminder about this inquiry. Before refactoring both the PWM and the fan driver I'd like to be sure that the proposed approach is at least acceptable.
This is just as bad as the exported symbol, as it creates a cross-module dependency which I would strongly prefer to avoid. Given that this is actually suggested in the guidance for auxiliary drivers (shiver), lets just keep the EXPORT_SYMBOL_NS approach after all.
Guenter