• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
dual_accel_detect_bosc0200(void)20 static bool dual_accel_detect_bosc0200(void)
21 {
22 	struct acpi_device *adev;
23 	int count;
24 
25 	adev = acpi_dev_get_first_match_dev("BOSC0200", NULL, -1);
26 	if (!adev)
27 		return false;
28 
29 	count = i2c_acpi_client_count(adev);
30 
31 	acpi_dev_put(adev);
32 
33 	return count == 2;
34 }
35 
dual_accel_detect(void)36 static bool dual_accel_detect(void)
37 {
38 	/* Systems which use a pair of accels with KIOX010A / KIOX020A ACPI ids */
39 	if (acpi_dev_present("KIOX010A", NULL, -1) &&
40 	    acpi_dev_present("KIOX020A", NULL, -1))
41 		return true;
42 
43 	/* Systems which use a single DUAL250E ACPI device to model 2 accels */
44 	if (acpi_dev_present("DUAL250E", NULL, -1))
45 		return true;
46 
47 	/* Systems which use a single BOSC0200 ACPI device to model 2 accels */
48 	if (dual_accel_detect_bosc0200())
49 		return true;
50 
51 	return false;
52 }
53