pwm: sifive: Fix PWM algorithm and clarify inverted compare behavior
authorNylon Chen <nylon.chen@sifive.com>
Thu, 29 May 2025 03:53:40 +0000 (11:53 +0800)
committerUwe Kleine-König <ukleinek@kernel.org>
Mon, 7 Jul 2025 06:39:34 +0000 (08:39 +0200)
commit7dbc4432ea6bf9d709391eb57f1e9fb44e99845a
tree3deab3d9770eeb4960ea9b946ad4efbdaed28f2d
parentf4bcf818e5d6474c981ef16153827458a2b57181
pwm: sifive: Fix PWM algorithm and clarify inverted compare behavior

The `frac` variable represents the pulse inactive time, and the result
of this algorithm is the pulse active time. Therefore, we must reverse
the result.

Although the SiFive Reference Manual states "pwms >= pwmcmpX -> HIGH",
the hardware behavior is inverted due to a fixed XNOR with 0. As a result,
the pwmcmp register actually defines the low (inactive) portion of the pulse.

The reference is SiFive FU740-C000 Manual[0]

Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf
Co-developed-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
Co-developed-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Link: https://lore.kernel.org/r/20250529035341.51736-3-nylon.chen@sifive.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-sifive.c