Skip to content

Commit 4724b19

Browse files
committed
HID: multitouch: make mt_set_mode() less cryptic
JIRA: https://issues.redhat.com/browse/RHEL-101770 Upstream Status: since v6.13 Tested: with the hid-tools test suite and some hardware commit e8a0581 Author: Dmitry Torokhov <[email protected]> Date: Mon Oct 28 12:07:50 2024 -0700 HID: multitouch: make mt_set_mode() less cryptic mt_set_mode() accepts 2 boolean switches indicating whether the device (if it follows Windows Precision Touchpad specification) should report hardware buttons and/or surface contacts. For a casual reader it is completely not clear, as they look at the call site, which exact mode is being requested. Define report_mode enum and change mt_set_mode() to accept is as an argument instead. This allows to write: mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL); or mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_BUTTONS); which makes intent much more clear. Reviewed-by: Benjamin Tissoires <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 96c7229 commit 4724b19

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

drivers/hid/hid-multitouch.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* [1] https://gitlab.freedesktop.org/libevdev/hid-tools
3232
*/
3333

34+
#include <linux/bits.h>
3435
#include <linux/device.h>
3536
#include <linux/hid.h>
3637
#include <linux/module.h>
@@ -83,6 +84,13 @@ enum latency_mode {
8384
HID_LATENCY_HIGH = 1,
8485
};
8586

87+
enum report_mode {
88+
TOUCHPAD_REPORT_NONE = 0,
89+
TOUCHPAD_REPORT_BUTTONS = BIT(0),
90+
TOUCHPAD_REPORT_CONTACTS = BIT(1),
91+
TOUCHPAD_REPORT_ALL = TOUCHPAD_REPORT_BUTTONS | TOUCHPAD_REPORT_CONTACTS,
92+
};
93+
8694
#define MT_IO_FLAGS_RUNNING 0
8795
#define MT_IO_FLAGS_ACTIVE_SLOTS 1
8896
#define MT_IO_FLAGS_PENDING_SLOTS 2
@@ -1493,8 +1501,7 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
14931501
struct hid_field *field,
14941502
struct hid_usage *usage,
14951503
enum latency_mode latency,
1496-
bool surface_switch,
1497-
bool button_switch,
1504+
enum report_mode report_mode,
14981505
bool *inputmode_found)
14991506
{
15001507
struct mt_device *td = hid_get_drvdata(hdev);
@@ -1549,19 +1556,19 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
15491556
return true;
15501557

15511558
case HID_DG_SURFACESWITCH:
1552-
field->value[index] = surface_switch;
1559+
field->value[index] = !!(report_mode & TOUCHPAD_REPORT_CONTACTS);
15531560
return true;
15541561

15551562
case HID_DG_BUTTONSWITCH:
1556-
field->value[index] = button_switch;
1563+
field->value[index] = !!(report_mode & TOUCHPAD_REPORT_BUTTONS);
15571564
return true;
15581565
}
15591566

15601567
return false; /* no need to update the report */
15611568
}
15621569

15631570
static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
1564-
bool surface_switch, bool button_switch)
1571+
enum report_mode report_mode)
15651572
{
15661573
struct hid_report_enum *rep_enum;
15671574
struct hid_report *rep;
@@ -1586,8 +1593,7 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
15861593
rep->field[i],
15871594
usage,
15881595
latency,
1589-
surface_switch,
1590-
button_switch,
1596+
report_mode,
15911597
&inputmode_found))
15921598
update_report = true;
15931599
}
@@ -1830,7 +1836,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
18301836
dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
18311837
hdev->name);
18321838

1833-
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1839+
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
18341840

18351841
return 0;
18361842
}
@@ -1842,17 +1848,17 @@ static int mt_suspend(struct hid_device *hdev, pm_message_t state)
18421848
/* High latency is desirable for power savings during S3/S0ix */
18431849
if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
18441850
!hid_hw_may_wakeup(hdev))
1845-
mt_set_modes(hdev, HID_LATENCY_HIGH, false, false);
1851+
mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
18461852
else
1847-
mt_set_modes(hdev, HID_LATENCY_HIGH, true, true);
1853+
mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_ALL);
18481854

18491855
return 0;
18501856
}
18511857

18521858
static int mt_reset_resume(struct hid_device *hdev)
18531859
{
18541860
mt_release_contacts(hdev);
1855-
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1861+
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
18561862
return 0;
18571863
}
18581864

@@ -1864,7 +1870,7 @@ static int mt_resume(struct hid_device *hdev)
18641870

18651871
hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
18661872

1867-
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
1873+
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
18681874

18691875
return 0;
18701876
}

0 commit comments

Comments
 (0)