From fd2df1ece5c96eac89d7fab8e1787c136589df71 Mon Sep 17 00:00:00 2001 From: Pat Nakajima Date: Sun, 19 Apr 2026 15:43:57 -0700 Subject: [PATCH] bump --- setup-audio.sh | 130 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 34 deletions(-) diff --git a/setup-audio.sh b/setup-audio.sh index c097ccc..2e2a583 100755 --- a/setup-audio.sh +++ b/setup-audio.sh @@ -32,6 +32,23 @@ mkdir -p "$OVERLAYS" RESTORE_HELPER="/usr/local/sbin/barepi-audio-restore" RESTORE_SERVICE="/etc/systemd/system/barepi-audio-restore.service" +MODULES_LOAD_FILE="/etc/modules-load.d/barepi-audio.conf" +NEED_KERNEL_REBOOT=0 + +have_audio_modules() { + modinfo snd-soc-simple-card >/dev/null 2>&1 \ + && modinfo snd-soc-tlv320aic31xx >/dev/null 2>&1 \ + && modinfo snd-soc-ics43432 >/dev/null 2>&1 +} + +install_pkg_if_available() { + local pkg="$1" + if apt-cache show "$pkg" >/dev/null 2>&1; then + apt-get install -y "$pkg" + return 0 + fi + return 1 +} echo "=== barepi audio setup ===" echo "User: $TARGET_USER Home: $TARGET_HOME" @@ -43,6 +60,48 @@ echo "" echo "[1/7] Installing packages..." apt-get update apt-get install -y alsa-utils libasound2-plugins swh-plugins i2c-tools device-tree-compiler + +if ! have_audio_modules; then + KERNEL_MODULES_PKG="linux-modules-$(uname -r)" + if install_pkg_if_available "$KERNEL_MODULES_PKG"; then + echo " Installed $KERNEL_MODULES_PKG" + fi +fi + +if ! have_audio_modules && [ -r /etc/os-release ]; then + . /etc/os-release + if [ "${ID:-}" = "ubuntu" ] && install_pkg_if_available linux-image-raspi-6.8; then + install_pkg_if_available linux-headers-raspi-6.8 || true + NEED_KERNEL_REBOOT=1 + echo " Installed Ubuntu raspi 6.8 kernel fallback for ASoC modules." + fi +fi + +if ! have_audio_modules; then + if [ "$NEED_KERNEL_REBOOT" -eq 1 ]; then + echo " Current kernel still lacks the required ASoC modules; continuing because a compatible kernel was installed." >&2 + echo " Reboot into the new kernel after setup completes." >&2 + else + echo "Missing required audio kernel modules: snd-soc-simple-card, snd-soc-tlv320aic31xx, snd-soc-ics43432" >&2 + echo "Install a raspi kernel package that provides them, then rerun this script." >&2 + exit 1 + fi +fi + +{ + echo "i2c-dev" + for mod in snd-soc-simple-card snd-soc-tlv320aic31xx snd-soc-ics43432; do + if [ "$NEED_KERNEL_REBOOT" -eq 1 ] || modinfo "$mod" >/dev/null 2>&1; then + echo "$mod" + fi + done +} > "$MODULES_LOAD_FILE" + +modprobe i2c-dev || true +modprobe snd-soc-simple-card || true +modprobe snd-soc-tlv320aic31xx || true +modprobe snd-soc-ics43432 || true + echo " Done." # 2. Compile and install device tree overlay @@ -143,44 +202,45 @@ cat > "$DTS" << 'DTS_EOF' }; fragment@3 { - target = <&sound>; + target-path = "/"; __overlay__ { - compatible = "simple-audio-card"; - i2s-controller = <&i2s_clk_producer>; - #address-cells = <1>; - #size-cells = <0>; - simple-audio-card,name = "barepi-audio"; - simple-audio-card,format = "i2s"; - status = "okay"; + sound { + compatible = "simple-audio-card"; + #address-cells = <1>; + #size-cells = <0>; + simple-audio-card,name = "barepi-audio"; + simple-audio-card,format = "i2s"; + status = "okay"; - simple-audio-card,dai-link@0 { - reg = <0>; - format = "i2s"; - bitclock-master = <&dailink0_master>; - frame-master = <&dailink0_master>; + simple-audio-card,dai-link@0 { + reg = <0>; + format = "i2s"; + bitclock-master = <&cpu0>; + frame-master = <&cpu0>; - dailink0_master: cpu { - sound-dai = <&i2s_clk_producer>; + cpu0: cpu { + sound-dai = <&i2s_clk_producer>; + }; + + codec0: codec { + sound-dai = <&dac_codec>; + system-clock-frequency = <1536000>; + }; }; - codec { - sound-dai = <&dac_codec>; - system-clock-frequency = <1536000>; - }; - }; + simple-audio-card,dai-link@1 { + reg = <1>; + format = "i2s"; + bitclock-master = <&cpu1>; + frame-master = <&cpu1>; - simple-audio-card,dai-link@1 { - reg = <1>; - format = "i2s"; - bitclock-master = <&dailink1_master>; - frame-master = <&dailink1_master>; + cpu1: cpu { + sound-dai = <&i2s_clk_producer>; + }; - dailink1_master: cpu { - sound-dai = <&i2s_clk_producer>; - }; - - codec { - sound-dai = <&mic_codec>; + codec1: codec { + sound-dai = <&mic_codec>; + }; }; }; }; @@ -686,10 +746,12 @@ fi echo "" echo "=== Done ===" if [ "$CHANGED" -eq 1 ]; then - echo "config.txt was modified — reboot to load the overlay/reset config." -else - echo "config.txt unchanged. Reboot if this is a first-time setup." + echo "config.txt was modified." fi +if [ "$NEED_KERNEL_REBOOT" -eq 1 ]; then + echo "A compatible Ubuntu raspi kernel was installed." +fi +echo "Reboot to load the updated overlay and audio kernel/module state." echo "Speaker routing defaults and mic GPIO defaults will be restored automatically after boot." echo "Manual speaker check/adjust: $TARGET_HOME/volume.sh" echo "Manual mic test: $TARGET_HOME/test-mics.sh"