diff mbox

[v2] thinkpad_acpi: Add support for HKEY version 0x200

Message ID 1465397665-9343-1-git-send-email-cpaul@redhat.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

cpaul@redhat.com June 8, 2016, 2:54 p.m. UTC
From: Dennis Wassenberg <dennis.wassenberg@secunet.com>

Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
HKEY version 0x200 without adaptive keyboard.

HKEY version 0x200 has method MHKA with one parameter value.
Passing parameter value 1 will get hotkey_all_mask (the same like
HKEY version 0x100 without parameter). Passing parameter value 2 to
MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
that case there is no adaptive keyboard available.

Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
Signed-off-by: Lyude <cpaul@redhat.com>
Tested-by: Lyude <cpaul@redhat.com>
Tested-by: Marco Trevisan <marco@ubuntu.com>
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
---
Changes since v1:
 - Fix all of the indenting issues
 - Add appropriate Tested-by's, Signed-off's, etc.

 drivers/platform/x86/thinkpad_acpi.c | 85 ++++++++++++++++++++++++++----------
 1 file changed, 63 insertions(+), 22 deletions(-)

Comments

Darren Hart June 8, 2016, 7:30 p.m. UTC | #1
On Wed, Jun 08, 2016 at 10:54:25AM -0400, Lyude wrote:
> From: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> 
> Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
> HKEY version 0x200 without adaptive keyboard.
> 
> HKEY version 0x200 has method MHKA with one parameter value.
> Passing parameter value 1 will get hotkey_all_mask (the same like
> HKEY version 0x100 without parameter). Passing parameter value 2 to
> MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
> that case there is no adaptive keyboard available.
> 
> Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> Signed-off-by: Lyude <cpaul@redhat.com>
> Tested-by: Lyude <cpaul@redhat.com>
> Tested-by: Marco Trevisan <marco@ubuntu.com>
> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
> ---
> Changes since v1:
>  - Fix all of the indenting issues
>  - Add appropriate Tested-by's, Signed-off's, etc.
> 
>  drivers/platform/x86/thinkpad_acpi.c | 85 ++++++++++++++++++++++++++----------
>  1 file changed, 63 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 9255ff3..210ecf5 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -2043,6 +2043,7 @@ static int hotkey_autosleep_ack;
>  
>  static u32 hotkey_orig_mask;		/* events the BIOS had enabled */
>  static u32 hotkey_all_mask;		/* all events supported in fw */
> +static u32 hotkey_adaptive_all_mask;	/* all adaptive events supported in fw */
>  static u32 hotkey_reserved_mask;	/* events better left disabled */
>  static u32 hotkey_driver_mask;		/* events needed by the driver */
>  static u32 hotkey_user_mask;		/* events visible to userspace */
> @@ -2742,6 +2743,17 @@ static ssize_t hotkey_all_mask_show(struct device *dev,
>  
>  static DEVICE_ATTR_RO(hotkey_all_mask);
>  
> +/* sysfs hotkey all_mask ----------------------------------------------- */
> +static ssize_t hotkey_adaptive_all_mask_show(struct device *dev,
> +			   struct device_attribute *attr,
> +			   char *buf)
> +{
> +	return snprintf(buf, PAGE_SIZE, "0x%08x\n",
> +			hotkey_adaptive_all_mask | hotkey_source_mask);
> +}
> +
> +static DEVICE_ATTR_RO(hotkey_adaptive_all_mask);
> +
>  /* sysfs hotkey recommended_mask --------------------------------------- */
>  static ssize_t hotkey_recommended_mask_show(struct device *dev,
>  					    struct device_attribute *attr,
> @@ -2985,6 +2997,7 @@ static struct attribute *hotkey_attributes[] __initdata = {
>  	&dev_attr_wakeup_hotunplug_complete.attr,
>  	&dev_attr_hotkey_mask.attr,
>  	&dev_attr_hotkey_all_mask.attr,
> +	&dev_attr_hotkey_adaptive_all_mask.attr,
>  	&dev_attr_hotkey_recommended_mask.attr,
>  #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
>  	&dev_attr_hotkey_source_mask.attr,
> @@ -3321,20 +3334,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>  	if (!tp_features.hotkey)
>  		return 1;
>  
> -	/*
> -	 * Check if we have an adaptive keyboard, like on the
> -	 * Lenovo Carbon X1 2014 (2nd Gen).
> -	 */
> -	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
> -		if ((hkeyv >> 8) == 2) {
> -			tp_features.has_adaptive_kbd = true;
> -			res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
> -					&adaptive_kbd_attr_group);
> -			if (res)
> -				goto err_exit;
> -		}
> -	}
> -
>  	quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
>  				     ARRAY_SIZE(tpacpi_hotkey_qtable));
>  
> @@ -3357,18 +3356,16 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>  	   A30, R30, R31, T20-22, X20-21, X22-24.  Detected by checking
>  	   for HKEY interface version 0x100 */
>  	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
> -		if ((hkeyv >> 8) != 1) {
> -			pr_err("unknown version of the HKEY interface: 0x%x\n",
> -			       hkeyv);
> -			pr_err("please report this to %s\n", TPACPI_MAIL);
> -		} else {
> +		vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> +			    "firmware HKEY interface version: 0x%x\n",
> +			    hkeyv);
> +
> +		switch (hkeyv >> 8) {
> +		case 1:
>  			/*
>  			 * MHKV 0x100 in A31, R40, R40e,
>  			 * T4x, X31, and later
>  			 */
> -			vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> -				"firmware HKEY interface version: 0x%x\n",
> -				hkeyv);
>  
>  			/* Paranoia check AND init hotkey_all_mask */
>  			if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
> @@ -3381,6 +3378,50 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
>  			} else {
>  				tp_features.hotkey_mask = 1;
>  			}
> +			break;
> +
> +		case 2:
> +			/*
> +			 * MHKV 0x200 in X1, T460s, X260, T560, X1 Tablet (2016)
> +			 */
> +
> +			/* Paranoia check AND init hotkey_all_mask */
> +			if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
> +					"MHKA", "dd", 1)) {
> +				pr_err("missing MHKA handler, "
> +				       "please report this to %s\n",

Strings should be kept on the same line so they can be searched for in the
sources. I've corrected this here as well as the existing duplicate message in case 1.

Otherwise, queued for 4.8. Thanks.
Marco Trevisan (Treviño) June 9, 2016, 5:05 a.m. UTC | #2
2016-06-08 10:54 GMT-04:00 Lyude <cpaul@redhat.com>:
> From: Dennis Wassenberg <dennis.wassenberg@secunet.com>
>
> Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
> HKEY version 0x200 without adaptive keyboard.
>
> HKEY version 0x200 has method MHKA with one parameter value.
> Passing parameter value 1 will get hotkey_all_mask (the same like
> HKEY version 0x100 without parameter). Passing parameter value 2 to
> MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
> that case there is no adaptive keyboard available.
>
> Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> Signed-off-by: Lyude <cpaul@redhat.com>
> Tested-by: Lyude <cpaul@redhat.com>
> Tested-by: Marco Trevisan <marco@ubuntu.com>
> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>

Can you also Cc: stable@vger.kernel.org so that it can be imported
there once merged?
--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darren Hart June 9, 2016, 7:57 p.m. UTC | #3
On Thu, Jun 09, 2016 at 01:05:12AM -0400, Marco Trevisan (Treviño) wrote:
> 2016-06-08 10:54 GMT-04:00 Lyude <cpaul@redhat.com>:
> > From: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> >
> > Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
> > HKEY version 0x200 without adaptive keyboard.
> >
> > HKEY version 0x200 has method MHKA with one parameter value.
> > Passing parameter value 1 will get hotkey_all_mask (the same like
> > HKEY version 0x100 without parameter). Passing parameter value 2 to
> > MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
> > that case there is no adaptive keyboard available.
> >
> > Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> > Signed-off-by: Lyude <cpaul@redhat.com>
> > Tested-by: Lyude <cpaul@redhat.com>
> > Tested-by: Marco Trevisan <marco@ubuntu.com>
> > Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
> 
> Can you also Cc: stable@vger.kernel.org so that it can be imported
> there once merged?

It doesn't meet stable kernel rules unfortunately, with 143 lines diff.

Henrique, do you want to weigh in on whether this goes back to stable?

One thing I could do is include this in my 4.7-rc fixes branch instead of
waiting for 4.8.
Henrique de Moraes Holschuh June 9, 2016, 9:04 p.m. UTC | #4
On Thu, 09 Jun 2016, Darren Hart wrote:
> On Thu, Jun 09, 2016 at 01:05:12AM -0400, Marco Trevisan (Treviño) wrote:
> > 2016-06-08 10:54 GMT-04:00 Lyude <cpaul@redhat.com>:
> > > From: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> > >
> > > Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
> > > HKEY version 0x200 without adaptive keyboard.
> > >
> > > HKEY version 0x200 has method MHKA with one parameter value.
> > > Passing parameter value 1 will get hotkey_all_mask (the same like
> > > HKEY version 0x100 without parameter). Passing parameter value 2 to
> > > MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
> > > that case there is no adaptive keyboard available.
> > >
> > > Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> > > Signed-off-by: Lyude <cpaul@redhat.com>
> > > Tested-by: Lyude <cpaul@redhat.com>
> > > Tested-by: Marco Trevisan <marco@ubuntu.com>
> > > Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
> > 
> > Can you also Cc: stable@vger.kernel.org so that it can be imported
> > there once merged?
> 
> It doesn't meet stable kernel rules unfortunately, with 143 lines diff.
> 
> Henrique, do you want to weigh in on whether this goes back to stable?

It should be in a bunch of -rc kernel releases before we even consider
it.

> One thing I could do is include this in my 4.7-rc fixes branch instead of
> waiting for 4.8.

If Linus will take it, I don't see a problem with that.
Darren Hart June 9, 2016, 9:18 p.m. UTC | #5
On Thu, Jun 09, 2016 at 06:04:52PM -0300, Henrique de Moraes Holschuh wrote:
> On Thu, 09 Jun 2016, Darren Hart wrote:
> > On Thu, Jun 09, 2016 at 01:05:12AM -0400, Marco Trevisan (Treviño) wrote:
> > > 2016-06-08 10:54 GMT-04:00 Lyude <cpaul@redhat.com>:
> > > > From: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> > > >
> > > > Lenovo Thinkpad devices T460, T460s, T460p, T560, X260 use
> > > > HKEY version 0x200 without adaptive keyboard.
> > > >
> > > > HKEY version 0x200 has method MHKA with one parameter value.
> > > > Passing parameter value 1 will get hotkey_all_mask (the same like
> > > > HKEY version 0x100 without parameter). Passing parameter value 2 to
> > > > MHKA method will retrieve hotkey_all_adaptive_mask. If 0 is returned in
> > > > that case there is no adaptive keyboard available.
> > > >
> > > > Signed-off-by: Dennis Wassenberg <dennis.wassenberg@secunet.com>
> > > > Signed-off-by: Lyude <cpaul@redhat.com>
> > > > Tested-by: Lyude <cpaul@redhat.com>
> > > > Tested-by: Marco Trevisan <marco@ubuntu.com>
> > > > Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
> > > 
> > > Can you also Cc: stable@vger.kernel.org so that it can be imported
> > > there once merged?
> > 
> > It doesn't meet stable kernel rules unfortunately, with 143 lines diff.
> > 
> > Henrique, do you want to weigh in on whether this goes back to stable?
> 
> It should be in a bunch of -rc kernel releases before we even consider
> it.
> 
> > One thing I could do is include this in my 4.7-rc fixes branch instead of
> > waiting for 4.8.
> 
> If Linus will take it, I don't see a problem with that.

I'll do that.
diff mbox

Patch

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 9255ff3..210ecf5 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2043,6 +2043,7 @@  static int hotkey_autosleep_ack;
 
 static u32 hotkey_orig_mask;		/* events the BIOS had enabled */
 static u32 hotkey_all_mask;		/* all events supported in fw */
+static u32 hotkey_adaptive_all_mask;	/* all adaptive events supported in fw */
 static u32 hotkey_reserved_mask;	/* events better left disabled */
 static u32 hotkey_driver_mask;		/* events needed by the driver */
 static u32 hotkey_user_mask;		/* events visible to userspace */
@@ -2742,6 +2743,17 @@  static ssize_t hotkey_all_mask_show(struct device *dev,
 
 static DEVICE_ATTR_RO(hotkey_all_mask);
 
+/* sysfs hotkey all_mask ----------------------------------------------- */
+static ssize_t hotkey_adaptive_all_mask_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	return snprintf(buf, PAGE_SIZE, "0x%08x\n",
+			hotkey_adaptive_all_mask | hotkey_source_mask);
+}
+
+static DEVICE_ATTR_RO(hotkey_adaptive_all_mask);
+
 /* sysfs hotkey recommended_mask --------------------------------------- */
 static ssize_t hotkey_recommended_mask_show(struct device *dev,
 					    struct device_attribute *attr,
@@ -2985,6 +2997,7 @@  static struct attribute *hotkey_attributes[] __initdata = {
 	&dev_attr_wakeup_hotunplug_complete.attr,
 	&dev_attr_hotkey_mask.attr,
 	&dev_attr_hotkey_all_mask.attr,
+	&dev_attr_hotkey_adaptive_all_mask.attr,
 	&dev_attr_hotkey_recommended_mask.attr,
 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
 	&dev_attr_hotkey_source_mask.attr,
@@ -3321,20 +3334,6 @@  static int __init hotkey_init(struct ibm_init_struct *iibm)
 	if (!tp_features.hotkey)
 		return 1;
 
-	/*
-	 * Check if we have an adaptive keyboard, like on the
-	 * Lenovo Carbon X1 2014 (2nd Gen).
-	 */
-	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
-		if ((hkeyv >> 8) == 2) {
-			tp_features.has_adaptive_kbd = true;
-			res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
-					&adaptive_kbd_attr_group);
-			if (res)
-				goto err_exit;
-		}
-	}
-
 	quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
 				     ARRAY_SIZE(tpacpi_hotkey_qtable));
 
@@ -3357,18 +3356,16 @@  static int __init hotkey_init(struct ibm_init_struct *iibm)
 	   A30, R30, R31, T20-22, X20-21, X22-24.  Detected by checking
 	   for HKEY interface version 0x100 */
 	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
-		if ((hkeyv >> 8) != 1) {
-			pr_err("unknown version of the HKEY interface: 0x%x\n",
-			       hkeyv);
-			pr_err("please report this to %s\n", TPACPI_MAIL);
-		} else {
+		vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
+			    "firmware HKEY interface version: 0x%x\n",
+			    hkeyv);
+
+		switch (hkeyv >> 8) {
+		case 1:
 			/*
 			 * MHKV 0x100 in A31, R40, R40e,
 			 * T4x, X31, and later
 			 */
-			vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
-				"firmware HKEY interface version: 0x%x\n",
-				hkeyv);
 
 			/* Paranoia check AND init hotkey_all_mask */
 			if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
@@ -3381,6 +3378,50 @@  static int __init hotkey_init(struct ibm_init_struct *iibm)
 			} else {
 				tp_features.hotkey_mask = 1;
 			}
+			break;
+
+		case 2:
+			/*
+			 * MHKV 0x200 in X1, T460s, X260, T560, X1 Tablet (2016)
+			 */
+
+			/* Paranoia check AND init hotkey_all_mask */
+			if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
+					"MHKA", "dd", 1)) {
+				pr_err("missing MHKA handler, "
+				       "please report this to %s\n",
+				       TPACPI_MAIL);
+				/* Fallback: pre-init for FN+F3,F4,F12 */
+				hotkey_all_mask = 0x080cU;
+			} else {
+				tp_features.hotkey_mask = 1;
+			}
+
+			/*
+			 * Check if we have an adaptive keyboard, like on the
+			 * Lenovo Carbon X1 2014 (2nd Gen).
+			 */
+			if (acpi_evalf(hkey_handle, &hotkey_adaptive_all_mask,
+				       "MHKA", "dd", 2)) {
+				if (hotkey_adaptive_all_mask != 0) {
+					tp_features.has_adaptive_kbd = true;
+					res = sysfs_create_group(
+						&tpacpi_pdev->dev.kobj,
+						&adaptive_kbd_attr_group);
+					if (res)
+						goto err_exit;
+				}
+			} else {
+				tp_features.has_adaptive_kbd = false;
+				hotkey_adaptive_all_mask = 0x0U;
+			}
+			break;
+
+		default:
+			pr_err("unknown version of the HKEY interface: 0x%x\n",
+			       hkeyv);
+			pr_err("please report this to %s\n", TPACPI_MAIL);
+			break;
 		}
 	}