Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

native: SOF-aware audio period sizing (fixes G7 DAPM amp storm)

Root cause of silent G7 speakers with everything else correct: the old
audio.c config hardcoded ~1ms ALSA period (rate/1000 frames) + 4ms total
buffer. Works fine on HDA-direct codecs (ThinkPad X13 etc.) but on
SOF+MAX98360A the boot log shows **10,686 sdmode toggles per boot** —
once per period, matching the ~5ms toggle spacing exactly.

Mechanism: MAX98357A's DAPM event handler flips SD_MODE high on POST_PMU
and low on PRE_PMD. At 4ms buffer depth, ac-native's 16ms paint-loop
audio submission cadence misses every period = constant underrun =
stream bounces PMU/PMD every period = amp physically toggles faster
than it can stabilize = silence even though the ALSA layer looks fine.

Probe sound/soc/sof's presence (card0 exists AND no legacy HDA codec97
node) and bump to 10ms period / 40ms buffer — same shape ChromeOS uses
on Dedede. HDA paths unaffected; ThinkPad keeps its tight latency.

Also: drop loglevel=7 + per-subsystem dyndbg from kernel cmdline now
that we've extracted the diagnosis. Flooding tty0 with kernel messages
was slowing userspace enough that the trackpad's HID polling was
failing to register. Keep only max98357a dyndbg so the next boot
confirms sdmode stays HIGH during playback instead of cycling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+28 -6
+1 -1
fedac/native/kernel/config-minimal
··· 425 425 CONFIG_LEGACY_VSYSCALL_XONLY=y 426 426 # CONFIG_LEGACY_VSYSCALL_NONE is not set 427 427 CONFIG_CMDLINE_BOOL=y 428 - CONFIG_CMDLINE="initrd=\\initramfs.cpio.gz console=tty0 loglevel=7 vt.global_cursor_default=0 init=/init mitigations=off snd_hda_intel.power_save=0 nmi_watchdog=0 tsc=reliable no_timer_check acpi_backlight=native thinkpad_acpi.brightness_enable=1 i8042.reset i8042.nomux reboot=efi,cold dyndbg=\"file drivers/pinctrl/intel/* +p; file drivers/gpio/* +p; file sound/soc/codecs/max98357a.c +p\"" 428 + CONFIG_CMDLINE="initrd=\\initramfs.cpio.gz console=tty0 quiet loglevel=3 vt.global_cursor_default=0 init=/init mitigations=off snd_hda_intel.power_save=0 nmi_watchdog=0 tsc=reliable no_timer_check acpi_backlight=native thinkpad_acpi.brightness_enable=1 i8042.reset i8042.nomux reboot=efi,cold dyndbg=\"file sound/soc/codecs/max98357a.c +p\"" 429 429 # CONFIG_CMDLINE_OVERRIDE is not set 430 430 CONFIG_MODIFY_LDT_SYSCALL=y 431 431 # CONFIG_STRICT_SIGALTSTACK_SIZE is not set
+27 -5
fedac/native/src/audio.c
··· 1842 1842 fprintf(stderr, "[audio] Selected rate: %u Hz (hw range %u–%u)\n", rate, rate_min, rate_max); 1843 1843 snd_pcm_hw_params_set_rate_near(pcm, params, &rate, 0); 1844 1844 1845 - // Scale period and buffer to ~1ms latency at the negotiated rate 1846 - snd_pcm_uframes_t period = rate / 1000; // ~1ms worth of frames 1847 - if (period < 64) period = 64; 1845 + // Period + buffer sizing. The old config aimed for ~1ms latency (period = 1846 + // rate/1000, buffer = 4 periods) which works on HDA-direct codecs but 1847 + // breaks SOF+MAX98360A on Jasper Lake Chromebooks: the MAX98357A DAPM 1848 + // event handler toggles the amp's SD_MODE GPIO on every PMU/PMD event, 1849 + // and with a 4ms buffer the stream underruns constantly → DAPM rapid- 1850 + // cycles the amp on/off → audio never stabilizes → speakers stay silent 1851 + // despite mixer, codec, and GPIO all looking correct. We saw 10,686 1852 + // sdmode toggles in a single boot's kmsg on the G7 at the 1ms setting. 1853 + // 1854 + // Probe whether we're on a SOF platform (sound/soc/sof is one path) and 1855 + // bump to 10ms / 40ms which is what ChromeOS itself uses. Non-SOF HDA 1856 + // devices (ThinkPads, most laptops) keep the tight latency because their 1857 + // amp/codec model doesn't gate on per-period DAPM events. 1858 + int sof_active = (access("/sys/class/sound/card0/id", R_OK) == 0) && 1859 + (access("/proc/asound/card0/codec97#0", F_OK) != 0); 1860 + snd_pcm_uframes_t period; 1861 + snd_pcm_uframes_t buffer_size; 1862 + if (sof_active) { 1863 + period = rate / 100; // 10ms (480 frames at 48kHz) 1864 + buffer_size = period * 4; // 40ms total — SOF DAPM-friendly 1865 + fprintf(stderr, "[audio] SOF platform detected — period=%lu buffer=%lu (10ms/40ms)\n", 1866 + (unsigned long)period, (unsigned long)buffer_size); 1867 + } else { 1868 + period = rate / 1000; // 1ms on HDA-direct paths 1869 + if (period < 64) period = 64; 1870 + buffer_size = period * 4; 1871 + } 1848 1872 snd_pcm_hw_params_set_period_size_near(pcm, params, &period, 0); 1849 - 1850 - snd_pcm_uframes_t buffer_size = period * 4; // 4 periods (~4ms total) 1851 1873 snd_pcm_hw_params_set_buffer_size_near(pcm, params, &buffer_size); 1852 1874 1853 1875 err = snd_pcm_hw_params(pcm, params);