Skip to content

Commit 6701e7e

Browse files
committed
Merge tag 'pwm/for-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "The changes this time around are mostly janitorial in nature. A lot of this is simplifications of drivers using device-managed functions and improving compilation coverage. The Mediatek display PWM driver now supports the atomic API. Cleanups and minor fixes make up the remainder of this set" * tag 'pwm/for-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (54 commits) pwm: mtk-disp: Implement atomic API .get_state() pwm: mtk-disp: Fix overflow in period and duty calculation pwm: mtk-disp: Implement atomic API .apply() pwm: mtk-disp: Adjust the clocks to avoid them mismatch dt-bindings: pwm: rockchip: Add description for rk3568 pwm: Make pwmchip_remove() return void pwm: sun4i: Don't check the return code of pwmchip_remove() pwm: sifive: Don't check the return code of pwmchip_remove() pwm: samsung: Don't check the return code of pwmchip_remove() pwm: renesas-tpu: Don't check the return code of pwmchip_remove() pwm: rcar: Don't check the return code of pwmchip_remove() pwm: pca9685: Don't check the return code of pwmchip_remove() pwm: omap-dmtimer: Don't check the return code of pwmchip_remove() pwm: mtk-disp: Don't check the return code of pwmchip_remove() pwm: imx-tpm: Don't check the return code of pwmchip_remove() pwm: img: Don't check the return code of pwmchip_remove() pwm: cros-ec: Don't check the return code of pwmchip_remove() pwm: brcmstb: Don't check the return code of pwmchip_remove() pwm: atmel-tcb: Don't check the return code of pwmchip_remove() pwm: atmel-hlcdc: Don't check the return code of pwmchip_remove() ...
2 parents dd47038 + 3f2b167 commit 6701e7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+260
-440
lines changed

Documentation/devicetree/bindings/pwm/pwm-rockchip.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ properties:
2929
- enum:
3030
- rockchip,px30-pwm
3131
- rockchip,rk3308-pwm
32+
- rockchip,rk3568-pwm
3233
- const: rockchip,rk3328-pwm
3334

3435
reg:

drivers/pwm/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ config PWM_IQS620A
272272

273273
config PWM_JZ4740
274274
tristate "Ingenic JZ47xx PWM support"
275-
depends on MIPS
275+
depends on MIPS || COMPILE_TEST
276276
depends on COMMON_CLK
277277
select MFD_SYSCON
278278
help
@@ -284,7 +284,8 @@ config PWM_JZ4740
284284

285285
config PWM_KEEMBAY
286286
tristate "Intel Keem Bay PWM driver"
287-
depends on ARCH_KEEMBAY || (ARM64 && COMPILE_TEST)
287+
depends on ARCH_KEEMBAY || COMPILE_TEST
288+
depends on COMMON_CLK && HAS_IOMEM
288289
help
289290
The platform driver for Intel Keem Bay PWM controller.
290291

drivers/pwm/core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ EXPORT_SYMBOL_GPL(pwmchip_add);
304304
*
305305
* Returns: 0 on success or a negative error code on failure.
306306
*/
307-
int pwmchip_remove(struct pwm_chip *chip)
307+
void pwmchip_remove(struct pwm_chip *chip)
308308
{
309309
pwmchip_sysfs_unexport(chip);
310310

@@ -318,8 +318,6 @@ int pwmchip_remove(struct pwm_chip *chip)
318318
free_pwms(chip);
319319

320320
mutex_unlock(&pwm_lock);
321-
322-
return 0;
323321
}
324322
EXPORT_SYMBOL_GPL(pwmchip_remove);
325323

drivers/pwm/pwm-ab8500.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,29 @@
2222

2323
struct ab8500_pwm_chip {
2424
struct pwm_chip chip;
25+
unsigned int hwid;
2526
};
2627

