Skip to content

Commit 5d98079

Browse files
LawstorantJiri Kosina
authored andcommitted
HID: pidff: Factor out pool report fetch and remove excess declaration
We only want to refetch the pool report during device init. Reset function is now called when uploading effects to an empty device so extract pool fetch to separate function and call it from init before autocenter check (autocenter check triggered reset during init). Remove a superfluous pointer declaration and assigment as well. 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 2175516 commit 5d98079

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

drivers/hid/usbhid/hid-pidff.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -591,36 +591,39 @@ static void pidff_modify_actuators_state(struct pidff_device *pidff, bool enable
591591

592592
/*
593593
* Reset the device, stop all effects, enable actuators
594-
* Refetch pool report
595594
*/
596595
static void pidff_reset(struct pidff_device *pidff)
597596
{
598-
int i = 0;
599-
600597
/* We reset twice as sometimes hid_wait_io isn't waiting long enough */
601598
pidff_send_device_control(pidff, PID_RESET);
602599
pidff_send_device_control(pidff, PID_RESET);
603600
pidff->effect_count = 0;
604601

605602
pidff_send_device_control(pidff, PID_STOP_ALL_EFFECTS);
606603
pidff_modify_actuators_state(pidff, 1);
604+
}
607605

608-
/* pool report is sometimes messed up, refetch it */
609-
hid_hw_request(pidff->hid, pidff->reports[PID_POOL], HID_REQ_GET_REPORT);
610-
hid_hw_wait(pidff->hid);
606+
/*
607+
* Refetch pool report
608+
*/
609+
static void pidff_fetch_pool(struct pidff_device *pidff)
610+
{
611+
if (!pidff->pool[PID_SIMULTANEOUS_MAX].value)
612+
return;
611613

612-
if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
613-
while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
614-
if (i++ > 20) {
615-
hid_warn(pidff->hid,
616-
"device reports %d simultaneous effects\n",
617-
pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
618-
break;
619-
}
620-
hid_dbg(pidff->hid, "pid_pool requested again\n");
621-
hid_hw_request(pidff->hid, pidff->reports[PID_POOL],
622-
HID_REQ_GET_REPORT);
623-
hid_hw_wait(pidff->hid);
614+
int i = 0;
615+
while (pidff->pool[PID_SIMULTANEOUS_MAX].value[0] < 2) {
616+
hid_dbg(pidff->hid, "pid_pool requested again\n");
617+
hid_hw_request(pidff->hid, pidff->reports[PID_POOL],
618+
HID_REQ_GET_REPORT);
619+
hid_hw_wait(pidff->hid);
620+
621+
/* break after 20 tries with SIMULTANEOUS_MAX < 2 */
622+
if (i++ > 20) {
623+
hid_warn(pidff->hid,
624+
"device reports %d simultaneous effects\n",
625+
pidff->pool[PID_SIMULTANEOUS_MAX].value[0]);
626+
break;
624627
}
625628
}
626629
}
@@ -916,9 +919,7 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
916919
*/
917920
static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude)
918921
{
919-
struct pidff_device *pidff = dev->ff->private;
920-
921-
pidff_autocenter(pidff, magnitude);
922+
pidff_autocenter(dev->ff->private, magnitude);
922923
}
923924

924925
/*
@@ -1424,6 +1425,8 @@ int hid_pidff_init_with_quirks(struct hid_device *hid, u32 initial_quirks)
14241425
if (error)
14251426
goto fail;
14261427

1428+
/* pool report is sometimes messed up, refetch it */
1429+
pidff_fetch_pool(pidff);
14271430
pidff_set_gain_report(pidff, U16_MAX);
14281431
error = pidff_check_autocenter(pidff, dev);
14291432
if (error)

0 commit comments

Comments
 (0)