Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: MIT
0002 /*
0003  * Copyright (C) 2020 Red Hat, Inc.
0004  *
0005  * Authors:
0006  * Hans de Goede <hdegoede@redhat.com>
0007  */
0008 
0009 #include <linux/acpi.h>
0010 #include <drm/drm_privacy_screen_machine.h>
0011 
0012 #ifdef CONFIG_X86
0013 static struct drm_privacy_screen_lookup arch_lookup;
0014 
0015 struct arch_init_data {
0016     struct drm_privacy_screen_lookup lookup;
0017     bool (*detect)(void);
0018 };
0019 
0020 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
0021 static acpi_status __init acpi_set_handle(acpi_handle handle, u32 level,
0022                       void *context, void **return_value)
0023 {
0024     *(acpi_handle *)return_value = handle;
0025     return AE_CTRL_TERMINATE;
0026 }
0027 
0028 static bool __init detect_thinkpad_privacy_screen(void)
0029 {
0030     union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
0031     struct acpi_object_list args = { .count = 1, .pointer = &obj, };
0032     acpi_handle ec_handle = NULL;
0033     unsigned long long output;
0034     acpi_status status;
0035 
0036     if (acpi_disabled)
0037         return false;
0038 
0039     /* Get embedded-controller handle */
0040     status = acpi_get_devices("PNP0C09", acpi_set_handle, NULL, &ec_handle);
0041     if (ACPI_FAILURE(status) || !ec_handle)
0042         return false;
0043 
0044     /* And call the privacy-screen get-status method */
0045     status = acpi_evaluate_integer(ec_handle, "HKEY.GSSS", &args, &output);
0046     if (ACPI_FAILURE(status))
0047         return false;
0048 
0049     return (output & 0x10000) ? true : false;
0050 }
0051 #endif
0052 
0053 #if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
0054 static bool __init detect_chromeos_privacy_screen(void)
0055 {
0056     return acpi_dev_present("GOOG0010", NULL, -1);
0057 }
0058 #endif
0059 
0060 static const struct arch_init_data arch_init_data[] __initconst = {
0061 #if IS_ENABLED(CONFIG_THINKPAD_ACPI)
0062     {
0063         .lookup = {
0064             .dev_id = NULL,
0065             .con_id = NULL,
0066             .provider = "privacy_screen-thinkpad_acpi",
0067         },
0068         .detect = detect_thinkpad_privacy_screen,
0069     },
0070 #endif
0071 #if IS_ENABLED(CONFIG_CHROMEOS_PRIVACY_SCREEN)
0072     {
0073         .lookup = {
0074             .dev_id = NULL,
0075             .con_id = NULL,
0076             .provider = "privacy_screen-GOOG0010:00",
0077         },
0078         .detect = detect_chromeos_privacy_screen,
0079     },
0080 #endif
0081 };
0082 
0083 void __init drm_privacy_screen_lookup_init(void)
0084 {
0085     int i;
0086 
0087     for (i = 0; i < ARRAY_SIZE(arch_init_data); i++) {
0088         if (!arch_init_data[i].detect())
0089             continue;
0090 
0091         pr_info("Found '%s' privacy-screen provider\n",
0092             arch_init_data[i].lookup.provider);
0093 
0094         /* Make a copy because arch_init_data is __initconst */
0095         arch_lookup = arch_init_data[i].lookup;
0096         drm_privacy_screen_lookup_add(&arch_lookup);
0097         break;
0098     }
0099 }
0100 
0101 void drm_privacy_screen_lookup_exit(void)
0102 {
0103     if (arch_lookup.provider)
0104         drm_privacy_screen_lookup_remove(&arch_lookup);
0105 }
0106 #endif /* ifdef CONFIG_X86 */