1c9b443d4STobin Davis /* 2c9b443d4STobin Davis * HD audio interface patch for Conexant HDA audio codec 3c9b443d4STobin Davis * 4c9b443d4STobin Davis * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5c9b443d4STobin Davis * Takashi Iwai <tiwai@suse.de> 6c9b443d4STobin Davis * Tobin Davis <tdavis@dsl-only.net> 7c9b443d4STobin Davis * 8c9b443d4STobin Davis * This driver is free software; you can redistribute it and/or modify 9c9b443d4STobin Davis * it under the terms of the GNU General Public License as published by 10c9b443d4STobin Davis * the Free Software Foundation; either version 2 of the License, or 11c9b443d4STobin Davis * (at your option) any later version. 12c9b443d4STobin Davis * 13c9b443d4STobin Davis * This driver is distributed in the hope that it will be useful, 14c9b443d4STobin Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9b443d4STobin Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9b443d4STobin Davis * GNU General Public License for more details. 17c9b443d4STobin Davis * 18c9b443d4STobin Davis * You should have received a copy of the GNU General Public License 19c9b443d4STobin Davis * along with this program; if not, write to the Free Software 20c9b443d4STobin Davis * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c9b443d4STobin Davis */ 22c9b443d4STobin Davis 23c9b443d4STobin Davis #include <linux/init.h> 24c9b443d4STobin Davis #include <linux/delay.h> 25c9b443d4STobin Davis #include <linux/slab.h> 26c9b443d4STobin Davis #include <linux/pci.h> 27c9b443d4STobin Davis #include <sound/core.h> 28bc7a166dSUlrich Dangel #include <sound/jack.h> 29bc7a166dSUlrich Dangel 30c9b443d4STobin Davis #include "hda_codec.h" 31c9b443d4STobin Davis #include "hda_local.h" 32c0f8faf0SEinar Rünkaru #include "hda_beep.h" 33c9b443d4STobin Davis 34c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 39c9b443d4STobin Davis 40c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 42c9b443d4STobin Davis 43bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 44c9b443d4STobin Davis 45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT 0x12 46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 48bc7a166dSUlrich Dangel 49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB (1 << 1) 50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC (1 << 2) 51bc7a166dSUlrich Dangel 52f2e5731dSTakashi Iwai struct pin_dac_pair { 53f2e5731dSTakashi Iwai hda_nid_t pin; 54f2e5731dSTakashi Iwai hda_nid_t dac; 55f2e5731dSTakashi Iwai int type; 56f2e5731dSTakashi Iwai }; 57f2e5731dSTakashi Iwai 58c9b443d4STobin Davis struct conexant_spec { 59c9b443d4STobin Davis 6034cbe3a6STakashi Iwai const struct snd_kcontrol_new *mixers[5]; 61c9b443d4STobin Davis int num_mixers; 62dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 63c9b443d4STobin Davis 64c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 65c9b443d4STobin Davis * don't forget NULL 66c9b443d4STobin Davis * termination! 67c9b443d4STobin Davis */ 68c9b443d4STobin Davis unsigned int num_init_verbs; 69c9b443d4STobin Davis 70c9b443d4STobin Davis /* playback */ 71c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 72c9b443d4STobin Davis * max_channels, dacs must be set 73c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 74c9b443d4STobin Davis */ 75c9b443d4STobin Davis unsigned int cur_eapd; 7682f30040STobin Davis unsigned int hp_present; 77faddaa5dSTakashi Iwai unsigned int auto_mic; 78f6100bb4STakashi Iwai int auto_mic_ext; /* imux_pins[] index for ext mic */ 79c9b443d4STobin Davis unsigned int need_dac_fix; 80f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 81c9b443d4STobin Davis 82c9b443d4STobin Davis /* capture */ 83c9b443d4STobin Davis unsigned int num_adc_nids; 8434cbe3a6STakashi Iwai const hda_nid_t *adc_nids; 85c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 86c9b443d4STobin Davis 87461e2c78STakashi Iwai unsigned int cur_adc_idx; 88461e2c78STakashi Iwai hda_nid_t cur_adc; 89461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 90461e2c78STakashi Iwai unsigned int cur_adc_format; 91461e2c78STakashi Iwai 926764bcefSTakashi Iwai const struct hda_pcm_stream *capture_stream; 936764bcefSTakashi Iwai 94c9b443d4STobin Davis /* capture source */ 95c9b443d4STobin Davis const struct hda_input_mux *input_mux; 9634cbe3a6STakashi Iwai const hda_nid_t *capsrc_nids; 97c9b443d4STobin Davis unsigned int cur_mux[3]; 98c9b443d4STobin Davis 99c9b443d4STobin Davis /* channel model */ 100c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 101c9b443d4STobin Davis int num_channel_mode; 102c9b443d4STobin Davis 103c9b443d4STobin Davis /* PCM information */ 104c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 105c9b443d4STobin Davis 106c9b443d4STobin Davis unsigned int spdif_route; 107c9b443d4STobin Davis 108c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 109c9b443d4STobin Davis struct auto_pin_cfg autocfg; 110c9b443d4STobin Davis struct hda_input_mux private_imux; 111cf27f29aSTakashi Iwai int imux_cfg_idx[HDA_MAX_NUM_INPUTS]; /* corresponding autocfg.input */ 112f9759301STakashi Iwai hda_nid_t imux_boost_nid[HDA_MAX_NUM_INPUTS]; /* boost widget */ 1136764bcefSTakashi Iwai hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS]; 114f6100bb4STakashi Iwai hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS]; 11522ce5f74STakashi Iwai hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 11641923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 117f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 118f2e5731dSTakashi Iwai int dac_info_filled; 119c9b443d4STobin Davis 1200fb67e98SDaniel Drake unsigned int port_d_mode; 121f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 122f2e5731dSTakashi Iwai unsigned int dell_automute:1; 123cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 124cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1257b2bfdbcSJens Taprogge unsigned int thinkpad:1; 126048e78a5SDavid Henningsson unsigned int hp_laptop:1; 127a1d6906eSDavid Henningsson unsigned int asus:1; 12875f8991dSDaniel Drake 1296764bcefSTakashi Iwai unsigned int adc_switching:1; 1306764bcefSTakashi Iwai 13175f8991dSDaniel Drake unsigned int ext_mic_present; 13275f8991dSDaniel Drake unsigned int recording; 13375f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 13475f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 135c4cfe66cSDaniel Drake 136c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 137c4cfe66cSDaniel Drake * through the microphone jack. 138c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 139c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 140c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 141c4cfe66cSDaniel Drake * control. */ 142c4cfe66cSDaniel Drake unsigned int dc_enable; 143c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 144c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1453507e2a8STakashi Iwai 1463507e2a8STakashi Iwai unsigned int beep_amp; 147c9b443d4STobin Davis }; 148c9b443d4STobin Davis 149c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 150c9b443d4STobin Davis struct hda_codec *codec, 151c9b443d4STobin Davis struct snd_pcm_substream *substream) 152c9b443d4STobin Davis { 153c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1549a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1559a08160bSTakashi Iwai hinfo); 156c9b443d4STobin Davis } 157c9b443d4STobin Davis 158c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 159c9b443d4STobin Davis struct hda_codec *codec, 160c9b443d4STobin Davis unsigned int stream_tag, 161c9b443d4STobin Davis unsigned int format, 162c9b443d4STobin Davis struct snd_pcm_substream *substream) 163c9b443d4STobin Davis { 164c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 165c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 166c9b443d4STobin Davis stream_tag, 167c9b443d4STobin Davis format, substream); 168c9b443d4STobin Davis } 169c9b443d4STobin Davis 170c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 171c9b443d4STobin Davis struct hda_codec *codec, 172c9b443d4STobin Davis struct snd_pcm_substream *substream) 173c9b443d4STobin Davis { 174c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 175c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 176c9b443d4STobin Davis } 177c9b443d4STobin Davis 178c9b443d4STobin Davis /* 179c9b443d4STobin Davis * Digital out 180c9b443d4STobin Davis */ 181c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 182c9b443d4STobin Davis struct hda_codec *codec, 183c9b443d4STobin Davis struct snd_pcm_substream *substream) 184c9b443d4STobin Davis { 185c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 186c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 187c9b443d4STobin Davis } 188c9b443d4STobin Davis 189c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 190c9b443d4STobin Davis struct hda_codec *codec, 191c9b443d4STobin Davis struct snd_pcm_substream *substream) 192c9b443d4STobin Davis { 193c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 194c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 195c9b443d4STobin Davis } 196c9b443d4STobin Davis 1976b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1986b97eb45STakashi Iwai struct hda_codec *codec, 1996b97eb45STakashi Iwai unsigned int stream_tag, 2006b97eb45STakashi Iwai unsigned int format, 2016b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2026b97eb45STakashi Iwai { 2036b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2046b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2056b97eb45STakashi Iwai stream_tag, 2066b97eb45STakashi Iwai format, substream); 2076b97eb45STakashi Iwai } 2086b97eb45STakashi Iwai 209c9b443d4STobin Davis /* 210c9b443d4STobin Davis * Analog capture 211c9b443d4STobin Davis */ 212c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 213c9b443d4STobin Davis struct hda_codec *codec, 214c9b443d4STobin Davis unsigned int stream_tag, 215c9b443d4STobin Davis unsigned int format, 216c9b443d4STobin Davis struct snd_pcm_substream *substream) 217c9b443d4STobin Davis { 218c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 21975f8991dSDaniel Drake if (spec->capture_prepare) 22075f8991dSDaniel Drake spec->capture_prepare(codec); 221c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 222c9b443d4STobin Davis stream_tag, 0, format); 223c9b443d4STobin Davis return 0; 224c9b443d4STobin Davis } 225c9b443d4STobin Davis 226c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 227c9b443d4STobin Davis struct hda_codec *codec, 228c9b443d4STobin Davis struct snd_pcm_substream *substream) 229c9b443d4STobin Davis { 230c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 231888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 23275f8991dSDaniel Drake if (spec->capture_cleanup) 23375f8991dSDaniel Drake spec->capture_cleanup(codec); 234c9b443d4STobin Davis return 0; 235c9b443d4STobin Davis } 236c9b443d4STobin Davis 237c9b443d4STobin Davis 238c9b443d4STobin Davis 23934cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 240c9b443d4STobin Davis .substreams = 1, 241c9b443d4STobin Davis .channels_min = 2, 242c9b443d4STobin Davis .channels_max = 2, 243c9b443d4STobin Davis .nid = 0, /* fill later */ 244c9b443d4STobin Davis .ops = { 245c9b443d4STobin Davis .open = conexant_playback_pcm_open, 246c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 247c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 248c9b443d4STobin Davis }, 249c9b443d4STobin Davis }; 250c9b443d4STobin Davis 25134cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 252c9b443d4STobin Davis .substreams = 1, 253c9b443d4STobin Davis .channels_min = 2, 254c9b443d4STobin Davis .channels_max = 2, 255c9b443d4STobin Davis .nid = 0, /* fill later */ 256c9b443d4STobin Davis .ops = { 257c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 258c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 259c9b443d4STobin Davis }, 260c9b443d4STobin Davis }; 261c9b443d4STobin Davis 262c9b443d4STobin Davis 26334cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 264c9b443d4STobin Davis .substreams = 1, 265c9b443d4STobin Davis .channels_min = 2, 266c9b443d4STobin Davis .channels_max = 2, 267c9b443d4STobin Davis .nid = 0, /* fill later */ 268c9b443d4STobin Davis .ops = { 269c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2706b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2716b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 272c9b443d4STobin Davis }, 273c9b443d4STobin Davis }; 274c9b443d4STobin Davis 27534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 276c9b443d4STobin Davis .substreams = 1, 277c9b443d4STobin Davis .channels_min = 2, 278c9b443d4STobin Davis .channels_max = 2, 279c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 280c9b443d4STobin Davis }; 281c9b443d4STobin Davis 282461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 283461e2c78STakashi Iwai struct hda_codec *codec, 284461e2c78STakashi Iwai unsigned int stream_tag, 285461e2c78STakashi Iwai unsigned int format, 286461e2c78STakashi Iwai struct snd_pcm_substream *substream) 287461e2c78STakashi Iwai { 288461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 289461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 290461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 291461e2c78STakashi Iwai spec->cur_adc_format = format; 292461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 293461e2c78STakashi Iwai return 0; 294461e2c78STakashi Iwai } 295461e2c78STakashi Iwai 296461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 297461e2c78STakashi Iwai struct hda_codec *codec, 298461e2c78STakashi Iwai struct snd_pcm_substream *substream) 299461e2c78STakashi Iwai { 300461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 301888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 302461e2c78STakashi Iwai spec->cur_adc = 0; 303461e2c78STakashi Iwai return 0; 304461e2c78STakashi Iwai } 305461e2c78STakashi Iwai 30634cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 307461e2c78STakashi Iwai .substreams = 1, 308461e2c78STakashi Iwai .channels_min = 2, 309461e2c78STakashi Iwai .channels_max = 2, 310461e2c78STakashi Iwai .nid = 0, /* fill later */ 311461e2c78STakashi Iwai .ops = { 312461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 313461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 314461e2c78STakashi Iwai }, 315461e2c78STakashi Iwai }; 316461e2c78STakashi Iwai 317c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 318c9b443d4STobin Davis { 319c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 320c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 321c9b443d4STobin Davis 322c9b443d4STobin Davis codec->num_pcms = 1; 323c9b443d4STobin Davis codec->pcm_info = info; 324c9b443d4STobin Davis 325c9b443d4STobin Davis info->name = "CONEXANT Analog"; 326c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 327c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 328c9b443d4STobin Davis spec->multiout.max_channels; 329c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 330c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3316764bcefSTakashi Iwai if (spec->capture_stream) 3326764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3336764bcefSTakashi Iwai else { 334461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 335461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 336461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3376764bcefSTakashi Iwai else { 338461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 339461e2c78STakashi Iwai conexant_pcm_analog_capture; 3406764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3416764bcefSTakashi Iwai spec->num_adc_nids; 3426764bcefSTakashi Iwai } 3436764bcefSTakashi Iwai } 344c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 345c9b443d4STobin Davis 346c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 347c9b443d4STobin Davis info++; 348c9b443d4STobin Davis codec->num_pcms++; 349c9b443d4STobin Davis info->name = "Conexant Digital"; 3507ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 351c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 352c9b443d4STobin Davis conexant_pcm_digital_playback; 353c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 354c9b443d4STobin Davis spec->multiout.dig_out_nid; 355c9b443d4STobin Davis if (spec->dig_in_nid) { 356c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 357c9b443d4STobin Davis conexant_pcm_digital_capture; 358c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 359c9b443d4STobin Davis spec->dig_in_nid; 360c9b443d4STobin Davis } 361f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 362f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 363c9b443d4STobin Davis } 364c9b443d4STobin Davis 365c9b443d4STobin Davis return 0; 366c9b443d4STobin Davis } 367c9b443d4STobin Davis 368c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 369c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 370c9b443d4STobin Davis { 371c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 372c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 373c9b443d4STobin Davis 374c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 375c9b443d4STobin Davis } 376c9b443d4STobin Davis 377c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 378c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 379c9b443d4STobin Davis { 380c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 381c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 382c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 383c9b443d4STobin Davis 384c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 385c9b443d4STobin Davis return 0; 386c9b443d4STobin Davis } 387c9b443d4STobin Davis 388c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 389c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 390c9b443d4STobin Davis { 391c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 392c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 393c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 394c9b443d4STobin Davis 395c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 396c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 397c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 398c9b443d4STobin Davis } 399c9b443d4STobin Davis 400bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 401bc7a166dSUlrich Dangel { 402cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 403bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 404bc7a166dSUlrich Dangel int i; 405bc7a166dSUlrich Dangel 406bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 407bc7a166dSUlrich Dangel const struct hda_verb *hv; 408bc7a166dSUlrich Dangel 409bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 410bc7a166dSUlrich Dangel while (hv->nid) { 411bc7a166dSUlrich Dangel int err = 0; 412bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 413bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 414cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 415cd372fb3STakashi Iwai SND_JACK_HEADPHONE, NULL); 416cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 417bc7a166dSUlrich Dangel break; 418bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 419bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 420cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 421cd372fb3STakashi Iwai SND_JACK_MICROPHONE, NULL); 422cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 423bc7a166dSUlrich Dangel break; 424bc7a166dSUlrich Dangel } 425bc7a166dSUlrich Dangel if (err < 0) 426bc7a166dSUlrich Dangel return err; 427bc7a166dSUlrich Dangel ++hv; 428bc7a166dSUlrich Dangel } 429bc7a166dSUlrich Dangel } 430cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */ 4315801f992STakashi Iwai return 0; 4325801f992STakashi Iwai } 433bc7a166dSUlrich Dangel 434c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 435c9b443d4STobin Davis { 436c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 437c9b443d4STobin Davis int i; 438c9b443d4STobin Davis 439c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 440c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 441c9b443d4STobin Davis return 0; 442c9b443d4STobin Davis } 443c9b443d4STobin Davis 444c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 445c9b443d4STobin Davis { 446cd372fb3STakashi Iwai snd_hda_input_jack_free(codec); 447c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 448c9b443d4STobin Davis kfree(codec->spec); 449c9b443d4STobin Davis } 450c9b443d4STobin Davis 45134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 452b880c74aSTakashi Iwai { 453b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 454b880c74aSTakashi Iwai .name = "Capture Source", 455b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 456b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 457b880c74aSTakashi Iwai .put = conexant_mux_enum_put 458b880c74aSTakashi Iwai }, 459b880c74aSTakashi Iwai {} 460b880c74aSTakashi Iwai }; 461b880c74aSTakashi Iwai 4623507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4633507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 46434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4653507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4663507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4673507e2a8STakashi Iwai { } /* end */ 4683507e2a8STakashi Iwai }; 4693507e2a8STakashi Iwai #endif 4703507e2a8STakashi Iwai 471ea734963STakashi Iwai static const char * const slave_vols[] = { 472dd5746a8STakashi Iwai "Headphone Playback Volume", 473dd5746a8STakashi Iwai "Speaker Playback Volume", 474dd5746a8STakashi Iwai NULL 475dd5746a8STakashi Iwai }; 476dd5746a8STakashi Iwai 477ea734963STakashi Iwai static const char * const slave_sws[] = { 478dd5746a8STakashi Iwai "Headphone Playback Switch", 479dd5746a8STakashi Iwai "Speaker Playback Switch", 480dd5746a8STakashi Iwai NULL 481dd5746a8STakashi Iwai }; 482dd5746a8STakashi Iwai 483c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 484c9b443d4STobin Davis { 485c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 486c9b443d4STobin Davis unsigned int i; 487c9b443d4STobin Davis int err; 488c9b443d4STobin Davis 489c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 490c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 491c9b443d4STobin Davis if (err < 0) 492c9b443d4STobin Davis return err; 493c9b443d4STobin Davis } 494c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 495c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 496c9b443d4STobin Davis spec->multiout.dig_out_nid); 497c9b443d4STobin Davis if (err < 0) 498c9b443d4STobin Davis return err; 4999a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5009a08160bSTakashi Iwai &spec->multiout); 5019a08160bSTakashi Iwai if (err < 0) 5029a08160bSTakashi Iwai return err; 5039a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 504c9b443d4STobin Davis } 505c9b443d4STobin Davis if (spec->dig_in_nid) { 506c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 507c9b443d4STobin Davis if (err < 0) 508c9b443d4STobin Davis return err; 509c9b443d4STobin Davis } 510dd5746a8STakashi Iwai 511dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 512dd5746a8STakashi Iwai if (spec->vmaster_nid && 513dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 514dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 515dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 516dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 517dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 518dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 519dd5746a8STakashi Iwai if (err < 0) 520dd5746a8STakashi Iwai return err; 521dd5746a8STakashi Iwai } 522dd5746a8STakashi Iwai if (spec->vmaster_nid && 523dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 524dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 525dd5746a8STakashi Iwai NULL, slave_sws); 526dd5746a8STakashi Iwai if (err < 0) 527dd5746a8STakashi Iwai return err; 528dd5746a8STakashi Iwai } 529dd5746a8STakashi Iwai 530b880c74aSTakashi Iwai if (spec->input_mux) { 531b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 532b880c74aSTakashi Iwai if (err < 0) 533b880c74aSTakashi Iwai return err; 534b880c74aSTakashi Iwai } 535b880c74aSTakashi Iwai 5363507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5373507e2a8STakashi Iwai /* create beep controls if needed */ 5383507e2a8STakashi Iwai if (spec->beep_amp) { 53934cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5403507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5413507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5423507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5433507e2a8STakashi Iwai if (!kctl) 5443507e2a8STakashi Iwai return -ENOMEM; 5453507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5463507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5473507e2a8STakashi Iwai if (err < 0) 5483507e2a8STakashi Iwai return err; 5493507e2a8STakashi Iwai } 5503507e2a8STakashi Iwai } 5513507e2a8STakashi Iwai #endif 5523507e2a8STakashi Iwai 553c9b443d4STobin Davis return 0; 554c9b443d4STobin Davis } 555c9b443d4STobin Davis 556697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 557697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 558697c373eSTakashi Iwai { 559697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 560697c373eSTakashi Iwai return 0; 561697c373eSTakashi Iwai } 562697c373eSTakashi Iwai #endif 563697c373eSTakashi Iwai 56434cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 565c9b443d4STobin Davis .build_controls = conexant_build_controls, 566c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 567c9b443d4STobin Davis .init = conexant_init, 568c9b443d4STobin Davis .free = conexant_free, 569697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 570697c373eSTakashi Iwai .suspend = conexant_suspend, 571697c373eSTakashi Iwai #endif 572697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 573c9b443d4STobin Davis }; 574c9b443d4STobin Davis 5753507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5763507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5773507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5783507e2a8STakashi Iwai #else 5793507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5803507e2a8STakashi Iwai #endif 5813507e2a8STakashi Iwai 5826764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 583c9b443d4STobin Davis /* 584c9b443d4STobin Davis * EAPD control 585c9b443d4STobin Davis * the private value = nid | (invert << 8) 586c9b443d4STobin Davis */ 587c9b443d4STobin Davis 588a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 589c9b443d4STobin Davis 59082f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 591c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 592c9b443d4STobin Davis { 593c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 594c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 595c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 596c9b443d4STobin Davis if (invert) 597c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 598c9b443d4STobin Davis else 599c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 600c9b443d4STobin Davis return 0; 60182f30040STobin Davis 602c9b443d4STobin Davis } 603c9b443d4STobin Davis 60482f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 605c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 606c9b443d4STobin Davis { 607c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 608c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 609c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 610c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 611c9b443d4STobin Davis unsigned int eapd; 61282f30040STobin Davis 61368ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 614c9b443d4STobin Davis if (invert) 615c9b443d4STobin Davis eapd = !eapd; 61682beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 617c9b443d4STobin Davis return 0; 61882f30040STobin Davis 619c9b443d4STobin Davis spec->cur_eapd = eapd; 62082beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 621c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 622c9b443d4STobin Davis eapd ? 0x02 : 0x00); 623c9b443d4STobin Davis return 1; 624c9b443d4STobin Davis } 625c9b443d4STobin Davis 62686d72bdfSTakashi Iwai /* controls for test mode */ 62786d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 62886d72bdfSTakashi Iwai 62982f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 63082f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 63182f30040STobin Davis .info = cxt_eapd_info, \ 63282f30040STobin Davis .get = cxt_eapd_get, \ 63382f30040STobin Davis .put = cxt_eapd_put, \ 63482f30040STobin Davis .private_value = nid | (mask<<16) } 63582f30040STobin Davis 63682f30040STobin Davis 63782f30040STobin Davis 638c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 639c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 640c9b443d4STobin Davis { 641c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 642c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 643c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 644c9b443d4STobin Davis spec->num_channel_mode); 645c9b443d4STobin Davis } 646c9b443d4STobin Davis 647c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 648c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 649c9b443d4STobin Davis { 650c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 651c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 652c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 653c9b443d4STobin Davis spec->num_channel_mode, 654c9b443d4STobin Davis spec->multiout.max_channels); 655c9b443d4STobin Davis } 656c9b443d4STobin Davis 657c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 658c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 659c9b443d4STobin Davis { 660c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 661c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 662c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 663c9b443d4STobin Davis spec->num_channel_mode, 664c9b443d4STobin Davis &spec->multiout.max_channels); 665c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 666c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 667c9b443d4STobin Davis return err; 668c9b443d4STobin Davis } 669c9b443d4STobin Davis 670c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 671c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 672c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 673c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 674c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 675c9b443d4STobin Davis .private_value = nid | (dir<<16) } 676c9b443d4STobin Davis 67786d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 67886d72bdfSTakashi Iwai 679c9b443d4STobin Davis /* Conexant 5045 specific */ 680c9b443d4STobin Davis 68134cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 68234cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 68334cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 684cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 685c9b443d4STobin Davis 68634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6875cd57529STobin Davis { 2, NULL }, 6885cd57529STobin Davis }; 689c9b443d4STobin Davis 69034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 691c9b443d4STobin Davis .num_items = 2, 692c9b443d4STobin Davis .items = { 69382f30040STobin Davis { "IntMic", 0x1 }, 694f4beee94SJiang zhe { "ExtMic", 0x2 }, 695c9b443d4STobin Davis } 696c9b443d4STobin Davis }; 697c9b443d4STobin Davis 69834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 69922e14130SLukasz Marcinowski .num_items = 5, 7005218c892SJiang Zhe .items = { 7015218c892SJiang Zhe { "IntMic", 0x1 }, 7025218c892SJiang Zhe { "ExtMic", 0x2 }, 7035218c892SJiang Zhe { "LineIn", 0x3 }, 70422e14130SLukasz Marcinowski { "CD", 0x4 }, 70522e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7065218c892SJiang Zhe } 7075218c892SJiang Zhe }; 7085218c892SJiang Zhe 70934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7102de3c232SJiang zhe .num_items = 2, 7112de3c232SJiang zhe .items = { 7122de3c232SJiang zhe { "ExtMic", 0x1 }, 7132de3c232SJiang zhe { "IntMic", 0x2 }, 7142de3c232SJiang zhe } 7152de3c232SJiang zhe }; 7162de3c232SJiang zhe 717c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 718c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 719c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 720c9b443d4STobin Davis { 721c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 722c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 72382f30040STobin Davis unsigned int bits; 724c9b443d4STobin Davis 72582f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 726c9b443d4STobin Davis return 0; 727c9b443d4STobin Davis 72882f30040STobin Davis /* toggle internal speakers mute depending of presence of 72982f30040STobin Davis * the headphone jack 73082f30040STobin Davis */ 73147fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 73247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 73347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7347f29673bSTobin Davis 73547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 73647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 73747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 738c9b443d4STobin Davis return 1; 739c9b443d4STobin Davis } 740c9b443d4STobin Davis 741c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 74234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 743cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 744cca3b371STakashi Iwai .values = { 745cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 746cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 747cca3b371STakashi Iwai 0 748cca3b371STakashi Iwai }, 749cca3b371STakashi Iwai }; 750c9b443d4STobin Davis 7517f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7527f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7537f29673bSTobin Davis { 75434cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7557f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7567f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7577f29673bSTobin Davis {} 7587f29673bSTobin Davis }; 75934cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7607f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7617f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7627f29673bSTobin Davis {} 7637f29673bSTobin Davis }; 7647f29673bSTobin Davis unsigned int present; 7657f29673bSTobin Davis 766d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7677f29673bSTobin Davis if (present) 7687f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7697f29673bSTobin Davis else 7707f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7717f29673bSTobin Davis } 7727f29673bSTobin Davis 773c9b443d4STobin Davis 774c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 775c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 776c9b443d4STobin Davis { 77782f30040STobin Davis struct conexant_spec *spec = codec->spec; 778dd87da1cSTobin Davis unsigned int bits; 779c9b443d4STobin Davis 780d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 781dd87da1cSTobin Davis 78247fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 78347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 78447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 785c9b443d4STobin Davis } 786c9b443d4STobin Davis 787c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 788c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 789c9b443d4STobin Davis unsigned int res) 790c9b443d4STobin Davis { 791c9b443d4STobin Davis res >>= 26; 792c9b443d4STobin Davis switch (res) { 793c9b443d4STobin Davis case CONEXANT_HP_EVENT: 794c9b443d4STobin Davis cxt5045_hp_automute(codec); 795c9b443d4STobin Davis break; 7967f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7977f29673bSTobin Davis cxt5045_hp_automic(codec); 7987f29673bSTobin Davis break; 7997f29673bSTobin Davis 800c9b443d4STobin Davis } 801c9b443d4STobin Davis } 802c9b443d4STobin Davis 80334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 80428c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 80528c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8068607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8078607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 808c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 809c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 81028c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 81128c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8128607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8138607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 814cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 815c9b443d4STobin Davis { 816c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 817c9b443d4STobin Davis .name = "Master Playback Switch", 81882f30040STobin Davis .info = cxt_eapd_info, 81982f30040STobin Davis .get = cxt_eapd_get, 820c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 82182f30040STobin Davis .private_value = 0x10, 822c9b443d4STobin Davis }, 823c9b443d4STobin Davis 824c9b443d4STobin Davis {} 825c9b443d4STobin Davis }; 826c9b443d4STobin Davis 82734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 82822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 82922e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 83022e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 83122e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 83222e14130SLukasz Marcinowski 8335218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8345218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8355218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8365218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8375218c892SJiang Zhe 83822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 83922e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 84022e14130SLukasz Marcinowski 8415218c892SJiang Zhe {} 8425218c892SJiang Zhe }; 8435218c892SJiang Zhe 84434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 84528c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 84628c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8478607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8488607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8492de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8502de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 85128c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 85228c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8538607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8548607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8552de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8562de3c232SJiang zhe { 8572de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8582de3c232SJiang zhe .name = "Master Playback Switch", 8592de3c232SJiang zhe .info = cxt_eapd_info, 8602de3c232SJiang zhe .get = cxt_eapd_get, 8612de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8622de3c232SJiang zhe .private_value = 0x10, 8632de3c232SJiang zhe }, 8642de3c232SJiang zhe 8652de3c232SJiang zhe {} 8662de3c232SJiang zhe }; 8672de3c232SJiang zhe 86834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 869c9b443d4STobin Davis /* Line in, Mic */ 8704090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8717f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 872c9b443d4STobin Davis /* HP, Amp */ 873c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 874c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 87582f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 876c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 877c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 878c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 879c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 880c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 881c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 88228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8837f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 88482f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 885c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 886c9b443d4STobin Davis /* SPDIF route: PCM */ 887cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 888c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 889c9b443d4STobin Davis /* EAPD */ 89082f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 891c9b443d4STobin Davis { } /* end */ 892c9b443d4STobin Davis }; 893c9b443d4STobin Davis 89434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 89528c4edb7SDavid Henningsson /* Internal Mic, Mic */ 8965218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8975218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8985218c892SJiang Zhe /* Line In,HP, Amp */ 8995218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9005218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9015218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9025218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9035218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9045218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9055218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9065218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9075218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 90828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9095218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9105218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9115218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9125218c892SJiang Zhe /* SPDIF route: PCM */ 913cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9145218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9155218c892SJiang Zhe /* EAPD */ 9165218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9175218c892SJiang Zhe { } /* end */ 9185218c892SJiang Zhe }; 9197f29673bSTobin Davis 92034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9217f29673bSTobin Davis /* pin sensing on HP jack */ 9227f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 923d3091fadSTakashi Iwai { } /* end */ 9247f29673bSTobin Davis }; 9257f29673bSTobin Davis 92634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9277f29673bSTobin Davis /* pin sensing on HP jack */ 9287f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 929d3091fadSTakashi Iwai { } /* end */ 9307f29673bSTobin Davis }; 9317f29673bSTobin Davis 932c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 933c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 934c9b443d4STobin Davis * configuration. 935c9b443d4STobin Davis */ 93634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 937c9b443d4STobin Davis .num_items = 5, 938c9b443d4STobin Davis .items = { 939c9b443d4STobin Davis { "MIXER", 0x0 }, 940c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 941c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 942c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 943c9b443d4STobin Davis { "CD pin", 0x4 }, 944c9b443d4STobin Davis }, 945c9b443d4STobin Davis }; 946c9b443d4STobin Davis 94734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 948c9b443d4STobin Davis 949c9b443d4STobin Davis /* Output controls */ 950c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 951c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9527f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9537f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9547f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9557f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 956c9b443d4STobin Davis 957c9b443d4STobin Davis /* Modes for retasking pin widgets */ 958c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 959c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 960c9b443d4STobin Davis 96182f30040STobin Davis /* EAPD Switch Control */ 96282f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 96382f30040STobin Davis 964c9b443d4STobin Davis /* Loopback mixer controls */ 965c9b443d4STobin Davis 9667f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9677f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9687f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9697f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9707f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9717f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9727f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9737f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9747f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9757f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 976c9b443d4STobin Davis { 977c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 978c9b443d4STobin Davis .name = "Input Source", 979c9b443d4STobin Davis .info = conexant_mux_enum_info, 980c9b443d4STobin Davis .get = conexant_mux_enum_get, 981c9b443d4STobin Davis .put = conexant_mux_enum_put, 982c9b443d4STobin Davis }, 983fb3409e7STobin Davis /* Audio input controls */ 984fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 985fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 986fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 987fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 988fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 989fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 990fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 991fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 992fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 993fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 994c9b443d4STobin Davis { } /* end */ 995c9b443d4STobin Davis }; 996c9b443d4STobin Davis 99734cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 9987f29673bSTobin Davis /* Set connections */ 9997f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10007f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10017f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1002c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1003c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10047f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1005c9b443d4STobin Davis 1006c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1007c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1008c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1009c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1010c9b443d4STobin Davis * control. 1011c9b443d4STobin Davis */ 1012cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1013cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1014c9b443d4STobin Davis 1015c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1016c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1017c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1018c9b443d4STobin Davis 1019c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1020c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1021c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1022c9b443d4STobin Davis * input/output buffers as needed. 1023c9b443d4STobin Davis */ 1024c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1025c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1026c9b443d4STobin Davis 1027c9b443d4STobin Davis /* Mute capture amp left and right */ 1028c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1029c9b443d4STobin Davis 1030c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1031c9b443d4STobin Davis * pin) 1032c9b443d4STobin Davis */ 1033c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10347f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1035c9b443d4STobin Davis 1036c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1037c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1038c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1039c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1040c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1041c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1042c9b443d4STobin Davis 1043c9b443d4STobin Davis { } 1044c9b443d4STobin Davis }; 1045c9b443d4STobin Davis #endif 1046c9b443d4STobin Davis 1047c9b443d4STobin Davis 1048c9b443d4STobin Davis /* initialize jack-sensing, too */ 1049c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1050c9b443d4STobin Davis { 1051c9b443d4STobin Davis conexant_init(codec); 1052c9b443d4STobin Davis cxt5045_hp_automute(codec); 1053c9b443d4STobin Davis return 0; 1054c9b443d4STobin Davis } 1055c9b443d4STobin Davis 1056c9b443d4STobin Davis 1057c9b443d4STobin Davis enum { 105815908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 105915908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 106015908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10615218c892SJiang Zhe CXT5045_BENQ, 10622de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1063c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1064c9b443d4STobin Davis CXT5045_TEST, 1065c9b443d4STobin Davis #endif 10661f8458a2STakashi Iwai CXT5045_AUTO, 1067f5fcc13cSTakashi Iwai CXT5045_MODELS 1068c9b443d4STobin Davis }; 1069c9b443d4STobin Davis 1070ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 107115908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 107215908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 107315908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10745218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10752de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1076c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1077f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1078c9b443d4STobin Davis #endif 10791f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1080f5fcc13cSTakashi Iwai }; 1081c9b443d4STobin Davis 108234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10832de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1084dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1085dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 10866a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10875218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 108815908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 108915908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10909e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10919e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 109215908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 109315908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 109415908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1095dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1096dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 109715908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1098c9b443d4STobin Davis {} 1099c9b443d4STobin Davis }; 1100c9b443d4STobin Davis 1101c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1102c9b443d4STobin Davis { 1103c9b443d4STobin Davis struct conexant_spec *spec; 1104c9b443d4STobin Davis int board_config; 1105c9b443d4STobin Davis 11061f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 11071f8458a2STakashi Iwai cxt5045_models, 11081f8458a2STakashi Iwai cxt5045_cfg_tbl); 11099b842cd8STakashi Iwai #if 0 /* use the old method just for safety */ 11101f8458a2STakashi Iwai if (board_config < 0) 11111f8458a2STakashi Iwai board_config = CXT5045_AUTO; 11129b842cd8STakashi Iwai #endif 11131f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11141f8458a2STakashi Iwai return patch_conexant_auto(codec); 11151f8458a2STakashi Iwai 1116c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1117c9b443d4STobin Davis if (!spec) 1118c9b443d4STobin Davis return -ENOMEM; 1119c9b443d4STobin Davis codec->spec = spec; 11209421f954STakashi Iwai codec->pin_amp_workaround = 1; 1121c9b443d4STobin Davis 1122c9b443d4STobin Davis spec->multiout.max_channels = 2; 1123c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1124c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1125c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1126c9b443d4STobin Davis spec->num_adc_nids = 1; 1127c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1128c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1129c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1130c9b443d4STobin Davis spec->num_mixers = 1; 1131c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1132c9b443d4STobin Davis spec->num_init_verbs = 1; 1133c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1134c9b443d4STobin Davis spec->spdif_route = 0; 11353507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11363507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11375cd57529STobin Davis 11383507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1139c9b443d4STobin Davis 1140c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1141c9b443d4STobin Davis 1142c9b443d4STobin Davis switch (board_config) { 114315908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11447f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1145c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1146c9b443d4STobin Davis spec->num_init_verbs = 2; 11477f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11487f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11497f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11507f29673bSTobin Davis break; 115115908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 115286376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11537f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11547f29673bSTobin Davis spec->num_init_verbs = 2; 11557f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1156c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1157c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1158c9b443d4STobin Davis break; 115915908c36SMarc Boucher default: 116015908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 116115908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 116215908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 116315908c36SMarc Boucher spec->num_init_verbs = 3; 116415908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 116515908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 116615908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 116715908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 116815908c36SMarc Boucher break; 11695218c892SJiang Zhe case CXT5045_BENQ: 11705218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11715218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11725218c892SJiang Zhe spec->num_init_verbs = 1; 11735218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11745218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11755218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11765218c892SJiang Zhe spec->num_mixers = 2; 11775218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11785218c892SJiang Zhe break; 11792de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11802de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11812de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11822de3c232SJiang zhe spec->num_init_verbs = 2; 11832de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11842de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11852de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11862de3c232SJiang zhe break; 1187c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1188c9b443d4STobin Davis case CXT5045_TEST: 1189c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1190c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1191c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 119215908c36SMarc Boucher break; 119315908c36SMarc Boucher 1194c9b443d4STobin Davis #endif 1195c9b443d4STobin Davis } 119648ecb7e8STakashi Iwai 1197031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1198031005f7STakashi Iwai case 0x103c: 11998f0f5ff6SDaniel T Chen case 0x1631: 12000b587fc4SDaniel T Chen case 0x1734: 12010ebf9e36SDaniel T Chen case 0x17aa: 12020ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12030ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12040ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 120548ecb7e8STakashi Iwai */ 120648ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 120748ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 120848ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 120948ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 121048ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1211031005f7STakashi Iwai break; 1212031005f7STakashi Iwai } 121348ecb7e8STakashi Iwai 12143507e2a8STakashi Iwai if (spec->beep_amp) 12153507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12163507e2a8STakashi Iwai 1217c9b443d4STobin Davis return 0; 1218c9b443d4STobin Davis } 1219c9b443d4STobin Davis 1220c9b443d4STobin Davis 1221c9b443d4STobin Davis /* Conexant 5047 specific */ 122282f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1223c9b443d4STobin Davis 122434cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 122534cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 122634cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1227c9b443d4STobin Davis 122834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12295cd57529STobin Davis { 2, NULL }, 12305cd57529STobin Davis }; 1231c9b443d4STobin Davis 123234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 123382f30040STobin Davis .num_items = 2, 123482f30040STobin Davis .items = { 123582f30040STobin Davis { "ExtMic", 0x2 }, 123682f30040STobin Davis { "Line-In", 0x1 }, 1237c9b443d4STobin Davis } 1238c9b443d4STobin Davis }; 1239c9b443d4STobin Davis 1240c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1241c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1242c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1243c9b443d4STobin Davis { 1244c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1245c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 124682f30040STobin Davis unsigned int bits; 1247c9b443d4STobin Davis 124882f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1249c9b443d4STobin Davis return 0; 1250c9b443d4STobin Davis 125182f30040STobin Davis /* toggle internal speakers mute depending of presence of 125282f30040STobin Davis * the headphone jack 125382f30040STobin Davis */ 125447fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12553b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12563b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12573b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12583b7523fcSTakashi Iwai */ 12595d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 126047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 126147fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 126247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 126347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1264c9b443d4STobin Davis return 1; 1265c9b443d4STobin Davis } 1266c9b443d4STobin Davis 1267c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1268c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1269c9b443d4STobin Davis { 127082f30040STobin Davis struct conexant_spec *spec = codec->spec; 1271dd87da1cSTobin Davis unsigned int bits; 1272c9b443d4STobin Davis 1273d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1274dd87da1cSTobin Davis 127547fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12763b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12775d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 127847fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1279c9b443d4STobin Davis } 1280c9b443d4STobin Davis 1281c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1282c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1283c9b443d4STobin Davis { 128434cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12859f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12869f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1287c9b443d4STobin Davis {} 1288c9b443d4STobin Davis }; 128934cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12909f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12919f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1292c9b443d4STobin Davis {} 1293c9b443d4STobin Davis }; 1294c9b443d4STobin Davis unsigned int present; 1295c9b443d4STobin Davis 1296d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1297c9b443d4STobin Davis if (present) 1298c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1299c9b443d4STobin Davis else 1300c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1301c9b443d4STobin Davis } 1302c9b443d4STobin Davis 1303c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1304c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1305c9b443d4STobin Davis unsigned int res) 1306c9b443d4STobin Davis { 13079f113e0eSMarc Boucher switch (res >> 26) { 1308c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1309c9b443d4STobin Davis cxt5047_hp_automute(codec); 1310c9b443d4STobin Davis break; 1311c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1312c9b443d4STobin Davis cxt5047_hp_automic(codec); 1313c9b443d4STobin Davis break; 1314c9b443d4STobin Davis } 1315c9b443d4STobin Davis } 1316c9b443d4STobin Davis 131734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1318df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1319df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13205f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1321c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1322c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1323c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1324c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 132582f30040STobin Davis { 132682f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 132782f30040STobin Davis .name = "Master Playback Switch", 132882f30040STobin Davis .info = cxt_eapd_info, 132982f30040STobin Davis .get = cxt_eapd_get, 1330c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1331c9b443d4STobin Davis .private_value = 0x13, 1332c9b443d4STobin Davis }, 1333c9b443d4STobin Davis 1334c9b443d4STobin Davis {} 1335c9b443d4STobin Davis }; 1336c9b443d4STobin Davis 133734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13383b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13395d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1340df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1341df481e41STakashi Iwai {} 1342df481e41STakashi Iwai }; 1343df481e41STakashi Iwai 134434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1345c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1346c9b443d4STobin Davis { } /* end */ 1347c9b443d4STobin Davis }; 1348c9b443d4STobin Davis 134934cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1350c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1351c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1352c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1353c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13547f29673bSTobin Davis /* HP, Speaker */ 1355b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13565b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13575b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13587f29673bSTobin Davis /* Record selector: Mic */ 13597f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13607f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13617f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13627f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1363c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1364c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1365c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1366c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1367c9b443d4STobin Davis /* SPDIF route: PCM */ 1368c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 136982f30040STobin Davis /* Enable unsolicited events */ 137082f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 137182f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1372c9b443d4STobin Davis { } /* end */ 1373c9b443d4STobin Davis }; 1374c9b443d4STobin Davis 1375c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 137634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13773b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1378c9b443d4STobin Davis {} 1379c9b443d4STobin Davis }; 1380c9b443d4STobin Davis 1381c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1382c9b443d4STobin Davis * configuration. 1383c9b443d4STobin Davis */ 1384c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 138534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 138682f30040STobin Davis .num_items = 4, 1387c9b443d4STobin Davis .items = { 138882f30040STobin Davis { "LINE1 pin", 0x0 }, 138982f30040STobin Davis { "MIC1 pin", 0x1 }, 139082f30040STobin Davis { "MIC2 pin", 0x2 }, 139182f30040STobin Davis { "CD pin", 0x3 }, 1392c9b443d4STobin Davis }, 1393c9b443d4STobin Davis }; 1394c9b443d4STobin Davis 139534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1396c9b443d4STobin Davis 1397c9b443d4STobin Davis /* Output only controls */ 139882f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 139982f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 140082f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 140182f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1402c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1403c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1404c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1405c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 140682f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 140782f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 140882f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 140982f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1410c9b443d4STobin Davis 1411c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1412c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1413c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1414c9b443d4STobin Davis 141582f30040STobin Davis /* EAPD Switch Control */ 141682f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 141782f30040STobin Davis 1418c9b443d4STobin Davis /* Loopback mixer controls */ 141982f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 142082f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 142182f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 142282f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 142382f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 142482f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 142582f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 142682f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1427c9b443d4STobin Davis 142882f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 142982f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 143082f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 143182f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 143282f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 143382f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 143482f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 143582f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1436c9b443d4STobin Davis { 1437c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1438c9b443d4STobin Davis .name = "Input Source", 1439c9b443d4STobin Davis .info = conexant_mux_enum_info, 1440c9b443d4STobin Davis .get = conexant_mux_enum_get, 1441c9b443d4STobin Davis .put = conexant_mux_enum_put, 1442c9b443d4STobin Davis }, 1443854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14449f113e0eSMarc Boucher 1445c9b443d4STobin Davis { } /* end */ 1446c9b443d4STobin Davis }; 1447c9b443d4STobin Davis 144834cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1449c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1450c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1451c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1452c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1453c9b443d4STobin Davis 1454c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1455c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1456c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1457c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1458c9b443d4STobin Davis * control. 1459c9b443d4STobin Davis */ 1460c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1463c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1464c9b443d4STobin Davis */ 1465c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1466c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1467c9b443d4STobin Davis 1468c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1469c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1470c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1471c9b443d4STobin Davis 1472c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1473c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1474c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1475c9b443d4STobin Davis * input/output buffers as needed. 1476c9b443d4STobin Davis */ 1477c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1478c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1479c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1480c9b443d4STobin Davis 1481c9b443d4STobin Davis /* Mute capture amp left and right */ 1482c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1483c9b443d4STobin Davis 1484c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1485c9b443d4STobin Davis * pin) 1486c9b443d4STobin Davis */ 1487c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1488c9b443d4STobin Davis 1489c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1490c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1491c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1492c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1493c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1494c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1495c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1496c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1497c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1498c9b443d4STobin Davis 1499c9b443d4STobin Davis { } 1500c9b443d4STobin Davis }; 1501c9b443d4STobin Davis #endif 1502c9b443d4STobin Davis 1503c9b443d4STobin Davis 1504c9b443d4STobin Davis /* initialize jack-sensing, too */ 1505c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1506c9b443d4STobin Davis { 1507c9b443d4STobin Davis conexant_init(codec); 1508c9b443d4STobin Davis cxt5047_hp_automute(codec); 1509c9b443d4STobin Davis return 0; 1510c9b443d4STobin Davis } 1511c9b443d4STobin Davis 1512c9b443d4STobin Davis 1513c9b443d4STobin Davis enum { 1514f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1515f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1516f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1517c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1518c9b443d4STobin Davis CXT5047_TEST, 1519c9b443d4STobin Davis #endif 1520fa5dadcbSTakashi Iwai CXT5047_AUTO, 1521f5fcc13cSTakashi Iwai CXT5047_MODELS 1522c9b443d4STobin Davis }; 1523c9b443d4STobin Davis 1524ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1525f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1526f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1527f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1528c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1529f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1530c9b443d4STobin Davis #endif 1531fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1532f5fcc13cSTakashi Iwai }; 1533c9b443d4STobin Davis 153434cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1535ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1536dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1537dea0a509STakashi Iwai CXT5047_LAPTOP), 1538f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1539c9b443d4STobin Davis {} 1540c9b443d4STobin Davis }; 1541c9b443d4STobin Davis 1542c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1543c9b443d4STobin Davis { 1544c9b443d4STobin Davis struct conexant_spec *spec; 1545c9b443d4STobin Davis int board_config; 1546c9b443d4STobin Davis 1547fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1548fa5dadcbSTakashi Iwai cxt5047_models, 1549fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1550fa5dadcbSTakashi Iwai #if 0 /* not enabled as default, as BIOS often broken for this codec */ 1551fa5dadcbSTakashi Iwai if (board_config < 0) 1552fa5dadcbSTakashi Iwai board_config = CXT5047_AUTO; 1553fa5dadcbSTakashi Iwai #endif 1554fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1555fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1556fa5dadcbSTakashi Iwai 1557c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1558c9b443d4STobin Davis if (!spec) 1559c9b443d4STobin Davis return -ENOMEM; 1560c9b443d4STobin Davis codec->spec = spec; 15619421f954STakashi Iwai codec->pin_amp_workaround = 1; 1562c9b443d4STobin Davis 1563c9b443d4STobin Davis spec->multiout.max_channels = 2; 1564c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1565c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1566c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1567c9b443d4STobin Davis spec->num_adc_nids = 1; 1568c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1569c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1570c9b443d4STobin Davis spec->num_mixers = 1; 1571df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1572c9b443d4STobin Davis spec->num_init_verbs = 1; 1573c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1574c9b443d4STobin Davis spec->spdif_route = 0; 15755cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15765cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1577c9b443d4STobin Davis 1578c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1579c9b443d4STobin Davis 1580c9b443d4STobin Davis switch (board_config) { 1581c9b443d4STobin Davis case CXT5047_LAPTOP: 1582df481e41STakashi Iwai spec->num_mixers = 2; 1583df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1584df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1585c9b443d4STobin Davis break; 1586c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1587df481e41STakashi Iwai spec->num_mixers = 2; 1588df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1589fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1590c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1591c9b443d4STobin Davis break; 1592c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 159382f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1594df481e41STakashi Iwai spec->num_mixers = 2; 1595df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1596c9b443d4STobin Davis spec->num_init_verbs = 2; 1597c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1598fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1599c9b443d4STobin Davis break; 1600c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1601c9b443d4STobin Davis case CXT5047_TEST: 1602c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1603c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1604c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1605fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1606c9b443d4STobin Davis #endif 1607c9b443d4STobin Davis } 1608dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1609025f206cSDaniel T Chen 1610025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1611025f206cSDaniel T Chen case 0x103c: 1612025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1613025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1614025f206cSDaniel T Chen * with 0 dB offset 0x17) 1615025f206cSDaniel T Chen */ 1616025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1617025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1618025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1619025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1620025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1621025f206cSDaniel T Chen break; 1622025f206cSDaniel T Chen } 1623025f206cSDaniel T Chen 1624c9b443d4STobin Davis return 0; 1625c9b443d4STobin Davis } 1626c9b443d4STobin Davis 1627461e2c78STakashi Iwai /* Conexant 5051 specific */ 162834cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 162934cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1630461e2c78STakashi Iwai 163134cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1632461e2c78STakashi Iwai { 2, NULL }, 1633461e2c78STakashi Iwai }; 1634461e2c78STakashi Iwai 1635461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1636461e2c78STakashi Iwai { 1637461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1638461e2c78STakashi Iwai unsigned int pinctl; 163923d2df5bSTakashi Iwai /* headphone pin */ 164023d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 164123d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 164223d2df5bSTakashi Iwai pinctl); 164323d2df5bSTakashi Iwai /* speaker pin */ 1644461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1645461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1646461e2c78STakashi Iwai pinctl); 1647f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1648f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1649f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1650f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1651f7154de2SHerton Ronaldo Krzesinski pinctl); 1652461e2c78STakashi Iwai } 1653461e2c78STakashi Iwai 1654461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1655461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1656461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1657461e2c78STakashi Iwai { 1658461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1659461e2c78STakashi Iwai 1660461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1661461e2c78STakashi Iwai return 0; 1662461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1663461e2c78STakashi Iwai return 1; 1664461e2c78STakashi Iwai } 1665461e2c78STakashi Iwai 1666461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1667461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1668461e2c78STakashi Iwai { 166979d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1670461e2c78STakashi Iwai unsigned int present; 1671461e2c78STakashi Iwai 1672faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 167379d7d533STakashi Iwai return; 1674d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1675461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1676461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1677461e2c78STakashi Iwai present ? 0x01 : 0x00); 1678461e2c78STakashi Iwai } 1679461e2c78STakashi Iwai 1680461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1681461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1682461e2c78STakashi Iwai { 1683461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1684461e2c78STakashi Iwai unsigned int present; 1685461e2c78STakashi Iwai hda_nid_t new_adc; 1686461e2c78STakashi Iwai 1687faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 168879d7d533STakashi Iwai return; 1689d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1690461e2c78STakashi Iwai if (present) 1691461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1692461e2c78STakashi Iwai else 1693461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1694461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1695461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1696461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1697f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1698461e2c78STakashi Iwai spec->cur_adc = new_adc; 1699461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1700461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1701461e2c78STakashi Iwai spec->cur_adc_format); 1702461e2c78STakashi Iwai } 1703461e2c78STakashi Iwai } 1704461e2c78STakashi Iwai 1705461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1706461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1707461e2c78STakashi Iwai { 1708461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1709461e2c78STakashi Iwai 1710d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1711461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1712461e2c78STakashi Iwai } 1713461e2c78STakashi Iwai 1714461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1715461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1716461e2c78STakashi Iwai unsigned int res) 1717461e2c78STakashi Iwai { 1718acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1719461e2c78STakashi Iwai switch (res >> 26) { 1720461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1721461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1722461e2c78STakashi Iwai break; 1723461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1724461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1725461e2c78STakashi Iwai break; 1726461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1727461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1728461e2c78STakashi Iwai break; 1729461e2c78STakashi Iwai } 1730cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 1731461e2c78STakashi Iwai } 1732461e2c78STakashi Iwai 173334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1734461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1735461e2c78STakashi Iwai { 1736461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1737461e2c78STakashi Iwai .name = "Master Playback Switch", 1738461e2c78STakashi Iwai .info = cxt_eapd_info, 1739461e2c78STakashi Iwai .get = cxt_eapd_get, 1740461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1741461e2c78STakashi Iwai .private_value = 0x1a, 1742461e2c78STakashi Iwai }, 17432c7a3fb3STakashi Iwai {} 17442c7a3fb3STakashi Iwai }; 1745461e2c78STakashi Iwai 174634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17472c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17482c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17498607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17508607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17512c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17522c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1753461e2c78STakashi Iwai {} 1754461e2c78STakashi Iwai }; 1755461e2c78STakashi Iwai 175634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1757461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1758461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17598607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17608607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1761461e2c78STakashi Iwai {} 1762461e2c78STakashi Iwai }; 1763461e2c78STakashi Iwai 176434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17654e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17664e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 176779d7d533STakashi Iwai {} 176879d7d533STakashi Iwai }; 176979d7d533STakashi Iwai 177034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17715f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17725f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1773cd9d95a5SKen Prox {} 1774cd9d95a5SKen Prox }; 1775cd9d95a5SKen Prox 177634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1777faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1778faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17798607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17808607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1781faddaa5dSTakashi Iwai {} 1782faddaa5dSTakashi Iwai }; 1783faddaa5dSTakashi Iwai 178434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1785461e2c78STakashi Iwai /* Line in, Mic */ 1786461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1787461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1788461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1789461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1790461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1791461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1792461e2c78STakashi Iwai /* SPK */ 1793461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1794461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1795461e2c78STakashi Iwai /* HP, Amp */ 1796461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1797461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1798461e2c78STakashi Iwai /* DAC1 */ 1799461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 180028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1801461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1802461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1803461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1804461e2c78STakashi Iwai /* SPDIF route: PCM */ 18051965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1806461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1807461e2c78STakashi Iwai /* EAPD */ 1808461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1809461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1810461e2c78STakashi Iwai { } /* end */ 1811461e2c78STakashi Iwai }; 1812461e2c78STakashi Iwai 181334cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 181479d7d533STakashi Iwai /* Line in, Mic */ 181579d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 181679d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 181779d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 181879d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 181979d7d533STakashi Iwai /* SPK */ 182079d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 182179d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 182279d7d533STakashi Iwai /* HP, Amp */ 182379d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 182479d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 182579d7d533STakashi Iwai /* DAC1 */ 182679d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 182728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 182879d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 182979d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 183079d7d533STakashi Iwai /* SPDIF route: PCM */ 183179d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 183279d7d533STakashi Iwai /* EAPD */ 183379d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 183479d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 183579d7d533STakashi Iwai { } /* end */ 183679d7d533STakashi Iwai }; 183779d7d533STakashi Iwai 183834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 183927e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 184027e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 184127e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 184227e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 184327e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 184427e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 184527e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 184627e08988SAristeu Sergio Rozanski Filho /* SPK */ 184727e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 184827e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 184927e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 185027e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 185127e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 185227e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 185327e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 185427e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 185527e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 185627e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 185728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 185827e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 185927e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 186027e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 186127e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 18621965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ 186327e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 186427e08988SAristeu Sergio Rozanski Filho /* EAPD */ 186527e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 186627e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 186727e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 186827e08988SAristeu Sergio Rozanski Filho { } /* end */ 186927e08988SAristeu Sergio Rozanski Filho }; 187027e08988SAristeu Sergio Rozanski Filho 187134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1872cd9d95a5SKen Prox /* Line in, Mic */ 187330ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1874cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1875cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1876cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1877cd9d95a5SKen Prox /* SPK */ 1878cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1879cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1880cd9d95a5SKen Prox /* HP, Amp */ 1881cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1882cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1883cd9d95a5SKen Prox /* DAC1 */ 1884cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 188528c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1886cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1887cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1888cd9d95a5SKen Prox /* SPDIF route: PCM */ 1889cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1890cd9d95a5SKen Prox /* EAPD */ 1891cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1892cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1893cd9d95a5SKen Prox { } /* end */ 1894cd9d95a5SKen Prox }; 1895cd9d95a5SKen Prox 18966953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18976953e552STakashi Iwai unsigned int event) 18986953e552STakashi Iwai { 18996953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19006953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19016953e552STakashi Iwai AC_USRSP_EN | event); 1902cd372fb3STakashi Iwai snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL); 1903cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 19046953e552STakashi Iwai } 19056953e552STakashi Iwai 190634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1907f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1908f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1909f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1910f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1911f7154de2SHerton Ronaldo Krzesinski }; 1912f7154de2SHerton Ronaldo Krzesinski 1913461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1914461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1915461e2c78STakashi Iwai { 19166953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19176953e552STakashi Iwai 1918461e2c78STakashi Iwai conexant_init(codec); 1919acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19206953e552STakashi Iwai 19216953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19226953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19236953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19246953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19256953e552STakashi Iwai 1926461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1927461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1928461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1929461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1930461e2c78STakashi Iwai } 1931461e2c78STakashi Iwai return 0; 1932461e2c78STakashi Iwai } 1933461e2c78STakashi Iwai 1934461e2c78STakashi Iwai 1935461e2c78STakashi Iwai enum { 1936461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1937461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 193879d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 19391965c441SPierre-Louis Bossart CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ 1940cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1941faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1942f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 19436764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1944461e2c78STakashi Iwai CXT5051_MODELS 1945461e2c78STakashi Iwai }; 1946461e2c78STakashi Iwai 1947ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1948461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1949461e2c78STakashi Iwai [CXT5051_HP] = "hp", 195079d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 195127e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 19525f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1953faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1954f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19556764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1956461e2c78STakashi Iwai }; 1957461e2c78STakashi Iwai 195834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 195979d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19601812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19615f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1962faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1963461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1964461e2c78STakashi Iwai CXT5051_LAPTOP), 1965461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 196627e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 1967f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1968461e2c78STakashi Iwai {} 1969461e2c78STakashi Iwai }; 1970461e2c78STakashi Iwai 1971461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1972461e2c78STakashi Iwai { 1973461e2c78STakashi Iwai struct conexant_spec *spec; 1974461e2c78STakashi Iwai int board_config; 1975461e2c78STakashi Iwai 19766764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19776764bcefSTakashi Iwai cxt5051_models, 19786764bcefSTakashi Iwai cxt5051_cfg_tbl); 19799b842cd8STakashi Iwai #if 0 /* use the old method just for safety */ 19806764bcefSTakashi Iwai if (board_config < 0) 19816764bcefSTakashi Iwai board_config = CXT5051_AUTO; 19829b842cd8STakashi Iwai #endif 19831f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19846764bcefSTakashi Iwai return patch_conexant_auto(codec); 19856764bcefSTakashi Iwai 1986461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1987461e2c78STakashi Iwai if (!spec) 1988461e2c78STakashi Iwai return -ENOMEM; 1989461e2c78STakashi Iwai codec->spec = spec; 19909421f954STakashi Iwai codec->pin_amp_workaround = 1; 1991461e2c78STakashi Iwai 1992461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1993461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1994461e2c78STakashi Iwai 1995461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1996461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1997461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1998461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1999461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 2000461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 20012c7a3fb3STakashi Iwai spec->num_mixers = 2; 20022c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20032c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2004461e2c78STakashi Iwai spec->num_init_verbs = 1; 2005461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2006461e2c78STakashi Iwai spec->spdif_route = 0; 2007461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2008461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2009461e2c78STakashi Iwai spec->cur_adc = 0; 2010461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2011461e2c78STakashi Iwai 20123507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20133507e2a8STakashi Iwai 201479d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 201579d7d533STakashi Iwai 2016faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2017461e2c78STakashi Iwai switch (board_config) { 2018461e2c78STakashi Iwai case CXT5051_HP: 2019461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2020461e2c78STakashi Iwai break; 202179d7d533STakashi Iwai case CXT5051_HP_DV6736: 202279d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 202379d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2024faddaa5dSTakashi Iwai spec->auto_mic = 0; 202579d7d533STakashi Iwai break; 202627e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 202727e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 2028607bc3e4SJerone Young /* Thinkpad X301 does not have S/PDIF wired and no ability 2029607bc3e4SJerone Young to use a docking station. */ 2030607bc3e4SJerone Young if (codec->subsystem_id == 0x17aa211f) 2031607bc3e4SJerone Young spec->multiout.dig_out_nid = 0; 2032461e2c78STakashi Iwai break; 2033cd9d95a5SKen Prox case CXT5051_F700: 2034cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2035cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2036faddaa5dSTakashi Iwai spec->auto_mic = 0; 2037faddaa5dSTakashi Iwai break; 2038faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2039faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2040faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2041cd9d95a5SKen Prox break; 2042f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2043f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2044f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2045f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2046f7154de2SHerton Ronaldo Krzesinski break; 2047461e2c78STakashi Iwai } 2048461e2c78STakashi Iwai 20493507e2a8STakashi Iwai if (spec->beep_amp) 20503507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20513507e2a8STakashi Iwai 2052461e2c78STakashi Iwai return 0; 2053461e2c78STakashi Iwai } 2054461e2c78STakashi Iwai 20550fb67e98SDaniel Drake /* Conexant 5066 specific */ 20560fb67e98SDaniel Drake 205734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 205834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 205934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 206034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 20610fb67e98SDaniel Drake 2062dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2063dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2064dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2065dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2066dbaccc0cSDaniel Drake 206734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20680fb67e98SDaniel Drake { 2, NULL }, 20690fb67e98SDaniel Drake }; 20700fb67e98SDaniel Drake 2071a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2072a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2073a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2074a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2075a3de8ab8STakashi Iwai 20760fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20770fb67e98SDaniel Drake { 20780fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20790fb67e98SDaniel Drake unsigned int pinctl; 20800fb67e98SDaniel Drake 20813a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20823a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20830fb67e98SDaniel Drake 20840fb67e98SDaniel Drake /* Port A (HP) */ 2085a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20860fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20870fb67e98SDaniel Drake pinctl); 20880fb67e98SDaniel Drake 20890fb67e98SDaniel Drake /* Port D (HP/LO) */ 2090a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2091a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2092a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2093a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20943a253445SJohn Baboval pinctl = 0; 20953a253445SJohn Baboval } else { 2096a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2097a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2098a3de8ab8STakashi Iwai pinctl = 0; 20993a253445SJohn Baboval } 21000fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21010fb67e98SDaniel Drake pinctl); 21020fb67e98SDaniel Drake 21030fb67e98SDaniel Drake /* CLASS_D AMP */ 21040fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21050fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21060fb67e98SDaniel Drake pinctl); 21070fb67e98SDaniel Drake } 21080fb67e98SDaniel Drake 21090fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21100fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21110fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21120fb67e98SDaniel Drake { 21130fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21140fb67e98SDaniel Drake 21150fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21160fb67e98SDaniel Drake return 0; 21170fb67e98SDaniel Drake 21180fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21190fb67e98SDaniel Drake return 1; 21200fb67e98SDaniel Drake } 21210fb67e98SDaniel Drake 2122c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2123c4cfe66cSDaniel Drake .num_items = 3, 2124c4cfe66cSDaniel Drake .items = { 2125c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2126c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2127c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2128c4cfe66cSDaniel Drake }, 2129c4cfe66cSDaniel Drake }; 2130c4cfe66cSDaniel Drake 2131c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2132c4cfe66cSDaniel Drake { 2133c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2134c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2135c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2136c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2137c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2138c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2139c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2140c4cfe66cSDaniel Drake } 2141c4cfe66cSDaniel Drake 214275f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 214375f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 214475f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 214575f8991dSDaniel Drake * is happening when it is not. */ 214675f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21470fb67e98SDaniel Drake { 2148dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 214975f8991dSDaniel Drake if (!spec->recording) 215075f8991dSDaniel Drake return; 21510fb67e98SDaniel Drake 2152c4cfe66cSDaniel Drake if (spec->dc_enable) { 2153c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2154c4cfe66cSDaniel Drake * through our special DC port */ 2155c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2156c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2157c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2158c4cfe66cSDaniel Drake 2159c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2160c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2161c4cfe66cSDaniel Drake {}, 2162c4cfe66cSDaniel Drake }; 2163c4cfe66cSDaniel Drake 2164c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2165c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2166c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2167c4cfe66cSDaniel Drake return; 2168c4cfe66cSDaniel Drake } 2169c4cfe66cSDaniel Drake 2170c4cfe66cSDaniel Drake /* disable DC (port F) */ 2171c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2172c4cfe66cSDaniel Drake 217375f8991dSDaniel Drake /* external mic, port B */ 217475f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 217575f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21760fb67e98SDaniel Drake 217775f8991dSDaniel Drake /* internal mic, port C */ 217875f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 217975f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 218075f8991dSDaniel Drake } 21810fb67e98SDaniel Drake 218275f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 218375f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 218475f8991dSDaniel Drake { 218575f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21860fb67e98SDaniel Drake unsigned int present; 21870fb67e98SDaniel Drake 2188c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2189c4cfe66cSDaniel Drake return; 2190c4cfe66cSDaniel Drake 219175f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 219275f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 219375f8991dSDaniel Drake if (present) 21940fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 219575f8991dSDaniel Drake else 21960fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 219775f8991dSDaniel Drake 219875f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 219975f8991dSDaniel Drake present ? 0 : 1); 220075f8991dSDaniel Drake spec->ext_mic_present = !!present; 220175f8991dSDaniel Drake 220275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22030fb67e98SDaniel Drake } 22040fb67e98SDaniel Drake 220595a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 220695a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 220795a618bdSEinar Rünkaru { 220895a618bdSEinar Rünkaru unsigned int present; 220995a618bdSEinar Rünkaru 221095a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 221195a618bdSEinar Rünkaru /* enable external mic, port B */ 221275f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 221395a618bdSEinar Rünkaru 221495a618bdSEinar Rünkaru /* switch to external mic input */ 221595a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 221695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 221795a618bdSEinar Rünkaru 221895a618bdSEinar Rünkaru /* disable internal digital mic */ 221995a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 222095a618bdSEinar Rünkaru {} 222195a618bdSEinar Rünkaru }; 222234cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 222395a618bdSEinar Rünkaru /* enable internal mic, port C */ 222495a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 222595a618bdSEinar Rünkaru 222695a618bdSEinar Rünkaru /* switch to internal mic input */ 222795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 222895a618bdSEinar Rünkaru 222995a618bdSEinar Rünkaru /* disable external mic, port B */ 223095a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 223195a618bdSEinar Rünkaru {} 223295a618bdSEinar Rünkaru }; 223395a618bdSEinar Rünkaru 223495a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 223595a618bdSEinar Rünkaru if (present) { 223695a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 223795a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 223895a618bdSEinar Rünkaru } else { 223995a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 224095a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 224195a618bdSEinar Rünkaru } 224295a618bdSEinar Rünkaru } 224395a618bdSEinar Rünkaru 2244cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2245cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2246cfd3d8dcSGreg Alexander { 2247cfd3d8dcSGreg Alexander unsigned int present; 2248cfd3d8dcSGreg Alexander 2249cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2250cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2251cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2252cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2253cfd3d8dcSGreg Alexander {} 2254cfd3d8dcSGreg Alexander }; 225534cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2256cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2257cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2258cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2259cfd3d8dcSGreg Alexander {} 2260cfd3d8dcSGreg Alexander }; 2261cfd3d8dcSGreg Alexander 2262cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2263cfd3d8dcSGreg Alexander if (present) { 2264cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2265cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2266cfd3d8dcSGreg Alexander } else { 2267cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2268cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2269cfd3d8dcSGreg Alexander } 2270cfd3d8dcSGreg Alexander } 2271cfd3d8dcSGreg Alexander 2272a1d6906eSDavid Henningsson 2273a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2274a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2275a1d6906eSDavid Henningsson { 2276a1d6906eSDavid Henningsson unsigned int present; 2277a1d6906eSDavid Henningsson 2278a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2279a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2280a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2281a1d6906eSDavid Henningsson present ? 1 : 0); 2282a1d6906eSDavid Henningsson } 2283a1d6906eSDavid Henningsson 2284a1d6906eSDavid Henningsson 2285048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2286048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2287048e78a5SDavid Henningsson { 2288048e78a5SDavid Henningsson unsigned int present; 2289048e78a5SDavid Henningsson 2290048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2291048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2292048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2293048e78a5SDavid Henningsson present ? 1 : 3); 2294048e78a5SDavid Henningsson } 2295048e78a5SDavid Henningsson 2296048e78a5SDavid Henningsson 22977b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22987b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22997b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23007b2bfdbcSJens Taprogge { 23017b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23027b2bfdbcSJens Taprogge 230334cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 23047b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23057b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23067b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23077b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23087b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23097b2bfdbcSJens Taprogge {} 23107b2bfdbcSJens Taprogge }; 231134cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 23127b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23137b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23147b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23157b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23167b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23177b2bfdbcSJens Taprogge {} 23187b2bfdbcSJens Taprogge }; 231934cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 23207b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23217b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23227b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23237b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23247b2bfdbcSJens Taprogge {} 23257b2bfdbcSJens Taprogge }; 23267b2bfdbcSJens Taprogge 23277b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23287b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23297b2bfdbcSJens Taprogge if (ext_present) { 23307b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23317b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23327b2bfdbcSJens Taprogge } else if (dock_present) { 23337b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23347b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23357b2bfdbcSJens Taprogge } else { 23367b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23377b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23387b2bfdbcSJens Taprogge } 23397b2bfdbcSJens Taprogge } 23407b2bfdbcSJens Taprogge 23410fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23420fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23430fb67e98SDaniel Drake { 23440fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23450fb67e98SDaniel Drake unsigned int portA, portD; 23460fb67e98SDaniel Drake 23470fb67e98SDaniel Drake /* Port A */ 2348d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23490fb67e98SDaniel Drake 23500fb67e98SDaniel Drake /* Port D */ 2351d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23520fb67e98SDaniel Drake 2353a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2354a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 23550fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23560fb67e98SDaniel Drake portA, portD, spec->hp_present); 23570fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23580fb67e98SDaniel Drake } 23590fb67e98SDaniel Drake 236002b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 236102b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 236202b6b5b6SDavid Henningsson { 236302b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 236402b6b5b6SDavid Henningsson 236502b6b5b6SDavid Henningsson if (spec->dell_vostro) 236602b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 236702b6b5b6SDavid Henningsson else if (spec->ideapad) 236802b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 236902b6b5b6SDavid Henningsson else if (spec->thinkpad) 237002b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 237102b6b5b6SDavid Henningsson else if (spec->hp_laptop) 237202b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2373a1d6906eSDavid Henningsson else if (spec->asus) 2374a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 237502b6b5b6SDavid Henningsson } 237602b6b5b6SDavid Henningsson 23770fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 237875f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23790fb67e98SDaniel Drake { 2380c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23810fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23820fb67e98SDaniel Drake switch (res >> 26) { 23830fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23840fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23850fb67e98SDaniel Drake break; 23860fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2387c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2388c4cfe66cSDaniel Drake if (!spec->dc_enable) 238975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23900fb67e98SDaniel Drake break; 23910fb67e98SDaniel Drake } 23920fb67e98SDaniel Drake } 23930fb67e98SDaniel Drake 239495a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 239502b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 239695a618bdSEinar Rünkaru { 239702b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 239895a618bdSEinar Rünkaru switch (res >> 26) { 239995a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 240095a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 240195a618bdSEinar Rünkaru break; 240295a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 240302b6b5b6SDavid Henningsson cxt5066_automic(codec); 240495a618bdSEinar Rünkaru break; 240595a618bdSEinar Rünkaru } 240695a618bdSEinar Rünkaru } 240795a618bdSEinar Rünkaru 24087b2bfdbcSJens Taprogge 24090fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24100fb67e98SDaniel Drake .num_items = 5, 24110fb67e98SDaniel Drake .items = { 24120fb67e98SDaniel Drake { "0dB", 0 }, 24130fb67e98SDaniel Drake { "10dB", 1 }, 24140fb67e98SDaniel Drake { "20dB", 2 }, 24150fb67e98SDaniel Drake { "30dB", 3 }, 24160fb67e98SDaniel Drake { "40dB", 4 }, 24170fb67e98SDaniel Drake }, 24180fb67e98SDaniel Drake }; 24190fb67e98SDaniel Drake 2420cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2421c4cfe66cSDaniel Drake { 2422c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2423cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2424c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2425c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2426c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24277b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2428cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2429cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2430cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2431cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2432cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2433cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2434cfd3d8dcSGreg Alexander } 2435c4cfe66cSDaniel Drake } 2436c4cfe66cSDaniel Drake 24370fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24380fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24390fb67e98SDaniel Drake { 24400fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24410fb67e98SDaniel Drake } 24420fb67e98SDaniel Drake 24430fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24440fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24450fb67e98SDaniel Drake { 24460fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2447c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2448c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 24490fb67e98SDaniel Drake return 0; 24500fb67e98SDaniel Drake } 24510fb67e98SDaniel Drake 24520fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 24530fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24540fb67e98SDaniel Drake { 24550fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2456c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24570fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 24580fb67e98SDaniel Drake unsigned int idx; 24590fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 24600fb67e98SDaniel Drake if (idx >= imux->num_items) 24610fb67e98SDaniel Drake idx = imux->num_items - 1; 24620fb67e98SDaniel Drake 2463c4cfe66cSDaniel Drake spec->mic_boost = idx; 2464c4cfe66cSDaniel Drake if (!spec->dc_enable) 2465c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2466c4cfe66cSDaniel Drake return 1; 2467c4cfe66cSDaniel Drake } 24680fb67e98SDaniel Drake 2469c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2470c4cfe66cSDaniel Drake { 2471c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2472c4cfe66cSDaniel Drake /* disable gain */ 2473c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2474c4cfe66cSDaniel Drake 2475c4cfe66cSDaniel Drake /* switch to DC input */ 2476c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2477c4cfe66cSDaniel Drake {} 2478c4cfe66cSDaniel Drake }; 2479c4cfe66cSDaniel Drake 2480c4cfe66cSDaniel Drake /* configure as input source */ 2481c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2482c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2483c4cfe66cSDaniel Drake } 2484c4cfe66cSDaniel Drake 2485c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2486c4cfe66cSDaniel Drake { 2487c4cfe66cSDaniel Drake /* reconfigure input source */ 2488c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2489c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2490c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2491c4cfe66cSDaniel Drake } 2492c4cfe66cSDaniel Drake 2493c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2494c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2495c4cfe66cSDaniel Drake { 2496c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2497c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2498c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2499c4cfe66cSDaniel Drake return 0; 2500c4cfe66cSDaniel Drake } 2501c4cfe66cSDaniel Drake 2502c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2503c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2504c4cfe66cSDaniel Drake { 2505c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2506c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2507c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2508c4cfe66cSDaniel Drake 2509c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2510c4cfe66cSDaniel Drake return 0; 2511c4cfe66cSDaniel Drake 2512c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2513c4cfe66cSDaniel Drake if (dc_enable) 2514c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2515c4cfe66cSDaniel Drake else 2516c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2517c4cfe66cSDaniel Drake 2518c4cfe66cSDaniel Drake return 1; 2519c4cfe66cSDaniel Drake } 2520c4cfe66cSDaniel Drake 2521c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2522c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2523c4cfe66cSDaniel Drake { 2524c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2525c4cfe66cSDaniel Drake } 2526c4cfe66cSDaniel Drake 2527c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2528c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2529c4cfe66cSDaniel Drake { 2530c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2531c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2532c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2533c4cfe66cSDaniel Drake return 0; 2534c4cfe66cSDaniel Drake } 2535c4cfe66cSDaniel Drake 2536c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2537c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2538c4cfe66cSDaniel Drake { 2539c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2540c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2541c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2542c4cfe66cSDaniel Drake unsigned int idx; 2543c4cfe66cSDaniel Drake 2544c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2545c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2546c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2547c4cfe66cSDaniel Drake 2548c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2549c4cfe66cSDaniel Drake if (spec->dc_enable) 2550c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25510fb67e98SDaniel Drake return 1; 25520fb67e98SDaniel Drake } 25530fb67e98SDaniel Drake 255475f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 255575f8991dSDaniel Drake { 255675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 255775f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 255875f8991dSDaniel Drake * recording LED comes on. */ 255975f8991dSDaniel Drake spec->recording = 1; 256075f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 256175f8991dSDaniel Drake } 256275f8991dSDaniel Drake 256375f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 256475f8991dSDaniel Drake { 256575f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 256675f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 256775f8991dSDaniel Drake /* disable external mic, port B */ 256875f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 256975f8991dSDaniel Drake 257075f8991dSDaniel Drake /* disble internal mic, port C */ 257175f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2572c4cfe66cSDaniel Drake 2573c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2574c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 257575f8991dSDaniel Drake {}, 257675f8991dSDaniel Drake }; 257775f8991dSDaniel Drake 257875f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 257975f8991dSDaniel Drake spec->recording = 0; 258075f8991dSDaniel Drake } 258175f8991dSDaniel Drake 2582f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 258334cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2584f6a2491cSAndy Robinson int num_pins) 2585f6a2491cSAndy Robinson { 2586f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2587f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2588f6a2491cSAndy Robinson int i; 2589f6a2491cSAndy Robinson 2590f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2591f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2592f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2593f6a2491cSAndy Robinson continue; 2594f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2595f6a2491cSAndy Robinson continue; 2596f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2597f6a2491cSAndy Robinson nid_loc++; 2598f6a2491cSAndy Robinson else 2599f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2600f6a2491cSAndy Robinson } 2601f6a2491cSAndy Robinson } 2602f6a2491cSAndy Robinson 260334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 26040fb67e98SDaniel Drake .num_items = 4, 26050fb67e98SDaniel Drake .items = { 26060fb67e98SDaniel Drake { "Mic B", 0 }, 26070fb67e98SDaniel Drake { "Mic C", 1 }, 26080fb67e98SDaniel Drake { "Mic E", 2 }, 26090fb67e98SDaniel Drake { "Mic F", 3 }, 26100fb67e98SDaniel Drake }, 26110fb67e98SDaniel Drake }; 26120fb67e98SDaniel Drake 261334cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26140fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26150fb67e98SDaniel Drake .values = { 26160fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26170fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26180fb67e98SDaniel Drake 0 26190fb67e98SDaniel Drake }, 26200fb67e98SDaniel Drake }; 26210fb67e98SDaniel Drake 262234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26230fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26240fb67e98SDaniel Drake .values = { 26250fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26260fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26270fb67e98SDaniel Drake 0 26280fb67e98SDaniel Drake }, 26290fb67e98SDaniel Drake }; 26300fb67e98SDaniel Drake 263134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 26320fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26330fb67e98SDaniel Drake {} 26340fb67e98SDaniel Drake }; 26350fb67e98SDaniel Drake 263634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26370fb67e98SDaniel Drake { 26380fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26390fb67e98SDaniel Drake .name = "Master Playback Volume", 26400fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26410fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26420fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26435e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26440fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26450fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26460fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26470fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26480fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26490fb67e98SDaniel Drake .private_value = 26500fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26510fb67e98SDaniel Drake }, 26520fb67e98SDaniel Drake {} 26530fb67e98SDaniel Drake }; 26540fb67e98SDaniel Drake 265534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2656c4cfe66cSDaniel Drake { 2657c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2658c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2659c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2660c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2661c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2662c4cfe66cSDaniel Drake }, 2663c4cfe66cSDaniel Drake { 2664c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2665c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2666c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2667c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2668c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2669c4cfe66cSDaniel Drake }, 2670c4cfe66cSDaniel Drake {} 2671c4cfe66cSDaniel Drake }; 2672c4cfe66cSDaniel Drake 267334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 26740fb67e98SDaniel Drake { 26750fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26760fb67e98SDaniel Drake .name = "Master Playback Switch", 26770fb67e98SDaniel Drake .info = cxt_eapd_info, 26780fb67e98SDaniel Drake .get = cxt_eapd_get, 26790fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26800fb67e98SDaniel Drake .private_value = 0x1d, 26810fb67e98SDaniel Drake }, 26820fb67e98SDaniel Drake 26830fb67e98SDaniel Drake { 26840fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2685c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26860fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26870fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26880fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26890fb67e98SDaniel Drake }, 26900fb67e98SDaniel Drake 26910fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26920fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26930fb67e98SDaniel Drake {} 26940fb67e98SDaniel Drake }; 26950fb67e98SDaniel Drake 269634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2697254bba6aSEinar Rünkaru { 2698254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 269928c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2700254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2701254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2702254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2703254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2704254bba6aSEinar Rünkaru }, 2705254bba6aSEinar Rünkaru {} 2706254bba6aSEinar Rünkaru }; 2707254bba6aSEinar Rünkaru 270834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 27090fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27100fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27110fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27120fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27130fb67e98SDaniel Drake 27140fb67e98SDaniel Drake /* Speakers */ 27150fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27160fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27170fb67e98SDaniel Drake 27180fb67e98SDaniel Drake /* HP, Amp */ 27190fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27200fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27210fb67e98SDaniel Drake 27220fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27230fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27240fb67e98SDaniel Drake 27250fb67e98SDaniel Drake /* DAC1 */ 27260fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27270fb67e98SDaniel Drake 27280fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27290fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27300fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27310fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27320fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27330fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27340fb67e98SDaniel Drake 27350fb67e98SDaniel Drake /* no digital microphone support yet */ 27360fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27370fb67e98SDaniel Drake 27380fb67e98SDaniel Drake /* Audio input selector */ 27390fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27400fb67e98SDaniel Drake 27410fb67e98SDaniel Drake /* SPDIF route: PCM */ 27420fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27430fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27440fb67e98SDaniel Drake 27450fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27460fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27470fb67e98SDaniel Drake 27480fb67e98SDaniel Drake /* EAPD */ 27490fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27500fb67e98SDaniel Drake 27510fb67e98SDaniel Drake /* not handling these yet */ 27520fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27530fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27540fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27550fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27560fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27570fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27580fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27590fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27600fb67e98SDaniel Drake { } /* end */ 27610fb67e98SDaniel Drake }; 27620fb67e98SDaniel Drake 276334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27640fb67e98SDaniel Drake /* Port A: headphones */ 27650fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27660fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27670fb67e98SDaniel Drake 27680fb67e98SDaniel Drake /* Port B: external microphone */ 276975f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27700fb67e98SDaniel Drake 27710fb67e98SDaniel Drake /* Port C: internal microphone */ 277275f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27730fb67e98SDaniel Drake 27740fb67e98SDaniel Drake /* Port D: unused */ 27750fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27760fb67e98SDaniel Drake 27770fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27780fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27790fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27800fb67e98SDaniel Drake 2781c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27820fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27830fb67e98SDaniel Drake 27840fb67e98SDaniel Drake /* Port G: internal speakers */ 27850fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27860fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27870fb67e98SDaniel Drake 27880fb67e98SDaniel Drake /* DAC1 */ 27890fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27900fb67e98SDaniel Drake 27910fb67e98SDaniel Drake /* DAC2: unused */ 27920fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27930fb67e98SDaniel Drake 27940fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27950fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27960fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27970fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27980fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27990fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28000fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28010fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28020fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28030fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28040fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28050fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28060fb67e98SDaniel Drake 28070fb67e98SDaniel Drake /* Disable digital microphone port */ 28080fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28090fb67e98SDaniel Drake 28100fb67e98SDaniel Drake /* Audio input selectors */ 28110fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28120fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28130fb67e98SDaniel Drake 28140fb67e98SDaniel Drake /* Disable SPDIF */ 28150fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28160fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28170fb67e98SDaniel Drake 28180fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28190fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28200fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28210fb67e98SDaniel Drake { } /* end */ 28220fb67e98SDaniel Drake }; 28230fb67e98SDaniel Drake 282434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 282595a618bdSEinar Rünkaru /* Port A: headphones */ 282695a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 282895a618bdSEinar Rünkaru 282995a618bdSEinar Rünkaru /* Port B: external microphone */ 283095a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 283195a618bdSEinar Rünkaru 283295a618bdSEinar Rünkaru /* Port C: unused */ 283395a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 283495a618bdSEinar Rünkaru 283595a618bdSEinar Rünkaru /* Port D: unused */ 283695a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 283795a618bdSEinar Rünkaru 283895a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 283995a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 284095a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 284195a618bdSEinar Rünkaru 284295a618bdSEinar Rünkaru /* Port F: unused */ 284395a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 284495a618bdSEinar Rünkaru 284595a618bdSEinar Rünkaru /* Port G: internal speakers */ 284695a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 284795a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 284895a618bdSEinar Rünkaru 284995a618bdSEinar Rünkaru /* DAC1 */ 285095a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 285195a618bdSEinar Rünkaru 285295a618bdSEinar Rünkaru /* DAC2: unused */ 285395a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 285495a618bdSEinar Rünkaru 285595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 285695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 285795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 285895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 285995a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 286095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 286195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 286295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 286395a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 286495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 286595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 286695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 286795a618bdSEinar Rünkaru 286895a618bdSEinar Rünkaru /* Digital microphone port */ 286995a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 287095a618bdSEinar Rünkaru 287195a618bdSEinar Rünkaru /* Audio input selectors */ 287295a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 287395a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 287495a618bdSEinar Rünkaru 287595a618bdSEinar Rünkaru /* Disable SPDIF */ 287695a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287795a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287895a618bdSEinar Rünkaru 287995a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 288095a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 288195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 288295a618bdSEinar Rünkaru { } /* end */ 288395a618bdSEinar Rünkaru }; 288495a618bdSEinar Rünkaru 288534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2886cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2887cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2888cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2889cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2890cfd3d8dcSGreg Alexander 2891cfd3d8dcSGreg Alexander /* Speakers */ 2892cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2893cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2894cfd3d8dcSGreg Alexander 2895cfd3d8dcSGreg Alexander /* HP, Amp */ 2896cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2897cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2898cfd3d8dcSGreg Alexander 2899cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2900cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2901cfd3d8dcSGreg Alexander 2902cfd3d8dcSGreg Alexander /* DAC1 */ 2903cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2904cfd3d8dcSGreg Alexander 2905cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2906cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2907cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2908cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2909cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2910cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2911cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2912cfd3d8dcSGreg Alexander 2913cfd3d8dcSGreg Alexander /* Audio input selector */ 2914cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2915cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2916cfd3d8dcSGreg Alexander 2917cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2918cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2919cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2920cfd3d8dcSGreg Alexander 2921cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2922cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2923cfd3d8dcSGreg Alexander 2924cfd3d8dcSGreg Alexander /* internal microphone */ 292528c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2926cfd3d8dcSGreg Alexander 2927cfd3d8dcSGreg Alexander /* EAPD */ 2928cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2929cfd3d8dcSGreg Alexander 2930cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2931cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2932cfd3d8dcSGreg Alexander { } /* end */ 2933cfd3d8dcSGreg Alexander }; 2934cfd3d8dcSGreg Alexander 293534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29367b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29377b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29387b2bfdbcSJens Taprogge 29397b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29407b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29417b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29427b2bfdbcSJens Taprogge 29437b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29447b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29457b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29467b2bfdbcSJens Taprogge 29477b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29487b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29497b2bfdbcSJens Taprogge 29507b2bfdbcSJens Taprogge /* Port C: Mic */ 29517b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29527b2bfdbcSJens Taprogge 29537b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29547b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29557b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29567b2bfdbcSJens Taprogge 29577b2bfdbcSJens Taprogge /* DAC1 */ 29587b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29597b2bfdbcSJens Taprogge 29607b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29617b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29627b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29637b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29647b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29657b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29667b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29677b2bfdbcSJens Taprogge 29687b2bfdbcSJens Taprogge /* Audio input selector */ 29697b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29707b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29717b2bfdbcSJens Taprogge 29727b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29737b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29747b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29757b2bfdbcSJens Taprogge 29767b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29777b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29787b2bfdbcSJens Taprogge 29797b2bfdbcSJens Taprogge /* internal microphone */ 298028c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29817b2bfdbcSJens Taprogge 29827b2bfdbcSJens Taprogge /* EAPD */ 29837b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29847b2bfdbcSJens Taprogge 29857b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29867b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29877b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29887b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29897b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29907b2bfdbcSJens Taprogge { } /* end */ 29917b2bfdbcSJens Taprogge }; 29927b2bfdbcSJens Taprogge 299334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29940fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29950fb67e98SDaniel Drake { } /* end */ 29960fb67e98SDaniel Drake }; 29970fb67e98SDaniel Drake 2998048e78a5SDavid Henningsson 299934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3000048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3001048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3002048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3003048e78a5SDavid Henningsson { } /* end */ 3004048e78a5SDavid Henningsson }; 3005048e78a5SDavid Henningsson 30060fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30070fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30080fb67e98SDaniel Drake { 30090fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30100fb67e98SDaniel Drake conexant_init(codec); 30110fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30120fb67e98SDaniel Drake cxt5066_hp_automute(codec); 301302b6b5b6SDavid Henningsson cxt5066_automic(codec); 30140fb67e98SDaniel Drake } 3015c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30160fb67e98SDaniel Drake return 0; 30170fb67e98SDaniel Drake } 30180fb67e98SDaniel Drake 301975f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 302075f8991dSDaniel Drake { 3021c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 302275f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 302375f8991dSDaniel Drake conexant_init(codec); 302475f8991dSDaniel Drake cxt5066_hp_automute(codec); 3025c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3026c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 302775f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3028c4cfe66cSDaniel Drake } else { 3029c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3030c4cfe66cSDaniel Drake } 303175f8991dSDaniel Drake return 0; 303275f8991dSDaniel Drake } 303375f8991dSDaniel Drake 30340fb67e98SDaniel Drake enum { 30350fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30360fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30370fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 30381feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 3039cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30407b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3041a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 3042048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 3043*fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 30440fb67e98SDaniel Drake CXT5066_MODELS 30450fb67e98SDaniel Drake }; 30460fb67e98SDaniel Drake 3047ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 30480fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30490fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30500fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30511feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3052cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30537b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3054a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 3055048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 3056*fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 30570fb67e98SDaniel Drake }; 30580fb67e98SDaniel Drake 305934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 306000cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30611feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30628a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3063ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30641feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3065231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3066ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3067ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3068048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3069f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3070a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3071f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 30722ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3073c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30744442dd46SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 30755637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30765637edb2SDavid Henningsson CXT5066_LAPTOP), 30775637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30784d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3079ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 308019593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 30817b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 308284012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3083b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3084a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 308522f21d51SDavid Henningsson SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ 30860fb67e98SDaniel Drake {} 30870fb67e98SDaniel Drake }; 30880fb67e98SDaniel Drake 30890fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30900fb67e98SDaniel Drake { 30910fb67e98SDaniel Drake struct conexant_spec *spec; 30920fb67e98SDaniel Drake int board_config; 30930fb67e98SDaniel Drake 3094*fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3095*fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3096*fea4a4f9STakashi Iwai #if 0 /* use the old method just for safety */ 3097*fea4a4f9STakashi Iwai if (board_config < 0) 3098*fea4a4f9STakashi Iwai board_config = CXT5066_AUTO; 3099*fea4a4f9STakashi Iwai #endif 3100*fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3101*fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3102*fea4a4f9STakashi Iwai 31030fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31040fb67e98SDaniel Drake if (!spec) 31050fb67e98SDaniel Drake return -ENOMEM; 31060fb67e98SDaniel Drake codec->spec = spec; 31070fb67e98SDaniel Drake 31080fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 310975f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31100fb67e98SDaniel Drake 31110fb67e98SDaniel Drake spec->dell_automute = 0; 31120fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31130fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31140fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3115f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3116f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 31170fb67e98SDaniel Drake spec->num_adc_nids = 1; 31180fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31190fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31200fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31210fb67e98SDaniel Drake 31220fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31230fb67e98SDaniel Drake 31240fb67e98SDaniel Drake spec->num_init_verbs = 1; 31250fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31260fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31270fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31280fb67e98SDaniel Drake spec->cur_adc = 0; 31290fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31300fb67e98SDaniel Drake 31313507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31323507e2a8STakashi Iwai 31330fb67e98SDaniel Drake switch (board_config) { 31340fb67e98SDaniel Drake default: 31350fb67e98SDaniel Drake case CXT5066_LAPTOP: 31360fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31370fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31380fb67e98SDaniel Drake break; 31390fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31400fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31410fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31420fb67e98SDaniel Drake 31430fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31440fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31450fb67e98SDaniel Drake spec->num_init_verbs++; 31460fb67e98SDaniel Drake spec->dell_automute = 1; 31470fb67e98SDaniel Drake break; 3148a1d6906eSDavid Henningsson case CXT5066_ASUS: 3149048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3150048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 315102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3152048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3153048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3154048e78a5SDavid Henningsson spec->num_init_verbs++; 3155a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3156a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3157048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3158048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3159048e78a5SDavid Henningsson /* no S/PDIF out */ 3160f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3161048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3162048e78a5SDavid Henningsson /* input source automatically selected */ 3163048e78a5SDavid Henningsson spec->input_mux = NULL; 3164048e78a5SDavid Henningsson spec->port_d_mode = 0; 3165048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3166048e78a5SDavid Henningsson break; 3167048e78a5SDavid Henningsson 31680fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 316975f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 317075f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31710fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31720fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3173c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31740fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31750fb67e98SDaniel Drake spec->port_d_mode = 0; 3176c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31770fb67e98SDaniel Drake 31780fb67e98SDaniel Drake /* no S/PDIF out */ 31790fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31800fb67e98SDaniel Drake 31810fb67e98SDaniel Drake /* input source automatically selected */ 31820fb67e98SDaniel Drake spec->input_mux = NULL; 318375f8991dSDaniel Drake 318475f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 318575f8991dSDaniel Drake * at the right time */ 318675f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 318775f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31880fb67e98SDaniel Drake break; 31891feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 319075f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 319102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 319295a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 319395a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 319495a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3195254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 319695a618bdSEinar Rünkaru spec->port_d_mode = 0; 3197254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3198c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 319995a618bdSEinar Rünkaru 320095a618bdSEinar Rünkaru /* no S/PDIF out */ 320195a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 320295a618bdSEinar Rünkaru 320395a618bdSEinar Rünkaru /* input source automatically selected */ 320495a618bdSEinar Rünkaru spec->input_mux = NULL; 320595a618bdSEinar Rünkaru break; 3206cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3207cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 320802b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3209cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3210cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3211cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3212cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3213cfd3d8dcSGreg Alexander spec->ideapad = 1; 3214cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3215cfd3d8dcSGreg Alexander 3216cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3217cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3218cfd3d8dcSGreg Alexander 3219cfd3d8dcSGreg Alexander /* input source automatically selected */ 3220cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3221cfd3d8dcSGreg Alexander break; 32227b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32237b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 322402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 32257b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32267b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32277b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32287b2bfdbcSJens Taprogge spec->thinkpad = 1; 32297b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32307b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32317b2bfdbcSJens Taprogge 32327b2bfdbcSJens Taprogge /* no S/PDIF out */ 32337b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32347b2bfdbcSJens Taprogge 32357b2bfdbcSJens Taprogge /* input source automatically selected */ 32367b2bfdbcSJens Taprogge spec->input_mux = NULL; 32377b2bfdbcSJens Taprogge break; 32380fb67e98SDaniel Drake } 32390fb67e98SDaniel Drake 32403507e2a8STakashi Iwai if (spec->beep_amp) 32413507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32423507e2a8STakashi Iwai 32430fb67e98SDaniel Drake return 0; 32440fb67e98SDaniel Drake } 3245461e2c78STakashi Iwai 3246461e2c78STakashi Iwai /* 3247f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3248f2e5731dSTakashi Iwai */ 3249f2e5731dSTakashi Iwai 32506764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 32516764bcefSTakashi Iwai struct hda_codec *codec, 32526764bcefSTakashi Iwai unsigned int stream_tag, 32536764bcefSTakashi Iwai unsigned int format, 32546764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32556764bcefSTakashi Iwai { 32566764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32576764bcefSTakashi Iwai hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]]; 32586764bcefSTakashi Iwai if (spec->adc_switching) { 32596764bcefSTakashi Iwai spec->cur_adc = adc; 32606764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32616764bcefSTakashi Iwai spec->cur_adc_format = format; 32626764bcefSTakashi Iwai } 32636764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32646764bcefSTakashi Iwai return 0; 32656764bcefSTakashi Iwai } 32666764bcefSTakashi Iwai 32676764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 32686764bcefSTakashi Iwai struct hda_codec *codec, 32696764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32706764bcefSTakashi Iwai { 32716764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32726764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 32736764bcefSTakashi Iwai spec->cur_adc = 0; 32746764bcefSTakashi Iwai return 0; 32756764bcefSTakashi Iwai } 32766764bcefSTakashi Iwai 32776764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32786764bcefSTakashi Iwai .substreams = 1, 32796764bcefSTakashi Iwai .channels_min = 2, 32806764bcefSTakashi Iwai .channels_max = 2, 32816764bcefSTakashi Iwai .nid = 0, /* fill later */ 32826764bcefSTakashi Iwai .ops = { 32836764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32846764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32856764bcefSTakashi Iwai }, 32866764bcefSTakashi Iwai }; 32876764bcefSTakashi Iwai 328834cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3289f2e5731dSTakashi Iwai 3290f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */ 3291f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, 3292f2e5731dSTakashi Iwai hda_nid_t nid) 3293f2e5731dSTakashi Iwai { 3294f2e5731dSTakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 3295f2e5731dSTakashi Iwai int i, nums; 3296f2e5731dSTakashi Iwai 3297f2e5731dSTakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 3298f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) 3299f2e5731dSTakashi Iwai if (conn[i] == nid) 3300f2e5731dSTakashi Iwai return i; 3301f2e5731dSTakashi Iwai return -1; 3302f2e5731dSTakashi Iwai } 3303f2e5731dSTakashi Iwai 3304f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3305f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3306f2e5731dSTakashi Iwai * not found 3307f2e5731dSTakashi Iwai */ 3308f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3309f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3310f2e5731dSTakashi Iwai { 3311f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3312f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3313f2e5731dSTakashi Iwai 3314f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3315f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3316f2e5731dSTakashi Iwai ret = dacs[i]; 3317f2e5731dSTakashi Iwai break; 3318f2e5731dSTakashi Iwai } 3319f2e5731dSTakashi Iwai } 3320f2e5731dSTakashi Iwai if (!ret) 3321f2e5731dSTakashi Iwai return 0; 3322f2e5731dSTakashi Iwai if (--nums > 0) 3323f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3324f2e5731dSTakashi Iwai *num_dacs = nums; 3325f2e5731dSTakashi Iwai return ret; 3326f2e5731dSTakashi Iwai } 3327f2e5731dSTakashi Iwai 3328f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3329f2e5731dSTakashi Iwai 3330f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3331f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3332f2e5731dSTakashi Iwai { 3333f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3334f2e5731dSTakashi Iwai int nums = 0; 3335f2e5731dSTakashi Iwai 3336f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3337f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3338f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3339f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3340f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3341f2e5731dSTakashi Iwai dacs[nums++] = nid; 3342f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3343f2e5731dSTakashi Iwai break; 3344f2e5731dSTakashi Iwai } 3345f2e5731dSTakashi Iwai } 3346f2e5731dSTakashi Iwai return nums; 3347f2e5731dSTakashi Iwai } 3348f2e5731dSTakashi Iwai 3349f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3350f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3351f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3352f2e5731dSTakashi Iwai struct pin_dac_pair *filled, int type) 3353f2e5731dSTakashi Iwai { 3354f2e5731dSTakashi Iwai int i, nums; 3355f2e5731dSTakashi Iwai 3356f2e5731dSTakashi Iwai nums = 0; 3357f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3358f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3359f2e5731dSTakashi Iwai filled[nums].type = type; 3360f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3361f2e5731dSTakashi Iwai nums++; 3362f2e5731dSTakashi Iwai } 3363f2e5731dSTakashi Iwai return nums; 3364f2e5731dSTakashi Iwai } 3365f2e5731dSTakashi Iwai 3366f2e5731dSTakashi Iwai /* parse analog output paths */ 3367f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3368f2e5731dSTakashi Iwai { 3369f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3370f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3371f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3372f2e5731dSTakashi Iwai int i, j, nums, rest; 3373f2e5731dSTakashi Iwai 3374f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3375f2e5731dSTakashi Iwai /* parse all analog output pins */ 3376f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3377f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info, 3378f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3379f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3380f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3381f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3382f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3383f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3384f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3385f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3386f2e5731dSTakashi Iwai /* fill multiout struct */ 3387f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3388f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 3389f2e5731dSTakashi Iwai if (!dac) 3390f2e5731dSTakashi Iwai continue; 3391f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3392f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3393f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3394f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3395f2e5731dSTakashi Iwai break; 3396f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3397f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3398f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3399f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3400f2e5731dSTakashi Iwai break; 3401f2e5731dSTakashi Iwai } 3402f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3403f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3404f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3405f2e5731dSTakashi Iwai break; 3406f2e5731dSTakashi Iwai } 3407f2e5731dSTakashi Iwai break; 3408f2e5731dSTakashi Iwai } 3409f2e5731dSTakashi Iwai } 3410f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 341189724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3412f2e5731dSTakashi Iwai 3413f2e5731dSTakashi Iwai if (cfg->hp_outs > 0) 3414f2e5731dSTakashi Iwai spec->auto_mute = 1; 3415f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3416f2e5731dSTakashi Iwai } 3417f2e5731dSTakashi Iwai 3418da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3419da339866STakashi Iwai hda_nid_t *pins, bool on); 3420da339866STakashi Iwai 3421f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 3422f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3423f2e5731dSTakashi Iwai { 3424f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3425f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3426f2e5731dSTakashi Iwai int i, present; 3427f2e5731dSTakashi Iwai 3428f2e5731dSTakashi Iwai if (!spec->auto_mute) 3429f2e5731dSTakashi Iwai return; 3430f2e5731dSTakashi Iwai present = 0; 3431f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3432f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) { 3433f2e5731dSTakashi Iwai present = 1; 3434f2e5731dSTakashi Iwai break; 3435f2e5731dSTakashi Iwai } 3436f2e5731dSTakashi Iwai } 3437da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present); 3438f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 3439f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3440f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3441f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3442f2e5731dSTakashi Iwai } 3443da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present); 3444fbb5bb56STakashi Iwai for (i = 0; !present && i < cfg->line_outs; i++) 3445fbb5bb56STakashi Iwai if (snd_hda_jack_detect(codec, cfg->line_out_pins[i])) 3446fbb5bb56STakashi Iwai present = 1; 3447f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) { 3448f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3449f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3450f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3451f2e5731dSTakashi Iwai } 3452da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present); 3453f2e5731dSTakashi Iwai } 3454f2e5731dSTakashi Iwai 34556764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 34566764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 34576764bcefSTakashi Iwai { 34586764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 34596764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 34606764bcefSTakashi Iwai 34616764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 34626764bcefSTakashi Iwai } 34636764bcefSTakashi Iwai 34646764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 34656764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 34666764bcefSTakashi Iwai { 34676764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 34686764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 34696764bcefSTakashi Iwai 34706764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 34716764bcefSTakashi Iwai return 0; 34726764bcefSTakashi Iwai } 34736764bcefSTakashi Iwai 34745c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 34755c9887e0STakashi Iwai * if do_select is set, actually select the route. 34765c9887e0STakashi Iwai */ 34775c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3478cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3479cf27f29aSTakashi Iwai bool do_select, int depth) 34805c9887e0STakashi Iwai { 34815c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 34825c9887e0STakashi Iwai int i, nums; 34835c9887e0STakashi Iwai 3484cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3485cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3486cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3487cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3488cf27f29aSTakashi Iwai break; 3489cf27f29aSTakashi Iwai default: 3490cf27f29aSTakashi Iwai return -1; 3491cf27f29aSTakashi Iwai } 3492cf27f29aSTakashi Iwai 34935c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 34945c9887e0STakashi Iwai for (i = 0; i < nums; i++) 34955c9887e0STakashi Iwai if (conn[i] == pin) { 34965c9887e0STakashi Iwai if (do_select) 34975c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 34985c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3499cf27f29aSTakashi Iwai if (srcp) 3500cf27f29aSTakashi Iwai *srcp = mux; 35015c9887e0STakashi Iwai return i; 35025c9887e0STakashi Iwai } 35035c9887e0STakashi Iwai depth++; 35045c9887e0STakashi Iwai if (depth == 2) 35055c9887e0STakashi Iwai return -1; 35065c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3507cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 35085c9887e0STakashi Iwai do_select, depth); 35095c9887e0STakashi Iwai if (ret >= 0) { 35105c9887e0STakashi Iwai if (do_select) 35115c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35125c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3513cf27f29aSTakashi Iwai return i; 35145c9887e0STakashi Iwai } 35155c9887e0STakashi Iwai } 35165c9887e0STakashi Iwai return -1; 35175c9887e0STakashi Iwai } 35185c9887e0STakashi Iwai 35195c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 35205c9887e0STakashi Iwai hda_nid_t pin) 35215c9887e0STakashi Iwai { 3522cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 35235c9887e0STakashi Iwai } 35245c9887e0STakashi Iwai 35255c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 35265c9887e0STakashi Iwai hda_nid_t pin) 35275c9887e0STakashi Iwai { 3528cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 35295c9887e0STakashi Iwai } 35305c9887e0STakashi Iwai 35316764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 35326764bcefSTakashi Iwai const struct hda_input_mux *imux, 35336764bcefSTakashi Iwai unsigned int idx) 35346764bcefSTakashi Iwai { 35356764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35366764bcefSTakashi Iwai hda_nid_t adc; 35376764bcefSTakashi Iwai 35386764bcefSTakashi Iwai if (!imux->num_items) 35396764bcefSTakashi Iwai return 0; 35406764bcefSTakashi Iwai if (idx >= imux->num_items) 35416764bcefSTakashi Iwai idx = imux->num_items - 1; 35426764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 35436764bcefSTakashi Iwai return 0; 35446764bcefSTakashi Iwai adc = spec->imux_adcs[idx]; 35455c9887e0STakashi Iwai select_input_connection(codec, spec->imux_adcs[idx], 35465c9887e0STakashi Iwai spec->imux_pins[idx]); 35476764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 35486764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 35496764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 35506764bcefSTakashi Iwai spec->cur_adc = adc; 35516764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 35526764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 35536764bcefSTakashi Iwai spec->cur_adc_format); 35546764bcefSTakashi Iwai } 35556764bcefSTakashi Iwai spec->cur_mux[0] = idx; 35566764bcefSTakashi Iwai return 1; 35576764bcefSTakashi Iwai } 35586764bcefSTakashi Iwai 35596764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 35606764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35616764bcefSTakashi Iwai { 35626764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35636764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35646764bcefSTakashi Iwai 35656764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 35666764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 35676764bcefSTakashi Iwai } 35686764bcefSTakashi Iwai 35696764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 35706764bcefSTakashi Iwai { 35716764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 35726764bcefSTakashi Iwai .name = "Capture Source", 35736764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 35746764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 35756764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 35766764bcefSTakashi Iwai }, 35776764bcefSTakashi Iwai {} 35786764bcefSTakashi Iwai }; 35796764bcefSTakashi Iwai 3580f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3581f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3582f2e5731dSTakashi Iwai { 3583f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3584f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3585f2e5731dSTakashi Iwai 3586f2e5731dSTakashi Iwai if (!spec->auto_mic) 3587f2e5731dSTakashi Iwai return; 3588f6100bb4STakashi Iwai if (snd_hda_jack_detect(codec, spec->imux_pins[ext_idx])) 35896764bcefSTakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx); 35906764bcefSTakashi Iwai else 35916764bcefSTakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx); 3592f2e5731dSTakashi Iwai } 3593f2e5731dSTakashi Iwai 3594f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3595f2e5731dSTakashi Iwai { 3596f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3597f2e5731dSTakashi Iwai switch (res >> 26) { 3598f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3599f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3600cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 3601f2e5731dSTakashi Iwai break; 3602f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3603f2e5731dSTakashi Iwai cx_auto_automic(codec); 3604cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 3605f2e5731dSTakashi Iwai break; 3606f2e5731dSTakashi Iwai } 3607f2e5731dSTakashi Iwai } 3608f2e5731dSTakashi Iwai 3609f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */ 3610f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) 3611f2e5731dSTakashi Iwai { 3612f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3613f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 361499ae28beSTakashi Iwai snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT; 3615f2e5731dSTakashi Iwai } 3616f2e5731dSTakashi Iwai 3617f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */ 3618f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin) 3619f2e5731dSTakashi Iwai { 3620f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3621f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3622f68b3b29STakashi Iwai snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL && 3623f68b3b29STakashi Iwai (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT); 3624f2e5731dSTakashi Iwai } 3625f2e5731dSTakashi Iwai 3626f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 3627f2e5731dSTakashi Iwai * auto-mic is enabled only when one int-mic and one-ext mic exist 3628f2e5731dSTakashi Iwai */ 3629f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3630f2e5731dSTakashi Iwai { 3631f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3632f2e5731dSTakashi Iwai 3633f6100bb4STakashi Iwai if (is_ext_mic(codec, spec->imux_pins[0]) && 3634f6100bb4STakashi Iwai is_int_mic(codec, spec->imux_pins[1])) { 3635f2e5731dSTakashi Iwai spec->auto_mic = 1; 36362557f742STakashi Iwai spec->auto_mic_ext = 0; 3637f2e5731dSTakashi Iwai return; 3638f2e5731dSTakashi Iwai } 3639f6100bb4STakashi Iwai if (is_int_mic(codec, spec->imux_pins[0]) && 3640f6100bb4STakashi Iwai is_ext_mic(codec, spec->imux_pins[1])) { 3641f2e5731dSTakashi Iwai spec->auto_mic = 1; 36422557f742STakashi Iwai spec->auto_mic_ext = 1; 3643f2e5731dSTakashi Iwai return; 3644f2e5731dSTakashi Iwai } 3645f2e5731dSTakashi Iwai } 3646f2e5731dSTakashi Iwai 3647f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3648f2e5731dSTakashi Iwai { 3649f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3650f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3651f2e5731dSTakashi Iwai struct hda_input_mux *imux; 36526764bcefSTakashi Iwai int i, j; 3653f2e5731dSTakashi Iwai 3654f2e5731dSTakashi Iwai imux = &spec->private_imux; 3655f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 36566764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 36576764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 36585c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3659f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3660f2e5731dSTakashi Iwai if (idx >= 0) { 3661f2e5731dSTakashi Iwai const char *label; 3662f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3663cf27f29aSTakashi Iwai spec->imux_cfg_idx[imux->num_items] = i; 3664f9759301STakashi Iwai spec->imux_boost_nid[imux->num_items] = 0; 3665f6100bb4STakashi Iwai spec->imux_adcs[imux->num_items] = adc; 3666f6100bb4STakashi Iwai spec->imux_pins[imux->num_items] = 3667f6100bb4STakashi Iwai cfg->inputs[i].pin; 3668f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 36696764bcefSTakashi Iwai break; 36706764bcefSTakashi Iwai } 3671f2e5731dSTakashi Iwai } 3672f2e5731dSTakashi Iwai } 3673f2e5731dSTakashi Iwai if (imux->num_items == 2 && cfg->num_inputs == 2) 3674f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 36756764bcefSTakashi Iwai if (imux->num_items > 1 && !spec->auto_mic) { 36766764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 36776764bcefSTakashi Iwai if (spec->imux_adcs[i] != spec->imux_adcs[0]) { 36786764bcefSTakashi Iwai spec->adc_switching = 1; 36796764bcefSTakashi Iwai break; 36806764bcefSTakashi Iwai } 36816764bcefSTakashi Iwai } 36826764bcefSTakashi Iwai } 3683f2e5731dSTakashi Iwai } 3684f2e5731dSTakashi Iwai 3685f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3686f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3687f2e5731dSTakashi Iwai { 3688f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3689f2e5731dSTakashi Iwai 3690f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3691f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3692f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3693f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3694f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3695f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3696f2e5731dSTakashi Iwai return nid; 3697f2e5731dSTakashi Iwai } 3698f2e5731dSTakashi Iwai } 3699f2e5731dSTakashi Iwai return 0; 3700f2e5731dSTakashi Iwai } 3701f2e5731dSTakashi Iwai 3702f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3703f2e5731dSTakashi Iwai { 3704f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3705f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3706f2e5731dSTakashi Iwai hda_nid_t nid; 3707f2e5731dSTakashi Iwai 3708f2e5731dSTakashi Iwai if (cfg->dig_outs && 3709f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3710f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3711f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3712f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3713f2e5731dSTakashi Iwai } 3714f2e5731dSTakashi Iwai 3715f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3716f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3717f2e5731dSTakashi Iwai { 3718f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3719f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3720f2e5731dSTakashi Iwai 3721f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3722f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3723f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3724f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3725f2e5731dSTakashi Iwai break; 3726f2e5731dSTakashi Iwai } 3727f2e5731dSTakashi Iwai } 3728f2e5731dSTakashi Iwai #else 3729f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3730f2e5731dSTakashi Iwai #endif 3731f2e5731dSTakashi Iwai 3732f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3733f2e5731dSTakashi Iwai { 3734f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3735f2e5731dSTakashi Iwai int err; 3736f2e5731dSTakashi Iwai 3737f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3738f2e5731dSTakashi Iwai if (err < 0) 3739f2e5731dSTakashi Iwai return err; 3740f2e5731dSTakashi Iwai 3741f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3742f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3743f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3744f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 3745f2e5731dSTakashi Iwai return 0; 3746f2e5731dSTakashi Iwai } 3747f2e5731dSTakashi Iwai 3748da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3749da339866STakashi Iwai hda_nid_t *pins, bool on) 3750f2e5731dSTakashi Iwai { 3751f2e5731dSTakashi Iwai int i; 3752f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3753f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3754f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3755da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3756da339866STakashi Iwai on ? 0x02 : 0); 3757f2e5731dSTakashi Iwai } 3758f2e5731dSTakashi Iwai } 3759f2e5731dSTakashi Iwai 3760f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3761f2e5731dSTakashi Iwai hda_nid_t src) 3762f2e5731dSTakashi Iwai { 3763f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3764f2e5731dSTakashi Iwai if (idx >= 0) 3765f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3766f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3767f2e5731dSTakashi Iwai } 3768f2e5731dSTakashi Iwai 37691f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 37701f8458a2STakashi Iwai const hda_nid_t *nids) 3771f2e5731dSTakashi Iwai { 37720ad1b5b6STakashi Iwai int i, val; 3773f2e5731dSTakashi Iwai 37741f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 37751f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 37761f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 37771f8458a2STakashi Iwai continue; 37780ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 37790ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 37800ad1b5b6STakashi Iwai else 37810ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 37820ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 37830ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 37840ad1b5b6STakashi Iwai } 37851f8458a2STakashi Iwai } 3786f2e5731dSTakashi Iwai 37871f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 37881f8458a2STakashi Iwai { 37891f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 37901f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 37911f8458a2STakashi Iwai hda_nid_t nid; 37921f8458a2STakashi Iwai int i; 37931f8458a2STakashi Iwai 37941f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3795f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3796f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3797f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 37981f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 37991f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 38001f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3801f2e5731dSTakashi Iwai if (spec->auto_mute) { 3802f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3803f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3804f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3805f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_HP_EVENT); 3806f2e5731dSTakashi Iwai } 3807f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3808f2e5731dSTakashi Iwai } else { 3809f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) 3810f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3811f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3812f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) 3813f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3814f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3815da339866STakashi Iwai /* turn on EAPD */ 3816da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, 3817da339866STakashi Iwai true); 3818da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, 3819da339866STakashi Iwai true); 3820da339866STakashi Iwai cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, 3821da339866STakashi Iwai true); 3822f2e5731dSTakashi Iwai } 3823f2e5731dSTakashi Iwai 3824f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3825f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3826f2e5731dSTakashi Iwai if (!nid) 3827f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 3828f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3829f2e5731dSTakashi Iwai } 3830f2e5731dSTakashi Iwai } 3831f2e5731dSTakashi Iwai 3832f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3833f2e5731dSTakashi Iwai { 3834f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3835f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 38360ad1b5b6STakashi Iwai int i, val; 3837f2e5731dSTakashi Iwai 38380ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 38390ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 38401f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 38411f8458a2STakashi Iwai continue; 38420ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 38430ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 38440ad1b5b6STakashi Iwai else 38450ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 38460ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 38470ad1b5b6STakashi Iwai val); 38480ad1b5b6STakashi Iwai } 3849f2e5731dSTakashi Iwai 3850f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3851f2e5731dSTakashi Iwai unsigned int type; 3852f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 3853f2e5731dSTakashi Iwai type = PIN_VREF80; 3854f2e5731dSTakashi Iwai else 3855f2e5731dSTakashi Iwai type = PIN_IN; 3856f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 3857f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 3858f2e5731dSTakashi Iwai } 3859f2e5731dSTakashi Iwai 3860f2e5731dSTakashi Iwai if (spec->auto_mic) { 3861f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3862f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0, 3863f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3864f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 3865f2e5731dSTakashi Iwai cx_auto_automic(codec); 3866f2e5731dSTakashi Iwai } else { 38675c9887e0STakashi Iwai select_input_connection(codec, spec->imux_adcs[0], 38685c9887e0STakashi Iwai spec->imux_pins[0]); 3869f2e5731dSTakashi Iwai } 3870f2e5731dSTakashi Iwai } 3871f2e5731dSTakashi Iwai 3872f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 3873f2e5731dSTakashi Iwai { 3874f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3875f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3876f2e5731dSTakashi Iwai 3877f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 3878f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 3879f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3880f2e5731dSTakashi Iwai if (spec->dig_in_nid) 3881f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 3882f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 3883f2e5731dSTakashi Iwai } 3884f2e5731dSTakashi Iwai 3885f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 3886f2e5731dSTakashi Iwai { 3887f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 3888f2e5731dSTakashi Iwai cx_auto_init_output(codec); 3889f2e5731dSTakashi Iwai cx_auto_init_input(codec); 3890f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 3891f2e5731dSTakashi Iwai return 0; 3892f2e5731dSTakashi Iwai } 3893f2e5731dSTakashi Iwai 3894983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 3895f2e5731dSTakashi Iwai const char *dir, int cidx, 3896983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 3897f2e5731dSTakashi Iwai { 3898f2e5731dSTakashi Iwai static char name[32]; 3899f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 3900f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 3901f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 3902f2e5731dSTakashi Iwai }; 390334cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 3904f2e5731dSTakashi Iwai int i, err; 3905f2e5731dSTakashi Iwai 3906f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 3907f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 3908983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 3909983345e5SDavid Henningsson hda_dir); 3910f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 3911f2e5731dSTakashi Iwai knew[i].index = cidx; 3912f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 3913f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 3914f2e5731dSTakashi Iwai if (!kctl) 3915f2e5731dSTakashi Iwai return -ENOMEM; 3916f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 3917f2e5731dSTakashi Iwai if (err < 0) 3918f2e5731dSTakashi Iwai return err; 3919f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 3920f2e5731dSTakashi Iwai break; 3921f2e5731dSTakashi Iwai } 3922f2e5731dSTakashi Iwai return 0; 3923f2e5731dSTakashi Iwai } 3924f2e5731dSTakashi Iwai 3925983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 3926983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 3927983345e5SDavid Henningsson 3928f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 3929f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 3930f2e5731dSTakashi Iwai 39311f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 39321f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 39331f8458a2STakashi Iwai { 39341f8458a2STakashi Iwai unsigned int caps; 39351f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 39361f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 39371f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 39381f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 39391f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 39401f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 39411f8458a2STakashi Iwai return 0; 39421f8458a2STakashi Iwai } 39431f8458a2STakashi Iwai 3944f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 3945f2e5731dSTakashi Iwai { 3946f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3947f2e5731dSTakashi Iwai int i, err; 3948f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 3949ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 3950f2e5731dSTakashi Iwai 3951f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 39521f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 39531f8458a2STakashi Iwai spec->dac_info[0].pin, 3954f2e5731dSTakashi Iwai "Master", 0); 39551f8458a2STakashi Iwai 3956f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3957f2e5731dSTakashi Iwai const char *label; 3958f2e5731dSTakashi Iwai int idx, type; 3959f2e5731dSTakashi Iwai if (!spec->dac_info[i].dac) 3960f2e5731dSTakashi Iwai continue; 3961f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 3962f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 3963f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 3964f2e5731dSTakashi Iwai switch (type) { 3965f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3966f2e5731dSTakashi Iwai default: 3967f2e5731dSTakashi Iwai label = texts[num_line++]; 3968f2e5731dSTakashi Iwai idx = 0; 3969f2e5731dSTakashi Iwai break; 3970f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3971f2e5731dSTakashi Iwai label = "Headphone"; 3972f2e5731dSTakashi Iwai idx = num_hp++; 3973f2e5731dSTakashi Iwai break; 3974f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3975f2e5731dSTakashi Iwai label = "Speaker"; 3976f2e5731dSTakashi Iwai idx = num_spk++; 3977f2e5731dSTakashi Iwai break; 3978f2e5731dSTakashi Iwai } 39791f8458a2STakashi Iwai err = try_add_pb_volume(codec, spec->dac_info[i].dac, 39801f8458a2STakashi Iwai spec->dac_info[i].pin, 3981f2e5731dSTakashi Iwai label, idx); 3982f2e5731dSTakashi Iwai if (err < 0) 3983f2e5731dSTakashi Iwai return err; 3984f2e5731dSTakashi Iwai } 3985f2e5731dSTakashi Iwai return 0; 3986f2e5731dSTakashi Iwai } 3987f2e5731dSTakashi Iwai 39886764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 39896764bcefSTakashi Iwai const char *label, const char *pfx, 39906764bcefSTakashi Iwai int cidx) 39916764bcefSTakashi Iwai { 39926764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 39936764bcefSTakashi Iwai int i; 39946764bcefSTakashi Iwai 39956764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 39966764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 39975c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 39986764bcefSTakashi Iwai if (idx < 0) 39996764bcefSTakashi Iwai continue; 40006764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 40016764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 40026764bcefSTakashi Iwai } 40036764bcefSTakashi Iwai return 0; 40046764bcefSTakashi Iwai } 40056764bcefSTakashi Iwai 4006cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4007cf27f29aSTakashi Iwai const char *label, int cidx) 4008cf27f29aSTakashi Iwai { 4009cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4010cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4011f9759301STakashi Iwai int i, con; 4012cf27f29aSTakashi Iwai 4013cf27f29aSTakashi Iwai nid = spec->imux_pins[idx]; 4014cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4015cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4016cf27f29aSTakashi Iwai nid, HDA_INPUT); 4017cf27f29aSTakashi Iwai con = __select_input_connection(codec, spec->imux_adcs[idx], nid, &mux, 4018cf27f29aSTakashi Iwai false, 0); 4019cf27f29aSTakashi Iwai if (con < 0) 4020cf27f29aSTakashi Iwai return 0; 4021f9759301STakashi Iwai for (i = 0; i < idx; i++) { 4022f9759301STakashi Iwai if (spec->imux_boost_nid[i] == mux) 4023f9759301STakashi Iwai return 0; /* already present */ 4024f9759301STakashi Iwai } 4025f9759301STakashi Iwai 4026f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 4027f9759301STakashi Iwai spec->imux_boost_nid[idx] = mux; 4028cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4029cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4030f9759301STakashi Iwai } 4031cf27f29aSTakashi Iwai return 0; 4032cf27f29aSTakashi Iwai } 4033cf27f29aSTakashi Iwai 4034f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4035f2e5731dSTakashi Iwai { 4036f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4037cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4038cf27f29aSTakashi Iwai const char *prev_label; 4039cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 40406764bcefSTakashi Iwai int i, err, cidx; 4041cf27f29aSTakashi Iwai int multi_connection; 4042cf27f29aSTakashi Iwai 4043cf27f29aSTakashi Iwai multi_connection = 0; 4044cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 4045cf27f29aSTakashi Iwai cidx = get_input_connection(codec, spec->imux_adcs[i], 4046cf27f29aSTakashi Iwai spec->imux_pins[i]); 4047cf27f29aSTakashi Iwai input_conn[i] = (spec->imux_adcs[i] << 8) | cidx; 4048cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4049cf27f29aSTakashi Iwai multi_connection = 1; 4050cf27f29aSTakashi Iwai } 4051983345e5SDavid Henningsson 4052f2e5731dSTakashi Iwai prev_label = NULL; 4053f2e5731dSTakashi Iwai cidx = 0; 4054cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 4055cf27f29aSTakashi Iwai hda_nid_t nid = spec->imux_pins[i]; 4056f2e5731dSTakashi Iwai const char *label; 4057983345e5SDavid Henningsson 4058cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 4059cf27f29aSTakashi Iwai spec->imux_cfg_idx[i]); 4060f2e5731dSTakashi Iwai if (label == prev_label) 4061f2e5731dSTakashi Iwai cidx++; 4062f2e5731dSTakashi Iwai else 4063f2e5731dSTakashi Iwai cidx = 0; 4064f2e5731dSTakashi Iwai prev_label = label; 4065983345e5SDavid Henningsson 4066cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4067f2e5731dSTakashi Iwai if (err < 0) 4068f2e5731dSTakashi Iwai return err; 4069983345e5SDavid Henningsson 4070cf27f29aSTakashi Iwai if (!multi_connection) { 4071f9759301STakashi Iwai if (i > 0) 4072f9759301STakashi Iwai continue; 40736764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 40746764bcefSTakashi Iwai "Capture", "", cidx); 40756764bcefSTakashi Iwai } else { 40766764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 40776764bcefSTakashi Iwai label, " Capture", cidx); 40786764bcefSTakashi Iwai } 4079983345e5SDavid Henningsson if (err < 0) 4080983345e5SDavid Henningsson return err; 4081983345e5SDavid Henningsson } 40826764bcefSTakashi Iwai 40836764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 40846764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 40856764bcefSTakashi Iwai if (err < 0) 40866764bcefSTakashi Iwai return err; 4087983345e5SDavid Henningsson } 40886764bcefSTakashi Iwai 4089f2e5731dSTakashi Iwai return 0; 4090f2e5731dSTakashi Iwai } 4091f2e5731dSTakashi Iwai 4092f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4093f2e5731dSTakashi Iwai { 4094f2e5731dSTakashi Iwai int err; 4095f2e5731dSTakashi Iwai 4096f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4097f2e5731dSTakashi Iwai if (err < 0) 4098f2e5731dSTakashi Iwai return err; 4099f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4100f2e5731dSTakashi Iwai if (err < 0) 4101f2e5731dSTakashi Iwai return err; 4102f2e5731dSTakashi Iwai return conexant_build_controls(codec); 4103f2e5731dSTakashi Iwai } 4104f2e5731dSTakashi Iwai 410522ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 410622ce5f74STakashi Iwai { 410722ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 410822ce5f74STakashi Iwai hda_nid_t nid, end_nid; 410922ce5f74STakashi Iwai 411022ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 411122ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 411222ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 411322ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 411422ce5f74STakashi Iwai continue; 411522ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 411622ce5f74STakashi Iwai continue; 411722ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 411822ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 411922ce5f74STakashi Iwai break; 412022ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 412122ce5f74STakashi Iwai } 412222ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 412322ce5f74STakashi Iwai return 0; 412422ce5f74STakashi Iwai } 412522ce5f74STakashi Iwai 412622ce5f74STakashi Iwai 412734cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4128f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4129f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4130f2e5731dSTakashi Iwai .init = cx_auto_init, 4131f2e5731dSTakashi Iwai .free = conexant_free, 4132f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4133f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4134f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4135f2e5731dSTakashi Iwai #endif 4136f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4137f2e5731dSTakashi Iwai }; 4138f2e5731dSTakashi Iwai 4139f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4140f2e5731dSTakashi Iwai { 4141f2e5731dSTakashi Iwai struct conexant_spec *spec; 4142f2e5731dSTakashi Iwai int err; 4143f2e5731dSTakashi Iwai 41441f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 41451f8458a2STakashi Iwai codec->chip_name); 41461f8458a2STakashi Iwai 4147f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4148f2e5731dSTakashi Iwai if (!spec) 4149f2e5731dSTakashi Iwai return -ENOMEM; 4150f2e5731dSTakashi Iwai codec->spec = spec; 41511387cde5STakashi Iwai codec->pin_amp_workaround = 1; 415222ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 415322ce5f74STakashi Iwai if (err < 0) 415422ce5f74STakashi Iwai return err; 4155f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4156f2e5731dSTakashi Iwai if (err < 0) { 4157f2e5731dSTakashi Iwai kfree(codec->spec); 4158f2e5731dSTakashi Iwai codec->spec = NULL; 4159f2e5731dSTakashi Iwai return err; 4160f2e5731dSTakashi Iwai } 41616764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4162f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4163f2e5731dSTakashi Iwai if (spec->beep_amp) 4164f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 4165f2e5731dSTakashi Iwai return 0; 4166f2e5731dSTakashi Iwai } 4167f2e5731dSTakashi Iwai 4168f2e5731dSTakashi Iwai /* 4169461e2c78STakashi Iwai */ 4170461e2c78STakashi Iwai 417134cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 417282f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 417382f30040STobin Davis .patch = patch_cxt5045 }, 417482f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 417582f30040STobin Davis .patch = patch_cxt5047 }, 4176461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4177461e2c78STakashi Iwai .patch = patch_cxt5051 }, 41780fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 41790fb67e98SDaniel Drake .patch = patch_cxt5066 }, 418095a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 418195a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4182850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4183850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 41847b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 41857b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 41866da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 41876da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4188f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4189f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4190f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4191f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4192f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4193f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4194f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4195f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4196f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4197f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4198f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4199f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4200f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4201f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4202f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4203f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4204c9b443d4STobin Davis {} /* terminator */ 4205c9b443d4STobin Davis }; 42061289e9e8STakashi Iwai 42071289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 42081289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 42091289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 42100fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 421195a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4212850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 42137b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 42146da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4215f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4216f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4217f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4218f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4219f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4220f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4221f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4222f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 42231289e9e8STakashi Iwai 42241289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 42251289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 42261289e9e8STakashi Iwai 42271289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 42281289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 42291289e9e8STakashi Iwai .owner = THIS_MODULE, 42301289e9e8STakashi Iwai }; 42311289e9e8STakashi Iwai 42321289e9e8STakashi Iwai static int __init patch_conexant_init(void) 42331289e9e8STakashi Iwai { 42341289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 42351289e9e8STakashi Iwai } 42361289e9e8STakashi Iwai 42371289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 42381289e9e8STakashi Iwai { 42391289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 42401289e9e8STakashi Iwai } 42411289e9e8STakashi Iwai 42421289e9e8STakashi Iwai module_init(patch_conexant_init) 42431289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4244