Commit 3cb6dcfa authored by Axel Lin's avatar Axel Lin Committed by Dmitry Torokhov

Input: regulator-haptic - simplify code

All the use cases in this driver has a regulator_haptic_toggle() call after
regulator_haptic_set_voltage(). So make regulator_haptic_set_voltage() call
regulator_haptic_toggle() to simplify the code.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent f17effbe
...@@ -76,6 +76,8 @@ static int regulator_haptic_set_voltage(struct regulator_haptic *haptic, ...@@ -76,6 +76,8 @@ static int regulator_haptic_set_voltage(struct regulator_haptic *haptic,
return error; return error;
} }
regulator_haptic_toggle(haptic, !!magnitude);
return 0; return 0;
} }
...@@ -83,23 +85,12 @@ static void regulator_haptic_work(struct work_struct *work) ...@@ -83,23 +85,12 @@ static void regulator_haptic_work(struct work_struct *work)
{ {
struct regulator_haptic *haptic = container_of(work, struct regulator_haptic *haptic = container_of(work,
struct regulator_haptic, work); struct regulator_haptic, work);
unsigned int magnitude;
int error;
mutex_lock(&haptic->mutex); mutex_lock(&haptic->mutex);
if (haptic->suspended) if (!haptic->suspended)
goto out; regulator_haptic_set_voltage(haptic, haptic->magnitude);
magnitude = ACCESS_ONCE(haptic->magnitude);
error = regulator_haptic_set_voltage(haptic, magnitude);
if (error)
goto out;
regulator_haptic_toggle(haptic, magnitude != 0);
out:
mutex_unlock(&haptic->mutex); mutex_unlock(&haptic->mutex);
} }
...@@ -123,7 +114,6 @@ static void regulator_haptic_close(struct input_dev *input) ...@@ -123,7 +114,6 @@ static void regulator_haptic_close(struct input_dev *input)
cancel_work_sync(&haptic->work); cancel_work_sync(&haptic->work);
regulator_haptic_set_voltage(haptic, 0); regulator_haptic_set_voltage(haptic, 0);
regulator_haptic_toggle(haptic, false);
} }
static int __maybe_unused static int __maybe_unused
...@@ -225,7 +215,6 @@ static int __maybe_unused regulator_haptic_suspend(struct device *dev) ...@@ -225,7 +215,6 @@ static int __maybe_unused regulator_haptic_suspend(struct device *dev)
return error; return error;
regulator_haptic_set_voltage(haptic, 0); regulator_haptic_set_voltage(haptic, 0);
regulator_haptic_toggle(haptic, false);
haptic->suspended = true; haptic->suspended = true;
...@@ -245,10 +234,8 @@ static int __maybe_unused regulator_haptic_resume(struct device *dev) ...@@ -245,10 +234,8 @@ static int __maybe_unused regulator_haptic_resume(struct device *dev)
haptic->suspended = false; haptic->suspended = false;
magnitude = ACCESS_ONCE(haptic->magnitude); magnitude = ACCESS_ONCE(haptic->magnitude);
if (magnitude) { if (magnitude)
regulator_haptic_set_voltage(haptic, magnitude); regulator_haptic_set_voltage(haptic, magnitude);
regulator_haptic_toggle(haptic, true);
}
mutex_unlock(&haptic->mutex); mutex_unlock(&haptic->mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment