@@ -58,8 +58,14 @@ static int max8997_haptic_set_duty_cycle(struct max8997_haptic *chip)
int ret = 0;
if (chip->mode == MAX8997_EXTERNAL_MODE) {
- unsigned int duty = chip->pwm_period * chip->level / 100;
- ret = pwm_config(chip->pwm, duty, chip->pwm_period);
+ struct pwm_state state;
+
+ pwm_init_state(chip->pwm, &state);
+ state.period = chip->pwm_period;
+ state.duty_cycle = chip->pwm_period * chip->level / 100;
+ state.enabled = true;
+
+ ret = pwm_apply_might_sleep(chip->pwm, &state);
} else {
u8 duty_index = 0;
@@ -168,14 +174,6 @@ static void max8997_haptic_enable(struct max8997_haptic *chip)
return;
}
max8997_haptic_configure(chip);
- if (chip->mode == MAX8997_EXTERNAL_MODE) {
- error = pwm_enable(chip->pwm);
- if (error) {
- dev_err(chip->dev, "Failed to enable PWM\n");
- regulator_disable(chip->regulator);
- return;
- }
- }
chip->enabled = true;
}
}
Both pwm_config() and pwm_enable() are wrappers around pwm_apply_might_sleep(). Instead of calling this function twice only call it once without an intermediate step. max8997_haptic_enable() is the only user of max8997_haptic_set_duty_cycle(), so it's known in the latter that the PWM should be enabled. There is a slight change in semantic because without this change the polarity configured before (which probably is at its bootup state) was kept, while with this change it is set to its default polarity. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> --- Hello, the motivation for this patch is to get rid of pwm_config(). This driver is one of the remaining two users of this function. Best regards Uwe drivers/input/misc/max8997_haptic.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) base-commit: f817b6dd2b62d921a6cdc0a3ac599cd1851f343c