[PATCH v2] ASoC: sun8i-codec-analog: Add the headphone inversion switches

From: Romain TISSERAND

Date: Thu Nov 26 2026 - 21:00:36 EST


Bits 1 and 0 of PAEN_HP_CTRL (analog register 0x07; LTRNMUTE, RTLNMUTE)
are "Left HPOUT Negative To Right HPOUT Mute" and "Right HPOUT Negative
To Left HPOUT Mute" in the A23 and A33 user manuals and the V3s
datasheet (0 = mute, the reset value). The driver defines them, but
nothing can set them.

The PocketGo S30 (A33) has a mono speaker amplifier bridged across HPL
and HPR. With the same signal on both outputs it gets very little;
setting bit 1 makes it clearly louder, which is what the board needs.

Expose each bit as its own switch, "Headphone L to R Inversion Playback
Switch" and "Headphone R to L Inversion Playback Switch". Both default
to off (the reset value), so nothing changes for existing boards.

Signed-off-by: Romain TISSERAND <romain.tisserand@xxxxxxxxx>
---
Changes in v2:
- Two independent switches instead of one enum that kept both bits from
being set together (Mark Brown). With both bits set the S30 speaker
goes silent (results below), which does no harm, so there is no reason
to forbid it in the driver.
- Commit message: describe the bits by their manual names and what the
S30 needs, without a signal model I cannot back up.
- Link to v1: https://lore.kernel.org/r/20261103133935.2892210-1-romain.tisserand@xxxxxxxxx

Notes:
- Testing: built with W=1 for arm (multi_v7_defconfig) and arm64
(defconfig), SND_SUN8I_CODEC_ANALOG=m, and =y in the A33 kernel
below, no warnings. On a PocketGo S30 (A33, mono speaker amplifier bridged
across HPL and HPR) on 7.3.1, stereo path (AIF1 DA0 "Stereo", headphone
source DAC), 440 Hz tone on both channels, listening to the speaker:
both switches off (PAEN_HP_CTRL 0xf4): quiet; "L to R" on (0xf6):
clearly louder; both on (0xf7): silent apart from a few clicks. (The
test kernel had longer control names, which ALSA truncated; this
version only shortens them.)
Before this version, the same bits written by hand while playing, with
a second tone on the left channel only:

bits 1:0 both channels left channel only
00 normal normal
10 louder silent
01 loud loud
11 silent silent

- The A23 shares this code path; its user manual (v1.0, PAEN_HP_CTRL)
documents the same two bits, with the same names and reset value.
- Tool disclosure: this patch was prepared with Claude Opus 5.5
(Anthropic) as a coding assistant, in an interactive session where I
asked it to get the PocketGo S30 speaker working. It ran the register
tests above while I listened, found the two unused bits in the A33
manual and drafted the change and the message. I reviewed and
understand the change and tested it as described above.

sound/soc/sunxi/sun8i-codec-analog.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/sound/soc/sunxi/sun8i-codec-analog.c b/sound/soc/sunxi/sun8i-codec-analog.c
index 3335855c6311..e24fd7bd0613 100644
--- a/sound/soc/sunxi/sun8i-codec-analog.c
+++ b/sound/soc/sunxi/sun8i-codec-analog.c
@@ -323,6 +323,13 @@ static const struct snd_kcontrol_new sun8i_codec_headphone_controls[] = {
SUN8I_ADDA_DAC_PA_SRC,
SUN8I_ADDA_DAC_PA_SRC_LHPPAMUTE,
SUN8I_ADDA_DAC_PA_SRC_RHPPAMUTE, 1, 0),
+ /* inverted left to the right output, and the reverse */
+ SOC_SINGLE("Headphone L to R Inversion Playback Switch",
+ SUN8I_ADDA_PAEN_HP_CTRL,
+ SUN8I_ADDA_PAEN_HP_CTRL_LTRNMUTE, 1, 0),
+ SOC_SINGLE("Headphone R to L Inversion Playback Switch",
+ SUN8I_ADDA_PAEN_HP_CTRL,
+ SUN8I_ADDA_PAEN_HP_CTRL_RTLNMUTE, 1, 0),
};

static const char * const sun8i_codec_hp_src_enum_text[] = {

base-commit: 9f961caa18fc4678067232f8f021a23cb1588de4
--
2.43.0