Skip to content

Commit 3586b02

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: sifive: Enable clk only after period check in .apply()
For the period check and the initial calculations of register values there is no hardware access needed. So delay enabling the clk a bit to simplify the code flow a bit. Signed-off-by: Uwe Kleine-König <[email protected]> Tested-by: Emil Renner Berthing <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 0f02f49 commit 3586b02

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

drivers/pwm/pwm-sifive.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
139139
if (state->polarity != PWM_POLARITY_INVERSED)
140140
return -EINVAL;
141141

142-
ret = clk_enable(ddata->clk);
143-
if (ret) {
144-
dev_err(ddata->chip.dev, "Enable clk failed\n");
145-
return ret;
146-
}
147-
148142
cur_state = pwm->state;
149143
enabled = cur_state.enabled;
150144

@@ -167,14 +161,19 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
167161
if (state->period != ddata->approx_period) {
168162
if (ddata->user_count != 1) {
169163
mutex_unlock(&ddata->lock);
170-
ret = -EBUSY;
171-
goto exit;
164+
return -EBUSY;
172165
}
173166
ddata->approx_period = state->period;
174167
pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk));
175168
}
176169
mutex_unlock(&ddata->lock);
177170

171+
ret = clk_enable(ddata->clk);
172+
if (ret) {
173+
dev_err(ddata->chip.dev, "Enable clk failed\n");
174+
return ret;
175+
}
176+
178177
writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm));
179178

180179
if (state->enabled != enabled) {
@@ -186,9 +185,8 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
186185
}
187186
}
188187

189-
exit:
190188
clk_disable(ddata->clk);
191-
return ret;
189+
return 0;
192190
}
193191

194192
static const struct pwm_ops pwm_sifive_ops = {

0 commit comments

Comments
 (0)