Fix MBHC wired headphone autodetection across all targets for a1125 (ampere)

Retain PM8909 MBHC digital debounce clock (DIG_CLK_CTL_D_MBHC_CLK_EN) and master bias (CDC_A_MASTER_BIAS_CTL = 0x30) across s2 standby gating while keeping the 100 uA button ISRC and button IRQs disabled when unplugged, check CDC_A_MBHC_RESULT_2 on boot/set_jack/switch IRQs with 3/4-pole FSM classification, fix iface=CARD jack queries, event coalescing, and stale unplugged Headphones boot fallback in bananarchy-soundmonitor and sxmo audio scripts, harden host tests against CPU contention, and rebuild all a1125 (ampere) target images.
This commit is contained in:
Luxferre committed 2026-11-24 11:00:06 +02:00
1 parent aba38a58f2
commit 9619cc9541
19 files changed
+515 -92

No files matched your search

+1 -1
View File
@@ -176,7 +176,7 @@ Keep this file short. Full details live in `README.md`, `MANUAL.md`, `SDK.md`, `
keypad udev/Xorg rules, BusyBox applet lists, and `scripts/set-bananarchy-hostname.sh`. keypad udev/Xorg rules, BusyBox applet lists, and `scripts/set-bananarchy-hostname.sh`.
- The Power menu label is **Reboot to loader** and still calls `sxmo_power.sh bootloader`; `Logout` is removed from - The Power menu label is **Reboot to loader** and still calls `sxmo_power.sh bootloader`; `Logout` is removed from
`dmenu.c`, `dmenu.so`, `sxmo_appmenu.sh`, and `sxmo_hook_contextmenu.sh`. Keep the compact Power menu layout synchronized. `dmenu.c`, `dmenu.so`, `sxmo_appmenu.sh`, and `sxmo_hook_contextmenu.sh`. Keep the compact Power menu layout synchronized.
- Keep `quagr` (`quagr.so` / `xquagr`) receiver autostart strictly gated on `autostart_rx=1` plus a valid Rx passphrase or 64-char hex key, closed-flip `QUAGR` cover alerts dismissing on any side button (`scripts/test-quagr.py`), `msm8905-cam.c` 180-degree rotation enabled for `nokia,beatles`, `nokia,sparkler`, and `nokia,leo` alongside cached `row_buf` RAW10 demosaic; keep `patches/kernel/0013-msm8909-early-scm-smp-cpufreq.patch` (4-core SMP + `cpufreq` up to `1.267 GHz`), `patches/kernel/0014-input-core-keypad-debouncer.patch` (ABI-preserving `input_core` `/sys/module/input_core/parameters/key_debounce_ms` debouncer without editing `include/linux/input.h`, `pm8941-pwrkey` chatter holdoff, `col-scan-delay-us = <0x32>` across all 6 DTS/DTBs, `xset r rate 300 25`, `scripts/test-keypad-debouncer.py`), `patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch` (`REGCACHE_FLAT` 97-register `0x00` `.reg_defaults` without `.volatile_reg` + unconditional `regmap_write_bits` in `probe`/`hw_params`/`enable_interpolator`/`enable_dec` + `msm8916_wcd_digital_force_sync_ctl()` `.use_pmdown_time = 0` `48 kHz` programming in `msm8916-wcd-digital.c`, ADSP `< 2.7` `AFE_PORT_ID_PRIMARY_MI2S_RX` `INT_DIGITAL_CDC_CLK` retention in `q6afe.c` + `q6core_query_versions_locked()` in `q6core.c`, PM8909 `CAJON_2_0` `CDC_A_PERPH_SUBTYPE == 0x0a` non-boost Class-D `0x69`/`0xE9` PA, HPH DAC/PA sequencing, `NCP_FBCTRL = 0xA8`, `NCP_VCTRL = 0xA4`/`0xA7`, `RX_HPH_BIAS_PA = 0xFA`, `SPKR_ANA_BIAS_SET = 0x41`, and `s2` wakeup restore without clobbering `SPK DAC Switch` in `msm8916-wcd-analog.c`), WirePlumber `create-item.lua` + `msm8916-s16le.conf` `item.features.mono = true` (`[ MONO ]` `PortConfig` with `channelmix.normalize = true`) Speaker/Earpiece stereo-to-mono downmix and `/etc/pipewire/{client,pipewire-pulse}.conf.d/10-bananarchy-audio.conf` (`channelmix.normalize = true`, `dither.method = "triangular"`), `<= 84` (`0 dB`) ALSA digital output ceiling with `card0` PipeWire unity sync + `bananarchy-soundmonitor` initial internal sink sync (`scripts/test-audio-quality.py`), disabled `vibrator@c000` + volume-independent calibrated `157.0 Hz` haptic audio (`sxmo_vibrate.c`, `libpulse` + `SND_PCM_FORMAT_FLOAT_LE`, `HAPTIC_REF_RX3_VOL = 84`), Sparkler/Leo `157 Hz` LRA media filtering (`highpass=f=260` + `bandreject=f=157` on Speaker + non-speaker `RX3` zeroing in `music.so`, `files.so`, `ringtones.so`, `sxmo_audio.sh`, and Sparkler-only `/etc/mpv/mpv.conf` via `apply-bananarchy-overlay.sh`), `DEFAULT_USB_TIMEOUT_MS = 30000` (`--usb-timeout`), and `sxmo_timer.sh` / `dmenu.c` keypad cancellation (`scripts/test-timer.py`, `scripts/test-sparkler-port.py`, `scripts/test-edl-firehose-read.py`, `scripts/test-quagr.py`). - Keep `quagr` (`quagr.so` / `xquagr`) receiver autostart strictly gated on `autostart_rx=1` plus a valid Rx passphrase or 64-char hex key, closed-flip `QUAGR` cover alerts dismissing on any side button (`scripts/test-quagr.py`), `msm8905-cam.c` 180-degree rotation enabled for `nokia,beatles`, `nokia,sparkler`, and `nokia,leo` alongside cached `row_buf` RAW10 demosaic; keep `patches/kernel/0013-msm8909-early-scm-smp-cpufreq.patch` (4-core SMP + `cpufreq` up to `1.267 GHz`), `patches/kernel/0014-input-core-keypad-debouncer.patch` (ABI-preserving `input_core` `/sys/module/input_core/parameters/key_debounce_ms` debouncer without editing `include/linux/input.h`, `pm8941-pwrkey` chatter holdoff, `col-scan-delay-us = <0x32>` across all 6 DTS/DTBs, `xset r rate 300 25`, `scripts/test-keypad-debouncer.py`), `patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch` (`REGCACHE_FLAT` 97-register `0x00` `.reg_defaults` without `.volatile_reg` + unconditional `regmap_write_bits` in `probe`/`hw_params`/`enable_interpolator`/`enable_dec` + `msm8916_wcd_digital_force_sync_ctl()` `.use_pmdown_time = 0` `48 kHz` programming in `msm8916-wcd-digital.c`, ADSP `< 2.7` `AFE_PORT_ID_PRIMARY_MI2S_RX` `INT_DIGITAL_CDC_CLK` retention in `q6afe.c` + `q6core_query_versions_locked()` in `q6core.c`, PM8909 `CAJON_2_0` `CDC_A_PERPH_SUBTYPE == 0x0a` non-boost Class-D `0x69`/`0xE9` PA, HPH DAC/PA sequencing, `NCP_FBCTRL = 0xA8`, `NCP_VCTRL = 0xA4`/`0xA7`, `RX_HPH_BIAS_PA = 0xFA`, `SPKR_ANA_BIAS_SET = 0x41`, `s2` wakeup restore without clobbering `SPK DAC Switch`, MBHC `DIG_CLK_CTL_D_MBHC_CLK_EN` + `CDC_A_MASTER_BIAS_CTL = 0x30` idle retention, and `CDC_A_MBHC_RESULT_2` 3/4-pole detection in `msm8916-wcd-analog.c`), WirePlumber `create-item.lua` + `msm8916-s16le.conf` `item.features.mono = true` (`[ MONO ]` `PortConfig` with `channelmix.normalize = true`) Speaker/Earpiece stereo-to-mono downmix and `/etc/pipewire/{client,pipewire-pulse}.conf.d/10-bananarchy-audio.conf` (`channelmix.normalize = true`, `dither.method = "triangular"`), `<= 84` (`0 dB`) ALSA digital output ceiling with `card0` PipeWire unity sync + `bananarchy-soundmonitor` initial internal sink sync & `iface=CARD` / `drain_jack_events()` coalescing (`scripts/test-audio-quality.py`), disabled `vibrator@c000` + volume-independent calibrated `157.0 Hz` haptic audio (`sxmo_vibrate.c`, `libpulse` + `SND_PCM_FORMAT_FLOAT_LE`, `HAPTIC_REF_RX3_VOL = 84`), Sparkler/Leo `157 Hz` LRA media filtering (`highpass=f=260` + `bandreject=f=157` on Speaker + non-speaker `RX3` zeroing in `music.so`, `files.so`, `ringtones.so`, `sxmo_audio.sh`, and Sparkler-only `/etc/mpv/mpv.conf` via `apply-bananarchy-overlay.sh`), `DEFAULT_USB_TIMEOUT_MS = 30000` (`--usb-timeout`), and `sxmo_timer.sh` / `dmenu.c` keypad cancellation (`scripts/test-timer.py`, `scripts/test-sparkler-port.py`, `scripts/test-edl-firehose-read.py`, `scripts/test-quagr.py`).
- Bluetooth HOGP config and plugin load are verified, but full hardware sign-off still needs a wake-up paired keyboard - Bluetooth HOGP config and plugin load are verified, but full hardware sign-off still needs a wake-up paired keyboard
and **Connect Device** to confirm real HID key events. and **Connect Device** to confirm real HID key events.
+9 -9
View File
@@ -18,8 +18,8 @@ Upcoming release build (`a1125` / `ampere` via `scripts/version.sh`) targeting *
### Audio playback quality (`0015` WCD `48 kHz` interpolators, PM8909 `CAJON_2_0` analog codec, PipeWire downmix & unity gain staging) across all targets ### Audio playback quality (`0015` WCD `48 kHz` interpolators, PM8909 `CAJON_2_0` analog codec, PipeWire downmix & unity gain staging) across all targets
- **48 kHz WCD digital interpolators/decimators & PM8909 `CAJON_2_0` analog codec (`patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch`, `scripts/build-kernel-audio.sh`)**: fixed `REGCACHE_FLAT` in `msm8916-wcd-digital.c` missing `.reg_defaults` (which previously zeroed `LPASS_CDC_RX1/2/3_B5_CTL` POR `0x68` (`48 kHz`) to `0x00` (`8 kHz` narrowband HSP filter), `TX1/2_CLK_FS_CTL` POR `0x03` to `0x00`, and `LPASS_CDC_CLK_OTHR_CTL` POR `0x04` to `0x00` on `regcache_sync()`, while placing non-zero operating values directly in `.reg_defaults` would let `regcache_mark_dirty()` / `no_sync_defaults` skip re-writing `RX1/2/3_B5_CTL` after MSM8905 `INT_DIGITAL_CDC_CLK` resets, and marking `.volatile_reg` would expose unclocked `0x0771c000` LPASS AHB debugfs reads) by adding complete 97-register `0x00` hardware-reset `msm8916_wcd_digital_reg_defaults[]` with `valid_reg` (without `.volatile_reg`), `probe()` non-zero POR writes via `regmap_write_bits()`, unconditional `regmap_write_bits()` (`force=true`) in `hw_params()` (`RX1/2/3_B5_CTL = (rx_fs_rate << 5) | BIT(3)`, `TX1/2_CLK_FS_CTL = tx_fs_rate`), `enable_interpolator()`, and `enable_dec()`, plus `msm8916_wcd_digital_force_sync_ctl()` across `startup()`/`runtime_resume()` and `.use_pmdown_time = 0`; fixed MSM8905 (`Q6_ADSP_VERSION_2_6`) `q6afe.c` and `q6core.c` clock/version handling by passing explicit `AFE_PORT_ID_PRIMARY_MI2S_RX` (`0x1000`) in `q6afe_set_param_v2()` for `Q6AFE_LPASS_CLK_ID_INTERNAL_DIGITAL_CODEC_CORE` on ADSP `< 2.7`, retaining `afe->digital_cdc_clk_freq` across `q6afe_port_stop(PRIMARY_MI2S_RX)` until runtime suspend disables `mclk`, and falling back to `q6core_get_svc_versions()` in `q6core_query_versions_locked()` without latching `Q6_ADSP_VERSION_UNKNOWN` on early APR timeouts; detected PM8909 `CAJON_2_0` (`CDC_A_PERPH_SUBTYPE == 0x0a`) in `msm8916-wcd-analog.c` to apply Qualcomm `cajon2p0` defaults (`NCP_FBCTRL = 0xA8`, `NCP_VCTRL = 0xA4`/`0xA7`, `RX_HPH_BIAS_PA = 0xFA`, `SPKR_ANA_BIAS_SET = 0x41`, `TX_1_2_OPAMP_BIAS = 0x4C`, `RX_EAR_STATUS = 0x10`) and restore them across `s2` standby gating without clobbering `SPK DAC Switch`, configured the non-boost Class-D `SPK PA` (`SPKR_DRV_CTL = 0x69`/`0xE9` without nonexistent 5 V `BOOST_SET`/`CMFB_SET` bits), and added `CAJON_2_0` `HPHL DAC`/`HPHR DAC`/`HPH PA` DAPM sequencing and `+6 dB` analog `EAR PA` headroom (`RX_EAR_CTL BIT(5)`). Verified initial `0015` build live on connected `nokia-sparkler` (`Nokia 8000 4G`): `050/070/090 = 0x68` (`48 kHz` halfband interpolators), `290/2b0 = 0x03`, `198 = 0x03`, `CAJON_2_0` analog regmap `f146 = 0x30`, `f165 = 0x4c`, `f183 = 0xa8`, `f185 = 0xa4`, `f194 = 0xfa`, `f1b3 = 0x41`, `f1b0 = 0x83`, `f1b2 = 0xe9`, `f1b5 = 0xff`, and idle `pm8909_s2` `state=disabled` / `use_count=0` (live MSM8905 `nokia-beatles` verification pending reboot/reflash after the updated `0015` build). - **48 kHz WCD digital interpolators/decimators, MBHC wired jack autodetection, & PM8909 `CAJON_2_0` analog codec (`patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch`, `scripts/build-kernel-audio.sh`)**: fixed `REGCACHE_FLAT` in `msm8916-wcd-digital.c` missing `.reg_defaults` (which previously zeroed `LPASS_CDC_RX1/2/3_B5_CTL` POR `0x68` (`48 kHz`) to `0x00` (`8 kHz` narrowband HSP filter), `TX1/2_CLK_FS_CTL` POR `0x03` to `0x00`, and `LPASS_CDC_CLK_OTHR_CTL` POR `0x04` to `0x00` on `regcache_sync()`, while placing non-zero operating values directly in `.reg_defaults` would let `regcache_mark_dirty()` / `no_sync_defaults` skip re-writing `RX1/2/3_B5_CTL` after MSM8905 `INT_DIGITAL_CDC_CLK` resets, and marking `.volatile_reg` would expose unclocked `0x0771c000` LPASS AHB debugfs reads) by adding complete 97-register `0x00` hardware-reset `msm8916_wcd_digital_reg_defaults[]` with `valid_reg` (without `.volatile_reg`), `probe()` non-zero POR writes via `regmap_write_bits()`, unconditional `regmap_write_bits()` (`force=true`) in `hw_params()` (`RX1/2/3_B5_CTL = (rx_fs_rate << 5) | BIT(3)`, `TX1/2_CLK_FS_CTL = tx_fs_rate`), `enable_interpolator()`, and `enable_dec()`, plus `msm8916_wcd_digital_force_sync_ctl()` across `startup()`/`runtime_resume()` and `.use_pmdown_time = 0`; fixed MSM8905 (`Q6_ADSP_VERSION_2_6`) `q6afe.c` and `q6core.c` clock/version handling by passing explicit `AFE_PORT_ID_PRIMARY_MI2S_RX` (`0x1000`) in `q6afe_set_param_v2()` for `Q6AFE_LPASS_CLK_ID_INTERNAL_DIGITAL_CODEC_CORE` on ADSP `< 2.7`, retaining `afe->digital_cdc_clk_freq` across `q6afe_port_stop(PRIMARY_MI2S_RX)` until runtime suspend disables `mclk`, and falling back to `q6core_get_svc_versions()` in `q6core_query_versions_locked()` without latching `Q6_ADSP_VERSION_UNKNOWN` on early APR timeouts; detected PM8909 `CAJON_2_0` (`CDC_A_PERPH_SUBTYPE == 0x0a`) in `msm8916-wcd-analog.c` to apply Qualcomm `cajon2p0` defaults (`NCP_FBCTRL = 0xA8`, `NCP_VCTRL = 0xA4`/`0xA7`, `RX_HPH_BIAS_PA = 0xFA`, `SPKR_ANA_BIAS_SET = 0x41`, `TX_1_2_OPAMP_BIAS = 0x4C`, `RX_EAR_STATUS = 0x10`) and restore them across `s2` standby gating without clobbering `SPK DAC Switch`, configured the non-boost Class-D `SPK PA` (`SPKR_DRV_CTL = 0x69`/`0xE9` without nonexistent 5 V `BOOST_SET`/`CMFB_SET` bits), added `CAJON_2_0` `HPHL DAC`/`HPHR DAC`/`HPH PA` DAPM sequencing and `+6 dB` analog `EAR PA` headroom (`RX_EAR_CTL BIT(5)`), and fixed `0012` MBHC jack autodetection starvation by preserving `DIG_CLK_CTL_D_MBHC_CLK_EN` (`0xf04A BIT(3)`) and `CDC_A_MASTER_BIAS_CTL = 0x30` while gating the `100 uA` button ISRC (`CDC_A_MBHC_FSM_CTL`), `MICB_1_INT_TX2_INT_RBIAS`, button IRQs, and Linux `pm8909_s2` regulator vote off at unplugged idle, reading `CDC_A_MBHC_RESULT_2` (`0xf159 BIT(4)` `SWCH_LEVEL_REMOVE`) in `probe()`, `set_jack()`, and `pm8916_mbhc_switch_irq_handler()` (`phys_ins != waiting_ins` clear-edge guard), and distinguishing 3-pole TRS vs 4-pole TRRS headsets via `MBHC_BUTTON_PRESS_DET` after FSM settle. Verified initial `0015` build live on connected `nokia-sparkler` (`Nokia 8000 4G`): `050/070/090 = 0x68`, `290/2b0 = 0x03`, `198 = 0x03`, `CAJON_2_0` analog regmap `f146 = 0x30`, `f165 = 0x4c`, `f183 = 0xa8`, `f185 = 0xa4`, `f194 = 0xfa`, `f1b3 = 0x41`, `f1b0 = 0x83`, `f1b2 = 0xe9`, `f1b5 = 0xff`, and idle `pm8909_s2` `state=disabled` / `use_count=0`; verified updated `0015` build live on connected `nokia-beatles` (`Nokia 2720 Flip`): `050/070/090 = 0x00000068` and `198/290/2b0 = 0x00000003` safely readable at idle, during playback, and after `2.5 s` idle suspend without AHB hangs, alongside idle MBHC readiness (`f04a = 0x08`, `f146 = 0x30`, `f147 = 0xb4`, `f150 = 0xf1`, `f151 = 0x00`, `f015 = 0x80`, `f159 = 0x10`) and `pm8909_s2` `state=disabled` / `num_users=0`.
- **Lossless PipeWire stereo-to-mono downmix, TPDF dithering, and `<= 0 dB` unity gain staging (`create-item.lua`, `msm8916-s16le.conf`, `10-bananarchy-audio.conf`, `UCM2`, `sxmo_audio.sh`, `bananarchy-soundmonitor`, `sxmo_hook_ring.sh`, `xdrawer.cpp`, `callscreen_plugin.cpp`, `files_plugin.cpp`, `ringtones_plugin.cpp`, `scripts/test-audio-quality.py`)**: added per-node `item.features.mono` support in `overlay/rootfs/usr/share/wireplumber/scripts/node/create-item.lua` to replace unpositioned `[ FC, AUX0 ]` mapping (where WirePlumber 0.5 `si_audio_adapter_find_format` marks `AUX*` nodes `0x1000..0x1fff` as `item.node.unpositioned = "true"`, causing `si-standard-link` to skip `PortConfig` downmixing and route `output_FL -> playback_AUX0` while leaving positioned `playback_FC` unlinked and Speaker silent), and updated all four `msm8916-s16le.conf` copies to lock `audio.rate = 48000` and `dither.method = "triangular"` across internal ALSA nodes while enabling `item.features.mono = true` (`[ MONO ]` `PortConfig` keeping hardware `hw:0,0` in `2 ch` `48 kHz` `S16_LE` while keeping `Headphones` and Bluetooth A2DP sinks in full `2 ch` `[ FL, FR ]` stereo) and `channelmix.normalize = true` on `HiFi__Speaker__sink` and `HiFi__Earpiece__sink`, paired with `/etc/pipewire/{client,pipewire-pulse}.conf.d/10-bananarchy-audio.conf` (`channelmix.normalize = true`, `dither.method = "triangular"`) so stereo music sums `0.5 * FL + 0.5 * FR` without discarding `FR` or halving `sxmo_vibrate` amplitude; kept PipeWire's software sink at `100%` unity (`0.0 dB`) whenever `/proc/asound/card0` is present (`bananarchy_sync_internal_pw_vol`, `bananarchy_set_sink_volume` covering `@DEFAULT_AUDIO_SINK@`, sink ID fallback, and `pactl @DEFAULT_SINK@`, plus 500 ms `alsa_output.platform-7702000.sound.HiFi__*__sink` readiness wait in `sync_pipewire_profile` and initial `has_internal_sink()` / `internal_synced` jack-aware sync in `bananarchy-soundmonitor`) and capped ALSA hardware digital playback mappings (`Speaker`/`Earpiece` `52..84`, `Headphones` `51..83`, UCM2 initial `80`/`84`) at `<= 84` (`0 dB` unity) to eliminate `+4..+8 dB` 16-bit digital clipping; added `scripts/test-audio-quality.py` wired into `scripts/check-rebuild.sh`. Verified live on `nokia-sparkler`: `mpv:output_MONO -> HiFi__Speaker__sink:playback_MONO [active]` with `pcm0p/sub0` `RUNNING`, `0.5 * FL + 0.5 * FR` confirmed via `parecord` monitor DFT (`440 Hz = 6979.1`, `660 Hz = 7746.8`), and `sxmo_vibrate` `vib_rc=0`. - **Lossless PipeWire stereo-to-mono downmix, TPDF dithering, `<= 0 dB` unity gain staging, and jack autodetection (`create-item.lua`, `msm8916-s16le.conf`, `10-bananarchy-audio.conf`, `UCM2`, `sxmo_audio.sh`, `sxmo_modemaudio.sh`, `sxmo_hook_statusbar.sh`, `bananarchy-soundmonitor`, `sxmo_hook_ring.sh`, `xdrawer.cpp`, `callscreen_plugin.cpp`, `files_plugin.cpp`, `ringtones_plugin.cpp`, `scripts/test-audio-quality.py`)**: added per-node `item.features.mono` support in `overlay/rootfs/usr/share/wireplumber/scripts/node/create-item.lua` to replace unpositioned `[ FC, AUX0 ]` mapping (where WirePlumber 0.5 `si_audio_adapter_find_format` marks `AUX*` nodes `0x1000..0x1fff` as `item.node.unpositioned = "true"`, causing `si-standard-link` to skip `PortConfig` downmixing and route `output_FL -> playback_AUX0` while leaving positioned `playback_FC` unlinked and Speaker silent), and updated all four `msm8916-s16le.conf` copies to lock `audio.rate = 48000` and `dither.method = "triangular"` across internal ALSA nodes while enabling `item.features.mono = true` (`[ MONO ]` `PortConfig` keeping hardware `hw:0,0` in `2 ch` `48 kHz` `S16_LE` while keeping `Headphones` and Bluetooth A2DP sinks in full `2 ch` `[ FL, FR ]` stereo) and `channelmix.normalize = true` on `HiFi__Speaker__sink` and `HiFi__Earpiece__sink`, paired with `/etc/pipewire/{client,pipewire-pulse}.conf.d/10-bananarchy-audio.conf` (`channelmix.normalize = true`, `dither.method = "triangular"`) so stereo music sums `0.5 * FL + 0.5 * FR` without discarding `FR` or halving `sxmo_vibrate` amplitude; kept PipeWire's software sink at `100%` unity (`0.0 dB`) whenever `/proc/asound/card0` is present (`bananarchy_sync_internal_pw_vol`, `bananarchy_set_sink_volume` covering `@DEFAULT_AUDIO_SINK@`, sink ID fallback, and `pactl @DEFAULT_SINK@`, plus 500 ms `alsa_output.platform-7702000.sound.HiFi__*__sink` readiness wait in `sync_pipewire_profile` and initial `has_internal_sink()` / `internal_synced` jack-aware sync in `bananarchy-soundmonitor`); fixed `bananarchy-soundmonitor.c`, `sxmo_audio.sh`, `sxmo_modemaudio.sh`, and `sxmo_hook_statusbar.sh` jack autodetection (`iface=CARD,name='Headphone Jack'`/`'Mic Jack'` queries, `50 ms` `drain_jack_events()` coalescing into one atomic `sxmo_audio.sh device set` switch, stale persisted `Headphones`/`Headset` boot fallback when unplugged, call handoff Mic/Headset preservation, and dark-screen statusbar volume updates); and capped ALSA hardware digital playback mappings (`Speaker`/`Earpiece` `52..84`, `Headphones` `51..83`, UCM2 initial `80`/`84`) at `<= 84` (`0 dB` unity) to eliminate `+4..+8 dB` 16-bit digital clipping; added `scripts/test-audio-quality.py` wired into `scripts/check-rebuild.sh`. Verified live on `nokia-sparkler` (`mpv:output_MONO -> HiFi__Speaker__sink:playback_MONO [active]`, `0.5 * FL + 0.5 * FR` DFT, `sxmo_vibrate` `vib_rc=0`) and on `nokia-beatles` boot with stale `~/.config/sxmo/audio_out_device = Headphones` (`/tmp/sxmo_audio_out_device = Speaker`, `wpctl` `Built-in Audio Speaker playback [vol: 1.00]`, `Active Profile: HiFi (Mic1, Speaker)`).
### Cellular PS attach, Dual-SIM QMI WDS subscription binding (`libmm-wds-bind.so`), and mobile data (`wwan0`) fixes across all targets ### Cellular PS attach, Dual-SIM QMI WDS subscription binding (`libmm-wds-bind.so`), and mobile data (`wwan0`) fixes across all targets
@@ -49,13 +49,13 @@ Upcoming release build (`a1125` / `ampere` via `scripts/version.sh`) targeting *
- **microSD PM8909 `l11` static `200 mA` load removal & `sdhci-msm` probe/active HPM + standby LPM `set_load` (`patches/kernel/0012-msm8909-standby-wifi-wcd-panel-ldo-bms.patch`, `devices/*/*.dts`, `prebuilt/kernel-6.12.1-msm8916/`)**: removed static `regulator-system-load = <0x30d40>;` from PM8909 `l11` across all 6 DTS files while extending `sdhci-msm.c` (`sdhci_msm_register_vreg()`, `sdhci_msm_set_vmmc()`, `msm_toggle_vqmmc()`, `sdhci_msm_runtime_resume()`, `sdhci_msm_runtime_suspend()`) and rebuilding `vmlinuz`/modules/DTBs so microSD probe and UHS-I tuning receive full `200 mA` / `20 mA` HPM without brownout (`-5`/`-110`) and idle runtime suspend drops `vmmc`/`vqmmc` to `2 mA`/`0 mA` PM8909 LPM. - **microSD PM8909 `l11` static `200 mA` load removal & `sdhci-msm` probe/active HPM + standby LPM `set_load` (`patches/kernel/0012-msm8909-standby-wifi-wcd-panel-ldo-bms.patch`, `devices/*/*.dts`, `prebuilt/kernel-6.12.1-msm8916/`)**: removed static `regulator-system-load = <0x30d40>;` from PM8909 `l11` across all 6 DTS files while extending `sdhci-msm.c` (`sdhci_msm_register_vreg()`, `sdhci_msm_set_vmmc()`, `msm_toggle_vqmmc()`, `sdhci_msm_runtime_resume()`, `sdhci_msm_runtime_suspend()`) and rebuilding `vmlinuz`/modules/DTBs so microSD probe and UHS-I tuning receive full `200 mA` / `20 mA` HPM without brownout (`-5`/`-110`) and idle runtime suspend drops `vmmc`/`vqmmc` to `2 mA`/`0 mA` PM8909 LPM.
- **Offline verification (`scripts/test-imsd-volte.py`, `scripts/test-standby-power-policy.py`, `scripts/check-rebuild.sh`, `BATTERY-OPTIMIZATION-ANALYSIS.md`)**: added host regression tests for Combined EPS/IMSI (`cs_attach=1`), `searching_lte`, and 0-packet `2.2 s` QRTR idle silence in `test-imsd-volte.py`; added host tests for `CPU_GOV_PATH` + idempotent `screenoff`/`screenon` across dark/cover-lit/open, `standby.mode`/`rat_timer.pid`, `bananarchy-dsds --sig-hysteresis` QMI `0x0045`/`0x0050` wire framing over `AF_UNIX` `SOCK_SEQPACKET`, and `30-bananarchy-network-status.sh` dark gating in `test-standby-power-policy.py`; guarded DTS/DTBs against `regulator-system-load` in `check-rebuild.sh`; and documented Section 24 in `BATTERY-OPTIMIZATION-ANALYSIS.md`. - **Offline verification (`scripts/test-imsd-volte.py`, `scripts/test-standby-power-policy.py`, `scripts/check-rebuild.sh`, `BATTERY-OPTIMIZATION-ANALYSIS.md`)**: added host regression tests for Combined EPS/IMSI (`cs_attach=1`), `searching_lte`, and 0-packet `2.2 s` QRTR idle silence in `test-imsd-volte.py`; added host tests for `CPU_GOV_PATH` + idempotent `screenoff`/`screenon` across dark/cover-lit/open, `standby.mode`/`rat_timer.pid`, `bananarchy-dsds --sig-hysteresis` QMI `0x0045`/`0x0050` wire framing over `AF_UNIX` `SOCK_SEQPACKET`, and `30-bananarchy-network-status.sh` dark gating in `test-standby-power-policy.py`; guarded DTS/DTBs against `regulator-system-load` in `check-rebuild.sh`; and documented Section 24 in `BATTERY-OPTIMIZATION-ANALYSIS.md`.
- **Rebuilt local `a1125` (`ampere`) image SHA-256 checksums (`--mkinitfs`, no release `.zip` archives built yet)**: - **Rebuilt local `a1125` (`ampere`) image SHA-256 checksums (`--mkinitfs`, no release `.zip` archives built yet)**:
- `images/bananarchy-nokia-argon.img`: `6279d2b99600aee7751f501257ac48d485eaeee3b3f31c0f98a2b8522400bcd1` - `images/bananarchy-nokia-argon.img`: `5df590a5c0a74a1594882e3d83a81c7691bdd3bfc396a320eb6e84e27f41b356`
- `images/bananarchy-nokia-beatles.img`: `f067a130984d7fe6f79fdf46b3ff657bbe19fe12400e5db1e6ebd4cac24d1e6c` - `images/bananarchy-nokia-beatles.img`: `55cb9c17347735ff066f9a88f3b3e5c574281296ff78ac796cf79e2bbd0c2b81`
- `images/boot-bananarchy-nokia-beatles.img`: `d32c7a38ac85df7faa71d2649d7c6ead1adcef0af39c3e91f08993965ddd44b9` - `images/boot-bananarchy-nokia-beatles.img`: `4500324c8c875588b60063befb9f852069ce5a84b70c92025708c412ddc9a30e`
- `images/bananarchy-nokia-coconut.img`: `4d6733b633ca78ec7fe5de93e1ed0564a3aa116088aee3634147759a414af2c7` - `images/bananarchy-nokia-coconut.img`: `5d629a64b6c82b0ce46af7135e2eff8620142043903c2e65f27a7163a9b21b32`
- `images/boot-bananarchy-nokia-coconut.img`: `fdad08c8501de6b53c6ac76b7886849834fc8840ffec289b41a5c58e924ac803` - `images/boot-bananarchy-nokia-coconut.img`: `c6c1d3fe3ad8eae39cc0ec6eeae14de136fd7524430976cb39ba79255a5dd9c2`
- `images/bananarchy-nokia-sparkler.img`: `068f4fa606bee9c63ac6044902e04a28d596b04edcd230d9703a2687951ee4bb` - `images/bananarchy-nokia-sparkler.img`: `efd541291277e702f67b18b9bf90a7571e459c87c124a705d6dad265dc032be8`
- `images/boot-bananarchy-nokia-sparkler.img`: `026852df5acc871738322ff1de3febf91c097f0f1d745fbbe71f22661023b0e2` - `images/boot-bananarchy-nokia-sparkler.img`: `ba922d89ad0a778086ef6a400d48b816125ad017d24d5bd81ad601d77293342e`
--- ---
Binary file not shown.
Binary file not shown.
+4
View File
@@ -303,6 +303,8 @@ deviceget() {
dev="$(normalize_out_dev "$dev")" dev="$(normalize_out_dev "$dev")"
if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ] && [ -z "$(find_bt_card)" ]; then if [ "$dev" = "Bluetooth" ] && [ -z "$(find_bt_sink)" ] && [ -z "$(find_bt_card)" ]; then
dev="Speaker" dev="Speaker"
elif [ "$dev" = "Headphones" ] && [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" != "1" ]; then
dev="Speaker"
fi fi
printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true printf "%s\n" "$dev" > /tmp/sxmo_audio_out_device 2>/dev/null || true
printf "%s\n" "$dev" printf "%s\n" "$dev"
@@ -345,6 +347,8 @@ devicegetinput() {
in_dev="$(normalize_in_dev "$in_dev")" in_dev="$(normalize_in_dev "$in_dev")"
if [ "$in_dev" = "Bluetooth" ] && [ -z "$(find_bt_source)" ]; then if [ "$in_dev" = "Bluetooth" ] && [ -z "$(find_bt_source)" ]; then
in_dev="Mic1" in_dev="Mic1"
elif [ "$in_dev" = "Headset" ] && [ "$(cat /tmp/sxmo_jack_plugged 2>/dev/null || true)" != "1" ]; then
in_dev="Mic1"
fi fi
printf "%s\n" "$in_dev" > /tmp/sxmo_audio_in_device 2>/dev/null || true printf "%s\n" "$in_dev" > /tmp/sxmo_audio_in_device 2>/dev/null || true
printf "%s\n" "$in_dev" printf "%s\n" "$in_dev"
+14 -1
View File
@@ -79,8 +79,15 @@ EOF
else else
if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then
target_out="Headphones" target_out="Headphones"
if command -v amixer >/dev/null 2>&1 && \
amixer -c 0 cget "iface=CARD,name='Mic Jack'" 2>/dev/null | grep -q ": values=on"; then
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
else
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
fi
else else
target_out="Earpiece" target_out="Earpiece"
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
fi fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then if command -v amixer >/dev/null 2>&1; then
@@ -143,10 +150,16 @@ EOF
else else
if [ "$jack_plugged" = "1" ]; then if [ "$jack_plugged" = "1" ]; then
target_out="Headphones" target_out="Headphones"
if command -v amixer >/dev/null 2>&1 && \
amixer -c 0 cget "iface=CARD,name='Mic Jack'" 2>/dev/null | grep -q ": values=on"; then
sxmo_audio.sh device setinput Headset >/dev/null 2>&1 || true
else
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
fi
else else
target_out="Speaker" target_out="Speaker"
fi
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
fi fi
@@ -554,9 +554,12 @@ case "$1" in
set_time set_time
force_bar=1 force_bar=1
;; ;;
modem|volume) modem)
is_screen_dark && exit 0 is_screen_dark && exit 0
set_"$1" set_modem
;;
volume)
set_volume
;; ;;
state|notifications|notch|inputmethod) state|notifications|notch|inputmethod)
set_"$1" set_"$1"
@@ -1,5 +1,5 @@
diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index 257f780..457b552 100644 index 257f780..f820437 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c --- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c +++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -82,6 +82,7 @@ @@ -82,6 +82,7 @@
@@ -10,7 +10,16 @@ index 257f780..457b552 100644
#define CDC_A_INT_RT_STS (0xf110) #define CDC_A_INT_RT_STS (0xf110)
#define CDC_A_INT_SET_TYPE (0xf111) #define CDC_A_INT_SET_TYPE (0xf111)
#define CDC_A_INT_POLARITY_HIGH (0xf112) #define CDC_A_INT_POLARITY_HIGH (0xf112)
@@ -220,20 +221,28 @@ @@ -191,6 +192,8 @@
CDC_A_MBHC_BTN_VREF_FINE_MASK)
#define CDC_A_MBHC_RESULT_1 (0xf158)
#define CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK GENMASK(4, 0)
+#define CDC_A_MBHC_RESULT_2 (0xf159)
+#define CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE BIT(4)
#define CDC_A_TX_1_EN (0xf160)
#define CDC_A_TX_2_EN (0xf161)
#define CDC_A_TX_1_2_TEST_CTL_1 (0xf162)
@@ -220,20 +223,28 @@
#define CDC_A_RX_HPH_BIAS_LDO_OCP (0xf195) #define CDC_A_RX_HPH_BIAS_LDO_OCP (0xf195)
#define CDC_A_RX_HPH_BIAS_CNP (0xf196) #define CDC_A_RX_HPH_BIAS_CNP (0xf196)
#define CDC_A_RX_HPH_CNP_EN (0xf197) #define CDC_A_RX_HPH_CNP_EN (0xf197)
@@ -39,7 +48,7 @@ index 257f780..457b552 100644
#define CDC_A_SPKR_DAC_CTL (0xf1B0) #define CDC_A_SPKR_DAC_CTL (0xf1B0)
#define SPKR_DAC_CTL_DAC_RESET_MASK BIT(4) #define SPKR_DAC_CTL_DAC_RESET_MASK BIT(4)
@@ -249,10 +258,13 @@ @@ -249,10 +260,13 @@
#define SPKR_DRV_BOOST_SET BIT(2) #define SPKR_DRV_BOOST_SET BIT(2)
#define SPKR_DRV_CMFB_SET BIT(1) #define SPKR_DRV_CMFB_SET BIT(1)
#define SPKR_DRV_GAIN_SET BIT(0) #define SPKR_DRV_GAIN_SET BIT(0)
@@ -53,25 +62,53 @@ index 257f780..457b552 100644
#define CDC_A_SPKR_OCP_CTL (0xf1B4) #define CDC_A_SPKR_OCP_CTL (0xf1B4)
#define CDC_A_SPKR_PWRSTG_CTL (0xf1B5) #define CDC_A_SPKR_PWRSTG_CTL (0xf1B5)
#define SPKR_PWRSTG_CTL_DAC_EN_MASK BIT(0) #define SPKR_PWRSTG_CTL_DAC_EN_MASK BIT(0)
@@ -314,6 +326,7 @@ struct pm8916_wcd_analog_priv { @@ -314,6 +328,8 @@ struct pm8916_wcd_analog_priv {
bool audio_active; bool audio_active;
bool jack_inserted; bool jack_inserted;
bool s2_enabled; bool s2_enabled;
+ bool is_cajon; + bool is_cajon;
+ int jack_report;
}; };
static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" }; static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
@@ -435,6 +448,9 @@ static int pm8916_wcd_analog_enable_micbias2(struct snd_soc_dapm_widget *w, @@ -435,6 +451,36 @@ static int pm8916_wcd_analog_enable_micbias2(struct snd_soc_dapm_widget *w,
} }
+static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component, +static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component,
+ bool preserve_switch); + bool preserve_switch);
+static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, bool ins);
+
+static bool pm8916_mbhc_plug_present(struct snd_soc_component *component)
+{
+ int res2 = snd_soc_component_read(component, CDC_A_MBHC_RESULT_2);
+
+ if (res2 < 0)
+ return false;
+ return !(res2 & CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE);
+}
+
+static void pm8916_mbhc_disable_btn_bias(struct snd_soc_component *component)
+{
+ snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
+ CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK |
+ CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
+ 0);
+ if (!(snd_soc_component_read(component, CDC_A_MICB_2_EN) &
+ CDC_A_MICB_2_EN_ENABLE)) {
+ snd_soc_component_update_bits(component, CDC_A_MICB_1_INT_RBIAS,
+ MICB_1_INT_TX2_INT_RBIAS_EN_MASK,
+ 0);
+ snd_soc_component_update_bits(component, CDC_A_MICB_2_EN,
+ CDC_A_MICB_2_PULL_DOWN_EN_MASK,
+ CDC_A_MICB_2_PULL_DOWN_EN);
+ }
+}
+ +
static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *component) static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *component)
{ {
struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component); struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
@@ -446,7 +462,10 @@ static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *compo @@ -446,19 +492,31 @@ static int pm8916_wcd_analog_update_power_locked(struct snd_soc_component *compo
if (!ret) { if (!ret) {
priv->s2_enabled = true; priv->s2_enabled = true;
usleep_range(1000, 1500); usleep_range(1000, 1500);
@@ -80,10 +117,37 @@ index 257f780..457b552 100644
+ pm8916_wcd_analog_apply_defaults(component, true); + pm8916_wcd_analog_apply_defaults(component, true);
+ else + else
+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30); + snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
+ /*
+ * Keep digital MBHC debounce clock running so jack
+ * insertion/removal edges work cleanly even when playback starts idle.
+ */
+ snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
+ DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
+ DIG_CLK_CTL_D_MBHC_CLK_EN);
} else { } else {
dev_err(component->dev, "failed to enable vdd-cdc-tx-rx-cx (%d)\n", ret); dev_err(component->dev, "failed to enable vdd-cdc-tx-rx-cx (%d)\n", ret);
} }
@@ -698,37 +717,81 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w, } else if (!need_s2 && priv->s2_enabled) {
- snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
- CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK |
- CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
- 0);
+ pm8916_mbhc_disable_btn_bias(component);
+ /*
+ * Gate the 100uA button current source and s2 Linux vote while
+ * preserving MASTER_BIAS_CTL and DIG_CLK_CTL_D_MBHC_CLK_EN so the
+ * 3uA HPHL insertion comparator/debouncer keeps waking from idle.
+ */
snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
- 0);
- snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x00);
+ DIG_CLK_CTL_D_MBHC_CLK_EN);
+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
regulator_disable(priv->supplies[1].consumer);
priv->s2_enabled = false;
}
@@ -698,37 +756,81 @@ static int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
int event) int event)
{ {
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
@@ -182,7 +246,7 @@ index 257f780..457b552 100644
snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL, snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
SPKR_DAC_CTL_DAC_RESET_MASK, SPKR_DAC_CTL_DAC_RESET_MASK,
@@ -745,11 +808,15 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w, @@ -745,11 +847,15 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
int event) int event)
{ {
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
@@ -199,7 +263,7 @@ index 257f780..457b552 100644
break; break;
case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMU:
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL, snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
@@ -762,7 +829,114 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w, @@ -762,7 +868,114 @@ static int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
/* Delay to reduce ear turn off pop */ /* Delay to reduce ear turn off pop */
usleep_range(7000, 7100); usleep_range(7000, 7100);
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL, snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
@@ -315,7 +379,7 @@ index 257f780..457b552 100644
break; break;
} }
return 0; return 0;
@@ -787,10 +961,59 @@ static const struct reg_default wcd_reg_defaults_2_0[] = { @@ -787,10 +1000,59 @@ static const struct reg_default wcd_reg_defaults_2_0[] = {
{CDC_A_MASTER_BIAS_CTL, 0x30}, {CDC_A_MASTER_BIAS_CTL, 0x30},
}; };
@@ -376,7 +440,7 @@ index 257f780..457b552 100644
err = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); err = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
if (err != 0) { if (err != 0) {
@@ -806,16 +1029,17 @@ static int pm8916_wcd_analog_probe(struct snd_soc_component *component) @@ -806,16 +1068,17 @@ static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
snd_soc_component_set_drvdata(component, priv); snd_soc_component_set_drvdata(component, priv);
priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1); priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1);
priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE); priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE);
@@ -399,7 +463,45 @@ index 257f780..457b552 100644
priv->component = component; priv->component = component;
@@ -981,14 +1205,27 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = { @@ -824,24 +1087,21 @@ static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
RST_CTL_DIG_SW_RST_N_REMOVE_RESET);
pm8916_wcd_setup_mbhc(priv);
- usleep_range(1000, 1500);
+ usleep_range(5000, 6000);
- mutex_lock(&priv->power_lock);
- if (!priv->jack_inserted) {
- u32 det_ctl = snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1);
- u32 rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
-
- if (!(det_ctl & CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK) ||
- (rt_sts & MBHC_SWITCH_INT))
- priv->jack_inserted = true;
+ if (!priv->jack_gpio.report && pm8916_mbhc_plug_present(component)) {
+ pm8916_wcd_analog_switch_check(priv, true);
+ } else {
+ mutex_lock(&priv->power_lock);
+ if (!priv->jack_inserted && priv->mbhc_btn_enabled)
+ snd_soc_component_write(component, CDC_D_INT_EN_CLR,
+ MBHC_BUTTON_PRESS_DET |
+ MBHC_BUTTON_RELEASE_DET);
+ err = pm8916_wcd_analog_update_power_locked(component);
+ mutex_unlock(&priv->power_lock);
+ if (err)
+ dev_warn(component->dev, "failed initial wcd power sync (%d)\n", err);
}
- if (!priv->jack_inserted && priv->mbhc_btn_enabled)
- snd_soc_component_write(component, CDC_D_INT_EN_CLR,
- MBHC_BUTTON_PRESS_DET | MBHC_BUTTON_RELEASE_DET);
- err = pm8916_wcd_analog_update_power_locked(component);
- mutex_unlock(&priv->power_lock);
- if (err)
- dev_warn(component->dev, "failed initial wcd power sync (%d)\n", err);
return 0;
}
@@ -981,14 +1241,27 @@ static const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux), SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0), SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
@@ -433,6 +535,146 @@ index 257f780..457b552 100644
SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0, SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
spkr_switch, ARRAY_SIZE(spkr_switch)), spkr_switch, ARRAY_SIZE(spkr_switch)),
@@ -1094,6 +1367,14 @@ static int pm8916_wcd_analog_set_jack(struct snd_soc_component *component,
}
wcd->jack = jack;
+ if (jack && !wcd->jack_gpio.report) {
+ int initial_report;
+
+ mutex_lock(&wcd->power_lock);
+ initial_report = wcd->jack_inserted ? wcd->jack_report : 0;
+ mutex_unlock(&wcd->power_lock);
+ snd_soc_jack_report(jack, initial_report, hs_jack_mask);
+ }
return 0;
}
@@ -1164,9 +1445,14 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK,
(!ins << CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_SHIFT));
-
if (ins) { /* hs insertion */
bool micbias_enabled = false;
+ int rt_sts;
+
+ if (priv->mbhc_btn_enabled)
+ snd_soc_component_write(component, CDC_D_INT_EN_CLR,
+ MBHC_BUTTON_PRESS_DET |
+ MBHC_BUTTON_RELEASE_DET);
mutex_lock(&priv->power_lock);
priv->jack_inserted = true;
@@ -1176,33 +1462,56 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
DIG_CLK_CTL_D_MBHC_CLK_EN);
- if (priv->mbhc_btn_enabled)
- snd_soc_component_update_bits(component, CDC_D_INT_EN_SET,
- MBHC_BUTTON_PRESS_DET |
- MBHC_BUTTON_RELEASE_DET,
- MBHC_BUTTON_PRESS_DET |
- MBHC_BUTTON_RELEASE_DET);
if (snd_soc_component_read(component, CDC_A_MICB_2_EN) &
CDC_A_MICB_2_EN_ENABLE)
micbias_enabled = true;
+ snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
+ CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
+ 0);
pm8916_mbhc_configure_bias(priv, micbias_enabled);
+ msleep(25);
+ rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
+ if (rt_sts >= 0 && (rt_sts & MBHC_BUTTON_PRESS_DET)) {
+ msleep(75);
+ rt_sts = snd_soc_component_read(component, CDC_D_INT_RT_STS);
+ }
+
+ if (!priv->jack_gpio.report && !pm8916_mbhc_plug_present(component)) {
+ snd_soc_component_update_bits(component, CDC_A_MBHC_DET_CTL_1,
+ CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK,
+ CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION);
+ goto remove;
+ }
/*
- * if only a btn0 press event is receive just before
- * insert event then its a 3 pole headphone else if
- * both press and release event received then its
- * a headset.
+ * After MBHC FSM settling, a 4-pole headset pulls MIC above BTN0
+ * (no BTN_PRESS_DET) or releases BTN0; a 3-pole headphone shorts
+ * MIC to GND (BTN_PRESS_DET stays asserted), so keep 100uA ISRC
+ * and button IRQs disabled on 3-pole plugs.
*/
- if (priv->mbhc_btn0_released)
+ if (priv->mbhc_btn0_released ||
+ (rt_sts >= 0 && !(rt_sts & MBHC_BUTTON_PRESS_DET))) {
report = SND_JACK_HEADSET;
- else
+ if (priv->mbhc_btn_enabled)
+ snd_soc_component_update_bits(component, CDC_D_INT_EN_SET,
+ MBHC_BUTTON_PRESS_DET |
+ MBHC_BUTTON_RELEASE_DET,
+ MBHC_BUTTON_PRESS_DET |
+ MBHC_BUTTON_RELEASE_DET);
+ } else {
report = SND_JACK_HEADPHONE;
+ pm8916_mbhc_disable_btn_bias(component);
+ }
priv->detect_accessory_type = false;
+ mutex_lock(&priv->power_lock);
+ priv->jack_report = report;
+ mutex_unlock(&priv->power_lock);
} else { /* removal */
+remove:
report = 0;
priv->detect_accessory_type = true;
priv->mbhc_btn0_released = false;
@@ -1210,8 +1519,10 @@ static int pm8916_wcd_analog_switch_check(struct pm8916_wcd_analog_priv *priv, b
snd_soc_component_write(component, CDC_D_INT_EN_CLR,
MBHC_BUTTON_PRESS_DET |
MBHC_BUTTON_RELEASE_DET);
+ pm8916_mbhc_disable_btn_bias(component);
mutex_lock(&priv->power_lock);
priv->jack_inserted = false;
+ priv->jack_report = 0;
pm8916_wcd_analog_update_power_locked(component);
mutex_unlock(&priv->power_lock);
}
@@ -1223,15 +1534,22 @@ static irqreturn_t pm8916_mbhc_switch_irq_handler(int irq, void *arg)
{
struct pm8916_wcd_analog_priv *priv = arg;
struct snd_soc_component *component = priv->component;
- bool ins = false;
+ u32 det_ctl;
+ bool waiting_ins, phys_ins;
int report;
- if (snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1) &
- CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK)
- ins = true;
+ if (!component)
+ return IRQ_HANDLED;
+
+ det_ctl = snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1);
+ waiting_ins = !!(det_ctl & CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK);
+ phys_ins = pm8916_mbhc_plug_present(component);
+ if (phys_ins != waiting_ins)
+ return IRQ_HANDLED;
- report = pm8916_wcd_analog_switch_check(priv, ins);
- snd_soc_jack_report(priv->jack, report, hs_jack_mask);
+ report = pm8916_wcd_analog_switch_check(priv, phys_ins);
+ if (priv->jack)
+ snd_soc_jack_report(priv->jack, report, hs_jack_mask);
return IRQ_HANDLED;
}
diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c
index 81d1134..fc2520e 100644 index 81d1134..fc2520e 100644
--- a/sound/soc/codecs/msm8916-wcd-digital.c --- a/sound/soc/codecs/msm8916-wcd-digital.c
Binary file not shown.
+2 -1
View File
@@ -112,7 +112,8 @@ EOF
echo "[2m/5] Applying system-core keypad debouncer patch..." echo "[2m/5] Applying system-core keypad debouncer patch..."
patch -p1 < /bananarchy/patches/kernel/0014-input-core-keypad-debouncer.patch patch -p1 < /bananarchy/patches/kernel/0014-input-core-keypad-debouncer.patch
fi fi
if ! grep -q "msm8916_wcd_digital_force_sync_ctl" sound/soc/codecs/msm8916-wcd-digital.c 2>/dev/null; then if ! grep -q "msm8916_wcd_digital_force_sync_ctl" sound/soc/codecs/msm8916-wcd-digital.c 2>/dev/null || \
! grep -q "CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE" sound/soc/codecs/msm8916-wcd-analog.c 2>/dev/null; then
echo "[2n/5] Applying WCD digital 48 kHz interpolator and CAJON analog codec patch..." echo "[2n/5] Applying WCD digital 48 kHz interpolator and CAJON analog codec patch..."
patch -p1 < /bananarchy/patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch patch -p1 < /bananarchy/patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch
fi fi
+7 -7
View File
@@ -564,15 +564,15 @@ fi
echo "[check] Known-good flashable image set..." echo "[check] Known-good flashable image set..."
for pair in \ for pair in \
"6279d2b99600aee7751f501257ac48d485eaeee3b3f31c0f98a2b8522400bcd1 images/bananarchy-nokia-argon.img" \ "5df590a5c0a74a1594882e3d83a81c7691bdd3bfc396a320eb6e84e27f41b356 images/bananarchy-nokia-argon.img" \
"f067a130984d7fe6f79fdf46b3ff657bbe19fe12400e5db1e6ebd4cac24d1e6c images/bananarchy-nokia-beatles.img" \ "55cb9c17347735ff066f9a88f3b3e5c574281296ff78ac796cf79e2bbd0c2b81 images/bananarchy-nokia-beatles.img" \
"d32c7a38ac85df7faa71d2649d7c6ead1adcef0af39c3e91f08993965ddd44b9 images/boot-bananarchy-nokia-beatles.img" \ "4500324c8c875588b60063befb9f852069ce5a84b70c92025708c412ddc9a30e images/boot-bananarchy-nokia-beatles.img" \
"f13db705a714aaebd2d8fcc2e0f7266d0e40268c0a276208117dfdf9d8f45351 images/boot-lk2nd-nokia-beatles-display.img" \ "f13db705a714aaebd2d8fcc2e0f7266d0e40268c0a276208117dfdf9d8f45351 images/boot-lk2nd-nokia-beatles-display.img" \
"4d6733b633ca78ec7fe5de93e1ed0564a3aa116088aee3634147759a414af2c7 images/bananarchy-nokia-coconut.img" \ "5d629a64b6c82b0ce46af7135e2eff8620142043903c2e65f27a7163a9b21b32 images/bananarchy-nokia-coconut.img" \
"fdad08c8501de6b53c6ac76b7886849834fc8840ffec289b41a5c58e924ac803 images/boot-bananarchy-nokia-coconut.img" \ "c6c1d3fe3ad8eae39cc0ec6eeae14de136fd7524430976cb39ba79255a5dd9c2 images/boot-bananarchy-nokia-coconut.img" \
"9a5bd2da6cfd95c745d9c1acb2e3bc61afa339824810e3d160bf079e17b23192 images/boot-lk2nd-nokia-coconut-display.img" \ "9a5bd2da6cfd95c745d9c1acb2e3bc61afa339824810e3d160bf079e17b23192 images/boot-lk2nd-nokia-coconut-display.img" \
"068f4fa606bee9c63ac6044902e04a28d596b04edcd230d9703a2687951ee4bb images/bananarchy-nokia-sparkler.img" \ "efd541291277e702f67b18b9bf90a7571e459c87c124a705d6dad265dc032be8 images/bananarchy-nokia-sparkler.img" \
"026852df5acc871738322ff1de3febf91c097f0f1d745fbbe71f22661023b0e2 images/boot-bananarchy-nokia-sparkler.img" \ "ba922d89ad0a778086ef6a400d48b816125ad017d24d5bd81ad601d77293342e images/boot-bananarchy-nokia-sparkler.img" \
"120ade81bc5416263a1afd95a29981675358b98516e105e5ed611edf258a29f7 images/boot-lk2nd-nokia-sparkler-display.img"; do "120ade81bc5416263a1afd95a29981675358b98516e105e5ed611edf258a29f7 images/boot-lk2nd-nokia-sparkler-display.img"; do
set -- $pair set -- $pair
want=$1 want=$1
+77 -1
View File
@@ -200,11 +200,21 @@ def check_patch_0015():
"pm8916_wcd_analog_enable_hphr_dac", "pm8916_wcd_analog_enable_hphr_dac",
"pm8916_wcd_analog_enable_hph_pa", "pm8916_wcd_analog_enable_hph_pa",
"pm8916_wcd_analog_apply_defaults(component, true);", "pm8916_wcd_analog_apply_defaults(component, true);",
"CDC_A_MBHC_RESULT_2_SWCH_LEVEL_REMOVE",
"pm8916_mbhc_plug_present",
"DIG_CLK_CTL_D_MBHC_CLK_EN",
"CDC_A_MASTER_BIAS_CTL, 0x30",
"snd_soc_jack_report(jack, initial_report, hs_jack_mask);",
"phys_ins != waiting_ins",
] ]
for tok in required: for tok in required:
if tok not in txt: if tok not in txt:
return fail(f"0015 patch missing required token: {tok}") return fail(f"0015 patch missing required token: {tok}")
analog_diff = txt.split("diff --git a/sound/soc/codecs/msm8916-wcd-digital.c")[0]
if "+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x00);" in analog_diff:
return fail("0015 must not zero CDC_A_MASTER_BIAS_CTL on s2 idle gating")
if ".volatile_reg" in txt: if ".volatile_reg" in txt:
return fail("0015 patch must not set .volatile_reg on msm8916_codec_regmap_config") return fail("0015 patch must not set .volatile_reg on msm8916_codec_regmap_config")
@@ -313,10 +323,76 @@ def check_gain_staging():
return fail("sxmo_audio.sh missing PipeWire unity sync guard, @DEFAULT_AUDIO_SINK@, or sink wait") return fail("sxmo_audio.sh missing PipeWire unity sync guard, @DEFAULT_AUDIO_SINK@, or sink wait")
soundmon_txt = read_text(SOUNDMONITOR_C) soundmon_txt = read_text(SOUNDMONITOR_C)
for tok in ("has_internal_sink", "internal_synced"): for tok in (
"has_internal_sink",
"internal_synced",
"drain_jack_events",
"last_hp_plugged",
"iface=CARD,name='Headphone Jack'",
"iface=CARD,name='Mic Jack'",
):
if tok not in soundmon_txt: if tok not in soundmon_txt:
return fail(f"bananarchy-soundmonitor.c missing {tok}") return fail(f"bananarchy-soundmonitor.c missing {tok}")
gcc = shutil.which("gcc")
if gcc:
with tempfile.TemporaryDirectory(prefix="ba_soundmon_") as td:
exe = os.path.join(td, "bananarchy-soundmonitor")
bld = subprocess.run(
[
gcc, "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-I", os.path.dirname(SOUNDMONITOR_C),
SOUNDMONITOR_C, "-o", exe,
],
capture_output=True,
text=True,
)
if bld.returncode != 0:
return fail(f"host gcc build of bananarchy-soundmonitor.c failed:\n{bld.stderr}")
with tempfile.TemporaryDirectory(prefix="ba_audio_dev_") as td:
tmp_dir = os.path.join(td, "tmp")
cfg_dir = os.path.join(td, "cfg")
bin_dir = os.path.join(td, "bin")
os.makedirs(tmp_dir, exist_ok=True)
os.makedirs(cfg_dir, exist_ok=True)
os.makedirs(bin_dir, exist_ok=True)
mock_pactl = os.path.join(bin_dir, "pactl")
with open(mock_pactl, "w", encoding="utf-8") as handle:
handle.write("#!/bin/sh\nexit 0\n")
os.chmod(mock_pactl, 0o755)
patched_sh = os.path.join(td, "sxmo_audio.sh")
with open(patched_sh, "w", encoding="utf-8") as handle:
handle.write(audio_txt.replace("/tmp/", tmp_dir + "/"))
env = dict(os.environ)
env["XDG_CONFIG_HOME"] = td
env["CFG_DIR"] = cfg_dir
env["PATH"] = bin_dir + ":" + env.get("PATH", "")
# Rewrite CFG_DIR to cfg_dir explicitly via a symlink sxmo -> cfg_dir.
os.symlink(cfg_dir, os.path.join(td, "sxmo"))
with open(os.path.join(cfg_dir, "audio_out_device"), "w", encoding="utf-8") as handle:
handle.write("Headphones\n")
with open(os.path.join(cfg_dir, "audio_in_device"), "w", encoding="utf-8") as handle:
handle.write("Headset\n")
with open(os.path.join(tmp_dir, "sxmo_jack_plugged"), "w", encoding="utf-8") as handle:
handle.write("0\n")
r_out = subprocess.run(["sh", patched_sh, "device", "get"], env=env, capture_output=True, text=True, check=True)
r_in = subprocess.run(["sh", patched_sh, "device", "getinput"], env=env, capture_output=True, text=True, check=True)
if r_out.stdout.strip() != "Speaker" or r_in.stdout.strip() != "Mic1":
return fail(f"unplugged boot fallback failed: out={r_out.stdout!r} in={r_in.stdout!r}")
for p in ("sxmo_audio_out_device", "sxmo_audio_in_device"):
fp = os.path.join(tmp_dir, p)
if os.path.exists(fp):
os.unlink(fp)
with open(os.path.join(tmp_dir, "sxmo_jack_plugged"), "w", encoding="utf-8") as handle:
handle.write("1\n")
r_out2 = subprocess.run(["sh", patched_sh, "device", "get"], env=env, capture_output=True, text=True, check=True)
r_in2 = subprocess.run(["sh", patched_sh, "device", "getinput"], env=env, capture_output=True, text=True, check=True)
if r_out2.stdout.strip() != "Headphones" or r_in2.stdout.strip() != "Headset":
return fail(f"plugged boot preservation failed: out={r_out2.stdout!r} in={r_in2.stdout!r}")
probe_script = r""" probe_script = r"""
set -eu set -eu
. "%s" >/dev/null 2>&1 || true . "%s" >/dev/null 2>&1 || true
+10 -2
View File
@@ -351,16 +351,24 @@ def main():
knobs, _ = run_case(root, exe, {}) knobs, _ = run_case(root, exe, {})
try: try:
knobs.send("LID CLOSED") knobs.send("LID CLOSED")
if not knobs.wait_event("cmd fe 0 "): if not knobs.wait_event("frame lit=0"):
return not check(False, "runtime-knob daemon did not init the panel") return not check(False, "runtime-knob daemon did not init the panel")
before = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")]) before = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if before <= 0:
return not check(False, "runtime-knob daemon logged no init stream")
knobs.send("SET mux_closed_level 0") knobs.send("SET mux_closed_level 0")
if not knobs.wait_event("release"): if not knobs.wait_event("release"):
return not check(False, "SET polarity did not release the panel lines") return not check(False, "SET polarity did not release the panel lines")
deadline = time.time() + 5.0
after = before
while time.time() < deadline:
after = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if after > before and any(e == "gpio 0" for e in knobs.events()):
break
time.sleep(0.05)
if not check(any(e == "gpio 0" for e in knobs.events()), if not check(any(e == "gpio 0" for e in knobs.events()),
"SET mux_closed_level was ignored"): "SET mux_closed_level was ignored"):
return 1 return 1
after = len([e for e in knobs.events() if e.startswith("cmd fe 0 ")])
if after <= before: if after <= before:
return not check(False, "SET polarity did not re-init the panel") return not check(False, "SET polarity did not re-init the panel")
knobs.send("SET backend none") knobs.send("SET backend none")
+17 -23
View File
@@ -39,26 +39,17 @@ def setup_mocks(tmp: pathlib.Path) -> dict:
write_exec( write_exec(
mock_bin / "logger", mock_bin / "logger",
"#!/usr/bin/env python3\n" "#!/bin/sh\n"
"import os, pathlib, sys\n" "orig=\"$*\"\n"
"log_path = pathlib.Path(os.environ['MOCK_LOGGER_LOG'])\n" "while [ $# -gt 0 ]; do\n"
"args = sys.argv[1:]\n" " case \"$1\" in\n"
"i = 0\n" " -s) shift ;;\n"
"while i < len(args):\n" " -t|-p) [ $# -ge 2 ] || exit 1; shift 2 ;;\n"
" a = args[i]\n" " -*) echo \"logger: unrecognized option: $1\" >&2; exit 1 ;;\n"
" if a == '-s':\n" " *) break ;;\n"
" i += 1\n" " esac\n"
" elif a in ('-t', '-p'):\n" "done\n"
" if i + 1 >= len(args):\n" "printf '%s\\n' \"$orig\" >> \"$MOCK_LOGGER_LOG\"\n",
" sys.exit(1)\n"
" i += 2\n"
" elif a.startswith('-'):\n"
" sys.stderr.write(f'logger: unrecognized option: {a}\\n')\n"
" sys.exit(1)\n"
" else:\n"
" break\n"
"with log_path.open('a', encoding='utf-8') as f:\n"
" f.write(' '.join(args) + '\\n')\n",
) )
write_exec( write_exec(
@@ -251,7 +242,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
res, calls, elapsed, _ = run_filter(ctx, state_no_dnsmasq, ifn, act) res, calls, elapsed, _ = run_filter(ctx, state_no_dnsmasq, ifn, act)
assert res.returncode == 0, f"{ifn} {act} failed: {res.stderr}" assert res.returncode == 0, f"{ifn} {act} failed: {res.stderr}"
assert calls == [], f"unexpected dnsmasq calls when not running: {calls}" assert calls == [], f"unexpected dnsmasq calls when not running: {calls}"
assert elapsed < 1.0, f"expected fast exit, took {elapsed:.2f}s" assert elapsed < 3.0, f"expected fast exit, took {elapsed:.2f}s"
# 2. Wi-Fi early SLAAC RA before DHCPv4 completes, then dhcp4-change recovery # 2. Wi-Fi early SLAAC RA before DHCPv4 completes, then dhcp4-change recovery
ctx["nm_resolv"].write_text("# Generated by NetworkManager\nnameserver 127.0.0.1\n", encoding="utf-8") ctx["nm_resolv"].write_text("# Generated by NetworkManager\nnameserver 127.0.0.1\n", encoding="utf-8")
@@ -274,7 +265,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
} }
res, calls, elapsed, _ = run_filter(ctx, state_slaac_race, "wlan0", "up") res, calls, elapsed, _ = run_filter(ctx, state_slaac_race, "wlan0", "up")
assert res.returncode == 0, res.stderr assert res.returncode == 0, res.stderr
assert elapsed < 1.0, f"blocking sleep detected in 50-dns-filter.sh ({elapsed:.2f}s)" assert elapsed < 3.0, f"blocking sleep detected in 50-dns-filter.sh ({elapsed:.2f}s)"
assert "SetFilterA b false" in calls, f"early SLAAC RA must not block IPv4 A records: {calls}" assert "SetFilterA b false" in calls, f"early SLAAC RA must not block IPv4 A records: {calls}"
state_dhcp4_done = { state_dhcp4_done = {
@@ -293,7 +284,7 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
} }
res, calls, elapsed, _ = run_filter(ctx, state_dhcp4_done, "wlan0", "dhcp4-change") res, calls, elapsed, _ = run_filter(ctx, state_dhcp4_done, "wlan0", "dhcp4-change")
assert res.returncode == 0, res.stderr assert res.returncode == 0, res.stderr
assert elapsed < 1.0, f"dhcp4-change took too long ({elapsed:.2f}s)" assert elapsed < 3.0, f"dhcp4-change took too long ({elapsed:.2f}s)"
assert calls == ["SetFilterA b false", "SetFilterAAAA b true", "ClearCache"], f"unexpected dhcp4-change calls: {calls}" assert calls == ["SetFilterA b false", "SetFilterAAAA b true", "ClearCache"], f"unexpected dhcp4-change calls: {calls}"
# 3. True dual-stack (2001:db8::2/64 GUA + IPv4) # 3. True dual-stack (2001:db8::2/64 GUA + IPv4)
@@ -393,6 +384,9 @@ def test_runtime_scenarios(tmp: pathlib.Path) -> None:
def test_static_invariants() -> None: def test_static_invariants() -> None:
dns_filter = DNS_FILTER.read_text(encoding="utf-8")
assert "sleep " not in dns_filter, "50-dns-filter.sh must stay non-blocking"
dns_conf = DNS_CONF.read_text(encoding="utf-8") dns_conf = DNS_CONF.read_text(encoding="utf-8")
assert "dns=dnsmasq" in dns_conf and "rc-manager=file" in dns_conf, dns_conf assert "dns=dnsmasq" in dns_conf and "rc-manager=file" in dns_conf, dns_conf
+115 -33
View File
@@ -11,6 +11,8 @@
static volatile sig_atomic_t stop_requested = 0; static volatile sig_atomic_t stop_requested = 0;
static volatile pid_t pactl_pid = -1; static volatile pid_t pactl_pid = -1;
static int internal_synced = 0; static int internal_synced = 0;
static int last_hp_plugged = -1;
static int last_mic_plugged = -1;
static void handle_signal(int sig) static void handle_signal(int sig)
{ {
@@ -264,9 +266,25 @@ static void write_state_file(const char *path, const char *val)
fclose(f); fclose(f);
} }
static void sanitize_unplugged_boot_state(void)
{
char buf[64] = "";
write_state_file("/tmp/sxmo_jack_plugged", "0");
if(read_first_line("/tmp/sxmo_audio_out_device", buf, sizeof(buf)) == 0 &&
strcmp(buf, "Headphones") == 0) {
unlink("/tmp/sxmo_audio_out_device");
}
buf[0] = '\0';
if(read_first_line("/tmp/sxmo_audio_in_device", buf, sizeof(buf)) == 0 &&
strcmp(buf, "Headset") == 0) {
unlink("/tmp/sxmo_audio_in_device");
}
}
static void handle_jack_insert(int jack_fd) static void handle_jack_insert(int jack_fd)
{ {
char cur_out[64] = ""; char cur_out[64] = "";
int mic_plugged;
char *const get_argv[] = { char *const get_argv[] = {
(char *)"sxmo_audio.sh", (char *)"device", (char *)"get", NULL (char *)"sxmo_audio.sh", (char *)"device", (char *)"get", NULL
}; };
@@ -277,53 +295,90 @@ static void handle_jack_insert(int jack_fd)
} }
if(strcmp(cur_out, "Headphones") != 0) if(strcmp(cur_out, "Headphones") != 0)
write_state_file("/tmp/sxmo_prev_out_device", cur_out); write_state_file("/tmp/sxmo_prev_out_device", cur_out);
mic_plugged = query_ev_sw(jack_fd, SW_MICROPHONE_INSERT,
"iface=CARD,name='Mic Jack'");
write_state_file("/tmp/sxmo_jack_plugged", "1"); write_state_file("/tmp/sxmo_jack_plugged", "1");
if(query_ev_sw(jack_fd, SW_MICROPHONE_INSERT, "name='Mic Jack'")) { write_state_file("/tmp/sxmo_audio_in_device",
write_state_file("/tmp/sxmo_audio_in_device", "Headset"); mic_plugged ? "Headset" : "Mic1");
sxmo_audio_cmd("setinput", "Headset");
} else {
write_state_file("/tmp/sxmo_audio_in_device", "Mic1");
}
sxmo_audio_cmd("set", "Headphones"); sxmo_audio_cmd("set", "Headphones");
last_hp_plugged = 1;
last_mic_plugged = mic_plugged;
} }
static void handle_jack_remove(void) static void handle_jack_remove(void)
{ {
char incall[16] = ""; char incall[16] = "";
char bt_sink[128] = "";
const char *target = "Speaker"; const char *target = "Speaker";
write_state_file("/tmp/sxmo_jack_plugged", "0"); write_state_file("/tmp/sxmo_jack_plugged", "0");
write_state_file("/tmp/sxmo_audio_in_device", "Mic1"); write_state_file("/tmp/sxmo_audio_in_device", "Mic1");
sxmo_audio_cmd("setinput", "Mic1"); find_bt_sink(bt_sink, sizeof(bt_sink));
if(read_first_line("/tmp/sxmo_in_call", incall, sizeof(incall)) == 0 && if(bt_sink[0] != '\0') {
target = "Bluetooth";
} else if(read_first_line("/tmp/sxmo_in_call", incall, sizeof(incall)) == 0 &&
strcmp(incall, "1") == 0) { strcmp(incall, "1") == 0) {
target = "Earpiece"; target = "Earpiece";
} }
sxmo_audio_cmd("set", target); sxmo_audio_cmd("set", target);
last_hp_plugged = 0;
last_mic_plugged = 0;
}
static int drain_jack_events(int fd, int *saw_sw)
{
struct input_event ev;
ssize_t n;
while((n = read(fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) {
if(ev.type == EV_SW &&
(ev.code == SW_HEADPHONE_INSERT || ev.code == SW_MICROPHONE_INSERT)) {
*saw_sw = 1;
}
}
if(n < 0 && errno != EAGAIN && errno != EWOULDBLOCK)
return -1;
return 0;
} }
static void handle_jack_events(int *jack_fd_ptr) static void handle_jack_events(int *jack_fd_ptr)
{ {
int fd = *jack_fd_ptr; int fd = *jack_fd_ptr;
struct input_event ev; int saw_sw = 0;
ssize_t n; int hp;
while((n = read(fd, &ev, sizeof(ev))) == (ssize_t)sizeof(ev)) { int mic;
if(ev.type != EV_SW)
continue; if(drain_jack_events(fd, &saw_sw) < 0) {
if(ev.code == SW_HEADPHONE_INSERT && ev.value == 1) {
struct timespec ts = { 0, 100000000L };
nanosleep(&ts, NULL);
handle_jack_insert(fd);
} else if(ev.code == SW_HEADPHONE_INSERT && ev.value == 0) {
handle_jack_remove();
} else if(ev.code == SW_MICROPHONE_INSERT && ev.value == 1) {
sxmo_audio_cmd("setinput", "Headset");
} else if(ev.code == SW_MICROPHONE_INSERT && ev.value == 0) {
sxmo_audio_cmd("setinput", "Mic1");
}
}
if(n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
close(fd); close(fd);
*jack_fd_ptr = -1; *jack_fd_ptr = -1;
last_hp_plugged = -1;
last_mic_plugged = -1;
return;
}
if(!saw_sw)
return;
/* Coalesce 4-pole insert/remove SW_HEADPHONE + SW_MICROPHONE bounce pairs. */
{
struct timespec ts = { 0, 50000000L };
nanosleep(&ts, NULL);
}
if(drain_jack_events(fd, &saw_sw) < 0) {
close(fd);
*jack_fd_ptr = -1;
last_hp_plugged = -1;
last_mic_plugged = -1;
return;
}
hp = query_ev_sw(fd, SW_HEADPHONE_INSERT, "iface=CARD,name='Headphone Jack'");
mic = query_ev_sw(fd, SW_MICROPHONE_INSERT, "iface=CARD,name='Mic Jack'");
if(hp && last_hp_plugged != 1) {
handle_jack_insert(fd);
} else if(!hp && last_hp_plugged != 0) {
handle_jack_remove();
} else if(hp && mic != last_mic_plugged) {
last_mic_plugged = mic;
write_state_file("/tmp/sxmo_audio_in_device", mic ? "Headset" : "Mic1");
sxmo_audio_cmd("setinput", mic ? "Headset" : "Mic1");
} }
} }
@@ -369,6 +424,21 @@ static int start_pactl_subscribe(char *prev_bt, size_t prev_bt_len)
return pfd[0]; return pfd[0];
} }
static void sync_reopened_jack(int jack_fd)
{
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT,
"iface=CARD,name='Headphone Jack'")) {
if(last_hp_plugged != 1)
handle_jack_insert(jack_fd);
} else if(last_hp_plugged == 1) {
handle_jack_remove();
} else {
sanitize_unplugged_boot_state();
last_hp_plugged = 0;
last_mic_plugged = 0;
}
}
static void dispatch_pactl_line(const char *line, char *prev_bt, size_t prev_bt_len, static void dispatch_pactl_line(const char *line, char *prev_bt, size_t prev_bt_len,
int jack_fd) int jack_fd)
{ {
@@ -384,12 +454,17 @@ static void dispatch_pactl_line(const char *line, char *prev_bt, size_t prev_bt_
if(!internal_synced && has_internal_sink()) { if(!internal_synced && has_internal_sink()) {
internal_synced = 1; internal_synced = 1;
if(bt_sink[0] == '\0') { if(bt_sink[0] == '\0') {
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT, "name='Headphone Jack'")) if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT,
"iface=CARD,name='Headphone Jack'")) {
handle_jack_insert(jack_fd); handle_jack_insert(jack_fd);
else } else {
sanitize_unplugged_boot_state();
last_hp_plugged = 0;
last_mic_plugged = 0;
sxmo_audio_cmd("apply", NULL); sxmo_audio_cmd("apply", NULL);
} }
} }
}
{ {
char *const sb_argv[] = { char *const sb_argv[] = {
(char *)"sxmo_hook_statusbar.sh", (char *)"volume", NULL (char *)"sxmo_hook_statusbar.sh", (char *)"volume", NULL
@@ -457,11 +532,14 @@ int main(void)
inotify_fd = open_input_inotify(); inotify_fd = open_input_inotify();
jack_fd = open_jack_dev(jack_path, sizeof(jack_path)); jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT, "name='Headphone Jack'")) { if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT,
"iface=CARD,name='Headphone Jack'")) {
handle_jack_insert(jack_fd); handle_jack_insert(jack_fd);
} else { } else {
char bt_sink[128] = ""; char bt_sink[128] = "";
write_state_file("/tmp/sxmo_jack_plugged", "0"); sanitize_unplugged_boot_state();
last_hp_plugged = 0;
last_mic_plugged = 0;
find_bt_sink(bt_sink, sizeof(bt_sink)); find_bt_sink(bt_sink, sizeof(bt_sink));
if(bt_sink[0] != '\0') if(bt_sink[0] != '\0')
sxmo_audio_cmd("set", "Bluetooth"); sxmo_audio_cmd("set", "Bluetooth");
@@ -535,8 +613,7 @@ int main(void)
jack_fd = open_jack_dev(jack_path, sizeof(jack_path)); jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
if(jack_fd >= 0) { if(jack_fd >= 0) {
jack_retry_at = -1; jack_retry_at = -1;
if(query_ev_sw(jack_fd, SW_HEADPHONE_INSERT, "name='Headphone Jack'")) sync_reopened_jack(jack_fd);
handle_jack_insert(jack_fd);
} }
} }
@@ -588,7 +665,12 @@ int main(void)
now = now_ms(); now = now_ms();
if(jack_fd < 0 && jack_retry_at > 0 && now >= jack_retry_at) { if(jack_fd < 0 && jack_retry_at > 0 && now >= jack_retry_at) {
jack_fd = open_jack_dev(jack_path, sizeof(jack_path)); jack_fd = open_jack_dev(jack_path, sizeof(jack_path));
jack_retry_at = (jack_fd < 0) ? (now + 5000) : -1; if(jack_fd >= 0) {
jack_retry_at = -1;
sync_reopened_jack(jack_fd);
} else {
jack_retry_at = now + 5000;
}
} }
if(pactl_fd < 0 && pactl_retry_at > 0 && now >= pactl_retry_at) { if(pactl_fd < 0 && pactl_retry_at > 0 && now >= pactl_retry_at) {
pactl_fd = start_pactl_subscribe(prev_bt, sizeof(prev_bt)); pactl_fd = start_pactl_subscribe(prev_bt, sizeof(prev_bt));