diff mbox series

[v10,1/4] input: pm8xxx-vibrator: correct VIB_MAX_LEVELS calculation

Message ID 20240412-pm8xxx-vibrator-new-design-v10-1-0ec0ad133866@quicinc.com
State New
Headers show
Series Add support for vibrator in multiple PMICs | expand

Commit Message

Fenglin Wu via B4 Relay April 12, 2024, 12:36 p.m. UTC
From: Fenglin Wu <quic_fenglinw@quicinc.com>

The output voltage is inclusive hence the max level calculation is
off-by-one-step. Correct it.

Fixes: 11205bb63e5c ("Input: add support for pm8xxx based vibrator driver")
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
---
 drivers/input/misc/pm8xxx-vibrator.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Dmitry Torokhov April 15, 2024, 11:30 p.m. UTC | #1
On Fri, Apr 12, 2024 at 07:21:16PM +0300, Dmitry Baryshkov wrote:
> On Fri, 12 Apr 2024 at 15:36, Fenglin Wu via B4 Relay
> <devnull+quic_fenglinw.quicinc.com@kernel.org> wrote:
> >
> > From: Fenglin Wu <quic_fenglinw@quicinc.com>
> >
> > The output voltage is inclusive hence the max level calculation is
> > off-by-one-step. Correct it.
> 
> ... while we are at it also add a define for the step size instead of
> using the magic value.

I adjusted the patch description as Dmitry suggested, and applied this
patch. Please address Konrad's feedback on the other 2 and I will apply
the rest.

Thank you.
diff mbox series

Patch

diff --git a/drivers/input/misc/pm8xxx-vibrator.c b/drivers/input/misc/pm8xxx-vibrator.c
index 04cb87efd799..844ca7e1f59f 100644
--- a/drivers/input/misc/pm8xxx-vibrator.c
+++ b/drivers/input/misc/pm8xxx-vibrator.c
@@ -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);