pwm: renesas-tpu: Improve maths to compute register settings
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 20 Apr 2022 12:12:39 +0000 (14:12 +0200)
committerThierry Reding <thierry.reding@gmail.com>
Fri, 20 May 2022 14:18:05 +0000 (16:18 +0200)
commit3c173376efc461dc670b02ba2846c2a533491104
treecd48b75dfc3f01046d8b3096088dfdb96aab2526
parent208ab8676b9c787b4285364fcb52a159f94b861d
pwm: renesas-tpu: Improve maths to compute register settings

The newly computed register values are intended to exactly match the
previously computed values. The main improvement is that the prescaler
is computed without a loop that involves two divisions in each step.
This uses the fact, that prescalers[i] = 1 << (2 * i).

Assuming a moderately smart compiler, the needed number of divisions for
the case where the requested period is too big, is reduced from 5 to 2.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-renesas-tpu.c