[x86] thinkpad_acpi: Add support for X1 Carbon 2nd generation's adaptive keyboard (Closes: #745252)

svn path=/dists/trunk/linux/; revision=21257
This commit is contained in:
Ben Hutchings 2014-04-21 12:32:03 +00:00
parent da27d6543d
commit 7050896aac
4 changed files with 234 additions and 0 deletions

2
debian/changelog vendored
View File

@ -5,6 +5,8 @@ linux (3.14.1-1~exp2) UNRELEASED; urgency=medium
[ Ben Hutchings ]
* [x86] Enable X86_INTEL_LPSS (Closes: #745331)
* [x86] thinkpad_acpi: Add support for X1 Carbon 2nd generation's adaptive
keyboard (Closes: #745252)
-- Ben Hutchings <ben@decadent.org.uk> Sun, 20 Apr 2014 21:54:54 +0100

View File

@ -0,0 +1,83 @@
From: Shuduo Sang <shuduo.sang@canonical.com>
Date: Thu, 27 Mar 2014 18:06:25 +0800
Subject: [2/2] save and restore adaptive keyboard mode for suspend and,resume
Origin: https://git.kernel.org/linus/330947b84382479459e5296a0024c670367b0b57
Dan Aloni has submitted a patch to set adaptive mode to function mode
when system resume back. Thanks Dan. :)
Following patch can make it to be restored to previous mode like What
Windows does.
Thanks,
Shuduo
>From 0ca960138518ceab23110141a0d7c0cafd54a859 Mon Sep 17 00:00:00 2001
From: Shuduo Sang <shuduo.sang@canonical.com>
Date: Thu, 27 Mar 2014 17:51:24 +0800
Subject: [PATCH] save and restore adaptive keyboard mode for suspend and
resume
The mode of adaptive keyboard on X1 Carbon need be saved first before
suspend then it can be restored after resume. Otherwise it will be
unusable.
Signed-off-by: Bruce Ma <bruce.ma@canonical.com>
Signed-off-by: Shuduo Sang <shuduo.sang@canonical.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
---
drivers/platform/x86/thinkpad_acpi.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index d0f2a53..18c9862 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3830,13 +3830,28 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
static void hotkey_suspend(void)
{
+ int hkeyv;
+
/* Do these on suspend, we get the events on early resume! */
hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
hotkey_autosleep_ack = 0;
+
+ /* save previous mode of adaptive keyboard of X1 Carbon */
+ if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
+ if ((hkeyv >> 8) == 2) {
+ if (!acpi_evalf(hkey_handle,
+ &adaptive_keyboard_prev_mode,
+ "GTRW", "dd", 0)) {
+ pr_err("Cannot read adaptive keyboard mode.\n");
+ }
+ }
+ }
}
static void hotkey_resume(void)
{
+ int hkeyv;
+
tpacpi_disable_brightness_delay();
if (hotkey_status_set(true) < 0 ||
@@ -3849,6 +3864,18 @@ static void hotkey_resume(void)
hotkey_wakeup_reason_notify_change();
hotkey_wakeup_hotunplug_complete_notify_change();
hotkey_poll_setup_safe(false);
+
+ /* restore previous mode of adapive keyboard of X1 Carbon */
+ if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
+ if ((hkeyv >> 8) == 2) {
+ if (!acpi_evalf(hkey_handle,
+ NULL,
+ "STRW", "vd",
+ adaptive_keyboard_prev_mode)) {
+ pr_err("Cannot set adaptive keyboard mode.\n");
+ }
+ }
+ }
}
/* procfs -------------------------------------------------------------- */

View File