28+
static struct ab8500_pwm_chip *ab8500_pwm_from_chip(struct pwm_chip *chip)
29+
{
30+
return container_of(chip, struct ab8500_pwm_chip, chip);
31+
}
32+
2733
static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
2834
const struct pwm_state *state)
2935
{
3036
int ret;
3137
u8 reg;
3238
unsigned int higher_val, lower_val;
39+
struct ab8500_pwm_chip *ab8500 = ab8500_pwm_from_chip(chip);
3340

3441
if (state->polarity != PWM_POLARITY_NORMAL)
3542
return -EINVAL;
3643

3744
if (!state->enabled) {
3845
ret = abx500_mask_and_set_register_interruptible(chip->dev,
3946
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
40-
1 << (chip->base - 1), 0);
47+
1 << ab8500->hwid, 0);
4148

4249
if (ret < 0)
4350
dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n",
@@ -56,7 +63,7 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
5663
*/
5764
higher_val = ((state->duty_cycle & 0x0300) >> 8);
5865

59-
reg = AB8500_PWM_OUT_CTRL1_REG + ((chip->base - 1) * 2);
66+
reg = AB8500_PWM_OUT_CTRL1_REG + (ab8500->hwid * 2);
6067

6168
ret = abx500_set_register_interruptible(chip->dev, AB8500_MISC,
6269
reg, (u8)lower_val);
@@ -70,7 +77,7 @@ static int ab8500_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
7077

7178
ret = abx500_mask_and_set_register_interruptible(chip->dev,
7279
AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG,
73-
1 << (chip->base - 1), 1 << (chip->base - 1));
80+
1 << ab8500->hwid, 1 << ab8500->hwid);
7481
if (ret < 0)
7582
dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n",
7683
pwm->label, ret);
@@ -88,6 +95,9 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
8895
struct ab8500_pwm_chip *ab8500;
8996
int err;
9097

98+
if (pdev->id < 1 || pdev->id > 31)
99+
return dev_err_probe(&pdev->dev, EINVAL, "Invalid device id %d\n", pdev->id);
100+
91101
/*
92102
* Nothing to be done in probe, this is required to get the
93103
* device which is required for ab8500 read and write
@@ -99,27 +109,13 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
99109
ab8500->chip.dev = &pdev->dev;
100110
ab8500->chip.ops = &ab8500_pwm_ops;
101111
ab8500->chip.npwm = 1;
112+
ab8500->hwid = pdev->id - 1;
102113

103-
err = pwmchip_add(&ab8500->chip);
114+
err = devm_pwmchip_add(&pdev->dev, &ab8500->chip);
104115
if (err < 0)
105116
return dev_err_probe(&pdev->dev, err, "Failed to add pwm chip\n");
106117

107118
dev_dbg(&pdev->dev, "pwm probe successful\n");
108-
platform_set_drvdata(pdev, ab8500);
109-
110-
return 0;
111-
}
112-
113-
static int ab8500_pwm_remove(struct platform_device *pdev)
114-
{
115-
struct ab8500_pwm_chip *ab8500 = platform_get_drvdata(pdev);
116-
int err;
117-
118-
err = pwmchip_remove(&ab8500->chip);
119-
if (err < 0)
120-
return err;
121-
122-
dev_dbg(&pdev->dev, "pwm driver removed\n");
123119

124120
return 0;
125121
}
@@ -129,7 +125,6 @@ static struct platform_driver ab8500_pwm_driver = {
129125
.name = "ab8500-pwm",
130126
},
131127
.probe = ab8500_pwm_probe,
132-
.remove = ab8500_pwm_remove,
133128
};
134129
module_platform_driver(ab8500_pwm_driver);
135130

drivers/pwm/pwm-atmel-hlcdc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,8 @@ static int atmel_hlcdc_pwm_probe(struct platform_device *pdev)
281281
static int atmel_hlcdc_pwm_remove(struct platform_device *pdev)
282282
{
283283
struct atmel_hlcdc_pwm *chip = platform_get_drvdata(pdev);
284-
int ret;
285284

286-
ret = pwmchip_remove(&chip->chip);
287-
if (ret)
288-
return ret;
285+
pwmchip_remove(&chip->chip);
289286

290287
clk_disable_unprepare(chip->hlcdc->periph_clk);
291288

drivers/pwm/pwm-atmel-tcb.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,8 @@ static int atmel_tcb_pwm_probe(struct platform_device *pdev)
503503
static int atmel_tcb_pwm_remove(struct platform_device *pdev)
504504
{
505505
struct atmel_tcb_pwm_chip *tcbpwm = platform_get_drvdata(pdev);
506-
int err;
507506

508-
err = pwmchip_remove(&tcbpwm->chip);
509-
if (err < 0)
510-
return err;
507+
pwmchip_remove(&tcbpwm->chip);
511508

512509
clk_disable_unprepare(tcbpwm->slow_clk);
513510
clk_put(tcbpwm->slow_clk);

drivers/pwm/pwm-atmel.c

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,19 @@ struct atmel_pwm_chip {
8484
void __iomem *base;
8585
const struct atmel_pwm_data *data;
8686

87-
unsigned int updated_pwms;
88-
/* ISR is cleared when read, ensure only one thread does that */
89-
struct mutex isr_lock;
87+
/*
88+
* The hardware supports a mechanism to update a channel's duty cycle at
89+
* the end of the currently running period. When such an update is
90+
* pending we delay disabling the PWM until the new configuration is
91+
* active because otherwise pmw_config(duty_cycle=0); pwm_disable();
92+
* might not result in an inactive output.
93+
* This bitmask tracks for which channels an update is pending in
94+
* hardware.
95+
*/
96+
u32 update_pending;
97+
98+
/* Protects .update_pending */
99+
spinlock_t lock;
90100
};
91101

