qualcommax: fix pwm period calculation
The GL.iNet GL-AXT1800 (ipq6018) requests a 40,000 ns (25 kHz) PWM
period for its four-wire fan:
pwms = <&pwm 1 40000 0>;
with the IPQ6018 PWM node clocked at 100 MHz. ipq_pwm_apply() pins
pwm_div at its maximum and derives only pre_div from the requested
period:
pre_div = period_ns * clk_rate / (NSEC_PER_SEC * (pwm_div + 1));
if (!pre_div)
return -ERANGE;
For 40,000 ns at 100 MHz this is floor(0.061) == 0, so the driver
deterministically returns -ERANGE and pwm-fan fails to probe on every
boot:
pwm-fan pwm-fan: failed to enable PWM
pwm-fan pwm-fan: Failed to configure PWM: -34
pwm-fan pwm-fan: probe with driver pwm-fan failed with error -34
Probe returns before the tachometer IRQ is requested and before
fan-supply is claimed, so the board loses fan RPM reporting and the
vcc_fan 5V regulator stays disabled. The fan never spins and the DTS
cooling-maps (trips at 50/75/100 C) have no cooling device to bind to.
This is the same defect fixed for qualcommbe in commit
8db23dc91a01
("qualcommbe: fix pwm period calculation") by Kenneth Kasilag, whose
rationale explicitly calls out 25 kHz four-wire fan PWM. qualcommax
carries its own copy of the pwm-ipq driver and was not covered by that
fix. The patch added here is that work backported to qualcommax, with
authorship preserved; the base driver differs slightly between targets
so the hunks were rebased onto the qualcommax copy.
Confirmed on hardware. The board was tested on the 6.12 kernel, which
this target has since dropped; the pwm-ipq driver source is identical
under 6.12 and 6.18, so the patch and its effect are unchanged. Before,
driving the PWM directly from userspace on a GL-AXT1800 running
r35591-
d0110a25ed:
# echo 40000 > period; echo 1 > enable -> write error (-ERANGE)
# echo
2700000 > period; echo 1 > enable -> succeeds
After building and flashing an image with this patch, pwm-fan probes
cleanly and the fan is verified spinning by its own tachometer:
/sys/class/hwmon/hwmon7/name = pwmfan
/sys/devices/platform/pwm-fan/hwmon/hwmon7/fan1_input = 3548
/sys/class/regulator/regulator.3 (vcc_fan) = enabled
/sys/class/thermal/cooling_device1 = pwm-fan
and no PWM errors remain in dmesg.
Link: https://github.com/openwrt/openwrt/commit/8db23dc91a015bf843f1e3fbd0891574594e86f9
Signed-off-by: Stephane Lepain <stephanelepain@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/24479
Signed-off-by: Robert Marko <robimarko@gmail.com>