@ -0,0 +1,147 @@
From: Shuduo Sang <shuduo.sang@canonical.com>
Date: Thu, 6 Mar 2014 18:20:46 +0800
Subject: [1/2] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
Origin: https://git.kernel.org/linus/3a9d20bda1d6daae9d81a4cc4cc67238c5574d31
Submit patch V4 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
generation according to Tobias's comments.
Thanks,
Shuduo
>From b153a7b14791c6e01892c0e274e23eefd625fb8d Mon Sep 17 00:00:00 2001
From: Shuduo Sang <shuduo.sang@canonical.com>
Date: Mon, 3 Mar 2014 14:29:32 +0800
Subject: [PATCH] support thinkpad X1 Carbon's adaptive keyboard
Thinkpad X1 Carbon's adaptive keyboard has five modes including Home
mode, Web browser mode, Web conference mode, Function mode and Lay-flat
mode. We support Home mode and Function mode currently.
Signed-off-by: Bruce Ma <bruce.ma@canonical.com>
Signed-off-by: Shuduo Sang <shuduo.sang@canonical.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
---
drivers/platform/x86/thinkpad_acpi.c | 102 +++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index dcc833a..d0f2a53 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3437,6 +3437,106 @@ err_exit:
return (res < 0)? res : 1;
}
+/* Thinkpad X1 Carbon support 5 modes including Home mode, Web browser
+ * mode, Web conference mode, Function mode and Lay-flat mode.
+ * We support Home mode and Function mode currently.
+ *
+ * Will consider support rest of modes in future.
+ *
+ */
+enum ADAPTIVE_KEY_MODE {
+ HOME_MODE,
+ WEB_BROWSER_MODE,
+ WEB_CONFERENCE_MODE,
+ FUNCTION_MODE,
+ LAYFLAT_MODE
+};
+
+const int adaptive_keyboard_modes[] = {
+ HOME_MODE,
+/* WEB_BROWSER_MODE = 2,
+ WEB_CONFERENCE_MODE = 3, */
+ FUNCTION_MODE
+};
+
+#define DFR_CHANGE_ROW 0x101
+#define DFR_SHOW_QUICKVIEW_ROW 0x102
+
+/* press Fn key a while second, it will switch to Function Mode. Then
+ * release Fn key, previous mode be restored.
+ */
+static bool adaptive_keyboard_mode_is_saved;
+static int adaptive_keyboard_prev_mode;
+
+static int adaptive_keyboard_get_next_mode(int mode)
+{
+ size_t i;
+ size_t max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1;
+
+ for (i = 0; i <= max_mode; i++) {
+ if (adaptive_keyboard_modes[i] == mode)
+ break;
+ }
+
+ if (i >= max_mode)
+ i = 0;
+ else
+ i++;
+
+ return adaptive_keyboard_modes[i];
+}
+
+static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
+{
+ u32 current_mode = 0;
+ int new_mode = 0;
+
+ switch (scancode) {
+ case DFR_CHANGE_ROW:
+ if (adaptive_keyboard_mode_is_saved) {
+ new_mode = adaptive_keyboard_prev_mode;
+ adaptive_keyboard_mode_is_saved = false;
+ } else {
+ if (!acpi_evalf(
+ hkey_handle, &current_mode,
+ "GTRW", "dd", 0)) {
+ pr_err("Cannot read adaptive keyboard mode\n");
+ return false;
+ } else {
+ new_mode = adaptive_keyboard_get_next_mode(
+ current_mode);
+ }
+ }
+
+ if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) {
+ pr_err("Cannot set adaptive keyboard mode\n");
+ return false;
+ }
+
+ return true;
+
+ case DFR_SHOW_QUICKVIEW_ROW:
+ if (!acpi_evalf(hkey_handle,
+ &adaptive_keyboard_prev_mode,
+ "GTRW", "dd", 0)) {
+ pr_err("Cannot read adaptive keyboard mode\n");
+ return false;
+ } else {
+ adaptive_keyboard_mode_is_saved = true;
+
+ if (!acpi_evalf(hkey_handle,
+ NULL, "STRW", "vd", FUNCTION_MODE)) {
+ pr_err("Cannot set adaptive keyboard mode\n");
+ return false;
+ }
+ }
+ return true;
+
+ default:
+ return false;
+ }
+}
+
static bool hotkey_notify_hotkey(const u32 hkey,
bool *send_acpi_ev,
bool *ignore_acpi_ev)
@@ -3456,6 +3556,8 @@ static bool hotkey_notify_hotkey(const u32 hkey,
*ignore_acpi_ev = true;
}
return true;
+ } else {
+ return adaptive_keyboard_hotkey_notify_hotkey(scancode);
}
return false;
}

View File

@ -71,3 +71,5 @@ features/all/x86-memtest-WARN-if-bad-RAM-found.patch
features/all/efi-autoload-efivars.patch
features/all/mvsas-Recognise-device-subsystem-9485-9485-as-88SE94.patch
bugfix/arm/bfa-Replace-large-udelay-with-mdelay.patch
features/all/support-Thinkpad-X1-Carbon-2nd-generation-s-adaptive.patch
features/all/save-and-restore-adaptive-keyboard-mode-for-suspend-.patch