Skip to content

Commit 13120ab

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Reduce PID_EFFECT_OPERATION spam
Keep track of effect's loop_count to reduce the spam of ffb play commands coming from some games. This should speed up normal magnitude etc updates and slightly increase max possible FFB refresh rate. Helps games like Dirt Rally 2.0, F1 2023, WRC from KT Signed-off-by: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 5b9cae8 commit 13120ab

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

drivers/hid/usbhid/hid-pidff.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ struct pidff_usage {
184184
s32 *value;
185185
};
186186

187+
struct pidff_effect {
188+
int pid_id;
189+
int is_infinite;
190+
unsigned int loop_count;
191+
};
192+
187193
struct pidff_device {
188194
struct hid_device *hid;
189195

@@ -202,6 +208,8 @@ struct pidff_device {
202208
struct pidff_usage effect_operation[ARRAY_SIZE(pidff_effect_operation)];
203209
struct pidff_usage block_free[ARRAY_SIZE(pidff_block_free)];
204210

211+
struct pidff_effect effect[PID_EFFECTS_MAX];
212+
205213
/*
206214
* Special field is a field that is not composed of
207215
* usage<->value pairs that pidff_usage values are
@@ -230,8 +238,6 @@ struct pidff_device {
230238
int operation_id[ARRAY_SIZE(pidff_effect_operation_status)];
231239
int direction_axis_id[ARRAY_SIZE(pidff_direction_axis)];
232240

233-
int pid_id[PID_EFFECTS_MAX];
234-
235241
u32 quirks;
236242
u8 effect_count;
237243
u8 axis_count;
@@ -798,6 +804,12 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
798804
return -EIO;
799805
}
800806

807+
static int pidff_needs_playback(struct pidff_device *pidff, int effect_id, int n)
808+
{
809+
return pidff->effect[effect_id].is_infinite ||
810+
pidff->effect[effect_id].loop_count != n;
811+
}
812+
801813
/*
802814
* Play the effect with PID id n times
803815
*/
@@ -829,9 +841,14 @@ static int pidff_playback(struct input_dev *dev, int effect_id, int value)
829841
{
830842
struct pidff_device *pidff = dev->ff->private;
831843

844+
if (!pidff_needs_playback(pidff, effect_id, value))
845+
return 0;
846+
832847
hid_dbg(pidff->hid, "requesting %s on FF effect %d",
833848
value == 0 ? "stop" : "playback", effect_id);
834-
pidff_playback_pid(pidff, pidff->pid_id[effect_id], value);
849+
850+
pidff->effect[effect_id].loop_count = value;
851+
pidff_playback_pid(pidff, pidff->effect[effect_id].pid_id, value);
835852
return 0;
836853
}
837854

@@ -852,10 +869,9 @@ static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
852869
static int pidff_erase_effect(struct input_dev *dev, int effect_id)
853870
{
854871
struct pidff_device *pidff = dev->ff->private;
855-
int pid_id = pidff->pid_id[effect_id];
872+
int pid_id = pidff->effect[effect_id].pid_id;
856873

857-
hid_dbg(pidff->hid, "starting to erase %d/%d\n", effect_id,
858-
pidff->pid_id[effect_id]);
874+
hid_dbg(pidff->hid, "starting to erase %d/%d\n", effect_id, pid_id);
859875

860876
/*
861877
* Wait for the queue to clear. We do not want
@@ -906,12 +922,16 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *new,
906922

907923
pidff->effect_count++;
908924
hid_dbg(pidff->hid, "current effect count: %d", pidff->effect_count);
909-
pidff->pid_id[new->id] =
925+
pidff->effect[new->id].loop_count = 0;
926+
pidff->effect[new->id].pid_id =
910927
pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
911928
}
912929

930+
pidff->effect[new->id].is_infinite =
931+
pidff_is_duration_infinite(new->replay.length);
932+
913933
pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] =
914-
pidff->pid_id[new->id];
934+
pidff->effect[new->id].pid_id;
915935

916936
PIDFF_SET_REPORT_IF_NEEDED(effect, new, old);
917937
switch (new->type) {

0 commit comments

Comments
 (0)