Fix WCD 48 kHz interpolators, CAJON analog codec, PipeWire mono downmix, and gain staging for a1125 (ampere)

- Add patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch
  and rebuild kernel + audio codec modules (prebuilt/ + overlay/rootfs/)
  so REGCACHE_FLAT keeps 48 kHz POR interpolator/decimator defaults
  (RX1/2/3_B5_CTL=0x68, TX1/2_CLK_FS_CTL=0x03) and PM8909 CAJON_2_0
  analog defaults, non-boost Class-D SPK PA, HPH DAC/PA sequencing,
  EAR +6 dB headroom, and pm8909_s2 wakeup restore apply cleanly.
- Add WirePlumber create-item.lua item.features.mono = true support and
  PipeWire client drop-ins so Speaker and Earpiece present a positioned
  [ MONO ] PortConfig (0.5 * FL + 0.5 * FR with channelmix.normalize = true
  and triangular TPDF dithering) over 2 ch 48 kHz S16LE hardware while
  keeping Headphones and Bluetooth A2DP sinks stereo.
- Sync unity 100% PipeWire software sink volume when card0 is present
  and cap UCM2/plugin digital ALSA playback ceiling at <= 84 (0 dB).
- Add scripts/test-audio-quality.py wired into scripts/check-rebuild.sh,
  pin all 7 rebuilt a1125 (ampere) image SHA-256 hashes, and update
  CHANGELOG.md, MANUAL.md, and AGENTS.md.
