Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] correct boot value
@ 2025-06-09  6:53 feng.liu
  2025-06-09  8:03 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: feng.liu @ 2025-06-09  6:53 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-sound, linux-kernel, feng.liu

  Read the Boost Level configured for input pins in the BIOS 
init verbs, and restore these settings during audio recording. 
This addresses issues of low recording volume or excessive 
background noise caused by incorrect boost configurations.
  Compare with the last commit:
  1.Correct the function definition; cxt_get_default_capture_gain_boost 
does not require a return value.
  2.Check array indices to prevent operations causing memory out-of-bounds
access.

Signed-off-by: feng.liu <feng.liu@senarytech.com>
---
 sound/pci/hda/patch_conexant.c | 49 ++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 34874039ad4..95c76bb8e3c 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -43,6 +43,8 @@ struct conexant_spec {
 	unsigned int gpio_mute_led_mask;
 	unsigned int gpio_mic_led_mask;
 	bool is_cx8070_sn6140;
+
+	unsigned char init_imux_boost_val[HDA_MAX_NUM_INPUTS];
 };
 
 
@@ -1178,6 +1180,51 @@ static void add_cx5051_fake_mutes(struct hda_codec *codec)
 	spec->gen.dac_min_mute = true;
 }
 
+static void cxt_fixed_mic_boost(struct hda_codec *codec,
+	unsigned char node_id,
+	unsigned char mic_boost)
+{
+	unsigned char value = 0;
+
+	value = snd_hda_codec_read(codec, node_id, 0, AC_VERB_GET_AMP_GAIN_MUTE, 0);
+	if (value != mic_boost)
+		snd_hda_codec_amp_stereo(codec, node_id, HDA_INPUT, 0, HDA_AMP_VOLMASK, mic_boost);
+}
+
+static void cxt_cap_sync_hook(struct hda_codec *codec,
+					 struct snd_kcontrol *kcontrol,
+					 struct snd_ctl_elem_value *ucontrol)
+{
+	struct conexant_spec *spec = codec->spec;
+	hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
+
+	if (spec->init_imux_boost_val[mux_pin])
+		cxt_fixed_mic_boost(codec, mux_pin, spec->init_imux_boost_val[mux_pin]);
+}
+
+static void cxt_get_default_capture_gain_boost(struct hda_codec *codec)
+{
+	struct conexant_spec *spec = codec->spec;
+	int i;
+	unsigned int boost;
+
+	spec->init_imux_boost_val[0] = 0;
+	for (i = 0; i < HDA_MAX_NUM_INPUTS; i++) {
+		if (spec->gen.imux_pins[i] == 0)
+			continue;
+
+		if (spec->gen.imux_pins[i] < HDA_MAX_NUM_INPUTS) {
+			boost = snd_hda_codec_read(codec, spec->gen.imux_pins[i],
+				0, AC_VERB_GET_AMP_GAIN_MUTE, 0);
+			spec->init_imux_boost_val[spec->gen.imux_pins[i]] = boost;
+			codec_info(codec, "%s, node_id = %x, mic_boost =%x", __func__,
+				spec->gen.imux_pins[i], boost);
+		}
+	}
+
+	spec->gen.cap_sync_hook = cxt_cap_sync_hook;
+}
+
 static int patch_conexant_auto(struct hda_codec *codec)
 {
 	struct conexant_spec *spec;
@@ -1245,6 +1292,8 @@ static int patch_conexant_auto(struct hda_codec *codec)
 	if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
 		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
 
+	cxt_get_default_capture_gain_boost(codec);
+
 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
 
 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-09  8:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09  6:53 [PATCH] correct boot value feng.liu
2025-06-09  8:03 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox