Skip to content

Commit 153cca9

Browse files
committed
platform/x86: Add and use a dual_accel_detect() helper
Various 360 degree hinges (yoga) style 2-in-1 devices use 2 accelerometers to allow the OS to determine the angle between the display and the base of the device. On Windows these are read by a special HingeAngleService process which calls undocumented ACPI methods, to let the firmware know if the 2-in-1 is in tablet- or laptop-mode. The firmware may use this to disable the kbd and touchpad to avoid spurious input in tablet-mode as well as to report SW_TABLET_MODE info to the OS. Since Linux does not call these undocumented methods, the SW_TABLET_MODE info reported by various pdx86 drivers is incorrect on these devices. Before this commit the intel-hid and thinkpad_acpi code already had 2 hardcoded checks for ACPI hardware-ids of dual-accel sensors to avoid reporting broken info. And now we also have a bug-report about the same problem in the intel-vbtn code. Since there are at least 3 different ACPI hardware-ids in play, add a new dual_accel_detect() helper which checks for all 3, rather then adding different hardware-ids to the drivers as bug-reports trickle in. Having shared code which checks all known hardware-ids is esp. important for the intel-hid and intel-vbtn drivers as these are generic drivers which are used on a lot of devices. The BOSC0200 hardware-id requires special handling, because often it is used for a single-accelerometer setup. Only in a few cases it refers to a dual-accel setup, in which case there will be 2 I2cSerialBus resources in the device's resource-list, so the helper checks for this. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=209011 Reported-and-tested-by: Julius Lehmann <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2b2c66f commit 153cca9

File tree

5 files changed

+101
-19
lines changed

5 files changed

+101
-19
lines changed

drivers/platform/x86/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ config THINKPAD_ACPI
508508
depends on RFKILL || RFKILL = n
509509
depends on ACPI_VIDEO || ACPI_VIDEO = n
510510
depends on BACKLIGHT_CLASS_DEVICE
511+
depends on I2C
511512
select ACPI_PLATFORM_PROFILE
512513
select HWMON
513514
select NVRAM
@@ -691,6 +692,7 @@ config INTEL_HID_EVENT
691692
tristate "INTEL HID Event"
692693
depends on ACPI
693694
depends on INPUT
695+
depends on I2C
694696
select INPUT_SPARSEKMAP
695697
help
696698
This driver provides support for the Intel HID Event hotkey interface.
@@ -742,6 +744,7 @@ config INTEL_VBTN
742744
tristate "INTEL VIRTUAL BUTTON"
743745
depends on ACPI
744746
depends on INPUT
747+
depends on I2C
745748
select INPUT_SPARSEKMAP
746749
help
747750
This driver provides support for the Intel Virtual Button interface.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Helper code to detect 360 degree hinges (yoga) style 2-in-1 devices using 2 accelerometers
4+
* to allow the OS to determine the angle between the display and the base of the device.
5+
*
6+
* On Windows these are read by a special HingeAngleService process which calls undocumented
7+
* ACPI methods, to let the firmware know if the 2-in-1 is in tablet- or laptop-mode.
8+
* The firmware may use this to disable the kbd and touchpad to avoid spurious input in
9+
* tablet-mode as well as to report SW_TABLET_MODE info to the OS.
10+
*
11+
* Since Linux does not call these undocumented methods, the SW_TABLET_MODE info reported
12+
* by various drivers/platform/x86 drivers is incorrect. These drivers use the detection
13+
* code in this file to disable SW_TABLET_MODE reporting to avoid reporting broken info
14+
* (instead userspace can derive the status itself by directly reading the 2 accels).
15+
*/
16+
17+
#include <linux/acpi.h>
18+
#include <linux/i2c.h>
19+
20+
static int dual_accel_i2c_resource_count(struct acpi_resource *ares, void *data)
21+
{
22+
struct acpi_resource_i2c_serialbus *sb;
23+
int *count = data;
24+
25+
if (i2c_acpi_get_i2c_resource(ares, &sb))
26+
*count = *count + 1;
27+
28+
return 1;
29+
}
30+
31+
static int dual_accel_i2c_client_count(struct acpi_device *adev)
32+
{
33+
int ret, count = 0;
34+
LIST_HEAD(r);
35+
36+
ret = acpi_dev_get_resources(adev, &r, dual_accel_i2c_resource_count, &count);
37+
if (ret < 0)
38+
return ret;
39+
40+
acpi_dev_free_resource_list(&r);
41+
return count;
42+
}
43+
44+
static bool dual_accel_detect_bosc0200(void)
45+
{
46+
struct acpi_device *adev;
47+
int count;
48+
49+
adev = acpi_dev_get_first_match_dev("BOSC0200", NULL, -1);
50+
if (!adev)
51+
return false;
52+
53+
count = dual_accel_i2c_client_count(adev);
54+
55+
acpi_dev_put(adev);
56+
57+
return count == 2;
58+
}
59+
60+
static bool dual_accel_detect(void)
61+
{
62+
/* Systems which use a pair of accels with KIOX010A / KIOX020A ACPI ids */
63+
if (acpi_dev_present("KIOX010A", NULL, -1))
64+
return true;
65+
66+
/* Systems which use a single DUAL250E ACPI device to model 2 accels */
67+
if (acpi_dev_present("DUAL250E", NULL, -1))
68+
return true;
69+
70+
/* Systems which use a single BOSC0200 ACPI device to model 2 accels */
71+
if (dual_accel_detect_bosc0200())
72+
return true;
73+
74+
return false;
75+
}

