Input: drv260x - fix magnitude handling
authorLuca Weiss <luca@z3ntu.xyz>
Tue, 2 May 2023 00:02:56 +0000 (17:02 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 2 May 2023 00:07:12 +0000 (17:07 -0700)
commitd09dbc7a018c4d479d7ab0d3b4f6a3211b110923
treed7be4a92554f7f6fa5a4e3d168cba17118d48ed6
parent980626ec1ca82a10dc04026a79dcbade23cc3438
Input: drv260x - fix magnitude handling

First of all, previously the 16-bit magnitude was written as-is to the
device which actually discarded the upper 8 bits since the device has
8-bit registers only. This meant that a strong_magnitude of 0xFF00 would
result in 0. To correct this shift the strong_magnitude / weak_magnitude
input values so we discard the lower 8 bits and keep the upper bits
instead.

Secondly the RTP mode that is used by default interprets the values as
signed (2s complement), so 0x81 = 0%, 0x00 = 50%, 0x7F = 100%. This
doesn't match the FF_RUMBLE interface at all, so let's tell the device
to interpret the data as unsigned instead which gets us 0x00 = 0% and
0xFF = 100%.

As last change switch ERM to using "Closed-Loop Mode, Unidirectional"
instead of "Open-Loop Mode" since it's recommended by the datasheet
compared to open loop and better matches our use case of 0% - 100%
vibration.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lore.kernel.org/r/20230430-drv260x-improvements-v1-4-1fb28b4cc698@z3ntu.xyz
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/drv260x.c