^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Intel Virtual Button driver for Windows 8.1+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2016 AceLan Kao <acelan.kao@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2016 Alex Hung <alex.hung@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/input/sparse-keymap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Returned when NOT in tablet mode on some HP Stream x360 11 models */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define VGBS_TABLET_MODE_FLAG_ALT 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* When NOT in tablet mode, VGBS returns with the flag 0x40 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define VGBS_TABLET_MODE_FLAG 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define VGBS_DOCK_MODE_FLAG 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define VGBS_TABLET_MODE_FLAGS (VGBS_TABLET_MODE_FLAG | VGBS_TABLET_MODE_FLAG_ALT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) MODULE_AUTHOR("AceLan Kao");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static const struct acpi_device_id intel_vbtn_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {"INT33D6", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) MODULE_DEVICE_TABLE(acpi, intel_vbtn_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* In theory, these are HID usages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static const struct key_entry intel_vbtn_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { KE_KEY, 0xC0, { KEY_POWER } }, /* power key press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) { KE_IGNORE, 0xC1, { KEY_POWER } }, /* power key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { KE_KEY, 0xC2, { KEY_LEFTMETA } }, /* 'Windows' key press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) { KE_KEY, 0xC3, { KEY_LEFTMETA } }, /* 'Windows' key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { KE_KEY, 0xC4, { KEY_VOLUMEUP } }, /* volume-up key press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) { KE_IGNORE, 0xC5, { KEY_VOLUMEUP } }, /* volume-up key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { KE_KEY, 0xC6, { KEY_VOLUMEDOWN } }, /* volume-down key press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN } }, /* volume-down key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { KE_KEY, 0xC8, { KEY_ROTATE_LOCK_TOGGLE } }, /* rotate-lock key press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { KE_KEY, 0xC9, { KEY_ROTATE_LOCK_TOGGLE } }, /* rotate-lock key release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static const struct key_entry intel_vbtn_switchmap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * SW_DOCK should only be reported for docking stations, but DSDTs using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * intel-vbtn code, always seem to use this for 2-in-1s / convertibles and set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * SW_DOCK=1 when in laptop-mode (in tandem with setting SW_TABLET_MODE=0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * This causes userspace to think the laptop is docked to a port-replicator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * and to disable suspend-on-lid-close, which is undesirable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Map the dock events to KEY_IGNORE to avoid this broken SW_DOCK reporting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { KE_IGNORE, 0xCA, { .sw = { SW_DOCK, 1 } } }, /* Docked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { KE_IGNORE, 0xCB, { .sw = { SW_DOCK, 0 } } }, /* Undocked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { KE_SW, 0xCC, { .sw = { SW_TABLET_MODE, 1 } } }, /* Tablet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { KE_SW, 0xCD, { .sw = { SW_TABLET_MODE, 0 } } }, /* Laptop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define KEYMAP_LEN \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) (ARRAY_SIZE(intel_vbtn_keymap) + ARRAY_SIZE(intel_vbtn_switchmap) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct intel_vbtn_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct key_entry keymap[KEYMAP_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) bool has_buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) bool has_switches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bool wakeup_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static void detect_tablet_mode(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long long vgbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) status = acpi_evaluate_integer(handle, "VGBS", NULL, &vgbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) m = !(vgbs & VGBS_TABLET_MODE_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) input_report_switch(priv->input_dev, SW_TABLET_MODE, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) m = (vgbs & VGBS_DOCK_MODE_FLAG) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) input_report_switch(priv->input_dev, SW_DOCK, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int intel_vbtn_input_setup(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int ret, keymap_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (priv->has_buttons) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) memcpy(&priv->keymap[keymap_len], intel_vbtn_keymap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ARRAY_SIZE(intel_vbtn_keymap) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sizeof(struct key_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) keymap_len += ARRAY_SIZE(intel_vbtn_keymap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (priv->has_switches) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) memcpy(&priv->keymap[keymap_len], intel_vbtn_switchmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ARRAY_SIZE(intel_vbtn_switchmap) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sizeof(struct key_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) keymap_len += ARRAY_SIZE(intel_vbtn_switchmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) priv->keymap[keymap_len].type = KE_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) priv->input_dev = devm_input_allocate_device(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (!priv->input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ret = sparse_keymap_setup(priv->input_dev, priv->keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) priv->input_dev->dev.parent = &device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) priv->input_dev->name = "Intel Virtual Button driver";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) priv->input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (priv->has_switches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) detect_tablet_mode(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return input_register_device(priv->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void notify_handler(acpi_handle handle, u32 event, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct platform_device *device = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct intel_vbtn_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned int val = !(event & 1); /* Even=press, Odd=release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) const struct key_entry *ke, *ke_rel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) bool autorelease;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (priv->wakeup_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ke = sparse_keymap_entry_from_scancode(priv->input_dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (ke) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pm_wakeup_hard_event(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * Switch events like tablet mode will wake the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * and report the new switch position to the input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (ke->type == KE_SW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) sparse_keymap_report_event(priv->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto out_unknown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Even press events are autorelease if there is no corresponding odd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * release event, or if the odd event is KE_IGNORE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ke_rel = sparse_keymap_entry_from_scancode(priv->input_dev, event | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) autorelease = val && (!ke_rel || ke_rel->type == KE_IGNORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (sparse_keymap_report_event(priv->input_dev, event, val, autorelease))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) out_unknown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_dbg(&device->dev, "unknown event index 0x%x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static bool intel_vbtn_has_buttons(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) status = acpi_evaluate_object(handle, "VBDL", NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ACPI_SUCCESS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * There are several laptops (non 2-in-1) models out there which support VGBS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * but simply always return 0, which we translate to SW_TABLET_MODE=1. This in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * turn causes userspace (libinput) to suppress events from the builtin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * keyboard and touchpad, making the laptop essentially unusable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Since the problem of wrongly reporting SW_TABLET_MODE=1 in combination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * with libinput, leads to a non-usable system. Where as OTOH many people will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * not even notice when SW_TABLET_MODE is not being reported, a DMI based allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * list is used here. This list mainly matches on the chassis-type of 2-in-1s.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * There are also some 2-in-1s which use the intel-vbtn ACPI interface to report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * SW_TABLET_MODE with a chassis-type of 8 ("Portable") or 10 ("Notebook"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * these are matched on a per model basis, since many normal laptops with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * possible broken VGBS ACPI-method also use these chassis-types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static const struct dmi_system_id dmi_switches_allow_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31" /* Convertible */),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32" /* Detachable */),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion 13 x360 PC"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) DMI_MATCH(DMI_PRODUCT_NAME, "Switch SA5-271"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7352"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {} /* Array terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static bool intel_vbtn_has_switches(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unsigned long long vgbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!dmi_check_system(dmi_switches_allow_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) status = acpi_evaluate_integer(handle, "VGBS", NULL, &vgbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return ACPI_SUCCESS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int intel_vbtn_probe(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) bool has_buttons, has_switches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct intel_vbtn_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) has_buttons = intel_vbtn_has_buttons(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) has_switches = intel_vbtn_has_switches(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!has_buttons && !has_switches) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dev_warn(&device->dev, "failed to read Intel Virtual Button driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dev_set_drvdata(&device->dev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) priv->has_buttons = has_buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) priv->has_switches = has_switches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) err = intel_vbtn_input_setup(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) pr_err("Failed to setup Intel Virtual Button\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) status = acpi_install_notify_handler(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) notify_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) device_init_wakeup(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * In order for system wakeup to work, the EC GPE has to be marked as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * a wakeup one, so do that here (this setting will persist, but it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * no effect until the wakeup mask is set for the EC GPE).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) acpi_ec_mark_gpe_for_wake();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int intel_vbtn_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) device_init_wakeup(&device->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * Even if we failed to shut off the event stream, we can still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * safely detach from the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int intel_vbtn_pm_prepare(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (device_may_wakeup(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct intel_vbtn_priv *priv = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) priv->wakeup_mode = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void intel_vbtn_pm_complete(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct intel_vbtn_priv *priv = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) priv->wakeup_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int intel_vbtn_pm_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) intel_vbtn_pm_complete(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static const struct dev_pm_ops intel_vbtn_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .prepare = intel_vbtn_pm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .complete = intel_vbtn_pm_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .resume = intel_vbtn_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .restore = intel_vbtn_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .thaw = intel_vbtn_pm_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static struct platform_driver intel_vbtn_pl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .name = "intel-vbtn",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .acpi_match_table = intel_vbtn_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .pm = &intel_vbtn_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .probe = intel_vbtn_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .remove = intel_vbtn_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static acpi_status __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) const struct acpi_device_id *ids = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct acpi_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (acpi_bus_get_device(handle, &dev) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (acpi_match_device_ids(dev, ids) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dev_info(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) "intel-vbtn: created platform device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int __init intel_vbtn_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ACPI_UINT32_MAX, check_acpi_dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) (void *)intel_vbtn_ids, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return platform_driver_register(&intel_vbtn_pl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) module_init(intel_vbtn_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static void __exit intel_vbtn_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) platform_driver_unregister(&intel_vbtn_pl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) module_exit(intel_vbtn_exit);