Skip to contentSkip to conversation

ALSA: hda/conexant: Fix headset auto detect fail in cx8070 and SN6140

PATCH 刘博 2 participants 2 messages Jan 8, 2024 Sound

lore
Share & tools
lore

刘博

author
#0 lore raw

hi Takashi Iwai,
Thank you very much for your patient guidance. Below is the reply to
the question, please kindly correct it, thanks.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static void cx_fixup_headset_recog(struct hda_codec *codec) {
+	unsigned int mic_persent;
+
+	/* fix some headset type recognize fail issue, such as EDIFIER

headset */

Review

Quoted 3 lines
(quoted diff) +3 -0
+	snd_hda_codec_write(codec, 0x1c, 0, 0x320, 0x010);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x4f0, 0x0eb);

Please use the defined verbs in sound/hda_verbs.h.
The arguments (0x320, 0x010) are (AC_VERB_SET_AMP_GAIN_MUTE, 0x2010) etc.

Re: (0x1c, 0x320) is not amp gain register, but vendor defined register as rx control register. Use AC_VERB_SET_AMP_GAIN_MUTE will confused. It's similar to 0x4f0 and 0xca0.

Also, it's still not clear what if other nodes are used for headphone and mic pins -- or when either only headphone or only mic is present. A rare case, but we need to cover.

Re: in cx8070 and sn6140, only 0x16 and 0x19 can be used together as headset. Other nodes can be used separately as headphones or microphones, but not as headset,
so their configuration will not interfere with the type detection of headset.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* fix reboot headset type recognize fail issue */
+	mic_persent = snd_hda_codec_read(codec, 0x19, 0,

AC_VERB_GET_PIN_SENSE, 0x0);

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (mic_persent&0x80000000)

A coding style problem. Similar issues seen in a few other places, too. Consult scripts/checkpatch.pl.

Re: was & need space? I have checked with scripts/checkpatch.pl before submitting the patch and there are no warnings or errors.

Review

