]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: max77693 - convert to atomic pwm operation
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Mon, 30 Jun 2025 16:27:26 +0000 (09:27 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 4 Aug 2025 06:12:09 +0000 (23:12 -0700)
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>
drivers/input/misc/max77693-haptic.c

index 1dfd7b95a4ce6699ed66513359f1dfe13ee90d91..5d45680d74a44bc63ff987f533016b88520b255d 100644 (file)
@@ -68,15 +68,16 @@ struct max77693_haptic {
 
 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
 {
-       struct pwm_args pargs;
-       int delta;
+       struct pwm_state state;
        int error;
 
-       pwm_get_args(haptic->pwm_dev, &pargs);
-       delta = (pargs.period + haptic->pwm_duty) / 2;
-       error = pwm_config(haptic->pwm_dev, delta, pargs.period);
+       pwm_init_state(haptic->pwm_dev, &state);
+       state.duty_cycle = (state.period + haptic->pwm_duty) / 2;
+
+       error = pwm_apply_might_sleep(haptic->pwm_dev, &state);
        if (error) {
-               dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
+               dev_err(haptic->dev,
+                       "failed to set pwm duty cycle: %d\n", error);
                return error;
        }
 
@@ -166,12 +167,17 @@ static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable)
 
 static void max77693_haptic_enable(struct max77693_haptic *haptic)
 {
+       struct pwm_state state;
        int error;
 
        if (haptic->enabled)
                return;
 
-       error = pwm_enable(haptic->pwm_dev);
+       pwm_init_state(haptic->pwm_dev, &state);
+       state.duty_cycle = (state.period + haptic->pwm_duty) / 2;
+       state.enabled = true;
+
+       error = pwm_apply_might_sleep(haptic->pwm_dev, &state);
        if (error) {
                dev_err(haptic->dev,
                        "failed to enable haptic pwm device: %d\n", error);
@@ -224,18 +230,13 @@ static void max77693_haptic_play_work(struct work_struct *work)
 {
        struct max77693_haptic *haptic =
                        container_of(work, struct max77693_haptic, work);
-       int error;
-
-       error = max77693_haptic_set_duty_cycle(haptic);
-       if (error) {
-               dev_err(haptic->dev, "failed to set duty cycle: %d\n", error);
-               return;
-       }
 
-       if (haptic->magnitude)
-               max77693_haptic_enable(haptic);
-       else
+       if (!haptic->magnitude)
                max77693_haptic_disable(haptic);
+       else if (haptic->enabled)
+               max77693_haptic_set_duty_cycle(haptic);
+       else
+               max77693_haptic_enable(haptic);
 }
 
 static int max77693_haptic_play_effect(struct input_dev *dev, void *data,
@@ -340,12 +341,6 @@ static int max77693_haptic_probe(struct platform_device *pdev)
                return PTR_ERR(haptic->pwm_dev);
        }
 
-       /*
-        * FIXME: pwm_apply_args() should be removed when switching to the
-        * atomic PWM API.
-        */
-       pwm_apply_args(haptic->pwm_dev);
-
        haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic");
        if (IS_ERR(haptic->motor_reg)) {
                dev_err(&pdev->dev, "failed to get regulator\n");