about summary refs log tree commit diff
path: root/modules/nixos-hardware/microsoft
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-02-27 02:57:35 +0000
committerAlyssa Ross <hi@alyssa.is>2021-02-27 03:02:31 +0000
commitab630003f4951542d7f246f25c11a19dc718bb64 (patch)
treef62eee9a6e91ad9d6ce6a62d68facd23c3c36dbe /modules/nixos-hardware/microsoft
parent7eb57d645ab60d8e61911c1aebc221cc2b9d98f8 (diff)
parent115770eed0c0fa50c1277cd0f7fe0f15501dbc43 (diff)
downloadnixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar.gz
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar.bz2
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar.lz
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar.xz
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.tar.zst
nixlib-ab630003f4951542d7f246f25c11a19dc718bb64.zip
modules/nixos-hardware: merge 115770eed0c
Diffstat (limited to 'modules/nixos-hardware/microsoft')
-rw-r--r--modules/nixos-hardware/microsoft/surface-pro/3/default.nix7
-rw-r--r--modules/nixos-hardware/microsoft/surface/README.md73
-rw-r--r--modules/nixos-hardware/microsoft/surface/TODO.org38
-rw-r--r--modules/nixos-hardware/microsoft/surface/default.nix8
-rw-r--r--modules/nixos-hardware/microsoft/surface/firmware/default.nix6
-rw-r--r--modules/nixos-hardware/microsoft/surface/hardware_configuration.nix18
-rw-r--r--modules/nixos-hardware/microsoft/surface/kernel/default.nix5
-rw-r--r--modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/default.nix112
-rw-r--r--modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/linux-5.10.2.nix18
-rw-r--r--modules/nixos-hardware/microsoft/surface/repos.nix8
10 files changed, 287 insertions, 6 deletions
diff --git a/modules/nixos-hardware/microsoft/surface-pro/3/default.nix b/modules/nixos-hardware/microsoft/surface-pro/3/default.nix
index a09c60b1f205..4fa8f79a4135 100644
--- a/modules/nixos-hardware/microsoft/surface-pro/3/default.nix
+++ b/modules/nixos-hardware/microsoft/surface-pro/3/default.nix
@@ -1,9 +1,4 @@
 { lib, ... }:
-
 {
-  # to use the type cover in the initrd
-  boot.kernelModules = [ "hid-microsoft" ];
-
-  # TODO: reverse compat
-  networking.wireless.enable = lib.mkDefault true;
+  imports = [ ../../surface ];
 }
