FILE
hid.c
File preview with syntax highlighting.
linux-6.19.14/drivers/platform/x86/intel/hid.c
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Intel HID event & 5 button array driver 4 * 5 * Copyright (C) 2015 Alex Hung <alex.hung@canonical.com> 6 * Copyright (C) 2015 Andrew Lutomirski <luto@kernel.org> 7 */ 8 9#include <linux/acpi.h> 10#include <linux/dmi.h> 11#include <linux/input.h> 12#include <linux/input/sparse-keymap.h> 13#include <linux/kernel.h> 14#include <linux/module.h> 15#include <linux/platform_device.h> 16#include <linux/string_choices.h> 17#include <linux/suspend.h> 18#include "../dual_accel_detect.h" 19 20enum intel_hid_tablet_sw_mode { 21 TABLET_SW_AUTO = -1, 22 TABLET_SW_OFF = 0, 23 TABLET_SW_AT_EVENT, 24 TABLET_SW_AT_PROBE, 25}; 26 27static bool enable_5_button_array; 28module_param(enable_5_button_array, bool, 0444); 29MODULE_PARM_DESC(enable_5_button_array, 30 "Enable 5 Button Array support. " 31 "If you need this please report this to: platform-driver-x86@vger.kernel.org"); 32 33static int enable_sw_tablet_mode = TABLET_SW_AUTO; 34module_param(enable_sw_tablet_mode, int, 0444); 35MODULE_PARM_DESC(enable_sw_tablet_mode, 36 "Enable SW_TABLET_MODE reporting -1:auto 0:off 1:at-first-event 2:at-probe. " 37 "If you need this please report this to: platform-driver-x86@vger.kernel.org"); 38 39/* When NOT in tablet mode, VGBS returns with the flag 0x40 */ 40#define TABLET_MODE_FLAG BIT(6) 41 42MODULE_DESCRIPTION("Intel HID Event hotkey driver"); 43MODULE_LICENSE("GPL"); 44MODULE_AUTHOR("Alex Hung"); 45 46static const struct acpi_device_id intel_hid_ids[] = { 47 { "INT33D5" }, 48 { "INTC1051" }, 49 { "INTC1054" }, 50 { "INTC1070" }, 51 { "INTC1076" }, 52 { "INTC1077" }, 53 { "INTC1078" }, 54 { "INTC107B" }, 55 { "INTC10CB" }, 56 { "INTC10CC" }, 57 { "INTC10F1" }, 58 { "INTC10F2" }, 59 { } 60}; 61MODULE_DEVICE_TABLE(acpi, intel_hid_ids); 62 63/* In theory, these are HID usages. */ 64static const struct key_entry intel_hid_keymap[] = { 65 /* 1: LSuper (Page 0x07, usage 0xE3) -- unclear what to do */ 66 /* 2: Toggle SW_ROTATE_LOCK -- easy to implement if seen in wild */ 67 { KE_KEY, 3, { KEY_NUMLOCK } }, 68 { KE_KEY, 4, { KEY_HOME } }, 69 { KE_KEY, 5, { KEY_END } }, 70 { KE_KEY, 6, { KEY_PAGEUP } }, 71 { KE_KEY, 7, { KEY_PAGEDOWN } }, 72 { KE_KEY, 8, { KEY_RFKILL } }, 73 { KE_KEY, 9, { KEY_POWER } }, 74 { KE_KEY, 11, { KEY_SLEEP } }, 75 /* 13 has two different meanings in the spec -- ignore it. */ 76 { KE_KEY, 14, { KEY_STOPCD } }, 77 { KE_KEY, 15, { KEY_PLAYPAUSE } }, 78 { KE_KEY, 16, { KEY_MUTE } }, 79 { KE_KEY, 17, { KEY_VOLUMEUP } }, 80 { KE_KEY, 18, { KEY_VOLUMEDOWN } }, 81 { KE_KEY, 19, { KEY_BRIGHTNESSUP } }, 82 { KE_KEY, 20, { KEY_BRIGHTNESSDOWN } }, 83 /* 27: wake -- needs special handling */ 84 { KE_END }, 85}; 86 87/* 5 button array notification value. */ 88static const struct key_entry intel_array_keymap[] = { 89 { KE_KEY, 0xC2, { KEY_LEFTMETA } }, /* Press */ 90 { KE_IGNORE, 0xC3, { KEY_LEFTMETA } }, /* Release */ 91 { KE_KEY, 0xC4, { KEY_VOLUMEUP } }, /* Press */ 92 { KE_IGNORE, 0xC5, { KEY_VOLUMEUP } }, /* Release */ 93 { KE_KEY, 0xC6, { KEY_VOLUMEDOWN } }, /* Press */ 94 { KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN } }, /* Release */ 95 { KE_KEY, 0xC8, { KEY_ROTATE_LOCK_TOGGLE } }, /* Press */ 96 { KE_IGNORE, 0xC9, { KEY_ROTATE_LOCK_TOGGLE } }, /* Release */ 97 { KE_KEY, 0xCE, { KEY_POWER } }, /* Press */ 98 { KE_IGNORE, 0xCF, { KEY_POWER } }, /* Release */ 99 { KE_END }, 100}; 101 102static const struct dmi_system_id button_array_table[] = { 103 { 104 .ident = "Wacom MobileStudio Pro 13", 105 .matches = { 106 DMI_MATCH(DMI_SYS_VENDOR, "Wacom Co.,Ltd"), 107 DMI_MATCH(DMI_PRODUCT_NAME, "Wacom MobileStudio Pro 13"), 108 }, 109 }, 110 { 111 .ident = "Wacom MobileStudio Pro 16", 112 .matches = { 113 DMI_MATCH(DMI_SYS_VENDOR, "Wacom Co.,Ltd"), 114 DMI_MATCH(DMI_PRODUCT_NAME, "Wacom MobileStudio Pro 16"), 115 }, 116 }, 117 { 118 .ident = "HP Spectre x2 (2015)", 119 .matches = { 120 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 121 DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x2 Detachable"), 122 }, 123 }, 124 { 125 .ident = "Lenovo ThinkPad X1 Tablet Gen 1", 126 .matches = { 127 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 128 DMI_MATCH(DMI_PRODUCT_FAMILY, "ThinkPad X12 Detachable Gen 1"), 129 }, 130 }, 131 { 132 .ident = "Lenovo ThinkPad X1 Tablet Gen 2", 133 .matches = { 134 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 135 DMI_MATCH(DMI_PRODUCT_FAMILY, "ThinkPad X1 Tablet Gen 2"), 136 }, 137 }, 138 { 139 .ident = "Lenovo ThinkPad X1 Fold 16 Gen 1", 140 .matches = { 141 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 142 DMI_MATCH(DMI_PRODUCT_FAMILY, "ThinkPad X1 Fold 16 Gen 1"), 143 }, 144 }, 145 { 146 .ident = "Microsoft Surface Go 3", 147 .matches = { 148 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), 149 DMI_MATCH(DMI_PRODUCT_NAME, "Surface Go 3"), 150 }, 151 }, 152 { 153 .ident = "Microsoft Surface Go 4", 154 .matches = { 155 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), 156 DMI_MATCH(DMI_PRODUCT_NAME, "Surface Go 4"), 157 }, 158 }, 159 { } 160}; 161 162/* 163 * Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE, 164 * these need to be compared via a DMI based authorization list because some 165 * models have unreliable VGBS return which could cause incorrect 166 * SW_TABLET_MODE report. 167 */ 168static const struct dmi_system_id dmi_vgbs_allow_list[] = { 169 { 170 .matches = { 171 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 172 DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Convertible 15-df0xxx"), 173 }, 174 }, 175 { 176 .matches = { 177 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), 178 DMI_MATCH(DMI_PRODUCT_NAME, "Surface Go"), 179 }, 180 }, 181 { 182 .matches = { 183 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 184 DMI_MATCH(DMI_PRODUCT_NAME, "HP Elite Dragonfly G2 Notebook PC"), 185 }, 186 }, 187 { 188 .matches = { 189 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 190 DMI_MATCH(DMI_PRODUCT_NAME, "Dell Pro Rugged 10 Tablet RA00260"), 191 }, 192 }, 193 { 194 .matches = { 195 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 196 DMI_MATCH(DMI_PRODUCT_NAME, "Dell Pro Rugged 12 Tablet RA02260"), 197 }, 198 }, 199 { 200 .matches = { 201 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 202 DMI_MATCH(DMI_PRODUCT_NAME, "Dell 14 Plus 2-in-1 DB04250"), 203 }, 204 }, 205 { } 206}; 207 208/* 209 * Some devices, even non convertible ones, can send incorrect SW_TABLET_MODE 210 * reports. Accept such reports only from devices in this list. 211 */ 212static const struct dmi_system_id dmi_auto_add_switch[] = { 213 { 214 .matches = { 215 DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31" /* Convertible */), 216 }, 217 }, 218 { 219 .matches = { 220 DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32" /* Detachable */), 221 }, 222 }, 223 {} /* Array terminator */ 224}; 225 226struct intel_hid_priv { 227 struct input_dev *input_dev; 228 struct input_dev *array; 229 struct input_dev *switches; 230 bool wakeup_mode; 231}; 232 233#define HID_EVENT_FILTER_UUID "eeec56b3-4442-408f-a792-4edd4d758054" 234 235enum intel_hid_dsm_fn_codes { 236 INTEL_HID_DSM_FN_INVALID, 237 INTEL_HID_DSM_BTNL_FN, 238 INTEL_HID_DSM_HDMM_FN, 239 INTEL_HID_DSM_HDSM_FN, 240 INTEL_HID_DSM_HDEM_FN, 241 INTEL_HID_DSM_BTNS_FN, 242 INTEL_HID_DSM_BTNE_FN, 243 INTEL_HID_DSM_HEBC_V1_FN, 244 INTEL_HID_DSM_VGBS_FN, 245 INTEL_HID_DSM_HEBC_V2_FN, 246 INTEL_HID_DSM_FN_MAX 247}; 248 249static const char *intel_hid_dsm_fn_to_method[INTEL_HID_DSM_FN_MAX] = { 250 NULL, 251 "BTNL", 252 "HDMM", 253 "HDSM", 254 "HDEM", 255 "BTNS", 256 "BTNE", 257 "HEBC", 258 "VGBS", 259 "HEBC" 260}; 261 262static unsigned long long intel_hid_dsm_fn_mask; 263static guid_t intel_dsm_guid; 264 265static bool intel_hid_execute_method(acpi_handle handle, 266 enum intel_hid_dsm_fn_codes fn_index, 267 unsigned long long arg) 268{ 269 union acpi_object *obj, argv4, req; 270 acpi_status status; 271 char *method_name; 272 273 if (fn_index <= INTEL_HID_DSM_FN_INVALID || 274 fn_index >= INTEL_HID_DSM_FN_MAX) 275 return false; 276 277 method_name = (char *)intel_hid_dsm_fn_to_method[fn_index]; 278 279 if (!(intel_hid_dsm_fn_mask & BIT(fn_index))) 280 goto skip_dsm_exec; 281 282 /* All methods expects a package with one integer element */ 283 req.type = ACPI_TYPE_INTEGER; 284 req.integer.value = arg; 285 286 argv4.type = ACPI_TYPE_PACKAGE; 287 argv4.package.count = 1; 288 argv4.package.elements = &req; 289 290 obj = acpi_evaluate_dsm(handle, &intel_dsm_guid, 1, fn_index, &argv4); 291 if (obj) { 292 acpi_handle_debug(handle, "Exec DSM Fn code: %d[%s] success\n", 293 fn_index, method_name); 294 ACPI_FREE(obj); 295 return true; 296 } 297 298skip_dsm_exec: 299 status = acpi_execute_simple_method(handle, method_name, arg); 300 if (ACPI_SUCCESS(status)) 301 return true; 302 303 return false; 304} 305 306static bool intel_hid_evaluate_method(acpi_handle handle, 307 enum intel_hid_dsm_fn_codes fn_index, 308 unsigned long long *result) 309{ 310 union acpi_object *obj; 311 acpi_status status; 312 char *method_name; 313 314 if (fn_index <= INTEL_HID_DSM_FN_INVALID || 315 fn_index >= INTEL_HID_DSM_FN_MAX) 316 return false; 317 318 method_name = (char *)intel_hid_dsm_fn_to_method[fn_index]; 319 320 if (!(intel_hid_dsm_fn_mask & BIT(fn_index))) 321 goto skip_dsm_eval; 322 323 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, 324 1, fn_index, 325 NULL, ACPI_TYPE_INTEGER); 326 if (obj) { 327 *result = obj->integer.value; 328 acpi_handle_debug(handle, 329 "Eval DSM Fn code: %d[%s] results: 0x%llx\n", 330 fn_index, method_name, *result); 331 ACPI_FREE(obj); 332 return true; 333 } 334 335skip_dsm_eval: 336 status = acpi_evaluate_integer(handle, method_name, NULL, result); 337 if (ACPI_SUCCESS(status)) 338 return true; 339 340 return false; 341} 342 343static void intel_hid_init_dsm(acpi_handle handle) 344{ 345 union acpi_object *obj; 346 347 guid_parse(HID_EVENT_FILTER_UUID, &intel_dsm_guid); 348 349 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, 1, 0, NULL, 350 ACPI_TYPE_BUFFER); 351 if (obj) { 352 switch (obj->buffer.length) { 353 default: 354 case 2: 355 intel_hid_dsm_fn_mask = *(u16 *)obj->buffer.pointer; 356 break; 357 case 1: 358 intel_hid_dsm_fn_mask = *obj->buffer.pointer; 359 break; 360 case 0: 361 acpi_handle_warn(handle, "intel_hid_dsm_fn_mask length is zero\n"); 362 intel_hid_dsm_fn_mask = 0; 363 break; 364 } 365 ACPI_FREE(obj); 366 } 367 368 acpi_handle_debug(handle, "intel_hid_dsm_fn_mask = %llx\n", 369 intel_hid_dsm_fn_mask); 370} 371 372static int intel_hid_set_enable(struct device *device, bool enable) 373{ 374 acpi_handle handle = ACPI_HANDLE(device); 375 376 /* Enable|disable features - power button is always enabled */ 377 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_HDSM_FN, enable)) { 378 dev_warn(device, "failed to %s hotkeys\n", str_enable_disable(enable)); 379 return -EIO; 380 } 381 382 return 0; 383} 384 385static void intel_button_array_enable(struct device *device, bool enable) 386{ 387 struct intel_hid_priv *priv = dev_get_drvdata(device); 388 acpi_handle handle = ACPI_HANDLE(device); 389 unsigned long long button_cap; 390 acpi_status status; 391 392 if (!priv->array) 393 return; 394 395 /* Query supported platform features */ 396 status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap); 397 if (ACPI_FAILURE(status)) { 398 dev_warn(device, "failed to get button capability\n"); 399 return; 400 } 401 402 /* Enable|disable features - power button is always enabled */ 403 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_BTNE_FN, 404 enable ? button_cap : 1)) 405 dev_warn(device, "failed to set button capability\n"); 406} 407 408static int intel_hid_pm_prepare(struct device *device) 409{ 410 if (device_may_wakeup(device)) { 411 struct intel_hid_priv *priv = dev_get_drvdata(device); 412 413 priv->wakeup_mode = true; 414 } 415 return 0; 416} 417 418static void intel_hid_pm_complete(struct device *device) 419{ 420 struct intel_hid_priv *priv = dev_get_drvdata(device); 421 422 priv->wakeup_mode = false; 423} 424 425static int intel_hid_pl_suspend_handler(struct device *device) 426{ 427 intel_button_array_enable(device, false); 428 429 if (!pm_suspend_no_platform()) 430 intel_hid_set_enable(device, false); 431 432 return 0; 433} 434 435static int intel_hid_pl_freeze_handler(struct device *device) 436{ 437 struct intel_hid_priv *priv = dev_get_drvdata(device); 438 439 priv->wakeup_mode = false; 440 return intel_hid_pl_suspend_handler(device); 441} 442 443static int intel_hid_pl_resume_handler(struct device *device) 444{ 445 intel_hid_pm_complete(device); 446 447 if (!pm_suspend_no_platform()) 448 intel_hid_set_enable(device, true); 449 450 intel_button_array_enable(device, true); 451 return 0; 452} 453 454static const struct dev_pm_ops intel_hid_pl_pm_ops = { 455 .prepare = intel_hid_pm_prepare, 456 .complete = intel_hid_pm_complete, 457 .freeze = intel_hid_pl_freeze_handler, 458 .thaw = intel_hid_pl_resume_handler, 459 .restore = intel_hid_pl_resume_handler, 460 .suspend = intel_hid_pl_suspend_handler, 461 .resume = intel_hid_pl_resume_handler, 462}; 463 464static int intel_hid_input_setup(struct platform_device *device) 465{ 466 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); 467 int ret; 468 469 priv->input_dev = devm_input_allocate_device(&device->dev); 470 if (!priv->input_dev) 471 return -ENOMEM; 472 473 ret = sparse_keymap_setup(priv->input_dev, intel_hid_keymap, NULL); 474 if (ret) 475 return ret; 476 477 priv->input_dev->name = "Intel HID events"; 478 priv->input_dev->id.bustype = BUS_HOST; 479 480 return input_register_device(priv->input_dev); 481} 482 483static int intel_button_array_input_setup(struct platform_device *device) 484{ 485 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); 486 int ret; 487 488 /* Setup input device for 5 button array */ 489 priv->array = devm_input_allocate_device(&device->dev); 490 if (!priv->array) 491 return -ENOMEM; 492 493 ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL); 494 if (ret) 495 return ret; 496 497 priv->array->name = "Intel HID 5 button array"; 498 priv->array->id.bustype = BUS_HOST; 499 500 return input_register_device(priv->array); 501} 502 503static int intel_hid_switches_setup(struct platform_device *device) 504{ 505 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); 506 507 /* Setup input device for switches */ 508 priv->switches = devm_input_allocate_device(&device->dev); 509 if (!priv->switches) 510 return -ENOMEM; 511 512 __set_bit(EV_SW, priv->switches->evbit); 513 __set_bit(SW_TABLET_MODE, priv->switches->swbit); 514 515 priv->switches->name = "Intel HID switches"; 516 priv->switches->id.bustype = BUS_HOST; 517 return input_register_device(priv->switches); 518} 519 520static void report_tablet_mode_state(struct platform_device *device) 521{ 522 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); 523 acpi_handle handle = ACPI_HANDLE(&device->dev); 524 unsigned long long vgbs; 525 int m; 526 527 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_VGBS_FN, &vgbs)) 528 return; 529 530 m = !(vgbs & TABLET_MODE_FLAG); 531 input_report_switch(priv->switches, SW_TABLET_MODE, m); 532 input_sync(priv->switches); 533} 534 535static bool report_tablet_mode_event(struct input_dev *input_dev, u32 event) 536{ 537 if (!input_dev) 538 return false; 539 540 switch (event) { 541 case 0xcc: 542 input_report_switch(input_dev, SW_TABLET_MODE, 1); 543 input_sync(input_dev); 544 return true; 545 case 0xcd: 546 input_report_switch(input_dev, SW_TABLET_MODE, 0); 547 input_sync(input_dev); 548 return true; 549 default: 550 return false; 551 } 552} 553 554static void notify_handler(acpi_handle handle, u32 event, void *context) 555{ 556 struct platform_device *device = context; 557 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); 558 unsigned long long ev_index; 559 struct key_entry *ke; 560 int err; 561 562 /* 563 * Some convertible have unreliable VGBS return which could cause incorrect 564 * SW_TABLET_MODE report, in these cases we enable support when receiving 565 * the first event instead of during driver setup. 566 */ 567 if (!priv->switches && enable_sw_tablet_mode == TABLET_SW_AT_EVENT && 568 (event == 0xcc || event == 0xcd)) { 569 dev_info(&device->dev, "switch event received, enable switches supports\n"); 570 err = intel_hid_switches_setup(device); 571 if (err) 572 pr_err("Failed to setup Intel HID switches\n"); 573 } 574 575 if (priv->wakeup_mode) { 576 /* 577 * Needed for wakeup from suspend-to-idle to work on some 578 * platforms that don't expose the 5-button array, but still 579 * send notifies with the power button event code to this 580 * device object on power button actions while suspended. 581 */ 582 if (event == 0xce) 583 goto wakeup; 584 585 /* 586 * Some devices send (duplicate) tablet-mode events when moved 587 * around even though the mode has not changed; and they do this 588 * even when suspended. 589 * Update the switch state in case it changed and then return 590 * without waking up to avoid spurious wakeups. 591 */ 592 if (event == 0xcc || event == 0xcd) { 593 report_tablet_mode_event(priv->switches, event); 594 return; 595 } 596 597 /* Wake up on 5-button array events only. */ 598 if (event == 0xc0 || !priv->array) 599 return; 600 601 ke = sparse_keymap_entry_from_scancode(priv->array, event); 602 if (!ke) { 603 dev_info(&device->dev, "unknown event 0x%x\n", event); 604 return; 605 } 606 607 if (ke->type == KE_IGNORE) 608 return; 609 610wakeup: 611 pm_wakeup_hard_event(&device->dev); 612 613 return; 614 } 615 616 /* 617 * Needed for suspend to work on some platforms that don't expose 618 * the 5-button array, but still send notifies with power button 619 * event code to this device object on power button actions. 620 * 621 * Report the power button press and release. 622 */ 623 if (!priv->array) { 624 if (event == 0xce) { 625 input_report_key(priv->input_dev, KEY_POWER, 1); 626 input_sync(priv->input_dev); 627 return; 628 } 629 630 if (event == 0xcf) { 631 input_report_key(priv->input_dev, KEY_POWER, 0); 632 input_sync(priv->input_dev); 633 return; 634 } 635 } 636 637 if (report_tablet_mode_event(priv->switches, event)) 638 return; 639 640 /* 0xC0 is for HID events, other values are for 5 button array */ 641 if (event != 0xc0) { 642 if (!priv->array || 643 !sparse_keymap_report_event(priv->array, event, 1, true)) 644 dev_dbg(&device->dev, "unknown event 0x%x\n", event); 645 return; 646 } 647 648 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDEM_FN, 649 &ev_index)) { 650 dev_warn(&device->dev, "failed to get event index\n"); 651 return; 652 } 653 654 if (!sparse_keymap_report_event(priv->input_dev, ev_index, 1, true)) 655 dev_dbg(&device->dev, "unknown event index 0x%llx\n", 656 ev_index); 657} 658 659static bool button_array_present(struct platform_device *device) 660{ 661 acpi_handle handle = ACPI_HANDLE(&device->dev); 662 unsigned long long event_cap; 663 664 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V2_FN, 665 &event_cap)) { 666 /* Check presence of 5 button array or v2 power button */ 667 if (event_cap & 0x60000) 668 return true; 669 } 670 671 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V1_FN, 672 &event_cap)) { 673 if (event_cap & 0x20000) 674 return true; 675 } 676 677 if (enable_5_button_array || dmi_check_system(button_array_table)) 678 return true; 679 680 return false; 681} 682 683static int intel_hid_probe(struct platform_device *device) 684{ 685 acpi_handle handle = ACPI_HANDLE(&device->dev); 686 unsigned long long mode, dummy; 687 struct intel_hid_priv *priv; 688 acpi_status status; 689 int err; 690 691 intel_hid_init_dsm(handle); 692 693 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDMM_FN, &mode)) { 694 dev_warn(&device->dev, "failed to read mode\n"); 695 return -ENODEV; 696 } 697 698 if (mode != 0) { 699 /* 700 * This driver only implements "simple" mode. There appear 701 * to be no other modes, but we should be paranoid and check 702 * for compatibility. 703 */ 704 dev_info(&device->dev, "platform is not in simple mode\n"); 705 return -ENODEV; 706 } 707 708 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); 709 if (!priv) 710 return -ENOMEM; 711 dev_set_drvdata(&device->dev, priv); 712 713 /* See dual_accel_detect.h for more info on the dual_accel check. */ 714 if (enable_sw_tablet_mode == TABLET_SW_AUTO) { 715 if (dmi_check_system(dmi_vgbs_allow_list)) 716 enable_sw_tablet_mode = TABLET_SW_AT_PROBE; 717 else if (dmi_check_system(dmi_auto_add_switch) && !dual_accel_detect()) 718 enable_sw_tablet_mode = TABLET_SW_AT_EVENT; 719 else 720 enable_sw_tablet_mode = TABLET_SW_OFF; 721 } 722 723 err = intel_hid_input_setup(device); 724 if (err) { 725 pr_err("Failed to setup Intel HID hotkeys\n"); 726 return err; 727 } 728 729 /* Setup 5 button array */ 730 if (button_array_present(device)) { 731 dev_info(&device->dev, "platform supports 5 button array\n"); 732 err = intel_button_array_input_setup(device); 733 if (err) 734 pr_err("Failed to setup Intel 5 button array hotkeys\n"); 735 } 736 737 /* Setup switches for devices that we know VGBS return correctly */ 738 if (enable_sw_tablet_mode == TABLET_SW_AT_PROBE) { 739 dev_info(&device->dev, "platform supports switches\n"); 740 err = intel_hid_switches_setup(device); 741 if (err) 742 pr_err("Failed to setup Intel HID switches\n"); 743 else 744 report_tablet_mode_state(device); 745 } 746 747 status = acpi_install_notify_handler(handle, 748 ACPI_DEVICE_NOTIFY, 749 notify_handler, 750 device); 751 if (ACPI_FAILURE(status)) 752 return -EBUSY; 753 754 err = intel_hid_set_enable(&device->dev, true); 755 if (err) 756 goto err_remove_notify; 757 758 intel_button_array_enable(&device->dev, true); 759 760 /* 761 * Call button load method to enable HID power button 762 * Always do this since it activates events on some devices without 763 * a button array too. 764 */ 765 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_BTNL_FN, &dummy)) 766 dev_warn(&device->dev, "failed to enable HID power button\n"); 767 768 device_init_wakeup(&device->dev, true); 769 /* 770 * In order for system wakeup to work, the EC GPE has to be marked as 771 * a wakeup one, so do that here (this setting will persist, but it has 772 * no effect until the wakeup mask is set for the EC GPE). 773 */ 774 acpi_ec_mark_gpe_for_wake(); 775 return 0; 776 777err_remove_notify: 778 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); 779 780 return err; 781} 782 783static void intel_hid_remove(struct platform_device *device) 784{ 785 acpi_handle handle = ACPI_HANDLE(&device->dev); 786 787 device_init_wakeup(&device->dev, false); 788 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); 789 intel_hid_set_enable(&device->dev, false); 790 intel_button_array_enable(&device->dev, false); 791} 792 793static struct platform_driver intel_hid_pl_driver = { 794 .driver = { 795 .name = "intel-hid", 796 .acpi_match_table = intel_hid_ids, 797 .pm = &intel_hid_pl_pm_ops, 798 }, 799 .probe = intel_hid_probe, 800 .remove = intel_hid_remove, 801}; 802 803/* 804 * Unfortunately, some laptops provide a _HID="INT33D5" device with 805 * _CID="PNP0C02". This causes the pnpacpi scan driver to claim the 806 * ACPI node, so no platform device will be created. The pnpacpi 807 * driver rejects this device in subsequent processing, so no physical 808 * node is created at all. 809 * 810 * As a workaround until the ACPI core figures out how to handle 811 * this corner case, manually ask the ACPI platform device code to 812 * claim the ACPI node. 813 */ 814static acpi_status __init 815check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv) 816{ 817 const struct acpi_device_id *ids = context; 818 struct acpi_device *dev = acpi_fetch_acpi_dev(handle); 819 820 if (dev && acpi_match_device_ids(dev, ids) == 0) 821 if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL))) 822 dev_info(&dev->dev, 823 "intel-hid: created platform device\n"); 824 825 return AE_OK; 826} 827 828static int __init intel_hid_init(void) 829{ 830 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 831 ACPI_UINT32_MAX, check_acpi_dev, NULL, 832 (void *)intel_hid_ids, NULL); 833 834 return platform_driver_register(&intel_hid_pl_driver); 835} 836module_init(intel_hid_init); 837 838static void __exit intel_hid_exit(void) 839{ 840 platform_driver_unregister(&intel_hid_pl_driver); 841} 842module_exit(intel_hid_exit);
~/
Read-only file preview.