linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: 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>,
	"Matthew Garrett" <mjg59@srcf.ucam.org>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Darren Hart" <dvhart@linux.intel.com>
Subject: [PATCH v3 3/3] dell-laptop: Use dell-rbtn instead i8042 filter when possible
Date: Thu, 14 May 2015 12:54:27 +0200	[thread overview]
Message-ID: <1431600868-11737-4-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1431600868-11737-1-git-send-email-pali.rohar@gmail.com>

Until now module dell-laptop registered rfkill device which used i8042
filter function for receiving HW switch rfkill events (handling special
keycode).

But for some dell laptops there is native ACPI driver dell-rbtn which can
receive rfkill events (without i8042 hacks). On some machines it can also
control rfkill devices, but can turn on/off all radio devices.

So this patch will combine best from both sides. It will use native ACPI
driver dell-rbtn for receiving events and dell-laptop SMBIOS interface for
enabling or disabling radio devices. If ACPI driver or device will not be
available fallback to i8042 filter function will be used.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Tested-by: Gabriele Mazzotta <gabriele.mzt@gmail.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>
---
 drivers/platform/x86/dell-laptop.c |   67 +++++++++++++++++++++++++++++++++---
 1 file changed, 62 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index d688d80..c9ea0f8 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -32,6 +32,7 @@
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
 #include "../../firmware/dcdbas.h"
+#include "dell-rbtn.h"
 
 #define BRIGHTNESS_TOKEN 0x7d
 #define KBD_LED_OFF_TOKEN 0x01E1
@@ -642,6 +643,20 @@ static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
 	return false;
 }
 
+static bool dell_laptop_use_rbtn;
+
+static int dell_laptop_rbtn_notifier_call(struct notifier_block *nb,
+					  unsigned long action, void *data)
+{
+	schedule_delayed_work(&dell_rfkill_work,
+			      round_jiffies_relative(HZ / 4));
+	return NOTIFY_OK;
+}
+
+static struct notifier_block dell_laptop_rbtn_notifier = {
+	.notifier_call = dell_laptop_rbtn_notifier_call,
+};
+
 static int __init dell_setup_rfkill(void)
 {
 	int status, ret, whitelisted;
@@ -718,10 +733,46 @@ static int __init dell_setup_rfkill(void)
 			goto err_wwan;
 	}
 
-	ret = i8042_install_filter(dell_laptop_i8042_filter);
-	if (ret) {
-		pr_warn("Unable to install key filter\n");
+	/*
+	 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
+	 * which can receive HW button switch events and also can control radio
+	 * devices. Somtimes ACPI device supports only reciving events (without
+	 * enable/disable software control).
+	 *
+	 * Dell SMBIOS on whitelisted models supports controlling radio devices
+	 * but does not support receiving HW button switch events. We can use
+	 * i8042 filter hook function to receive keyboard data and handle
+	 * keycode for HW button.
+	 *
+	 * Dell Airplane Mode Switch driver supports only one rfkill switch
+	 * which enable/disable all radio devices. But Dell SMBIOS supports more
+	 * granularity and can enable/disable also one type of radio device
+	 * (e.g disable only bluetooth device without touching wifi device).
+	 *
+	 * So if it is possible we will use Dell Airplane Mode Switch ACPI
+	 * driver for receiving HW events and Dell SMBIOS for setting rfkill
+	 * states. If ACPI driver or device is not available we will fallback to
+	 * i8042 filter hook function.
+	 *
+	 * To prevent duplicate rfkill devices which control and do same thing,
+	 * dell-rbtn driver will automatically remove its own rfkill devices
+	 * once function dell_rbtn_notifier_register() is called.
+	 */
+
+	ret = dell_rbtn_notifier_register(&dell_laptop_rbtn_notifier);
+	if (ret == 0) {
+		pr_info("Using dell-rbtn acpi driver for receiving events\n");
+		dell_laptop_use_rbtn = true;
+	} else if (ret != -ENODEV) {
+		pr_warn("Unable to register dell rbtn notifier\n");
 		goto err_filter;
+	} else {
+		ret = i8042_install_filter(dell_laptop_i8042_filter);
+		if (ret) {
+			pr_warn("Unable to install key filter\n");
+			goto err_filter;
+		}
+		pr_info("Using i8042 filter function for receiving events\n");
 	}
 
 	return 0;
@@ -1961,7 +2012,10 @@ static int __init dell_init(void)
 	return 0;
 
 fail_backlight:
-	i8042_remove_filter(dell_laptop_i8042_filter);
+	if (dell_laptop_use_rbtn)
+		dell_rbtn_notifier_unregister(&dell_laptop_rbtn_notifier);
+	else
+		i8042_remove_filter(dell_laptop_i8042_filter);
 	cancel_delayed_work_sync(&dell_rfkill_work);
 	dell_cleanup_rfkill();
 fail_rfkill:
@@ -1983,7 +2037,10 @@ static void __exit dell_exit(void)
 	if (quirks && quirks->touchpad_led)
 		touchpad_led_exit();
 	kbd_led_exit();
-	i8042_remove_filter(dell_laptop_i8042_filter);
+	if (dell_laptop_use_rbtn)
+		dell_rbtn_notifier_unregister(&dell_laptop_rbtn_notifier);
+	else
+		i8042_remove_filter(dell_laptop_i8042_filter);
 	cancel_delayed_work_sync(&dell_rfkill_work);
 	backlight_device_unregister(dell_backlight_device);
 	dell_cleanup_rfkill();
-- 
1.7.10.4


  parent reply	other threads:[~2015-05-14 10:55 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   ` [PATCH v2 1/3] platform: x86: dell-rbtn: " Pali Rohár
2015-04-29 10:30     ` 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   ` Pali Rohár [this message]
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=1431600868-11737-4-git-send-email-pali.rohar@gmail.com \
    --to=pali.rohar@gmail.com \
    --cc=alex.hung@canonical.com \
    --cc=dvhart@infradead.org \
    --cc=dvhart@linux.intel.com \
    --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).