User Tools

Site Tools


howto:surface

This is an old revision of the document!


MS Surface Pro 3

Kernel less 4.16

Linux seems to get stuck in sleep on kernels less than 4.16. A workaround is to replace the sleep function with hibernate so that when you put your device to sleep it hibernates instead.

sudo ln -s /usr/lib/systemd/system/hibernate.target /etc/systemd/system/suspend.target
sudo ln -s /usr/lib/systemd/system/systemd-hibernate.service /etc/systemd/system/systemd-suspend.service

Substitute Suspend with Freeze

Surface Pro 3 does not support suspend-to-RAM (not even in Windows). The “Connected Standby”, “modern” standby or active idle (S0i1/S0i3 states) is not implemented in Linux, but there is “freeze” state which is at least something and may help conserve battery somewhat compared to leaving the machine running.

sudo vi /etc/systemd/sleep.conf
[Sleep]
SuspendState=freeze

Wifi crashes

Wifi crashes

sudo vi /etc/NetworkManager/dispatcher.d/no-power-save
#!/bin/sh

# MDJ
IFACE=$1
ACTION=$2

IW=/sbin/iw

test -x $IW || exit 0
[ "$IFACE" = "wlp1s0" ] || exit 0

case "$ACTION" in
    up)
        $IW dev $IFACE set power_save off
        ;;
esac
sudo chmod 755 /etc/NetworkManager/dispatcher.d/no-power-save
sudo vi /etc/NetworkManager/NetworkManager.conf
[connection]
wifi.powersafe=2 # 2=disable
wifi.mac-address-randomization=1 # 1=disable
wifi.cloned-mac-address=permanent

[device]
wifi.scan-rand-mac-address=no

Wifi sleep

Wifi slow not not coming back after sleep:

Turn off or enable wifi power savings:

cat /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
[connection]
# 2 = powersave disabled, 3 = powersave enabled
wifi.powersave = 2

sudo systemctl restart NetworkManager

OR

A systemd script which reloads the mwiflex WiFi kernel module of the Surface Pro 3 when resuming from suspend:

/lib/systemd/system-sleep/wifi-reset
#!/bin/sh

# NAME: /lib/systemd/system-sleep/wifi-reset
# DESC: Resets WiFi which can be flakey after a long suspend.

MYNAME=$0

restart_wifi() {
    /usr/bin/logger $MYNAME 'restart_wifi BEGIN'
    /sbin/modprobe -v -r mwifiex_pcie # This removes mwifiex too
    /sbin/modprobe -v mwifiex
    /sbin/modprobe -v mwifiex_pcie
#    systemctl restart NetworkManager.service
    /usr/bin/logger 'systemctl restart NetworkManager.service (SUPPRESSED)'
    /usr/bin/logger $MYNAME 'restart_wifi END'
}

/usr/bin/logger $MYNAME 'case=[' ${1}' ]'
case "${1}/${2}" in
    hibernate|suspend|pre*)
      ;;
    resume|thaw|post*)
      restart_wifi;;
esac

NOTE: Sometimes simply resetting network manager is all that is needed. In that case un-comment the line above by removing #. Then comment out the two lines above it by putting # at the beginning of those two lines.

You'll need to create this script, called wifi-reset, with sudo powers and save it into the directory /lib/systemd/system-sleep. Then mark it executable using:

chmod a+x /lib/systemd/system-sleep/wifi-reset

OR

Try to go into sleep mode, start the computer up and do

sudo nmcli radio wifi on

if your computer connects to the correct wifi, then this might be a optional solution for you. your computer should auto-connect to your saved wi-fi access point.

Switch wifi off and on again using a script:
Create a script

sudo vi /usr/lib/pm-utils/sleep.d/wakewifi

content:

#!/bin/sh
    case "$1" in
        resume)
            nmcli radio wifi on
    esac

Make it executable.

sudo chmod a+x /usr/lib/pm-utils/sleep.d/wakewifi

Disable power management of network interface:
Another approach is to add an explicit directive (wireless-power) to control power management in the /etc/network/interfaces configuration file (e.g. Disable it for wlan0 with DHCP):

    auto wlan0 
    iface wlan0 inet dhcp
    wireless-power off

Wifi Resume service:
Test if the following command works

sudo systemctl restart network-manager.service

If this works, you can create a script to automate it.

sudo vi /etc/systemd/system/wifi-resume.service
#/etc/systemd/system/wifi-resume.service
#sudo systemctl enable wifi-resume.service
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Activate it with

sudo systemctl enable wifi-resume.service

Module option available to prevent deep sleep:

$ grep 'MWIFIEX' /var/log/dmesg
[   31.679019] kernel: mwifiex_pcie 0000:01:00.0: info: MWIFIEX VERSION: mwifiex 1.0 (15.68.19.p21) 
$ modinfo mwifiex | egrep 'desc|sleep'
description:    Marvell WiFi-Ex Driver version 1.0
parm:           disable_auto_ds:deepsleep enabled=0(default), deepsleep disabled=1 (bool)
$ sudo vi /etc/modprobe.d/mwifiex.conf
options mwifiex disable_auto_ds=1
$ sudo systemctl restart NetworkManager

$ iwconfig wlp1s0 | grep "Power Management"

Mint on Surface Notes

menu -> display -> set display resolution to 1600x1024
menu -> power management -> set lid to do nothing
menu -> keyboard -> layouts -> set to english uk with win keys

sudo vi /etc/initramfs-tools/modules
hid_sensor_hub
i2c_hid
hid_generic
usbhid
hid_multitouch

sudo update-initramfs -u


#swap suspend with hibernate (suspend not supported)
sudo rm -Rf /etc/systemd/system/suspend.target && sudo ln -sf /lib/systemd/system/hibernate.target /etc/systemd/system/suspend.target
sudo rm -Rf /etc/systemd/system/systemd-suspend.service && sudo ln -sf /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/systemd-suspend.service

#swap suspend with hibernate (suspend not supported)
sudo rm -Rf /etc/systemd/system/suspend.target
sudo rm -Rf /etc/systemd/system/systemd-suspend.service
sudo ln -sf /lib/systemd/system/suspend.target /etc/systemd/system/suspend.target
sudo ln -sf /lib/systemd/system/systemd-suspend.service /etc/systemd/system/systemd-suspend.service
sudo ln -sf /lib/systemd/system/hibernate.target /etc/systemd/system/hibernate.target
sudo ln -sf /lib/systemd/system/systemd-hibernate.service /etc/systemd/system/systemd-hibernate.service


Disable Lid-Wake if you find lid-events to cause sleep issues.
    sudo gedit /etc/UPower/UPower.conf
    and change IgnoreLid=false to IgnoreLid=true


add applet: battery applet with monitoring and shutdown (bams)
https://cinnamon-spices.linuxmint.com/applets/view/255
requirements:
sudo apt-get install zenity sox libsox-fmt-mp3

#wifi disconnect issues requiring full reboot to get wifi working again:
sudo vi /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
#disable wifi powersave using:
wifi.powersave = 2
alternative (older version?):
iwconfig mlan0 power off
and you should see Power Management:off when you type iwconfig. To get it automatically, save this script in /etc/pm/power.d/wireless:
#!/bin/sh
/sbin/iwconfig mlan0 power off


Screen saver
It works but the screen is not off which heats and consumes energy. If you want it really off do:

xset +dpms
xset dpms 300

300 being seconds, it turns off the screen after 5 minutes. It can be put in Xorg configuration by adding a file in /etc/X11/xorg.conf.d with:

Section "Monitor"
  Identifier "Monitor0"
  Option "DPMS" "true"
EndSection

Section "ServerLayout"
  Identifier "ServerLayout0"
  Option "OffTime" "5"
EndSection

I must confess it is not a perfect success since sometime it does turn off the backlight, sometime it does not... 


http://www.ricou.eu.org/sp3.html


wifi drivers:
1. Open a Terminal and install Git via sudo apt-get install git 
2. Download the drivers from the Git repository, to do so, run:
git clone git://git.marvell.com/mwifiex-firmware.git  
mkdir -p /lib/firmware/mrvl/  
cp mwifiex-firmware/mrvl/* /lib/firmware/mrvl/

Firmware updates

FN Function Keys

By default the F1-F12 keys on the Surface Pro 3 need to be accessed using the FN key and the media keys are the default state.

To lock the FN key, so that the F1-12 keys work directly, press FN + CAPS LOCK

Custom Surface Kernel

https://github.com/linux-surface/linux-surface/wiki/Installation-and-Setup

Debian / Ubuntu

First you need to import the keys we use to sign packages.

$ wget -qO - https://raw.githubusercontent.com/linux-surface/linux-surface/master/pkg/keys/surface.asc \
    | gpg --dearmor | sudo dd of=/etc/apt/trusted.gpg.d/linux-surface.gpg
After this you can add the repository configuration and update APT.

$ echo "deb [arch=amd64] https://pkg.surfacelinux.com/debian release main" \
	| sudo tee /etc/apt/sources.list.d/linux-surface.list

$ sudo apt update
Now you can install the linux-surface kernel and its dependencies. You should also enable the iptsd service for touchscreen support.

$ sudo apt install linux-image-surface linux-headers-surface iptsd libwacom-surface

After that you can install the secureboot key. This will import the key that the linux-surface kernel is signed with into your bootloader, so that the kernel is bootable without disabling secureboot. This package will print instructions to the terminal, so please install it on its own, not as part of a bigger batch of packages.

If your Debian derivate does not support secure boot, please skip this step.
$ sudo apt install linux-surface-secureboot-mok

The linux-surface kernel will be installed alongside the default kernel provided by the distribution. This way you have a backup kernel you can use if something goes wrong. The bootloader will pick up the kernel by default, but you should update its configuration to make sure it was recognized.

$ sudo update-grub
Finally, reboot your system and you should boot into the linux-surface kernel. 

This should ask for the secureboot key password for the key to be installed. The password is "surface"

Please make sure you are actually using the right kernel by checking if the output of uname -a contains the string surface. If it doesn't contain that string, you are still using the default kernel and need to configure your bootloader.

Adjust apt if manually installed to enable autoremove to work on old kernels:

https://help.ubuntu.com/community/RemoveOldKernels

Plymouth Theme

Download from https://www.gnome-look.org/p/1233605/

tar -xvzf urko-mint-dark-plymouth-theme_v1.0.tar.gz 
cd urko-mint-dark/
sudo ./install.sh 
cd ..
rm -rf urko-mint-dark
rm urko-mint-dark-plymouth-theme_v1.0.tar.gz

Missing i915 firmware

To rectify initramfs and boot errors like:

W: Possible missing firmware /lib/firmware/i915/tgl_huc_7.5.0.bin for module i915

Download the missing firmware from:
http://anduin.linuxfromscratch.org/sources/linux-firmware/i915/
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/
and regenerate initramfs and update grub:

wget http://anduin.linuxfromscratch.org/sources/linux-firmware/i915/tgl_huc_7.5.0.bin
sudo mv tgl_huc_7.5.0.bin /lib/firmware/i915/
sudo chmod 755 /lib/firmware/i915/tgl_huc_7.5.0.bin 
sudo update-initramfs -u
sudo update-grub

Manual Kernel update

https://github.com/linux-surface/linux-surface/releases

wget https://github.com/linux-surface/libwacom-surface/releases/download/v1.12-2/libwacom-surface_1.12-2_amd64.deb
sudo dpkg -i libwacom-surface_1.12-2_amd64.deb 
wget https://github.com/linux-surface/secureboot-mok/releases/download/20211103-1/linux-surface-secureboot-mok_20211103-1_amd64.deb
sudo dpkg -i linux-surface-secureboot-mok_20211103-1_amd64.deb

wget https://github.com/linux-surface/linux-surface/releases/download/debian-5.14.16-2/linux-image-5.14.16-surface_5.14.16-surface-2_amd64.deb
wget https://github.com/linux-surface/linux-surface/releases/download/debian-5.14.16-2/linux-headers-5.14.16-surface_5.14.16-surface-2_amd64.deb
wget https://github.com/linux-surface/linux-surface/releases/download/debian-5.14.16-2/linux-headers-surface_5.14.16-surface-2_amd64.deb
wget https://github.com/linux-surface/linux-surface/releases/download/debian-5.14.16-2/linux-image-surface_5.14.16-surface-2_amd64.deb
sudo dpkg -i linux-headers-5.14.16-surface_5.14.16-surface-2_amd64.deb
sudo dpkg -i linux-image-5.14.16-surface_5.14.16-surface-2_amd64.deb 
sudo dpkg -i linux-headers-surface_5.14.16-surface-2_amd64.deb
sudo dpkg -i linux-image-surface_5.14.16-surface-2_amd64.deb
kernel.sh
#!/bin/bash

get_surface_releases() {
curl -s https://api.github.com/repos/linux-surface/linux-surface/releases | \
  jq -r '[[.[] |
    select(.draft != true) |
    select(.prerelease != true)][] |
    .assets |
    .[] |
    select(.name | endswith(".deb")) |
    .browser_download_url]' | grep -o "http.*deb"
}

mkdir /tmp/linsurf
cd /tmp/linsurf
get_surface_releases | head -4 | xargs -n1 wget
sudo dpkg -i -R /tmp/linsurf
rm -rf /tmp/linsurf

Surface Kernel Github issue solved by upgrading apt to 2.0.9 (for ubuntu focal based distros)
see wiki https://github.com/linux-surface/linux-surface/wiki/Known-Issues-and-FAQ/d65bd6ee9cfbbbf74e6da76ddc52aa231be1be50

sudo add-apt-repository ppa:gpxbv/apt-urlfix
sudo apt-get update
sudo apt install apt

Screen resolution

The surface pro 3 has a native resolution of 2160×1440 with 3:2 aspect ratio. Fonts are too small on this resolution. A better resolution without using font or monitor scaling is 1920×1280 but this isn't available in drop downs.
Custom resolutions can be added using xrandr:

xrandr --newmode "1920x1280_60.00"  206.25  1920 2056 2256 2592  1280 1283 1293 1327 -hsync +vsync
xrandr --addmode eDP-1 "1920x1280_60.00"

Note that this is not permanent and after a reboot, the modelines do not exist any longer.

Add to rc.local / .profile or whatever best applies to your system.

This can be applied in lightdm:

/etc/lightdm/lightdm.conf.d/70-linuxmint.conf
[SeatDefaults]
user-session=cinnamon
display-setup-script=/usr/local/bin/screenfix.sh
/usr/local/bin/screenfix.sh
#!/bin/sh
/usr/bin/xrandr --newmode "1920x1280_60.00"  206.25  1920 2056 2256 2592  1280 1283 1293 1327 -hsync +vsync
/usr/bin/xrandr --addmode eDP-1 "1920x1280_60.00" ;\
/usr/bin/xrandr --output eDP-1 --primary --mode 1920x1280_60.00 --rotate normal
exit 0
chmod 755 /usr/local/bin/screenfix.sh

Surface 6 has a native resolution of 2736×1824 in 3:2 aspect ratio. Scaling by 200% is applied by default in mint. 100% scaling with 2/3rds the resolution works better:

xrandr --newmode "1824x1216_59.96" 186.01 1824 1944 2144 2464 1216 1217 1220 1259 -hsync +vsync
xrandr --addmode eDP-1 "1824x1216_59.96"
howto/surface.1707346411.txt.gz · Last modified: 2024/02/07 22:53 by Wulf Rajek