diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2021-01-14 23:48:04 +0300 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2021-03-22 13:48:07 +0300 |
commit | ca0d2fb790eb26fc53d851007ed1ead6c048be11 (patch) | |
tree | e80ce9c3b4fda243f785b559b358a8d3a5af4281 /drivers/pwm/pwm-ab8500.c | |
parent | a38fd8748464831584a19438cbb3082b5a2dab15 (diff) | |
download | linux-ca0d2fb790eb26fc53d851007ed1ead6c048be11.tar.xz |
pwm: bcm2835: Improve period and duty cycle calculation
With an input clk rate bigger than 2000000000, scaler would have been
zero which then would have resulted in a division by zero.
Also the originally implemented algorithm divided by the result of a
division. This nearly always looses precision. Consider a requested period
of 1000000 ns. With an input clock frequency of 32786885 Hz the hardware
was configured with an actual period of 983869.007 ns (PERIOD = 32258)
while the hardware can provide 1000003.508 ns (PERIOD = 32787).
And note if the input clock frequency was 32786886 Hz instead, the hardware
was configured to 1016656.477 ns (PERIOD = 33333) while the optimal
setting results in 1000003.477 ns (PERIOD = 32787).
This patch implements proper range checking and only divides once for
the calculation of period (and similar for duty_cycle).
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Tested-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-ab8500.c')
0 files changed, 0 insertions, 0 deletions