Skip to content

Commit e37e3bc

Browse files
committed
Merge tag 'pwm/for-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "Besides one new driver being added for the PWM controller found in various Spreadtrum SoCs, this series of changes brings a slew of, mostly minor, fixes and cleanups for existing drivers, as well as some enhancements to the core code. Lastly, Uwe is added to the PWM subsystem entry of the MAINTAINERS file, making official his role as a reviewer" * tag 'pwm/for-5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (34 commits) MAINTAINERS: Add myself as reviewer for the PWM subsystem MAINTAINERS: Add patchwork link for PWM entry MAINTAINERS: Add a selection of PWM related keywords to the PWM entry pwm: mediatek: Add MT7629 compatible string dt-bindings: pwm: Update bindings for MT7629 SoC pwm: mediatek: Update license and switch to SPDX tag pwm: mediatek: Use pwm_mediatek as common prefix pwm: mediatek: Allocate the clks array dynamically pwm: mediatek: Remove the has_clks field pwm: mediatek: Drop the check for of_device_get_match_data() pwm: atmel: Consolidate driver data initialization pwm: atmel: Remove unneeded check for match data pwm: atmel: Remove platform_device_id and use only dt bindings pwm: stm32-lp: Add check in case requested period cannot be achieved pwm: Ensure pwm_apply_state() doesn't modify the state argument pwm: fsl-ftm: Don't update the state for the caller of pwm_apply_state() pwm: sun4i: Don't update the state for the caller of pwm_apply_state() pwm: rockchip: Don't update the state for the caller of pwm_apply_state() pwm: Let pwm_get_state() return the last implemented state pwm: Introduce local struct pwm_chip in pwm_apply_state() ...
2 parents 738f531 + da635e7 commit e37e3bc

31 files changed

+576
-236
lines changed

Documentation/devicetree/bindings/pwm/pwm-mediatek.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Required properties:
66
- "mediatek,mt7622-pwm": found on mt7622 SoC.
77
- "mediatek,mt7623-pwm": found on mt7623 SoC.
88
- "mediatek,mt7628-pwm": found on mt7628 SoC.
9+
- "mediatek,mt7629-pwm", "mediatek,mt7622-pwm": found on mt7629 SoC.
10+
- "mediatek,mt8516-pwm": found on mt8516 SoC.
911
- reg: physical base address and length of the controller's registers.
1012
- #pwm-cells: must be 2. See pwm.txt in this directory for a description of
1113
the cell format.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Spreadtrum PWM controller
2+
3+
Spreadtrum SoCs PWM controller provides 4 PWM channels.
4+
5+
Required properties:
6+
- compatible : Should be "sprd,ums512-pwm".
7+
- reg: Physical base address and length of the controller's registers.
8+
- clocks: The phandle and specifier referencing the controller's clocks.
9+
- clock-names: Should contain following entries:
10+
"pwmn": used to derive the functional clock for PWM channel n (n range: 0 ~ 3).
11+
"enablen": for PWM channel n enable clock (n range: 0 ~ 3).
12+
- #pwm-cells: Should be 2. See pwm.txt in this directory for a description of
13+
the cells format.
14+
15+
Optional properties:
16+
- assigned-clocks: Reference to the PWM clock entries.
17+
- assigned-clock-parents: The phandle of the parent clock of PWM clock.
18+
19+
Example:
20+
pwms: pwm@32260000 {
21+
compatible = "sprd,ums512-pwm";
22+
reg = <0 0x32260000 0 0x10000>;
23+
clock-names = "pwm0", "enable0",
24+
"pwm1", "enable1",
25+
"pwm2", "enable2",
26+
"pwm3", "enable3";
27+
clocks = <&aon_clk CLK_PWM0>, <&aonapb_gate CLK_PWM0_EB>,
28+
<&aon_clk CLK_PWM1>, <&aonapb_gate CLK_PWM1_EB>,
29+
<&aon_clk CLK_PWM2>, <&aonapb_gate CLK_PWM2_EB>,
30+
<&aon_clk CLK_PWM3>, <&aonapb_gate CLK_PWM3_EB>;
31+
assigned-clocks = <&aon_clk CLK_PWM0>,
32+
<&aon_clk CLK_PWM1>,
33+
<&aon_clk CLK_PWM2>,
34+
<&aon_clk CLK_PWM3>;
35+
assigned-clock-parents = <&ext_26m>,
36+
<&ext_26m>,
37+
<&ext_26m>,
38+
<&ext_26m>;
39+
#pwm-cells = <2>;
40+
};

MAINTAINERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13246,9 +13246,11 @@ F: drivers/media/rc/pwm-ir-tx.c
1324613246

1324713247
PWM SUBSYSTEM
1324813248
M: Thierry Reding <[email protected]>
13249+
R: Uwe Kleine-König <[email protected]>
1324913250
1325013251
S: Maintained
1325113252
T: git git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm.git
13253+
Q: https://patchwork.ozlabs.org/project/linux-pwm/list/
1325213254
F: Documentation/driver-api/pwm.rst
1325313255
F: Documentation/devicetree/bindings/pwm/
1325413256
F: include/linux/pwm.h
@@ -13257,6 +13259,7 @@ F: drivers/video/backlight/pwm_bl.c
1325713259
F: include/linux/pwm_backlight.h
1325813260
F: drivers/gpio/gpio-mvebu.c
1325913261
F: Documentation/devicetree/bindings/gpio/gpio-mvebu.txt
13262+
K: pwm_(config|apply_state|ops)
1326013263

1326113264
PXA GPIO DRIVER
1326213265
M: Robert Jarzmik <[email protected]>

drivers/gpio/gpio-mvebu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip,
694694
}
695695

696696
static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
697-
struct pwm_state *state)
697+
const struct pwm_state *state)
698698
{
699699
struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
700700
struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;

drivers/pwm/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ config PWM_AB8500
4444

4545
config PWM_ATMEL
4646
tristate "Atmel PWM support"
47-
depends on ARCH_AT91
47+
depends on ARCH_AT91 && OF
4848
help
4949
Generic PWM framework driver for Atmel SoC.
5050

@@ -423,6 +423,17 @@ config PWM_SPEAR
423423
To compile this driver as a module, choose M here: the module
424424
will be called pwm-spear.
425425

426+
config PWM_SPRD
427+
tristate "Spreadtrum PWM support"
428+
depends on ARCH_SPRD || COMPILE_TEST
429+
depends on HAS_IOMEM
430+
help
431+
Generic PWM framework driver for the PWM controller on
432+
Spreadtrum SoCs.
433+
434+
To compile this driver as a module, choose M here: the module
435+
will be called pwm-sprd.
436+
426437
config PWM_STI
427438
tristate "STiH4xx PWM support"
428439
depends on ARCH_STI

drivers/pwm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o
4141
obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
4242
obj-$(CONFIG_PWM_SIFIVE) += pwm-sifive.o
4343
obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o
44+
obj-$(CONFIG_PWM_SPRD) += pwm-sprd.o
4445
obj-$(CONFIG_PWM_STI) += pwm-sti.o
4546
obj-$(CONFIG_PWM_STM32) += pwm-stm32.o
4647
obj-$(CONFIG_PWM_STM32_LP) += pwm-stm32-lp.o

drivers/pwm/core.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,36 +448,44 @@ EXPORT_SYMBOL_GPL(pwm_free);
448448
/**
449449
* pwm_apply_state() - atomically apply a new state to a PWM device
450450
* @pwm: PWM device
451-
* @state: new state to apply. This can be adjusted by the PWM driver
452-
* if the requested config is not achievable, for example,
453-
* ->duty_cycle and ->period might be approximated.
451+
* @state: new state to apply
454452
*/
455-
int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
453+
int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
456454
{
455+
struct pwm_chip *chip;
457456
int err;
458457

459458
if (!pwm || !state || !state->period ||
460459
state->duty_cycle > state->period)
461460
return -EINVAL;
462461

462+
chip = pwm->chip;
463+
463464
if (state->period == pwm->state.period &&
464465
state->duty_cycle == pwm->state.duty_cycle &&
465466
state->polarity == pwm->state.polarity &&
466467
state->enabled == pwm->state.enabled)
467468
return 0;
468469

469-
if (pwm->chip->ops->apply) {
470-
err = pwm->chip->ops->apply(pwm->chip, pwm, state);
470+
if (chip->ops->apply) {
471+
err = chip->ops->apply(chip, pwm, state);
471472
if (err)
472473
return err;
473474

474-
pwm->state = *state;
475+
/*
476+
* .apply might have to round some values in *state, if possible
477+
* read the actually implemented value back.
478+
*/
479+
if (chip->ops->get_state)
480+
chip->ops->get_state(chip, pwm, &pwm->state);
481+
else
482+
pwm->state = *state;
475483
} else {
476484
/*
477485
* FIXME: restore the initial state in case of error.
478486
*/
479487
if (state->polarity != pwm->state.polarity) {
480-
if (!pwm->chip->ops->set_polarity)
488+
if (!chip->ops->set_polarity)
481489
return -ENOTSUPP;
482490

483491
/*
@@ -486,12 +494,12 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
486494
* ->apply().
487495
*/
488496
if (pwm->state.enabled) {
489-
pwm->chip->ops->disable(pwm->chip, pwm);
497+
chip->ops->disable(chip, pwm);
490498
pwm->state.enabled = false;
491499
}
492500

493-
err = pwm->chip->ops->set_polarity(pwm->chip, pwm,
494-
state->polarity);
501+
err = chip->ops->set_polarity(chip, pwm,
502+
state->polarity);
495503
if (err)
496504
return err;
497505

@@ -500,9 +508,9 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
500508

501509
if (state->period != pwm->state.period ||
502510
state->duty_cycle != pwm->state.duty_cycle) {
503-
err = pwm->chip->ops->config(pwm->chip, pwm,
504-
state->duty_cycle,
505-
state->period);
511+
err = chip->ops->config(pwm->chip, pwm,
512+
state->duty_cycle,
513+
state->period);
506514
if (err)
507515
return err;
508516

@@ -512,11 +520,11 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
512520

513521
if (state->enabled != pwm->state.enabled) {
514522
if (state->enabled) {
515-
err = pwm->chip->ops->enable(pwm->chip, pwm);
523+
err = chip->ops->enable(chip, pwm);
516524
if (err)
517525
return err;
518526
} else {
519-
pwm->chip->ops->disable(pwm->chip, pwm);
527+
chip->ops->disable(chip, pwm);
520528
}
521529

522530
pwm->state.enabled = state->enabled;

drivers/pwm/pwm-atmel-hlcdc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static inline struct atmel_hlcdc_pwm *to_atmel_hlcdc_pwm(struct pwm_chip *chip)
3939
}
4040

4141
static int atmel_hlcdc_pwm_apply(struct pwm_chip *c, struct pwm_device *pwm,
42-
struct pwm_state *state)
42+
const struct pwm_state *state)
4343
{
4444
struct atmel_hlcdc_pwm *chip = to_atmel_hlcdc_pwm(c);
4545
struct atmel_hlcdc *hlcdc = chip->hlcdc;

drivers/pwm/pwm-atmel.c

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm,
209209
}
210210

211211
static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
212-
struct pwm_state *state)
212+
const struct pwm_state *state)
213213
{
214214
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
215215
struct pwm_state cstate;
@@ -318,19 +318,6 @@ static const struct atmel_pwm_data mchp_sam9x60_pwm_data = {
318318
},
319319
};
320320

321-
static const struct platform_device_id atmel_pwm_devtypes[] = {
322-
{
323-
.name = "at91sam9rl-pwm",
324-
.driver_data = (kernel_ulong_t)&atmel_sam9rl_pwm_data,
325-
}, {
326-
.name = "sama5d3-pwm",
327-
.driver_data = (kernel_ulong_t)&atmel_sama5_pwm_data,
328-
}, {
329-
/* sentinel */
330-
},
331-
};
332-
MODULE_DEVICE_TABLE(platform, atmel_pwm_devtypes);
333-
334321
static const struct of_device_id atmel_pwm_dt_ids[] = {
335322
{
336323
.compatible = "atmel,at91sam9rl-pwm",
@@ -350,34 +337,20 @@ static const struct of_device_id atmel_pwm_dt_ids[] = {
350337
};
351338
MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids);
352339

353-
static inline const struct atmel_pwm_data *
354-
atmel_pwm_get_driver_data(struct platform_device *pdev)
355-
{
356-
const struct platform_device_id *id;
357-
358-
if (pdev->dev.of_node)
359-
return of_device_get_match_data(&pdev->dev);
360-
361-
id = platform_get_device_id(pdev);
362-
363-
return (struct atmel_pwm_data *)id->driver_data;
364-
}
365-
366340
static int atmel_pwm_probe(struct platform_device *pdev)
367341
{
368-
const struct atmel_pwm_data *data;
369342
struct atmel_pwm_chip *atmel_pwm;
370343
struct resource *res;
371344
int ret;
372345

373-
data = atmel_pwm_get_driver_data(pdev);
374-
if (!data)
375-
return -ENODEV;
376-
377346
atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL);
378347
if (!atmel_pwm)
379348
return -ENOMEM;
380349

350+
mutex_init(&atmel_pwm->isr_lock);
351+
atmel_pwm->data = of_device_get_match_data(&pdev->dev);
352+
atmel_pwm->updated_pwms = 0;
353+
381354
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
382355
atmel_pwm->base = devm_ioremap_resource(&pdev->dev, res);
383356
if (IS_ERR(atmel_pwm->base))
@@ -395,17 +368,10 @@ static int atmel_pwm_probe(struct platform_device *pdev)
395368

396369
atmel_pwm->chip.dev = &pdev->dev;
397370
atmel_pwm->chip.ops = &atmel_pwm_ops;
398-
399-
if (pdev->dev.of_node) {
400-
atmel_pwm->chip.of_xlate = of_pwm_xlate_with_flags;
401-
atmel_pwm->chip.of_pwm_n_cells = 3;
402-
}
403-
371+
atmel_pwm->chip.of_xlate = of_pwm_xlate_with_flags;
372+
atmel_pwm->chip.of_pwm_n_cells = 3;
404373
atmel_pwm->chip.base = -1;
405374
atmel_pwm->chip.npwm = 4;
406-
atmel_pwm->data = data;
407-
atmel_pwm->updated_pwms = 0;
408-
mutex_init(&atmel_pwm->isr_lock);
409375

410376
ret = pwmchip_add(&atmel_pwm->chip);
411377
if (ret < 0) {
@@ -437,7 +403,6 @@ static struct platform_driver atmel_pwm_driver = {
437403
.name = "atmel-pwm",
438404
.of_match_table = of_match_ptr(atmel_pwm_dt_ids),
439405
},
440-
.id_table = atmel_pwm_devtypes,
441406
.probe = atmel_pwm_probe,
442407
.remove = atmel_pwm_remove,
443408
};

drivers/pwm/pwm-bcm-iproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
115115
}
116116

117117
static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
118-
struct pwm_state *state)
118+
const struct pwm_state *state)
119119
{
120120
unsigned long prescale = IPROC_PWM_PRESCALE_MIN;
121121
struct iproc_pwmc *ip = to_iproc_pwmc(chip);

0 commit comments

Comments
 (0)