From: "Pali Rohár" <pali.rohar@gmail.com>
To: Matthew Garrett <mjg59@srcf.ucam.org>,
Darren Hart <dvhart@infradead.org>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Gabriele Mazzotta" <gabriele.mzt@gmail.com>,
"Alex Hung" <alex.hung@canonical.com>,
"Pali Rohár" <pali.rohar@gmail.com>
Subject: [PATCH v2 1/3] platform: x86: dell-rbtn: Dell Airplane Mode Switch driver
Date: Wed, 29 Apr 2015 11:51:04 +0200 [thread overview]
Message-ID: <1430301066-22870-2-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1430301066-22870-1-git-send-email-pali.rohar@gmail.com>
This is an ACPI driver for Dell laptops which receive HW switch events.
It exports rfkill device dell-rbtn which provide correct hard rfkill state.
Alex Hung added code for supporting Dell laptops which have toggle button
instead HW slider switch. On these laptops toggle button event is reported
by new input device (instead rfkill) as they do not have hw radio switch.
It looks like those are two different functions (rfkill, input device), but
Dell BIOS exports them via same ACPI device and uses same ACPI functions.
So code is in one kernel driver.
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Cc: Alex Hung <alex.hung@canonical.com>
---
drivers/platform/x86/Kconfig | 13 ++
drivers/platform/x86/Makefile | 1 +
drivers/platform/x86/dell-rbtn.c | 344 ++++++++++++++++++++++++++++++++++++++
3 files changed, 358 insertions(+)
create mode 100644 drivers/platform/x86/dell-rbtn.c
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index f9f205c..9d065c2 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -138,6 +138,19 @@ config DELL_SMO8800
To compile this driver as a module, choose M here: the module will
be called dell-smo8800.
+config DELL_RBTN
+ tristate "Dell Airplane Mode Switch driver"
+ depends on ACPI
+ depends on RFKILL
+ ---help---
+ Say Y here if you want to support Dell Airplane Mode Switch ACPI
+ device on Dell laptops. Sometimes it has names: DELLABCE or DELRBTN.
+ This driver register rfkill device and receives HW rfkill events
+ (when wifi/bluetooth was enabled) and set correct hard rfkill state.
+
+ To compile this driver as a module, choose M here: the module will
+ be called dell-rbtn.
+
config FUJITSU_LAPTOP
tristate "Fujitsu Laptop Extras"
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index f82232b..b3e54ed 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_DELL_LAPTOP) += dell-laptop.o
obj-$(CONFIG_DELL_WMI) += dell-wmi.o
obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o
obj-$(CONFIG_DELL_SMO8800) += dell-smo8800.o
+obj-$(CONFIG_DELL_RBTN) += dell-rbtn.o
obj-$(CONFIG_ACER_WMI) += acer-wmi.o
obj-$(CONFIG_ACERHDF) += acerhdf.o
obj-$(CONFIG_HP_ACCEL) += hp_accel.o
diff --git a/drivers/platform/x86/dell-rbtn.c b/drivers/platform/x86/dell-rbtn.c
new file mode 100644
index 0000000..894cd9a
--- /dev/null
+++ b/drivers/platform/x86/dell-rbtn.c
@@ -0,0 +1,344 @@
+/*
+ Dell Airplane Mode Switch driver
+ Copyright (C) 2014-2015 Pali Rohár <pali.rohar@gmail.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+*/
+
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/rfkill.h>
+#include <linux/input.h>
+
+enum rbtn_type {
+ RBTN_UNKNOWN,
+ RBTN_TOGGLE,
+ RBTN_SLIDER,
+};
+
+struct rbtn_data {
+ enum rbtn_type type;
+ struct rfkill *rfkill;
+ struct input_dev *input_dev;
+};
+
+
+/*
+ * acpi functions
+ */
+
+static enum rbtn_type rbtn_check(struct acpi_device *device)
+{
+ unsigned long long output;
+ acpi_status status;
+
+ status = acpi_evaluate_integer(device->handle, "CRBT", NULL, &output);
+ if (ACPI_FAILURE(status))
+ return RBTN_UNKNOWN;
+
+ switch (output) {
+ case 0:
+ case 1:
+ return RBTN_TOGGLE;
+ case 2:
+ case 3:
+ return RBTN_SLIDER;
+ default:
+ return RBTN_UNKNOWN;
+ }
+}
+
+static int rbtn_get(struct acpi_device *device)
+{
+ unsigned long long output;
+ acpi_status status;
+
+ status = acpi_evaluate_integer(device->handle, "GRBT", NULL, &output);
+ if (ACPI_FAILURE(status))
+ return -EINVAL;
+
+ return !output;
+}
+
+static int rbtn_radio_enable(struct acpi_device *device, bool enable)
+{
+ struct acpi_object_list input;
+ union acpi_object param;
+ acpi_status status;
+
+ param.type = ACPI_TYPE_INTEGER;
+ param.integer.value = enable;
+ input.count = 1;
+ input.pointer = ¶m;
+
+ status = acpi_evaluate_object(device->handle, "ARBT", &input, NULL);
+ if (ACPI_FAILURE(status))
+ return -EINVAL;
+
+ return 0;
+}
+
+
+/*
+ * rfkill device
+ */
+
+static void rbtn_rfkill_query(struct rfkill *rfkill, void *data)
+{
+ struct acpi_device *device = data;
+ int state;
+
+ state = rbtn_get(device);
+ if (state < 0)
+ return;
+
+ rfkill_set_states(rfkill, state, state);
+}
+
+static int rbtn_rfkill_set_block(void *data, bool blocked)
+{
+ /* NOTE: setting soft rfkill state is not supported */
+ return -EINVAL;
+}
+
+struct rfkill_ops rbtn_ops = {
+ .query = rbtn_rfkill_query,
+ .set_block = rbtn_rfkill_set_block,
+};
+
+static int rbtn_rfkill_init(struct acpi_device *device)
+{
+ struct rbtn_data *rbtn_data = device->driver_data;
+ int ret;
+
+ if (rbtn_data->rfkill)
+ return 0;
+
+ /* NOTE: rbtn controls all radio devices, not only WLAN
+ but rfkill interface does not support "ANY" type
+ so "WLAN" type is used
+ */
+ rbtn_data->rfkill = rfkill_alloc("dell-rbtn", &device->dev,
+ RFKILL_TYPE_WLAN, &rbtn_ops, device);
+ if (!rbtn_data->rfkill)
+ return -ENOMEM;
+
+ ret = rfkill_register(rbtn_data->rfkill);
+ if (ret) {
+ rfkill_destroy(rbtn_data->rfkill);
+ rbtn_data->rfkill = NULL;
+ return ret;
+ }
+
+ return 0;
+}
+
+static void rbtn_rfkill_exit(struct acpi_device *device)
+{
+ struct rbtn_data *rbtn_data = device->driver_data;
+
+ if (!rbtn_data->rfkill)
+ return;
+
+ rfkill_unregister(rbtn_data->rfkill);
+ rfkill_destroy(rbtn_data->rfkill);
+ rbtn_data->rfkill = NULL;
+}
+
+static void rbtn_rfkill_event(struct acpi_device *device)
+{
+ struct rbtn_data *rbtn_data = device->driver_data;
+
+ if (rbtn_data->rfkill)
+ rbtn_rfkill_query(rbtn_data->rfkill, device);
+}
+
+
+/*
+ * input device
+ */
+
+static int rbtn_input_init(struct rbtn_data *rbtn_data)
+{
+ int ret;
+
+ rbtn_data->input_dev = input_allocate_device();
+ if (!rbtn_data->input_dev)
+ return -ENOMEM;
+
+ rbtn_data->input_dev->name = "DELL Wireless hotkeys";
+ rbtn_data->input_dev->phys = "dellabce/input0";
+ rbtn_data->input_dev->id.bustype = BUS_HOST;
+ rbtn_data->input_dev->evbit[0] = BIT(EV_KEY);
+ set_bit(KEY_RFKILL, rbtn_data->input_dev->keybit);
+
+ ret = input_register_device(rbtn_data->input_dev);
+ if (ret) {
+ input_free_device(rbtn_data->input_dev);
+ rbtn_data->input_dev = NULL;
+ return ret;
+ }
+
+ return 0;
+}
+
+static void rbtn_input_exit(struct rbtn_data *rbtn_data)
+{
+ input_unregister_device(rbtn_data->input_dev);
+ rbtn_data->input_dev = NULL;
+}
+
+static void rbtn_input_event(struct rbtn_data *rbtn_data)
+{
+ input_report_key(rbtn_data->input_dev, KEY_RFKILL, 1);
+ input_sync(rbtn_data->input_dev);
+ input_report_key(rbtn_data->input_dev, KEY_RFKILL, 0);
+ input_sync(rbtn_data->input_dev);
+}
+
+
+/*
+ * acpi driver
+ */
+
+static int rbtn_add(struct acpi_device *device);
+static int rbtn_remove(struct acpi_device *device);
+static void rbtn_notify(struct acpi_device *device, u32 event);
+
+static const struct acpi_device_id rbtn_ids[] = {
+ { "DELRBTN", 0 },
+ { "DELLABCE", 0 },
+ { "", 0 },
+};
+
+static struct acpi_driver rbtn_driver = {
+ .name = "dell-rbtn",
+ .ids = rbtn_ids,
+ .ops = {
+ .add = rbtn_add,
+ .remove = rbtn_remove,
+ .notify = rbtn_notify,
+ },
+ .owner = THIS_MODULE,
+};
+
+
+/*
+ * acpi driver functions
+ */
+
+static int rbtn_add(struct acpi_device *device)
+{
+ struct rbtn_data *rbtn_data;
+ enum rbtn_type type;
+ int ret = 0;
+
+ type = rbtn_check(device);
+ if (type == RBTN_UNKNOWN) {
+ dev_info(&device->dev, "Unknown device type\n");
+ return -EINVAL;
+ }
+
+ ret = rbtn_radio_enable(device, true);
+ if (ret < 0) {
+ dev_err(&device->dev, "Cannot enable device\n");
+ return ret;
+ }
+
+ rbtn_data = devm_kzalloc(&device->dev, sizeof(*rbtn_data), GFP_KERNEL);
+ if (!rbtn_data)
+ return -ENOMEM;
+
+ rbtn_data->type = type;
+ device->driver_data = rbtn_data;
+
+ switch (rbtn_data->type) {
+ case RBTN_TOGGLE:
+ ret = rbtn_input_init(rbtn_data);
+ break;
+ case RBTN_SLIDER:
+ ret = rbtn_rfkill_init(device);
+ break;
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+
+}
+
+static int rbtn_remove(struct acpi_device *device)
+{
+ struct rbtn_data *rbtn_data = device->driver_data;
+ int ret;
+
+ switch (rbtn_data->type) {
+ case RBTN_TOGGLE:
+ rbtn_input_exit(rbtn_data);
+ break;
+ case RBTN_SLIDER:
+ rbtn_rfkill_exit(device);
+ break;
+ default:
+ break;
+ }
+
+ ret = rbtn_radio_enable(device, false);
+ if (ret < 0)
+ return ret;
+
+ device->driver_data = NULL;
+ return 0;
+}
+
+static void rbtn_notify(struct acpi_device *device, u32 event)
+{
+ struct rbtn_data *rbtn_data = device->driver_data;
+
+ if (event != 0x80) {
+ dev_info(&device->dev, "Received unknown event (0x%x)\n", event);
+ return;
+ }
+
+ switch (rbtn_data->type) {
+ case RBTN_TOGGLE:
+ rbtn_input_event(rbtn_data);
+ break;
+ case RBTN_SLIDER:
+ rbtn_rfkill_event(device);
+ break;
+ default:
+ break;
+ }
+}
+
+
+/*
+ * module functions
+ */
+
+static int __init rbtn_init(void)
+{
+ return acpi_bus_register_driver(&rbtn_driver);
+}
+
+static void __exit rbtn_exit(void)
+{
+ acpi_bus_unregister_driver(&rbtn_driver);
+}
+
+module_init(rbtn_init);
+module_exit(rbtn_exit);
+
+MODULE_DEVICE_TABLE(acpi, rbtn_ids);
+MODULE_DESCRIPTION("Dell Airplane Mode Switch driver");
+MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
+MODULE_LICENSE("GPL");
--
1.7.9.5
next prev parent reply other threads:[~2015-04-29 9:51 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-23 15:09 [PATCH 0/3] Dell Airplane Mode Switch driver Pali Rohár
2014-11-23 15:09 ` [PATCH 1/3] platform: x86: dell-rbtn: " Pali Rohár
2014-11-24 20:09 ` Matthew Garrett
2014-11-24 20:55 ` Pali Rohár
2014-11-24 21:50 ` Matthew Garrett
2014-11-24 22:01 ` Pali Rohár
2014-11-28 11:33 ` Mika Westerberg
2014-11-28 11:45 ` Pali Rohár
2014-11-28 11:54 ` Mika Westerberg
2014-11-25 21:58 ` Darren Hart
2014-11-23 15:09 ` [PATCH 2/3] platform: x86: dell-rbtn: Export notifier for other kernel modules Pali Rohár
2014-11-25 22:39 ` Darren Hart
2015-04-29 9:55 ` Pali Rohár
2014-11-23 15:09 ` [PATCH 3/3] platform: x86: dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2014-11-25 23:05 ` [PATCH 0/3] Dell Airplane Mode Switch driver Darren Hart
2014-12-02 8:42 ` Pali Rohár
2014-12-04 8:16 ` Alex Hung
2014-12-03 12:56 ` Darren Hart
2014-12-04 9:55 ` Pali Rohár
2014-12-03 13:00 ` Darren Hart
2014-12-05 20:38 ` Pali Rohár
2014-12-05 20:53 ` Gabriele Mazzotta
2014-12-05 21:03 ` Pali Rohár
2014-12-05 21:12 ` Gabriele Mazzotta
2014-12-05 21:23 ` Pali Rohár
2014-12-05 21:49 ` Gabriele Mazzotta
2014-12-22 7:27 ` Alex Hung
2014-12-22 9:21 ` Pali Rohár
2014-12-22 12:35 ` Gabriele Mazzotta
2014-12-22 19:16 ` Gabriele Mazzotta
2014-12-24 9:13 ` Alex Hung
2014-12-24 11:40 ` Gabriele Mazzotta
2014-12-25 3:13 ` Alex Hung
2014-12-25 20:11 ` Pali Rohár
2014-12-25 21:55 ` Gabriele Mazzotta
2014-12-29 7:27 ` Alex Hung
2014-12-29 8:32 ` Pali Rohár
2015-01-05 9:55 ` Alex Hung
2015-04-24 7:39 ` Alex Hung
2015-04-29 9:51 ` [PATCH v2 " Pali Rohár
2015-04-29 9:51 ` Pali Rohár [this message]
2015-04-29 10:30 ` [PATCH v2 1/3] platform: x86: dell-rbtn: " Gabriele Mazzotta
2015-04-29 13:08 ` Pali Rohár
2015-04-29 13:57 ` Gabriele Mazzotta
2015-04-29 16:28 ` Pali Rohár
2015-04-29 17:54 ` Gabriele Mazzotta
2015-04-29 18:00 ` Pali Rohár
2015-04-29 18:11 ` Gabriele Mazzotta
2015-04-29 18:16 ` Pali Rohár
2015-04-29 18:41 ` Gabriele Mazzotta
2015-04-29 18:59 ` Pali Rohár
2015-04-30 6:06 ` Alex Hung
2015-04-30 7:44 ` Pali Rohár
2015-05-02 13:51 ` Gabriele Mazzotta
2015-05-02 15:13 ` Pali Rohár
2015-05-05 20:31 ` Darren Hart
2015-05-05 21:23 ` Gabriele Mazzotta
2015-05-06 5:55 ` Darren Hart
2015-05-06 7:49 ` Pali Rohár
2015-05-06 9:34 ` Alex Hung
2015-04-29 9:51 ` [PATCH v2 2/3] platform: x86: dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-04-29 9:51 ` [PATCH v2 3/3] platform: x86: dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-03 10:38 ` [PATCH v2 0/3] Dell Airplane Mode Switch driver Pali Rohár
2015-05-05 20:37 ` Darren Hart
2015-05-05 21:24 ` Gabriele Mazzotta
2015-05-06 7:58 ` Pali Rohár
2015-05-06 9:11 ` Alex Hung
2015-05-06 11:31 ` Pali Rohár
2015-05-06 21:57 ` Darren Hart
2015-05-07 2:24 ` Alex Hung
2015-05-13 11:48 ` Pali Rohár
2015-05-13 18:38 ` Darren Hart
2015-05-14 10:54 ` [PATCH v3 " Pali Rohár
2015-05-14 10:54 ` [PATCH v3 1/3] dell-rbtn: " Pali Rohár
2015-05-14 10:54 ` [PATCH v3 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-05-22 22:45 ` Dmitry Torokhov
2015-05-23 1:05 ` Pali Rohár
2015-05-24 5:07 ` Valdis.Kletnieks
2015-05-24 11:42 ` Pali Rohár
2015-05-14 10:54 ` [PATCH v3 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-18 18:07 ` [PATCH v3 0/3] Dell Airplane Mode Switch driver Darren Hart
2015-05-27 21:28 ` [PATCH v4 " Pali Rohár
2015-05-27 21:28 ` [PATCH v4 1/3] dell-rbtn: " Pali Rohár
2015-05-27 21:28 ` [PATCH v4 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-05-27 21:28 ` [PATCH v4 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-05-28 2:52 ` Darren Hart
2015-06-03 3:55 ` Darren Hart
2015-06-03 8:15 ` Pali Rohár
2015-06-04 5:16 ` Darren Hart
2015-06-06 8:24 ` Pali Rohár
2015-06-06 8:23 ` [PATCH v5 0/3] Dell Airplane Mode Switch driver Pali Rohár
2015-06-06 8:23 ` [PATCH v5 1/3] dell-rbtn: " Pali Rohár
2015-06-06 8:23 ` [PATCH v5 2/3] dell-rbtn: Export notifier for other kernel modules Pali Rohár
2015-06-06 8:23 ` [PATCH v5 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible Pali Rohár
2015-06-08 4:12 ` [PATCH v5 0/3] Dell Airplane Mode Switch driver Darren Hart
2015-06-08 7:30 ` Pali Rohár
2015-06-11 4:55 ` Darren Hart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430301066-22870-2-git-send-email-pali.rohar@gmail.com \
--to=pali.rohar@gmail.com \
--cc=alex.hung@canonical.com \
--cc=dvhart@infradead.org \
--cc=gabriele.mzt@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).