]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Input: pm8xxx-vibrator - correct VIB_MAX_LEVELS calculation
authorFenglin Wu <quic_fenglinw@quicinc.com>
Mon, 15 Apr 2024 23:03:40 +0000 (16:03 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:28:43 +0000 (13:28 +0200)
[ Upstream commit 48c0687a322d54ac7e7a685c0b6db78d78f593af ]

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: 11205bb63e5c ("Input: add support for pm8xxx based vibrator driver")
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240412-pm8xxx-vibrator-new-design-v10-1-0ec0ad133866@quicinc.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/input/misc/pm8xxx-vibrator.c

index 53ad25eaf1a289e80aa64cfb97e2818c1df0fcd9..8bfe5c7b1244c319af4d3d1e960d04642d487375 100644 (file)
@@ -14,7 +14,8 @@
 
 #define VIB_MAX_LEVEL_mV       (3100)
 #define VIB_MIN_LEVEL_mV       (1200)
-#define VIB_MAX_LEVELS         (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV)
+#define VIB_PER_STEP_mV                (100)
+#define VIB_MAX_LEVELS         (VIB_MAX_LEVEL_mV - VIB_MIN_LEVEL_mV + VIB_PER_STEP_mV)
 
 #define MAX_FF_SPEED           0xff
 
@@ -118,10 +119,10 @@ static void pm8xxx_work_handler(struct work_struct *work)
                vib->active = true;
                vib->level = ((VIB_MAX_LEVELS * vib->speed) / MAX_FF_SPEED) +
                                                VIB_MIN_LEVEL_mV;
-               vib->level /= 100;
+               vib->level /= VIB_PER_STEP_mV;
        } else {
                vib->active = false;
-               vib->level = VIB_MIN_LEVEL_mV / 100;
+               vib->level = VIB_MIN_LEVEL_mV / VIB_PER_STEP_mV;
        }
 
        pm8xxx_vib_set(vib, vib->active);