Skip to content

Commit fded091

Browse files
committed
Merge tag 'pwm/for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
Pull pwm updates from Thierry Reding: "The majority of this batch is conversion of the PWM period and duty cycle to 64-bit unsigned integers, which is required so that some types of hardware can generate the full range of signals that they're capable of. The remainder is mostly minor fixes and cleanups" * tag 'pwm/for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: pwm: bcm-iproc: handle clk_get_rate() return pwm: Replace HTTP links with HTTPS ones pwm: omap-dmtimer: Repair pwm_omap_dmtimer_chip's broken kerneldoc header pwm: mediatek: Provide missing kerneldoc description for 'soc' arg pwm: bcm-kona: Remove impossible comparison when validating duty cycle pwm: bcm-iproc: Remove impossible comparison when validating duty cycle pwm: iqs620a: Use lowercase hexadecimal literals for consistency pwm: Convert period and duty cycle to u64 clk: pwm: Use 64-bit division function backlight: pwm_bl: Use 64-bit division function pwm: sun4i: Use nsecs_to_jiffies to avoid a division pwm: sifive: Use 64-bit division macro pwm: iqs620a: Use 64-bit division pwm: imx27: Use 64-bit division macro pwm: imx-tpm: Use 64-bit division macro pwm: clps711x: Use 64-bit division macro hwmon: pwm-fan: Use 64-bit division macro drm/i915: Use 64-bit division macro
2 parents 87bd8c2 + 6ced5ff commit fded091

File tree

21 files changed

+56
-44
lines changed

21 files changed

+56
-44
lines changed

drivers/clk/clk-pwm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ static int clk_pwm_probe(struct platform_device *pdev)
8989
}
9090

9191
if (of_property_read_u32(node, "clock-frequency", &clk_pwm->fixed_rate))
92-
clk_pwm->fixed_rate = NSEC_PER_SEC / pargs.period;
92+
clk_pwm->fixed_rate = div64_u64(NSEC_PER_SEC, pargs.period);
93+
94+
if (!clk_pwm->fixed_rate) {
95+
dev_err(&pdev->dev, "fixed_rate cannot be zero\n");
96+
return -EINVAL;
97+
}
9398

9499
if (pargs.period != NSEC_PER_SEC / clk_pwm->fixed_rate &&
95100
pargs.period != DIV_ROUND_UP(NSEC_PER_SEC, clk_pwm->fixed_rate)) {

drivers/gpu/drm/i915/display/intel_panel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ static int pwm_setup_backlight(struct intel_connector *connector,
19291929
return retval;
19301930
}
19311931

1932-
level = DIV_ROUND_UP(pwm_get_duty_cycle(panel->backlight.pwm) * 100,
1932+
level = DIV_ROUND_UP_ULL(pwm_get_duty_cycle(panel->backlight.pwm) * 100,
19331933
CRC_PMIC_PWM_PERIOD_NS);
19341934
panel->backlight.level =
19351935
intel_panel_compute_brightness(connector, level);

drivers/hwmon/pwm-fan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static int pwm_fan_resume(struct device *dev)
447447
return 0;
448448

449449
pwm_get_args(ctx->pwm, &pargs);
450-
duty = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), MAX_PWM);
450+
duty = DIV_ROUND_UP_ULL(ctx->pwm_value * (pargs.period - 1), MAX_PWM);
451451
ret = pwm_config(ctx->pwm, duty, pargs.period);
452452
if (ret)
453453
return ret;

drivers/pwm/core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,12 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
510510
last->period > s2.period &&
511511
last->period <= state->period)
512512
dev_warn(chip->dev,
513-
".apply didn't pick the best available period (requested: %u, applied: %u, possible: %u)\n",
513+
".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
514514
state->period, s2.period, last->period);
515515

516516
if (state->enabled && state->period < s2.period)
517517
dev_warn(chip->dev,
518-
".apply is supposed to round down period (requested: %u, applied: %u)\n",
518+
".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
519519
state->period, s2.period);
520520