92102
static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip)
@@ -123,6 +133,64 @@ static inline void atmel_pwm_ch_writel(struct atmel_pwm_chip *chip,
123133
atmel_pwm_writel(chip, base + offset, val);
124134
}
125135

136+
static void atmel_pwm_update_pending(struct atmel_pwm_chip *chip)
137+
{
138+
/*
139+
* Each channel that has its bit in ISR set started a new period since
140+
* ISR was cleared and so there is no more update pending. Note that
141+
* reading ISR clears it, so this needs to handle all channels to not
142+
* loose information.
143+
*/
144+
u32 isr = atmel_pwm_readl(chip, PWM_ISR);
145+
146+
chip->update_pending &= ~isr;
147+
}
148+
149+
static void atmel_pwm_set_pending(struct atmel_pwm_chip *chip, unsigned int ch)
150+
{
151+
spin_lock(&chip->lock);
152+
153+
/*
154+
* Clear pending flags in hardware because otherwise there might still
155+
* be a stale flag in ISR.
156+
*/
157+
atmel_pwm_update_pending(chip);
158+
159+
chip->update_pending |= (1 << ch);
160+
161+
spin_unlock(&chip->lock);
162+
}
163+
164+
static int atmel_pwm_test_pending(struct atmel_pwm_chip *chip, unsigned int ch)
165+
{
166+
int ret = 0;
167+
168+
spin_lock(&chip->lock);
169+
170+
if (chip->update_pending & (1 << ch)) {
171+
atmel_pwm_update_pending(chip);
172+
173+
if (chip->update_pending & (1 << ch))
174+
ret = 1;
175+
}
176+
177+
spin_unlock(&chip->lock);
178+
179+
return ret;
180+
}
181+
182+
static int atmel_pwm_wait_nonpending(struct atmel_pwm_chip *chip, unsigned int ch)
183+
{
184+
unsigned long timeout = jiffies + 2 * HZ;
185+
int ret;
186+
187+
while ((ret = atmel_pwm_test_pending(chip, ch)) &&
188+
time_before(jiffies, timeout))
189+
usleep_range(10, 100);
190+
191+
return ret ? -ETIMEDOUT : 0;
192+
}
193+
126194
static int atmel_pwm_calculate_cprd_and_pres(struct pwm_chip *chip,
127195
unsigned long clkrate,
128196
const struct pwm_state *state,
@@ -185,6 +253,7 @@ static void atmel_pwm_update_cdty(struct pwm_chip *chip, struct pwm_device *pwm,
185253

186254
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm,
187255
atmel_pwm->data->regs.duty_upd, cdty);
256+
atmel_pwm_set_pending(atmel_pwm, pwm->hwpwm);
188257
}
189258

190259
static void atmel_pwm_set_cprd_cdty(struct pwm_chip *chip,
@@ -205,20 +274,8 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm,
205274
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
206275
unsigned long timeout = jiffies + 2 * HZ;
207276

208-
/*
209-
* Wait for at least a complete period to have passed before disabling a
210-
* channel to be sure that CDTY has been updated
211-
*/
212-
mutex_lock(&atmel_pwm->isr_lock);
213-
atmel_pwm->updated_pwms |= atmel_pwm_readl(atmel_pwm, PWM_ISR);
214-
215-
while (!(atmel_pwm->updated_pwms & (1 << pwm->hwpwm)) &&
216-
time_before(jiffies, timeout)) {
217-
usleep_range(10, 100);
218-
atmel_pwm->updated_pwms |= atmel_pwm_readl(atmel_pwm, PWM_ISR);
219-
}
277+
atmel_pwm_wait_nonpending(atmel_pwm, pwm->hwpwm);
220278

221-
mutex_unlock(&atmel_pwm->isr_lock);
222279
atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
223280

224281
/*
@@ -292,10 +349,6 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
292349
val |= PWM_CMR_CPOL;
293350
atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val);
294351
atmel_pwm_set_cprd_cdty(chip, pwm, cprd, cdty);
295-
mutex_lock(&atmel_pwm->isr_lock);
296-
atmel_pwm->updated_pwms |= atmel_pwm_readl(atmel_pwm, PWM_ISR);
297-
atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm);
298-
mutex_unlock(&atmel_pwm->isr_lock);
299352
atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
300353
} else if (cstate.enabled) {
301354
atmel_pwm_disable(chip, pwm, true);
@@ -326,6 +379,9 @@ static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
326379
tmp <<= pres;
327380
state->period = DIV64_U64_ROUND_UP(tmp, rate);
328381

382+
/* Wait for an updated duty_cycle queued in hardware */
383+
atmel_pwm_wait_nonpending(atmel_pwm, pwm->hwpwm);
384+
329385
cdty = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm,
330386
atmel_pwm->data->regs.duty);
331387
tmp = (u64)(cprd - cdty) * NSEC_PER_SEC;
@@ -416,9 +472,10 @@ static int atmel_pwm_probe(struct platform_device *pdev)
416472
if (!atmel_pwm)
417473
return -ENOMEM;
418474

