45b5fd0
Bugzilla: 958826
45b5fd0
Upstream-status: 3.13
45b5fd0
45b5fd0
From 4cc8a57425c623753b10b77b15392e5b83baa5a3 Mon Sep 17 00:00:00 2001
45b5fd0
From: Hans de Goede <hdegoede@redhat.com>
45b5fd0
Date: Sun, 17 Nov 2013 14:00:16 +0100
45b5fd0
Subject: [PATCH 1/2] Revert "dell-laptop: Remove rfkill code"
45b5fd0
45b5fd0
Without rfkill functionality in dell-laptop I have the following problems:
45b5fd0
-If the hardware radio switch is set to disable the radio, then userspace
45b5fd0
 will still think it can use wireless and bluetooth.
45b5fd0
-The wwan / 3g modem cannot be soft blocked without the dell-laptop rfkill
45b5fd0
 functionality
45b5fd0
45b5fd0
I know the rfkill functionality was removed from the dell-laptop driver because
45b5fd0
it caused more problems then it fixed, and the blacklist for it was growing out
45b5fd0
of control.
45b5fd0
45b5fd0
But in the thread discussing this Dell mentioned that they only QA the rfkill
45b5fd0
acpi interface on Latitudes and indeed there have been no blacklist entries
45b5fd0
for Latitudes. Therefor I would like to bring the rfkill functionality back
45b5fd0
only for Latitudes. This patch is a straight-forward revert. The next patch
45b5fd0
in this set will drop the blacklist and replace it with a Latitude check.
45b5fd0
45b5fd0
This reverts commit a6c2390cd6d2083d27a2359658e08f2d3df375ac.
45b5fd0
45b5fd0
Conflicts:
45b5fd0
	drivers/platform/x86/dell-laptop.c
45b5fd0
45b5fd0
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
45b5fd0
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
45b5fd0
---
45b5fd0
 drivers/platform/x86/dell-laptop.c | 289 +++++++++++++++++++++++++++++++++++++
45b5fd0
 1 file changed, 289 insertions(+)
45b5fd0
45b5fd0
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
45b5fd0
index bb77e18..55f75a2 100644
45b5fd0
--- a/drivers/platform/x86/dell-laptop.c
45b5fd0
+++ b/drivers/platform/x86/dell-laptop.c
45b5fd0
@@ -21,6 +21,7 @@
45b5fd0
 #include <linux/err.h>
45b5fd0
 #include <linux/dmi.h>
45b5fd0
 #include <linux/io.h>
45b5fd0
+#include <linux/rfkill.h>
45b5fd0
 #include <linux/power_supply.h>
45b5fd0
 #include <linux/acpi.h>
45b5fd0
 #include <linux/mm.h>
