From: Andrea della Porta <andrea.porta@suse.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>,
linux-pwm@vger.kernel.org, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, devicetree@vger.kernel.org,
florian.fainelli@broadcom.com, rjui@broadcom.com,
sbranden@broadcom.com, bcm-kernel-feedback-list@broadcom.com,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: naush@raspberrypi.com, svarbanov@suse.de, gary@garyguo.net,
linux@roeck-us.net, linux-hwmon@vger.kernel.org,
krzysztof.kozlowski@oss.qualcomm.com,
Andrea della Porta <andrea.porta@suse.com>
Subject: [PATCH v13 3/3] pwm: rp1: Register auxiliary device for the fan tachometer
Date: Tue, 24 Nov 2026 18:36:57 +0100 [thread overview]
Message-ID: <20261124173658.31030-4-andrea.porta@suse.com> (raw)
In-Reply-To: <20261124173658.31030-1-andrea.porta@suse.com>
On the Raspberry Pi 5, the firmware running on the RP1 Cortex-M core
measures the fan tachometer pulses and periodically writes the computed
RPM value into the phase register of PWM channel 2, inside the RP1 PWM
controller register block.
The Linux PWM framework has no abstraction to report such a value, and
the reading belongs to the hwmon subsystem. Following the auxiliary bus
model, let the PWM driver instantiate a "fan" auxiliary device
(pwm_rp1.fan.<id>) to which the hwmon driver can bind, without needing
any additional DT node.
The way the tachometer value is obtained (the register is shared with
the channel phase control) is an implementation detail of the PWM
driver, so provide rp1_pwm_read_tachometer(), exported in the 'RP1_PWM'
symbol namespace, for the auxiliary driver to use, as documented in
Documentation/driver-api/auxiliary_bus.rst.
The auxiliary device is destroyed first in .remove(), so that the hwmon
driver is unbound before the PWM controller resources are released.
Signed-off-by: Andrea della Porta <andrea.porta@suse.com>
---
MAINTAINERS | 1 +
drivers/pwm/Kconfig | 5 +++
drivers/pwm/pwm-rp1.c | 49 +++++++++++++++++++++++
include/soc/bcm2835/raspberrypi-pwm-rp1.h | 12 ++++++
4 files changed, 67 insertions(+)
create mode 100644 include/soc/bcm2835/raspberrypi-pwm-rp1.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 5c7b280a2bdb..26f8520c02ee 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23382,6 +23382,7 @@ L: linux-pwm@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/pwm/raspberrypi,rp1-pwm.yaml
F: drivers/pwm/pwm-rp1.c
+F: include/soc/bcm2835/raspberrypi-pwm-rp1.h
RC-CORE / LIRC FRAMEWORK
M: Sean Young <sean@mess.org>
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 523789e82355..7b271a16a483 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -641,9 +641,14 @@ config PWM_RASPBERRYPI_RP1
tristate "RP1 PWM support"
depends on MISC_RP1 || COMPILE_TEST
depends on HAS_IOMEM
+ select AUXILIARY_BUS
help
PWM framework driver for Raspberry Pi RP1 controller.
+ The driver also registers an auxiliary device that allows the
+ companion hwmon driver (SENSORS_RP1_FAN) to report the fan speed
+ measured by the RP1 firmware.
+
config PWM_SAMSUNG
tristate "Samsung PWM support"
depends on PLAT_SAMSUNG || ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST
diff --git a/drivers/pwm/pwm-rp1.c b/drivers/pwm/pwm-rp1.c
index 69ce0db4e9aa..f7443b9f9fa1 100644
--- a/drivers/pwm/pwm-rp1.c
+++ b/drivers/pwm/pwm-rp1.c
@@ -38,6 +38,7 @@
* channel. As a result, phase control will be ignored for now.
*/
+#include <linux/auxiliary_bus.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
#include <linux/clk.h>
@@ -49,6 +50,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)
@@ -79,12 +81,16 @@ enum rp1_pwm_ctrl_mode {
#define RP1_PWM_NUM_PWMS 4
+/* Channel whose phase register is used by the firmware to report the fan RPM */
+#define RP1_PWM_FAN_TACH_CHAN 2
+
struct rp1_pwm {
void __iomem *base;
struct clk *clk;
unsigned long clk_rate;
bool clk_enabled;
spinlock_t lock; /* sync for RP1_PWM_GLB_CTRL RMW access */
+ struct auxiliary_device *fan_adev;
};
struct rp1_pwm_waveform {
@@ -286,6 +292,32 @@ static const struct pwm_ops rp1_pwm_ops = {
.write_waveform = rp1_pwm_write_waveform,
};
+/**
+ * rp1_pwm_read_tachometer() - read the fan speed reported by the RP1 firmware
+ * @adev: the "fan" auxiliary device registered by this driver
+ * @rpm: where to store the fan speed, in RPM
+ *
+ * Meant to be called only by the driver bound to the auxiliary device
+ * created by rp1_pwm_probe(), which carries the controller private data as
+ * platform data. The auxiliary device is unregistered before the PWM
+ * controller resources are released, so that data is guaranteed to be
+ * valid for as long as the auxiliary driver is bound.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int rp1_pwm_read_tachometer(struct auxiliary_device *adev, u32 *rpm)
+{
+ struct rp1_pwm *rp1 = dev_get_platdata(&adev->dev);
+
+ if (!rp1->clk_enabled)
+ return -EBUSY;
+
+ *rpm = readl(rp1->base + RP1_PWM_PHASE(RP1_PWM_FAN_TACH_CHAN));
+
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(rp1_pwm_read_tachometer, "RP1_PWM");
+
static int rp1_pwm_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -347,8 +379,23 @@ static int rp1_pwm_probe(struct platform_device *pdev)
goto err_disable_clk;
}
+ /*
+ * The fan tachometer is exposed to the hwmon subsystem through an
+ * auxiliary device. The chip id is unique, so it is used to avoid
+ * name clashes if more than one RP1 PWM controller is enabled.
+ */
+ rp1->fan_adev = auxiliary_device_create(dev, KBUILD_MODNAME, "fan",
+ rp1, chip->id);
+ if (!rp1->fan_adev) {
+ ret = dev_err_probe(dev, -ENODEV,
+ "Failed to register fan auxiliary device\n");
+ goto err_remove_chip;
+ }
+
return 0;
+err_remove_chip:
+ pwmchip_remove(chip);
err_disable_clk:
clk_disable_unprepare(rp1->clk);
@@ -360,6 +407,8 @@ static void rp1_pwm_remove(struct platform_device *pdev)
struct pwm_chip *chip = platform_get_drvdata(pdev);
struct rp1_pwm *rp1 = pwmchip_get_drvdata(chip);
+ /* Unbind the fan driver before tearing down the PWM controller */
+ auxiliary_device_destroy(rp1->fan_adev);
pwmchip_remove(chip);
if (rp1->clk_enabled) {
diff --git a/include/soc/bcm2835/raspberrypi-pwm-rp1.h b/include/soc/bcm2835/raspberrypi-pwm-rp1.h
new file mode 100644
index 000000000000..290a052480bc
--- /dev/null
+++ b/include/soc/bcm2835/raspberrypi-pwm-rp1.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __SOC_RASPBERRY_PWM_RP1_H__
+#define __SOC_RASPBERRY_PWM_RP1_H__
+
+#include <linux/types.h>
+
+struct auxiliary_device;
+
+int rp1_pwm_read_tachometer(struct auxiliary_device *adev, u32 *rpm);
+
+#endif /* __SOC_RASPBERRY_PWM_RP1_H__ */
--
2.51.0
prev parent reply other threads:[~2026-11-24 17:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 17:36 [PATCH v13 0/3] Add RP1 PWM controller support Andrea della Porta
2026-11-24 17:36 ` [PATCH v13 1/3] dt-bindings: pwm: Add Raspberry Pi RP1 PWM controller Andrea della Porta
2026-11-24 17:36 ` [PATCH v13 2/3] pwm: rp1: Add RP1 PWM controller driver Andrea della Porta
2026-11-24 17:36 ` Andrea della Porta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124173658.31030-4-andrea.porta@suse.com \
--to=andrea.porta@suse.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=florian.fainelli@broadcom.com \
--cc=gary@garyguo.net \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=linux@roeck-us.net \
--cc=naush@raspberrypi.com \
--cc=rjui@broadcom.com \
--cc=robh@kernel.org \
--cc=sbranden@broadcom.com \
--cc=svarbanov@suse.de \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®