Skip to content

Commit 7a693ea

Browse files
committed
Merge tag 'pwm/for-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "Various changes across the board, mostly improvements and cleanups" * tag 'pwm/for-6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (42 commits) pwm: pca9685: Convert to i2c's .probe_new() pwm: sun4i: Propagate errors in .get_state() to the caller pwm: Handle .get_state() failures pwm: sprd: Propagate errors in .get_state() to the caller pwm: rockchip: Propagate errors in .get_state() to the caller pwm: mtk-disp: Propagate errors in .get_state() to the caller pwm: imx27: Propagate errors in .get_state() to the caller pwm: cros-ec: Propagate errors in .get_state() to the caller pwm: crc: Propagate errors in .get_state() to the caller leds: qcom-lpg: Propagate errors in .get_state() to the caller drm/bridge: ti-sn65dsi86: Propagate errors in .get_state() to the caller pwm/tracing: Also record trace events for failed API calls pwm: Make .get_state() callback return an error code pwm: pxa: Enable for MMP platform pwm: pxa: Add reference manual link and limitations pwm: pxa: Use abrupt shutdown mode pwm: pxa: Remove clk enable/disable from pxa_pwm_config pwm: pxa: Set duty cycle to 0 when disabling PWM pwm: pxa: Remove pxa_pwm_enable/disable pwm: mediatek: Add support for MT7986 ...
2 parents 9cf5b50 + 8fa22f4 commit 7a693ea

Some content is hidden

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

42 files changed

+299
-229
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ properties:
3535
- renesas,pwm-r8a77980 # R-Car V3H
3636
- renesas,pwm-r8a77990 # R-Car E3
3737
- renesas,pwm-r8a77995 # R-Car D3
38+
- renesas,pwm-r8a779g0 # R-Car V4H
3839
- const: renesas,pwm-rcar
3940

4041
reg:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ properties:
4040
- renesas,tpu-r8a77970 # R-Car V3M
4141
- renesas,tpu-r8a77980 # R-Car V3H
4242
- renesas,tpu-r8a779a0 # R-Car V3U
43+
- renesas,tpu-r8a779g0 # R-Car V4H
4344
- const: renesas,tpu
4445

4546
reg:

drivers/gpio/gpio-mvebu.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,10 @@ static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
657657
spin_unlock_irqrestore(&mvpwm->lock, flags);
658658
}
659659

660-
static void mvebu_pwm_get_state(struct pwm_chip *chip,
661-
struct pwm_device *pwm,
662-
struct pwm_state *state) {
660+
static int mvebu_pwm_get_state(struct pwm_chip *chip,
661+
struct pwm_device *pwm,
662+
struct pwm_state *state)
663+
{
663664

664665
struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
665666
struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
@@ -693,6 +694,8 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip,
693694
state->enabled = false;
694695

695696
spin_unlock_irqrestore(&mvpwm->lock, flags);
697+
698+
return 0;
696699
}
697700

698701
static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,

drivers/gpu/drm/bridge/ti-sn65dsi86.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,8 @@ static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
15001500
return ret;
15011501
}
15021502

1503-
static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
1504-
struct pwm_state *state)
1503+
static int ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
1504+
struct pwm_state *state)
15051505
{
15061506
struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip);
15071507
unsigned int pwm_en_inv;
@@ -1512,19 +1512,19 @@ static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
15121512

15131513
ret = regmap_read(pdata->regmap, SN_PWM_EN_INV_REG, &pwm_en_inv);
15141514
if (ret)
1515-
return;
1515+
return ret;
15161516

15171517
ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_SCALE_REG, &scale);
15181518
if (ret)
1519-
return;
1519+
return ret;
15201520

15211521
ret = ti_sn65dsi86_read_u16(pdata, SN_BACKLIGHT_REG, &backlight);
15221522
if (ret)
1523-
return;
1523+
return ret;
15241524

15251525
ret = regmap_read(pdata->regmap, SN_PWM_PRE_DIV_REG, &pre_div);
15261526
if (ret)
1527-
return;
1527+
return ret;
15281528

15291529
state->enabled = FIELD_GET(SN_PWM_EN_MASK, pwm_en_inv);
15301530
if (FIELD_GET(SN_PWM_INV_MASK, pwm_en_inv))
@@ -1539,6 +1539,8 @@ static void ti_sn_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
15391539

15401540
if (state->duty_cycle > state->period)
15411541
state->duty_cycle = state->period;
1542+
1543+
return 0;
15421544
}
15431545

15441546
static const struct pwm_ops ti_sn_pwm_ops = {

drivers/leds/rgb/leds-qcom-lpg.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,8 @@ static int lpg_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
972972
return ret;
973973
}
974974

