From 7ac7d214769593a33a4f1042f697ee9505387b5a Mon Sep 17 00:00:00 2001 From: Jordan Holt Date: Sun, 12 Nov 2023 23:13:23 +0000 Subject: [PATCH] Patch snd_usb_audio and add 1824c PipeWire config --- ...-Update-device-ID-for-PreSonus-1824c.patch | 57 +++++++++++++++++++ hosts/odyssey/default.nix | 23 ++++++++ hosts/odyssey/hardware-configuration.nix | 12 +++- hosts/odyssey/snd-usb-audio.nix | 36 ++++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 hosts/odyssey/0001-Update-device-ID-for-PreSonus-1824c.patch create mode 100644 hosts/odyssey/snd-usb-audio.nix diff --git a/hosts/odyssey/0001-Update-device-ID-for-PreSonus-1824c.patch b/hosts/odyssey/0001-Update-device-ID-for-PreSonus-1824c.patch new file mode 100644 index 0000000..c3f7cf5 --- /dev/null +++ b/hosts/odyssey/0001-Update-device-ID-for-PreSonus-1824c.patch @@ -0,0 +1,57 @@ +From c16be6b3b4da5a55e3ff4258ada123b5f03757e5 Mon Sep 17 00:00:00 2001 +From: Jordan Holt +Date: Sun, 12 Nov 2023 12:13:39 +0000 +Subject: [PATCH] Update device ID for PreSonus 1824c + +--- + sound/usb/format.c | 4 ++-- + sound/usb/mixer_quirks.c | 2 +- + sound/usb/quirks.c | 4 ++-- + 3 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/sound/usb/format.c b/sound/usb/format.c +index ab5fed9f55b6..da50a4782414 100644 +--- a/sound/usb/format.c ++++ b/sound/usb/format.c +@@ -378,8 +378,8 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, + + for (rate = min; rate <= max; rate += res) { + +- /* Filter out invalid rates on Presonus Studio 1810c */ +- if (chip->usb_id == USB_ID(0x194f, 0x010c) && ++ /* Filter out invalid rates on Presonus Studio 1824c */ ++ if (chip->usb_id == USB_ID(0x194f, 0x010d) && + !s1810c_valid_sample_rate(fp, rate)) + goto skip_rate; + +diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c +index 898bc3baca7b..c3135459c38c 100644 +--- a/sound/usb/mixer_quirks.c ++++ b/sound/usb/mixer_quirks.c +@@ -3445,7 +3445,7 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) + err = snd_rme_controls_create(mixer); + break; + +- case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */ ++ case USB_ID(0x194f, 0x010d): /* Presonus Studio 1824c */ + err = snd_sc1810_init_mixer(mixer); + break; + case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */ +diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c +index ab2b938502eb..b86832edaaa0 100644 +--- a/sound/usb/quirks.c ++++ b/sound/usb/quirks.c +@@ -1551,8 +1551,8 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip, + /* fasttrackpro usb: skip altsets incompatible with device_setup */ + if (chip->usb_id == USB_ID(0x0763, 0x2012)) + return fasttrackpro_skip_setting_quirk(chip, iface, altno); +- /* presonus studio 1810c: skip altsets incompatible with device_setup */ +- if (chip->usb_id == USB_ID(0x194f, 0x010c)) ++ /* presonus studio 1824c: skip altsets incompatible with device_setup */ ++ if (chip->usb_id == USB_ID(0x194f, 0x010d)) + return s1810c_skip_setting_quirk(chip, iface, altno); + + +-- +2.40.1 + diff --git a/hosts/odyssey/default.nix b/hosts/odyssey/default.nix index cc1fd57..cf58dc8 100644 --- a/hosts/odyssey/default.nix +++ b/hosts/odyssey/default.nix @@ -19,6 +19,29 @@ with lib.my; networking.networkmanager.enable = true; + environment.etc."pipewire/pipewire.conf.d/surround.conf".text = '' + context.modules = [ + { + name = libpipewire-module-loopback + args = { + node.description = "1824c Surround" + capture.props = { + node.name = "1824c_Speakers" + media.class = "Audio/Sink" + audio.position = [ FL FR FC SL SR LFE ] + } + playback.props = { + node.name = "playback.1824c_Speakers" + audio.position = [ AUX0 AUX1 AUX2 AUX3 AUX4 AUX5 ] + target.object = "alsa_output.usb-PreSonus_Studio_1824c_SC4E21110775-00.multichannel-output" + stream.dont-remix = true + node.passive = true + } + } + } + ] + ''; + nix.package = pkgs.nixFlakes; nix.extraOptions = '' experimental-features = nix-command flakes diff --git a/hosts/odyssey/hardware-configuration.nix b/hosts/odyssey/hardware-configuration.nix index 7bf33d5..7847dcd 100644 --- a/hosts/odyssey/hardware-configuration.nix +++ b/hosts/odyssey/hardware-configuration.nix @@ -3,7 +3,11 @@ # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: -{ +let + snd-usb-audio-module = pkgs.callPackage ./snd-usb-audio.nix { + kernel = config.boot.kernelPackages.kernel; + }; +in { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; @@ -11,7 +15,11 @@ boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; + boot.extraModulePackages = [ + (snd-usb-audio-module.overrideAttrs (_: { + patches = [ ./0001-Update-device-ID-for-PreSonus-1824c.patch ]; + })) + ]; boot.supportedFilesystems = [ "ntfs" ]; boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; diff --git a/hosts/odyssey/snd-usb-audio.nix b/hosts/odyssey/snd-usb-audio.nix new file mode 100644 index 0000000..329501e --- /dev/null +++ b/hosts/odyssey/snd-usb-audio.nix @@ -0,0 +1,36 @@ +{ pkgs, lib, kernel ? pkgs.linuxPackages_latest.kernel }: + +pkgs.stdenv.mkDerivation { + pname = "snd-usb-audio"; + inherit (kernel) src version postPatch nativeBuildInputs; + + kernel_dev = kernel.dev; + kernelVersion = kernel.modDirVersion; + + modulePath = "sound/usb"; + + buildPhase = '' + BUILT_KERNEL=$kernel_dev/lib/modules/$kernelVersion/build + + cp $BUILT_KERNEL/Module.symvers . + cp $BUILT_KERNEL/.config . + cp $kernel_dev/vmlinux . + + make "-j$NIX_BUILD_CORES" modules_prepare + make "-j$NIX_BUILD_CORES" M=$modulePath modules + ''; + + installPhase = '' + make \ + INSTALL_MOD_PATH="$out" \ + XZ="xz -T$NIX_BUILD_CORES" \ + M="$modulePath" \ + modules_install + ''; + + meta = { + description = "USB Sound kernel module"; + license = lib.licenses.gpl2; + }; +} +