misc: pm8058-pwm: bypass period calculation if no change
If a period is the same as before, there is no need to recalculate
it. This patch is adding such optimizations.
Signed-off-by: Willie Ruan <wruan@codeaurora.org>
diff --git a/drivers/misc/pmic8058-pwm.c b/drivers/misc/pmic8058-pwm.c
index ddf29c5..451bb56 100644
--- a/drivers/misc/pmic8058-pwm.c
+++ b/drivers/misc/pmic8058-pwm.c
@@ -625,7 +625,7 @@
int rc;
if (pwm == NULL || IS_ERR(pwm) ||
- (unsigned)duty_us > (unsigned)period_us ||
+ duty_us > period_us ||
(unsigned)period_us > PM_PWM_PERIOD_MAX ||
(unsigned)period_us < PM_PWM_PERIOD_MIN)
return -EINVAL;
@@ -639,9 +639,12 @@
goto out_unlock;
}
- pm8058_pwm_calc_period(period_us, &pwm->period);
+ if (pwm->pwm_period != period_us) {
+ pm8058_pwm_calc_period(period_us, &pwm->period);
+ pm8058_pwm_save_period(pwm);
+ pwm->pwm_period = period_us;
+ }
- pm8058_pwm_save_period(pwm);
pm8058_pwm_calc_pwm_value(pwm, period_us, duty_us);
pm8058_pwm_save_pwm_value(pwm);
pm8058_pwm_save(&pwm->pwm_ctl[1],
@@ -754,8 +757,11 @@
goto out_unlock;
}
- pm8058_pwm_calc_period(period_us, &pwm->period);
- pm8058_pwm_save_period(pwm);
+ if (pwm->pwm_period != period_us) {
+ pm8058_pwm_calc_period(period_us, &pwm->period);
+ pm8058_pwm_save_period(pwm);
+ pwm->pwm_period = period_us;
+ }
len = (idx_len > PM_PWM_LUT_SIZE) ? PM_PWM_LUT_SIZE : idx_len;