1 /* 2 * HD audio interface patch for Conexant HDA audio codec 3 * 4 * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5 * Takashi Iwai <tiwai@suse.de> 6 * Tobin Davis <tdavis@dsl-only.net> 7 * 8 * This driver is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This driver is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 #include <linux/init.h> 24 #include <linux/delay.h> 25 #include <linux/slab.h> 26 #include <linux/pci.h> 27 #include <linux/module.h> 28 #include <sound/core.h> 29 #include <sound/jack.h> 30 31 #include "hda_codec.h" 32 #include "hda_local.h" 33 #include "hda_auto_parser.h" 34 #include "hda_beep.h" 35 #include "hda_jack.h" 36 37 #define CXT_PIN_DIR_IN 0x00 38 #define CXT_PIN_DIR_OUT 0x01 39 #define CXT_PIN_DIR_INOUT 0x02 40 #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 41 #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 42 43 #define CONEXANT_HP_EVENT 0x37 44 #define CONEXANT_MIC_EVENT 0x38 45 #define CONEXANT_LINE_EVENT 0x39 46 47 /* Conexant 5051 specific */ 48 49 #define CXT5051_SPDIF_OUT 0x12 50 #define CXT5051_PORTB_EVENT 0x38 51 #define CXT5051_PORTC_EVENT 0x39 52 53 #define AUTO_MIC_PORTB (1 << 1) 54 #define AUTO_MIC_PORTC (1 << 2) 55 56 struct pin_dac_pair { 57 hda_nid_t pin; 58 hda_nid_t dac; 59 int type; 60 }; 61 62 struct imux_info { 63 hda_nid_t pin; /* input pin NID */ 64 hda_nid_t adc; /* connected ADC NID */ 65 hda_nid_t boost; /* optional boost volume NID */ 66 int index; /* corresponding to autocfg.input */ 67 }; 68 69 struct conexant_spec { 70 struct hda_gen_spec gen; 71 72 const struct snd_kcontrol_new *mixers[5]; 73 int num_mixers; 74 hda_nid_t vmaster_nid; 75 struct hda_vmaster_mute_hook vmaster_mute; 76 bool vmaster_mute_led; 77 78 const struct hda_verb *init_verbs[5]; /* initialization verbs 79 * don't forget NULL 80 * termination! 81 */ 82 unsigned int num_init_verbs; 83 84 /* playback */ 85 struct hda_multi_out multiout; /* playback set-up 86 * max_channels, dacs must be set 87 * dig_out_nid and hp_nid are optional 88 */ 89 unsigned int cur_eapd; 90 unsigned int hp_present; 91 unsigned int line_present; 92 unsigned int auto_mic; 93 int auto_mic_ext; /* imux_pins[] index for ext mic */ 94 int auto_mic_dock; /* imux_pins[] index for dock mic */ 95 int auto_mic_int; /* imux_pins[] index for int mic */ 96 unsigned int need_dac_fix; 97 hda_nid_t slave_dig_outs[2]; 98 99 /* capture */ 100 unsigned int num_adc_nids; 101 const hda_nid_t *adc_nids; 102 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 103 104 unsigned int cur_adc_idx; 105 hda_nid_t cur_adc; 106 unsigned int cur_adc_stream_tag; 107 unsigned int cur_adc_format; 108 109 const struct hda_pcm_stream *capture_stream; 110 111 /* capture source */ 112 const struct hda_input_mux *input_mux; 113 const hda_nid_t *capsrc_nids; 114 unsigned int cur_mux[3]; 115 116 /* channel model */ 117 const struct hda_channel_mode *channel_mode; 118 int num_channel_mode; 119 120 /* PCM information */ 121 struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 122 123 unsigned int spdif_route; 124 125 /* dynamic controls, init_verbs and input_mux */ 126 struct auto_pin_cfg autocfg; 127 struct hda_input_mux private_imux; 128 struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; 129 hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 130 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 131 struct pin_dac_pair dac_info[8]; 132 int dac_info_filled; 133 134 unsigned int port_d_mode; 135 unsigned int auto_mute:1; /* used in auto-parser */ 136 unsigned int detect_line:1; /* Line-out detection enabled */ 137 unsigned int automute_lines:1; /* automute line-out as well */ 138 unsigned int automute_hp_lo:1; /* both HP and LO available */ 139 unsigned int dell_automute:1; 140 unsigned int dell_vostro:1; 141 unsigned int ideapad:1; 142 unsigned int thinkpad:1; 143 unsigned int hp_laptop:1; 144 unsigned int asus:1; 145 unsigned int pin_eapd_ctrls:1; 146 unsigned int fixup_stereo_dmic:1; 147 148 unsigned int adc_switching:1; 149 150 unsigned int ext_mic_present; 151 unsigned int recording; 152 void (*capture_prepare)(struct hda_codec *codec); 153 void (*capture_cleanup)(struct hda_codec *codec); 154 155 /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 156 * through the microphone jack. 157 * When the user enables this through a mixer switch, both internal and 158 * external microphones are disabled. Gain is fixed at 0dB. In this mode, 159 * we also allow the bias to be configured through a separate mixer 160 * control. */ 161 unsigned int dc_enable; 162 unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 163 unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 164 165 unsigned int beep_amp; 166 167 /* extra EAPD pins */ 168 unsigned int num_eapds; 169 hda_nid_t eapds[4]; 170 }; 171 172 static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 173 struct hda_codec *codec, 174 struct snd_pcm_substream *substream) 175 { 176 struct conexant_spec *spec = codec->spec; 177 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 178 hinfo); 179 } 180 181 static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 182 struct hda_codec *codec, 183 unsigned int stream_tag, 184 unsigned int format, 185 struct snd_pcm_substream *substream) 186 { 187 struct conexant_spec *spec = codec->spec; 188 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 189 stream_tag, 190 format, substream); 191 } 192 193 static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 194 struct hda_codec *codec, 195 struct snd_pcm_substream *substream) 196 { 197 struct conexant_spec *spec = codec->spec; 198 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 199 } 200 201 /* 202 * Digital out 203 */ 204 static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 205 struct hda_codec *codec, 206 struct snd_pcm_substream *substream) 207 { 208 struct conexant_spec *spec = codec->spec; 209 return snd_hda_multi_out_dig_open(codec, &spec->multiout); 210 } 211 212 static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 213 struct hda_codec *codec, 214 struct snd_pcm_substream *substream) 215 { 216 struct conexant_spec *spec = codec->spec; 217 return snd_hda_multi_out_dig_close(codec, &spec->multiout); 218 } 219 220 static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 221 struct hda_codec *codec, 222 unsigned int stream_tag, 223 unsigned int format, 224 struct snd_pcm_substream *substream) 225 { 226 struct conexant_spec *spec = codec->spec; 227 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 228 stream_tag, 229 format, substream); 230 } 231 232 /* 233 * Analog capture 234 */ 235 static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 236 struct hda_codec *codec, 237 unsigned int stream_tag, 238 unsigned int format, 239 struct snd_pcm_substream *substream) 240 { 241 struct conexant_spec *spec = codec->spec; 242 if (spec->capture_prepare) 243 spec->capture_prepare(codec); 244 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 245 stream_tag, 0, format); 246 return 0; 247 } 248 249 static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 250 struct hda_codec *codec, 251 struct snd_pcm_substream *substream) 252 { 253 struct conexant_spec *spec = codec->spec; 254 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 255 if (spec->capture_cleanup) 256 spec->capture_cleanup(codec); 257 return 0; 258 } 259 260 261 262 static const struct hda_pcm_stream conexant_pcm_analog_playback = { 263 .substreams = 1, 264 .channels_min = 2, 265 .channels_max = 2, 266 .nid = 0, /* fill later */ 267 .ops = { 268 .open = conexant_playback_pcm_open, 269 .prepare = conexant_playback_pcm_prepare, 270 .cleanup = conexant_playback_pcm_cleanup 271 }, 272 }; 273 274 static const struct hda_pcm_stream conexant_pcm_analog_capture = { 275 .substreams = 1, 276 .channels_min = 2, 277 .channels_max = 2, 278 .nid = 0, /* fill later */ 279 .ops = { 280 .prepare = conexant_capture_pcm_prepare, 281 .cleanup = conexant_capture_pcm_cleanup 282 }, 283 }; 284 285 286 static const struct hda_pcm_stream conexant_pcm_digital_playback = { 287 .substreams = 1, 288 .channels_min = 2, 289 .channels_max = 2, 290 .nid = 0, /* fill later */ 291 .ops = { 292 .open = conexant_dig_playback_pcm_open, 293 .close = conexant_dig_playback_pcm_close, 294 .prepare = conexant_dig_playback_pcm_prepare 295 }, 296 }; 297 298 static const struct hda_pcm_stream conexant_pcm_digital_capture = { 299 .substreams = 1, 300 .channels_min = 2, 301 .channels_max = 2, 302 /* NID is set in alc_build_pcms */ 303 }; 304 305 static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 306 struct hda_codec *codec, 307 unsigned int stream_tag, 308 unsigned int format, 309 struct snd_pcm_substream *substream) 310 { 311 struct conexant_spec *spec = codec->spec; 312 spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 313 spec->cur_adc_stream_tag = stream_tag; 314 spec->cur_adc_format = format; 315 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 316 return 0; 317 } 318 319 static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 320 struct hda_codec *codec, 321 struct snd_pcm_substream *substream) 322 { 323 struct conexant_spec *spec = codec->spec; 324 snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 325 spec->cur_adc = 0; 326 return 0; 327 } 328 329 static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 330 .substreams = 1, 331 .channels_min = 2, 332 .channels_max = 2, 333 .nid = 0, /* fill later */ 334 .ops = { 335 .prepare = cx5051_capture_pcm_prepare, 336 .cleanup = cx5051_capture_pcm_cleanup 337 }, 338 }; 339 340 static bool is_2_1_speaker(struct conexant_spec *spec); 341 342 static int conexant_build_pcms(struct hda_codec *codec) 343 { 344 struct conexant_spec *spec = codec->spec; 345 struct hda_pcm *info = spec->pcm_rec; 346 347 codec->num_pcms = 1; 348 codec->pcm_info = info; 349 350 info->name = "CONEXANT Analog"; 351 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 352 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 353 spec->multiout.max_channels; 354 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 355 spec->multiout.dac_nids[0]; 356 if (is_2_1_speaker(spec)) 357 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap = 358 snd_pcm_2_1_chmaps; 359 if (spec->capture_stream) 360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 361 else { 362 if (codec->vendor_id == 0x14f15051) 363 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 364 cx5051_pcm_analog_capture; 365 else { 366 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 367 conexant_pcm_analog_capture; 368 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 369 spec->num_adc_nids; 370 } 371 } 372 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 373 374 if (spec->multiout.dig_out_nid) { 375 info++; 376 codec->num_pcms++; 377 info->name = "Conexant Digital"; 378 info->pcm_type = HDA_PCM_TYPE_SPDIF; 379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 380 conexant_pcm_digital_playback; 381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 382 spec->multiout.dig_out_nid; 383 if (spec->dig_in_nid) { 384 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 385 conexant_pcm_digital_capture; 386 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 387 spec->dig_in_nid; 388 } 389 if (spec->slave_dig_outs[0]) 390 codec->slave_dig_outs = spec->slave_dig_outs; 391 } 392 393 return 0; 394 } 395 396 static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 397 struct snd_ctl_elem_info *uinfo) 398 { 399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 400 struct conexant_spec *spec = codec->spec; 401 402 return snd_hda_input_mux_info(spec->input_mux, uinfo); 403 } 404 405 static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 406 struct snd_ctl_elem_value *ucontrol) 407 { 408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 409 struct conexant_spec *spec = codec->spec; 410 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 411 412 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 413 return 0; 414 } 415 416 static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 417 struct snd_ctl_elem_value *ucontrol) 418 { 419 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 420 struct conexant_spec *spec = codec->spec; 421 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 422 423 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 424 spec->capsrc_nids[adc_idx], 425 &spec->cur_mux[adc_idx]); 426 } 427 428 static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 429 unsigned int power_state) 430 { 431 if (power_state == AC_PWRST_D3) 432 msleep(100); 433 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 434 power_state); 435 /* partial workaround for "azx_get_response timeout" */ 436 if (power_state == AC_PWRST_D0) 437 msleep(10); 438 snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 439 } 440 441 static int conexant_init(struct hda_codec *codec) 442 { 443 struct conexant_spec *spec = codec->spec; 444 int i; 445 446 for (i = 0; i < spec->num_init_verbs; i++) 447 snd_hda_sequence_write(codec, spec->init_verbs[i]); 448 return 0; 449 } 450 451 static void conexant_free(struct hda_codec *codec) 452 { 453 struct conexant_spec *spec = codec->spec; 454 snd_hda_gen_free(&spec->gen); 455 snd_hda_detach_beep_device(codec); 456 kfree(spec); 457 } 458 459 static const struct snd_kcontrol_new cxt_capture_mixers[] = { 460 { 461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 462 .name = "Capture Source", 463 .info = conexant_mux_enum_info, 464 .get = conexant_mux_enum_get, 465 .put = conexant_mux_enum_put 466 }, 467 {} 468 }; 469 470 #ifdef CONFIG_SND_HDA_INPUT_BEEP 471 /* additional beep mixers; the actual parameters are overwritten at build */ 472 static const struct snd_kcontrol_new cxt_beep_mixer[] = { 473 HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 474 HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 475 { } /* end */ 476 }; 477 #endif 478 479 static const char * const slave_pfxs[] = { 480 "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE", 481 NULL 482 }; 483 484 static int conexant_build_controls(struct hda_codec *codec) 485 { 486 struct conexant_spec *spec = codec->spec; 487 unsigned int i; 488 int err; 489 490 for (i = 0; i < spec->num_mixers; i++) { 491 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 492 if (err < 0) 493 return err; 494 } 495 if (spec->multiout.dig_out_nid) { 496 err = snd_hda_create_spdif_out_ctls(codec, 497 spec->multiout.dig_out_nid, 498 spec->multiout.dig_out_nid); 499 if (err < 0) 500 return err; 501 err = snd_hda_create_spdif_share_sw(codec, 502 &spec->multiout); 503 if (err < 0) 504 return err; 505 spec->multiout.share_spdif = 1; 506 } 507 if (spec->dig_in_nid) { 508 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 509 if (err < 0) 510 return err; 511 } 512 513 /* if we have no master control, let's create it */ 514 if (spec->vmaster_nid && 515 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 516 unsigned int vmaster_tlv[4]; 517 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 518 HDA_OUTPUT, vmaster_tlv); 519 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 520 vmaster_tlv, slave_pfxs, 521 "Playback Volume"); 522 if (err < 0) 523 return err; 524 } 525 if (spec->vmaster_nid && 526 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 527 err = __snd_hda_add_vmaster(codec, "Master Playback Switch", 528 NULL, slave_pfxs, 529 "Playback Switch", true, 530 &spec->vmaster_mute.sw_kctl); 531 if (err < 0) 532 return err; 533 } 534 535 if (spec->input_mux) { 536 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 537 if (err < 0) 538 return err; 539 } 540 541 #ifdef CONFIG_SND_HDA_INPUT_BEEP 542 /* create beep controls if needed */ 543 if (spec->beep_amp) { 544 const struct snd_kcontrol_new *knew; 545 for (knew = cxt_beep_mixer; knew->name; knew++) { 546 struct snd_kcontrol *kctl; 547 kctl = snd_ctl_new1(knew, codec); 548 if (!kctl) 549 return -ENOMEM; 550 kctl->private_value = spec->beep_amp; 551 err = snd_hda_ctl_add(codec, 0, kctl); 552 if (err < 0) 553 return err; 554 } 555 } 556 #endif 557 558 return 0; 559 } 560 561 static const struct hda_codec_ops conexant_patch_ops = { 562 .build_controls = conexant_build_controls, 563 .build_pcms = conexant_build_pcms, 564 .init = conexant_init, 565 .free = conexant_free, 566 .set_power_state = conexant_set_power, 567 }; 568 569 #ifdef CONFIG_SND_HDA_INPUT_BEEP 570 #define set_beep_amp(spec, nid, idx, dir) \ 571 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 572 #else 573 #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 574 #endif 575 576 static int patch_conexant_auto(struct hda_codec *codec); 577 /* 578 * EAPD control 579 * the private value = nid | (invert << 8) 580 */ 581 582 #define cxt_eapd_info snd_ctl_boolean_mono_info 583 584 static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 585 struct snd_ctl_elem_value *ucontrol) 586 { 587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 588 struct conexant_spec *spec = codec->spec; 589 int invert = (kcontrol->private_value >> 8) & 1; 590 if (invert) 591 ucontrol->value.integer.value[0] = !spec->cur_eapd; 592 else 593 ucontrol->value.integer.value[0] = spec->cur_eapd; 594 return 0; 595 596 } 597 598 static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 599 struct snd_ctl_elem_value *ucontrol) 600 { 601 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 602 struct conexant_spec *spec = codec->spec; 603 int invert = (kcontrol->private_value >> 8) & 1; 604 hda_nid_t nid = kcontrol->private_value & 0xff; 605 unsigned int eapd; 606 607 eapd = !!ucontrol->value.integer.value[0]; 608 if (invert) 609 eapd = !eapd; 610 if (eapd == spec->cur_eapd) 611 return 0; 612 613 spec->cur_eapd = eapd; 614 snd_hda_codec_write_cache(codec, nid, 615 0, AC_VERB_SET_EAPD_BTLENABLE, 616 eapd ? 0x02 : 0x00); 617 return 1; 618 } 619 620 /* controls for test mode */ 621 #ifdef CONFIG_SND_DEBUG 622 623 #define CXT_EAPD_SWITCH(xname, nid, mask) \ 624 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 625 .info = cxt_eapd_info, \ 626 .get = cxt_eapd_get, \ 627 .put = cxt_eapd_put, \ 628 .private_value = nid | (mask<<16) } 629 630 631 632 static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 633 struct snd_ctl_elem_info *uinfo) 634 { 635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 636 struct conexant_spec *spec = codec->spec; 637 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 638 spec->num_channel_mode); 639 } 640 641 static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 642 struct snd_ctl_elem_value *ucontrol) 643 { 644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 645 struct conexant_spec *spec = codec->spec; 646 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 647 spec->num_channel_mode, 648 spec->multiout.max_channels); 649 } 650 651 static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 652 struct snd_ctl_elem_value *ucontrol) 653 { 654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 655 struct conexant_spec *spec = codec->spec; 656 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 657 spec->num_channel_mode, 658 &spec->multiout.max_channels); 659 if (err >= 0 && spec->need_dac_fix) 660 spec->multiout.num_dacs = spec->multiout.max_channels / 2; 661 return err; 662 } 663 664 #define CXT_PIN_MODE(xname, nid, dir) \ 665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 666 .info = conexant_ch_mode_info, \ 667 .get = conexant_ch_mode_get, \ 668 .put = conexant_ch_mode_put, \ 669 .private_value = nid | (dir<<16) } 670 671 #endif /* CONFIG_SND_DEBUG */ 672 673 /* Conexant 5045 specific */ 674 675 static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 676 static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 677 static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 678 #define CXT5045_SPDIF_OUT 0x18 679 680 static const struct hda_channel_mode cxt5045_modes[1] = { 681 { 2, NULL }, 682 }; 683 684 static const struct hda_input_mux cxt5045_capture_source = { 685 .num_items = 2, 686 .items = { 687 { "Internal Mic", 0x1 }, 688 { "Mic", 0x2 }, 689 } 690 }; 691 692 static const struct hda_input_mux cxt5045_capture_source_benq = { 693 .num_items = 4, 694 .items = { 695 { "Internal Mic", 0x1 }, 696 { "Mic", 0x2 }, 697 { "Line", 0x3 }, 698 { "Mixer", 0x0 }, 699 } 700 }; 701 702 static const struct hda_input_mux cxt5045_capture_source_hp530 = { 703 .num_items = 2, 704 .items = { 705 { "Mic", 0x1 }, 706 { "Internal Mic", 0x2 }, 707 } 708 }; 709 710 /* turn on/off EAPD (+ mute HP) as a master switch */ 711 static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 712 struct snd_ctl_elem_value *ucontrol) 713 { 714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 715 struct conexant_spec *spec = codec->spec; 716 unsigned int bits; 717 718 if (!cxt_eapd_put(kcontrol, ucontrol)) 719 return 0; 720 721 /* toggle internal speakers mute depending of presence of 722 * the headphone jack 723 */ 724 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 725 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 726 HDA_AMP_MUTE, bits); 727 728 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 729 snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 730 HDA_AMP_MUTE, bits); 731 return 1; 732 } 733 734 /* bind volumes of both NID 0x10 and 0x11 */ 735 static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 736 .ops = &snd_hda_bind_vol, 737 .values = { 738 HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 739 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 740 0 741 }, 742 }; 743 744 /* toggle input of built-in and mic jack appropriately */ 745 static void cxt5045_hp_automic(struct hda_codec *codec) 746 { 747 static const struct hda_verb mic_jack_on[] = { 748 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 749 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 750 {} 751 }; 752 static const struct hda_verb mic_jack_off[] = { 753 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 754 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 755 {} 756 }; 757 unsigned int present; 758 759 present = snd_hda_jack_detect(codec, 0x12); 760 if (present) 761 snd_hda_sequence_write(codec, mic_jack_on); 762 else 763 snd_hda_sequence_write(codec, mic_jack_off); 764 } 765 766 767 /* mute internal speaker if HP is plugged */ 768 static void cxt5045_hp_automute(struct hda_codec *codec) 769 { 770 struct conexant_spec *spec = codec->spec; 771 unsigned int bits; 772 773 spec->hp_present = snd_hda_jack_detect(codec, 0x11); 774 775 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 776 snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 777 HDA_AMP_MUTE, bits); 778 } 779 780 /* unsolicited event for HP jack sensing */ 781 static void cxt5045_hp_unsol_event(struct hda_codec *codec, 782 unsigned int res) 783 { 784 res >>= 26; 785 switch (res) { 786 case CONEXANT_HP_EVENT: 787 cxt5045_hp_automute(codec); 788 break; 789 case CONEXANT_MIC_EVENT: 790 cxt5045_hp_automic(codec); 791 break; 792 793 } 794 } 795 796 static const struct snd_kcontrol_new cxt5045_mixers[] = { 797 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 798 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 799 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 800 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 801 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 802 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 803 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 804 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 805 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 806 { 807 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 808 .name = "Master Playback Switch", 809 .info = cxt_eapd_info, 810 .get = cxt_eapd_get, 811 .put = cxt5045_hp_master_sw_put, 812 .private_value = 0x10, 813 }, 814 815 {} 816 }; 817 818 static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 819 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), 820 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), 821 822 {} 823 }; 824 825 static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 826 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 827 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 828 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 829 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 830 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 831 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 832 HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 833 HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 834 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 835 { 836 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 837 .name = "Master Playback Switch", 838 .info = cxt_eapd_info, 839 .get = cxt_eapd_get, 840 .put = cxt5045_hp_master_sw_put, 841 .private_value = 0x10, 842 }, 843 844 {} 845 }; 846 847 static const struct hda_verb cxt5045_init_verbs[] = { 848 /* Line in, Mic */ 849 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 850 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 851 /* HP, Amp */ 852 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 853 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 854 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 855 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 856 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 857 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 858 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 859 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 860 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 861 /* Record selector: Internal mic */ 862 {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 863 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 864 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 865 /* SPDIF route: PCM */ 866 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 867 { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 868 /* EAPD */ 869 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 870 { } /* end */ 871 }; 872 873 static const struct hda_verb cxt5045_benq_init_verbs[] = { 874 /* Internal Mic, Mic */ 875 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 876 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 877 /* Line In,HP, Amp */ 878 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 879 {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 880 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 881 {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 882 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 883 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 884 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 885 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 886 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 887 /* Record selector: Internal mic */ 888 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 889 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 890 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 891 /* SPDIF route: PCM */ 892 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 893 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 894 /* EAPD */ 895 {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 896 { } /* end */ 897 }; 898 899 static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 900 /* pin sensing on HP jack */ 901 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 902 { } /* end */ 903 }; 904 905 static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 906 /* pin sensing on HP jack */ 907 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 908 { } /* end */ 909 }; 910 911 #ifdef CONFIG_SND_DEBUG 912 /* Test configuration for debugging, modelled after the ALC260 test 913 * configuration. 914 */ 915 static const struct hda_input_mux cxt5045_test_capture_source = { 916 .num_items = 5, 917 .items = { 918 { "MIXER", 0x0 }, 919 { "MIC1 pin", 0x1 }, 920 { "LINE1 pin", 0x2 }, 921 { "HP-OUT pin", 0x3 }, 922 { "CD pin", 0x4 }, 923 }, 924 }; 925 926 static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 927 928 /* Output controls */ 929 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 930 HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 931 HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT), 932 HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT), 933 HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 934 HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 935 936 /* Modes for retasking pin widgets */ 937 CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 938 CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 939 940 /* EAPD Switch Control */ 941 CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 942 943 /* Loopback mixer controls */ 944 945 HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT), 946 HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT), 947 HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT), 948 HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT), 949 HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT), 950 HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT), 951 HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT), 952 HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT), 953 HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT), 954 HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT), 955 { 956 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 957 .name = "Input Source", 958 .info = conexant_mux_enum_info, 959 .get = conexant_mux_enum_get, 960 .put = conexant_mux_enum_put, 961 }, 962 /* Audio input controls */ 963 HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), 964 HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 965 { } /* end */ 966 }; 967 968 static const struct hda_verb cxt5045_test_init_verbs[] = { 969 /* Set connections */ 970 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 971 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 972 { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 973 /* Enable retasking pins as output, initially without power amp */ 974 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 975 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 976 977 /* Disable digital (SPDIF) pins initially, but users can enable 978 * them via a mixer switch. In the case of SPDIF-out, this initverb 979 * payload also sets the generation to 0, output to be in "consumer" 980 * PCM format, copyright asserted, no pre-emphasis and no validity 981 * control. 982 */ 983 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 984 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 985 986 /* Unmute retasking pin widget output buffers since the default 987 * state appears to be output. As the pin mode is changed by the 988 * user the pin mode control will take care of enabling the pin's 989 * input/output buffers as needed. 990 */ 991 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 992 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 993 994 /* Mute capture amp left and right */ 995 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 996 997 /* Set ADC connection select to match default mixer setting (mic1 998 * pin) 999 */ 1000 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, 1001 {0x17, AC_VERB_SET_CONNECT_SEL, 0x01}, 1002 1003 /* Mute all inputs to mixer widget (even unconnected ones) */ 1004 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */ 1005 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1006 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1007 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1008 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1009 1010 { } 1011 }; 1012 #endif 1013 1014 1015 /* initialize jack-sensing, too */ 1016 static int cxt5045_init(struct hda_codec *codec) 1017 { 1018 conexant_init(codec); 1019 cxt5045_hp_automute(codec); 1020 return 0; 1021 } 1022 1023 1024 enum { 1025 CXT5045_LAPTOP_HPSENSE, 1026 CXT5045_LAPTOP_MICSENSE, 1027 CXT5045_LAPTOP_HPMICSENSE, 1028 CXT5045_BENQ, 1029 CXT5045_LAPTOP_HP530, 1030 #ifdef CONFIG_SND_DEBUG 1031 CXT5045_TEST, 1032 #endif 1033 CXT5045_AUTO, 1034 CXT5045_MODELS 1035 }; 1036 1037 static const char * const cxt5045_models[CXT5045_MODELS] = { 1038 [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 1039 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 1040 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 1041 [CXT5045_BENQ] = "benq", 1042 [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1043 #ifdef CONFIG_SND_DEBUG 1044 [CXT5045_TEST] = "test", 1045 #endif 1046 [CXT5045_AUTO] = "auto", 1047 }; 1048 1049 static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 1050 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1051 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 1052 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 1053 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 1054 SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 1055 SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 1056 CXT5045_LAPTOP_HPMICSENSE), 1057 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1058 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1059 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1060 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1061 CXT5045_LAPTOP_HPMICSENSE), 1062 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1063 {} 1064 }; 1065 1066 static int patch_cxt5045(struct hda_codec *codec) 1067 { 1068 struct conexant_spec *spec; 1069 int board_config; 1070 1071 board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1072 cxt5045_models, 1073 cxt5045_cfg_tbl); 1074 if (board_config < 0) 1075 board_config = CXT5045_AUTO; /* model=auto as default */ 1076 if (board_config == CXT5045_AUTO) 1077 return patch_conexant_auto(codec); 1078 1079 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1080 if (!spec) 1081 return -ENOMEM; 1082 codec->spec = spec; 1083 codec->single_adc_amp = 1; 1084 1085 spec->multiout.max_channels = 2; 1086 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1087 spec->multiout.dac_nids = cxt5045_dac_nids; 1088 spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1089 spec->num_adc_nids = 1; 1090 spec->adc_nids = cxt5045_adc_nids; 1091 spec->capsrc_nids = cxt5045_capsrc_nids; 1092 spec->input_mux = &cxt5045_capture_source; 1093 spec->num_mixers = 1; 1094 spec->mixers[0] = cxt5045_mixers; 1095 spec->num_init_verbs = 1; 1096 spec->init_verbs[0] = cxt5045_init_verbs; 1097 spec->spdif_route = 0; 1098 spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 1099 spec->channel_mode = cxt5045_modes; 1100 1101 set_beep_amp(spec, 0x16, 0, 1); 1102 1103 codec->patch_ops = conexant_patch_ops; 1104 1105 switch (board_config) { 1106 case CXT5045_LAPTOP_HPSENSE: 1107 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1108 spec->input_mux = &cxt5045_capture_source; 1109 spec->num_init_verbs = 2; 1110 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 1111 spec->mixers[0] = cxt5045_mixers; 1112 codec->patch_ops.init = cxt5045_init; 1113 break; 1114 case CXT5045_LAPTOP_MICSENSE: 1115 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1116 spec->input_mux = &cxt5045_capture_source; 1117 spec->num_init_verbs = 2; 1118 spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1119 spec->mixers[0] = cxt5045_mixers; 1120 codec->patch_ops.init = cxt5045_init; 1121 break; 1122 default: 1123 case CXT5045_LAPTOP_HPMICSENSE: 1124 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1125 spec->input_mux = &cxt5045_capture_source; 1126 spec->num_init_verbs = 3; 1127 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 1128 spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 1129 spec->mixers[0] = cxt5045_mixers; 1130 codec->patch_ops.init = cxt5045_init; 1131 break; 1132 case CXT5045_BENQ: 1133 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1134 spec->input_mux = &cxt5045_capture_source_benq; 1135 spec->num_init_verbs = 1; 1136 spec->init_verbs[0] = cxt5045_benq_init_verbs; 1137 spec->mixers[0] = cxt5045_mixers; 1138 spec->mixers[1] = cxt5045_benq_mixers; 1139 spec->num_mixers = 2; 1140 codec->patch_ops.init = cxt5045_init; 1141 break; 1142 case CXT5045_LAPTOP_HP530: 1143 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1144 spec->input_mux = &cxt5045_capture_source_hp530; 1145 spec->num_init_verbs = 2; 1146 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 1147 spec->mixers[0] = cxt5045_mixers_hp530; 1148 codec->patch_ops.init = cxt5045_init; 1149 break; 1150 #ifdef CONFIG_SND_DEBUG 1151 case CXT5045_TEST: 1152 spec->input_mux = &cxt5045_test_capture_source; 1153 spec->mixers[0] = cxt5045_test_mixer; 1154 spec->init_verbs[0] = cxt5045_test_init_verbs; 1155 break; 1156 1157 #endif 1158 } 1159 1160 switch (codec->subsystem_id >> 16) { 1161 case 0x103c: 1162 case 0x1631: 1163 case 0x1734: 1164 case 0x17aa: 1165 /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 1166 * really bad sound over 0dB on NID 0x17. Fix max PCM level to 1167 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 1168 */ 1169 snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 1170 (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 1171 (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1172 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1173 (1 << AC_AMPCAP_MUTE_SHIFT)); 1174 break; 1175 } 1176 1177 if (spec->beep_amp) 1178 snd_hda_attach_beep_device(codec, spec->beep_amp); 1179 1180 return 0; 1181 } 1182 1183 1184 /* Conexant 5047 specific */ 1185 #define CXT5047_SPDIF_OUT 0x11 1186 1187 static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1188 static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1189 static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1190 1191 static const struct hda_channel_mode cxt5047_modes[1] = { 1192 { 2, NULL }, 1193 }; 1194 1195 static const struct hda_input_mux cxt5047_toshiba_capture_source = { 1196 .num_items = 2, 1197 .items = { 1198 { "ExtMic", 0x2 }, 1199 { "Line-In", 0x1 }, 1200 } 1201 }; 1202 1203 /* turn on/off EAPD (+ mute HP) as a master switch */ 1204 static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1205 struct snd_ctl_elem_value *ucontrol) 1206 { 1207 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1208 struct conexant_spec *spec = codec->spec; 1209 unsigned int bits; 1210 1211 if (!cxt_eapd_put(kcontrol, ucontrol)) 1212 return 0; 1213 1214 /* toggle internal speakers mute depending of presence of 1215 * the headphone jack 1216 */ 1217 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 1218 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 1219 * pin widgets unlike other codecs. In this case, we need to 1220 * set index 0x01 for the volume from the mixer amp 0x19. 1221 */ 1222 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 1223 HDA_AMP_MUTE, bits); 1224 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 1225 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 1226 HDA_AMP_MUTE, bits); 1227 return 1; 1228 } 1229 1230 /* mute internal speaker if HP is plugged */ 1231 static void cxt5047_hp_automute(struct hda_codec *codec) 1232 { 1233 struct conexant_spec *spec = codec->spec; 1234 unsigned int bits; 1235 1236 spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1237 1238 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 1239 /* See the note in cxt5047_hp_master_sw_put */ 1240 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 1241 HDA_AMP_MUTE, bits); 1242 } 1243 1244 /* toggle input of built-in and mic jack appropriately */ 1245 static void cxt5047_hp_automic(struct hda_codec *codec) 1246 { 1247 static const struct hda_verb mic_jack_on[] = { 1248 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1249 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1250 {} 1251 }; 1252 static const struct hda_verb mic_jack_off[] = { 1253 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1254 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1255 {} 1256 }; 1257 unsigned int present; 1258 1259 present = snd_hda_jack_detect(codec, 0x15); 1260 if (present) 1261 snd_hda_sequence_write(codec, mic_jack_on); 1262 else 1263 snd_hda_sequence_write(codec, mic_jack_off); 1264 } 1265 1266 /* unsolicited event for HP jack sensing */ 1267 static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1268 unsigned int res) 1269 { 1270 switch (res >> 26) { 1271 case CONEXANT_HP_EVENT: 1272 cxt5047_hp_automute(codec); 1273 break; 1274 case CONEXANT_MIC_EVENT: 1275 cxt5047_hp_automic(codec); 1276 break; 1277 } 1278 } 1279 1280 static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1281 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1282 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1283 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1284 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1285 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1286 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1287 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1288 { 1289 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1290 .name = "Master Playback Switch", 1291 .info = cxt_eapd_info, 1292 .get = cxt_eapd_get, 1293 .put = cxt5047_hp_master_sw_put, 1294 .private_value = 0x13, 1295 }, 1296 1297 {} 1298 }; 1299 1300 static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 1301 /* See the note in cxt5047_hp_master_sw_put */ 1302 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1303 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1304 {} 1305 }; 1306 1307 static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1308 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1309 { } /* end */ 1310 }; 1311 1312 static const struct hda_verb cxt5047_init_verbs[] = { 1313 /* Line in, Mic, Built-in Mic */ 1314 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1315 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1316 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1317 /* HP, Speaker */ 1318 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 1319 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 1320 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 1321 /* Record selector: Mic */ 1322 {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 1323 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 1324 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 1325 {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1326 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1327 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1328 {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1329 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1330 /* SPDIF route: PCM */ 1331 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1332 /* Enable unsolicited events */ 1333 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1334 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1335 { } /* end */ 1336 }; 1337 1338 /* configuration for Toshiba Laptops */ 1339 static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 1340 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1341 {} 1342 }; 1343 1344 /* Test configuration for debugging, modelled after the ALC260 test 1345 * configuration. 1346 */ 1347 #ifdef CONFIG_SND_DEBUG 1348 static const struct hda_input_mux cxt5047_test_capture_source = { 1349 .num_items = 4, 1350 .items = { 1351 { "LINE1 pin", 0x0 }, 1352 { "MIC1 pin", 0x1 }, 1353 { "MIC2 pin", 0x2 }, 1354 { "CD pin", 0x3 }, 1355 }, 1356 }; 1357 1358 static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1359 1360 /* Output only controls */ 1361 HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 1362 HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 1363 HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 1364 HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1365 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1366 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1367 HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1368 HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 1369 HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 1370 HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 1371 HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 1372 HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1373 1374 /* Modes for retasking pin widgets */ 1375 CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1376 CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1377 1378 /* EAPD Switch Control */ 1379 CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 1380 1381 /* Loopback mixer controls */ 1382 HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 1383 HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 1384 HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 1385 HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 1386 HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 1387 HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 1388 HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 1389 HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1390 1391 HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 1392 HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 1393 HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 1394 HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 1395 HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 1396 HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 1397 HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 1398 HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1399 { 1400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1401 .name = "Input Source", 1402 .info = conexant_mux_enum_info, 1403 .get = conexant_mux_enum_get, 1404 .put = conexant_mux_enum_put, 1405 }, 1406 HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1407 1408 { } /* end */ 1409 }; 1410 1411 static const struct hda_verb cxt5047_test_init_verbs[] = { 1412 /* Enable retasking pins as output, initially without power amp */ 1413 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1414 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1415 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1416 1417 /* Disable digital (SPDIF) pins initially, but users can enable 1418 * them via a mixer switch. In the case of SPDIF-out, this initverb 1419 * payload also sets the generation to 0, output to be in "consumer" 1420 * PCM format, copyright asserted, no pre-emphasis and no validity 1421 * control. 1422 */ 1423 {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1424 1425 /* Ensure mic1, mic2, line1 pin widgets take input from the 1426 * OUT1 sum bus when acting as an output. 1427 */ 1428 {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1429 {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1430 1431 /* Start with output sum widgets muted and their output gains at min */ 1432 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1433 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1434 1435 /* Unmute retasking pin widget output buffers since the default 1436 * state appears to be output. As the pin mode is changed by the 1437 * user the pin mode control will take care of enabling the pin's 1438 * input/output buffers as needed. 1439 */ 1440 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1441 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1442 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1443 1444 /* Mute capture amp left and right */ 1445 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1446 1447 /* Set ADC connection select to match default mixer setting (mic1 1448 * pin) 1449 */ 1450 {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1451 1452 /* Mute all inputs to mixer widget (even unconnected ones) */ 1453 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1454 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1455 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1456 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1457 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1458 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1459 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1460 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1461 1462 { } 1463 }; 1464 #endif 1465 1466 1467 /* initialize jack-sensing, too */ 1468 static int cxt5047_hp_init(struct hda_codec *codec) 1469 { 1470 conexant_init(codec); 1471 cxt5047_hp_automute(codec); 1472 return 0; 1473 } 1474 1475 1476 enum { 1477 CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1478 CXT5047_LAPTOP_HP, /* Some HP laptops */ 1479 CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1480 #ifdef CONFIG_SND_DEBUG 1481 CXT5047_TEST, 1482 #endif 1483 CXT5047_AUTO, 1484 CXT5047_MODELS 1485 }; 1486 1487 static const char * const cxt5047_models[CXT5047_MODELS] = { 1488 [CXT5047_LAPTOP] = "laptop", 1489 [CXT5047_LAPTOP_HP] = "laptop-hp", 1490 [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1491 #ifdef CONFIG_SND_DEBUG 1492 [CXT5047_TEST] = "test", 1493 #endif 1494 [CXT5047_AUTO] = "auto", 1495 }; 1496 1497 static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1498 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1499 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1500 CXT5047_LAPTOP), 1501 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1502 {} 1503 }; 1504 1505 static int patch_cxt5047(struct hda_codec *codec) 1506 { 1507 struct conexant_spec *spec; 1508 int board_config; 1509 1510 board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1511 cxt5047_models, 1512 cxt5047_cfg_tbl); 1513 if (board_config < 0) 1514 board_config = CXT5047_AUTO; /* model=auto as default */ 1515 if (board_config == CXT5047_AUTO) 1516 return patch_conexant_auto(codec); 1517 1518 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1519 if (!spec) 1520 return -ENOMEM; 1521 codec->spec = spec; 1522 codec->pin_amp_workaround = 1; 1523 1524 spec->multiout.max_channels = 2; 1525 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1526 spec->multiout.dac_nids = cxt5047_dac_nids; 1527 spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1528 spec->num_adc_nids = 1; 1529 spec->adc_nids = cxt5047_adc_nids; 1530 spec->capsrc_nids = cxt5047_capsrc_nids; 1531 spec->num_mixers = 1; 1532 spec->mixers[0] = cxt5047_base_mixers; 1533 spec->num_init_verbs = 1; 1534 spec->init_verbs[0] = cxt5047_init_verbs; 1535 spec->spdif_route = 0; 1536 spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 1537 spec->channel_mode = cxt5047_modes, 1538 1539 codec->patch_ops = conexant_patch_ops; 1540 1541 switch (board_config) { 1542 case CXT5047_LAPTOP: 1543 spec->num_mixers = 2; 1544 spec->mixers[1] = cxt5047_hp_spk_mixers; 1545 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1546 break; 1547 case CXT5047_LAPTOP_HP: 1548 spec->num_mixers = 2; 1549 spec->mixers[1] = cxt5047_hp_only_mixers; 1550 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1551 codec->patch_ops.init = cxt5047_hp_init; 1552 break; 1553 case CXT5047_LAPTOP_EAPD: 1554 spec->input_mux = &cxt5047_toshiba_capture_source; 1555 spec->num_mixers = 2; 1556 spec->mixers[1] = cxt5047_hp_spk_mixers; 1557 spec->num_init_verbs = 2; 1558 spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1559 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1560 break; 1561 #ifdef CONFIG_SND_DEBUG 1562 case CXT5047_TEST: 1563 spec->input_mux = &cxt5047_test_capture_source; 1564 spec->mixers[0] = cxt5047_test_mixer; 1565 spec->init_verbs[0] = cxt5047_test_init_verbs; 1566 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1567 #endif 1568 } 1569 spec->vmaster_nid = 0x13; 1570 1571 switch (codec->subsystem_id >> 16) { 1572 case 0x103c: 1573 /* HP laptops have really bad sound over 0 dB on NID 0x10. 1574 * Fix max PCM level to 0 dB (originally it has 0x1e steps 1575 * with 0 dB offset 0x17) 1576 */ 1577 snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1578 (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1579 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1580 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1581 (1 << AC_AMPCAP_MUTE_SHIFT)); 1582 break; 1583 } 1584 1585 return 0; 1586 } 1587 1588 /* Conexant 5051 specific */ 1589 static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1590 static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1591 1592 static const struct hda_channel_mode cxt5051_modes[1] = { 1593 { 2, NULL }, 1594 }; 1595 1596 static void cxt5051_update_speaker(struct hda_codec *codec) 1597 { 1598 struct conexant_spec *spec = codec->spec; 1599 unsigned int pinctl; 1600 /* headphone pin */ 1601 pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 1602 snd_hda_set_pin_ctl(codec, 0x16, pinctl); 1603 /* speaker pin */ 1604 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1605 snd_hda_set_pin_ctl(codec, 0x1a, pinctl); 1606 /* on ideapad there is an additional speaker (subwoofer) to mute */ 1607 if (spec->ideapad) 1608 snd_hda_set_pin_ctl(codec, 0x1b, pinctl); 1609 } 1610 1611 /* turn on/off EAPD (+ mute HP) as a master switch */ 1612 static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1613 struct snd_ctl_elem_value *ucontrol) 1614 { 1615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1616 1617 if (!cxt_eapd_put(kcontrol, ucontrol)) 1618 return 0; 1619 cxt5051_update_speaker(codec); 1620 return 1; 1621 } 1622 1623 /* toggle input of built-in and mic jack appropriately */ 1624 static void cxt5051_portb_automic(struct hda_codec *codec) 1625 { 1626 struct conexant_spec *spec = codec->spec; 1627 unsigned int present; 1628 1629 if (!(spec->auto_mic & AUTO_MIC_PORTB)) 1630 return; 1631 present = snd_hda_jack_detect(codec, 0x17); 1632 snd_hda_codec_write(codec, 0x14, 0, 1633 AC_VERB_SET_CONNECT_SEL, 1634 present ? 0x01 : 0x00); 1635 } 1636 1637 /* switch the current ADC according to the jack state */ 1638 static void cxt5051_portc_automic(struct hda_codec *codec) 1639 { 1640 struct conexant_spec *spec = codec->spec; 1641 unsigned int present; 1642 hda_nid_t new_adc; 1643 1644 if (!(spec->auto_mic & AUTO_MIC_PORTC)) 1645 return; 1646 present = snd_hda_jack_detect(codec, 0x18); 1647 if (present) 1648 spec->cur_adc_idx = 1; 1649 else 1650 spec->cur_adc_idx = 0; 1651 new_adc = spec->adc_nids[spec->cur_adc_idx]; 1652 if (spec->cur_adc && spec->cur_adc != new_adc) { 1653 /* stream is running, let's swap the current ADC */ 1654 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1655 spec->cur_adc = new_adc; 1656 snd_hda_codec_setup_stream(codec, new_adc, 1657 spec->cur_adc_stream_tag, 0, 1658 spec->cur_adc_format); 1659 } 1660 } 1661 1662 /* mute internal speaker if HP is plugged */ 1663 static void cxt5051_hp_automute(struct hda_codec *codec) 1664 { 1665 struct conexant_spec *spec = codec->spec; 1666 1667 spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1668 cxt5051_update_speaker(codec); 1669 } 1670 1671 /* unsolicited event for HP jack sensing */ 1672 static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1673 unsigned int res) 1674 { 1675 switch (res >> 26) { 1676 case CONEXANT_HP_EVENT: 1677 cxt5051_hp_automute(codec); 1678 break; 1679 case CXT5051_PORTB_EVENT: 1680 cxt5051_portb_automic(codec); 1681 break; 1682 case CXT5051_PORTC_EVENT: 1683 cxt5051_portc_automic(codec); 1684 break; 1685 } 1686 } 1687 1688 static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1689 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1690 { 1691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1692 .name = "Master Playback Switch", 1693 .info = cxt_eapd_info, 1694 .get = cxt_eapd_get, 1695 .put = cxt5051_hp_master_sw_put, 1696 .private_value = 0x1a, 1697 }, 1698 {} 1699 }; 1700 1701 static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 1702 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1703 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1704 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 1705 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1706 HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT), 1707 HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT), 1708 {} 1709 }; 1710 1711 static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1712 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1713 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1714 HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 1715 HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1716 {} 1717 }; 1718 1719 static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 1720 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 1721 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 1722 {} 1723 }; 1724 1725 static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 1726 HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 1727 HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1728 {} 1729 }; 1730 1731 static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1732 HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1733 HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1734 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 1735 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1736 {} 1737 }; 1738 1739 static const struct hda_verb cxt5051_init_verbs[] = { 1740 /* Line in, Mic */ 1741 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1742 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1743 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1744 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1745 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1746 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1747 /* SPK */ 1748 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1749 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1750 /* HP, Amp */ 1751 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1752 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1753 /* DAC1 */ 1754 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1755 /* Record selector: Internal mic */ 1756 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1757 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1758 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1759 /* SPDIF route: PCM */ 1760 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1761 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1762 /* EAPD */ 1763 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1764 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1765 { } /* end */ 1766 }; 1767 1768 static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 1769 /* Line in, Mic */ 1770 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1771 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1772 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1773 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1774 /* SPK */ 1775 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1776 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1777 /* HP, Amp */ 1778 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1779 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1780 /* DAC1 */ 1781 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1782 /* Record selector: Internal mic */ 1783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1784 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1785 /* SPDIF route: PCM */ 1786 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1787 /* EAPD */ 1788 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1789 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1790 { } /* end */ 1791 }; 1792 1793 static const struct hda_verb cxt5051_f700_init_verbs[] = { 1794 /* Line in, Mic */ 1795 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1796 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1797 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1798 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1799 /* SPK */ 1800 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1801 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1802 /* HP, Amp */ 1803 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1804 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1805 /* DAC1 */ 1806 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1807 /* Record selector: Internal mic */ 1808 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1809 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1810 /* SPDIF route: PCM */ 1811 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1812 /* EAPD */ 1813 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1814 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1815 { } /* end */ 1816 }; 1817 1818 static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 1819 unsigned int event) 1820 { 1821 snd_hda_codec_write(codec, nid, 0, 1822 AC_VERB_SET_UNSOLICITED_ENABLE, 1823 AC_USRSP_EN | event); 1824 } 1825 1826 static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1827 /* Subwoofer */ 1828 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1829 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1830 { } /* end */ 1831 }; 1832 1833 /* initialize jack-sensing, too */ 1834 static int cxt5051_init(struct hda_codec *codec) 1835 { 1836 struct conexant_spec *spec = codec->spec; 1837 1838 conexant_init(codec); 1839 1840 if (spec->auto_mic & AUTO_MIC_PORTB) 1841 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 1842 if (spec->auto_mic & AUTO_MIC_PORTC) 1843 cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 1844 1845 if (codec->patch_ops.unsol_event) { 1846 cxt5051_hp_automute(codec); 1847 cxt5051_portb_automic(codec); 1848 cxt5051_portc_automic(codec); 1849 } 1850 return 0; 1851 } 1852 1853 1854 enum { 1855 CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1856 CXT5051_HP, /* no docking */ 1857 CXT5051_HP_DV6736, /* HP without mic switch */ 1858 CXT5051_F700, /* HP Compaq Presario F700 */ 1859 CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1860 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 1861 CXT5051_AUTO, /* auto-parser */ 1862 CXT5051_MODELS 1863 }; 1864 1865 static const char *const cxt5051_models[CXT5051_MODELS] = { 1866 [CXT5051_LAPTOP] = "laptop", 1867 [CXT5051_HP] = "hp", 1868 [CXT5051_HP_DV6736] = "hp-dv6736", 1869 [CXT5051_F700] = "hp-700", 1870 [CXT5051_TOSHIBA] = "toshiba", 1871 [CXT5051_IDEAPAD] = "ideapad", 1872 [CXT5051_AUTO] = "auto", 1873 }; 1874 1875 static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 1876 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 1877 SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 1878 SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1879 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1880 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1881 CXT5051_LAPTOP), 1882 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1883 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1884 {} 1885 }; 1886 1887 static int patch_cxt5051(struct hda_codec *codec) 1888 { 1889 struct conexant_spec *spec; 1890 int board_config; 1891 1892 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1893 cxt5051_models, 1894 cxt5051_cfg_tbl); 1895 if (board_config < 0) 1896 board_config = CXT5051_AUTO; /* model=auto as default */ 1897 if (board_config == CXT5051_AUTO) 1898 return patch_conexant_auto(codec); 1899 1900 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1901 if (!spec) 1902 return -ENOMEM; 1903 codec->spec = spec; 1904 codec->pin_amp_workaround = 1; 1905 1906 codec->patch_ops = conexant_patch_ops; 1907 codec->patch_ops.init = cxt5051_init; 1908 1909 spec->multiout.max_channels = 2; 1910 spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1911 spec->multiout.dac_nids = cxt5051_dac_nids; 1912 spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1913 spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1914 spec->adc_nids = cxt5051_adc_nids; 1915 spec->num_mixers = 2; 1916 spec->mixers[0] = cxt5051_capture_mixers; 1917 spec->mixers[1] = cxt5051_playback_mixers; 1918 spec->num_init_verbs = 1; 1919 spec->init_verbs[0] = cxt5051_init_verbs; 1920 spec->spdif_route = 0; 1921 spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1922 spec->channel_mode = cxt5051_modes; 1923 spec->cur_adc = 0; 1924 spec->cur_adc_idx = 0; 1925 1926 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 1927 1928 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 1929 1930 spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1931 switch (board_config) { 1932 case CXT5051_HP: 1933 spec->mixers[0] = cxt5051_hp_mixers; 1934 break; 1935 case CXT5051_HP_DV6736: 1936 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 1937 spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1938 spec->auto_mic = 0; 1939 break; 1940 case CXT5051_F700: 1941 spec->init_verbs[0] = cxt5051_f700_init_verbs; 1942 spec->mixers[0] = cxt5051_f700_mixers; 1943 spec->auto_mic = 0; 1944 break; 1945 case CXT5051_TOSHIBA: 1946 spec->mixers[0] = cxt5051_toshiba_mixers; 1947 spec->auto_mic = AUTO_MIC_PORTB; 1948 break; 1949 case CXT5051_IDEAPAD: 1950 spec->init_verbs[spec->num_init_verbs++] = 1951 cxt5051_ideapad_init_verbs; 1952 spec->ideapad = 1; 1953 break; 1954 } 1955 1956 if (spec->beep_amp) 1957 snd_hda_attach_beep_device(codec, spec->beep_amp); 1958 1959 return 0; 1960 } 1961 1962 /* Conexant 5066 specific */ 1963 1964 static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 1965 static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 1966 static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 1967 static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 1968 1969 /* OLPC's microphone port is DC coupled for use with external sensors, 1970 * therefore we use a 50% mic bias in order to center the input signal with 1971 * the DC input range of the codec. */ 1972 #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 1973 1974 static const struct hda_channel_mode cxt5066_modes[1] = { 1975 { 2, NULL }, 1976 }; 1977 1978 #define HP_PRESENT_PORT_A (1 << 0) 1979 #define HP_PRESENT_PORT_D (1 << 1) 1980 #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 1981 #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 1982 1983 static void cxt5066_update_speaker(struct hda_codec *codec) 1984 { 1985 struct conexant_spec *spec = codec->spec; 1986 unsigned int pinctl; 1987 1988 snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 1989 spec->hp_present, spec->cur_eapd); 1990 1991 /* Port A (HP) */ 1992 pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 1993 snd_hda_set_pin_ctl(codec, 0x19, pinctl); 1994 1995 /* Port D (HP/LO) */ 1996 pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 1997 if (spec->dell_automute || spec->thinkpad) { 1998 /* Mute if Port A is connected */ 1999 if (hp_port_a_present(spec)) 2000 pinctl = 0; 2001 } else { 2002 /* Thinkpad/Dell doesn't give pin-D status */ 2003 if (!hp_port_d_present(spec)) 2004 pinctl = 0; 2005 } 2006 snd_hda_set_pin_ctl(codec, 0x1c, pinctl); 2007 2008 /* CLASS_D AMP */ 2009 pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 2010 snd_hda_set_pin_ctl(codec, 0x1f, pinctl); 2011 } 2012 2013 /* turn on/off EAPD (+ mute HP) as a master switch */ 2014 static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 2015 struct snd_ctl_elem_value *ucontrol) 2016 { 2017 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2018 2019 if (!cxt_eapd_put(kcontrol, ucontrol)) 2020 return 0; 2021 2022 cxt5066_update_speaker(codec); 2023 return 1; 2024 } 2025 2026 static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2027 .num_items = 3, 2028 .items = { 2029 { "Off", PIN_IN }, 2030 { "50%", PIN_VREF50 }, 2031 { "80%", PIN_VREF80 }, 2032 }, 2033 }; 2034 2035 static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2036 { 2037 struct conexant_spec *spec = codec->spec; 2038 /* Even though port F is the DC input, the bias is controlled on port B. 2039 * we also leave that port as an active input (but unselected) in DC mode 2040 * just in case that is necessary to make the bias setting take effect. */ 2041 return snd_hda_set_pin_ctl_cache(codec, 0x1a, 2042 cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2043 } 2044 2045 /* OLPC defers mic widget control until when capture is started because the 2046 * microphone LED comes on as soon as these settings are put in place. if we 2047 * did this before recording, it would give the false indication that recording 2048 * is happening when it is not. */ 2049 static void cxt5066_olpc_select_mic(struct hda_codec *codec) 2050 { 2051 struct conexant_spec *spec = codec->spec; 2052 if (!spec->recording) 2053 return; 2054 2055 if (spec->dc_enable) { 2056 /* in DC mode we ignore presence detection and just use the jack 2057 * through our special DC port */ 2058 const struct hda_verb enable_dc_mode[] = { 2059 /* disble internal mic, port C */ 2060 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2061 2062 /* enable DC capture, port F */ 2063 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2064 {}, 2065 }; 2066 2067 snd_hda_sequence_write(codec, enable_dc_mode); 2068 /* port B input disabled (and bias set) through the following call */ 2069 cxt5066_set_olpc_dc_bias(codec); 2070 return; 2071 } 2072 2073 /* disable DC (port F) */ 2074 snd_hda_set_pin_ctl(codec, 0x1e, 0); 2075 2076 /* external mic, port B */ 2077 snd_hda_set_pin_ctl(codec, 0x1a, 2078 spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 2079 2080 /* internal mic, port C */ 2081 snd_hda_set_pin_ctl(codec, 0x1b, 2082 spec->ext_mic_present ? 0 : PIN_VREF80); 2083 } 2084 2085 /* toggle input of built-in and mic jack appropriately */ 2086 static void cxt5066_olpc_automic(struct hda_codec *codec) 2087 { 2088 struct conexant_spec *spec = codec->spec; 2089 unsigned int present; 2090 2091 if (spec->dc_enable) /* don't do presence detection in DC mode */ 2092 return; 2093 2094 present = snd_hda_codec_read(codec, 0x1a, 0, 2095 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 2096 if (present) 2097 snd_printdd("CXT5066: external microphone detected\n"); 2098 else 2099 snd_printdd("CXT5066: external microphone absent\n"); 2100 2101 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2102 present ? 0 : 1); 2103 spec->ext_mic_present = !!present; 2104 2105 cxt5066_olpc_select_mic(codec); 2106 } 2107 2108 /* toggle input of built-in digital mic and mic jack appropriately */ 2109 static void cxt5066_vostro_automic(struct hda_codec *codec) 2110 { 2111 unsigned int present; 2112 2113 struct hda_verb ext_mic_present[] = { 2114 /* enable external mic, port B */ 2115 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2116 2117 /* switch to external mic input */ 2118 {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 2119 {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2120 2121 /* disable internal digital mic */ 2122 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2123 {} 2124 }; 2125 static const struct hda_verb ext_mic_absent[] = { 2126 /* enable internal mic, port C */ 2127 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2128 2129 /* switch to internal mic input */ 2130 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2131 2132 /* disable external mic, port B */ 2133 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2134 {} 2135 }; 2136 2137 present = snd_hda_jack_detect(codec, 0x1a); 2138 if (present) { 2139 snd_printdd("CXT5066: external microphone detected\n"); 2140 snd_hda_sequence_write(codec, ext_mic_present); 2141 } else { 2142 snd_printdd("CXT5066: external microphone absent\n"); 2143 snd_hda_sequence_write(codec, ext_mic_absent); 2144 } 2145 } 2146 2147 /* toggle input of built-in digital mic and mic jack appropriately */ 2148 static void cxt5066_ideapad_automic(struct hda_codec *codec) 2149 { 2150 unsigned int present; 2151 2152 struct hda_verb ext_mic_present[] = { 2153 {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2154 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2155 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2156 {} 2157 }; 2158 static const struct hda_verb ext_mic_absent[] = { 2159 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2160 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2161 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2162 {} 2163 }; 2164 2165 present = snd_hda_jack_detect(codec, 0x1b); 2166 if (present) { 2167 snd_printdd("CXT5066: external microphone detected\n"); 2168 snd_hda_sequence_write(codec, ext_mic_present); 2169 } else { 2170 snd_printdd("CXT5066: external microphone absent\n"); 2171 snd_hda_sequence_write(codec, ext_mic_absent); 2172 } 2173 } 2174 2175 2176 /* toggle input of built-in digital mic and mic jack appropriately */ 2177 static void cxt5066_asus_automic(struct hda_codec *codec) 2178 { 2179 unsigned int present; 2180 2181 present = snd_hda_jack_detect(codec, 0x1b); 2182 snd_printdd("CXT5066: external microphone present=%d\n", present); 2183 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2184 present ? 1 : 0); 2185 } 2186 2187 2188 /* toggle input of built-in digital mic and mic jack appropriately */ 2189 static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2190 { 2191 unsigned int present; 2192 2193 present = snd_hda_jack_detect(codec, 0x1b); 2194 snd_printdd("CXT5066: external microphone present=%d\n", present); 2195 snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2196 present ? 1 : 3); 2197 } 2198 2199 2200 /* toggle input of built-in digital mic and mic jack appropriately 2201 order is: external mic -> dock mic -> interal mic */ 2202 static void cxt5066_thinkpad_automic(struct hda_codec *codec) 2203 { 2204 unsigned int ext_present, dock_present; 2205 2206 static const struct hda_verb ext_mic_present[] = { 2207 {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2208 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 2209 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2210 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2211 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2212 {} 2213 }; 2214 static const struct hda_verb dock_mic_present[] = { 2215 {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2216 {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 2217 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2218 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2219 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2220 {} 2221 }; 2222 static const struct hda_verb ext_mic_absent[] = { 2223 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2224 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2225 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2226 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2227 {} 2228 }; 2229 2230 ext_present = snd_hda_jack_detect(codec, 0x1b); 2231 dock_present = snd_hda_jack_detect(codec, 0x1a); 2232 if (ext_present) { 2233 snd_printdd("CXT5066: external microphone detected\n"); 2234 snd_hda_sequence_write(codec, ext_mic_present); 2235 } else if (dock_present) { 2236 snd_printdd("CXT5066: dock microphone detected\n"); 2237 snd_hda_sequence_write(codec, dock_mic_present); 2238 } else { 2239 snd_printdd("CXT5066: external microphone absent\n"); 2240 snd_hda_sequence_write(codec, ext_mic_absent); 2241 } 2242 } 2243 2244 /* mute internal speaker if HP is plugged */ 2245 static void cxt5066_hp_automute(struct hda_codec *codec) 2246 { 2247 struct conexant_spec *spec = codec->spec; 2248 unsigned int portA, portD; 2249 2250 /* Port A */ 2251 portA = snd_hda_jack_detect(codec, 0x19); 2252 2253 /* Port D */ 2254 portD = snd_hda_jack_detect(codec, 0x1c); 2255 2256 spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2257 spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 2258 snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2259 portA, portD, spec->hp_present); 2260 cxt5066_update_speaker(codec); 2261 } 2262 2263 /* Dispatch the right mic autoswitch function */ 2264 static void cxt5066_automic(struct hda_codec *codec) 2265 { 2266 struct conexant_spec *spec = codec->spec; 2267 2268 if (spec->dell_vostro) 2269 cxt5066_vostro_automic(codec); 2270 else if (spec->ideapad) 2271 cxt5066_ideapad_automic(codec); 2272 else if (spec->thinkpad) 2273 cxt5066_thinkpad_automic(codec); 2274 else if (spec->hp_laptop) 2275 cxt5066_hp_laptop_automic(codec); 2276 else if (spec->asus) 2277 cxt5066_asus_automic(codec); 2278 } 2279 2280 /* unsolicited event for jack sensing */ 2281 static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 2282 { 2283 struct conexant_spec *spec = codec->spec; 2284 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 2285 switch (res >> 26) { 2286 case CONEXANT_HP_EVENT: 2287 cxt5066_hp_automute(codec); 2288 break; 2289 case CONEXANT_MIC_EVENT: 2290 /* ignore mic events in DC mode; we're always using the jack */ 2291 if (!spec->dc_enable) 2292 cxt5066_olpc_automic(codec); 2293 break; 2294 } 2295 } 2296 2297 /* unsolicited event for jack sensing */ 2298 static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 2299 { 2300 snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 2301 switch (res >> 26) { 2302 case CONEXANT_HP_EVENT: 2303 cxt5066_hp_automute(codec); 2304 break; 2305 case CONEXANT_MIC_EVENT: 2306 cxt5066_automic(codec); 2307 break; 2308 } 2309 } 2310 2311 2312 static const struct hda_input_mux cxt5066_analog_mic_boost = { 2313 .num_items = 5, 2314 .items = { 2315 { "0dB", 0 }, 2316 { "10dB", 1 }, 2317 { "20dB", 2 }, 2318 { "30dB", 3 }, 2319 { "40dB", 4 }, 2320 }, 2321 }; 2322 2323 static void cxt5066_set_mic_boost(struct hda_codec *codec) 2324 { 2325 struct conexant_spec *spec = codec->spec; 2326 snd_hda_codec_write_cache(codec, 0x17, 0, 2327 AC_VERB_SET_AMP_GAIN_MUTE, 2328 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2329 cxt5066_analog_mic_boost.items[spec->mic_boost].index); 2330 if (spec->ideapad || spec->thinkpad) { 2331 /* adjust the internal mic as well...it is not through 0x17 */ 2332 snd_hda_codec_write_cache(codec, 0x23, 0, 2333 AC_VERB_SET_AMP_GAIN_MUTE, 2334 AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2335 cxt5066_analog_mic_boost. 2336 items[spec->mic_boost].index); 2337 } 2338 } 2339 2340 static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 2341 struct snd_ctl_elem_info *uinfo) 2342 { 2343 return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 2344 } 2345 2346 static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 2347 struct snd_ctl_elem_value *ucontrol) 2348 { 2349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2350 struct conexant_spec *spec = codec->spec; 2351 ucontrol->value.enumerated.item[0] = spec->mic_boost; 2352 return 0; 2353 } 2354 2355 static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 2356 struct snd_ctl_elem_value *ucontrol) 2357 { 2358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2359 struct conexant_spec *spec = codec->spec; 2360 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2361 unsigned int idx; 2362 idx = ucontrol->value.enumerated.item[0]; 2363 if (idx >= imux->num_items) 2364 idx = imux->num_items - 1; 2365 2366 spec->mic_boost = idx; 2367 if (!spec->dc_enable) 2368 cxt5066_set_mic_boost(codec); 2369 return 1; 2370 } 2371 2372 static void cxt5066_enable_dc(struct hda_codec *codec) 2373 { 2374 const struct hda_verb enable_dc_mode[] = { 2375 /* disable gain */ 2376 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2377 2378 /* switch to DC input */ 2379 {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2380 {} 2381 }; 2382 2383 /* configure as input source */ 2384 snd_hda_sequence_write(codec, enable_dc_mode); 2385 cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2386 } 2387 2388 static void cxt5066_disable_dc(struct hda_codec *codec) 2389 { 2390 /* reconfigure input source */ 2391 cxt5066_set_mic_boost(codec); 2392 /* automic also selects the right mic if we're recording */ 2393 cxt5066_olpc_automic(codec); 2394 } 2395 2396 static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2397 struct snd_ctl_elem_value *ucontrol) 2398 { 2399 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2400 struct conexant_spec *spec = codec->spec; 2401 ucontrol->value.integer.value[0] = spec->dc_enable; 2402 return 0; 2403 } 2404 2405 static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2406 struct snd_ctl_elem_value *ucontrol) 2407 { 2408 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2409 struct conexant_spec *spec = codec->spec; 2410 int dc_enable = !!ucontrol->value.integer.value[0]; 2411 2412 if (dc_enable == spec->dc_enable) 2413 return 0; 2414 2415 spec->dc_enable = dc_enable; 2416 if (dc_enable) 2417 cxt5066_enable_dc(codec); 2418 else 2419 cxt5066_disable_dc(codec); 2420 2421 return 1; 2422 } 2423 2424 static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2425 struct snd_ctl_elem_info *uinfo) 2426 { 2427 return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2428 } 2429 2430 static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2431 struct snd_ctl_elem_value *ucontrol) 2432 { 2433 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2434 struct conexant_spec *spec = codec->spec; 2435 ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2436 return 0; 2437 } 2438 2439 static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2440 struct snd_ctl_elem_value *ucontrol) 2441 { 2442 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2443 struct conexant_spec *spec = codec->spec; 2444 const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2445 unsigned int idx; 2446 2447 idx = ucontrol->value.enumerated.item[0]; 2448 if (idx >= imux->num_items) 2449 idx = imux->num_items - 1; 2450 2451 spec->dc_input_bias = idx; 2452 if (spec->dc_enable) 2453 cxt5066_set_olpc_dc_bias(codec); 2454 return 1; 2455 } 2456 2457 static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 2458 { 2459 struct conexant_spec *spec = codec->spec; 2460 /* mark as recording and configure the microphone widget so that the 2461 * recording LED comes on. */ 2462 spec->recording = 1; 2463 cxt5066_olpc_select_mic(codec); 2464 } 2465 2466 static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 2467 { 2468 struct conexant_spec *spec = codec->spec; 2469 const struct hda_verb disable_mics[] = { 2470 /* disable external mic, port B */ 2471 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2472 2473 /* disble internal mic, port C */ 2474 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2475 2476 /* disable DC capture, port F */ 2477 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2478 {}, 2479 }; 2480 2481 snd_hda_sequence_write(codec, disable_mics); 2482 spec->recording = 0; 2483 } 2484 2485 static void conexant_check_dig_outs(struct hda_codec *codec, 2486 const hda_nid_t *dig_pins, 2487 int num_pins) 2488 { 2489 struct conexant_spec *spec = codec->spec; 2490 hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2491 int i; 2492 2493 for (i = 0; i < num_pins; i++, dig_pins++) { 2494 unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2495 if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2496 continue; 2497 if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2498 continue; 2499 if (spec->slave_dig_outs[0]) 2500 nid_loc++; 2501 else 2502 nid_loc = spec->slave_dig_outs; 2503 } 2504 } 2505 2506 static const struct hda_input_mux cxt5066_capture_source = { 2507 .num_items = 4, 2508 .items = { 2509 { "Mic B", 0 }, 2510 { "Mic C", 1 }, 2511 { "Mic E", 2 }, 2512 { "Mic F", 3 }, 2513 }, 2514 }; 2515 2516 static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 2517 .ops = &snd_hda_bind_vol, 2518 .values = { 2519 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 2520 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 2521 0 2522 }, 2523 }; 2524 2525 static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 2526 .ops = &snd_hda_bind_sw, 2527 .values = { 2528 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 2529 HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 2530 0 2531 }, 2532 }; 2533 2534 static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 2535 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 2536 {} 2537 }; 2538 2539 static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 2540 { 2541 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2542 .name = "Master Playback Volume", 2543 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 2544 SNDRV_CTL_ELEM_ACCESS_TLV_READ | 2545 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 2546 .subdevice = HDA_SUBDEV_AMP_FLAG, 2547 .info = snd_hda_mixer_amp_volume_info, 2548 .get = snd_hda_mixer_amp_volume_get, 2549 .put = snd_hda_mixer_amp_volume_put, 2550 .tlv = { .c = snd_hda_mixer_amp_tlv }, 2551 /* offset by 28 volume steps to limit minimum gain to -46dB */ 2552 .private_value = 2553 HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 2554 }, 2555 {} 2556 }; 2557 2558 static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2559 { 2560 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2561 .name = "DC Mode Enable Switch", 2562 .info = snd_ctl_boolean_mono_info, 2563 .get = cxt5066_olpc_dc_get, 2564 .put = cxt5066_olpc_dc_put, 2565 }, 2566 { 2567 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2568 .name = "DC Input Bias Enum", 2569 .info = cxt5066_olpc_dc_bias_enum_info, 2570 .get = cxt5066_olpc_dc_bias_enum_get, 2571 .put = cxt5066_olpc_dc_bias_enum_put, 2572 }, 2573 {} 2574 }; 2575 2576 static const struct snd_kcontrol_new cxt5066_mixers[] = { 2577 { 2578 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2579 .name = "Master Playback Switch", 2580 .info = cxt_eapd_info, 2581 .get = cxt_eapd_get, 2582 .put = cxt5066_hp_master_sw_put, 2583 .private_value = 0x1d, 2584 }, 2585 2586 { 2587 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2588 .name = "Analog Mic Boost Capture Enum", 2589 .info = cxt5066_mic_boost_mux_enum_info, 2590 .get = cxt5066_mic_boost_mux_enum_get, 2591 .put = cxt5066_mic_boost_mux_enum_put, 2592 }, 2593 2594 HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 2595 HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 2596 {} 2597 }; 2598 2599 static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2600 { 2601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2602 .name = "Internal Mic Boost Capture Enum", 2603 .info = cxt5066_mic_boost_mux_enum_info, 2604 .get = cxt5066_mic_boost_mux_enum_get, 2605 .put = cxt5066_mic_boost_mux_enum_put, 2606 .private_value = 0x23 | 0x100, 2607 }, 2608 {} 2609 }; 2610 2611 static const struct hda_verb cxt5066_init_verbs[] = { 2612 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2613 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2614 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2615 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2616 2617 /* Speakers */ 2618 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2619 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2620 2621 /* HP, Amp */ 2622 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2623 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2624 2625 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2626 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2627 2628 /* DAC1 */ 2629 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2630 2631 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2632 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2633 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2634 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2635 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2636 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2637 2638 /* no digital microphone support yet */ 2639 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2640 2641 /* Audio input selector */ 2642 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 2643 2644 /* SPDIF route: PCM */ 2645 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2646 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2647 2648 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2649 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2650 2651 /* EAPD */ 2652 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2653 2654 /* not handling these yet */ 2655 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2656 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2657 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2658 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2659 {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2660 {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2661 {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2662 {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2663 { } /* end */ 2664 }; 2665 2666 static const struct hda_verb cxt5066_init_verbs_olpc[] = { 2667 /* Port A: headphones */ 2668 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2669 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2670 2671 /* Port B: external microphone */ 2672 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2673 2674 /* Port C: internal microphone */ 2675 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2676 2677 /* Port D: unused */ 2678 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2679 2680 /* Port E: unused, but has primary EAPD */ 2681 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2682 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2683 2684 /* Port F: external DC input through microphone port */ 2685 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2686 2687 /* Port G: internal speakers */ 2688 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2689 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2690 2691 /* DAC1 */ 2692 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2693 2694 /* DAC2: unused */ 2695 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2696 2697 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2698 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2699 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2700 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2701 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2702 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2703 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2704 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2705 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2706 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2707 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2708 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2709 2710 /* Disable digital microphone port */ 2711 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2712 2713 /* Audio input selectors */ 2714 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 2715 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 2716 2717 /* Disable SPDIF */ 2718 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2719 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2720 2721 /* enable unsolicited events for Port A and B */ 2722 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2723 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2724 { } /* end */ 2725 }; 2726 2727 static const struct hda_verb cxt5066_init_verbs_vostro[] = { 2728 /* Port A: headphones */ 2729 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2730 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2731 2732 /* Port B: external microphone */ 2733 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2734 2735 /* Port C: unused */ 2736 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2737 2738 /* Port D: unused */ 2739 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2740 2741 /* Port E: unused, but has primary EAPD */ 2742 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2743 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2744 2745 /* Port F: unused */ 2746 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2747 2748 /* Port G: internal speakers */ 2749 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2750 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2751 2752 /* DAC1 */ 2753 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2754 2755 /* DAC2: unused */ 2756 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2757 2758 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2759 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2761 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2762 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2763 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2764 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2765 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2766 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2767 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2768 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2769 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2770 2771 /* Digital microphone port */ 2772 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2773 2774 /* Audio input selectors */ 2775 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 2776 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 2777 2778 /* Disable SPDIF */ 2779 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2780 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2781 2782 /* enable unsolicited events for Port A and B */ 2783 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2784 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2785 { } /* end */ 2786 }; 2787 2788 static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2789 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2790 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2791 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2792 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2793 2794 /* Speakers */ 2795 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2796 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2797 2798 /* HP, Amp */ 2799 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2800 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2801 2802 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2803 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2804 2805 /* DAC1 */ 2806 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2807 2808 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2809 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2810 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2811 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2813 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2814 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2815 2816 /* Audio input selector */ 2817 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2818 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2819 2820 /* SPDIF route: PCM */ 2821 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2822 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2823 2824 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2825 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2826 2827 /* internal microphone */ 2828 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2829 2830 /* EAPD */ 2831 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2832 2833 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2834 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2835 { } /* end */ 2836 }; 2837 2838 static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 2839 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2840 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2841 2842 /* Port G: internal speakers */ 2843 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2844 {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2845 2846 /* Port A: HP, Amp */ 2847 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2848 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2849 2850 /* Port B: Mic Dock */ 2851 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2852 2853 /* Port C: Mic */ 2854 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2855 2856 /* Port D: HP Dock, Amp */ 2857 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2858 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2859 2860 /* DAC1 */ 2861 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2862 2863 /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2864 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2865 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2866 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2867 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2868 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2869 {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2870 2871 /* Audio input selector */ 2872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2873 {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2874 2875 /* SPDIF route: PCM */ 2876 {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2877 {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2878 2879 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2880 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2881 2882 /* internal microphone */ 2883 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2884 2885 /* EAPD */ 2886 {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2887 2888 /* enable unsolicited events for Port A, B, C and D */ 2889 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2890 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2891 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2892 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2893 { } /* end */ 2894 }; 2895 2896 static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 2897 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2898 { } /* end */ 2899 }; 2900 2901 2902 static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2903 {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2904 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2905 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2906 { } /* end */ 2907 }; 2908 2909 /* initialize jack-sensing, too */ 2910 static int cxt5066_init(struct hda_codec *codec) 2911 { 2912 snd_printdd("CXT5066: init\n"); 2913 conexant_init(codec); 2914 if (codec->patch_ops.unsol_event) { 2915 cxt5066_hp_automute(codec); 2916 cxt5066_automic(codec); 2917 } 2918 cxt5066_set_mic_boost(codec); 2919 return 0; 2920 } 2921 2922 static int cxt5066_olpc_init(struct hda_codec *codec) 2923 { 2924 struct conexant_spec *spec = codec->spec; 2925 snd_printdd("CXT5066: init\n"); 2926 conexant_init(codec); 2927 cxt5066_hp_automute(codec); 2928 if (!spec->dc_enable) { 2929 cxt5066_set_mic_boost(codec); 2930 cxt5066_olpc_automic(codec); 2931 } else { 2932 cxt5066_enable_dc(codec); 2933 } 2934 return 0; 2935 } 2936 2937 enum { 2938 CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2939 CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2940 CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 2941 CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2942 CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 2943 CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2944 CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2945 CXT5066_HP_LAPTOP, /* HP Laptop */ 2946 CXT5066_AUTO, /* BIOS auto-parser */ 2947 CXT5066_MODELS 2948 }; 2949 2950 static const char * const cxt5066_models[CXT5066_MODELS] = { 2951 [CXT5066_LAPTOP] = "laptop", 2952 [CXT5066_DELL_LAPTOP] = "dell-laptop", 2953 [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2954 [CXT5066_DELL_VOSTRO] = "dell-vostro", 2955 [CXT5066_IDEAPAD] = "ideapad", 2956 [CXT5066_THINKPAD] = "thinkpad", 2957 [CXT5066_ASUS] = "asus", 2958 [CXT5066_HP_LAPTOP] = "hp-laptop", 2959 [CXT5066_AUTO] = "auto", 2960 }; 2961 2962 static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 2963 SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 2964 SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 2965 SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 2966 SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 2967 SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 2968 SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 2969 SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 2970 SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 2971 SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 2972 SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 2973 SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 2974 SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 2975 SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 2976 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2977 CXT5066_LAPTOP), 2978 SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 2979 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 2980 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 2981 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 2982 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 2983 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 2984 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 2985 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 2986 {} 2987 }; 2988 2989 static int patch_cxt5066(struct hda_codec *codec) 2990 { 2991 struct conexant_spec *spec; 2992 int board_config; 2993 2994 board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 2995 cxt5066_models, cxt5066_cfg_tbl); 2996 if (board_config < 0) 2997 board_config = CXT5066_AUTO; /* model=auto as default */ 2998 if (board_config == CXT5066_AUTO) 2999 return patch_conexant_auto(codec); 3000 3001 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3002 if (!spec) 3003 return -ENOMEM; 3004 codec->spec = spec; 3005 3006 codec->patch_ops = conexant_patch_ops; 3007 codec->patch_ops.init = conexant_init; 3008 3009 spec->dell_automute = 0; 3010 spec->multiout.max_channels = 2; 3011 spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 3012 spec->multiout.dac_nids = cxt5066_dac_nids; 3013 conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3014 ARRAY_SIZE(cxt5066_digout_pin_nids)); 3015 spec->num_adc_nids = 1; 3016 spec->adc_nids = cxt5066_adc_nids; 3017 spec->capsrc_nids = cxt5066_capsrc_nids; 3018 spec->input_mux = &cxt5066_capture_source; 3019 3020 spec->port_d_mode = PIN_HP; 3021 3022 spec->num_init_verbs = 1; 3023 spec->init_verbs[0] = cxt5066_init_verbs; 3024 spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 3025 spec->channel_mode = cxt5066_modes; 3026 spec->cur_adc = 0; 3027 spec->cur_adc_idx = 0; 3028 3029 set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 3030 3031 switch (board_config) { 3032 default: 3033 case CXT5066_LAPTOP: 3034 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3035 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3036 break; 3037 case CXT5066_DELL_LAPTOP: 3038 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3039 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3040 3041 spec->port_d_mode = PIN_OUT; 3042 spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 3043 spec->num_init_verbs++; 3044 spec->dell_automute = 1; 3045 break; 3046 case CXT5066_ASUS: 3047 case CXT5066_HP_LAPTOP: 3048 codec->patch_ops.init = cxt5066_init; 3049 codec->patch_ops.unsol_event = cxt5066_unsol_event; 3050 spec->init_verbs[spec->num_init_verbs] = 3051 cxt5066_init_verbs_hp_laptop; 3052 spec->num_init_verbs++; 3053 spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3054 spec->asus = board_config == CXT5066_ASUS; 3055 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3056 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3057 /* no S/PDIF out */ 3058 if (board_config == CXT5066_HP_LAPTOP) 3059 spec->multiout.dig_out_nid = 0; 3060 /* input source automatically selected */ 3061 spec->input_mux = NULL; 3062 spec->port_d_mode = 0; 3063 spec->mic_boost = 3; /* default 30dB gain */ 3064 break; 3065 3066 case CXT5066_OLPC_XO_1_5: 3067 codec->patch_ops.init = cxt5066_olpc_init; 3068 codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 3069 spec->init_verbs[0] = cxt5066_init_verbs_olpc; 3070 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3071 spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 3072 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3073 spec->port_d_mode = 0; 3074 spec->mic_boost = 3; /* default 30dB gain */ 3075 3076 /* no S/PDIF out */ 3077 spec->multiout.dig_out_nid = 0; 3078 3079 /* input source automatically selected */ 3080 spec->input_mux = NULL; 3081 3082 /* our capture hooks which allow us to turn on the microphone LED 3083 * at the right time */ 3084 spec->capture_prepare = cxt5066_olpc_capture_prepare; 3085 spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 3086 break; 3087 case CXT5066_DELL_VOSTRO: 3088 codec->patch_ops.init = cxt5066_init; 3089 codec->patch_ops.unsol_event = cxt5066_unsol_event; 3090 spec->init_verbs[0] = cxt5066_init_verbs_vostro; 3091 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3092 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3093 spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 3094 spec->port_d_mode = 0; 3095 spec->dell_vostro = 1; 3096 spec->mic_boost = 3; /* default 30dB gain */ 3097 3098 /* no S/PDIF out */ 3099 spec->multiout.dig_out_nid = 0; 3100 3101 /* input source automatically selected */ 3102 spec->input_mux = NULL; 3103 break; 3104 case CXT5066_IDEAPAD: 3105 codec->patch_ops.init = cxt5066_init; 3106 codec->patch_ops.unsol_event = cxt5066_unsol_event; 3107 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3108 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3109 spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3110 spec->port_d_mode = 0; 3111 spec->ideapad = 1; 3112 spec->mic_boost = 2; /* default 20dB gain */ 3113 3114 /* no S/PDIF out */ 3115 spec->multiout.dig_out_nid = 0; 3116 3117 /* input source automatically selected */ 3118 spec->input_mux = NULL; 3119 break; 3120 case CXT5066_THINKPAD: 3121 codec->patch_ops.init = cxt5066_init; 3122 codec->patch_ops.unsol_event = cxt5066_unsol_event; 3123 spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3124 spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3125 spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 3126 spec->thinkpad = 1; 3127 spec->port_d_mode = PIN_OUT; 3128 spec->mic_boost = 2; /* default 20dB gain */ 3129 3130 /* no S/PDIF out */ 3131 spec->multiout.dig_out_nid = 0; 3132 3133 /* input source automatically selected */ 3134 spec->input_mux = NULL; 3135 break; 3136 } 3137 3138 if (spec->beep_amp) 3139 snd_hda_attach_beep_device(codec, spec->beep_amp); 3140 3141 return 0; 3142 } 3143 3144 /* 3145 * Automatic parser for CX20641 & co 3146 */ 3147 3148 static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 3149 struct hda_codec *codec, 3150 unsigned int stream_tag, 3151 unsigned int format, 3152 struct snd_pcm_substream *substream) 3153 { 3154 struct conexant_spec *spec = codec->spec; 3155 hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 3156 if (spec->adc_switching) { 3157 spec->cur_adc = adc; 3158 spec->cur_adc_stream_tag = stream_tag; 3159 spec->cur_adc_format = format; 3160 } 3161 snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 3162 return 0; 3163 } 3164 3165 static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 3166 struct hda_codec *codec, 3167 struct snd_pcm_substream *substream) 3168 { 3169 struct conexant_spec *spec = codec->spec; 3170 snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 3171 spec->cur_adc = 0; 3172 return 0; 3173 } 3174 3175 static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 3176 .substreams = 1, 3177 .channels_min = 2, 3178 .channels_max = 2, 3179 .nid = 0, /* fill later */ 3180 .ops = { 3181 .prepare = cx_auto_capture_pcm_prepare, 3182 .cleanup = cx_auto_capture_pcm_cleanup 3183 }, 3184 }; 3185 3186 static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3187 3188 #define get_connection_index(codec, mux, nid)\ 3189 snd_hda_get_conn_index(codec, mux, nid, 0) 3190 3191 /* get an unassigned DAC from the given list. 3192 * Return the nid if found and reduce the DAC list, or return zero if 3193 * not found 3194 */ 3195 static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3196 hda_nid_t *dacs, int *num_dacs) 3197 { 3198 int i, nums = *num_dacs; 3199 hda_nid_t ret = 0; 3200 3201 for (i = 0; i < nums; i++) { 3202 if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3203 ret = dacs[i]; 3204 break; 3205 } 3206 } 3207 if (!ret) 3208 return 0; 3209 if (--nums > 0) 3210 memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3211 *num_dacs = nums; 3212 return ret; 3213 } 3214 3215 #define MAX_AUTO_DACS 5 3216 3217 #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 3218 3219 /* fill analog DAC list from the widget tree */ 3220 static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3221 { 3222 hda_nid_t nid, end_nid; 3223 int nums = 0; 3224 3225 end_nid = codec->start_nid + codec->num_nodes; 3226 for (nid = codec->start_nid; nid < end_nid; nid++) { 3227 unsigned int wcaps = get_wcaps(codec, nid); 3228 unsigned int type = get_wcaps_type(wcaps); 3229 if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3230 dacs[nums++] = nid; 3231 if (nums >= MAX_AUTO_DACS) 3232 break; 3233 } 3234 } 3235 return nums; 3236 } 3237 3238 /* fill pin_dac_pair list from the pin and dac list */ 3239 static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3240 int num_pins, hda_nid_t *dacs, int *rest, 3241 struct pin_dac_pair *filled, int nums, 3242 int type) 3243 { 3244 int i, start = nums; 3245 3246 for (i = 0; i < num_pins; i++, nums++) { 3247 filled[nums].pin = pins[i]; 3248 filled[nums].type = type; 3249 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3250 if (filled[nums].dac) 3251 continue; 3252 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3253 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3254 continue; 3255 } 3256 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 3257 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3258 continue; 3259 } 3260 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3261 } 3262 return nums; 3263 } 3264 3265 /* parse analog output paths */ 3266 static void cx_auto_parse_output(struct hda_codec *codec) 3267 { 3268 struct conexant_spec *spec = codec->spec; 3269 struct auto_pin_cfg *cfg = &spec->autocfg; 3270 hda_nid_t dacs[MAX_AUTO_DACS]; 3271 int i, j, nums, rest; 3272 3273 rest = fill_cx_auto_dacs(codec, dacs); 3274 /* parse all analog output pins */ 3275 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3276 dacs, &rest, spec->dac_info, 0, 3277 AUTO_PIN_LINE_OUT); 3278 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3279 dacs, &rest, spec->dac_info, nums, 3280 AUTO_PIN_HP_OUT); 3281 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3282 dacs, &rest, spec->dac_info, nums, 3283 AUTO_PIN_SPEAKER_OUT); 3284 spec->dac_info_filled = nums; 3285 /* fill multiout struct */ 3286 for (i = 0; i < nums; i++) { 3287 hda_nid_t dac = spec->dac_info[i].dac; 3288 if (!dac || (dac & DAC_SLAVE_FLAG)) 3289 continue; 3290 switch (spec->dac_info[i].type) { 3291 case AUTO_PIN_LINE_OUT: 3292 spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3293 spec->multiout.num_dacs++; 3294 break; 3295 case AUTO_PIN_HP_OUT: 3296 case AUTO_PIN_SPEAKER_OUT: 3297 if (!spec->multiout.hp_nid) { 3298 spec->multiout.hp_nid = dac; 3299 break; 3300 } 3301 for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3302 if (!spec->multiout.extra_out_nid[j]) { 3303 spec->multiout.extra_out_nid[j] = dac; 3304 break; 3305 } 3306 break; 3307 } 3308 } 3309 spec->multiout.dac_nids = spec->private_dac_nids; 3310 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3311 3312 for (i = 0; i < cfg->hp_outs; i++) { 3313 if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3314 spec->auto_mute = 1; 3315 break; 3316 } 3317 } 3318 if (spec->auto_mute && 3319 cfg->line_out_pins[0] && 3320 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 3321 cfg->line_out_pins[0] != cfg->hp_pins[0] && 3322 cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 3323 for (i = 0; i < cfg->line_outs; i++) { 3324 if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 3325 spec->detect_line = 1; 3326 break; 3327 } 3328 } 3329 spec->automute_lines = spec->detect_line; 3330 } 3331 3332 spec->vmaster_nid = spec->private_dac_nids[0]; 3333 } 3334 3335 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3336 hda_nid_t *pins, bool on); 3337 3338 static void do_automute(struct hda_codec *codec, int num_pins, 3339 hda_nid_t *pins, bool on) 3340 { 3341 struct conexant_spec *spec = codec->spec; 3342 int i; 3343 for (i = 0; i < num_pins; i++) 3344 snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0); 3345 if (spec->pin_eapd_ctrls) 3346 cx_auto_turn_eapd(codec, num_pins, pins, on); 3347 } 3348 3349 static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 3350 { 3351 int i, present = 0; 3352 3353 for (i = 0; i < num_pins; i++) { 3354 hda_nid_t nid = pins[i]; 3355 if (!nid || !is_jack_detectable(codec, nid)) 3356 break; 3357 present |= snd_hda_jack_detect(codec, nid); 3358 } 3359 return present; 3360 } 3361 3362 /* auto-mute/unmute speaker and line outs according to headphone jack */ 3363 static void cx_auto_update_speakers(struct hda_codec *codec) 3364 { 3365 struct conexant_spec *spec = codec->spec; 3366 struct auto_pin_cfg *cfg = &spec->autocfg; 3367 int on = 1; 3368 3369 /* turn on HP EAPD when HP jacks are present */ 3370 if (spec->pin_eapd_ctrls) { 3371 if (spec->auto_mute) 3372 on = spec->hp_present; 3373 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3374 } 3375 3376 /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3377 if (spec->auto_mute) 3378 on = !(spec->hp_present || 3379 (spec->detect_line && spec->line_present)); 3380 do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 3381 3382 /* toggle line-out mutes if needed, too */ 3383 /* if LO is a copy of either HP or Speaker, don't need to handle it */ 3384 if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 3385 cfg->line_out_pins[0] == cfg->speaker_pins[0]) 3386 return; 3387 if (spec->auto_mute) { 3388 /* mute LO in auto-mode when HP jack is present */ 3389 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3390 spec->automute_lines) 3391 on = !spec->hp_present; 3392 else 3393 on = 1; 3394 } 3395 do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 3396 } 3397 3398 static void cx_auto_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) 3399 { 3400 struct conexant_spec *spec = codec->spec; 3401 struct auto_pin_cfg *cfg = &spec->autocfg; 3402 3403 if (!spec->auto_mute) 3404 return; 3405 spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 3406 cx_auto_update_speakers(codec); 3407 } 3408 3409 static void cx_auto_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) 3410 { 3411 struct conexant_spec *spec = codec->spec; 3412 struct auto_pin_cfg *cfg = &spec->autocfg; 3413 3414 if (!spec->auto_mute || !spec->detect_line) 3415 return; 3416 spec->line_present = detect_jacks(codec, cfg->line_outs, 3417 cfg->line_out_pins); 3418 cx_auto_update_speakers(codec); 3419 } 3420 3421 static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 3422 struct snd_ctl_elem_info *uinfo) 3423 { 3424 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3425 struct conexant_spec *spec = codec->spec; 3426 static const char * const texts3[] = { 3427 "Disabled", "Speaker Only", "Line Out+Speaker" 3428 }; 3429 3430 if (spec->automute_hp_lo) 3431 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); 3432 return snd_hda_enum_bool_helper_info(kcontrol, uinfo); 3433 } 3434 3435 static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 3436 struct snd_ctl_elem_value *ucontrol) 3437 { 3438 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3439 struct conexant_spec *spec = codec->spec; 3440 unsigned int val; 3441 if (!spec->auto_mute) 3442 val = 0; 3443 else if (!spec->automute_lines) 3444 val = 1; 3445 else 3446 val = 2; 3447 ucontrol->value.enumerated.item[0] = val; 3448 return 0; 3449 } 3450 3451 static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 3452 struct snd_ctl_elem_value *ucontrol) 3453 { 3454 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3455 struct conexant_spec *spec = codec->spec; 3456 3457 switch (ucontrol->value.enumerated.item[0]) { 3458 case 0: 3459 if (!spec->auto_mute) 3460 return 0; 3461 spec->auto_mute = 0; 3462 break; 3463 case 1: 3464 if (spec->auto_mute && !spec->automute_lines) 3465 return 0; 3466 spec->auto_mute = 1; 3467 spec->automute_lines = 0; 3468 break; 3469 case 2: 3470 if (!spec->automute_hp_lo) 3471 return -EINVAL; 3472 if (spec->auto_mute && spec->automute_lines) 3473 return 0; 3474 spec->auto_mute = 1; 3475 spec->automute_lines = 1; 3476 break; 3477 default: 3478 return -EINVAL; 3479 } 3480 cx_auto_update_speakers(codec); 3481 return 1; 3482 } 3483 3484 static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 3485 { 3486 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3487 .name = "Auto-Mute Mode", 3488 .info = cx_automute_mode_info, 3489 .get = cx_automute_mode_get, 3490 .put = cx_automute_mode_put, 3491 }, 3492 { } 3493 }; 3494 3495 static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 3496 struct snd_ctl_elem_info *uinfo) 3497 { 3498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3499 struct conexant_spec *spec = codec->spec; 3500 3501 return snd_hda_input_mux_info(&spec->private_imux, uinfo); 3502 } 3503 3504 static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 3505 struct snd_ctl_elem_value *ucontrol) 3506 { 3507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3508 struct conexant_spec *spec = codec->spec; 3509 3510 ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 3511 return 0; 3512 } 3513 3514 /* look for the route the given pin from mux and return the index; 3515 * if do_select is set, actually select the route. 3516 */ 3517 static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3518 hda_nid_t pin, hda_nid_t *srcp, 3519 bool do_select, int depth) 3520 { 3521 struct conexant_spec *spec = codec->spec; 3522 hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 3523 int startidx, i, nums; 3524 3525 switch (get_wcaps_type(get_wcaps(codec, mux))) { 3526 case AC_WID_AUD_IN: 3527 case AC_WID_AUD_SEL: 3528 case AC_WID_AUD_MIX: 3529 break; 3530 default: 3531 return -1; 3532 } 3533 3534 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 3535 for (i = 0; i < nums; i++) 3536 if (conn[i] == pin) { 3537 if (do_select) 3538 snd_hda_codec_write(codec, mux, 0, 3539 AC_VERB_SET_CONNECT_SEL, i); 3540 if (srcp) 3541 *srcp = mux; 3542 return i; 3543 } 3544 depth++; 3545 if (depth == 2) 3546 return -1; 3547 3548 /* Try to rotate around connections to avoid one boost controlling 3549 another input path as well */ 3550 startidx = 0; 3551 for (i = 0; i < spec->private_imux.num_items; i++) 3552 if (spec->imux_info[i].pin == pin) { 3553 startidx = i; 3554 break; 3555 } 3556 3557 for (i = 0; i < nums; i++) { 3558 int j = (i + startidx) % nums; 3559 int ret = __select_input_connection(codec, conn[j], pin, srcp, 3560 do_select, depth); 3561 if (ret >= 0) { 3562 if (do_select) 3563 snd_hda_codec_write(codec, mux, 0, 3564 AC_VERB_SET_CONNECT_SEL, j); 3565 return j; 3566 } 3567 } 3568 return -1; 3569 } 3570 3571 static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3572 hda_nid_t pin) 3573 { 3574 __select_input_connection(codec, mux, pin, NULL, true, 0); 3575 } 3576 3577 static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 3578 hda_nid_t pin) 3579 { 3580 return __select_input_connection(codec, mux, pin, NULL, false, 0); 3581 } 3582 3583 static int cx_auto_mux_enum_update(struct hda_codec *codec, 3584 const struct hda_input_mux *imux, 3585 unsigned int idx) 3586 { 3587 struct conexant_spec *spec = codec->spec; 3588 hda_nid_t adc; 3589 int changed = 1; 3590 3591 if (!imux->num_items) 3592 return 0; 3593 if (idx >= imux->num_items) 3594 idx = imux->num_items - 1; 3595 if (spec->cur_mux[0] == idx) 3596 changed = 0; 3597 adc = spec->imux_info[idx].adc; 3598 select_input_connection(codec, spec->imux_info[idx].adc, 3599 spec->imux_info[idx].pin); 3600 if (spec->cur_adc && spec->cur_adc != adc) { 3601 /* stream is running, let's swap the current ADC */ 3602 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 3603 spec->cur_adc = adc; 3604 snd_hda_codec_setup_stream(codec, adc, 3605 spec->cur_adc_stream_tag, 0, 3606 spec->cur_adc_format); 3607 } 3608 spec->cur_mux[0] = idx; 3609 return changed; 3610 } 3611 3612 static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 3613 struct snd_ctl_elem_value *ucontrol) 3614 { 3615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 3616 struct conexant_spec *spec = codec->spec; 3617 3618 return cx_auto_mux_enum_update(codec, &spec->private_imux, 3619 ucontrol->value.enumerated.item[0]); 3620 } 3621 3622 static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 3623 { 3624 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3625 .name = "Capture Source", 3626 .info = cx_auto_mux_enum_info, 3627 .get = cx_auto_mux_enum_get, 3628 .put = cx_auto_mux_enum_put 3629 }, 3630 {} 3631 }; 3632 3633 static bool select_automic(struct hda_codec *codec, int idx, bool detect) 3634 { 3635 struct conexant_spec *spec = codec->spec; 3636 if (idx < 0) 3637 return false; 3638 if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 3639 return false; 3640 cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 3641 return true; 3642 } 3643 3644 /* automatic switch internal and external mic */ 3645 static void cx_auto_automic(struct hda_codec *codec, struct hda_jack_tbl *jack) 3646 { 3647 struct conexant_spec *spec = codec->spec; 3648 3649 if (!spec->auto_mic) 3650 return; 3651 if (!select_automic(codec, spec->auto_mic_ext, true)) 3652 if (!select_automic(codec, spec->auto_mic_dock, true)) 3653 select_automic(codec, spec->auto_mic_int, false); 3654 } 3655 3656 /* check whether the pin config is suitable for auto-mic switching; 3657 * auto-mic is enabled only when one int-mic and one ext- and/or 3658 * one dock-mic exist 3659 */ 3660 static void cx_auto_check_auto_mic(struct hda_codec *codec) 3661 { 3662 struct conexant_spec *spec = codec->spec; 3663 int pset[INPUT_PIN_ATTR_NORMAL + 1]; 3664 int i; 3665 3666 for (i = 0; i < ARRAY_SIZE(pset); i++) 3667 pset[i] = -1; 3668 for (i = 0; i < spec->private_imux.num_items; i++) { 3669 hda_nid_t pin = spec->imux_info[i].pin; 3670 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3671 int type, attr; 3672 attr = snd_hda_get_input_pin_attr(def_conf); 3673 if (attr == INPUT_PIN_ATTR_UNUSED) 3674 return; /* invalid entry */ 3675 if (attr > INPUT_PIN_ATTR_NORMAL) 3676 attr = INPUT_PIN_ATTR_NORMAL; 3677 if (attr != INPUT_PIN_ATTR_INT && 3678 !is_jack_detectable(codec, pin)) 3679 return; /* non-detectable pin */ 3680 type = get_defcfg_device(def_conf); 3681 if (type != AC_JACK_MIC_IN && 3682 (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3683 return; /* no valid input type */ 3684 if (pset[attr] >= 0) 3685 return; /* already occupied */ 3686 pset[attr] = i; 3687 } 3688 if (pset[INPUT_PIN_ATTR_INT] < 0 || 3689 (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 3690 return; /* no input to switch*/ 3691 spec->auto_mic = 1; 3692 spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 3693 spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 3694 spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3695 } 3696 3697 static void cx_auto_parse_input(struct hda_codec *codec) 3698 { 3699 struct conexant_spec *spec = codec->spec; 3700 struct auto_pin_cfg *cfg = &spec->autocfg; 3701 struct hda_input_mux *imux; 3702 int i, j; 3703 3704 imux = &spec->private_imux; 3705 for (i = 0; i < cfg->num_inputs; i++) { 3706 for (j = 0; j < spec->num_adc_nids; j++) { 3707 hda_nid_t adc = spec->adc_nids[j]; 3708 int idx = get_input_connection(codec, adc, 3709 cfg->inputs[i].pin); 3710 if (idx >= 0) { 3711 const char *label; 3712 label = hda_get_autocfg_input_label(codec, cfg, i); 3713 spec->imux_info[imux->num_items].index = i; 3714 spec->imux_info[imux->num_items].boost = 0; 3715 spec->imux_info[imux->num_items].adc = adc; 3716 spec->imux_info[imux->num_items].pin = 3717 cfg->inputs[i].pin; 3718 snd_hda_add_imux_item(imux, label, idx, NULL); 3719 break; 3720 } 3721 } 3722 } 3723 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3724 cx_auto_check_auto_mic(codec); 3725 if (imux->num_items > 1) { 3726 for (i = 1; i < imux->num_items; i++) { 3727 if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 3728 spec->adc_switching = 1; 3729 break; 3730 } 3731 } 3732 } 3733 } 3734 3735 /* get digital-input audio widget corresponding to the given pin */ 3736 static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3737 { 3738 hda_nid_t nid, end_nid; 3739 3740 end_nid = codec->start_nid + codec->num_nodes; 3741 for (nid = codec->start_nid; nid < end_nid; nid++) { 3742 unsigned int wcaps = get_wcaps(codec, nid); 3743 unsigned int type = get_wcaps_type(wcaps); 3744 if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3745 if (get_connection_index(codec, nid, pin) >= 0) 3746 return nid; 3747 } 3748 } 3749 return 0; 3750 } 3751 3752 static void cx_auto_parse_digital(struct hda_codec *codec) 3753 { 3754 struct conexant_spec *spec = codec->spec; 3755 struct auto_pin_cfg *cfg = &spec->autocfg; 3756 hda_nid_t nid; 3757 3758 if (cfg->dig_outs && 3759 snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3760 spec->multiout.dig_out_nid = nid; 3761 if (cfg->dig_in_pin) 3762 spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3763 } 3764 3765 #ifdef CONFIG_SND_HDA_INPUT_BEEP 3766 static void cx_auto_parse_beep(struct hda_codec *codec) 3767 { 3768 struct conexant_spec *spec = codec->spec; 3769 hda_nid_t nid, end_nid; 3770 3771 end_nid = codec->start_nid + codec->num_nodes; 3772 for (nid = codec->start_nid; nid < end_nid; nid++) 3773 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3774 set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3775 break; 3776 } 3777 } 3778 #else 3779 #define cx_auto_parse_beep(codec) 3780 #endif 3781 3782 /* parse EAPDs */ 3783 static void cx_auto_parse_eapd(struct hda_codec *codec) 3784 { 3785 struct conexant_spec *spec = codec->spec; 3786 hda_nid_t nid, end_nid; 3787 3788 end_nid = codec->start_nid + codec->num_nodes; 3789 for (nid = codec->start_nid; nid < end_nid; nid++) { 3790 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 3791 continue; 3792 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 3793 continue; 3794 spec->eapds[spec->num_eapds++] = nid; 3795 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 3796 break; 3797 } 3798 3799 /* NOTE: below is a wild guess; if we have more than two EAPDs, 3800 * it's a new chip, where EAPDs are supposed to be associated to 3801 * pins, and we can control EAPD per pin. 3802 * OTOH, if only one or two EAPDs are found, it's an old chip, 3803 * thus it might control over all pins. 3804 */ 3805 spec->pin_eapd_ctrls = spec->num_eapds > 2; 3806 } 3807 3808 static int cx_auto_parse_auto_config(struct hda_codec *codec) 3809 { 3810 struct conexant_spec *spec = codec->spec; 3811 int err; 3812 3813 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3814 if (err < 0) 3815 return err; 3816 3817 cx_auto_parse_output(codec); 3818 cx_auto_parse_input(codec); 3819 cx_auto_parse_digital(codec); 3820 cx_auto_parse_beep(codec); 3821 cx_auto_parse_eapd(codec); 3822 return 0; 3823 } 3824 3825 static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3826 hda_nid_t *pins, bool on) 3827 { 3828 int i; 3829 for (i = 0; i < num_pins; i++) { 3830 if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3831 snd_hda_codec_write(codec, pins[i], 0, 3832 AC_VERB_SET_EAPD_BTLENABLE, 3833 on ? 0x02 : 0); 3834 } 3835 } 3836 3837 static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3838 hda_nid_t src) 3839 { 3840 int idx = get_connection_index(codec, pin, src); 3841 if (idx >= 0) 3842 snd_hda_codec_write(codec, pin, 0, 3843 AC_VERB_SET_CONNECT_SEL, idx); 3844 } 3845 3846 static void mute_outputs(struct hda_codec *codec, int num_nids, 3847 const hda_nid_t *nids) 3848 { 3849 int i, val; 3850 3851 for (i = 0; i < num_nids; i++) { 3852 hda_nid_t nid = nids[i]; 3853 if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 3854 continue; 3855 if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 3856 val = AMP_OUT_MUTE; 3857 else 3858 val = AMP_OUT_ZERO; 3859 snd_hda_codec_write(codec, nid, 0, 3860 AC_VERB_SET_AMP_GAIN_MUTE, val); 3861 } 3862 } 3863 3864 static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 3865 hda_nid_t *pins, unsigned int action, 3866 hda_jack_callback cb) 3867 { 3868 int i; 3869 for (i = 0; i < num_pins; i++) 3870 snd_hda_jack_detect_enable_callback(codec, pins[i], action, cb); 3871 } 3872 3873 static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 3874 { 3875 int i; 3876 for (i = 0; i < nums; i++) 3877 if (list[i] == nid) 3878 return true; 3879 return false; 3880 } 3881 3882 /* is the given NID found in any of autocfg items? */ 3883 static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) 3884 { 3885 int i; 3886 3887 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || 3888 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || 3889 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || 3890 found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) 3891 return true; 3892 for (i = 0; i < cfg->num_inputs; i++) 3893 if (cfg->inputs[i].pin == nid) 3894 return true; 3895 if (cfg->dig_in_pin == nid) 3896 return true; 3897 return false; 3898 } 3899 3900 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave 3901 * invalid unsol tags by some reason 3902 */ 3903 static void clear_unsol_on_unused_pins(struct hda_codec *codec) 3904 { 3905 struct conexant_spec *spec = codec->spec; 3906 struct auto_pin_cfg *cfg = &spec->autocfg; 3907 int i; 3908 3909 for (i = 0; i < codec->init_pins.used; i++) { 3910 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 3911 if (!found_in_autocfg(cfg, pin->nid)) 3912 snd_hda_codec_write(codec, pin->nid, 0, 3913 AC_VERB_SET_UNSOLICITED_ENABLE, 0); 3914 } 3915 } 3916 3917 /* turn on/off EAPD according to Master switch */ 3918 static void cx_auto_vmaster_hook(void *private_data, int enabled) 3919 { 3920 struct hda_codec *codec = private_data; 3921 struct conexant_spec *spec = codec->spec; 3922 3923 if (enabled && spec->pin_eapd_ctrls) { 3924 cx_auto_update_speakers(codec); 3925 return; 3926 } 3927 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 3928 } 3929 3930 static void cx_auto_init_output(struct hda_codec *codec) 3931 { 3932 struct conexant_spec *spec = codec->spec; 3933 struct auto_pin_cfg *cfg = &spec->autocfg; 3934 hda_nid_t nid; 3935 int i; 3936 3937 mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3938 for (i = 0; i < cfg->hp_outs; i++) { 3939 unsigned int val = PIN_OUT; 3940 if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & 3941 AC_PINCAP_HP_DRV) 3942 val |= AC_PINCTL_HP_EN; 3943 snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val); 3944 } 3945 mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 3946 mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 3947 mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3948 for (i = 0; i < spec->dac_info_filled; i++) { 3949 nid = spec->dac_info[i].dac; 3950 if (!nid) 3951 nid = spec->multiout.dac_nids[0]; 3952 else if (nid & DAC_SLAVE_FLAG) 3953 nid &= ~DAC_SLAVE_FLAG; 3954 select_connection(codec, spec->dac_info[i].pin, nid); 3955 } 3956 if (spec->auto_mute) { 3957 enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 3958 CONEXANT_HP_EVENT, cx_auto_hp_automute); 3959 spec->hp_present = detect_jacks(codec, cfg->hp_outs, 3960 cfg->hp_pins); 3961 if (spec->detect_line) { 3962 enable_unsol_pins(codec, cfg->line_outs, 3963 cfg->line_out_pins, 3964 CONEXANT_LINE_EVENT, 3965 cx_auto_line_automute); 3966 spec->line_present = 3967 detect_jacks(codec, cfg->line_outs, 3968 cfg->line_out_pins); 3969 } 3970 } 3971 cx_auto_update_speakers(codec); 3972 /* turn on all EAPDs if no individual EAPD control is available */ 3973 if (!spec->pin_eapd_ctrls) 3974 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 3975 clear_unsol_on_unused_pins(codec); 3976 } 3977 3978 static void cx_auto_init_input(struct hda_codec *codec) 3979 { 3980 struct conexant_spec *spec = codec->spec; 3981 struct auto_pin_cfg *cfg = &spec->autocfg; 3982 int i, val; 3983 3984 for (i = 0; i < spec->num_adc_nids; i++) { 3985 hda_nid_t nid = spec->adc_nids[i]; 3986 if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 3987 continue; 3988 if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 3989 val = AMP_IN_MUTE(0); 3990 else 3991 val = AMP_IN_UNMUTE(0); 3992 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3993 val); 3994 } 3995 3996 for (i = 0; i < cfg->num_inputs; i++) { 3997 hda_nid_t pin = cfg->inputs[i].pin; 3998 unsigned int type = PIN_IN; 3999 if (cfg->inputs[i].type == AUTO_PIN_MIC) 4000 type |= snd_hda_get_default_vref(codec, pin); 4001 snd_hda_set_pin_ctl(codec, pin, type); 4002 } 4003 4004 if (spec->auto_mic) { 4005 if (spec->auto_mic_ext >= 0) { 4006 snd_hda_jack_detect_enable_callback(codec, 4007 cfg->inputs[spec->auto_mic_ext].pin, 4008 CONEXANT_MIC_EVENT, cx_auto_automic); 4009 } 4010 if (spec->auto_mic_dock >= 0) { 4011 snd_hda_jack_detect_enable_callback(codec, 4012 cfg->inputs[spec->auto_mic_dock].pin, 4013 CONEXANT_MIC_EVENT, cx_auto_automic); 4014 } 4015 cx_auto_automic(codec, NULL); 4016 } else { 4017 select_input_connection(codec, spec->imux_info[0].adc, 4018 spec->imux_info[0].pin); 4019 } 4020 } 4021 4022 static void cx_auto_init_digital(struct hda_codec *codec) 4023 { 4024 struct conexant_spec *spec = codec->spec; 4025 struct auto_pin_cfg *cfg = &spec->autocfg; 4026 4027 if (spec->multiout.dig_out_nid) 4028 snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT); 4029 if (spec->dig_in_nid) 4030 snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN); 4031 } 4032 4033 static int cx_auto_init(struct hda_codec *codec) 4034 { 4035 struct conexant_spec *spec = codec->spec; 4036 snd_hda_gen_apply_verbs(codec); 4037 cx_auto_init_output(codec); 4038 cx_auto_init_input(codec); 4039 cx_auto_init_digital(codec); 4040 snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4041 return 0; 4042 } 4043 4044 static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4045 const char *dir, int cidx, 4046 hda_nid_t nid, int hda_dir, int amp_idx, int chs) 4047 { 4048 static char name[44]; 4049 static struct snd_kcontrol_new knew[] = { 4050 HDA_CODEC_VOLUME(name, 0, 0, 0), 4051 HDA_CODEC_MUTE(name, 0, 0, 0), 4052 }; 4053 static const char * const sfx[2] = { "Volume", "Switch" }; 4054 int i, err; 4055 4056 for (i = 0; i < 2; i++) { 4057 struct snd_kcontrol *kctl; 4058 knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, 4059 hda_dir); 4060 knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4061 knew[i].index = cidx; 4062 snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4063 kctl = snd_ctl_new1(&knew[i], codec); 4064 if (!kctl) 4065 return -ENOMEM; 4066 err = snd_hda_ctl_add(codec, nid, kctl); 4067 if (err < 0) 4068 return err; 4069 if (!(query_amp_caps(codec, nid, hda_dir) & 4070 (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) 4071 break; 4072 } 4073 return 0; 4074 } 4075 4076 #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4077 cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) 4078 4079 #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4080 cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4081 4082 static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 4083 hda_nid_t pin, const char *name, int idx) 4084 { 4085 unsigned int caps; 4086 if (dac && !(dac & DAC_SLAVE_FLAG)) { 4087 caps = query_amp_caps(codec, dac, HDA_OUTPUT); 4088 if (caps & AC_AMPCAP_NUM_STEPS) 4089 return cx_auto_add_pb_volume(codec, dac, name, idx); 4090 } 4091 caps = query_amp_caps(codec, pin, HDA_OUTPUT); 4092 if (caps & AC_AMPCAP_NUM_STEPS) 4093 return cx_auto_add_pb_volume(codec, pin, name, idx); 4094 return 0; 4095 } 4096 4097 static bool is_2_1_speaker(struct conexant_spec *spec) 4098 { 4099 int i, type, num_spk = 0; 4100 4101 for (i = 0; i < spec->dac_info_filled; i++) { 4102 type = spec->dac_info[i].type; 4103 if (type == AUTO_PIN_LINE_OUT) 4104 type = spec->autocfg.line_out_type; 4105 if (type == AUTO_PIN_SPEAKER_OUT) 4106 num_spk++; 4107 } 4108 return (num_spk == 2 && spec->autocfg.line_out_type != AUTO_PIN_LINE_OUT); 4109 } 4110 4111 static int cx_auto_build_output_controls(struct hda_codec *codec) 4112 { 4113 struct conexant_spec *spec = codec->spec; 4114 int i, err; 4115 int num_line = 0, num_hp = 0, num_spk = 0; 4116 bool speaker_2_1; 4117 static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4118 4119 if (spec->dac_info_filled == 1) 4120 return try_add_pb_volume(codec, spec->dac_info[0].dac, 4121 spec->dac_info[0].pin, 4122 "Master", 0); 4123 4124 speaker_2_1 = is_2_1_speaker(spec); 4125 4126 for (i = 0; i < spec->dac_info_filled; i++) { 4127 const char *label; 4128 int idx, type; 4129 hda_nid_t dac = spec->dac_info[i].dac; 4130 type = spec->dac_info[i].type; 4131 if (type == AUTO_PIN_LINE_OUT) 4132 type = spec->autocfg.line_out_type; 4133 switch (type) { 4134 case AUTO_PIN_LINE_OUT: 4135 default: 4136 label = texts[num_line++]; 4137 idx = 0; 4138 break; 4139 case AUTO_PIN_HP_OUT: 4140 label = "Headphone"; 4141 idx = num_hp++; 4142 break; 4143 case AUTO_PIN_SPEAKER_OUT: 4144 if (speaker_2_1) { 4145 label = num_spk++ ? "Bass Speaker" : "Speaker"; 4146 idx = 0; 4147 } else { 4148 label = "Speaker"; 4149 idx = num_spk++; 4150 } 4151 break; 4152 } 4153 err = try_add_pb_volume(codec, dac, 4154 spec->dac_info[i].pin, 4155 label, idx); 4156 if (err < 0) 4157 return err; 4158 } 4159 4160 if (spec->auto_mute) { 4161 err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 4162 if (err < 0) 4163 return err; 4164 } 4165 4166 return 0; 4167 } 4168 4169 /* Returns zero if this is a normal stereo channel, and non-zero if it should 4170 be split in two independent channels. 4171 dest_label must be at least 44 characters. */ 4172 static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, 4173 char *dest_label, int nid) 4174 { 4175 struct conexant_spec *spec = codec->spec; 4176 int i; 4177 4178 if (!spec->fixup_stereo_dmic) 4179 return 0; 4180 4181 for (i = 0; i < AUTO_CFG_MAX_INS; i++) { 4182 int def_conf; 4183 if (spec->autocfg.inputs[i].pin != nid) 4184 continue; 4185 4186 if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) 4187 return 0; 4188 def_conf = snd_hda_codec_get_pincfg(codec, nid); 4189 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) 4190 return 0; 4191 4192 /* Finally found the inverted internal mic! */ 4193 snprintf(dest_label, 44, "Inverted %s", label); 4194 return 1; 4195 } 4196 return 0; 4197 } 4198 4199 static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 4200 const char *label, const char *pfx, 4201 int cidx) 4202 { 4203 struct conexant_spec *spec = codec->spec; 4204 int i; 4205 4206 for (i = 0; i < spec->num_adc_nids; i++) { 4207 char rightch_label[44]; 4208 hda_nid_t adc_nid = spec->adc_nids[i]; 4209 int idx = get_input_connection(codec, adc_nid, nid); 4210 if (idx < 0) 4211 continue; 4212 if (codec->single_adc_amp) 4213 idx = 0; 4214 4215 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4216 /* Make two independent kcontrols for left and right */ 4217 int err = cx_auto_add_volume_idx(codec, label, pfx, 4218 cidx, adc_nid, HDA_INPUT, idx, 1); 4219 if (err < 0) 4220 return err; 4221 return cx_auto_add_volume_idx(codec, rightch_label, pfx, 4222 cidx, adc_nid, HDA_INPUT, idx, 2); 4223 } 4224 return cx_auto_add_volume_idx(codec, label, pfx, 4225 cidx, adc_nid, HDA_INPUT, idx, 3); 4226 } 4227 return 0; 4228 } 4229 4230 static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4231 const char *label, int cidx) 4232 { 4233 struct conexant_spec *spec = codec->spec; 4234 hda_nid_t mux, nid; 4235 int i, con; 4236 4237 nid = spec->imux_info[idx].pin; 4238 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 4239 char rightch_label[44]; 4240 if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4241 int err = cx_auto_add_volume_idx(codec, label, " Boost", 4242 cidx, nid, HDA_INPUT, 0, 1); 4243 if (err < 0) 4244 return err; 4245 return cx_auto_add_volume_idx(codec, rightch_label, " Boost", 4246 cidx, nid, HDA_INPUT, 0, 2); 4247 } 4248 return cx_auto_add_volume(codec, label, " Boost", cidx, 4249 nid, HDA_INPUT); 4250 } 4251 con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 4252 &mux, false, 0); 4253 if (con < 0) 4254 return 0; 4255 for (i = 0; i < idx; i++) { 4256 if (spec->imux_info[i].boost == mux) 4257 return 0; /* already present */ 4258 } 4259 4260 if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 4261 spec->imux_info[idx].boost = mux; 4262 return cx_auto_add_volume(codec, label, " Boost", cidx, 4263 mux, HDA_OUTPUT); 4264 } 4265 return 0; 4266 } 4267 4268 static int cx_auto_build_input_controls(struct hda_codec *codec) 4269 { 4270 struct conexant_spec *spec = codec->spec; 4271 struct hda_input_mux *imux = &spec->private_imux; 4272 const char *prev_label; 4273 int input_conn[HDA_MAX_NUM_INPUTS]; 4274 int i, j, err, cidx; 4275 int multi_connection; 4276 4277 if (!imux->num_items) 4278 return 0; 4279 4280 multi_connection = 0; 4281 for (i = 0; i < imux->num_items; i++) { 4282 cidx = get_input_connection(codec, spec->imux_info[i].adc, 4283 spec->imux_info[i].pin); 4284 if (cidx < 0) 4285 continue; 4286 input_conn[i] = spec->imux_info[i].adc; 4287 if (!codec->single_adc_amp) 4288 input_conn[i] |= cidx << 8; 4289 if (i > 0 && input_conn[i] != input_conn[0]) 4290 multi_connection = 1; 4291 } 4292 4293 prev_label = NULL; 4294 cidx = 0; 4295 for (i = 0; i < imux->num_items; i++) { 4296 hda_nid_t nid = spec->imux_info[i].pin; 4297 const char *label; 4298 4299 label = hda_get_autocfg_input_label(codec, &spec->autocfg, 4300 spec->imux_info[i].index); 4301 if (label == prev_label) 4302 cidx++; 4303 else 4304 cidx = 0; 4305 prev_label = label; 4306 4307 err = cx_auto_add_boost_volume(codec, i, label, cidx); 4308 if (err < 0) 4309 return err; 4310 4311 if (!multi_connection) { 4312 if (i > 0) 4313 continue; 4314 err = cx_auto_add_capture_volume(codec, nid, 4315 "Capture", "", cidx); 4316 } else { 4317 bool dup_found = false; 4318 for (j = 0; j < i; j++) { 4319 if (input_conn[j] == input_conn[i]) { 4320 dup_found = true; 4321 break; 4322 } 4323 } 4324 if (dup_found) 4325 continue; 4326 err = cx_auto_add_capture_volume(codec, nid, 4327 label, " Capture", cidx); 4328 } 4329 if (err < 0) 4330 return err; 4331 } 4332 4333 if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 4334 err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 4335 if (err < 0) 4336 return err; 4337 } 4338 4339 return 0; 4340 } 4341 4342 static int cx_auto_build_controls(struct hda_codec *codec) 4343 { 4344 struct conexant_spec *spec = codec->spec; 4345 int err; 4346 4347 err = cx_auto_build_output_controls(codec); 4348 if (err < 0) 4349 return err; 4350 err = cx_auto_build_input_controls(codec); 4351 if (err < 0) 4352 return err; 4353 err = conexant_build_controls(codec); 4354 if (err < 0) 4355 return err; 4356 err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 4357 if (err < 0) 4358 return err; 4359 if (spec->vmaster_mute.sw_kctl) { 4360 spec->vmaster_mute.hook = cx_auto_vmaster_hook; 4361 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4362 spec->vmaster_mute_led); 4363 if (err < 0) 4364 return err; 4365 } 4366 return 0; 4367 } 4368 4369 static int cx_auto_search_adcs(struct hda_codec *codec) 4370 { 4371 struct conexant_spec *spec = codec->spec; 4372 hda_nid_t nid, end_nid; 4373 4374 end_nid = codec->start_nid + codec->num_nodes; 4375 for (nid = codec->start_nid; nid < end_nid; nid++) { 4376 unsigned int caps = get_wcaps(codec, nid); 4377 if (get_wcaps_type(caps) != AC_WID_AUD_IN) 4378 continue; 4379 if (caps & AC_WCAP_DIGITAL) 4380 continue; 4381 if (snd_BUG_ON(spec->num_adc_nids >= 4382 ARRAY_SIZE(spec->private_adc_nids))) 4383 break; 4384 spec->private_adc_nids[spec->num_adc_nids++] = nid; 4385 } 4386 spec->adc_nids = spec->private_adc_nids; 4387 return 0; 4388 } 4389 4390 static const struct hda_codec_ops cx_auto_patch_ops = { 4391 .build_controls = cx_auto_build_controls, 4392 .build_pcms = conexant_build_pcms, 4393 .init = cx_auto_init, 4394 .free = conexant_free, 4395 .unsol_event = snd_hda_jack_unsol_event, 4396 }; 4397 4398 /* 4399 * pin fix-up 4400 */ 4401 enum { 4402 CXT_PINCFG_LENOVO_X200, 4403 CXT_PINCFG_LENOVO_TP410, 4404 CXT_PINCFG_LEMOTE_A1004, 4405 CXT_PINCFG_LEMOTE_A1205, 4406 CXT_FIXUP_STEREO_DMIC, 4407 CXT_FIXUP_INC_MIC_BOOST, 4408 }; 4409 4410 static void cxt_fixup_stereo_dmic(struct hda_codec *codec, 4411 const struct hda_fixup *fix, int action) 4412 { 4413 struct conexant_spec *spec = codec->spec; 4414 spec->fixup_stereo_dmic = 1; 4415 } 4416 4417 static void cxt5066_increase_mic_boost(struct hda_codec *codec, 4418 const struct hda_fixup *fix, int action) 4419 { 4420 if (action != HDA_FIXUP_ACT_PRE_PROBE) 4421 return; 4422 4423 snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT, 4424 (0x3 << AC_AMPCAP_OFFSET_SHIFT) | 4425 (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) | 4426 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) | 4427 (0 << AC_AMPCAP_MUTE_SHIFT)); 4428 } 4429 4430 /* ThinkPad X200 & co with cxt5051 */ 4431 static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = { 4432 { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4433 { 0x17, 0x21a11000 }, /* dock-mic */ 4434 { 0x19, 0x2121103f }, /* dock-HP */ 4435 { 0x1c, 0x21440100 }, /* dock SPDIF out */ 4436 {} 4437 }; 4438 4439 /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 4440 static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = { 4441 { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 4442 { 0x1a, 0x21a190f0 }, /* dock-mic */ 4443 { 0x1c, 0x212140ff }, /* dock-HP */ 4444 {} 4445 }; 4446 4447 /* Lemote A1004/A1205 with cxt5066 */ 4448 static const struct hda_pintbl cxt_pincfg_lemote[] = { 4449 { 0x1a, 0x90a10020 }, /* Internal mic */ 4450 { 0x1b, 0x03a11020 }, /* External mic */ 4451 { 0x1d, 0x400101f0 }, /* Not used */ 4452 { 0x1e, 0x40a701f0 }, /* Not used */ 4453 { 0x20, 0x404501f0 }, /* Not used */ 4454 { 0x22, 0x404401f0 }, /* Not used */ 4455 { 0x23, 0x40a701f0 }, /* Not used */ 4456 {} 4457 }; 4458 4459 static const struct hda_fixup cxt_fixups[] = { 4460 [CXT_PINCFG_LENOVO_X200] = { 4461 .type = HDA_FIXUP_PINS, 4462 .v.pins = cxt_pincfg_lenovo_x200, 4463 }, 4464 [CXT_PINCFG_LENOVO_TP410] = { 4465 .type = HDA_FIXUP_PINS, 4466 .v.pins = cxt_pincfg_lenovo_tp410, 4467 }, 4468 [CXT_PINCFG_LEMOTE_A1004] = { 4469 .type = HDA_FIXUP_PINS, 4470 .chained = true, 4471 .chain_id = CXT_FIXUP_INC_MIC_BOOST, 4472 .v.pins = cxt_pincfg_lemote, 4473 }, 4474 [CXT_PINCFG_LEMOTE_A1205] = { 4475 .type = HDA_FIXUP_PINS, 4476 .v.pins = cxt_pincfg_lemote, 4477 }, 4478 [CXT_FIXUP_STEREO_DMIC] = { 4479 .type = HDA_FIXUP_FUNC, 4480 .v.func = cxt_fixup_stereo_dmic, 4481 }, 4482 [CXT_FIXUP_INC_MIC_BOOST] = { 4483 .type = HDA_FIXUP_FUNC, 4484 .v.func = cxt5066_increase_mic_boost, 4485 }, 4486 }; 4487 4488 static const struct snd_pci_quirk cxt5051_fixups[] = { 4489 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4490 {} 4491 }; 4492 4493 static const struct snd_pci_quirk cxt5066_fixups[] = { 4494 SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC), 4495 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 4496 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 4497 SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 4498 SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 4499 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 4500 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 4501 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), 4502 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), 4503 SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004), 4504 SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205), 4505 {} 4506 }; 4507 4508 /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 4509 * can be created (bko#42825) 4510 */ 4511 static void add_cx5051_fake_mutes(struct hda_codec *codec) 4512 { 4513 static hda_nid_t out_nids[] = { 4514 0x10, 0x11, 0 4515 }; 4516 hda_nid_t *p; 4517 4518 for (p = out_nids; *p; p++) 4519 snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 4520 AC_AMPCAP_MIN_MUTE | 4521 query_amp_caps(codec, *p, HDA_OUTPUT)); 4522 } 4523 4524 static int patch_conexant_auto(struct hda_codec *codec) 4525 { 4526 struct conexant_spec *spec; 4527 int err; 4528 4529 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 4530 codec->chip_name); 4531 4532 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4533 if (!spec) 4534 return -ENOMEM; 4535 codec->spec = spec; 4536 snd_hda_gen_init(&spec->gen); 4537 4538 switch (codec->vendor_id) { 4539 case 0x14f15045: 4540 codec->single_adc_amp = 1; 4541 break; 4542 case 0x14f15051: 4543 add_cx5051_fake_mutes(codec); 4544 codec->pin_amp_workaround = 1; 4545 snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups); 4546 break; 4547 default: 4548 codec->pin_amp_workaround = 1; 4549 snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups); 4550 break; 4551 } 4552 4553 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 4554 4555 /* Show mute-led control only on HP laptops 4556 * This is a sort of white-list: on HP laptops, EAPD corresponds 4557 * only to the mute-LED without actualy amp function. Meanwhile, 4558 * others may use EAPD really as an amp switch, so it might be 4559 * not good to expose it blindly. 4560 */ 4561 switch (codec->subsystem_id >> 16) { 4562 case 0x103c: 4563 spec->vmaster_mute_led = 1; 4564 break; 4565 } 4566 4567 err = cx_auto_search_adcs(codec); 4568 if (err < 0) 4569 return err; 4570 err = cx_auto_parse_auto_config(codec); 4571 if (err < 0) { 4572 kfree(codec->spec); 4573 codec->spec = NULL; 4574 return err; 4575 } 4576 spec->capture_stream = &cx_auto_pcm_analog_capture; 4577 codec->patch_ops = cx_auto_patch_ops; 4578 if (spec->beep_amp) 4579 snd_hda_attach_beep_device(codec, spec->beep_amp); 4580 4581 /* Some laptops with Conexant chips show stalls in S3 resume, 4582 * which falls into the single-cmd mode. 4583 * Better to make reset, then. 4584 */ 4585 if (!codec->bus->sync_write) { 4586 snd_printd("hda_codec: " 4587 "Enable sync_write for stable communication\n"); 4588 codec->bus->sync_write = 1; 4589 codec->bus->allow_bus_reset = 1; 4590 } 4591 4592 return 0; 4593 } 4594 4595 /* 4596 */ 4597 4598 static const struct hda_codec_preset snd_hda_preset_conexant[] = { 4599 { .id = 0x14f15045, .name = "CX20549 (Venice)", 4600 .patch = patch_cxt5045 }, 4601 { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 4602 .patch = patch_cxt5047 }, 4603 { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4604 .patch = patch_cxt5051 }, 4605 { .id = 0x14f15066, .name = "CX20582 (Pebble)", 4606 .patch = patch_cxt5066 }, 4607 { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 4608 .patch = patch_cxt5066 }, 4609 { .id = 0x14f15068, .name = "CX20584", 4610 .patch = patch_cxt5066 }, 4611 { .id = 0x14f15069, .name = "CX20585", 4612 .patch = patch_cxt5066 }, 4613 { .id = 0x14f1506c, .name = "CX20588", 4614 .patch = patch_cxt5066 }, 4615 { .id = 0x14f1506e, .name = "CX20590", 4616 .patch = patch_cxt5066 }, 4617 { .id = 0x14f15097, .name = "CX20631", 4618 .patch = patch_conexant_auto }, 4619 { .id = 0x14f15098, .name = "CX20632", 4620 .patch = patch_conexant_auto }, 4621 { .id = 0x14f150a1, .name = "CX20641", 4622 .patch = patch_conexant_auto }, 4623 { .id = 0x14f150a2, .name = "CX20642", 4624 .patch = patch_conexant_auto }, 4625 { .id = 0x14f150ab, .name = "CX20651", 4626 .patch = patch_conexant_auto }, 4627 { .id = 0x14f150ac, .name = "CX20652", 4628 .patch = patch_conexant_auto }, 4629 { .id = 0x14f150b8, .name = "CX20664", 4630 .patch = patch_conexant_auto }, 4631 { .id = 0x14f150b9, .name = "CX20665", 4632 .patch = patch_conexant_auto }, 4633 { .id = 0x14f1510f, .name = "CX20751/2", 4634 .patch = patch_conexant_auto }, 4635 { .id = 0x14f15110, .name = "CX20751/2", 4636 .patch = patch_conexant_auto }, 4637 { .id = 0x14f15111, .name = "CX20753/4", 4638 .patch = patch_conexant_auto }, 4639 { .id = 0x14f15113, .name = "CX20755", 4640 .patch = patch_conexant_auto }, 4641 { .id = 0x14f15114, .name = "CX20756", 4642 .patch = patch_conexant_auto }, 4643 { .id = 0x14f15115, .name = "CX20757", 4644 .patch = patch_conexant_auto }, 4645 {} /* terminator */ 4646 }; 4647 4648 MODULE_ALIAS("snd-hda-codec-id:14f15045"); 4649 MODULE_ALIAS("snd-hda-codec-id:14f15047"); 4650 MODULE_ALIAS("snd-hda-codec-id:14f15051"); 4651 MODULE_ALIAS("snd-hda-codec-id:14f15066"); 4652 MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4653 MODULE_ALIAS("snd-hda-codec-id:14f15068"); 4654 MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4655 MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 4656 MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4657 MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4658 MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4659 MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4660 MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4661 MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4662 MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4663 MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4664 MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 4665 MODULE_ALIAS("snd-hda-codec-id:14f1510f"); 4666 MODULE_ALIAS("snd-hda-codec-id:14f15110"); 4667 MODULE_ALIAS("snd-hda-codec-id:14f15111"); 4668 MODULE_ALIAS("snd-hda-codec-id:14f15113"); 4669 MODULE_ALIAS("snd-hda-codec-id:14f15114"); 4670 MODULE_ALIAS("snd-hda-codec-id:14f15115"); 4671 4672 MODULE_LICENSE("GPL"); 4673 MODULE_DESCRIPTION("Conexant HD-audio codec"); 4674 4675 static struct hda_codec_preset_list conexant_list = { 4676 .preset = snd_hda_preset_conexant, 4677 .owner = THIS_MODULE, 4678 }; 4679 4680 static int __init patch_conexant_init(void) 4681 { 4682 return snd_hda_add_codec_preset(&conexant_list); 4683 } 4684 4685 static void __exit patch_conexant_exit(void) 4686 { 4687 snd_hda_delete_codec_preset(&conexant_list); 4688 } 4689 4690 module_init(patch_conexant_init) 4691 module_exit(patch_conexant_exit) 4692