Quoted 7 lines
(quoted diff) +7 -0
+static void cx_process_headset_plugin(struct hda_codec *codec) {
+	unsigned int val;
+	unsigned int count = 0;
+
+	/* Wait headset detect done. */
+	do {
+		val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);

Use the verb: AC_VERB_GET_PROC_COEF, 0xa000.
At best, define the COEF values 0xa000 and 0xb000, and the corresponding value bits, too.

Re: (0x1c, 0xca0) is not COEF register, but vendor defined register as jacksense register.

Review

Quoted 6 lines
(quoted diff) +6 -0
+static void cx_update_headset_mic_vref(struct hda_codec *codec, 
+unsigned int res) {
+	unsigned int phone_present, mic_persent, phone_tag, mic_tag;
+	struct conexant_spec *spec = codec->spec;
+
+	/* In cx8070 and sn6140, headset is fixed to use node 16 and node

19.

Is it really guaranteed? IMO, we should check the pin configs beforehand at the parsing time.

Re: in cx8070 and sn6140, only 0x16 and 0x19 can be used together as headset. The node 16 can only be config to headphone or disable, The node 19 can only be config to microphone or disable. Only node 16 and node 19 both enable, the patch will process.

Best Regards
Bo Liu

-----邮件原件-----
发件人: Takashi Iwai <[email protected]>
发送时间: 2024年1月6日 1:02
收件人: bo liu <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]
主题: Re: [PATCH] ALSA: hda/conexant: Fix headset auto detect fail in cx8070 and SN6140

Quoted 3 lines · bo liu

When OMTP headset plugin the headset jack of CX8070 and SN6160 sound cards, the headset type detection circuit will recognize the headset type

as CTIA.

Quoted 11 lines

At this point, plugout and plugin the headset will get the correct headset type as OMTP.
The reason for the failure of headset type recognition is that the sound card creation will enable the VREF voltage of the headset mic, which interferes with the headset type automatic detection circuit. Plugout and plugin the headset will restart the headset detection and get the correct headset type.
The patch is disable the VREF voltage when the headset is not present, and will enable the VREF voltage when the headset is present.

Please put the revision number to the subject prefix, i.e. "Subject: [PATCH v3] ALSA: hda/conexant: ...."

Review

Quoted 4 lines
(quoted diff) +4 -0
+static void cx_fixup_headset_recog(struct hda_codec *codec) {
+	unsigned int mic_persent;
+
+	/* fix some headset type recognize fail issue, such as EDIFIER

headset */

Review

Quoted 3 lines
(quoted diff) +3 -0
+	snd_hda_codec_write(codec, 0x1c, 0, 0x320, 0x010);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x4f0, 0x0eb);

Please use the defined verbs in sound/hda_verbs.h.
The arguments (0x320, 0x010) are (AC_VERB_SET_AMP_GAIN_MUTE, 0x2010) etc.

Also, it's still not clear what if other nodes are used for headphone and mic pins -- or when either only headphone or only mic is present. A rare case, but we need to cover.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* fix reboot headset type recognize fail issue */
+	mic_persent = snd_hda_codec_read(codec, 0x19, 0,

AC_VERB_GET_PIN_SENSE, 0x0);

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (mic_persent&0x80000000)

A coding style problem. Similar issues seen in a few other places, too. Consult scripts/checkpatch.pl.

Review

Quoted 5 lines
(quoted diff) +5 -0
+enum {
+	CX_HEADSET_NOPRESENT = 0,
+	CX_HEADSET_PARTPRESENT,
+	CX_HEADSET_ALLPRESENT,
+};

This should be defined earlier. You can use the enum type for spec->headset_present_flag, too.

Review

Quoted 7 lines
(quoted diff) +7 -0
+static void cx_process_headset_plugin(struct hda_codec *codec) {
+	unsigned int val;
+	unsigned int count = 0;
+
+	/* Wait headset detect done. */
+	do {
+		val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);

Use the verb: AC_VERB_GET_PROC_COEF, 0xa000.
At best, define the COEF values 0xa000 and 0xb000, and the corresponding value bits, too.

Review

Quoted 6 lines
(quoted diff) +6 -0
+static void cx_update_headset_mic_vref(struct hda_codec *codec, 
+unsigned int res) {
+	unsigned int phone_present, mic_persent, phone_tag, mic_tag;
+	struct conexant_spec *spec = codec->spec;
+
+	/* In cx8070 and sn6140, headset is fixed to use node 16 and node

19.

Is it really guaranteed? IMO, we should check the pin configs beforehand at the parsing time.

thanks,

Takashi

#1 lore raw
Quoted 17 lines · 刘博

hi Takashi Iwai,
Thank you very much for your patient guidance. Below is the reply to
the question, please kindly correct it, thanks.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static void cx_fixup_headset_recog(struct hda_codec *codec) {
+	unsigned int mic_persent;
+
+	/* fix some headset type recognize fail issue, such as EDIFIER

headset */

Review

Quoted 3 lines
(quoted diff) +3 -0
+	snd_hda_codec_write(codec, 0x1c, 0, 0x320, 0x010);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
+	snd_hda_codec_write(codec, 0x1c, 0, 0x4f0, 0x0eb);

Please use the defined verbs in sound/hda_verbs.h.
The arguments (0x320, 0x010) are (AC_VERB_SET_AMP_GAIN_MUTE, 0x2010) etc.

Quoted 3 lines

Re: (0x1c, 0x320) is not amp gain register, but vendor defined register as rx control register. Use AC_VERB_SET_AMP_GAIN_MUTE will confused. It's similar to 0x4f0 and 0xca0.

Ah interesting. But the verb is actually seen as AC_VERB_SET_AMP_GAIN_MUTE -- although the resultant bits seem invalid.

HD-audio combines the verb and the value into 20 bits, e.g. (0x320, 0x10) is composed as 0x32010, and (0x3b0, 0xe10) is 0x3be10. 0x3xx is translated as SET_AMP_GAIN_MUTE, but in your case, 0x32010 leaves 0 to both the input/output bits (bits 14 and 15), which makes it as invalid.

0x3be10 is another invalid verb, which sets SET_AMP_GAIN_MUTE with OUTPUT, but it sets both LEFT and RIGHT, and passes a high index (14).

And, what actually (0x4f0, 0x0eb) does? It's composed as 0x4f0eb, and in this case, it's a valid verb (SET_PROC_COEF + 0xf0eb). But COEF is vendor-specific, so it can be translated in everything the chip wants.

So, if those verbs are vendor-specific ones, please define them and/or give proper comments to explain what they do for each.

Quoted 9 lines

Also, it's still not clear what if other nodes are used for headphone and mic pins -- or when either only headphone or only mic is present. A rare case, but we need to cover.

Re: in cx8070 and sn6140, only 0x16 and 0x19 can be used together as headset. Other nodes can be used separately as headphones or microphones, but not as headset,
so their configuration will not interfere with the type detection of headset.

OK, then explain this in comments, too (that we blindly assume those pins).

Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* fix reboot headset type recognize fail issue */
+	mic_persent = snd_hda_codec_read(codec, 0x19, 0,

AC_VERB_GET_PIN_SENSE, 0x0);

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (mic_persent&0x80000000)

A coding style problem. Similar issues seen in a few other places, too. Consult scripts/checkpatch.pl.

Re: was & need space? I have checked with scripts/checkpatch.pl before submitting the patch and there are no warnings or errors.

Yes. Please put spaces around the operators.

Quoted 23 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static void cx_process_headset_plugin(struct hda_codec *codec) {
+	unsigned int val;
+	unsigned int count = 0;
+
+	/* Wait headset detect done. */
+	do {
+		val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);

Use the verb: AC_VERB_GET_PROC_COEF, 0xa000.
At best, define the COEF values 0xa000 and 0xb000, and the corresponding value bits, too.

Re: (0x1c, 0xca0) is not COEF register, but vendor defined register as jacksense register.

Review

Quoted 6 lines
(quoted diff) +6 -0
+static void cx_update_headset_mic_vref(struct hda_codec *codec, 
+unsigned int res) {
+	unsigned int phone_present, mic_persent, phone_tag, mic_tag;
+	struct conexant_spec *spec = codec->spec;
+
+	/* In cx8070 and sn6140, headset is fixed to use node 16 and node

19.

Quoted 7 lines

Is it really guaranteed? IMO, we should check the pin configs beforehand at the parsing time.

Re: in cx8070 and sn6140, only 0x16 and 0x19 can be used together as headset. The node 16 can only be config to headphone or disable, The node 19 can only be config to microphone or disable. Only node 16 and node 19 both enable, the patch will process.

Then we still might need a check for the condition?

thanks,

Takashi