All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] support Thinkpad X1 Carbon's adaptive keyboard
@ 2014-03-03 16:31 ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-03 16:31 UTC (permalink / raw)
  To: bjorn, ibm-acpi-devel, linux-acpi, linux-kernel, ibm-acpi,
	matthew.garrett, platform-driver-x86
  Cc: bruce.ma

Hi,

Support Thinkpad X1 Carbon's Adaptive keyboard patch version 2 is here.

Modified V1 patch's code according to Bjorn's comment.


Thanks,
Shuduo


>From fd2ab11002f3e5cb7fb9b26452db170e9835cde1 Mon Sep 17 00:00:00 2001
From: Shuduo Sang <sangshuduo@gmail.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>
---
 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 defb6af..fe2db4d 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
+};
+
+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.
+ */
+bool adaptive_keyboard_mode_is_saved;
+int adaptive_keybarod_prev_mode;
+
+static int adaptive_keyboard_get_next_mode(int mode)
+{
+	int i;
+	int 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_keybarod_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_keybarod_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;
 }
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V2] support Thinkpad X1 Carbon's adaptive keyboard
@ 2014-03-03 16:31 ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-03 16:31 UTC (permalink / raw)
  To: bjorn, ibm-acpi-devel, linux-acpi, linux-kernel, ibm-acpi,
	matthew.garrett, platform-driver-x86
  Cc: bruce.ma

Hi,

Support Thinkpad X1 Carbon's Adaptive keyboard patch version 2 is here.

Modified V1 patch's code according to Bjorn's comment.


Thanks,
Shuduo


From fd2ab11002f3e5cb7fb9b26452db170e9835cde1 Mon Sep 17 00:00:00 2001
From: Shuduo Sang <sangshuduo@gmail.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>
---
 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 defb6af..fe2db4d 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
+};
+
+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.
+ */
+bool adaptive_keyboard_mode_is_saved;
+int adaptive_keybarod_prev_mode;
+
+static int adaptive_keyboard_get_next_mode(int mode)
+{
+	int i;
+	int 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_keybarod_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_keybarod_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;
 }
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH V2] support Thinkpad X1 Carbon's adaptive keyboard
  2014-03-03 16:31 ` Shuduo Sang
  (?)
@ 2014-03-04  9:19 ` Tobias Klauser
  2014-03-04  9:47   ` Shuduo Sang
                     ` (2 more replies)
  -1 siblings, 3 replies; 14+ messages in thread
From: Tobias Klauser @ 2014-03-04  9:19 UTC (permalink / raw)
  To: Shuduo Sang
  Cc: bjorn, ibm-acpi-devel, linux-acpi, linux-kernel, ibm-acpi,
	matthew.garrett, platform-driver-x86, bruce.ma

On 2014-03-03 at 17:31:08 +0100, Shuduo Sang <shuduo.sang@canonical.com> wrote:
[...]
> +/* press Fn key a while second, it will switch to Function Mode. Then
> + * release Fn key, previous mode be restored.
> + */
> +bool adaptive_keyboard_mode_is_saved;
> +int adaptive_keybarod_prev_mode;

These should probably be made static, since they're only used inside the
module.

> +static int adaptive_keyboard_get_next_mode(int mode)
> +{
> +	int i;
> +	int max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1;

sizeof and thus ARRAY_SIZE returns a size_t, so i and max_mode could be
of type size_t as well.

> +
> +	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_keybarod_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_keybarod_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;
>  }
> -- 
> 1.9.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V2] support Thinkpad X1 Carbon's adaptive keyboard
  2014-03-04  9:19 ` Tobias Klauser
@ 2014-03-04  9:47   ` Shuduo Sang
  2014-03-04 11:13     ` Shuduo Sang
       [not found]   ` <20140304091916.GE1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-04  9:47 UTC (permalink / raw)
  To: Tobias Klauser
  Cc: bjorn, ibm-acpi-devel, linux-acpi, linux-kernel, ibm-acpi,
	matthew.garrett, platform-driver-x86, bruce.ma

Hi Tobias,

Thanks for your comments.

Shuduo

