All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ideapad-laptop: add support for Yoga 3 ESC key
@ 2015-11-06 21:28 Arnd Bergmann
  2015-11-06 22:26 ` [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist Arnd Bergmann
  2015-11-09 21:46 ` [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Darren Hart
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2015-11-06 21:28 UTC (permalink / raw)
  To: platform-driver-x86, Ike Panhc; +Cc: Darren Hart, linux-kernel

The ideapad-laptop handles most special keys on various Lenovo Laptops
including the Yoga line. Unfortunately, the Yoga 3 11/13/14 models have
one important exception, which is the Fn-ESC combination.

On other Lenovo Laptops, this is FnLock, which switches the function keys
between the primary (Mute, Vol down, Vol up, ...) and the secondary (F1,
F2, F3, ...) behavior. On the new machines, FnLock is only available
through BIOS setup (possibly through a yet-to-be-implemented feature
in this driver) but not through Fn-ESC, but instead the ESC key itself
switched between ESC and a "Paper Display" app for Windows.

Unfortunately, that means that you can never have both ESC *and* the
function keys working at the same time without needing to press Fn on
one of them.
As pointed out in the official Lenovo Forum by dozens of users, this
makes the machine rather useless for any serious work [1].

I have now studied the ACPI DSDT one more time and found the event
that is generated for the ESC key. Unlike all other key events on this
machine, it is actually a WMI, while the other ones are read from the
embedded controller.

I am now installing a WMI notifier that uses the event number from the
WMI subsystem as the scancode. The only event number generated here is
'128', and that fits in nicely with the two existing ranges of scancodes
used by the EC: 0-15 for the 16-bit VPCCMD_R_VPC register, 16-17 for
the VPCCMD_R_NOVO register and 64-67 for VPCCMD_R_SPECIAL_BUTTONS.

The only sane way to handle this button (in absence of the Windows Paper
Display driver) seems to be to have it emit KEY_ESC, so that is what
I use as the default. Should any user ever want to overwrite the default,
they can install their own keymap.

To ensure that we can still build the driver without adding a CONFIG_WMI
dependency, all new code is enclosed in #ifdef.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

[1] https://forums.lenovo.com/t5/Lenovo-Yoga-Series-Notebooks/YOGA-3-14-How-to-reclaim-my-Esc-key-and-permanently-disable/td-p/2070816

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 02bbc70c332d..1089eaa02b00 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -345,6 +345,7 @@ config IDEAPAD_LAPTOP
 	depends on SERIO_I8042
 	depends on BACKLIGHT_CLASS_DEVICE
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
+	depends on ACPI_WMI || ACPI_WMI = n
 	select INPUT_SPARSEKMAP
 	help
 	  This is a driver for Lenovo IdeaPad netbooks contains drivers for
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index ad4b8b7e97cc..231db03a6417 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -47,6 +47,10 @@
 #define CFG_WIFI_BIT	(18)
 #define CFG_CAMERA_BIT	(19)
 
+#if IS_ENABLED(CONFIG_ACPI_WMI)
+static const char ideapad_wmi_fnesc_event[] = "26CAB2E5-5CF1-46AE-AAC3-4A12B6BA50E6";
+#endif
+
 enum {
 	VPCCMD_R_VPC1 = 0x10,
 	VPCCMD_R_BL_MAX,
@@ -567,6 +571,8 @@ static const struct key_entry ideapad_keymap[] = {
 	{ KE_KEY, 65, { KEY_PROG4 } },
 	{ KE_KEY, 66, { KEY_TOUCHPAD_OFF } },
 	{ KE_KEY, 67, { KEY_TOUCHPAD_ON } },
+	{ KE_KEY, 128, { KEY_ESC } },
+
 	{ KE_END, 0 },
 };
 
@@ -825,6 +831,19 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
 	}
 }
 
+#if IS_ENABLED(CONFIG_ACPI_WMI)
+static void ideapad_wmi_notify(u32 value, void *context)
+{
+	switch (value) {
+	case 128:
+		ideapad_input_report(context, value);
+		break;
+	default:
+		pr_info("Unknown WMI event %u\n", value);
+	}
+}
+#endif
+
 /*
  * Some ideapads don't have a hardware rfkill switch, reading VPCCMD_R_RF
  * always results in 0 on these models, causing ideapad_laptop to wrongly
@@ -942,8 +961,18 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 		ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv);
 	if (ret)
 		goto notification_failed;
+#if IS_ENABLED(CONFIG_ACPI_WMI)
+	ret = wmi_install_notify_handler(ideapad_wmi_fnesc_event, ideapad_wmi_notify, priv);
+	if (ret != AE_OK && ret != AE_NOT_EXIST)
+		goto notification_failed_wmi;
+#endif
 
 	return 0;
+#if IS_ENABLED(CONFIG_ACPI_WMI)
+notification_failed_wmi:
+	acpi_remove_notify_handler(priv->adev->handle,
+		ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
+#endif
 notification_failed:
 	ideapad_backlight_exit(priv);
 backlight_failed:
@@ -962,6 +991,9 @@ static int ideapad_acpi_remove(struct platform_device *pdev)
 	struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
 	int i;
 
+#if IS_ENABLED(CONFIG_ACPI_WMI)
+	wmi_remove_notify_handler(ideapad_wmi_fnesc_event);
+#endif
 	acpi_remove_notify_handler(priv->adev->handle,
 		ACPI_DEVICE_NOTIFY, ideapad_acpi_notify);
 	ideapad_backlight_exit(priv);


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

* [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist
  2015-11-06 21:28 [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Arnd Bergmann
@ 2015-11-06 22:26 ` Arnd Bergmann
  2015-11-09 21:46   ` Darren Hart
  2015-11-09 21:46 ` [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Darren Hart
  1 sibling, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2015-11-06 22:26 UTC (permalink / raw)
  To: platform-driver-x86; +Cc: Ike Panhc, Darren Hart, linux-kernel

This changes the entry to the whitelist of machines that do not have
a physical rfkill switch. Unfortunately, the Yoga 3 generation seems
to use upper-case letters for the YOGA 3 Pro-1370, while it uses normal
capitalization for its Yoga 3 1170 and 1470 siblings.

In order to catch all variants of the Yoga 3, I'm changing both
the entry for the 1470 (using "Yoga" as the name) and the entry for
the Pro 1370 (using all-caps "YOGA") to not match the exact model number
but only the generation. This way, the 1170 and 1470 models share one
entry, but if the firmware changes from one format to the other, it will
still work.

The second entry for Yoga 2 Pro that was recently added for some
reason ended up not being added in alphanumeric order, and I'm
moving the Yoga 3 1470 entry down while making the change, so they
are sorted more logically.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I realized that this patch didn't make it in when I sent it back in may.
I have adapted it to the changes that happened since.

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index db76d011bedd..c11f40f37bd0 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -872,24 +872,24 @@ static const struct dmi_system_id no_hw_rfkill_list[] = {
 		},
 	},
 	{
-		.ident = "Lenovo Yoga 3 14",
+		.ident = "Lenovo Yoga 2 11 / 13 / Pro",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 3 14"),
+			DMI_MATCH(DMI_BOARD_NAME, "Yoga2"),
 		},
 	},
 	{
-		.ident = "Lenovo Yoga 2 11 / 13 / Pro",
+		.ident = "Lenovo Yoga 3 1170 / 1470",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-			DMI_MATCH(DMI_BOARD_NAME, "Yoga2"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 3"),
 		},
 	},
 	{
 		.ident = "Lenovo Yoga 3 Pro 1370",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3 Pro-1370"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3"),
 		},
 	},
 	{}


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

* Re: [PATCH] ideapad-laptop: add support for Yoga 3 ESC key
  2015-11-06 21:28 [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Arnd Bergmann
  2015-11-06 22:26 ` [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist Arnd Bergmann
@ 2015-11-09 21:46 ` Darren Hart
  1 sibling, 0 replies; 4+ messages in thread
From: Darren Hart @ 2015-11-09 21:46 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: platform-driver-x86, Ike Panhc, linux-kernel

On Fri, Nov 06, 2015 at 10:28:49PM +0100, Arnd Bergmann wrote:
> The ideapad-laptop handles most special keys on various Lenovo Laptops
> including the Yoga line. Unfortunately, the Yoga 3 11/13/14 models have
> one important exception, which is the Fn-ESC combination.
> 
> On other Lenovo Laptops, this is FnLock, which switches the function keys
> between the primary (Mute, Vol down, Vol up, ...) and the secondary (F1,
> F2, F3, ...) behavior. On the new machines, FnLock is only available
> through BIOS setup (possibly through a yet-to-be-implemented feature
> in this driver) but not through Fn-ESC, but instead the ESC key itself
> switched between ESC and a "Paper Display" app for Windows.
> 
> Unfortunately, that means that you can never have both ESC *and* the
> function keys working at the same time without needing to press Fn on
> one of them.
> As pointed out in the official Lenovo Forum by dozens of users, this
> makes the machine rather useless for any serious work [1].
> 
> I have now studied the ACPI DSDT one more time and found the event
> that is generated for the ESC key. Unlike all other key events on this
> machine, it is actually a WMI, while the other ones are read from the
> embedded controller.
> 
> I am now installing a WMI notifier that uses the event number from the
> WMI subsystem as the scancode. The only event number generated here is
> '128', and that fits in nicely with the two existing ranges of scancodes
> used by the EC: 0-15 for the 16-bit VPCCMD_R_VPC register, 16-17 for
> the VPCCMD_R_NOVO register and 64-67 for VPCCMD_R_SPECIAL_BUTTONS.
> 
> The only sane way to handle this button (in absence of the Windows Paper
> Display driver) seems to be to have it emit KEY_ESC, so that is what
> I use as the default. Should any user ever want to overwrite the default,
> they can install their own keymap.
> 
> To ensure that we can still build the driver without adding a CONFIG_WMI
> dependency, all new code is enclosed in #ifdef.

I'm not thrilled with the ifdefs, but whether that's worse than the CONFIG_WMI
dependency or not... I'm not prepared to argue, so I'm siding with you :-)

> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 
> [1] https://forums.lenovo.com/t5/Lenovo-Yoga-Series-Notebooks/YOGA-3-14-How-to-reclaim-my-Esc-key-and-permanently-disable/td-p/2070816
> 

Queued to testing, thanks Arnd.
-- 
Darren Hart
Intel Open Source Technology Center

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

* Re: [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist
  2015-11-06 22:26 ` [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist Arnd Bergmann
@ 2015-11-09 21:46   ` Darren Hart
  0 siblings, 0 replies; 4+ messages in thread
From: Darren Hart @ 2015-11-09 21:46 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: platform-driver-x86, Ike Panhc, linux-kernel

On Fri, Nov 06, 2015 at 11:26:59PM +0100, Arnd Bergmann wrote:
> This changes the entry to the whitelist of machines that do not have
> a physical rfkill switch. Unfortunately, the Yoga 3 generation seems
> to use upper-case letters for the YOGA 3 Pro-1370, while it uses normal
> capitalization for its Yoga 3 1170 and 1470 siblings.
> 
> In order to catch all variants of the Yoga 3, I'm changing both
> the entry for the 1470 (using "Yoga" as the name) and the entry for
> the Pro 1370 (using all-caps "YOGA") to not match the exact model number
> but only the generation. This way, the 1170 and 1470 models share one
> entry, but if the firmware changes from one format to the other, it will
> still work.
> 
> The second entry for Yoga 2 Pro that was recently added for some
> reason ended up not being added in alphanumeric order, and I'm
> moving the Yoga 3 1470 entry down while making the change, so they
> are sorted more logically.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Queued to testing, thank you.

-- 
Darren Hart
Intel Open Source Technology Center

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

end of thread, other threads:[~2015-11-09 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-06 21:28 [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Arnd Bergmann
2015-11-06 22:26 ` [PATCH] ideapad-laptop: include Yoga 3 1170 in add rfkill whitelist Arnd Bergmann
2015-11-09 21:46   ` Darren Hart
2015-11-09 21:46 ` [PATCH] ideapad-laptop: add support for Yoga 3 ESC key Darren Hart

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.