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 21140fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 21150fb67e98SDaniel Drake { 21160fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 21170fb67e98SDaniel Drake unsigned int pinctl; 21180fb67e98SDaniel Drake 21190fb67e98SDaniel Drake snd_printdd("CXT5066: update speaker, hp_present=%d\n", 21200fb67e98SDaniel Drake spec->hp_present); 21210fb67e98SDaniel Drake 21220fb67e98SDaniel Drake /* Port A (HP) */ 21230fb67e98SDaniel Drake pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 21240fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21250fb67e98SDaniel Drake pinctl); 21260fb67e98SDaniel Drake 21270fb67e98SDaniel Drake /* Port D (HP/LO) */ 21280fb67e98SDaniel Drake pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 21290fb67e98SDaniel Drake ? spec->port_d_mode : 0; 21307b2bfdbcSJens Taprogge /* Mute if Port A is connected on Thinkpad */ 21317b2bfdbcSJens Taprogge if (spec->thinkpad && (spec->hp_present & 1)) 21327b2bfdbcSJens Taprogge pinctl = 0; 21330fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21340fb67e98SDaniel Drake pinctl); 21350fb67e98SDaniel Drake 21360fb67e98SDaniel Drake /* CLASS_D AMP */ 21370fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21380fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21390fb67e98SDaniel Drake pinctl); 21400fb67e98SDaniel Drake 21410fb67e98SDaniel Drake if (spec->dell_automute) { 21420fb67e98SDaniel Drake /* DELL AIO Port Rule: PortA > PortD > IntSpk */ 21430fb67e98SDaniel Drake pinctl = (!(spec->hp_present & 1) && spec->cur_eapd) 21440fb67e98SDaniel Drake ? PIN_OUT : 0; 21450fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, 21460fb67e98SDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); 21470fb67e98SDaniel Drake } 21480fb67e98SDaniel Drake } 21490fb67e98SDaniel Drake 21500fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21510fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21520fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21530fb67e98SDaniel Drake { 21540fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21550fb67e98SDaniel Drake 21560fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21570fb67e98SDaniel Drake return 0; 21580fb67e98SDaniel Drake 21590fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21600fb67e98SDaniel Drake return 1; 21610fb67e98SDaniel Drake } 21620fb67e98SDaniel Drake 2163c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2164c4cfe66cSDaniel Drake .num_items = 3, 2165c4cfe66cSDaniel Drake .items = { 2166c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2167c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2168c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2169c4cfe66cSDaniel Drake }, 2170c4cfe66cSDaniel Drake }; 2171c4cfe66cSDaniel Drake 2172c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2173c4cfe66cSDaniel Drake { 2174c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2175c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2176c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2177c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2178c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2179c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2180c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2181c4cfe66cSDaniel Drake } 2182c4cfe66cSDaniel Drake 218375f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 218475f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 218575f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 218675f8991dSDaniel Drake * is happening when it is not. */ 218775f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21880fb67e98SDaniel Drake { 2189dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 219075f8991dSDaniel Drake if (!spec->recording) 219175f8991dSDaniel Drake return; 21920fb67e98SDaniel Drake 2193c4cfe66cSDaniel Drake if (spec->dc_enable) { 2194c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2195c4cfe66cSDaniel Drake * through our special DC port */ 2196c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2197c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2198c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2199c4cfe66cSDaniel Drake 2200c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2201c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2202c4cfe66cSDaniel Drake {}, 2203c4cfe66cSDaniel Drake }; 2204c4cfe66cSDaniel Drake 2205c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2206c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2207c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2208c4cfe66cSDaniel Drake return; 2209c4cfe66cSDaniel Drake } 2210c4cfe66cSDaniel Drake 2211c4cfe66cSDaniel Drake /* disable DC (port F) */ 2212c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2213c4cfe66cSDaniel Drake 221475f8991dSDaniel Drake /* external mic, port B */ 221575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 221675f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 22170fb67e98SDaniel Drake 221875f8991dSDaniel Drake /* internal mic, port C */ 221975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 222075f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 222175f8991dSDaniel Drake } 22220fb67e98SDaniel Drake 222375f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 222475f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 222575f8991dSDaniel Drake { 222675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 22270fb67e98SDaniel Drake unsigned int present; 22280fb67e98SDaniel Drake 2229c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2230c4cfe66cSDaniel Drake return; 2231c4cfe66cSDaniel Drake 223275f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 223375f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 223475f8991dSDaniel Drake if (present) 22350fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 223675f8991dSDaniel Drake else 22370fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 223875f8991dSDaniel Drake 223975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 224075f8991dSDaniel Drake present ? 0 : 1); 224175f8991dSDaniel Drake spec->ext_mic_present = !!present; 224275f8991dSDaniel Drake 224375f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22440fb67e98SDaniel Drake } 22450fb67e98SDaniel Drake 224695a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 224795a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 224895a618bdSEinar Rünkaru { 224995a618bdSEinar Rünkaru unsigned int present; 225095a618bdSEinar Rünkaru 225195a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 225295a618bdSEinar Rünkaru /* enable external mic, port B */ 225375f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 225495a618bdSEinar Rünkaru 225595a618bdSEinar Rünkaru /* switch to external mic input */ 225695a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 225795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 225895a618bdSEinar Rünkaru 225995a618bdSEinar Rünkaru /* disable internal digital mic */ 226095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 226195a618bdSEinar Rünkaru {} 226295a618bdSEinar Rünkaru }; 226395a618bdSEinar Rünkaru static struct hda_verb ext_mic_absent[] = { 226495a618bdSEinar Rünkaru /* enable internal mic, port C */ 226595a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 226695a618bdSEinar Rünkaru 226795a618bdSEinar Rünkaru /* switch to internal mic input */ 226895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 226995a618bdSEinar Rünkaru 227095a618bdSEinar Rünkaru /* disable external mic, port B */ 227195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 227295a618bdSEinar Rünkaru {} 227395a618bdSEinar Rünkaru }; 227495a618bdSEinar Rünkaru 227595a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 227695a618bdSEinar Rünkaru if (present) { 227795a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 227895a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 227995a618bdSEinar Rünkaru } else { 228095a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 228195a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 228295a618bdSEinar Rünkaru } 228395a618bdSEinar Rünkaru } 228495a618bdSEinar Rünkaru 2285cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2286cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2287cfd3d8dcSGreg Alexander { 2288cfd3d8dcSGreg Alexander unsigned int present; 2289cfd3d8dcSGreg Alexander 2290cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2291cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2292cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2293cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2294cfd3d8dcSGreg Alexander {} 2295cfd3d8dcSGreg Alexander }; 2296cfd3d8dcSGreg Alexander static struct hda_verb ext_mic_absent[] = { 2297cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2298cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2299cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2300cfd3d8dcSGreg Alexander {} 2301cfd3d8dcSGreg Alexander }; 2302cfd3d8dcSGreg Alexander 2303cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2304cfd3d8dcSGreg Alexander if (present) { 2305cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2306cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2307cfd3d8dcSGreg Alexander } else { 2308cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2309cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2310cfd3d8dcSGreg Alexander } 2311cfd3d8dcSGreg Alexander } 2312cfd3d8dcSGreg Alexander 2313048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2314048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2315048e78a5SDavid Henningsson { 2316048e78a5SDavid Henningsson unsigned int present; 2317048e78a5SDavid Henningsson 2318048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2319048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2320048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2321048e78a5SDavid Henningsson present ? 1 : 3); 2322048e78a5SDavid Henningsson } 2323048e78a5SDavid Henningsson 2324048e78a5SDavid Henningsson 23257b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 23267b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 23277b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23287b2bfdbcSJens Taprogge { 23297b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23307b2bfdbcSJens Taprogge 23317b2bfdbcSJens Taprogge static struct hda_verb ext_mic_present[] = { 23327b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23337b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23347b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23357b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23367b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23377b2bfdbcSJens Taprogge {} 23387b2bfdbcSJens Taprogge }; 23397b2bfdbcSJens Taprogge static struct hda_verb dock_mic_present[] = { 23407b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23417b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23427b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23437b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23447b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23457b2bfdbcSJens Taprogge {} 23467b2bfdbcSJens Taprogge }; 23477b2bfdbcSJens Taprogge static struct hda_verb ext_mic_absent[] = { 23487b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23497b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23507b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23517b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23527b2bfdbcSJens Taprogge {} 23537b2bfdbcSJens Taprogge }; 23547b2bfdbcSJens Taprogge 23557b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23567b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23577b2bfdbcSJens Taprogge if (ext_present) { 23587b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23597b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23607b2bfdbcSJens Taprogge } else if (dock_present) { 23617b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23627b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23637b2bfdbcSJens Taprogge } else { 23647b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23657b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23667b2bfdbcSJens Taprogge } 23677b2bfdbcSJens Taprogge } 23687b2bfdbcSJens Taprogge 23690fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23700fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23710fb67e98SDaniel Drake { 23720fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23730fb67e98SDaniel Drake unsigned int portA, portD; 23740fb67e98SDaniel Drake 23750fb67e98SDaniel Drake /* Port A */ 2376d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23770fb67e98SDaniel Drake 23780fb67e98SDaniel Drake /* Port D */ 2379d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23800fb67e98SDaniel Drake 23817b2bfdbcSJens Taprogge spec->hp_present = !!(portA); 23827b2bfdbcSJens Taprogge spec->hp_present |= portD ? 2 : 0; 23830fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23840fb67e98SDaniel Drake portA, portD, spec->hp_present); 23850fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23860fb67e98SDaniel Drake } 23870fb67e98SDaniel Drake 23880fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 238975f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23900fb67e98SDaniel Drake { 2391c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23920fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23930fb67e98SDaniel Drake switch (res >> 26) { 23940fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23950fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23960fb67e98SDaniel Drake break; 23970fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2398c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2399c4cfe66cSDaniel Drake if (!spec->dc_enable) 240075f8991dSDaniel Drake cxt5066_olpc_automic(codec); 24010fb67e98SDaniel Drake break; 24020fb67e98SDaniel Drake } 24030fb67e98SDaniel Drake } 24040fb67e98SDaniel Drake 240595a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 240695a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res) 240795a618bdSEinar Rünkaru { 240895a618bdSEinar Rünkaru snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26); 240995a618bdSEinar Rünkaru switch (res >> 26) { 241095a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 241195a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 241295a618bdSEinar Rünkaru break; 241395a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 241495a618bdSEinar Rünkaru cxt5066_vostro_automic(codec); 241595a618bdSEinar Rünkaru break; 241695a618bdSEinar Rünkaru } 241795a618bdSEinar Rünkaru } 241895a618bdSEinar Rünkaru 2419cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */ 2420cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res) 2421cfd3d8dcSGreg Alexander { 2422cfd3d8dcSGreg Alexander snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26); 2423cfd3d8dcSGreg Alexander switch (res >> 26) { 2424cfd3d8dcSGreg Alexander case CONEXANT_HP_EVENT: 2425cfd3d8dcSGreg Alexander cxt5066_hp_automute(codec); 2426cfd3d8dcSGreg Alexander break; 2427cfd3d8dcSGreg Alexander case CONEXANT_MIC_EVENT: 2428cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 2429cfd3d8dcSGreg Alexander break; 2430cfd3d8dcSGreg Alexander } 2431cfd3d8dcSGreg Alexander } 2432cfd3d8dcSGreg Alexander 24337b2bfdbcSJens Taprogge /* unsolicited event for jack sensing */ 2434048e78a5SDavid Henningsson static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res) 2435048e78a5SDavid Henningsson { 2436048e78a5SDavid Henningsson snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26); 2437048e78a5SDavid Henningsson switch (res >> 26) { 2438048e78a5SDavid Henningsson case CONEXANT_HP_EVENT: 2439048e78a5SDavid Henningsson cxt5066_hp_automute(codec); 2440048e78a5SDavid Henningsson break; 2441048e78a5SDavid Henningsson case CONEXANT_MIC_EVENT: 2442048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2443048e78a5SDavid Henningsson break; 2444048e78a5SDavid Henningsson } 2445048e78a5SDavid Henningsson } 2446048e78a5SDavid Henningsson 2447048e78a5SDavid Henningsson /* unsolicited event for jack sensing */ 24487b2bfdbcSJens Taprogge static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res) 24497b2bfdbcSJens Taprogge { 24507b2bfdbcSJens Taprogge snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26); 24517b2bfdbcSJens Taprogge switch (res >> 26) { 24527b2bfdbcSJens Taprogge case CONEXANT_HP_EVENT: 24537b2bfdbcSJens Taprogge cxt5066_hp_automute(codec); 24547b2bfdbcSJens Taprogge break; 24557b2bfdbcSJens Taprogge case CONEXANT_MIC_EVENT: 24567b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 24577b2bfdbcSJens Taprogge break; 24587b2bfdbcSJens Taprogge } 24597b2bfdbcSJens Taprogge } 24607b2bfdbcSJens Taprogge 24610fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24620fb67e98SDaniel Drake .num_items = 5, 24630fb67e98SDaniel Drake .items = { 24640fb67e98SDaniel Drake { "0dB", 0 }, 24650fb67e98SDaniel Drake { "10dB", 1 }, 24660fb67e98SDaniel Drake { "20dB", 2 }, 24670fb67e98SDaniel Drake { "30dB", 3 }, 24680fb67e98SDaniel Drake { "40dB", 4 }, 24690fb67e98SDaniel Drake }, 24700fb67e98SDaniel Drake }; 24710fb67e98SDaniel Drake 2472cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2473c4cfe66cSDaniel Drake { 2474c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2475cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2476c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2477c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2478c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24797b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2480cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2481cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2482cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2483cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2484cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2485cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2486cfd3d8dcSGreg Alexander } 2487c4cfe66cSDaniel Drake } 2488c4cfe66cSDaniel Drake 24890fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24900fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24910fb67e98SDaniel Drake { 24920fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24930fb67e98SDaniel Drake } 24940fb67e98SDaniel Drake 24950fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24960fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24970fb67e98SDaniel Drake { 24980fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2499c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2500c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 25010fb67e98SDaniel Drake return 0; 25020fb67e98SDaniel Drake } 25030fb67e98SDaniel Drake 25040fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 25050fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 25060fb67e98SDaniel Drake { 25070fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2508c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 25090fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 25100fb67e98SDaniel Drake unsigned int idx; 25110fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 25120fb67e98SDaniel Drake if (idx >= imux->num_items) 25130fb67e98SDaniel Drake idx = imux->num_items - 1; 25140fb67e98SDaniel Drake 2515c4cfe66cSDaniel Drake spec->mic_boost = idx; 2516c4cfe66cSDaniel Drake if (!spec->dc_enable) 2517c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2518c4cfe66cSDaniel Drake return 1; 2519c4cfe66cSDaniel Drake } 25200fb67e98SDaniel Drake 2521c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2522c4cfe66cSDaniel Drake { 2523c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2524c4cfe66cSDaniel Drake /* disable gain */ 2525c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2526c4cfe66cSDaniel Drake 2527c4cfe66cSDaniel Drake /* switch to DC input */ 2528c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2529c4cfe66cSDaniel Drake {} 2530c4cfe66cSDaniel Drake }; 2531c4cfe66cSDaniel Drake 2532c4cfe66cSDaniel Drake /* configure as input source */ 2533c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2534c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2535c4cfe66cSDaniel Drake } 2536c4cfe66cSDaniel Drake 2537c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2538c4cfe66cSDaniel Drake { 2539c4cfe66cSDaniel Drake /* reconfigure input source */ 2540c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2541c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2542c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2543c4cfe66cSDaniel Drake } 2544c4cfe66cSDaniel Drake 2545c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2546c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2547c4cfe66cSDaniel Drake { 2548c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2549c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2550c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2551c4cfe66cSDaniel Drake return 0; 2552c4cfe66cSDaniel Drake } 2553c4cfe66cSDaniel Drake 2554c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2555c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2556c4cfe66cSDaniel Drake { 2557c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2558c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2559c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2560c4cfe66cSDaniel Drake 2561c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2562c4cfe66cSDaniel Drake return 0; 2563c4cfe66cSDaniel Drake 2564c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2565c4cfe66cSDaniel Drake if (dc_enable) 2566c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2567c4cfe66cSDaniel Drake else 2568c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2569c4cfe66cSDaniel Drake 2570c4cfe66cSDaniel Drake return 1; 2571c4cfe66cSDaniel Drake } 2572c4cfe66cSDaniel Drake 2573c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2574c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2575c4cfe66cSDaniel Drake { 2576c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2577c4cfe66cSDaniel Drake } 2578c4cfe66cSDaniel Drake 2579c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2580c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2581c4cfe66cSDaniel Drake { 2582c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2583c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2584c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2585c4cfe66cSDaniel Drake return 0; 2586c4cfe66cSDaniel Drake } 2587c4cfe66cSDaniel Drake 2588c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2589c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2590c4cfe66cSDaniel Drake { 2591c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2592c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2593c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2594c4cfe66cSDaniel Drake unsigned int idx; 2595c4cfe66cSDaniel Drake 2596c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2597c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2598c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2599c4cfe66cSDaniel Drake 2600c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2601c4cfe66cSDaniel Drake if (spec->dc_enable) 2602c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 26030fb67e98SDaniel Drake return 1; 26040fb67e98SDaniel Drake } 26050fb67e98SDaniel Drake 260675f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 260775f8991dSDaniel Drake { 260875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 260975f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 261075f8991dSDaniel Drake * recording LED comes on. */ 261175f8991dSDaniel Drake spec->recording = 1; 261275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 261375f8991dSDaniel Drake } 261475f8991dSDaniel Drake 261575f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 261675f8991dSDaniel Drake { 261775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 261875f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 261975f8991dSDaniel Drake /* disable external mic, port B */ 262075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 262175f8991dSDaniel Drake 262275f8991dSDaniel Drake /* disble internal mic, port C */ 262375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2624c4cfe66cSDaniel Drake 2625c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2626c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 262775f8991dSDaniel Drake {}, 262875f8991dSDaniel Drake }; 262975f8991dSDaniel Drake 263075f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 263175f8991dSDaniel Drake spec->recording = 0; 263275f8991dSDaniel Drake } 263375f8991dSDaniel Drake 26340fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 26350fb67e98SDaniel Drake .num_items = 4, 26360fb67e98SDaniel Drake .items = { 26370fb67e98SDaniel Drake { "Mic B", 0 }, 26380fb67e98SDaniel Drake { "Mic C", 1 }, 26390fb67e98SDaniel Drake { "Mic E", 2 }, 26400fb67e98SDaniel Drake { "Mic F", 3 }, 26410fb67e98SDaniel Drake }, 26420fb67e98SDaniel Drake }; 26430fb67e98SDaniel Drake 26440fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26450fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26460fb67e98SDaniel Drake .values = { 26470fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26480fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26490fb67e98SDaniel Drake 0 26500fb67e98SDaniel Drake }, 26510fb67e98SDaniel Drake }; 26520fb67e98SDaniel Drake 26530fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26540fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26550fb67e98SDaniel Drake .values = { 26560fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26570fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26580fb67e98SDaniel Drake 0 26590fb67e98SDaniel Drake }, 26600fb67e98SDaniel Drake }; 26610fb67e98SDaniel Drake 26620fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 26630fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26640fb67e98SDaniel Drake {} 26650fb67e98SDaniel Drake }; 26660fb67e98SDaniel Drake 26670fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26680fb67e98SDaniel Drake { 26690fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26700fb67e98SDaniel Drake .name = "Master Playback Volume", 26710fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26720fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26730fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26745e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26750fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26760fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26770fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26780fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26790fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26800fb67e98SDaniel Drake .private_value = 26810fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26820fb67e98SDaniel Drake }, 26830fb67e98SDaniel Drake {} 26840fb67e98SDaniel Drake }; 26850fb67e98SDaniel Drake 2686c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2687c4cfe66cSDaniel Drake { 2688c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2689c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2690c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2691c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2692c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2693c4cfe66cSDaniel Drake }, 2694c4cfe66cSDaniel Drake { 2695c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2696c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2697c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2698c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2699c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2700c4cfe66cSDaniel Drake }, 2701c4cfe66cSDaniel Drake {} 2702c4cfe66cSDaniel Drake }; 2703c4cfe66cSDaniel Drake 27040fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 27050fb67e98SDaniel Drake { 27060fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 27070fb67e98SDaniel Drake .name = "Master Playback Switch", 27080fb67e98SDaniel Drake .info = cxt_eapd_info, 27090fb67e98SDaniel Drake .get = cxt_eapd_get, 27100fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 27110fb67e98SDaniel Drake .private_value = 0x1d, 27120fb67e98SDaniel Drake }, 27130fb67e98SDaniel Drake 27140fb67e98SDaniel Drake { 27150fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2716c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 27170fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 27180fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 27190fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 27200fb67e98SDaniel Drake }, 27210fb67e98SDaniel Drake 27220fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 27230fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 27240fb67e98SDaniel Drake {} 27250fb67e98SDaniel Drake }; 27260fb67e98SDaniel Drake 2727254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2728254bba6aSEinar Rünkaru { 2729254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2730254bba6aSEinar Rünkaru .name = "Int Mic Boost Capture Enum", 2731254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2732254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2733254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2734254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2735254bba6aSEinar Rünkaru }, 2736254bba6aSEinar Rünkaru {} 2737254bba6aSEinar Rünkaru }; 2738254bba6aSEinar Rünkaru 27390fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 27400fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27410fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27420fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27430fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27440fb67e98SDaniel Drake 27450fb67e98SDaniel Drake /* Speakers */ 27460fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27470fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27480fb67e98SDaniel Drake 27490fb67e98SDaniel Drake /* HP, Amp */ 27500fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27510fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27520fb67e98SDaniel Drake 27530fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27540fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27550fb67e98SDaniel Drake 27560fb67e98SDaniel Drake /* DAC1 */ 27570fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27580fb67e98SDaniel Drake 27590fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27600fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27610fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27620fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27630fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27640fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27650fb67e98SDaniel Drake 27660fb67e98SDaniel Drake /* no digital microphone support yet */ 27670fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27680fb67e98SDaniel Drake 27690fb67e98SDaniel Drake /* Audio input selector */ 27700fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27710fb67e98SDaniel Drake 27720fb67e98SDaniel Drake /* SPDIF route: PCM */ 27730fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27740fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27750fb67e98SDaniel Drake 27760fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27770fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27780fb67e98SDaniel Drake 27790fb67e98SDaniel Drake /* EAPD */ 27800fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27810fb67e98SDaniel Drake 27820fb67e98SDaniel Drake /* not handling these yet */ 27830fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27840fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27850fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27860fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27870fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27880fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27890fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27900fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27910fb67e98SDaniel Drake { } /* end */ 27920fb67e98SDaniel Drake }; 27930fb67e98SDaniel Drake 27940fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 27950fb67e98SDaniel Drake /* Port A: headphones */ 27960fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27970fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27980fb67e98SDaniel Drake 27990fb67e98SDaniel Drake /* Port B: external microphone */ 280075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28010fb67e98SDaniel Drake 28020fb67e98SDaniel Drake /* Port C: internal microphone */ 280375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28040fb67e98SDaniel Drake 28050fb67e98SDaniel Drake /* Port D: unused */ 28060fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28070fb67e98SDaniel Drake 28080fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 28090fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28100fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28110fb67e98SDaniel Drake 2812c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 28130fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28140fb67e98SDaniel Drake 28150fb67e98SDaniel Drake /* Port G: internal speakers */ 28160fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28170fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28180fb67e98SDaniel Drake 28190fb67e98SDaniel Drake /* DAC1 */ 28200fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28210fb67e98SDaniel Drake 28220fb67e98SDaniel Drake /* DAC2: unused */ 28230fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 28240fb67e98SDaniel Drake 28250fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28260fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28270fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28280fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28290fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28300fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28310fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28320fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28330fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28340fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28350fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28360fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28370fb67e98SDaniel Drake 28380fb67e98SDaniel Drake /* Disable digital microphone port */ 28390fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28400fb67e98SDaniel Drake 28410fb67e98SDaniel Drake /* Audio input selectors */ 28420fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28430fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28440fb67e98SDaniel Drake 28450fb67e98SDaniel Drake /* Disable SPDIF */ 28460fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28470fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28480fb67e98SDaniel Drake 28490fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28500fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28510fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28520fb67e98SDaniel Drake { } /* end */ 28530fb67e98SDaniel Drake }; 28540fb67e98SDaniel Drake 285595a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = { 285695a618bdSEinar Rünkaru /* Port A: headphones */ 285795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 285895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 285995a618bdSEinar Rünkaru 286095a618bdSEinar Rünkaru /* Port B: external microphone */ 286195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286295a618bdSEinar Rünkaru 286395a618bdSEinar Rünkaru /* Port C: unused */ 286495a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286595a618bdSEinar Rünkaru 286695a618bdSEinar Rünkaru /* Port D: unused */ 286795a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286895a618bdSEinar Rünkaru 286995a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 287095a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287195a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 287295a618bdSEinar Rünkaru 287395a618bdSEinar Rünkaru /* Port F: unused */ 287495a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287595a618bdSEinar Rünkaru 287695a618bdSEinar Rünkaru /* Port G: internal speakers */ 287795a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 287895a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 287995a618bdSEinar Rünkaru 288095a618bdSEinar Rünkaru /* DAC1 */ 288195a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 288295a618bdSEinar Rünkaru 288395a618bdSEinar Rünkaru /* DAC2: unused */ 288495a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 288595a618bdSEinar Rünkaru 288695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 288795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 288895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 288995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289895a618bdSEinar Rünkaru 289995a618bdSEinar Rünkaru /* Digital microphone port */ 290095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 290195a618bdSEinar Rünkaru 290295a618bdSEinar Rünkaru /* Audio input selectors */ 290395a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 290495a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 290595a618bdSEinar Rünkaru 290695a618bdSEinar Rünkaru /* Disable SPDIF */ 290795a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 290895a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 290995a618bdSEinar Rünkaru 291095a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 291195a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 291295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 291395a618bdSEinar Rünkaru { } /* end */ 291495a618bdSEinar Rünkaru }; 291595a618bdSEinar Rünkaru 2916cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = { 2917cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2918cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2919cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2920cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2921cfd3d8dcSGreg Alexander 2922cfd3d8dcSGreg Alexander /* Speakers */ 2923cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2924cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2925cfd3d8dcSGreg Alexander 2926cfd3d8dcSGreg Alexander /* HP, Amp */ 2927cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2928cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2929cfd3d8dcSGreg Alexander 2930cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2931cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2932cfd3d8dcSGreg Alexander 2933cfd3d8dcSGreg Alexander /* DAC1 */ 2934cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2935cfd3d8dcSGreg Alexander 2936cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2937cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2938cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2939cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2940cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2941cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2942cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2943cfd3d8dcSGreg Alexander 2944cfd3d8dcSGreg Alexander /* Audio input selector */ 2945cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2946cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2947cfd3d8dcSGreg Alexander 2948cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2949cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2950cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2951cfd3d8dcSGreg Alexander 2952cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2953cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2954cfd3d8dcSGreg Alexander 2955cfd3d8dcSGreg Alexander /* internal microphone */ 2956cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 2957cfd3d8dcSGreg Alexander 2958cfd3d8dcSGreg Alexander /* EAPD */ 2959cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2960cfd3d8dcSGreg Alexander 2961cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2962cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2963cfd3d8dcSGreg Alexander { } /* end */ 2964cfd3d8dcSGreg Alexander }; 2965cfd3d8dcSGreg Alexander 29667b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29677b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29687b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29697b2bfdbcSJens Taprogge 29707b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29717b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29727b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29737b2bfdbcSJens Taprogge 29747b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29757b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29767b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29777b2bfdbcSJens Taprogge 29787b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29797b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29807b2bfdbcSJens Taprogge 29817b2bfdbcSJens Taprogge /* Port C: Mic */ 29827b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29837b2bfdbcSJens Taprogge 29847b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29857b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29867b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29877b2bfdbcSJens Taprogge 29887b2bfdbcSJens Taprogge /* DAC1 */ 29897b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29907b2bfdbcSJens Taprogge 29917b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29927b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29937b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29947b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29957b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29967b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29977b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29987b2bfdbcSJens Taprogge 29997b2bfdbcSJens Taprogge /* Audio input selector */ 30007b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 30017b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 30027b2bfdbcSJens Taprogge 30037b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 30047b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 30057b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 30067b2bfdbcSJens Taprogge 30077b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30087b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30097b2bfdbcSJens Taprogge 30107b2bfdbcSJens Taprogge /* internal microphone */ 30117b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 30127b2bfdbcSJens Taprogge 30137b2bfdbcSJens Taprogge /* EAPD */ 30147b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 30157b2bfdbcSJens Taprogge 30167b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 30177b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30187b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30197b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30207b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30217b2bfdbcSJens Taprogge { } /* end */ 30227b2bfdbcSJens Taprogge }; 30237b2bfdbcSJens Taprogge 30240fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 30250fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30260fb67e98SDaniel Drake { } /* end */ 30270fb67e98SDaniel Drake }; 30280fb67e98SDaniel Drake 3029048e78a5SDavid Henningsson 3030048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3031048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3032048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3033048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3034048e78a5SDavid Henningsson { } /* end */ 3035048e78a5SDavid Henningsson }; 3036048e78a5SDavid Henningsson 30370fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30380fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30390fb67e98SDaniel Drake { 3040254bba6aSEinar Rünkaru struct conexant_spec *spec = codec->spec; 3041254bba6aSEinar Rünkaru 30420fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30430fb67e98SDaniel Drake conexant_init(codec); 30440fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30450fb67e98SDaniel Drake cxt5066_hp_automute(codec); 3046254bba6aSEinar Rünkaru if (spec->dell_vostro) 3047254bba6aSEinar Rünkaru cxt5066_vostro_automic(codec); 3048cfd3d8dcSGreg Alexander else if (spec->ideapad) 3049cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 30507b2bfdbcSJens Taprogge else if (spec->thinkpad) 30517b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 3052048e78a5SDavid Henningsson else if (spec->hp_laptop) 3053048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 30540fb67e98SDaniel Drake } 3055c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30560fb67e98SDaniel Drake return 0; 30570fb67e98SDaniel Drake } 30580fb67e98SDaniel Drake 305975f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 306075f8991dSDaniel Drake { 3061c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 306275f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 306375f8991dSDaniel Drake conexant_init(codec); 306475f8991dSDaniel Drake cxt5066_hp_automute(codec); 3065c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3066c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 306775f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3068c4cfe66cSDaniel Drake } else { 3069c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3070c4cfe66cSDaniel Drake } 307175f8991dSDaniel Drake return 0; 307275f8991dSDaniel Drake } 307375f8991dSDaniel Drake 30740fb67e98SDaniel Drake enum { 30750fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30760fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30770fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 307895a618bdSEinar Rünkaru CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */ 3079cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30807b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3081048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 30820fb67e98SDaniel Drake CXT5066_MODELS 30830fb67e98SDaniel Drake }; 30840fb67e98SDaniel Drake 30850fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = { 30860fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30870fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30880fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 3089cfd3d8dcSGreg Alexander [CXT5066_DELL_VOSTO] = "dell-vostro", 3090cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30917b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3092048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 30930fb67e98SDaniel Drake }; 30940fb67e98SDaniel Drake 30950fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30960fb67e98SDaniel Drake SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30970fb67e98SDaniel Drake CXT5066_LAPTOP), 30980fb67e98SDaniel Drake SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 30990fb67e98SDaniel Drake CXT5066_DELL_LAPTOP), 3100798a8a15SDaniel Drake SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 3101*3b119f66STakashi Iwai SND_PCI_QUIRK(0x1025, 0x040a, "Acer", CXT5066_IDEAPAD), 3102c3e68fadSTakashi Iwai SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTO), 310395a618bdSEinar Rünkaru SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO), 3104231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3105048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", 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), 31094d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 31100217f149SAndrej Gelenberg SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD), 3111badf18b5SAndreas Herrmann SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD), 3112a39e33ebSJerone Young SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD), 31137b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3114ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD), 31156f0ef6eaSJerone Young SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD), 3116ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD), 3117ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD), 31180fb67e98SDaniel Drake {} 31190fb67e98SDaniel Drake }; 31200fb67e98SDaniel Drake 31210fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 31220fb67e98SDaniel Drake { 31230fb67e98SDaniel Drake struct conexant_spec *spec; 31240fb67e98SDaniel Drake int board_config; 31250fb67e98SDaniel Drake 31260fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31270fb67e98SDaniel Drake if (!spec) 31280fb67e98SDaniel Drake return -ENOMEM; 31290fb67e98SDaniel Drake codec->spec = spec; 31300fb67e98SDaniel Drake 31310fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 313275f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31330fb67e98SDaniel Drake 31340fb67e98SDaniel Drake spec->dell_automute = 0; 31350fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31360fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31370fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 31380fb67e98SDaniel Drake spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT; 31390fb67e98SDaniel Drake spec->num_adc_nids = 1; 31400fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31410fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31420fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31430fb67e98SDaniel Drake 31440fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31450fb67e98SDaniel Drake 31460fb67e98SDaniel Drake spec->num_init_verbs = 1; 31470fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31480fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31490fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31500fb67e98SDaniel Drake spec->cur_adc = 0; 31510fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31520fb67e98SDaniel Drake 31533507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31543507e2a8STakashi Iwai 31550fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 31560fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 31570fb67e98SDaniel Drake switch (board_config) { 31580fb67e98SDaniel Drake default: 31590fb67e98SDaniel Drake case CXT5066_LAPTOP: 31600fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31610fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31620fb67e98SDaniel Drake break; 31630fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31640fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31650fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31660fb67e98SDaniel Drake 31670fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31680fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31690fb67e98SDaniel Drake spec->num_init_verbs++; 31700fb67e98SDaniel Drake spec->dell_automute = 1; 31710fb67e98SDaniel Drake break; 3172048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3173048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 3174048e78a5SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_hp_laptop_event; 3175048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3176048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3177048e78a5SDavid Henningsson spec->num_init_verbs++; 3178048e78a5SDavid Henningsson spec->hp_laptop = 1; 3179048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3180048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3181048e78a5SDavid Henningsson /* no S/PDIF out */ 3182048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3183048e78a5SDavid Henningsson /* input source automatically selected */ 3184048e78a5SDavid Henningsson spec->input_mux = NULL; 3185048e78a5SDavid Henningsson spec->port_d_mode = 0; 3186048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3187048e78a5SDavid Henningsson break; 3188048e78a5SDavid Henningsson 31890fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 319075f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 319175f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31920fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31930fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3194c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31950fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31960fb67e98SDaniel Drake spec->port_d_mode = 0; 3197c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31980fb67e98SDaniel Drake 31990fb67e98SDaniel Drake /* no S/PDIF out */ 32000fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 32010fb67e98SDaniel Drake 32020fb67e98SDaniel Drake /* input source automatically selected */ 32030fb67e98SDaniel Drake spec->input_mux = NULL; 320475f8991dSDaniel Drake 320575f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 320675f8991dSDaniel Drake * at the right time */ 320775f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 320875f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 32090fb67e98SDaniel Drake break; 321095a618bdSEinar Rünkaru case CXT5066_DELL_VOSTO: 321175f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 321295a618bdSEinar Rünkaru codec->patch_ops.unsol_event = cxt5066_vostro_event; 321395a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 321495a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 321595a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3216254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 321795a618bdSEinar Rünkaru spec->port_d_mode = 0; 3218254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3219c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 322095a618bdSEinar Rünkaru 322195a618bdSEinar Rünkaru /* no S/PDIF out */ 322295a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 322395a618bdSEinar Rünkaru 322495a618bdSEinar Rünkaru /* input source automatically selected */ 322595a618bdSEinar Rünkaru spec->input_mux = NULL; 322695a618bdSEinar Rünkaru break; 3227cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3228cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 3229cfd3d8dcSGreg Alexander codec->patch_ops.unsol_event = cxt5066_ideapad_event; 3230cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3231cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3232cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3233cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3234cfd3d8dcSGreg Alexander spec->ideapad = 1; 3235cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3236cfd3d8dcSGreg Alexander 3237cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3238cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3239cfd3d8dcSGreg Alexander 3240cfd3d8dcSGreg Alexander /* input source automatically selected */ 3241cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3242cfd3d8dcSGreg Alexander break; 32437b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32447b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 32457b2bfdbcSJens Taprogge codec->patch_ops.unsol_event = cxt5066_thinkpad_event; 32467b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32477b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32487b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32497b2bfdbcSJens Taprogge spec->thinkpad = 1; 32507b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32517b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32527b2bfdbcSJens Taprogge 32537b2bfdbcSJens Taprogge /* no S/PDIF out */ 32547b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32557b2bfdbcSJens Taprogge 32567b2bfdbcSJens Taprogge /* input source automatically selected */ 32577b2bfdbcSJens Taprogge spec->input_mux = NULL; 32587b2bfdbcSJens Taprogge break; 32590fb67e98SDaniel Drake } 32600fb67e98SDaniel Drake 32613507e2a8STakashi Iwai if (spec->beep_amp) 32623507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32633507e2a8STakashi Iwai 32640fb67e98SDaniel Drake return 0; 32650fb67e98SDaniel Drake } 3266461e2c78STakashi Iwai 3267461e2c78STakashi Iwai /* 3268f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3269f2e5731dSTakashi Iwai */ 3270f2e5731dSTakashi Iwai 3271f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3272f2e5731dSTakashi Iwai 3273f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */ 3274f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, 3275f2e5731dSTakashi Iwai hda_nid_t nid) 3276f2e5731dSTakashi Iwai { 3277f2e5731dSTakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 3278f2e5731dSTakashi Iwai int i, nums; 3279f2e5731dSTakashi Iwai 3280f2e5731dSTakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 3281f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) 3282f2e5731dSTakashi Iwai if (conn[i] == nid) 3283f2e5731dSTakashi Iwai return i; 3284f2e5731dSTakashi Iwai return -1; 3285f2e5731dSTakashi Iwai } 3286f2e5731dSTakashi Iwai 3287f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3288f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3289f2e5731dSTakashi Iwai * not found 3290f2e5731dSTakashi Iwai */ 3291f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3292f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3293f2e5731dSTakashi Iwai { 3294f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3295f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3296f2e5731dSTakashi Iwai 3297f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3298f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3299f2e5731dSTakashi Iwai ret = dacs[i]; 3300f2e5731dSTakashi Iwai break; 3301f2e5731dSTakashi Iwai } 3302f2e5731dSTakashi Iwai } 3303f2e5731dSTakashi Iwai if (!ret) 3304f2e5731dSTakashi Iwai return 0; 3305f2e5731dSTakashi Iwai if (--nums > 0) 3306f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3307f2e5731dSTakashi Iwai *num_dacs = nums; 3308f2e5731dSTakashi Iwai return ret; 3309f2e5731dSTakashi Iwai } 3310f2e5731dSTakashi Iwai 3311f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3312f2e5731dSTakashi Iwai 3313f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3314f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3315f2e5731dSTakashi Iwai { 3316f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3317f2e5731dSTakashi Iwai int nums = 0; 3318f2e5731dSTakashi Iwai 3319f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3320f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3321f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3322f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3323f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3324f2e5731dSTakashi Iwai dacs[nums++] = nid; 3325f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3326f2e5731dSTakashi Iwai break; 3327f2e5731dSTakashi Iwai } 3328f2e5731dSTakashi Iwai } 3329f2e5731dSTakashi Iwai return nums; 3330f2e5731dSTakashi Iwai } 3331f2e5731dSTakashi Iwai 3332f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3333f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3334f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3335f2e5731dSTakashi Iwai struct pin_dac_pair *filled, int type) 3336f2e5731dSTakashi Iwai { 3337f2e5731dSTakashi Iwai int i, nums; 3338f2e5731dSTakashi Iwai 3339f2e5731dSTakashi Iwai nums = 0; 3340f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3341f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3342f2e5731dSTakashi Iwai filled[nums].type = type; 3343f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3344f2e5731dSTakashi Iwai nums++; 3345f2e5731dSTakashi Iwai } 3346f2e5731dSTakashi Iwai return nums; 3347f2e5731dSTakashi Iwai } 3348f2e5731dSTakashi Iwai 3349f2e5731dSTakashi Iwai /* parse analog output paths */ 3350f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3351f2e5731dSTakashi Iwai { 3352f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3353f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3354f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3355f2e5731dSTakashi Iwai int i, j, nums, rest; 3356f2e5731dSTakashi Iwai 3357f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3358f2e5731dSTakashi Iwai /* parse all analog output pins */ 3359f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3360f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info, 3361f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3362f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3363f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3364f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3365f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3366f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3367f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3368f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3369f2e5731dSTakashi Iwai /* fill multiout struct */ 3370f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3371f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 3372f2e5731dSTakashi Iwai if (!dac) 3373f2e5731dSTakashi Iwai continue; 3374f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3375f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3376f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3377f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3378f2e5731dSTakashi Iwai break; 3379f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3380f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3381f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3382f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3383f2e5731dSTakashi Iwai break; 3384f2e5731dSTakashi Iwai } 3385f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3386f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3387f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3388f2e5731dSTakashi Iwai break; 3389f2e5731dSTakashi Iwai } 3390f2e5731dSTakashi Iwai break; 3391f2e5731dSTakashi Iwai } 3392f2e5731dSTakashi Iwai } 3393f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 3394f2e5731dSTakashi Iwai spec->multiout.max_channels = nums * 2; 3395f2e5731dSTakashi Iwai 3396f2e5731dSTakashi Iwai if (cfg->hp_outs > 0) 3397f2e5731dSTakashi Iwai spec->auto_mute = 1; 3398f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3399f2e5731dSTakashi Iwai } 3400f2e5731dSTakashi Iwai 3401f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 3402f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3403f2e5731dSTakashi Iwai { 3404f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3405f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3406f2e5731dSTakashi Iwai int i, present; 3407f2e5731dSTakashi Iwai 3408f2e5731dSTakashi Iwai if (!spec->auto_mute) 3409f2e5731dSTakashi Iwai return; 3410f2e5731dSTakashi Iwai present = 0; 3411f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3412f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) { 3413f2e5731dSTakashi Iwai present = 1; 3414f2e5731dSTakashi Iwai break; 3415f2e5731dSTakashi Iwai } 3416f2e5731dSTakashi Iwai } 3417f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 3418f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3419f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3420f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3421f2e5731dSTakashi Iwai } 3422f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) { 3423f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3424f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 3425f2e5731dSTakashi Iwai present ? 0 : PIN_OUT); 3426f2e5731dSTakashi Iwai } 3427f2e5731dSTakashi Iwai } 3428f2e5731dSTakashi Iwai 3429f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3430f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3431f2e5731dSTakashi Iwai { 3432f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3433f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3434f2e5731dSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 3435f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3436f2e5731dSTakashi Iwai 3437f2e5731dSTakashi Iwai if (!spec->auto_mic) 3438f2e5731dSTakashi Iwai return; 3439f2e5731dSTakashi Iwai if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) { 3440f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[0], 0, 3441f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3442f2e5731dSTakashi Iwai imux->items[ext_idx].index); 3443f2e5731dSTakashi Iwai } else { 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 } 3448f2e5731dSTakashi Iwai } 3449f2e5731dSTakashi Iwai 3450f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3451f2e5731dSTakashi Iwai { 3452f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3453f2e5731dSTakashi Iwai switch (res >> 26) { 3454f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3455f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3456f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3457f2e5731dSTakashi Iwai break; 3458f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3459f2e5731dSTakashi Iwai cx_auto_automic(codec); 3460f2e5731dSTakashi Iwai conexant_report_jack(codec, nid); 3461f2e5731dSTakashi Iwai break; 3462f2e5731dSTakashi Iwai } 3463f2e5731dSTakashi Iwai } 3464f2e5731dSTakashi Iwai 3465f2e5731dSTakashi Iwai static int is_int_mic_conn(unsigned int def_conf) 3466f2e5731dSTakashi Iwai { 3467f2e5731dSTakashi Iwai unsigned int loc = get_defcfg_location(def_conf); 3468f2e5731dSTakashi Iwai return get_defcfg_connect(def_conf) == AC_JACK_PORT_FIXED || 3469f2e5731dSTakashi Iwai (loc & 0x30) == AC_JACK_LOC_INTERNAL; 3470f2e5731dSTakashi Iwai } 3471f2e5731dSTakashi Iwai 3472f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */ 3473f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) 3474f2e5731dSTakashi Iwai { 3475f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3476f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3477f2e5731dSTakashi Iwai is_int_mic_conn(def_conf); 3478f2e5731dSTakashi Iwai } 3479f2e5731dSTakashi Iwai 3480f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */ 3481f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin) 3482f2e5731dSTakashi Iwai { 3483f2e5731dSTakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3484f2e5731dSTakashi Iwai return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3485f2e5731dSTakashi Iwai !is_int_mic_conn(def_conf); 3486f2e5731dSTakashi Iwai } 3487f2e5731dSTakashi Iwai 3488f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 3489f2e5731dSTakashi Iwai * auto-mic is enabled only when one int-mic and one-ext mic exist 3490f2e5731dSTakashi Iwai */ 3491f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3492f2e5731dSTakashi Iwai { 3493f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3494f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3495f2e5731dSTakashi Iwai 3496f2e5731dSTakashi Iwai if (is_ext_mic(codec, cfg->inputs[0].pin) && 3497f2e5731dSTakashi Iwai is_int_mic(codec, cfg->inputs[1].pin)) { 3498f2e5731dSTakashi Iwai spec->auto_mic = 1; 3499f2e5731dSTakashi Iwai spec->auto_mic_ext = 1; 3500f2e5731dSTakashi Iwai return; 3501f2e5731dSTakashi Iwai } 3502f2e5731dSTakashi Iwai if (is_int_mic(codec, cfg->inputs[1].pin) && 3503f2e5731dSTakashi Iwai is_ext_mic(codec, cfg->inputs[0].pin)) { 3504f2e5731dSTakashi Iwai spec->auto_mic = 1; 3505f2e5731dSTakashi Iwai spec->auto_mic_ext = 0; 3506f2e5731dSTakashi Iwai return; 3507f2e5731dSTakashi Iwai } 3508f2e5731dSTakashi Iwai } 3509f2e5731dSTakashi Iwai 3510f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3511f2e5731dSTakashi Iwai { 3512f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3513f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3514f2e5731dSTakashi Iwai struct hda_input_mux *imux; 3515f2e5731dSTakashi Iwai int i; 3516f2e5731dSTakashi Iwai 3517f2e5731dSTakashi Iwai imux = &spec->private_imux; 3518f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3519f2e5731dSTakashi Iwai int idx = get_connection_index(codec, spec->adc_nids[0], 3520f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3521f2e5731dSTakashi Iwai if (idx >= 0) { 3522f2e5731dSTakashi Iwai const char *label; 3523f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3524f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 3525f2e5731dSTakashi Iwai } 3526f2e5731dSTakashi Iwai } 3527f2e5731dSTakashi Iwai if (imux->num_items == 2 && cfg->num_inputs == 2) 3528f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 3529f2e5731dSTakashi Iwai if (imux->num_items > 1 && !spec->auto_mic) 3530f2e5731dSTakashi Iwai spec->input_mux = imux; 3531f2e5731dSTakashi Iwai } 3532f2e5731dSTakashi Iwai 3533f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3534f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3535f2e5731dSTakashi Iwai { 3536f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3537f2e5731dSTakashi Iwai 3538f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3539f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3540f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3541f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3542f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3543f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3544f2e5731dSTakashi Iwai return nid; 3545f2e5731dSTakashi Iwai } 3546f2e5731dSTakashi Iwai } 3547f2e5731dSTakashi Iwai return 0; 3548f2e5731dSTakashi Iwai } 3549f2e5731dSTakashi Iwai 3550f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3551f2e5731dSTakashi Iwai { 3552f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3553f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3554f2e5731dSTakashi Iwai hda_nid_t nid; 3555f2e5731dSTakashi Iwai 3556f2e5731dSTakashi Iwai if (cfg->dig_outs && 3557f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3558f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3559f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3560f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3561f2e5731dSTakashi Iwai } 3562f2e5731dSTakashi Iwai 3563f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3564f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3565f2e5731dSTakashi Iwai { 3566f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3567f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3568f2e5731dSTakashi Iwai 3569f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3570f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3571f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3572f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3573f2e5731dSTakashi Iwai break; 3574f2e5731dSTakashi Iwai } 3575f2e5731dSTakashi Iwai } 3576f2e5731dSTakashi Iwai #else 3577f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3578f2e5731dSTakashi Iwai #endif 3579f2e5731dSTakashi Iwai 3580f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3581f2e5731dSTakashi Iwai { 3582f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3583f2e5731dSTakashi Iwai int err; 3584f2e5731dSTakashi Iwai 3585f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3586f2e5731dSTakashi Iwai if (err < 0) 3587f2e5731dSTakashi Iwai return err; 3588f2e5731dSTakashi Iwai 3589f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3590f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3591f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3592f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 3593f2e5731dSTakashi Iwai return 0; 3594f2e5731dSTakashi Iwai } 3595f2e5731dSTakashi Iwai 3596f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins, 3597f2e5731dSTakashi Iwai hda_nid_t *pins) 3598f2e5731dSTakashi Iwai { 3599f2e5731dSTakashi Iwai int i; 3600f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3601f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3602f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3603f2e5731dSTakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 0x02); 3604f2e5731dSTakashi Iwai } 3605f2e5731dSTakashi Iwai } 3606f2e5731dSTakashi Iwai 3607f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3608f2e5731dSTakashi Iwai hda_nid_t src) 3609f2e5731dSTakashi Iwai { 3610f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3611f2e5731dSTakashi Iwai if (idx >= 0) 3612f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3613f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3614f2e5731dSTakashi Iwai } 3615f2e5731dSTakashi Iwai 3616f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 3617f2e5731dSTakashi Iwai { 3618f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3619f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3620f2e5731dSTakashi Iwai hda_nid_t nid; 3621f2e5731dSTakashi Iwai int i; 3622f2e5731dSTakashi Iwai 3623f2e5731dSTakashi Iwai for (i = 0; i < spec->multiout.num_dacs; i++) 3624f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0, 3625f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); 3626f2e5731dSTakashi Iwai 3627f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3628f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3629f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 3630f2e5731dSTakashi Iwai if (spec->auto_mute) { 3631f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3632f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3633f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3634f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_HP_EVENT); 3635f2e5731dSTakashi Iwai } 3636f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 3637f2e5731dSTakashi Iwai } else { 3638f2e5731dSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) 3639f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 3640f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3641f2e5731dSTakashi Iwai for (i = 0; i < cfg->speaker_outs; i++) 3642f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->speaker_pins[i], 0, 3643f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3644f2e5731dSTakashi Iwai } 3645f2e5731dSTakashi Iwai 3646f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3647f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3648f2e5731dSTakashi Iwai if (!nid) 3649f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 3650f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3651f2e5731dSTakashi Iwai } 3652f2e5731dSTakashi Iwai 3653f2e5731dSTakashi Iwai /* turn on EAPD */ 3654f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins); 3655f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins); 3656f2e5731dSTakashi Iwai cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins); 3657f2e5731dSTakashi Iwai } 3658f2e5731dSTakashi Iwai 3659f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3660f2e5731dSTakashi Iwai { 3661f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3662f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3663f2e5731dSTakashi Iwai int i; 3664f2e5731dSTakashi Iwai 3665f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) 3666f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3667f2e5731dSTakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)); 3668f2e5731dSTakashi Iwai 3669f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3670f2e5731dSTakashi Iwai unsigned int type; 3671f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 3672f2e5731dSTakashi Iwai type = PIN_VREF80; 3673f2e5731dSTakashi Iwai else 3674f2e5731dSTakashi Iwai type = PIN_IN; 3675f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 3676f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 3677f2e5731dSTakashi Iwai } 3678f2e5731dSTakashi Iwai 3679f2e5731dSTakashi Iwai if (spec->auto_mic) { 3680f2e5731dSTakashi Iwai int ext_idx = spec->auto_mic_ext; 3681f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0, 3682f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 3683f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 3684f2e5731dSTakashi Iwai cx_auto_automic(codec); 3685f2e5731dSTakashi Iwai } else { 3686f2e5731dSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 3687f2e5731dSTakashi Iwai snd_hda_codec_write(codec, spec->adc_nids[i], 0, 3688f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, 3689f2e5731dSTakashi Iwai spec->private_imux.items[0].index); 3690f2e5731dSTakashi Iwai } 3691f2e5731dSTakashi Iwai } 3692f2e5731dSTakashi Iwai } 3693f2e5731dSTakashi Iwai 3694f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 3695f2e5731dSTakashi Iwai { 3696f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3697f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3698f2e5731dSTakashi Iwai 3699f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 3700f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 3701f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 3702f2e5731dSTakashi Iwai if (spec->dig_in_nid) 3703f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 3704f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 3705f2e5731dSTakashi Iwai } 3706f2e5731dSTakashi Iwai 3707f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 3708f2e5731dSTakashi Iwai { 3709f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 3710f2e5731dSTakashi Iwai cx_auto_init_output(codec); 3711f2e5731dSTakashi Iwai cx_auto_init_input(codec); 3712f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 3713f2e5731dSTakashi Iwai return 0; 3714f2e5731dSTakashi Iwai } 3715f2e5731dSTakashi Iwai 3716f2e5731dSTakashi Iwai static int cx_auto_add_volume(struct hda_codec *codec, const char *basename, 3717f2e5731dSTakashi Iwai const char *dir, int cidx, 3718f2e5731dSTakashi Iwai hda_nid_t nid, int hda_dir) 3719f2e5731dSTakashi Iwai { 3720f2e5731dSTakashi Iwai static char name[32]; 3721f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 3722f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 3723f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 3724f2e5731dSTakashi Iwai }; 3725f2e5731dSTakashi Iwai static char *sfx[2] = { "Volume", "Switch" }; 3726f2e5731dSTakashi Iwai int i, err; 3727f2e5731dSTakashi Iwai 3728f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 3729f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 3730f2e5731dSTakashi Iwai knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, hda_dir); 3731f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 3732f2e5731dSTakashi Iwai knew[i].index = cidx; 3733f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 3734f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 3735f2e5731dSTakashi Iwai if (!kctl) 3736f2e5731dSTakashi Iwai return -ENOMEM; 3737f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 3738f2e5731dSTakashi Iwai if (err < 0) 3739f2e5731dSTakashi Iwai return err; 3740f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 3741f2e5731dSTakashi Iwai break; 3742f2e5731dSTakashi Iwai } 3743f2e5731dSTakashi Iwai return 0; 3744f2e5731dSTakashi Iwai } 3745f2e5731dSTakashi Iwai 3746f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 3747f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 3748f2e5731dSTakashi Iwai 3749f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 3750f2e5731dSTakashi Iwai { 3751f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3752f2e5731dSTakashi Iwai int i, err; 3753f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 3754f2e5731dSTakashi Iwai static const char *texts[3] = { "Front", "Surround", "CLFE" }; 3755f2e5731dSTakashi Iwai 3756f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 3757f2e5731dSTakashi Iwai return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac, 3758f2e5731dSTakashi Iwai "Master", 0); 3759f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3760f2e5731dSTakashi Iwai const char *label; 3761f2e5731dSTakashi Iwai int idx, type; 3762f2e5731dSTakashi Iwai if (!spec->dac_info[i].dac) 3763f2e5731dSTakashi Iwai continue; 3764f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 3765f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 3766f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 3767f2e5731dSTakashi Iwai switch (type) { 3768f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3769f2e5731dSTakashi Iwai default: 3770f2e5731dSTakashi Iwai label = texts[num_line++]; 3771f2e5731dSTakashi Iwai idx = 0; 3772f2e5731dSTakashi Iwai break; 3773f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3774f2e5731dSTakashi Iwai label = "Headphone"; 3775f2e5731dSTakashi Iwai idx = num_hp++; 3776f2e5731dSTakashi Iwai break; 3777f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3778f2e5731dSTakashi Iwai label = "Speaker"; 3779f2e5731dSTakashi Iwai idx = num_spk++; 3780f2e5731dSTakashi Iwai break; 3781f2e5731dSTakashi Iwai } 3782f2e5731dSTakashi Iwai err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac, 3783f2e5731dSTakashi Iwai label, idx); 3784f2e5731dSTakashi Iwai if (err < 0) 3785f2e5731dSTakashi Iwai return err; 3786f2e5731dSTakashi Iwai } 3787f2e5731dSTakashi Iwai return 0; 3788f2e5731dSTakashi Iwai } 3789f2e5731dSTakashi Iwai 3790f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 3791f2e5731dSTakashi Iwai { 3792f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3793f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3794f2e5731dSTakashi Iwai static const char *prev_label; 3795f2e5731dSTakashi Iwai int i, err, cidx; 3796f2e5731dSTakashi Iwai 3797f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, "Capture", "", 0, spec->adc_nids[0], 3798f2e5731dSTakashi Iwai HDA_INPUT); 3799f2e5731dSTakashi Iwai if (err < 0) 3800f2e5731dSTakashi Iwai return err; 3801f2e5731dSTakashi Iwai prev_label = NULL; 3802f2e5731dSTakashi Iwai cidx = 0; 3803f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3804f2e5731dSTakashi Iwai hda_nid_t nid = cfg->inputs[i].pin; 3805f2e5731dSTakashi Iwai const char *label; 3806f2e5731dSTakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 3807f2e5731dSTakashi Iwai continue; 3808f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 3809f2e5731dSTakashi Iwai if (label == prev_label) 3810f2e5731dSTakashi Iwai cidx++; 3811f2e5731dSTakashi Iwai else 3812f2e5731dSTakashi Iwai cidx = 0; 3813f2e5731dSTakashi Iwai prev_label = label; 3814f2e5731dSTakashi Iwai err = cx_auto_add_volume(codec, label, " Capture", cidx, 3815f2e5731dSTakashi Iwai nid, HDA_INPUT); 3816f2e5731dSTakashi Iwai if (err < 0) 3817f2e5731dSTakashi Iwai return err; 3818f2e5731dSTakashi Iwai } 3819f2e5731dSTakashi Iwai return 0; 3820f2e5731dSTakashi Iwai } 3821f2e5731dSTakashi Iwai 3822f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 3823f2e5731dSTakashi Iwai { 3824f2e5731dSTakashi Iwai int err; 3825f2e5731dSTakashi Iwai 3826f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 3827f2e5731dSTakashi Iwai if (err < 0) 3828f2e5731dSTakashi Iwai return err; 3829f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 3830f2e5731dSTakashi Iwai if (err < 0) 3831f2e5731dSTakashi Iwai return err; 3832f2e5731dSTakashi Iwai return conexant_build_controls(codec); 3833f2e5731dSTakashi Iwai } 3834f2e5731dSTakashi Iwai 3835f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = { 3836f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 3837f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 3838f2e5731dSTakashi Iwai .init = cx_auto_init, 3839f2e5731dSTakashi Iwai .free = conexant_free, 3840f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 3841f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 3842f2e5731dSTakashi Iwai .suspend = conexant_suspend, 3843f2e5731dSTakashi Iwai #endif 3844f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 3845f2e5731dSTakashi Iwai }; 3846f2e5731dSTakashi Iwai 3847f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 3848f2e5731dSTakashi Iwai { 3849f2e5731dSTakashi Iwai struct conexant_spec *spec; 3850f2e5731dSTakashi Iwai int err; 3851f2e5731dSTakashi Iwai 3852f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3853f2e5731dSTakashi Iwai if (!spec) 3854f2e5731dSTakashi Iwai return -ENOMEM; 3855f2e5731dSTakashi Iwai codec->spec = spec; 3856f2e5731dSTakashi Iwai spec->adc_nids = cx_auto_adc_nids; 3857f2e5731dSTakashi Iwai spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids); 3858f2e5731dSTakashi Iwai spec->capsrc_nids = spec->adc_nids; 3859f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 3860f2e5731dSTakashi Iwai if (err < 0) { 3861f2e5731dSTakashi Iwai kfree(codec->spec); 3862f2e5731dSTakashi Iwai codec->spec = NULL; 3863f2e5731dSTakashi Iwai return err; 3864f2e5731dSTakashi Iwai } 3865f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 3866f2e5731dSTakashi Iwai if (spec->beep_amp) 3867f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 3868f2e5731dSTakashi Iwai return 0; 3869f2e5731dSTakashi Iwai } 3870f2e5731dSTakashi Iwai 3871f2e5731dSTakashi Iwai /* 3872461e2c78STakashi Iwai */ 3873461e2c78STakashi Iwai 38741289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 387582f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 387682f30040STobin Davis .patch = patch_cxt5045 }, 387782f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 387882f30040STobin Davis .patch = patch_cxt5047 }, 3879461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 3880461e2c78STakashi Iwai .patch = patch_cxt5051 }, 38810fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 38820fb67e98SDaniel Drake .patch = patch_cxt5066 }, 388395a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 388495a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 3885850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 3886850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 38877b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 38887b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 3889f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 3890f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3891f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 3892f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3893f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 3894f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3895f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 3896f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3897f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 3898f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3899f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 3900f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3901f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 3902f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3903f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 3904f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 3905c9b443d4STobin Davis {} /* terminator */ 3906c9b443d4STobin Davis }; 39071289e9e8STakashi Iwai 39081289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 39091289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 39101289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 39110fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 391295a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 3913850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 39147b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 3915f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 3916f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 3917f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 3918f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 3919f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 3920f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 3921f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 3922f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 39231289e9e8STakashi Iwai 39241289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 39251289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 39261289e9e8STakashi Iwai 39271289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 39281289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 39291289e9e8STakashi Iwai .owner = THIS_MODULE, 39301289e9e8STakashi Iwai }; 39311289e9e8STakashi Iwai 39321289e9e8STakashi Iwai static int __init patch_conexant_init(void) 39331289e9e8STakashi Iwai { 39341289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 39351289e9e8STakashi Iwai } 39361289e9e8STakashi Iwai 39371289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 39381289e9e8STakashi Iwai { 39391289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 39401289e9e8STakashi Iwai } 39411289e9e8STakashi Iwai 39421289e9e8STakashi Iwai module_init(patch_conexant_init) 39431289e9e8STakashi Iwai module_exit(patch_conexant_exit) 3944