Lines Matching +full:headset +full:- +full:codec
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HD audio codec driver for Conexant HDA audio codec
7 * Tobin Davis <tdavis@dsl-only.net>
63 spec->gen.beep_nid = nid;
65 knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
68 return -ENOMEM;
69 knew->private_value = beep_amp;
74 static int cx_auto_parse_beep(struct hda_codec *codec)
76 struct conexant_spec *spec = codec->spec;
79 for_each_hda_codec_node(nid, codec)
80 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
85 #define cx_auto_parse_beep(codec) 0
93 static void cx_auto_parse_eapd(struct hda_codec *codec)
95 struct conexant_spec *spec = codec->spec;
98 for_each_hda_codec_node(nid, codec) {
99 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
101 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
103 spec->eapds[spec->num_eapds++] = nid;
104 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
114 if (spec->num_eapds > 2)
115 spec->dynamic_eapd = 1;
118 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
123 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
124 snd_hda_codec_write(codec, pins[i], 0,
133 struct hda_codec *codec = private_data;
134 struct conexant_spec *spec = codec->spec;
136 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
143 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
144 struct conexant_spec *spec = codec->spec;
146 snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
152 static void cxt_init_gpio_led(struct hda_codec *codec)
154 struct conexant_spec *spec = codec->spec;
155 unsigned int mask = spec->gpio_mute_led_mask | spec->gpio_mic_led_mask;
158 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK,
160 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION,
162 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
163 spec->gpio_led);
167 static void cx_fixup_headset_recog(struct hda_codec *codec)
171 /* fix some headset type recognize fail issue, such as EDIFIER headset */
173 snd_hda_codec_write(codec, 0x1c, 0, 0x320, 0x010);
174 /* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias register
177 snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10);
178 /* fix reboot headset type recognize fail issue */
179 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0);
181 /* enable headset mic VREF */
182 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
184 /* disable headset mic VREF */
185 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
188 static int cx_init(struct hda_codec *codec)
190 struct conexant_spec *spec = codec->spec;
191 snd_hda_gen_init(codec);
192 if (!spec->dynamic_eapd)
193 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
195 cxt_init_gpio_led(codec);
196 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
198 if (spec->is_cx11880_sn6140)
199 cx_fixup_headset_recog(codec);
204 static void cx_auto_shutdown(struct hda_codec *codec)
206 struct conexant_spec *spec = codec->spec;
208 /* Turn the problematic codec into D3 to avoid spurious noises
210 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false);
213 static void cx_remove(struct hda_codec *codec)
215 cx_auto_shutdown(codec);
216 snd_hda_gen_remove(codec);
219 static void cx_process_headset_plugin(struct hda_codec *codec)
224 /* Wait headset detect done. */
226 val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0);
228 codec_dbg(codec, "headset type detect done!\n");
234 val = snd_hda_codec_read(codec, 0x1c, 0, 0xcb0, 0x0);
236 codec_dbg(codec, "headset plugin, type is CTIA\n");
237 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
239 codec_dbg(codec, "headset plugin, type is OMTP\n");
240 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24);
242 codec_dbg(codec, "headphone plugin\n");
246 static void cx_update_headset_mic_vref(struct hda_codec *codec, struct hda_jack_callback *event)
252 * Check hp&mic tag to process headset plugin & plugout.
254 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0);
256 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20);
258 cx_process_headset_plugin(codec);
261 static int cx_suspend(struct hda_codec *codec)
263 cx_auto_shutdown(codec);
268 * pin fix-up
310 static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
313 struct conexant_spec *spec = codec->spec;
314 spec->gen.inv_dmic_split = 1;
318 static void cxt_fixup_update_pinctl(struct hda_codec *codec,
323 * This is the value stored in the codec register after
326 snd_hda_set_pin_ctl_cache(codec, 0x1d, AC_PINCTL_HP_EN);
330 static void cxt5066_increase_mic_boost(struct hda_codec *codec,
336 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
343 static void cxt_update_headset_mode(struct hda_codec *codec)
345 /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
348 struct conexant_spec *spec = codec->spec;
349 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
351 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
353 for (i = 0; i < cfg->num_inputs; i++)
354 if (cfg->inputs[i].pin == mux_pin) {
355 mic_mode = !!cfg->inputs[i].is_headphone_mic;
360 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
361 spec->gen.hp_jack_present = false;
363 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
364 spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
367 snd_hda_gen_update_outputs(codec);
370 static void cxt_update_headset_mode_hook(struct hda_codec *codec,
374 cxt_update_headset_mode(codec);
377 static void cxt_fixup_headphone_mic(struct hda_codec *codec,
380 struct conexant_spec *spec = codec->spec;
384 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
385 snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410);
388 WARN_ON(spec->gen.cap_sync_hook);
389 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
390 spec->gen.automute_hook = cxt_update_headset_mode;
393 cxt_update_headset_mode(codec);
398 static void cxt_fixup_headset_mic(struct hda_codec *codec,
401 struct conexant_spec *spec = codec->spec;
405 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
412 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
419 #define update_mic_pin(codec, nid, val) \
420 snd_hda_codec_write_cache(codec, nid, 0, \
432 static void olpc_xo_update_mic_boost(struct hda_codec *codec)
434 struct conexant_spec *spec = codec->spec;
440 if (!spec->dc_enable)
441 val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
442 snd_hda_codec_write(codec, 0x17, 0,
447 static void olpc_xo_update_mic_pins(struct hda_codec *codec)
449 struct conexant_spec *spec = codec->spec;
453 cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
455 /* Set up mic pins for port-B, C and F dynamically as the recording
458 if (!spec->dc_enable) {
460 update_mic_pin(codec, 0x1e, 0);
461 snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
470 update_mic_pin(codec, 0x1a, spec->recording ?
471 snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
472 update_mic_pin(codec, 0x1b, spec->recording ?
473 snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
475 path = snd_hda_get_path_from_idx(codec, cur_input);
477 snd_hda_activate_path(codec, path, true, false);
480 path = snd_hda_get_path_from_idx(codec, cur_input);
482 snd_hda_activate_path(codec, path, false, false);
489 if (spec->recording)
490 val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
493 update_mic_pin(codec, 0x1a, val);
494 update_mic_pin(codec, 0x1b, 0);
496 update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
497 snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
502 static void olpc_xo_automic(struct hda_codec *codec,
505 struct conexant_spec *spec = codec->spec;
508 if (!spec->dc_enable)
509 snd_hda_gen_mic_autoswitch(codec, jack);
510 olpc_xo_update_mic_pins(codec);
511 if (spec->dc_enable)
512 olpc_xo_update_mic_boost(codec);
517 struct hda_codec *codec,
521 struct conexant_spec *spec = codec->spec;
523 /* toggle spec->recording flag and update mic pins accordingly
528 spec->recording = 1;
529 olpc_xo_update_mic_pins(codec);
532 spec->recording = 0;
533 olpc_xo_update_mic_pins(codec);
541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
542 struct conexant_spec *spec = codec->spec;
543 ucontrol->value.integer.value[0] = spec->dc_enable;
550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
551 struct conexant_spec *spec = codec->spec;
552 int dc_enable = !!ucontrol->value.integer.value[0];
554 if (dc_enable == spec->dc_enable)
557 spec->dc_enable = dc_enable;
558 olpc_xo_update_mic_pins(codec);
559 olpc_xo_update_mic_boost(codec);
566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
567 struct conexant_spec *spec = codec->spec;
568 ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582 struct conexant_spec *spec = codec->spec;
586 idx = ucontrol->value.enumerated.item[0];
587 if (idx >= imux->num_items)
588 idx = imux->num_items - 1;
589 if (spec->dc_input_bias == idx)
592 spec->dc_input_bias = idx;
593 if (spec->dc_enable)
594 olpc_xo_update_mic_pins(codec);
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct conexant_spec *spec = codec->spec;
625 if (ret > 0 && spec->dc_enable)
626 olpc_xo_update_mic_boost(codec);
630 static void cxt_fixup_olpc_xo(struct hda_codec *codec,
633 struct conexant_spec *spec = codec->spec;
640 spec->gen.mic_autoswitch_hook = olpc_xo_automic;
641 spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
642 spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
644 snd_hda_add_new_ctls(codec, olpc_xo_mixers);
648 * with the DC input range of the codec.
650 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
653 snd_array_for_each(&spec->gen.kctls, i, kctl) {
654 if (!strcmp(kctl->name, "Mic Boost Volume")) {
655 kctl->put = olpc_xo_mic_boost_put;
661 static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
664 struct conexant_spec *spec = codec->spec;
667 spec->mute_led_eapd = 0x1b;
668 spec->dynamic_eapd = true;
669 snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led);
677 static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
680 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
691 static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
694 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
701 static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec,
709 snd_hda_jack_set_gating_jack(codec, 0x19, 0x16);
713 static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask,
716 struct conexant_spec *spec = codec->spec;
717 unsigned int oldval = spec->gpio_led;
719 if (spec->mute_led_polarity)
723 spec->gpio_led |= mask;
725 spec->gpio_led &= ~mask;
726 codec_dbg(codec, "mask:%d enabled:%d gpio_led:%d\n",
727 mask, led_on, spec->gpio_led);
728 if (spec->gpio_led != oldval)
729 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
730 spec->gpio_led);
737 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
738 struct conexant_spec *spec = codec->spec;
740 cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness);
744 /* turn on/off mic-mute LED via GPIO per capture hook */
748 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
749 struct conexant_spec *spec = codec->spec;
751 cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness);
755 static void cxt_setup_mute_led(struct hda_codec *codec,
758 struct conexant_spec *spec = codec->spec;
760 spec->gpio_led = 0;
761 spec->mute_led_polarity = 0;
763 snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update);
764 spec->gpio_mute_led_mask = mute;
767 snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update);
768 spec->gpio_mic_led_mask = mic_mute;
772 static void cxt_setup_gpio_unmute(struct hda_codec *codec,
777 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
778 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_MASK, gpio_mute_mask);
779 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DIRECTION, gpio_mute_mask);
780 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_STICKY_MASK, 0);
784 static void cxt_fixup_mute_led_gpio(struct hda_codec *codec,
788 cxt_setup_mute_led(codec, 0x01, 0x02);
791 static void cxt_fixup_hp_zbook_mute_led(struct hda_codec *codec,
795 cxt_setup_mute_led(codec, 0x10, 0x20);
798 static void cxt_fixup_hp_a_u(struct hda_codec *codec,
804 cxt_setup_gpio_unmute(codec, 0x2);
810 { 0x17, 0x21a11000 }, /* dock-mic */
811 { 0x19, 0x2121103f }, /* dock-HP */
819 { 0x1a, 0x21a190f0 }, /* dock-mic */
820 { 0x1c, 0x212140ff }, /* dock-HP */
836 /* SuoWoSi/South-holding JS201D with sn6140 */
841 { 0x19, 0x03a11020 }, /* Headset Mic */
968 { 0x16, 0x21011020 }, /* line-out */
969 { 0x18, 0x2181103f }, /* line-in */
1032 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
1043 { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
1044 { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
1045 { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
1057 { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
1068 { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
1102 SND_PCI_QUIRK(0x14f1, 0x0252, "MBX-Z60MR100", CXT_FIXUP_HP_A_U),
1104 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
1112 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
1114 SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC),
1115 SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC),
1121 SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC),
1132 { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
1134 { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
1137 { .id = CXT_FIXUP_LENOVO_XPAD_ACPI, .name = "thinkpad-ideapad" },
1138 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
1139 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
1140 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
1141 { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
1142 { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" },
1143 { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" },
1144 { .id = CXT_FIXUP_HP_ZBOOK_MUTE_LED, .name = "hp-zbook-mute-led" },
1145 { .id = CXT_FIXUP_HP_MIC_NO_PRESENCE, .name = "hp-mic-fix" },
1146 { .id = CXT_PINCFG_LENOVO_NOTEBOOK, .name = "lenovo-20149" },
1147 { .id = CXT_PINCFG_SWS_JS201D, .name = "sws-js201d" },
1148 { .id = CXT_PINCFG_TOP_SPEAKER, .name = "sirius-top-speaker" },
1149 { .id = CXT_FIXUP_HP_A_U, .name = "HP-U-support" },
1153 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
1156 static void add_cx5051_fake_mutes(struct hda_codec *codec)
1158 struct conexant_spec *spec = codec->spec;
1165 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
1167 query_amp_caps(codec, *p, HDA_OUTPUT));
1168 spec->gen.dac_min_mute = true;
1171 static int cx_probe(struct hda_codec *codec, const struct hda_device_id *id)
1176 codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name);
1180 return -ENOMEM;
1181 snd_hda_gen_spec_init(&spec->gen);
1182 codec->spec = spec;
1185 switch (codec->core.vendor_id) {
1188 spec->is_cx11880_sn6140 = true;
1189 snd_hda_jack_detect_enable_callback(codec, 0x19, cx_update_headset_mic_vref);
1193 cx_auto_parse_eapd(codec);
1194 spec->gen.own_eapd_ctl = 1;
1196 switch (codec->core.vendor_id) {
1198 codec->single_adc_amp = 1;
1199 spec->gen.mixer_nid = 0x17;
1200 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1201 snd_hda_pick_fixup(codec, cxt5045_fixup_models,
1205 codec->pin_amp_workaround = 1;
1206 spec->gen.mixer_nid = 0x19;
1207 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1208 snd_hda_pick_fixup(codec, cxt5047_fixup_models,
1212 add_cx5051_fake_mutes(codec);
1213 codec->pin_amp_workaround = 1;
1214 snd_hda_pick_fixup(codec, cxt5051_fixup_models,
1218 codec->pin_amp_workaround = 1;
1219 spec->gen.mixer_nid = 0x22;
1220 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
1221 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1225 codec->power_save_node = 1;
1228 codec->pin_amp_workaround = 1;
1229 snd_hda_pick_fixup(codec, cxt5066_fixup_models,
1234 if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd)
1235 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
1237 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
1239 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
1240 spec->parse_flags);
1244 err = cx_auto_parse_beep(codec);
1248 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
1253 * which falls into the single-cmd mode.
1256 if (!codec->bus->core.sync_write) {
1257 codec_info(codec,
1259 codec->bus->core.sync_write = 1;
1260 codec->bus->allow_bus_reset = 1;
1263 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
1268 cx_remove(codec);
1326 MODULE_DESCRIPTION("Conexant HD-audio codec");