From 9e832877f592d726f37f90ef1e9e201fada7645b Mon Sep 17 00:00:00 2001 From: Jian Hu Date: Wed, 9 May 2018 13:50:29 +0800 Subject: [PATCH] pwm: fix min and max duty cycle PD#165774: pwm: fix min and max duty cycle When the duty equal 0% and 100%, there is one high or low count ,the constant bit should be enabled;and constant bit should be disabled for other duty_cycle. Change-Id: I36eefee3613f113f6c30db076e41cd8223086c54 Signed-off-by: Jian Hu --- drivers/amlogic/pwm/pwm_meson.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/amlogic/pwm/pwm_meson.c b/drivers/amlogic/pwm/pwm_meson.c index e7b1b1ddad41..22853df3c023 100644 --- a/drivers/amlogic/pwm/pwm_meson.c +++ b/drivers/amlogic/pwm/pwm_meson.c @@ -204,12 +204,12 @@ static int meson_pwm_calc(struct meson_pwm *meson, if (duty == period) { channel->pre_div = pre_div; - channel->hi = cnt - 1; + channel->hi = cnt; channel->lo = 0; } else if (duty == 0) { channel->pre_div = pre_div; channel->hi = 0; - channel->lo = cnt - 1; + channel->lo = cnt; } else { /* Then check is we can have the duty with the same pre_div */ duty_cnt = DIV_ROUND_CLOSEST_ULL((u64)duty * 1000, @@ -226,6 +226,16 @@ static int meson_pwm_calc(struct meson_pwm *meson, channel->hi = duty_cnt - 1; channel->lo = cnt - duty_cnt - 1; } + /* + * duty_cycle equal 0% and 100%,constant should be enabled, + * high and low count will not incease one; + * otherwise, high and low count increase one. + */ + if (duty == period || duty == 0) + pwm_constant_enable(meson, id); + else + pwm_constant_disable(meson, id); + return 0; }