Skip to content

Commit b0dbd97

Browse files
jwrdegoedeandy-shev
authored andcommitted
platform/x86: asus-wmi: Add support for SW_TABLET_MODE
On Asus 2-in-1s with a detachable keyboard the Asus WMI interface reports if the tablet is attached to the keyboard or not. Report if the 2-in-1 is in tablet or clamshell mode to userspace by reporting SW_TABLET_MODE events to userspace. This has been tested on a T100TA, T100CHI, T100HA and T200TA. Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]>
1 parent fed5003 commit b0dbd97

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

drivers/platform/x86/asus-wmi.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ MODULE_LICENSE("GPL");
5757
#define NOTIFY_BRNDOWN_MIN 0x20
5858
#define NOTIFY_BRNDOWN_MAX 0x2e
5959
#define NOTIFY_FNLOCK_TOGGLE 0x4e
60+
#define NOTIFY_KBD_DOCK_CHANGE 0x75
6061
#define NOTIFY_KBD_BRTUP 0xc4
6162
#define NOTIFY_KBD_BRTDWN 0xc5
6263
#define NOTIFY_KBD_BRTTOGGLE 0xc7
@@ -346,7 +347,7 @@ static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id)
346347

347348
static int asus_wmi_input_init(struct asus_wmi *asus)
348349
{
349-
int err;
350+
int err, result;
350351

351352
asus->inputdev = input_allocate_device();
352353
if (!asus->inputdev)
@@ -362,6 +363,14 @@ static int asus_wmi_input_init(struct asus_wmi *asus)
362363
if (err)
363364
goto err_free_dev;
364365

366+
result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_DOCK);
367+
if (result >= 0) {
368+
input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
369+
input_report_switch(asus->inputdev, SW_TABLET_MODE, !result);
370+
} else if (result != -ENODEV) {
371+
pr_err("Error checking for keyboard-dock: %d\n", result);
372+
}
373+
365374
err = input_register_device(asus->inputdev);
366375
if (err)
367376
goto err_free_dev;
@@ -2055,9 +2064,9 @@ static int asus_wmi_get_event_code(u32 value)
20552064

20562065
static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
20572066
{
2058-
int orig_code;
20592067
unsigned int key_value = 1;
20602068
bool autorelease = 1;
2069+
int result, orig_code;
20612070

20622071
orig_code = code;
20632072

@@ -2102,6 +2111,17 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
21022111
return;
21032112
}
21042113

2114+
if (code == NOTIFY_KBD_DOCK_CHANGE) {
2115+
result = asus_wmi_get_devstate_simple(asus,
2116+
ASUS_WMI_DEVID_KBD_DOCK);
2117+
if (result >= 0) {
2118+
input_report_switch(asus->inputdev, SW_TABLET_MODE,
2119+
!result);
2120+
input_sync(asus->inputdev);
2121+
}
2122+
return;
2123+
}
2124+
21052125
if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) {
21062126
fan_boost_mode_switch_next(asus);
21072127
return;

include/linux/platform_data/x86/asus-wmi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
/* Maximum charging percentage */
8686
#define ASUS_WMI_DEVID_RSOC 0x00120057
8787

88+
/* Keyboard dock */
89+
#define ASUS_WMI_DEVID_KBD_DOCK 0x00120063
90+
8891
/* DSTS masks */
8992
#define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
9093
#define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002

0 commit comments

Comments
 (0)