• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0+
12 #include <linux/input/sparse-keymap.h>
30 /* 1: LSuper (Page 0x07, usage 0xE3) -- unclear what to do */
31 /* 2: Toggle SW_ROTATE_LOCK -- easy to implement if seen in wild */
40 /* 13 has two different meanings in the spec -- ignore it. */
48 /* 27: wake -- needs special handling */
112 #define HID_EVENT_FILTER_UUID "eeec56b3-4442-408f-a792-4edd4d758054"
144 static bool intel_hid_execute_method(acpi_handle handle, in intel_hid_execute_method() argument
169 obj = acpi_evaluate_dsm(handle, &intel_dsm_guid, 1, fn_index, &argv4); in intel_hid_execute_method()
171 acpi_handle_debug(handle, "Exec DSM Fn code: %d[%s] success\n", in intel_hid_execute_method()
178 status = acpi_execute_simple_method(handle, method_name, arg); in intel_hid_execute_method()
185 static bool intel_hid_evaluate_method(acpi_handle handle, in intel_hid_evaluate_method() argument
202 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, in intel_hid_evaluate_method()
206 *result = obj->integer.value; in intel_hid_evaluate_method()
207 acpi_handle_debug(handle, in intel_hid_evaluate_method()
215 status = acpi_evaluate_integer(handle, method_name, NULL, result); in intel_hid_evaluate_method()
222 static void intel_hid_init_dsm(acpi_handle handle) in intel_hid_init_dsm() argument
228 obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, 1, 0, NULL, in intel_hid_init_dsm()
231 intel_hid_dsm_fn_mask = *obj->buffer.pointer; in intel_hid_init_dsm()
235 acpi_handle_debug(handle, "intel_hid_dsm_fn_mask = %llx\n", in intel_hid_init_dsm()
239 static int intel_hid_set_enable(struct device *device, bool enable) in intel_hid_set_enable() argument
241 acpi_handle handle = ACPI_HANDLE(device); in intel_hid_set_enable() local
243 /* Enable|disable features - power button is always enabled */ in intel_hid_set_enable()
244 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_HDSM_FN, in intel_hid_set_enable()
246 dev_warn(device, "failed to %sable hotkeys\n", in intel_hid_set_enable()
248 return -EIO; in intel_hid_set_enable()
254 static void intel_button_array_enable(struct device *device, bool enable) in intel_button_array_enable() argument
256 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_button_array_enable()
257 acpi_handle handle = ACPI_HANDLE(device); in intel_button_array_enable() local
261 if (!priv->array) in intel_button_array_enable()
265 status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap); in intel_button_array_enable()
267 dev_warn(device, "failed to get button capability\n"); in intel_button_array_enable()
271 /* Enable|disable features - power button is always enabled */ in intel_button_array_enable()
272 if (!intel_hid_execute_method(handle, INTEL_HID_DSM_BTNE_FN, in intel_button_array_enable()
274 dev_warn(device, "failed to set button capability\n"); in intel_button_array_enable()
277 static int intel_hid_pm_prepare(struct device *device) in intel_hid_pm_prepare() argument
279 if (device_may_wakeup(device)) { in intel_hid_pm_prepare()
280 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_hid_pm_prepare()
282 priv->wakeup_mode = true; in intel_hid_pm_prepare()
287 static void intel_hid_pm_complete(struct device *device) in intel_hid_pm_complete() argument
289 struct intel_hid_priv *priv = dev_get_drvdata(device); in intel_hid_pm_complete()
291 priv->wakeup_mode = false; in intel_hid_pm_complete()
294 static int intel_hid_pl_suspend_handler(struct device *device) in intel_hid_pl_suspend_handler() argument
296 intel_button_array_enable(device, false); in intel_hid_pl_suspend_handler()
299 intel_hid_set_enable(device, false); in intel_hid_pl_suspend_handler()
304 static int intel_hid_pl_resume_handler(struct device *device) in intel_hid_pl_resume_handler() argument
306 intel_hid_pm_complete(device); in intel_hid_pl_resume_handler()
309 intel_hid_set_enable(device, true); in intel_hid_pl_resume_handler()
311 intel_button_array_enable(device, true); in intel_hid_pl_resume_handler()
325 static int intel_hid_input_setup(struct platform_device *device) in intel_hid_input_setup() argument
327 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in intel_hid_input_setup()
330 priv->input_dev = devm_input_allocate_device(&device->dev); in intel_hid_input_setup()
331 if (!priv->input_dev) in intel_hid_input_setup()
332 return -ENOMEM; in intel_hid_input_setup()
334 ret = sparse_keymap_setup(priv->input_dev, intel_hid_keymap, NULL); in intel_hid_input_setup()
338 priv->input_dev->name = "Intel HID events"; in intel_hid_input_setup()
339 priv->input_dev->id.bustype = BUS_HOST; in intel_hid_input_setup()
341 return input_register_device(priv->input_dev); in intel_hid_input_setup()
344 static int intel_button_array_input_setup(struct platform_device *device) in intel_button_array_input_setup() argument
346 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in intel_button_array_input_setup()
349 /* Setup input device for 5 button array */ in intel_button_array_input_setup()
350 priv->array = devm_input_allocate_device(&device->dev); in intel_button_array_input_setup()
351 if (!priv->array) in intel_button_array_input_setup()
352 return -ENOMEM; in intel_button_array_input_setup()
354 ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL); in intel_button_array_input_setup()
358 priv->array->name = "Intel HID 5 button array"; in intel_button_array_input_setup()
359 priv->array->id.bustype = BUS_HOST; in intel_button_array_input_setup()
361 return input_register_device(priv->array); in intel_button_array_input_setup()
364 static void notify_handler(acpi_handle handle, u32 event, void *context) in notify_handler() argument
366 struct platform_device *device = context; in notify_handler() local
367 struct intel_hid_priv *priv = dev_get_drvdata(&device->dev); in notify_handler()
370 if (priv->wakeup_mode) { in notify_handler()
372 * Needed for wakeup from suspend-to-idle to work on some in notify_handler()
373 * platforms that don't expose the 5-button array, but still in notify_handler()
375 * device object on power button actions while suspended. in notify_handler()
380 /* Wake up on 5-button array events only. */ in notify_handler()
381 if (event == 0xc0 || !priv->array) in notify_handler()
384 if (!sparse_keymap_entry_from_scancode(priv->array, event)) { in notify_handler()
385 dev_info(&device->dev, "unknown event 0x%x\n", event); in notify_handler()
390 pm_wakeup_hard_event(&device->dev); in notify_handler()
396 * the 5-button array, but still send notifies with power button in notify_handler()
397 * event code to this device object on power button actions. in notify_handler()
401 if (!priv->array) { in notify_handler()
403 input_report_key(priv->input_dev, KEY_POWER, 1); in notify_handler()
404 input_sync(priv->input_dev); in notify_handler()
409 input_report_key(priv->input_dev, KEY_POWER, 0); in notify_handler()
410 input_sync(priv->input_dev); in notify_handler()
417 if (!priv->array || in notify_handler()
418 !sparse_keymap_report_event(priv->array, event, 1, true)) in notify_handler()
419 dev_dbg(&device->dev, "unknown event 0x%x\n", event); in notify_handler()
423 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDEM_FN, in notify_handler()
425 dev_warn(&device->dev, "failed to get event index\n"); in notify_handler()
429 if (!sparse_keymap_report_event(priv->input_dev, ev_index, 1, true)) in notify_handler()
430 dev_dbg(&device->dev, "unknown event index 0x%llx\n", in notify_handler()
434 static bool button_array_present(struct platform_device *device) in button_array_present() argument
436 acpi_handle handle = ACPI_HANDLE(&device->dev); in button_array_present() local
439 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V2_FN, in button_array_present()
446 if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V1_FN, in button_array_present()
458 static int intel_hid_probe(struct platform_device *device) in intel_hid_probe() argument
460 acpi_handle handle = ACPI_HANDLE(&device->dev); in intel_hid_probe() local
466 intel_hid_init_dsm(handle); in intel_hid_probe()
468 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDMM_FN, &mode)) { in intel_hid_probe()
469 dev_warn(&device->dev, "failed to read mode\n"); in intel_hid_probe()
470 return -ENODEV; in intel_hid_probe()
479 dev_info(&device->dev, "platform is not in simple mode\n"); in intel_hid_probe()
480 return -ENODEV; in intel_hid_probe()
483 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); in intel_hid_probe()
485 return -ENOMEM; in intel_hid_probe()
486 dev_set_drvdata(&device->dev, priv); in intel_hid_probe()
488 err = intel_hid_input_setup(device); in intel_hid_probe()
495 if (button_array_present(device)) { in intel_hid_probe()
496 dev_info(&device->dev, "platform supports 5 button array\n"); in intel_hid_probe()
497 err = intel_button_array_input_setup(device); in intel_hid_probe()
502 status = acpi_install_notify_handler(handle, in intel_hid_probe()
505 device); in intel_hid_probe()
507 return -EBUSY; in intel_hid_probe()
509 err = intel_hid_set_enable(&device->dev, true); in intel_hid_probe()
513 intel_button_array_enable(&device->dev, true); in intel_hid_probe()
520 if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_BTNL_FN, &dummy)) in intel_hid_probe()
521 dev_warn(&device->dev, "failed to enable HID power button\n"); in intel_hid_probe()
523 device_init_wakeup(&device->dev, true); in intel_hid_probe()
533 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); in intel_hid_probe()
538 static int intel_hid_remove(struct platform_device *device) in intel_hid_remove() argument
540 acpi_handle handle = ACPI_HANDLE(&device->dev); in intel_hid_remove() local
542 device_init_wakeup(&device->dev, false); in intel_hid_remove()
543 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler); in intel_hid_remove()
544 intel_hid_set_enable(&device->dev, false); in intel_hid_remove()
545 intel_button_array_enable(&device->dev, false); in intel_hid_remove()
549 * safely detach from the device. in intel_hid_remove()
556 .name = "intel-hid",
565 * Unfortunately, some laptops provide a _HID="INT33D5" device with
567 * ACPI node, so no platform device will be created. The pnpacpi
568 * driver rejects this device in subsequent processing, so no physical
571 * As a workaround until the ACPI core figures out how to handle
572 * this corner case, manually ask the ACPI platform device code to
576 check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv) in check_acpi_dev() argument
581 if (acpi_bus_get_device(handle, &dev) != 0) in check_acpi_dev()
586 dev_info(&dev->dev, in check_acpi_dev()
587 "intel-hid: created platform device\n"); in check_acpi_dev()