}
 
 static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
-                         int duty_ns, int period_ns)
+                         int duty_ns, int period_ns, bool enabled)
 {
        static const unsigned int prescalers[] = { 1, 4, 16, 64 };
        struct tpu_pwm_device *pwm = pwm_get_chip_data(_pwm);
        pwm->duty = duty;
 
        /* If the channel is disabled we're done. */
-       if (!pwm_is_enabled(_pwm))
+       if (!enabled)
                return 0;
 
        if (duty_only && pwm->timer_on) {
        tpu_pwm_timer_stop(pwm);
 }
 
+static int tpu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+                        const struct pwm_state *state)
+{
+       int err;
+       bool enabled = pwm->state.enabled;
+
+       if (state->polarity != pwm->state.polarity) {
+               if (enabled) {
+                       tpu_pwm_disable(chip, pwm);
+                       enabled = false;
+               }
+
+               err = tpu_pwm_set_polarity(chip, pwm, state->polarity);
+               if (err)
+                       return err;
+       }
+
+       if (!state->enabled) {
+               if (enabled)
+                       tpu_pwm_disable(chip, pwm);
+
+               return 0;
+       }
+
+       err = tpu_pwm_config(pwm->chip, pwm,
+                            state->duty_cycle, state->period, enabled);
+       if (err)
+               return err;
+
+       if (!enabled)
+               err = tpu_pwm_enable(chip, pwm);
+
+       return err;
+}
+
 static const struct pwm_ops tpu_pwm_ops = {
        .request = tpu_pwm_request,
        .free = tpu_pwm_free,
-       .config = tpu_pwm_config,
-       .set_polarity = tpu_pwm_set_polarity,
-       .enable = tpu_pwm_enable,
-       .disable = tpu_pwm_disable,
+       .apply = tpu_pwm_apply,
        .owner = THIS_MODULE,
 };