Skip to content

Commit 7612872

Browse files
committed
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
2 parents e9338ab + f4a8e31 commit 7612872

File tree

5 files changed

+56
-73
lines changed

5 files changed

+56
-73
lines changed

drivers/pwm/pwm-berlin.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,9 @@ static int berlin_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
190190
return 0;
191191
}
192192

193-
if (state->period != pwm->state.period ||
194-
state->duty_cycle != pwm->state.duty_cycle) {
195-
err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period);
196-
if (err)
197-
return err;
198-
}
193+
err = berlin_pwm_config(chip, pwm, state->duty_cycle, state->period);
194+
if (err)
195+
return err;
199196

200197
if (!enabled)
201198
return berlin_pwm_enable(chip, pwm);

drivers/pwm/pwm-ep93xx.c

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
6464
int ret;
6565
struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
6666
bool enabled = state->enabled;
67+
void __iomem *base = ep93xx_pwm->base;
68+
unsigned long long c;
69+
unsigned long period_cycles;
70+
unsigned long duty_cycles;
71+
unsigned long term;
6772

6873
if (state->polarity != pwm->state.polarity) {
6974
if (enabled) {
@@ -97,57 +102,47 @@ static int ep93xx_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
97102
return 0;
98103
}
99104

100-
if (state->period != pwm->state.period ||
101-
state->duty_cycle != pwm->state.duty_cycle) {
102-
struct ep93xx_pwm *ep93xx_pwm = to_ep93xx_pwm(chip);
103-
void __iomem *base = ep93xx_pwm->base;
104-
unsigned long long c;
105-
unsigned long period_cycles;
106-
unsigned long duty_cycles;
107-
unsigned long term;
105+
/*
106+
* The clock needs to be enabled to access the PWM registers.
107+
* Configuration can be changed at any time.
108+
*/
109+
if (!pwm_is_enabled(pwm)) {
110+
ret = clk_prepare_enable(ep93xx_pwm->clk);
111+
if (ret)
112+
return ret;
113+
}
108114

109-
/*
110-
* The clock needs to be enabled to access the PWM registers.
111-
* Configuration can be changed at any time.
112-
*/
113-
if (!pwm_is_enabled(pwm)) {
114-
ret = clk_prepare_enable(ep93xx_pwm->clk);
115-
if (ret)
116-
return ret;
117-
}
115+
c = clk_get_rate(ep93xx_pwm->clk);
116+
c *= state->period;
117+
do_div(c, 1000000000);
118+
period_cycles = c;
119+
120+
c = period_cycles;
121+
c *= state->duty_cycle;
122+
do_div(c, state->period);
123+
duty_cycles = c;
118124

119-
c = clk_get_rate(ep93xx_pwm->clk);
120-
c *= state->period;
121-
do_div(c, 1000000000);
122-
period_cycles = c;
123-
124-
c = period_cycles;
125-
c *= state->duty_cycle;
126-
do_div(c, state->period);
127-
duty_cycles = c;
128-
129-
if (period_cycles < 0x10000 && duty_cycles < 0x10000) {
130-
term = readw(base + EP93XX_PWMx_TERM_COUNT);
131-
132-
/* Order is important if PWM is running */
133-
if (period_cycles > term) {
134-
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
135-
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
136-
} else {
137-
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
138-
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
139-
}
140-
ret = 0;
125+
if (period_cycles < 0x10000 && duty_cycles < 0x10000) {
126+
term = readw(base + EP93XX_PWMx_TERM_COUNT);
127+
128+
/* Order is important if PWM is running */
129+
if (period_cycles > term) {
130+
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
131+
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
141132
} else {
142-
ret = -EINVAL;
133+
writew(duty_cycles, base + EP93XX_PWMx_DUTY_CYCLE);
134+
writew(period_cycles, base + EP93XX_PWMx_TERM_COUNT);
143135
}
136+
ret = 0;
137+
} else {
138+
ret = -EINVAL;
139+
}
144140

145-
if (!pwm_is_enabled(pwm))
146-
clk_disable_unprepare(ep93xx_pwm->clk);
141+
if (!pwm_is_enabled(pwm))
142+
clk_disable_unprepare(ep93xx_pwm->clk);
147143

148-
if (ret)
149-
return ret;
150-
}
144+
if (ret)
145+
return ret;
151146

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

drivers/pwm/pwm-spear.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,9 @@ static int spear_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
177177
return 0;
178178
}
179179

180-
if (state->period != pwm->state.period ||
181-
state->duty_cycle != pwm->state.duty_cycle) {
182-
err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period);
183-
if (err)
184-
return err;
185-
}
180+
err = spear_pwm_config(chip, pwm, state->duty_cycle, state->period);
181+
if (err)
182+
return err;
186183

187184
if (!pwm->state.enabled)
188185
return spear_pwm_enable(chip, pwm);

drivers/pwm/pwm-sprd.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,10 @@ static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
183183
}
184184
}
185185

186-
if (state->period != cstate->period ||
187-
state->duty_cycle != cstate->duty_cycle) {
188-
ret = sprd_pwm_config(spc, pwm, state->duty_cycle,
189-
state->period);
190-
if (ret)
191-
return ret;
192-
}
186+
ret = sprd_pwm_config(spc, pwm, state->duty_cycle,
187+
state->period);
188+
if (ret)
189+
return ret;
193190

194191
sprd_pwm_write(spc, pwm->hwpwm, SPRD_PWM_ENABLE, 1);
195192
} else if (cstate->enabled) {

drivers/pwm/pwm-tiecap.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,13 @@ static int ecap_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
189189
return 0;
190190
}
191191

192-
if (state->period != pwm->state.period ||
193-
state->duty_cycle != pwm->state.duty_cycle) {
194-
if (state->period > NSEC_PER_SEC)
195-
return -ERANGE;
192+
if (state->period > NSEC_PER_SEC)
193+
return -ERANGE;
196194

197-
err = ecap_pwm_config(chip, pwm, state->duty_cycle,
198-
state->period, enabled);
199-
if (err)
200-
return err;
201-
}
195+
err = ecap_pwm_config(chip, pwm, state->duty_cycle,
196+
state->period, enabled);
197+
if (err)
198+
return err;
202199

203200
if (!enabled)
204201
return ecap_pwm_enable(chip, pwm);

0 commit comments

Comments
 (0)