Skip to content

Commit 61c6fef

Browse files
ukleinekdtor
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 1c44b81 commit 61c6fef

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

drivers/input/misc/max77693-haptic.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ struct max77693_haptic {
6868

6969
static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
7070
{
71-
struct pwm_args pargs;
72-
int delta;
71+
struct pwm_state state;
7372
int error;
7473

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);
7878
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);
8081
return error;
8182
}
8283

@@ -166,12 +167,17 @@ static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable)
166167

167168
static void max77693_haptic_enable(struct max77693_haptic *haptic)
168169
{
170+
struct pwm_state state;
169171
int error;
170172

171173
if (haptic->enabled)
172174
return;
173175

174-
error = pwm_enable(haptic->pwm_dev);
176+
pwm_init_state(haptic->pwm_dev, &state);
177+
state.duty_cycle = (state.period + haptic->pwm_duty) / 2;
178+
state.enabled = true;
179+
180+
error = pwm_apply_might_sleep(haptic->pwm_dev, &state);
175181
if (error) {
176182
dev_err(haptic->dev,
177183
"failed to enable haptic pwm device: %d\n", error);
@@ -224,18 +230,13 @@ static void max77693_haptic_play_work(struct work_struct *work)
224230
{
225231
struct max77693_haptic *haptic =
226232
container_of(work, struct max77693_haptic, work);
227-
int error;
228-
229-
error = max77693_haptic_set_duty_cycle(haptic);
230-
if (error) {
231-
dev_err(haptic->dev, "failed to set duty cycle: %d\n", error);
232-
return;
233-
}
234233

235-
if (haptic->magnitude)
236-
max77693_haptic_enable(haptic);
237-
else
234+
if (!haptic->magnitude)
238235
max77693_haptic_disable(haptic);
236+
else if (haptic->enabled)
237+
max77693_haptic_set_duty_cycle(haptic);
238+
else
239+
max77693_haptic_enable(haptic);
239240
}
240241

241242
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)
340341
return PTR_ERR(haptic->pwm_dev);
341342
}
342343

343-
/*
344-
* FIXME: pwm_apply_args() should be removed when switching to the
345-
* atomic PWM API.
346-
*/
347-
pwm_apply_args(haptic->pwm_dev);
348-
349344
haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic");
350345
if (IS_ERR(haptic->motor_reg)) {
351346
dev_err(&pdev->dev, "failed to get regulator\n");

0 commit comments

Comments
 (0)