Bug 210269

Summary: Tablet mode not correctly reported after wake-up from hibernate
Product: Drivers Reporter: Julian (j.r)
Component: Platform_x86Assignee: drivers_platform_x86 (drivers_platform_x86)
Status: NEW ---    
Severity: normal CC: benjamin, jwrdegoede, pobrn
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.9.9 Tree: Mainline
Regression: No
Attachments: Trivial patch to send the switch key event

Description Julian 2020-11-19 15:39:32 UTC
I'm currently using a Lenovo Thinkpad X1 Yoga 2nd Gen which is a convertible. If I fold it into tablet mode, go to hibernate / suspend, fold it back to laptop mode (while powered off) and resume the system the tablet mode on/off is not reported anymore until I fold it into tablet mode and back one time.

I debugged this via evemu-record which does not show 0 for SW_TABLET_MODE when I resume in laptop mode.

I also tested if normal sleep / suspend to RAM is affected but there SW_TABLET_MODE was correctly reported after resuming.
Comment 1 Benjamin Berg 2020-11-19 16:46:29 UTC
Yeah, the only thing that is missing here should be a call to dytc_lapmode_refresh at resume time.

i.e. should be as simple as:
 * Adding a resume handler into dytc_driver_data
 * Add a call to dytc_lapmode_refresh there
Comment 2 Benjamin Berg 2020-11-19 17:06:53 UTC
Er, sorry, this is tablet mode, not lapmode …

So, it looks like we already have a call to
  hotkey_tablet_mode_notify_change
in the resume handler. So I suspect that the sysfs file "hotkey_tablet_mode" has the correct value. If that is the case, we'll need to add a call to tpacpi_input_send_tabletsw into hotkey_resume.
Comment 3 Julian 2020-11-19 18:09:12 UTC
Is there a way I could find out if this sysfs file has the correct value? I'm not very experienced with Kernel internals so I don't really know how to find out such stuff.
Comment 4 Barnabás Pőcze 2020-11-19 18:14:37 UTC
If I see it correctly

  cat /sys/devices/platform/thinkpad_acpi/hotkey_tablet_mode

should be the value you're looking for.
Comment 5 Benjamin Berg 2020-11-19 19:42:45 UTC
Yup, that should be the file (which will actually query ACPI for the status each time you read it).

Julian, would you be able to test a patch for the thinkpad module?

I could create a kernel scratch build for Fedora, not sure about other distros.
Comment 6 Julian 2020-11-19 19:59:58 UTC
Yeah Benjamin I could test a patch
Comment 7 Julian 2020-11-19 20:03:22 UTC
Just checked it and the sysfs file does contain a 0 after wakeup as you said Benjamin.
Comment 8 Benjamin Berg 2020-11-19 20:11:21 UTC
Created attachment 293737 [details]
Trivial patch to send the switch key event

I wonder if we should only do this if the switch actually changed. But I suspect the input layer will already take care of that case.
Comment 9 Julian 2020-11-21 13:40:39 UTC
Your patch seems to fix the problem Benjamin, thanks.
Comment 10 Hans de Goede 2020-11-21 14:17:43 UTC
(In reply to Benjamin Berg from comment #8)
> I wonder if we should only do this if the switch actually changed. But I
> suspect the input layer will already take care of that case.

There is no need to check if the switch actually changed, as you already presumed the input layer will filter out the event if there is no change.

(In reply to Julian from comment #9)
> Your patch seems to fix the problem Benjamin, thanks.

Awesome, thank you for testing.

Benjamin, can you submit the fix for this upstream please ? Then I'll pick it up and merge it for the 5.11 cycle.

Note please add the following tags to the commit msg:

Fixes: dda3ec0aa631 ("platform/x86: thinkpad_acpi: Implement tablet mode using GMMS method")
BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=210269