pwm: Fixes for v5.14-rc2

This contains a couple of fixes from Uwe that I missed for v5.14-rc1.
 -----BEGIN PGP SIGNATURE-----
 
 iQJNBAABCAA3FiEEiOrDCAFJzPfAjcif3SOs138+s6EFAmDukoMZHHRoaWVycnku
 cmVkaW5nQGdtYWlsLmNvbQAKCRDdI6zXfz6zoSe0D/wNNdTHdI3uzn/jhU6W1Hmw
 CHU0nza4wh/n445VYc/0+0dFxMEqyI/vwGw79xcpTb/drydklJ9FrpXqSG4Tp2T0
 cW/Br3w89yAtNvO/gsbro+ckgHfhLO+O1hZ9OtpbsqKMgnXWwky5qc7mfojUaAEu
 aCBnbJ0f7BVm4BHIjQirbys5txs/tnExtuOPjGRYs5/UP2jLi8mqHlt3/sUHsT49
 u/x1nhGp3/NReJUou0CKvmHS1srNn7c8dGCINR1cPv57WdWwABXSSAp7iRYyqR+g
 /4dIeo5ToA7l3c5KEmcwA/d1vNlDB6B6YI6lgiBthxTnS+F07nEv1IJCbb1RzSXJ
 8Sg8az8Vfza/Dv/TB5Tmn01YNPFXa+XX+f3mP9syuYUd3G9xf8+QekkGK4hXSGIi
 ZkeoozwRjHy0TA5g0DqynciAjEYBV2DqBrBhdFVaDlCzEdPuSNY2Y4B5HXHC/ZM0
 2i5e4+yd1cOrsW0Pzx02wQxlAl6ZE0uM6HJZkMSTzYI+zU85izQurA2hXyHPjopF
 tHK0HZRKa4Xg+ua+85TTjpKgQnQcZgLUNgtrbZ7mdbZO0S2leAQs3Sa0UBGiSxO5
 UPj1DUVpmN7uw95Qm/giD4NndEtlsit7DMY2pBrOt+NUPfM5yiLXhSB8C8+BJFVp
 xNfpu1LWd8l5OVd4txEpLA==
 =ij9H
 -----END PGP SIGNATURE-----

Merge tag 'pwm/for-5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm

Pull pwm fixes from Thierry Reding:
 "A couple of fixes from Uwe that I missed for v5.14-rc1"

* tag 'pwm/for-5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
  pwm: ep93xx: Ensure configuring period and duty_cycle isn't wrongly skipped
  pwm: berlin: Ensure configuring period and duty_cycle isn't wrongly skipped
  pwm: tiecap: Ensure configuring period and duty_cycle isn't wrongly skipped
  pwm: spear: Ensure configuring period and duty_cycle isn't wrongly skipped
  pwm: sprd: Ensure configuring period and duty_cycle isn't wrongly skipped
This commit is contained in:
Linus Torvalds 2021-07-15 17:29:44 -07:00
commit 7612872866
5 changed files with 59 additions and 76 deletions

View File

@ -190,12 +190,9 @@ static int berlin_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) {
err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;
}
err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;
if (!enabled)
return berlin_pwm_enable(chip, pwm);

View File

@ -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,58 +102,48 @@ 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.
*/
if (!pwm_is_enabled(pwm)) {
ret = clk_prepare_enable(ep93xx_pwm->clk);
if (ret)
return ret;
}
c = clk_get_rate(ep93xx_pwm->clk);
c *= state->period;
do_div(c, 1000000000);
period_cycles = c;
c = period_cycles;
c *= state->duty_cycle;
do_div(c, state->period);
duty_cycles = c;
if (period_cycles < 0x10000 && duty_cycles < 0x10000) {
term = readw(base + EP93XX_PWMx_TERM_COUNT);
/* Order is important if PWM is running */
if (period_cycles > term) {
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
} else {
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
}
ret = 0;
} else {
ret = -EINVAL;
}
if (!pwm_is_enabled(pwm))
clk_disable_unprepare(ep93xx_pwm->clk);
/*
* The clock needs to be enabled to access the PWM registers.
* Configuration can be changed at any time.
*/
if (!pwm_is_enabled(pwm)) {
ret = clk_prepare_enable(ep93xx_pwm->clk);
if (ret)
return ret;
}
c = clk_get_rate(ep93xx_pwm->clk);
c *= state->period;
do_div(c, 1000000000);
period_cycles = c;
c = period_cycles;
c *= state->duty_cycle;
do_div(c, state->period);
duty_cycles = c;
if (period_cycles < 0x10000 && duty_cycles < 0x10000) {
term = readw(base + EP93XX_PWMx_TERM_COUNT);
/* Order is important if PWM is running */
if (period_cycles > term) {
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
} else {
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
}
ret = 0;
} else {
ret = -EINVAL;
}
if (!pwm_is_enabled(pwm))
clk_disable_unprepare(ep93xx_pwm->clk);
if (ret)
return ret;
if (!enabled) {
ret = clk_prepare_enable(ep93xx_pwm->clk);
if (ret)

View File

@ -177,12 +177,9 @@ static int spear_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) {
err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;
}
err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period);
if (err)
return err;
if (!pwm->state.enabled)
return spear_pwm_enable(chip, pwm);

View File

@ -183,13 +183,10 @@ static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
}
}
if (state->period != cstate->period ||
state->duty_cycle != cstate->duty_cycle) {
ret = sprd_pwm_config(spc, pwm, state->duty_cycle,
state->period);
if (ret)
return ret;
}
ret = sprd_pwm_config(spc, pwm, state->duty_cycle,
state->period);
if (ret)
return ret;
sprd_pwm_write(spc, pwm->hwpwm, SPRD_PWM_ENABLE, 1);
} else if (cstate->enabled) {

View File

@ -189,16 +189,13 @@ static int ecap_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) {
if (state->period > NSEC_PER_SEC)
return -ERANGE;
if (state->period > NSEC_PER_SEC)
return -ERANGE;
err = ecap_pwm_config(chip, pwm, state->duty_cycle,
state->period, enabled);
if (err)
return err;
}
err = ecap_pwm_config(chip, pwm, state->duty_cycle,
state->period, enabled);
if (err)
return err;
if (!enabled)
return ecap_pwm_enable(chip, pwm);