Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: max77693 - convert to atomic pwm operation

The driver called pwm_config() and pwm_enable() separately. Today both
are wrappers for pwm_apply_might_sleep() and it's more effective to call
this function directly and only once. Also don't configure the
duty_cycle and period if the next operation is to disable the PWM so
configure the PWM in max77693_haptic_enable().

With the direct use of pwm_apply_might_sleep() the need to call
pwm_apply_args() in .probe() is now gone, too, so drop this one.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://lore.kernel.org/r/20250630103851.2069952-2-u.kleine-koenig@baylibre.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Uwe Kleine-König and committed by
Dmitry Torokhov
61c6fef7 1c44b818

+18 -23
+18 -23
drivers/input/misc/max77693-haptic.c
··· 68 68 69 69 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic) 70 70 { 71 - struct pwm_args pargs; 72 - int delta; 71 + struct pwm_state state; 73 72 int error; 74 73 75 - pwm_get_args(haptic->pwm_dev, &pargs); 76 - delta = (pargs.period + haptic->pwm_duty) / 2; 77 - error = pwm_config(haptic->pwm_dev, delta, pargs.period); 74 + pwm_init_state(haptic->pwm_dev, &state); 75 + state.duty_cycle = (state.period + haptic->pwm_duty) / 2; 76 + 77 + error = pwm_apply_might_sleep(haptic->pwm_dev, &state); 78 78 if (error) { 79 - dev_err(haptic->dev, "failed to configure pwm: %d\n", error); 79 + dev_err(haptic->dev, 80 + "failed to set pwm duty cycle: %d\n", error); 80 81 return error; 81 82 } 82 83 ··· 167 166 168 167 static void max77693_haptic_enable(struct max77693_haptic *haptic) 169 168 { 169 + struct pwm_state state; 170 170 int error; 171 171 172 172 if (haptic->enabled) 173 173 return; 174 174 175 - error = pwm_enable(haptic->pwm_dev); 175 + pwm_init_state(haptic->pwm_dev, &state); 176 + state.duty_cycle = (state.period + haptic->pwm_duty) / 2; 177 + state.enabled = true; 178 + 179 + error = pwm_apply_might_sleep(haptic->pwm_dev, &state); 176 180 if (error) { 177 181 dev_err(haptic->dev, 178 182 "failed to enable haptic pwm device: %d\n", error); ··· 230 224 { 231 225 struct max77693_haptic *haptic = 232 226 container_of(work, struct max77693_haptic, work); 233 - int error; 234 227 235 - error = max77693_haptic_set_duty_cycle(haptic); 236 - if (error) { 237 - dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); 238 - return; 239 - } 240 - 241 - if (haptic->magnitude) 242 - max77693_haptic_enable(haptic); 243 - else 228 + if (!haptic->magnitude) 244 229 max77693_haptic_disable(haptic); 230 + else if (haptic->enabled) 231 + max77693_haptic_set_duty_cycle(haptic); 232 + else 233 + max77693_haptic_enable(haptic); 245 234 } 246 235 247 236 static int max77693_haptic_play_effect(struct input_dev *dev, void *data, ··· 340 339 dev_err(&pdev->dev, "failed to get pwm device\n"); 341 340 return PTR_ERR(haptic->pwm_dev); 342 341 } 343 - 344 - /* 345 - * FIXME: pwm_apply_args() should be removed when switching to the 346 - * atomic PWM API. 347 - */ 348 - pwm_apply_args(haptic->pwm_dev); 349 342 350 343 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic"); 351 344 if (IS_ERR(haptic->motor_reg)) {