video: rockchip: vpu: add rk3368 support
[firefly-linux-kernel-4.4.55.git] / drivers / pwm / core.c
index d57d3746eccfc68619c7c8f1b3f2ae8199487213..172ef82458112c268782d24f55cd882904340ea8 100644 (file)
@@ -459,7 +459,8 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
 {
        int err;
 
-       if (!pwm)
+       if (!pwm || !state || !state->period ||
+           state->duty_cycle > state->period)
                return -EINVAL;
 
        if (!memcmp(state, &pwm->state, sizeof(*state)))
@@ -526,6 +527,33 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
 }
 EXPORT_SYMBOL_GPL(pwm_apply_state);
 
+/**
+ * pwm_capture() - capture and report a PWM signal
+ * @pwm: PWM device
+ * @result: structure to fill with capture result
+ * @timeout: time to wait, in milliseconds, before giving up on capture
+ *
+ * Returns: 0 on success or a negative error code on failure.
+ */
+int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
+               unsigned long timeout)
+{
+       int err;
+
+       if (!pwm || !pwm->chip->ops)
+               return -EINVAL;
+
+       if (!pwm->chip->ops->capture)
+               return -ENOSYS;
+
+       mutex_lock(&pwm_lock);
+       err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
+       mutex_unlock(&pwm_lock);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(pwm_capture);
+
 /**
  * pwm_adjust_config() - adjust the current PWM config to the PWM arguments
  * @pwm: PWM device
@@ -951,15 +979,23 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
 
        for (i = 0; i < chip->npwm; i++) {
                struct pwm_device *pwm = &chip->pwms[i];
+               struct pwm_state state;
+
+               pwm_get_state(pwm, &state);
 
                seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
 
                if (test_bit(PWMF_REQUESTED, &pwm->flags))
                        seq_puts(s, " requested");
 
-               if (pwm_is_enabled(pwm))
+               if (state.enabled)
                        seq_puts(s, " enabled");
 
+               seq_printf(s, " period: %u ns", state.period);
+               seq_printf(s, " duty: %u ns", state.duty_cycle);
+               seq_printf(s, " polarity: %s",
+                          state.polarity ? "inverse" : "normal");
+
                seq_puts(s, "\n");
        }
 }