Skip to content

Commit a0d8383

Browse files
authored
Port of linux-surface/linux-surface Kernel patches to NixOS (#221)
1 parent 8748309 commit a0d8383

File tree

9 files changed

+286
-0
lines changed

9 files changed

+286
-0
lines changed

microsoft/surface/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Derivatives for Microsoft Surface notebooks
2+
3+
These derivatives use the patches from the [linux-surface repo](https://github.com/linux-surface/linux-surface/tree/master/patches).
4+
5+
## Kernel
6+
7+
The kernel needs several patches to make it work correctly with some of the hardware on various
8+
Surface models, e.g. keyboard/trackpad, camera, wifi.
9+
10+
Not all hardware is fully supported, but the
11+
[linux-surface feature matrix](https://github.com/linux-surface/linux-surface/wiki/Supported-Devices-and-Features#feature-matrix)
12+
provides details on which devices are supported on which types of machine.
13+
14+
The kernel-specific derivations are under the `kernel/` sub-directory.
15+
In order to simplify maintenance of the Nix code, only the most-recent kernel patch-set is expected
16+
to be maintained in this repo.
17+
18+
_*NOTE:*_Some built-in Kernel config items need to be set, that aren't set by default:
19+
- https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
20+
21+
## Firmware, Drivers and Support Tools
22+
23+
### WiFi
24+
25+
For the Surface Go, please see the "Issues" sections below.
26+
27+
### IPTS
28+
29+
IPTS is used on most of the Surface range, except for Surface Go and Surface Laptop 3 (AMD version).
30+
31+
Older kernels used specialised firmware which used a method that's no longer supported by the
32+
more-recent kernels.
33+
34+
Newer kernels use the kernel-space `intel-precise-touch` driver and user-space `ipstd` daemon.
35+
36+
The `iptsd` daemon works with the `intel-precise-touch` driver to convert raw touch data from the
37+
kernel-space driver into events for the HID / input sub-system.
38+
39+
- https://github.com/linux-surface/iptsd
40+
- https://github.com/linux-surface/intel-precise-touch
41+
- _*NOTE:*_ The patches from this repo are included in the above kernel patches, already.
42+
43+
### DTX, `surface-control`
44+
45+
*TODO*
46+
47+
# ToDo's Not Done
48+
49+
See: [TODO.org](./TODO.org)
50+
51+
# Issues
52+
53+
## TLP daemon
54+
55+
TLP is known to cause problems on Surface unless correctly configured.
56+
See: https://github.com/linux-surface/linux-surface/blob/master/README.md
57+
58+
## Wifi Firmware for Surface Go
59+
60+
On the Surface Go, the standard firmware from the official Linux Firmware repo has issues with the
61+
`ath10k` QCA6174 Wifi device.
62+
You will see messages like "Can't ping firmware" *TODO - Copy messages from console*
63+
64+
The most effective fix to-date is to remove the `board-2.bin` file or replace it with a copy of the
65+
`board.bin` file.
66+
67+
References:
68+
- https://github.com/jakeday/linux-surface/issues/441
69+
- https://www.reddit.com/r/SurfaceLinux/comments/e8quqg/surface_go_official_wifi_fix/
70+
- https://hackmd.io/@dasgeek/ryA5i5Dor
71+
- https://github.com/thebitstick/surfacego-wifi
72+
- https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/ath10k
73+
- https://wireless.wiki.kernel.org/en/users/drivers/ath10k/firmware

microsoft/surface/TODO.org

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
* Kernel Patching
2+
** DONE Create derivative to patch kernel 5.10.2
3+
- Latest from linux-surface
4+
- [X] Download github.com/linux-surface/linux-surface kernel patches
5+
- [X] Build kernel using downloaded patches
6+
** TODO Create a function for selecting preferred kernel
7+
** DONE Fix how Keyboard & Trackpad are not being enabled on SL3
8+
- https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
9+
* Firmware
10+
** DONE Remove old firmware binaries
11+
- Looks like the ath10k files aren't needed, any more
12+
** DONE Create derivative for `ipts` firmware
13+
- [X] Download github.com/linux-surface/surface-ipts-firmware firmware
14+
- [X] Install the binaries
15+
** DONE Remove `ipts` firmware derivative
16+
- This is only needed on the 4.19 kernel
17+
** TODO Investigate problem with ath10k wifi firmware on Surface Go
18+
*** TODO README entry explaining problem(s) with nonfree firmware on Surface Go
19+
*** TODO Create derivative for `ath10k` firmware on Surface Go
20+
- [X] Download github.com/kvalo/ath10k-firmware ?
21+
- [X] Download kernel.org linux-firmware?
22+
- [ ] Download `board.bin` from Killer Networks?
23+
- [ ] Install ath10k firmware fix for Surface Go
24+
- `board-2.bin` needs to be removed / replaced with `board.bin`
25+
* Support Tools
26+
** TODO Incorporate @hpfr's function(s) from this commit:
27+
- https://github.com/hpfr/system/commit/03fa1b0a83f8a336e812910d0d50f5247a8a630c
28+
** TODO Create derivative for `iptsd` touch-screen daemon
29+
- [ ] Download
30+
- [ ] Install binary
31+
- [ ] Enable via systemd
32+
** TODO Create derivative to patch and rebuild libwacom
33+
- github.com/linux-surface/libwacom-surface
34+
- The plan is to do this in a separate PR against `nixpkgs` instead of `nixos-hardware`
35+
** TODO Create derivative to install `surface-control`
36+
- Download github.com/linux-surface/surface-control
37+
** TODO Create derivative to install `surface-dtx-daemon`
38+
- Download github.com/linux-surface/surface-dtx-daemon

microsoft/surface/default.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ config, lib, pkgs, ... }:
2+
{
3+
imports = [
4+
./kernel
5+
./firmware
6+
./hardware_configuration.nix
7+
];
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{ config, lib, pkgs, ... }:
2+
{
3+
hardware.enableAllFirmware = true;
4+
hardware.firmware = [
5+
];
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ config, lib, pkgs, ... }:
2+
{
3+
boot.extraModprobeConfig = lib.mkDefault ''
4+
options i915 enable_fbc=1 enable_rc6=1 modeset=1
5+
options snd_hda_intel power_save=1
6+
options snd_ac97_codec power_save=1
7+
options iwlwifi power_save=Y
8+
options iwldvm force_cam=N
9+
options ath10k_core skip_otp=Y
10+
'';
11+
12+
boot.kernelParams = [ "mem_sleep_default=deep" ];
13+
14+
# NOTE: Check the README before enabling TLP:
15+
services.tlp.enable = lib.mkDefault false;
16+
17+
hardware.sensor.iio.enable = lib.mkDefault true;
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
{
4+
boot.kernelPackages = pkgs.callPackage ./linux-5.10.2 {};
5+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{ config, lib, pkgs, ... }:
2+
let
3+
repos = (pkgs.callPackage ../../repos.nix {});
4+
# TODO: Can I append the path ./patches instead of a string?
5+
patches = repos.linux-surface + "/patches";
6+
surface_kernelPatches = [
7+
{ name = "microsoft-surface-patches-linux-5.10.2";
8+
patch = null;
9+
extraConfig = ''
10+
#
11+
# Surface Aggregator Module
12+
#
13+
SURFACE_AGGREGATOR m
14+
SURFACE_AGGREGATOR_ERROR_INJECTION n
15+
SURFACE_AGGREGATOR_BUS y
16+
SURFACE_AGGREGATOR_CDEV m
17+
SURFACE_AGGREGATOR_REGISTRY m
18+
SURFACE_ACPI_NOTIFY m
19+
SURFACE_BATTERY m
20+
SURFACE_DTX m
21+
SURFACE_HID m
22+
SURFACE_PERFMODE m
23+
24+
#
25+
# These built-in modules are required for the Surface Aggregator Module
26+
# See: https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
27+
#
28+
SERIAL_DEV_BUS y
29+
SERIAL_DEV_CTRL_TTYPORT y
30+
31+
#
32+
# Surface Hotplug
33+
#
34+
SURFACE_HOTPLUG m
35+
36+
#
37+
# IPTS touchscreen
38+
#
39+
# This only enables the user interface for IPTS data.
40+
# For the touchscreen to work, you need to install iptsd.
41+
#
42+
MISC_IPTS m
43+
44+
#
45+
# Cameras: IPU3
46+
#
47+
## TODO: Fix for kernel 5.10.2:
48+
##VIDEO_IPU3_IMGU m
49+
VIDEO_IPU3_CIO2 m
50+
CIO2_BRIDGE y
51+
INT3472 m
52+
53+
#
54+
# Cameras: Sensor drivers
55+
#
56+
VIDEO_OV5693 m
57+
## TODO: Fix for kernel 5.10.2:
58+
##VIDEO_OV8865 m
59+
60+
#
61+
# Other Drivers
62+
#
63+
INPUT_SOC_BUTTON_ARRAY m
64+
SURFACE_3_BUTTON m
65+
SURFACE_3_POWER_OPREGION m
66+
SURFACE_PRO3_BUTTON m
67+
SURFACE_GPE m
68+
SURFACE_BOOK1_DGPU_SWITCH m
69+
'';
70+
}
71+
{
72+
name = "ms-surface/0001-surface3-oemb";
73+
patch = patches + "/5.10/0001-surface3-oemb.patch";
74+
}
75+
{
76+
name = "ms-surface/0002-wifi";
77+
patch = patches + "/5.10/0002-wifi.patch";
78+
}
79+
{
80+
name = "ms-surface/0003-ipts";
81+
patch = patches + "/5.10/0003-ipts.patch";
82+
}
83+
{
84+
name = "ms-surface/0004-surface-gpe";
85+
patch = patches + "/5.10/0004-surface-gpe.patch";
86+
}
87+
{
88+
name = "ms-surface/0005-surface-sam-over-hid";
89+
patch = patches + "/5.10/0005-surface-sam-over-hid.patch";
90+
}
91+
{
92+
name = "ms-surface/0006-surface-sam";
93+
patch = patches + "/5.10/0006-surface-sam.patch";
94+
}
95+
{
96+
name = "ms-surface/0007-surface-hotplug";
97+
patch = patches + "/5.10/0007-surface-hotplug.patch";
98+
}
99+
{
100+
name = "ms-surface/0008-surface-typecover";
101+
patch = patches + "/5.10/0008-surface-typecover.patch";
102+
}
103+
{
104+
name = "ms-surface/0009-cameras";
105+
patch = patches + "/5.10/0009-cameras.patch";
106+
}
107+
];
108+
in (with pkgs; recurseIntoAttrs (linuxPackagesFor (
109+
callPackage ./linux-5.10.2.nix {
110+
kernelPatches = surface_kernelPatches;
111+
}
112+
)))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ stdenv, buildPackages, fetchurl, perl, buildLinux, modDirVersionArg ? null, ... } @ args:
2+
3+
with stdenv.lib;
4+
5+
buildLinux (args // rec {
6+
version = "5.10.2";
7+
8+
# modDirVersion needs to be x.y.z, will automatically add .0 if needed
9+
modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg;
10+
11+
# branchVersion needs to be x.y
12+
extraMeta.branch = versions.majorMinor version;
13+
14+
src = fetchurl {
15+
url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
16+
sha256 = "18l1ywp99inm90434fm74w8rjfl4yl974kfcpizg2sp2p8xf311v";
17+
};
18+
} // (args.argsOverride or {}))

microsoft/surface/repos.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ lib, pkgs, fetchgit }:
2+
{
3+
linux-surface = fetchgit {
4+
url="https://github.com/linux-surface/linux-surface.git";
5+
rev="25ab2cf75e5eda5ab9739db1907300010c06dacf";
6+
sha256="0h8624d7ix1p6ysw9bllmnnwnv164z8xkx56zj3vdczn91vmqcf9";
7+
};
8+
}

0 commit comments

Comments
 (0)