This commit is contained in:
Luxferre committed 2026-11-23 19:53:06 +02:00
1 parent 1a229b0587
commit 4f73c28e5e
39 files changed
+1398 -55

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`), 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` `.reg_defaults` `0x050/0x070/0x090 = 0x68` + `hw_params` `RXn_B5_CTL` / `TXn_CLK_FS_CTL` `48 kHz` programming in `msm8916-wcd-digital.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 (`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.
+12 -7
View File
@@ -16,6 +16,11 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
Upcoming release build (`a1125` / `ampere` via `scripts/version.sh`) targeting **Nokia 8110 4G (`nokia-argon`)**, **Nokia 2720 Flip (`nokia-beatles`)**, **Nokia 800 Tough (`nokia-coconut`)**, and **Nokia 8000 4G (`nokia-sparkler`)** while keeping `a1120` (`cocojamboo`) as the current published release. Upcoming release build (`a1125` / `ampere` via `scripts/version.sh`) targeting **Nokia 8110 4G (`nokia-argon`)**, **Nokia 2720 Flip (`nokia-beatles`)**, **Nokia 800 Tough (`nokia-coconut`)**, and **Nokia 8000 4G (`nokia-sparkler`)** while keeping `a1120` (`cocojamboo`) as the current published release.
### 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 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()`) by adding complete `reg_defaults`, `valid_reg`/`volatile_reg` callbacks, non-zero POR writes on probe, and dynamic `hw_params` programming of `RX1/2/3_B5_CTL` (`(rx_fs_rate << 5) | BIT(3)`) and `TX1/2_CLK_FS_CTL` (`tx_fs_rate`); 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 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`.
- **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`, `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`) 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`.
### 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
- **QMI `WDS` subscription binding (`src/bananarchy-daemons/mm-wds-bind.c`, `libmm-wds-bind.so`, `/etc/init.d/modemmanager`)**: added a lightweight C `LD_PRELOAD` library preloaded by `ModemManager` and `msm-modem-uim-selection` (`run_wds_qmicli`) that hooks `qmi_device_allocate_client_finish()`, `qmi_client_wds_bind_mux_data_port()`, and `qmi_client_wds_bind_data_port()` to serialize `QMI_SUBSCRIPTION_TYPE_PRIMARY` (`1`, overrideable via `BANANARCHY_WDS_SUBSCRIPTION`) binding on every `QMI_SERVICE_WDS` (`1`) client both at allocation and after `Bind Mux Data Port` (`0x00A2`) / `Bind Data Port` (`0x0089`), preventing sticky KaiOS `SECONDARY` EFS `DDS` state (`QMI_DSD 0x004F == 2`) from resetting or routing `WDS Start Network` or `3gpp` profile lookups to the unprovisioned secondary subscription. - **QMI `WDS` subscription binding (`src/bananarchy-daemons/mm-wds-bind.c`, `libmm-wds-bind.so`, `/etc/init.d/modemmanager`)**: added a lightweight C `LD_PRELOAD` library preloaded by `ModemManager` and `msm-modem-uim-selection` (`run_wds_qmicli`) that hooks `qmi_device_allocate_client_finish()`, `qmi_client_wds_bind_mux_data_port()`, and `qmi_client_wds_bind_data_port()` to serialize `QMI_SUBSCRIPTION_TYPE_PRIMARY` (`1`, overrideable via `BANANARCHY_WDS_SUBSCRIPTION`) binding on every `QMI_SERVICE_WDS` (`1`) client both at allocation and after `Bind Mux Data Port` (`0x00A2`) / `Bind Data Port` (`0x0089`), preventing sticky KaiOS `SECONDARY` EFS `DDS` state (`QMI_DSD 0x004F == 2`) from resetting or routing `WDS Start Network` or `3gpp` profile lookups to the unprovisioned secondary subscription.
@@ -44,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`: `2ba4620680a981a87fa8adf7a2fb6ab98d932c73f9de9be1c69981edc096d2a8` - `images/bananarchy-nokia-argon.img`: `e15e0fff0e68d059000caf28f73a061170a9da62368531499c6d82b275821903`
- `images/bananarchy-nokia-beatles.img`: `23d1fdd6598bf0c5497b1e41a16888d966ad4ac3f4eee3aa04623b339c896c59` - `images/bananarchy-nokia-beatles.img`: `64fcf14fbe8863490d8a3b2838e66baa9e9b5712450526ca0b9e3bed5d724437`
- `images/boot-bananarchy-nokia-beatles.img`: `0459151f37c746963dc734539a4284a0524b1b8ad777cd8690a87f928d2cec58` - `images/boot-bananarchy-nokia-beatles.img`: `7c6aec20941b074cd36c856f62cb9b51b4ad2fe111c4f43f68844e07b828fb84`
- `images/bananarchy-nokia-coconut.img`: `1f47b0f6b96c1637e1febaa6b5d150c2dd661ba9d200286315cb0400ca61a6a0` - `images/bananarchy-nokia-coconut.img`: `753029acf664a78b6990d799c060ee29ccb8b464bc0a4c40c1909b1a1a5dbfcb`
- `images/boot-bananarchy-nokia-coconut.img`: `81695b3242403ebbd8631957a0ca67128b9791199e8121f58ed5e8f32ea2cc77` - `images/boot-bananarchy-nokia-coconut.img`: `948c44097e069624d60cf952de065961b38e9d45c77bcee958684b96d86dbb7c`
- `images/bananarchy-nokia-sparkler.img`: `7e6b7bdc1ac96f748c46c6fde0f7debe2ae5562d0c2feb1f5ddfc274fd22717e` - `images/bananarchy-nokia-sparkler.img`: `36e3a663de0d2586422aa5303a18ce2a70f05274d4d2ff7e377cf5dad243c777`
- `images/boot-bananarchy-nokia-sparkler.img`: `5fde23c229bcfcec276bfa064308a37736dc9f34bcb80c6f5b6c16400417adfa` - `images/boot-bananarchy-nokia-sparkler.img`: `f40757646fb9a5c0c489df370f59a97a5638d36bda037042a98be894b47bcf8e`
--- ---
+1 -1
View File
@@ -524,7 +524,7 @@ The `msm8905-cam` kernel module drives the rear 2MP GalaxyCore `GC2395` (TA-1048
### 5.2 Audio routing, music playback, and microphone recording ### 5.2 Audio routing, music playback, and microphone recording
Both the rear loudspeaker (`Speaker`, with boosted `RX3 Digital Volume` for loud, clear ringtones and media), the front earpiece speaker (`Earpiece`, boosted by +6 dB and selectable as a standard output device for any audio stream), and wired 3.5mm headphones (`Headphones`, automatically detected and routed on plug-in and restored to `Speaker` on unplug by `bananarchy-soundmonitor`), as well as the internal MEMS microphone (`Mic1`) and 3.5mm headset microphone (`Mic2`), are managed through PipeWire/WirePlumber and `sxmo_audio.sh` with linear `1%`–`100%` volume controls across all channels: Both the rear loudspeaker (`Speaker`, downmixed from stereo `FL`/`FR` via WirePlumber `item.features.mono` (`[ MONO ]` `PortConfig`) and client `channelmix.normalize = true` with triangular TPDF dithering and up to `0 dB` `RX3 Digital Volume` = `84` without digital overdrive), the front earpiece speaker (`Earpiece`, with `+6 dB` analog `EAR PA` headroom and unity `RX1 Digital Volume`), and wired 3.5mm headphones (`Headphones`, full `48 kHz` discrete stereo `FL`/`FR`, automatically detected and routed on plug-in and restored to `Speaker` on unplug by `bananarchy-soundmonitor`), as well as the internal MEMS microphone (`Mic1`) and 3.5mm headset microphone (`Mic2`), are managed through PipeWire/WirePlumber and `sxmo_audio.sh` with linear `1%`–`100%` hardware volume controls (keeping PipeWire's software sink at `100%` unity when ALSA `card0` is present):
- **Open an audio file, tracker module (`.mod`, `.xm`, `.it`, `.s3m`), monophonic ringtone (`.nrt`, `.rtttl`, `.rtx`, `.emy`, `.imy`), or folder in the native music player (`xmusic`)**: - **Open an audio file, tracker module (`.mod`, `.xm`, `.it`, `.s3m`), monophonic ringtone (`.nrt`, `.rtttl`, `.rtx`, `.emy`, `.imy`), or folder in the native music player (`xmusic`)**:
```bash ```bash
Binary file not shown.
@@ -0,0 +1,4 @@
stream.properties = {
channelmix.normalize = true
dither.method = "triangular"
}
@@ -0,0 +1,4 @@
stream.properties = {
channelmix.normalize = true
dither.method = "triangular"
}
@@ -29,6 +29,30 @@ monitor.alsa.rules = [
actions = { actions = {
update-props = { update-props = {
audio.format = "S16LE" audio.format = "S16LE"
audio.rate = 48000
dither.method = "triangular"
}
}
},
{
matches = [
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Earpiece__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Earpiece__sink"
}
]
actions = {
update-props = {
item.features.mono = true
channelmix.normalize = true
} }
} }
} }
@@ -29,6 +29,30 @@ monitor.alsa.rules = [
actions = { actions = {
update-props = { update-props = {
audio.format = "S16LE" audio.format = "S16LE"
audio.rate = 48000
dither.method = "triangular"
}
}
},
{
matches = [
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Earpiece__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Earpiece__sink"
}
]
actions = {
update-props = {
item.features.mono = true
channelmix.normalize = true
} }
} }
} }
@@ -29,6 +29,30 @@ monitor.alsa.rules = [
actions = { actions = {
update-props = { update-props = {
audio.format = "S16LE" audio.format = "S16LE"
audio.rate = 48000
dither.method = "triangular"
}
}
},
{
matches = [
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Earpiece__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Earpiece__sink"
}
]
actions = {
update-props = {
item.features.mono = true
channelmix.normalize = true
} }
} }
} }
+22 -10
View File
@@ -214,10 +214,11 @@ default_vol_for_dev() {
esac esac
} }
# Linear percentage (0..100%) to hardware digital volume register: # Linear percentage (0..100%) to hardware digital volume register (max 84 = 0 dB
# - Speaker (RX3 Digital Volume): 0 -> 0, 1..100 -> 56..88 (-28 dB .. +4 dB) # unity so the 16-bit WCD interpolator never applies digital overdrive):
# - Earpiece (RX1 Digital Volume): 0 -> 0, 1..100 -> 60..92 (-24 dB .. +8 dB) # - Speaker (RX3 Digital Volume): 0 -> 0, 1..100 -> 52..84 (-32 dB .. 0 dB)
# - Headphones (RX1 & RX2 Digital): 0 -> 0, 1..100 -> 52..84 (-32 dB .. 0 dB) # - Earpiece (RX1 Digital Volume): 0 -> 0, 1..100 -> 52..84 (-32 dB .. 0 dB)
# - Headphones (RX1 & RX2 Digital): 0 -> 0, 1..100 -> 51..83 (-33 dB .. -1 dB)
# - Microphone (TX1 Digital Volume): 0 -> 0, 1..100 -> 56..88 (-28 dB .. +4 dB) # - Microphone (TX1 Digital Volume): 0 -> 0, 1..100 -> 56..88 (-28 dB .. +4 dB)
# PipeWire software sink/source is kept at 100% (0.0 dB unity gain) when unmuted # PipeWire software sink/source is kept at 100% (0.0 dB unity gain) when unmuted
# so software cubic scaling never compounds with the linear hardware curve. # so software cubic scaling never compounds with the linear hardware curve.
@@ -230,13 +231,13 @@ pct_to_hw_out() {
fi fi
case "$dev" in case "$dev" in
Earpiece) Earpiece)
printf "%d" "$(( 60 + (pct * 32 + 50) / 100 ))"
;;
Headphones)
printf "%d" "$(( 52 + (pct * 32 + 50) / 100 ))" printf "%d" "$(( 52 + (pct * 32 + 50) / 100 ))"
;; ;;
Headphones)
printf "%d" "$(( 51 + (pct * 32 + 50) / 100 ))"
;;
*) *)
printf "%d" "$(( 56 + (pct * 32 + 50) / 100 ))" printf "%d" "$(( 52 + (pct * 32 + 50) / 100 ))"
;; ;;
esac esac
} }
@@ -543,13 +544,24 @@ EOF
if [ "$eff_pct" -gt 0 ]; then if [ "$eff_pct" -gt 0 ]; then
printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true
pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true
bananarchy_set_sink_volume "$eff_pct" bananarchy_sync_internal_pw_vol "$eff_pct"
else else
printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true
pactl set-sink-mute @DEFAULT_SINK@ 1 >/dev/null 2>&1 || true pactl set-sink-mute @DEFAULT_SINK@ 1 >/dev/null 2>&1 || true
fi fi
} }
# Bananarchy: keep PipeWire's software sink at 100% (0.0 dB unity) whenever ALSA
# card0 is present so software cubic scaling never compounds with WCD digital
# volume; only fall back to scaling PipeWire software volume when card0 is absent.
bananarchy_sync_internal_pw_vol() {
if [ -d /proc/asound/card0 ]; then
bananarchy_set_sink_volume 100
else
bananarchy_set_sink_volume "$1"
fi
}
# Bananarchy: the MSM8905 mainline kernel exposes no ALSA card yet, so the # Bananarchy: the MSM8905 mainline kernel exposes no ALSA card yet, so the
# amixer csets below are no-ops and PipeWire's null sink is the real output. # amixer csets below are no-ops and PipeWire's null sink is the real output.
# @DEFAULT_SINK@ does not resolve when wireplumber has no default configured # @DEFAULT_SINK@ does not resolve when wireplumber has no default configured
@@ -681,7 +693,7 @@ EOF
printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true printf "0\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true
pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true
fi fi
bananarchy_set_sink_volume "$eff_pct" bananarchy_sync_internal_pw_vol "$eff_pct"
else else
if [ "$pw_muted" != "1" ]; then if [ "$pw_muted" != "1" ]; then
printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true printf "1\n" > /tmp/sxmo_pw_sink_muted 2>/dev/null || true
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,7 +10,7 @@ SectionDevice."Earpiece" {
cset "name='RX1 MIX1 INP1' 'RX1'" cset "name='RX1 MIX1 INP1' 'RX1'"
cset "name='RDAC2 MUX' 'RX1'" cset "name='RDAC2 MUX' 'RX1'"
cset "name='EAR_S' 1" cset "name='EAR_S' 1"
cset "name='RX1 Digital Volume' 90" cset "name='RX1 Digital Volume' 84"
] ]
DisableSequence [ DisableSequence [
@@ -12,8 +12,8 @@ SectionDevice."Headphones" {
cset "name='RDAC2 MUX' 'RX2'" cset "name='RDAC2 MUX' 'RX2'"
cset "name='HPHL' 1" cset "name='HPHL' 1"
cset "name='HPHR' 1" cset "name='HPHR' 1"
cset "name='RX1 Digital Volume' 84" cset "name='RX1 Digital Volume' 80"
cset "name='RX2 Digital Volume' 84" cset "name='RX2 Digital Volume' 80"
] ]
DisableSequence [ DisableSequence [
@@ -9,7 +9,7 @@ SectionDevice."Speaker" {
EnableSequence [ EnableSequence [
cset "name='RX3 MIX1 INP1' 'RX1'" cset "name='RX3 MIX1 INP1' 'RX1'"
cset "name='SPK DAC Switch' 1" cset "name='SPK DAC Switch' 1"
cset "name='RX3 Digital Volume' 88" cset "name='RX3 Digital Volume' 80"
] ]
DisableSequence [ DisableSequence [
@@ -177,7 +177,7 @@ ring() {
if [ "${SXMO_RINGVOL:-100}" -le 0 ] || [ -z "${SXMO_RINGTONE:-}" ] || [ ! -f "$SXMO_RINGTONE" ]; then if [ "${SXMO_RINGVOL:-100}" -le 0 ] || [ -z "${SXMO_RINGTONE:-}" ] || [ ! -f "$SXMO_RINGTONE" ]; then
return 0 return 0
fi fi
ring_rx3=$(( 56 + (SXMO_RINGVOL * 32 + 50) / 100 )) ring_rx3=$(( 52 + (SXMO_RINGVOL * 32 + 50) / 100 ))
out_dev="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || printf 'Speaker')" out_dev="$(cat /tmp/sxmo_audio_out_device 2>/dev/null || printf 'Speaker')"
( (
@@ -190,7 +190,7 @@ ring() {
pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true pactl set-sink-mute @DEFAULT_SINK@ 0 >/dev/null 2>&1 || true
pactl set-sink-volume @DEFAULT_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true pactl set-sink-volume @DEFAULT_SINK@ "${SXMO_RINGVOL}%" >/dev/null 2>&1 || true
elif [ "$out_dev" = "Headphones" ]; then elif [ "$out_dev" = "Headphones" ]; then
ring_hp=$(( 52 + (SXMO_RINGVOL * 32 + 50) / 100 )) ring_hp=$(( 51 + (SXMO_RINGVOL * 32 + 50) / 100 ))
amixer -c 0 -s >/dev/null 2>&1 <<EOF || true amixer -c 0 -s >/dev/null 2>&1 <<EOF || true
cset "name='SPK DAC Switch'" 0 cset "name='SPK DAC Switch'" 0
cset "name='RX3 MIX1 INP1'" 0 cset "name='RX3 MIX1 INP1'" 0
@@ -0,0 +1,207 @@
-- WirePlumber
--
-- Copyright © 2021 Collabora Ltd.
-- @author Julian Bouzas <julian.bouzas@collabora.com>
--
-- SPDX-License-Identifier: MIT
-- create-item.lua script takes pipewire nodes and creates session items (a.k.a
-- linkable) objects out of them.
cutils = require ("common-utils")
log = Log.open_topic ("s-node")
items = {}
function configProperties (node)
local properties = node.properties
local media_class = properties ["media.class"] or ""
local factory_name = properties ["factory.name"] or ""
-- ensure a media.type is set
if not properties ["media.type"] then
properties ["media.type"] = "Unknown"
for _, i in ipairs ({ "Audio", "Video", "Midi" }) do
if media_class:find (i) then
properties ["media.type"] = i
break
end
end
end
properties ["item.node"] = node
properties ["item.node.direction"] =
cutils.mediaClassToDirection (media_class)
properties ["item.node.type"] =
media_class:find ("^Stream/") and "stream" or "device"
properties ["item.plugged.usec"] = GLib.get_monotonic_time ()
properties ["item.features.no-dsp"] =
Settings.get_boolean ("node.features.audio.no-dsp")
properties ["item.features.monitor"] =
Settings.get_boolean ("node.features.audio.monitor-ports")
properties ["item.features.control-port"] =
Settings.get_boolean ("node.features.audio.control-port")
properties ["item.features.mono"] =
(factory_name == "api.alsa.pcm.sink" or factory_name == "api.bluez5.a2dp.sink") and
(Settings.get_boolean ("node.features.audio.mono") or
cutils.parseBool (properties ["item.features.mono"]))
properties ["node.id"] = node ["bound-id"]
-- set the default media.role, if configured
-- avoid Settings.get_string(), as it will parse the default "null" value
-- as a string instead of returning nil
local default_role = Settings.get ("node.stream.default-media-role")
if default_role then
default_role = default_role:parse()
properties ["media.role"] = properties ["media.role"] or default_role
end
return properties
end
AsyncEventHook {
name = "node/create-item",
interests = {
EventInterest {
Constraint { "event.type", "=", "node-added" },
Constraint { "media.class", "#", "Stream/*", type = "pw-global" },
},
EventInterest {
Constraint { "event.type", "=", "node-added" },
Constraint { "media.class", "#", "Video/*", type = "pw-global" },
},
EventInterest {
Constraint { "event.type", "=", "node-added" },
Constraint { "media.class", "#", "Audio/*", type = "pw-global" },
Constraint { "wireplumber.is-virtual", "-", type = "pw" },
},
},
steps = {
start = {
next = "register",
execute = function (event, transition)
local node = event:get_subject ()
local id = node.id
local item
local item_type
local media_class = node.properties ['media.class']
if string.find (media_class, "Audio") then
item_type = "si-audio-adapter"
else
item_type = "si-node"
end
log:info (node, "creating item for node -> " .. item_type)
-- create item
item = SessionItem (item_type)
items [id] = item
-- configure item
if not item:configure (configProperties (node)) then
transition:return_error ("failed to configure item for node "
.. tostring (id))
return
end
-- activate item
item:activate (Features.ALL, function (_, e)
if e then
transition:return_error ("failed to activate item: "
.. tostring (e));
else
transition:advance ()
end
end)
end,
},
register = {
next = "none",
execute = function (event, transition)
local node = event:get_subject ()
local bound_id = node ["bound-id"]
local item = items [node.id]
log:info (item, "activated item for node " .. tostring (bound_id))
item:register ()
transition:advance ()
end,
},
},
}:register ()
SimpleEventHook {
name = "node/destroy-item",
interests = {
EventInterest {
Constraint { "event.type", "=", "node-removed" },
Constraint { "media.class", "#", "Stream/*", type = "pw-global" },
},
EventInterest {
Constraint { "event.type", "=", "node-removed" },
Constraint { "media.class", "#", "Video/*", type = "pw-global" },
},
EventInterest {
Constraint { "event.type", "=", "node-removed" },
Constraint { "media.class", "#", "Audio/*", type = "pw-global" },
Constraint { "wireplumber.is-virtual", "-", type = "pw" },
},
},
execute = function (event)
local node = event:get_subject ()
local id = node.id
if items [id] then
items [id]:remove ()
items [id] = nil
end
end
}:register ()
function reconfigureAudioAdapters ()
local ids = {}
-- Get the Id of all session items that are audio adapters
for id, item in pairs(items) do
local si_props = item.properties
if si_props ["item.factory.name"] == "si-audio-adapter" then
table.insert (ids, id)
end
end
-- Re-configure all audio adapters
for _, id in pairs (ids) do
local item = items[id]
local node = item:get_associated_proxy ("node")
log:info (item, "Started re-configuring audio adapter")
-- Remove the session item so that it is unlinked
items[id] = nil
item:remove()
-- Configure the session item
if not item:configure (configProperties (node)) then
log:warning (item, "Could not re-configure audio adapter")
goto skip_item
end
-- Activate the session item so that it is linked again
items[id] = item
item:activate (Features.ALL, function (si, e)
if e then
log:warning (si, "Could not re-activate audio adapter")
else
log:info (si, "Successfully re-activated audio adapter")
si:register ()
end
end)
::skip_item::
end
end
Settings.subscribe ("node.features.audio.*", function ()
reconfigureAudioAdapters ()
end)
@@ -29,6 +29,30 @@ monitor.alsa.rules = [
actions = { actions = {
update-props = { update-props = {
audio.format = "S16LE" audio.format = "S16LE"
audio.rate = 48000
dither.method = "triangular"
}
}
},
{
matches = [
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Speaker__sink"
},
{
node.name = "~alsa_output.platform-7702000.*.HiFi__Earpiece__sink"
},
{
node.name = "~alsa_output.platform-sound.*.HiFi__Earpiece__sink"
}
]
actions = {
update-props = {
item.features.mono = true
channelmix.normalize = true
} }
} }
} }
@@ -0,0 +1,654 @@
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -82,6 +82,7 @@
#define CDC_A_REVISION4 (0xf103)
#define CDC_A_PERPH_TYPE (0xf104)
#define CDC_A_PERPH_SUBTYPE (0xf105)
+#define CDC_A_PERPH_SUBTYPE_CAJON 0x0a
#define CDC_A_INT_RT_STS (0xf110)
#define CDC_A_INT_SET_TYPE (0xf111)
#define CDC_A_INT_POLARITY_HIGH (0xf112)
@@ -220,20 +221,28 @@
#define CDC_A_RX_HPH_BIAS_LDO_OCP (0xf195)
#define CDC_A_RX_HPH_BIAS_CNP (0xf196)
#define CDC_A_RX_HPH_CNP_EN (0xf197)
+#define CDC_A_RX_HPH_CNP_EN_PU_MASK BIT(3)
+#define CDC_A_RX_HPH_L_TEST (0xf19A)
#define CDC_A_RX_HPH_L_PA_DAC_CTL (0xf19B)
#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK BIT(1)
#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_RESET BIT(1)
+#define CDC_A_RX_HPH_R_TEST (0xf19C)
#define CDC_A_RX_HPH_R_PA_DAC_CTL (0xf19D)
#define RX_HPH_R_PA_DAC_CTL_DATA_RESET BIT(1)
#define RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK BIT(1)
+#define RX_HPH_TEST_PA_EN BIT(2)
+#define RX_HPH_TEST_CAJON_CFG BIT(7)
#define CDC_A_RX_EAR_CTL (0xf19E)
#define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK BIT(0)
#define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE BIT(0)
+#define RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK BIT(5)
+#define RX_EAR_CTL_PA_GAIN_POS_6_DB BIT(5)
#define RX_EAR_CTL_PA_EAR_PA_EN_MASK BIT(6)
#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE BIT(6)
#define RX_EAR_CTL_PA_SEL_MASK BIT(7)
#define RX_EAR_CTL_PA_SEL BIT(7)
+#define CDC_A_RX_EAR_STATUS (0xf1A1)
#define CDC_A_SPKR_DAC_CTL (0xf1B0)
#define SPKR_DAC_CTL_DAC_RESET_MASK BIT(4)
@@ -249,10 +258,13 @@
#define SPKR_DRV_BOOST_SET BIT(2)
#define SPKR_DRV_CMFB_SET BIT(1)
#define SPKR_DRV_GAIN_SET BIT(0)
+#define SPKR_DRV_CTL_NO_BOOST_VAL (SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
+ SPKR_DRV_FW_EN | SPKR_DRV_GAIN_SET)
#define SPKR_DRV_CTL_DEF_VAL (SPKR_DRV_CLASSD_PA_EN_ENABLE | \
SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
SPKR_DRV_FW_EN | SPKR_DRV_BOOST_SET | \
SPKR_DRV_CMFB_SET | SPKR_DRV_GAIN_SET)
+#define CDC_A_SPKR_ANA_BIAS_SET (0xf1B3)
#define CDC_A_SPKR_OCP_CTL (0xf1B4)
#define CDC_A_SPKR_PWRSTG_CTL (0xf1B5)
#define SPKR_PWRSTG_CTL_DAC_EN_MASK BIT(0)
@@ -314,6 +326,7 @@
bool audio_active;
bool jack_inserted;
bool s2_enabled;
+ bool is_cajon;
};
static const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
@@ -435,6 +448,9 @@
}
+static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component,
+ bool preserve_switch);
+
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);
@@ -446,7 +462,10 @@
if (!ret) {
priv->s2_enabled = true;
usleep_range(1000, 1500);
- snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
+ if (priv->is_cajon)
+ pm8916_wcd_analog_apply_defaults(component, true);
+ else
+ snd_soc_component_write(component, CDC_A_MASTER_BIAS_CTL, 0x30);
} else {
dev_err(component->dev, "failed to enable vdd-cdc-tx-rx-cx (%d)\n", ret);
}
@@ -698,37 +717,81 @@
int event)
{
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
- snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
- SPKR_PWRSTG_CTL_DAC_EN_MASK |
- SPKR_PWRSTG_CTL_BBM_MASK |
- SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
- SPKR_PWRSTG_CTL_CLAMP_EN_MASK,
- SPKR_PWRSTG_CTL_DAC_EN|
- SPKR_PWRSTG_CTL_BBM_EN |
- SPKR_PWRSTG_CTL_HBRDGE_EN |
- SPKR_PWRSTG_CTL_CLAMP_EN);
+ if (priv->is_cajon) {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_DAC_EN_MASK,
+ SPKR_PWRSTG_CTL_DAC_EN);
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
+ SPKR_DAC_CTL_DAC_RESET_MASK,
+ SPKR_DAC_CTL_DAC_RESET_MASK);
+ usleep_range(1000, 1100);
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_MASK,
+ SPKR_PWRSTG_CTL_BBM_EN |
+ SPKR_PWRSTG_CTL_HBRDGE_EN |
+ SPKR_PWRSTG_CTL_CLAMP_EN);
+ } else {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_DAC_EN_MASK |
+ SPKR_PWRSTG_CTL_BBM_MASK |
+ SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
+ SPKR_PWRSTG_CTL_CLAMP_EN_MASK,
+ SPKR_PWRSTG_CTL_DAC_EN |
+ SPKR_PWRSTG_CTL_BBM_EN |
+ SPKR_PWRSTG_CTL_HBRDGE_EN |
+ SPKR_PWRSTG_CTL_CLAMP_EN);
+ }
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK,
RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE);
break;
case SND_SOC_DAPM_POST_PMU:
- snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
- SPKR_DRV_CTL_DEF_MASK,
- SPKR_DRV_CTL_DEF_VAL);
+ if (priv->is_cajon) {
+ usleep_range(1000, 1100);
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
+ SPKR_DAC_CTL_DAC_RESET_MASK,
+ SPKR_DAC_CTL_DAC_RESET_NORMAL);
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
+ SPKR_DRV_CTL_DEF_MASK &
+ ~SPKR_DRV_CLASSD_PA_EN_MASK,
+ SPKR_DRV_CTL_NO_BOOST_VAL);
+ } else {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
+ SPKR_DRV_CTL_DEF_MASK,
+ SPKR_DRV_CTL_DEF_VAL);
+ }
snd_soc_component_update_bits(component, w->reg,
SPKR_DRV_CLASSD_PA_EN_MASK,
SPKR_DRV_CLASSD_PA_EN_ENABLE);
break;
+ case SND_SOC_DAPM_PRE_PMD:
+ if (priv->is_cajon) {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
+ SPKR_DAC_CTL_DAC_RESET_MASK,
+ SPKR_DAC_CTL_DAC_RESET_MASK);
+ snd_soc_component_update_bits(component, w->reg,
+ SPKR_DRV_CLASSD_PA_EN_MASK, 0);
+ }
+ break;
case SND_SOC_DAPM_POST_PMD:
- snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
- SPKR_PWRSTG_CTL_DAC_EN_MASK|
- SPKR_PWRSTG_CTL_BBM_MASK |
- SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
- SPKR_PWRSTG_CTL_CLAMP_EN_MASK, 0);
+ if (priv->is_cajon) {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_MASK, 0);
+ usleep_range(1000, 1100);
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_DAC_EN_MASK, 0);
+ } else {
+ snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
+ SPKR_PWRSTG_CTL_DAC_EN_MASK |
+ SPKR_PWRSTG_CTL_BBM_MASK |
+ SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
+ SPKR_PWRSTG_CTL_CLAMP_EN_MASK, 0);
+ }
snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
SPKR_DAC_CTL_DAC_RESET_MASK,
@@ -745,11 +808,15 @@
int event)
{
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
- RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
+ RX_EAR_CTL_PA_SEL_MASK |
+ (priv->is_cajon ? RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK : 0),
+ RX_EAR_CTL_PA_SEL |
+ (priv->is_cajon ? RX_EAR_CTL_PA_GAIN_POS_6_DB : 0));
break;
case SND_SOC_DAPM_POST_PMU:
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
@@ -762,7 +829,114 @@
/* Delay to reduce ear turn off pop */
usleep_range(7000, 7100);
snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
- RX_EAR_CTL_PA_SEL_MASK, 0);
+ RX_EAR_CTL_PA_SEL_MASK |
+ (priv->is_cajon ? RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK : 0),
+ 0);
+ break;
+ }
+ return 0;
+}
+
+static int pm8916_wcd_analog_enable_hphl_dac(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol,
+ int event)
+{
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ if (priv->is_cajon) {
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_CNP_EN,
+ CDC_A_RX_HPH_CNP_EN_PU_MASK,
+ CDC_A_RX_HPH_CNP_EN_PU_MASK);
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_TEST,
+ RX_HPH_TEST_CAJON_CFG,
+ RX_HPH_TEST_CAJON_CFG);
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_TEST,
+ RX_HPH_TEST_CAJON_CFG,
+ RX_HPH_TEST_CAJON_CFG);
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_CNP_EN,
+ CDC_A_RX_HPH_CNP_EN_PU_MASK, 0);
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+ RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK,
+ RX_EAR_CTL_PA_GAIN_POS_6_DB);
+ snd_soc_component_update_bits(component, CDC_A_NCP_VCTRL,
+ 0x07, 0x07);
+ }
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_PA_DAC_CTL,
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK,
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_RESET);
+ break;
+ case SND_SOC_DAPM_POST_PMU:
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_L_PA_DAC_CTL,
+ RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK, 0);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ if (priv->is_cajon) {
+ snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
+ RX_EAR_CTL_PA_GAIN_POS_6_DB_MASK, 0);
+ snd_soc_component_update_bits(component, CDC_A_NCP_VCTRL,
+ 0x07, 0x04);
+ }
+ break;
+ }
+ return 0;
+}
+
+static int pm8916_wcd_analog_enable_hphr_dac(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol,
+ int event)
+{
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_PA_DAC_CTL,
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK,
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET);
+ break;
+ case SND_SOC_DAPM_POST_PMU:
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_R_PA_DAC_CTL,
+ RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK, 0);
+ break;
+ }
+ return 0;
+}
+
+static int pm8916_wcd_analog_enable_hph_pa(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol,
+ int event)
+{
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
+ unsigned int test_reg = (w->shift == 5) ? CDC_A_RX_HPH_L_TEST : CDC_A_RX_HPH_R_TEST;
+
+ if (!priv->is_cajon)
+ return 0;
+
+ switch (event) {
+ case SND_SOC_DAPM_PRE_PMU:
+ snd_soc_component_update_bits(component, CDC_A_NCP_FBCTRL,
+ CDC_A_NCP_FBCTRL_FB_CLK_INV_MASK,
+ CDC_A_NCP_FBCTRL_FB_CLK_INV);
+ break;
+ case SND_SOC_DAPM_POST_PMU:
+ usleep_range(7000, 7100);
+ snd_soc_component_update_bits(component, test_reg,
+ RX_HPH_TEST_PA_EN,
+ RX_HPH_TEST_PA_EN);
+ break;
+ case SND_SOC_DAPM_PRE_PMD:
+ snd_soc_component_update_bits(component, test_reg,
+ RX_HPH_TEST_PA_EN, 0);
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_BIAS_CNP,
+ 0xF0, 0x30);
+ break;
+ case SND_SOC_DAPM_POST_PMD:
+ snd_soc_component_update_bits(component, CDC_A_RX_HPH_BIAS_CNP,
+ 0xF0, 0x20);
+ usleep_range(5000, 5200);
break;
}
return 0;
@@ -787,10 +961,59 @@
{CDC_A_MASTER_BIAS_CTL, 0x30},
};
+static const struct reg_default wcd_reg_defaults_cajon_2_0[] = {
+ {CDC_A_RX_COM_OCP_CTL, 0xD1},
+ {CDC_A_RX_COM_OCP_COUNT, 0xFF},
+ {CDC_D_SEC_ACCESS, 0xA5},
+ {CDC_D_PERPH_RESET_CTL3, 0x0F},
+ {CDC_A_SEC_ACCESS, 0xA5},
+ {CDC_A_PERPH_RESET_CTL3, 0x0F},
+ {CDC_A_TX_1_2_OPAMP_BIAS, 0x4C},
+ {CDC_A_NCP_FBCTRL, 0xA8},
+ {CDC_A_NCP_VCTRL, 0xA4},
+ {CDC_A_RX_HPH_BIAS_PA, 0xFA},
+ {CDC_A_SPKR_ANA_BIAS_SET, 0x41},
+ {CDC_A_SPKR_DRV_CTL, 0x69},
+ {CDC_A_SPKR_DRV_DBG, 0x01},
+ {CDC_A_SPKR_OCP_CTL, 0xE1},
+ {CDC_A_SPKR_DAC_CTL, 0x03},
+ {CDC_A_RX_EAR_STATUS, 0x10},
+ {CDC_A_MASTER_BIAS_CTL, 0x30},
+};
+
+static void pm8916_wcd_analog_apply_defaults(struct snd_soc_component *component,
+ bool preserve_switch)
+{
+ struct pm8916_wcd_analog_priv *priv = snd_soc_component_get_drvdata(component);
+ const struct reg_default *defs = priv->is_cajon ?
+ wcd_reg_defaults_cajon_2_0 : wcd_reg_defaults_2_0;
+ size_t count = priv->is_cajon ?
+ ARRAY_SIZE(wcd_reg_defaults_cajon_2_0) :
+ ARRAY_SIZE(wcd_reg_defaults_2_0);
+ size_t i;
+
+ for (i = 0; i < count; i++) {
+ if (preserve_switch && defs[i].reg == CDC_A_SPKR_DAC_CTL) {
+ snd_soc_component_update_bits(component, defs[i].reg,
+ 0x7F, defs[i].def & 0x7F);
+ } else if (preserve_switch && defs[i].reg == CDC_A_SPKR_DRV_CTL) {
+ snd_soc_component_update_bits(component, defs[i].reg,
+ SPKR_DRV_CTL_DEF_MASK &
+ ~SPKR_DRV_CLASSD_PA_EN_MASK &
+ ~SPKR_DRV_CAL_EN,
+ defs[i].def &
+ ~SPKR_DRV_CLASSD_PA_EN_MASK &
+ ~SPKR_DRV_CAL_EN);
+ } else {
+ snd_soc_component_write(component, defs[i].reg, defs[i].def);
+ }
+ }
+}
+
static int pm8916_wcd_analog_probe(struct snd_soc_component *component)
{
struct pm8916_wcd_analog_priv *priv = dev_get_drvdata(component->dev);
- int err, reg;
+ int err;
err = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
if (err != 0) {
@@ -806,16 +1029,17 @@
snd_soc_component_set_drvdata(component, priv);
priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1);
priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE);
+ priv->is_cajon = (snd_soc_component_read(component, CDC_A_PERPH_SUBTYPE) ==
+ CDC_A_PERPH_SUBTYPE_CAJON);
- dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d\n",
- priv->pmic_rev, priv->codec_version);
+ dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d%s\n",
+ priv->pmic_rev, priv->codec_version,
+ priv->is_cajon ? " (CAJON)" : "");
snd_soc_component_write(component, CDC_D_PERPH_RESET_CTL4, 0x01);
snd_soc_component_write(component, CDC_A_PERPH_RESET_CTL4, 0x01);
- for (reg = 0; reg < ARRAY_SIZE(wcd_reg_defaults_2_0); reg++)
- snd_soc_component_write(component, wcd_reg_defaults_2_0[reg].reg,
- wcd_reg_defaults_2_0[reg].def);
+ pm8916_wcd_analog_apply_defaults(component, false);
priv->component = component;
@@ -981,14 +1205,27 @@
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_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
+ SND_SOC_DAPM_PGA_E("HPHL PA", CDC_A_RX_HPH_CNP_EN,
+ 5, 0, NULL, 0,
+ pm8916_wcd_analog_enable_hph_pa,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
- SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
- 0),
- SND_SOC_DAPM_PGA("HPHR PA", CDC_A_RX_HPH_CNP_EN, 4, 0, NULL, 0),
+ SND_SOC_DAPM_MIXER_E("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL,
+ 3, 0, NULL, 0,
+ pm8916_wcd_analog_enable_hphl_dac,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+ SND_SOC_DAPM_POST_PMD),
+ SND_SOC_DAPM_PGA_E("HPHR PA", CDC_A_RX_HPH_CNP_EN,
+ 4, 0, NULL, 0,
+ pm8916_wcd_analog_enable_hph_pa,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_MUX("HPHR", SND_SOC_NOPM, 0, 0, &hphr_mux),
- SND_SOC_DAPM_MIXER("HPHR DAC", CDC_A_RX_HPH_R_PA_DAC_CTL, 3, 0, NULL,
- 0),
+ SND_SOC_DAPM_MIXER_E("HPHR DAC", CDC_A_RX_HPH_R_PA_DAC_CTL,
+ 3, 0, NULL, 0,
+ pm8916_wcd_analog_enable_hphr_dac,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
spkr_switch, ARRAY_SIZE(spkr_switch)),
--- a/sound/soc/codecs/msm8916-wcd-digital.c
+++ b/sound/soc/codecs/msm8916-wcd-digital.c
@@ -85,6 +85,9 @@
#define LPASS_CDC_RX1_B5_CTL (0x050)
#define LPASS_CDC_RX2_B5_CTL (0x070)
#define LPASS_CDC_RX3_B5_CTL (0x090)
+#define RXn_B5_CTL_INTERP_FS_RATE_MASK GENMASK(7, 5)
+#define RXn_B5_CTL_INTERP_FS_RATE_SHIFT 5
+#define RXn_B5_CTL_INTERP_HALFBAND_EN BIT(3)
#define LPASS_CDC_RX1_B6_CTL (0x054)
#define RXn_B6_CTL_MUTE_MASK BIT(0)
#define RXn_B6_CTL_MUTE_ENABLE BIT(0)
@@ -172,6 +175,7 @@
#define LPASS_CDC_TX2_MUX_CTL (0x2AC)
#define LPASS_CDC_TX1_CLK_FS_CTL (0x290)
#define LPASS_CDC_TX2_CLK_FS_CTL (0x2B0)
+#define TXn_CLK_FS_CTL_FS_RATE_MASK GENMASK(2, 0)
#define LPASS_CDC_TX1_DMIC_CTL (0x294)
#define LPASS_CDC_TX2_DMIC_CTL (0x2B4)
#define TXN_DMIC_CTL_CLK_SEL_MASK GENMASK(2, 0)
@@ -895,10 +899,29 @@
case SNDRV_PCM_STREAM_CAPTURE:
snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_TX_I2S_CTL,
TX_I2S_CTL_TX_I2S_FS_RATE_MASK, tx_fs_rate);
+ snd_soc_component_update_bits(dai->component, LPASS_CDC_TX1_CLK_FS_CTL,
+ TXn_CLK_FS_CTL_FS_RATE_MASK, tx_fs_rate);
+ snd_soc_component_update_bits(dai->component, LPASS_CDC_TX2_CLK_FS_CTL,
+ TXn_CLK_FS_CTL_FS_RATE_MASK, tx_fs_rate);
break;
case SNDRV_PCM_STREAM_PLAYBACK:
snd_soc_component_update_bits(dai->component, LPASS_CDC_CLK_RX_I2S_CTL,
RX_I2S_CTL_RX_I2S_FS_RATE_MASK, rx_fs_rate);
+ snd_soc_component_update_bits(dai->component, LPASS_CDC_RX1_B5_CTL,
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
+ snd_soc_component_update_bits(dai->component, LPASS_CDC_RX2_B5_CTL,
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
+ snd_soc_component_update_bits(dai->component, LPASS_CDC_RX3_B5_CTL,
+ RXn_B5_CTL_INTERP_FS_RATE_MASK |
+ RXn_B5_CTL_INTERP_HALFBAND_EN,
+ (rx_fs_rate << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) |
+ RXn_B5_CTL_INTERP_HALFBAND_EN);
break;
default:
return -EINVAL;
@@ -1159,11 +1182,145 @@
.endianness = 1,
};
+static const struct reg_default msm8916_wcd_digital_reg_defaults[] = {
+ { LPASS_CDC_CLK_DMIC_B1_CTL, 0x00 },
+ { LPASS_CDC_CLK_RX_I2S_CTL, 0x13 },
+ { LPASS_CDC_CLK_TX_I2S_CTL, 0x13 },
+ { LPASS_CDC_CLK_TX_CLK_EN_B1_CTL, 0x00 },
+ { LPASS_CDC_CLK_OTHR_CTL, 0x04 },
+ { LPASS_CDC_CLK_RX_B1_CTL, 0x00 },
+ { LPASS_CDC_CLK_MCLK_CTL, 0x00 },
+ { LPASS_CDC_CLK_PDM_CTL, 0x00 },
+ { LPASS_CDC_CLK_SD_CTL, 0x00 },
+ { LPASS_CDC_RX1_B1_CTL, 0x00 },
+ { LPASS_CDC_RX1_B2_CTL, 0x00 },
+ { LPASS_CDC_RX1_B3_CTL, 0x00 },
+ { LPASS_CDC_RX1_B4_CTL, 0x00 },
+ { LPASS_CDC_RX1_B5_CTL, 0x68 },
+ { LPASS_CDC_RX1_B6_CTL, 0x00 },
+ { LPASS_CDC_RX1_VOL_CTL_B1_CTL, 0x00 },
+ { LPASS_CDC_RX1_VOL_CTL_B2_CTL, 0x00 },
+ { LPASS_CDC_RX2_B1_CTL, 0x00 },
+ { LPASS_CDC_RX2_B2_CTL, 0x00 },
+ { LPASS_CDC_RX2_B3_CTL, 0x00 },
+ { LPASS_CDC_RX2_B4_CTL, 0x00 },
+ { LPASS_CDC_RX2_B5_CTL, 0x68 },
+ { LPASS_CDC_RX2_B6_CTL, 0x00 },
+ { LPASS_CDC_RX2_VOL_CTL_B1_CTL, 0x00 },
+ { LPASS_CDC_RX2_VOL_CTL_B2_CTL, 0x00 },
+ { LPASS_CDC_RX3_B1_CTL, 0x00 },
+ { LPASS_CDC_RX3_B2_CTL, 0x00 },
+ { LPASS_CDC_RX3_B3_CTL, 0x00 },
+ { LPASS_CDC_RX3_B4_CTL, 0x00 },
+ { LPASS_CDC_RX3_B5_CTL, 0x68 },
+ { LPASS_CDC_RX3_B6_CTL, 0x00 },
+ { LPASS_CDC_RX3_VOL_CTL_B1_CTL, 0x00 },
+ { LPASS_CDC_RX3_VOL_CTL_B2_CTL, 0x00 },
+ { LPASS_CDC_TOP_GAIN_UPDATE, 0x00 },
+ { LPASS_CDC_TOP_CTL, 0x01 },
+ { LPASS_CDC_DEBUG_DESER1_CTL, 0x00 },
+ { LPASS_CDC_DEBUG_DESER2_CTL, 0x00 },
+ { LPASS_CDC_DEBUG_B1_CTL_CFG, 0x00 },
+ { LPASS_CDC_DEBUG_B2_CTL_CFG, 0x00 },
+ { LPASS_CDC_DEBUG_B3_CTL_CFG, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B1_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B2_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B3_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B4_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B5_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B6_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B7_CTL, 0x00 },
+ { LPASS_CDC_IIR1_GAIN_B8_CTL, 0x00 },
+ { LPASS_CDC_IIR1_CTL, 0x40 },
+ { LPASS_CDC_IIR1_GAIN_TIMER_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B1_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B2_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B3_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B4_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B5_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B6_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B7_CTL, 0x00 },
+ { LPASS_CDC_IIR2_GAIN_B8_CTL, 0x00 },
+ { LPASS_CDC_IIR2_CTL, 0x40 },
+ { LPASS_CDC_IIR2_GAIN_TIMER_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX1_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX1_B2_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX1_B3_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX2_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX2_B2_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX2_B3_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX3_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_RX3_B2_CTL, 0x00 },
+ { LPASS_CDC_CONN_TX_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ1_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ1_B2_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ1_B3_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ1_B4_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ2_B1_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ2_B2_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ2_B3_CTL, 0x00 },
+ { LPASS_CDC_CONN_EQ2_B4_CTL, 0x00 },
+ { LPASS_CDC_CONN_TX_I2S_SD1_CTL, 0x00 },
+ { LPASS_CDC_TX1_VOL_CTL_TIMER, 0x00 },
+ { LPASS_CDC_TX1_VOL_CTL_GAIN, 0x00 },
+ { LPASS_CDC_TX1_VOL_CTL_CFG, 0x00 },
+ { LPASS_CDC_TX1_MUX_CTL, 0x00 },
+ { LPASS_CDC_TX1_CLK_FS_CTL, 0x03 },
+ { LPASS_CDC_TX1_DMIC_CTL, 0x00 },
+ { LPASS_CDC_TX2_VOL_CTL_TIMER, 0x00 },
+ { LPASS_CDC_TX2_VOL_CTL_GAIN, 0x00 },
+ { LPASS_CDC_TX2_VOL_CTL_CFG, 0x00 },
+ { LPASS_CDC_TX2_MUX_CTL, 0x00 },
+ { LPASS_CDC_TX2_CLK_FS_CTL, 0x03 },
+ { LPASS_CDC_TX2_DMIC_CTL, 0x00 },
+};
+
+static bool msm8916_wcd_digital_valid_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case LPASS_CDC_CLK_RX_RESET_CTL ... LPASS_CDC_CLK_SD_CTL:
+ case LPASS_CDC_RX1_B1_CTL ... LPASS_CDC_RX1_VOL_CTL_B2_CTL:
+ case LPASS_CDC_RX2_B1_CTL ... LPASS_CDC_RX2_VOL_CTL_B2_CTL:
+ case LPASS_CDC_RX3_B1_CTL ... LPASS_CDC_TOP_CTL:
+ case LPASS_CDC_DEBUG_DESER1_CTL ... LPASS_CDC_DEBUG_B3_CTL_CFG:
+ case LPASS_CDC_IIR1_GAIN_B1_CTL ... LPASS_CDC_IIR1_COEF_B2_CTL:
+ case LPASS_CDC_IIR2_GAIN_B1_CTL ... LPASS_CDC_IIR2_COEF_B2_CTL:
+ case LPASS_CDC_CONN_RX1_B1_CTL ... LPASS_CDC_CONN_TX_B1_CTL:
+ case LPASS_CDC_CONN_EQ1_B1_CTL ... LPASS_CDC_CONN_TX_I2S_SD1_CTL:
+ case LPASS_CDC_TX1_VOL_CTL_TIMER ... LPASS_CDC_TX1_DMIC_CTL:
+ case LPASS_CDC_TX2_VOL_CTL_TIMER ... LPASS_CDC_TX2_DMIC_CTL:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool msm8916_wcd_digital_volatile_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case LPASS_CDC_CLK_RX_RESET_CTL:
+ case LPASS_CDC_CLK_TX_RESET_B1_CTL:
+ case LPASS_CDC_CLK_OTHR_RESET_B1_CTL:
+ case LPASS_CDC_IIR1_COEF_B1_CTL:
+ case LPASS_CDC_IIR1_COEF_B2_CTL:
+ case LPASS_CDC_IIR2_COEF_B1_CTL:
+ case LPASS_CDC_IIR2_COEF_B2_CTL:
+ return true;
+ default:
+ return false;
+ }
+}
+
static const struct regmap_config msm8916_codec_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.max_register = LPASS_CDC_TX2_DMIC_CTL,
+ .readable_reg = msm8916_wcd_digital_valid_reg,
+ .writeable_reg = msm8916_wcd_digital_valid_reg,
+ .volatile_reg = msm8916_wcd_digital_volatile_reg,
+ .reg_defaults = msm8916_wcd_digital_reg_defaults,
+ .num_reg_defaults = ARRAY_SIZE(msm8916_wcd_digital_reg_defaults),
.cache_type = REGCACHE_FLAT,
};
@@ -1209,7 +1366,6 @@
struct device *dev = &pdev->dev;
void __iomem *base;
struct regmap *digital_map;
- unsigned int reg, val;
int ret;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -1244,7 +1400,14 @@
goto err_clk;
}
- for (reg = 0; reg <= LPASS_CDC_TX2_DMIC_CTL; reg += 4)
- regmap_read(digital_map, reg, &val);
+ regmap_write(digital_map, LPASS_CDC_CLK_OTHR_CTL, 0x04);
+ regmap_write(digital_map, LPASS_CDC_RX1_B5_CTL, 0x68);
+ regmap_write(digital_map, LPASS_CDC_RX2_B5_CTL, 0x68);
+ regmap_write(digital_map, LPASS_CDC_RX3_B5_CTL, 0x68);
+ regmap_write(digital_map, LPASS_CDC_TOP_CTL, 0x01);
+ regmap_write(digital_map, LPASS_CDC_IIR1_CTL, 0x40);
+ regmap_write(digital_map, LPASS_CDC_IIR2_CTL, 0x40);
+ regmap_write(digital_map, LPASS_CDC_TX1_CLK_FS_CTL, 0x03);
+ regmap_write(digital_map, LPASS_CDC_TX2_CLK_FS_CTL, 0x03);
dev_set_drvdata(dev, priv);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
View File
@@ -112,6 +112,10 @@ 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_reg_defaults" sound/soc/codecs/msm8916-wcd-digital.c 2>/dev/null; then
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
fi
if [ ! -f include/config/auto.conf ] || \ if [ ! -f include/config/auto.conf ] || \
! grep -q "CONFIG_NETFILTER_XT_MATCH_OWNER=m" .config 2>/dev/null || \ ! grep -q "CONFIG_NETFILTER_XT_MATCH_OWNER=m" .config 2>/dev/null || \
! grep -q "CONFIG_INTERCONNECT_QCOM_MSM8909=y" .config 2>/dev/null || \ ! grep -q "CONFIG_INTERCONNECT_QCOM_MSM8909=y" .config 2>/dev/null || \
@@ -162,6 +166,8 @@ EOF
patch -p1 < /bananarchy/patches/kernel/0013-msm8909-early-scm-smp-cpufreq.patch patch -p1 < /bananarchy/patches/kernel/0013-msm8909-early-scm-smp-cpufreq.patch
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
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
echo "[3/5] Preparing kernel configuration and Module.symvers..." echo "[3/5] Preparing kernel configuration and Module.symvers..."
cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config cp /bananarchy/patches/kernel/config-bananarchy-msm8909.armv7 .config
+14 -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 \
"2ba4620680a981a87fa8adf7a2fb6ab98d932c73f9de9be1c69981edc096d2a8 images/bananarchy-nokia-argon.img" \ "e15e0fff0e68d059000caf28f73a061170a9da62368531499c6d82b275821903 images/bananarchy-nokia-argon.img" \
"23d1fdd6598bf0c5497b1e41a16888d966ad4ac3f4eee3aa04623b339c896c59 images/bananarchy-nokia-beatles.img" \ "64fcf14fbe8863490d8a3b2838e66baa9e9b5712450526ca0b9e3bed5d724437 images/bananarchy-nokia-beatles.img" \
"0459151f37c746963dc734539a4284a0524b1b8ad777cd8690a87f928d2cec58 images/boot-bananarchy-nokia-beatles.img" \ "7c6aec20941b074cd36c856f62cb9b51b4ad2fe111c4f43f68844e07b828fb84 images/boot-bananarchy-nokia-beatles.img" \
"f13db705a714aaebd2d8fcc2e0f7266d0e40268c0a276208117dfdf9d8f45351 images/boot-lk2nd-nokia-beatles-display.img" \ "f13db705a714aaebd2d8fcc2e0f7266d0e40268c0a276208117dfdf9d8f45351 images/boot-lk2nd-nokia-beatles-display.img" \
"1f47b0f6b96c1637e1febaa6b5d150c2dd661ba9d200286315cb0400ca61a6a0 images/bananarchy-nokia-coconut.img" \ "753029acf664a78b6990d799c060ee29ccb8b464bc0a4c40c1909b1a1a5dbfcb images/bananarchy-nokia-coconut.img" \
"81695b3242403ebbd8631957a0ca67128b9791199e8121f58ed5e8f32ea2cc77 images/boot-bananarchy-nokia-coconut.img" \ "948c44097e069624d60cf952de065961b38e9d45c77bcee958684b96d86dbb7c images/boot-bananarchy-nokia-coconut.img" \
"9a5bd2da6cfd95c745d9c1acb2e3bc61afa339824810e3d160bf079e17b23192 images/boot-lk2nd-nokia-coconut-display.img" \ "9a5bd2da6cfd95c745d9c1acb2e3bc61afa339824810e3d160bf079e17b23192 images/boot-lk2nd-nokia-coconut-display.img" \
"7e6b7bdc1ac96f748c46c6fde0f7debe2ae5562d0c2feb1f5ddfc274fd22717e images/bananarchy-nokia-sparkler.img" \ "36e3a663de0d2586422aa5303a18ce2a70f05274d4d2ff7e377cf5dad243c777 images/bananarchy-nokia-sparkler.img" \
"5fde23c229bcfcec276bfa064308a37736dc9f34bcb80c6f5b6c16400417adfa images/boot-bananarchy-nokia-sparkler.img" \ "f40757646fb9a5c0c489df370f59a97a5638d36bda037042a98be894b47bcf8e 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
@@ -2531,6 +2531,13 @@ elif ! "$BASE_DIR/scripts/test-keypad-debouncer.py" >/dev/null 2>&1; then
fail "host keypad debouncer test failed" fail "host keypad debouncer test failed"
fi fi
echo "[check] WCD 48 kHz interpolators, CAJON_2_0 analog codec, PipeWire downmix, and gain staging..."
if [ ! -x "$BASE_DIR/scripts/test-audio-quality.py" ]; then
fail "missing executable host test scripts/test-audio-quality.py"
elif ! "$BASE_DIR/scripts/test-audio-quality.py" >/dev/null 2>&1; then
fail "host audio quality test failed"
fi
echo "[check] microSD sdhci@7864000 non-removable and zero-polling invariants..." echo "[check] microSD sdhci@7864000 non-removable and zero-polling invariants..."
for dts in \ for dts in \
"$BASE_DIR/devices/nokia-argon/qcom-msm8905-nokia-argon.dts" \ "$BASE_DIR/devices/nokia-argon/qcom-msm8905-nokia-argon.dts" \
+348
View File
@@ -0,0 +1,348 @@
#!/usr/bin/env python3
"""Offline regression test for MSM8905/MSM8909 audio quality fixes (patch 0015, PipeWire downmix, gain staging)."""
import os
import re
import shutil
import subprocess
import sys
import tempfile
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PATCH_0015 = os.path.join(
BASE_DIR, "patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch"
)
BUILD_KERNEL = os.path.join(BASE_DIR, "scripts/build-kernel-audio.sh")
SXMO_AUDIO = os.path.join(BASE_DIR, "overlay/rootfs/usr/bin/sxmo_audio.sh")
SXMO_RING = os.path.join(
BASE_DIR, "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_ring.sh"
)
CALLSCREEN_CPP = os.path.join(BASE_DIR, "src/dwm-plugins/callscreen_plugin.cpp")
FILES_CPP = os.path.join(BASE_DIR, "src/dwm-plugins/files_plugin.cpp")
RINGTONES_CPP = os.path.join(BASE_DIR, "src/dwm-plugins/ringtones_plugin.cpp")
XDRAWER_CPP = os.path.join(BASE_DIR, "src/xdrawer/xdrawer.cpp")
WP_S16LE_PATHS = [
"overlay/rootfs/etc/wireplumber/wireplumber.conf.d/msm8916-s16le.conf",
"overlay/rootfs/usr/share/wireplumber/wireplumber.conf.d/msm8916-s16le.conf",
"overlay/rootfs/etc/skel/.config/wireplumber/wireplumber.conf.d/msm8916-s16le.conf",
"overlay/rootfs/home/user/.config/wireplumber/wireplumber.conf.d/msm8916-s16le.conf",
]
WP_BT_PATHS = [
"overlay/rootfs/etc/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
"overlay/rootfs/usr/share/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
"overlay/rootfs/etc/skel/.config/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
"overlay/rootfs/home/user/.config/wireplumber/wireplumber.conf.d/50-bluetooth.conf",
]
WP_CREATE_ITEM_LUA = (
"overlay/rootfs/usr/share/wireplumber/scripts/node/create-item.lua"
)
PW_STREAM_DROPINS = [
"overlay/rootfs/etc/pipewire/client.conf.d/10-bananarchy-audio.conf",
"overlay/rootfs/etc/pipewire/pipewire-pulse.conf.d/10-bananarchy-audio.conf",
]
UCM_FILES = {
"overlay/rootfs/usr/share/alsa/ucm2/codecs/msm8916-wcd/Speaker.conf": ("RX3 Digital Volume", 84),
"overlay/rootfs/usr/share/alsa/ucm2/codecs/msm8916-wcd/Headphones.conf": ("RX1 Digital Volume", 84),
"overlay/rootfs/usr/share/alsa/ucm2/codecs/msm8916-wcd/Earpiece.conf": ("RX1 Digital Volume", 84),
}
def read_text(path):
with open(path, "r", encoding="utf-8") as handle:
return handle.read()
def fail(msg):
sys.stderr.write(f"[fail] {msg}\n")
return 1
def run_c_codec_harness():
gcc = shutil.which("gcc")
if not gcc:
print("[skip] host gcc unavailable; skipping C codec register verification")
return
c_src = r"""
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#define GENMASK(h, l) (((~0U) - (1U << (l)) + 1) & (~0U >> (31 - (h))))
#define BIT(n) (1U << (n))
#define RXn_B5_CTL_INTERP_FS_RATE_MASK GENMASK(7, 5)
#define RXn_B5_CTL_INTERP_FS_RATE_SHIFT 5
#define RXn_B5_CTL_INTERP_HALFBAND_EN BIT(3)
#define TXn_CLK_FS_CTL_FS_RATE_MASK GENMASK(2, 0)
#define SPKR_DRV_CTL_DEF_MASK 0xEFU
#define SPKR_DRV_CLASSD_PA_EN_MASK BIT(7)
#define SPKR_DRV_CLASSD_PA_EN_ENABLE BIT(7)
#define SPKR_DRV_CAL_EN BIT(6)
#define SPKR_DRV_SETTLE_EN BIT(5)
#define SPKR_DRV_FW_EN BIT(3)
#define SPKR_DRV_BOOST_SET BIT(2)
#define SPKR_DRV_CMFB_SET BIT(1)
#define SPKR_DRV_GAIN_SET BIT(0)
#define SPKR_DRV_CTL_NO_BOOST_VAL (SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
SPKR_DRV_FW_EN | SPKR_DRV_GAIN_SET)
#define SPKR_DRV_CTL_DEF_VAL (SPKR_DRV_CLASSD_PA_EN_ENABLE | SPKR_DRV_CAL_EN | \
SPKR_DRV_SETTLE_EN | SPKR_DRV_FW_EN | \
SPKR_DRV_BOOST_SET | SPKR_DRV_CMFB_SET | \
SPKR_DRV_GAIN_SET)
static uint32_t update_bits(uint32_t cur, uint32_t mask, uint32_t val) {
return (cur & ~mask) | (val & mask);
}
static uint32_t compute_rx_b5(uint32_t cur_b5, unsigned int rate) {
uint32_t rx_fs = 3;
if (rate == 8000) rx_fs = 0;
else if (rate == 16000) rx_fs = 1;
else if (rate == 32000) rx_fs = 2;
else if (rate == 48000) rx_fs = 3;
return update_bits(cur_b5,
RXn_B5_CTL_INTERP_FS_RATE_MASK | RXn_B5_CTL_INTERP_HALFBAND_EN,
(rx_fs << RXn_B5_CTL_INTERP_FS_RATE_SHIFT) | RXn_B5_CTL_INTERP_HALFBAND_EN);
}
int main(void) {
/* 1. Verify B5_CTL updates fs rate and halfband while preserving DCB switch (BIT 2). */
if (compute_rx_b5(0x00, 48000) != 0x68 ||
compute_rx_b5(0x04, 48000) != 0x6C ||
compute_rx_b5(0x6C, 8000) != 0x0C ||
compute_rx_b5(0x08, 16000) != 0x28 ||
compute_rx_b5(0x08, 32000) != 0x48) {
fprintf(stderr, "RXn_B5_CTL rate transition mismatch\n");
return 1;
}
/* 2. Verify TXn_CLK_FS_CTL lower 3 bits update without clobbering reserved bits. */
if (update_bits(0x03, TXn_CLK_FS_CTL_FS_RATE_MASK, 0) != 0x00 ||
update_bits(0x00, TXn_CLK_FS_CTL_FS_RATE_MASK, 3) != 0x03) {
fprintf(stderr, "TXn_CLK_FS_CTL update mismatch\n");
return 2;
}
/* 3. Verify CAJON speaker PA clears BOOST_SET & CMFB_SET (0xE9 vs 0xEF). */
uint32_t drv = 0x29; /* after DAPM sets CAL_EN -> 0x69 */
drv = update_bits(drv, SPKR_DRV_CTL_DEF_MASK & ~SPKR_DRV_CLASSD_PA_EN_MASK,
SPKR_DRV_CTL_NO_BOOST_VAL);
if (drv != 0x69) {
fprintf(stderr, "CAJON pre-PA DRV_CTL expected 0x69, got 0x%x\n", drv);
return 3;
}
drv = update_bits(drv, SPKR_DRV_CLASSD_PA_EN_MASK, SPKR_DRV_CLASSD_PA_EN_ENABLE);
if (drv != 0xE9 || (drv & (SPKR_DRV_BOOST_SET | SPKR_DRV_CMFB_SET)) != 0) {
fprintf(stderr, "CAJON active DRV_CTL expected 0xE9 without boost bits, got 0x%x\n", drv);
return 4;
}
/* 4. Verify s2 wakeup preserves SPK DAC Switch bit 7 while restoring CAJON 0x03. */
uint32_t spkr_dac_ctl = 0x80; /* SPK DAC Switch ON before standby */
spkr_dac_ctl = update_bits(spkr_dac_ctl, 0x7FU, 0x03U);
if (spkr_dac_ctl != 0x83U) {
fprintf(stderr, "s2 restore clobbered SPK DAC Switch: 0x%x\n", spkr_dac_ctl);
return 5;
}
return 0;
}
"""
with tempfile.TemporaryDirectory(prefix="ba_audio_q_") as td:
src = os.path.join(td, "test_audio_q.c")
exe = os.path.join(td, "test_audio_q")
with open(src, "w", encoding="utf-8") as handle:
handle.write(c_src)
subprocess.run([gcc, "-Wall", "-Wextra", "-Werror", "-O2", src, "-o", exe], check=True)
subprocess.run([exe], check=True)
def check_patch_0015():
if not os.path.isfile(PATCH_0015):
return fail("missing patches/kernel/0015-msm8909-wcd-digital-interpolator-cajon-analog.patch")
txt = read_text(PATCH_0015)
required = [
"msm8916_wcd_digital_reg_defaults",
"{ LPASS_CDC_RX1_B5_CTL, 0x68 }",
"{ LPASS_CDC_RX2_B5_CTL, 0x68 }",
"{ LPASS_CDC_RX3_B5_CTL, 0x68 }",
"{ LPASS_CDC_TX1_CLK_FS_CTL, 0x03 }",
"{ LPASS_CDC_TX2_CLK_FS_CTL, 0x03 }",
"{ LPASS_CDC_CLK_OTHR_CTL, 0x04 }",
"RXn_B5_CTL_INTERP_FS_RATE_MASK",
"TXn_CLK_FS_CTL_FS_RATE_MASK",
"wcd_reg_defaults_cajon_2_0",
"{CDC_A_NCP_FBCTRL, 0xA8}",
"{CDC_A_NCP_VCTRL, 0xA4}",
"{CDC_A_RX_HPH_BIAS_PA, 0xFA}",
"{CDC_A_SPKR_ANA_BIAS_SET, 0x41}",
"{CDC_A_SPKR_DRV_CTL, 0x69}",
"SPKR_DRV_CTL_NO_BOOST_VAL",
"CDC_A_PERPH_SUBTYPE_CAJON",
"pm8916_wcd_analog_enable_hphl_dac",
"pm8916_wcd_analog_enable_hphr_dac",
"pm8916_wcd_analog_enable_hph_pa",
"pm8916_wcd_analog_apply_defaults(component, true);",
]
for tok in required:
if tok not in txt:
return fail(f"0015 patch missing required token: {tok}")
build_txt = read_text(BUILD_KERNEL)
if build_txt.count("0015-msm8909-wcd-digital-interpolator-cajon-analog.patch") != 2:
return fail("scripts/build-kernel-audio.sh must apply 0015 in both kcache and tarball paths")
return 0
def check_wireplumber():
s16_ref = None
for rel in WP_S16LE_PATHS:
path = os.path.join(BASE_DIR, rel)
if not os.path.isfile(path):
return fail(f"missing {rel}")
raw = read_text(path)
if s16_ref is None:
s16_ref = raw
elif raw != s16_ref:
return fail(f"wireplumber msm8916-s16le.conf drifted in {rel}")
for tok in (
'audio.format = "S16LE"',
"audio.rate = 48000",
'dither.method = "triangular"',
"~alsa_output.platform-7702000.*.HiFi__Speaker__sink",
"~alsa_output.platform-sound.*.HiFi__Speaker__sink",
"~alsa_output.platform-7702000.*.HiFi__Earpiece__sink",
"~alsa_output.platform-sound.*.HiFi__Earpiece__sink",
"item.features.mono = true",
"channelmix.normalize = true",
):
if tok not in s16_ref:
return fail(f"msm8916-s16le.conf missing {tok}")
for forbidden in ("AUX0", "channelmix.upmix = false"):
if forbidden in s16_ref:
return fail(f"msm8916-s16le.conf must not contain unpositioned/no-upmix token {forbidden}")
create_item_path = os.path.join(BASE_DIR, WP_CREATE_ITEM_LUA)
if not os.path.isfile(create_item_path):
return fail(f"missing {WP_CREATE_ITEM_LUA}")
create_item_txt = read_text(create_item_path)
for tok in (
'Settings.get_boolean ("node.features.audio.mono")',
'cutils.parseBool (properties ["item.features.mono"])',
):
if tok not in create_item_txt:
return fail(f"{WP_CREATE_ITEM_LUA} missing {tok}")
pw_ref = None
for rel in PW_STREAM_DROPINS:
path = os.path.join(BASE_DIR, rel)
if not os.path.isfile(path):
return fail(f"missing {rel}")
raw = read_text(path)
if pw_ref is None:
pw_ref = raw
elif raw != pw_ref:
return fail(f"PipeWire stream drop-in drifted in {rel}")
for tok in ("channelmix.normalize = true", 'dither.method = "triangular"'):
if tok not in pw_ref:
return fail(f"PipeWire stream drop-in missing {tok}")
bt_ref = None
for rel in WP_BT_PATHS:
path = os.path.join(BASE_DIR, rel)
raw = read_text(path)
if bt_ref is None:
bt_ref = raw
elif raw != bt_ref:
return fail(f"wireplumber 50-bluetooth.conf drifted in {rel}")
if "bluez5.roles = [ a2dp_sink hsp_hs hfp_hf ]" not in bt_ref:
return fail("50-bluetooth.conf lost bluez5.roles invariant")
return 0
def check_gain_staging():
for rel, (ctl_name, max_vol) in UCM_FILES.items():
txt = read_text(os.path.join(BASE_DIR, rel))
matches = re.findall(rf'{re.escape(ctl_name)}\x27\s+(\d+)', txt)
if not matches:
return fail(f"{rel} missing {ctl_name}")
for m in matches:
if int(m) > max_vol:
return fail(f"{rel} {ctl_name}={m} exceeds 0 dB unity ceiling ({max_vol})")
audio_txt = read_text(SXMO_AUDIO)
if "bananarchy_set_sink_volume" not in audio_txt or \
"bananarchy_sync_internal_pw_vol" not in audio_txt or \
"[ -d /proc/asound/card0 ]" not in audio_txt:
return fail("sxmo_audio.sh missing PipeWire unity sync guard for card0")
probe_script = r"""
set -eu
. "%s" >/dev/null 2>&1 || true
""" % SXMO_AUDIO
# Extract pct_to_hw_out + dependencies and evaluate edge percentages with sh
res = subprocess.run(
[
"sh", "-eu", "-c",
f"""
eval "$(sed -n '/^normalize_out_dev()/,/^}}/p; /^clamp_pct()/,/^}}/p; /^pct_to_hw_out()/,/^}}/p' '{SXMO_AUDIO}')"
for dev in Speaker Headphones Earpiece; do
v0="$(pct_to_hw_out "$dev" 0)"
v1="$(pct_to_hw_out "$dev" 1)"
v85="$(pct_to_hw_out "$dev" 85)"
v100="$(pct_to_hw_out "$dev" 100)"
printf '%s %s %s %s %s\n' "$dev" "$v0" "$v1" "$v85" "$v100"
done
""",
],
capture_output=True,
text=True,
check=True,
)
expected = {
"Speaker": (0, 52, 79, 84),
"Earpiece": (0, 52, 79, 84),
"Headphones": (0, 51, 78, 83),
}
for line in res.stdout.strip().splitlines():
dev, v0, v1, v85, v100 = line.split()
got = (int(v0), int(v1), int(v85), int(v100))
if got != expected[dev]:
return fail(f"sxmo_audio.sh pct_to_hw_out {dev} expected {expected[dev]}, got {got}")
ring_txt = read_text(SXMO_RING)
if "ring_rx3=$(( 52 +" not in ring_txt or "ring_hp=$(( 51 +" not in ring_txt:
return fail("sxmo_hook_ring.sh volume curve out of sync with unity ceiling")
for path, label, needles in [
(CALLSCREEN_CPP, "callscreen_plugin.cpp", ["51 + (c * 32 + 50) / 100", "52 + (c * 32 + 50) / 100"]),
(FILES_CPP, "files_plugin.cpp", ["52 + (rvol * 32 + 50) / 100", "51 + (rvol * 32 + 50) / 100"]),
(RINGTONES_CPP, "ringtones_plugin.cpp", ["52 + (rvol * 32 + 50) / 100", "51 + (rvol * 32 + 50) / 100"]),
(XDRAWER_CPP, "xdrawer.cpp", ["rx1 >= 83", "rx3 >= 84", "51 + std::lround", "52 + std::lround"]),
]:
txt = read_text(path)
for n in needles:
if n not in txt:
return fail(f"{label} missing synced gain staging expression: {n}")
return 0
def main():
for fn in (check_patch_0015, check_wireplumber, check_gain_staging):
rc = fn()
if rc != 0:
return rc
run_c_codec_harness()
print("[ok] 0015 WCD digital 48 kHz interpolator, CAJON analog codec, WirePlumber item.features.mono downmix, and <= 0 dB gain staging passed")
return 0
if __name__ == "__main__":
sys.exit(main())
+3 -3
View File
@@ -584,10 +584,10 @@ int callscreen_run_main(int argc, char** argv) {
int softkeyPending = 0; int softkeyPending = 0;
int64_t softkeyDeadlineMs = 0; int64_t softkeyDeadlineMs = 0;
auto pctToHwVol = [](int pct, bool spk, bool hp = false) -> long { auto pctToHwVol = [](int pct, bool /*spk*/, bool hp = false) -> long {
int c = std::clamp(pct, 5, 100); int c = std::clamp(pct, 5, 100);
if (hp) return 52 + (c * 32 + 50) / 100; if (hp) return 51 + (c * 32 + 50) / 100;
return spk ? (56 + (c * 32 + 50) / 100) : (60 + (c * 32 + 50) / 100); return 52 + (c * 32 + 50) / 100;
}; };
auto refreshHardwareAudioState = [&]() { auto refreshHardwareAudioState = [&]() {
+3 -3
View File
@@ -902,9 +902,9 @@ int runFilesApp(int argc, char** argv) {
} }
int rvol = std::clamp(readRingVolumePct(), 0, 100); int rvol = std::clamp(readRingVolumePct(), 0, 100);
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100); int rx3 = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100); int hp = (rvol <= 0) ? 0 : (51 + (rvol * 32 + 50) / 100);
int ear = (rvol <= 0) ? 0 : (60 + (rvol * 32 + 50) / 100); int ear = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
std::string cfgDir = homeDir + "/.config/sxmo"; std::string cfgDir = homeDir + "/.config/sxmo";
const char* xdgCfg = std::getenv("XDG_CONFIG_HOME"); const char* xdgCfg = std::getenv("XDG_CONFIG_HOME");
if (xdgCfg && *xdgCfg) cfgDir = std::string(xdgCfg) + "/sxmo"; if (xdgCfg && *xdgCfg) cfgDir = std::string(xdgCfg) + "/sxmo";
+5 -5
View File
@@ -574,9 +574,9 @@ int runRingtonesApp(int argc, char** argv) {
settings = loadRingSettings(); settings = loadRingSettings();
int rvol = std::clamp(settings.ringVol, 0, 100); int rvol = std::clamp(settings.ringVol, 0, 100);
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100); int rx3 = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100); int hp = (rvol <= 0) ? 0 : (51 + (rvol * 32 + 50) / 100);
int ear = (rvol <= 0) ? 0 : (60 + (rvol * 32 + 50) / 100); int ear = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
std::string volArg = "--volume=100"; std::string volArg = "--volume=100";
std::string loopArg = singleShot ? "--loop=no" : "--loop=2"; std::string loopArg = singleShot ? "--loop=no" : "--loop=2";
bool useSparklerAf = isHapticAudioSpeakerDevice() && bool useSparklerAf = isHapticAudioSpeakerDevice() &&
@@ -1124,8 +1124,8 @@ int runRingtonesApp(int argc, char** argv) {
saveRingSettings(settings); saveRingSettings(settings);
if (previewPid > 0) { if (previewPid > 0) {
int rvol = settings.ringVol; int rvol = settings.ringVol;
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100); int rx3 = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100);
int hp = (rvol <= 0) ? 0 : (52 + (rvol * 32 + 50) / 100); int hp = (rvol <= 0) ? 0 : (51 + (rvol * 32 + 50) / 100);
runAsyncCmd("outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); " runAsyncCmd("outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
"if [ \"$outdev\" = \"Bluetooth\" ]; then " "if [ \"$outdev\" = \"Bluetooth\" ]; then "
" pactl set-sink-volume @DEFAULT_SINK@ " + std::to_string(rvol) + "% >/dev/null 2>&1; " " pactl set-sink-volume @DEFAULT_SINK@ " + std::to_string(rvol) + "% >/dev/null 2>&1; "
+12 -12
View File
@@ -343,10 +343,10 @@ class PhoneController {
long rx1 = alsa_.getInteger("RX1 Digital Volume", 78); long rx1 = alsa_.getInteger("RX1 Digital Volume", 78);
if (rx1 <= 0) { if (rx1 <= 0) {
hpPct = 0; hpPct = 0;
} else if (rx1 >= 84) { } else if (rx1 >= 83) {
hpPct = 100; hpPct = 100;
} else { } else {
hpPct = std::clamp(static_cast<int>(std::lround(((rx1 - 52) * 100.0) / 32.0)), 5, 100); hpPct = std::clamp(static_cast<int>(std::lround(((rx1 - 51) * 100.0) / 32.0)), 5, 100);
} }
} }
hpPct = ((hpPct + 2) / 5) * 5; hpPct = ((hpPct + 2) / 5) * 5;
@@ -355,13 +355,13 @@ class PhoneController {
} else { } else {
int spkPct = readIntFile(getSxmoCfgDir() + "/speaker_vol", -1); int spkPct = readIntFile(getSxmoCfgDir() + "/speaker_vol", -1);
if (spkPct < 0 || spkPct > 100) { if (spkPct < 0 || spkPct > 100) {
long rx3 = alsa_.getInteger("RX3 Digital Volume", 84); long rx3 = alsa_.getInteger("RX3 Digital Volume", 79);
if (rx3 <= 0) { if (rx3 <= 0) {
spkPct = 0; spkPct = 0;
} else if (rx3 >= 88) { } else if (rx3 >= 84) {
spkPct = 100; spkPct = 100;
} else { } else {
spkPct = std::clamp(static_cast<int>(std::lround(((rx3 - 56) * 100.0) / 32.0)), 5, 100); spkPct = std::clamp(static_cast<int>(std::lround(((rx3 - 52) * 100.0) / 32.0)), 5, 100);
} }
} }
spkPct = ((spkPct + 2) / 5) * 5; spkPct = ((spkPct + 2) / 5) * 5;
@@ -369,16 +369,16 @@ class PhoneController {
"Speaker", true, 0, 100, 5, spkPct}); "Speaker", true, 0, 100, 5, spkPct});
} }
// 2. Earpiece volume (0..100%, linear mapped to ALSA RX1 Digital Volume 60..92) // 2. Earpiece volume (0..100%, linear mapped to ALSA RX1 Digital Volume 52..84)
int earPct = readIntFile(getSxmoCfgDir() + "/earpiece_vol", -1); int earPct = readIntFile(getSxmoCfgDir() + "/earpiece_vol", -1);
if (earPct < 0 || earPct > 100) { if (earPct < 0 || earPct > 100) {
long rx1 = alsa_.getInteger("RX1 Digital Volume", 88); long rx1 = alsa_.getInteger("RX1 Digital Volume", 79);
if (rx1 <= 0) { if (rx1 <= 0) {
earPct = 0; earPct = 0;
} else if (rx1 >= 92) { } else if (rx1 >= 84) {
earPct = 100; earPct = 100;
} else { } else {
earPct = std::clamp(static_cast<int>(std::lround(((rx1 - 60) * 100.0) / 32.0)), 5, 100); earPct = std::clamp(static_cast<int>(std::lround(((rx1 - 52) * 100.0) / 32.0)), 5, 100);
} }
} }
earPct = ((earPct + 2) / 5) * 5; earPct = ((earPct + 2) / 5) * 5;
@@ -651,7 +651,7 @@ class PhoneController {
} else if (outDev == "Headphones") { } else if (outDev == "Headphones") {
writeIntFile(cfg + "/headphones_vol", it.value); writeIntFile(cfg + "/headphones_vol", it.value);
writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0); writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0);
long hw = (it.value <= 0) ? 0 : (52 + std::lround((it.value * 32.0) / 100.0)); long hw = (it.value <= 0) ? 0 : (51 + std::lround((it.value * 32.0) / 100.0));
alsa_.setEnum("HPHL", (it.value > 0) ? 1 : 0); alsa_.setEnum("HPHL", (it.value > 0) ? 1 : 0);
alsa_.setEnum("HPHR", (it.value > 0) ? 1 : 0); alsa_.setEnum("HPHR", (it.value > 0) ? 1 : 0);
alsa_.setInteger("RX1 Digital Volume", hw); alsa_.setInteger("RX1 Digital Volume", hw);
@@ -663,7 +663,7 @@ class PhoneController {
runAsyncCmd(cmd); runAsyncCmd(cmd);
} else { } else {
writeIntFile(cfg + "/speaker_vol", it.value); writeIntFile(cfg + "/speaker_vol", it.value);
long hw = (it.value <= 0) ? 0 : (56 + std::lround((it.value * 32.0) / 100.0)); long hw = (it.value <= 0) ? 0 : (52 + std::lround((it.value * 32.0) / 100.0));
if (outDev == "Speaker") { if (outDev == "Speaker") {
writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0); writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0);
alsa_.setBoolean("SPK DAC Switch", it.value > 0); alsa_.setBoolean("SPK DAC Switch", it.value > 0);
@@ -684,7 +684,7 @@ class PhoneController {
std::string cfg = getSxmoCfgDir(); std::string cfg = getSxmoCfgDir();
::mkdir(cfg.c_str(), 0755); ::mkdir(cfg.c_str(), 0755);
writeIntFile(cfg + "/earpiece_vol", it.value); writeIntFile(cfg + "/earpiece_vol", it.value);
long hw = (it.value <= 0) ? 0 : (60 + std::lround((it.value * 32.0) / 100.0)); long hw = (it.value <= 0) ? 0 : (52 + std::lround((it.value * 32.0) / 100.0));
if (readActiveOutputDevice() == "Earpiece") { if (readActiveOutputDevice() == "Earpiece") {
writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0); writeIntFile("/tmp/sxmo_out_muted", (it.value <= 0) ? 1 : 0);
alsa_.setEnum("EAR_S", (it.value > 0) ? 1 : 0); alsa_.setEnum("EAR_S", (it.value > 0) ? 1 : 0);