Skip to content

Commit a9d887d

Browse files
Guru Das Srinageshthierryreding
authored andcommitted
pwm: Convert period and duty cycle to u64
Because period and duty cycle are defined as ints with units of nanoseconds, the maximum time duration that can be set is limited to ~2.147 seconds. Change their definitions to u64 in the structs of the PWM framework so that higher durations may be set. Also use the right format specifiers in debug prints in both core.c, pwm-stm32-lp.c as well as video/fbdev/ssd1307fb.c. Reported-by: kbuild test robot <[email protected]> Signed-off-by: Guru Das Srinagesh <[email protected]> Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent a673347 commit a9d887d

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

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-stm32-lp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm,
6161
do_div(div, NSEC_PER_SEC);
6262
if (!div) {
6363
/* Clock is too slow to achieve requested period. */
64-
dev_dbg(priv->chip.dev, "Can't reach %u ns\n", state->period);
64+
dev_dbg(priv->chip.dev, "Can't reach %llu ns\n", state->period);
6565
return -EINVAL;
6666
}
6767

drivers/pwm/sysfs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static ssize_t period_show(struct device *child,
4242

4343
pwm_get_state(pwm, &state);
4444

45-
return sprintf(buf, "%u\n", state.period);
45+
return sprintf(buf, "%llu\n", state.period);
4646
}
4747

4848
static ssize_t period_store(struct device *child,
@@ -52,10 +52,10 @@ static ssize_t period_store(struct device *child,
5252
struct pwm_export *export = child_to_pwm_export(child);
5353
struct pwm_device *pwm = export->pwm;
5454
struct pwm_state state;
55-
unsigned int val;
55+
u64 val;
5656
int ret;
5757

58-
ret = kstrtouint(buf, 0, &val);
58+
ret = kstrtou64(buf, 0, &val);
5959
if (ret)
6060
return ret;
6161

@@ -77,7 +77,7 @@ static ssize_t duty_cycle_show(struct device *child,
7777

7878
pwm_get_state(pwm, &state);
7979

80-
return sprintf(buf, "%u\n", state.duty_cycle);
80+
return sprintf(buf, "%llu\n", state.duty_cycle);
8181
}
8282

8383
static ssize_t duty_cycle_store(struct device *child,

drivers/video/fbdev/ssd1307fb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
312312
/* Enable the PWM */
313313
pwm_enable(par->pwm);
314314

315-
dev_dbg(&par->client->dev, "Using PWM%d with a %dns period.\n",
315+
dev_dbg(&par->client->dev, "Using PWM%d with a %lluns period.\n",
316316
par->pwm->pwm, pwm_get_period(par->pwm));
317317
}
318318

include/linux/pwm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum pwm_polarity {
3939
* current PWM hardware state.
4040
*/
4141
struct pwm_args {
42-
unsigned int period;
42+
u64 period;
4343
enum pwm_polarity polarity;
4444
};
4545

@@ -56,8 +56,8 @@ enum {
5656
* @enabled: PWM enabled status
5757
*/
5858
struct pwm_state {
59-
unsigned int period;
60-
unsigned int duty_cycle;
59+
u64 period;
60+
u64 duty_cycle;
6161
enum pwm_polarity polarity;
6262
bool enabled;
6363
};
@@ -107,13 +107,13 @@ static inline bool pwm_is_enabled(const struct pwm_device *pwm)
107107
return state.enabled;
108108
}
109109

110-
static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
110+
static inline void pwm_set_period(struct pwm_device *pwm, u64 period)
111111
{
112112
if (pwm)
113113
pwm->state.period = period;
114114
}
115115

116-
static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
116+
static inline u64 pwm_get_period(const struct pwm_device *pwm)
117117
{
118118
struct pwm_state state;
119119

@@ -128,7 +128,7 @@ static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
128128
pwm->state.duty_cycle = duty;
129129
}
130130

131-
static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
131+
static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm)
132132
{
133133
struct pwm_state state;
134134

0 commit comments

Comments
 (0)