dual_accel_detect.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <linux/acpi.h>
  17. #include <linux/i2c.h>
  18. static bool dual_accel_detect_bosc0200(void)
  19. {
  20. struct acpi_device *adev;
  21. int count;
  22. adev = acpi_dev_get_first_match_dev("BOSC0200", NULL, -1);
  23. if (!adev)
  24. return false;
  25. count = i2c_acpi_client_count(adev);
  26. acpi_dev_put(adev);
  27. return count == 2;
  28. }
  29. static bool dual_accel_detect(void)
  30. {
  31. /* Systems which use a pair of accels with KIOX010A / KIOX020A ACPI ids */
  32. if (acpi_dev_present("KIOX010A", NULL, -1) &&
  33. acpi_dev_present("KIOX020A", NULL, -1))
  34. return true;
  35. /* Systems which use a single DUAL250E ACPI device to model 2 accels */
  36. if (acpi_dev_present("DUAL250E", NULL, -1))
  37. return true;
  38. /* Systems which use a single BOSC0200 ACPI device to model 2 accels */
  39. if (dual_accel_detect_bosc0200())
  40. return true;
  41. return false;
  42. }