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