From 3b672c433cb43f44e229b37a1f48f2bbfc802c89 Mon Sep 17 00:00:00 2001 From: Daniel Jacob Chittoor Date: Sat, 25 Nov 2023 02:00:32 +0530 Subject: [PATCH] ASoC: aw882xx: Don't use max amplifier gain for AW882XX_RECEIVER_MODE In the case of Fairphone 4's stereo speaker setup, where one speaker also serves as the earpiece module, the earpiece is treated as a mono transmit source during standalone use, such as in VoIP calls. The current issue lies in the amplifier applying maximum gains regardless of whether it operates standalone or as part of a stereo setup which is not ideal considering the usecase. Controlling amplifier gains for a specific audio backend device via mixer paths is not possible, as the property exported by the amplifier gets overwritten by the kernelspace. When the "handset" device is being used the amplifier switches the working mode to "Rcv" as shown in [1], this patch checks whether the current working mode is "Rcv" and limits the gain being set to max. The more appropriate fix is adjusting digital RX volume or addressing and tuning the volume curves for the HANDSET backend on ACDBs. [1] https://github.com/WeAreFairphone/android_device_fairphone_FP4/blob/staging/lineage-19.1/audio/mixer_paths_lagoon_fp4.xml#L3428 --- sound/soc/codecs/aw882xx/aw882xx.c | 14 ++++++++++---- sound/soc/codecs/aw882xx/aw882xx.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/aw882xx/aw882xx.c b/sound/soc/codecs/aw882xx/aw882xx.c index cb84a35e1255..7d12821053b1 100644 --- a/sound/soc/codecs/aw882xx/aw882xx.c +++ b/sound/soc/codecs/aw882xx/aw882xx.c @@ -349,18 +349,24 @@ static int aw882xx_fade_in_out(struct aw882xx *aw882xx, bool fade_in) { int i = 0; uint32_t start_volume = 0; + int target_offset = 0; /*volume up*/ if (fade_in) { - for (i = AW_FADE_OUT_TARGET_VOL; i >= (int32_t)aw882xx->db_offset; + if (aw882xx->cfg_num != AW882XX_RECEIVER_MODE) { + target_offset = aw882xx->db_offset; + } else { + target_offset = AW_EARPIECE_MAX_GAIN; + } + for (i = AW_FADE_OUT_TARGET_VOL; i >= (int32_t)target_offset; i -= aw882xx->fade_step) { if (i < (int32_t)aw882xx->fade_step) - i = aw882xx->db_offset; + i = target_offset; aw882xx_set_volume(aw882xx, i); usleep_range(1400, 1600); } - if (i != (int32_t)aw882xx->db_offset) - aw882xx_set_volume(aw882xx, aw882xx->db_offset); + if (i != (int32_t)target_offset) + aw882xx_set_volume(aw882xx, target_offset); } else { /*volume down*/ aw882xx_get_volume(aw882xx, &start_volume); diff --git a/sound/soc/codecs/aw882xx/aw882xx.h b/sound/soc/codecs/aw882xx/aw882xx.h index 92cac5997ab3..393881197f98 100644 --- a/sound/soc/codecs/aw882xx/aw882xx.h +++ b/sound/soc/codecs/aw882xx/aw882xx.h @@ -32,6 +32,7 @@ #define AW882XX_CFG_NAME_MAX (64) #define AW_FADE_OUT_TARGET_VOL (90 * 2) +#define AW_EARPIECE_MAX_GAIN (40) #define AW882XX_VOLUME_STEP_DB (6 * 2) -- GitLab