]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: pidff: Factor out code for setting gain
authorTomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Sat, 1 Feb 2025 11:39:01 +0000 (12:39 +0100)
committerJiri Kosina <jkosina@suse.com>
Mon, 3 Feb 2025 14:17:03 +0000 (15:17 +0100)
Makes it possible to easily set gain from inside hid-pidff.c

Changes in v7:
- Check if device gain field exists before setting device gain

Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com>
Reviewed-by: Michał Kopeć <michal@nozomi.space>
Reviewed-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Paul Dino Jones <paul@spacefreak18.xyz>
Tested-by: Cristóferson Bueno <cbueno81@gmail.com>
Tested-by: Pablo Cisneros <patchkez@protonmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/usbhid/hid-pidff.c

index 8a2a4bed2632d50bb3a2b7ee83d7f1c04336558e..a7d9f9b19668cec83a07a6adf714e5d146106a0d 100644 (file)
@@ -539,6 +539,19 @@ static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old)
               effect->u.ramp.end_level != old->u.ramp.end_level;
 }
 
+/*
+ * Set device gain
+ */
+static void pidff_set_gain_report(struct pidff_device *pidff, u16 gain)
+{
+       if (!pidff->device_gain[PID_DEVICE_GAIN_FIELD].field)
+               return;
+
+       pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
+       hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
+                       HID_REQ_SET_REPORT);
+}
+
 /*
  * Clear device control report
  */
@@ -865,11 +878,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
  */
 static void pidff_set_gain(struct input_dev *dev, u16 gain)
 {
-       struct pidff_device *pidff = dev->ff->private;
-
-       pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
-       hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
-                       HID_REQ_SET_REPORT);
+       pidff_set_gain_report(dev->ff->private, gain);
 }
 
 static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
@@ -1404,12 +1413,7 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, __u32 initial_quirks)
        if (error)
                goto fail;
 
-       if (test_bit(FF_GAIN, dev->ffbit)) {
-               pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
-               hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN],
-                                    HID_REQ_SET_REPORT);
-       }
-
+       pidff_set_gain_report(pidff, 0xffff);
        error = pidff_check_autocenter(pidff, dev);
        if (error)
                goto fail;