Lines Matching +full:device +full:- +full:handle

1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/input/sparse-keymap.h>
21 TABLET_SW_AUTO = -1,
31 "If you need this please report this to: platform-driver-[email protected]");
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-[email protected]");
62 /* 1: LSuper (Page 0x07, usage 0xE3) -- unclear what to do */
63 /* 2: Toggle SW_ROTATE_LOCK -- easy to implement if seen in wild */
72 /* 13 has two different meanings in the spec -- ignore it. */
80 /* 27: wake -- needs special handling */
153 * Some convertible use the intel-hid ACPI interface to report SW_TABLET_MODE,
162 DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Convertible 15-df0xxx"),
205 #define HID_EVENT_FILTER_UUID "eeec56b3-4442-408f-a792-4edd4d758054"
237 static bool intel_hid_execute_method(acpi_handle handle, in intel_hid_execute_method() argument
262 obj = acpi_evaluate_dsm(handle, &intel_dsm_guid, 1, fn_index, &argv4); in intel_hid_execute_method()
264 acpi_handle_debug(handle, "Exec DSM Fn code: %d[%s] success\n", in intel_hid_execute_method()
271 status = acpi_execute_simple_method(handle, method_name, arg); in intel_hid_execute_method()
278 static bool intel_hid_evaluate_method(acpi_handle handle, in intel_hid_evaluate_method() argument
295 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, in intel_hid_evaluate_method()
299 *result = obj->integer.value; in intel_hid_evaluate_method()
300 acpi_handle_debug(handle, in intel_hid_evaluate_method()
308 status = acpi_evaluate_integer(handle, method_name, NULL, result); in intel_hid_evaluate_method()
315 static void intel_hid_init_dsm(acpi_handle handle) in intel_hid_init_dsm() argument
321 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, 1, 0, NULL, in intel_hid_init_dsm()
324 switch (obj->buffer.length) { in intel_hid_init_dsm()
327 intel_hid_dsm_fn_mask = *(u16 *)obj->buffer.pointer; in intel_hid_init_dsm()
330 intel_hid_dsm_fn_mask = *obj->buffer.pointer; in intel_hid_init_dsm()
333 acpi_handle_warn(handle, "intel_hid_dsm_fn_mask length is zero\n"); in intel_hid_init_dsm()
340 acpi_handle_debug(handle, "intel_hid_dsm_fn_mask = %llx\n", in intel_hid_init_dsm()
344 static int intel_hid_set_enable(struct device *device, bool enable) in intel_hid_set_enable() argument
346 acpi_handle handle = ACPI_HANDLE(device); in intel_hid_set_enable() local
348 /* Enable|disable features - power button is always enabled */ in intel_hid_set_enable()
349 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_HDSM_FN, enable)) { in intel_hid_set_enable()
350 dev_warn(device, "failed to %s hotkeys\n", str_enable_disable(enable)); in intel_hid_set_enable()
351 return -EIO; in intel_hid_set_enable()
357 static void intel_button_array_enable(struct device *device, bool enable) in intel_button_array_enable() argument
359 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_button_array_enable()
360 acpi_handle handle = ACPI_HANDLE(device); in intel_button_array_enable() local
364 if (!priv->array) in intel_button_array_enable()
368 status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap); in intel_button_array_enable()
370 dev_warn(device, "failed to get button capability\n"); in intel_button_array_enable()
374 /* Enable|disable features - power button is always enabled */ in intel_button_array_enable()
375 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_BTNE_FN, in intel_button_array_enable()
377 dev_warn(device, "failed to set button capability\n"); in intel_button_array_enable()
380 static int intel_hid_pm_prepare(struct device *device) in intel_hid_pm_prepare() argument
382 if (device_may_wakeup(device)) { in intel_hid_pm_prepare()
383 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_hid_pm_prepare()
385 priv->wakeup_mode = true; in intel_hid_pm_prepare()
390 static void intel_hid_pm_complete(struct device *device) in intel_hid_pm_complete() argument
392 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_hid_pm_complete()
394 priv->wakeup_mode = false; in intel_hid_pm_complete()
397 static int intel_hid_pl_suspend_handler(struct device *device) in intel_hid_pl_suspend_handler() argument
399 intel_button_array_enable(device, false); in intel_hid_pl_suspend_handler()
402 intel_hid_set_enable(device, false); in intel_hid_pl_suspend_handler()
407 static int intel_hid_pl_resume_handler(struct device *device) in intel_hid_pl_resume_handler() argument
409 intel_hid_pm_complete(device); in intel_hid_pl_resume_handler()
412 intel_hid_set_enable(device, true); in intel_hid_pl_resume_handler()
414 intel_button_array_enable(device, true); in intel_hid_pl_resume_handler()
428 static int intel_hid_input_setup(struct platform_device *device) in intel_hid_input_setup() argument
430 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in intel_hid_input_setup()
433 priv->input_dev = devm_input_allocate_device(&device->dev); in intel_hid_input_setup()
434 if (!priv->input_dev) in intel_hid_input_setup()
435 return -ENOMEM; in intel_hid_input_setup()
437 ret = sparse_keymap_setup(priv->input_dev, intel_hid_keymap, NULL); in intel_hid_input_setup()
441 priv->input_dev->name = "Intel HID events"; in intel_hid_input_setup()
442 priv->input_dev->id.bustype = BUS_HOST; in intel_hid_input_setup()
444 return input_register_device(priv->input_dev); in intel_hid_input_setup()
447 static int intel_button_array_input_setup(struct platform_device *device) in intel_button_array_input_setup() argument
449 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in intel_button_array_input_setup()
452 /* Setup input device for 5 button array */ in intel_button_array_input_setup()
453 priv->array = devm_input_allocate_device(&device->dev); in intel_button_array_input_setup()
454 if (!priv->array) in intel_button_array_input_setup()
455 return -ENOMEM; in intel_button_array_input_setup()
457 ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL); in intel_button_array_input_setup()
461 priv->array->name = "Intel HID 5 button array"; in intel_button_array_input_setup()
462 priv->array->id.bustype = BUS_HOST; in intel_button_array_input_setup()
464 return input_register_device(priv->array); in intel_button_array_input_setup()
467 static int intel_hid_switches_setup(struct platform_device *device) in intel_hid_switches_setup() argument
469 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in intel_hid_switches_setup()
471 /* Setup input device for switches */ in intel_hid_switches_setup()
472 priv->switches = devm_input_allocate_device(&device->dev); in intel_hid_switches_setup()
473 if (!priv->switches) in intel_hid_switches_setup()
474 return -ENOMEM; in intel_hid_switches_setup()
476 __set_bit(EV_SW, priv->switches->evbit); in intel_hid_switches_setup()
477 __set_bit(SW_TABLET_MODE, priv->switches->swbit); in intel_hid_switches_setup()
479 priv->switches->name = "Intel HID switches"; in intel_hid_switches_setup()
480 priv->switches->id.bustype = BUS_HOST; in intel_hid_switches_setup()
481 return input_register_device(priv->switches); in intel_hid_switches_setup()
484 static void report_tablet_mode_state(struct platform_device *device) in report_tablet_mode_state() argument
486 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in report_tablet_mode_state()
487 acpi_handle handle = ACPI_HANDLE(&device->dev); in report_tablet_mode_state() local
491 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_VGBS_FN, &vgbs)) in report_tablet_mode_state()
495 input_report_switch(priv->switches, SW_TABLET_MODE, m); in report_tablet_mode_state()
496 input_sync(priv->switches); in report_tablet_mode_state()
518 static void notify_handler(acpi_handle handle, u32 event, void *context) in notify_handler() argument
520 struct platform_device *device = context; in notify_handler() local
521 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in notify_handler()
531 if (!priv->switches && enable_sw_tablet_mode == TABLET_SW_AT_EVENT && in notify_handler()
533 dev_info(&device->dev, "switch event received, enable switches supports\n"); in notify_handler()
534 err = intel_hid_switches_setup(device); in notify_handler()
539 if (priv->wakeup_mode) { in notify_handler()
541 * Needed for wakeup from suspend-to-idle to work on some in notify_handler()
542 * platforms that don't expose the 5-button array, but still in notify_handler()
544 * device object on power button actions while suspended. in notify_handler()
550 * Some devices send (duplicate) tablet-mode events when moved in notify_handler()
557 report_tablet_mode_event(priv->switches, event); in notify_handler()
561 /* Wake up on 5-button array events only. */ in notify_handler()
562 if (event == 0xc0 || !priv->array) in notify_handler()
565 ke = sparse_keymap_entry_from_scancode(priv->array, event); in notify_handler()
567 dev_info(&device->dev, "unknown event 0x%x\n", event); in notify_handler()
571 if (ke->type == KE_IGNORE) in notify_handler()
575 pm_wakeup_hard_event(&device->dev); in notify_handler()
582 * the 5-button array, but still send notifies with power button in notify_handler()
583 * event code to this device object on power button actions. in notify_handler()
587 if (!priv->array) { in notify_handler()
589 input_report_key(priv->input_dev, KEY_POWER, 1); in notify_handler()
590 input_sync(priv->input_dev); in notify_handler()
595 input_report_key(priv->input_dev, KEY_POWER, 0); in notify_handler()
596 input_sync(priv->input_dev); in notify_handler()
601 if (report_tablet_mode_event(priv->switches, event)) in notify_handler()
606 if (!priv->array || in notify_handler()
607 !sparse_keymap_report_event(priv->array, event, 1, true)) in notify_handler()
608 dev_dbg(&device->dev, "unknown event 0x%x\n", event); in notify_handler()
612 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDEM_FN, in notify_handler()
614 dev_warn(&device->dev, "failed to get event index\n"); in notify_handler()
618 if (!sparse_keymap_report_event(priv->input_dev, ev_index, 1, true)) in notify_handler()
619 dev_dbg(&device->dev, "unknown event index 0x%llx\n", in notify_handler()
623 static bool button_array_present(struct platform_device *device) in button_array_present() argument
625 acpi_handle handle = ACPI_HANDLE(&device->dev); in button_array_present() local
628 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V2_FN, in button_array_present()
635 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V1_FN, in button_array_present()
647 static int intel_hid_probe(struct platform_device *device) in intel_hid_probe() argument
649 acpi_handle handle = ACPI_HANDLE(&device->dev); in intel_hid_probe() local
655 intel_hid_init_dsm(handle); in intel_hid_probe()
657 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDMM_FN, &mode)) { in intel_hid_probe()
658 dev_warn(&device->dev, "failed to read mode\n"); in intel_hid_probe()
659 return -ENODEV; in intel_hid_probe()
668 dev_info(&device->dev, "platform is not in simple mode\n"); in intel_hid_probe()
669 return -ENODEV; in intel_hid_probe()
672 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); in intel_hid_probe()
674 return -ENOMEM; in intel_hid_probe()
675 dev_set_drvdata(&device->dev, priv); in intel_hid_probe()
687 err = intel_hid_input_setup(device); in intel_hid_probe()
694 if (button_array_present(device)) { in intel_hid_probe()
695 dev_info(&device->dev, "platform supports 5 button array\n"); in intel_hid_probe()
696 err = intel_button_array_input_setup(device); in intel_hid_probe()
703 dev_info(&device->dev, "platform supports switches\n"); in intel_hid_probe()
704 err = intel_hid_switches_setup(device); in intel_hid_probe()
708 report_tablet_mode_state(device); in intel_hid_probe()
711 status = acpi_install_notify_handler(handle, in intel_hid_probe()
714 device); in intel_hid_probe()
716 return -EBUSY; in intel_hid_probe()
718 err = intel_hid_set_enable(&device->dev, true); in intel_hid_probe()
722 intel_button_array_enable(&device->dev, true); in intel_hid_probe()
729 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_BTNL_FN, &dummy)) in intel_hid_probe()
730 dev_warn(&device->dev, "failed to enable HID power button\n"); in intel_hid_probe()
732 device_init_wakeup(&device->dev, true); in intel_hid_probe()
742 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); in intel_hid_probe()
747 static void intel_hid_remove(struct platform_device *device) in intel_hid_remove() argument
749 acpi_handle handle = ACPI_HANDLE(&device->dev); in intel_hid_remove() local
751 device_init_wakeup(&device->dev, false); in intel_hid_remove()
752 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); in intel_hid_remove()
753 intel_hid_set_enable(&device->dev, false); in intel_hid_remove()
754 intel_button_array_enable(&device->dev, false); in intel_hid_remove()
759 .name = "intel-hid",
768 * Unfortunately, some laptops provide a _HID="INT33D5" device with
770 * ACPI node, so no platform device will be created. The pnpacpi
771 * driver rejects this device in subsequent processing, so no physical
774 * As a workaround until the ACPI core figures out how to handle
775 * this corner case, manually ask the ACPI platform device code to
779 check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv) in check_acpi_dev() argument
782 struct acpi_device *dev = acpi_fetch_acpi_dev(handle); in check_acpi_dev()
786 dev_info(&dev->dev, in check_acpi_dev()
787 "intel-hid: created platform device\n"); in check_acpi_dev()