975-
static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
976-
struct pwm_state *state)
975+
static int lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
976+
struct pwm_state *state)
977977
{
978978
struct lpg *lpg = container_of(chip, struct lpg, pwm);
979979
struct lpg_channel *chan = &lpg->channels[pwm->hwpwm];
@@ -986,20 +986,20 @@ static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
986986

987987
ret = regmap_read(lpg->map, chan->base + LPG_SIZE_CLK_REG, &val);
988988
if (ret)
989-
return;
989+
return ret;
990990

991991
refclk = lpg_clk_rates[val & PWM_CLK_SELECT_MASK];
992992
if (refclk) {
993993
ret = regmap_read(lpg->map, chan->base + LPG_PREDIV_CLK_REG, &val);
994994
if (ret)
995-
return;
995+
return ret;
996996

997997
pre_div = lpg_pre_divs[FIELD_GET(PWM_FREQ_PRE_DIV_MASK, val)];
998998
m = FIELD_GET(PWM_FREQ_EXP_MASK, val);
999999

10001000
ret = regmap_bulk_read(lpg->map, chan->base + PWM_VALUE_REG, &pwm_value, sizeof(pwm_value));
10011001
if (ret)
1002-
return;
1002+
return ret;
10031003

10041004
state->period = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * LPG_RESOLUTION * pre_div * (1 << m), refclk);
10051005
state->duty_cycle = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC * pwm_value * pre_div * (1 << m), refclk);
@@ -1010,13 +1010,15 @@ static void lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
10101010

10111011
ret = regmap_read(lpg->map, chan->base + PWM_ENABLE_CONTROL_REG, &val);
10121012
if (ret)
1013-
return;
1013+
return ret;
10141014

10151015
state->enabled = FIELD_GET(LPG_ENABLE_CONTROL_OUTPUT, val);
10161016
state->polarity = PWM_POLARITY_NORMAL;
10171017

10181018
if (state->duty_cycle > state->period)
10191019
state->duty_cycle = state->period;
1020+
1021+
return 0;
10201022
}
10211023

10221024
static const struct pwm_ops lpg_pwm_ops = {

drivers/pwm/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ config PWM_IQS620A
282282

283283
config PWM_JZ4740
284284
tristate "Ingenic JZ47xx PWM support"
285-
depends on MIPS || COMPILE_TEST
286-
depends on COMMON_CLK
285+
depends on MACH_INGENIC || COMPILE_TEST
286+
depends on COMMON_CLK && OF
287287
select MFD_SYSCON
288288
help
289289
Generic PWM framework driver for Ingenic JZ47xx based
@@ -434,7 +434,7 @@ config PWM_PCA9685
434434

435435
config PWM_PXA
436436
tristate "PXA PWM support"
437-
depends on ARCH_PXA || COMPILE_TEST
437+
depends on ARCH_PXA || ARCH_MMP || COMPILE_TEST
438438
depends on HAS_IOMEM
439439
help
440440
Generic PWM framework driver for PXA.

drivers/pwm/core.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
static DEFINE_MUTEX(pwm_lookup_lock);
2929
static LIST_HEAD(pwm_lookup_list);
30+
31+
/* protects access to pwm_chips, allocated_pwms, and pwm_tree */
3032
static DEFINE_MUTEX(pwm_lock);
33+
3134
static LIST_HEAD(pwm_chips);
3235
static DECLARE_BITMAP(allocated_pwms, MAX_PWMS);
3336
static RADIX_TREE(pwm_tree, GFP_KERNEL);
@@ -37,6 +40,7 @@ static struct pwm_device *pwm_to_device(unsigned int pwm)
3740
return radix_tree_lookup(&pwm_tree, pwm);
3841
}
3942

43+
/* Called with pwm_lock held */
4044
static int alloc_pwms(unsigned int count)
4145
{
4246
unsigned int start;
@@ -47,9 +51,12 @@ static int alloc_pwms(unsigned int count)
4751
if (start + count > MAX_PWMS)
4852
return -ENOSPC;
4953

54+
bitmap_set(allocated_pwms, start, count);
55+
5056
return start;
5157
}
5258

59+
/* Called with pwm_lock held */
5360
static void free_pwms(struct pwm_chip *chip)
5461
{
5562
unsigned int i;
@@ -108,8 +115,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
108115
}
109116

110117
if (pwm->chip->ops->get_state) {
111-
pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state);
112-
trace_pwm_get(pwm, &pwm->state);
118+
struct pwm_state state;
119+
120+
err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
121+
trace_pwm_get(pwm, &state, err);
122+
123+
if (!err)
124+
pwm->state = state;
113125

114126
if (IS_ENABLED(CONFIG_PWM_DEBUG))
115127
pwm->last = pwm->state;
@@ -267,20 +279,21 @@ int pwmchip_add(struct pwm_chip *chip)
267279
if (!pwm_ops_check(chip))
268280
return -EINVAL;
269281

282+
chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
283+
if (!chip->pwms)
284+
return -ENOMEM;
285+
270286
mutex_lock(&pwm_lock);
271287

272288
ret = alloc_pwms(chip->npwm);
273-
if (ret < 0)
274-
goto out;
289+
if (ret < 0) {
290+
mutex_unlock(&pwm_lock);
291+
kfree(chip->pwms);
292+
return ret;
293+
}
275294

