drm_privacy_screen_x86.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright (C) 2020 Red Hat, Inc.
  4. *
  5. * Authors:
  6. * Hans de Goede <hdegoede@redhat.com>
  7. */
  8. #include <linux/acpi.h>
  9. #include <drm/drm_privacy_screen_machine.h>
  10. #ifdef CONFIG_X86
  11. static struct drm_privacy_screen_lookup arch_lookup;
  12. struct arch_init_data {
  13. struct drm_privacy_screen_lookup lookup;
  14. bool (*detect)(void);
  15. };
  16. #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
  17. static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
  18. void *context, void **return_value)
  19. {
  20. *(acpi_handle *)return_value = handle;
  21. return AE_CTRL_TERMINATE;
  22. }
  23. static bool __init detect_thinkpad_privacy_screen(void)
  24. {
  25. union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
  26. struct acpi_object_list args = { .count = 1, .pointer = &obj, };
  27. acpi_handle ec_handle = NULL;
  28. unsigned long long output;
  29. acpi_status status;
  30. if (acpi_disabled)
  31. return false;
  32. /* Get embedded-controller handle */
  33. status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, &ec_handle);
  34. if (ACPI_FAILURE(status) || !ec_handle)
  35. return false;
  36. /* And call the privacy-screen get-status method */
  37. status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", &args, &output);
  38. if (ACPI_FAILURE(status))
  39. return false;
  40. return (output & 0x10000) ? true : false;
  41. }
  42. #endif
  43. #if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
  44. static bool __init detect_chromeos_privacy_screen(void)
  45. {
  46. return acpi_dev_present("GOOG0010", NULL, -1);
  47. }
  48. #endif
  49. static const struct arch_init_data arch_init_data[] __initconst = {
  50. #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
  51. {
  52. .lookup = {
  53. .dev_id = NULL,
  54. .con_id = NULL,
  55. .provider = "privacy_screen-thinkpad_acpi",
  56. },
  57. .detect = detect_thinkpad_privacy_screen,
  58. },
  59. #endif
  60. #if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
  61. {
  62. .lookup = {
  63. .dev_id = NULL,
  64. .con_id = NULL,
  65. .provider = "privacy_screen-GOOG0010:00",
  66. },
  67. .detect = detect_chromeos_privacy_screen,
  68. },
  69. #endif
  70. };
  71. void __init drm_privacy_screen_lookup_init(void)
  72. {
  73. int i;
  74. for (i = 0; i < ARRAY_SIZE(arch_init_data); i++) {
  75. if (!arch_init_data[i].detect())
  76. continue;
  77. pr_info("Found '%s' privacy-screen provider\n",
  78. arch_init_data[i].lookup.provider);
  79. /* Make a copy because arch_init_data is __initconst */
  80. arch_lookup = arch_init_data[i].lookup;
  81. drm_privacy_screen_lookup_add(&arch_lookup);
  82. break;
  83. }
  84. }
  85. void drm_privacy_screen_lookup_exit(void)
  86. {
  87. if (arch_lookup.provider)
  88. drm_privacy_screen_lookup_remove(&arch_lookup);
  89. }
  90. #endif /* ifdef CONFIG_X86 */