xref: /linux/drivers/platform/x86/asus-wireless.c (revision 2bc46b3ad3c15165f91459b07ff8682478683194)
1 /*
2  * Asus Wireless Radio Control Driver
3  *
4  * Copyright (C) 2015-2016 Endless Mobile, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/types.h>
15 #include <linux/acpi.h>
16 #include <linux/input.h>
17 #include <linux/pci_ids.h>
18 
19 struct asus_wireless_data {
20 	struct input_dev *idev;
21 };
22 
23 static void asus_wireless_notify(struct acpi_device *adev, u32 event)
24 {
25 	struct asus_wireless_data *data = acpi_driver_data(adev);
26 
27 	dev_dbg(&adev->dev, "event=%#x\n", event);
28 	if (event != 0x88) {
29 		dev_notice(&adev->dev, "Unknown ASHS event: %#x\n", event);
30 		return;
31 	}
32 	input_report_key(data->idev, KEY_RFKILL, 1);
33 	input_report_key(data->idev, KEY_RFKILL, 0);
34 	input_sync(data->idev);
35 }
36 
37 static int asus_wireless_add(struct acpi_device *adev)
38 {
39 	struct asus_wireless_data *data;
40 
41 	data = devm_kzalloc(&adev->dev, sizeof(*data), GFP_KERNEL);
42 	if (!data)
43 		return -ENOMEM;
44 	adev->driver_data = data;
45 
46 	data->idev = devm_input_allocate_device(&adev->dev);
47 	if (!data->idev)
48 		return -ENOMEM;
49 	data->idev->name = "Asus Wireless Radio Control";
50 	data->idev->phys = "asus-wireless/input0";
51 	data->idev->id.bustype = BUS_HOST;
52 	data->idev->id.vendor = PCI_VENDOR_ID_ASUSTEK;
53 	set_bit(EV_KEY, data->idev->evbit);
54 	set_bit(KEY_RFKILL, data->idev->keybit);
55 	return input_register_device(data->idev);
56 }
57 
58 static int asus_wireless_remove(struct acpi_device *adev)
59 {
60 	return 0;
61 }
62 
63 static const struct acpi_device_id device_ids[] = {
64 	{"ATK4001", 0},
65 	{"ATK4002", 0},
66 	{"", 0},
67 };
68 MODULE_DEVICE_TABLE(acpi, device_ids);
69 
70 static struct acpi_driver asus_wireless_driver = {
71 	.name = "Asus Wireless Radio Control Driver",
72 	.class = "hotkey",
73 	.ids = device_ids,
74 	.ops = {
75 		.add = asus_wireless_add,
76 		.remove = asus_wireless_remove,
77 		.notify = asus_wireless_notify,
78 	},
79 };
80 module_acpi_driver(asus_wireless_driver);
81 
82 MODULE_DESCRIPTION("Asus Wireless Radio Control Driver");
83 MODULE_AUTHOR("João Paulo Rechi Vita <jprvita@gmail.com>");
84 MODULE_LICENSE("GPL");
85