Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm-sun4i: Calculate "delay_jiffies" directly, eliminate absolute time

Basically this code did "jiffies + period - jiffies", and we can
simply eliminate the "jiffies" time stamp here.

Signed-off-by: Max Kellermann <max.kellermann@gmail.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Max Kellermann and committed by
Thierry Reding
ba3e5037 c7078972

+7 -12
+7 -12
drivers/pwm/pwm-sun4i.c
··· 234 234 struct pwm_state cstate; 235 235 u32 ctrl, duty = 0, period = 0, val; 236 236 int ret; 237 + unsigned int delay_jiffies; 237 238 unsigned int delay_us, prescaler = 0; 238 - unsigned long now; 239 - unsigned long next_period; 240 239 bool bypass; 241 240 242 241 pwm_get_state(pwm, &cstate); ··· 283 284 284 285 val = (duty & PWM_DTY_MASK) | PWM_PRD(period); 285 286 sun4i_pwm_writel(sun4i_pwm, val, PWM_CH_PRD(pwm->hwpwm)); 286 - next_period = jiffies + 287 - nsecs_to_jiffies(cstate.period + 1000); 288 287 289 288 if (state->polarity != PWM_POLARITY_NORMAL) 290 289 ctrl &= ~BIT_CH(PWM_ACT_STATE, pwm->hwpwm); ··· 302 305 return 0; 303 306 304 307 /* We need a full period to elapse before disabling the channel. */ 305 - now = jiffies; 306 - if (time_before(now, next_period)) { 307 - delay_us = jiffies_to_usecs(next_period - now); 308 - if ((delay_us / 500) > MAX_UDELAY_MS) 309 - msleep(delay_us / 1000 + 1); 310 - else 311 - usleep_range(delay_us, delay_us * 2); 312 - } 308 + delay_jiffies = nsecs_to_jiffies(cstate.period + 1000); 309 + delay_us = jiffies_to_usecs(delay_jiffies); 310 + if ((delay_us / 500) > MAX_UDELAY_MS) 311 + msleep(delay_us / 1000 + 1); 312 + else 313 + usleep_range(delay_us, delay_us * 2); 313 314 314 315 spin_lock(&sun4i_pwm->ctrl_lock); 315 316 ctrl = sun4i_pwm_readl(sun4i_pwm, PWM_CTRL_REG);