On 03/04/2014 05:19 PM, Tobias Klauser wrote:
> On 2014-03-03 at 17:31:08 +0100, Shuduo Sang <shuduo.sang@canonical.com> wrote:
> [...]
>> +/* press Fn key a while second, it will switch to Function Mode. Then
>> + * release Fn key, previous mode be restored.
>> + */
>> +bool adaptive_keyboard_mode_is_saved;
>> +int adaptive_keybarod_prev_mode;
> 
> These should probably be made static, since they're only used inside the
> module.
> 

Yes. Let me fix it in V3.

>> +static int adaptive_keyboard_get_next_mode(int mode)
>> +{
>> +	int i;
>> +	int max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1;
> 
> sizeof and thus ARRAY_SIZE returns a size_t, so i and max_mode could be
> of type size_t as well.
> 

Agree. Will fix in V3.

>> +
>> +	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_keybarod_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_keybarod_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;
>>  }
>> -- 
>> 1.9.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-04  9:19 ` Tobias Klauser
@ 2014-03-04 11:13     ` Shuduo Sang
  2014-03-04 11:13     ` Shuduo Sang
       [not found]   ` <20140304091916.GE1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-04 11:13 UTC (permalink / raw)
  To: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86, bruce.ma


Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
generation according to Tobias's comments.

Thanks,
Shuduo

>From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
From: Shuduo Sang <sangshuduo@gmail.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>
---
 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 defb6af..6664dcd 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
+};
+
+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)
+{
+	int 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;
 }
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
@ 2014-03-04 11:13     ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-04 11:13 UTC (permalink / raw)
  To: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86, bruce.ma


Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
generation according to Tobias's comments.

Thanks,
Shuduo

From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
From: Shuduo Sang <sangshuduo@gmail.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>
---
 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 defb6af..6664dcd 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
+};
+
+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)
+{
+	int 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;
 }
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-04 11:13     ` Shuduo Sang
  (?)
@ 2014-03-04 13:51     ` Tobias Klauser
       [not found]       ` <20140304135120.GF1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  -1 siblings, 1 reply; 14+ messages in thread
From: Tobias Klauser @ 2014-03-04 13:51 UTC (permalink / raw)
  To: Shuduo Sang
  Cc: bjorn, ibm-acpi-devel, linux-acpi, linux-kernel, ibm-acpi,
	matthew.garrett, platform-driver-x86, bruce.ma

On 2014-03-04 at 12:13:54 +0100, Shuduo Sang <shuduo.sang@canonical.com> wrote:
> 
> Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
> generation according to Tobias's comments.

It seems like I missed one in the previous comment, sorry. Also one
of the previous comments was only partially addressed in this updated
patch. See below for the comments...

> Thanks,
> Shuduo
> 
> From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
> From: Shuduo Sang <sangshuduo@gmail.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>
> ---
>  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 defb6af..6664dcd 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
> +};
> +
> +int adaptive_keyboard_modes[] = {
> +	HOME_MODE,
> +/*	WEB_BROWSER_MODE = 2,
> +	WEB_CONFERENCE_MODE = 3, */
> +	FUNCTION_MODE
> +};

This array can be made be static const.

> +
> +#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)
> +{
> +	int i;

This should be size_t as well, as mentioned in the previous comment.

> +	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;
>  }
> -- 
> 1.9.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
       [not found]       ` <20140304135120.GF1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
@ 2014-03-05  4:20         ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-05  4:20 UTC (permalink / raw)
  To: Tobias Klauser
  Cc: linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	ibm-acpi-N3TV7GIv+o9fyO9Q7EP/yw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	platform-driver-x86-u79uwXL29TY76Z2rM5mHXA,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Bruce Ma,
	matthew.garrett-+LlxwbBB2+6sTnJN9+BGXg, Bjørn Mork


[-- Attachment #1.1: Type: text/plain, Size: 5819 bytes --]

OK. I will modify them in V4. :)


On Tue, Mar 4, 2014 at 9:51 PM, Tobias Klauser <tklauser-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org> wrote:

> On 2014-03-04 at 12:13:54 +0100, Shuduo Sang <shuduo.sang-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> wrote:
> >
> > Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
> > generation according to Tobias's comments.
>
> It seems like I missed one in the previous comment, sorry. Also one
> of the previous comments was only partially addressed in this updated
> patch. See below for the comments...
>
> > Thanks,
> > Shuduo
> >
> > From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
> > From: Shuduo Sang <sangshuduo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > 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-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> > Signed-off-by: Shuduo Sang <shuduo.sang-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
> > ---
> >  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 defb6af..6664dcd 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
> > +};
> > +
> > +int adaptive_keyboard_modes[] = {
> > +     HOME_MODE,
> > +/*   WEB_BROWSER_MODE = 2,
> > +     WEB_CONFERENCE_MODE = 3, */
> > +     FUNCTION_MODE
> > +};
>
> This array can be made be static const.
>
> > +
> > +#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)
> > +{
> > +     int i;
>
> This should be size_t as well, as mentioned in the previous comment.
>
> > +     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;
> >  }
> > --
> > 1.9.0
> >
>

[-- Attachment #1.2: Type: text/html, Size: 7613 bytes --]

[-- Attachment #2: Type: text/plain, Size: 451 bytes --]

------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
ibm-acpi-devel mailing list
ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/ibm-acpi-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-04 11:13     ` Shuduo Sang
  (?)
  (?)
@ 2014-03-05  5:54     ` SeongJae Park
  2014-03-05  6:35       ` Shuduo Sang
  -1 siblings, 1 reply; 14+ messages in thread
From: SeongJae Park @ 2014-03-05  5:54 UTC (permalink / raw)
  To: Shuduo Sang
  Cc: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86, bruce.ma

Hello,
This is just a trivial comment.


On Tue, Mar 4, 2014 at 8:13 PM, Shuduo Sang <shuduo.sang@canonical.com> wrote:
>
>
> Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
> generation according to Tobias's comments.
>
> Thanks,
> Shuduo
>
> From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
> From: Shuduo Sang <sangshuduo@gmail.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>
> ---
>  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 defb6af..6664dcd 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
> +};
> +
> +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)
> +{
> +       int 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;

Isn't the blank line above return statement unnecessary?

> +
> +       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;
>  }
> --
> 1.9.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-05  5:54     ` SeongJae Park
@ 2014-03-05  6:35       ` Shuduo Sang
  2014-03-05  7:06         ` SeongJae Park
  0 siblings, 1 reply; 14+ messages in thread
From: Shuduo Sang @ 2014-03-05  6:35 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86, bruce.ma



On 03/05/2014 01:54 PM, SeongJae Park wrote:
> Hello,
> This is just a trivial comment.
> 
> 
> On Tue, Mar 4, 2014 at 8:13 PM, Shuduo Sang <shuduo.sang@canonical.com> wrote:
>>
>>
>> Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
>> generation according to Tobias's comments.
>>
>> Thanks,
>> Shuduo
>>
>> From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
>> From: Shuduo Sang <sangshuduo@gmail.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>
>> ---
>>  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 defb6af..6664dcd 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
>> +};
>> +
>> +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)
>> +{
>> +       int 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;
> 
> Isn't the blank line above return statement unnecessary?
> 

Doesn't it look clearly? :)

>> +
>> +       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;
>>  }
>> --
>> 1.9.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH V3] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-05  6:35       ` Shuduo Sang
@ 2014-03-05  7:06         ` SeongJae Park
  0 siblings, 0 replies; 14+ messages in thread
From: SeongJae Park @ 2014-03-05  7:06 UTC (permalink / raw)
  To: Shuduo Sang
  Cc: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86, Bruce Ma

On Wed, Mar 5, 2014 at 3:35 PM, Shuduo Sang <shuduo.sang@canonical.com> wrote:
>
>
> On 03/05/2014 01:54 PM, SeongJae Park wrote:
>> Hello,
>> This is just a trivial comment.
>>
>>
>> On Tue, Mar 4, 2014 at 8:13 PM, Shuduo Sang <shuduo.sang@canonical.com> wrote:
>>>
>>>
>>> Submit patch V3 to support Adaptive Keyboard on Thinkpad X1 Carbon 2nd
>>> generation according to Tobias's comments.
>>>
>>> Thanks,
>>> Shuduo
>>>
>>> From 2b8175e69deee661d97d371b2422a9c192fefd52 Mon Sep 17 00:00:00 2001
>>> From: Shuduo Sang <sangshuduo@gmail.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>
>>> ---
>>>  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 defb6af..6664dcd 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
>>> +};
>>> +
>>> +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)
>>> +{
>>> +       int 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;
>>
>> Isn't the blank line above return statement unnecessary?
>>
>
> Doesn't it look clearly? :)

Well, I thought it might be unintended blank line because
the return statement in below case doesn't have blank line.
Anyway, I agree if it was your intention.

>
>>> +
>>> +       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;
>>>  }
>>> --
>>> 1.9.0
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH V4] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
  2014-03-04  9:19 ` Tobias Klauser
  2014-03-04  9:47   ` Shuduo Sang
@ 2014-03-06 10:20       ` Shuduo Sang
       [not found]   ` <20140304091916.GE1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-06 10:20 UTC (permalink / raw)
  To: Tobias Klauser, bjorn-yOkvZcmFvRU,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	ibm-acpi-N3TV7GIv+o9fyO9Q7EP/yw,
	matthew.garrett-+LlxwbBB2+6sTnJN9+BGXg,
	platform-driver-x86-u79uwXL29TY76Z2rM5mHXA
  Cc: bruce.ma-Z7WLFzj8eWMS+FvcfC7Uqw


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-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
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-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Signed-off-by: Shuduo Sang <shuduo.sang-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
---
 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 defb6af..f4978fa 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;
 }
-- 
1.9.0


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V4] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
@ 2014-03-06 10:20       ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-06 10:20 UTC (permalink / raw)
  To: Tobias Klauser, bjorn, ibm-acpi-devel, linux-acpi, linux-kernel,
	ibm-acpi, matthew.garrett, platform-driver-x86
  Cc: bruce.ma


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>
---
 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 defb6af..f4978fa 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;
 }
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH V4] support Thinkpad X1 Carbon 2nd generation's adaptive keyboard
@ 2014-03-06 10:20       ` Shuduo Sang
  0 siblings, 0 replies; 14+ messages in thread
From: Shuduo Sang @ 2014-03-06 10:20 UTC (permalink / raw)
  To: Tobias Klauser, bjorn-yOkvZcmFvRU,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	ibm-acpi-N3TV7GIv+o9fyO9Q7EP/yw,
	matthew.garrett-+LlxwbBB2+6sTnJN9+BGXg,
	platform-driver-x86-u79uwXL29TY76Z2rM5mHXA
  Cc: bruce.ma-Z7WLFzj8eWMS+FvcfC7Uqw


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-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
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-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Signed-off-by: Shuduo Sang <shuduo.sang-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
---
 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 defb6af..f4978fa 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;
 }
-- 
1.9.0


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-03-06 10:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-03 16:31 [PATCH V2] support Thinkpad X1 Carbon's adaptive keyboard Shuduo Sang
2014-03-03 16:31 ` Shuduo Sang
2014-03-04  9:19 ` Tobias Klauser
2014-03-04  9:47   ` Shuduo Sang
2014-03-04 11:13   ` [PATCH V3] support Thinkpad X1 Carbon 2nd generation's " Shuduo Sang
2014-03-04 11:13     ` Shuduo Sang
2014-03-04 13:51     ` Tobias Klauser
     [not found]       ` <20140304135120.GF1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
2014-03-05  4:20         ` Shuduo Sang
2014-03-05  5:54     ` SeongJae Park
2014-03-05  6:35       ` Shuduo Sang
2014-03-05  7:06         ` SeongJae Park
     [not found]   ` <20140304091916.GE1883-93Khv+1bN0NyDzI6CaY1VQ@public.gmane.org>
2014-03-06 10:20     ` [PATCH V4] " Shuduo Sang
2014-03-06 10:20       ` Shuduo Sang
2014-03-06 10:20       ` Shuduo Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.