pwm: stm32-lp: Add check in case requested period cannot be achieved
authorFabrice Gasnier <fabrice.gasnier@st.com>
Wed, 18 Sep 2019 14:54:21 +0000 (16:54 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Oct 2019 16:21:17 +0000 (18:21 +0200)
commit65348659535d23e6fb7a79aa9d54332479cf980e
tree599a37be88f9b764e93b864a96c160887ba50aa9
parent19b1c70e911c4979a501a56228414cbc4229982d
pwm: stm32-lp: Add check in case requested period cannot be achieved

[ Upstream commit c91e3234c6035baf5a79763cb4fcd5d23ce75c2b ]

LPTimer can use a 32KHz clock for counting. It depends on clock tree
configuration. In such a case, PWM output frequency range is limited.
Although unlikely, nothing prevents user from requesting a PWM frequency
above counting clock (32KHz for instance):
- This causes (prd - 1) = 0xffff to be written in ARR register later in
the apply() routine.
This results in badly configured PWM period (and also duty_cycle).
Add a check to report an error is such a case.

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pwm/pwm-stm32-lp.c