]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/pwm/core.c
Merge tag 'copy-struct-from-user-v5.4-rc4' of gitolite.kernel.org:pub/scm/linux/kerne...
[linux.git] / drivers / pwm / core.c
index 4ab683a30629afdfeb47ea647cf7aed3ab2b5acb..6ad51aa60c03dd1cf8afd00410a53a459f4d0a35 100644 (file)
@@ -448,11 +448,9 @@ EXPORT_SYMBOL_GPL(pwm_free);
 /**
  * pwm_apply_state() - atomically apply a new state to a PWM device
  * @pwm: PWM device
- * @state: new state to apply. This can be adjusted by the PWM driver
- *        if the requested config is not achievable, for example,
- *        ->duty_cycle and ->period might be approximated.
+ * @state: new state to apply
  */
-int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
+int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
 {
        struct pwm_chip *chip;
        int err;
@@ -474,7 +472,14 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
                if (err)
                        return err;
 
-               pwm->state = *state;
+               /*
+                * .apply might have to round some values in *state, if possible
+                * read the actually implemented value back.
+                */
+               if (chip->ops->get_state)
+                       chip->ops->get_state(chip, pwm, &pwm->state);
+               else
+                       pwm->state = *state;
        } else {
                /*
                 * FIXME: restore the initial state in case of error.