Fairphone 5 (fairphone-fp5)/Audio
GitLab issues
Fairphone 5 audio is associated with the following three issues (the first two now closed/merged):
- pmaports#3794: Microphone issue on GitLab
- pmaports#3793: Speaker support issue on GitLab
- Call/routing work item on GitLab
Current status
Speaker output and microphone input are both now working on Nura edge. Microphone input levels are fairly low, at least by default.
What also works
Bluetooth and USB-C audio work fine out of the box. Note: one cannot currently use Bluetooth or USB-C for voice calls.
DP/HDMI sound output works fine but currently requires restarting PulseAudio after connecting the display (killall pulseaudio pipewire pipewire-pulse). After restarting PulseAudio, sound should be routed through HDMI/DP without problems. This appears to be a known wider problem (not device-specific).
Analogue headphones (through a USB adapter) can be made to work, but this is currently in a development branch and not in the main kernel package.
There is no integration with the modem (for call audio) yet, althought a WIP workaround is available to make call audio routing work.
Hardware
The Fairphone 5 uses the Qualcomm QCM6490 SoC (yupik), which is a variant of the SM7325 and SC7280 SoCs.
Sound is handled by two separate codec chips. The on-board Qualcomm WCD9385 handles the four microphones and the analogue headphones (through USB dongle). The speaker output is handled by the Awinic AW88261 digital amplifier and codec.
AW88261 receives digital audio via the I2S bus, decodes it, amplifies it and drives the onboard speakers. WCD is not involved in this process. I2S can carry multiple signals (primary, secondary, etc.). On the FP5, the QCM6490 connects to the AW88261 via quinary I2S (see schematics below).
WCD9385 communicates to mics via SoundWire (AMIC1, AMIC3, AMIC4). It communicates with headphones (WCD_HPH) and AMIC2 via Type-C audio. There is also AUX, but I'm not sure if that's relevant for us, likely not a priority.
Qualcomm chips have a complex routing infrastructure that allows different parts of the SoC to communicate. This is handled by the mainline Qualcomm drivers and (AFAIK) works fine.
Driver support
All relevant drivers are in mainline at the moment. QCM6490 is supported in Luca's SC7280 kernel fork (close to mainline). This includes all the complex code to enable audio routing inside the SoC. AW88261 has a mainline driver. This driver is thought to work because there are devices where this chip reported to work (xiaomi-pipa).
There is a downstream Android driver for Awinic sound chips. I have not experimented with this, but it was reported to not work reliably on mainline (very quiet sound) which could be due to differences between mainline and downstream Qualcomm driver implementation. It is also hellish in terms of code quality and will probably never be mainlined. Because of this, most of the effort has gone into the existing mainline driver. However, it can be useful in order to analyse its behaviour compared to the mainline AW88261 driver.
WCD9385 also has a mainline driver that reportedly works on other hardware.
Firmware
AW88261 requires firmware file aw882xx_acf.bin (MD5sum: 47e2e868a18b13bb3c43ab24ea4d7a4a). This can be extracted from the FP5 Android image and placed under /lib/firmware/. It will need to be renamed to aw88261_acf.bin for the driver to find it.
In the longer term, we probably want to add this to the
firmware-fairphone-fp5 package (any reason not to do this now?)
In-kernel device tree
A device tree is a structured description of the hardware. It is used by the kernel to load and initialise drivers. It is a key part of embedded/ARM kernel development and can be very confusing to those of us coming from the x86 world.
The Fairphone 5 dts (device tree source) file contains most of the work needed to get sound working. It supplies information about connectivity, clocks, voltages, compatible drivers and similar detail that the kernel cannot discover on its own. FP5 device tree is defined in arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts and includes a lot of information from related files (especially the sc7280 SoC) which means it takes time to understand how everything fits together.
The relevant values for clocks and voltage regulators are mostly based on the reference SC7280 implementation and available schematics. Relevant sections for FP5 sound include (there are probably others):
- sound: for specifying sound driver and how to route signals
- wcd9385: for wcd-related voltages and pinctrls
- i2c2: for aw88261 codec connections via i2c
- q6afedai: for specifying registers corresponding to I2S, displayport etc.
Resources
- my WIP version: https://github.com/cosmo-floss/linux/blob/cosmo-fp5-speaker/arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts
Call audio routing WIP support
A WIP support for call audio routing is available (for PipeWire only as of right now).
First, ensure you are using PipeWire. Otherwise, you can install it using:
$ sudo apk add postmarketos-base-ui-audio-backend-pipewire !postmarketos-base-ui-audio-backend-pulseaudio
Once PipeWire is installed, reboot your device. Call audio routing should now work.
Maybe you like to remove old MR:
$ sudo apk del .mrtest-5-wrenix && sudo apk upgrade -Ua
Known issues while in a call
- Only Earpiece ia supported
- The speaker button doesn't work.
- The mute button doesn't work.
- No volume control.
- No call audio routing over Bluetooth or USB-C.
- After ending a call no Audio exits, so play an Alert or restart wireplumber.
Resources
- Wren IX's branch: https://gitlab.postmarketos.org/wrenix/pmaports/-/tree/fp5-kernel-voice
- Wren IX's draft MR: https://gitlab.postmarketos.org/wrenix/pmaports/-/merge_requests/2
Kernel mainline WIP for AW88261
The most recent work on this is in the following kernel branch:
https://github.com/ferrieux/linux-pmos/tree/sc7280-alex-6.16.y
This is based on Bharadwaj Raju's fork[1] which did a lot of the initial bug fixing, but which does not currently have the correct bitshifting or audio control support.
This includes an updated device tree file (dts), as well as some bug fixes to the AW88261 driver and the qcom subsystem. The GitLab issue linked above has more information on the work that was done.
For instructions on how to install this, see #In-kernel device tree.
There are three other branches I'm aware of that contain some initial work on AW88261 on FP5, but these have not been maintained in quite a while:
- Luca's initial work: https://github.com/z3ntu/linux/commits/sc7280-6.9-wip-audio-speakeronly/
- Manuel's Mobian work: https://salsa.debian.org/Mobian-team/devices/kernels/qcom-linux/-/merge_requests/8
- My WIP branch (cosmo): https://github.com/cosmo-floss/linux/tree/cosmo-fp5-speaker
All of these three branches are in a similar state as far as I'm aware. The relevant work is in the device tree: arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts. This makes it easy to port changes to later kernels, so working on older kernel versions is OK.
Kernel sources have useful documentation:
- Reference implementation (yupik): sc7280-idp.dtsi
- QCom documentation: Documentation/devicetree/bindings/sound
The xiaomi-pipa fork has some work on the aw88261 chip that could be worth looking at: https://github.com/pipa-mainline/linux/commit/1e353b0d52b40491b6676f0028fb8a4270c7fd6a
Android (downstream) driver for AW88261
There is some initial work by Luca to get this working in the following branch:
https://github.com/z3ntu/linux/commits/fp5-6.8-wip-audio-speakeronly/
There is also a pre-built version at:
To test this, you should run the following script manually after booting:
#!/bin/bash
echo start | sudo tee /sys/class/remoteproc/remoteproc1/state
sleep 1
amixer -c0 cset name='QUIN_MI2S_RX Audio Mixer MultiMedia1' 1
sleep 0.5
aplay -D plughw:0,0 foo.wav
This reportedly outputs some (quiet) sound but is not stable.
Running this downstream kernel could be useful for monitoring register values and comparing them to the mainline driver, to aid debugging.
Kernel WIP for WCD9385
There is currently less progress on this. It is possible that there are routing/qcom-related issues that affect all sound work.
There were timing issues reported when trying to mainline WCD9385 on the FP5, not sure whether this ever got resolved: https://patches.linaro.org/project/linux-arm-msm/patch/CXCXIAY8RBVK.2Y9W66THN9QH2@fairphone.com/
There has been progress on this on nothing-spacewar (closely related SoC, same WCD codec). I don't think mics work on spacewar yet, and once they do, FP5 will probably need changes (due to individual mic biases and how they connect). The relevant commits from Mar 25 are linked below, I can't find the original branch anymore to see whether there was follow-up work on this (it was probably removed at some point).
| Function | Device | WCD9380 pin | Soundwire channel |
|---|---|---|---|
| Voice microphone | MIC1 | AMIC1 | |
| USB-C audio | - | AMIC2 | |
| Top microphone | MIC2 | AMIC3 | |
| Side microphone | MIC3 | AMIC4 | |
| - | - | AMIC5 | |
| - | - | AMIC6 | |
| - | - | AMIC7 | |
| USB-C audio | - | HPH | |
| Unused amplifier? | HAC | AUX | |
| - | - | EAR |
Resources
- sm7325 mainlining work: https://github.com/mainlining/linux/commits/b5ba9c818a8be20a21ef364078c9b50b9ee735c6/
- Luca's branch (probably best): https://github.com/sc7280-mainline/linux/tree/sc7280-6.14.y-wip-wcd
- my branch (similar but untested): https://github.com/cosmo-floss/linux/tree/cosmo-fp5-wcd
ALSA WIP
In order to test the sound, valid audio routes first need to be set. ALSA uses DAPM (Dynamic Audio Power Management), which is essential even if one is not interested in power management. This is because the kernel will only power up specific hardware (such as audio amp or speaker) if it is part of a valid audio path. Everything that is not part of a valid audio path (for example, headphone amp when headphones are not plugged in) is not powered up and will not produce sound. So to test whether sound works one will need to establish an audio path from a source to a sink (in this case it will terminate with AW88261 and then the speakers).
This is normally handled via UCM profiles. These will need to be set up once kernel stuff works. At the moment, there is a profile for DP/HDMI sound and nothing else.
In the meantime, one can establish routes manually using the amixer tool (see Nura wiki linked below) in order to test if sound works. Once a kernel is installed that supports aw88261, you should be able to see a sound card (aplay -l). If the FP5 is listed, one can do the following:
$ amixer -c0 cset name='QUIN_MI2S_RX Audio Mixer MultiMedia1' 1
$ aplay --dump-hw-params -D plughw:0,0 /usr/share/sounds/alsa/*.wav
You may need to adjust the volume using alsamixer -c 0 but sound should play.
Some open questions
- Is there a good overview of Qualcomm ADSP stuff (afedai, asmdai, routing, etc.)?
- Correct mapping of amic ports to swr ports for mics over WCD9835
How to get involved
You will need to compile a kernel with working fixes, and compile and install it. You will probably want to do this on edge (for envkernel support).
At the moment of writing, this fork has the most complete support: https://github.com/ferrieux/linux-pmos/tree/sc7280-alex-6.16.y . This could change.
$ git clone https://github.com/ferrieux/linux-pmos.git
Check out the "sc7280-alex-6.16.y" branch; commit 0600617bb428 is known to work. Now, copy the sc7280 kernel config[2] from pmaports to /arch/arm64/configs/sc7280_defconfig.
If needed, edit the config to make sure the AW88261 driver is built (CONFIG_SND_SOC_AW88261=y).
$ source ~/.pmbootstrap/helpers/envkernel.sh
$ make sc7280_defconfig
$ make
Then package and install the kernel:
$ pmbootstrap build --envkernel linux-postmarketos-qcom-sc7280
$ pmbootstrap sideload --host myhost --user myuser linux-postmarketos-qcom-sc7280
Test that the sound card is initialised properly:
$ aplay -l
If the FP5 soundcard shows up, follow #ALSA_WIP to set up a route and try to play a sound.
See also
Relevant devices
- SHIFT SHIFTphone 8 (shift-otter) uses the same SoC (QCM6490) but uses a different digital amp (no sound yet)
- Nothing Phone 1 (nothing-spacewar) uses essentially the same SoC (SM7325-AE) but uses a different digital amp (Goodix TFA9873)
- Motorola Edge 30 (motorola-dubai) uses essentially the same SoC (SM7325-AE), the same digital amp (AW88261), and WCD9375
- Xiaomi Pad 6 (xiaomi-pipa) uses a different SoC (SM8250-AC) but the same digital amp (AW88261) and has reported support for the amp in the wiki. (TODO: try to get hold of the dts from the Nura kernel for this device)
References
- ↑ Bharadwaj Raju's repository on GitHub
- ↑ SC7280 device config on GitLab
External links
- Audio and Embedded Linux by Marcus Folkesson
- Sound Subsystem in the Linux Kernel documentation
ALSA and DAPM
- ALSA SoC Layer Overview in the Linux Kernel documentation
- DAPM in the Linux Kernel documentation
- DAPM in the AlsaProject documentation
- ALSA/DAPM overview by Lars-Peter Clausen
- Introduction to DAPM by Luca Ceresoli