linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: misc: max8997: Switch to pwm_apply()
@ 2021-03-16 20:38 Uwe Kleine-König
  2021-03-21 22:23 ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2021-03-16 20:38 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Thierry Reding, Lee Jones, linux-input, linux-pwm

max8997_haptic_enable() is the only caller of
max8997_haptic_set_duty_cycle(). For the non-external case the PWM is
already enabled in max8997_haptic_set_duty_cycle(), so this can be done
for the external case, too, and so the pwm_enable() call can be folded into
max8997_haptic_set_duty_cycle()'s call to pwm_apply_state().

With max8997_haptic_set_duty_cycle() now using pwm_init_state() the call to
pwm_apply_args() can be dropped.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/input/misc/max8997_haptic.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
index 20ff087b8a44..c86966ea0f16 100644
--- a/drivers/input/misc/max8997_haptic.c
+++ b/drivers/input/misc/max8997_haptic.c
@@ -58,8 +58,12 @@ 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.enabled = true;
+		state.period = chip->pwm_period;
+		pwm_set_relative_duty_cycle(&state, chip->level, 100);
+		ret = pwm_apply_state(chip->pwm, &state);
 	} else {
 		int i;
 		u8 duty_index = 0;
@@ -173,14 +177,6 @@ static void max8997_haptic_enable(struct max8997_haptic *chip)
 			goto out;
 		}
 		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);
-				goto out;
-			}
-		}
 		chip->enabled = true;
 	}
 
@@ -293,11 +289,6 @@ static int max8997_haptic_probe(struct platform_device *pdev)
 			goto err_free_mem;
 		}
 
-		/*
-		 * FIXME: pwm_apply_args() should be removed when switching to
-		 * the atomic PWM API.
-		 */
-		pwm_apply_args(chip->pwm);
 		break;
 
 	default:
-- 
2.30.1


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

end of thread, other threads:[~2021-03-22 23:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-16 20:38 [PATCH] input: misc: max8997: Switch to pwm_apply() Uwe Kleine-König
2021-03-21 22:23 ` Dmitry Torokhov
2021-03-22  8:16   ` Uwe Kleine-König
2021-03-22 23:29     ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).