Add support for X1 Yoga (2016) Tablet Mode + refactors
cover Add support for X1 Yoga (2016) Tablet Mode + refactors
Updated patchset for adding support for detecting tablet mode on the X1 Yoga 2016 model, along with some refactoring suggested by Daniel.
Important: I realized I never actually tried testing this on any of the older Thinkpad tablets. If someone has one who is willing to test let me know, otherwise I'll test it out when I get to the office on Thursday.
Lyude (3):
thinkpad_acpi: Move tablet detection into separate function
thinkpad_acpi: Don't repeat ourselves in hotkey_init_tablet_mode()
thinkpad_acpi: Add support for X1 Yoga (2016) Tablet Mode
drivers/platform/x86/thinkpad_acpi.c | 88 ++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 15 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 thinkpad_acpi: Move tablet detection into separate function
Suggested by Daniel Martin <[email protected]>
Lenovo's having a bit of fun randomly changing what hotkey events and acpi handles they use for reporting tablet mode, so unfortunately this means we're definitely going to need to probe for multiple types of tablet mode support. Since the hotkey_init() is already a lot larger then it should be, let's split up this detection into it's own function to make things a little easier to read.
As well, since we're going to have multiple types of tablet modes, make hotkey_tablet into an enum so we can also use it to indicate the type of tablet mode reporting the machine supports.
--- drivers/platform/x86/thinkpad_acpi.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +38 -12
@@ -302,7 +302,10 @@ static struct { u32 hotkey:1; u32 hotkey_mask:1; u32 hotkey_wlsw:1; - u32 hotkey_tablet:1; +enum { +TP_HOTKEY_TABLET_NONE =0 , +TP_HOTKEY_TABLET_USES_MHKG =1 , + } hotkey_tablet; u32 kbdlight:1; u32 light:1; u32 light_status:1;
@@ -3117,6 +3120,34 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {typedef u16 tpacpi_keymap_entry_t ;typedef tpacpi_keymap_entry_t tpacpi_keymap_t [TPACPI_HOTKEY_MAP_LEN ]; +static int +hotkey_init_tablet_mode (void ) +{ +int res; +char *type; +bool in_tablet_mode; + +/* For X41t, X60t, X61t Tablets... */ +if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { + tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; + in_tablet_mode = !!(res &TP_HOTKEY_TABLET_MASK ); + type ="MHKG" ; + } + +if (!tp_features.hotkey_tablet) +return 0 ; + +pr_info ("Tablet mode switch found (type: %s), currently in %s mode\n" , + type, in_tablet_mode ?"tablet" :"laptop" ); + + res =add_to_attr_set (hotkey_dev_attributes, + &dev_attr_hotkey_tablet_mode.attr); +if (res) +return -1 ; + +return in_tablet_mode; +} +static int __init hotkey_init (struct ibm_init_struct *iibm) {/* Requirements for changing the default keymaps:
@@ -3464,17 +3495,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) res =add_to_attr_set (hotkey_dev_attributes, &dev_attr_hotkey_radio_sw.attr); -/* For X41t, X60t, X61t Tablets... */ -if (!res &&acpi_evalf (hkey_handle, &status,"MHKG" ,"qd" )) { - tp_features.hotkey_tablet =1 ; - tabletsw_state = !!(status &TP_HOTKEY_TABLET_MASK ); -pr_info ("possible tablet mode switch found; " -"ThinkPad in %s mode\n" , - (tabletsw_state) ?"tablet" :"laptop" ); - res =add_to_attr_set (hotkey_dev_attributes, - &dev_attr_hotkey_tablet_mode.attr); - } -if (!res) res = register_attr_set_with_sysfs( hotkey_dev_attributes,
@@ -3482,6 +3502,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)if (res) goto err_exit; + res =hotkey_init_tablet_mode (); +if (res <0 ) + goto err_exit; + + tabletsw_state = res; +/* Set up key map */ hotkey_keycode_map =kmalloc (TPACPI_HOTKEY_MAP_SIZE ,GFP_KERNEL );
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
Re: [PATCH 1/3] thinkpad_acpi: Move tablet detection into separate function
Quoted 1 line · Lyude
Suggested by Daniel Martin <[email protected]>
Down below with the other -by: tags please.
Quoted 2 lines
Lenovo's having a bit of fun randomly changing what hotkey events and
Please avoid contractions in documentation in general.
Quoted 4 lines
acpi handles they use for reporting tablet mode, so unfortunately this means we're definitely going to need to probe for multiple types of tablet mode support. Since the
hotkey_init()is already a lot larger then it should be, let's split up this detection into it's own function
s/then/than/ (nit, but since I'm commenting anyway...) s/it's/its/
Quoted 17 lines
to make things a little easier to read.
As well, since we're going to have multiple types of tablet modes, make
hotkey_tabletinto an enum so we can also use it to indicate the type of tablet mode reporting the machine supports.Signed-off-by Lyude <[email protected]>Cc Daniel Martin <[email protected]>--- drivers/platform/x86/thinkpad_acpi.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-)drivers/platform/x86/thinkpad_acpi.c +0
-0
drivers/platform/x86/thinkpad_acpi.c static struct { · line 307
Quoted 7 lines
drivers/platform/x86/thinkpad_acpi.c +3
-1@@ -302,7 +302,10 @@ static struct { u32 hotkey:1; u32 hotkey_mask:1; u32 hotkey_wlsw:1; - u32 hotkey_tablet:1; +enum { +TP_HOTKEY_TABLET_NONE =0 , +TP_HOTKEY_TABLET_USES_MHKG =1 ,
1 will follow automatically, no need to specify explicitly.
enum usage in this driver is not very consistent, but I don't particularly care to have it defined within the struct, but I'll leave that for Henrique to decide.
Quoted 5 lines
drivers/platform/x86/thinkpad_acpi.c +1
-0+ } hotkey_tablet; u32 kbdlight:1; u32 light:1; u32 light_status:1;
drivers/platform/x86/thinkpad_acpi.c static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = { · line 3128
Quoted 9 lines
drivers/platform/x86/thinkpad_acpi.c +6
-0@@ -3117,6 +3120,34 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {typedef u16 tpacpi_keymap_entry_t ;typedef tpacpi_keymap_entry_t tpacpi_keymap_t [TPACPI_HOTKEY_MAP_LEN ]; +static int +hotkey_init_tablet_mode (void ) +{ +int res; +char *type; +bool in_tablet_mode;
Declare variables in reverse line length order please:
bool in_tablet_mode; char *type; int res;
Quoted 60 lines
drivers/platform/x86/thinkpad_acpi.c +28
-11+ +/* For X41t, X60t, X61t Tablets... */ +if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { + tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; + in_tablet_mode = !!(res &TP_HOTKEY_TABLET_MASK ); + type ="MHKG" ; + } + +if (!tp_features.hotkey_tablet) +return 0 ; + +pr_info ("Tablet mode switch found (type: %s), currently in %s mode\n" , + type, in_tablet_mode ?"tablet" :"laptop" ); + + res =add_to_attr_set (hotkey_dev_attributes, + &dev_attr_hotkey_tablet_mode.attr); +if (res) +return -1 ; + +return in_tablet_mode; +} +static int __init hotkey_init (struct ibm_init_struct *iibm) {/* Requirements for changing the default keymaps: @@ -3464,17 +3495,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) res =add_to_attr_set (hotkey_dev_attributes, &dev_attr_hotkey_radio_sw.attr); -/* For X41t, X60t, X61t Tablets... */ -if (!res &&acpi_evalf (hkey_handle, &status,"MHKG" ,"qd" )) { - tp_features.hotkey_tablet =1 ; - tabletsw_state = !!(status &TP_HOTKEY_TABLET_MASK ); -pr_info ("possible tablet mode switch found; " -"ThinkPad in %s mode\n" , - (tabletsw_state) ?"tablet" :"laptop" ); - res =add_to_attr_set (hotkey_dev_attributes, - &dev_attr_hotkey_tablet_mode.attr); - } -if (!res) res = register_attr_set_with_sysfs( hotkey_dev_attributes,@@ -3482,6 +3502,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)if (res) goto err_exit; + res =hotkey_init_tablet_mode (); +if (res <0 ) + goto err_exit; + + tabletsw_state = res; +/* Set up key map */ hotkey_keycode_map =kmalloc (TPACPI_HOTKEY_MAP_SIZE ,GFP_KERNEL );Signature · 1 line
2.7.4
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
PATCH 2/3 thinkpad_acpi: Don't repeat ourselves in hotkey_init_tablet_mode()
In reply to LyudeThere's no need to have multiple copies of the logic we use for checking whether or not we're in tablet mode, so just use hotkey_get_tablet_mode() when checking the initial state in hotkey_init_tablet_mode().
--- drivers/platform/x86/thinkpad_acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/thinkpad_acpi.c +4 -1
@@ -3130,13 +3130,16 @@ hotkey_init_tablet_mode(void)/* For X41t, X60t, X61t Tablets... */ if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; - in_tablet_mode = !!(res &TP_HOTKEY_TABLET_MASK ); type ="MHKG" ; }if (!tp_features.hotkey_tablet)return 0 ; + res =hotkey_get_tablet_mode (&in_tablet_mode); +if (res) +return res; +pr_info ("Tablet mode switch found (type: %s), currently in %s mode\n" , type, in_tablet_mode ?"tablet" :"laptop" );
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
kbuild test robot
build botRe: [PATCH 2/3] thinkpad_acpi: Don't repeat ourselves in hotkey_init_tablet_mode()
reproduce:
Hi Lyude,
[auto build test ERROR on platform-drivers-x86/for-next]
[also build test ERROR on v4.9-rc3 next-20161028]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]
url: https://github.com/0day-ci/linux/commits/Lyude/Add-support-for-X1-Yoga-2016-Tablet-Mode-refactors/20161101-070155 base: git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git for-next config: x86_64-randconfig-x014-201644 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/platform/x86/thinkpad_acpi.c: In function 'hotkey_init_tablet_mode':
>> drivers/platform/x86/thinkpad_acpi.c:3139:31: error: passing argument 1 of 'hotkey_get_tablet_mode' from incompatible pointer type [-Werror=incompatible-pointer-types]
res = hotkey_get_tablet_mode(&in_tablet_mode);
^ drivers/platform/x86/thinkpad_acpi.c:2085:12: note: expected 'int *' but argument is of type 'bool * {aka _Bool *}'
static int hotkey_get_tablet_mode(int *status)
^~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/hotkey_get_tablet_mode +3139 drivers/platform/x86/thinkpad_acpi.c
3133 type = "MHKG";
3134 }
3135
3136 if (!tp_features.hotkey_tablet)
3137 return 0;
3138
> 3139 res = hotkey_get_tablet_mode(&in_tablet_mode);
3140 if (res)
3141 return res;
3142
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 2/3] thinkpad_acpi: Don't repeat ourselves in hotkey_init_tablet_mode()
In reply to Lyudereproduce:
Hi Lyude,
[auto build test WARNING on platform-drivers-x86/for-next]
[also build test WARNING on v4.9-rc3 next-20161028]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]
url: https://github.com/0day-ci/linux/commits/Lyude/Add-support-for-X1-Yoga-2016-Tablet-Mode-refactors/20161101-070155 base: git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git for-next config: i386-randconfig-c0-11010241 (attached as .config) compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All warnings (new ones prefixed by >>):
drivers/platform/x86/thinkpad_acpi.c: In function 'hotkey_init_tablet_mode':
>> drivers/platform/x86/thinkpad_acpi.c:3139:31: warning: passing argument 1 of 'hotkey_get_tablet_mode' from incompatible pointer type
res = hotkey_get_tablet_mode(&in_tablet_mode);
^ drivers/platform/x86/thinkpad_acpi.c:2085:12: note: expected 'int *' but argument is of type 'bool *'
static int hotkey_get_tablet_mode(int *status)
^
vim +/hotkey_get_tablet_mode +3139 drivers/platform/x86/thinkpad_acpi.c
3123 static int
3124 hotkey_init_tablet_mode(void)
3125 {
3126 int res;
3127 char *type;
3128 bool in_tablet_mode;
3129
3130 /* For X41t, X60t, X61t Tablets... */
3131 if (acpi_evalf(hkey_handle, &res, "MHKG", "qd")) {
3132 tp_features.hotkey_tablet = TP_HOTKEY_TABLET_USES_MHKG;
3133 type = "MHKG";
3134 }
3135
3136 if (!tp_features.hotkey_tablet)
3137 return 0;
3138
> 3139 res = hotkey_get_tablet_mode(&in_tablet_mode);
3140 if (res)
3141 return res;
3142
3143 pr_info("Tablet mode switch found (type: %s), currently in %s mode\n",
3144 type, in_tablet_mode ? "tablet" : "laptop");
3145
3146 res = add_to_attr_set(hotkey_dev_attributes,
3147 &dev_attr_hotkey_tablet_mode.attr);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/3 thinkpad_acpi: Move tablet detection into separate function
Suggested by Daniel Martin <[email protected]>
Lenovo's having a bit of fun randomly changing what hotkey events and acpi handles they use for reporting tablet mode, so unfortunately this means we're definitely going to need to probe for multiple types of tablet mode support. Since the hotkey_init() is already a lot larger then it should be, let's split up this detection into it's own function to make things a little easier to read.
As well, since we're going to have multiple types of tablet modes, make hotkey_tablet into an enum so we can also use it to indicate the type of tablet mode reporting the machine supports.
Changes since v1:
- Don't use bool for in_tablet_mode (fixes complaints from kbuild test robot)
--- drivers/platform/x86/thinkpad_acpi.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +38 -12
@@ -302,7 +302,10 @@ static struct { u32 hotkey:1; u32 hotkey_mask:1; u32 hotkey_wlsw:1; - u32 hotkey_tablet:1; +enum { +TP_HOTKEY_TABLET_NONE =0 , +TP_HOTKEY_TABLET_USES_MHKG =1 , + } hotkey_tablet; u32 kbdlight:1; u32 light:1; u32 light_status:1;
@@ -3117,6 +3120,34 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {typedef u16 tpacpi_keymap_entry_t ;typedef tpacpi_keymap_entry_t tpacpi_keymap_t [TPACPI_HOTKEY_MAP_LEN ]; +static int +hotkey_init_tablet_mode (void ) +{ +int res; +char *type; +int in_tablet_mode; + +/* For X41t, X60t, X61t Tablets... */ +if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { + tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; + in_tablet_mode = !!(res &TP_HOTKEY_TABLET_MASK ); + type ="MHKG" ; + } + +if (!tp_features.hotkey_tablet) +return 0 ; + +pr_info ("Tablet mode switch found (type: %s), currently in %s mode\n" , + type, in_tablet_mode ?"tablet" :"laptop" ); + + res =add_to_attr_set (hotkey_dev_attributes, + &dev_attr_hotkey_tablet_mode.attr); +if (res) +return -1 ; + +return in_tablet_mode; +} +static int __init hotkey_init (struct ibm_init_struct *iibm) {/* Requirements for changing the default keymaps:
@@ -3464,17 +3495,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) res =add_to_attr_set (hotkey_dev_attributes, &dev_attr_hotkey_radio_sw.attr); -/* For X41t, X60t, X61t Tablets... */ -if (!res &&acpi_evalf (hkey_handle, &status,"MHKG" ,"qd" )) { - tp_features.hotkey_tablet =1 ; - tabletsw_state = !!(status &TP_HOTKEY_TABLET_MASK ); -pr_info ("possible tablet mode switch found; " -"ThinkPad in %s mode\n" , - (tabletsw_state) ?"tablet" :"laptop" ); - res =add_to_attr_set (hotkey_dev_attributes, - &dev_attr_hotkey_tablet_mode.attr); - } -if (!res) res = register_attr_set_with_sysfs( hotkey_dev_attributes,
@@ -3482,6 +3502,12 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)if (res) goto err_exit; + res =hotkey_init_tablet_mode (); +if (res <0 ) + goto err_exit; + + tabletsw_state = res; +/* Set up key map */ hotkey_keycode_map =kmalloc (TPACPI_HOTKEY_MAP_SIZE ,GFP_KERNEL );
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
Re: [PATCH v2 1/3] thinkpad_acpi: Move tablet detection into separate function
Quoted 9 lines · Lyude
Suggested by Daniel Martin <[email protected]>
Lenovo's having a bit of fun randomly changing what hotkey events and acpi handles they use for reporting tablet mode, so unfortunately this means we're definitely going to need to probe for multiple types of tablet mode support. Since the
hotkey_init()is already a lot larger then it should be, let's split up this detection into it's own function to make things a little easier to read.
Quoted 8 lines
As well, since we're going to have multiple types of tablet modes, make
hotkey_tabletinto an enum so we can also use it to indicate the type of tablet mode reporting the machine supports.Changes since v1:
- Don't use bool forin_tablet_mode(fixes complaints from kbuild test robot)
This series doesn't apply cleanly now (simple fuzz).
Once we hear back from Henrique on his enum preference and thoughts on the refactoring (which looks reasonable to me), please resubmit this series and review Documentation/SubmittingPatches for the changelog (below ---) and please be consistent in your placement of "v2" in the subject [PATCH vX N/M] prefix.
Most all of my feedback here is minor, but there were enough little things that added up and I'd like to see this resubmitted as a series with those addressed that applies cleanly - largely to make sure I haven't missed context and somehow merged the wrong bits.
Thanks Lyude,
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Re: [PATCH v2 1/3] thinkpad_acpi: Move tablet detection into separate function
Quoted 19 lines · Darren Hart
Quoted 9 lines · Lyude
Suggested by Daniel Martin <[email protected]>
Lenovo's having a bit of fun randomly changing what hotkey events and acpi handles they use for reporting tablet mode, so unfortunately this means we're definitely going to need to probe for multiple types of tablet mode support. Since the
hotkey_init()is already a lot larger then it should be, let's split up this detection into it's own function to make things a little easier to read.Quoted 8 lines
As well, since we're going to have multiple types of tablet modes, make
hotkey_tabletinto an enum so we can also use it to indicate the type of tablet mode reporting the machine supports.Changes since v1:
- Don't use bool forin_tablet_mode(fixes complaints from kbuild test robot)
Quoted 4 lines
This series doesn't apply cleanly now (simple fuzz).
Once we hear back from Henrique on his enum preference and thoughts on the refactoring (which looks reasonable to me), please resubmit this series and
I don't mind the enum usage, as long as it is correct. As you said, the driver is not consistent there. I also don't mind the refactoring.
Signature · 1 line
Henrique Holschuh
PATCH v3 3/3 thinkpad_acpi: Add support for X1 Yoga (2016) Tablet Mode
In reply to LyudeFor whatever reason, the X1 Yoga doesn't support the normal method of querying for tablet mode. Instead of providing the MHKG method under the hotkey handle, we're instead given the CMMD method under the EC handle. Values on this handle are either 0x1, laptop mode, or 0x6, tablet mode.
Changes since v1:
- Clarify kernel output when finding the tablet mode switch Changes since v2:
- Rebase on top of previous patch
- Use an enum for hotkey_tablet. This does make a bit more sense then just adding another flag.
- Call hotkey_tablet_mode_notify_change() when getting TABLET_CHANGED event.
--- drivers/platform/x86/thinkpad_acpi.c | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)
drivers/platform/x86/thinkpad_acpi.c +33 -4
@@ -190,6 +190,9 @@ enum tpacpi_hkey_event_t {TP_HKEY_EV_LID_OPEN =0x5002 ,/* laptop lid opened */ TP_HKEY_EV_TABLET_TABLET =0x5009 ,/* tablet swivel up */ TP_HKEY_EV_TABLET_NOTEBOOK =0x500a ,/* tablet swivel down */ +TP_HKEY_EV_TABLET_CHANGED =0x60c0 ,/* X1 Yoga (2016): +* enter/leave tablet mode +*/ TP_HKEY_EV_PEN_INSERTED =0x500b ,/* tablet pen inserted */ TP_HKEY_EV_PEN_REMOVED =0x500c ,/* tablet pen removed */ TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */
@@ -305,6 +308,7 @@ static struct {enum {TP_HOTKEY_TABLET_NONE =0 ,TP_HOTKEY_TABLET_USES_MHKG =1 , +TP_HOTKEY_TABLET_USES_CMMD =2 , } hotkey_tablet; u32 kbdlight:1; u32 light:1;
@@ -2062,6 +2066,8 @@ static void hotkey_poll_setup(const bool may_warn);/* HKEY.MHKG() return bits */ #define TP_HOTKEY_TABLET_MASK (1 << 3) +/* ThinkPad X1 Yoga (2016) */ +#define TP_EC_CMMD_TABLET_MODE 0x6static int hotkey_get_wlsw (void ) {
@@ -2086,10 +2092,23 @@ static int hotkey_get_tablet_mode(int *status) {int s; -if (!acpi_evalf (hkey_handle, &s,"MHKG" ,"d" )) -return -EIO ; +switch (tp_features.hotkey_tablet) { +case TP_HOTKEY_TABLET_USES_MHKG : +if (!acpi_evalf (hkey_handle, &s,"MHKG" ,"d" )) +return -EIO ; + + *status = ((s &TP_HOTKEY_TABLET_MASK ) !=0 ); +break ; +case TP_HOTKEY_TABLET_USES_CMMD : +if (!acpi_evalf (ec_handle, &s,"CMMD" ,"d" )) +return -EIO ; + + *status = (s ==TP_EC_CMMD_TABLET_MODE ); +break ; +default : +break ; + } - *status = ((s &TP_HOTKEY_TABLET_MASK ) !=0 );return 0 ; }
@@ -3127,10 +3146,14 @@ hotkey_init_tablet_mode(void)char *type;bool in_tablet_mode; -/* For X41t, X60t, X61t Tablets... */ if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { +/* For X41t, X60t, X61t Tablets... */ tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; type ="MHKG" ; + }else if (acpi_evalf (ec_handle, &res,"CMMD" ,"qd" )) { +/* For X1 Yoga (2016) */ + tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_CMMD ; + type ="CMMD" ; }if (!tp_features.hotkey_tablet)
@@ -3928,6 +3951,12 @@ static bool hotkey_notify_6xxx(const u32 hkey, *ignore_acpi_ev = true;return true; +case TP_HKEY_EV_TABLET_CHANGED : +tpacpi_input_send_tabletsw (); +hotkey_tablet_mode_notify_change (); + *send_acpi_ev = false; +break ; +default :pr_warn ("unknown possible thermal alarm or keyboard event received\n" ); known = false;
Signature · 9 lines
2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
Re: [PATCH 3/3 v3] thinkpad_acpi: Add support for X1 Yoga (2016) Tablet Mode
Quoted 5 lines · Lyude
For whatever reason, the X1 Yoga doesn't support the normal method of querying for tablet mode. Instead of providing the MHKG method under the hotkey handle, we're instead given the CMMD method under the EC handle. Values on this handle are either
0x1, laptop mode, or0x6, tablet mode.
Quoted 8 lines
Changes since v1:
- Clarify kernel output when finding the tablet mode switch Changes since v2:
- Rebase on top of previous patch
- Use an enum forhotkey_tablet. This does make a bit more sense then just adding another flag.
- Callhotkey_tablet_mode_notify_change()when gettingTABLET_CHANGEDevent.
These go below the ---
Quoted 22 lines
Cc Daniel Martin <[email protected]>Signed-off-by Lyude <[email protected]>--- drivers/platform/x86/thinkpad_acpi.c | 37 ++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-)drivers/platform/x86/thinkpad_acpi.c +3
-0@@ -190,6 +190,9 @@ enum tpacpi_hkey_event_t {TP_HKEY_EV_LID_OPEN =0x5002 ,/* laptop lid opened */ TP_HKEY_EV_TABLET_TABLET =0x5009 ,/* tablet swivel up */ TP_HKEY_EV_TABLET_NOTEBOOK =0x500a ,/* tablet swivel down */ +TP_HKEY_EV_TABLET_CHANGED =0x60c0 ,/* X1 Yoga (2016): +* enter/leave tablet mode +*/ TP_HKEY_EV_PEN_INSERTED =0x500b ,/* tablet pen inserted */ TP_HKEY_EV_PEN_REMOVED =0x500c ,/* tablet pen removed */ TP_HKEY_EV_BRGHT_CHANGED = 0x5010, /* backlight control event */
drivers/platform/x86/thinkpad_acpi.c static struct { · line 311
Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +1
-0@@ -305,6 +308,7 @@ static struct {enum {TP_HOTKEY_TABLET_NONE =0 ,TP_HOTKEY_TABLET_USES_MHKG =1 , +TP_HOTKEY_TABLET_USES_CMMD =2 ,
1 and 2 will follow automatically, no need to specify.
Pending Henrique's preference on inline enum or external definition.
Quoted 72 lines
drivers/platform/x86/thinkpad_acpi.c +29
-4} hotkey_tablet; u32 kbdlight:1; u32 light:1;@@ -2062,6 +2066,8 @@ static void hotkey_poll_setup(const bool may_warn);/* HKEY.MHKG() return bits */ #define TP_HOTKEY_TABLET_MASK (1 << 3) +/* ThinkPad X1 Yoga (2016) */ +#define TP_EC_CMMD_TABLET_MODE 0x6static int hotkey_get_wlsw (void ) {@@ -2086,10 +2092,23 @@ static int hotkey_get_tablet_mode(int *status) {int s; -if (!acpi_evalf (hkey_handle, &s,"MHKG" ,"d" )) -return -EIO ; +switch (tp_features.hotkey_tablet) { +case TP_HOTKEY_TABLET_USES_MHKG : +if (!acpi_evalf (hkey_handle, &s,"MHKG" ,"d" )) +return -EIO ; + + *status = ((s &TP_HOTKEY_TABLET_MASK ) !=0 ); +break ; +case TP_HOTKEY_TABLET_USES_CMMD : +if (!acpi_evalf (ec_handle, &s,"CMMD" ,"d" )) +return -EIO ; + + *status = (s ==TP_EC_CMMD_TABLET_MODE ); +break ; +default : +break ; + } - *status = ((s &TP_HOTKEY_TABLET_MASK ) !=0 );return 0 ; }@@ -3127,10 +3146,14 @@ hotkey_init_tablet_mode(void)char *type;bool in_tablet_mode; -/* For X41t, X60t, X61t Tablets... */ if (acpi_evalf (hkey_handle, &res,"MHKG" ,"qd" )) { +/* For X41t, X60t, X61t Tablets... */ tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_MHKG ; type ="MHKG" ; + }else if (acpi_evalf (ec_handle, &res,"CMMD" ,"qd" )) { +/* For X1 Yoga (2016) */ + tp_features.hotkey_tablet =TP_HOTKEY_TABLET_USES_CMMD ; + type ="CMMD" ; }if (!tp_features.hotkey_tablet)@@ -3928,6 +3951,12 @@ static bool hotkey_notify_6xxx(const u32 hkey, *ignore_acpi_ev = true;return true; +case TP_HKEY_EV_TABLET_CHANGED : +tpacpi_input_send_tabletsw (); +hotkey_tablet_mode_notify_change (); + *send_acpi_ev = false; +break ; +default :pr_warn ("unknown possible thermal alarm or keyboard event received\n" ); known = false;Signature · 1 line
2.7.4
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Got in touch with a friend who happened to have a X201 and had them test the patches, so I've confirmed this doesn't break anything with older ThinkPad tablets.
Quoted 22 lines · Lyude
Updated patchset for adding support for detecting tablet mode on the X1 Yoga
2016 model, along with some refactoring suggested by Daniel.Important: I realized I never actually tried testing this on any of the older
Thinkpad tablets. If someone has one who is willing to test let me know,
otherwise I'll test it out when I get to the office on Thursday.Signed-off-by Lyude <[email protected]>Cc Daniel Martin <[email protected]>Lyude (3):
thinkpad_acpi: Move tablet detection into separate function
thinkpad_acpi: Don't repeat ourselves inhotkey_init_tablet_mode()
thinkpad_acpi: Add support for X1 Yoga (2016) Tablet Modedrivers/platform/x86/thinkpad_acpi.c | 88
++++++++++++++++++++++++++++++------1 file changed, 73 insertions(+), 15 deletions(-)
Signature · 2 lines
Cheers, Lyude