1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * HD audio codec driver for Conexant HDA audio codec 4 * 5 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 6 * Takashi Iwai <tiwai@suse.de> 7 * Tobin Davis <tdavis@dsl-only.net> 8 */ 9 10 #include <linux/init.h> 11 #include <linux/delay.h> 12 #include <linux/slab.h> 13 #include <linux/module.h> 14 #include <sound/core.h> 15 #include <sound/jack.h> 16 17 #include <sound/hda_codec.h> 18 #include "hda_local.h" 19 #include "hda_auto_parser.h" 20 #include "hda_beep.h" 21 #include "hda_jack.h" 22 #include "generic.h" 23 24 struct conexant_spec { 25 struct hda_gen_spec gen; 26 27 /* extra EAPD pins */ 28 unsigned int num_eapds; 29 hda_nid_t eapds[4]; 30 bool dynamic_eapd; 31 hda_nid_t mute_led_eapd; 32 33 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ 34 35 /* OLPC XO specific */ 36 bool recording; 37 bool dc_enable; 38 unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */ 39 struct nid_path *dc_mode_path; 40 41 int mute_led_polarity; 42 unsigned int gpio_led; 43 unsigned int gpio_mute_led_mask; 44 unsigned int gpio_mic_led_mask; 45 bool is_cx11880_sn6140; 46 }; 47 48 49 #ifdef CONFIG_SND_HDA_INPUT_BEEP 50 /* additional beep mixers; private_value will be overwritten */ 51 static const struct snd_kcontrol_new cxt_beep_mixer[] = { 52 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 53 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 54 }; 55 56 static int set_beep_amp(struct conexant_spec *spec, hda_nid_t nid, 57 int idx, int dir) 58 { 59 struct snd_kcontrol_new *knew; 60 unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); 61 int i; 62 63 spec->gen.beep_nid = nid; 64 for (i = 0; i < ARRAY_SIZE(cxt_beep_mixer); i++) { 65 knew = snd_hda_gen_add_kctl(&spec->gen, NULL, 66 &cxt_beep_mixer[i]); 67 if (!knew) 68 return -ENOMEM; 69 knew->private_value = beep_amp; 70 } 71 return 0; 72 } 73 74 static int cx_auto_parse_beep(struct hda_codec *codec) 75 { 76 struct conexant_spec *spec = codec->spec; 77 hda_nid_t nid; 78 79 for_each_hda_codec_node(nid, codec) 80 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) 81 return set_beep_amp(spec, nid, 0, HDA_OUTPUT); 82 return 0; 83 } 84 #else 85 #define cx_auto_parse_beep(codec) 0 86 #endif 87 88 /* 89 * Automatic parser for CX20641 & co 90 */ 91 92 /* parse EAPDs */ 93 static void cx_auto_parse_eapd(struct hda_codec *codec) 94 { 95 struct conexant_spec *spec = codec->spec; 96 hda_nid_t nid; 97 98 for_each_hda_codec_node(nid, codec) { 99 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 100 continue; 101 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 102 continue; 103 spec->eapds[spec->num_eapds++] = nid; 104 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 105 break; 106 } 107 108 /* NOTE: below is a wild guess; if we have more than two EAPDs, 109 * it's a new chip, where EAPDs are supposed to be associated to 110 * pins, and we can control EAPD per pin. 111 * OTOH, if only one or two EAPDs are found, it's an old chip, 112 * thus it might control over all pins. 113 */ 114 if (spec->num_eapds > 2) 115 spec->dynamic_eapd = 1; 116 } 117 118 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 119 const hda_nid_t *pins, bool on) 120 { 121 int i; 122 for (i = 0; i < num_pins; i++) { 123 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 124 snd_hda_codec_write(codec, pins[i], 0, 125 AC_VERB_SET_EAPD_BTLENABLE, 126 on ? 0x02 : 0); 127 } 128 } 129 130 /* turn on/off EAPD according to Master switch */ 131 static void cx_auto_vmaster_hook(void *private_data, int enabled) 132 { 133 struct hda_codec *codec = private_data; 134 struct conexant_spec *spec = codec->spec; 135 136 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 137 } 138 139 /* turn on/off EAPD according to Master switch (inversely!) for mute LED */ 140 static int cx_auto_vmaster_mute_led(struct led_classdev *led_cdev, 141 enum led_brightness brightness) 142 { 143 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent); 144 struct conexant_spec *spec = codec->spec; 145 146 snd_hda_codec_write(codec, spec->mute_led_eapd, 0, 147 AC_VERB_SET_EAPD_BTLENABLE, 148 brightness ? 0x02 : 0x00); 149 return 0; 150 } 151 152 static void cxt_init_gpio_led(struct hda_codec *codec) 153 { 154 struct conexant_spec *spec = codec->spec; 155 unsigned int mask = spec->gpio_mute_led_mask | spec->gpio_mic_led_mask; 156 157 if (mask) 158 snd_hda_codec_set_gpio(codec, mask, mask, spec->gpio_led, 0); 159 } 160 161 static void cx_fixup_headset_recog(struct hda_codec *codec) 162 { 163 unsigned int mic_present; 164 165 /* set OFF voltage for DFET from -1.2V to -0.8V, set headset micbias register 166 * value adjustment trim from 2.2K ohms to 2.0K ohms. 167 */ 168 snd_hda_codec_write(codec, 0x1c, 0, 0x3b0, 0xe10); 169 /* fix reboot headset type recognize fail issue */ 170 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0); 171 if (mic_present & AC_PINSENSE_PRESENCE) 172 /* enable headset mic VREF */ 173 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24); 174 else 175 /* disable headset mic VREF */ 176 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20); 177 } 178 179 static int cx_init(struct hda_codec *codec) 180 { 181 struct conexant_spec *spec = codec->spec; 182 snd_hda_gen_init(codec); 183 if (!spec->dynamic_eapd) 184 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 185 186 cxt_init_gpio_led(codec); 187 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT); 188 189 if (spec->is_cx11880_sn6140) 190 cx_fixup_headset_recog(codec); 191 192 return 0; 193 } 194 195 static void cx_auto_shutdown(struct hda_codec *codec) 196 { 197 struct conexant_spec *spec = codec->spec; 198 199 /* Turn the problematic codec into D3 to avoid spurious noises 200 from the internal speaker during (and after) reboot */ 201 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false); 202 } 203 204 static void cx_remove(struct hda_codec *codec) 205 { 206 cx_auto_shutdown(codec); 207 snd_hda_gen_remove(codec); 208 } 209 210 static void cx_process_headset_detect_plug_type(struct hda_codec *codec) 211 { 212 unsigned int val; 213 unsigned int count = 0; 214 215 /* Wait headset detect done. */ 216 do { 217 val = snd_hda_codec_read(codec, 0x1c, 0, 0xca0, 0x0); 218 if (val & 0x080) { 219 codec_dbg(codec, "headset type detect done!\n"); 220 break; 221 } 222 msleep(20); 223 count++; 224 } while (count < 3); 225 val = snd_hda_codec_read(codec, 0x1c, 0, 0xcb0, 0x0); 226 if (val & 0xc00) { 227 codec_dbg(codec, "headset plugin, type is %s\n", 228 val & 0x800 ? "CTIA" : "OMTP"); 229 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24); 230 } else { 231 codec_dbg(codec, "headphone plugin\n"); 232 } 233 } 234 235 static void cx_update_headset_mic_vref(struct hda_codec *codec, struct hda_jack_callback *event) 236 { 237 unsigned int mic_present; 238 239 /* In cx11880 and sn6140, the node 16 can only be configured to headphone or disabled, 240 * the node 19 can only be configured to microphone or disabled. 241 * Check hp&mic tag to process headset plugin & plugout. 242 */ 243 mic_present = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0x0); 244 if (!(mic_present & AC_PINSENSE_PRESENCE)) { /* mic plugout */ 245 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20); 246 } else { 247 cx_process_headset_detect_plug_type(codec); 248 snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24); 249 } 250 } 251 252 #define SN6140_S3_AFG_D0_DELAY_MS 1000 253 254 static void cx_set_power_state(struct hda_codec *codec, hda_nid_t fg, 255 unsigned int power_state) 256 { 257 snd_hda_codec_write_sync(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state); 258 259 /* 260 * SN6140 may not respond to AFG D0 immediately after S3. 261 * Wait before the D0 verb so the power-state command itself succeeds. 262 */ 263 if (codec->core.vendor_id == 0x14f11f87 && 264 power_state == AC_PWRST_D0 && 265 codec->core.dev.power.power_state.event == PM_EVENT_RESUME) 266 msleep(SN6140_S3_AFG_D0_DELAY_MS); 267 268 snd_hda_codec_set_power_to_all(codec, fg, power_state); 269 } 270 271 static int cx_suspend(struct hda_codec *codec) 272 { 273 cx_auto_shutdown(codec); 274 return 0; 275 } 276 277 /* 278 * pin fix-up 279 */ 280 enum { 281 CXT_PINCFG_LENOVO_X200, 282 CXT_PINCFG_LENOVO_TP410, 283 CXT_PINCFG_LEMOTE_A1004, 284 CXT_PINCFG_LEMOTE_A1205, 285 CXT_PINCFG_COMPAQ_CQ60, 286 CXT_FIXUP_STEREO_DMIC, 287 CXT_PINCFG_LENOVO_NOTEBOOK, 288 CXT_FIXUP_INC_MIC_BOOST, 289 CXT_FIXUP_HEADPHONE_MIC_PIN, 290 CXT_FIXUP_HEADPHONE_MIC, 291 CXT_FIXUP_GPIO1, 292 CXT_FIXUP_ASPIRE_DMIC, 293 CXT_FIXUP_THINKPAD_ACPI, 294 CXT_FIXUP_LENOVO_XPAD_ACPI, 295 CXT_FIXUP_OLPC_XO, 296 CXT_FIXUP_CAP_MIX_AMP, 297 CXT_FIXUP_TOSHIBA_P105, 298 CXT_FIXUP_HP_530, 299 CXT_FIXUP_CAP_MIX_AMP_5047, 300 CXT_FIXUP_MUTE_LED_EAPD, 301 CXT_FIXUP_HP_DOCK, 302 CXT_FIXUP_HP_SPECTRE, 303 CXT_FIXUP_HP_GATE_MIC, 304 CXT_FIXUP_MUTE_LED_GPIO, 305 CXT_FIXUP_ACER_ASPIRE_GO_MUTE_LED, 306 CXT_FIXUP_HP_ELITEONE_OUT_DIS, 307 CXT_FIXUP_HP_ZBOOK_MUTE_LED, 308 CXT_FIXUP_HEADSET_MIC, 309 CXT_FIXUP_HP_MIC_NO_PRESENCE, 310 CXT_PINCFG_SWS_JS201D, 311 CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10, 312 CXT_PINCFG_TOP_SPEAKER, 313 CXT_FIXUP_HP_A_U, 314 CXT_FIXUP_ACER_SWIFT_HP, 315 CXT_FIXUP_HUAWEI_MATEBOOK_HP, 316 CXT_FIXUP_MATEBOOK14_SN6140, 317 }; 318 319 /* for hda_fixup_thinkpad_acpi() */ 320 #include "helpers/thinkpad.c" 321 322 /* for hda_fixup_ideapad_acpi() */ 323 #include "helpers/ideapad_hotkey_led.c" 324 325 static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 326 const struct hda_fixup *fix, int action) 327 { 328 struct conexant_spec *spec = codec->spec; 329 spec->gen.inv_dmic_split = 1; 330 } 331 332 /* fix widget control pin settings */ 333 static void cxt_fixup_update_pinctl(struct hda_codec *codec, 334 const struct hda_fixup *fix, int action) 335 { 336 if (action == HDA_FIXUP_ACT_PROBE) { 337 /* Unset OUT_EN for this Node pin, leaving only HP_EN. 338 * This is the value stored in the codec register after 339 * the correct initialization of the previous windows boot. 340 */ 341 snd_hda_set_pin_ctl_cache(codec, 0x1d, AC_PINCTL_HP_EN); 342 } 343 } 344 345 static void cxt5066_increase_mic_boost(struct hda_codec *codec, 346 const struct hda_fixup *fix, int action) 347 { 348 if (action != HDA_FIXUP_ACT_PRE_PROBE) 349 return; 350 351 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT, 352 (0x3 << AC_AMPCAP_OFFSET_SHIFT) | 353 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) | 354 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | 355 (0 << AC_AMPCAP_MUTE_SHIFT)); 356 } 357 358 static void cxt_update_headset_mode(struct hda_codec *codec) 359 { 360 /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */ 361 int i; 362 bool mic_mode = false; 363 struct conexant_spec *spec = codec->spec; 364 struct auto_pin_cfg *cfg = &spec->gen.autocfg; 365 366 hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]]; 367 368 for (i = 0; i < cfg->num_inputs; i++) 369 if (cfg->inputs[i].pin == mux_pin) { 370 mic_mode = !!cfg->inputs[i].is_headphone_mic; 371 break; 372 } 373 374 if (mic_mode) { 375 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */ 376 spec->gen.hp_jack_present = false; 377 } else { 378 snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */ 379 spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]); 380 } 381 382 snd_hda_gen_update_outputs(codec); 383 } 384 385 static void cxt_update_headset_mode_hook(struct hda_codec *codec, 386 struct snd_kcontrol *kcontrol, 387 struct snd_ctl_elem_value *ucontrol) 388 { 389 cxt_update_headset_mode(codec); 390 } 391 392 static void cxt_fixup_headphone_mic(struct hda_codec *codec, 393 const struct hda_fixup *fix, int action) 394 { 395 struct conexant_spec *spec = codec->spec; 396 397 switch (action) { 398 case HDA_FIXUP_ACT_PRE_PROBE: 399 spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC; 400 snd_hdac_regmap_add_vendor_verb(&codec->core, 0x410); 401 break; 402 case HDA_FIXUP_ACT_PROBE: 403 WARN_ON(spec->gen.cap_sync_hook); 404 spec->gen.cap_sync_hook = cxt_update_headset_mode_hook; 405 spec->gen.automute_hook = cxt_update_headset_mode; 406 break; 407 case HDA_FIXUP_ACT_INIT: 408 cxt_update_headset_mode(codec); 409 break; 410 } 411 } 412 413 static void cxt_fixup_headset_mic(struct hda_codec *codec, 414 const struct hda_fixup *fix, int action) 415 { 416 struct conexant_spec *spec = codec->spec; 417 418 switch (action) { 419 case HDA_FIXUP_ACT_PRE_PROBE: 420 spec->parse_flags |= HDA_PINCFG_HEADSET_MIC; 421 break; 422 } 423 } 424 425 /* OLPC XO 1.5 fixup */ 426 427 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 428 * through the microphone jack. 429 * When the user enables this through a mixer switch, both internal and 430 * external microphones are disabled. Gain is fixed at 0dB. In this mode, 431 * we also allow the bias to be configured through a separate mixer 432 * control. */ 433 434 #define update_mic_pin(codec, nid, val) \ 435 snd_hda_codec_write_cache(codec, nid, 0, \ 436 AC_VERB_SET_PIN_WIDGET_CONTROL, val) 437 438 static const struct hda_input_mux olpc_xo_dc_bias = { 439 .num_items = 3, 440 .items = { 441 { "Off", PIN_IN }, 442 { "50%", PIN_VREF50 }, 443 { "80%", PIN_VREF80 }, 444 }, 445 }; 446 447 static void olpc_xo_update_mic_boost(struct hda_codec *codec) 448 { 449 struct conexant_spec *spec = codec->spec; 450 int ch, val; 451 452 for (ch = 0; ch < 2; ch++) { 453 val = AC_AMP_SET_OUTPUT | 454 (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT); 455 if (!spec->dc_enable) 456 val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0); 457 snd_hda_codec_write(codec, 0x17, 0, 458 AC_VERB_SET_AMP_GAIN_MUTE, val); 459 } 460 } 461 462 static void olpc_xo_update_mic_pins(struct hda_codec *codec) 463 { 464 struct conexant_spec *spec = codec->spec; 465 int cur_input, val; 466 struct nid_path *path; 467 468 cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]]; 469 470 /* Set up mic pins for port-B, C and F dynamically as the recording 471 * LED is turned on/off by these pin controls 472 */ 473 if (!spec->dc_enable) { 474 /* disable DC bias path and pin for port F */ 475 update_mic_pin(codec, 0x1e, 0); 476 if (spec->dc_mode_path) 477 snd_hda_activate_path(codec, spec->dc_mode_path, false, false); 478 479 /* update port B (ext mic) and C (int mic) */ 480 /* OLPC defers mic widget control until when capture is 481 * started because the microphone LED comes on as soon as 482 * these settings are put in place. if we did this before 483 * recording, it would give the false indication that 484 * recording is happening when it is not. 485 */ 486 update_mic_pin(codec, 0x1a, spec->recording ? 487 snd_hda_codec_get_pin_target(codec, 0x1a) : 0); 488 update_mic_pin(codec, 0x1b, spec->recording ? 489 snd_hda_codec_get_pin_target(codec, 0x1b) : 0); 490 /* enable normal mic path */ 491 path = snd_hda_get_path_from_idx(codec, cur_input); 492 if (path) 493 snd_hda_activate_path(codec, path, true, false); 494 } else { 495 /* disable normal mic path */ 496 path = snd_hda_get_path_from_idx(codec, cur_input); 497 if (path) 498 snd_hda_activate_path(codec, path, false, false); 499 500 /* Even though port F is the DC input, the bias is controlled 501 * on port B. We also leave that port as an active input (but 502 * unselected) in DC mode just in case that is necessary to 503 * make the bias setting take effect. 504 */ 505 if (spec->recording) 506 val = olpc_xo_dc_bias.items[spec->dc_input_bias].index; 507 else 508 val = 0; 509 update_mic_pin(codec, 0x1a, val); 510 update_mic_pin(codec, 0x1b, 0); 511 /* enable DC bias path and pin */ 512 update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0); 513 if (spec->dc_mode_path) 514 snd_hda_activate_path(codec, spec->dc_mode_path, true, false); 515 } 516 } 517 518 /* mic_autoswitch hook */ 519 static void olpc_xo_automic(struct hda_codec *codec, 520 struct hda_jack_callback *jack) 521 { 522 struct conexant_spec *spec = codec->spec; 523 524 /* in DC mode, we don't handle automic */ 525 if (!spec->dc_enable) 526 snd_hda_gen_mic_autoswitch(codec, jack); 527 olpc_xo_update_mic_pins(codec); 528 if (spec->dc_enable) 529 olpc_xo_update_mic_boost(codec); 530 } 531 532 /* pcm_capture hook */ 533 static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo, 534 struct hda_codec *codec, 535 struct snd_pcm_substream *substream, 536 int action) 537 { 538 struct conexant_spec *spec = codec->spec; 539 540 /* toggle spec->recording flag and update mic pins accordingly 541 * for turning on/off LED 542 */ 543 switch (action) { 544 case HDA_GEN_PCM_ACT_PREPARE: 545 spec->recording = 1; 546 olpc_xo_update_mic_pins(codec); 547 break; 548 case HDA_GEN_PCM_ACT_CLEANUP: 549 spec->recording = 0; 550 olpc_xo_update_mic_pins(codec); 551 break; 552 } 553 } 554 555 static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol, 556 struct snd_ctl_elem_value *ucontrol) 557 { 558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 559 struct conexant_spec *spec = codec->spec; 560 ucontrol->value.integer.value[0] = spec->dc_enable; 561 return 0; 562 } 563 564 static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol, 565 struct snd_ctl_elem_value *ucontrol) 566 { 567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 568 struct conexant_spec *spec = codec->spec; 569 int dc_enable = !!ucontrol->value.integer.value[0]; 570 571 if (dc_enable == spec->dc_enable) 572 return 0; 573 574 spec->dc_enable = dc_enable; 575 olpc_xo_update_mic_pins(codec); 576 olpc_xo_update_mic_boost(codec); 577 return 1; 578 } 579 580 static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 581 struct snd_ctl_elem_value *ucontrol) 582 { 583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 584 struct conexant_spec *spec = codec->spec; 585 ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 586 return 0; 587 } 588 589 static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 590 struct snd_ctl_elem_info *uinfo) 591 { 592 return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo); 593 } 594 595 static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 596 struct snd_ctl_elem_value *ucontrol) 597 { 598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 599 struct conexant_spec *spec = codec->spec; 600 const struct hda_input_mux *imux = &olpc_xo_dc_bias; 601 unsigned int idx; 602 603 idx = ucontrol->value.enumerated.item[0]; 604 if (idx >= imux->num_items) 605 idx = imux->num_items - 1; 606 if (spec->dc_input_bias == idx) 607 return 0; 608 609 spec->dc_input_bias = idx; 610 if (spec->dc_enable) 611 olpc_xo_update_mic_pins(codec); 612 return 1; 613 } 614 615 static const struct snd_kcontrol_new olpc_xo_mixers[] = { 616 { 617 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 618 .name = "DC Mode Enable Switch", 619 .info = snd_ctl_boolean_mono_info, 620 .get = olpc_xo_dc_mode_get, 621 .put = olpc_xo_dc_mode_put, 622 }, 623 { 624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 625 .name = "DC Input Bias Enum", 626 .info = olpc_xo_dc_bias_enum_info, 627 .get = olpc_xo_dc_bias_enum_get, 628 .put = olpc_xo_dc_bias_enum_put, 629 }, 630 {} 631 }; 632 633 /* overriding mic boost put callback; update mic boost volume only when 634 * DC mode is disabled 635 */ 636 static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol, 637 struct snd_ctl_elem_value *ucontrol) 638 { 639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 640 struct conexant_spec *spec = codec->spec; 641 int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol); 642 if (ret > 0 && spec->dc_enable) 643 olpc_xo_update_mic_boost(codec); 644 return ret; 645 } 646 647 static void cxt_fixup_olpc_xo(struct hda_codec *codec, 648 const struct hda_fixup *fix, int action) 649 { 650 struct conexant_spec *spec = codec->spec; 651 struct snd_kcontrol_new *kctl; 652 int i; 653 654 if (action != HDA_FIXUP_ACT_PROBE) 655 return; 656 657 spec->gen.mic_autoswitch_hook = olpc_xo_automic; 658 spec->gen.pcm_capture_hook = olpc_xo_capture_hook; 659 spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0); 660 661 snd_hda_add_new_ctls(codec, olpc_xo_mixers); 662 663 /* OLPC's microphone port is DC coupled for use with external sensors, 664 * therefore we use a 50% mic bias in order to center the input signal 665 * with the DC input range of the codec. 666 */ 667 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50); 668 669 /* override mic boost control */ 670 snd_array_for_each(&spec->gen.kctls, i, kctl) { 671 if (!strcmp(kctl->name, "Mic Boost Volume")) { 672 kctl->put = olpc_xo_mic_boost_put; 673 break; 674 } 675 } 676 } 677 678 static void cxt_fixup_mute_led_eapd(struct hda_codec *codec, 679 const struct hda_fixup *fix, int action) 680 { 681 struct conexant_spec *spec = codec->spec; 682 683 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 684 spec->mute_led_eapd = 0x1b; 685 spec->dynamic_eapd = true; 686 snd_hda_gen_add_mute_led_cdev(codec, cx_auto_vmaster_mute_led); 687 } 688 } 689 690 /* 691 * Fix max input level on mixer widget to 0dB 692 * (originally it has 0x2b steps with 0dB offset 0x14) 693 */ 694 static void cxt_fixup_cap_mix_amp(struct hda_codec *codec, 695 const struct hda_fixup *fix, int action) 696 { 697 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 698 (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 699 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 700 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 701 (1 << AC_AMPCAP_MUTE_SHIFT)); 702 } 703 704 /* 705 * Fix max input level on mixer widget to 0dB 706 * (originally it has 0x1e steps with 0 dB offset 0x17) 707 */ 708 static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec, 709 const struct hda_fixup *fix, int action) 710 { 711 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 712 (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 713 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 714 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 715 (1 << AC_AMPCAP_MUTE_SHIFT)); 716 } 717 718 static void cxt_fixup_hp_gate_mic_jack(struct hda_codec *codec, 719 const struct hda_fixup *fix, 720 int action) 721 { 722 /* the mic pin (0x19) doesn't give an unsolicited event; 723 * probe the mic pin together with the headphone pin (0x16) 724 */ 725 if (action == HDA_FIXUP_ACT_PROBE) 726 snd_hda_jack_set_gating_jack(codec, 0x19, 0x16); 727 } 728 729 /* update LED status via GPIO */ 730 static void cxt_update_gpio_led(struct hda_codec *codec, unsigned int mask, 731 bool led_on) 732 { 733 struct conexant_spec *spec = codec->spec; 734 unsigned int oldval = spec->gpio_led; 735 736 if (spec->mute_led_polarity) 737 led_on = !led_on; 738 739 if (led_on) 740 spec->gpio_led |= mask; 741 else 742 spec->gpio_led &= ~mask; 743 codec_dbg(codec, "mask:%d enabled:%d gpio_led:%d\n", 744 mask, led_on, spec->gpio_led); 745 if (spec->gpio_led != oldval) 746 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 747 spec->gpio_led); 748 } 749 750 /* turn on/off mute LED via GPIO per vmaster hook */ 751 static int cxt_gpio_mute_update(struct led_classdev *led_cdev, 752 enum led_brightness brightness) 753 { 754 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent); 755 struct conexant_spec *spec = codec->spec; 756 757 cxt_update_gpio_led(codec, spec->gpio_mute_led_mask, brightness); 758 return 0; 759 } 760 761 /* turn on/off mic-mute LED via GPIO per capture hook */ 762 static int cxt_gpio_micmute_update(struct led_classdev *led_cdev, 763 enum led_brightness brightness) 764 { 765 struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent); 766 struct conexant_spec *spec = codec->spec; 767 768 cxt_update_gpio_led(codec, spec->gpio_mic_led_mask, brightness); 769 return 0; 770 } 771 772 static void cxt_setup_mute_led(struct hda_codec *codec, 773 unsigned int mute, unsigned int mic_mute) 774 { 775 struct conexant_spec *spec = codec->spec; 776 777 spec->gpio_led = 0; 778 spec->mute_led_polarity = 0; 779 if (mute) { 780 snd_hda_gen_add_mute_led_cdev(codec, cxt_gpio_mute_update); 781 spec->gpio_mute_led_mask = mute; 782 } 783 if (mic_mute) { 784 snd_hda_gen_add_micmute_led_cdev(codec, cxt_gpio_micmute_update); 785 spec->gpio_mic_led_mask = mic_mute; 786 } 787 } 788 789 static void cxt_setup_gpio_unmute(struct hda_codec *codec, 790 unsigned int gpio_mute_mask) 791 { 792 if (gpio_mute_mask) { 793 // set gpio data to 0. 794 snd_hda_codec_set_gpio(codec, gpio_mute_mask, gpio_mute_mask, 0, 0); 795 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_STICKY_MASK, 0); 796 } 797 } 798 799 static void cxt_fixup_mute_led_gpio(struct hda_codec *codec, 800 const struct hda_fixup *fix, int action) 801 { 802 if (action == HDA_FIXUP_ACT_PRE_PROBE) 803 cxt_setup_mute_led(codec, 0x01, 0x02); 804 } 805 806 static void cxt_fixup_hp_zbook_mute_led(struct hda_codec *codec, 807 const struct hda_fixup *fix, int action) 808 { 809 if (action == HDA_FIXUP_ACT_PRE_PROBE) 810 cxt_setup_mute_led(codec, 0x10, 0x20); 811 } 812 813 static void cxt_fixup_acer_aspire_go_mute_led(struct hda_codec *codec, 814 const struct hda_fixup *fix, int action) 815 { 816 if (action == HDA_FIXUP_ACT_PRE_PROBE) 817 cxt_setup_mute_led(codec, 0, 0x10); 818 } 819 820 static void cxt_fixup_hp_a_u(struct hda_codec *codec, 821 const struct hda_fixup *fix, int action) 822 { 823 // Init vers in BIOS mute the spk/hp by set gpio high to avoid pop noise, 824 // so need to unmute once by clearing the gpio data when runs into the system. 825 if (action == HDA_FIXUP_ACT_INIT) 826 cxt_setup_gpio_unmute(codec, 0x2); 827 } 828 829 /* Huawei MateBook 14 (SN6140): the speaker output follows the headphone 830 * pin's connection select in hardware. Both pins must be routed to the 831 * shared DAC 0x10, which carries the playback stream; the generic 832 * parser mutes that DAC when no headphone is plugged, silencing the 833 * speaker. Suppress the auto-mute, bind the speaker pin to the shared 834 * DAC, remove its mute switch and keep it unmuted; the auto-mute hook 835 * re-applies the routing after every output update. 836 */ 837 static void cxt_mb14_route_unmute(struct hda_codec *codec) 838 { 839 /* route both pins to the shared DAC 0x10, enable the speaker 840 * EAPD and unmute the DAC at a moderate gain; the vmaster 841 * volume takes over once userspace starts 842 */ 843 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_CONNECT_SEL, 0); 844 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 0); 845 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_EAPD_BTLENABLE, 0x02); 846 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 847 HDA_AMP_VOLMASK | HDA_AMP_MUTE, 0x40); 848 } 849 850 static void cxt_mb14_automute(struct hda_codec *codec) 851 { 852 snd_hda_gen_update_outputs(codec); 853 cxt_mb14_route_unmute(codec); 854 } 855 856 static void cxt_fixup_matebook14_sn6140(struct hda_codec *codec, 857 const struct hda_fixup *fix, int action) 858 { 859 struct conexant_spec *spec = codec->spec; 860 861 if (action == HDA_FIXUP_ACT_PRE_PROBE) { 862 static const hda_nid_t dac_0x10[] = { 0x10 }; 863 864 spec->gen.suppress_auto_mute = 1; 865 spec->gen.automute_hook = cxt_mb14_automute; 866 /* Bind the speaker pin to the shared DAC 0x10. 867 */ 868 snd_hda_override_conn_list(codec, 0x17, 1, dac_0x10); 869 return; 870 } 871 if (action == HDA_FIXUP_ACT_PROBE) { 872 unsigned int caps; 873 874 /* Remove the mute switch on the shared DAC so that 875 * userspace (WirePlumber) cannot mute it when the 876 * headphone route becomes unavailable (e.g. after 877 * resume). Must be done here: the codec regmap is not 878 * available at pre-probe time. 879 */ 880 caps = query_amp_caps(codec, 0x10, HDA_OUTPUT); 881 snd_hda_override_amp_caps(codec, 0x10, HDA_OUTPUT, 882 caps & ~AC_AMPCAP_MUTE); 883 return; 884 } 885 if (action != HDA_FIXUP_ACT_INIT) 886 return; 887 cxt_mb14_route_unmute(codec); 888 } 889 890 /* ThinkPad X200 & co with cxt5051 */ 891 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 892 { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 893 { 0x17, 0x21a11000 }, /* dock-mic */ 894 { 0x19, 0x2121103f }, /* dock-HP */ 895 { 0x1c, 0x21440100 }, /* dock SPDIF out */ 896 {} 897 }; 898 899 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 900 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { 901 { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 902 { 0x1a, 0x21a190f0 }, /* dock-mic */ 903 { 0x1c, 0x212140ff }, /* dock-HP */ 904 {} 905 }; 906 907 /* Lemote A1004/A1205 with cxt5066 */ 908 static const struct hda_pintbl cxt_pincfg_lemote[] = { 909 { 0x1a, 0x90a10020 }, /* Internal mic */ 910 { 0x1b, 0x03a11020 }, /* External mic */ 911 { 0x1d, 0x400101f0 }, /* Not used */ 912 { 0x1e, 0x40a701f0 }, /* Not used */ 913 { 0x20, 0x404501f0 }, /* Not used */ 914 { 0x22, 0x404401f0 }, /* Not used */ 915 { 0x23, 0x40a701f0 }, /* Not used */ 916 {} 917 }; 918 919 /* Lenovo IdeaPad Slim 5 16AKP10 with SN6140 */ 920 static const struct hda_pintbl cxt_pincfg_lenovo_ideapad_slim5_16akp10[] = { 921 { 0x1a, 0x95a60130 }, /* Internal mic, fixed/always-connected */ 922 {} 923 }; 924 925 /* SuoWoSi/South-holding JS201D with sn6140 */ 926 static const struct hda_pintbl cxt_pincfg_sws_js201d[] = { 927 { 0x16, 0x03211040 }, /* hp out */ 928 { 0x17, 0x91170110 }, /* SPK/Class_D */ 929 { 0x18, 0x95a70130 }, /* Internal mic */ 930 { 0x19, 0x03a11020 }, /* Headset Mic */ 931 { 0x1a, 0x40f001f0 }, /* Not used */ 932 { 0x21, 0x40f001f0 }, /* Not used */ 933 {} 934 }; 935 936 static const struct hda_fixup cxt_fixups[] = { 937 [CXT_PINCFG_LENOVO_X200] = { 938 .type = HDA_FIXUP_PINS, 939 .v.pins = cxt_pincfg_lenovo_x200, 940 }, 941 [CXT_PINCFG_LENOVO_TP410] = { 942 .type = HDA_FIXUP_PINS, 943 .v.pins = cxt_pincfg_lenovo_tp410, 944 .chained = true, 945 .chain_id = CXT_FIXUP_THINKPAD_ACPI, 946 }, 947 [CXT_PINCFG_LEMOTE_A1004] = { 948 .type = HDA_FIXUP_PINS, 949 .chained = true, 950 .chain_id = CXT_FIXUP_INC_MIC_BOOST, 951 .v.pins = cxt_pincfg_lemote, 952 }, 953 [CXT_PINCFG_LEMOTE_A1205] = { 954 .type = HDA_FIXUP_PINS, 955 .v.pins = cxt_pincfg_lemote, 956 }, 957 [CXT_PINCFG_COMPAQ_CQ60] = { 958 .type = HDA_FIXUP_PINS, 959 .v.pins = (const struct hda_pintbl[]) { 960 /* 0x17 was falsely set up as a mic, it should 0x1d */ 961 { 0x17, 0x400001f0 }, 962 { 0x1d, 0x97a70120 }, 963 { } 964 } 965 }, 966 [CXT_FIXUP_STEREO_DMIC] = { 967 .type = HDA_FIXUP_FUNC, 968 .v.func = cxt_fixup_stereo_dmic, 969 }, 970 [CXT_PINCFG_LENOVO_NOTEBOOK] = { 971 .type = HDA_FIXUP_PINS, 972 .v.pins = (const struct hda_pintbl[]) { 973 { 0x1a, 0x05d71030 }, 974 { } 975 }, 976 .chain_id = CXT_FIXUP_STEREO_DMIC, 977 }, 978 [CXT_FIXUP_INC_MIC_BOOST] = { 979 .type = HDA_FIXUP_FUNC, 980 .v.func = cxt5066_increase_mic_boost, 981 }, 982 [CXT_FIXUP_HEADPHONE_MIC_PIN] = { 983 .type = HDA_FIXUP_PINS, 984 .chained = true, 985 .chain_id = CXT_FIXUP_HEADPHONE_MIC, 986 .v.pins = (const struct hda_pintbl[]) { 987 { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */ 988 { } 989 } 990 }, 991 [CXT_FIXUP_HEADPHONE_MIC] = { 992 .type = HDA_FIXUP_FUNC, 993 .v.func = cxt_fixup_headphone_mic, 994 }, 995 [CXT_FIXUP_GPIO1] = { 996 .type = HDA_FIXUP_VERBS, 997 .v.verbs = (const struct hda_verb[]) { 998 { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 }, 999 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 }, 1000 { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 }, 1001 { } 1002 }, 1003 }, 1004 [CXT_FIXUP_ASPIRE_DMIC] = { 1005 .type = HDA_FIXUP_FUNC, 1006 .v.func = cxt_fixup_stereo_dmic, 1007 .chained = true, 1008 .chain_id = CXT_FIXUP_GPIO1, 1009 }, 1010 [CXT_FIXUP_THINKPAD_ACPI] = { 1011 .type = HDA_FIXUP_FUNC, 1012 .v.func = hda_fixup_thinkpad_acpi, 1013 }, 1014 [CXT_FIXUP_LENOVO_XPAD_ACPI] = { 1015 .type = HDA_FIXUP_FUNC, 1016 .v.func = hda_fixup_ideapad_acpi, 1017 .chained = true, 1018 .chain_id = CXT_FIXUP_THINKPAD_ACPI, 1019 }, 1020 [CXT_FIXUP_OLPC_XO] = { 1021 .type = HDA_FIXUP_FUNC, 1022 .v.func = cxt_fixup_olpc_xo, 1023 }, 1024 [CXT_FIXUP_CAP_MIX_AMP] = { 1025 .type = HDA_FIXUP_FUNC, 1026 .v.func = cxt_fixup_cap_mix_amp, 1027 }, 1028 [CXT_FIXUP_TOSHIBA_P105] = { 1029 .type = HDA_FIXUP_PINS, 1030 .v.pins = (const struct hda_pintbl[]) { 1031 { 0x10, 0x961701f0 }, /* speaker/hp */ 1032 { 0x12, 0x02a1901e }, /* ext mic */ 1033 { 0x14, 0x95a70110 }, /* int mic */ 1034 {} 1035 }, 1036 }, 1037 [CXT_FIXUP_HP_530] = { 1038 .type = HDA_FIXUP_PINS, 1039 .v.pins = (const struct hda_pintbl[]) { 1040 { 0x12, 0x90a60160 }, /* int mic */ 1041 {} 1042 }, 1043 .chained = true, 1044 .chain_id = CXT_FIXUP_CAP_MIX_AMP, 1045 }, 1046 [CXT_FIXUP_CAP_MIX_AMP_5047] = { 1047 .type = HDA_FIXUP_FUNC, 1048 .v.func = cxt_fixup_cap_mix_amp_5047, 1049 }, 1050 [CXT_FIXUP_MUTE_LED_EAPD] = { 1051 .type = HDA_FIXUP_FUNC, 1052 .v.func = cxt_fixup_mute_led_eapd, 1053 }, 1054 [CXT_FIXUP_HP_DOCK] = { 1055 .type = HDA_FIXUP_PINS, 1056 .v.pins = (const struct hda_pintbl[]) { 1057 { 0x16, 0x21011020 }, /* line-out */ 1058 { 0x18, 0x2181103f }, /* line-in */ 1059 { } 1060 }, 1061 .chained = true, 1062 .chain_id = CXT_FIXUP_MUTE_LED_GPIO, 1063 }, 1064 [CXT_FIXUP_HP_SPECTRE] = { 1065 .type = HDA_FIXUP_PINS, 1066 .v.pins = (const struct hda_pintbl[]) { 1067 /* enable NID 0x1d for the speaker on top */ 1068 { 0x1d, 0x91170111 }, 1069 { } 1070 } 1071 }, 1072 [CXT_FIXUP_HP_GATE_MIC] = { 1073 .type = HDA_FIXUP_FUNC, 1074 .v.func = cxt_fixup_hp_gate_mic_jack, 1075 }, 1076 [CXT_FIXUP_MUTE_LED_GPIO] = { 1077 .type = HDA_FIXUP_FUNC, 1078 .v.func = cxt_fixup_mute_led_gpio, 1079 }, 1080 [CXT_FIXUP_ACER_ASPIRE_GO_MUTE_LED] = { 1081 .type = HDA_FIXUP_FUNC, 1082 .v.func = cxt_fixup_acer_aspire_go_mute_led, 1083 }, 1084 [CXT_FIXUP_HP_ELITEONE_OUT_DIS] = { 1085 .type = HDA_FIXUP_FUNC, 1086 .v.func = cxt_fixup_update_pinctl, 1087 }, 1088 [CXT_FIXUP_HP_ZBOOK_MUTE_LED] = { 1089 .type = HDA_FIXUP_FUNC, 1090 .v.func = cxt_fixup_hp_zbook_mute_led, 1091 }, 1092 [CXT_FIXUP_HEADSET_MIC] = { 1093 .type = HDA_FIXUP_FUNC, 1094 .v.func = cxt_fixup_headset_mic, 1095 }, 1096 [CXT_FIXUP_HP_MIC_NO_PRESENCE] = { 1097 .type = HDA_FIXUP_PINS, 1098 .v.pins = (const struct hda_pintbl[]) { 1099 { 0x1a, 0x02a1113c }, 1100 { } 1101 }, 1102 .chained = true, 1103 .chain_id = CXT_FIXUP_HEADSET_MIC, 1104 }, 1105 [CXT_PINCFG_SWS_JS201D] = { 1106 .type = HDA_FIXUP_PINS, 1107 .v.pins = cxt_pincfg_sws_js201d, 1108 }, 1109 [CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10] = { 1110 .type = HDA_FIXUP_PINS, 1111 .v.pins = cxt_pincfg_lenovo_ideapad_slim5_16akp10, 1112 }, 1113 [CXT_PINCFG_TOP_SPEAKER] = { 1114 .type = HDA_FIXUP_PINS, 1115 .v.pins = (const struct hda_pintbl[]) { 1116 { 0x1d, 0x82170111 }, 1117 { } 1118 }, 1119 }, 1120 [CXT_FIXUP_HP_A_U] = { 1121 .type = HDA_FIXUP_FUNC, 1122 .v.func = cxt_fixup_hp_a_u, 1123 }, 1124 [CXT_FIXUP_ACER_SWIFT_HP] = { 1125 .type = HDA_FIXUP_PINS, 1126 .v.pins = (const struct hda_pintbl[]) { 1127 { 0x16, 0x0321403f }, /* Headphone */ 1128 { 0x19, 0x40f001f0 }, /* Mic */ 1129 { } 1130 }, 1131 }, 1132 [CXT_FIXUP_HUAWEI_MATEBOOK_HP] = { 1133 .type = HDA_FIXUP_PINS, 1134 .v.pins = (const struct hda_pintbl[]) { 1135 { 0x18, 0x03211020 }, /* Headphone */ 1136 { } 1137 }, 1138 }, 1139 [CXT_FIXUP_MATEBOOK14_SN6140] = { 1140 .type = HDA_FIXUP_FUNC, 1141 .v.func = cxt_fixup_matebook14_sn6140, 1142 }, 1143 }; 1144 1145 static const struct hda_quirk cxt5045_fixups[] = { 1146 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530), 1147 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105), 1148 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 1149 * really bad sound over 0dB on NID 0x17. 1150 */ 1151 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP), 1152 SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP), 1153 SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP), 1154 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP), 1155 {} 1156 }; 1157 1158 static const struct hda_model_fixup cxt5045_fixup_models[] = { 1159 { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" }, 1160 { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" }, 1161 { .id = CXT_FIXUP_HP_530, .name = "hp-530" }, 1162 {} 1163 }; 1164 1165 static const struct hda_quirk cxt5047_fixups[] = { 1166 /* HP laptops have really bad sound over 0 dB on NID 0x10. 1167 */ 1168 SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047), 1169 {} 1170 }; 1171 1172 static const struct hda_model_fixup cxt5047_fixup_models[] = { 1173 { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" }, 1174 {} 1175 }; 1176 1177 static const struct hda_quirk cxt5051_fixups[] = { 1178 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq CQ60", CXT_PINCFG_COMPAQ_CQ60), 1179 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 1180 {} 1181 }; 1182 1183 static const struct hda_model_fixup cxt5051_fixup_models[] = { 1184 { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" }, 1185 {} 1186 }; 1187 1188 static const struct hda_quirk cxt5066_fixups[] = { 1189 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 1190 SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_ASPIRE_DMIC), 1191 SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", CXT_FIXUP_ASPIRE_DMIC), 1192 SND_PCI_QUIRK(0x1025, 0x136d, "Acer Swift SF314", CXT_FIXUP_ACER_SWIFT_HP), 1193 SND_PCI_QUIRK(0x1025, 0x1937, "Acer Aspire Go 16", CXT_FIXUP_ACER_ASPIRE_GO_MUTE_LED), 1194 SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK), 1195 SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK), 1196 SND_PCI_QUIRK(0x103c, 0x80d6, "HP ZBook 17 G3", CXT_FIXUP_MUTE_LED_GPIO), 1197 SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK), 1198 SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC), 1199 SND_PCI_QUIRK(0x103c, 0x814f, "HP ZBook 15u G3", CXT_FIXUP_MUTE_LED_GPIO), 1200 SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE), 1201 SND_PCI_QUIRK(0x103c, 0x822e, "HP ProBook 440 G4", CXT_FIXUP_MUTE_LED_GPIO), 1202 SND_PCI_QUIRK(0x103c, 0x8231, "HP ProBook 450 G4", CXT_FIXUP_MUTE_LED_GPIO), 1203 SND_PCI_QUIRK(0x103c, 0x826b, "HP ZBook Studio G4", CXT_FIXUP_MUTE_LED_GPIO), 1204 SND_PCI_QUIRK(0x103c, 0x828c, "HP EliteBook 840 G4", CXT_FIXUP_HP_DOCK), 1205 SND_PCI_QUIRK(0x103c, 0x8299, "HP 800 G3 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1206 SND_PCI_QUIRK(0x103c, 0x829a, "HP 800 G3 DM", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1207 SND_PCI_QUIRK(0x103c, 0x82b4, "HP ProDesk 600 G3", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1208 SND_PCI_QUIRK(0x103c, 0x836e, "HP ProBook 455 G5", CXT_FIXUP_MUTE_LED_GPIO), 1209 SND_PCI_QUIRK(0x103c, 0x837b, "HP ProBook 440 G5", CXT_FIXUP_MUTE_LED_GPIO), 1210 SND_PCI_QUIRK(0x103c, 0x837f, "HP ProBook 470 G5", CXT_FIXUP_MUTE_LED_GPIO), 1211 SND_PCI_QUIRK(0x103c, 0x83b2, "HP EliteBook 840 G5", CXT_FIXUP_HP_DOCK), 1212 SND_PCI_QUIRK(0x103c, 0x83b3, "HP EliteBook 830 G5", CXT_FIXUP_HP_DOCK), 1213 SND_PCI_QUIRK(0x103c, 0x83d3, "HP ProBook 640 G4", CXT_FIXUP_HP_DOCK), 1214 SND_PCI_QUIRK(0x103c, 0x83e5, "HP EliteOne 1000 G2", CXT_FIXUP_HP_ELITEONE_OUT_DIS), 1215 SND_PCI_QUIRK(0x103c, 0x8402, "HP ProBook 645 G4", CXT_FIXUP_MUTE_LED_GPIO), 1216 SND_PCI_QUIRK(0x103c, 0x8427, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED), 1217 SND_PCI_QUIRK(0x103c, 0x844f, "HP ZBook Studio G5", CXT_FIXUP_HP_ZBOOK_MUTE_LED), 1218 SND_PCI_QUIRK(0x103c, 0x8455, "HP Z2 G4", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1219 SND_PCI_QUIRK(0x103c, 0x8456, "HP Z2 G4 SFF", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1220 SND_PCI_QUIRK(0x103c, 0x8457, "HP Z2 G4 mini", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1221 SND_PCI_QUIRK(0x103c, 0x8458, "HP Z2 G4 mini premium", CXT_FIXUP_HP_MIC_NO_PRESENCE), 1222 SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN), 1223 SND_PCI_QUIRK(0x14f1, 0x0252, "MBX-Z60MR100", CXT_FIXUP_HP_A_U), 1224 SND_PCI_QUIRK(0x14f1, 0x0265, "SWS JS201D", CXT_PINCFG_SWS_JS201D), 1225 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO), 1226 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 1227 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 1228 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 1229 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 1230 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 1231 SND_PCI_QUIRK(0x17aa, 0x21d2, "Lenovo T420s", CXT_PINCFG_LENOVO_TP410), 1232 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410), 1233 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410), 1234 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD), 1235 SND_PCI_QUIRK(0x17aa, 0x38b6, "Lenovo IdeaPad Slim 5 16AKP10", CXT_PINCFG_LENOVO_IDEAPAD_SLIM5_16AKP10), 1236 SND_PCI_QUIRK(0x17aa, 0x3905, "Lenovo G50-30", CXT_FIXUP_STEREO_DMIC), 1237 SND_PCI_QUIRK(0x17aa, 0x390b, "Lenovo G50-80", CXT_FIXUP_STEREO_DMIC), 1238 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 1239 /* NOTE: we'd need to extend the quirk for 17aa:3977 as the same 1240 * PCI SSID is used on multiple Lenovo models 1241 */ 1242 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), 1243 SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo G50-70", CXT_FIXUP_STEREO_DMIC), 1244 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), 1245 SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad/Ideapad", CXT_FIXUP_LENOVO_XPAD_ACPI), 1246 SND_PCI_QUIRK(0x19e5, 0x3289, "Huawei Matebook", CXT_FIXUP_HUAWEI_MATEBOOK_HP), 1247 SND_PCI_QUIRK(0x19e5, 0x329e, "Huawei MateBook 14", CXT_FIXUP_MATEBOOK14_SN6140), 1248 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004), 1249 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205), 1250 SND_PCI_QUIRK(0x1d05, 0x3012, "MECHREVO Wujie 15X Pro", CXT_FIXUP_HEADSET_MIC), 1251 HDA_CODEC_QUIRK(0x2782, 0x12c3, "Sirius Gen1", CXT_PINCFG_TOP_SPEAKER), 1252 HDA_CODEC_QUIRK(0x2782, 0x12c5, "Sirius Gen2", CXT_PINCFG_TOP_SPEAKER), 1253 {} 1254 }; 1255 1256 static const struct hda_model_fixup cxt5066_fixup_models[] = { 1257 { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" }, 1258 { .id = CXT_FIXUP_GPIO1, .name = "gpio1" }, 1259 { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" }, 1260 { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" }, 1261 { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" }, 1262 { .id = CXT_FIXUP_LENOVO_XPAD_ACPI, .name = "thinkpad-ideapad" }, 1263 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" }, 1264 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" }, 1265 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" }, 1266 { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" }, 1267 { .id = CXT_FIXUP_HP_DOCK, .name = "hp-dock" }, 1268 { .id = CXT_FIXUP_MUTE_LED_GPIO, .name = "mute-led-gpio" }, 1269 { .id = CXT_FIXUP_HP_ZBOOK_MUTE_LED, .name = "hp-zbook-mute-led" }, 1270 { .id = CXT_FIXUP_HP_MIC_NO_PRESENCE, .name = "hp-mic-fix" }, 1271 { .id = CXT_PINCFG_LENOVO_NOTEBOOK, .name = "lenovo-20149" }, 1272 { .id = CXT_PINCFG_SWS_JS201D, .name = "sws-js201d" }, 1273 { .id = CXT_PINCFG_TOP_SPEAKER, .name = "sirius-top-speaker" }, 1274 { .id = CXT_FIXUP_HP_A_U, .name = "HP-U-support" }, 1275 {} 1276 }; 1277 1278 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 1279 * can be created (bko#42825) 1280 */ 1281 static void add_cx5051_fake_mutes(struct hda_codec *codec) 1282 { 1283 struct conexant_spec *spec = codec->spec; 1284 static const hda_nid_t out_nids[] = { 1285 0x10, 0x11, 0 1286 }; 1287 const hda_nid_t *p; 1288 1289 for (p = out_nids; *p; p++) 1290 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 1291 AC_AMPCAP_MIN_MUTE | 1292 query_amp_caps(codec, *p, HDA_OUTPUT)); 1293 spec->gen.dac_min_mute = true; 1294 } 1295 1296 static int cx_probe(struct hda_codec *codec, const struct hda_device_id *id) 1297 { 1298 struct conexant_spec *spec; 1299 struct hda_jack_callback *callback; 1300 int err; 1301 1302 codec_info(codec, "%s: BIOS auto-probing.\n", codec->core.chip_name); 1303 1304 spec = kzalloc_obj(*spec); 1305 if (!spec) 1306 return -ENOMEM; 1307 snd_hda_gen_spec_init(&spec->gen); 1308 codec->spec = spec; 1309 1310 /* init cx11880/sn6140 flag and reset headset_present_flag */ 1311 switch (codec->core.vendor_id) { 1312 case 0x14f11f86: 1313 case 0x14f11f87: 1314 spec->is_cx11880_sn6140 = true; 1315 callback = snd_hda_jack_detect_enable_callback(codec, 0x19, 1316 cx_update_headset_mic_vref); 1317 if (IS_ERR(callback)) { 1318 err = PTR_ERR(callback); 1319 goto error; 1320 } 1321 break; 1322 } 1323 1324 cx_auto_parse_eapd(codec); 1325 spec->gen.own_eapd_ctl = 1; 1326 1327 switch (codec->core.vendor_id) { 1328 case 0x14f15045: 1329 codec->single_adc_amp = 1; 1330 spec->gen.mixer_nid = 0x17; 1331 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 1332 snd_hda_pick_fixup(codec, cxt5045_fixup_models, 1333 cxt5045_fixups, cxt_fixups); 1334 break; 1335 case 0x14f15047: 1336 codec->pin_amp_workaround = 1; 1337 spec->gen.mixer_nid = 0x19; 1338 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 1339 snd_hda_pick_fixup(codec, cxt5047_fixup_models, 1340 cxt5047_fixups, cxt_fixups); 1341 break; 1342 case 0x14f15051: 1343 add_cx5051_fake_mutes(codec); 1344 codec->pin_amp_workaround = 1; 1345 snd_hda_pick_fixup(codec, cxt5051_fixup_models, 1346 cxt5051_fixups, cxt_fixups); 1347 break; 1348 case 0x14f15098: 1349 codec->pin_amp_workaround = 1; 1350 spec->gen.mixer_nid = 0x22; 1351 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 1352 snd_hda_pick_fixup(codec, cxt5066_fixup_models, 1353 cxt5066_fixups, cxt_fixups); 1354 break; 1355 case 0x14f150f2: 1356 codec->power_save_node = 1; 1357 fallthrough; 1358 default: 1359 codec->pin_amp_workaround = 1; 1360 snd_hda_pick_fixup(codec, cxt5066_fixup_models, 1361 cxt5066_fixups, cxt_fixups); 1362 break; 1363 } 1364 1365 if (!spec->gen.vmaster_mute.hook && spec->dynamic_eapd) 1366 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook; 1367 1368 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 1369 1370 err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 1371 spec->parse_flags); 1372 if (err < 0) 1373 goto error; 1374 1375 err = cx_auto_parse_beep(codec); 1376 if (err < 0) 1377 goto error; 1378 1379 err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); 1380 if (err < 0) 1381 goto error; 1382 1383 /* Some laptops with Conexant chips show stalls in S3 resume, 1384 * which falls into the single-cmd mode. 1385 * Better to make reset, then. 1386 */ 1387 if (!codec->bus->core.sync_write) { 1388 codec_info(codec, 1389 "Enable sync_write for stable communication\n"); 1390 codec->bus->core.sync_write = 1; 1391 codec->bus->allow_bus_reset = 1; 1392 } 1393 1394 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 1395 1396 return 0; 1397 1398 error: 1399 cx_remove(codec); 1400 return err; 1401 } 1402 1403 static const struct hda_codec_ops cx_codec_ops = { 1404 .probe = cx_probe, 1405 .remove = cx_remove, 1406 .build_controls = snd_hda_gen_build_controls, 1407 .build_pcms = snd_hda_gen_build_pcms, 1408 .init = cx_init, 1409 .unsol_event = snd_hda_jack_unsol_event, 1410 .suspend = cx_suspend, 1411 .set_power_state = cx_set_power_state, 1412 .check_power_status = snd_hda_gen_check_power_status, 1413 .stream_pm = snd_hda_gen_stream_pm, 1414 }; 1415 1416 /* 1417 */ 1418 1419 static const struct hda_device_id snd_hda_id_conexant[] = { 1420 HDA_CODEC_ID(0x14f11f86, "CX11880"), 1421 HDA_CODEC_ID(0x14f11f87, "SN6140"), 1422 HDA_CODEC_ID(0x14f12008, "CX8200"), 1423 HDA_CODEC_ID(0x14f120d0, "CX11970"), 1424 HDA_CODEC_ID(0x14f120d1, "SN6180"), 1425 HDA_CODEC_ID(0x14f15045, "CX20549 (Venice)"), 1426 HDA_CODEC_ID(0x14f15047, "CX20551 (Waikiki)"), 1427 HDA_CODEC_ID(0x14f15051, "CX20561 (Hermosa)"), 1428 HDA_CODEC_ID(0x14f15066, "CX20582 (Pebble)"), 1429 HDA_CODEC_ID(0x14f15067, "CX20583 (Pebble HSF)"), 1430 HDA_CODEC_ID(0x14f15068, "CX20584"), 1431 HDA_CODEC_ID(0x14f15069, "CX20585"), 1432 HDA_CODEC_ID(0x14f1506c, "CX20588"), 1433 HDA_CODEC_ID(0x14f1506e, "CX20590"), 1434 HDA_CODEC_ID(0x14f15097, "CX20631"), 1435 HDA_CODEC_ID(0x14f15098, "CX20632"), 1436 HDA_CODEC_ID(0x14f150a1, "CX20641"), 1437 HDA_CODEC_ID(0x14f150a2, "CX20642"), 1438 HDA_CODEC_ID(0x14f150ab, "CX20651"), 1439 HDA_CODEC_ID(0x14f150ac, "CX20652"), 1440 HDA_CODEC_ID(0x14f150b8, "CX20664"), 1441 HDA_CODEC_ID(0x14f150b9, "CX20665"), 1442 HDA_CODEC_ID(0x14f150f1, "CX21722"), 1443 HDA_CODEC_ID(0x14f150f2, "CX20722"), 1444 HDA_CODEC_ID(0x14f150f3, "CX21724"), 1445 HDA_CODEC_ID(0x14f150f4, "CX20724"), 1446 HDA_CODEC_ID(0x14f1510f, "CX20751/2"), 1447 HDA_CODEC_ID(0x14f15110, "CX20751/2"), 1448 HDA_CODEC_ID(0x14f15111, "CX20753/4"), 1449 HDA_CODEC_ID(0x14f15113, "CX20755"), 1450 HDA_CODEC_ID(0x14f15114, "CX20756"), 1451 HDA_CODEC_ID(0x14f15115, "CX20757"), 1452 HDA_CODEC_ID(0x14f151d7, "CX20952"), 1453 {} /* terminator */ 1454 }; 1455 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_conexant); 1456 1457 MODULE_LICENSE("GPL"); 1458 MODULE_DESCRIPTION("Conexant HD-audio codec"); 1459 1460 static struct hda_codec_driver conexant_driver = { 1461 .id = snd_hda_id_conexant, 1462 .ops = &cx_codec_ops, 1463 }; 1464 1465 module_hda_codec_driver(conexant_driver); 1466