Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: max77693 - Convert to atomic pwm operation
@ 2025-06-30 10:38 Uwe Kleine-König
  2025-06-30 19:23 ` Dmitry Torokhov
  0 siblings, 1 reply; 8+ messages in thread
From: Uwe Kleine-König @ 2025-06-30 10:38 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dzmitry Sankouski, Marek Szyprowski, Krzysztof Kozlowski,
	linux-input, linux-pwm

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>
---
Hello,

the motivation for this patch is getting rid of pwm_config(),
pwm_enable() and pwm_apply_args(). I plan to remove these once all
callers are fixed to use pwm_apply_might_sleep().

Best regards
Uwe

 drivers/input/misc/max77693-haptic.c | 41 ++++++----------------------
 1 file changed, 8 insertions(+), 33 deletions(-)

diff --git a/drivers/input/misc/max77693-haptic.c b/drivers/input/misc/max77693-haptic.c
index 1dfd7b95a4ce..ecb3e8d541c3 100644
--- a/drivers/input/misc/max77693-haptic.c
+++ b/drivers/input/misc/max77693-haptic.c
@@ -66,23 +66,6 @@ struct max77693_haptic {
 	struct work_struct work;
 };
 
-static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
-{
-	struct pwm_args pargs;
-	int delta;
-	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);
-	if (error) {
-		dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
-		return error;
-	}
-
-	return 0;
-}
-
 static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on)
 {
 	int error;
@@ -167,17 +150,22 @@ static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable)
 static void max77693_haptic_enable(struct max77693_haptic *haptic)
 {
 	int error;
+	struct pwm_state state;
 
-	if (haptic->enabled)
-		return;
+	pwm_init_state(haptic->pwm_dev, &state);
+	state.duty_cycle = (state.period + haptic->pwm_duty) / 2;
+	state.enabled = true;
 
-	error = pwm_enable(haptic->pwm_dev);
+	error = pwm_apply_might_sleep(haptic->pwm_dev, &state);
 	if (error) {
 		dev_err(haptic->dev,
 			"failed to enable haptic pwm device: %d\n", error);
 		return;
 	}
 
+	if (haptic->enabled)
+		return;
+
 	error = max77693_haptic_lowsys(haptic, true);
 	if (error)
 		goto err_enable_lowsys;
@@ -224,13 +212,6 @@ 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);
@@ -340,12 +321,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");

base-commit: 1343433ed38923a21425c602e92120a1f1db5f7a
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-07  6:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30 10:38 [PATCH] Input: max77693 - Convert to atomic pwm operation Uwe Kleine-König
2025-06-30 19:23 ` Dmitry Torokhov
2025-07-01  5:49   ` Uwe Kleine-König
2025-07-01 18:06     ` Dmitry Torokhov
2025-07-02  6:02       ` Uwe Kleine-König
2025-07-29 20:04         ` Uwe Kleine-König
2025-08-07  4:33           ` Dmitry Torokhov
2025-08-07  6:42             ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox