All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case
@ 2017-02-28 16:10 Christian Kellner
  2017-02-28 16:10 ` [PATCH v2 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys Christian Kellner
       [not found] ` <20170228161057.28394-1-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Kellner @ 2017-02-28 16:10 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh, Darren Hart, Andy Shevchenko,
	ibm-acpi-devel, platform-driver-x86
  Cc: Christian Kellner, Christian Kellner

From: Christian Kellner <christian@kellner.me>

Currently when dispatching hotkeys we check if the scancode is in
the range of 0 and TPACPI_HOTKEY_MAP_LEN, although the bottom 20
entries in the hotkey keymap are already adaptive keycodes.
Therefore we introduce a TP_ACPI_HOTKEYSCAN_ADAPTIVE_START and
ensure that we are in the range 0 and ADAPTIVE_START for the generic
keycode case.

Signed-off-by: Christian Kellner <ckellner@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Don't initialize TP_ACPI_HOTKEYSCAN_ADAPTIVE_START manually, but use
  it to initialize TP_ACPI_HOTKEYSCAN_MUTE2
- Add a comment before the adaptive keycodes block
---
 drivers/platform/x86/thinkpad_acpi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 1d18b32628ec..e2b962f0fdc4 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -1922,7 +1922,9 @@ enum {	/* hot key scan codes (derived from ACPI DSDT) */
 	TP_ACPI_HOTKEYSCAN_UNK7,
 	TP_ACPI_HOTKEYSCAN_UNK8,
 
-	TP_ACPI_HOTKEYSCAN_MUTE2,
+	/* Adaptive keyboard keycodes */
+	TP_ACPI_HOTKEYSCAN_ADAPTIVE_START,
+	TP_ACPI_HOTKEYSCAN_MUTE2        = TP_ACPI_HOTKEYSCAN_ADAPTIVE_START,
 	TP_ACPI_HOTKEYSCAN_BRIGHTNESS_ZERO,
 	TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL,
 	TP_ACPI_HOTKEYSCAN_CLOUD,
@@ -3656,7 +3658,6 @@ static const int adaptive_keyboard_modes[] = {
 #define DFR_CHANGE_ROW			0x101
 #define DFR_SHOW_QUICKVIEW_ROW		0x102
 #define FIRST_ADAPTIVE_KEY		0x103
-#define ADAPTIVE_KEY_OFFSET		0x020
 
 /* press Fn key a while second, it will switch to Function Mode. Then
  * release Fn key, previous mode be restored.
@@ -3747,12 +3748,13 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
 	default:
 		if (scancode < FIRST_ADAPTIVE_KEY ||
 		    scancode >= FIRST_ADAPTIVE_KEY + TPACPI_HOTKEY_MAP_LEN -
-				ADAPTIVE_KEY_OFFSET) {
+				TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
 			pr_info("Unhandled adaptive keyboard key: 0x%x\n",
 					scancode);
 			return false;
 		}
-		keycode = hotkey_keycode_map[scancode - FIRST_ADAPTIVE_KEY + ADAPTIVE_KEY_OFFSET];
+		keycode = hotkey_keycode_map[scancode - FIRST_ADAPTIVE_KEY +
+					     TP_ACPI_HOTKEYSCAN_ADAPTIVE_START];
 		if (keycode != KEY_RESERVED) {
 			mutex_lock(&tpacpi_inputdev_send_mutex);
 
@@ -3778,7 +3780,7 @@ static bool hotkey_notify_hotkey(const u32 hkey,
 	*ignore_acpi_ev = false;
 
 	/* HKEY event 0x1001 is scancode 0x00 */
-	if (scancode > 0 && scancode <= TPACPI_HOTKEY_MAP_LEN) {
+	if (scancode > 0 && scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
 		scancode--;
 		if (!(hotkey_source_mask & (1 << scancode))) {
 			tpacpi_input_send_key_masked(scancode);
-- 
2.11.1

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

* [PATCH v2 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys
  2017-02-28 16:10 [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case Christian Kellner
@ 2017-02-28 16:10 ` Christian Kellner
       [not found]   ` <20170228161057.28394-2-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
       [not found] ` <20170228161057.28394-1-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Christian Kellner @ 2017-02-28 16:10 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh, Darren Hart, Andy Shevchenko,
	ibm-acpi-devel, platform-driver-x86
  Cc: Christian Kellner, Christian Kellner

From: Christian Kellner <christian@kellner.me>

The T470, X270 emits new hkey events in the 0x1311 - 0x1315 range.
According to the user manual they should launch a user selected
favorite application (star icon, 0x1311), snipping tool (0x1312,
currently ignored), enable/disable bluetooth (0x1314) and open they
keyboard settings (0x1315).

The third nibble (0xf00) is used to differentiate between the original
hotkeys, the adaptive keyboard codes and the new, additional ones.

Signed-off-by: Christian Kellner <ckellner@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Reword comments to also mention the X270
-No need to initialize TP_ACPI_HOTKEYSCAN_EXTENDED_START to '52'
---
 drivers/platform/x86/thinkpad_acpi.c | 91 +++++++++++++++++++++++++++++++-----
 1 file changed, 79 insertions(+), 12 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index e2b962f0fdc4..7b6cb0c69b02 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -1945,6 +1945,15 @@ enum {	/* hot key scan codes (derived from ACPI DSDT) */
 	TP_ACPI_HOTKEYSCAN_CAMERA_MODE,
 	TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY,
 
+	/* Lenovo extended keymap, starting at 0x1300 */
+	TP_ACPI_HOTKEYSCAN_EXTENDED_START,
+	/* first new observed key (star, favorites) is 0x1311 */
+	TP_ACPI_HOTKEYSCAN_STAR = 69,
+	TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2,
+	TP_ACPI_HOTKEYSCAN_UNK25,
+	TP_ACPI_HOTKEYSCAN_BLUETOOTH,
+	TP_ACPI_HOTKEYSCAN_KEYBOARD,
+
 	/* Hotkey keymap size */
 	TPACPI_HOTKEY_MAP_LEN
 };
@@ -3252,6 +3261,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+
+		/* No assignment, used for newer Lenovo models */
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN
+
 		},
 
 	/* Generic keymap for Lenovo ThinkPads */
@@ -3337,6 +3355,29 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 		KEY_RESERVED,        /* Microphone cancellation */
 		KEY_RESERVED,        /* Camera mode */
 		KEY_RESERVED,        /* Rotate display, 0x116 */
+
+		/*
+		 * These are found in 2017 models (e.g. T470s, X270).
+		 * The lowest known value is 0x311, which according to
+		 * the manual should launch a user defined favorite
+		 * application.
+		 *
+		 * The offset for these is TP_ACPI_HOTKEYSCAN_EXTENDED_START,
+		 * corresponding to 0x34.
+		 */
+
+		/* (assignments unknown, please report if found) */
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+		KEY_UNKNOWN,
+
+		KEY_FAVORITES,       /* Favorite app, 0x311 */
+		KEY_RESERVED,        /* Clipping tool */
+		KEY_RESERVED,
+		KEY_BLUETOOTH,       /* Bluetooth */
+		KEY_KEYBOARD         /* Keyboard, 0x315 */
 		},
 	};
 
@@ -3747,8 +3788,9 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
 
 	default:
 		if (scancode < FIRST_ADAPTIVE_KEY ||
-		    scancode >= FIRST_ADAPTIVE_KEY + TPACPI_HOTKEY_MAP_LEN -
-				TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
+		    scancode >= FIRST_ADAPTIVE_KEY +
+		    TP_ACPI_HOTKEYSCAN_EXTENDED_START -
+		    TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
 			pr_info("Unhandled adaptive keyboard key: 0x%x\n",
 					scancode);
 			return false;
@@ -3779,19 +3821,44 @@ static bool hotkey_notify_hotkey(const u32 hkey,
 	*send_acpi_ev = true;
 	*ignore_acpi_ev = false;
 
-	/* HKEY event 0x1001 is scancode 0x00 */
-	if (scancode > 0 && scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
-		scancode--;
-		if (!(hotkey_source_mask & (1 << scancode))) {
-			tpacpi_input_send_key_masked(scancode);
-			*send_acpi_ev = false;
-		} else {
-			*ignore_acpi_ev = true;
+	/*
+	 * Original events are in the 0x10XX range, the adaptive keyboard
+	 * found in 2014 X1 Carbon emits events are of 0x11XX. In 2017
+	 * models, additional keys are emitted through 0x13XX.
+	 */
+	switch ((hkey >> 8) & 0xf) {
+	case 0:
+		if (scancode > 0 &&
+		    scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
+			/* HKEY event 0x1001 is scancode 0x00 */
+			scancode--;
+			if (!(hotkey_source_mask & (1 << scancode))) {
+				tpacpi_input_send_key_masked(scancode);
+				*send_acpi_ev = false;
+			} else {
+				*ignore_acpi_ev = true;
+			}
+			return true;
 		}
-		return true;
-	} else {
+		break;
+
+	case 1:
 		return adaptive_keyboard_hotkey_notify_hotkey(scancode);
+
+	case 3:
+		/* Extended keycodes start at 0x300 and our offset into the map
+		 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
+		 * will be positive, but might not be in the correct range.
+		 */
+		scancode -= (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
+		if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
+		    scancode < TPACPI_HOTKEY_MAP_LEN) {
+			tpacpi_input_send_key(scancode);
+			return true;
+		}
+		break;
 	}
+
 	return false;
 }
 
-- 
2.11.1

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

* Re: [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case
       [not found] ` <20170228161057.28394-1-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2017-02-28 20:02   ` Henrique de Moraes Holschuh
  2017-03-03 18:28     ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Henrique de Moraes Holschuh @ 2017-02-28 20:02 UTC (permalink / raw)
  To: Christian Kellner
  Cc: Darren Hart, Christian Kellner,
	platform-driver-x86-u79uwXL29TY76Z2rM5mHXA, Andy Shevchenko,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Tue, 28 Feb 2017, Christian Kellner wrote:
> From: Christian Kellner <christian-NSKU5diinRdBDLzU/O5InQ@public.gmane.org>
> 
> Currently when dispatching hotkeys we check if the scancode is in
> the range of 0 and TPACPI_HOTKEY_MAP_LEN, although the bottom 20
> entries in the hotkey keymap are already adaptive keycodes.
> Therefore we introduce a TP_ACPI_HOTKEYSCAN_ADAPTIVE_START and
> ensure that we are in the range 0 and ADAPTIVE_START for the generic
> keycode case.
> 
> Signed-off-by: Christian Kellner <ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Reviewed-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Acked-by: Henrique de Moraes Holschuh <hmh-N3TV7GIv+o9fyO9Q7EP/yw@public.gmane.org>


-- 
  Henrique Holschuh

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

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

* Re: [PATCH v2 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys
       [not found]   ` <20170228161057.28394-2-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2017-02-28 20:03     ` Henrique de Moraes Holschuh
  0 siblings, 0 replies; 5+ messages in thread
From: Henrique de Moraes Holschuh @ 2017-02-28 20:03 UTC (permalink / raw)
  To: Christian Kellner
  Cc: Darren Hart, Christian Kellner,
	platform-driver-x86-u79uwXL29TY76Z2rM5mHXA, Andy Shevchenko,
	ibm-acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

On Tue, 28 Feb 2017, Christian Kellner wrote:
> From: Christian Kellner <christian-NSKU5diinRdBDLzU/O5InQ@public.gmane.org>
> 
> The T470, X270 emits new hkey events in the 0x1311 - 0x1315 range.
> According to the user manual they should launch a user selected
> favorite application (star icon, 0x1311), snipping tool (0x1312,
> currently ignored), enable/disable bluetooth (0x1314) and open they
> keyboard settings (0x1315).
> 
> The third nibble (0xf00) is used to differentiate between the original
> hotkeys, the adaptive keyboard codes and the new, additional ones.
> 
> Signed-off-by: Christian Kellner <ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> Reviewed-by: Hans de Goede <hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Acked-by: Henrique de Moraes Holschuh <hmh-N3TV7GIv+o9fyO9Q7EP/yw@public.gmane.org>

-- 
  Henrique Holschuh

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

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

* Re: [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case
  2017-02-28 20:02   ` [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case Henrique de Moraes Holschuh
@ 2017-03-03 18:28     ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2017-03-03 18:28 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh
  Cc: Christian Kellner, Darren Hart, Andy Shevchenko, ibm-acpi-devel,
	Platform Driver, Christian Kellner

On Tue, Feb 28, 2017 at 10:02 PM, Henrique de Moraes Holschuh
<hmh@hmh.eng.br> wrote:
> On Tue, 28 Feb 2017, Christian Kellner wrote:
>> From: Christian Kellner <christian@kellner.me>
>>
>> Currently when dispatching hotkeys we check if the scancode is in
>> the range of 0 and TPACPI_HOTKEY_MAP_LEN, although the bottom 20
>> entries in the hotkey keymap are already adaptive keycodes.
>> Therefore we introduce a TP_ACPI_HOTKEYSCAN_ADAPTIVE_START and
>> ensure that we are in the range 0 and ADAPTIVE_START for the generic
>> keycode case.
>>
>> Signed-off-by: Christian Kellner <ckellner@redhat.com>
>> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
>
> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>

Both pushed to testing.
Thanks.

-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2017-03-03 18:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 16:10 [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case Christian Kellner
2017-02-28 16:10 ` [PATCH v2 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys Christian Kellner
     [not found]   ` <20170228161057.28394-2-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-02-28 20:03     ` Henrique de Moraes Holschuh
     [not found] ` <20170228161057.28394-1-ckellner-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-02-28 20:02   ` [PATCH v2 1/2] platform/x86: thinkpad_acpi: guard generic hotkey case Henrique de Moraes Holschuh
2017-03-03 18:28     ` Andy Shevchenko

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.