From af2ce732be11c5ba86dddc5a49c20a31677a3247 Mon Sep 17 00:00:00 2001 From: Victor Fuentes Date: Tue, 10 Dec 2024 02:58:18 -0800 Subject: [PATCH] orange-pi-5-max: init --- README.md | 1 + flake.nix | 1 + orange-pi/5-max/README.md | 85 +++++++++++ orange-pi/5-max/audio.nix | 42 ++++++ orange-pi/5-max/bcmdhd_sdio.nix | 53 +++++++ orange-pi/5-max/default.nix | 71 ++++++++++ orange-pi/5-max/graphics.nix | 31 ++++ orange-pi/5-max/leds.nix | 46 ++++++ orange-pi/5-max/mali-firmware.nix | 23 +++ orange-pi/5-max/orangepi-firmware.nix | 35 +++++ orange-pi/5-max/sd-image-installer.nix | 11 ++ orange-pi/5-max/sd-image.nix | 38 +++++ orange-pi/5-max/uart.nix | 23 +++ orange-pi/5-max/uboot/default.nix | 46 ++++++ orange-pi/5-max/uboot/package.nix | 17 +++ orange-pi/5-max/wireless.nix | 187 +++++++++++++++++++++++++ 16 files changed, 710 insertions(+) create mode 100644 orange-pi/5-max/README.md create mode 100644 orange-pi/5-max/audio.nix create mode 100644 orange-pi/5-max/bcmdhd_sdio.nix create mode 100644 orange-pi/5-max/default.nix create mode 100644 orange-pi/5-max/graphics.nix create mode 100644 orange-pi/5-max/leds.nix create mode 100644 orange-pi/5-max/mali-firmware.nix create mode 100644 orange-pi/5-max/orangepi-firmware.nix create mode 100644 orange-pi/5-max/sd-image-installer.nix create mode 100644 orange-pi/5-max/sd-image.nix create mode 100644 orange-pi/5-max/uart.nix create mode 100644 orange-pi/5-max/uboot/default.nix create mode 100644 orange-pi/5-max/uboot/package.nix create mode 100644 orange-pi/5-max/wireless.nix diff --git a/README.md b/README.md index 7a774cf07..1b5a819a6 100644 --- a/README.md +++ b/README.md @@ -377,6 +377,7 @@ See code for all available configurations. | [Omen 15-en1007sa](omen/15-en1007sa) | `` | `omen-15-en1007sa` | | [Omen 15-en0002np](omen/15-en0002np) | `` | `omen-15-en0002np` | | [One-Netbook OneNetbook 4](onenetbook/4) | `` | `onenetbook-4` | +| [Orange Pi 5 Max](orange-pi/5-max) | `` | `orange-pi-5-max` | | [Panasonic Let's Note CF-LX4](panasonic/letsnote/cf-lx4) | `` | `panasonic-letsnote-cf-lx4` | | [PC Engines APU](pcengines/apu) | `` | `pcengines-apu` | | [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `` | `pine64-pinebook-pro` | diff --git a/flake.nix b/flake.nix index 3cd9e3551..a9f0c1dad 100644 --- a/flake.nix +++ b/flake.nix @@ -320,6 +320,7 @@ omen-15-en0002np = import ./omen/15-en0002np; onenetbook-4 = import ./onenetbook/4; olimex-teres_i = import ./olimex/teres_i; + orange-pi-5-max = import ./orange-pi/5-max; pcengines-apu = import ./pcengines/apu; pine64-pinebook-pro = import ./pine64/pinebook-pro; pine64-rockpro64 = import ./pine64/rockpro64; diff --git a/orange-pi/5-max/README.md b/orange-pi/5-max/README.md new file mode 100644 index 000000000..c6f7af70c --- /dev/null +++ b/orange-pi/5-max/README.md @@ -0,0 +1,85 @@ +# Creating an installation SD card image + +Create and customize a `flake.nix` file: + +```nix +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixos-hardware.url = "github:nixos/nixos-hardware"; + }; + + outputs = { nixpkgs, nixos-hardware, ... }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "riscv64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSupportedSystems = nixpkgs.lib.genAttrs supportedSystems; + in + { + packages = forAllSupportedSystems (system: rec { + default = sd-image; + sd-image = (import "${nixpkgs}/nixos" { + configuration = { + imports = [ + "${nixos-hardware}/orange-pi/5-max/sd-image-installer.nix" + ]; + + nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [ + "orangepi-firmware" + "mali-g610-firmware" + ]; + + # If you want to use ssh set a password + # users.users.nixos.password = "super secure password"; + # OR add your public ssh key + # users.users.nixos.openssh.authorizedKeys.keys = [ "ssh-rsa ..." ]; + + nixpkgs.buildPlatform.system = system; + nixpkgs.hostPlatform.system = "aarch64-linux"; + + system.stateVersion = "24.11"; + }; + inherit system; + }).config.system.build.sdImage; + }); + }; +} +``` + +Then build the image by running `nix build .#` in the same folder. + +## Flashing image +Replace `/dev/sdX` with the device name of your sd card. +```sh +zstdcat result/sd-image/nixos-sd-image-*-orange-pi-5-max.img.zst | sudo dd status=progress bs=8M of=/dev/sdX +``` + +# Updating the bootloader +Install the enable the update scripts +```nix +hardware.orange-pi."5-max".uboot.updater.enable = true; +``` + +uart debugging options are applied to the bootloader installed by the firmware update script +```nix +hardware.orange-pi."5-max".uartDebug = { + enable = true; # enabled by default for debugging + baudRate = 57600; # default is 1500000 +}; +``` + +## SD-Card +Run as root +``` sh +orangepi5max-firmware-update-sd +``` +## SPI Flash +Run as root +``` sh +orangepi5max-firmware-update-flash +``` diff --git a/orange-pi/5-max/audio.nix b/orange-pi/5-max/audio.nix new file mode 100644 index 000000000..694d56605 --- /dev/null +++ b/orange-pi/5-max/audio.nix @@ -0,0 +1,42 @@ +{ config, lib, ... }: +let + cfg = config.hardware.orange-pi."5-max".audio; +in +{ + options.hardware = { + orange-pi."5-max".audio = { + enable = lib.mkEnableOption "audio device configuration" // { + default = true; + }; + }; + }; + + config = lib.mkIf cfg.enable { + services.pipewire.wireplumber.extraConfig = { + "orange-pi-5-max-descriptions" = { + "monitor.alsa.rules" = + let + makeRule = name: description: { + matches = [ { "device.name" = name; } ]; + actions = { + update-props = { + "device.description" = description; + }; + }; + }; + in + [ + (makeRule "alsa_card.platform-hdmi0-sound" "HDMI0 Audio") + (makeRule "alsa_card.platform-hdmi1-sound" "HDMI1 Audio") + (makeRule "alsa_card.platform-sound" "ES8388 Audio") + ]; + }; + }; + + services.udev.extraRules = '' + SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi0-sound", ENV{SOUND_DESCRIPTION}="HDMI0 Audio" + SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi1-sound", ENV{SOUND_DESCRIPTION}="HDMI1 Audio" + SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-sound", ENV{SOUND_DESCRIPTION}="ES8388 Audio" + ''; + }; +} diff --git a/orange-pi/5-max/bcmdhd_sdio.nix b/orange-pi/5-max/bcmdhd_sdio.nix new file mode 100644 index 000000000..f358119b9 --- /dev/null +++ b/orange-pi/5-max/bcmdhd_sdio.nix @@ -0,0 +1,53 @@ +{ + fetchFromGitHub, + kernel, + lib, + stdenv, + ... +}: +let + rev = "101.10.591.52.27-4"; +in +stdenv.mkDerivation rec { + pname = "bcmdhd_sdio"; + version = "${rev}-${kernel.version}"; + + passthru.moduleName = "bcmdhd_sdio"; + + src = fetchFromGitHub { + owner = "armbian"; + repo = "bcmdhd-dkms"; + inherit rev; + hash = "sha256-e9oWorovZrsqm7qZjXygVluahTCIxi4yJy2Pp6lwdl8="; + }; + + sourceRoot = "${src.name}/src"; + + hardeningDisable = [ "pic" ]; + + nativeBuildInputs = kernel.moduleBuildDependencies; + + postPatch = '' + substituteInPlace include/linuxver.h \ + --replace-fail 'del_timer(&((t)->timer))' 'timer_delete(&((t)->timer))' + substituteInPlace include/linuxver.h \ + --replace-fail 'del_timer_sync(&((t)->timer))' 'timer_delete_sync(&((t)->timer))' + ''; + + buildPhase = '' + make \ + LINUXDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build \ + ARCH=arm64 \ + CROSS_COMPILE=${stdenv.cc.targetPrefix} \ + bcmdhd_sdio \ + CONFIG_BCMDHD_SDIO=y \ + CONFIG_BCMDHD_DTS=y + ''; + + installPhase = '' + install -D bcmdhd_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd_sdio.ko + install -D dhd_static_buf_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_static_buf_sdio.ko + ''; + + meta.license = lib.licenses.gpl2Only; +} diff --git a/orange-pi/5-max/default.nix b/orange-pi/5-max/default.nix new file mode 100644 index 000000000..1cf83434a --- /dev/null +++ b/orange-pi/5-max/default.nix @@ -0,0 +1,71 @@ +{ lib, pkgs, ... }: +let + orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { }; +in +{ + imports = [ + ./audio.nix + ./wireless.nix + ./graphics.nix + ./leds.nix + ./uart.nix + ./uboot + ../../common/gpu/24.05-compat.nix + ]; + + powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand"; + + boot = { + kernelPackages = + if (lib.versionOlder pkgs.linux.version "6.15") then + lib.mkDefault pkgs.linuxPackages_latest + else + lib.mkDefault pkgs.linuxPackages; + supportedFilesystems.zfs = false; + + kernelParams = [ + "rootwait" + "consoleblank=0" + "console=tty1" + ]; + + initrd.includeDefaultModules = false; + initrd.availableKernelModules = [ + "nvme" + "mmc_block" + "usbhid" + "hid_generic" + "dm_mod" + "input_leds" + ]; + + loader = { + grub.enable = lib.mkDefault false; + generic-extlinux-compatible.enable = lib.mkDefault true; + }; + }; + + disabledModules = [ "profiles/all-hardware.nix" ]; + + hardware = { + deviceTree = { + enable = lib.mkDefault true; + name = lib.mkDefault "rockchip/rk3588-orangepi-5-max.dtb"; + }; + + firmware = [ orangepi-firmware ]; + + enableRedistributableFirmware = lib.mkDefault true; + }; + + networking.networkmanager.wifi.scanRandMacAddress = lib.mkDefault false; + + systemd.services."orangepi5-usb2-init" = { + description = "Initialize USB2 on Orange Pi 5"; + wantedBy = [ "default.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.bash}/bin/sh -c 'echo host > /sys/kernel/debug/usb/fc000000.usb/mode'"; + }; + }; +} diff --git a/orange-pi/5-max/graphics.nix b/orange-pi/5-max/graphics.nix new file mode 100644 index 000000000..ebd369a6b --- /dev/null +++ b/orange-pi/5-max/graphics.nix @@ -0,0 +1,31 @@ +{ + config, + pkgs, + lib, + ... +}: +let + cfg = config.hardware.orange-pi."5-max".graphics; + mali-firmware = pkgs.callPackage ./mali-firmware.nix { }; +in +{ + options.hardware = { + orange-pi."5-max".graphics = { + enable = lib.mkEnableOption "gpu configuration" // { + default = config.hardware.graphics.enable; + }; + }; + }; + + config = lib.mkIf cfg.enable { + hardware = { + firmware = [ + mali-firmware + ]; + }; + # VK_KHR_sampler_ycbcr_conversion is not available for g610 in older mesa versions + environment.sessionVariables = lib.optionalAttrs (lib.versionOlder pkgs.mesa.version "25.1.0") { + GDK_VULKAN_DISABLE = "ycbcr"; + }; + }; +} diff --git a/orange-pi/5-max/leds.nix b/orange-pi/5-max/leds.nix new file mode 100644 index 000000000..49f122c45 --- /dev/null +++ b/orange-pi/5-max/leds.nix @@ -0,0 +1,46 @@ +{ config, lib, ... }: +let + cfg = config.hardware.orange-pi."5-max".leds; +in +{ + options.hardware.orange-pi."5-max".leds = { + enable = lib.mkEnableOption "heartbeat leds" // { + default = true; + }; + }; + + config = lib.mkIf (!cfg.enable) { + hardware = { + deviceTree = { + overlays = [ + { + name = "orangepi-5-max-enable-leds"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "xunlong,orangepi-5-max"; + }; + / { + fragment@0 { + target = <&led_blue_pwm>; + __overlay__ { + linux,default-trigger = "none"; + }; + }; + }; + / { + fragment@1 { + target = <&led_green_pwm>; + __overlay__ { + linux,default-trigger = "none"; + }; + }; + }; + ''; + } + ]; + }; + }; + }; +} diff --git a/orange-pi/5-max/mali-firmware.nix b/orange-pi/5-max/mali-firmware.nix new file mode 100644 index 000000000..437191f1f --- /dev/null +++ b/orange-pi/5-max/mali-firmware.nix @@ -0,0 +1,23 @@ +{ + fetchurl, + lib, + stdenv, + ... +}: +stdenv.mkDerivation { + pname = "mali-g610-firmware"; + version = "g18p0-01eac0"; + + src = fetchurl { + url = "https://github.com/JeffyCN/mirrors/raw/e08ced3e0235b25a7ba2a3aeefd0e2fcbd434b68/firmware/g610/mali_csffw.bin"; + hash = "sha256-jnyCGlXKHDRcx59hJDYW3SX8NbgfCQlG8wKIbWdxLfU="; + }; + + buildCommand = '' + install -Dm444 $src $out/lib/firmware/mali_csffw.bin + ''; + + compressFirmware = false; + + meta.license = lib.licenses.unfreeRedistributableFirmware; +} diff --git a/orange-pi/5-max/orangepi-firmware.nix b/orange-pi/5-max/orangepi-firmware.nix new file mode 100644 index 000000000..8a40dd992 --- /dev/null +++ b/orange-pi/5-max/orangepi-firmware.nix @@ -0,0 +1,35 @@ +{ + fetchFromGitHub, + lib, + stdenvNoCC, + ... +}: +stdenvNoCC.mkDerivation { + pname = "orangepi-firmware"; + version = "2024.10.09"; + dontBuild = true; + dontFixup = true; + compressFirmware = false; + + src = fetchFromGitHub { + owner = "orangepi-xunlong"; + repo = "firmware"; + rev = "75ea6fc5f3c454861b39b33823cb6876f3eca598"; + hash = "sha256-X+n0voO3HRtPPAQsajGPIN9LOfDKBxF+8l9wFwGAFSQ="; + }; + + installPhase = '' + runHook preInstall + + mkdir -p $out/lib/firmware + cp -a * $out/lib/firmware/ + + mkdir -p $out/lib/firmware/brcm + ln -sf ../SYN43711A0.hcd $out/lib/firmware/brcm/SYN43711A0.hcd + ln -sf ../SYN43711A0.hcd $out/lib/firmware/brcm/BCM.xunlong,orangepi-5-max.hcd + + runHook postInstall + ''; + + meta.license = lib.licenses.unfreeRedistributableFirmware; +} diff --git a/orange-pi/5-max/sd-image-installer.nix b/orange-pi/5-max/sd-image-installer.nix new file mode 100644 index 000000000..22394ff9d --- /dev/null +++ b/orange-pi/5-max/sd-image-installer.nix @@ -0,0 +1,11 @@ +{ modulesPath, ... }: +{ + imports = [ + "${modulesPath}/profiles/installation-device.nix" + ./sd-image.nix + ]; + + # the installation media is also the installation target, + # so we don't want to provide the installation configuration.nix. + installer.cloneConfig = false; +} diff --git a/orange-pi/5-max/sd-image.nix b/orange-pi/5-max/sd-image.nix new file mode 100644 index 000000000..9eda5dc88 --- /dev/null +++ b/orange-pi/5-max/sd-image.nix @@ -0,0 +1,38 @@ +{ + modulesPath, + config, + pkgs, + ... +}: +let + uboot = config.hardware.orange-pi."5-max".uboot.package; +in +{ + imports = [ + "${modulesPath}/profiles/base.nix" + "${modulesPath}/installer/sd-card/sd-image.nix" + ./default.nix + ]; + + image = { + fileName = "${config.image.baseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-orange-pi-5-max.img"; + }; + sdImage = { + firmwarePartitionOffset = 16; + firmwarePartitionName = "BOOT"; + + compressImage = true; + expandOnBoot = true; + + populateFirmwareCommands = "dd if=${uboot}/u-boot-rockchip.bin of=$img seek=64 conv=notrunc"; + + postBuildCommands = '' + cp ${uboot}/u-boot-rockchip.bin firmware/ + ''; + + populateRootCommands = '' + mkdir -p ./files/boot + ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; +} diff --git a/orange-pi/5-max/uart.nix b/orange-pi/5-max/uart.nix new file mode 100644 index 000000000..b52bdee9f --- /dev/null +++ b/orange-pi/5-max/uart.nix @@ -0,0 +1,23 @@ +{ config, lib, ... }: +let + cfg = config.hardware.orange-pi."5-max".uartDebug; +in +{ + options.hardware.orange-pi."5-max".uartDebug = { + enable = lib.mkEnableOption "UART2 serial console" // { + default = true; + }; + baudRate = lib.mkOption { + type = lib.types.int; + default = 1500000; + description = "Baud rate for the UART2 serial console"; + }; + }; + + config = lib.mkIf cfg.enable { + boot.kernelParams = [ + "earlycon=uart8250,mmio32,0xfeb50000" + "console=ttyS2,${toString cfg.baudRate}" + ]; + }; +} diff --git a/orange-pi/5-max/uboot/default.nix b/orange-pi/5-max/uboot/default.nix new file mode 100644 index 000000000..7525573f2 --- /dev/null +++ b/orange-pi/5-max/uboot/default.nix @@ -0,0 +1,46 @@ +{ + config, + pkgs, + lib, + ... +}: +let + cfg = config.hardware.orange-pi."5-max".uboot; + uboot = pkgs.callPackage ./package.nix { + enableUart = config.hardware.orange-pi."5-max".uartDebug.enable; + baudRate = config.hardware.orange-pi."5-max".uartDebug.baudRate; + }; + updater-flash = pkgs.writeShellApplication { + name = "orangepi5max-firmware-update-flash"; + runtimeInputs = [ pkgs.mtdutils ]; + text = '' + flashcp -v ${cfg.package}/u-boot-rockchip-spi.bin /dev/mtd0 + ''; + }; + updater-sd = pkgs.writeShellApplication { + name = "orangepi5max-firmware-update-sd"; + runtimeInputs = [ ]; + text = '' + dd if=${cfg.package}/u-boot-rockchip.bin of=/dev/mmcblk1 seek=64 conv=notrunc + ''; + }; +in +{ + options.hardware = { + orange-pi."5-max".uboot = { + package = lib.mkOption { + type = lib.types.package; + default = uboot; + description = "uboot package to use in sd image and updater scripts"; + }; + updater.enable = lib.mkEnableOption "updater program installation"; + }; + }; + + config = lib.mkIf cfg.updater.enable { + environment.systemPackages = [ + updater-flash + updater-sd + ]; + }; +} diff --git a/orange-pi/5-max/uboot/package.nix b/orange-pi/5-max/uboot/package.nix new file mode 100644 index 000000000..caa41d8da --- /dev/null +++ b/orange-pi/5-max/uboot/package.nix @@ -0,0 +1,17 @@ +{ + ubootOrangePi5Max, + lib, + enableUart ? true, + baudRate ? 1500000, + ... +}: +ubootOrangePi5Max.overrideAttrs (_prev: { + preConfigure = + '' + sed -i "s/^CONFIG_BAUDRATE=1500000/CONFIG_BAUDRATE=${toString baudRate}/" configs/orangepi-5-max-rk3588_defconfig + sed -i "s/serial2:1500000n8/serial2:${toString baudRate}n8/" dts/upstream/src/arm64/rockchip/rk3588-orangepi-5.dtsi + '' + + lib.optionalString (!enableUart) '' + sed -i "s/^CONFIG_DEBUG_UART=y/# CONFIG_DEBUG_UART is not set/" configs/orangepi-5-max-rk3588_defconfig + ''; +}) diff --git a/orange-pi/5-max/wireless.nix b/orange-pi/5-max/wireless.nix new file mode 100644 index 000000000..161be3687 --- /dev/null +++ b/orange-pi/5-max/wireless.nix @@ -0,0 +1,187 @@ +{ + config, + pkgs, + lib, + ... +}: +let + cfg = config.hardware.orange-pi."5-max".wireless; + bcmdhd_sdio = config.boot.kernelPackages.callPackage ./bcmdhd_sdio.nix { }; + orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { }; +in +{ + options.hardware = { + orange-pi."5-max".wireless = { + enable = lib.mkEnableOption "configuration for wireless wlan/bluetooth" // { + default = config.networking.wireless.enable || config.hardware.bluetooth.enable; + }; + }; + }; + + config = lib.mkIf cfg.enable { + boot = { + kernelParams = [ "8250.nr_uarts=8" ]; + kernelModules = [ + "bcmdhd_sdio" + "btbcm" + ]; + blacklistedKernelModules = [ + "bcmdhd" + "dhd_static_buf" + ]; + extraModulePackages = [ bcmdhd_sdio ]; + extraModprobeConfig = + let + options = [ + "firmware_path=${orangepi-firmware}/lib/firmware/fw_syn43711a0_sdio.bin" + "nvram_path=${orangepi-firmware}/lib/firmware/nvram_ap6611s.txt" + "clm_path=${orangepi-firmware}/lib/firmware/clm_syn43711a0.blob" + ]; + in + '' + options bcmdhd_sdio ${lib.concatStringsSep " " options} + ''; + }; + + hardware = { + deviceTree = { + overlays = + [ + { + name = "orangepi-5-max-wlan"; + dtsText = '' + /dts-v1/; + /plugin/; + + #include + #include + + / { + compatible = "xunlong,orangepi-5-max"; + }; + / { + fragment@0 { + target = <&pinctrl>; + __overlay__ { + sdio-pwrseq { + wifi_enable_h: wifi-enable-h { + rockchip,pins = <2 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>; + }; + }; + wireless-wlan { + wifi_host_wake_irq: wifi-host-wake-irq { + rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; + }; + }; + fragment@1 { + target-path = "/"; + __overlay__ { + sdio_pwrseq: sdio-pwrseq { + compatible = "mmc-pwrseq-simple"; + clocks = <&hym8563>; + clock-names = "ext_clock"; + pinctrl-names = "default"; + pinctrl-0 = <&wifi_enable_h>; + post-power-on-delay-ms = <200>; + reset-gpios = <&gpio2 RK_PC5 GPIO_ACTIVE_LOW>; + }; + wireless_wlan: wireless-wlan { + compatible = "wlan-platdata"; + wifi_chip_type = "ap6611"; + pinctrl-names = "default"; + pinctrl-0 = <&wifi_host_wake_irq>; + WIFI,host_wake_irq = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>; + WIFI,poweren_gpio = <&gpio2 RK_PC5 GPIO_ACTIVE_HIGH>; + status = "okay"; + }; + }; + }; + fragment@2 { + target = <&sdio>; + __overlay__ { + max-frequency = <150000000>; + no-sd; + no-mmc; + bus-width = <4>; + disable-wp; + cap-sd-highspeed; + cap-sdio-irq; + keep-power-in-suspend; + mmc-pwrseq = <&sdio_pwrseq>; + non-removable; + pinctrl-names = "default"; + pinctrl-0 = <&sdiom0_pins>; + sd-uhs-sdr104; + status = "okay"; + bcmdhd_wlan { + compatible = "android,bcmdhd_wlan"; + gpio_wl_host_wake = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>; + }; + }; + }; + }; + ''; + } + ] + ++ lib.optional (lib.versionOlder pkgs.linux.version "6.16") { + name = "orangepi-5-max-bt"; + dtsText = '' + /dts-v1/; + /plugin/; + + #include + #include + #include + + / { + compatible = "xunlong,orangepi-5-max"; + }; + / { + fragment@0 { + target = <&pinctrl>; + __overlay__ { + wireless-bluetooth { + bt_reg_on: bt-reg-on { + rockchip,pins = <4 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>; + }; + host_wake_bt: host-wake-bt { + rockchip,pins = <4 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>; + }; + bt_wake_host: bt-wake-host { + rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>; + }; + }; + }; + }; + fragment@1 { + target = <&uart7>; + __overlay__ { + pinctrl-names = "default"; + pinctrl-0 = <&uart7m0_xfer &uart7m0_ctsn &uart7m0_rtsn>; + uart-has-rtscts; + status = "okay"; + bluetooth { + compatible = "brcm,bcm43438-bt"; + clocks = <&hym8563>; + clock-names = "lpo"; + device-wakeup-gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>; + interrupt-parent = <&gpio0>; + interrupts = ; + interrupt-names = "host-wakeup"; + pinctrl-names = "default"; + pinctrl-0 = <&bt_reg_on>, <&host_wake_bt>, <&bt_wake_host>; + shutdown-gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>; + vbat-supply = <&vcc_3v3_s3>; + vddio-supply = <&vcc_1v8_s3>; + }; + }; + }; + }; + ''; + }; + }; + }; + }; +}