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

Configure Feed

Select the types of activity you want to include in your feed.

pwm: sifive: Simplify clk handling

The clk is necessary for both register access and (enabled) operation of
the PWM. Instead of

clk_enable()
update_hw()
if pwm_got_enabled():
clk_enable()
elif pwm_got_disabled():
clk_disable()
clk_disable()

which is some cases only calls clk_enable() to immediately afterwards
call clk_disable again, do:

if (!prev_state.enabled)
clk_enable()

# clk enabled exactly once

update_hw()

if (!next_state.enabled)
clk_disable()

which is much easier.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
1695b421 3586b026

+13 -13
+13 -13
drivers/pwm/pwm-sifive.c
··· 168 168 } 169 169 mutex_unlock(&ddata->lock); 170 170 171 - ret = clk_enable(ddata->clk); 172 - if (ret) { 173 - dev_err(ddata->chip.dev, "Enable clk failed\n"); 174 - return ret; 171 + /* 172 + * If the PWM is enabled the clk is already on. So only enable it 173 + * conditionally to have it on exactly once afterwards independent of 174 + * the PWM state. 175 + */ 176 + if (!enabled) { 177 + ret = clk_enable(ddata->clk); 178 + if (ret) { 179 + dev_err(ddata->chip.dev, "Enable clk failed\n"); 180 + return ret; 181 + } 175 182 } 176 183 177 184 writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); 178 185 179 - if (state->enabled != enabled) { 180 - if (state->enabled) { 181 - if (clk_enable(ddata->clk)) 182 - dev_err(ddata->chip.dev, "Enable clk failed\n"); 183 - } else { 184 - clk_disable(ddata->clk); 185 - } 186 - } 186 + if (!state->enabled) 187 + clk_disable(ddata->clk); 187 188 188 - clk_disable(ddata->clk); 189 189 return 0; 190 190 } 191 191