]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: aw86927 - respect vibration magnitude levels
authorGriffin Kroah-Hartman <griffin.kroah@fairphone.com>
Wed, 4 Mar 2026 01:37:18 +0000 (17:37 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 1 Apr 2026 16:08:32 +0000 (09:08 -0700)
Previously the gain value was hardcoded. Take the magnitude passed via
the input API and configure the gain register accordingly.

Signed-off-by: Griffin Kroah-Hartman <griffin.kroah@fairphone.com>
Link: https://patch.msgid.link/20260302-aw86938-driver-v4-1-92c865df9cca@fairphone.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/misc/aw86927.c

index 8ad361239cfe3a888628b15e4dbdeed0c9ca3d1a..454e1af23df05d041ef20f6a27fd895a30e10ccd 100644 (file)
@@ -180,7 +180,7 @@ struct aw86927_data {
        struct i2c_client *client;
        struct regmap *regmap;
        struct gpio_desc *reset_gpio;
-       bool running;
+       u16 level;
 };
 
 static const struct regmap_config aw86927_regmap_config = {
@@ -325,11 +325,12 @@ static int aw86927_haptics_play(struct input_dev *dev, void *data, struct ff_eff
        if (!level)
                level = effect->u.rumble.weak_magnitude;
 
-       /* If already running, don't restart playback */
-       if (haptics->running && level)
+       /* If level does not change, don't restart playback */
+       if (haptics->level == level)
                return 0;
 
-       haptics->running = level;
+       haptics->level = level;
+
        schedule_work(&haptics->play_work);
 
        return 0;
@@ -376,8 +377,7 @@ static int aw86927_play_sine(struct aw86927_data *haptics)
        if (err)
                return err;
 
-       /* set gain to value lower than 0x80 to avoid distorted playback */
-       err = regmap_write(haptics->regmap, AW86927_PLAYCFG2_REG, 0x7c);
+       err = regmap_write(haptics->regmap, AW86927_PLAYCFG2_REG, haptics->level * 0x80 / 0xffff);
        if (err)
                return err;
 
@@ -409,7 +409,7 @@ static void aw86927_haptics_play_work(struct work_struct *work)
        struct device *dev = &haptics->client->dev;
        int err;
 
-       if (haptics->running)
+       if (haptics->level)
                err = aw86927_play_sine(haptics);
        else
                err = aw86927_stop(haptics);