Skip to content

Commit

Permalink
pwm: core: Support new usage_power setting in PWM state
Browse files Browse the repository at this point in the history
If usage_power is set, the PWM driver is only required to maintain
the power output but has more freedom regarding signal form.

If supported, the signal can be optimized, for example to
improve EMI by phase shifting individual channels.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
  • Loading branch information
Clemens Gruber authored and Thierry Reding committed Jun 4, 2021
1 parent 98761ce commit 9e40ee1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Documentation/driver-api/pwm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ After being requested, a PWM has to be configured using::

This API controls both the PWM period/duty_cycle config and the
enable/disable state.
There is also a usage_power setting: If set, the PWM driver is only required to
maintain the power output but has more freedom regarding signal form.
If supported by the driver, the signal can be optimized, for example to improve
EMI by phase shifting the individual channels of a chip.

The pwm_config(), pwm_enable() and pwm_disable() functions are just wrappers
around pwm_apply_state() and should not be used if the user wants to change
Expand Down
6 changes: 5 additions & 1 deletion drivers/pwm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
if (state->period == pwm->state.period &&
state->duty_cycle == pwm->state.duty_cycle &&
state->polarity == pwm->state.polarity &&
state->enabled == pwm->state.enabled)
state->enabled == pwm->state.enabled &&
state->usage_power == pwm->state.usage_power)
return 0;

if (chip->ops->apply) {
Expand Down Expand Up @@ -1241,6 +1242,9 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
seq_printf(s, " polarity: %s",
state.polarity ? "inverse" : "normal");

if (state.usage_power)
seq_puts(s, " usage_power");

seq_puts(s, "\n");
}
}
Expand Down
7 changes: 7 additions & 0 deletions include/linux/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ enum {
* @duty_cycle: PWM duty cycle (in nanoseconds)
* @polarity: PWM polarity
* @enabled: PWM enabled status
* @usage_power: If set, the PWM driver is only required to maintain the power
* output but has more freedom regarding signal form.
* If supported, the signal can be optimized, for example to
* improve EMI by phase shifting individual channels.
*/
struct pwm_state {
u64 period;
u64 duty_cycle;
enum pwm_polarity polarity;
bool enabled;
bool usage_power;
};

/**
Expand Down Expand Up @@ -188,6 +193,7 @@ static inline void pwm_init_state(const struct pwm_device *pwm,
state->period = args.period;
state->polarity = args.polarity;
state->duty_cycle = 0;
state->usage_power = false;
}

/**
Expand Down Expand Up @@ -558,6 +564,7 @@ static inline void pwm_apply_args(struct pwm_device *pwm)
state.enabled = false;
state.polarity = pwm->args.polarity;
state.period = pwm->args.period;
state.usage_power = false;

pwm_apply_state(pwm, &state);
}
Expand Down

0 comments on commit 9e40ee1

Please sign in to comment.