Add JHB100 Fan-Tach support
Subsystems (3)
v3 cover Add JHB100 Fan-Tach support
StarFive Fan-Tach controller can support up to 16 fan tach input. The series has been tested on the EVB1 board.
Change since v2:
PATCH 2:
- Fix typo in commit message: than ==> then
- Remove struct device *dev and struct mutex lock from struct starfive_fan_tach_data.
- Change return type of starfive_fan_tach_get_ch_en() to bool.
- Simplify the condition check in starfive_fan_read() by removing the unnecessary intermediate ret variable assignment when checking the tachometer channel enable status.
- Return an error when tach_ch >= STARFIVE_FAN_TACH_CH.
- Add a description that accessing the fan status can be time-consuming in certain scenarios in starfive-fan-tach.rst.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Changhuang Liang (2):
dt-bindings: hwmon: Add starfive,jhb100-fan-tach
hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
.../hwmon/starfive,jhb100-fan-tach.yaml | 93 +++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/starfive-fan-tach.rst | 38 ++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 14 + drivers/hwmon/Makefile | 1 + drivers/hwmon/starfive-fan-tach.c | 540 ++++++++++++++++++ 7 files changed, 695 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/starfive,jhb100-fan-tach.yaml create mode 100644 Documentation/hwmon/starfive-fan-tach.rst create mode 100644 drivers/hwmon/starfive-fan-tach.c
--
2.25.1
PATCH v3 1/2 dt-bindings: hwmon: Add starfive,jhb100-fan-tach
Add compatible "starfive,jhb100-fan-tach" for StarFive JHB100 Fan-Tach controller.
--- .../hwmon/starfive,jhb100-fan-tach.yaml | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/starfive,jhb100-fan-tach.yaml
Documentation/devicetree/bindings/hwmon/starfive,jhb100-fan-tach.yaml new file +93 -0
@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/starfive,jhb100-fan-tach.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JHB100 Fan-Tach controller + +maintainers: + - Changhuang Liang <[email protected]> + +description: + The StarFive Fan-Tach controller can support up to 16 fan tach input. + +properties: + compatible: + enum: + - starfive,jhb100-fan-tach + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + interrupts: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^fan@[0-9a-f]+$": + $ref: fan-common.yaml# + unevaluatedProperties: false + + properties: + reg: + description: + PWM channel index. The driver allows two fans to share the same + PWM channel, or each fan to use a dedicated channel. + maximum: 15 + + tach-ch: + description: + The tachometer channel(s) wired to the fan(s) driven by this PWM + channel. Integer values in the range 0-15. + minItems: 1 + maxItems: 2 + items: + maximum: 15 + + required: + - reg + - tach-ch + +required: + - compatible + - reg + - clocks + - resets + - interrupts + +additionalProperties: false + +examples: + - | + fan-controller@11be0000 { + compatible = "starfive,jhb100-fan-tach"; + reg = <0x11be0000 0x400>; + interrupts = <128>; + clocks = <&per2crg 33>; + resets = <&per2crg 5>; + #address-cells = <1>; + #size-cells = <0>; + + fan@0 { + reg = <0x0>; + tach-ch = /bits/ 8 <0x0 0x8>; + pulses-per-revolution = <2>; + }; + fan@1 { + reg = <0x1>; + tach-ch = /bits/ 8 <0x1>; + pulses-per-revolution = <2>; + }; + };
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH v3 1/2] dt-bindings: hwmon: Add starfive,jhb100-fan-tach
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Add compatible "starfive,jhb100-fan-tach" for StarFive JHB100 Fan-Tach controller.
Signed-off-by Changhuang Liang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/2 hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
In reply to Changhuang LiangAdd fan tach driver for StarFive JHB100 SoC.
The controller supports up to 16 independent fan tachometer inputs and reports fan speed in RPM through the hwmon sysfs interface, along with stall and low-speed alarms.
For this controller, the special clock and reset operation sequence is:
probe: clk_prepare_enable() then reset_control_deassert()
remove: clk_disable_unprepare() then reset_control_assert()
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/starfive-fan-tach.rst | 38 ++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 14 + drivers/hwmon/Makefile | 1 + drivers/hwmon/starfive-fan-tach.c | 540 ++++++++++++++++++++++ 6 files changed, 602 insertions(+) create mode 100644 Documentation/hwmon/starfive-fan-tach.rst create mode 100644 drivers/hwmon/starfive-fan-tach.c
Documentation/hwmon/index.rst +1 -0
@@ -253,6 +253,7 @@ Hardware Monitoring Kernel Drivers smsc47m1 sparx5-temp spd5118 + starfive-fan-tach stpddc60 surface_fan sy7636a-hwmon
Documentation/hwmon/starfive-fan-tach.rst new file +38 -0
@@ -0,0 +1,38 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver starfive-fan-tach +=============================== + +Supported chips: + + * StarFive JHB100 + + Prefix: 'starfive_fan_tach' + + Addresses scanned: - + +Authors: + - Changhuang Liang <[email protected]> + +Description +----------- + +This driver implements support for the fan tachometer controller found on +the StarFive JHB100 SoC. The controller supports up to 16 independent fan +tachometer inputs. Each tachometer channel measures the number of pulses +within a fixed 100 ms window. + +Sysfs entries +------------- + +===================== ======================================================= +fan[1-16]_input Fan speed in RPM (read-only), without a fan connected, + reading this value can be significantly slow. +fan[1-16]_min Lower fan speed limit in RPM (read/write) +fan[1-16]_enable Enable/disable the tachometer channel (read/write) +fan[1-16]_fault Fan stall indication (read-only), with the fan running + normally, reading this value can be significantly slow. +fan[1-16]_min_alarm Fan speed below fan[1-16]_min (read-only), when + fan[1-16]_input is greater than or equal fan[1-16]_min, + reading this value can be significantly slow. +===================== =======================================================
MAINTAINERS +8 -0
@@ -25897,6 +25897,14 @@ S: Supported F: Documentation/devicetree/bindings/interrupt-controller/starfive,jhb100-intc.yaml F: drivers/irqchip/irq-starfive-jhb100-intc.c +STARFIVE JHB100 FAN-TACH DRIVER +M: Changhuang Liang <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/hwmon/starfive,jhb100-fan-tach.yaml +F: Documentation/hwmon/starfive-fan-tach.rst +F: drivers/hwmon/starfive-fan-tach.c + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/hwmon/Kconfig +14 -0
@@ -2383,6 +2383,20 @@ config SENSORS_SPD5118_DETECT If unsure, say Y. +config SENSORS_STARFIVE_FAN_TACH + tristate "StarFive Fan-Tach driver" + depends on ARCH_STARFIVE || COMPILE_TEST + depends on HAS_IOMEM + help + This driver provides support for the fan tachometer controller + found on StarFive SoCs such as the JHB100. The controller supports + up to 16 independent fan tachometer inputs and reports fan speed + in RPM through the hwmon sysfs interface, along with stall and + low-speed alarms. + + This driver can also be built as a module. If so, the module + will be called starfive-fan-tach. + config SENSORS_TC74 tristate "Microchip TC74" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -223,6 +223,7 @@ obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o obj-$(CONFIG_SENSORS_SPARX5) += sparx5-temp.o obj-$(CONFIG_SENSORS_SPD5118) += spd5118.o +obj-$(CONFIG_SENSORS_STARFIVE_FAN_TACH) += starfive-fan-tach.o obj-$(CONFIG_SENSORS_STTS751) += stts751.o obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o obj-$(CONFIG_SENSORS_SURFACE_TEMP)+= surface_temp.o
drivers/hwmon/starfive-fan-tach.c new file +540 -0
540 lines not on this page · raw message
--
2.25.1
[email protected]
AI reviewRe: [PATCH v3 2/2] hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing explicit initialization of interrupt and channel enable registers during probe --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing explicit initialization of interrupt and channel enable registers during probe --
--- Patch [2]: [PATCH v3 2/2] hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100 --- commit ea266a681c03cda9faa04f08b171c20f1e003841
Author: Changhuang Liang <[email protected]>
hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
This commit adds a new driver for the fan tachometer controller found on the StarFive JHB100 SoC. It provides support for up to 16 independent fan tachometer inputs and reports fan speed in RPM through the hwmon sysfs interface.
Quoted 5 lines
drivers/hwmon/starfive-fan-tach.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/hwmon/starfive-fan-tach.c new file +2
-0+static int starfive_fan_tach_probe (struct platform_device *pdev) +{
[ ... ]
Quoted 4 lines
drivers/hwmon/starfive-fan-tach.c new file +4
-0+ ret =reset_control_deassert (priv->rst); +if (ret) { +clk_disable_unprepare (priv->clk); +return dev_err_probe (dev, ret,"Failed to deassert reset\n" );
drivers/hwmon/starfive-fan-tach.c line 499
Quoted 10 lines
drivers/hwmon/starfive-fan-tach.c new file +10
-0+ } + + ret =devm_add_action_or_reset (dev, starfive_fan_tach_disable, priv); +if (ret) +return ret; + +writel (STARFIVE_FAN_TACH_STALL_INT_MASK |STARFIVE_FAN_TACH_SLOW_INT_MASK , + priv->regs +STARFIVE_FAN_TACH_STATUS ); +writel (priv->clk_rate /STARFIVE_FAN_DEFAULT_MEASURE_RATIO , + priv->regs +STARFIVE_FAN_TACH_MEASURE_TIME );
[Severity: Medium]
Could this code be susceptible to an interrupt storm if the bootloader leaves the FAN-TACH controller enabled with unmasked interrupts?
Since the driver only deasserts the reset line during probe (and does not assert it first), the hardware state might be retained from before the kernel booted. Any read-modify-write operations on STARFIVE_FAN_TACH_INT_EN and STARFIVE_FAN_TACH_CH_EN later in the driver would then preserve these stray bits.
Once devm_request_irq() is called, any unexpected unmasked interrupts will trigger. If the interrupt condition is continuous (e.g., a disconnected or stalled fan), the ISR will clear the STATUS bit, but the hardware will immediately re-assert it. Because the driver's ISR does not mask unexpected interrupts in INT_EN (it only signals completions if armed_stall or armed_slow are set), wouldn't this lead to an interrupt storm?
Should the interrupt and channel enable registers be explicitly initialized to 0 before requesting the IRQ to ensure a known safe hardware state?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Guenter Roeck
maintainerRe: [PATCH v3 2/2] hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
Quoted 56 lines · On 8/23/26 20:27, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing explicit initialization of interrupt and channel enable registers during probe ----- Patch [2]: [PATCH v3 2/2] hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100 --- commit
ea266a681c03cda9faa04f08b171c20f1e003841
Author: Changhuang Liang <[email protected]>hwmon: (starfive-fan-tach) Add fan tach driver for StarFive JHB100
This commit adds a new driver for the fan tachometer controller found on the StarFive JHB100 SoC. It provides support for up to 16 independent fan tachometer inputs and reports fan speed in RPM through the hwmon sysfs interface.
Quoted 5 lines
drivers/hwmon/starfive-fan-tach.c new file +0
-0[ ... ]
Quoted 2 lines
drivers/hwmon/starfive-fan-tach.c new file +2
-0+static int starfive_fan_tach_probe (struct platform_device *pdev) +{[ ... ]
Quoted 4 lines
drivers/hwmon/starfive-fan-tach.c new file +4
-0+ ret =reset_control_deassert (priv->rst); +if (ret) { +clk_disable_unprepare (priv->clk); +return dev_err_probe (dev, ret,"Failed to deassert reset\n" );drivers/hwmon/starfive-fan-tach.c line 499
Quoted 10 lines
drivers/hwmon/starfive-fan-tach.c new file +10
-0+ } + + ret =devm_add_action_or_reset (dev, starfive_fan_tach_disable, priv); +if (ret) +return ret; + +writel (STARFIVE_FAN_TACH_STALL_INT_MASK |STARFIVE_FAN_TACH_SLOW_INT_MASK , + priv->regs +STARFIVE_FAN_TACH_STATUS ); +writel (priv->clk_rate /STARFIVE_FAN_DEFAULT_MEASURE_RATIO , + priv->regs +STARFIVE_FAN_TACH_MEASURE_TIME );[Severity: Medium]
Could this code be susceptible to an interrupt storm if the bootloader leaves the FAN-TACH controller enabled with unmasked interrupts?Since the driver only deasserts the reset line during probe (and does not assert it first), the hardware state might be retained from before the kernel booted. Any read-modify-write operations on
STARFIVE_FAN_TACH_INT_ENandSTARFIVE_FAN_TACH_CH_ENlater in the driver would then preserve these stray bits.Once
devm_request_irq()is called, any unexpected unmasked interrupts will trigger. If the interrupt condition is continuous (e.g., a disconnected or stalled fan), the ISR will clear the STATUS bit, but the hardware will immediately re-assert it. Because the driver's ISR does not mask unexpected interrupts inINT_EN(it only signals completions ifarmed_stallorarmed_sloware set), wouldn't this lead to an interrupt storm?
Quoted 3 lines
Should the interrupt and channel enable registers be explicitly initialized to 0 before requesting the IRQ to ensure a known safe hardware state?
Please either implement as suggested or explain why it is not needed. In that case, please add a comment into the code explaining the reason.
Thanks,
Guenter