Skip to content

Commit f7bee55

Browse files
authored
Merge pull request #1443 from 8bitbuddhist/surface/kernel-multiple-versions
feat: add kernel switching for Microsoft Surface devices
2 parents b673d3a + 306ff6c commit f7bee55

File tree

9 files changed

+265
-95
lines changed

9 files changed

+265
-95
lines changed

microsoft/surface/README.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# NOTE: Structure changes from 2023-01-10
2-
3-
Please read the [Deprecated Behaviour README](./OLD-BEHAVIOUR-DEPRECATION.md) to understand how some structural changes to
4-
the code might affect you!
5-
61
# Derivations for Microsoft Surface notebooks
72

83
These derivatives use the patches from the [linux-surface repo](https://github.com/linux-surface/linux-surface/tree/master/patches).
@@ -32,13 +27,24 @@ Not all hardware is fully supported, but the
3227
[linux-surface feature matrix](https://github.com/linux-surface/linux-surface/wiki/Supported-Devices-and-Features#feature-matrix)
3328
provides details on which devices are supported on which types of machine.
3429

35-
The kernel-specific derivations are under the [`common/kernel/`](./common/kernel/) sub-directory.
36-
In order to simplify maintenance of the Nix code, only the most-recent kernel patch-set is expected
37-
to be maintained in this repo.
30+
The kernel-specific derivations are under the [`common/kernel/`](./common/kernel/) sub-directory. This directory defines patch sets for each supported kernel release (see Kernel versions below for more information).
3831

3932
_*NOTE:*_ Some built-in Kernel config items need to be set, that aren't set by default:
4033
- https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
4134

35+
#### Kernel versions
36+
37+
There are multiple versions of the Surface kernel available:
38+
39+
- `longterm`, which tracks the latest long term support (LTS) release.
40+
- `stable`, which tracks the most recent stable release.
41+
42+
This repo uses `longterm` by default, but you can switch it to `stable` by adding this to your configuration file:
43+
44+
```nix
45+
hardware.microsoft-surface.kernelVersion = "stable";
46+
```
47+
4248
### Support Tools
4349

4450
### IPTS
@@ -120,3 +126,7 @@ References:
120126
- https://github.com/thebitstick/surfacego-wifi
121127
- https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/ath10k
122128
- https://wireless.wiki.kernel.org/en/users/drivers/ath10k/firmware
129+
130+
## Structural changes from earlier versions (2023-01-10 and earlier)
131+
132+
If you're upgrading from an older version of nixos-hardware, please read the [Deprecated Behaviour README](./OLD-BEHAVIOUR-DEPRECATION.md) to understand how some structural changes to the code might affect you!

microsoft/surface/common/default.nix

+80-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,89 @@
1-
{ lib, ... }:
1+
{ config, lib, pkgs, ... }:
22

33
let
4-
inherit (lib) mkDefault;
4+
inherit (lib) mkDefault mkOption types versions;
5+
6+
# Set the version and hash for the kernel sources
7+
srcVersion = with config.hardware.microsoft-surface;
8+
if kernelVersion == "longterm" then
9+
"6.12.19"
10+
else if kernelVersion == "stable" then
11+
"6.14.2"
12+
else
13+
abort "Invalid kernel version: ${kernelVersion}";
14+
15+
srcHash = with config.hardware.microsoft-surface;
16+
if kernelVersion == "longterm" then
17+
"sha256-1zvwV77ARDSxadG2FkGTb30Ml865I6KB8y413U3MZTE="
18+
else if kernelVersion == "stable" then
19+
"sha256-xcaCo1TqMZATk1elfTSnnlw3IhrOgjqTjhARa1d6Lhs="
20+
else
21+
abort "Invalid kernel version: ${kernelVersion}";
22+
23+
# Set the version and hash for the linux-surface releases
24+
pkgVersion = with config.hardware.microsoft-surface;
25+
if kernelVersion == "longterm" then
26+
"6.12.7"
27+
else if kernelVersion == "stable" then
28+
"6.14.2"
29+
else
30+
abort "Invalid kernel version: ${kernelVersion}";
31+
32+
pkgHash = with config.hardware.microsoft-surface;
33+
if kernelVersion == "longterm" then
34+
"sha256-Pv7O8D8ma+MPLhYP3HSGQki+Yczp8b7d63qMb6l4+mY="
35+
else if kernelVersion == "stable" then
36+
"sha256-Pzn+C52TtDcqDVepM5z2cVNCsnRDy0Wwn+FLwgsuicQ="
37+
else
38+
abort "Invalid kernel version: ${kernelVersion}";
39+
40+
# Fetch the linux-surface package
41+
repos = pkgs.callPackage ({ fetchFromGitHub, rev, hash }: {
42+
linux-surface = fetchFromGitHub {
43+
owner = "linux-surface";
44+
repo = "linux-surface";
45+
rev = rev;
46+
hash = hash;
47+
};
48+
}) { hash = pkgHash; rev = "arch-${pkgVersion}-1"; };
49+
50+
# Fetch and build the kernel package
51+
inherit (pkgs.callPackage ./kernel/linux-package.nix { inherit repos; }) linuxPackage surfacePatches;
52+
kernelPatches = surfacePatches {
53+
version = pkgVersion;
54+
patchFn = ./kernel/${versions.majorMinor pkgVersion}/patches.nix;
55+
};
56+
kernelPackages = linuxPackage {
57+
inherit kernelPatches; version = srcVersion;
58+
sha256 = srcHash;
59+
ignoreConfigErrors=true;
60+
};
561

662
in {
7-
imports = [
8-
./kernel
9-
];
63+
options.hardware.microsoft-surface.kernelVersion = mkOption {
64+
description = "Kernel Version to use (patched for MS Surface)";
65+
type = types.enum [
66+
"longterm"
67+
"stable"
68+
];
69+
default = "longterm";
70+
};
1071

11-
microsoft-surface.kernelVersion = mkDefault "6.12";
72+
config = {
73+
boot = {
74+
inherit kernelPackages;
1275

13-
# Seems to be required to properly enable S0ix "Modern Standby":
14-
boot.kernelParams = mkDefault [ "mem_sleep_default=deep" ];
76+
# Seems to be required to properly enable S0ix "Modern Standby":
77+
kernelParams = mkDefault [ "mem_sleep_default=deep" ];
78+
};
1579

16-
# NOTE: Check the README before enabling TLP:
17-
services.tlp.enable = mkDefault false;
80+
# NOTE: Check the README before enabling TLP:
81+
services.tlp.enable = mkDefault false;
1882

19-
# i.e. needed for wifi firmware, see https://github.com/NixOS/nixos-hardware/issues/364
20-
hardware.enableRedistributableFirmware = mkDefault true;
21-
hardware.sensor.iio.enable = mkDefault true;
83+
# Needed for wifi firmware, see https://github.com/NixOS/nixos-hardware/issues/364
84+
hardware = {
85+
enableRedistributableFirmware = mkDefault true;
86+
sensor.iio.enable = mkDefault true;
87+
};
88+
};
2289
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{ lib,
2+
kernel ? lib.kernel,
3+
patchSrc,
4+
version,
5+
}:
6+
7+
[
8+
{
9+
name = "microsoft-surface-patches-linux-${version}";
10+
patch = null;
11+
extraStructuredConfig = with kernel; {
12+
STAGING_MEDIA = yes;
13+
##
14+
## Surface Aggregator Module
15+
##
16+
CONFIG_SURFACE_AGGREGATOR = module;
17+
# CONFIG_SURFACE_AGGREGATOR_ERROR_INJECTION is not set
18+
CONFIG_SURFACE_AGGREGATOR_BUS = yes;
19+
CONFIG_SURFACE_AGGREGATOR_CDEV = module;
20+
CONFIG_SURFACE_AGGREGATOR_HUB = module;
21+
CONFIG_SURFACE_AGGREGATOR_REGISTRY = module;
22+
CONFIG_SURFACE_AGGREGATOR_TABLET_SWITCH = module;
23+
24+
CONFIG_SURFACE_ACPI_NOTIFY = module;
25+
CONFIG_SURFACE_DTX = module;
26+
CONFIG_SURFACE_PLATFORM_PROFILE = module;
27+
28+
CONFIG_SURFACE_HID = module;
29+
CONFIG_SURFACE_KBD = module;
30+
31+
CONFIG_BATTERY_SURFACE = module;
32+
CONFIG_CHARGER_SURFACE = module;
33+
34+
CONFIG_SENSORS_SURFACE_TEMP = module;
35+
CONFIG_SENSORS_SURFACE_FAN = module;
36+
37+
CONFIG_RTC_DRV_SURFACE = module;
38+
39+
##
40+
## Surface Hotplug
41+
##
42+
CONFIG_SURFACE_HOTPLUG = module;
43+
44+
##
45+
## IPTS and ITHC touchscreen
46+
##
47+
## This only enables the user interface for IPTS/ITHC data.
48+
## For the touchscreen to work, you need to install iptsd.
49+
##
50+
CONFIG_HID_IPTS = module;
51+
CONFIG_HID_ITHC = module;
52+
53+
##
54+
## Cameras: IPU3
55+
##
56+
CONFIG_VIDEO_DW9719 = module;
57+
CONFIG_VIDEO_IPU3_IMGU = module;
58+
CONFIG_VIDEO_IPU3_CIO2 = module;
59+
CONFIG_IPU_BRIDGE = module;
60+
CONFIG_INTEL_SKL_INT3472 = module;
61+
CONFIG_REGULATOR_TPS68470 = module;
62+
CONFIG_COMMON_CLK_TPS68470 = module;
63+
CONFIG_LEDS_TPS68470 = module;
64+
65+
##
66+
## Cameras: Sensor drivers
67+
##
68+
CONFIG_VIDEO_OV5693 = module;
69+
CONFIG_VIDEO_OV7251 = module;
70+
CONFIG_VIDEO_OV8865 = module;
71+
72+
##
73+
## Surface 3: atomisp causes problems (see issue #1095). Disable it for now.
74+
##
75+
# CONFIG_INTEL_ATOMISP is not set
76+
77+
##
78+
## ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7
79+
##
80+
CONFIG_APDS9960 = module;
81+
82+
##
83+
## Build-in UFS support (required for some Surface Go devices)
84+
##
85+
CONFIG_SCSI_UFSHCD = module;
86+
CONFIG_SCSI_UFSHCD_PCI = module;
87+
88+
##
89+
## Other Drivers
90+
##
91+
CONFIG_INPUT_SOC_BUTTON_ARRAY = module;
92+
CONFIG_SURFACE_3_POWER_OPREGION = module;
93+
CONFIG_SURFACE_PRO3_BUTTON = module;
94+
CONFIG_SURFACE_GPE = module;
95+
CONFIG_SURFACE_BOOK1_DGPU_SWITCH = module;
96+
};
97+
}
98+
{
99+
name = "ms-surface/0001-secureboot";
100+
patch = patchSrc + "/0001-secureboot.patch";
101+
}
102+
{
103+
name = "ms-surface/0002-surface3";
104+
patch = patchSrc + "/0002-surface3.patch";
105+
}
106+
{
107+
name = "ms-surface/0003-mwifiex";
108+
patch = patchSrc + "/0003-mwifiex.patch";
109+
}
110+
{
111+
name = "ms-surface/0004-ath10k";
112+
patch = patchSrc + "/0004-ath10k.patch";
113+
}
114+
{
115+
name = "ms-surface/0005-ipts";
116+
patch = patchSrc + "/0005-ipts.patch";
117+
}
118+
{
119+
name = "ms-surface/0006-ithc";
120+
patch = patchSrc + "/0006-ithc.patch";
121+
}
122+
{
123+
name = "ms-surface/0007-surface-sam";
124+
patch = patchSrc + "/0007-surface-sam.patch";
125+
}
126+
{
127+
name = "ms-surface/0008-surface-sam-over-hid";
128+
patch = patchSrc + "/0008-surface-sam-over-hid.patch";
129+
}
130+
{
131+
name = "ms-surface/0009-surface-button";
132+
patch = patchSrc + "/0009-surface-button.patch";
133+
}
134+
{
135+
name = "ms-surface/0010-surface-typecover";
136+
patch = patchSrc + "/0010-surface-typecover.patch";
137+
}
138+
{
139+
name = "ms-surface/0011-surface-shutdown";
140+
patch = patchSrc + "/0011-surface-shutdown.patch";
141+
}
142+
{
143+
name = "ms-surface/0012-surface-gpe";
144+
patch = patchSrc + "/0012-surface-gpe.patch";
145+
}
146+
{
147+
name = "ms-surface/0013-cameras";
148+
patch = patchSrc + "/0013-cameras.patch";
149+
}
150+
{
151+
name = "ms-surface/0014-amd-gpio";
152+
patch = patchSrc + "/0014-amd-gpio.patch";
153+
}
154+
{
155+
name = "ms-surface/0015-rtc";
156+
patch = patchSrc + "/0015-rtc.patch";
157+
}
158+
]

microsoft/surface/common/kernel/default.nix

-15
This file was deleted.

microsoft/surface/common/kernel/linux-package.nix

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
fetchurl,
44
buildLinux,
55
linuxPackagesFor,
6+
repos,
67
}:
78

89
let
910
inherit (builtins) elem;
1011
inherit (lib) recurseIntoAttrs types versions;
1112

12-
repos = pkgs.callPackage ../repos.nix {};
13-
1413
linuxPackage =
1514
{ url ? "mirror://kernel/linux/kernel/v${versions.major version}.x/linux-${version}.tar.xz",
1615
sha256 ? null,

microsoft/surface/common/kernel/linux-surface/default.nix

-31
This file was deleted.

microsoft/surface/common/repos.nix

-25
This file was deleted.

0 commit comments

Comments
 (0)