Skip to contentSkip to conversation

Initialize the gain and boost values of the ADC in the SN6180 chip to achieve a better recording experience.

PATCH In review bo liu 2 participants 2 messages Mar 25, 2025 Sound

lore
Share & tools
lore

bo liu

author
#0 lore raw

PATCH v4 1/1 Initialize the gain and boost values of the ADC in the SN6180 chip to achieve a better recording experience.

---
 sound/pci/hda/patch_conexant.c | 37 ++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
sound/pci/hda/patch_conexant.c +37 -0
index 34874039ad45..7017db4a0fee 100644
@@ -185,6 +185,40 @@ static void cx_fixup_headset_recog(struct hda_codec *codec)
 		snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
 }
 
+static void cxt_setup_capture_default_boost_gain(struct hda_codec *codec)
+{
+	struct conexant_spec *spec = codec->spec;
+	struct hda_gen_spec *gen = &(spec->gen);
+	hda_nid_t adc_id = 0, nid = 0;
+	int nids;
+	size_t i = 0;
+
+	for (i = 0; i < gen->num_all_adcs; i++) {
+		int index;
+
+		adc_id = gen->all_adcs[i];
+
+		index = snd_hda_codec_read(codec, adc_id, 0, AC_VERB_GET_CONNECT_SEL, 0);
+		nids = snd_hda_codec_read(codec, adc_id, 0, AC_VERB_GET_CONNECT_LIST, 0);
+		nid = ((nids & (0xFF << (8*index))) >> (8*index));
+
+		if (nid < codec->core.start_nid || nid > codec->core.end_nid) {
+			codec_err(codec, "Error, invalid nid 0x%02x.\n", nid);
+			continue;
+		}
+
+		snd_hda_codec_write(codec, adc_id, 0, (0x370|(index&0xF)), 0x4A);
+		snd_hda_codec_write(codec, nid, 0, 0x370, 0x2);
+		codec_dbg(codec, "ADC 0x%02x, nid=0x%02x are set. Boost=2, gain=0x4A.\n",
+			adc_id, nid);
+	}
+}
+
+static void cxt_init_capture_boost_gain(struct hda_codec *codec)
+{
+	cxt_setup_capture_default_boost_gain(codec);
+}
+
 static int cx_auto_init(struct hda_codec *codec)
 {
 	struct conexant_spec *spec = codec->spec;
@@ -198,6 +232,9 @@ static int cx_auto_init(struct hda_codec *codec)
 	if (spec->is_cx8070_sn6140)
 		cx_fixup_headset_recog(codec);
 
+	if (codec->core.vendor_id == 0x14f120d1) //SN6180
+		cxt_init_capture_boost_gain(codec);
+
 	return 0;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · bo liu

First off, could you use a proper subject line? It should be more concise, and have a prefix such as "ALSA: hda/conexant:".

Then put more information in the patch description, instead of putting to the subject line.

About the code change:

Review

Quoted 3 lines
(quoted diff) +2 -0
+static void cxt_setup_capture_default_boost_gain(struct hda_codec *codec)
+{

Better to give more comments about what this function actually does.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 191

Quoted 2 lines
sound/pci/hda/patch_conexant.c +2 -0
+	struct conexant_spec *spec = codec->spec;
+	struct hda_gen_spec *gen = &(spec->gen);

No need for parentheses.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 192

Quoted 1 line
sound/pci/hda/patch_conexant.c +1 -0
+	hda_nid_t adc_id = 0, nid = 0;

Why initializing those?

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 193

Quoted 1 line
sound/pci/hda/patch_conexant.c +1 -0
+	int nids;

This should be either u32 or unsigned int.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 194

Quoted 1 line
sound/pci/hda/patch_conexant.c +1 -0
+	size_t i = 0;

It's superfluous initialization.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 203

Quoted 9 lines
sound/pci/hda/patch_conexant.c +9 -0
+
+	for (i = 0; i < gen->num_all_adcs; i++) {
+		int index;
+
+		adc_id = gen->all_adcs[i];
+
+		index = snd_hda_codec_read(codec, adc_id, 0, AC_VERB_GET_CONNECT_SEL, 0);
+		nids = snd_hda_codec_read(codec, adc_id, 0, AC_VERB_GET_CONNECT_LIST, 0);
+		nid = ((nids & (0xFF << (8*index))) >> (8*index));

It's simpler and clearer to do right-shift at first, then mask.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 210

Quoted 6 lines
sound/pci/hda/patch_conexant.c +6 -0
+		if (nid < codec->core.start_nid || nid > codec->core.end_nid) {
+			codec_err(codec, "Error, invalid nid 0x%02x.\n", nid);
+			continue;
+		}
+
+		snd_hda_codec_write(codec, adc_id, 0, (0x370|(index&0xF)), 0x4A);

Too cryptic. Use the defined verbs.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 211

Quoted 1 line
sound/pci/hda/patch_conexant.c +1 -0
+		snd_hda_codec_write(codec, nid, 0, 0x370, 0x2);

Ditto.

sound/pci/hda/patch_conexant.c static void cx_fixup_headset_recog(struct hda_codec *codec) · line 220

Quoted 7 lines
sound/pci/hda/patch_conexant.c +7 -0
+	}
+}
+
+static void cxt_init_capture_boost_gain(struct hda_codec *codec)
+{
+	cxt_setup_capture_default_boost_gain(codec);
+}

Why nested calls...?

thanks,

Takashi