Bug 75901

Summary: Newish Samsung laptops need SABI call for proper lid switch handling
Product: Drivers Reporter: Bryan Stine (bryan+lk)
Component: Platform_x86Assignee: drivers_platform_x86 (drivers_platform_x86)
Status: NEW ---    
Severity: enhancement CC: julijonas.kikutis, kalmisoft
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.13.11.2 Subsystem:
Regression: No Bisected commit-id:

Description Bryan Stine 2014-05-10 23:59:18 UTC
With a Samsung NP900X4C, I've noticed that the lid switch normally has a delay of approximately 10 seconds before it will detect closure. Additionally, the machine is normally incapable of waking from sleep with the lid.

Using a bruteforce attack on the debugfs interface provided by samsung_laptop, I was able to send a command that flipped some switch that makes the lid switch behave in Linux as it does in Windows. It removes the delay for the lid switch, plus it enables lid wake from sleep.

To enable this "better behavior mode", I called the following in samsung_laptop debugfs:
command = 0x6e, d0 = 0x81 (presumably 0x80 | enable), d1-3 = 0

So, it appears that some SABI3 Samsung machines will need this (and possibly other SABI commands?) for better power management behavior. Perhaps this could be provided by samsung_laptop via a user-friendly sysfs entry?

Additionally, further testing would be needed on similar models (Ivy Bridge at least) to verify this works. I also do not know the implications, if any, that this would have on the EC issue in bug 44161. Or on the rest of the machine, for that matter.

Thanks.
Comment 1 Julijonas Kikutis 2014-08-12 22:40:19 UTC
I have Samsung Series 3 NP300V4Z-S09TH with the same issue.

/proc/acpi/button/lid/LID0/state changes after about 10 seconds after closing the lid.

Also, lid opening does not trigger system wake up, there is /proc/acpi/button/lid/LID0/state, but no LID0 in /proc/acpi/wakeup.

Samsung provides Settings/Easy Settings for Windows 8/Windows 7 respectively. It enables faster detection of closing, detection of opening, and disables the blinking of a power LED on the front side of the laptop. It would normally blink during sleep.

As samsung_laptop module is disabled in UEFI mode, I cannot test that command now.
Comment 2 Julijonas Kikutis 2014-08-29 17:29:58 UTC
I reinstalled Linux in BIOS mode and can confirm that the mentioned command  removes the delay for the lid switch, enables waking up by opening lid, and disables blinking LED just like in Windows with Samsung drivers.

Samsung driver for Windows works even in UEFI mode, so at least this single command could be executed under UEFI in Linux.
Comment 3 kalmi 2014-08-30 05:00:54 UTC
NP900X3A (Sandy Bridge) in BIOS mode

cd /sys/kernel/debug/samsung-laptop/
echo 0x81 >d0
echo 0 >d1
echo 0 >d2
echo 0 >d3
cat call

Running Bryan's command gives me non-delayed sleep on lid close and instant wake on lid open, however now the power button has to be pressed twice to wake the machine. Restarting the machine brings back the old behaviors.

Without the command lid close detection is slower, machine does not wake on lid open, and power button wakes machine on first try.

LID0 is not present in /proc/acpi/wakeup, but /proc/acpi/button/lid/LID0/state is present.
Comment 4 kalmi 2014-08-30 05:36:22 UTC
Sorry, the following line is missing from my previous comment:
echo 0x6e > command
Comment 5 kalmi 2014-08-30 05:45:53 UTC
An other interesting change that this command causes is that the single power/sleep button no longer acts as a power button but as a sleep button.
Comment 6 Julijonas Kikutis 2015-04-03 15:57:16 UTC
This patch should fix the bug.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=b0dcaf4fbb36895175657be029ed64eda2a34707

However, I had to enable this command automatically only for the laptops in the DMI whitelist as opposed to all laptops that load the module because of the mentioned regression in comment 3. If there is a better solution, please let me know.

You can test the behavior of your laptop by changing the value of /sys/devices/platform/samsung/lid_handling to 1. Then you can add the DMI information of your laptop to the whitelist in the module source.