521521
if (state->enabled &&
@@ -524,14 +524,14 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
524524
last->duty_cycle > s2.duty_cycle &&
525525
last->duty_cycle <= state->duty_cycle)
526526
dev_warn(chip->dev,
527-
".apply didn't pick the best available duty cycle (requested: %u/%u, applied: %u/%u, possible: %u/%u)\n",
527+
".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n",
528528
state->duty_cycle, state->period,
529529
s2.duty_cycle, s2.period,
530530
last->duty_cycle, last->period);
531531

532532
if (state->enabled && state->duty_cycle < s2.duty_cycle)
533533
dev_warn(chip->dev,
534-
".apply is supposed to round down duty_cycle (requested: %u/%u, applied: %u/%u)\n",
534+
".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
535535
state->duty_cycle, state->period,
536536
s2.duty_cycle, s2.period);
537537

@@ -558,7 +558,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
558558
(s1.enabled && s1.period != last->period) ||
559559
(s1.enabled && s1.duty_cycle != last->duty_cycle)) {
560560
dev_err(chip->dev,
561-
".apply is not idempotent (ena=%d pol=%d %u/%u) -> (ena=%d pol=%d %u/%u)\n",
561+
".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n",
562562
s1.enabled, s1.polarity, s1.duty_cycle, s1.period,
563563
last->enabled, last->polarity, last->duty_cycle,
564564
last->period);
@@ -1284,8 +1284,8 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
12841284
if (state.enabled)
12851285
seq_puts(s, " enabled");
12861286

1287-
seq_printf(s, " period: %u ns", state.period);
1288-
seq_printf(s, " duty: %u ns", state.duty_cycle);
1287+
seq_printf(s, " period: %llu ns", state.period);
1288+
seq_printf(s, " duty: %llu ns", state.duty_cycle);
12891289
seq_printf(s, " polarity: %s",
12901290
state.polarity ? "inverse" : "normal");
12911291

drivers/pwm/pwm-bcm-iproc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
8585
u64 tmp, multi, rate;
8686
u32 value, prescale;
8787

88-
rate = clk_get_rate(ip->clk);
89-
9088
value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
9189

9290
if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm)))
@@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
9997
else
10098
state->polarity = PWM_POLARITY_INVERSED;
10199

100+
rate = clk_get_rate(ip->clk);
101+
if (rate == 0) {
102+
state->period = 0;
103+
state->duty_cycle = 0;
104+
return;
105+
}
106+
102107
value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
103108
prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
104109
prescale &= IPROC_PWM_PRESCALE_MAX;
@@ -143,8 +148,7 @@ static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm,
143148
value = rate * state->duty_cycle;
144149
duty = div64_u64(value, div);
145150

146-
if (period < IPROC_PWM_PERIOD_MIN ||
147-
duty < IPROC_PWM_DUTY_CYCLE_MIN)
151+
if (period < IPROC_PWM_PERIOD_MIN)
148152
return -EINVAL;
149153

150154
if (period <= IPROC_PWM_PERIOD_MAX &&

drivers/pwm/pwm-bcm-kona.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm,
138138
dc = div64_u64(val, div);
139139

140140
/* If duty_ns or period_ns are not achievable then return */
141-
if (pc < PERIOD_COUNT_MIN || dc < DUTY_CYCLE_HIGH_MIN)
141+
if (pc < PERIOD_COUNT_MIN)
142142
return -EINVAL;
143143

144144
/* If pc and dc are in bounds, the calculation is done */

drivers/pwm/pwm-clps711x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void clps711x_pwm_update_val(struct clps711x_chip *priv, u32 n, u32 v)
4343
static unsigned int clps711x_get_duty(struct pwm_device *pwm, unsigned int v)
4444
{
4545
/* Duty cycle 0..15 max */
46-
return DIV_ROUND_CLOSEST(v * 0xf, pwm->args.period);
46+
return DIV64_U64_ROUND_CLOSEST(v * 0xf, pwm->args.period);
4747
}
4848

4949
static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)