diff --git a/modules/nixos-hardware/microsoft/surface/README.md b/modules/nixos-hardware/microsoft/surface/README.md
new file mode 100644
index 000000000000..d67a91e9a161
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/README.md
@@ -0,0 +1,73 @@
+# Derivatives for Microsoft Surface notebooks
+
+These derivatives use the patches from the [linux-surface repo](https://github.com/linux-surface/linux-surface/tree/master/patches).
+
+## Kernel
+
+The kernel needs several patches to make it work correctly with some of the hardware on various
+Surface models, e.g. keyboard/trackpad, camera, wifi.
+
+Not all hardware is fully supported, but the
+[linux-surface feature matrix](https://github.com/linux-surface/linux-surface/wiki/Supported-Devices-and-Features#feature-matrix)
+provides details on which devices are supported on which types of machine.
+
+The kernel-specific derivations are under the `kernel/` sub-directory.
+In order to simplify maintenance of the Nix code, only the most-recent kernel patch-set is expected
+to be maintained in this repo.
+
+_*NOTE:*_Some built-in Kernel config items need to be set, that aren't set by default:
+- https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
+
+## Firmware, Drivers and Support Tools
+
+### WiFi
+
+For the Surface Go, please see the "Issues" sections below.
+
+### IPTS
+
+IPTS is used on most of the Surface range, except for Surface Go and Surface Laptop 3 (AMD version).
+
+Older kernels used specialised firmware which used a method that's no longer supported by the
+more-recent kernels.
+
+Newer kernels use the kernel-space `intel-precise-touch` driver and user-space `ipstd` daemon.
+
+The `iptsd` daemon works with the `intel-precise-touch` driver to convert raw touch data from the
+kernel-space driver into events for the HID / input sub-system.
+
+- https://github.com/linux-surface/iptsd
+- https://github.com/linux-surface/intel-precise-touch
+  - _*NOTE:*_ The patches from this repo are included in the above kernel patches, already.
+
+### DTX, `surface-control`
+
+*TODO*
+
+# ToDo's Not Done
+
+See: [TODO.org](./TODO.org)
+
+# Issues
+
+## TLP daemon
+
+TLP is known to cause problems on Surface unless correctly configured.
+See: https://github.com/linux-surface/linux-surface/blob/master/README.md
+
+## Wifi Firmware for Surface Go
+
+On the Surface Go, the standard firmware from the official Linux Firmware repo has issues with the
+`ath10k` QCA6174 Wifi device.
+You will see messages like "Can't ping firmware" *TODO - Copy messages from console*
+
+The most effective fix to-date is to remove the `board-2.bin` file or replace it with a copy of the
+`board.bin` file.
+
+References:
+- https://github.com/jakeday/linux-surface/issues/441
+- https://www.reddit.com/r/SurfaceLinux/comments/e8quqg/surface_go_official_wifi_fix/
+- https://hackmd.io/@dasgeek/ryA5i5Dor
+- https://github.com/thebitstick/surfacego-wifi
+- https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/ath10k
+- https://wireless.wiki.kernel.org/en/users/drivers/ath10k/firmware
diff --git a/modules/nixos-hardware/microsoft/surface/TODO.org b/modules/nixos-hardware/microsoft/surface/TODO.org
new file mode 100644
index 000000000000..7db7ea42d23d
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/TODO.org
@@ -0,0 +1,38 @@
+* Kernel Patching
+** DONE Create derivative to patch kernel 5.10.2
+   - Latest from linux-surface
+   - [X] Download github.com/linux-surface/linux-surface kernel patches
+   - [X] Build kernel using downloaded patches
+** TODO Create a function for selecting preferred kernel
+** DONE Fix how Keyboard & Trackpad are not being enabled on SL3
+   - https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
+* Firmware
+** DONE Remove old firmware binaries
+   - Looks like the ath10k files aren't needed, any more
+** DONE Create derivative for `ipts` firmware
+   - [X] Download github.com/linux-surface/surface-ipts-firmware firmware
+   - [X] Install the binaries
+** DONE Remove `ipts` firmware derivative
+   - This is only needed on the 4.19 kernel
+** TODO Investigate problem with ath10k wifi firmware on Surface Go
+*** TODO README entry explaining problem(s) with nonfree firmware on Surface Go
+*** TODO Create derivative for `ath10k` firmware on Surface Go
+    - [X] Download github.com/kvalo/ath10k-firmware ?
+    - [X] Download kernel.org linux-firmware?
+    - [ ] Download `board.bin` from Killer Networks?
+    - [ ] Install ath10k firmware fix for Surface Go
+      - `board-2.bin` needs to be removed / replaced with `board.bin`
+* Support Tools
+** TODO Incorporate @hpfr's function(s) from this commit:
+   - https://github.com/hpfr/system/commit/03fa1b0a83f8a336e812910d0d50f5247a8a630c
+** TODO Create derivative for `iptsd` touch-screen daemon
+   - [ ] Download
+   - [ ] Install binary
+   - [ ] Enable via systemd
+** TODO Create derivative to patch and rebuild libwacom
+   - github.com/linux-surface/libwacom-surface
+   - The plan is to do this in a separate PR against `nixpkgs` instead of `nixos-hardware`
+** TODO Create derivative to install `surface-control`
+   - Download github.com/linux-surface/surface-control
+** TODO Create derivative to install `surface-dtx-daemon`
+   - Download github.com/linux-surface/surface-dtx-daemon
diff --git a/modules/nixos-hardware/microsoft/surface/default.nix b/modules/nixos-hardware/microsoft/surface/default.nix
new file mode 100644
index 000000000000..7a49d08f945b
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/default.nix
@@ -0,0 +1,8 @@
+{ config, lib, pkgs, ... }:
+{
+  imports = [
+    ./kernel
+    ./firmware
+    ./hardware_configuration.nix
+  ];
+}
diff --git a/modules/nixos-hardware/microsoft/surface/firmware/default.nix b/modules/nixos-hardware/microsoft/surface/firmware/default.nix
new file mode 100644
index 000000000000..67f2ce229214
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/firmware/default.nix
@@ -0,0 +1,6 @@
+{ config, lib, pkgs, ... }:
+{
+  hardware.enableAllFirmware = true;
+  hardware.firmware = [
+  ];
+}
diff --git a/modules/nixos-hardware/microsoft/surface/hardware_configuration.nix b/modules/nixos-hardware/microsoft/surface/hardware_configuration.nix
new file mode 100644
index 000000000000..2053b01acd49
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/hardware_configuration.nix
@@ -0,0 +1,18 @@
+{ config, lib, pkgs, ... }:
+{
+  boot.extraModprobeConfig = lib.mkDefault ''
+    options i915 enable_fbc=1 enable_rc6=1 modeset=1
+    options snd_hda_intel power_save=1
+    options snd_ac97_codec power_save=1
+    options iwlwifi power_save=Y
+    options iwldvm force_cam=N
+    options ath10k_core skip_otp=Y
+  '';
+
+  boot.kernelParams = [ "mem_sleep_default=deep" ];
+
+  # NOTE: Check the README before enabling TLP:
+  services.tlp.enable = lib.mkDefault false;
+
+  hardware.sensor.iio.enable = lib.mkDefault true;
+}
diff --git a/modules/nixos-hardware/microsoft/surface/kernel/default.nix b/modules/nixos-hardware/microsoft/surface/kernel/default.nix
new file mode 100644
index 000000000000..b280f2d9941c
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/kernel/default.nix
@@ -0,0 +1,5 @@
+{ config, lib, pkgs, ... }:
+
+{
+  boot.kernelPackages = pkgs.callPackage ./linux-5.10.2 {};
+}
diff --git a/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/default.nix b/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/default.nix
new file mode 100644
index 000000000000..d4f6eb4eb9d8
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/default.nix
@@ -0,0 +1,112 @@
+{ config, lib, pkgs, ... }:
+let
+  repos = (pkgs.callPackage ../../repos.nix {});
+  # TODO: Can I append the path ./patches instead of a string?
+  patches = repos.linux-surface + "/patches";
+  surface_kernelPatches = [
+    { name = "microsoft-surface-patches-linux-5.10.2";
+      patch = null;
+      extraConfig = ''
+          #
+          # Surface Aggregator Module
+          #
+          SURFACE_AGGREGATOR m
+          SURFACE_AGGREGATOR_ERROR_INJECTION n
+          SURFACE_AGGREGATOR_BUS y
+          SURFACE_AGGREGATOR_CDEV m
+          SURFACE_AGGREGATOR_REGISTRY m
+          SURFACE_ACPI_NOTIFY m
+          SURFACE_BATTERY m
+          SURFACE_DTX m
+          SURFACE_HID m
+          SURFACE_PERFMODE m
+
+          #
+          # These built-in modules are required for the Surface Aggregator Module
+          # See: https://github.com/linux-surface/surface-aggregator-module/wiki/Testing-and-Installing
+          #
+          SERIAL_DEV_BUS y
+          SERIAL_DEV_CTRL_TTYPORT y
+
+          #
+          # Surface Hotplug
+          #
+          SURFACE_HOTPLUG m
+
+          #
+          # IPTS touchscreen
+          #
+          # This only enables the user interface for IPTS data.
+          # For the touchscreen to work, you need to install iptsd.
+          #
+          MISC_IPTS m
+
+          #
+          # Cameras: IPU3
+          #
+          ## TODO: Fix for kernel 5.10.2:
+          ##VIDEO_IPU3_IMGU m
+          VIDEO_IPU3_CIO2 m
+          CIO2_BRIDGE y
+          INT3472 m
+
+          #
+          # Cameras: Sensor drivers
+          #
+          VIDEO_OV5693 m
+          ## TODO: Fix for kernel 5.10.2:
+          ##VIDEO_OV8865 m
+
+          #
+          # Other Drivers
+          #
+          INPUT_SOC_BUTTON_ARRAY m
+          SURFACE_3_BUTTON m
+          SURFACE_3_POWER_OPREGION m
+          SURFACE_PRO3_BUTTON m
+          SURFACE_GPE m
+          SURFACE_BOOK1_DGPU_SWITCH m
+        '';
+    }
+    {
+      name = "ms-surface/0001-surface3-oemb";
+      patch = patches + "/5.10/0001-surface3-oemb.patch";
+    }
+    {
+      name = "ms-surface/0002-wifi";
+      patch = patches + "/5.10/0002-wifi.patch";
+    }
+    {
+      name = "ms-surface/0003-ipts";
+      patch = patches + "/5.10/0003-ipts.patch";
+    }
+    {
+      name = "ms-surface/0004-surface-gpe";
+      patch = patches + "/5.10/0004-surface-gpe.patch";
+    }
+    {
+      name = "ms-surface/0005-surface-sam-over-hid";
+      patch = patches + "/5.10/0005-surface-sam-over-hid.patch";
+    }
+    {
+      name = "ms-surface/0006-surface-sam";
+      patch = patches + "/5.10/0006-surface-sam.patch";
+    }
+    {
+      name = "ms-surface/0007-surface-hotplug";
+      patch = patches + "/5.10/0007-surface-hotplug.patch";
+    }
+    {
+      name = "ms-surface/0008-surface-typecover";
+      patch = patches + "/5.10/0008-surface-typecover.patch";
+    }
+    {
+      name = "ms-surface/0009-cameras";
+      patch = patches + "/5.10/0009-cameras.patch";
+    }
+  ];
+in (with pkgs; recurseIntoAttrs (linuxPackagesFor (
+     callPackage ./linux-5.10.2.nix {
+       kernelPatches = surface_kernelPatches;
+     }
+   )))
diff --git a/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/linux-5.10.2.nix b/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/linux-5.10.2.nix
new file mode 100644
index 000000000000..411a88d92934
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/kernel/linux-5.10.2/linux-5.10.2.nix
@@ -0,0 +1,18 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, modDirVersionArg ? null, ... } @ args:
+
+with stdenv.lib;
+
+buildLinux (args // rec {
+  version = "5.10.2";
+
+  # modDirVersion needs to be x.y.z, will automatically add .0 if needed
+  modDirVersion = if (modDirVersionArg == null) then concatStringsSep "." (take 3 (splitVersion "${version}.0")) else modDirVersionArg;
+
+  # branchVersion needs to be x.y
+  extraMeta.branch = versions.majorMinor version;
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
+    sha256 = "18l1ywp99inm90434fm74w8rjfl4yl974kfcpizg2sp2p8xf311v";
+  };
+} // (args.argsOverride or {}))
diff --git a/modules/nixos-hardware/microsoft/surface/repos.nix b/modules/nixos-hardware/microsoft/surface/repos.nix
new file mode 100644
index 000000000000..86424162e399
--- /dev/null
+++ b/modules/nixos-hardware/microsoft/surface/repos.nix
@@ -0,0 +1,8 @@
+{ lib, pkgs, fetchgit }:
+{
+  linux-surface = fetchgit {
+    url="https://github.com/linux-surface/linux-surface.git";
+    rev="25ab2cf75e5eda5ab9739db1907300010c06dacf";
+    sha256="0h8624d7ix1p6ysw9bllmnnwnv164z8xkx56zj3vdczn91vmqcf9";
+  };
+}