Skip to content

Commit 48c0687

Browse files
Fenglin Wudtor
authored andcommitted
Input: pm8xxx-vibrator - correct VIB_MAX_LEVELS calculation
The output voltage is inclusive hence the max level calculation is off-by-one-step. Correct it. iWhile we are at it also add a define for the step size instead of using the magic value. Fixes: 11205bb ("Input: add support for pm8xxx based vibrator driver") Signed-off-by: Fenglin Wu <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/20240412-pm8xxx-vibrator-new-design-v10-1-0ec0ad133866@quicinc.com Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent ba2ec9c commit 48c0687

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/input/misc/pm8xxx-vibrator.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
#define VIB_MAX_LEVEL_mV (3100)
1515
#define VIB_MIN_LEVEL_mV (1200)
16-
#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV)
16+
#define VIB_PER_STEP_mV (100)
17+
#define VIB_MAX_LEVELS (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV + VIB_PER_STEP_mV)
1718

1819
#define MAX_FF_SPEED 0xff
1920

@@ -117,10 +118,10 @@ static void pm8xxx_work_handler(struct work_struct *work)
117118
vib->active = true;
118119
vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) +
119120
VIB_MIN_LEVEL_mV;
120-
vib->level /= 100;
121+
vib->level /= VIB_PER_STEP_mV;
121122
} else {
122123
vib->active = false;
123-
vib->level = VIB_MIN_LEVEL_mV / 100;
124+
vib->level = VIB_MIN_LEVEL_mV / VIB_PER_STEP_mV;
124125
}
125126

126127
pm8xxx_vib_set(vib, vib->active);

0 commit comments

Comments
 (0)