Skip to content

Commit 030c28a

Browse files
committed
Merge tag 'pwm/for-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "This set is mostly small fixes and cleanups, so more of a janitorial update for this cycle" * tag 'pwm/for-5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: pwm: vt8500: Rename pwm_busy_wait() to make it obviously driver-specific dt-bindings: pwm: tpu: Add R-Car M3-W+ device tree bindings dt-bindings: pwm: tpu: Add R-Car V3U device tree bindings pwm: pwm-samsung: Trigger manual update when disabling PWM pwm: visconti: Simplify using devm_pwmchip_add() pwm: samsung: Describe driver in Kconfig pwm: Make it explicit that pwm_apply_state() might sleep pwm: Add might_sleep() annotations for !CONFIG_PWM API functions pwm: atmel: Drop unused header
2 parents 0d5d746 + e9d866d commit 030c28a

File tree

8 files changed

+58
-31
lines changed

8 files changed

+58
-31
lines changed

Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ properties:
3535
- renesas,tpu-r8a7794 # R-Car E2
3636
- renesas,tpu-r8a7795 # R-Car H3
3737
- renesas,tpu-r8a7796 # R-Car M3-W
38+
- renesas,tpu-r8a77961 # R-Car M3-W+
3839
- renesas,tpu-r8a77965 # R-Car M3-N
3940
- renesas,tpu-r8a77970 # R-Car V3M
4041
- renesas,tpu-r8a77980 # R-Car V3H
42+
- renesas,tpu-r8a779a0 # R-Car V3U
4143
- const: renesas,tpu
4244

4345
reg:

drivers/pwm/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ config PWM_SAMSUNG
476476
depends on PLAT_SAMSUNG || ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST
477477
depends on HAS_IOMEM
478478
help
479-
Generic PWM framework driver for Samsung.
479+
Generic PWM framework driver for Samsung S3C24xx, S3C64xx, S5Pv210
480+
and Exynos SoCs.
481+
Choose Y here only if you build for such Samsung SoC.
480482

481483
To compile this driver as a module, choose M here: the module
482484
will be called pwm-samsung.

drivers/pwm/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,15 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
532532
struct pwm_chip *chip;
533533
int err;
534534

535+
/*
536+
* Some lowlevel driver's implementations of .apply() make use of
537+
* mutexes, also with some drivers only returning when the new
538+
* configuration is active calling pwm_apply_state() from atomic context
539+
* is a bad idea. So make it explicit that calling this function might
540+
* sleep.
541+
*/
542+
might_sleep();
543+
535544
if (!pwm || !state || !state->period ||
536545
state->duty_cycle > state->period)
537546
return -EINVAL;

drivers/pwm/pwm-atmel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <linux/err.h>
2525
#include <linux/io.h>
2626
#include <linux/module.h>
27-
#include <linux/mutex.h>
2827
#include <linux/of.h>
2928
#include <linux/of_device.h>
3029
#include <linux/platform_device.h>

drivers/pwm/pwm-samsung.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ static inline unsigned int to_tcon_channel(unsigned int channel)
117117
return (channel == 0) ? 0 : (channel + 1);
118118
}
119119

120+
static void __pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
121+
struct pwm_device *pwm)
122+
{
123+
unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm);
124+
u32 tcon;
125+
126+
tcon = readl(chip->base + REG_TCON);
127+
tcon |= TCON_MANUALUPDATE(tcon_chan);
128+
writel(tcon, chip->base + REG_TCON);
129+
130+
tcon &= ~TCON_MANUALUPDATE(tcon_chan);
131+
writel(tcon, chip->base + REG_TCON);
132+
}
133+
120134
static void pwm_samsung_set_divisor(struct samsung_pwm_chip *pwm,
121135
unsigned int channel, u8 divisor)
122136
{
@@ -276,6 +290,13 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm)
276290
tcon &= ~TCON_AUTORELOAD(tcon_chan);
277291
writel(tcon, our_chip->base + REG_TCON);
278292

293+
/*
294+
* In case the PWM is at 100% duty cycle, force a manual
295+
* update to prevent the signal from staying high.
296+
*/
297+
if (readl(our_chip->base + REG_TCMPB(pwm->hwpwm)) == (u32)-1U)
298+
__pwm_samsung_manual_update(our_chip, pwm);
299+
279300
our_chip->disabled_mask |= BIT(pwm->hwpwm);
280301

281302
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
@@ -284,18 +305,11 @@ static void pwm_samsung_disable(struct pwm_chip *chip, struct pwm_device *pwm)
284305
static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip,
285306
struct pwm_device *pwm)
286307
{
287-
unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm);
288-
u32 tcon;
289308
unsigned long flags;
290309

291310
spin_lock_irqsave(&samsung_pwm_lock, flags);
292311

293-
tcon = readl(chip->base + REG_TCON);
294-
tcon |= TCON_MANUALUPDATE(tcon_chan);
295-
writel(tcon, chip->base + REG_TCON);
296-
297-
tcon &= ~TCON_MANUALUPDATE(tcon_chan);
298-
writel(tcon, chip->base + REG_TCON);
312+
__pwm_samsung_manual_update(chip, pwm);
299313

300314
spin_unlock_irqrestore(&samsung_pwm_lock, flags);
301315
}

drivers/pwm/pwm-visconti.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,17 @@ static int visconti_pwm_probe(struct platform_device *pdev)
144144
if (IS_ERR(priv->base))
145145
return PTR_ERR(priv->base);
146146

147-
platform_set_drvdata(pdev, priv);
148-
149147
priv->chip.dev = dev;
150148
priv->chip.ops = &visconti_pwm_ops;
151149
priv->chip.npwm = 4;
152150

153-
ret = pwmchip_add(&priv->chip);
151+
ret = devm_pwmchip_add(&pdev->dev, &priv->chip);
154152
if (ret < 0)
155153
return dev_err_probe(&pdev->dev, ret, "Cannot register visconti PWM\n");
156154

157155
return 0;
158156
}
159157

160-
static int visconti_pwm_remove(struct platform_device *pdev)
161-
{
162-
struct visconti_pwm_chip *priv = platform_get_drvdata(pdev);
163-
164-
pwmchip_remove(&priv->chip);
165-
166-
return 0;
167-
}
168-
169158
static const struct of_device_id visconti_pwm_of_match[] = {
170159
{ .compatible = "toshiba,visconti-pwm", },
171160
{ }
@@ -178,7 +167,6 @@ static struct platform_driver visconti_pwm_driver = {
178167
.of_match_table = visconti_pwm_of_match,
179168
},
180169
.probe = visconti_pwm_probe,
181-
.remove = visconti_pwm_remove,
182170
};
183171
module_platform_driver(visconti_pwm_driver);
184172

drivers/pwm/pwm-vt8500.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct vt8500_chip {
5656
#define to_vt8500_chip(chip) container_of(chip, struct vt8500_chip, chip)
5757

5858
#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
59-
static inline void pwm_busy_wait(struct vt8500_chip *vt8500, int nr, u8 bitmask)
59+
static inline void vt8500_pwm_busy_wait(struct vt8500_chip *vt8500, int nr, u8 bitmask)
6060
{
6161
int loops = msecs_to_loops(10);
6262
u32 mask = bitmask << (nr << 8);
@@ -106,18 +106,18 @@ static int vt8500_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
106106
dc = c;
107107

108108
writel(prescale, vt8500->base + REG_SCALAR(pwm->hwpwm));
109-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_SCALAR_UPDATE);
109+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_SCALAR_UPDATE);
110110

111111
writel(pv, vt8500->base + REG_PERIOD(pwm->hwpwm));
112-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_PERIOD_UPDATE);
112+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_PERIOD_UPDATE);
113113

114114
writel(dc, vt8500->base + REG_DUTY(pwm->hwpwm));
115-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_DUTY_UPDATE);
115+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_DUTY_UPDATE);
116116

