Commit a9d887dc authored by Guru Das Srinagesh's avatar Guru Das Srinagesh Committed by Thierry Reding

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: default avatarkbuild test robot <lkp@intel.com>
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
parent a6733474
...@@ -510,12 +510,12 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, ...@@ -510,12 +510,12 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
last->period > s2.period && last->period > s2.period &&
last->period <= state->period) last->period <= state->period)
dev_warn(chip->dev, dev_warn(chip->dev,
".apply didn't pick the best available period (requested: %u, applied: %u, possible: %u)\n", ".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
state->period, s2.period, last->period); state->period, s2.period, last->period);
if (state->enabled && state->period < s2.period) if (state->enabled && state->period < s2.period)
dev_warn(chip->dev, dev_warn(chip->dev,
".apply is supposed to round down period (requested: %u, applied: %u)\n", ".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
state->period, s2.period); state->period, s2.period);
if (state->enabled && if (state->enabled &&
...@@ -524,14 +524,14 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, ...@@ -524,14 +524,14 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
last->duty_cycle > s2.duty_cycle && last->duty_cycle > s2.duty_cycle &&
last->duty_cycle <= state->duty_cycle) last->duty_cycle <= state->duty_cycle)
dev_warn(chip->dev, dev_warn(chip->dev,
".apply didn't pick the best available duty cycle (requested: %u/%u, applied: %u/%u, possible: %u/%u)\n", ".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n",
state->duty_cycle, state->period, state->duty_cycle, state->period,
s2.duty_cycle, s2.period, s2.duty_cycle, s2.period,
last->duty_cycle, last->period); last->duty_cycle, last->period);
if (state->enabled && state->duty_cycle < s2.duty_cycle) if (state->enabled && state->duty_cycle < s2.duty_cycle)
dev_warn(chip->dev, dev_warn(chip->dev,
".apply is supposed to round down duty_cycle (requested: %u/%u, applied: %u/%u)\n", ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
state->duty_cycle, state->period, state->duty_cycle, state->period,
s2.duty_cycle, s2.period); s2.duty_cycle, s2.period);
...@@ -558,7 +558,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm, ...@@ -558,7 +558,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
(s1.enabled && s1.period != last->period) || (s1.enabled && s1.period != last->period) ||
(s1.enabled && s1.duty_cycle != last->duty_cycle)) { (s1.enabled && s1.duty_cycle != last->duty_cycle)) {
dev_err(chip->dev, dev_err(chip->dev,
".apply is not idempotent (ena=%d pol=%d %u/%u) -> (ena=%d pol=%d %u/%u)\n", ".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n",
s1.enabled, s1.polarity, s1.duty_cycle, s1.period, s1.enabled, s1.polarity, s1.duty_cycle, s1.period,
last->enabled, last->polarity, last->duty_cycle, last->enabled, last->polarity, last->duty_cycle,
last->period); last->period);
...@@ -1284,8 +1284,8 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) ...@@ -1284,8 +1284,8 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
if (state.enabled) if (state.enabled)
seq_puts(s, " enabled"); seq_puts(s, " enabled");
seq_printf(s, " period: %u ns", state.period); seq_printf(s, " period: %llu ns", state.period);
seq_printf(s, " duty: %u ns", state.duty_cycle); seq_printf(s, " duty: %llu ns", state.duty_cycle);
seq_printf(s, " polarity: %s", seq_printf(s, " polarity: %s",
state.polarity ? "inverse" : "normal"); state.polarity ? "inverse" : "normal");
......
...@@ -61,7 +61,7 @@ static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -61,7 +61,7 @@ static int stm32_pwm_lp_apply(struct pwm_chip *chip, struct pwm_device *pwm,
do_div(div, NSEC_PER_SEC); do_div(div, NSEC_PER_SEC);
if (!div) { if (!div) {
/* Clock is too slow to achieve requested period. */ /* Clock is too slow to achieve requested period. */
dev_dbg(priv->chip.dev, "Can't reach %u ns\n", state->period); dev_dbg(priv->chip.dev, "Can't reach %llu ns\n", state->period);
return -EINVAL; return -EINVAL;
} }
......
...@@ -42,7 +42,7 @@ static ssize_t period_show(struct device *child, ...@@ -42,7 +42,7 @@ static ssize_t period_show(struct device *child,
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
return sprintf(buf, "%u\n", state.period); return sprintf(buf, "%llu\n", state.period);
} }
static ssize_t period_store(struct device *child, static ssize_t period_store(struct device *child,
...@@ -52,10 +52,10 @@ static ssize_t period_store(struct device *child, ...@@ -52,10 +52,10 @@ static ssize_t period_store(struct device *child,
struct pwm_export *export = child_to_pwm_export(child); struct pwm_export *export = child_to_pwm_export(child);
struct pwm_device *pwm = export->pwm; struct pwm_device *pwm = export->pwm;
struct pwm_state state; struct pwm_state state;
unsigned int val; u64 val;
int ret; int ret;
ret = kstrtouint(buf, 0, &val); ret = kstrtou64(buf, 0, &val);
if (ret) if (ret)
return ret; return ret;
...@@ -77,7 +77,7 @@ static ssize_t duty_cycle_show(struct device *child, ...@@ -77,7 +77,7 @@ static ssize_t duty_cycle_show(struct device *child,
pwm_get_state(pwm, &state); pwm_get_state(pwm, &state);
return sprintf(buf, "%u\n", state.duty_cycle); return sprintf(buf, "%llu\n", state.duty_cycle);
} }
static ssize_t duty_cycle_store(struct device *child, static ssize_t duty_cycle_store(struct device *child,
......
...@@ -312,7 +312,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par) ...@@ -312,7 +312,7 @@ static int ssd1307fb_init(struct ssd1307fb_par *par)
/* Enable the PWM */ /* Enable the PWM */
pwm_enable(par->pwm); pwm_enable(par->pwm);
dev_dbg(&par->client->dev, "Using PWM%d with a %dns period.\n", dev_dbg(&par->client->dev, "Using PWM%d with a %lluns period.\n",
par->pwm->pwm, pwm_get_period(par->pwm)); par->pwm->pwm, pwm_get_period(par->pwm));
} }
......
...@@ -39,7 +39,7 @@ enum pwm_polarity { ...@@ -39,7 +39,7 @@ enum pwm_polarity {
* current PWM hardware state. * current PWM hardware state.
*/ */
struct pwm_args { struct pwm_args {
unsigned int period; u64 period;
enum pwm_polarity polarity; enum pwm_polarity polarity;
}; };
...@@ -56,8 +56,8 @@ enum { ...@@ -56,8 +56,8 @@ enum {
* @enabled: PWM enabled status * @enabled: PWM enabled status
*/ */
struct pwm_state { struct pwm_state {
unsigned int period; u64 period;
unsigned int duty_cycle; u64 duty_cycle;
enum pwm_polarity polarity; enum pwm_polarity polarity;
bool enabled; bool enabled;
}; };
...@@ -107,13 +107,13 @@ static inline bool pwm_is_enabled(const struct pwm_device *pwm) ...@@ -107,13 +107,13 @@ static inline bool pwm_is_enabled(const struct pwm_device *pwm)
return state.enabled; return state.enabled;
} }
static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) static inline void pwm_set_period(struct pwm_device *pwm, u64 period)
{ {
if (pwm) if (pwm)
pwm->state.period = period; pwm->state.period = period;
} }
static inline unsigned int pwm_get_period(const struct pwm_device *pwm) static inline u64 pwm_get_period(const struct pwm_device *pwm)
{ {
struct pwm_state state; struct pwm_state state;
...@@ -128,7 +128,7 @@ static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty) ...@@ -128,7 +128,7 @@ static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
pwm->state.duty_cycle = duty; pwm->state.duty_cycle = duty;
} }
static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm) static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm)
{ {
struct pwm_state state; struct pwm_state state;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment