^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Airplane mode button for HP & Xiaomi laptops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014-2017 Alex Hung <alex.hung@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.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/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <acpi/acpi_bus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_AUTHOR("Alex Hung");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_ALIAS("acpi*:HPQ6001:*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) MODULE_ALIAS("acpi*:WSTADEF:*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) MODULE_ALIAS("acpi*:AMDI0051:*");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static struct input_dev *hpwl_input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static const struct acpi_device_id hpwl_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {"HPQ6001", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {"WSTADEF", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {"AMDI0051", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int hp_wireless_input_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) hpwl_input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (!hpwl_input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) hpwl_input_dev->name = "HP Wireless hotkeys";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) hpwl_input_dev->phys = "hpq6001/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) hpwl_input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) hpwl_input_dev->evbit[0] = BIT(EV_KEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) set_bit(KEY_RFKILL, hpwl_input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) err = input_register_device(hpwl_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) input_free_device(hpwl_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void hp_wireless_input_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) input_unregister_device(hpwl_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void hpwl_notify(struct acpi_device *acpi_dev, u32 event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (event != 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pr_info("Received unknown event (0x%x)\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) input_report_key(hpwl_input_dev, KEY_RFKILL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) input_sync(hpwl_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) input_report_key(hpwl_input_dev, KEY_RFKILL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) input_sync(hpwl_input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static int hpwl_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) err = hp_wireless_input_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) pr_err("Failed to setup hp wireless hotkeys\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int hpwl_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) hp_wireless_input_destroy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static struct acpi_driver hpwl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .name = "hp-wireless",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .ids = hpwl_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .add = hpwl_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .remove = hpwl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .notify = hpwl_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) module_acpi_driver(hpwl_driver);