276295
chip->base = ret;
277296

278-
chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
279-
if (!chip->pwms) {
280-
ret = -ENOMEM;
281-
goto out;
282-
}
283-
284297
for (i = 0; i < chip->npwm; i++) {
285298
pwm = &chip->pwms[i];
286299

@@ -291,23 +304,16 @@ int pwmchip_add(struct pwm_chip *chip)
291304
radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
292305
}
293306

294-
bitmap_set(allocated_pwms, chip->base, chip->npwm);
295-
296-
INIT_LIST_HEAD(&chip->list);
297307
list_add(&chip->list, &pwm_chips);
298308

299-
ret = 0;
309+
mutex_unlock(&pwm_lock);
300310

301311
if (IS_ENABLED(CONFIG_OF))
302312
of_pwmchip_add(chip);
303313

304-
out:
305-
mutex_unlock(&pwm_lock);
306-
307-
if (!ret)
308-
pwmchip_sysfs_export(chip);
314+
pwmchip_sysfs_export(chip);
309315

310-
return ret;
316+
return 0;
311317
}
312318
EXPORT_SYMBOL_GPL(pwmchip_add);
313319

@@ -457,8 +463,11 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
457463
* checks.
458464
*/
459465

460-
chip->ops->get_state(chip, pwm, &s1);
461-
trace_pwm_get(pwm, &s1);
466+
err = chip->ops->get_state(chip, pwm, &s1);
467+
trace_pwm_get(pwm, &s1, err);
468+
if (err)
469+
/* If that failed there isn't much to debug */
470+
return;
462471

463472
/*
464473
* The lowlevel driver either ignored .polarity (which is a bug) or as
@@ -514,16 +523,17 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
514523

515524
/* reapply the state that the driver reported being configured. */
516525
err = chip->ops->apply(chip, pwm, &s1);
526+
trace_pwm_apply(pwm, &s1, err);
517527
if (err) {
518528
*last = s1;
519529
dev_err(chip->dev, "failed to reapply current setting\n");
520530
return;
521531
}
522532

523-
trace_pwm_apply(pwm, &s1);
524-
525-
chip->ops->get_state(chip, pwm, last);
526-
trace_pwm_get(pwm, last);
533+
err = chip->ops->get_state(chip, pwm, last);
534+
trace_pwm_get(pwm, last, err);
535+
if (err)
536+
return;
527537

528538
/* reapplication of the current state should give an exact match */
529539
if (s1.enabled != last->enabled ||
@@ -571,11 +581,10 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
571581
return 0;
572582

573583
err = chip->ops->apply(chip, pwm, state);
584+
trace_pwm_apply(pwm, state, err);
574585
if (err)
575586
return err;
576587

577-
trace_pwm_apply(pwm, state);
578-
579588
pwm->state = *state;
580589

581590
/*
@@ -1179,8 +1188,7 @@ DEFINE_SEQ_ATTRIBUTE(pwm_debugfs);
11791188

11801189
static int __init pwm_debugfs_init(void)
11811190
{
1182-
debugfs_create_file("pwm", S_IFREG | 0444, NULL, NULL,
1183-
&pwm_debugfs_fops);
1191+
debugfs_create_file("pwm", 0444, NULL, NULL, &pwm_debugfs_fops);
11841192

11851193
return 0;
11861194
}

drivers/pwm/pwm-atmel.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ static int atmel_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
356356
return 0;
357357
}
358358

359-
static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
360-
struct pwm_state *state)
359+
static int atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
360+
struct pwm_state *state)
361361
{
362362
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
363363
u32 sr, cmr;
@@ -396,6 +396,8 @@ static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
396396
state->polarity = PWM_POLARITY_INVERSED;
397397
else
398398
state->polarity = PWM_POLARITY_NORMAL;
399+
400+
return 0;
399401
}
400402

401403
static const struct pwm_ops atmel_pwm_ops = {

drivers/pwm/pwm-bcm-iproc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static void iproc_pwmc_disable(struct iproc_pwmc *ip, unsigned int channel)
6868
ndelay(400);
6969
}
7070

71-
static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
72-
struct pwm_state *state)
71+
static int iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
72+
struct pwm_state *state)
7373
{
7474
struct iproc_pwmc *ip = to_iproc_pwmc(chip);
7575
u64 tmp, multi, rate;
@@ -91,7 +91,7 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
9191
if (rate == 0) {
9292
state->period = 0;
9393
state->duty_cycle = 0;
94-
return;
94+
return 0;
9595
}
9696

9797
value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
@@ -107,6 +107,8 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
107107
value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm));
108108
tmp = (value & IPROC_PWM_PERIOD_MAX) * multi;
109109
state->duty_cycle = div64_u64(tmp, rate);
110+
111+
return 0;
110112
}
111113

112114
static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,

0 commit comments

Comments
 (0)