Skip to content

Commit f7ebf0b

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Factor out code for setting gain
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>
1 parent 8713107 commit f7ebf0b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

drivers/hid/usbhid/hid-pidff.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ static int pidff_needs_set_ramp(struct ff_effect *effect, struct ff_effect *old)
539539
effect->u.ramp.end_level != old->u.ramp.end_level;
540540
}
541541

542+
/*
543+
* Set device gain
544+
*/
545+
static void pidff_set_gain_report(struct pidff_device *pidff, u16 gain)
546+
{
547+
if (!pidff->device_gain[PID_DEVICE_GAIN_FIELD].field)
548+
return;
549+
550+
pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
551+
hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
552+
HID_REQ_SET_REPORT);
553+
}
554+
542555
/*
543556
* Clear device control report
544557
*/
@@ -865,11 +878,7 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
865878
*/
866879
static void pidff_set_gain(struct input_dev *dev, u16 gain)
867880
{
868-
struct pidff_device *pidff = dev->ff->private;
869-
870-
pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
871-
hid_hw_request(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
872-
HID_REQ_SET_REPORT);
881+
pidff_set_gain_report(dev->ff->private, gain);
873882
}
874883

875884
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)
14041413
if (error)
14051414
goto fail;
14061415

1407-
if (test_bit(FF_GAIN, dev->ffbit)) {
1408-
pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1409-
hid_hw_request(hid, pidff->reports[PID_DEVICE_GAIN],
1410-
HID_REQ_SET_REPORT);
1411-
}
1412-
1416+
pidff_set_gain_report(pidff, 0xffff);
14131417
error = pidff_check_autocenter(pidff, dev);
14141418
if (error)
14151419
goto fail;

0 commit comments

Comments
 (0)