mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
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 <bentiss@kernel.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Link: https://patch.msgid.link/Zx_hBvg5Qa3KU3ta@google.com Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
This commit is contained in:
parent
0951fede4e
commit
e8a0581914
@ -31,6 +31,7 @@
|
|||||||
* [1] https://gitlab.freedesktop.org/libevdev/hid-tools
|
* [1] https://gitlab.freedesktop.org/libevdev/hid-tools
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/bits.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/hid.h>
|
#include <linux/hid.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
@ -83,6 +84,13 @@ enum latency_mode {
|
|||||||
HID_LATENCY_HIGH = 1,
|
HID_LATENCY_HIGH = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum report_mode {
|
||||||
|
TOUCHPAD_REPORT_NONE = 0,
|
||||||
|
TOUCHPAD_REPORT_BUTTONS = BIT(0),
|
||||||
|
TOUCHPAD_REPORT_CONTACTS = BIT(1),
|
||||||
|
TOUCHPAD_REPORT_ALL = TOUCHPAD_REPORT_BUTTONS | TOUCHPAD_REPORT_CONTACTS,
|
||||||
|
};
|
||||||
|
|
||||||
#define MT_IO_FLAGS_RUNNING 0
|
#define MT_IO_FLAGS_RUNNING 0
|
||||||
#define MT_IO_FLAGS_ACTIVE_SLOTS 1
|
#define MT_IO_FLAGS_ACTIVE_SLOTS 1
|
||||||
#define MT_IO_FLAGS_PENDING_SLOTS 2
|
#define MT_IO_FLAGS_PENDING_SLOTS 2
|
||||||
@ -1493,8 +1501,7 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
|
|||||||
struct hid_field *field,
|
struct hid_field *field,
|
||||||
struct hid_usage *usage,
|
struct hid_usage *usage,
|
||||||
enum latency_mode latency,
|
enum latency_mode latency,
|
||||||
bool surface_switch,
|
enum report_mode report_mode,
|
||||||
bool button_switch,
|
|
||||||
bool *inputmode_found)
|
bool *inputmode_found)
|
||||||
{
|
{
|
||||||
struct mt_device *td = hid_get_drvdata(hdev);
|
struct mt_device *td = hid_get_drvdata(hdev);
|
||||||
@ -1549,11 +1556,11 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HID_DG_SURFACESWITCH:
|
case HID_DG_SURFACESWITCH:
|
||||||
field->value[index] = surface_switch;
|
field->value[index] = !!(report_mode & TOUCHPAD_REPORT_CONTACTS);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case HID_DG_BUTTONSWITCH:
|
case HID_DG_BUTTONSWITCH:
|
||||||
field->value[index] = button_switch;
|
field->value[index] = !!(report_mode & TOUCHPAD_REPORT_BUTTONS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1561,7 +1568,7 @@ static bool mt_need_to_apply_feature(struct hid_device *hdev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
|
static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
|
||||||
bool surface_switch, bool button_switch)
|
enum report_mode report_mode)
|
||||||
{
|
{
|
||||||
struct hid_report_enum *rep_enum;
|
struct hid_report_enum *rep_enum;
|
||||||
struct hid_report *rep;
|
struct hid_report *rep;
|
||||||
@ -1586,8 +1593,7 @@ static void mt_set_modes(struct hid_device *hdev, enum latency_mode latency,
|
|||||||
rep->field[i],
|
rep->field[i],
|
||||||
usage,
|
usage,
|
||||||
latency,
|
latency,
|
||||||
surface_switch,
|
report_mode,
|
||||||
button_switch,
|
|
||||||
&inputmode_found))
|
&inputmode_found))
|
||||||
update_report = true;
|
update_report = true;
|
||||||
}
|
}
|
||||||
@ -1830,7 +1836,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
|||||||
dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
|
dev_warn(&hdev->dev, "Cannot allocate sysfs group for %s\n",
|
||||||
hdev->name);
|
hdev->name);
|
||||||
|
|
||||||
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
|
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1842,9 +1848,9 @@ static int mt_suspend(struct hid_device *hdev, pm_message_t state)
|
|||||||
/* High latency is desirable for power savings during S3/S0ix */
|
/* High latency is desirable for power savings during S3/S0ix */
|
||||||
if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
|
if ((td->mtclass.quirks & MT_QUIRK_DISABLE_WAKEUP) ||
|
||||||
!hid_hw_may_wakeup(hdev))
|
!hid_hw_may_wakeup(hdev))
|
||||||
mt_set_modes(hdev, HID_LATENCY_HIGH, false, false);
|
mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE);
|
||||||
else
|
else
|
||||||
mt_set_modes(hdev, HID_LATENCY_HIGH, true, true);
|
mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_ALL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1852,7 +1858,7 @@ static int mt_suspend(struct hid_device *hdev, pm_message_t state)
|
|||||||
static int mt_reset_resume(struct hid_device *hdev)
|
static int mt_reset_resume(struct hid_device *hdev)
|
||||||
{
|
{
|
||||||
mt_release_contacts(hdev);
|
mt_release_contacts(hdev);
|
||||||
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
|
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1864,7 +1870,7 @@ static int mt_resume(struct hid_device *hdev)
|
|||||||
|
|
||||||
hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
|
hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE);
|
||||||
|
|
||||||
mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true);
|
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user