@@ -347,33 +347,51 @@ int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state);
int pwm_adjust_config(struct pwm_device *pwm);
/**
- * pwm_config() - change a PWM device configuration
+ * pwm_config_full() - change a PWM device configuration, including duty
+ * offset
* @pwm: PWM device
* @duty_ns: "on" time (in nanoseconds)
+ * @duty_offset_ns: offset (in nanoseconds) of "on" pulse
* @period_ns: duration (in nanoseconds) of one cycle
*
* Returns: 0 on success or a negative error code on failure.
*/
-static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
- int period_ns)
+static inline int pwm_config_full(struct pwm_device *pwm, int duty_ns,
+ int duty_offset_ns, int period_ns)
{
struct pwm_state state;
if (!pwm)
return -EINVAL;
- if (duty_ns < 0 || period_ns < 0)
+ if (duty_ns < 0 || period_ns < 0 || duty_offset_ns < 0)
return -EINVAL;
pwm_get_state(pwm, &state);
- if (state.duty_cycle == duty_ns && state.period == period_ns)
+ if (state.duty_cycle == duty_ns && state.period == period_ns &&
+ state.duty_offset == duty_offset_ns)
return 0;
state.duty_cycle = duty_ns;
+ state.duty_offset = duty_offset_ns;
state.period = period_ns;
return pwm_apply_might_sleep(pwm, &state);
}
+/**
+ * pwm_config() - change a PWM device configuration
+ * @pwm: PWM device
+ * @duty_ns: "on" time (in nanoseconds)
+ * @period_ns: duration (in nanoseconds) of one cycle
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
+ int period_ns)
+{
+ return pwm_config_full(pwm, duty_ns, 0, period_ns);
+}
+
/**
* pwm_enable() - start a PWM output toggling
* @pwm: PWM device
@@ -480,6 +498,13 @@ static inline int pwm_adjust_config(struct pwm_device *pwm)
return -EOPNOTSUPP;
}
+static inline int pwm_config_full(struct pwm_device *pwm, int duty_ns,
+ int duty_offset_ns, int period_ns)
+{
+ might_sleep();
+ return -EINVAL;
+}
+
static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
int period_ns)
{
Add a function that performs the old pwm_config operations while also handling duty_offset. Change pwm_config to use pwm_config_full with the duty_offset_ns argument set to 0. Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com> --- include/linux/pwm.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-)