Skip to content

Instantly share code, notes, and snippets.

@katyo
Last active January 31, 2023 17:34
Show Gist options
  • Save katyo/1246ad22ce61be943f30092fc92438f9 to your computer and use it in GitHub Desktop.
Save katyo/1246ad22ce61be943f30092fc92438f9 to your computer and use it in GitHub Desktop.
Teclast F5 onboard sound support for NixOS

To get onboard sound working on Teclast F5 with ES8336 codec we needs to use Linux kernel patches from SOF Project and the latest sof-firmware (v1.9).

On NixOS modify your configuration.nix like the following:

{ config, pkgs, lib, ... }:
{
  imports = [
    ./hardware-configuration.nix
    ./hardware-fixes/asoc-es8336.nix
  ];
  boot.kernelPackages = pkgs.linuxPackages_5_14;
}
{ pkgs, ... }:
with pkgs;
{
boot.kernelPatches = [
{
name = "ES8336 Support";
patch = fetchurl {
url = "https://patchwork.kernel.org/series/557373/mbox/";
sha256 = "0dvvbb8r63d4r1n2z1scjyvwb33f5g15jffcn5ylfbcca89pfb4x";
};
extraConfig = ''
SND_SOC_INTEL_SOF_ES8336_MACH m
'';
}
{
name = "ES8336 Support Hack";
patch = fetchurl {
url = "https://github.com/thesofproject/linux/pull/3107.patch";
sha256 = "0pnajp23ahnd94gnghdsr97jylfafi0k61mcyip5amb0sgxgj8br";
};
}
];
nixpkgs.overlays = [
(self: super: {
sof-firmware = callPackage ./sof-firmware.nix {};
})
];
}
{ lib, stdenvNoCC, fetchFromGitHub }:
stdenvNoCC.mkDerivation rec {
pname = "sof-firmware";
version = "1.9";
src = fetchFromGitHub {
owner = "thesofproject";
repo = "sof-bin";
rev = "v${version}";
sha256 = "sha256-yife3gO8lXOGwRye213II9rCQqDic7B7w1xW1o7ajF8=";
};
dontFixup = true;
installPhase = ''
runHook preInstall
cd "v${version}.x"
mkdir -p $out/lib/firmware/intel/
cp -a sof-v${version} $out/lib/firmware/intel/sof
cp -a sof-tplg-v${version} $out/lib/firmware/intel/sof-tplg
runHook postInstall
'';
}
@tshipenchko
Copy link

Hello! When I'm trying to build this, it says that pkgs don't have linuxPackages_5_14 attribute(

@tshipenchko
Copy link

tshipenchko commented Jan 19, 2023

Can you please pack this kernel with patches
and override new topology files into sof-firmware? Seems that only 6.0 version works ~okay
I couldn't build 5.19 version
my sof-fixes.nix:

{ config, pkgs, lib, ... }:
{
    boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linuxKernel.kernels.linux_6_0.override {
    argsOverride = rec {
      src = pkgs.fetchFromGitHub {
        owner = "thesofproject";
        repo = "linux";
        rev = "es8336-v6.0";
        hash = "sha256-bmPYvmhxlileNj8MSg3IPsyKbeOPqrv+jD+H2AfuZgI=";
      };
      modDirVersion = "6.0.0";
    };
  });
  nixpkgs = {
    overlays = [
      (self: super: {
        linuxZenWMuQSS = pkgs.linuxPackagesFor (pkgs.linuxKernel.kernels.linux_6_0.override {
          structuredExtraConfig = with lib.kernel; {
            CONFIG_SND_SOC_INTEL_SOF_ES8336_MACH=m;
            CONFIG_SND_SOC_ES8316=m;
          };
        });
      })
    ];
}

@tshipenchko
Copy link

So, I just installed latest available kernel :)

boot.kernelPackages = pkgs.linuxPackages_latest;

And also added to .bash_profile these commands. If you wish, you can create a systemd service. Note: after disconnecting from bluetooth headset you have to execute the commands again. I saw an awesome script with key binding, but I can't find one again.
The default sound card did not work because the speaker/microphone was turned off in the alsa settings. It is important to use alsa directly. Apparently, the alsa pipewire bridge cannot interact with the soundcard.

@katyo
Copy link
Author

katyo commented Jan 27, 2023

@tshipenchko What commands are you use to turn on speaker/microphone?
I my case sound stopped work on latest linux kernels with es8336 patches.

@tshipenchko
Copy link

tshipenchko commented Jan 31, 2023

@katyo
I am responding from mobile, so I will sent a link to another reply
https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2154#note_1734052
I used these commands. Also, maybe specifying card with amixer -c 0 or -c 1 will be necessary.
Internal mic still doesn't work 😭

Sorry, looks like I didn't provided commands in previous reply :c

@katyo
Copy link
Author

katyo commented Jan 31, 2023

@tshipenchko Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment