1 // SPDX-License-Identifier: GPL-2.0
3 * adv_swbutton.c - Software Button Interface Driver.
5 * (C) Copyright 2020 Advantech Corporation, Inc
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/input.h>
11 #include <linux/acpi.h>
12 #include <linux/platform_device.h>
14 #define ACPI_BUTTON_HID_SWBTN "AHC0310"
16 #define ACPI_BUTTON_NOTIFY_SWBTN_RELEASE 0x86
17 #define ACPI_BUTTON_NOTIFY_SWBTN_PRESSED 0x85
20 struct input_dev *input;
24 /*-------------------------------------------------------------------------
26 *--------------------------------------------------------------------------
28 static void adv_swbutton_notify(acpi_handle handle, u32 event, void *context)
30 struct platform_device *device = context;
31 struct adv_swbutton *button = dev_get_drvdata(&device->dev);
34 case ACPI_BUTTON_NOTIFY_SWBTN_RELEASE:
35 input_report_key(button->input, KEY_PROG1, 0);
36 input_sync(button->input);
38 case ACPI_BUTTON_NOTIFY_SWBTN_PRESSED:
39 input_report_key(button->input, KEY_PROG1, 1);
40 input_sync(button->input);
43 dev_dbg(&device->dev, "Unsupported event [0x%x]\n", event);
47 static int adv_swbutton_probe(struct platform_device *device)
49 struct adv_swbutton *button;
50 struct input_dev *input;
51 acpi_handle handle = ACPI_HANDLE(&device->dev);
55 button = devm_kzalloc(&device->dev, sizeof(*button), GFP_KERNEL);
59 dev_set_drvdata(&device->dev, button);
61 input = devm_input_allocate_device(&device->dev);
65 button->input = input;
66 snprintf(button->phys, sizeof(button->phys), "%s/button/input0", ACPI_BUTTON_HID_SWBTN);
68 input->name = "Advantech Software Button";
69 input->phys = button->phys;
70 input->id.bustype = BUS_HOST;
71 input->dev.parent = &device->dev;
72 set_bit(EV_REP, input->evbit);
73 input_set_capability(input, EV_KEY, KEY_PROG1);
75 error = input_register_device(input);
79 device_init_wakeup(&device->dev, true);
81 status = acpi_install_notify_handler(handle,
85 if (ACPI_FAILURE(status)) {
86 dev_err(&device->dev, "Error installing notify handler\n");
93 static void adv_swbutton_remove(struct platform_device *device)
95 acpi_handle handle = ACPI_HANDLE(&device->dev);
97 acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY,
101 static const struct acpi_device_id button_device_ids[] = {
102 {ACPI_BUTTON_HID_SWBTN, 0},
105 MODULE_DEVICE_TABLE(acpi, button_device_ids);
107 static struct platform_driver adv_swbutton_driver = {
109 .name = "adv_swbutton",
110 .acpi_match_table = button_device_ids,
112 .probe = adv_swbutton_probe,
113 .remove = adv_swbutton_remove,
115 module_platform_driver(adv_swbutton_driver);
117 MODULE_AUTHOR("Andrea Ho");
118 MODULE_DESCRIPTION("Advantech ACPI SW Button Driver");
119 MODULE_LICENSE("GPL v2");