2121#include "hda_jack.h"
2222#include "hda_generic.h"
2323
24- enum {
25- CX_HEADSET_NOPRESENT = 0 ,
26- CX_HEADSET_PARTPRESENT ,
27- CX_HEADSET_ALLPRESENT ,
28- };
29-
3024struct conexant_spec {
3125 struct hda_gen_spec gen ;
3226
@@ -48,7 +42,6 @@ struct conexant_spec {
4842 unsigned int gpio_led ;
4943 unsigned int gpio_mute_led_mask ;
5044 unsigned int gpio_mic_led_mask ;
51- unsigned int headset_present_flag ;
5245 bool is_cx8070_sn6140 ;
5346};
5447
@@ -250,48 +243,19 @@ static void cx_process_headset_plugin(struct hda_codec *codec)
250243 }
251244}
252245
253- static void cx_update_headset_mic_vref (struct hda_codec * codec , unsigned int res )
246+ static void cx_update_headset_mic_vref (struct hda_codec * codec , struct hda_jack_callback * event )
254247{
255- unsigned int phone_present , mic_persent , phone_tag , mic_tag ;
256- struct conexant_spec * spec = codec -> spec ;
248+ unsigned int mic_present ;
257249
258250 /* In cx8070 and sn6140, the node 16 can only be config to headphone or disabled,
259251 * the node 19 can only be config to microphone or disabled.
260252 * Check hp&mic tag to process headset pulgin&plugout.
261253 */
262- phone_tag = snd_hda_codec_read (codec , 0x16 , 0 , AC_VERB_GET_UNSOLICITED_RESPONSE , 0x0 );
263- mic_tag = snd_hda_codec_read (codec , 0x19 , 0 , AC_VERB_GET_UNSOLICITED_RESPONSE , 0x0 );
264- if ((phone_tag & (res >> AC_UNSOL_RES_TAG_SHIFT )) ||
265- (mic_tag & (res >> AC_UNSOL_RES_TAG_SHIFT ))) {
266- phone_present = snd_hda_codec_read (codec , 0x16 , 0 , AC_VERB_GET_PIN_SENSE , 0x0 );
267- if (!(phone_present & AC_PINSENSE_PRESENCE )) {/* headphone plugout */
268- spec -> headset_present_flag = CX_HEADSET_NOPRESENT ;
269- snd_hda_codec_write (codec , 0x19 , 0 , AC_VERB_SET_PIN_WIDGET_CONTROL , 0x20 );
270- return ;
271- }
272- if (spec -> headset_present_flag == CX_HEADSET_NOPRESENT ) {
273- spec -> headset_present_flag = CX_HEADSET_PARTPRESENT ;
274- } else if (spec -> headset_present_flag == CX_HEADSET_PARTPRESENT ) {
275- mic_persent = snd_hda_codec_read (codec , 0x19 , 0 ,
276- AC_VERB_GET_PIN_SENSE , 0x0 );
277- /* headset is present */
278- if ((phone_present & AC_PINSENSE_PRESENCE ) &&
279- (mic_persent & AC_PINSENSE_PRESENCE )) {
280- cx_process_headset_plugin (codec );
281- spec -> headset_present_flag = CX_HEADSET_ALLPRESENT ;
282- }
283- }
284- }
285- }
286-
287- static void cx_jack_unsol_event (struct hda_codec * codec , unsigned int res )
288- {
289- struct conexant_spec * spec = codec -> spec ;
290-
291- if (spec -> is_cx8070_sn6140 )
292- cx_update_headset_mic_vref (codec , res );
293-
294- snd_hda_jack_unsol_event (codec , res );
254+ mic_present = snd_hda_codec_read (codec , 0x19 , 0 , AC_VERB_GET_PIN_SENSE , 0x0 );
255+ if (!(mic_present & AC_PINSENSE_PRESENCE )) /* mic plugout */
256+ snd_hda_codec_write (codec , 0x19 , 0 , AC_VERB_SET_PIN_WIDGET_CONTROL , 0x20 );
257+ else
258+ cx_process_headset_plugin (codec );
295259}
296260
297261static int cx_auto_suspend (struct hda_codec * codec )
@@ -305,7 +269,7 @@ static const struct hda_codec_ops cx_auto_patch_ops = {
305269 .build_pcms = snd_hda_gen_build_pcms ,
306270 .init = cx_auto_init ,
307271 .free = cx_auto_free ,
308- .unsol_event = cx_jack_unsol_event ,
272+ .unsol_event = snd_hda_jack_unsol_event ,
309273 .suspend = cx_auto_suspend ,
310274 .check_power_status = snd_hda_gen_check_power_status ,
311275};
@@ -1163,7 +1127,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
11631127 case 0x14f11f86 :
11641128 case 0x14f11f87 :
11651129 spec -> is_cx8070_sn6140 = true;
1166- spec -> headset_present_flag = CX_HEADSET_NOPRESENT ;
1130+ snd_hda_jack_detect_enable_callback ( codec , 0x19 , cx_update_headset_mic_vref ) ;
11671131 break ;
11681132 }
11691133
0 commit comments