419-
mutex_init(&atmel_pwm->isr_lock);
420475
atmel_pwm->data = of_device_get_match_data(&pdev->dev);
421-
atmel_pwm->updated_pwms = 0;
476+
477+
atmel_pwm->update_pending = 0;
478+
spin_lock_init(&atmel_pwm->lock);
422479

423480
atmel_pwm->base = devm_platform_ioremap_resource(pdev, 0);
424481
if (IS_ERR(atmel_pwm->base))
@@ -460,7 +517,6 @@ static int atmel_pwm_remove(struct platform_device *pdev)
460517
pwmchip_remove(&atmel_pwm->chip);
461518

462519
clk_unprepare(atmel_pwm->clk);
463-
mutex_destroy(&atmel_pwm->isr_lock);
464520

465521
return 0;
466522
}

drivers/pwm/pwm-bcm-kona.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ static int kona_pwmc_probe(struct platform_device *pdev)
267267
if (kp == NULL)
268268
return -ENOMEM;
269269

270-
platform_set_drvdata(pdev, kp);
271-
272270
kp->chip.dev = &pdev->dev;
273271
kp->chip.ops = &kona_pwm_ops;
274272
kp->chip.npwm = 6;
@@ -298,20 +296,13 @@ static int kona_pwmc_probe(struct platform_device *pdev)
298296

299297
clk_disable_unprepare(kp->clk);
300298

301-
ret = pwmchip_add(&kp->chip);
299+
ret = devm_pwmchip_add(&pdev->dev, &kp->chip);
302300
if (ret < 0)
303301
dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
304302

305303
return ret;
306304
}
307305

308-
static int kona_pwmc_remove(struct platform_device *pdev)
309-
{
310-
struct kona_pwmc *kp = platform_get_drvdata(pdev);
311-
312-
return pwmchip_remove(&kp->chip);
313-
}
314-
315306
static const struct of_device_id bcm_kona_pwmc_dt[] = {
316307
{ .compatible = "brcm,kona-pwm" },
317308
{ },
@@ -324,7 +315,6 @@ static struct platform_driver kona_pwmc_driver = {
324315
.of_match_table = bcm_kona_pwmc_dt,
325316
},
326317
.probe = kona_pwmc_probe,
327-
.remove = kona_pwmc_remove,
328318
};
329319
module_platform_driver(kona_pwmc_driver);
330320

drivers/pwm/pwm-brcmstb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,11 @@ static int brcmstb_pwm_probe(struct platform_device *pdev)
282282
static int brcmstb_pwm_remove(struct platform_device *pdev)
283283
{
284284
struct brcmstb_pwm *p = platform_get_drvdata(pdev);
285-
int ret;
286285

287-
ret = pwmchip_remove(&p->chip);
286+
pwmchip_remove(&p->chip);
288287
clk_disable_unprepare(p->clk);
289288

290-
return ret;
289+
return 0;
291290
}
292291

293292
#ifdef CONFIG_PM_SLEEP

drivers/pwm/pwm-cros-ec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ static int cros_ec_pwm_remove(struct platform_device *dev)
280280
struct cros_ec_pwm_device *ec_pwm = platform_get_drvdata(dev);
281281
struct pwm_chip *chip = &ec_pwm->chip;
282282

283-
return pwmchip_remove(chip);
283+
pwmchip_remove(chip);
284+
285+
return 0;
284286
}
285287

286288
#ifdef CONFIG_OF

0 commit comments

Comments
 (0)