45b5fd0
@@ -89,6 +90,9 @@ static struct platform_driver platform_driver = {
45b5fd0
 
45b5fd0
 static struct platform_device *platform_device;
45b5fd0
 static struct backlight_device *dell_backlight_device;
45b5fd0
+static struct rfkill *wifi_rfkill;
45b5fd0
+static struct rfkill *bluetooth_rfkill;
45b5fd0
+static struct rfkill *wwan_rfkill;
45b5fd0
 
45b5fd0
 static const struct dmi_system_id dell_device_table[] __initconst = {
45b5fd0
 	{
45b5fd0
@@ -115,6 +119,53 @@ static const struct dmi_system_id dell_device_table[] __initconst = {
45b5fd0
 };
45b5fd0
 MODULE_DEVICE_TABLE(dmi, dell_device_table);
45b5fd0
 
45b5fd0
+static struct dmi_system_id dell_blacklist[] = {
45b5fd0
+	/* Supported by compal-laptop */
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Mini 9",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Mini 10",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Mini 10v",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Mini 1012",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Inspiron 11z",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{
45b5fd0
+		.ident = "Dell Mini 12",
45b5fd0
+		.matches = {
45b5fd0
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
45b5fd0
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
45b5fd0
+		},
45b5fd0
+	},
45b5fd0
+	{}
45b5fd0
+};
45b5fd0
+
45b5fd0
 static struct dmi_system_id dell_quirks[] = {
45b5fd0
 	{
45b5fd0
 		.callback = dmi_matched,
45b5fd0
@@ -355,6 +406,94 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
45b5fd0
 	return buffer;
45b5fd0
 }
45b5fd0
 
45b5fd0
+/* Derived from information in DellWirelessCtl.cpp:
45b5fd0
+   Class 17, select 11 is radio control. It returns an array of 32-bit values.
45b5fd0
+
45b5fd0
+   Input byte 0 = 0: Wireless information
45b5fd0
+
45b5fd0
+   result[0]: return code
45b5fd0
+   result[1]:
45b5fd0
+     Bit 0:      Hardware switch supported
45b5fd0
+     Bit 1:      Wifi locator supported
45b5fd0
+     Bit 2:      Wifi is supported
45b5fd0
+     Bit 3:      Bluetooth is supported
45b5fd0
+     Bit 4:      WWAN is supported
45b5fd0
+     Bit 5:      Wireless keyboard supported
45b5fd0
+     Bits 6-7:   Reserved
45b5fd0
+     Bit 8:      Wifi is installed
45b5fd0
+     Bit 9:      Bluetooth is installed
45b5fd0
+     Bit 10:     WWAN is installed
45b5fd0
+     Bits 11-15: Reserved
45b5fd0
+     Bit 16:     Hardware switch is on
45b5fd0
+     Bit 17:     Wifi is blocked
45b5fd0
+     Bit 18:     Bluetooth is blocked
45b5fd0
+     Bit 19:     WWAN is blocked
45b5fd0
+     Bits 20-31: Reserved
45b5fd0
+   result[2]: NVRAM size in bytes
45b5fd0
+   result[3]: NVRAM format version number
45b5fd0
+
45b5fd0
+   Input byte 0 = 2: Wireless switch configuration
45b5fd0
+   result[0]: return code
45b5fd0
+   result[1]:
45b5fd0
+     Bit 0:      Wifi controlled by switch
45b5fd0
+     Bit 1:      Bluetooth controlled by switch
45b5fd0
+     Bit 2:      WWAN controlled by switch
45b5fd0
+     Bits 3-6:   Reserved
45b5fd0
+     Bit 7:      Wireless switch config locked
45b5fd0
+     Bit 8:      Wifi locator enabled
45b5fd0
+     Bits 9-14:  Reserved
45b5fd0
+     Bit 15:     Wifi locator setting locked
45b5fd0
+     Bits 16-31: Reserved
45b5fd0
+*/
45b5fd0
+
45b5fd0
+static int dell_rfkill_set(void *data, bool blocked)
45b5fd0
+{
45b5fd0
+	int disable = blocked ? 1 : 0;
45b5fd0
+	unsigned long radio = (unsigned long)data;
45b5fd0
+	int hwswitch_bit = (unsigned long)data - 1;
45b5fd0
+	int ret = 0;
45b5fd0
+
45b5fd0
+	get_buffer();
45b5fd0
+	dell_send_request(buffer, 17, 11);
45b5fd0
+
45b5fd0
+	/* If the hardware switch controls this radio, and the hardware
45b5fd0
+	   switch is disabled, don't allow changing the software state */
45b5fd0
+	if ((hwswitch_state & BIT(hwswitch_bit)) &&
45b5fd0
+	    !(buffer->output[1] & BIT(16))) {
45b5fd0
+		ret = -EINVAL;
45b5fd0
+		goto out;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	buffer->input[0] = (1 | (radio<<8) | (disable << 16));
45b5fd0
+	dell_send_request(buffer, 17, 11);
45b5fd0
+
45b5fd0
+out:
45b5fd0
+	release_buffer();
45b5fd0
+	return ret;
45b5fd0
+}
45b5fd0
+
45b5fd0
+static void dell_rfkill_query(struct rfkill *rfkill, void *data)
45b5fd0
+{
45b5fd0
+	int status;
45b5fd0
+	int bit = (unsigned long)data + 16;
45b5fd0
+	int hwswitch_bit = (unsigned long)data - 1;
45b5fd0
+
45b5fd0
+	get_buffer();
45b5fd0
+	dell_send_request(buffer, 17, 11);
45b5fd0
+	status = buffer->output[1];
45b5fd0
+	release_buffer();
45b5fd0
+
45b5fd0
+	rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
45b5fd0
+
45b5fd0
+	if (hwswitch_state & (BIT(hwswitch_bit)))
45b5fd0
+		rfkill_set_hw_state(rfkill, !(status & BIT(16)));
45b5fd0
+}
45b5fd0
+
45b5fd0
+static const struct rfkill_ops dell_rfkill_ops = {
45b5fd0
+	.set_block = dell_rfkill_set,
45b5fd0
+	.query = dell_rfkill_query,
45b5fd0
+};
45b5fd0
+
45b5fd0
 static struct dentry *dell_laptop_dir;
45b5fd0
 
45b5fd0
 static int dell_debugfs_show(struct seq_file *s, void *data)
45b5fd0
@@ -424,6 +563,108 @@ static const struct file_operations dell_debugfs_fops = {
45b5fd0
 	.release = single_release,
45b5fd0
 };
45b5fd0
 
45b5fd0
+static void dell_update_rfkill(struct work_struct *ignored)
45b5fd0
+{
45b5fd0
+	if (wifi_rfkill)
45b5fd0
+		dell_rfkill_query(wifi_rfkill, (void *)1);
45b5fd0
+	if (bluetooth_rfkill)
45b5fd0
+		dell_rfkill_query(bluetooth_rfkill, (void *)2);
45b5fd0
+	if (wwan_rfkill)
45b5fd0
+		dell_rfkill_query(wwan_rfkill, (void *)3);
45b5fd0
+}
45b5fd0
+static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
45b5fd0
+
45b5fd0
+
45b5fd0
+static int __init dell_setup_rfkill(void)
45b5fd0
+{
45b5fd0
+	int status;
45b5fd0
+	int ret;
45b5fd0
+
45b5fd0
+	if (dmi_check_system(dell_blacklist)) {
45b5fd0
+		pr_info("Blacklisted hardware detected - not enabling rfkill\n");
45b5fd0
+		return 0;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	get_buffer();
45b5fd0
+	dell_send_request(buffer, 17, 11);
45b5fd0
+	status = buffer->output[1];
45b5fd0
+	buffer->input[0] = 0x2;
45b5fd0
+	dell_send_request(buffer, 17, 11);
45b5fd0
+	hwswitch_state = buffer->output[1];
45b5fd0
+	release_buffer();
45b5fd0
+
45b5fd0
+	if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
45b5fd0
+		wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
45b5fd0
+					   RFKILL_TYPE_WLAN,
45b5fd0
+					   &dell_rfkill_ops, (void *) 1);
45b5fd0
+		if (!wifi_rfkill) {
45b5fd0
+			ret = -ENOMEM;
45b5fd0
+			goto err_wifi;
45b5fd0
+		}
45b5fd0
+		ret = rfkill_register(wifi_rfkill);
45b5fd0
+		if (ret)
45b5fd0
+			goto err_wifi;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
45b5fd0
+		bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
45b5fd0
+						&platform_device->dev,
45b5fd0
+						RFKILL_TYPE_BLUETOOTH,
45b5fd0
+						&dell_rfkill_ops, (void *) 2);
45b5fd0
+		if (!bluetooth_rfkill) {
45b5fd0
+			ret = -ENOMEM;
45b5fd0
+			goto err_bluetooth;
45b5fd0
+		}
45b5fd0
+		ret = rfkill_register(bluetooth_rfkill);
45b5fd0
+		if (ret)
45b5fd0
+			goto err_bluetooth;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
45b5fd0
+		wwan_rfkill = rfkill_alloc("dell-wwan",
45b5fd0
+					   &platform_device->dev,
45b5fd0
+					   RFKILL_TYPE_WWAN,
45b5fd0
+					   &dell_rfkill_ops, (void *) 3);
45b5fd0
+		if (!wwan_rfkill) {
45b5fd0
+			ret = -ENOMEM;
45b5fd0
+			goto err_wwan;
45b5fd0
+		}
45b5fd0
+		ret = rfkill_register(wwan_rfkill);
45b5fd0
+		if (ret)
45b5fd0
+			goto err_wwan;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	return 0;
45b5fd0
+err_wwan:
45b5fd0
+	rfkill_destroy(wwan_rfkill);
45b5fd0
+	if (bluetooth_rfkill)
45b5fd0
+		rfkill_unregister(bluetooth_rfkill);
45b5fd0
+err_bluetooth:
45b5fd0
+	rfkill_destroy(bluetooth_rfkill);
45b5fd0
+	if (wifi_rfkill)
45b5fd0
+		rfkill_unregister(wifi_rfkill);
45b5fd0
+err_wifi:
45b5fd0
+	rfkill_destroy(wifi_rfkill);
45b5fd0
+
45b5fd0
+	return ret;
45b5fd0
+}
45b5fd0
+
45b5fd0
+static void dell_cleanup_rfkill(void)
45b5fd0
+{
45b5fd0
+	if (wifi_rfkill) {
45b5fd0
+		rfkill_unregister(wifi_rfkill);
45b5fd0
+		rfkill_destroy(wifi_rfkill);
45b5fd0
+	}
45b5fd0
+	if (bluetooth_rfkill) {
45b5fd0
+		rfkill_unregister(bluetooth_rfkill);
45b5fd0
+		rfkill_destroy(bluetooth_rfkill);
45b5fd0
+	}
45b5fd0
+	if (wwan_rfkill) {
45b5fd0
+		rfkill_unregister(wwan_rfkill);
45b5fd0
+		rfkill_destroy(wwan_rfkill);
45b5fd0
+	}
45b5fd0
+}
45b5fd0
+
45b5fd0
 static int dell_send_intensity(struct backlight_device *bd)
45b5fd0
 {
45b5fd0
 	int ret = 0;
45b5fd0
@@ -515,6 +756,30 @@ static void touchpad_led_exit(void)
45b5fd0
 	led_classdev_unregister(&touchpad_led);
45b5fd0
 }
45b5fd0
 
45b5fd0
+static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
45b5fd0
+			      struct serio *port)
45b5fd0
+{
45b5fd0
+	static bool extended;
45b5fd0
+
45b5fd0
+	if (str & 0x20)
45b5fd0
+		return false;
45b5fd0
+
45b5fd0
+	if (unlikely(data == 0xe0)) {
45b5fd0
+		extended = true;
45b5fd0
+		return false;
45b5fd0
+	} else if (unlikely(extended)) {
45b5fd0
+		switch (data) {
45b5fd0
+		case 0x8:
45b5fd0
+			schedule_delayed_work(&dell_rfkill_work,
45b5fd0
+					      round_jiffies_relative(HZ));
45b5fd0
+			break;
45b5fd0
+		}
45b5fd0
+		extended = false;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	return false;
45b5fd0
+}
45b5fd0
+
45b5fd0
 static int __init dell_init(void)
45b5fd0
 {
45b5fd0
 	int max_intensity = 0;
45b5fd0
@@ -557,10 +822,26 @@ static int __init dell_init(void)
45b5fd0
 	}
45b5fd0
 	buffer = page_address(bufferpage);
45b5fd0
 
45b5fd0
+	ret = dell_setup_rfkill();
45b5fd0
+
45b5fd0
+	if (ret) {
45b5fd0
+		pr_warn("Unable to setup rfkill\n");
45b5fd0
+		goto fail_rfkill;
45b5fd0
+	}
45b5fd0
+
45b5fd0
+	ret = i8042_install_filter(dell_laptop_i8042_filter);
45b5fd0
+	if (ret) {
45b5fd0
+		pr_warn("Unable to install key filter\n");
45b5fd0
+		goto fail_filter;
45b5fd0
+	}
45b5fd0
+
45b5fd0
 	if (quirks && quirks->touchpad_led)
45b5fd0
 		touchpad_led_init(&platform_device->dev);
45b5fd0
 
45b5fd0
 	dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
45b5fd0
+	if (dell_laptop_dir != NULL)
45b5fd0
+		debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
45b5fd0
+				    &dell_debugfs_fops);
45b5fd0
 
45b5fd0
 #ifdef CONFIG_ACPI
45b5fd0
 	/* In the event of an ACPI backlight being available, don't
45b5fd0
@@ -603,6 +884,11 @@ static int __init dell_init(void)
45b5fd0
 	return 0;
45b5fd0
 
45b5fd0
 fail_backlight:
45b5fd0
+	i8042_remove_filter(dell_laptop_i8042_filter);
45b5fd0
+	cancel_delayed_work_sync(&dell_rfkill_work);
45b5fd0
+fail_filter:
45b5fd0
+	dell_cleanup_rfkill();
45b5fd0
+fail_rfkill:
45b5fd0
 	free_page((unsigned long)bufferpage);
45b5fd0
 fail_buffer:
45b5fd0
 	platform_device_del(platform_device);
45b5fd0
@@ -620,7 +906,10 @@ static void __exit dell_exit(void)
45b5fd0
 	debugfs_remove_recursive(dell_laptop_dir);
45b5fd0
 	if (quirks && quirks->touchpad_led)
45b5fd0
 		touchpad_led_exit();
45b5fd0
+	i8042_remove_filter(dell_laptop_i8042_filter);
45b5fd0
+	cancel_delayed_work_sync(&dell_rfkill_work);
45b5fd0
 	backlight_device_unregister(dell_backlight_device);
45b5fd0
+	dell_cleanup_rfkill();
45b5fd0
 	if (platform_device) {
45b5fd0
 		platform_device_unregister(platform_device);
45b5fd0
 		platform_driver_unregister(&platform_driver);
45b5fd0
-- 
45b5fd0
1.8.3.1
45b5fd0