xref: /linux/drivers/platform/x86/acer-wireless.c (revision a67c554dbc0fdd7e3c5909cb9f0fff41c51b2e9d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Acer Wireless Radio Control Driver
4  *
5  * Copyright (C) 2017 Endless Mobile, Inc.
6  */
7 
8 #include <linux/acpi.h>
9 #include <linux/input.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pci_ids.h>
13 #include <linux/platform_device.h>
14 #include <linux/types.h>
15 
16 static const struct acpi_device_id acer_wireless_acpi_ids[] = {
17 	{"10251229", 0},
18 	{"", 0},
19 };
20 MODULE_DEVICE_TABLE(acpi, acer_wireless_acpi_ids);
21 
22 static void acer_wireless_notify(acpi_handle handle, u32 event, void *data)
23 {
24 	struct device *dev = data;
25 	struct input_dev *idev = dev_get_drvdata(dev);
26 
27 	dev_dbg(dev, "event=%#x\n", event);
28 	if (event != 0x80) {
29 		dev_notice(dev, "Unknown SMKB event: %#x\n", event);
30 		return;
31 	}
32 	input_report_key(idev, KEY_RFKILL, 1);
33 	input_sync(idev);
34 	input_report_key(idev, KEY_RFKILL, 0);
35 	input_sync(idev);
36 }
37 
38 static int acer_wireless_probe(struct platform_device *pdev)
39 {
40 	struct acpi_device *adev;
41 	struct input_dev *idev;
42 	int ret;
43 
44 	adev = ACPI_COMPANION(&pdev->dev);
45 	if (!adev)
46 		return -ENODEV;
47 
48 	idev = devm_input_allocate_device(&pdev->dev);
49 	if (!idev)
50 		return -ENOMEM;
51 
52 	platform_set_drvdata(pdev, idev);
53 	idev->name = "Acer Wireless Radio Control";
54 	idev->phys = "acer-wireless/input0";
55 	idev->id.bustype = BUS_HOST;
56 	idev->id.vendor = PCI_VENDOR_ID_AI;
57 	idev->id.product = 0x1229;
58 	set_bit(EV_KEY, idev->evbit);
59 	set_bit(KEY_RFKILL, idev->keybit);
60 
61 	ret = input_register_device(idev);
62 	if (ret)
63 		return ret;
64 
65 	return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
66 					       acer_wireless_notify,
67 					       &pdev->dev);
68 }
69 
70 static void acer_wireless_remove(struct platform_device *pdev)
71 {
72 	acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
73 				       ACPI_DEVICE_NOTIFY,
74 				       acer_wireless_notify);
75 }
76 
77 static struct platform_driver acer_wireless_driver = {
78 	.probe = acer_wireless_probe,
79 	.remove = acer_wireless_remove,
80 	.driver = {
81 		.name = "Acer Wireless Radio Control Driver",
82 		.acpi_match_table = acer_wireless_acpi_ids,
83 	},
84 };
85 module_platform_driver(acer_wireless_driver);
86 
87 MODULE_DESCRIPTION("Acer Wireless Radio Control Driver");
88 MODULE_AUTHOR("Chris Chiu <chiu@gmail.com>");
89 MODULE_LICENSE("GPL v2");
90