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 52bc7a166dSUlrich Dangel struct conexant_jack { 53bc7a166dSUlrich Dangel 54bc7a166dSUlrich Dangel hda_nid_t nid; 55bc7a166dSUlrich Dangel int type; 56bc7a166dSUlrich Dangel struct snd_jack *jack; 57bc7a166dSUlrich Dangel 58bc7a166dSUlrich Dangel }; 59c9b443d4STobin Davis 60f2e5731dSTakashi Iwai struct pin_dac_pair { 61f2e5731dSTakashi Iwai hda_nid_t pin; 62f2e5731dSTakashi Iwai hda_nid_t dac; 63f2e5731dSTakashi Iwai int type; 64f2e5731dSTakashi Iwai }; 65f2e5731dSTakashi Iwai 66c9b443d4STobin Davis struct conexant_spec { 67c9b443d4STobin Davis 68c9b443d4STobin Davis struct snd_kcontrol_new *mixers[5]; 69c9b443d4STobin Davis int num_mixers; 70dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 71c9b443d4STobin Davis 72c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 73c9b443d4STobin Davis * don't forget NULL 74c9b443d4STobin Davis * termination! 75c9b443d4STobin Davis */ 76c9b443d4STobin Davis unsigned int num_init_verbs; 77c9b443d4STobin Davis 78c9b443d4STobin Davis /* playback */ 79c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 80c9b443d4STobin Davis * max_channels, dacs must be set 81c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 82c9b443d4STobin Davis */ 83c9b443d4STobin Davis unsigned int cur_eapd; 8482f30040STobin Davis unsigned int hp_present; 85faddaa5dSTakashi Iwai unsigned int auto_mic; 86f2e5731dSTakashi Iwai int auto_mic_ext; /* autocfg.inputs[] index for ext mic */ 87c9b443d4STobin Davis unsigned int need_dac_fix; 88f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 89c9b443d4STobin Davis 90c9b443d4STobin Davis /* capture */ 91c9b443d4STobin Davis unsigned int num_adc_nids; 92c9b443d4STobin Davis hda_nid_t *adc_nids; 93c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 94c9b443d4STobin Davis 95461e2c78STakashi Iwai unsigned int cur_adc_idx; 96461e2c78STakashi Iwai hda_nid_t cur_adc; 97461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 98461e2c78STakashi Iwai unsigned int cur_adc_format; 99461e2c78STakashi Iwai 100c9b443d4STobin Davis /* capture source */ 101c9b443d4STobin Davis const struct hda_input_mux *input_mux; 102c9b443d4STobin Davis hda_nid_t *capsrc_nids; 103c9b443d4STobin Davis unsigned int cur_mux[3]; 104c9b443d4STobin Davis 105c9b443d4STobin Davis /* channel model */ 106c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 107c9b443d4STobin Davis int num_channel_mode; 108c9b443d4STobin Davis 109c9b443d4STobin Davis /* PCM information */ 110c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 111c9b443d4STobin Davis 112c9b443d4STobin Davis unsigned int spdif_route; 113c9b443d4STobin Davis 114bc7a166dSUlrich Dangel /* jack detection */ 115bc7a166dSUlrich Dangel struct snd_array jacks; 116bc7a166dSUlrich Dangel 117c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 118c9b443d4STobin Davis struct auto_pin_cfg autocfg; 119c9b443d4STobin Davis struct hda_input_mux private_imux; 12041923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 121f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 122f2e5731dSTakashi Iwai int dac_info_filled; 123c9b443d4STobin Davis 1240fb67e98SDaniel Drake unsigned int port_d_mode; 125f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 126f2e5731dSTakashi Iwai unsigned int dell_automute:1; 127cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 128cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1297b2bfdbcSJens Taprogge unsigned int thinkpad:1; 130048e78a5SDavid Henningsson unsigned int hp_laptop:1; 131a1d6906eSDavid Henningsson unsigned int asus:1; 13275f8991dSDaniel Drake 13375f8991dSDaniel Drake unsigned int ext_mic_present; 13475f8991dSDaniel Drake unsigned int recording; 13575f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 13675f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 137c4cfe66cSDaniel Drake 138c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 139c4cfe66cSDaniel Drake * through the microphone jack. 140c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 141c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 142c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 143c4cfe66cSDaniel Drake * control. */ 144c4cfe66cSDaniel Drake unsigned int dc_enable; 145c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 146c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1473507e2a8STakashi Iwai 1483507e2a8STakashi Iwai unsigned int beep_amp; 149c9b443d4STobin Davis }; 150c9b443d4STobin Davis 151c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 152c9b443d4STobin Davis struct hda_codec *codec, 153c9b443d4STobin Davis struct snd_pcm_substream *substream) 154c9b443d4STobin Davis { 155c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1569a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1579a08160bSTakashi Iwai hinfo); 158c9b443d4STobin Davis } 159c9b443d4STobin Davis 160c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 161c9b443d4STobin Davis struct hda_codec *codec, 162c9b443d4STobin Davis unsigned int stream_tag, 163c9b443d4STobin Davis unsigned int format, 164c9b443d4STobin Davis struct snd_pcm_substream *substream) 165c9b443d4STobin Davis { 166c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 167c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 168c9b443d4STobin Davis stream_tag, 169c9b443d4STobin Davis format, substream); 170c9b443d4STobin Davis } 171c9b443d4STobin Davis 172c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 173c9b443d4STobin Davis struct hda_codec *codec, 174c9b443d4STobin Davis struct snd_pcm_substream *substream) 175c9b443d4STobin Davis { 176c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 177c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 178c9b443d4STobin Davis } 179c9b443d4STobin Davis 180c9b443d4STobin Davis /* 181c9b443d4STobin Davis * Digital out 182c9b443d4STobin Davis */ 183c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 184c9b443d4STobin Davis struct hda_codec *codec, 185c9b443d4STobin Davis struct snd_pcm_substream *substream) 186c9b443d4STobin Davis { 187c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 188c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 189c9b443d4STobin Davis } 190c9b443d4STobin Davis 191c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 192c9b443d4STobin Davis struct hda_codec *codec, 193c9b443d4STobin Davis struct snd_pcm_substream *substream) 194c9b443d4STobin Davis { 195c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 196c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 197c9b443d4STobin Davis } 198c9b443d4STobin Davis 1996b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2006b97eb45STakashi Iwai struct hda_codec *codec, 2016b97eb45STakashi Iwai unsigned int stream_tag, 2026b97eb45STakashi Iwai unsigned int format, 2036b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2046b97eb45STakashi Iwai { 2056b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2066b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2076b97eb45STakashi Iwai stream_tag, 2086b97eb45STakashi Iwai format, substream); 2096b97eb45STakashi Iwai } 2106b97eb45STakashi Iwai 211c9b443d4STobin Davis /* 212c9b443d4STobin Davis * Analog capture 213c9b443d4STobin Davis */ 214c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 215c9b443d4STobin Davis struct hda_codec *codec, 216c9b443d4STobin Davis unsigned int stream_tag, 217c9b443d4STobin Davis unsigned int format, 218c9b443d4STobin Davis struct snd_pcm_substream *substream) 219c9b443d4STobin Davis { 220c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 22175f8991dSDaniel Drake if (spec->capture_prepare) 22275f8991dSDaniel Drake spec->capture_prepare(codec); 223c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 224c9b443d4STobin Davis stream_tag, 0, format); 225c9b443d4STobin Davis return 0; 226c9b443d4STobin Davis } 227c9b443d4STobin Davis 228c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 229c9b443d4STobin Davis struct hda_codec *codec, 230c9b443d4STobin Davis struct snd_pcm_substream *substream) 231c9b443d4STobin Davis { 232c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 233888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 23475f8991dSDaniel Drake if (spec->capture_cleanup) 23575f8991dSDaniel Drake spec->capture_cleanup(codec); 236c9b443d4STobin Davis return 0; 237c9b443d4STobin Davis } 238c9b443d4STobin Davis 239c9b443d4STobin Davis 240c9b443d4STobin Davis 241c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 242c9b443d4STobin Davis .substreams = 1, 243c9b443d4STobin Davis .channels_min = 2, 244c9b443d4STobin Davis .channels_max = 2, 245c9b443d4STobin Davis .nid = 0, /* fill later */ 246c9b443d4STobin Davis .ops = { 247c9b443d4STobin Davis .open = conexant_playback_pcm_open, 248c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 249c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 250c9b443d4STobin Davis }, 251c9b443d4STobin Davis }; 252c9b443d4STobin Davis 253c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 254c9b443d4STobin Davis .substreams = 1, 255c9b443d4STobin Davis .channels_min = 2, 256c9b443d4STobin Davis .channels_max = 2, 257c9b443d4STobin Davis .nid = 0, /* fill later */ 258c9b443d4STobin Davis .ops = { 259c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 260c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 261c9b443d4STobin Davis }, 262c9b443d4STobin Davis }; 263c9b443d4STobin Davis 264c9b443d4STobin Davis 265c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 266c9b443d4STobin Davis .substreams = 1, 267c9b443d4STobin Davis .channels_min = 2, 268c9b443d4STobin Davis .channels_max = 2, 269c9b443d4STobin Davis .nid = 0, /* fill later */ 270c9b443d4STobin Davis .ops = { 271c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2726b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2736b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 274c9b443d4STobin Davis }, 275c9b443d4STobin Davis }; 276c9b443d4STobin Davis 277c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 278c9b443d4STobin Davis .substreams = 1, 279c9b443d4STobin Davis .channels_min = 2, 280c9b443d4STobin Davis .channels_max = 2, 281c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 282c9b443d4STobin Davis }; 283c9b443d4STobin Davis 284461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 285461e2c78STakashi Iwai struct hda_codec *codec, 286461e2c78STakashi Iwai unsigned int stream_tag, 287461e2c78STakashi Iwai unsigned int format, 288461e2c78STakashi Iwai struct snd_pcm_substream *substream) 289461e2c78STakashi Iwai { 290461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 291461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 292461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 293461e2c78STakashi Iwai spec->cur_adc_format = format; 294461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 295461e2c78STakashi Iwai return 0; 296461e2c78STakashi Iwai } 297461e2c78STakashi Iwai 298461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 299461e2c78STakashi Iwai struct hda_codec *codec, 300461e2c78STakashi Iwai struct snd_pcm_substream *substream) 301461e2c78STakashi Iwai { 302461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 303888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 304461e2c78STakashi Iwai spec->cur_adc = 0; 305461e2c78STakashi Iwai return 0; 306461e2c78STakashi Iwai } 307461e2c78STakashi Iwai 308461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 309461e2c78STakashi Iwai .substreams = 1, 310461e2c78STakashi Iwai .channels_min = 2, 311461e2c78STakashi Iwai .channels_max = 2, 312461e2c78STakashi Iwai .nid = 0, /* fill later */ 313461e2c78STakashi Iwai .ops = { 314461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 315461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 316461e2c78STakashi Iwai }, 317461e2c78STakashi Iwai }; 318461e2c78STakashi Iwai 319c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 320c9b443d4STobin Davis { 321c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 322c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 323c9b443d4STobin Davis 324c9b443d4STobin Davis codec->num_pcms = 1; 325c9b443d4STobin Davis codec->pcm_info = info; 326c9b443d4STobin Davis 327c9b443d4STobin Davis info->name = "CONEXANT Analog"; 328c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 329c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 330c9b443d4STobin Davis spec->multiout.max_channels; 331c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 332c9b443d4STobin Davis spec->multiout.dac_nids[0]; 333461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 334461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 335461e2c78STakashi Iwai cx5051_pcm_analog_capture; 336461e2c78STakashi Iwai else 337461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 338461e2c78STakashi Iwai conexant_pcm_analog_capture; 339c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 340c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 341c9b443d4STobin Davis 342c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 343c9b443d4STobin Davis info++; 344c9b443d4STobin Davis codec->num_pcms++; 345c9b443d4STobin Davis info->name = "Conexant Digital"; 3467ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 347c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 348c9b443d4STobin Davis conexant_pcm_digital_playback; 349c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 350c9b443d4STobin Davis spec->multiout.dig_out_nid; 351c9b443d4STobin Davis if (spec->dig_in_nid) { 352c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 353c9b443d4STobin Davis conexant_pcm_digital_capture; 354c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 355c9b443d4STobin Davis spec->dig_in_nid; 356c9b443d4STobin Davis } 357f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 358f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 359c9b443d4STobin Davis } 360c9b443d4STobin Davis 361c9b443d4STobin Davis return 0; 362c9b443d4STobin Davis } 363c9b443d4STobin Davis 364c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 365c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 366c9b443d4STobin Davis { 367c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 368c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 369c9b443d4STobin Davis 370c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 371c9b443d4STobin Davis } 372c9b443d4STobin Davis 373c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 374c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 375c9b443d4STobin Davis { 376c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 377c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 378c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 379c9b443d4STobin Davis 380c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 381c9b443d4STobin Davis return 0; 382c9b443d4STobin Davis } 383c9b443d4STobin Davis 384c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 385c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 386c9b443d4STobin Davis { 387c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 388c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 389c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 390c9b443d4STobin Davis 391c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 392c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 393c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 394c9b443d4STobin Davis } 395c9b443d4STobin Davis 3968c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 39795c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack) 39895c09099STakashi Iwai { 39995c09099STakashi Iwai struct conexant_jack *jacks = jack->private_data; 40095c09099STakashi Iwai jacks->nid = 0; 40195c09099STakashi Iwai jacks->jack = NULL; 40295c09099STakashi Iwai } 40395c09099STakashi Iwai 404bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 405bc7a166dSUlrich Dangel hda_nid_t nid, int type) 406bc7a166dSUlrich Dangel { 407bc7a166dSUlrich Dangel struct conexant_spec *spec; 408bc7a166dSUlrich Dangel struct conexant_jack *jack; 409bc7a166dSUlrich Dangel const char *name; 41095c09099STakashi Iwai int err; 411bc7a166dSUlrich Dangel 412bc7a166dSUlrich Dangel spec = codec->spec; 413bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 414bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 415bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 416bc7a166dSUlrich Dangel 417bc7a166dSUlrich Dangel if (!jack) 418bc7a166dSUlrich Dangel return -ENOMEM; 419bc7a166dSUlrich Dangel 420bc7a166dSUlrich Dangel jack->nid = nid; 421bc7a166dSUlrich Dangel jack->type = type; 422bc7a166dSUlrich Dangel 42395c09099STakashi Iwai err = snd_jack_new(codec->bus->card, name, type, &jack->jack); 42495c09099STakashi Iwai if (err < 0) 42595c09099STakashi Iwai return err; 42695c09099STakashi Iwai jack->jack->private_data = jack; 42795c09099STakashi Iwai jack->jack->private_free = conexant_free_jack_priv; 42895c09099STakashi Iwai return 0; 429bc7a166dSUlrich Dangel } 430bc7a166dSUlrich Dangel 431bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 432bc7a166dSUlrich Dangel { 433bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 434bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 435bc7a166dSUlrich Dangel 436bc7a166dSUlrich Dangel if (jacks) { 437bc7a166dSUlrich Dangel int i; 438bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 439bc7a166dSUlrich Dangel if (jacks->nid == nid) { 440bc7a166dSUlrich Dangel unsigned int present; 441d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, nid); 442bc7a166dSUlrich Dangel 443bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 444bc7a166dSUlrich Dangel 445bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 446bc7a166dSUlrich Dangel present); 447bc7a166dSUlrich Dangel } 448bc7a166dSUlrich Dangel jacks++; 449bc7a166dSUlrich Dangel } 450bc7a166dSUlrich Dangel } 451bc7a166dSUlrich Dangel } 452bc7a166dSUlrich Dangel 453bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 454bc7a166dSUlrich Dangel { 455bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 456bc7a166dSUlrich Dangel int i; 457bc7a166dSUlrich Dangel 458bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 459bc7a166dSUlrich Dangel const struct hda_verb *hv; 460bc7a166dSUlrich Dangel 461bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 462bc7a166dSUlrich Dangel while (hv->nid) { 463bc7a166dSUlrich Dangel int err = 0; 464bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 465bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 466bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 467bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 468bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 469bc7a166dSUlrich Dangel break; 470bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 471bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 472bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 473bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 474bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 475bc7a166dSUlrich Dangel break; 476bc7a166dSUlrich Dangel } 477bc7a166dSUlrich Dangel if (err < 0) 478bc7a166dSUlrich Dangel return err; 479bc7a166dSUlrich Dangel ++hv; 480bc7a166dSUlrich Dangel } 481bc7a166dSUlrich Dangel } 482bc7a166dSUlrich Dangel return 0; 483bc7a166dSUlrich Dangel 484bc7a166dSUlrich Dangel } 4855801f992STakashi Iwai #else 4865801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4875801f992STakashi Iwai { 4885801f992STakashi Iwai } 4895801f992STakashi Iwai 4905801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4915801f992STakashi Iwai { 4925801f992STakashi Iwai return 0; 4935801f992STakashi Iwai } 4945801f992STakashi Iwai #endif 495bc7a166dSUlrich Dangel 496c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 497c9b443d4STobin Davis { 498c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 499c9b443d4STobin Davis int i; 500c9b443d4STobin Davis 501c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 502c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 503c9b443d4STobin Davis return 0; 504c9b443d4STobin Davis } 505c9b443d4STobin Davis 506c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 507c9b443d4STobin Davis { 5088c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 509bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 510bc7a166dSUlrich Dangel if (spec->jacks.list) { 511bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 512bc7a166dSUlrich Dangel int i; 51395c09099STakashi Iwai for (i = 0; i < spec->jacks.used; i++, jacks++) { 51495c09099STakashi Iwai if (jacks->jack) 51595c09099STakashi Iwai snd_device_free(codec->bus->card, jacks->jack); 51695c09099STakashi Iwai } 517bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 518bc7a166dSUlrich Dangel } 519bc7a166dSUlrich Dangel #endif 520c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 521c9b443d4STobin Davis kfree(codec->spec); 522c9b443d4STobin Davis } 523c9b443d4STobin Davis 524b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = { 525b880c74aSTakashi Iwai { 526b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 527b880c74aSTakashi Iwai .name = "Capture Source", 528b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 529b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 530b880c74aSTakashi Iwai .put = conexant_mux_enum_put 531b880c74aSTakashi Iwai }, 532b880c74aSTakashi Iwai {} 533b880c74aSTakashi Iwai }; 534b880c74aSTakashi Iwai 5353507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5363507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 5373507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = { 5383507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 5393507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 5403507e2a8STakashi Iwai { } /* end */ 5413507e2a8STakashi Iwai }; 5423507e2a8STakashi Iwai #endif 5433507e2a8STakashi Iwai 544ea734963STakashi Iwai static const char * const slave_vols[] = { 545dd5746a8STakashi Iwai "Headphone Playback Volume", 546dd5746a8STakashi Iwai "Speaker Playback Volume", 547dd5746a8STakashi Iwai NULL 548dd5746a8STakashi Iwai }; 549dd5746a8STakashi Iwai 550ea734963STakashi Iwai static const char * const slave_sws[] = { 551dd5746a8STakashi Iwai "Headphone Playback Switch", 552dd5746a8STakashi Iwai "Speaker Playback Switch", 553dd5746a8STakashi Iwai NULL 554dd5746a8STakashi Iwai }; 555dd5746a8STakashi Iwai 556c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 557c9b443d4STobin Davis { 558c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 559c9b443d4STobin Davis unsigned int i; 560c9b443d4STobin Davis int err; 561c9b443d4STobin Davis 562c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 563c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 564c9b443d4STobin Davis if (err < 0) 565c9b443d4STobin Davis return err; 566c9b443d4STobin Davis } 567c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 568c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 569c9b443d4STobin Davis spec->multiout.dig_out_nid); 570c9b443d4STobin Davis if (err < 0) 571c9b443d4STobin Davis return err; 5729a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5739a08160bSTakashi Iwai &spec->multiout); 5749a08160bSTakashi Iwai if (err < 0) 5759a08160bSTakashi Iwai return err; 5769a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 577c9b443d4STobin Davis } 578c9b443d4STobin Davis if (spec->dig_in_nid) { 579c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 580c9b443d4STobin Davis if (err < 0) 581c9b443d4STobin Davis return err; 582c9b443d4STobin Davis } 583dd5746a8STakashi Iwai 584dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 585dd5746a8STakashi Iwai if (spec->vmaster_nid && 586dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 587dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 588dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 589dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 590dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 591dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 592dd5746a8STakashi Iwai if (err < 0) 593dd5746a8STakashi Iwai return err; 594dd5746a8STakashi Iwai } 595dd5746a8STakashi Iwai if (spec->vmaster_nid && 596dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 597dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 598dd5746a8STakashi Iwai NULL, slave_sws); 599dd5746a8STakashi Iwai if (err < 0) 600dd5746a8STakashi Iwai return err; 601dd5746a8STakashi Iwai } 602dd5746a8STakashi Iwai 603b880c74aSTakashi Iwai if (spec->input_mux) { 604b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 605b880c74aSTakashi Iwai if (err < 0) 606b880c74aSTakashi Iwai return err; 607b880c74aSTakashi Iwai } 608b880c74aSTakashi Iwai 6093507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6103507e2a8STakashi Iwai /* create beep controls if needed */ 6113507e2a8STakashi Iwai if (spec->beep_amp) { 6123507e2a8STakashi Iwai struct snd_kcontrol_new *knew; 6133507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 6143507e2a8STakashi Iwai struct snd_kcontrol *kctl; 6153507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 6163507e2a8STakashi Iwai if (!kctl) 6173507e2a8STakashi Iwai return -ENOMEM; 6183507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 6193507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 6203507e2a8STakashi Iwai if (err < 0) 6213507e2a8STakashi Iwai return err; 6223507e2a8STakashi Iwai } 6233507e2a8STakashi Iwai } 6243507e2a8STakashi Iwai #endif 6253507e2a8STakashi Iwai 626c9b443d4STobin Davis return 0; 627c9b443d4STobin Davis } 628c9b443d4STobin Davis 629697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 630697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 631697c373eSTakashi Iwai { 632697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 633697c373eSTakashi Iwai return 0; 634697c373eSTakashi Iwai } 635697c373eSTakashi Iwai #endif 636697c373eSTakashi Iwai 637c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 638c9b443d4STobin Davis .build_controls = conexant_build_controls, 639c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 640c9b443d4STobin Davis .init = conexant_init, 641c9b443d4STobin Davis .free = conexant_free, 642697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 643697c373eSTakashi Iwai .suspend = conexant_suspend, 644697c373eSTakashi Iwai #endif 645697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 646c9b443d4STobin Davis }; 647c9b443d4STobin Davis 6483507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6493507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 6503507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 6513507e2a8STakashi Iwai #else 6523507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 6533507e2a8STakashi Iwai #endif 6543507e2a8STakashi Iwai 655c9b443d4STobin Davis /* 656c9b443d4STobin Davis * EAPD control 657c9b443d4STobin Davis * the private value = nid | (invert << 8) 658c9b443d4STobin Davis */ 659c9b443d4STobin Davis 660a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 661c9b443d4STobin Davis 66282f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 663c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 664c9b443d4STobin Davis { 665c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 666c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 667c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 668c9b443d4STobin Davis if (invert) 669c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 670c9b443d4STobin Davis else 671c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 672c9b443d4STobin Davis return 0; 67382f30040STobin Davis 674c9b443d4STobin Davis } 675c9b443d4STobin Davis 67682f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 677c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 678c9b443d4STobin Davis { 679c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 680c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 681c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 682c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 683c9b443d4STobin Davis unsigned int eapd; 68482f30040STobin Davis 68568ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 686c9b443d4STobin Davis if (invert) 687c9b443d4STobin Davis eapd = !eapd; 68882beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 689c9b443d4STobin Davis return 0; 69082f30040STobin Davis 691c9b443d4STobin Davis spec->cur_eapd = eapd; 69282beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 693c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 694c9b443d4STobin Davis eapd ? 0x02 : 0x00); 695c9b443d4STobin Davis return 1; 696c9b443d4STobin Davis } 697c9b443d4STobin Davis 69886d72bdfSTakashi Iwai /* controls for test mode */ 69986d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 70086d72bdfSTakashi Iwai 70182f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 70282f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 70382f30040STobin Davis .info = cxt_eapd_info, \ 70482f30040STobin Davis .get = cxt_eapd_get, \ 70582f30040STobin Davis .put = cxt_eapd_put, \ 70682f30040STobin Davis .private_value = nid | (mask<<16) } 70782f30040STobin Davis 70882f30040STobin Davis 70982f30040STobin Davis 710c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 711c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 712c9b443d4STobin Davis { 713c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 714c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 715c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 716c9b443d4STobin Davis spec->num_channel_mode); 717c9b443d4STobin Davis } 718c9b443d4STobin Davis 719c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 720c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 721c9b443d4STobin Davis { 722c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 723c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 724c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 725c9b443d4STobin Davis spec->num_channel_mode, 726c9b443d4STobin Davis spec->multiout.max_channels); 727c9b443d4STobin Davis } 728c9b443d4STobin Davis 729c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 730c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 731c9b443d4STobin Davis { 732c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 733c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 734c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 735c9b443d4STobin Davis spec->num_channel_mode, 736c9b443d4STobin Davis &spec->multiout.max_channels); 737c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 738c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 739c9b443d4STobin Davis return err; 740c9b443d4STobin Davis } 741c9b443d4STobin Davis 742c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 743c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 744c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 745c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 746c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 747c9b443d4STobin Davis .private_value = nid | (dir<<16) } 748c9b443d4STobin Davis 74986d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 75086d72bdfSTakashi Iwai 751c9b443d4STobin Davis /* Conexant 5045 specific */ 752c9b443d4STobin Davis 753c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 754c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 755c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 756cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 757c9b443d4STobin Davis 7585cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 7595cd57529STobin Davis { 2, NULL }, 7605cd57529STobin Davis }; 761c9b443d4STobin Davis 762c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 763c9b443d4STobin Davis .num_items = 2, 764c9b443d4STobin Davis .items = { 76582f30040STobin Davis { "IntMic", 0x1 }, 766f4beee94SJiang zhe { "ExtMic", 0x2 }, 767c9b443d4STobin Davis } 768c9b443d4STobin Davis }; 769c9b443d4STobin Davis 7705218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 77122e14130SLukasz Marcinowski .num_items = 5, 7725218c892SJiang Zhe .items = { 7735218c892SJiang Zhe { "IntMic", 0x1 }, 7745218c892SJiang Zhe { "ExtMic", 0x2 }, 7755218c892SJiang Zhe { "LineIn", 0x3 }, 77622e14130SLukasz Marcinowski { "CD", 0x4 }, 77722e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7785218c892SJiang Zhe } 7795218c892SJiang Zhe }; 7805218c892SJiang Zhe 7812de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 7822de3c232SJiang zhe .num_items = 2, 7832de3c232SJiang zhe .items = { 7842de3c232SJiang zhe { "ExtMic", 0x1 }, 7852de3c232SJiang zhe { "IntMic", 0x2 }, 7862de3c232SJiang zhe } 7872de3c232SJiang zhe }; 7882de3c232SJiang zhe 789c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 790c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 791c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 792c9b443d4STobin Davis { 793c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 794c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 79582f30040STobin Davis unsigned int bits; 796c9b443d4STobin Davis 79782f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 798c9b443d4STobin Davis return 0; 799c9b443d4STobin Davis 80082f30040STobin Davis /* toggle internal speakers mute depending of presence of 80182f30040STobin Davis * the headphone jack 80282f30040STobin Davis */ 80347fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 80447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 80547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 8067f29673bSTobin Davis 80747fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 80847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 80947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 810c9b443d4STobin Davis return 1; 811c9b443d4STobin Davis } 812c9b443d4STobin Davis 813c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 814cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 815cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 816cca3b371STakashi Iwai .values = { 817cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 818cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 819cca3b371STakashi Iwai 0 820cca3b371STakashi Iwai }, 821cca3b371STakashi Iwai }; 822c9b443d4STobin Davis 8237f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 8247f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 8257f29673bSTobin Davis { 8267f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 8277f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8287f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8297f29673bSTobin Davis {} 8307f29673bSTobin Davis }; 8317f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 8327f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8337f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8347f29673bSTobin Davis {} 8357f29673bSTobin Davis }; 8367f29673bSTobin Davis unsigned int present; 8377f29673bSTobin Davis 838d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 8397f29673bSTobin Davis if (present) 8407f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 8417f29673bSTobin Davis else 8427f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 8437f29673bSTobin Davis } 8447f29673bSTobin Davis 845c9b443d4STobin Davis 846c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 847c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 848c9b443d4STobin Davis { 84982f30040STobin Davis struct conexant_spec *spec = codec->spec; 850dd87da1cSTobin Davis unsigned int bits; 851c9b443d4STobin Davis 852d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 853dd87da1cSTobin Davis 85447fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 85547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 85647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 857c9b443d4STobin Davis } 858c9b443d4STobin Davis 859c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 860c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 861c9b443d4STobin Davis unsigned int res) 862c9b443d4STobin Davis { 863c9b443d4STobin Davis res >>= 26; 864c9b443d4STobin Davis switch (res) { 865c9b443d4STobin Davis case CONEXANT_HP_EVENT: 866c9b443d4STobin Davis cxt5045_hp_automute(codec); 867c9b443d4STobin Davis break; 8687f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8697f29673bSTobin Davis cxt5045_hp_automic(codec); 8707f29673bSTobin Davis break; 8717f29673bSTobin Davis 872c9b443d4STobin Davis } 873c9b443d4STobin Davis } 874c9b443d4STobin Davis 875c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 87628c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 87728c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8788607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8798607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 880c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 881c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 88228c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 88328c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8848607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8858607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 886cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 887c9b443d4STobin Davis { 888c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 889c9b443d4STobin Davis .name = "Master Playback Switch", 89082f30040STobin Davis .info = cxt_eapd_info, 89182f30040STobin Davis .get = cxt_eapd_get, 892c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 89382f30040STobin Davis .private_value = 0x10, 894c9b443d4STobin Davis }, 895c9b443d4STobin Davis 896c9b443d4STobin Davis {} 897c9b443d4STobin Davis }; 898c9b443d4STobin Davis 8995218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 90022e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 90122e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 90222e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 90322e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 90422e14130SLukasz Marcinowski 9055218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 9065218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 9075218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 9085218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 9095218c892SJiang Zhe 91022e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 91122e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 91222e14130SLukasz Marcinowski 9135218c892SJiang Zhe {} 9145218c892SJiang Zhe }; 9155218c892SJiang Zhe 9162de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 91728c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 91828c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 9198607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 9208607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 9212de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 9222de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 92328c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 92428c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 9258607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 9268607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 9272de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 9282de3c232SJiang zhe { 9292de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9302de3c232SJiang zhe .name = "Master Playback Switch", 9312de3c232SJiang zhe .info = cxt_eapd_info, 9322de3c232SJiang zhe .get = cxt_eapd_get, 9332de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 9342de3c232SJiang zhe .private_value = 0x10, 9352de3c232SJiang zhe }, 9362de3c232SJiang zhe 9372de3c232SJiang zhe {} 9382de3c232SJiang zhe }; 9392de3c232SJiang zhe 940c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 941c9b443d4STobin Davis /* Line in, Mic */ 9424090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9437f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 944c9b443d4STobin Davis /* HP, Amp */ 945c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 946c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 94782f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 948c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 949c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 950c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 951c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 952c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 953c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 95428c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9557f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 95682f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 957c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 958c9b443d4STobin Davis /* SPDIF route: PCM */ 959cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 960c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 961c9b443d4STobin Davis /* EAPD */ 96282f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 963c9b443d4STobin Davis { } /* end */ 964c9b443d4STobin Davis }; 965c9b443d4STobin Davis 9665218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 96728c4edb7SDavid Henningsson /* Internal Mic, Mic */ 9685218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9695218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9705218c892SJiang Zhe /* Line In,HP, Amp */ 9715218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9725218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9735218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9745218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9755218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9765218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9775218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9785218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9795218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 98028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9815218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9825218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9835218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9845218c892SJiang Zhe /* SPDIF route: PCM */ 985cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9865218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9875218c892SJiang Zhe /* EAPD */ 9885218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9895218c892SJiang Zhe { } /* end */ 9905218c892SJiang Zhe }; 9917f29673bSTobin Davis 9927f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9937f29673bSTobin Davis /* pin sensing on HP jack */ 9947f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 995d3091fadSTakashi Iwai { } /* end */ 9967f29673bSTobin Davis }; 9977f29673bSTobin Davis 9987f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9997f29673bSTobin Davis /* pin sensing on HP jack */ 10007f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1001d3091fadSTakashi Iwai { } /* end */ 10027f29673bSTobin Davis }; 10037f29673bSTobin Davis 1004c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1005c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1006c9b443d4STobin Davis * configuration. 1007c9b443d4STobin Davis */ 1008c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 1009c9b443d4STobin Davis .num_items = 5, 1010c9b443d4STobin Davis .items = { 1011c9b443d4STobin Davis { "MIXER", 0x0 }, 1012c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 1013c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 1014c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 1015c9b443d4STobin Davis { "CD pin", 0x4 }, 1016c9b443d4STobin Davis }, 1017c9b443d4STobin Davis }; 1018c9b443d4STobin Davis 1019c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 1020c9b443d4STobin Davis 1021c9b443d4STobin Davis /* Output controls */ 1022c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 1023c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 10247f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 10257f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 10267f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 10277f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1028c9b443d4STobin Davis 1029c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1030c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 1031c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 1032c9b443d4STobin Davis 103382f30040STobin Davis /* EAPD Switch Control */ 103482f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 103582f30040STobin Davis 1036c9b443d4STobin Davis /* Loopback mixer controls */ 1037c9b443d4STobin Davis 10387f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 10397f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 10407f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 10417f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 10427f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 10437f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 10447f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 10457f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 10467f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 10477f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 1048c9b443d4STobin Davis { 1049c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1050c9b443d4STobin Davis .name = "Input Source", 1051c9b443d4STobin Davis .info = conexant_mux_enum_info, 1052c9b443d4STobin Davis .get = conexant_mux_enum_get, 1053c9b443d4STobin Davis .put = conexant_mux_enum_put, 1054c9b443d4STobin Davis }, 1055fb3409e7STobin Davis /* Audio input controls */ 1056fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1057fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 1058fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 1059fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 1060fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 1061fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 1062fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1063fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1064fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1065fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1066c9b443d4STobin Davis { } /* end */ 1067c9b443d4STobin Davis }; 1068c9b443d4STobin Davis 1069c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 10707f29673bSTobin Davis /* Set connections */ 10717f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10727f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10737f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1074c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1075c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10767f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1077c9b443d4STobin Davis 1078c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1079c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1080c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1081c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1082c9b443d4STobin Davis * control. 1083c9b443d4STobin Davis */ 1084cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1085cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1086c9b443d4STobin Davis 1087c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1088c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1089c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1090c9b443d4STobin Davis 1091c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1092c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1093c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1094c9b443d4STobin Davis * input/output buffers as needed. 1095c9b443d4STobin Davis */ 1096c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1097c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1098c9b443d4STobin Davis 1099c9b443d4STobin Davis /* Mute capture amp left and right */ 1100c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1101c9b443d4STobin Davis 1102c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1103c9b443d4STobin Davis * pin) 1104c9b443d4STobin Davis */ 1105c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 11067f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1107c9b443d4STobin Davis 1108c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1109c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1110c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1111c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1112c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1113c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1114c9b443d4STobin Davis 1115c9b443d4STobin Davis { } 1116c9b443d4STobin Davis }; 1117c9b443d4STobin Davis #endif 1118c9b443d4STobin Davis 1119c9b443d4STobin Davis 1120c9b443d4STobin Davis /* initialize jack-sensing, too */ 1121c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1122c9b443d4STobin Davis { 1123c9b443d4STobin Davis conexant_init(codec); 1124c9b443d4STobin Davis cxt5045_hp_automute(codec); 1125c9b443d4STobin Davis return 0; 1126c9b443d4STobin Davis } 1127c9b443d4STobin Davis 1128c9b443d4STobin Davis 1129c9b443d4STobin Davis enum { 113015908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 113115908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 113215908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 11335218c892SJiang Zhe CXT5045_BENQ, 11342de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1135c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1136c9b443d4STobin Davis CXT5045_TEST, 1137c9b443d4STobin Davis #endif 1138f5fcc13cSTakashi Iwai CXT5045_MODELS 1139c9b443d4STobin Davis }; 1140c9b443d4STobin Davis 1141ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 114215908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 114315908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 114415908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 11455218c892SJiang Zhe [CXT5045_BENQ] = "benq", 11462de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1147c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1148f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1149c9b443d4STobin Davis #endif 1150f5fcc13cSTakashi Iwai }; 1151c9b443d4STobin Davis 1152f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 11532de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1154dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1155dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 11566a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 11575218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 115815908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 115915908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 11609e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 11619e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 116215908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 116315908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 116415908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1165dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1166dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 116715908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1168c9b443d4STobin Davis {} 1169c9b443d4STobin Davis }; 1170c9b443d4STobin Davis 1171c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1172c9b443d4STobin Davis { 1173c9b443d4STobin Davis struct conexant_spec *spec; 1174c9b443d4STobin Davis int board_config; 1175c9b443d4STobin Davis 1176c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1177c9b443d4STobin Davis if (!spec) 1178c9b443d4STobin Davis return -ENOMEM; 1179c9b443d4STobin Davis codec->spec = spec; 11809421f954STakashi Iwai codec->pin_amp_workaround = 1; 1181c9b443d4STobin Davis 1182c9b443d4STobin Davis spec->multiout.max_channels = 2; 1183c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1184c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1185c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1186c9b443d4STobin Davis spec->num_adc_nids = 1; 1187c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1188c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1189c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1190c9b443d4STobin Davis spec->num_mixers = 1; 1191c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1192c9b443d4STobin Davis spec->num_init_verbs = 1; 1193c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1194c9b443d4STobin Davis spec->spdif_route = 0; 11953507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11963507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11975cd57529STobin Davis 11983507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1199c9b443d4STobin Davis 1200c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1201c9b443d4STobin Davis 1202f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1203f5fcc13cSTakashi Iwai cxt5045_models, 1204f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1205c9b443d4STobin Davis switch (board_config) { 120615908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 12077f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1208c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1209c9b443d4STobin Davis spec->num_init_verbs = 2; 12107f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12117f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 12127f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 12137f29673bSTobin Davis break; 121415908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 121586376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12167f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 12177f29673bSTobin Davis spec->num_init_verbs = 2; 12187f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1219c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1220c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1221c9b443d4STobin Davis break; 122215908c36SMarc Boucher default: 122315908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 122415908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 122515908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 122615908c36SMarc Boucher spec->num_init_verbs = 3; 122715908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 122815908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 122915908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 123015908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 123115908c36SMarc Boucher break; 12325218c892SJiang Zhe case CXT5045_BENQ: 12335218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12345218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 12355218c892SJiang Zhe spec->num_init_verbs = 1; 12365218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 12375218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 12385218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 12395218c892SJiang Zhe spec->num_mixers = 2; 12405218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 12415218c892SJiang Zhe break; 12422de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 12432de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12442de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 12452de3c232SJiang zhe spec->num_init_verbs = 2; 12462de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12472de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 12482de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 12492de3c232SJiang zhe break; 1250c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1251c9b443d4STobin Davis case CXT5045_TEST: 1252c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1253c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1254c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 125515908c36SMarc Boucher break; 125615908c36SMarc Boucher 1257c9b443d4STobin Davis #endif 1258c9b443d4STobin Davis } 125948ecb7e8STakashi Iwai 1260031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1261031005f7STakashi Iwai case 0x103c: 12628f0f5ff6SDaniel T Chen case 0x1631: 12630b587fc4SDaniel T Chen case 0x1734: 12640ebf9e36SDaniel T Chen case 0x17aa: 12650ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12660ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12670ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 126848ecb7e8STakashi Iwai */ 126948ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 127048ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 127148ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 127248ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 127348ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1274031005f7STakashi Iwai break; 1275031005f7STakashi Iwai } 127648ecb7e8STakashi Iwai 12773507e2a8STakashi Iwai if (spec->beep_amp) 12783507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12793507e2a8STakashi Iwai 1280c9b443d4STobin Davis return 0; 1281c9b443d4STobin Davis } 1282c9b443d4STobin Davis 1283c9b443d4STobin Davis 1284c9b443d4STobin Davis /* Conexant 5047 specific */ 128582f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1286c9b443d4STobin Davis 12875b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1288c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1289c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1290c9b443d4STobin Davis 12915cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 12925cd57529STobin Davis { 2, NULL }, 12935cd57529STobin Davis }; 1294c9b443d4STobin Davis 129582f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 129682f30040STobin Davis .num_items = 2, 129782f30040STobin Davis .items = { 129882f30040STobin Davis { "ExtMic", 0x2 }, 129982f30040STobin Davis { "Line-In", 0x1 }, 1300c9b443d4STobin Davis } 1301c9b443d4STobin Davis }; 1302c9b443d4STobin Davis 1303c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1304c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1305c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1306c9b443d4STobin Davis { 1307c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1308c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 130982f30040STobin Davis unsigned int bits; 1310c9b443d4STobin Davis 131182f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1312c9b443d4STobin Davis return 0; 1313c9b443d4STobin Davis 131482f30040STobin Davis /* toggle internal speakers mute depending of presence of 131582f30040STobin Davis * the headphone jack 131682f30040STobin Davis */ 131747fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 13183b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 13193b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 13203b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 13213b7523fcSTakashi Iwai */ 13225d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 132347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 132447fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 132547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 132647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1327c9b443d4STobin Davis return 1; 1328c9b443d4STobin Davis } 1329c9b443d4STobin Davis 1330c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1331c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1332c9b443d4STobin Davis { 133382f30040STobin Davis struct conexant_spec *spec = codec->spec; 1334dd87da1cSTobin Davis unsigned int bits; 1335c9b443d4STobin Davis 1336d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1337dd87da1cSTobin Davis 133847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 13393b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13405d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 134147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1342c9b443d4STobin Davis } 1343c9b443d4STobin Davis 1344c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1345c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1346c9b443d4STobin Davis { 1347c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 13489f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13499f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1350c9b443d4STobin Davis {} 1351c9b443d4STobin Davis }; 1352c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 13539f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13549f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1355c9b443d4STobin Davis {} 1356c9b443d4STobin Davis }; 1357c9b443d4STobin Davis unsigned int present; 1358c9b443d4STobin Davis 1359d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1360c9b443d4STobin Davis if (present) 1361c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1362c9b443d4STobin Davis else 1363c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1364c9b443d4STobin Davis } 1365c9b443d4STobin Davis 1366c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1367c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1368c9b443d4STobin Davis unsigned int res) 1369c9b443d4STobin Davis { 13709f113e0eSMarc Boucher switch (res >> 26) { 1371c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1372c9b443d4STobin Davis cxt5047_hp_automute(codec); 1373c9b443d4STobin Davis break; 1374c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1375c9b443d4STobin Davis cxt5047_hp_automic(codec); 1376c9b443d4STobin Davis break; 1377c9b443d4STobin Davis } 1378c9b443d4STobin Davis } 1379c9b443d4STobin Davis 1380df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1381df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1382df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13835f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1384c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1385c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1386c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1387c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 138882f30040STobin Davis { 138982f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 139082f30040STobin Davis .name = "Master Playback Switch", 139182f30040STobin Davis .info = cxt_eapd_info, 139282f30040STobin Davis .get = cxt_eapd_get, 1393c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1394c9b443d4STobin Davis .private_value = 0x13, 1395c9b443d4STobin Davis }, 1396c9b443d4STobin Davis 1397c9b443d4STobin Davis {} 1398c9b443d4STobin Davis }; 1399c9b443d4STobin Davis 1400df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 14013b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 14025d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1403df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1404df481e41STakashi Iwai {} 1405df481e41STakashi Iwai }; 1406df481e41STakashi Iwai 1407df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1408c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1409c9b443d4STobin Davis { } /* end */ 1410c9b443d4STobin Davis }; 1411c9b443d4STobin Davis 1412c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1413c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1414c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1415c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1416c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 14177f29673bSTobin Davis /* HP, Speaker */ 1418b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 14195b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 14205b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 14217f29673bSTobin Davis /* Record selector: Mic */ 14227f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 14237f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 14247f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 14257f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1426c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1427c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1428c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1429c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1430c9b443d4STobin Davis /* SPDIF route: PCM */ 1431c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 143282f30040STobin Davis /* Enable unsolicited events */ 143382f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 143482f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1435c9b443d4STobin Davis { } /* end */ 1436c9b443d4STobin Davis }; 1437c9b443d4STobin Davis 1438c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1439c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 14403b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1441c9b443d4STobin Davis {} 1442c9b443d4STobin Davis }; 1443c9b443d4STobin Davis 1444c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1445c9b443d4STobin Davis * configuration. 1446c9b443d4STobin Davis */ 1447c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1448c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 144982f30040STobin Davis .num_items = 4, 1450c9b443d4STobin Davis .items = { 145182f30040STobin Davis { "LINE1 pin", 0x0 }, 145282f30040STobin Davis { "MIC1 pin", 0x1 }, 145382f30040STobin Davis { "MIC2 pin", 0x2 }, 145482f30040STobin Davis { "CD pin", 0x3 }, 1455c9b443d4STobin Davis }, 1456c9b443d4STobin Davis }; 1457c9b443d4STobin Davis 1458c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1459c9b443d4STobin Davis 1460c9b443d4STobin Davis /* Output only controls */ 146182f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 146282f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 146382f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 146482f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1465c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1466c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1467c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1468c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 146982f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 147082f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 147182f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 147282f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1473c9b443d4STobin Davis 1474c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1475c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1476c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1477c9b443d4STobin Davis 147882f30040STobin Davis /* EAPD Switch Control */ 147982f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 148082f30040STobin Davis 1481c9b443d4STobin Davis /* Loopback mixer controls */ 148282f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 148382f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 148482f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 148582f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 148682f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 148782f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 148882f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 148982f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1490c9b443d4STobin Davis 149182f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 149282f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 149382f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 149482f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 149582f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 149682f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 149782f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 149882f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1499c9b443d4STobin Davis { 1500c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1501c9b443d4STobin Davis .name = "Input Source", 1502c9b443d4STobin Davis .info = conexant_mux_enum_info, 1503c9b443d4STobin Davis .get = conexant_mux_enum_get, 1504c9b443d4STobin Davis .put = conexant_mux_enum_put, 1505c9b443d4STobin Davis }, 1506854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 15079f113e0eSMarc Boucher 1508c9b443d4STobin Davis { } /* end */ 1509c9b443d4STobin Davis }; 1510c9b443d4STobin Davis 1511c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1512c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1513c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1514c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1515c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1516c9b443d4STobin Davis 1517c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1518c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1519c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1520c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1521c9b443d4STobin Davis * control. 1522c9b443d4STobin Davis */ 1523c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1524c9b443d4STobin Davis 1525c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1526c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1527c9b443d4STobin Davis */ 1528c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1529c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1530c9b443d4STobin Davis 1531c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1532c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1533c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1534c9b443d4STobin Davis 1535c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1536c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1537c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1538c9b443d4STobin Davis * input/output buffers as needed. 1539c9b443d4STobin Davis */ 1540c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1541c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1542c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1543c9b443d4STobin Davis 1544c9b443d4STobin Davis /* Mute capture amp left and right */ 1545c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1546c9b443d4STobin Davis 1547c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1548c9b443d4STobin Davis * pin) 1549c9b443d4STobin Davis */ 1550c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1551c9b443d4STobin Davis 1552c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1553c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1554c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1555c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1556c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1557c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1558c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1559c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1560c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1561c9b443d4STobin Davis 1562c9b443d4STobin Davis { } 1563c9b443d4STobin Davis }; 1564c9b443d4STobin Davis #endif 1565c9b443d4STobin Davis 1566c9b443d4STobin Davis 1567c9b443d4STobin Davis /* initialize jack-sensing, too */ 1568c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1569c9b443d4STobin Davis { 1570c9b443d4STobin Davis conexant_init(codec); 1571c9b443d4STobin Davis cxt5047_hp_automute(codec); 1572c9b443d4STobin Davis return 0; 1573c9b443d4STobin Davis } 1574c9b443d4STobin Davis 1575c9b443d4STobin Davis 1576c9b443d4STobin Davis enum { 1577f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1578f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1579f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1580c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1581c9b443d4STobin Davis CXT5047_TEST, 1582c9b443d4STobin Davis #endif 1583f5fcc13cSTakashi Iwai CXT5047_MODELS 1584c9b443d4STobin Davis }; 1585c9b443d4STobin Davis 1586ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1587f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1588f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1589f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1590c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1591f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1592c9b443d4STobin Davis #endif 1593f5fcc13cSTakashi Iwai }; 1594c9b443d4STobin Davis 1595f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1596ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1597dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1598dea0a509STakashi Iwai CXT5047_LAPTOP), 1599f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1600c9b443d4STobin Davis {} 1601c9b443d4STobin Davis }; 1602c9b443d4STobin Davis 1603c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1604c9b443d4STobin Davis { 1605c9b443d4STobin Davis struct conexant_spec *spec; 1606c9b443d4STobin Davis int board_config; 1607c9b443d4STobin Davis 1608c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1609c9b443d4STobin Davis if (!spec) 1610c9b443d4STobin Davis return -ENOMEM; 1611c9b443d4STobin Davis codec->spec = spec; 16129421f954STakashi Iwai codec->pin_amp_workaround = 1; 1613c9b443d4STobin Davis 1614c9b443d4STobin Davis spec->multiout.max_channels = 2; 1615c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1616c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1617c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1618c9b443d4STobin Davis spec->num_adc_nids = 1; 1619c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1620c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1621c9b443d4STobin Davis spec->num_mixers = 1; 1622df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1623c9b443d4STobin Davis spec->num_init_verbs = 1; 1624c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1625c9b443d4STobin Davis spec->spdif_route = 0; 16265cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16275cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1628c9b443d4STobin Davis 1629c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1630c9b443d4STobin Davis 1631f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1632f5fcc13cSTakashi Iwai cxt5047_models, 1633f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1634c9b443d4STobin Davis switch (board_config) { 1635c9b443d4STobin Davis case CXT5047_LAPTOP: 1636df481e41STakashi Iwai spec->num_mixers = 2; 1637df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1638df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1639c9b443d4STobin Davis break; 1640c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1641df481e41STakashi Iwai spec->num_mixers = 2; 1642df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1643fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1644c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1645c9b443d4STobin Davis break; 1646c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 164782f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1648df481e41STakashi Iwai spec->num_mixers = 2; 1649df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1650c9b443d4STobin Davis spec->num_init_verbs = 2; 1651c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1652fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1653c9b443d4STobin Davis break; 1654c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1655c9b443d4STobin Davis case CXT5047_TEST: 1656c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1657c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1658c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1659fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1660c9b443d4STobin Davis #endif 1661c9b443d4STobin Davis } 1662dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1663025f206cSDaniel T Chen 1664025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1665025f206cSDaniel T Chen case 0x103c: 1666025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1667025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1668025f206cSDaniel T Chen * with 0 dB offset 0x17) 1669025f206cSDaniel T Chen */ 1670025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1671025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1672025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1673025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1674025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1675025f206cSDaniel T Chen break; 1676025f206cSDaniel T Chen } 1677025f206cSDaniel T Chen 1678c9b443d4STobin Davis return 0; 1679c9b443d4STobin Davis } 1680c9b443d4STobin Davis 1681461e2c78STakashi Iwai /* Conexant 5051 specific */ 1682461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1683461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1684461e2c78STakashi Iwai 1685461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1686461e2c78STakashi Iwai { 2, NULL }, 1687461e2c78STakashi Iwai }; 1688461e2c78STakashi Iwai 1689461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1690461e2c78STakashi Iwai { 1691461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1692461e2c78STakashi Iwai unsigned int pinctl; 169323d2df5bSTakashi Iwai /* headphone pin */ 169423d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 169523d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 169623d2df5bSTakashi Iwai pinctl); 169723d2df5bSTakashi Iwai /* speaker pin */ 1698461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1699461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1700461e2c78STakashi Iwai pinctl); 1701f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1702f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1703f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1704f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1705f7154de2SHerton Ronaldo Krzesinski pinctl); 1706461e2c78STakashi Iwai } 1707461e2c78STakashi Iwai 1708461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1709461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1710461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1711461e2c78STakashi Iwai { 1712461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1713461e2c78STakashi Iwai 1714461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1715461e2c78STakashi Iwai return 0; 1716461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1717461e2c78STakashi Iwai return 1; 1718461e2c78STakashi Iwai } 1719461e2c78STakashi Iwai 1720461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1721461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1722461e2c78STakashi Iwai { 172379d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1724461e2c78STakashi Iwai unsigned int present; 1725461e2c78STakashi Iwai 1726faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 172779d7d533STakashi Iwai return; 1728d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1729461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1730461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1731461e2c78STakashi Iwai present ? 0x01 : 0x00); 1732461e2c78STakashi Iwai } 1733461e2c78STakashi Iwai 1734461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1735461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1736461e2c78STakashi Iwai { 1737461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1738461e2c78STakashi Iwai unsigned int present; 1739461e2c78STakashi Iwai hda_nid_t new_adc; 1740461e2c78STakashi Iwai 1741faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 174279d7d533STakashi Iwai return; 1743d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1744461e2c78STakashi Iwai if (present) 1745461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1746461e2c78STakashi Iwai else 1747461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1748461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1749461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1750461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1751f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1752461e2c78STakashi Iwai spec->cur_adc = new_adc; 1753461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1754461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1755461e2c78STakashi Iwai spec->cur_adc_format); 1756461e2c78STakashi Iwai } 1757461e2c78STakashi Iwai } 1758461e2c78STakashi Iwai 1759461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1760461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1761461e2c78STakashi Iwai { 1762461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1763461e2c78STakashi Iwai 1764d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1765461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1766461e2c78STakashi Iwai } 1767461e2c78STakashi Iwai 1768461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1769461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1770461e2c78STakashi Iwai unsigned int res) 1771461e2c78STakashi Iwai { 1772acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1773461e2c78STakashi Iwai switch (res >> 26) { 1774461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1775461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1776461e2c78STakashi Iwai break; 1777461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1778461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1779461e2c78STakashi Iwai break; 1780461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1781461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1782461e2c78STakashi Iwai break; 1783461e2c78STakashi Iwai } 1784acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1785461e2c78STakashi Iwai } 1786461e2c78STakashi Iwai 17872c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1788461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1789461e2c78STakashi Iwai { 1790461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1791461e2c78STakashi Iwai .name = "Master Playback Switch", 1792461e2c78STakashi Iwai .info = cxt_eapd_info, 1793461e2c78STakashi Iwai .get = cxt_eapd_get, 1794461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1795461e2c78STakashi Iwai .private_value = 0x1a, 1796461e2c78STakashi Iwai }, 17972c7a3fb3STakashi Iwai {} 17982c7a3fb3STakashi Iwai }; 1799461e2c78STakashi Iwai 18002c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = { 18012c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 18022c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 18038607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 18048607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 18052c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 18062c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1807461e2c78STakashi Iwai {} 1808461e2c78STakashi Iwai }; 1809461e2c78STakashi Iwai 1810461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1811461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1812461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 18138607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 18148607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1815461e2c78STakashi Iwai {} 1816461e2c78STakashi Iwai }; 1817461e2c78STakashi Iwai 181879d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 18194e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 18204e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 182179d7d533STakashi Iwai {} 182279d7d533STakashi Iwai }; 182379d7d533STakashi Iwai 1824cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = { 18255f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 18265f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1827cd9d95a5SKen Prox {} 1828cd9d95a5SKen Prox }; 1829cd9d95a5SKen Prox 1830faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1831faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1832faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 18338607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 18348607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1835faddaa5dSTakashi Iwai {} 1836faddaa5dSTakashi Iwai }; 1837faddaa5dSTakashi Iwai 1838461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1839461e2c78STakashi Iwai /* Line in, Mic */ 1840461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1841461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1842461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1843461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1844461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1845461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1846461e2c78STakashi Iwai /* SPK */ 1847461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1848461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1849461e2c78STakashi Iwai /* HP, Amp */ 1850461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1851461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1852461e2c78STakashi Iwai /* DAC1 */ 1853461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 185428c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1855461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1856461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1857461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1858461e2c78STakashi Iwai /* SPDIF route: PCM */ 18591965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1860461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1861461e2c78STakashi Iwai /* EAPD */ 1862461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1863461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1864461e2c78STakashi Iwai { } /* end */ 1865461e2c78STakashi Iwai }; 1866461e2c78STakashi Iwai 186779d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 186879d7d533STakashi Iwai /* Line in, Mic */ 186979d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187079d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 187179d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 187279d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 187379d7d533STakashi Iwai /* SPK */ 187479d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 187579d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 187679d7d533STakashi Iwai /* HP, Amp */ 187779d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 187879d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 187979d7d533STakashi Iwai /* DAC1 */ 188079d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 188128c4edb7SDavid Henningsson /* Record selector: Internal mic */ 188279d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 188379d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 188479d7d533STakashi Iwai /* SPDIF route: PCM */ 188579d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 188679d7d533STakashi Iwai /* EAPD */ 188779d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 188879d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 188979d7d533STakashi Iwai { } /* end */ 189079d7d533STakashi Iwai }; 189179d7d533STakashi Iwai 189227e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 189327e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 189427e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 189527e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 189627e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 189727e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 189827e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 189927e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 190027e08988SAristeu Sergio Rozanski Filho /* SPK */ 190127e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 190227e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 190327e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 190427e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 190527e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 190627e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 190727e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 190827e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 190927e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 191027e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 191128c4edb7SDavid Henningsson /* Record selector: Internal mic */ 191227e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 191327e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 191427e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 191527e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 19161965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ 191727e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 191827e08988SAristeu Sergio Rozanski Filho /* EAPD */ 191927e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 192027e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 192127e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 192227e08988SAristeu Sergio Rozanski Filho { } /* end */ 192327e08988SAristeu Sergio Rozanski Filho }; 192427e08988SAristeu Sergio Rozanski Filho 1925cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = { 1926cd9d95a5SKen Prox /* Line in, Mic */ 192730ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1928cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1929cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1930cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1931cd9d95a5SKen Prox /* SPK */ 1932cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1933cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1934cd9d95a5SKen Prox /* HP, Amp */ 1935cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1936cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1937cd9d95a5SKen Prox /* DAC1 */ 1938cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 193928c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1940cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1941cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1942cd9d95a5SKen Prox /* SPDIF route: PCM */ 1943cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1944cd9d95a5SKen Prox /* EAPD */ 1945cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1946cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1947cd9d95a5SKen Prox { } /* end */ 1948cd9d95a5SKen Prox }; 1949cd9d95a5SKen Prox 19506953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 19516953e552STakashi Iwai unsigned int event) 19526953e552STakashi Iwai { 19536953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19546953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19556953e552STakashi Iwai AC_USRSP_EN | event); 19566953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 19576953e552STakashi Iwai conexant_add_jack(codec, nid, SND_JACK_MICROPHONE); 19586953e552STakashi Iwai conexant_report_jack(codec, nid); 19596953e552STakashi Iwai #endif 19606953e552STakashi Iwai } 19616953e552STakashi Iwai 1962f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = { 1963f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1964f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1965f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1966f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1967f7154de2SHerton Ronaldo Krzesinski }; 1968f7154de2SHerton Ronaldo Krzesinski 1969461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1970461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1971461e2c78STakashi Iwai { 19726953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19736953e552STakashi Iwai 1974461e2c78STakashi Iwai conexant_init(codec); 1975acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19766953e552STakashi Iwai 19776953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19786953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19796953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19806953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19816953e552STakashi Iwai 1982461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1983461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1984461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1985461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1986461e2c78STakashi Iwai } 1987461e2c78STakashi Iwai return 0; 1988461e2c78STakashi Iwai } 1989461e2c78STakashi Iwai 1990461e2c78STakashi Iwai 1991461e2c78STakashi Iwai enum { 1992461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1993461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 199479d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 19951965c441SPierre-Louis Bossart CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ 1996cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1997faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1998f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 1999461e2c78STakashi Iwai CXT5051_MODELS 2000461e2c78STakashi Iwai }; 2001461e2c78STakashi Iwai 2002ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 2003461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 2004461e2c78STakashi Iwai [CXT5051_HP] = "hp", 200579d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 200627e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 20075f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 2008faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 2009f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 2010461e2c78STakashi Iwai }; 2011461e2c78STakashi Iwai 2012461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 201379d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 20141812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 20155f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 2016faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 2017461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2018461e2c78STakashi Iwai CXT5051_LAPTOP), 2019461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 202027e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 2021f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 2022461e2c78STakashi Iwai {} 2023461e2c78STakashi Iwai }; 2024461e2c78STakashi Iwai 2025461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 2026461e2c78STakashi Iwai { 2027461e2c78STakashi Iwai struct conexant_spec *spec; 2028461e2c78STakashi Iwai int board_config; 2029461e2c78STakashi Iwai 2030461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2031461e2c78STakashi Iwai if (!spec) 2032461e2c78STakashi Iwai return -ENOMEM; 2033461e2c78STakashi Iwai codec->spec = spec; 20349421f954STakashi Iwai codec->pin_amp_workaround = 1; 2035461e2c78STakashi Iwai 2036461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 2037461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 2038461e2c78STakashi Iwai 2039461e2c78STakashi Iwai spec->multiout.max_channels = 2; 2040461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 2041461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 2042461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 2043461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 2044461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 20452c7a3fb3STakashi Iwai spec->num_mixers = 2; 20462c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20472c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2048461e2c78STakashi Iwai spec->num_init_verbs = 1; 2049461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2050461e2c78STakashi Iwai spec->spdif_route = 0; 2051461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2052461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2053461e2c78STakashi Iwai spec->cur_adc = 0; 2054461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2055461e2c78STakashi Iwai 20563507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20573507e2a8STakashi Iwai 205879d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 205979d7d533STakashi Iwai 2060461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 2061461e2c78STakashi Iwai cxt5051_models, 2062461e2c78STakashi Iwai cxt5051_cfg_tbl); 2063faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2064461e2c78STakashi Iwai switch (board_config) { 2065461e2c78STakashi Iwai case CXT5051_HP: 2066461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2067461e2c78STakashi Iwai break; 206879d7d533STakashi Iwai case CXT5051_HP_DV6736: 206979d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 207079d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2071faddaa5dSTakashi Iwai spec->auto_mic = 0; 207279d7d533STakashi Iwai break; 207327e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 207427e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 2075607bc3e4SJerone Young /* Thinkpad X301 does not have S/PDIF wired and no ability 2076607bc3e4SJerone Young to use a docking station. */ 2077607bc3e4SJerone Young if (codec->subsystem_id == 0x17aa211f) 2078607bc3e4SJerone Young spec->multiout.dig_out_nid = 0; 2079461e2c78STakashi Iwai break; 2080cd9d95a5SKen Prox case CXT5051_F700: 2081cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2082cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2083faddaa5dSTakashi Iwai spec->auto_mic = 0; 2084faddaa5dSTakashi Iwai break; 2085faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2086faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2087faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2088cd9d95a5SKen Prox break; 2089f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2090f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2091f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2092f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2093f7154de2SHerton Ronaldo Krzesinski break; 2094461e2c78STakashi Iwai } 2095461e2c78STakashi Iwai 20963507e2a8STakashi Iwai if (spec->beep_amp) 20973507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20983507e2a8STakashi Iwai 2099461e2c78STakashi Iwai return 0; 2100461e2c78STakashi Iwai } 2101461e2c78STakashi Iwai 21020fb67e98SDaniel Drake /* Conexant 5066 specific */ 21030fb67e98SDaniel Drake 21040fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 21050fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 21060fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 2107f6a2491cSAndy Robinson static hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 21080fb67e98SDaniel Drake 2109dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2110dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2111dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2112dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2113dbaccc0cSDaniel Drake 21140fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = { 21150fb67e98SDaniel Drake { 2, NULL }, 21160fb67e98SDaniel Drake }; 21170fb67e98SDaniel Drake 2118a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2119a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2120a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2121a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2122a3de8ab8STakashi Iwai 21230fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 21240fb67e98SDaniel Drake { 21250fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 21260fb67e98SDaniel Drake unsigned int pinctl; 21270fb67e98SDaniel Drake 21283a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 21293a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 21300fb67e98SDaniel Drake 21310fb67e98SDaniel Drake /* Port A (HP) */ 2132a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 21330fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21340fb67e98SDaniel Drake pinctl); 21350fb67e98SDaniel Drake 21360fb67e98SDaniel Drake /* Port D (HP/LO) */ 2137a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2138a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2139a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2140a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 21413a253445SJohn Baboval pinctl = 0; 21423a253445SJohn Baboval } else { 2143a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2144a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2145a3de8ab8STakashi Iwai pinctl = 0; 21463a253445SJohn Baboval } 21470fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21480fb67e98SDaniel Drake pinctl); 21490fb67e98SDaniel Drake 21500fb67e98SDaniel Drake /* CLASS_D AMP */ 21510fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21520fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21530fb67e98SDaniel Drake pinctl); 21540fb67e98SDaniel Drake } 21550fb67e98SDaniel Drake 21560fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21570fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21580fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21590fb67e98SDaniel Drake { 21600fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21610fb67e98SDaniel Drake 21620fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21630fb67e98SDaniel Drake return 0; 21640fb67e98SDaniel Drake 21650fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21660fb67e98SDaniel Drake return 1; 21670fb67e98SDaniel Drake } 21680fb67e98SDaniel Drake 2169c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2170c4cfe66cSDaniel Drake .num_items = 3, 2171c4cfe66cSDaniel Drake .items = { 2172c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2173c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2174c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2175c4cfe66cSDaniel Drake }, 2176c4cfe66cSDaniel Drake }; 2177c4cfe66cSDaniel Drake 2178c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2179c4cfe66cSDaniel Drake { 2180c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2181c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2182c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2183c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2184c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2185c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2186c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2187c4cfe66cSDaniel Drake } 2188c4cfe66cSDaniel Drake 218975f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 219075f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 219175f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 219275f8991dSDaniel Drake * is happening when it is not. */ 219375f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21940fb67e98SDaniel Drake { 2195dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 219675f8991dSDaniel Drake if (!spec->recording) 219775f8991dSDaniel Drake return; 21980fb67e98SDaniel Drake 2199c4cfe66cSDaniel Drake if (spec->dc_enable) { 2200c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2201c4cfe66cSDaniel Drake * through our special DC port */ 2202c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2203c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2204c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2205c4cfe66cSDaniel Drake 2206c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2207c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2208c4cfe66cSDaniel Drake {}, 2209c4cfe66cSDaniel Drake }; 2210c4cfe66cSDaniel Drake 2211c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2212c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2213c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2214c4cfe66cSDaniel Drake return; 2215c4cfe66cSDaniel Drake } 2216c4cfe66cSDaniel Drake 2217c4cfe66cSDaniel Drake /* disable DC (port F) */ 2218c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2219c4cfe66cSDaniel Drake 222075f8991dSDaniel Drake /* external mic, port B */ 222175f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 222275f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 22230fb67e98SDaniel Drake 222475f8991dSDaniel Drake /* internal mic, port C */ 222575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 222675f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 222775f8991dSDaniel Drake } 22280fb67e98SDaniel Drake 222975f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 223075f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 223175f8991dSDaniel Drake { 223275f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 22330fb67e98SDaniel Drake unsigned int present; 22340fb67e98SDaniel Drake 2235c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2236c4cfe66cSDaniel Drake return; 2237c4cfe66cSDaniel Drake 223875f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 223975f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 224075f8991dSDaniel Drake if (present) 22410fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 224275f8991dSDaniel Drake else 22430fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 224475f8991dSDaniel Drake 224575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 224675f8991dSDaniel Drake present ? 0 : 1); 224775f8991dSDaniel Drake spec->ext_mic_present = !!present; 224875f8991dSDaniel Drake 224975f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22500fb67e98SDaniel Drake } 22510fb67e98SDaniel Drake 225295a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 225395a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 225495a618bdSEinar Rünkaru { 225595a618bdSEinar Rünkaru unsigned int present; 225695a618bdSEinar Rünkaru 225795a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 225895a618bdSEinar Rünkaru /* enable external mic, port B */ 225975f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 226095a618bdSEinar Rünkaru 226195a618bdSEinar Rünkaru /* switch to external mic input */ 226295a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 226395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 226495a618bdSEinar Rünkaru 226595a618bdSEinar Rünkaru /* disable internal digital mic */ 226695a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 226795a618bdSEinar Rünkaru {} 226895a618bdSEinar Rünkaru }; 226995a618bdSEinar Rünkaru static struct hda_verb ext_mic_absent[] = { 227095a618bdSEinar Rünkaru /* enable internal mic, port C */ 227195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 227295a618bdSEinar Rünkaru 227395a618bdSEinar Rünkaru /* switch to internal mic input */ 227495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 227595a618bdSEinar Rünkaru 227695a618bdSEinar Rünkaru /* disable external mic, port B */ 227795a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 227895a618bdSEinar Rünkaru {} 227995a618bdSEinar Rünkaru }; 228095a618bdSEinar Rünkaru 228195a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 228295a618bdSEinar Rünkaru if (present) { 228395a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 228495a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 228595a618bdSEinar Rünkaru } else { 228695a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 228795a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 228895a618bdSEinar Rünkaru } 228995a618bdSEinar Rünkaru } 229095a618bdSEinar Rünkaru 2291cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2292cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2293cfd3d8dcSGreg Alexander { 2294cfd3d8dcSGreg Alexander unsigned int present; 2295cfd3d8dcSGreg Alexander 2296cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2297cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2298cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2299cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2300cfd3d8dcSGreg Alexander {} 2301cfd3d8dcSGreg Alexander }; 2302cfd3d8dcSGreg Alexander static struct hda_verb ext_mic_absent[] = { 2303cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2304cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2305cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2306cfd3d8dcSGreg Alexander {} 2307cfd3d8dcSGreg Alexander }; 2308cfd3d8dcSGreg Alexander 2309cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2310cfd3d8dcSGreg Alexander if (present) { 2311cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2312cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2313cfd3d8dcSGreg Alexander } else { 2314cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2315cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2316cfd3d8dcSGreg Alexander } 2317cfd3d8dcSGreg Alexander } 2318cfd3d8dcSGreg Alexander 2319a1d6906eSDavid Henningsson 2320a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2321a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2322a1d6906eSDavid Henningsson { 2323a1d6906eSDavid Henningsson unsigned int present; 2324a1d6906eSDavid Henningsson 2325a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2326a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2327a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2328a1d6906eSDavid Henningsson present ? 1 : 0); 2329a1d6906eSDavid Henningsson } 2330a1d6906eSDavid Henningsson 2331a1d6906eSDavid Henningsson 2332048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2333048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2334048e78a5SDavid Henningsson { 2335048e78a5SDavid Henningsson unsigned int present; 2336048e78a5SDavid Henningsson 2337048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2338048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2339048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2340048e78a5SDavid Henningsson present ? 1 : 3); 2341048e78a5SDavid Henningsson } 2342048e78a5SDavid Henningsson 2343048e78a5SDavid Henningsson 23447b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 23457b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 23467b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23477b2bfdbcSJens Taprogge { 23487b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23497b2bfdbcSJens Taprogge 23507b2bfdbcSJens Taprogge static struct hda_verb ext_mic_present[] = { 23517b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23527b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23537b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23547b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23557b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23567b2bfdbcSJens Taprogge {} 23577b2bfdbcSJens Taprogge }; 23587b2bfdbcSJens Taprogge static struct hda_verb dock_mic_present[] = { 23597b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23607b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23617b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23627b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23637b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23647b2bfdbcSJens Taprogge {} 23657b2bfdbcSJens Taprogge }; 23667b2bfdbcSJens Taprogge static struct hda_verb ext_mic_absent[] = { 23677b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23687b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23697b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23707b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23717b2bfdbcSJens Taprogge {} 23727b2bfdbcSJens Taprogge }; 23737b2bfdbcSJens Taprogge 23747b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23757b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23767b2bfdbcSJens Taprogge if (ext_present) { 23777b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23787b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23797b2bfdbcSJens Taprogge } else if (dock_present) { 23807b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23817b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23827b2bfdbcSJens Taprogge } else { 23837b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23847b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23857b2bfdbcSJens Taprogge } 23867b2bfdbcSJens Taprogge } 23877b2bfdbcSJens Taprogge 23880fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23890fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23900fb67e98SDaniel Drake { 23910fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23920fb67e98SDaniel Drake unsigned int portA, portD; 23930fb67e98SDaniel Drake 23940fb67e98SDaniel Drake /* Port A */ 2395d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23960fb67e98SDaniel Drake 23970fb67e98SDaniel Drake /* Port D */ 2398d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23990fb67e98SDaniel Drake 2400a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2401a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 24020fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 24030fb67e98SDaniel Drake portA, portD, spec->hp_present); 24040fb67e98SDaniel Drake cxt5066_update_speaker(codec); 24050fb67e98SDaniel Drake } 24060fb67e98SDaniel Drake 240702b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 240802b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 240902b6b5b6SDavid Henningsson { 241002b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 241102b6b5b6SDavid Henningsson 241202b6b5b6SDavid Henningsson if (spec->dell_vostro) 241302b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 241402b6b5b6SDavid Henningsson else if (spec->ideapad) 241502b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 241602b6b5b6SDavid Henningsson else if (spec->thinkpad) 241702b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 241802b6b5b6SDavid Henningsson else if (spec->hp_laptop) 241902b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2420a1d6906eSDavid Henningsson else if (spec->asus) 2421a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 242202b6b5b6SDavid Henningsson } 242302b6b5b6SDavid Henningsson 24240fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 242575f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 24260fb67e98SDaniel Drake { 2427c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24280fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 24290fb67e98SDaniel Drake switch (res >> 26) { 24300fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 24310fb67e98SDaniel Drake cxt5066_hp_automute(codec); 24320fb67e98SDaniel Drake break; 24330fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2434c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2435c4cfe66cSDaniel Drake if (!spec->dc_enable) 243675f8991dSDaniel Drake cxt5066_olpc_automic(codec); 24370fb67e98SDaniel Drake break; 24380fb67e98SDaniel Drake } 24390fb67e98SDaniel Drake } 24400fb67e98SDaniel Drake 244195a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 244202b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 244395a618bdSEinar Rünkaru { 244402b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 244595a618bdSEinar Rünkaru switch (res >> 26) { 244695a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 244795a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 244895a618bdSEinar Rünkaru break; 244995a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 245002b6b5b6SDavid Henningsson cxt5066_automic(codec); 245195a618bdSEinar Rünkaru break; 245295a618bdSEinar Rünkaru } 245395a618bdSEinar Rünkaru } 245495a618bdSEinar Rünkaru 24557b2bfdbcSJens Taprogge 24560fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24570fb67e98SDaniel Drake .num_items = 5, 24580fb67e98SDaniel Drake .items = { 24590fb67e98SDaniel Drake { "0dB", 0 }, 24600fb67e98SDaniel Drake { "10dB", 1 }, 24610fb67e98SDaniel Drake { "20dB", 2 }, 24620fb67e98SDaniel Drake { "30dB", 3 }, 24630fb67e98SDaniel Drake { "40dB", 4 }, 24640fb67e98SDaniel Drake }, 24650fb67e98SDaniel Drake }; 24660fb67e98SDaniel Drake 2467cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2468c4cfe66cSDaniel Drake { 2469c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2470cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2471c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2472c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2473c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24747b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2475cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2476cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2477cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2478cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2479cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2480cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2481cfd3d8dcSGreg Alexander } 2482c4cfe66cSDaniel Drake } 2483c4cfe66cSDaniel Drake 24840fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24850fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24860fb67e98SDaniel Drake { 24870fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24880fb67e98SDaniel Drake } 24890fb67e98SDaniel Drake 24900fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24910fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24920fb67e98SDaniel Drake { 24930fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2494c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2495c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 24960fb67e98SDaniel Drake return 0; 24970fb67e98SDaniel Drake } 24980fb67e98SDaniel Drake 24990fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 25000fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 25010fb67e98SDaniel Drake { 25020fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2503c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 25040fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 25050fb67e98SDaniel Drake unsigned int idx; 25060fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 25070fb67e98SDaniel Drake if (idx >= imux->num_items) 25080fb67e98SDaniel Drake idx = imux->num_items - 1; 25090fb67e98SDaniel Drake 2510c4cfe66cSDaniel Drake spec->mic_boost = idx; 2511c4cfe66cSDaniel Drake if (!spec->dc_enable) 2512c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2513c4cfe66cSDaniel Drake return 1; 2514c4cfe66cSDaniel Drake } 25150fb67e98SDaniel Drake 2516c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2517c4cfe66cSDaniel Drake { 2518c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2519c4cfe66cSDaniel Drake /* disable gain */ 2520c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2521c4cfe66cSDaniel Drake 2522c4cfe66cSDaniel Drake /* switch to DC input */ 2523c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2524c4cfe66cSDaniel Drake {} 2525c4cfe66cSDaniel Drake }; 2526c4cfe66cSDaniel Drake 2527c4cfe66cSDaniel Drake /* configure as input source */ 2528c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2529c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2530c4cfe66cSDaniel Drake } 2531c4cfe66cSDaniel Drake 2532c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2533c4cfe66cSDaniel Drake { 2534c4cfe66cSDaniel Drake /* reconfigure input source */ 2535c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2536c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2537c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2538c4cfe66cSDaniel Drake } 2539c4cfe66cSDaniel Drake 2540c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2541c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2542c4cfe66cSDaniel Drake { 2543c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2544c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2545c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2546c4cfe66cSDaniel Drake return 0; 2547c4cfe66cSDaniel Drake } 2548c4cfe66cSDaniel Drake 2549c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2550c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2551c4cfe66cSDaniel Drake { 2552c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2553c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2554c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2555c4cfe66cSDaniel Drake 2556c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2557c4cfe66cSDaniel Drake return 0; 2558c4cfe66cSDaniel Drake 2559c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2560c4cfe66cSDaniel Drake if (dc_enable) 2561c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2562c4cfe66cSDaniel Drake else 2563c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2564c4cfe66cSDaniel Drake 2565c4cfe66cSDaniel Drake return 1; 2566c4cfe66cSDaniel Drake } 2567c4cfe66cSDaniel Drake 2568c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2569c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2570c4cfe66cSDaniel Drake { 2571c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2572c4cfe66cSDaniel Drake } 2573c4cfe66cSDaniel Drake 2574c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2575c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2576c4cfe66cSDaniel Drake { 2577c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2578c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2579c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2580c4cfe66cSDaniel Drake return 0; 2581c4cfe66cSDaniel Drake } 2582c4cfe66cSDaniel Drake 2583c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2584c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2585c4cfe66cSDaniel Drake { 2586c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2587c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2588c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2589c4cfe66cSDaniel Drake unsigned int idx; 2590c4cfe66cSDaniel Drake 2591c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2592c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2593c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2594c4cfe66cSDaniel Drake 2595c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2596c4cfe66cSDaniel Drake if (spec->dc_enable) 2597c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25980fb67e98SDaniel Drake return 1; 25990fb67e98SDaniel Drake } 26000fb67e98SDaniel Drake 260175f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 260275f8991dSDaniel Drake { 260375f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 260475f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 260575f8991dSDaniel Drake * recording LED comes on. */ 260675f8991dSDaniel Drake spec->recording = 1; 260775f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 260875f8991dSDaniel Drake } 260975f8991dSDaniel Drake 261075f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 261175f8991dSDaniel Drake { 261275f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 261375f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 261475f8991dSDaniel Drake /* disable external mic, port B */ 261575f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 261675f8991dSDaniel Drake 261775f8991dSDaniel Drake /* disble internal mic, port C */ 261875f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2619c4cfe66cSDaniel Drake 2620c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2621c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 262275f8991dSDaniel Drake {}, 262375f8991dSDaniel Drake }; 262475f8991dSDaniel Drake 262575f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 262675f8991dSDaniel Drake spec->recording = 0; 262775f8991dSDaniel Drake } 262875f8991dSDaniel Drake 2629f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 2630f6a2491cSAndy Robinson hda_nid_t *dig_pins, 2631f6a2491cSAndy Robinson int num_pins) 2632f6a2491cSAndy Robinson { 2633f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2634f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2635f6a2491cSAndy Robinson int i; 2636f6a2491cSAndy Robinson 2637f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2638f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2639f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2640f6a2491cSAndy Robinson continue; 2641f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2642f6a2491cSAndy Robinson continue; 2643f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2644f6a2491cSAndy Robinson nid_loc++; 2645f6a2491cSAndy Robinson else 2646f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2647f6a2491cSAndy Robinson } 2648f6a2491cSAndy Robinson } 2649f6a2491cSAndy Robinson 26500fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 26510fb67e98SDaniel Drake .num_items = 4, 26520fb67e98SDaniel Drake .items = { 26530fb67e98SDaniel Drake { "Mic B", 0 }, 26540fb67e98SDaniel Drake { "Mic C", 1 }, 26550fb67e98SDaniel Drake { "Mic E", 2 }, 26560fb67e98SDaniel Drake { "Mic F", 3 }, 26570fb67e98SDaniel Drake }, 26580fb67e98SDaniel Drake }; 26590fb67e98SDaniel Drake 26600fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26610fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26620fb67e98SDaniel Drake .values = { 26630fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26640fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26650fb67e98SDaniel Drake 0 26660fb67e98SDaniel Drake }, 26670fb67e98SDaniel Drake }; 26680fb67e98SDaniel Drake 26690fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26700fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26710fb67e98SDaniel Drake .values = { 26720fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26730fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26740fb67e98SDaniel Drake 0 26750fb67e98SDaniel Drake }, 26760fb67e98SDaniel Drake }; 26770fb67e98SDaniel Drake 26780fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 26790fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26800fb67e98SDaniel Drake {} 26810fb67e98SDaniel Drake }; 26820fb67e98SDaniel Drake 26830fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26840fb67e98SDaniel Drake { 26850fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26860fb67e98SDaniel Drake .name = "Master Playback Volume", 26870fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26880fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26890fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26905e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26910fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26920fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26930fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26940fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26950fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26960fb67e98SDaniel Drake .private_value = 26970fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26980fb67e98SDaniel Drake }, 26990fb67e98SDaniel Drake {} 27000fb67e98SDaniel Drake }; 27010fb67e98SDaniel Drake 2702c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2703c4cfe66cSDaniel Drake { 2704c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2705c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2706c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2707c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2708c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2709c4cfe66cSDaniel Drake }, 2710c4cfe66cSDaniel Drake { 2711c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2712c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2713c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2714c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2715c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2716c4cfe66cSDaniel Drake }, 2717c4cfe66cSDaniel Drake {} 2718c4cfe66cSDaniel Drake }; 2719c4cfe66cSDaniel Drake 27200fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 27210fb67e98SDaniel Drake { 27220fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 27230fb67e98SDaniel Drake .name = "Master Playback Switch", 27240fb67e98SDaniel Drake .info = cxt_eapd_info, 27250fb67e98SDaniel Drake .get = cxt_eapd_get, 27260fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 27270fb67e98SDaniel Drake .private_value = 0x1d, 27280fb67e98SDaniel Drake }, 27290fb67e98SDaniel Drake 27300fb67e98SDaniel Drake { 27310fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2732c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 27330fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 27340fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 27350fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 27360fb67e98SDaniel Drake }, 27370fb67e98SDaniel Drake 27380fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 27390fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 27400fb67e98SDaniel Drake {} 27410fb67e98SDaniel Drake }; 27420fb67e98SDaniel Drake 2743254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2744254bba6aSEinar Rünkaru { 2745254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 274628c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2747254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2748254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2749254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2750254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2751254bba6aSEinar Rünkaru }, 2752254bba6aSEinar Rünkaru {} 2753254bba6aSEinar Rünkaru }; 2754254bba6aSEinar Rünkaru 27550fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 27560fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27570fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27580fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27590fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27600fb67e98SDaniel Drake 27610fb67e98SDaniel Drake /* Speakers */ 27620fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27630fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27640fb67e98SDaniel Drake 27650fb67e98SDaniel Drake /* HP, Amp */ 27660fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27670fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27680fb67e98SDaniel Drake 27690fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27700fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27710fb67e98SDaniel Drake 27720fb67e98SDaniel Drake /* DAC1 */ 27730fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27740fb67e98SDaniel Drake 27750fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27760fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27770fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27780fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27790fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27800fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27810fb67e98SDaniel Drake 27820fb67e98SDaniel Drake /* no digital microphone support yet */ 27830fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27840fb67e98SDaniel Drake 27850fb67e98SDaniel Drake /* Audio input selector */ 27860fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27870fb67e98SDaniel Drake 27880fb67e98SDaniel Drake /* SPDIF route: PCM */ 27890fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27900fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27910fb67e98SDaniel Drake 27920fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27930fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27940fb67e98SDaniel Drake 27950fb67e98SDaniel Drake /* EAPD */ 27960fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27970fb67e98SDaniel Drake 27980fb67e98SDaniel Drake /* not handling these yet */ 27990fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28000fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28010fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28020fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28030fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28040fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28050fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28060fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 28070fb67e98SDaniel Drake { } /* end */ 28080fb67e98SDaniel Drake }; 28090fb67e98SDaniel Drake 28100fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 28110fb67e98SDaniel Drake /* Port A: headphones */ 28120fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 28130fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28140fb67e98SDaniel Drake 28150fb67e98SDaniel Drake /* Port B: external microphone */ 281675f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28170fb67e98SDaniel Drake 28180fb67e98SDaniel Drake /* Port C: internal microphone */ 281975f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28200fb67e98SDaniel Drake 28210fb67e98SDaniel Drake /* Port D: unused */ 28220fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28230fb67e98SDaniel Drake 28240fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 28250fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28260fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28270fb67e98SDaniel Drake 2828c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 28290fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28300fb67e98SDaniel Drake 28310fb67e98SDaniel Drake /* Port G: internal speakers */ 28320fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28330fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28340fb67e98SDaniel Drake 28350fb67e98SDaniel Drake /* DAC1 */ 28360fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28370fb67e98SDaniel Drake 28380fb67e98SDaniel Drake /* DAC2: unused */ 28390fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 28400fb67e98SDaniel Drake 28410fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28420fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28430fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28440fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28450fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28460fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28470fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28480fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28490fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28500fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28510fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28520fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28530fb67e98SDaniel Drake 28540fb67e98SDaniel Drake /* Disable digital microphone port */ 28550fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28560fb67e98SDaniel Drake 28570fb67e98SDaniel Drake /* Audio input selectors */ 28580fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28590fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28600fb67e98SDaniel Drake 28610fb67e98SDaniel Drake /* Disable SPDIF */ 28620fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28630fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28640fb67e98SDaniel Drake 28650fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28660fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28670fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28680fb67e98SDaniel Drake { } /* end */ 28690fb67e98SDaniel Drake }; 28700fb67e98SDaniel Drake 287195a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = { 287295a618bdSEinar Rünkaru /* Port A: headphones */ 287395a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287495a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 287595a618bdSEinar Rünkaru 287695a618bdSEinar Rünkaru /* Port B: external microphone */ 287795a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287895a618bdSEinar Rünkaru 287995a618bdSEinar Rünkaru /* Port C: unused */ 288095a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 288195a618bdSEinar Rünkaru 288295a618bdSEinar Rünkaru /* Port D: unused */ 288395a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 288495a618bdSEinar Rünkaru 288595a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 288695a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 288795a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 288895a618bdSEinar Rünkaru 288995a618bdSEinar Rünkaru /* Port F: unused */ 289095a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 289195a618bdSEinar Rünkaru 289295a618bdSEinar Rünkaru /* Port G: internal speakers */ 289395a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 289495a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 289595a618bdSEinar Rünkaru 289695a618bdSEinar Rünkaru /* DAC1 */ 289795a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 289895a618bdSEinar Rünkaru 289995a618bdSEinar Rünkaru /* DAC2: unused */ 290095a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 290195a618bdSEinar Rünkaru 290295a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 290395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 290495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 290595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 290695a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 290795a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 290895a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 290995a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 291095a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 291195a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 291295a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 291395a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 291495a618bdSEinar Rünkaru 291595a618bdSEinar Rünkaru /* Digital microphone port */ 291695a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 291795a618bdSEinar Rünkaru 291895a618bdSEinar Rünkaru /* Audio input selectors */ 291995a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 292095a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 292195a618bdSEinar Rünkaru 292295a618bdSEinar Rünkaru /* Disable SPDIF */ 292395a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 292495a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 292595a618bdSEinar Rünkaru 292695a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 292795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 292895a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 292995a618bdSEinar Rünkaru { } /* end */ 293095a618bdSEinar Rünkaru }; 293195a618bdSEinar Rünkaru 2932cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = { 2933cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2934cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2935cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2936cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2937cfd3d8dcSGreg Alexander 2938cfd3d8dcSGreg Alexander /* Speakers */ 2939cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2940cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2941cfd3d8dcSGreg Alexander 2942cfd3d8dcSGreg Alexander /* HP, Amp */ 2943cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2944cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2945cfd3d8dcSGreg Alexander 2946cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2947cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2948cfd3d8dcSGreg Alexander 2949cfd3d8dcSGreg Alexander /* DAC1 */ 2950cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2951cfd3d8dcSGreg Alexander 2952cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2953cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2954cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2955cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2956cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2957cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2958cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2959cfd3d8dcSGreg Alexander 2960cfd3d8dcSGreg Alexander /* Audio input selector */ 2961cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2962cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2963cfd3d8dcSGreg Alexander 2964cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2965cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2966cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2967cfd3d8dcSGreg Alexander 2968cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2969cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2970cfd3d8dcSGreg Alexander 2971cfd3d8dcSGreg Alexander /* internal microphone */ 297228c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2973cfd3d8dcSGreg Alexander 2974cfd3d8dcSGreg Alexander /* EAPD */ 2975cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2976cfd3d8dcSGreg Alexander 2977cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2978cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2979cfd3d8dcSGreg Alexander { } /* end */ 2980cfd3d8dcSGreg Alexander }; 2981cfd3d8dcSGreg Alexander 29827b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29837b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29847b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29857b2bfdbcSJens Taprogge 29867b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29877b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29887b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29897b2bfdbcSJens Taprogge 29907b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29917b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29927b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29937b2bfdbcSJens Taprogge 29947b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29957b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29967b2bfdbcSJens Taprogge 29977b2bfdbcSJens Taprogge /* Port C: Mic */ 29987b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29997b2bfdbcSJens Taprogge 30007b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 30017b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 30027b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 30037b2bfdbcSJens Taprogge 30047b2bfdbcSJens Taprogge /* DAC1 */ 30057b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 30067b2bfdbcSJens Taprogge 30077b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 30087b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 30097b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 30107b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 30117b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 30127b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 30137b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 30147b2bfdbcSJens Taprogge 30157b2bfdbcSJens Taprogge /* Audio input selector */ 30167b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 30177b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 30187b2bfdbcSJens Taprogge 30197b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 30207b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 30217b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 30227b2bfdbcSJens Taprogge 30237b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30247b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30257b2bfdbcSJens Taprogge 30267b2bfdbcSJens Taprogge /* internal microphone */ 302728c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 30287b2bfdbcSJens Taprogge 30297b2bfdbcSJens Taprogge /* EAPD */ 30307b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 30317b2bfdbcSJens Taprogge 30327b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 30337b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30347b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30357b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30367b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30377b2bfdbcSJens Taprogge { } /* end */ 30387b2bfdbcSJens Taprogge }; 30397b2bfdbcSJens Taprogge 30400fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 30410fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30420fb67e98SDaniel Drake { } /* end */ 30430fb67e98SDaniel Drake }; 30440fb67e98SDaniel Drake 3045048e78a5SDavid Henningsson 3046048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3047048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3048048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3049048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3050048e78a5SDavid Henningsson { } /* end */ 3051048e78a5SDavid Henningsson }; 3052048e78a5SDavid Henningsson 30530fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30540fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30550fb67e98SDaniel Drake { 30560fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30570fb67e98SDaniel Drake conexant_init(codec); 30580fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30590fb67e98SDaniel Drake cxt5066_hp_automute(codec); 306002b6b5b6SDavid Henningsson cxt5066_automic(codec); 30610fb67e98SDaniel Drake } 3062c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30630fb67e98SDaniel Drake return 0; 30640fb67e98SDaniel Drake } 30650fb67e98SDaniel Drake 306675f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 306775f8991dSDaniel Drake { 3068c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 306975f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 307075f8991dSDaniel Drake conexant_init(codec); 307175f8991dSDaniel Drake cxt5066_hp_automute(codec); 3072c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3073c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 307475f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3075c4cfe66cSDaniel Drake } else { 3076c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3077c4cfe66cSDaniel Drake } 307875f8991dSDaniel Drake return 0; 307975f8991dSDaniel Drake } 308075f8991dSDaniel Drake 30810fb67e98SDaniel Drake enum { 30820fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30830fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30840fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 30851feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 3086cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30877b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3088a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 3089048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 30900fb67e98SDaniel Drake CXT5066_MODELS 30910fb67e98SDaniel Drake }; 30920fb67e98SDaniel Drake 3093ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 30940fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30950fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30960fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30971feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3098cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30997b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3100a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 3101048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 31020fb67e98SDaniel Drake }; 31030fb67e98SDaniel Drake 31040fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 310500cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 31061feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 31078a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3108ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 31091feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3110231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3111048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3112f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3113a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3114f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 31152ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3116c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 31174442dd46SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 31185637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 31195637edb2SDavid Henningsson CXT5066_LAPTOP), 31205637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 31214d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3122ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 3123*19593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 31247b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3125a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 312622f21d51SDavid Henningsson SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ 31270fb67e98SDaniel Drake {} 31280fb67e98SDaniel Drake }; 31290fb67e98SDaniel Drake 31300fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 31310fb67e98SDaniel Drake { 31320fb67e98SDaniel Drake struct conexant_spec *spec; 31330fb67e98SDaniel Drake int board_config; 31340fb67e98SDaniel Drake 31350fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31360fb67e98SDaniel Drake if (!spec) 31370fb67e98SDaniel Drake return -ENOMEM; 31380fb67e98SDaniel Drake codec->spec = spec; 31390fb67e98SDaniel Drake 31400fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 314175f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31420fb67e98SDaniel Drake 31430fb67e98SDaniel Drake spec->dell_automute = 0; 31440fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31450fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31460fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3147f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3148f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 31490fb67e98SDaniel Drake spec->num_adc_nids = 1; 31500fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31510fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31520fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31530fb67e98SDaniel Drake 31540fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31550fb67e98SDaniel Drake 31560fb67e98SDaniel Drake spec->num_init_verbs = 1; 31570fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31580fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31590fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31600fb67e98SDaniel Drake spec->cur_adc = 0; 31610fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31620fb67e98SDaniel Drake 31633507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31643507e2a8STakashi Iwai 31650fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 31660fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 31670fb67e98SDaniel Drake switch (board_config) { 31680fb67e98SDaniel Drake default: 31690fb67e98SDaniel Drake case CXT5066_LAPTOP: 31700fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31710fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31720fb67e98SDaniel Drake break; 31730fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31740fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31750fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31760fb67e98SDaniel Drake 31770fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31780fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31790fb67e98SDaniel Drake spec->num_init_verbs++; 31800fb67e98SDaniel Drake spec->dell_automute = 1; 31810fb67e98SDaniel Drake break; 3182a1d6906eSDavid Henningsson case CXT5066_ASUS: 3183048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3184048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 318502b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3186048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3187048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3188048e78a5SDavid Henningsson spec->num_init_verbs++; 3189a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3190a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3191048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3192048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3193048e78a5SDavid Henningsson /* no S/PDIF out */ 3194f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3195048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3196048e78a5SDavid Henningsson /* input source automatically selected */ 3197048e78a5SDavid Henningsson spec->input_mux = NULL; 3198048e78a5SDavid Henningsson spec->port_d_mode = 0; 3199048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3200048e78a5SDavid Henningsson break; 3201048e78a5SDavid Henningsson 32020fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 320375f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 320475f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 32050fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 32060fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3207c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 32080fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32090fb67e98SDaniel Drake spec->port_d_mode = 0; 3210c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 32110fb67e98SDaniel Drake 32120fb67e98SDaniel Drake /* no S/PDIF out */ 32130fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 32140fb67e98SDaniel Drake 32150fb67e98SDaniel Drake /* input source automatically selected */ 32160fb67e98SDaniel Drake spec->input_mux = NULL; 321775f8991dSDaniel Drake 321875f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 321975f8991dSDaniel Drake * at the right time */ 322075f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 322175f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 32220fb67e98SDaniel Drake break; 32231feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 322475f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 322502b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 322695a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 322795a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 322895a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3229254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 323095a618bdSEinar Rünkaru spec->port_d_mode = 0; 3231254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3232c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 323395a618bdSEinar Rünkaru 323495a618bdSEinar Rünkaru /* no S/PDIF out */ 323595a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 323695a618bdSEinar Rünkaru 323795a618bdSEinar Rünkaru /* input source automatically selected */ 323895a618bdSEinar Rünkaru spec->input_mux = NULL; 323995a618bdSEinar Rünkaru break; 3240cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3241cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 324202b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3243cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3244cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3245cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3246cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3247cfd3d8dcSGreg Alexander spec->ideapad = 1; 3248cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3249cfd3d8dcSGreg Alexander 3250cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3251cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3252cfd3d8dcSGreg Alexander 3253cfd3d8dcSGreg Alexander /* input source automatically selected */ 3254cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3255cfd3d8dcSGreg Alexander break; 32567b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32577b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 325802b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 32597b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32607b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32617b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32627b2bfdbcSJens Taprogge spec->thinkpad = 1; 32637b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32647b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32657b2bfdbcSJens Taprogge 32667b2bfdbcSJens Taprogge /* no S/PDIF out */ 32677b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32687b2bfdbcSJens Taprogge 32697b2bfdbcSJens Taprogge /* input source automatically selected */ 32707b2bfdbcSJens Taprogge spec->input_mux = NULL; 32717b2bfdbcSJens Taprogge break; 32720fb67e98SDaniel Drake } 32730fb67e98SDaniel Drake 32743507e2a8STakashi Iwai if (spec->beep_amp) 32753507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32763507e2a8STakashi Iwai 32770fb67e98SDaniel Drake return 0; 32780fb67e98SDaniel Drake } 3279461e2c78STakashi Iwai 3280461e2c78STakashi Iwai /* 3281f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3282f2e5731dSTakashi Iwai */ 3283f2e5731dSTakashi Iwai 3284f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3285f2e5731dSTakashi Iwai 3286f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */ 3287f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, 3288f2e5731dSTakashi Iwai hda_nid_t nid) 3289f2e5731dSTakashi Iwai { 3290f2e5731dSTakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 3291f2e5731dSTakashi Iwai int i, nums; 3292f2e5731dSTakashi Iwai 3293f2e5731dSTakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 3294f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) 3295f2e5731dSTakashi Iwai if (conn[i] == nid) 3296f2e5731dSTakashi Iwai return i; 3297f2e5731dSTakashi Iwai return -1; 3298f2e5731dSTakashi Iwai } 3299f2e5731dSTakashi Iwai 3300f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3301f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3302f2e5731dSTakashi Iwai * not found 3303f2e5731dSTakashi Iwai */ 3304f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3305f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3306f2e5731dSTakashi Iwai { 3307f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3308f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3309f2e5731dSTakashi Iwai 3310f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3311f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3312f2e5731dSTakashi Iwai ret = dacs[i]; 3313f2e5731dSTakashi Iwai break; 3314f2e5731dSTakashi Iwai } 3315f2e5731dSTakashi Iwai } 3316f2e5731dSTakashi Iwai if (!ret) 3317f2e5731dSTakashi Iwai return 0; 3318f2e5731dSTakashi Iwai if (--nums > 0) 3319f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3320f2e5731dSTakashi Iwai *num_dacs = nums; 3321f2e5731dSTakashi Iwai return ret; 3322f2e5731dSTakashi Iwai } 3323f2e5731dSTakashi Iwai 3324f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3325f2e5731dSTakashi Iwai 3326f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3327f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3328f2e5731dSTakashi Iwai { 3329f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3330f2e5731dSTakashi Iwai int nums = 0; 3331f2e5731dSTakashi Iwai 3332f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3333f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3334f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3335f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3336f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3337f2e5731dSTakashi Iwai dacs[nums++] = nid; 3338f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3339f2e5731dSTakashi Iwai break; 3340f2e5731dSTakashi Iwai } 3341f2e5731dSTakashi Iwai } 3342f2e5731dSTakashi Iwai return nums; 3343f2e5731dSTakashi Iwai } 3344f2e5731dSTakashi Iwai 3345f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3346f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3347f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3348f2e5731dSTakashi Iwai struct pin_dac_pair *filled, int type) 3349f2e5731dSTakashi Iwai { 3350f2e5731dSTakashi Iwai int i, nums; 3351f2e5731dSTakashi Iwai 3352f2e5731dSTakashi Iwai nums = 0; 3353f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3354f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3355f2e5731dSTakashi Iwai filled[nums].type = type; 3356f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3357f2e5731dSTakashi Iwai nums++; 3358f2e5731dSTakashi Iwai } 3359f2e5731dSTakashi Iwai return nums; 3360f2e5731dSTakashi Iwai } 3361f2e5731dSTakashi Iwai 3362f2e5731dSTakashi Iwai /* parse analog output paths */ 3363f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3364f2e5731dSTakashi Iwai { 3365f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3366f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3367f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3368f2e5731dSTakashi Iwai int i, j, nums, rest; 3369f2e5731dSTakashi Iwai 3370f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3371f2e5731dSTakashi Iwai /* parse all analog output pins */ 3372f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3373f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info, 3374f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3375f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3376f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3377f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3378f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3379f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3380f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3381f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3382f2e5731dSTakashi Iwai /* fill multiout struct */ 3383f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3384f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 3385f2e5731dSTakashi Iwai if (!dac) 3386f2e5731dSTakashi Iwai continue; 3387f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3388f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3389f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3390f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3391f2e5731dSTakashi Iwai break; 3392f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3393f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3394f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3395f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3396f2e5731dSTakashi Iwai break; 3397f2e5731dSTakashi Iwai } 3398f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3399f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3400f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3401f2e5731dSTakashi Iwai break; 3402f2e5731dSTakashi Iwai } 3403f2e5731dSTakashi Iwai break; 3404f2e5731dSTakashi Iwai } 3405f2e5731dSTakashi Iwai } 3406f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 3407f2e5731dSTakashi Iwai spec->multiout.max_channels = nums * 2; 3408f2e5731dSTakashi Iwai 3409f2e5731dSTakashi Iwai if (cfg->hp_outs > 0) 3410f2e5731dSTakashi Iwai spec->auto_mute = 1; 3411f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3412f2e5731dSTakashi Iwai } 3413f2e5731dSTakashi Iwai 3414f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 3415f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3416f2e5731dSTakashi Iwai { 3417f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3418f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3419f2e5731dSTakashi Iwai int i, present; 3420f2e5731dSTakashi Iwai 3421f2e5731dSTakashi Iwai if (!spec->auto_mute) 3422f2e5731dSTakashi Iwai return; 3423f2e5731dSTakashi Iwai present = 0; 3424f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3425f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) { 3426f2e5731dSTakashi Iwai present = 1; 3427f2e5731dSTakashi Iwai break; 3428f2e5731dSTakashi Iwai } 3429f2e5731dSTakashi Iwai } 3430f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 3431f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3432f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3433f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3434f2e5731dSTakashi Iwai } 3435fbb5bb56STakashi Iwai for (i = 0; !present && i < cfg->line_outs; i++) 3436fbb5bb56STakashi Iwai if (snd_hda_jack_detect(codec, cfg->line_out_pins[i])) 3437fbb5bb56STakashi Iwai present = 1; 3438f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) { 3439f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3440f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3441f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3442f2e5731dSTakashi Iwai } 3443f2e5731dSTakashi Iwai } 3444f2e5731dSTakashi Iwai 3445f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3446f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3447f2e5731dSTakashi Iwai { 3448f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3449f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3450f2e5731dSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 3451f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3452f2e5731dSTakashi Iwai 3453f2e5731dSTakashi Iwai if (!spec->auto_mic) 3454f2e5731dSTakashi Iwai return; 3455f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) { 3456f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[0], 0, 3457f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3458f2e5731dSTakashi Iwai imux->items[ext_idx].index); 3459f2e5731dSTakashi Iwai } else { 3460f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[0], 0, 3461f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3462f2e5731dSTakashi Iwai imux->items[!ext_idx].index); 3463f2e5731dSTakashi Iwai } 3464f2e5731dSTakashi Iwai } 3465f2e5731dSTakashi Iwai 3466f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3467f2e5731dSTakashi Iwai { 3468f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3469f2e5731dSTakashi Iwai switch (res >> 26) { 3470f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3471f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3472f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3473f2e5731dSTakashi Iwai break; 3474f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3475f2e5731dSTakashi Iwai cx_auto_automic(codec); 3476f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3477f2e5731dSTakashi Iwai break; 3478f2e5731dSTakashi Iwai } 3479f2e5731dSTakashi Iwai } 3480f2e5731dSTakashi Iwai 3481f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */ 3482f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) 3483f2e5731dSTakashi Iwai { 3484f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3485f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 348699ae28beSTakashi Iwai snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT; 3487f2e5731dSTakashi Iwai } 3488f2e5731dSTakashi Iwai 3489f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */ 3490f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin) 3491f2e5731dSTakashi Iwai { 3492f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3493f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3494f68b3b29STakashi Iwai snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL && 3495f68b3b29STakashi Iwai (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT); 3496f2e5731dSTakashi Iwai } 3497f2e5731dSTakashi Iwai 3498f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 3499f2e5731dSTakashi Iwai * auto-mic is enabled only when one int-mic and one-ext mic exist 3500f2e5731dSTakashi Iwai */ 3501f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3502f2e5731dSTakashi Iwai { 3503f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3504f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3505f2e5731dSTakashi Iwai 3506f2e5731dSTakashi Iwai if (is_ext_mic(codec, cfg->inputs[0].pin) && 3507f2e5731dSTakashi Iwai is_int_mic(codec, cfg->inputs[1].pin)) { 3508f2e5731dSTakashi Iwai spec->auto_mic = 1; 3509f2e5731dSTakashi Iwai spec->auto_mic_ext = 1; 3510f2e5731dSTakashi Iwai return; 3511f2e5731dSTakashi Iwai } 3512f2e5731dSTakashi Iwai if (is_int_mic(codec, cfg->inputs[1].pin) && 3513f2e5731dSTakashi Iwai is_ext_mic(codec, cfg->inputs[0].pin)) { 3514f2e5731dSTakashi Iwai spec->auto_mic = 1; 3515f2e5731dSTakashi Iwai spec->auto_mic_ext = 0; 3516f2e5731dSTakashi Iwai return; 3517f2e5731dSTakashi Iwai } 3518f2e5731dSTakashi Iwai } 3519f2e5731dSTakashi Iwai 3520f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3521f2e5731dSTakashi Iwai { 3522f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3523f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3524f2e5731dSTakashi Iwai struct hda_input_mux *imux; 3525f2e5731dSTakashi Iwai int i; 3526f2e5731dSTakashi Iwai 3527f2e5731dSTakashi Iwai imux = &spec->private_imux; 3528f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3529f2e5731dSTakashi Iwai int idx = get_connection_index(codec, spec->adc_nids[0], 3530f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3531f2e5731dSTakashi Iwai if (idx >= 0) { 3532f2e5731dSTakashi Iwai const char *label; 3533f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3534f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 3535f2e5731dSTakashi Iwai } 3536f2e5731dSTakashi Iwai } 3537f2e5731dSTakashi Iwai if (imux->num_items == 2 && cfg->num_inputs == 2) 3538f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 3539f2e5731dSTakashi Iwai if (imux->num_items > 1 && !spec->auto_mic) 3540f2e5731dSTakashi Iwai spec->input_mux = imux; 3541f2e5731dSTakashi Iwai } 3542f2e5731dSTakashi Iwai 3543f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3544f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3545f2e5731dSTakashi Iwai { 3546f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3547f2e5731dSTakashi Iwai 3548f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3549f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3550f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3551f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3552f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3553f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3554f2e5731dSTakashi Iwai return nid; 3555f2e5731dSTakashi Iwai } 3556f2e5731dSTakashi Iwai } 3557f2e5731dSTakashi Iwai return 0; 3558f2e5731dSTakashi Iwai } 3559f2e5731dSTakashi Iwai 3560f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3561f2e5731dSTakashi Iwai { 3562f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3563f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3564f2e5731dSTakashi Iwai hda_nid_t nid; 3565f2e5731dSTakashi Iwai 3566f2e5731dSTakashi Iwai if (cfg->dig_outs && 3567f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3568f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3569f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3570f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3571f2e5731dSTakashi Iwai } 3572f2e5731dSTakashi Iwai 3573f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3574f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3575f2e5731dSTakashi Iwai { 3576f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3577f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3578f2e5731dSTakashi Iwai 3579f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3580f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3581f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3582f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3583f2e5731dSTakashi Iwai break; 3584f2e5731dSTakashi Iwai } 3585f2e5731dSTakashi Iwai } 3586f2e5731dSTakashi Iwai #else 3587f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3588f2e5731dSTakashi Iwai #endif 3589f2e5731dSTakashi Iwai 3590f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3591f2e5731dSTakashi Iwai { 3592f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3593f2e5731dSTakashi Iwai int err; 3594f2e5731dSTakashi Iwai 3595f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3596f2e5731dSTakashi Iwai if (err < 0) 3597f2e5731dSTakashi Iwai return err; 3598f2e5731dSTakashi Iwai 3599f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3600f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3601f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3602f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 3603f2e5731dSTakashi Iwai return 0; 3604f2e5731dSTakashi Iwai } 3605f2e5731dSTakashi Iwai 3606f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins, 3607f2e5731dSTakashi Iwai hda_nid_t *pins) 3608f2e5731dSTakashi Iwai { 3609f2e5731dSTakashi Iwai int i; 3610f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3611f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3612f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3613f2e5731dSTakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 0x02); 3614f2e5731dSTakashi Iwai } 3615f2e5731dSTakashi Iwai } 3616f2e5731dSTakashi Iwai 3617f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3618f2e5731dSTakashi Iwai hda_nid_t src) 3619f2e5731dSTakashi Iwai { 3620f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3621f2e5731dSTakashi Iwai if (idx >= 0) 3622f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3623f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3624f2e5731dSTakashi Iwai } 3625f2e5731dSTakashi Iwai 3626f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 3627f2e5731dSTakashi Iwai { 3628f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3629f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3630f2e5731dSTakashi Iwai hda_nid_t nid; 3631f2e5731dSTakashi Iwai int i; 3632f2e5731dSTakashi Iwai 3633f2e5731dSTakashi Iwai for (i = 0; i < spec->multiout.num_dacs; i++) 3634f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0, 3635f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); 3636f2e5731dSTakashi Iwai 3637f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3638f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3639f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 3640f2e5731dSTakashi Iwai if (spec->auto_mute) { 3641f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3642f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3643f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3644f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_HP_EVENT); 3645f2e5731dSTakashi Iwai } 3646f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3647f2e5731dSTakashi Iwai } else { 3648f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) 3649f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3650f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3651f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) 3652f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3653f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3654f2e5731dSTakashi Iwai } 3655f2e5731dSTakashi Iwai 3656f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3657f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3658f2e5731dSTakashi Iwai if (!nid) 3659f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 3660f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3661f2e5731dSTakashi Iwai } 3662f2e5731dSTakashi Iwai 3663f2e5731dSTakashi Iwai /* turn on EAPD */ 3664f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins); 3665f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins); 3666f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins); 3667f2e5731dSTakashi Iwai } 3668f2e5731dSTakashi Iwai 3669f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3670f2e5731dSTakashi Iwai { 3671f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3672f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3673f2e5731dSTakashi Iwai int i; 3674f2e5731dSTakashi Iwai 3675f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) 3676f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3677f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)); 3678f2e5731dSTakashi Iwai 3679f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3680f2e5731dSTakashi Iwai unsigned int type; 3681f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 3682f2e5731dSTakashi Iwai type = PIN_VREF80; 3683f2e5731dSTakashi Iwai else 3684f2e5731dSTakashi Iwai type = PIN_IN; 3685f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 3686f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 3687f2e5731dSTakashi Iwai } 3688f2e5731dSTakashi Iwai 3689f2e5731dSTakashi Iwai if (spec->auto_mic) { 3690f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3691f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0, 3692f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3693f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 3694f2e5731dSTakashi Iwai cx_auto_automic(codec); 3695f2e5731dSTakashi Iwai } else { 3696f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 3697f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3698f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3699f2e5731dSTakashi Iwai spec->private_imux.items[0].index); 3700f2e5731dSTakashi Iwai } 3701f2e5731dSTakashi Iwai } 3702f2e5731dSTakashi Iwai } 3703f2e5731dSTakashi Iwai 3704f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 3705f2e5731dSTakashi Iwai { 3706f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3707f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3708f2e5731dSTakashi Iwai 3709f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 3710f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 3711f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3712f2e5731dSTakashi Iwai if (spec->dig_in_nid) 3713f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 3714f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 3715f2e5731dSTakashi Iwai } 3716f2e5731dSTakashi Iwai 3717f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 3718f2e5731dSTakashi Iwai { 3719f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 3720f2e5731dSTakashi Iwai cx_auto_init_output(codec); 3721f2e5731dSTakashi Iwai cx_auto_init_input(codec); 3722f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 3723f2e5731dSTakashi Iwai return 0; 3724f2e5731dSTakashi Iwai } 3725f2e5731dSTakashi Iwai 3726f2e5731dSTakashi Iwai static int cx_auto_add_volume(struct hda_codec *codec, const char *basename, 3727f2e5731dSTakashi Iwai const char *dir, int cidx, 3728f2e5731dSTakashi Iwai hda_nid_t nid, int hda_dir) 3729f2e5731dSTakashi Iwai { 3730f2e5731dSTakashi Iwai static char name[32]; 3731f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 3732f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 3733f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 3734f2e5731dSTakashi Iwai }; 3735f2e5731dSTakashi Iwai static char *sfx[2] = { "Volume", "Switch" }; 3736f2e5731dSTakashi Iwai int i, err; 3737f2e5731dSTakashi Iwai 3738f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 3739f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 3740f2e5731dSTakashi Iwai knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir); 3741f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 3742f2e5731dSTakashi Iwai knew[i].index = cidx; 3743f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 3744f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 3745f2e5731dSTakashi Iwai if (!kctl) 3746f2e5731dSTakashi Iwai return -ENOMEM; 3747f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 3748f2e5731dSTakashi Iwai if (err < 0) 3749f2e5731dSTakashi Iwai return err; 3750f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 3751f2e5731dSTakashi Iwai break; 3752f2e5731dSTakashi Iwai } 3753f2e5731dSTakashi Iwai return 0; 3754f2e5731dSTakashi Iwai } 3755f2e5731dSTakashi Iwai 3756f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 3757f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 3758f2e5731dSTakashi Iwai 3759f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 3760f2e5731dSTakashi Iwai { 3761f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3762f2e5731dSTakashi Iwai int i, err; 3763f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 3764ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 3765f2e5731dSTakashi Iwai 3766f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 3767f2e5731dSTakashi Iwai return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac, 3768f2e5731dSTakashi Iwai "Master", 0); 3769f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3770f2e5731dSTakashi Iwai const char *label; 3771f2e5731dSTakashi Iwai int idx, type; 3772f2e5731dSTakashi Iwai if (!spec->dac_info[i].dac) 3773f2e5731dSTakashi Iwai continue; 3774f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 3775f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 3776f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 3777f2e5731dSTakashi Iwai switch (type) { 3778f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3779f2e5731dSTakashi Iwai default: 3780f2e5731dSTakashi Iwai label = texts[num_line++]; 3781f2e5731dSTakashi Iwai idx = 0; 3782f2e5731dSTakashi Iwai break; 3783f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3784f2e5731dSTakashi Iwai label = "Headphone"; 3785f2e5731dSTakashi Iwai idx = num_hp++; 3786f2e5731dSTakashi Iwai break; 3787f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3788f2e5731dSTakashi Iwai label = "Speaker"; 3789f2e5731dSTakashi Iwai idx = num_spk++; 3790f2e5731dSTakashi Iwai break; 3791f2e5731dSTakashi Iwai } 3792f2e5731dSTakashi Iwai err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac, 3793f2e5731dSTakashi Iwai label, idx); 3794f2e5731dSTakashi Iwai if (err < 0) 3795f2e5731dSTakashi Iwai return err; 3796f2e5731dSTakashi Iwai } 3797f2e5731dSTakashi Iwai return 0; 3798f2e5731dSTakashi Iwai } 3799f2e5731dSTakashi Iwai 3800f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 3801f2e5731dSTakashi Iwai { 3802f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3803f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3804f2e5731dSTakashi Iwai static const char *prev_label; 3805f2e5731dSTakashi Iwai int i, err, cidx; 3806f2e5731dSTakashi Iwai 3807f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0], 3808f2e5731dSTakashi Iwai HDA_INPUT); 3809f2e5731dSTakashi Iwai if (err < 0) 3810f2e5731dSTakashi Iwai return err; 3811f2e5731dSTakashi Iwai prev_label = NULL; 3812f2e5731dSTakashi Iwai cidx = 0; 3813f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3814f2e5731dSTakashi Iwai hda_nid_t nid = cfg->inputs[i].pin; 3815f2e5731dSTakashi Iwai const char *label; 3816f2e5731dSTakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 3817f2e5731dSTakashi Iwai continue; 3818f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3819f2e5731dSTakashi Iwai if (label == prev_label) 3820f2e5731dSTakashi Iwai cidx++; 3821f2e5731dSTakashi Iwai else 3822f2e5731dSTakashi Iwai cidx = 0; 3823f2e5731dSTakashi Iwai prev_label = label; 3824f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, label, " Capture", cidx, 3825f2e5731dSTakashi Iwai nid, HDA_INPUT); 3826f2e5731dSTakashi Iwai if (err < 0) 3827f2e5731dSTakashi Iwai return err; 3828f2e5731dSTakashi Iwai } 3829f2e5731dSTakashi Iwai return 0; 3830f2e5731dSTakashi Iwai } 3831f2e5731dSTakashi Iwai 3832f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 3833f2e5731dSTakashi Iwai { 3834f2e5731dSTakashi Iwai int err; 3835f2e5731dSTakashi Iwai 3836f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 3837f2e5731dSTakashi Iwai if (err < 0) 3838f2e5731dSTakashi Iwai return err; 3839f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 3840f2e5731dSTakashi Iwai if (err < 0) 3841f2e5731dSTakashi Iwai return err; 3842f2e5731dSTakashi Iwai return conexant_build_controls(codec); 3843f2e5731dSTakashi Iwai } 3844f2e5731dSTakashi Iwai 3845f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = { 3846f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 3847f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 3848f2e5731dSTakashi Iwai .init = cx_auto_init, 3849f2e5731dSTakashi Iwai .free = conexant_free, 3850f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 3851f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 3852f2e5731dSTakashi Iwai .suspend = conexant_suspend, 3853f2e5731dSTakashi Iwai #endif 3854f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 3855f2e5731dSTakashi Iwai }; 3856f2e5731dSTakashi Iwai 3857f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 3858f2e5731dSTakashi Iwai { 3859f2e5731dSTakashi Iwai struct conexant_spec *spec; 3860f2e5731dSTakashi Iwai int err; 3861f2e5731dSTakashi Iwai 3862f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3863f2e5731dSTakashi Iwai if (!spec) 3864f2e5731dSTakashi Iwai return -ENOMEM; 3865f2e5731dSTakashi Iwai codec->spec = spec; 3866f2e5731dSTakashi Iwai spec->adc_nids = cx_auto_adc_nids; 3867f2e5731dSTakashi Iwai spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids); 3868f2e5731dSTakashi Iwai spec->capsrc_nids = spec->adc_nids; 3869f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 3870f2e5731dSTakashi Iwai if (err < 0) { 3871f2e5731dSTakashi Iwai kfree(codec->spec); 3872f2e5731dSTakashi Iwai codec->spec = NULL; 3873f2e5731dSTakashi Iwai return err; 3874f2e5731dSTakashi Iwai } 3875f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 3876f2e5731dSTakashi Iwai if (spec->beep_amp) 3877f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 3878f2e5731dSTakashi Iwai return 0; 3879f2e5731dSTakashi Iwai } 3880f2e5731dSTakashi Iwai 3881f2e5731dSTakashi Iwai /* 3882461e2c78STakashi Iwai */ 3883461e2c78STakashi Iwai 38841289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 388582f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 388682f30040STobin Davis .patch = patch_cxt5045 }, 388782f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 388882f30040STobin Davis .patch = patch_cxt5047 }, 3889461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 3890461e2c78STakashi Iwai .patch = patch_cxt5051 }, 38910fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 38920fb67e98SDaniel Drake .patch = patch_cxt5066 }, 389395a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 389495a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 3895850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 3896850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 38977b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 38987b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 3899f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 3900f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3901f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 3902f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3903f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 3904f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3905f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 3906f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3907f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 3908f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3909f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 3910f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3911f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 3912f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3913f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 3914f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3915c9b443d4STobin Davis {} /* terminator */ 3916c9b443d4STobin Davis }; 39171289e9e8STakashi Iwai 39181289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 39191289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 39201289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 39210fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 392295a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 3923850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 39247b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 3925f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 3926f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 3927f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 3928f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 3929f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 3930f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 3931f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 3932f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 39331289e9e8STakashi Iwai 39341289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 39351289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 39361289e9e8STakashi Iwai 39371289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 39381289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 39391289e9e8STakashi Iwai .owner = THIS_MODULE, 39401289e9e8STakashi Iwai }; 39411289e9e8STakashi Iwai 39421289e9e8STakashi Iwai static int __init patch_conexant_init(void) 39431289e9e8STakashi Iwai { 39441289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 39451289e9e8STakashi Iwai } 39461289e9e8STakashi Iwai 39471289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 39481289e9e8STakashi Iwai { 39491289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 39501289e9e8STakashi Iwai } 39511289e9e8STakashi Iwai 39521289e9e8STakashi Iwai module_init(patch_conexant_init) 39531289e9e8STakashi Iwai module_exit(patch_conexant_exit) 3954