diff --git a/README.md b/README.md index 1992563a1..4a5e8c82f 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,7 @@ See code for all available configurations. | [Panasonic Let's Note CF-LX4](panasonic/letsnote/cf-lx4) | `` | | [PC Engines APU](pcengines/apu) | `` | | [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `` | +| [PINE64 Pinephone Pro](pine64/pinephone-pro/) | `` | | [PINE64 RockPro64](pine64/rockpro64/) | `` | | [PINE64 STAR64](pine64/star64/) | `` | | [Protectli VP4670](protectli/vp4670/) | `` | diff --git a/flake.nix b/flake.nix index 0be724586..33a364d5c 100644 --- a/flake.nix +++ b/flake.nix @@ -247,6 +247,7 @@ olimex-teres_i = import ./olimex/teres_i; pcengines-apu = import ./pcengines/apu; pine64-pinebook-pro = import ./pine64/pinebook-pro; + pine64-pinephone-pro = import ./pine64/pinephone-pro; pine64-rockpro64 = import ./pine64/rockpro64; pine64-star64 = import ./pine64/star64; protectli-vp4670 = import ./protectli/vp4670; diff --git a/pine64/pinephone-pro/README.md b/pine64/pinephone-pro/README.md new file mode 100644 index 000000000..54a6e744d --- /dev/null +++ b/pine64/pinephone-pro/README.md @@ -0,0 +1,13 @@ +# Pine64 PinePhone Pro +## Bootloader +Either [Tow-Boot](https://github.com/Tow-Boot/Tow-Boot) or Megi's [rk2aw](https://xnux.eu/rk2aw/) are recommended to +allow boot via `boot.loader.generic-extlinux-compatible`. rk2aw features a touch-based boot selection which should +provide the ability to choose the NixOS generation. + +## Known Issues +- Audio is currently broken +- The `brcmfmac` driver regularly spews the following error `brcmf_set_channel: set chanspec 0x???? fail, reason -52` + this has been somewhat alleviated by [disabling SAE](./wifi.nix#L7) to the point of allowing WiFi to function + but the issue still remains. +- The cameras are curretly broken, patches exist but need to be rebased to be applicable +- panfrost crashes sometimes diff --git a/pine64/pinephone-pro/default.nix b/pine64/pinephone-pro/default.nix new file mode 100644 index 000000000..dda7b4c42 --- /dev/null +++ b/pine64/pinephone-pro/default.nix @@ -0,0 +1,41 @@ +{ + pkgs, + lib, + config, + ... +}: +let + cfg = config.hardware.pinephone-pro; +in +{ + imports = [ ./wifi.nix ]; + options.hardware.pinephone-pro = { + install-ucm2-rules = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to install PinePhone Pro specific UCM2 rules. + These provide audio usecaseses for HiFi audio and Voice calls. + ''; + }; + }; + config = { + nixpkgs.overlays = [ + (final: _prev: { + pine64-alsa-ucm = final.callPackage ./pine64-alsa-ucm { }; + firmware_pinephone-pro = pkgs.callPackage ./firmware.nix { }; + linuxPackages_pinephone-pro = pkgs.callPackage ./kernel { inherit (config.boot) kernelPatches; }; + }) + ]; + hardware.firmware = [ pkgs.firmware_pinephone-pro ]; + environment.systemPackages = lib.optionals cfg.install-ucm2-rules [ pkgs.pine64-alsa-ucm ]; + + boot = { + kernelPackages = pkgs.linuxPackagesFor pkgs.linuxPackages_pinephone-pro; + loader = { + generic-extlinux-compatible.enable = true; + grub.enable = false; + }; + }; + }; +} diff --git a/pine64/pinephone-pro/firmware.nix b/pine64/pinephone-pro/firmware.nix new file mode 100644 index 000000000..ae954fa22 --- /dev/null +++ b/pine64/pinephone-pro/firmware.nix @@ -0,0 +1,70 @@ +# MIT License + +# Copyright (c) 2018-2020 Samuel Dionne-Riel and the Mobile NixOS contributors + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +{ + runCommand, + firmwareLinuxNonfree, + fetchgit, + fetchFromGitLab, +}: + +let + pinephonepro-firmware = fetchFromGitLab { + domain = "gitlab.manjaro.org"; + owner = "tsys"; + repo = "pinebook-firmware"; + rev = "937f0d52d27d7712da6a008d35fd7c2819e2b077"; + sha256 = "sha256-Ij5u4IF55kPFs1BGq/sLlI3fjufwSjqrf8OZ2WnvjWI="; + }; + ap6256-firmware = fetchFromGitLab { + domain = "gitlab.manjaro.org"; + owner = "manjaro-arm"; + repo = "packages%2Fcommunity%2Fap6256-firmware"; + rev = "a30bf312b268eab42d38fab0cc3ed3177895ff5d"; + sha256 = "sha256-i2OEkn7RtEMbJd0sYEE2Hpkvw6KRppz5AbwXJFNa/pE="; + }; + brcm-firmware = fetchgit { + url = "https://megous.com/git/linux-firmware"; + rev = "6e8e591e17e207644dfe747e51026967bb1edab5"; + sha256 = "sha256-TaGwT0XvbxrfqEzUAdg18Yxr32oS+RffN+yzSXebtac="; + }; +in + +# The minimum set of firmware files required for the device. +runCommand "pine64-pinephonepro-firmware" { src = firmwareLinuxNonfree; } '' + for firmware in \ + rockchip/dptx.bin \ + ; do + mkdir -p "$(dirname $out/lib/firmware/$firmware)" + cp -vrf "$src/lib/firmware/$firmware" $out/lib/firmware/$firmware + done + + (PS4=" $ "; set -x + mkdir -p $out/lib/firmware/{brcm,rockchip} + (cd ${ap6256-firmware} + cp -fv *.hcd *blob *.bin *.txt $out/lib/firmware/brcm/ + ) + cp -fv ${pinephonepro-firmware}/brcm/* $out/lib/firmware/brcm/ + cp -fv ${pinephonepro-firmware}/rockchip/* $out/lib/firmware/rockchip/ + cp -fv ${brcm-firmware}/brcm/*43455* $out/lib/firmware/brcm/ + ) +'' diff --git a/pine64/pinephone-pro/kernel/builder.sh b/pine64/pinephone-pro/kernel/builder.sh new file mode 100644 index 000000000..fe7dfa3cb --- /dev/null +++ b/pine64/pinephone-pro/kernel/builder.sh @@ -0,0 +1,3 @@ +source $stdenv/setup +cat $patches | unxz | patch -p1 -N -r -||true +cp -r $src $out diff --git a/pine64/pinephone-pro/kernel/config.nix b/pine64/pinephone-pro/kernel/config.nix new file mode 100644 index 000000000..e0fc4d600 --- /dev/null +++ b/pine64/pinephone-pro/kernel/config.nix @@ -0,0 +1,121 @@ +{ lib, version }: +with lib.kernel; +with (lib.kernel.whenHelpers version); +{ + + ARCH_ROCKCHIP = yes; + + #charger, should always be included + CHARGER_RK818 = yes; + + #needed for networking via modem as it is connected via usb + USB_USBNET = module; + USB_NET_QMI_WWAN = module; + + DRM_ROCKCHIP = yes; + + #gpu + DRM_PANFROST = module; + + TOUCHSCREEN_GOODIX = module; + + #display + DRM_PANEL_HIMAX_HX8394 = module; + + #WiFi + BRCMFMAC = module; + + #bluetooth + BT_HCIBTSDIO = module; + + #adc + ROCKCHIP_SARADC = module; + + #IMU (also covers the MPU6500) + INV_MPU6050_IIO = module; + + #magnetometer + AF8133J = whenAtLeast "6.9" module; + + #ambient light sensor + STK3310 = module; + + #cameras + VIDEO_OV8858 = module; + VIDEO_IMX258 = module; + + #flash + LEDS_SGM3140 = module; + + #notification LED + LEDS_GPIO = module; + + #vibrator + INPUT_GPIO_VIBRA = module; + + #audio + SND_SOC_RT5616 = module; + SND_SOC_RT5640 = module; + SND_SOC_RK3399_GRU_SOUND = module; + SND_SOC_ROCKCHIP = module; + + #rk video decoder + VIDEO_ROCKCHIP_VDEC = module; + + #buttons + KEYBOARD_ADC = module; + + KEYBOARD_PINEPHONE = module; + + #Uneeded Platforms + ARCH_ACTIONS = no; + ARCH_SUNXI = no; + ARCH_ALPINE = no; + ARCH_APPLE = no; + ARCH_BCM = no; + ARCH_BERLIN = no; + ARCH_BITMAN = no; + ARCH_EXYNOS = no; + ARCH_SPARX5 = no; + ARCH_K3 = no; + ARCH_LG1k = no; + ARCH_HISI = no; + ARCH_KEEMBAY = no; + ARCH_MEDIATEK = no; + ARCH_MESON = no; + ARCH_MVEBU = no; + ARCH_NXP = no; + ARCH_MA35 = no; + ARCH_NPCM = no; + ARCH_QCOM = no; + ARCH_REALTEK = no; + ARCH_RENESAS = no; + ARCH_SEATTLE = no; + ARCH_SOCFPGA = no; + ARCH_STM32 = no; + ARCH_SYNQUACER = no; + ARCH_TEGRA = no; + ARCH_SPRD = no; + ARCH_THUNDER = no; + ARCH_THUNDER2 = no; + ARCH_UNIPHIER = no; + ARCH_VEXPRESS = no; + ARCH_VISCONTI = no; + ARCH_XGENE = no; + ARCH_ZYNQMP = no; + + #Modules that are probably not needed by anyone + DRM_NOUVEAU = no; + DRM_AMDGPU = no; + + #pahole causes OOM(6GiB> including zram) during build, disabling it as a mitigation + CONFIG_BPF = lib.mkForce no; + BPF_SYSCALL = lib.mkForce no; + BPF_JIT = lib.mkForce no; + BPF_JIT_ALWAYS_ON = lib.mkForce no; + BPF_JIT_DEFAULT_ON = lib.mkForce no; + PAHOLE_HAS_BTF_TAG = lib.mkForce no; + DEBUG_INFO_BTF = lib.mkForce no; + DEBUG_INFO_BTF_MODULES = lib.mkForce no; + +} diff --git a/pine64/pinephone-pro/kernel/default.nix b/pine64/pinephone-pro/kernel/default.nix new file mode 100644 index 000000000..b93f3584d --- /dev/null +++ b/pine64/pinephone-pro/kernel/default.nix @@ -0,0 +1,58 @@ +{ + lib, + fetchFromGitLab, + fetchurl, + kernelPatches, + callPackage, + buildLinux, + ... +}@args: +let + pver = "6.6.44"; + + src_pine64 = fetchFromGitLab { + owner = "pine64-org"; + repo = "linux"; + rev = "ppp-6.6-20231104-22589"; + sha256 = "sha256-wz2g+wE1DmhQQoldeiWEju3PaxSTIcqLSwamjzry+nc="; + }; + #apply mainline fixver patches + upstream_patch = fetchurl { + url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/patch-${pver}.xz"; + hash = "sha256-SSDqB/mqUmEWcf7fhZ3RRvGc2wvauORBuVl2ovJjX5M="; + }; + + ksrc = import ./source.nix; + + apply_patch = ( + path: { + name = builtins.baseNameOf path; + patch = path; + } + ); + patches = [ ]; +in +buildLinux ( + args + // { + version = pver; + # todo: find out why builder complains about patch-version + modDirVersion = "${lib.versions.majorMinor pver}.0"; + src = callPackage ksrc { + inherit pver upstream_patch; + src = src_pine64; + }; + features = { }; + structuredExtraConfig = import ./config.nix { + inherit lib; + version = pver; + }; + + kernelPatches = kernelPatches ++ map apply_patch patches; + extraMeta = { + platforms = lib.platforms.aarch64; + hydraPlatforms = [ "aarch64-linux" ]; + }; + } + // args.argsOverride or { } +) diff --git a/pine64/pinephone-pro/kernel/source.nix b/pine64/pinephone-pro/kernel/source.nix new file mode 100644 index 000000000..349fb2e60 --- /dev/null +++ b/pine64/pinephone-pro/kernel/source.nix @@ -0,0 +1,21 @@ +{ + pkgs, + stdenv, + pver, + src, + upstream_patch, + ... +}@args: +# Applies the full patch since last mainline which contains some previous patches causing it to fail +# which will work here as the builder doesn't use "set -e" +stdenv.mkDerivation { + name = "kernel-source"; + version = pver; + src = src; + patches = upstream_patch; + buildInputs = [ + pkgs.patch + pkgs.xz + ]; + builder = ./builder.sh; +} diff --git a/pine64/pinephone-pro/pine64-alsa-ucm/default.nix b/pine64/pinephone-pro/pine64-alsa-ucm/default.nix new file mode 100644 index 000000000..5cb6b67d1 --- /dev/null +++ b/pine64/pinephone-pro/pine64-alsa-ucm/default.nix @@ -0,0 +1,46 @@ +# MIT License + +# Copyright (c) 2018-2020 Samuel Dionne-Riel and the Mobile NixOS contributors + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +{ stdenv, pkgs, ... }: + +stdenv.mkDerivation rec { + name = "pine64-alsa-ucm"; + version = "ec0ef36b8b897ed1ae6bb0d0de13d5776f5d3659"; + + src = pkgs.fetchFromGitLab { + owner = "pine64-org"; + repo = "pine64-alsa-ucm"; + rev = version; + sha256 = "sha256-nsZXBB5VpF0YpfIS+/SSHMlPXSyIGLZSOkovjag8ifU="; + }; + + patches = [ ./repoint-pinephone-pro.patch ]; + + installPhase = '' + ucm_path=$out/share/alsa/ucm2/ + + mkdir -p $ucm_path/PinePhone $ucm_path/PinePhonePro $ucm_path/conf.d/simple-card + ln -s ../../PinePhonePro/PinePhonePro.conf $ucm_path/conf.d/simple-card/PinePhonePro.conf + + cp -r ucm2/* $ucm_path/ + ''; +} diff --git a/pine64/pinephone-pro/pine64-alsa-ucm/repoint-pinephone-pro.patch b/pine64/pinephone-pro/pine64-alsa-ucm/repoint-pinephone-pro.patch new file mode 100644 index 000000000..4e65d30d1 --- /dev/null +++ b/pine64/pinephone-pro/pine64-alsa-ucm/repoint-pinephone-pro.patch @@ -0,0 +1,19 @@ +diff --git a/ucm2/PinePhonePro/PinePhonePro.conf b/ucm2/PinePhonePro/PinePhonePro.conf +index 18b544a..c333958 100644 +--- a/ucm2/PinePhonePro/PinePhonePro.conf ++++ b/ucm2/PinePhonePro/PinePhonePro.conf +@@ -2,12 +2,12 @@ Syntax 4 + Comment "PinePhone Pro" + + SectionUseCase."HiFi" { +- File "HiFi.conf" ++ File "/PinePhonePro/HiFi.conf" + Comment "Default" + } + + SectionUseCase."Voice Call" { +- File "VoiceCall.conf" ++ File "/PinePhonePro/VoiceCall.conf" + Comment "Phone call" + } + diff --git a/pine64/pinephone-pro/wifi.nix b/pine64/pinephone-pro/wifi.nix new file mode 100644 index 000000000..6f478251d --- /dev/null +++ b/pine64/pinephone-pro/wifi.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: +let + cfg = config.hardware.pinephone-pro; +in +{ + options.hardware.pinephone-pro = { + wifi.workaround-sae = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + A bug in the brcmfmac module causes it to attempt to offload SAE. + This will cause connection failures and the following error message + + brcmfmac: brcmf_set_channel: set chanspec 0x???? fail, reason -52 + + Related: https://github.com/raspberrypi/linux/issues/6049 + ''; + }; + }; + config = lib.mkIf cfg.wifi.workaround-sae { + #Disable SAE and FWSUP + #See: https://iwd.wiki.kernel.org/offloading + boot.extraModprobeConfig = lib.mkDefault '' + options brcmfmac feature_disable=0x82000 + ''; + }; +}