drivers/platform/x86/intel-hid.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/module.h>
1515
#include <linux/platform_device.h>
1616
#include <linux/suspend.h>
17+
#include "dual_accel_detect.h"
1718

1819
/* When NOT in tablet mode, VGBS returns with the flag 0x40 */
1920
#define TABLET_MODE_FLAG BIT(6)
@@ -122,6 +123,7 @@ struct intel_hid_priv {
122123
struct input_dev *array;
123124
struct input_dev *switches;
124125
bool wakeup_mode;
126+
bool dual_accel;
125127
};
126128

127129
#define HID_EVENT_FILTER_UUID "eeec56b3-4442-408f-a792-4edd4d758054"
@@ -451,22 +453,9 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
451453
* SW_TABLET_MODE report, in these cases we enable support when receiving
452454
* the first event instead of during driver setup.
453455
*
454-
* Some 360 degree hinges (yoga) style 2-in-1 devices use 2 accelerometers
455-
* to allow the OS to determine the angle between the display and the base
456-
* of the device. On Windows these are read by a special HingeAngleService
457-
* process which calls an ACPI DSM (Device Specific Method) on the
458-
* ACPI KIOX010A device node for the sensor in the display, to let the
459-
* firmware know if the 2-in-1 is in tablet- or laptop-mode so that it can
460-
* disable the kbd and touchpad to avoid spurious input in tablet-mode.
461-
*
462-
* The linux kxcjk1013 driver calls the DSM for this once at probe time
463-
* to ensure that the builtin kbd and touchpad work. On some devices this
464-
* causes a "spurious" 0xcd event on the intel-hid ACPI dev. In this case
465-
* there is not a functional tablet-mode switch, so we should not register
466-
* the tablet-mode switch device.
456+
* See dual_accel_detect.h for more info on the dual_accel check.
467457
*/
468-
if (!priv->switches && (event == 0xcc || event == 0xcd) &&
469-
!acpi_dev_present("KIOX010A", NULL, -1)) {
458+
if (!priv->switches && !priv->dual_accel && (event == 0xcc || event == 0xcd)) {
470459
dev_info(&device->dev, "switch event received, enable switches supports\n");
471460
err = intel_hid_switches_setup(device);
472461
if (err)
@@ -607,6 +596,8 @@ static int intel_hid_probe(struct platform_device *device)
607596
return -ENOMEM;
608597
dev_set_drvdata(&device->dev, priv);
609598

599+
priv->dual_accel = dual_accel_detect();
600+
610601
err = intel_hid_input_setup(device);
611602
if (err) {
612603
pr_err("Failed to setup Intel HID hotkeys\n");

drivers/platform/x86/intel-vbtn.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/module.h>
1515
#include <linux/platform_device.h>
1616
#include <linux/suspend.h>
17+
#include "dual_accel_detect.h"
1718

1819
/* Returned when NOT in tablet mode on some HP Stream x360 11 models */
1920
#define VGBS_TABLET_MODE_FLAG_ALT 0x10
@@ -66,6 +67,7 @@ static const struct key_entry intel_vbtn_switchmap[] = {
6667
struct intel_vbtn_priv {
6768
struct input_dev *buttons_dev;
6869
struct input_dev *switches_dev;
70+
bool dual_accel;
6971
bool has_buttons;
7072
bool has_switches;
7173
bool wakeup_mode;
@@ -160,6 +162,10 @@ static void notify_handler(acpi_handle handle, u32 event, void *context)
160162
input_dev = priv->buttons_dev;
161163
} else if ((ke = sparse_keymap_entry_from_scancode(priv->switches_dev, event))) {
162164
if (!priv->has_switches) {
165+
/* See dual_accel_detect.h for more info */
166+
if (priv->dual_accel)
167+
return;
168+
163169
dev_info(&device->dev, "Registering Intel Virtual Switches input-dev after receiving a switch event\n");
164170
ret = input_register_device(priv->switches_dev);
165171
if (ret)
@@ -248,11 +254,15 @@ static const struct dmi_system_id dmi_switches_allow_list[] = {
248254
{} /* Array terminator */
249255
};
250256

251-
static bool intel_vbtn_has_switches(acpi_handle handle)
257+
static bool intel_vbtn_has_switches(acpi_handle handle, bool dual_accel)
252258
{
253259
unsigned long long vgbs;
254260
acpi_status status;
255261

262+
/* See dual_accel_detect.h for more info */
263+
if (dual_accel)
264+
return false;
265+
256266
if (!dmi_check_system(dmi_switches_allow_list))
257267
return false;
258268

@@ -263,13 +273,14 @@ static bool intel_vbtn_has_switches(acpi_handle handle)
263273
static int intel_vbtn_probe(struct platform_device *device)
264274
{
265275
acpi_handle handle = ACPI_HANDLE(&device->dev);
266-
bool has_buttons, has_switches;
276+
bool dual_accel, has_buttons, has_switches;
267277
struct intel_vbtn_priv *priv;
268278
acpi_status status;
269279
int err;
270280

281+
dual_accel = dual_accel_detect();
271282
has_buttons = acpi_has_method(handle, "VBDL");
272-
has_switches = intel_vbtn_has_switches(handle);
283+
has_switches = intel_vbtn_has_switches(handle, dual_accel);
273284

274285
if (!has_buttons && !has_switches) {
275286
dev_warn(&device->dev, "failed to read Intel Virtual Button driver\n");
@@ -281,6 +292,7 @@ static int intel_vbtn_probe(struct platform_device *device)
281292
return -ENOMEM;
282293
dev_set_drvdata(&device->dev, priv);
283294

295+
priv->dual_accel = dual_accel;
284296
priv->has_buttons = has_buttons;
285297
priv->has_switches = has_switches;
286298

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include <linux/uaccess.h>
7474
#include <acpi/battery.h>
7575
#include <acpi/video.h>
76+
#include "dual_accel_detect.h"
7677

7778
/* ThinkPad CMOS commands */
7879
#define TP_CMOS_VOLUME_DOWN 0
@@ -3232,7 +3233,7 @@ static int hotkey_init_tablet_mode(void)
32323233
* the laptop/tent/tablet mode to the EC. The bmc150 iio driver
32333234
* does not support this, so skip the hotkey on these models.
32343235
*/
3235-
if (has_tablet_mode && !acpi_dev_present("BOSC0200", "1", -1))
3236+
if (has_tablet_mode && !dual_accel_detect())
32363237
tp_features.hotkey_tablet = TP_HOTKEY_TABLET_USES_GMMS;
32373238
type = "GMMS";
32383239
} else if (acpi_evalf(hkey_handle, &res, "MHKG", "qd")) {

0 commit comments

Comments
 (0)