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; 88c9b443d4STobin Davis 89c9b443d4STobin Davis /* capture */ 90c9b443d4STobin Davis unsigned int num_adc_nids; 91c9b443d4STobin Davis hda_nid_t *adc_nids; 92c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 93c9b443d4STobin Davis 94461e2c78STakashi Iwai unsigned int cur_adc_idx; 95461e2c78STakashi Iwai hda_nid_t cur_adc; 96461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 97461e2c78STakashi Iwai unsigned int cur_adc_format; 98461e2c78STakashi Iwai 99c9b443d4STobin Davis /* capture source */ 100c9b443d4STobin Davis const struct hda_input_mux *input_mux; 101c9b443d4STobin Davis hda_nid_t *capsrc_nids; 102c9b443d4STobin Davis unsigned int cur_mux[3]; 103c9b443d4STobin Davis 104c9b443d4STobin Davis /* channel model */ 105c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 106c9b443d4STobin Davis int num_channel_mode; 107c9b443d4STobin Davis 108c9b443d4STobin Davis /* PCM information */ 109c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 110c9b443d4STobin Davis 111c9b443d4STobin Davis unsigned int spdif_route; 112c9b443d4STobin Davis 113bc7a166dSUlrich Dangel /* jack detection */ 114bc7a166dSUlrich Dangel struct snd_array jacks; 115bc7a166dSUlrich Dangel 116c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 117c9b443d4STobin Davis struct auto_pin_cfg autocfg; 118c9b443d4STobin Davis struct hda_input_mux private_imux; 11941923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 120f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 121f2e5731dSTakashi Iwai int dac_info_filled; 122c9b443d4STobin Davis 1230fb67e98SDaniel Drake unsigned int port_d_mode; 124f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 125f2e5731dSTakashi Iwai unsigned int dell_automute:1; 126cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 127cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1287b2bfdbcSJens Taprogge unsigned int thinkpad:1; 129048e78a5SDavid Henningsson unsigned int hp_laptop:1; 13075f8991dSDaniel Drake 13175f8991dSDaniel Drake unsigned int ext_mic_present; 13275f8991dSDaniel Drake unsigned int recording; 13375f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 13475f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 135c4cfe66cSDaniel Drake 136c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 137c4cfe66cSDaniel Drake * through the microphone jack. 138c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 139c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 140c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 141c4cfe66cSDaniel Drake * control. */ 142c4cfe66cSDaniel Drake unsigned int dc_enable; 143c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 144c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1453507e2a8STakashi Iwai 1463507e2a8STakashi Iwai unsigned int beep_amp; 147c9b443d4STobin Davis }; 148c9b443d4STobin Davis 149c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 150c9b443d4STobin Davis struct hda_codec *codec, 151c9b443d4STobin Davis struct snd_pcm_substream *substream) 152c9b443d4STobin Davis { 153c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1549a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1559a08160bSTakashi Iwai hinfo); 156c9b443d4STobin Davis } 157c9b443d4STobin Davis 158c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 159c9b443d4STobin Davis struct hda_codec *codec, 160c9b443d4STobin Davis unsigned int stream_tag, 161c9b443d4STobin Davis unsigned int format, 162c9b443d4STobin Davis struct snd_pcm_substream *substream) 163c9b443d4STobin Davis { 164c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 165c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 166c9b443d4STobin Davis stream_tag, 167c9b443d4STobin Davis format, substream); 168c9b443d4STobin Davis } 169c9b443d4STobin Davis 170c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 171c9b443d4STobin Davis struct hda_codec *codec, 172c9b443d4STobin Davis struct snd_pcm_substream *substream) 173c9b443d4STobin Davis { 174c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 175c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 176c9b443d4STobin Davis } 177c9b443d4STobin Davis 178c9b443d4STobin Davis /* 179c9b443d4STobin Davis * Digital out 180c9b443d4STobin Davis */ 181c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 182c9b443d4STobin Davis struct hda_codec *codec, 183c9b443d4STobin Davis struct snd_pcm_substream *substream) 184c9b443d4STobin Davis { 185c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 186c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 187c9b443d4STobin Davis } 188c9b443d4STobin Davis 189c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 190c9b443d4STobin Davis struct hda_codec *codec, 191c9b443d4STobin Davis struct snd_pcm_substream *substream) 192c9b443d4STobin Davis { 193c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 194c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 195c9b443d4STobin Davis } 196c9b443d4STobin Davis 1976b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1986b97eb45STakashi Iwai struct hda_codec *codec, 1996b97eb45STakashi Iwai unsigned int stream_tag, 2006b97eb45STakashi Iwai unsigned int format, 2016b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2026b97eb45STakashi Iwai { 2036b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2046b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2056b97eb45STakashi Iwai stream_tag, 2066b97eb45STakashi Iwai format, substream); 2076b97eb45STakashi Iwai } 2086b97eb45STakashi Iwai 209c9b443d4STobin Davis /* 210c9b443d4STobin Davis * Analog capture 211c9b443d4STobin Davis */ 212c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 213c9b443d4STobin Davis struct hda_codec *codec, 214c9b443d4STobin Davis unsigned int stream_tag, 215c9b443d4STobin Davis unsigned int format, 216c9b443d4STobin Davis struct snd_pcm_substream *substream) 217c9b443d4STobin Davis { 218c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 21975f8991dSDaniel Drake if (spec->capture_prepare) 22075f8991dSDaniel Drake spec->capture_prepare(codec); 221c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 222c9b443d4STobin Davis stream_tag, 0, format); 223c9b443d4STobin Davis return 0; 224c9b443d4STobin Davis } 225c9b443d4STobin Davis 226c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 227c9b443d4STobin Davis struct hda_codec *codec, 228c9b443d4STobin Davis struct snd_pcm_substream *substream) 229c9b443d4STobin Davis { 230c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 231888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 23275f8991dSDaniel Drake if (spec->capture_cleanup) 23375f8991dSDaniel Drake spec->capture_cleanup(codec); 234c9b443d4STobin Davis return 0; 235c9b443d4STobin Davis } 236c9b443d4STobin Davis 237c9b443d4STobin Davis 238c9b443d4STobin Davis 239c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 240c9b443d4STobin Davis .substreams = 1, 241c9b443d4STobin Davis .channels_min = 2, 242c9b443d4STobin Davis .channels_max = 2, 243c9b443d4STobin Davis .nid = 0, /* fill later */ 244c9b443d4STobin Davis .ops = { 245c9b443d4STobin Davis .open = conexant_playback_pcm_open, 246c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 247c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 248c9b443d4STobin Davis }, 249c9b443d4STobin Davis }; 250c9b443d4STobin Davis 251c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 252c9b443d4STobin Davis .substreams = 1, 253c9b443d4STobin Davis .channels_min = 2, 254c9b443d4STobin Davis .channels_max = 2, 255c9b443d4STobin Davis .nid = 0, /* fill later */ 256c9b443d4STobin Davis .ops = { 257c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 258c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 259c9b443d4STobin Davis }, 260c9b443d4STobin Davis }; 261c9b443d4STobin Davis 262c9b443d4STobin Davis 263c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 264c9b443d4STobin Davis .substreams = 1, 265c9b443d4STobin Davis .channels_min = 2, 266c9b443d4STobin Davis .channels_max = 2, 267c9b443d4STobin Davis .nid = 0, /* fill later */ 268c9b443d4STobin Davis .ops = { 269c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2706b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2716b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 272c9b443d4STobin Davis }, 273c9b443d4STobin Davis }; 274c9b443d4STobin Davis 275c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 276c9b443d4STobin Davis .substreams = 1, 277c9b443d4STobin Davis .channels_min = 2, 278c9b443d4STobin Davis .channels_max = 2, 279c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 280c9b443d4STobin Davis }; 281c9b443d4STobin Davis 282461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 283461e2c78STakashi Iwai struct hda_codec *codec, 284461e2c78STakashi Iwai unsigned int stream_tag, 285461e2c78STakashi Iwai unsigned int format, 286461e2c78STakashi Iwai struct snd_pcm_substream *substream) 287461e2c78STakashi Iwai { 288461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 289461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 290461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 291461e2c78STakashi Iwai spec->cur_adc_format = format; 292461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 293461e2c78STakashi Iwai return 0; 294461e2c78STakashi Iwai } 295461e2c78STakashi Iwai 296461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 297461e2c78STakashi Iwai struct hda_codec *codec, 298461e2c78STakashi Iwai struct snd_pcm_substream *substream) 299461e2c78STakashi Iwai { 300461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 301888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 302461e2c78STakashi Iwai spec->cur_adc = 0; 303461e2c78STakashi Iwai return 0; 304461e2c78STakashi Iwai } 305461e2c78STakashi Iwai 306461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 307461e2c78STakashi Iwai .substreams = 1, 308461e2c78STakashi Iwai .channels_min = 2, 309461e2c78STakashi Iwai .channels_max = 2, 310461e2c78STakashi Iwai .nid = 0, /* fill later */ 311461e2c78STakashi Iwai .ops = { 312461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 313461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 314461e2c78STakashi Iwai }, 315461e2c78STakashi Iwai }; 316461e2c78STakashi Iwai 317c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 318c9b443d4STobin Davis { 319c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 320c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 321c9b443d4STobin Davis 322c9b443d4STobin Davis codec->num_pcms = 1; 323c9b443d4STobin Davis codec->pcm_info = info; 324c9b443d4STobin Davis 325c9b443d4STobin Davis info->name = "CONEXANT Analog"; 326c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 327c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 328c9b443d4STobin Davis spec->multiout.max_channels; 329c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 330c9b443d4STobin Davis spec->multiout.dac_nids[0]; 331461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 332461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 333461e2c78STakashi Iwai cx5051_pcm_analog_capture; 334461e2c78STakashi Iwai else 335461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 336461e2c78STakashi Iwai conexant_pcm_analog_capture; 337c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 338c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 339c9b443d4STobin Davis 340c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 341c9b443d4STobin Davis info++; 342c9b443d4STobin Davis codec->num_pcms++; 343c9b443d4STobin Davis info->name = "Conexant Digital"; 3447ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 345c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 346c9b443d4STobin Davis conexant_pcm_digital_playback; 347c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 348c9b443d4STobin Davis spec->multiout.dig_out_nid; 349c9b443d4STobin Davis if (spec->dig_in_nid) { 350c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 351c9b443d4STobin Davis conexant_pcm_digital_capture; 352c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 353c9b443d4STobin Davis spec->dig_in_nid; 354c9b443d4STobin Davis } 355c9b443d4STobin Davis } 356c9b443d4STobin Davis 357c9b443d4STobin Davis return 0; 358c9b443d4STobin Davis } 359c9b443d4STobin Davis 360c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 361c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 362c9b443d4STobin Davis { 363c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 364c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 365c9b443d4STobin Davis 366c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 367c9b443d4STobin Davis } 368c9b443d4STobin Davis 369c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 370c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 371c9b443d4STobin Davis { 372c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 373c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 374c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 375c9b443d4STobin Davis 376c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 377c9b443d4STobin Davis return 0; 378c9b443d4STobin Davis } 379c9b443d4STobin Davis 380c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 381c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 382c9b443d4STobin Davis { 383c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 384c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 385c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 386c9b443d4STobin Davis 387c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 388c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 389c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 390c9b443d4STobin Davis } 391c9b443d4STobin Davis 3928c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 39395c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack) 39495c09099STakashi Iwai { 39595c09099STakashi Iwai struct conexant_jack *jacks = jack->private_data; 39695c09099STakashi Iwai jacks->nid = 0; 39795c09099STakashi Iwai jacks->jack = NULL; 39895c09099STakashi Iwai } 39995c09099STakashi Iwai 400bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 401bc7a166dSUlrich Dangel hda_nid_t nid, int type) 402bc7a166dSUlrich Dangel { 403bc7a166dSUlrich Dangel struct conexant_spec *spec; 404bc7a166dSUlrich Dangel struct conexant_jack *jack; 405bc7a166dSUlrich Dangel const char *name; 40695c09099STakashi Iwai int err; 407bc7a166dSUlrich Dangel 408bc7a166dSUlrich Dangel spec = codec->spec; 409bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 410bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 411bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 412bc7a166dSUlrich Dangel 413bc7a166dSUlrich Dangel if (!jack) 414bc7a166dSUlrich Dangel return -ENOMEM; 415bc7a166dSUlrich Dangel 416bc7a166dSUlrich Dangel jack->nid = nid; 417bc7a166dSUlrich Dangel jack->type = type; 418bc7a166dSUlrich Dangel 41995c09099STakashi Iwai err = snd_jack_new(codec->bus->card, name, type, &jack->jack); 42095c09099STakashi Iwai if (err < 0) 42195c09099STakashi Iwai return err; 42295c09099STakashi Iwai jack->jack->private_data = jack; 42395c09099STakashi Iwai jack->jack->private_free = conexant_free_jack_priv; 42495c09099STakashi Iwai return 0; 425bc7a166dSUlrich Dangel } 426bc7a166dSUlrich Dangel 427bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 428bc7a166dSUlrich Dangel { 429bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 430bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 431bc7a166dSUlrich Dangel 432bc7a166dSUlrich Dangel if (jacks) { 433bc7a166dSUlrich Dangel int i; 434bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 435bc7a166dSUlrich Dangel if (jacks->nid == nid) { 436bc7a166dSUlrich Dangel unsigned int present; 437d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, nid); 438bc7a166dSUlrich Dangel 439bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 440bc7a166dSUlrich Dangel 441bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 442bc7a166dSUlrich Dangel present); 443bc7a166dSUlrich Dangel } 444bc7a166dSUlrich Dangel jacks++; 445bc7a166dSUlrich Dangel } 446bc7a166dSUlrich Dangel } 447bc7a166dSUlrich Dangel } 448bc7a166dSUlrich Dangel 449bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 450bc7a166dSUlrich Dangel { 451bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 452bc7a166dSUlrich Dangel int i; 453bc7a166dSUlrich Dangel 454bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 455bc7a166dSUlrich Dangel const struct hda_verb *hv; 456bc7a166dSUlrich Dangel 457bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 458bc7a166dSUlrich Dangel while (hv->nid) { 459bc7a166dSUlrich Dangel int err = 0; 460bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 461bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 462bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 463bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 464bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 465bc7a166dSUlrich Dangel break; 466bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 467bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 468bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 469bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 470bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 471bc7a166dSUlrich Dangel break; 472bc7a166dSUlrich Dangel } 473bc7a166dSUlrich Dangel if (err < 0) 474bc7a166dSUlrich Dangel return err; 475bc7a166dSUlrich Dangel ++hv; 476bc7a166dSUlrich Dangel } 477bc7a166dSUlrich Dangel } 478bc7a166dSUlrich Dangel return 0; 479bc7a166dSUlrich Dangel 480bc7a166dSUlrich Dangel } 4815801f992STakashi Iwai #else 4825801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4835801f992STakashi Iwai { 4845801f992STakashi Iwai } 4855801f992STakashi Iwai 4865801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4875801f992STakashi Iwai { 4885801f992STakashi Iwai return 0; 4895801f992STakashi Iwai } 4905801f992STakashi Iwai #endif 491bc7a166dSUlrich Dangel 492c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 493c9b443d4STobin Davis { 494c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 495c9b443d4STobin Davis int i; 496c9b443d4STobin Davis 497c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 498c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 499c9b443d4STobin Davis return 0; 500c9b443d4STobin Davis } 501c9b443d4STobin Davis 502c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 503c9b443d4STobin Davis { 5048c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 505bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 506bc7a166dSUlrich Dangel if (spec->jacks.list) { 507bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 508bc7a166dSUlrich Dangel int i; 50995c09099STakashi Iwai for (i = 0; i < spec->jacks.used; i++, jacks++) { 51095c09099STakashi Iwai if (jacks->jack) 51195c09099STakashi Iwai snd_device_free(codec->bus->card, jacks->jack); 51295c09099STakashi Iwai } 513bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 514bc7a166dSUlrich Dangel } 515bc7a166dSUlrich Dangel #endif 516c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 517c9b443d4STobin Davis kfree(codec->spec); 518c9b443d4STobin Davis } 519c9b443d4STobin Davis 520b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = { 521b880c74aSTakashi Iwai { 522b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 523b880c74aSTakashi Iwai .name = "Capture Source", 524b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 525b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 526b880c74aSTakashi Iwai .put = conexant_mux_enum_put 527b880c74aSTakashi Iwai }, 528b880c74aSTakashi Iwai {} 529b880c74aSTakashi Iwai }; 530b880c74aSTakashi Iwai 5313507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5323507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 5333507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = { 5343507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 5353507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 5363507e2a8STakashi Iwai { } /* end */ 5373507e2a8STakashi Iwai }; 5383507e2a8STakashi Iwai #endif 5393507e2a8STakashi Iwai 540dd5746a8STakashi Iwai static const char *slave_vols[] = { 541dd5746a8STakashi Iwai "Headphone Playback Volume", 542dd5746a8STakashi Iwai "Speaker Playback Volume", 543dd5746a8STakashi Iwai NULL 544dd5746a8STakashi Iwai }; 545dd5746a8STakashi Iwai 546dd5746a8STakashi Iwai static const char *slave_sws[] = { 547dd5746a8STakashi Iwai "Headphone Playback Switch", 548dd5746a8STakashi Iwai "Speaker Playback Switch", 549dd5746a8STakashi Iwai NULL 550dd5746a8STakashi Iwai }; 551dd5746a8STakashi Iwai 552c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 553c9b443d4STobin Davis { 554c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 555c9b443d4STobin Davis unsigned int i; 556c9b443d4STobin Davis int err; 557c9b443d4STobin Davis 558c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 559c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 560c9b443d4STobin Davis if (err < 0) 561c9b443d4STobin Davis return err; 562c9b443d4STobin Davis } 563c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 564c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 565c9b443d4STobin Davis spec->multiout.dig_out_nid); 566c9b443d4STobin Davis if (err < 0) 567c9b443d4STobin Davis return err; 5689a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5699a08160bSTakashi Iwai &spec->multiout); 5709a08160bSTakashi Iwai if (err < 0) 5719a08160bSTakashi Iwai return err; 5729a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 573c9b443d4STobin Davis } 574c9b443d4STobin Davis if (spec->dig_in_nid) { 575c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 576c9b443d4STobin Davis if (err < 0) 577c9b443d4STobin Davis return err; 578c9b443d4STobin Davis } 579dd5746a8STakashi Iwai 580dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 581dd5746a8STakashi Iwai if (spec->vmaster_nid && 582dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 583dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 584dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 585dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 586dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 587dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 588dd5746a8STakashi Iwai if (err < 0) 589dd5746a8STakashi Iwai return err; 590dd5746a8STakashi Iwai } 591dd5746a8STakashi Iwai if (spec->vmaster_nid && 592dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 593dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 594dd5746a8STakashi Iwai NULL, slave_sws); 595dd5746a8STakashi Iwai if (err < 0) 596dd5746a8STakashi Iwai return err; 597dd5746a8STakashi Iwai } 598dd5746a8STakashi Iwai 599b880c74aSTakashi Iwai if (spec->input_mux) { 600b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 601b880c74aSTakashi Iwai if (err < 0) 602b880c74aSTakashi Iwai return err; 603b880c74aSTakashi Iwai } 604b880c74aSTakashi Iwai 6053507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6063507e2a8STakashi Iwai /* create beep controls if needed */ 6073507e2a8STakashi Iwai if (spec->beep_amp) { 6083507e2a8STakashi Iwai struct snd_kcontrol_new *knew; 6093507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 6103507e2a8STakashi Iwai struct snd_kcontrol *kctl; 6113507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 6123507e2a8STakashi Iwai if (!kctl) 6133507e2a8STakashi Iwai return -ENOMEM; 6143507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 6153507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 6163507e2a8STakashi Iwai if (err < 0) 6173507e2a8STakashi Iwai return err; 6183507e2a8STakashi Iwai } 6193507e2a8STakashi Iwai } 6203507e2a8STakashi Iwai #endif 6213507e2a8STakashi Iwai 622c9b443d4STobin Davis return 0; 623c9b443d4STobin Davis } 624c9b443d4STobin Davis 625697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 626697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 627697c373eSTakashi Iwai { 628697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 629697c373eSTakashi Iwai return 0; 630697c373eSTakashi Iwai } 631697c373eSTakashi Iwai #endif 632697c373eSTakashi Iwai 633c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 634c9b443d4STobin Davis .build_controls = conexant_build_controls, 635c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 636c9b443d4STobin Davis .init = conexant_init, 637c9b443d4STobin Davis .free = conexant_free, 638697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 639697c373eSTakashi Iwai .suspend = conexant_suspend, 640697c373eSTakashi Iwai #endif 641697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 642c9b443d4STobin Davis }; 643c9b443d4STobin Davis 6443507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6453507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 6463507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 6473507e2a8STakashi Iwai #else 6483507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 6493507e2a8STakashi Iwai #endif 6503507e2a8STakashi Iwai 651c9b443d4STobin Davis /* 652c9b443d4STobin Davis * EAPD control 653c9b443d4STobin Davis * the private value = nid | (invert << 8) 654c9b443d4STobin Davis */ 655c9b443d4STobin Davis 656a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 657c9b443d4STobin Davis 65882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 659c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 660c9b443d4STobin Davis { 661c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 662c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 663c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 664c9b443d4STobin Davis if (invert) 665c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 666c9b443d4STobin Davis else 667c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 668c9b443d4STobin Davis return 0; 66982f30040STobin Davis 670c9b443d4STobin Davis } 671c9b443d4STobin Davis 67282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 673c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 674c9b443d4STobin Davis { 675c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 676c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 677c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 678c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 679c9b443d4STobin Davis unsigned int eapd; 68082f30040STobin Davis 68168ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 682c9b443d4STobin Davis if (invert) 683c9b443d4STobin Davis eapd = !eapd; 68482beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 685c9b443d4STobin Davis return 0; 68682f30040STobin Davis 687c9b443d4STobin Davis spec->cur_eapd = eapd; 68882beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 689c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 690c9b443d4STobin Davis eapd ? 0x02 : 0x00); 691c9b443d4STobin Davis return 1; 692c9b443d4STobin Davis } 693c9b443d4STobin Davis 69486d72bdfSTakashi Iwai /* controls for test mode */ 69586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 69686d72bdfSTakashi Iwai 69782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 69882f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 69982f30040STobin Davis .info = cxt_eapd_info, \ 70082f30040STobin Davis .get = cxt_eapd_get, \ 70182f30040STobin Davis .put = cxt_eapd_put, \ 70282f30040STobin Davis .private_value = nid | (mask<<16) } 70382f30040STobin Davis 70482f30040STobin Davis 70582f30040STobin Davis 706c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 707c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 708c9b443d4STobin Davis { 709c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 710c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 711c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 712c9b443d4STobin Davis spec->num_channel_mode); 713c9b443d4STobin Davis } 714c9b443d4STobin Davis 715c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 716c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 717c9b443d4STobin Davis { 718c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 719c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 720c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 721c9b443d4STobin Davis spec->num_channel_mode, 722c9b443d4STobin Davis spec->multiout.max_channels); 723c9b443d4STobin Davis } 724c9b443d4STobin Davis 725c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 726c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 727c9b443d4STobin Davis { 728c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 729c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 730c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 731c9b443d4STobin Davis spec->num_channel_mode, 732c9b443d4STobin Davis &spec->multiout.max_channels); 733c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 734c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 735c9b443d4STobin Davis return err; 736c9b443d4STobin Davis } 737c9b443d4STobin Davis 738c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 739c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 740c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 741c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 742c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 743c9b443d4STobin Davis .private_value = nid | (dir<<16) } 744c9b443d4STobin Davis 74586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 74686d72bdfSTakashi Iwai 747c9b443d4STobin Davis /* Conexant 5045 specific */ 748c9b443d4STobin Davis 749c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 750c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 751c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 752cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 753c9b443d4STobin Davis 7545cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 7555cd57529STobin Davis { 2, NULL }, 7565cd57529STobin Davis }; 757c9b443d4STobin Davis 758c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 759c9b443d4STobin Davis .num_items = 2, 760c9b443d4STobin Davis .items = { 76182f30040STobin Davis { "IntMic", 0x1 }, 762f4beee94SJiang zhe { "ExtMic", 0x2 }, 763c9b443d4STobin Davis } 764c9b443d4STobin Davis }; 765c9b443d4STobin Davis 7665218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 76722e14130SLukasz Marcinowski .num_items = 5, 7685218c892SJiang Zhe .items = { 7695218c892SJiang Zhe { "IntMic", 0x1 }, 7705218c892SJiang Zhe { "ExtMic", 0x2 }, 7715218c892SJiang Zhe { "LineIn", 0x3 }, 77222e14130SLukasz Marcinowski { "CD", 0x4 }, 77322e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7745218c892SJiang Zhe } 7755218c892SJiang Zhe }; 7765218c892SJiang Zhe 7772de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 7782de3c232SJiang zhe .num_items = 2, 7792de3c232SJiang zhe .items = { 7802de3c232SJiang zhe { "ExtMic", 0x1 }, 7812de3c232SJiang zhe { "IntMic", 0x2 }, 7822de3c232SJiang zhe } 7832de3c232SJiang zhe }; 7842de3c232SJiang zhe 785c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 786c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 787c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 788c9b443d4STobin Davis { 789c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 790c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 79182f30040STobin Davis unsigned int bits; 792c9b443d4STobin Davis 79382f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 794c9b443d4STobin Davis return 0; 795c9b443d4STobin Davis 79682f30040STobin Davis /* toggle internal speakers mute depending of presence of 79782f30040STobin Davis * the headphone jack 79882f30040STobin Davis */ 79947fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 80047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 80147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 8027f29673bSTobin Davis 80347fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 80447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 80547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 806c9b443d4STobin Davis return 1; 807c9b443d4STobin Davis } 808c9b443d4STobin Davis 809c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 810cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 811cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 812cca3b371STakashi Iwai .values = { 813cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 814cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 815cca3b371STakashi Iwai 0 816cca3b371STakashi Iwai }, 817cca3b371STakashi Iwai }; 818c9b443d4STobin Davis 8197f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 8207f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 8217f29673bSTobin Davis { 8227f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 8237f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8247f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8257f29673bSTobin Davis {} 8267f29673bSTobin Davis }; 8277f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 8287f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8297f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8307f29673bSTobin Davis {} 8317f29673bSTobin Davis }; 8327f29673bSTobin Davis unsigned int present; 8337f29673bSTobin Davis 834d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 8357f29673bSTobin Davis if (present) 8367f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 8377f29673bSTobin Davis else 8387f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 8397f29673bSTobin Davis } 8407f29673bSTobin Davis 841c9b443d4STobin Davis 842c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 843c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 844c9b443d4STobin Davis { 84582f30040STobin Davis struct conexant_spec *spec = codec->spec; 846dd87da1cSTobin Davis unsigned int bits; 847c9b443d4STobin Davis 848d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 849dd87da1cSTobin Davis 85047fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 85147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 85247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 853c9b443d4STobin Davis } 854c9b443d4STobin Davis 855c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 856c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 857c9b443d4STobin Davis unsigned int res) 858c9b443d4STobin Davis { 859c9b443d4STobin Davis res >>= 26; 860c9b443d4STobin Davis switch (res) { 861c9b443d4STobin Davis case CONEXANT_HP_EVENT: 862c9b443d4STobin Davis cxt5045_hp_automute(codec); 863c9b443d4STobin Davis break; 8647f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8657f29673bSTobin Davis cxt5045_hp_automic(codec); 8667f29673bSTobin Davis break; 8677f29673bSTobin Davis 868c9b443d4STobin Davis } 869c9b443d4STobin Davis } 870c9b443d4STobin Davis 871c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 872c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 873c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 874c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 875c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 876c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 877c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 878c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 879c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 880c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 881c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 882cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 883c9b443d4STobin Davis { 884c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 885c9b443d4STobin Davis .name = "Master Playback Switch", 88682f30040STobin Davis .info = cxt_eapd_info, 88782f30040STobin Davis .get = cxt_eapd_get, 888c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 88982f30040STobin Davis .private_value = 0x10, 890c9b443d4STobin Davis }, 891c9b443d4STobin Davis 892c9b443d4STobin Davis {} 893c9b443d4STobin Davis }; 894c9b443d4STobin Davis 8955218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 89622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 89722e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 89822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 89922e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 90022e14130SLukasz Marcinowski 9015218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 9025218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 9035218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 9045218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 9055218c892SJiang Zhe 90622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 90722e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 90822e14130SLukasz Marcinowski 9095218c892SJiang Zhe {} 9105218c892SJiang Zhe }; 9115218c892SJiang Zhe 9122de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 9132de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 9142de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 9152de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 9162de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 9172de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 9182de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 9192de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 9202de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 9212de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 9222de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 9232de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 9242de3c232SJiang zhe { 9252de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9262de3c232SJiang zhe .name = "Master Playback Switch", 9272de3c232SJiang zhe .info = cxt_eapd_info, 9282de3c232SJiang zhe .get = cxt_eapd_get, 9292de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 9302de3c232SJiang zhe .private_value = 0x10, 9312de3c232SJiang zhe }, 9322de3c232SJiang zhe 9332de3c232SJiang zhe {} 9342de3c232SJiang zhe }; 9352de3c232SJiang zhe 936c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 937c9b443d4STobin Davis /* Line in, Mic */ 9384090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9397f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 940c9b443d4STobin Davis /* HP, Amp */ 941c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 942c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 94382f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 944c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 945c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 946c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 947c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 948c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 949c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 95082f30040STobin Davis /* Record selector: Int mic */ 9517f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 95282f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 953c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 954c9b443d4STobin Davis /* SPDIF route: PCM */ 955cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 956c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 957c9b443d4STobin Davis /* EAPD */ 95882f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 959c9b443d4STobin Davis { } /* end */ 960c9b443d4STobin Davis }; 961c9b443d4STobin Davis 9625218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 9635218c892SJiang Zhe /* Int Mic, Mic */ 9645218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9655218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9665218c892SJiang Zhe /* Line In,HP, Amp */ 9675218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9685218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9695218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9705218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9715218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9725218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9735218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9745218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9755218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 9765218c892SJiang Zhe /* Record selector: Int mic */ 9775218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9785218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9795218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9805218c892SJiang Zhe /* SPDIF route: PCM */ 981cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9825218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9835218c892SJiang Zhe /* EAPD */ 9845218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9855218c892SJiang Zhe { } /* end */ 9865218c892SJiang Zhe }; 9877f29673bSTobin Davis 9887f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9897f29673bSTobin Davis /* pin sensing on HP jack */ 9907f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 991d3091fadSTakashi Iwai { } /* end */ 9927f29673bSTobin Davis }; 9937f29673bSTobin Davis 9947f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9957f29673bSTobin Davis /* pin sensing on HP jack */ 9967f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 997d3091fadSTakashi Iwai { } /* end */ 9987f29673bSTobin Davis }; 9997f29673bSTobin Davis 1000c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1001c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1002c9b443d4STobin Davis * configuration. 1003c9b443d4STobin Davis */ 1004c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 1005c9b443d4STobin Davis .num_items = 5, 1006c9b443d4STobin Davis .items = { 1007c9b443d4STobin Davis { "MIXER", 0x0 }, 1008c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 1009c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 1010c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 1011c9b443d4STobin Davis { "CD pin", 0x4 }, 1012c9b443d4STobin Davis }, 1013c9b443d4STobin Davis }; 1014c9b443d4STobin Davis 1015c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 1016c9b443d4STobin Davis 1017c9b443d4STobin Davis /* Output controls */ 1018c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 1019c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 10207f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 10217f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 10227f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 10237f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1024c9b443d4STobin Davis 1025c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1026c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 1027c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 1028c9b443d4STobin Davis 102982f30040STobin Davis /* EAPD Switch Control */ 103082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 103182f30040STobin Davis 1032c9b443d4STobin Davis /* Loopback mixer controls */ 1033c9b443d4STobin Davis 10347f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 10357f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 10367f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 10377f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 10387f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 10397f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 10407f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 10417f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 10427f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 10437f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 1044c9b443d4STobin Davis { 1045c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1046c9b443d4STobin Davis .name = "Input Source", 1047c9b443d4STobin Davis .info = conexant_mux_enum_info, 1048c9b443d4STobin Davis .get = conexant_mux_enum_get, 1049c9b443d4STobin Davis .put = conexant_mux_enum_put, 1050c9b443d4STobin Davis }, 1051fb3409e7STobin Davis /* Audio input controls */ 1052fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1053fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 1054fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 1055fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 1056fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 1057fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 1058fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1059fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1060fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1061fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1062c9b443d4STobin Davis { } /* end */ 1063c9b443d4STobin Davis }; 1064c9b443d4STobin Davis 1065c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 10667f29673bSTobin Davis /* Set connections */ 10677f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10687f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10697f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1070c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1071c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10727f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1073c9b443d4STobin Davis 1074c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1075c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1076c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1077c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1078c9b443d4STobin Davis * control. 1079c9b443d4STobin Davis */ 1080cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1081cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1082c9b443d4STobin Davis 1083c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1084c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1085c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1086c9b443d4STobin Davis 1087c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1088c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1089c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1090c9b443d4STobin Davis * input/output buffers as needed. 1091c9b443d4STobin Davis */ 1092c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1093c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1094c9b443d4STobin Davis 1095c9b443d4STobin Davis /* Mute capture amp left and right */ 1096c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1097c9b443d4STobin Davis 1098c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1099c9b443d4STobin Davis * pin) 1100c9b443d4STobin Davis */ 1101c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 11027f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1103c9b443d4STobin Davis 1104c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1105c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1106c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1107c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1108c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1109c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1110c9b443d4STobin Davis 1111c9b443d4STobin Davis { } 1112c9b443d4STobin Davis }; 1113c9b443d4STobin Davis #endif 1114c9b443d4STobin Davis 1115c9b443d4STobin Davis 1116c9b443d4STobin Davis /* initialize jack-sensing, too */ 1117c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1118c9b443d4STobin Davis { 1119c9b443d4STobin Davis conexant_init(codec); 1120c9b443d4STobin Davis cxt5045_hp_automute(codec); 1121c9b443d4STobin Davis return 0; 1122c9b443d4STobin Davis } 1123c9b443d4STobin Davis 1124c9b443d4STobin Davis 1125c9b443d4STobin Davis enum { 112615908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 112715908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 112815908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 11295218c892SJiang Zhe CXT5045_BENQ, 11302de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1131c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1132c9b443d4STobin Davis CXT5045_TEST, 1133c9b443d4STobin Davis #endif 1134f5fcc13cSTakashi Iwai CXT5045_MODELS 1135c9b443d4STobin Davis }; 1136c9b443d4STobin Davis 1137f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 113815908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 113915908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 114015908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 11415218c892SJiang Zhe [CXT5045_BENQ] = "benq", 11422de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1143c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1144f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1145c9b443d4STobin Davis #endif 1146f5fcc13cSTakashi Iwai }; 1147c9b443d4STobin Davis 1148f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 11492de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1150dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1151dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 11526a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 11535218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 115415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 115515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 11569e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 11579e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 115815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 115915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 116015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1161dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1162dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 116315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1164c9b443d4STobin Davis {} 1165c9b443d4STobin Davis }; 1166c9b443d4STobin Davis 1167c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1168c9b443d4STobin Davis { 1169c9b443d4STobin Davis struct conexant_spec *spec; 1170c9b443d4STobin Davis int board_config; 1171c9b443d4STobin Davis 1172c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1173c9b443d4STobin Davis if (!spec) 1174c9b443d4STobin Davis return -ENOMEM; 1175c9b443d4STobin Davis codec->spec = spec; 11769421f954STakashi Iwai codec->pin_amp_workaround = 1; 1177c9b443d4STobin Davis 1178c9b443d4STobin Davis spec->multiout.max_channels = 2; 1179c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1180c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1181c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1182c9b443d4STobin Davis spec->num_adc_nids = 1; 1183c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1184c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1185c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1186c9b443d4STobin Davis spec->num_mixers = 1; 1187c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1188c9b443d4STobin Davis spec->num_init_verbs = 1; 1189c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1190c9b443d4STobin Davis spec->spdif_route = 0; 11913507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11923507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11935cd57529STobin Davis 11943507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1195c9b443d4STobin Davis 1196c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1197c9b443d4STobin Davis 1198f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1199f5fcc13cSTakashi Iwai cxt5045_models, 1200f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1201c9b443d4STobin Davis switch (board_config) { 120215908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 12037f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1204c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1205c9b443d4STobin Davis spec->num_init_verbs = 2; 12067f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12077f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 12087f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 12097f29673bSTobin Davis break; 121015908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 121186376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12127f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 12137f29673bSTobin Davis spec->num_init_verbs = 2; 12147f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1215c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1216c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1217c9b443d4STobin Davis break; 121815908c36SMarc Boucher default: 121915908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 122015908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 122115908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 122215908c36SMarc Boucher spec->num_init_verbs = 3; 122315908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 122415908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 122515908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 122615908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 122715908c36SMarc Boucher break; 12285218c892SJiang Zhe case CXT5045_BENQ: 12295218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12305218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 12315218c892SJiang Zhe spec->num_init_verbs = 1; 12325218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 12335218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 12345218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 12355218c892SJiang Zhe spec->num_mixers = 2; 12365218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 12375218c892SJiang Zhe break; 12382de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 12392de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12402de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 12412de3c232SJiang zhe spec->num_init_verbs = 2; 12422de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12432de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 12442de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 12452de3c232SJiang zhe break; 1246c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1247c9b443d4STobin Davis case CXT5045_TEST: 1248c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1249c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1250c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 125115908c36SMarc Boucher break; 125215908c36SMarc Boucher 1253c9b443d4STobin Davis #endif 1254c9b443d4STobin Davis } 125548ecb7e8STakashi Iwai 1256031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1257031005f7STakashi Iwai case 0x103c: 12588f0f5ff6SDaniel T Chen case 0x1631: 12590b587fc4SDaniel T Chen case 0x1734: 12600ebf9e36SDaniel T Chen case 0x17aa: 12610ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12620ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12630ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 126448ecb7e8STakashi Iwai */ 126548ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 126648ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 126748ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 126848ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 126948ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1270031005f7STakashi Iwai break; 1271031005f7STakashi Iwai } 127248ecb7e8STakashi Iwai 12733507e2a8STakashi Iwai if (spec->beep_amp) 12743507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12753507e2a8STakashi Iwai 1276c9b443d4STobin Davis return 0; 1277c9b443d4STobin Davis } 1278c9b443d4STobin Davis 1279c9b443d4STobin Davis 1280c9b443d4STobin Davis /* Conexant 5047 specific */ 128182f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1282c9b443d4STobin Davis 12835b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1284c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1285c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1286c9b443d4STobin Davis 12875cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 12885cd57529STobin Davis { 2, NULL }, 12895cd57529STobin Davis }; 1290c9b443d4STobin Davis 129182f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 129282f30040STobin Davis .num_items = 2, 129382f30040STobin Davis .items = { 129482f30040STobin Davis { "ExtMic", 0x2 }, 129582f30040STobin Davis { "Line-In", 0x1 }, 1296c9b443d4STobin Davis } 1297c9b443d4STobin Davis }; 1298c9b443d4STobin Davis 1299c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1300c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1301c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1302c9b443d4STobin Davis { 1303c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1304c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 130582f30040STobin Davis unsigned int bits; 1306c9b443d4STobin Davis 130782f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1308c9b443d4STobin Davis return 0; 1309c9b443d4STobin Davis 131082f30040STobin Davis /* toggle internal speakers mute depending of presence of 131182f30040STobin Davis * the headphone jack 131282f30040STobin Davis */ 131347fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 13143b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 13153b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 13163b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 13173b7523fcSTakashi Iwai */ 13185d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 131947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 132047fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 132147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 132247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1323c9b443d4STobin Davis return 1; 1324c9b443d4STobin Davis } 1325c9b443d4STobin Davis 1326c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1327c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1328c9b443d4STobin Davis { 132982f30040STobin Davis struct conexant_spec *spec = codec->spec; 1330dd87da1cSTobin Davis unsigned int bits; 1331c9b443d4STobin Davis 1332d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1333dd87da1cSTobin Davis 133447fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 13353b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13365d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 133747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1338c9b443d4STobin Davis } 1339c9b443d4STobin Davis 1340c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1341c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1342c9b443d4STobin Davis { 1343c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 13449f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13459f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1346c9b443d4STobin Davis {} 1347c9b443d4STobin Davis }; 1348c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 13499f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13509f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1351c9b443d4STobin Davis {} 1352c9b443d4STobin Davis }; 1353c9b443d4STobin Davis unsigned int present; 1354c9b443d4STobin Davis 1355d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1356c9b443d4STobin Davis if (present) 1357c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1358c9b443d4STobin Davis else 1359c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1360c9b443d4STobin Davis } 1361c9b443d4STobin Davis 1362c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1363c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1364c9b443d4STobin Davis unsigned int res) 1365c9b443d4STobin Davis { 13669f113e0eSMarc Boucher switch (res >> 26) { 1367c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1368c9b443d4STobin Davis cxt5047_hp_automute(codec); 1369c9b443d4STobin Davis break; 1370c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1371c9b443d4STobin Davis cxt5047_hp_automic(codec); 1372c9b443d4STobin Davis break; 1373c9b443d4STobin Davis } 1374c9b443d4STobin Davis } 1375c9b443d4STobin Davis 1376df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1377df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1378df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1379df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT), 1380c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1381c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1382c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1383c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 138482f30040STobin Davis { 138582f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 138682f30040STobin Davis .name = "Master Playback Switch", 138782f30040STobin Davis .info = cxt_eapd_info, 138882f30040STobin Davis .get = cxt_eapd_get, 1389c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1390c9b443d4STobin Davis .private_value = 0x13, 1391c9b443d4STobin Davis }, 1392c9b443d4STobin Davis 1393c9b443d4STobin Davis {} 1394c9b443d4STobin Davis }; 1395c9b443d4STobin Davis 1396df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13973b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13985d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1399df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1400df481e41STakashi Iwai {} 1401df481e41STakashi Iwai }; 1402df481e41STakashi Iwai 1403df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1404c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1405c9b443d4STobin Davis { } /* end */ 1406c9b443d4STobin Davis }; 1407c9b443d4STobin Davis 1408c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1409c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1410c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1411c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1412c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 14137f29673bSTobin Davis /* HP, Speaker */ 1414b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 14155b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 14165b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 14177f29673bSTobin Davis /* Record selector: Mic */ 14187f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 14197f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 14207f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 14217f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1422c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1423c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1424c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1425c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1426c9b443d4STobin Davis /* SPDIF route: PCM */ 1427c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 142882f30040STobin Davis /* Enable unsolicited events */ 142982f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 143082f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1431c9b443d4STobin Davis { } /* end */ 1432c9b443d4STobin Davis }; 1433c9b443d4STobin Davis 1434c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1435c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 14363b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1437c9b443d4STobin Davis {} 1438c9b443d4STobin Davis }; 1439c9b443d4STobin Davis 1440c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1441c9b443d4STobin Davis * configuration. 1442c9b443d4STobin Davis */ 1443c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1444c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 144582f30040STobin Davis .num_items = 4, 1446c9b443d4STobin Davis .items = { 144782f30040STobin Davis { "LINE1 pin", 0x0 }, 144882f30040STobin Davis { "MIC1 pin", 0x1 }, 144982f30040STobin Davis { "MIC2 pin", 0x2 }, 145082f30040STobin Davis { "CD pin", 0x3 }, 1451c9b443d4STobin Davis }, 1452c9b443d4STobin Davis }; 1453c9b443d4STobin Davis 1454c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1455c9b443d4STobin Davis 1456c9b443d4STobin Davis /* Output only controls */ 145782f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 145882f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 145982f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 146082f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1461c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1462c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1463c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1464c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 146582f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 146682f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 146782f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 146882f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1469c9b443d4STobin Davis 1470c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1471c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1472c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1473c9b443d4STobin Davis 147482f30040STobin Davis /* EAPD Switch Control */ 147582f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 147682f30040STobin Davis 1477c9b443d4STobin Davis /* Loopback mixer controls */ 147882f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 147982f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 148082f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 148182f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 148282f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 148382f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 148482f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 148582f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1486c9b443d4STobin Davis 148782f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 148882f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 148982f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 149082f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 149182f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 149282f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 149382f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 149482f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1495c9b443d4STobin Davis { 1496c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1497c9b443d4STobin Davis .name = "Input Source", 1498c9b443d4STobin Davis .info = conexant_mux_enum_info, 1499c9b443d4STobin Davis .get = conexant_mux_enum_get, 1500c9b443d4STobin Davis .put = conexant_mux_enum_put, 1501c9b443d4STobin Davis }, 1502854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 15039f113e0eSMarc Boucher 1504c9b443d4STobin Davis { } /* end */ 1505c9b443d4STobin Davis }; 1506c9b443d4STobin Davis 1507c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1508c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1509c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1510c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1511c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1512c9b443d4STobin Davis 1513c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1514c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1515c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1516c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1517c9b443d4STobin Davis * control. 1518c9b443d4STobin Davis */ 1519c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1520c9b443d4STobin Davis 1521c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1522c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1523c9b443d4STobin Davis */ 1524c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1525c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1526c9b443d4STobin Davis 1527c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1528c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1529c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1530c9b443d4STobin Davis 1531c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1532c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1533c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1534c9b443d4STobin Davis * input/output buffers as needed. 1535c9b443d4STobin Davis */ 1536c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1537c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1538c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1539c9b443d4STobin Davis 1540c9b443d4STobin Davis /* Mute capture amp left and right */ 1541c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1542c9b443d4STobin Davis 1543c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1544c9b443d4STobin Davis * pin) 1545c9b443d4STobin Davis */ 1546c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1547c9b443d4STobin Davis 1548c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1549c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1550c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1551c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1552c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1553c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1554c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1555c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1556c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1557c9b443d4STobin Davis 1558c9b443d4STobin Davis { } 1559c9b443d4STobin Davis }; 1560c9b443d4STobin Davis #endif 1561c9b443d4STobin Davis 1562c9b443d4STobin Davis 1563c9b443d4STobin Davis /* initialize jack-sensing, too */ 1564c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1565c9b443d4STobin Davis { 1566c9b443d4STobin Davis conexant_init(codec); 1567c9b443d4STobin Davis cxt5047_hp_automute(codec); 1568c9b443d4STobin Davis return 0; 1569c9b443d4STobin Davis } 1570c9b443d4STobin Davis 1571c9b443d4STobin Davis 1572c9b443d4STobin Davis enum { 1573f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1574f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1575f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1576c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1577c9b443d4STobin Davis CXT5047_TEST, 1578c9b443d4STobin Davis #endif 1579f5fcc13cSTakashi Iwai CXT5047_MODELS 1580c9b443d4STobin Davis }; 1581c9b443d4STobin Davis 1582f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1583f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1584f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1585f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1586c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1587f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1588c9b443d4STobin Davis #endif 1589f5fcc13cSTakashi Iwai }; 1590c9b443d4STobin Davis 1591f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1592ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1593dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1594dea0a509STakashi Iwai CXT5047_LAPTOP), 1595f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1596c9b443d4STobin Davis {} 1597c9b443d4STobin Davis }; 1598c9b443d4STobin Davis 1599c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1600c9b443d4STobin Davis { 1601c9b443d4STobin Davis struct conexant_spec *spec; 1602c9b443d4STobin Davis int board_config; 1603c9b443d4STobin Davis 1604c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1605c9b443d4STobin Davis if (!spec) 1606c9b443d4STobin Davis return -ENOMEM; 1607c9b443d4STobin Davis codec->spec = spec; 16089421f954STakashi Iwai codec->pin_amp_workaround = 1; 1609c9b443d4STobin Davis 1610c9b443d4STobin Davis spec->multiout.max_channels = 2; 1611c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1612c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1613c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1614c9b443d4STobin Davis spec->num_adc_nids = 1; 1615c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1616c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1617c9b443d4STobin Davis spec->num_mixers = 1; 1618df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1619c9b443d4STobin Davis spec->num_init_verbs = 1; 1620c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1621c9b443d4STobin Davis spec->spdif_route = 0; 16225cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16235cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1624c9b443d4STobin Davis 1625c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1626c9b443d4STobin Davis 1627f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1628f5fcc13cSTakashi Iwai cxt5047_models, 1629f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1630c9b443d4STobin Davis switch (board_config) { 1631c9b443d4STobin Davis case CXT5047_LAPTOP: 1632df481e41STakashi Iwai spec->num_mixers = 2; 1633df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1634df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1635c9b443d4STobin Davis break; 1636c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1637df481e41STakashi Iwai spec->num_mixers = 2; 1638df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1639fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1640c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1641c9b443d4STobin Davis break; 1642c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 164382f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1644df481e41STakashi Iwai spec->num_mixers = 2; 1645df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1646c9b443d4STobin Davis spec->num_init_verbs = 2; 1647c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1648fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1649c9b443d4STobin Davis break; 1650c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1651c9b443d4STobin Davis case CXT5047_TEST: 1652c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1653c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1654c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1655fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1656c9b443d4STobin Davis #endif 1657c9b443d4STobin Davis } 1658dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1659025f206cSDaniel T Chen 1660025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1661025f206cSDaniel T Chen case 0x103c: 1662025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1663025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1664025f206cSDaniel T Chen * with 0 dB offset 0x17) 1665025f206cSDaniel T Chen */ 1666025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1667025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1668025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1669025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1670025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1671025f206cSDaniel T Chen break; 1672025f206cSDaniel T Chen } 1673025f206cSDaniel T Chen 1674c9b443d4STobin Davis return 0; 1675c9b443d4STobin Davis } 1676c9b443d4STobin Davis 1677461e2c78STakashi Iwai /* Conexant 5051 specific */ 1678461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1679461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1680461e2c78STakashi Iwai 1681461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1682461e2c78STakashi Iwai { 2, NULL }, 1683461e2c78STakashi Iwai }; 1684461e2c78STakashi Iwai 1685461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1686461e2c78STakashi Iwai { 1687461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1688461e2c78STakashi Iwai unsigned int pinctl; 168923d2df5bSTakashi Iwai /* headphone pin */ 169023d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 169123d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 169223d2df5bSTakashi Iwai pinctl); 169323d2df5bSTakashi Iwai /* speaker pin */ 1694461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1695461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1696461e2c78STakashi Iwai pinctl); 1697f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1698f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1699f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1700f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1701f7154de2SHerton Ronaldo Krzesinski pinctl); 1702461e2c78STakashi Iwai } 1703461e2c78STakashi Iwai 1704461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1705461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1706461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1707461e2c78STakashi Iwai { 1708461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1709461e2c78STakashi Iwai 1710461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1711461e2c78STakashi Iwai return 0; 1712461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1713461e2c78STakashi Iwai return 1; 1714461e2c78STakashi Iwai } 1715461e2c78STakashi Iwai 1716461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1717461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1718461e2c78STakashi Iwai { 171979d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1720461e2c78STakashi Iwai unsigned int present; 1721461e2c78STakashi Iwai 1722faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 172379d7d533STakashi Iwai return; 1724d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1725461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1726461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1727461e2c78STakashi Iwai present ? 0x01 : 0x00); 1728461e2c78STakashi Iwai } 1729461e2c78STakashi Iwai 1730461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1731461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1732461e2c78STakashi Iwai { 1733461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1734461e2c78STakashi Iwai unsigned int present; 1735461e2c78STakashi Iwai hda_nid_t new_adc; 1736461e2c78STakashi Iwai 1737faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 173879d7d533STakashi Iwai return; 1739d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1740461e2c78STakashi Iwai if (present) 1741461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1742461e2c78STakashi Iwai else 1743461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1744461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1745461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1746461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1747f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1748461e2c78STakashi Iwai spec->cur_adc = new_adc; 1749461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1750461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1751461e2c78STakashi Iwai spec->cur_adc_format); 1752461e2c78STakashi Iwai } 1753461e2c78STakashi Iwai } 1754461e2c78STakashi Iwai 1755461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1756461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1757461e2c78STakashi Iwai { 1758461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1759461e2c78STakashi Iwai 1760d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1761461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1762461e2c78STakashi Iwai } 1763461e2c78STakashi Iwai 1764461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1765461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1766461e2c78STakashi Iwai unsigned int res) 1767461e2c78STakashi Iwai { 1768acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1769461e2c78STakashi Iwai switch (res >> 26) { 1770461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1771461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1772461e2c78STakashi Iwai break; 1773461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1774461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1775461e2c78STakashi Iwai break; 1776461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1777461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1778461e2c78STakashi Iwai break; 1779461e2c78STakashi Iwai } 1780acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1781461e2c78STakashi Iwai } 1782461e2c78STakashi Iwai 17832c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1784461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1785461e2c78STakashi Iwai { 1786461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1787461e2c78STakashi Iwai .name = "Master Playback Switch", 1788461e2c78STakashi Iwai .info = cxt_eapd_info, 1789461e2c78STakashi Iwai .get = cxt_eapd_get, 1790461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1791461e2c78STakashi Iwai .private_value = 0x1a, 1792461e2c78STakashi Iwai }, 17932c7a3fb3STakashi Iwai {} 17942c7a3fb3STakashi Iwai }; 1795461e2c78STakashi Iwai 17962c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17972c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17982c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17992c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 18002c7a3fb3STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 18012c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 18022c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1803461e2c78STakashi Iwai {} 1804461e2c78STakashi Iwai }; 1805461e2c78STakashi Iwai 1806461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1807461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1808461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1809461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1810461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1811461e2c78STakashi Iwai {} 1812461e2c78STakashi Iwai }; 1813461e2c78STakashi Iwai 181479d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 18154e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 18164e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 181779d7d533STakashi Iwai {} 181879d7d533STakashi Iwai }; 181979d7d533STakashi Iwai 1820cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = { 18215f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 18225f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1823cd9d95a5SKen Prox {} 1824cd9d95a5SKen Prox }; 1825cd9d95a5SKen Prox 1826faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1827faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1828faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1829faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1830faddaa5dSTakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1831faddaa5dSTakashi Iwai {} 1832faddaa5dSTakashi Iwai }; 1833faddaa5dSTakashi Iwai 1834461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1835461e2c78STakashi Iwai /* Line in, Mic */ 1836461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1837461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1838461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1839461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1840461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1841461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1842461e2c78STakashi Iwai /* SPK */ 1843461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1844461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1845461e2c78STakashi Iwai /* HP, Amp */ 1846461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1847461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1848461e2c78STakashi Iwai /* DAC1 */ 1849461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1850461e2c78STakashi Iwai /* Record selector: Int mic */ 1851461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1852461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1853461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1854461e2c78STakashi Iwai /* SPDIF route: PCM */ 18551965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1856461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1857461e2c78STakashi Iwai /* EAPD */ 1858461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1859461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1860461e2c78STakashi Iwai { } /* end */ 1861461e2c78STakashi Iwai }; 1862461e2c78STakashi Iwai 186379d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 186479d7d533STakashi Iwai /* Line in, Mic */ 186579d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 186679d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 186779d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 186879d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 186979d7d533STakashi Iwai /* SPK */ 187079d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 187179d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 187279d7d533STakashi Iwai /* HP, Amp */ 187379d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 187479d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 187579d7d533STakashi Iwai /* DAC1 */ 187679d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 187779d7d533STakashi Iwai /* Record selector: Int mic */ 187879d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 187979d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 188079d7d533STakashi Iwai /* SPDIF route: PCM */ 188179d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 188279d7d533STakashi Iwai /* EAPD */ 188379d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 188479d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 188579d7d533STakashi Iwai { } /* end */ 188679d7d533STakashi Iwai }; 188779d7d533STakashi Iwai 188827e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 188927e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 189027e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 189127e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 189227e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 189327e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 189427e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 189527e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 189627e08988SAristeu Sergio Rozanski Filho /* SPK */ 189727e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 189827e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 189927e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 190027e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 190127e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 190227e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 190327e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 190427e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 190527e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 190627e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 190727e08988SAristeu Sergio Rozanski Filho /* Record selector: Int mic */ 190827e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 190927e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 191027e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 191127e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 19121965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ 191327e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 191427e08988SAristeu Sergio Rozanski Filho /* EAPD */ 191527e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 191627e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 191727e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 191827e08988SAristeu Sergio Rozanski Filho { } /* end */ 191927e08988SAristeu Sergio Rozanski Filho }; 192027e08988SAristeu Sergio Rozanski Filho 1921cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = { 1922cd9d95a5SKen Prox /* Line in, Mic */ 192330ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1924cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1925cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1926cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1927cd9d95a5SKen Prox /* SPK */ 1928cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1929cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1930cd9d95a5SKen Prox /* HP, Amp */ 1931cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1932cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1933cd9d95a5SKen Prox /* DAC1 */ 1934cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1935cd9d95a5SKen Prox /* Record selector: Int mic */ 1936cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1937cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1938cd9d95a5SKen Prox /* SPDIF route: PCM */ 1939cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1940cd9d95a5SKen Prox /* EAPD */ 1941cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1942cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1943cd9d95a5SKen Prox { } /* end */ 1944cd9d95a5SKen Prox }; 1945cd9d95a5SKen Prox 19466953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 19476953e552STakashi Iwai unsigned int event) 19486953e552STakashi Iwai { 19496953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19506953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19516953e552STakashi Iwai AC_USRSP_EN | event); 19526953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 19536953e552STakashi Iwai conexant_add_jack(codec, nid, SND_JACK_MICROPHONE); 19546953e552STakashi Iwai conexant_report_jack(codec, nid); 19556953e552STakashi Iwai #endif 19566953e552STakashi Iwai } 19576953e552STakashi Iwai 1958f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = { 1959f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1960f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1961f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1962f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1963f7154de2SHerton Ronaldo Krzesinski }; 1964f7154de2SHerton Ronaldo Krzesinski 1965461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1966461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1967461e2c78STakashi Iwai { 19686953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19696953e552STakashi Iwai 1970461e2c78STakashi Iwai conexant_init(codec); 1971acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19726953e552STakashi Iwai 19736953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19746953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19756953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19766953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19776953e552STakashi Iwai 1978461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1979461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1980461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1981461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1982461e2c78STakashi Iwai } 1983461e2c78STakashi Iwai return 0; 1984461e2c78STakashi Iwai } 1985461e2c78STakashi Iwai 1986461e2c78STakashi Iwai 1987461e2c78STakashi Iwai enum { 1988461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1989461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 199079d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 19911965c441SPierre-Louis Bossart CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ 1992cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1993faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1994f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 1995461e2c78STakashi Iwai CXT5051_MODELS 1996461e2c78STakashi Iwai }; 1997461e2c78STakashi Iwai 1998461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1999461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 2000461e2c78STakashi Iwai [CXT5051_HP] = "hp", 200179d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 200227e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 20035f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 2004faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 2005f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 2006461e2c78STakashi Iwai }; 2007461e2c78STakashi Iwai 2008461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 200979d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 20101812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 20115f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 2012faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 2013461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2014461e2c78STakashi Iwai CXT5051_LAPTOP), 2015461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 201627e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 2017f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 2018461e2c78STakashi Iwai {} 2019461e2c78STakashi Iwai }; 2020461e2c78STakashi Iwai 2021461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 2022461e2c78STakashi Iwai { 2023461e2c78STakashi Iwai struct conexant_spec *spec; 2024461e2c78STakashi Iwai int board_config; 2025461e2c78STakashi Iwai 2026461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2027461e2c78STakashi Iwai if (!spec) 2028461e2c78STakashi Iwai return -ENOMEM; 2029461e2c78STakashi Iwai codec->spec = spec; 20309421f954STakashi Iwai codec->pin_amp_workaround = 1; 2031461e2c78STakashi Iwai 2032461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 2033461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 2034461e2c78STakashi Iwai 2035461e2c78STakashi Iwai spec->multiout.max_channels = 2; 2036461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 2037461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 2038461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 2039461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 2040461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 20412c7a3fb3STakashi Iwai spec->num_mixers = 2; 20422c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20432c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2044461e2c78STakashi Iwai spec->num_init_verbs = 1; 2045461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2046461e2c78STakashi Iwai spec->spdif_route = 0; 2047461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2048461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2049461e2c78STakashi Iwai spec->cur_adc = 0; 2050461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2051461e2c78STakashi Iwai 20523507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20533507e2a8STakashi Iwai 205479d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 205579d7d533STakashi Iwai 2056461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 2057461e2c78STakashi Iwai cxt5051_models, 2058461e2c78STakashi Iwai cxt5051_cfg_tbl); 2059faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2060461e2c78STakashi Iwai switch (board_config) { 2061461e2c78STakashi Iwai case CXT5051_HP: 2062461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2063461e2c78STakashi Iwai break; 206479d7d533STakashi Iwai case CXT5051_HP_DV6736: 206579d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 206679d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2067faddaa5dSTakashi Iwai spec->auto_mic = 0; 206879d7d533STakashi Iwai break; 206927e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 207027e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 2071607bc3e4SJerone Young /* Thinkpad X301 does not have S/PDIF wired and no ability 2072607bc3e4SJerone Young to use a docking station. */ 2073607bc3e4SJerone Young if (codec->subsystem_id == 0x17aa211f) 2074607bc3e4SJerone Young spec->multiout.dig_out_nid = 0; 2075461e2c78STakashi Iwai break; 2076cd9d95a5SKen Prox case CXT5051_F700: 2077cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2078cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2079faddaa5dSTakashi Iwai spec->auto_mic = 0; 2080faddaa5dSTakashi Iwai break; 2081faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2082faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2083faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2084cd9d95a5SKen Prox break; 2085f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2086f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2087f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2088f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2089f7154de2SHerton Ronaldo Krzesinski break; 2090461e2c78STakashi Iwai } 2091461e2c78STakashi Iwai 20923507e2a8STakashi Iwai if (spec->beep_amp) 20933507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20943507e2a8STakashi Iwai 2095461e2c78STakashi Iwai return 0; 2096461e2c78STakashi Iwai } 2097461e2c78STakashi Iwai 20980fb67e98SDaniel Drake /* Conexant 5066 specific */ 20990fb67e98SDaniel Drake 21000fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 21010fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 21020fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 21030fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT 0x21 21040fb67e98SDaniel Drake 2105dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2106dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2107dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2108dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2109dbaccc0cSDaniel Drake 21100fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = { 21110fb67e98SDaniel Drake { 2, NULL }, 21120fb67e98SDaniel Drake }; 21130fb67e98SDaniel Drake 2114*a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2115*a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2116*a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2117*a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2118*a3de8ab8STakashi Iwai 21190fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 21200fb67e98SDaniel Drake { 21210fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 21220fb67e98SDaniel Drake unsigned int pinctl; 21230fb67e98SDaniel Drake 21243a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 21253a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 21260fb67e98SDaniel Drake 21270fb67e98SDaniel Drake /* Port A (HP) */ 2128*a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 21290fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21300fb67e98SDaniel Drake pinctl); 21310fb67e98SDaniel Drake 21320fb67e98SDaniel Drake /* Port D (HP/LO) */ 2133*a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2134*a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2135*a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2136*a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 21373a253445SJohn Baboval pinctl = 0; 21383a253445SJohn Baboval } else { 2139*a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2140*a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2141*a3de8ab8STakashi Iwai pinctl = 0; 21423a253445SJohn Baboval } 21430fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21440fb67e98SDaniel Drake pinctl); 21450fb67e98SDaniel Drake 21460fb67e98SDaniel Drake /* CLASS_D AMP */ 21470fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21480fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21490fb67e98SDaniel Drake pinctl); 21500fb67e98SDaniel Drake } 21510fb67e98SDaniel Drake 21520fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21530fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21540fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21550fb67e98SDaniel Drake { 21560fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21570fb67e98SDaniel Drake 21580fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21590fb67e98SDaniel Drake return 0; 21600fb67e98SDaniel Drake 21610fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21620fb67e98SDaniel Drake return 1; 21630fb67e98SDaniel Drake } 21640fb67e98SDaniel Drake 2165c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2166c4cfe66cSDaniel Drake .num_items = 3, 2167c4cfe66cSDaniel Drake .items = { 2168c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2169c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2170c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2171c4cfe66cSDaniel Drake }, 2172c4cfe66cSDaniel Drake }; 2173c4cfe66cSDaniel Drake 2174c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2175c4cfe66cSDaniel Drake { 2176c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2177c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2178c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2179c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2180c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2181c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2182c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2183c4cfe66cSDaniel Drake } 2184c4cfe66cSDaniel Drake 218575f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 218675f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 218775f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 218875f8991dSDaniel Drake * is happening when it is not. */ 218975f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21900fb67e98SDaniel Drake { 2191dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 219275f8991dSDaniel Drake if (!spec->recording) 219375f8991dSDaniel Drake return; 21940fb67e98SDaniel Drake 2195c4cfe66cSDaniel Drake if (spec->dc_enable) { 2196c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2197c4cfe66cSDaniel Drake * through our special DC port */ 2198c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2199c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2200c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2201c4cfe66cSDaniel Drake 2202c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2203c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2204c4cfe66cSDaniel Drake {}, 2205c4cfe66cSDaniel Drake }; 2206c4cfe66cSDaniel Drake 2207c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2208c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2209c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2210c4cfe66cSDaniel Drake return; 2211c4cfe66cSDaniel Drake } 2212c4cfe66cSDaniel Drake 2213c4cfe66cSDaniel Drake /* disable DC (port F) */ 2214c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2215c4cfe66cSDaniel Drake 221675f8991dSDaniel Drake /* external mic, port B */ 221775f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 221875f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 22190fb67e98SDaniel Drake 222075f8991dSDaniel Drake /* internal mic, port C */ 222175f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 222275f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 222375f8991dSDaniel Drake } 22240fb67e98SDaniel Drake 222575f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 222675f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 222775f8991dSDaniel Drake { 222875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 22290fb67e98SDaniel Drake unsigned int present; 22300fb67e98SDaniel Drake 2231c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2232c4cfe66cSDaniel Drake return; 2233c4cfe66cSDaniel Drake 223475f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 223575f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 223675f8991dSDaniel Drake if (present) 22370fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 223875f8991dSDaniel Drake else 22390fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 224075f8991dSDaniel Drake 224175f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 224275f8991dSDaniel Drake present ? 0 : 1); 224375f8991dSDaniel Drake spec->ext_mic_present = !!present; 224475f8991dSDaniel Drake 224575f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22460fb67e98SDaniel Drake } 22470fb67e98SDaniel Drake 224895a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 224995a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 225095a618bdSEinar Rünkaru { 225195a618bdSEinar Rünkaru unsigned int present; 225295a618bdSEinar Rünkaru 225395a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 225495a618bdSEinar Rünkaru /* enable external mic, port B */ 225575f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 225695a618bdSEinar Rünkaru 225795a618bdSEinar Rünkaru /* switch to external mic input */ 225895a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 225995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 226095a618bdSEinar Rünkaru 226195a618bdSEinar Rünkaru /* disable internal digital mic */ 226295a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 226395a618bdSEinar Rünkaru {} 226495a618bdSEinar Rünkaru }; 226595a618bdSEinar Rünkaru static struct hda_verb ext_mic_absent[] = { 226695a618bdSEinar Rünkaru /* enable internal mic, port C */ 226795a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 226895a618bdSEinar Rünkaru 226995a618bdSEinar Rünkaru /* switch to internal mic input */ 227095a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 227195a618bdSEinar Rünkaru 227295a618bdSEinar Rünkaru /* disable external mic, port B */ 227395a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 227495a618bdSEinar Rünkaru {} 227595a618bdSEinar Rünkaru }; 227695a618bdSEinar Rünkaru 227795a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 227895a618bdSEinar Rünkaru if (present) { 227995a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 228095a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 228195a618bdSEinar Rünkaru } else { 228295a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 228395a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 228495a618bdSEinar Rünkaru } 228595a618bdSEinar Rünkaru } 228695a618bdSEinar Rünkaru 2287cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2288cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2289cfd3d8dcSGreg Alexander { 2290cfd3d8dcSGreg Alexander unsigned int present; 2291cfd3d8dcSGreg Alexander 2292cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2293cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2294cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2295cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2296cfd3d8dcSGreg Alexander {} 2297cfd3d8dcSGreg Alexander }; 2298cfd3d8dcSGreg Alexander static struct hda_verb ext_mic_absent[] = { 2299cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2300cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2301cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2302cfd3d8dcSGreg Alexander {} 2303cfd3d8dcSGreg Alexander }; 2304cfd3d8dcSGreg Alexander 2305cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2306cfd3d8dcSGreg Alexander if (present) { 2307cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2308cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2309cfd3d8dcSGreg Alexander } else { 2310cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2311cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2312cfd3d8dcSGreg Alexander } 2313cfd3d8dcSGreg Alexander } 2314cfd3d8dcSGreg Alexander 2315048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2316048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2317048e78a5SDavid Henningsson { 2318048e78a5SDavid Henningsson unsigned int present; 2319048e78a5SDavid Henningsson 2320048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2321048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2322048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2323048e78a5SDavid Henningsson present ? 1 : 3); 2324048e78a5SDavid Henningsson } 2325048e78a5SDavid Henningsson 2326048e78a5SDavid Henningsson 23277b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 23287b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 23297b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23307b2bfdbcSJens Taprogge { 23317b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23327b2bfdbcSJens Taprogge 23337b2bfdbcSJens Taprogge static struct hda_verb ext_mic_present[] = { 23347b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23357b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23367b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23377b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23387b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23397b2bfdbcSJens Taprogge {} 23407b2bfdbcSJens Taprogge }; 23417b2bfdbcSJens Taprogge static struct hda_verb dock_mic_present[] = { 23427b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23437b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23447b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23457b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23467b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23477b2bfdbcSJens Taprogge {} 23487b2bfdbcSJens Taprogge }; 23497b2bfdbcSJens Taprogge static struct hda_verb ext_mic_absent[] = { 23507b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23517b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23527b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23537b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23547b2bfdbcSJens Taprogge {} 23557b2bfdbcSJens Taprogge }; 23567b2bfdbcSJens Taprogge 23577b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23587b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23597b2bfdbcSJens Taprogge if (ext_present) { 23607b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23617b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23627b2bfdbcSJens Taprogge } else if (dock_present) { 23637b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23647b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23657b2bfdbcSJens Taprogge } else { 23667b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23677b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23687b2bfdbcSJens Taprogge } 23697b2bfdbcSJens Taprogge } 23707b2bfdbcSJens Taprogge 23710fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23720fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23730fb67e98SDaniel Drake { 23740fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23750fb67e98SDaniel Drake unsigned int portA, portD; 23760fb67e98SDaniel Drake 23770fb67e98SDaniel Drake /* Port A */ 2378d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23790fb67e98SDaniel Drake 23800fb67e98SDaniel Drake /* Port D */ 2381d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23820fb67e98SDaniel Drake 2383*a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2384*a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 23850fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23860fb67e98SDaniel Drake portA, portD, spec->hp_present); 23870fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23880fb67e98SDaniel Drake } 23890fb67e98SDaniel Drake 23900fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 239175f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23920fb67e98SDaniel Drake { 2393c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23940fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23950fb67e98SDaniel Drake switch (res >> 26) { 23960fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23970fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23980fb67e98SDaniel Drake break; 23990fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2400c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2401c4cfe66cSDaniel Drake if (!spec->dc_enable) 240275f8991dSDaniel Drake cxt5066_olpc_automic(codec); 24030fb67e98SDaniel Drake break; 24040fb67e98SDaniel Drake } 24050fb67e98SDaniel Drake } 24060fb67e98SDaniel Drake 240795a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 240895a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res) 240995a618bdSEinar Rünkaru { 241095a618bdSEinar Rünkaru snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26); 241195a618bdSEinar Rünkaru switch (res >> 26) { 241295a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 241395a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 241495a618bdSEinar Rünkaru break; 241595a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 241695a618bdSEinar Rünkaru cxt5066_vostro_automic(codec); 241795a618bdSEinar Rünkaru break; 241895a618bdSEinar Rünkaru } 241995a618bdSEinar Rünkaru } 242095a618bdSEinar Rünkaru 2421cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */ 2422cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res) 2423cfd3d8dcSGreg Alexander { 2424cfd3d8dcSGreg Alexander snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26); 2425cfd3d8dcSGreg Alexander switch (res >> 26) { 2426cfd3d8dcSGreg Alexander case CONEXANT_HP_EVENT: 2427cfd3d8dcSGreg Alexander cxt5066_hp_automute(codec); 2428cfd3d8dcSGreg Alexander break; 2429cfd3d8dcSGreg Alexander case CONEXANT_MIC_EVENT: 2430cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 2431cfd3d8dcSGreg Alexander break; 2432cfd3d8dcSGreg Alexander } 2433cfd3d8dcSGreg Alexander } 2434cfd3d8dcSGreg Alexander 24357b2bfdbcSJens Taprogge /* unsolicited event for jack sensing */ 2436048e78a5SDavid Henningsson static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res) 2437048e78a5SDavid Henningsson { 2438048e78a5SDavid Henningsson snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26); 2439048e78a5SDavid Henningsson switch (res >> 26) { 2440048e78a5SDavid Henningsson case CONEXANT_HP_EVENT: 2441048e78a5SDavid Henningsson cxt5066_hp_automute(codec); 2442048e78a5SDavid Henningsson break; 2443048e78a5SDavid Henningsson case CONEXANT_MIC_EVENT: 2444048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2445048e78a5SDavid Henningsson break; 2446048e78a5SDavid Henningsson } 2447048e78a5SDavid Henningsson } 2448048e78a5SDavid Henningsson 2449048e78a5SDavid Henningsson /* unsolicited event for jack sensing */ 24507b2bfdbcSJens Taprogge static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res) 24517b2bfdbcSJens Taprogge { 24527b2bfdbcSJens Taprogge snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26); 24537b2bfdbcSJens Taprogge switch (res >> 26) { 24547b2bfdbcSJens Taprogge case CONEXANT_HP_EVENT: 24557b2bfdbcSJens Taprogge cxt5066_hp_automute(codec); 24567b2bfdbcSJens Taprogge break; 24577b2bfdbcSJens Taprogge case CONEXANT_MIC_EVENT: 24587b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 24597b2bfdbcSJens Taprogge break; 24607b2bfdbcSJens Taprogge } 24617b2bfdbcSJens Taprogge } 24627b2bfdbcSJens Taprogge 24630fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24640fb67e98SDaniel Drake .num_items = 5, 24650fb67e98SDaniel Drake .items = { 24660fb67e98SDaniel Drake { "0dB", 0 }, 24670fb67e98SDaniel Drake { "10dB", 1 }, 24680fb67e98SDaniel Drake { "20dB", 2 }, 24690fb67e98SDaniel Drake { "30dB", 3 }, 24700fb67e98SDaniel Drake { "40dB", 4 }, 24710fb67e98SDaniel Drake }, 24720fb67e98SDaniel Drake }; 24730fb67e98SDaniel Drake 2474cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2475c4cfe66cSDaniel Drake { 2476c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2477cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2478c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2479c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2480c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24817b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2482cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2483cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2484cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2485cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2486cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2487cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2488cfd3d8dcSGreg Alexander } 2489c4cfe66cSDaniel Drake } 2490c4cfe66cSDaniel Drake 24910fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24920fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24930fb67e98SDaniel Drake { 24940fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24950fb67e98SDaniel Drake } 24960fb67e98SDaniel Drake 24970fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24980fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24990fb67e98SDaniel Drake { 25000fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2501c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2502c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 25030fb67e98SDaniel Drake return 0; 25040fb67e98SDaniel Drake } 25050fb67e98SDaniel Drake 25060fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 25070fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 25080fb67e98SDaniel Drake { 25090fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2510c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 25110fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 25120fb67e98SDaniel Drake unsigned int idx; 25130fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 25140fb67e98SDaniel Drake if (idx >= imux->num_items) 25150fb67e98SDaniel Drake idx = imux->num_items - 1; 25160fb67e98SDaniel Drake 2517c4cfe66cSDaniel Drake spec->mic_boost = idx; 2518c4cfe66cSDaniel Drake if (!spec->dc_enable) 2519c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2520c4cfe66cSDaniel Drake return 1; 2521c4cfe66cSDaniel Drake } 25220fb67e98SDaniel Drake 2523c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2524c4cfe66cSDaniel Drake { 2525c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2526c4cfe66cSDaniel Drake /* disable gain */ 2527c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2528c4cfe66cSDaniel Drake 2529c4cfe66cSDaniel Drake /* switch to DC input */ 2530c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2531c4cfe66cSDaniel Drake {} 2532c4cfe66cSDaniel Drake }; 2533c4cfe66cSDaniel Drake 2534c4cfe66cSDaniel Drake /* configure as input source */ 2535c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2536c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2537c4cfe66cSDaniel Drake } 2538c4cfe66cSDaniel Drake 2539c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2540c4cfe66cSDaniel Drake { 2541c4cfe66cSDaniel Drake /* reconfigure input source */ 2542c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2543c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2544c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2545c4cfe66cSDaniel Drake } 2546c4cfe66cSDaniel Drake 2547c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2548c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2549c4cfe66cSDaniel Drake { 2550c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2551c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2552c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2553c4cfe66cSDaniel Drake return 0; 2554c4cfe66cSDaniel Drake } 2555c4cfe66cSDaniel Drake 2556c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2557c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2558c4cfe66cSDaniel Drake { 2559c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2560c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2561c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2562c4cfe66cSDaniel Drake 2563c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2564c4cfe66cSDaniel Drake return 0; 2565c4cfe66cSDaniel Drake 2566c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2567c4cfe66cSDaniel Drake if (dc_enable) 2568c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2569c4cfe66cSDaniel Drake else 2570c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2571c4cfe66cSDaniel Drake 2572c4cfe66cSDaniel Drake return 1; 2573c4cfe66cSDaniel Drake } 2574c4cfe66cSDaniel Drake 2575c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2576c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2577c4cfe66cSDaniel Drake { 2578c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2579c4cfe66cSDaniel Drake } 2580c4cfe66cSDaniel Drake 2581c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2582c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2583c4cfe66cSDaniel Drake { 2584c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2585c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2586c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2587c4cfe66cSDaniel Drake return 0; 2588c4cfe66cSDaniel Drake } 2589c4cfe66cSDaniel Drake 2590c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2591c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2592c4cfe66cSDaniel Drake { 2593c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2594c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2595c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2596c4cfe66cSDaniel Drake unsigned int idx; 2597c4cfe66cSDaniel Drake 2598c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2599c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2600c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2601c4cfe66cSDaniel Drake 2602c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2603c4cfe66cSDaniel Drake if (spec->dc_enable) 2604c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 26050fb67e98SDaniel Drake return 1; 26060fb67e98SDaniel Drake } 26070fb67e98SDaniel Drake 260875f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 260975f8991dSDaniel Drake { 261075f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 261175f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 261275f8991dSDaniel Drake * recording LED comes on. */ 261375f8991dSDaniel Drake spec->recording = 1; 261475f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 261575f8991dSDaniel Drake } 261675f8991dSDaniel Drake 261775f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 261875f8991dSDaniel Drake { 261975f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 262075f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 262175f8991dSDaniel Drake /* disable external mic, port B */ 262275f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 262375f8991dSDaniel Drake 262475f8991dSDaniel Drake /* disble internal mic, port C */ 262575f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2626c4cfe66cSDaniel Drake 2627c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2628c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 262975f8991dSDaniel Drake {}, 263075f8991dSDaniel Drake }; 263175f8991dSDaniel Drake 263275f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 263375f8991dSDaniel Drake spec->recording = 0; 263475f8991dSDaniel Drake } 263575f8991dSDaniel Drake 26360fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 26370fb67e98SDaniel Drake .num_items = 4, 26380fb67e98SDaniel Drake .items = { 26390fb67e98SDaniel Drake { "Mic B", 0 }, 26400fb67e98SDaniel Drake { "Mic C", 1 }, 26410fb67e98SDaniel Drake { "Mic E", 2 }, 26420fb67e98SDaniel Drake { "Mic F", 3 }, 26430fb67e98SDaniel Drake }, 26440fb67e98SDaniel Drake }; 26450fb67e98SDaniel Drake 26460fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26470fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26480fb67e98SDaniel Drake .values = { 26490fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26500fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26510fb67e98SDaniel Drake 0 26520fb67e98SDaniel Drake }, 26530fb67e98SDaniel Drake }; 26540fb67e98SDaniel Drake 26550fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26560fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26570fb67e98SDaniel Drake .values = { 26580fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26590fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26600fb67e98SDaniel Drake 0 26610fb67e98SDaniel Drake }, 26620fb67e98SDaniel Drake }; 26630fb67e98SDaniel Drake 26640fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 26650fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26660fb67e98SDaniel Drake {} 26670fb67e98SDaniel Drake }; 26680fb67e98SDaniel Drake 26690fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26700fb67e98SDaniel Drake { 26710fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26720fb67e98SDaniel Drake .name = "Master Playback Volume", 26730fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26740fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26750fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26765e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26770fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26780fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26790fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26800fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26810fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26820fb67e98SDaniel Drake .private_value = 26830fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26840fb67e98SDaniel Drake }, 26850fb67e98SDaniel Drake {} 26860fb67e98SDaniel Drake }; 26870fb67e98SDaniel Drake 2688c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2689c4cfe66cSDaniel Drake { 2690c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2691c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2692c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2693c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2694c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2695c4cfe66cSDaniel Drake }, 2696c4cfe66cSDaniel Drake { 2697c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2698c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2699c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2700c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2701c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2702c4cfe66cSDaniel Drake }, 2703c4cfe66cSDaniel Drake {} 2704c4cfe66cSDaniel Drake }; 2705c4cfe66cSDaniel Drake 27060fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 27070fb67e98SDaniel Drake { 27080fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 27090fb67e98SDaniel Drake .name = "Master Playback Switch", 27100fb67e98SDaniel Drake .info = cxt_eapd_info, 27110fb67e98SDaniel Drake .get = cxt_eapd_get, 27120fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 27130fb67e98SDaniel Drake .private_value = 0x1d, 27140fb67e98SDaniel Drake }, 27150fb67e98SDaniel Drake 27160fb67e98SDaniel Drake { 27170fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2718c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 27190fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 27200fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 27210fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 27220fb67e98SDaniel Drake }, 27230fb67e98SDaniel Drake 27240fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 27250fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 27260fb67e98SDaniel Drake {} 27270fb67e98SDaniel Drake }; 27280fb67e98SDaniel Drake 2729254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2730254bba6aSEinar Rünkaru { 2731254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2732254bba6aSEinar Rünkaru .name = "Int Mic Boost Capture Enum", 2733254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2734254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2735254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2736254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2737254bba6aSEinar Rünkaru }, 2738254bba6aSEinar Rünkaru {} 2739254bba6aSEinar Rünkaru }; 2740254bba6aSEinar Rünkaru 27410fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 27420fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27430fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27440fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27450fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27460fb67e98SDaniel Drake 27470fb67e98SDaniel Drake /* Speakers */ 27480fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27490fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27500fb67e98SDaniel Drake 27510fb67e98SDaniel Drake /* HP, Amp */ 27520fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27530fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27540fb67e98SDaniel Drake 27550fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27560fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27570fb67e98SDaniel Drake 27580fb67e98SDaniel Drake /* DAC1 */ 27590fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27600fb67e98SDaniel Drake 27610fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27620fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27630fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27640fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27650fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27660fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27670fb67e98SDaniel Drake 27680fb67e98SDaniel Drake /* no digital microphone support yet */ 27690fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27700fb67e98SDaniel Drake 27710fb67e98SDaniel Drake /* Audio input selector */ 27720fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27730fb67e98SDaniel Drake 27740fb67e98SDaniel Drake /* SPDIF route: PCM */ 27750fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27760fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27770fb67e98SDaniel Drake 27780fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27790fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27800fb67e98SDaniel Drake 27810fb67e98SDaniel Drake /* EAPD */ 27820fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27830fb67e98SDaniel Drake 27840fb67e98SDaniel Drake /* not handling these yet */ 27850fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27860fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27870fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27880fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27890fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27900fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27910fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27920fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27930fb67e98SDaniel Drake { } /* end */ 27940fb67e98SDaniel Drake }; 27950fb67e98SDaniel Drake 27960fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 27970fb67e98SDaniel Drake /* Port A: headphones */ 27980fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27990fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28000fb67e98SDaniel Drake 28010fb67e98SDaniel Drake /* Port B: external microphone */ 280275f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28030fb67e98SDaniel Drake 28040fb67e98SDaniel Drake /* Port C: internal microphone */ 280575f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28060fb67e98SDaniel Drake 28070fb67e98SDaniel Drake /* Port D: unused */ 28080fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28090fb67e98SDaniel Drake 28100fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 28110fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28120fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28130fb67e98SDaniel Drake 2814c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 28150fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28160fb67e98SDaniel Drake 28170fb67e98SDaniel Drake /* Port G: internal speakers */ 28180fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28190fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28200fb67e98SDaniel Drake 28210fb67e98SDaniel Drake /* DAC1 */ 28220fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28230fb67e98SDaniel Drake 28240fb67e98SDaniel Drake /* DAC2: unused */ 28250fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 28260fb67e98SDaniel Drake 28270fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28280fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28290fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28300fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28310fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28320fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28330fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28340fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28350fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28360fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28370fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28380fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28390fb67e98SDaniel Drake 28400fb67e98SDaniel Drake /* Disable digital microphone port */ 28410fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28420fb67e98SDaniel Drake 28430fb67e98SDaniel Drake /* Audio input selectors */ 28440fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28450fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28460fb67e98SDaniel Drake 28470fb67e98SDaniel Drake /* Disable SPDIF */ 28480fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28490fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28500fb67e98SDaniel Drake 28510fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28520fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28530fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28540fb67e98SDaniel Drake { } /* end */ 28550fb67e98SDaniel Drake }; 28560fb67e98SDaniel Drake 285795a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = { 285895a618bdSEinar Rünkaru /* Port A: headphones */ 285995a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286095a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 286195a618bdSEinar Rünkaru 286295a618bdSEinar Rünkaru /* Port B: external microphone */ 286395a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286495a618bdSEinar Rünkaru 286595a618bdSEinar Rünkaru /* Port C: unused */ 286695a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286795a618bdSEinar Rünkaru 286895a618bdSEinar Rünkaru /* Port D: unused */ 286995a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287095a618bdSEinar Rünkaru 287195a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 287295a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287395a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 287495a618bdSEinar Rünkaru 287595a618bdSEinar Rünkaru /* Port F: unused */ 287695a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287795a618bdSEinar Rünkaru 287895a618bdSEinar Rünkaru /* Port G: internal speakers */ 287995a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 288095a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 288195a618bdSEinar Rünkaru 288295a618bdSEinar Rünkaru /* DAC1 */ 288395a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 288495a618bdSEinar Rünkaru 288595a618bdSEinar Rünkaru /* DAC2: unused */ 288695a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 288795a618bdSEinar Rünkaru 288895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 288995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289095a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289195a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289495a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289595a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289895a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289995a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 290095a618bdSEinar Rünkaru 290195a618bdSEinar Rünkaru /* Digital microphone port */ 290295a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 290395a618bdSEinar Rünkaru 290495a618bdSEinar Rünkaru /* Audio input selectors */ 290595a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 290695a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 290795a618bdSEinar Rünkaru 290895a618bdSEinar Rünkaru /* Disable SPDIF */ 290995a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 291095a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 291195a618bdSEinar Rünkaru 291295a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 291395a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 291495a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 291595a618bdSEinar Rünkaru { } /* end */ 291695a618bdSEinar Rünkaru }; 291795a618bdSEinar Rünkaru 2918cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = { 2919cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2920cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2921cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2922cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2923cfd3d8dcSGreg Alexander 2924cfd3d8dcSGreg Alexander /* Speakers */ 2925cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2926cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2927cfd3d8dcSGreg Alexander 2928cfd3d8dcSGreg Alexander /* HP, Amp */ 2929cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2930cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2931cfd3d8dcSGreg Alexander 2932cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2933cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2934cfd3d8dcSGreg Alexander 2935cfd3d8dcSGreg Alexander /* DAC1 */ 2936cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2937cfd3d8dcSGreg Alexander 2938cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2939cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2940cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2941cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2942cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2943cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2944cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2945cfd3d8dcSGreg Alexander 2946cfd3d8dcSGreg Alexander /* Audio input selector */ 2947cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2948cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2949cfd3d8dcSGreg Alexander 2950cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2951cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2952cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2953cfd3d8dcSGreg Alexander 2954cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2955cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2956cfd3d8dcSGreg Alexander 2957cfd3d8dcSGreg Alexander /* internal microphone */ 2958cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 2959cfd3d8dcSGreg Alexander 2960cfd3d8dcSGreg Alexander /* EAPD */ 2961cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2962cfd3d8dcSGreg Alexander 2963cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2964cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2965cfd3d8dcSGreg Alexander { } /* end */ 2966cfd3d8dcSGreg Alexander }; 2967cfd3d8dcSGreg Alexander 29687b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29697b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29707b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29717b2bfdbcSJens Taprogge 29727b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29737b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29747b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29757b2bfdbcSJens Taprogge 29767b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29777b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29787b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29797b2bfdbcSJens Taprogge 29807b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29817b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29827b2bfdbcSJens Taprogge 29837b2bfdbcSJens Taprogge /* Port C: Mic */ 29847b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29857b2bfdbcSJens Taprogge 29867b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29877b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29887b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29897b2bfdbcSJens Taprogge 29907b2bfdbcSJens Taprogge /* DAC1 */ 29917b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29927b2bfdbcSJens Taprogge 29937b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29947b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29957b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29967b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29977b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29987b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29997b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 30007b2bfdbcSJens Taprogge 30017b2bfdbcSJens Taprogge /* Audio input selector */ 30027b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 30037b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 30047b2bfdbcSJens Taprogge 30057b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 30067b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 30077b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 30087b2bfdbcSJens Taprogge 30097b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30107b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30117b2bfdbcSJens Taprogge 30127b2bfdbcSJens Taprogge /* internal microphone */ 30137b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 30147b2bfdbcSJens Taprogge 30157b2bfdbcSJens Taprogge /* EAPD */ 30167b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 30177b2bfdbcSJens Taprogge 30187b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 30197b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30207b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30217b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30227b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30237b2bfdbcSJens Taprogge { } /* end */ 30247b2bfdbcSJens Taprogge }; 30257b2bfdbcSJens Taprogge 30260fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 30270fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30280fb67e98SDaniel Drake { } /* end */ 30290fb67e98SDaniel Drake }; 30300fb67e98SDaniel Drake 3031048e78a5SDavid Henningsson 3032048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3033048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3034048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3035048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3036048e78a5SDavid Henningsson { } /* end */ 3037048e78a5SDavid Henningsson }; 3038048e78a5SDavid Henningsson 30390fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30400fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30410fb67e98SDaniel Drake { 3042254bba6aSEinar Rünkaru struct conexant_spec *spec = codec->spec; 3043254bba6aSEinar Rünkaru 30440fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30450fb67e98SDaniel Drake conexant_init(codec); 30460fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30470fb67e98SDaniel Drake cxt5066_hp_automute(codec); 3048254bba6aSEinar Rünkaru if (spec->dell_vostro) 3049254bba6aSEinar Rünkaru cxt5066_vostro_automic(codec); 3050cfd3d8dcSGreg Alexander else if (spec->ideapad) 3051cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 30527b2bfdbcSJens Taprogge else if (spec->thinkpad) 30537b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 3054048e78a5SDavid Henningsson else if (spec->hp_laptop) 3055048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 30560fb67e98SDaniel Drake } 3057c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30580fb67e98SDaniel Drake return 0; 30590fb67e98SDaniel Drake } 30600fb67e98SDaniel Drake 306175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 306275f8991dSDaniel Drake { 3063c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 306475f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 306575f8991dSDaniel Drake conexant_init(codec); 306675f8991dSDaniel Drake cxt5066_hp_automute(codec); 3067c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3068c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 306975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3070c4cfe66cSDaniel Drake } else { 3071c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3072c4cfe66cSDaniel Drake } 307375f8991dSDaniel Drake return 0; 307475f8991dSDaniel Drake } 307575f8991dSDaniel Drake 30760fb67e98SDaniel Drake enum { 30770fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30780fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30790fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 30801feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 3081cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30827b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3083048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 30840fb67e98SDaniel Drake CXT5066_MODELS 30850fb67e98SDaniel Drake }; 30860fb67e98SDaniel Drake 30870fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = { 30880fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30890fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30900fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30911feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3092cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30937b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3094048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 30950fb67e98SDaniel Drake }; 30960fb67e98SDaniel Drake 30970fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 309800cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30991feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 31005637edb2SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 31015637edb2SDavid Henningsson CXT5066_DELL_LAPTOP), 31021feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3103231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3104048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3105673f7a89SDaniel T Chen SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_HP_LAPTOP), 31062ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3107c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 31084442dd46SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 31095637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 31105637edb2SDavid Henningsson CXT5066_LAPTOP), 31115637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 31124d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 31130217f149SAndrej Gelenberg SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD), 3114badf18b5SAndreas Herrmann SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD), 3115a39e33ebSJerone Young SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD), 31166027277eSManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c8, "Thinkpad Edge 11", CXT5066_IDEAPAD), 31177b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3118ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD), 31196f0ef6eaSJerone Young SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD), 3120ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD), 3121ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD), 31220fb67e98SDaniel Drake {} 31230fb67e98SDaniel Drake }; 31240fb67e98SDaniel Drake 31250fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 31260fb67e98SDaniel Drake { 31270fb67e98SDaniel Drake struct conexant_spec *spec; 31280fb67e98SDaniel Drake int board_config; 31290fb67e98SDaniel Drake 31300fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31310fb67e98SDaniel Drake if (!spec) 31320fb67e98SDaniel Drake return -ENOMEM; 31330fb67e98SDaniel Drake codec->spec = spec; 31340fb67e98SDaniel Drake 31350fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 313675f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31370fb67e98SDaniel Drake 31380fb67e98SDaniel Drake spec->dell_automute = 0; 31390fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31400fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31410fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 31420fb67e98SDaniel Drake spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT; 31430fb67e98SDaniel Drake spec->num_adc_nids = 1; 31440fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31450fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31460fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31470fb67e98SDaniel Drake 31480fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31490fb67e98SDaniel Drake 31500fb67e98SDaniel Drake spec->num_init_verbs = 1; 31510fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31520fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31530fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31540fb67e98SDaniel Drake spec->cur_adc = 0; 31550fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31560fb67e98SDaniel Drake 31573507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31583507e2a8STakashi Iwai 31590fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 31600fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 31610fb67e98SDaniel Drake switch (board_config) { 31620fb67e98SDaniel Drake default: 31630fb67e98SDaniel Drake case CXT5066_LAPTOP: 31640fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31650fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31660fb67e98SDaniel Drake break; 31670fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31680fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31690fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31700fb67e98SDaniel Drake 31710fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31720fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31730fb67e98SDaniel Drake spec->num_init_verbs++; 31740fb67e98SDaniel Drake spec->dell_automute = 1; 31750fb67e98SDaniel Drake break; 3176048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3177048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 3178048e78a5SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_hp_laptop_event; 3179048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3180048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3181048e78a5SDavid Henningsson spec->num_init_verbs++; 3182048e78a5SDavid Henningsson spec->hp_laptop = 1; 3183048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3184048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3185048e78a5SDavid Henningsson /* no S/PDIF out */ 3186048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3187048e78a5SDavid Henningsson /* input source automatically selected */ 3188048e78a5SDavid Henningsson spec->input_mux = NULL; 3189048e78a5SDavid Henningsson spec->port_d_mode = 0; 3190048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3191048e78a5SDavid Henningsson break; 3192048e78a5SDavid Henningsson 31930fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 319475f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 319575f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31960fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31970fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3198c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31990fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32000fb67e98SDaniel Drake spec->port_d_mode = 0; 3201c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 32020fb67e98SDaniel Drake 32030fb67e98SDaniel Drake /* no S/PDIF out */ 32040fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 32050fb67e98SDaniel Drake 32060fb67e98SDaniel Drake /* input source automatically selected */ 32070fb67e98SDaniel Drake spec->input_mux = NULL; 320875f8991dSDaniel Drake 320975f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 321075f8991dSDaniel Drake * at the right time */ 321175f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 321275f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 32130fb67e98SDaniel Drake break; 32141feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 321575f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 321695a618bdSEinar Rünkaru codec->patch_ops.unsol_event = cxt5066_vostro_event; 321795a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 321895a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 321995a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3220254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 322195a618bdSEinar Rünkaru spec->port_d_mode = 0; 3222254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3223c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 322495a618bdSEinar Rünkaru 322595a618bdSEinar Rünkaru /* no S/PDIF out */ 322695a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 322795a618bdSEinar Rünkaru 322895a618bdSEinar Rünkaru /* input source automatically selected */ 322995a618bdSEinar Rünkaru spec->input_mux = NULL; 323095a618bdSEinar Rünkaru break; 3231cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3232cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 3233cfd3d8dcSGreg Alexander codec->patch_ops.unsol_event = cxt5066_ideapad_event; 3234cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3235cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3236cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3237cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3238cfd3d8dcSGreg Alexander spec->ideapad = 1; 3239cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3240cfd3d8dcSGreg Alexander 3241cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3242cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3243cfd3d8dcSGreg Alexander 3244cfd3d8dcSGreg Alexander /* input source automatically selected */ 3245cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3246cfd3d8dcSGreg Alexander break; 32477b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32487b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 32497b2bfdbcSJens Taprogge codec->patch_ops.unsol_event = cxt5066_thinkpad_event; 32507b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32517b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32527b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32537b2bfdbcSJens Taprogge spec->thinkpad = 1; 32547b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32557b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32567b2bfdbcSJens Taprogge 32577b2bfdbcSJens Taprogge /* no S/PDIF out */ 32587b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32597b2bfdbcSJens Taprogge 32607b2bfdbcSJens Taprogge /* input source automatically selected */ 32617b2bfdbcSJens Taprogge spec->input_mux = NULL; 32627b2bfdbcSJens Taprogge break; 32630fb67e98SDaniel Drake } 32640fb67e98SDaniel Drake 32653507e2a8STakashi Iwai if (spec->beep_amp) 32663507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32673507e2a8STakashi Iwai 32680fb67e98SDaniel Drake return 0; 32690fb67e98SDaniel Drake } 3270461e2c78STakashi Iwai 3271461e2c78STakashi Iwai /* 3272f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3273f2e5731dSTakashi Iwai */ 3274f2e5731dSTakashi Iwai 3275f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3276f2e5731dSTakashi Iwai 3277f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */ 3278f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, 3279f2e5731dSTakashi Iwai hda_nid_t nid) 3280f2e5731dSTakashi Iwai { 3281f2e5731dSTakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 3282f2e5731dSTakashi Iwai int i, nums; 3283f2e5731dSTakashi Iwai 3284f2e5731dSTakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 3285f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) 3286f2e5731dSTakashi Iwai if (conn[i] == nid) 3287f2e5731dSTakashi Iwai return i; 3288f2e5731dSTakashi Iwai return -1; 3289f2e5731dSTakashi Iwai } 3290f2e5731dSTakashi Iwai 3291f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3292f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3293f2e5731dSTakashi Iwai * not found 3294f2e5731dSTakashi Iwai */ 3295f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3296f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3297f2e5731dSTakashi Iwai { 3298f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3299f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3300f2e5731dSTakashi Iwai 3301f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3302f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3303f2e5731dSTakashi Iwai ret = dacs[i]; 3304f2e5731dSTakashi Iwai break; 3305f2e5731dSTakashi Iwai } 3306f2e5731dSTakashi Iwai } 3307f2e5731dSTakashi Iwai if (!ret) 3308f2e5731dSTakashi Iwai return 0; 3309f2e5731dSTakashi Iwai if (--nums > 0) 3310f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3311f2e5731dSTakashi Iwai *num_dacs = nums; 3312f2e5731dSTakashi Iwai return ret; 3313f2e5731dSTakashi Iwai } 3314f2e5731dSTakashi Iwai 3315f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3316f2e5731dSTakashi Iwai 3317f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3318f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3319f2e5731dSTakashi Iwai { 3320f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3321f2e5731dSTakashi Iwai int nums = 0; 3322f2e5731dSTakashi Iwai 3323f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3324f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3325f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3326f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3327f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3328f2e5731dSTakashi Iwai dacs[nums++] = nid; 3329f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3330f2e5731dSTakashi Iwai break; 3331f2e5731dSTakashi Iwai } 3332f2e5731dSTakashi Iwai } 3333f2e5731dSTakashi Iwai return nums; 3334f2e5731dSTakashi Iwai } 3335f2e5731dSTakashi Iwai 3336f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3337f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3338f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3339f2e5731dSTakashi Iwai struct pin_dac_pair *filled, int type) 3340f2e5731dSTakashi Iwai { 3341f2e5731dSTakashi Iwai int i, nums; 3342f2e5731dSTakashi Iwai 3343f2e5731dSTakashi Iwai nums = 0; 3344f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3345f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3346f2e5731dSTakashi Iwai filled[nums].type = type; 3347f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3348f2e5731dSTakashi Iwai nums++; 3349f2e5731dSTakashi Iwai } 3350f2e5731dSTakashi Iwai return nums; 3351f2e5731dSTakashi Iwai } 3352f2e5731dSTakashi Iwai 3353f2e5731dSTakashi Iwai /* parse analog output paths */ 3354f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3355f2e5731dSTakashi Iwai { 3356f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3357f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3358f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3359f2e5731dSTakashi Iwai int i, j, nums, rest; 3360f2e5731dSTakashi Iwai 3361f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3362f2e5731dSTakashi Iwai /* parse all analog output pins */ 3363f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3364f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info, 3365f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3366f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3367f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3368f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3369f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3370f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3371f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3372f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3373f2e5731dSTakashi Iwai /* fill multiout struct */ 3374f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3375f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 3376f2e5731dSTakashi Iwai if (!dac) 3377f2e5731dSTakashi Iwai continue; 3378f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3379f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3380f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3381f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3382f2e5731dSTakashi Iwai break; 3383f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3384f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3385f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3386f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3387f2e5731dSTakashi Iwai break; 3388f2e5731dSTakashi Iwai } 3389f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3390f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3391f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3392f2e5731dSTakashi Iwai break; 3393f2e5731dSTakashi Iwai } 3394f2e5731dSTakashi Iwai break; 3395f2e5731dSTakashi Iwai } 3396f2e5731dSTakashi Iwai } 3397f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 3398f2e5731dSTakashi Iwai spec->multiout.max_channels = nums * 2; 3399f2e5731dSTakashi Iwai 3400f2e5731dSTakashi Iwai if (cfg->hp_outs > 0) 3401f2e5731dSTakashi Iwai spec->auto_mute = 1; 3402f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3403f2e5731dSTakashi Iwai } 3404f2e5731dSTakashi Iwai 3405f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 3406f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3407f2e5731dSTakashi Iwai { 3408f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3409f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3410f2e5731dSTakashi Iwai int i, present; 3411f2e5731dSTakashi Iwai 3412f2e5731dSTakashi Iwai if (!spec->auto_mute) 3413f2e5731dSTakashi Iwai return; 3414f2e5731dSTakashi Iwai present = 0; 3415f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3416f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) { 3417f2e5731dSTakashi Iwai present = 1; 3418f2e5731dSTakashi Iwai break; 3419f2e5731dSTakashi Iwai } 3420f2e5731dSTakashi Iwai } 3421f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 3422f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3423f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3424f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3425f2e5731dSTakashi Iwai } 3426f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) { 3427f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3428f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3429f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3430f2e5731dSTakashi Iwai } 3431f2e5731dSTakashi Iwai } 3432f2e5731dSTakashi Iwai 3433f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3434f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3435f2e5731dSTakashi Iwai { 3436f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3437f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3438f2e5731dSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 3439f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3440f2e5731dSTakashi Iwai 3441f2e5731dSTakashi Iwai if (!spec->auto_mic) 3442f2e5731dSTakashi Iwai return; 3443f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) { 3444f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[0], 0, 3445f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3446f2e5731dSTakashi Iwai imux->items[ext_idx].index); 3447f2e5731dSTakashi Iwai } else { 3448f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[0], 0, 3449f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3450f2e5731dSTakashi Iwai imux->items[!ext_idx].index); 3451f2e5731dSTakashi Iwai } 3452f2e5731dSTakashi Iwai } 3453f2e5731dSTakashi Iwai 3454f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3455f2e5731dSTakashi Iwai { 3456f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3457f2e5731dSTakashi Iwai switch (res >> 26) { 3458f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3459f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3460f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3461f2e5731dSTakashi Iwai break; 3462f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3463f2e5731dSTakashi Iwai cx_auto_automic(codec); 3464f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3465f2e5731dSTakashi Iwai break; 3466f2e5731dSTakashi Iwai } 3467f2e5731dSTakashi Iwai } 3468f2e5731dSTakashi Iwai 3469f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */ 3470f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) 3471f2e5731dSTakashi Iwai { 3472f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3473f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 347499ae28beSTakashi Iwai snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT; 3475f2e5731dSTakashi Iwai } 3476f2e5731dSTakashi Iwai 3477f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */ 3478f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin) 3479f2e5731dSTakashi Iwai { 3480f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3481f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3482f68b3b29STakashi Iwai snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL && 3483f68b3b29STakashi Iwai (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT); 3484f2e5731dSTakashi Iwai } 3485f2e5731dSTakashi Iwai 3486f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 3487f2e5731dSTakashi Iwai * auto-mic is enabled only when one int-mic and one-ext mic exist 3488f2e5731dSTakashi Iwai */ 3489f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3490f2e5731dSTakashi Iwai { 3491f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3492f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3493f2e5731dSTakashi Iwai 3494f2e5731dSTakashi Iwai if (is_ext_mic(codec, cfg->inputs[0].pin) && 3495f2e5731dSTakashi Iwai is_int_mic(codec, cfg->inputs[1].pin)) { 3496f2e5731dSTakashi Iwai spec->auto_mic = 1; 3497f2e5731dSTakashi Iwai spec->auto_mic_ext = 1; 3498f2e5731dSTakashi Iwai return; 3499f2e5731dSTakashi Iwai } 3500f2e5731dSTakashi Iwai if (is_int_mic(codec, cfg->inputs[1].pin) && 3501f2e5731dSTakashi Iwai is_ext_mic(codec, cfg->inputs[0].pin)) { 3502f2e5731dSTakashi Iwai spec->auto_mic = 1; 3503f2e5731dSTakashi Iwai spec->auto_mic_ext = 0; 3504f2e5731dSTakashi Iwai return; 3505f2e5731dSTakashi Iwai } 3506f2e5731dSTakashi Iwai } 3507f2e5731dSTakashi Iwai 3508f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3509f2e5731dSTakashi Iwai { 3510f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3511f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3512f2e5731dSTakashi Iwai struct hda_input_mux *imux; 3513f2e5731dSTakashi Iwai int i; 3514f2e5731dSTakashi Iwai 3515f2e5731dSTakashi Iwai imux = &spec->private_imux; 3516f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3517f2e5731dSTakashi Iwai int idx = get_connection_index(codec, spec->adc_nids[0], 3518f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3519f2e5731dSTakashi Iwai if (idx >= 0) { 3520f2e5731dSTakashi Iwai const char *label; 3521f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3522f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 3523f2e5731dSTakashi Iwai } 3524f2e5731dSTakashi Iwai } 3525f2e5731dSTakashi Iwai if (imux->num_items == 2 && cfg->num_inputs == 2) 3526f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 3527f2e5731dSTakashi Iwai if (imux->num_items > 1 && !spec->auto_mic) 3528f2e5731dSTakashi Iwai spec->input_mux = imux; 3529f2e5731dSTakashi Iwai } 3530f2e5731dSTakashi Iwai 3531f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3532f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3533f2e5731dSTakashi Iwai { 3534f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3535f2e5731dSTakashi Iwai 3536f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3537f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3538f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3539f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3540f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3541f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3542f2e5731dSTakashi Iwai return nid; 3543f2e5731dSTakashi Iwai } 3544f2e5731dSTakashi Iwai } 3545f2e5731dSTakashi Iwai return 0; 3546f2e5731dSTakashi Iwai } 3547f2e5731dSTakashi Iwai 3548f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3549f2e5731dSTakashi Iwai { 3550f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3551f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3552f2e5731dSTakashi Iwai hda_nid_t nid; 3553f2e5731dSTakashi Iwai 3554f2e5731dSTakashi Iwai if (cfg->dig_outs && 3555f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3556f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3557f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3558f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3559f2e5731dSTakashi Iwai } 3560f2e5731dSTakashi Iwai 3561f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3562f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3563f2e5731dSTakashi Iwai { 3564f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3565f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3566f2e5731dSTakashi Iwai 3567f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3568f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3569f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3570f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3571f2e5731dSTakashi Iwai break; 3572f2e5731dSTakashi Iwai } 3573f2e5731dSTakashi Iwai } 3574f2e5731dSTakashi Iwai #else 3575f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3576f2e5731dSTakashi Iwai #endif 3577f2e5731dSTakashi Iwai 3578f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3579f2e5731dSTakashi Iwai { 3580f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3581f2e5731dSTakashi Iwai int err; 3582f2e5731dSTakashi Iwai 3583f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3584f2e5731dSTakashi Iwai if (err < 0) 3585f2e5731dSTakashi Iwai return err; 3586f2e5731dSTakashi Iwai 3587f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3588f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3589f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3590f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 3591f2e5731dSTakashi Iwai return 0; 3592f2e5731dSTakashi Iwai } 3593f2e5731dSTakashi Iwai 3594f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins, 3595f2e5731dSTakashi Iwai hda_nid_t *pins) 3596f2e5731dSTakashi Iwai { 3597f2e5731dSTakashi Iwai int i; 3598f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3599f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3600f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3601f2e5731dSTakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 0x02); 3602f2e5731dSTakashi Iwai } 3603f2e5731dSTakashi Iwai } 3604f2e5731dSTakashi Iwai 3605f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3606f2e5731dSTakashi Iwai hda_nid_t src) 3607f2e5731dSTakashi Iwai { 3608f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3609f2e5731dSTakashi Iwai if (idx >= 0) 3610f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3611f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3612f2e5731dSTakashi Iwai } 3613f2e5731dSTakashi Iwai 3614f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 3615f2e5731dSTakashi Iwai { 3616f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3617f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3618f2e5731dSTakashi Iwai hda_nid_t nid; 3619f2e5731dSTakashi Iwai int i; 3620f2e5731dSTakashi Iwai 3621f2e5731dSTakashi Iwai for (i = 0; i < spec->multiout.num_dacs; i++) 3622f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0, 3623f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); 3624f2e5731dSTakashi Iwai 3625f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3626f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3627f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 3628f2e5731dSTakashi Iwai if (spec->auto_mute) { 3629f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3630f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3631f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3632f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_HP_EVENT); 3633f2e5731dSTakashi Iwai } 3634f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3635f2e5731dSTakashi Iwai } else { 3636f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) 3637f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3638f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3639f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) 3640f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3641f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3642f2e5731dSTakashi Iwai } 3643f2e5731dSTakashi Iwai 3644f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3645f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3646f2e5731dSTakashi Iwai if (!nid) 3647f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 3648f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3649f2e5731dSTakashi Iwai } 3650f2e5731dSTakashi Iwai 3651f2e5731dSTakashi Iwai /* turn on EAPD */ 3652f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins); 3653f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins); 3654f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins); 3655f2e5731dSTakashi Iwai } 3656f2e5731dSTakashi Iwai 3657f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3658f2e5731dSTakashi Iwai { 3659f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3660f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3661f2e5731dSTakashi Iwai int i; 3662f2e5731dSTakashi Iwai 3663f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) 3664f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3665f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)); 3666f2e5731dSTakashi Iwai 3667f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3668f2e5731dSTakashi Iwai unsigned int type; 3669f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 3670f2e5731dSTakashi Iwai type = PIN_VREF80; 3671f2e5731dSTakashi Iwai else 3672f2e5731dSTakashi Iwai type = PIN_IN; 3673f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 3674f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 3675f2e5731dSTakashi Iwai } 3676f2e5731dSTakashi Iwai 3677f2e5731dSTakashi Iwai if (spec->auto_mic) { 3678f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3679f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0, 3680f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3681f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 3682f2e5731dSTakashi Iwai cx_auto_automic(codec); 3683f2e5731dSTakashi Iwai } else { 3684f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 3685f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3686f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3687f2e5731dSTakashi Iwai spec->private_imux.items[0].index); 3688f2e5731dSTakashi Iwai } 3689f2e5731dSTakashi Iwai } 3690f2e5731dSTakashi Iwai } 3691f2e5731dSTakashi Iwai 3692f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 3693f2e5731dSTakashi Iwai { 3694f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3695f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3696f2e5731dSTakashi Iwai 3697f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 3698f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 3699f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3700f2e5731dSTakashi Iwai if (spec->dig_in_nid) 3701f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 3702f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 3703f2e5731dSTakashi Iwai } 3704f2e5731dSTakashi Iwai 3705f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 3706f2e5731dSTakashi Iwai { 3707f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 3708f2e5731dSTakashi Iwai cx_auto_init_output(codec); 3709f2e5731dSTakashi Iwai cx_auto_init_input(codec); 3710f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 3711f2e5731dSTakashi Iwai return 0; 3712f2e5731dSTakashi Iwai } 3713f2e5731dSTakashi Iwai 3714f2e5731dSTakashi Iwai static int cx_auto_add_volume(struct hda_codec *codec, const char *basename, 3715f2e5731dSTakashi Iwai const char *dir, int cidx, 3716f2e5731dSTakashi Iwai hda_nid_t nid, int hda_dir) 3717f2e5731dSTakashi Iwai { 3718f2e5731dSTakashi Iwai static char name[32]; 3719f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 3720f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 3721f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 3722f2e5731dSTakashi Iwai }; 3723f2e5731dSTakashi Iwai static char *sfx[2] = { "Volume", "Switch" }; 3724f2e5731dSTakashi Iwai int i, err; 3725f2e5731dSTakashi Iwai 3726f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 3727f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 3728f2e5731dSTakashi Iwai knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir); 3729f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 3730f2e5731dSTakashi Iwai knew[i].index = cidx; 3731f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 3732f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 3733f2e5731dSTakashi Iwai if (!kctl) 3734f2e5731dSTakashi Iwai return -ENOMEM; 3735f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 3736f2e5731dSTakashi Iwai if (err < 0) 3737f2e5731dSTakashi Iwai return err; 3738f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 3739f2e5731dSTakashi Iwai break; 3740f2e5731dSTakashi Iwai } 3741f2e5731dSTakashi Iwai return 0; 3742f2e5731dSTakashi Iwai } 3743f2e5731dSTakashi Iwai 3744f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 3745f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 3746f2e5731dSTakashi Iwai 3747f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 3748f2e5731dSTakashi Iwai { 3749f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3750f2e5731dSTakashi Iwai int i, err; 3751f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 3752f2e5731dSTakashi Iwai static const char *texts[3] = { "Front", "Surround", "CLFE" }; 3753f2e5731dSTakashi Iwai 3754f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 3755f2e5731dSTakashi Iwai return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac, 3756f2e5731dSTakashi Iwai "Master", 0); 3757f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3758f2e5731dSTakashi Iwai const char *label; 3759f2e5731dSTakashi Iwai int idx, type; 3760f2e5731dSTakashi Iwai if (!spec->dac_info[i].dac) 3761f2e5731dSTakashi Iwai continue; 3762f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 3763f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 3764f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 3765f2e5731dSTakashi Iwai switch (type) { 3766f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3767f2e5731dSTakashi Iwai default: 3768f2e5731dSTakashi Iwai label = texts[num_line++]; 3769f2e5731dSTakashi Iwai idx = 0; 3770f2e5731dSTakashi Iwai break; 3771f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3772f2e5731dSTakashi Iwai label = "Headphone"; 3773f2e5731dSTakashi Iwai idx = num_hp++; 3774f2e5731dSTakashi Iwai break; 3775f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3776f2e5731dSTakashi Iwai label = "Speaker"; 3777f2e5731dSTakashi Iwai idx = num_spk++; 3778f2e5731dSTakashi Iwai break; 3779f2e5731dSTakashi Iwai } 3780f2e5731dSTakashi Iwai err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac, 3781f2e5731dSTakashi Iwai label, idx); 3782f2e5731dSTakashi Iwai if (err < 0) 3783f2e5731dSTakashi Iwai return err; 3784f2e5731dSTakashi Iwai } 3785f2e5731dSTakashi Iwai return 0; 3786f2e5731dSTakashi Iwai } 3787f2e5731dSTakashi Iwai 3788f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 3789f2e5731dSTakashi Iwai { 3790f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3791f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3792f2e5731dSTakashi Iwai static const char *prev_label; 3793f2e5731dSTakashi Iwai int i, err, cidx; 3794f2e5731dSTakashi Iwai 3795f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0], 3796f2e5731dSTakashi Iwai HDA_INPUT); 3797f2e5731dSTakashi Iwai if (err < 0) 3798f2e5731dSTakashi Iwai return err; 3799f2e5731dSTakashi Iwai prev_label = NULL; 3800f2e5731dSTakashi Iwai cidx = 0; 3801f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3802f2e5731dSTakashi Iwai hda_nid_t nid = cfg->inputs[i].pin; 3803f2e5731dSTakashi Iwai const char *label; 3804f2e5731dSTakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 3805f2e5731dSTakashi Iwai continue; 3806f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3807f2e5731dSTakashi Iwai if (label == prev_label) 3808f2e5731dSTakashi Iwai cidx++; 3809f2e5731dSTakashi Iwai else 3810f2e5731dSTakashi Iwai cidx = 0; 3811f2e5731dSTakashi Iwai prev_label = label; 3812f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, label, " Capture", cidx, 3813f2e5731dSTakashi Iwai nid, HDA_INPUT); 3814f2e5731dSTakashi Iwai if (err < 0) 3815f2e5731dSTakashi Iwai return err; 3816f2e5731dSTakashi Iwai } 3817f2e5731dSTakashi Iwai return 0; 3818f2e5731dSTakashi Iwai } 3819f2e5731dSTakashi Iwai 3820f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 3821f2e5731dSTakashi Iwai { 3822f2e5731dSTakashi Iwai int err; 3823f2e5731dSTakashi Iwai 3824f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 3825f2e5731dSTakashi Iwai if (err < 0) 3826f2e5731dSTakashi Iwai return err; 3827f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 3828f2e5731dSTakashi Iwai if (err < 0) 3829f2e5731dSTakashi Iwai return err; 3830f2e5731dSTakashi Iwai return conexant_build_controls(codec); 3831f2e5731dSTakashi Iwai } 3832f2e5731dSTakashi Iwai 3833f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = { 3834f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 3835f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 3836f2e5731dSTakashi Iwai .init = cx_auto_init, 3837f2e5731dSTakashi Iwai .free = conexant_free, 3838f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 3839f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 3840f2e5731dSTakashi Iwai .suspend = conexant_suspend, 3841f2e5731dSTakashi Iwai #endif 3842f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 3843f2e5731dSTakashi Iwai }; 3844f2e5731dSTakashi Iwai 3845f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 3846f2e5731dSTakashi Iwai { 3847f2e5731dSTakashi Iwai struct conexant_spec *spec; 3848f2e5731dSTakashi Iwai int err; 3849f2e5731dSTakashi Iwai 3850f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3851f2e5731dSTakashi Iwai if (!spec) 3852f2e5731dSTakashi Iwai return -ENOMEM; 3853f2e5731dSTakashi Iwai codec->spec = spec; 3854f2e5731dSTakashi Iwai spec->adc_nids = cx_auto_adc_nids; 3855f2e5731dSTakashi Iwai spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids); 3856f2e5731dSTakashi Iwai spec->capsrc_nids = spec->adc_nids; 3857f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 3858f2e5731dSTakashi Iwai if (err < 0) { 3859f2e5731dSTakashi Iwai kfree(codec->spec); 3860f2e5731dSTakashi Iwai codec->spec = NULL; 3861f2e5731dSTakashi Iwai return err; 3862f2e5731dSTakashi Iwai } 3863f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 3864f2e5731dSTakashi Iwai if (spec->beep_amp) 3865f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 3866f2e5731dSTakashi Iwai return 0; 3867f2e5731dSTakashi Iwai } 3868f2e5731dSTakashi Iwai 3869f2e5731dSTakashi Iwai /* 3870461e2c78STakashi Iwai */ 3871461e2c78STakashi Iwai 38721289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 387382f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 387482f30040STobin Davis .patch = patch_cxt5045 }, 387582f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 387682f30040STobin Davis .patch = patch_cxt5047 }, 3877461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 3878461e2c78STakashi Iwai .patch = patch_cxt5051 }, 38790fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 38800fb67e98SDaniel Drake .patch = patch_cxt5066 }, 388195a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 388295a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 3883850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 3884850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 38857b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 38867b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 3887f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 3888f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3889f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 3890f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3891f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 3892f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3893f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 3894f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3895f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 3896f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3897f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 3898f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3899f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 3900f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3901f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 3902f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3903c9b443d4STobin Davis {} /* terminator */ 3904c9b443d4STobin Davis }; 39051289e9e8STakashi Iwai 39061289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 39071289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 39081289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 39090fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 391095a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 3911850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 39127b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 3913f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 3914f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 3915f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 3916f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 3917f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 3918f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 3919f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 3920f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 39211289e9e8STakashi Iwai 39221289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 39231289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 39241289e9e8STakashi Iwai 39251289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 39261289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 39271289e9e8STakashi Iwai .owner = THIS_MODULE, 39281289e9e8STakashi Iwai }; 39291289e9e8STakashi Iwai 39301289e9e8STakashi Iwai static int __init patch_conexant_init(void) 39311289e9e8STakashi Iwai { 39321289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 39331289e9e8STakashi Iwai } 39341289e9e8STakashi Iwai 39351289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 39361289e9e8STakashi Iwai { 39371289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 39381289e9e8STakashi Iwai } 39391289e9e8STakashi Iwai 39401289e9e8STakashi Iwai module_init(patch_conexant_init) 39411289e9e8STakashi Iwai module_exit(patch_conexant_exit) 3942