Commit f4a8e31e authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Thierry Reding
Browse files

pwm: ep93xx: Ensure configuring period and duty_cycle isn't wrongly skipped



As the last call to ep93xx_pwm_apply() might have exited early if
state->enabled was false, the values for period and duty_cycle stored in
pwm->state might not have been written to hardware and it must be
ensured that they are configured before enabling the PWM.

Fixes: 6d45374a ("pwm: ep93xx: Implement .apply callback")
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent 7d6d4aaf
Loading
Loading
Loading
Loading
+40 −45
Original line number Diff line number Diff line
@@ -64,6 +64,11 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
	int ret;
	struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
	bool enabled = state->enabled;
	void __iomem *base = ep93xx_pwm->base;
	unsigned long long c;
	unsigned long period_cycles;
	unsigned long duty_cycles;
	unsigned long term;

	if (state->polarity != pwm->state.polarity) {
		if (enabled) {
@@ -97,15 +102,6 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
		return 0;
	}

	if (state->period != pwm->state.period ||
	    state->duty_cycle != pwm->state.duty_cycle) {
		struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
		void __iomem *base = ep93xx_pwm->base;
		unsigned long long c;
		unsigned long period_cycles;
		unsigned long duty_cycles;
		unsigned long term;

	/*
	 * The clock needs to be enabled to access the PWM registers.
	 * Configuration can be changed at any time.
@@ -147,7 +143,6 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

	if (ret)
		return ret;
	}

	if (!enabled) {
		ret = clk_prepare_enable(ep93xx_pwm->clk);