117117
val = readl(vt8500->base + REG_CTRL(pwm->hwpwm));
118118
val |= CTRL_AUTOLOAD;
119119
writel(val, vt8500->base + REG_CTRL(pwm->hwpwm));
120-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
120+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
121121

122122
clk_disable(vt8500->clk);
123123
return 0;
@@ -138,7 +138,7 @@ static int vt8500_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
138138
val = readl(vt8500->base + REG_CTRL(pwm->hwpwm));
139139
val |= CTRL_ENABLE;
140140
writel(val, vt8500->base + REG_CTRL(pwm->hwpwm));
141-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
141+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
142142

143143
return 0;
144144
}
@@ -151,7 +151,7 @@ static void vt8500_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
151151
val = readl(vt8500->base + REG_CTRL(pwm->hwpwm));
152152
val &= ~CTRL_ENABLE;
153153
writel(val, vt8500->base + REG_CTRL(pwm->hwpwm));
154-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
154+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
155155

156156
clk_disable(vt8500->clk);
157157
}
@@ -171,7 +171,7 @@ static int vt8500_pwm_set_polarity(struct pwm_chip *chip,
171171
val &= ~CTRL_INVERT;
172172

173173
writel(val, vt8500->base + REG_CTRL(pwm->hwpwm));
174-
pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
174+
vt8500_pwm_busy_wait(vt8500, pwm->hwpwm, STATUS_CTRL_UPDATE);
175175

176176
return 0;
177177
}

include/linux/pwm.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
429429
#else
430430
static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
431431
{
432+
might_sleep();
432433
return ERR_PTR(-ENODEV);
433434
}
434435

435436
static inline void pwm_free(struct pwm_device *pwm)
436437
{
438+
might_sleep();
437439
}
438440

439441
static inline int pwm_apply_state(struct pwm_device *pwm,
440442
const struct pwm_state *state)
441443
{
444+
might_sleep();
442445
return -ENOTSUPP;
443446
}
444447

@@ -450,6 +453,7 @@ static inline int pwm_adjust_config(struct pwm_device *pwm)
450453
static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
451454
int period_ns)
452455
{
456+
might_sleep();
453457
return -EINVAL;
454458
}
455459

@@ -462,11 +466,13 @@ static inline int pwm_capture(struct pwm_device *pwm,
462466

463467
static inline int pwm_enable(struct pwm_device *pwm)
464468
{
469+
might_sleep();
465470
return -EINVAL;
466471
}
467472

468473
static inline void pwm_disable(struct pwm_device *pwm)
469474
{
475+
might_sleep();
470476
}
471477

472478
static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
@@ -493,43 +499,50 @@ static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
493499
unsigned int index,
494500
const char *label)
495501
{
502+
might_sleep();
496503
return ERR_PTR(-ENODEV);
497504
}
498505

499506
static inline struct pwm_device *pwm_get(struct device *dev,
500507
const char *consumer)
501508
{
509+
might_sleep();
502510
return ERR_PTR(-ENODEV);
503511
}
504512

505513
static inline struct pwm_device *of_pwm_get(struct device *dev,
506514
struct device_node *np,
507515
const char *con_id)
508516
{
517+
might_sleep();
509518
return ERR_PTR(-ENODEV);
510519
}
511520

512521
static inline void pwm_put(struct pwm_device *pwm)
513522
{
523+
might_sleep();
514524
}
515525

516526
static inline struct pwm_device *devm_pwm_get(struct device *dev,
517527
const char *consumer)
518528
{
529+
might_sleep();
519530
return ERR_PTR(-ENODEV);
520531
}
521532

522533
static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
523534
struct device_node *np,
524535
const char *con_id)
525536
{
537+
might_sleep();
526538
return ERR_PTR(-ENODEV);
527539
}
528540

529541
static inline struct pwm_device *
530542
devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode,
531543
const char *con_id)
532544
{
545+
might_sleep();
533546
return ERR_PTR(-ENODEV);
534547
}
535548
#endif

0 commit comments

Comments
 (0)