drivers/pwm/pwm-imx-tpm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
124124
real_state->duty_cycle = state->duty_cycle;
125125

126126
tmp = (u64)p->mod * real_state->duty_cycle;
127-
p->val = DIV_ROUND_CLOSEST_ULL(tmp, real_state->period);
127+
p->val = DIV64_U64_ROUND_CLOSEST(tmp, real_state->period);
128128

129129
real_state->polarity = state->polarity;
130130
real_state->enabled = state->enabled;

drivers/pwm/pwm-imx27.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void pwm_imx27_wait_fifo_slot(struct pwm_chip *chip,
202202
sr = readl(imx->mmio_base + MX3_PWMSR);
203203
fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr);
204204
if (fifoav == MX3_PWMSR_FIFOAV_4WORDS) {
205-
period_ms = DIV_ROUND_UP(pwm_get_period(pwm),
205+
period_ms = DIV_ROUND_UP_ULL(pwm_get_period(pwm),
206206
NSEC_PER_MSEC);
207207
msleep(period_ms);
208208

drivers/pwm/pwm-iqs620a.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#include <linux/regmap.h>
2626
#include <linux/slab.h>
2727

28-
#define IQS620_PWR_SETTINGS 0xD2
28+
#define IQS620_PWR_SETTINGS 0xd2
2929
#define IQS620_PWR_SETTINGS_PWM_OUT BIT(7)
3030

31-
#define IQS620_PWM_DUTY_CYCLE 0xD8
31+
#define IQS620_PWM_DUTY_CYCLE 0xd8
3232

3333
#define IQS620_PWM_PERIOD_NS 1000000
3434

@@ -46,7 +46,8 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4646
{
4747
struct iqs620_pwm_private *iqs620_pwm;
4848
struct iqs62x_core *iqs62x;
49-
int duty_scale, ret;
49+
u64 duty_scale;
50+
int ret;
5051

5152
if (state->polarity != PWM_POLARITY_NORMAL)
5253
return -ENOTSUPP;
@@ -69,7 +70,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
6970
* For lower duty cycles (e.g. 0), the PWM output is simply disabled to
7071
* allow an external pull-down resistor to hold the GPIO3/LTX pin low.
7172
*/
72-
duty_scale = state->duty_cycle * 256 / IQS620_PWM_PERIOD_NS;
73+
duty_scale = div_u64(state->duty_cycle * 256, IQS620_PWM_PERIOD_NS);
7374

7475
mutex_lock(&iqs620_pwm->lock);
7576

@@ -81,7 +82,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
8182
}
8283

8384
if (duty_scale) {
84-
u8 duty_val = min(duty_scale - 1, 0xFF);
85+
u8 duty_val = min_t(u64, duty_scale - 1, 0xff);
8586

8687
ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE,
8788
duty_val);
@@ -93,7 +94,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
9394

9495
if (state->enabled && duty_scale) {
9596
ret = regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
96-
IQS620_PWR_SETTINGS_PWM_OUT, 0xFF);
97+
IQS620_PWR_SETTINGS_PWM_OUT, 0xff);
9798
if (ret)
9899
goto err_mutex;
99100
}
@@ -159,7 +160,7 @@ static int iqs620_pwm_notifier(struct notifier_block *notifier,
159160

160161
ret = regmap_update_bits(iqs62x->regmap, IQS620_PWR_SETTINGS,
161162
IQS620_PWR_SETTINGS_PWM_OUT,
162-
iqs620_pwm->out_en ? 0xFF : 0);
163+
iqs620_pwm->out_en ? 0xff : 0);
163164

164165
err_mutex:
165166
mutex_unlock(&iqs620_pwm->lock);

0 commit comments

Comments
 (0)