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> 27da155d5bSPaul Gortmaker #include <linux/module.h> 28c9b443d4STobin Davis #include <sound/core.h> 29bc7a166dSUlrich Dangel #include <sound/jack.h> 30bc7a166dSUlrich Dangel 31c9b443d4STobin Davis #include "hda_codec.h" 32c9b443d4STobin Davis #include "hda_local.h" 33c0f8faf0SEinar Rünkaru #include "hda_beep.h" 341835a0f9STakashi Iwai #include "hda_jack.h" 35c9b443d4STobin Davis 36c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 37c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 39c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 40c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 41c9b443d4STobin Davis 42c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 43c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 4403697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT 0x39 45c9b443d4STobin Davis 46bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 47c9b443d4STobin Davis 48ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT 0x12 49bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 50bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 51bc7a166dSUlrich Dangel 52faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB (1 << 1) 53faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC (1 << 2) 54bc7a166dSUlrich Dangel 55f2e5731dSTakashi Iwai struct pin_dac_pair { 56f2e5731dSTakashi Iwai hda_nid_t pin; 57f2e5731dSTakashi Iwai hda_nid_t dac; 58f2e5731dSTakashi Iwai int type; 59f2e5731dSTakashi Iwai }; 60f2e5731dSTakashi Iwai 6147ad1f4eSTakashi Iwai struct imux_info { 6247ad1f4eSTakashi Iwai hda_nid_t pin; /* input pin NID */ 6347ad1f4eSTakashi Iwai hda_nid_t adc; /* connected ADC NID */ 6447ad1f4eSTakashi Iwai hda_nid_t boost; /* optional boost volume NID */ 6547ad1f4eSTakashi Iwai int index; /* corresponding to autocfg.input */ 6647ad1f4eSTakashi Iwai }; 6747ad1f4eSTakashi Iwai 68c9b443d4STobin Davis struct conexant_spec { 69c9b443d4STobin Davis 7034cbe3a6STakashi Iwai const struct snd_kcontrol_new *mixers[5]; 71c9b443d4STobin Davis int num_mixers; 72dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 73d2f344b5STakashi Iwai struct hda_vmaster_mute_hook vmaster_mute; 74f29735cbSTakashi Iwai bool vmaster_mute_led; 75c9b443d4STobin Davis 76c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 77c9b443d4STobin Davis * don't forget NULL 78c9b443d4STobin Davis * termination! 79c9b443d4STobin Davis */ 80c9b443d4STobin Davis unsigned int num_init_verbs; 81c9b443d4STobin Davis 82c9b443d4STobin Davis /* playback */ 83c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 84c9b443d4STobin Davis * max_channels, dacs must be set 85c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 86c9b443d4STobin Davis */ 87c9b443d4STobin Davis unsigned int cur_eapd; 8882f30040STobin Davis unsigned int hp_present; 8903697e2aSTakashi Iwai unsigned int line_present; 90faddaa5dSTakashi Iwai unsigned int auto_mic; 91f6100bb4STakashi Iwai int auto_mic_ext; /* imux_pins[] index for ext mic */ 9243c1b2e9STakashi Iwai int auto_mic_dock; /* imux_pins[] index for dock mic */ 9343c1b2e9STakashi Iwai int auto_mic_int; /* imux_pins[] index for int mic */ 94c9b443d4STobin Davis unsigned int need_dac_fix; 95f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 96c9b443d4STobin Davis 97c9b443d4STobin Davis /* capture */ 98c9b443d4STobin Davis unsigned int num_adc_nids; 9934cbe3a6STakashi Iwai const hda_nid_t *adc_nids; 100c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 101c9b443d4STobin Davis 102461e2c78STakashi Iwai unsigned int cur_adc_idx; 103461e2c78STakashi Iwai hda_nid_t cur_adc; 104461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 105461e2c78STakashi Iwai unsigned int cur_adc_format; 106461e2c78STakashi Iwai 1076764bcefSTakashi Iwai const struct hda_pcm_stream *capture_stream; 1086764bcefSTakashi Iwai 109c9b443d4STobin Davis /* capture source */ 110c9b443d4STobin Davis const struct hda_input_mux *input_mux; 11134cbe3a6STakashi Iwai const hda_nid_t *capsrc_nids; 112c9b443d4STobin Davis unsigned int cur_mux[3]; 113c9b443d4STobin Davis 114c9b443d4STobin Davis /* channel model */ 115c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 116c9b443d4STobin Davis int num_channel_mode; 117c9b443d4STobin Davis 118c9b443d4STobin Davis /* PCM information */ 119c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 120c9b443d4STobin Davis 121c9b443d4STobin Davis unsigned int spdif_route; 122c9b443d4STobin Davis 123c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 124c9b443d4STobin Davis struct auto_pin_cfg autocfg; 125c9b443d4STobin Davis struct hda_input_mux private_imux; 12647ad1f4eSTakashi Iwai struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; 12722ce5f74STakashi Iwai hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 12841923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 129f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 130f2e5731dSTakashi Iwai int dac_info_filled; 131c9b443d4STobin Davis 1320fb67e98SDaniel Drake unsigned int port_d_mode; 133f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 13403697e2aSTakashi Iwai unsigned int detect_line:1; /* Line-out detection enabled */ 13503697e2aSTakashi Iwai unsigned int automute_lines:1; /* automute line-out as well */ 13603697e2aSTakashi Iwai unsigned int automute_hp_lo:1; /* both HP and LO available */ 137f2e5731dSTakashi Iwai unsigned int dell_automute:1; 138cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 139cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1407b2bfdbcSJens Taprogge unsigned int thinkpad:1; 141048e78a5SDavid Henningsson unsigned int hp_laptop:1; 142a1d6906eSDavid Henningsson unsigned int asus:1; 143254f2968STakashi Iwai unsigned int pin_eapd_ctrls:1; 1446b452142STakashi Iwai unsigned int single_adc_amp:1; 145*18dcd304SDavid Henningsson unsigned int fixup_stereo_dmic:1; 14675f8991dSDaniel Drake 1476764bcefSTakashi Iwai unsigned int adc_switching:1; 1486764bcefSTakashi Iwai 14975f8991dSDaniel Drake unsigned int ext_mic_present; 15075f8991dSDaniel Drake unsigned int recording; 15175f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 15275f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 153c4cfe66cSDaniel Drake 154c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 155c4cfe66cSDaniel Drake * through the microphone jack. 156c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 157c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 158c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 159c4cfe66cSDaniel Drake * control. */ 160c4cfe66cSDaniel Drake unsigned int dc_enable; 161c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 162c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1633507e2a8STakashi Iwai 1643507e2a8STakashi Iwai unsigned int beep_amp; 16519110595STakashi Iwai 16619110595STakashi Iwai /* extra EAPD pins */ 16719110595STakashi Iwai unsigned int num_eapds; 16819110595STakashi Iwai hda_nid_t eapds[4]; 169c9b443d4STobin Davis }; 170c9b443d4STobin Davis 171c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 172c9b443d4STobin Davis struct hda_codec *codec, 173c9b443d4STobin Davis struct snd_pcm_substream *substream) 174c9b443d4STobin Davis { 175c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1769a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1779a08160bSTakashi Iwai hinfo); 178c9b443d4STobin Davis } 179c9b443d4STobin Davis 180c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 181c9b443d4STobin Davis struct hda_codec *codec, 182c9b443d4STobin Davis unsigned int stream_tag, 183c9b443d4STobin Davis unsigned int format, 184c9b443d4STobin Davis struct snd_pcm_substream *substream) 185c9b443d4STobin Davis { 186c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 187c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 188c9b443d4STobin Davis stream_tag, 189c9b443d4STobin Davis format, substream); 190c9b443d4STobin Davis } 191c9b443d4STobin Davis 192c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 193c9b443d4STobin Davis struct hda_codec *codec, 194c9b443d4STobin Davis struct snd_pcm_substream *substream) 195c9b443d4STobin Davis { 196c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 197c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 198c9b443d4STobin Davis } 199c9b443d4STobin Davis 200c9b443d4STobin Davis /* 201c9b443d4STobin Davis * Digital out 202c9b443d4STobin Davis */ 203c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 204c9b443d4STobin Davis struct hda_codec *codec, 205c9b443d4STobin Davis struct snd_pcm_substream *substream) 206c9b443d4STobin Davis { 207c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 208c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 209c9b443d4STobin Davis } 210c9b443d4STobin Davis 211c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 212c9b443d4STobin Davis struct hda_codec *codec, 213c9b443d4STobin Davis struct snd_pcm_substream *substream) 214c9b443d4STobin Davis { 215c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 216c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 217c9b443d4STobin Davis } 218c9b443d4STobin Davis 2196b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2206b97eb45STakashi Iwai struct hda_codec *codec, 2216b97eb45STakashi Iwai unsigned int stream_tag, 2226b97eb45STakashi Iwai unsigned int format, 2236b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2246b97eb45STakashi Iwai { 2256b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2266b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2276b97eb45STakashi Iwai stream_tag, 2286b97eb45STakashi Iwai format, substream); 2296b97eb45STakashi Iwai } 2306b97eb45STakashi Iwai 231c9b443d4STobin Davis /* 232c9b443d4STobin Davis * Analog capture 233c9b443d4STobin Davis */ 234c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 235c9b443d4STobin Davis struct hda_codec *codec, 236c9b443d4STobin Davis unsigned int stream_tag, 237c9b443d4STobin Davis unsigned int format, 238c9b443d4STobin Davis struct snd_pcm_substream *substream) 239c9b443d4STobin Davis { 240c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 24175f8991dSDaniel Drake if (spec->capture_prepare) 24275f8991dSDaniel Drake spec->capture_prepare(codec); 243c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 244c9b443d4STobin Davis stream_tag, 0, format); 245c9b443d4STobin Davis return 0; 246c9b443d4STobin Davis } 247c9b443d4STobin Davis 248c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 249c9b443d4STobin Davis struct hda_codec *codec, 250c9b443d4STobin Davis struct snd_pcm_substream *substream) 251c9b443d4STobin Davis { 252c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 253888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 25475f8991dSDaniel Drake if (spec->capture_cleanup) 25575f8991dSDaniel Drake spec->capture_cleanup(codec); 256c9b443d4STobin Davis return 0; 257c9b443d4STobin Davis } 258c9b443d4STobin Davis 259c9b443d4STobin Davis 260c9b443d4STobin Davis 26134cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 262c9b443d4STobin Davis .substreams = 1, 263c9b443d4STobin Davis .channels_min = 2, 264c9b443d4STobin Davis .channels_max = 2, 265c9b443d4STobin Davis .nid = 0, /* fill later */ 266c9b443d4STobin Davis .ops = { 267c9b443d4STobin Davis .open = conexant_playback_pcm_open, 268c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 269c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 270c9b443d4STobin Davis }, 271c9b443d4STobin Davis }; 272c9b443d4STobin Davis 27334cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 274c9b443d4STobin Davis .substreams = 1, 275c9b443d4STobin Davis .channels_min = 2, 276c9b443d4STobin Davis .channels_max = 2, 277c9b443d4STobin Davis .nid = 0, /* fill later */ 278c9b443d4STobin Davis .ops = { 279c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 280c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 281c9b443d4STobin Davis }, 282c9b443d4STobin Davis }; 283c9b443d4STobin Davis 284c9b443d4STobin Davis 28534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 286c9b443d4STobin Davis .substreams = 1, 287c9b443d4STobin Davis .channels_min = 2, 288c9b443d4STobin Davis .channels_max = 2, 289c9b443d4STobin Davis .nid = 0, /* fill later */ 290c9b443d4STobin Davis .ops = { 291c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2926b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2936b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 294c9b443d4STobin Davis }, 295c9b443d4STobin Davis }; 296c9b443d4STobin Davis 29734cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 298c9b443d4STobin Davis .substreams = 1, 299c9b443d4STobin Davis .channels_min = 2, 300c9b443d4STobin Davis .channels_max = 2, 301c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 302c9b443d4STobin Davis }; 303c9b443d4STobin Davis 304461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 305461e2c78STakashi Iwai struct hda_codec *codec, 306461e2c78STakashi Iwai unsigned int stream_tag, 307461e2c78STakashi Iwai unsigned int format, 308461e2c78STakashi Iwai struct snd_pcm_substream *substream) 309461e2c78STakashi Iwai { 310461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 311461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 312461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 313461e2c78STakashi Iwai spec->cur_adc_format = format; 314461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 315461e2c78STakashi Iwai return 0; 316461e2c78STakashi Iwai } 317461e2c78STakashi Iwai 318461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 319461e2c78STakashi Iwai struct hda_codec *codec, 320461e2c78STakashi Iwai struct snd_pcm_substream *substream) 321461e2c78STakashi Iwai { 322461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 323888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 324461e2c78STakashi Iwai spec->cur_adc = 0; 325461e2c78STakashi Iwai return 0; 326461e2c78STakashi Iwai } 327461e2c78STakashi Iwai 32834cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 329461e2c78STakashi Iwai .substreams = 1, 330461e2c78STakashi Iwai .channels_min = 2, 331461e2c78STakashi Iwai .channels_max = 2, 332461e2c78STakashi Iwai .nid = 0, /* fill later */ 333461e2c78STakashi Iwai .ops = { 334461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 335461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 336461e2c78STakashi Iwai }, 337461e2c78STakashi Iwai }; 338461e2c78STakashi Iwai 339c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 340c9b443d4STobin Davis { 341c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 342c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 343c9b443d4STobin Davis 344c9b443d4STobin Davis codec->num_pcms = 1; 345c9b443d4STobin Davis codec->pcm_info = info; 346c9b443d4STobin Davis 347c9b443d4STobin Davis info->name = "CONEXANT Analog"; 348c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 349c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 350c9b443d4STobin Davis spec->multiout.max_channels; 351c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 352c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3536764bcefSTakashi Iwai if (spec->capture_stream) 3546764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3556764bcefSTakashi Iwai else { 356461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 357461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 358461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3596764bcefSTakashi Iwai else { 360461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 361461e2c78STakashi Iwai conexant_pcm_analog_capture; 3626764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3636764bcefSTakashi Iwai spec->num_adc_nids; 3646764bcefSTakashi Iwai } 3656764bcefSTakashi Iwai } 366c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 367c9b443d4STobin Davis 368c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 369c9b443d4STobin Davis info++; 370c9b443d4STobin Davis codec->num_pcms++; 371c9b443d4STobin Davis info->name = "Conexant Digital"; 3727ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 373c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 374c9b443d4STobin Davis conexant_pcm_digital_playback; 375c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 376c9b443d4STobin Davis spec->multiout.dig_out_nid; 377c9b443d4STobin Davis if (spec->dig_in_nid) { 378c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 379c9b443d4STobin Davis conexant_pcm_digital_capture; 380c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 381c9b443d4STobin Davis spec->dig_in_nid; 382c9b443d4STobin Davis } 383f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 384f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 385c9b443d4STobin Davis } 386c9b443d4STobin Davis 387c9b443d4STobin Davis return 0; 388c9b443d4STobin Davis } 389c9b443d4STobin Davis 390c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 391c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 392c9b443d4STobin Davis { 393c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 394c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 395c9b443d4STobin Davis 396c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 397c9b443d4STobin Davis } 398c9b443d4STobin Davis 399c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 400c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 401c9b443d4STobin Davis { 402c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 403c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 404c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 405c9b443d4STobin Davis 406c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 407c9b443d4STobin Davis return 0; 408c9b443d4STobin Davis } 409c9b443d4STobin Davis 410c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 411c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 412c9b443d4STobin Davis { 413c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 414c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 415c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 416c9b443d4STobin Davis 417c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 418c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 419c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 420c9b443d4STobin Davis } 421c9b443d4STobin Davis 4224d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 4234d7fbdbcSTakashi Iwai unsigned int power_state) 4244d7fbdbcSTakashi Iwai { 4254d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 4264d7fbdbcSTakashi Iwai msleep(100); 4274d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 4284d7fbdbcSTakashi Iwai power_state); 4294d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 4304d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 4314d7fbdbcSTakashi Iwai msleep(10); 4324d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 4334d7fbdbcSTakashi Iwai } 4344d7fbdbcSTakashi Iwai 435c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 436c9b443d4STobin Davis { 437c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 438c9b443d4STobin Davis int i; 439c9b443d4STobin Davis 440c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 441c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 442c9b443d4STobin Davis return 0; 443c9b443d4STobin Davis } 444c9b443d4STobin Davis 445c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 446c9b443d4STobin Davis { 447c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 448c9b443d4STobin Davis kfree(codec->spec); 449c9b443d4STobin Davis } 450c9b443d4STobin Davis 45134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 452b880c74aSTakashi Iwai { 453b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 454b880c74aSTakashi Iwai .name = "Capture Source", 455b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 456b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 457b880c74aSTakashi Iwai .put = conexant_mux_enum_put 458b880c74aSTakashi Iwai }, 459b880c74aSTakashi Iwai {} 460b880c74aSTakashi Iwai }; 461b880c74aSTakashi Iwai 4623507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4633507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 46434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4653507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4663507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4673507e2a8STakashi Iwai { } /* end */ 4683507e2a8STakashi Iwai }; 4693507e2a8STakashi Iwai #endif 4703507e2a8STakashi Iwai 4719322ca54STakashi Iwai static const char * const slave_pfxs[] = { 4729322ca54STakashi Iwai "Headphone", "Speaker", "Front", "Surround", "CLFE", 473dd5746a8STakashi Iwai NULL 474dd5746a8STakashi Iwai }; 475dd5746a8STakashi Iwai 476c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 477c9b443d4STobin Davis { 478c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 479c9b443d4STobin Davis unsigned int i; 480c9b443d4STobin Davis int err; 481c9b443d4STobin Davis 482c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 483c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 484c9b443d4STobin Davis if (err < 0) 485c9b443d4STobin Davis return err; 486c9b443d4STobin Davis } 487c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 488c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 48974b654c9SStephen Warren spec->multiout.dig_out_nid, 490c9b443d4STobin Davis spec->multiout.dig_out_nid); 491c9b443d4STobin Davis if (err < 0) 492c9b443d4STobin Davis return err; 4939a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 4949a08160bSTakashi Iwai &spec->multiout); 4959a08160bSTakashi Iwai if (err < 0) 4969a08160bSTakashi Iwai return err; 4979a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 498c9b443d4STobin Davis } 499c9b443d4STobin Davis if (spec->dig_in_nid) { 500c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 501c9b443d4STobin Davis if (err < 0) 502c9b443d4STobin Davis return err; 503c9b443d4STobin Davis } 504dd5746a8STakashi Iwai 505dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 506dd5746a8STakashi Iwai if (spec->vmaster_nid && 507dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 508dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 509dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 510dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 511dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 5129322ca54STakashi Iwai vmaster_tlv, slave_pfxs, 5139322ca54STakashi Iwai "Playback Volume"); 514dd5746a8STakashi Iwai if (err < 0) 515dd5746a8STakashi Iwai return err; 516dd5746a8STakashi Iwai } 517dd5746a8STakashi Iwai if (spec->vmaster_nid && 518dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 519527c73baSTakashi Iwai err = __snd_hda_add_vmaster(codec, "Master Playback Switch", 5209322ca54STakashi Iwai NULL, slave_pfxs, 521527c73baSTakashi Iwai "Playback Switch", true, 522d2f344b5STakashi Iwai &spec->vmaster_mute.sw_kctl); 523dd5746a8STakashi Iwai if (err < 0) 524dd5746a8STakashi Iwai return err; 525dd5746a8STakashi Iwai } 526dd5746a8STakashi Iwai 527b880c74aSTakashi Iwai if (spec->input_mux) { 528b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 529b880c74aSTakashi Iwai if (err < 0) 530b880c74aSTakashi Iwai return err; 531b880c74aSTakashi Iwai } 532b880c74aSTakashi Iwai 5333507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5343507e2a8STakashi Iwai /* create beep controls if needed */ 5353507e2a8STakashi Iwai if (spec->beep_amp) { 53634cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5373507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5383507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5393507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5403507e2a8STakashi Iwai if (!kctl) 5413507e2a8STakashi Iwai return -ENOMEM; 5423507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5433507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5443507e2a8STakashi Iwai if (err < 0) 5453507e2a8STakashi Iwai return err; 5463507e2a8STakashi Iwai } 5473507e2a8STakashi Iwai } 5483507e2a8STakashi Iwai #endif 5493507e2a8STakashi Iwai 550c9b443d4STobin Davis return 0; 551c9b443d4STobin Davis } 552c9b443d4STobin Davis 553697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 554697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 555697c373eSTakashi Iwai { 556697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 557697c373eSTakashi Iwai return 0; 558697c373eSTakashi Iwai } 559697c373eSTakashi Iwai #endif 560697c373eSTakashi Iwai 56134cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 562c9b443d4STobin Davis .build_controls = conexant_build_controls, 563c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 564c9b443d4STobin Davis .init = conexant_init, 565c9b443d4STobin Davis .free = conexant_free, 5664d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 567697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 568697c373eSTakashi Iwai .suspend = conexant_suspend, 569697c373eSTakashi Iwai #endif 570697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 571c9b443d4STobin Davis }; 572c9b443d4STobin Davis 5733507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5743507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5753507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5763507e2a8STakashi Iwai #else 5773507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5783507e2a8STakashi Iwai #endif 5793507e2a8STakashi Iwai 5806764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 581c9b443d4STobin Davis /* 582c9b443d4STobin Davis * EAPD control 583c9b443d4STobin Davis * the private value = nid | (invert << 8) 584c9b443d4STobin Davis */ 585c9b443d4STobin Davis 586a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 587c9b443d4STobin Davis 58882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 589c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 590c9b443d4STobin Davis { 591c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 592c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 593c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 594c9b443d4STobin Davis if (invert) 595c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 596c9b443d4STobin Davis else 597c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 598c9b443d4STobin Davis return 0; 59982f30040STobin Davis 600c9b443d4STobin Davis } 601c9b443d4STobin Davis 60282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 603c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 604c9b443d4STobin Davis { 605c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 606c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 607c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 608c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 609c9b443d4STobin Davis unsigned int eapd; 61082f30040STobin Davis 61168ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 612c9b443d4STobin Davis if (invert) 613c9b443d4STobin Davis eapd = !eapd; 61482beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 615c9b443d4STobin Davis return 0; 61682f30040STobin Davis 617c9b443d4STobin Davis spec->cur_eapd = eapd; 61882beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 619c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 620c9b443d4STobin Davis eapd ? 0x02 : 0x00); 621c9b443d4STobin Davis return 1; 622c9b443d4STobin Davis } 623c9b443d4STobin Davis 62486d72bdfSTakashi Iwai /* controls for test mode */ 62586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 62686d72bdfSTakashi Iwai 62782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 62882f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 62982f30040STobin Davis .info = cxt_eapd_info, \ 63082f30040STobin Davis .get = cxt_eapd_get, \ 63182f30040STobin Davis .put = cxt_eapd_put, \ 63282f30040STobin Davis .private_value = nid | (mask<<16) } 63382f30040STobin Davis 63482f30040STobin Davis 63582f30040STobin Davis 636c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 637c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 638c9b443d4STobin Davis { 639c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 640c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 641c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 642c9b443d4STobin Davis spec->num_channel_mode); 643c9b443d4STobin Davis } 644c9b443d4STobin Davis 645c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 646c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 647c9b443d4STobin Davis { 648c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 649c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 650c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 651c9b443d4STobin Davis spec->num_channel_mode, 652c9b443d4STobin Davis spec->multiout.max_channels); 653c9b443d4STobin Davis } 654c9b443d4STobin Davis 655c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 656c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 657c9b443d4STobin Davis { 658c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 659c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 660c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 661c9b443d4STobin Davis spec->num_channel_mode, 662c9b443d4STobin Davis &spec->multiout.max_channels); 663c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 664c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 665c9b443d4STobin Davis return err; 666c9b443d4STobin Davis } 667c9b443d4STobin Davis 668c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 669c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 670c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 671c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 672c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 673c9b443d4STobin Davis .private_value = nid | (dir<<16) } 674c9b443d4STobin Davis 67586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 67686d72bdfSTakashi Iwai 677c9b443d4STobin Davis /* Conexant 5045 specific */ 678c9b443d4STobin Davis 67934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 68034cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 68134cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 682cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 683c9b443d4STobin Davis 68434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6855cd57529STobin Davis { 2, NULL }, 6865cd57529STobin Davis }; 687c9b443d4STobin Davis 68834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 689c9b443d4STobin Davis .num_items = 2, 690c9b443d4STobin Davis .items = { 69182f30040STobin Davis { "IntMic", 0x1 }, 692f4beee94SJiang zhe { "ExtMic", 0x2 }, 693c9b443d4STobin Davis } 694c9b443d4STobin Davis }; 695c9b443d4STobin Davis 69634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 69722e14130SLukasz Marcinowski .num_items = 5, 6985218c892SJiang Zhe .items = { 6995218c892SJiang Zhe { "IntMic", 0x1 }, 7005218c892SJiang Zhe { "ExtMic", 0x2 }, 7015218c892SJiang Zhe { "LineIn", 0x3 }, 70222e14130SLukasz Marcinowski { "CD", 0x4 }, 70322e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7045218c892SJiang Zhe } 7055218c892SJiang Zhe }; 7065218c892SJiang Zhe 70734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7082de3c232SJiang zhe .num_items = 2, 7092de3c232SJiang zhe .items = { 7102de3c232SJiang zhe { "ExtMic", 0x1 }, 7112de3c232SJiang zhe { "IntMic", 0x2 }, 7122de3c232SJiang zhe } 7132de3c232SJiang zhe }; 7142de3c232SJiang zhe 715c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 716c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 717c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 718c9b443d4STobin Davis { 719c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 720c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 72182f30040STobin Davis unsigned int bits; 722c9b443d4STobin Davis 72382f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 724c9b443d4STobin Davis return 0; 725c9b443d4STobin Davis 72682f30040STobin Davis /* toggle internal speakers mute depending of presence of 72782f30040STobin Davis * the headphone jack 72882f30040STobin Davis */ 72947fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 73047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 73147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7327f29673bSTobin Davis 73347fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 73447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 73547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 736c9b443d4STobin Davis return 1; 737c9b443d4STobin Davis } 738c9b443d4STobin Davis 739c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 74034cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 741cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 742cca3b371STakashi Iwai .values = { 743cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 744cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 745cca3b371STakashi Iwai 0 746cca3b371STakashi Iwai }, 747cca3b371STakashi Iwai }; 748c9b443d4STobin Davis 7497f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7507f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7517f29673bSTobin Davis { 75234cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7537f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7547f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7557f29673bSTobin Davis {} 7567f29673bSTobin Davis }; 75734cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7587f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7597f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7607f29673bSTobin Davis {} 7617f29673bSTobin Davis }; 7627f29673bSTobin Davis unsigned int present; 7637f29673bSTobin Davis 764d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7657f29673bSTobin Davis if (present) 7667f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7677f29673bSTobin Davis else 7687f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7697f29673bSTobin Davis } 7707f29673bSTobin Davis 771c9b443d4STobin Davis 772c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 773c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 774c9b443d4STobin Davis { 77582f30040STobin Davis struct conexant_spec *spec = codec->spec; 776dd87da1cSTobin Davis unsigned int bits; 777c9b443d4STobin Davis 778d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 779dd87da1cSTobin Davis 78047fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 78147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 78247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 783c9b443d4STobin Davis } 784c9b443d4STobin Davis 785c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 786c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 787c9b443d4STobin Davis unsigned int res) 788c9b443d4STobin Davis { 789c9b443d4STobin Davis res >>= 26; 790c9b443d4STobin Davis switch (res) { 791c9b443d4STobin Davis case CONEXANT_HP_EVENT: 792c9b443d4STobin Davis cxt5045_hp_automute(codec); 793c9b443d4STobin Davis break; 7947f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7957f29673bSTobin Davis cxt5045_hp_automic(codec); 7967f29673bSTobin Davis break; 7977f29673bSTobin Davis 798c9b443d4STobin Davis } 799c9b443d4STobin Davis } 800c9b443d4STobin Davis 80134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 80228c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 80328c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8048607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8058607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 806c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 807c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 80828c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 80928c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8108607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8118607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 812cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 813c9b443d4STobin Davis { 814c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 815c9b443d4STobin Davis .name = "Master Playback Switch", 81682f30040STobin Davis .info = cxt_eapd_info, 81782f30040STobin Davis .get = cxt_eapd_get, 818c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 81982f30040STobin Davis .private_value = 0x10, 820c9b443d4STobin Davis }, 821c9b443d4STobin Davis 822c9b443d4STobin Davis {} 823c9b443d4STobin Davis }; 824c9b443d4STobin Davis 82534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 82622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 82722e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 82822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 82922e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 83022e14130SLukasz Marcinowski 8315218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8325218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8335218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8345218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8355218c892SJiang Zhe 83622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 83722e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 83822e14130SLukasz Marcinowski 8395218c892SJiang Zhe {} 8405218c892SJiang Zhe }; 8415218c892SJiang Zhe 84234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 84328c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 84428c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8458607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8468607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8472de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8482de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 84928c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 85028c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8518607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8528607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8532de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8542de3c232SJiang zhe { 8552de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8562de3c232SJiang zhe .name = "Master Playback Switch", 8572de3c232SJiang zhe .info = cxt_eapd_info, 8582de3c232SJiang zhe .get = cxt_eapd_get, 8592de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8602de3c232SJiang zhe .private_value = 0x10, 8612de3c232SJiang zhe }, 8622de3c232SJiang zhe 8632de3c232SJiang zhe {} 8642de3c232SJiang zhe }; 8652de3c232SJiang zhe 86634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 867c9b443d4STobin Davis /* Line in, Mic */ 8684090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8697f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 870c9b443d4STobin Davis /* HP, Amp */ 871c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 872c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 87382f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 874c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 875c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 876c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 877c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 878c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 879c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 88028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8817f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 88282f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 883c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 884c9b443d4STobin Davis /* SPDIF route: PCM */ 885cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 886c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 887c9b443d4STobin Davis /* EAPD */ 88882f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 889c9b443d4STobin Davis { } /* end */ 890c9b443d4STobin Davis }; 891c9b443d4STobin Davis 89234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 89328c4edb7SDavid Henningsson /* Internal Mic, Mic */ 8945218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8955218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8965218c892SJiang Zhe /* Line In,HP, Amp */ 8975218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8985218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8995218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9005218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9015218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9025218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9035218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9045218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9055218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 90628c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9075218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9085218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9095218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9105218c892SJiang Zhe /* SPDIF route: PCM */ 911cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9125218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9135218c892SJiang Zhe /* EAPD */ 9145218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9155218c892SJiang Zhe { } /* end */ 9165218c892SJiang Zhe }; 9177f29673bSTobin Davis 91834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9197f29673bSTobin Davis /* pin sensing on HP jack */ 9207f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 921d3091fadSTakashi Iwai { } /* end */ 9227f29673bSTobin Davis }; 9237f29673bSTobin Davis 92434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9257f29673bSTobin Davis /* pin sensing on HP jack */ 9267f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 927d3091fadSTakashi Iwai { } /* end */ 9287f29673bSTobin Davis }; 9297f29673bSTobin Davis 930c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 931c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 932c9b443d4STobin Davis * configuration. 933c9b443d4STobin Davis */ 93434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 935c9b443d4STobin Davis .num_items = 5, 936c9b443d4STobin Davis .items = { 937c9b443d4STobin Davis { "MIXER", 0x0 }, 938c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 939c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 940c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 941c9b443d4STobin Davis { "CD pin", 0x4 }, 942c9b443d4STobin Davis }, 943c9b443d4STobin Davis }; 944c9b443d4STobin Davis 94534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 946c9b443d4STobin Davis 947c9b443d4STobin Davis /* Output controls */ 948c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 949c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9507f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9517f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9527f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9537f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 954c9b443d4STobin Davis 955c9b443d4STobin Davis /* Modes for retasking pin widgets */ 956c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 957c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 958c9b443d4STobin Davis 95982f30040STobin Davis /* EAPD Switch Control */ 96082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 96182f30040STobin Davis 962c9b443d4STobin Davis /* Loopback mixer controls */ 963c9b443d4STobin Davis 9647f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9657f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9667f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9677f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9687f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9697f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9707f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9717f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9727f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9737f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 974c9b443d4STobin Davis { 975c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 976c9b443d4STobin Davis .name = "Input Source", 977c9b443d4STobin Davis .info = conexant_mux_enum_info, 978c9b443d4STobin Davis .get = conexant_mux_enum_get, 979c9b443d4STobin Davis .put = conexant_mux_enum_put, 980c9b443d4STobin Davis }, 981fb3409e7STobin Davis /* Audio input controls */ 982fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 983fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 984fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 985fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 986fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 987fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 988fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 989fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 990fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 991fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 992c9b443d4STobin Davis { } /* end */ 993c9b443d4STobin Davis }; 994c9b443d4STobin Davis 99534cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 9967f29673bSTobin Davis /* Set connections */ 9977f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9987f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9997f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1000c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1001c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10027f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1003c9b443d4STobin Davis 1004c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1005c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1006c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1007c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1008c9b443d4STobin Davis * control. 1009c9b443d4STobin Davis */ 1010cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1011cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1012c9b443d4STobin Davis 1013c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1014c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1015c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1016c9b443d4STobin Davis 1017c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1018c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1019c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1020c9b443d4STobin Davis * input/output buffers as needed. 1021c9b443d4STobin Davis */ 1022c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1023c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1024c9b443d4STobin Davis 1025c9b443d4STobin Davis /* Mute capture amp left and right */ 1026c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1027c9b443d4STobin Davis 1028c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1029c9b443d4STobin Davis * pin) 1030c9b443d4STobin Davis */ 1031c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10327f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1033c9b443d4STobin Davis 1034c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1035c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1036c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1037c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1038c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1039c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1040c9b443d4STobin Davis 1041c9b443d4STobin Davis { } 1042c9b443d4STobin Davis }; 1043c9b443d4STobin Davis #endif 1044c9b443d4STobin Davis 1045c9b443d4STobin Davis 1046c9b443d4STobin Davis /* initialize jack-sensing, too */ 1047c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1048c9b443d4STobin Davis { 1049c9b443d4STobin Davis conexant_init(codec); 1050c9b443d4STobin Davis cxt5045_hp_automute(codec); 1051c9b443d4STobin Davis return 0; 1052c9b443d4STobin Davis } 1053c9b443d4STobin Davis 1054c9b443d4STobin Davis 1055c9b443d4STobin Davis enum { 105615908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 105715908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 105815908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10595218c892SJiang Zhe CXT5045_BENQ, 10602de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1061c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1062c9b443d4STobin Davis CXT5045_TEST, 1063c9b443d4STobin Davis #endif 10641f8458a2STakashi Iwai CXT5045_AUTO, 1065f5fcc13cSTakashi Iwai CXT5045_MODELS 1066c9b443d4STobin Davis }; 1067c9b443d4STobin Davis 1068ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 106915908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 107015908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 107115908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10725218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10732de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1074c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1075f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1076c9b443d4STobin Davis #endif 10771f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1078f5fcc13cSTakashi Iwai }; 1079c9b443d4STobin Davis 108034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10812de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 10826a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10835218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 108415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 108515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10869e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10879e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 108815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 108915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 109015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1091dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1092dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 109315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1094c9b443d4STobin Davis {} 1095c9b443d4STobin Davis }; 1096c9b443d4STobin Davis 1097c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1098c9b443d4STobin Davis { 1099c9b443d4STobin Davis struct conexant_spec *spec; 1100c9b443d4STobin Davis int board_config; 1101c9b443d4STobin Davis 11021f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 11031f8458a2STakashi Iwai cxt5045_models, 11041f8458a2STakashi Iwai cxt5045_cfg_tbl); 11051f8458a2STakashi Iwai if (board_config < 0) 1106c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 11071f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11081f8458a2STakashi Iwai return patch_conexant_auto(codec); 11091f8458a2STakashi Iwai 1110c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1111c9b443d4STobin Davis if (!spec) 1112c9b443d4STobin Davis return -ENOMEM; 1113c9b443d4STobin Davis codec->spec = spec; 11149421f954STakashi Iwai codec->pin_amp_workaround = 1; 1115c9b443d4STobin Davis 1116c9b443d4STobin Davis spec->multiout.max_channels = 2; 1117c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1118c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1119c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1120c9b443d4STobin Davis spec->num_adc_nids = 1; 1121c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1122c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1123c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1124c9b443d4STobin Davis spec->num_mixers = 1; 1125c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1126c9b443d4STobin Davis spec->num_init_verbs = 1; 1127c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1128c9b443d4STobin Davis spec->spdif_route = 0; 11293507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11303507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11315cd57529STobin Davis 11323507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1133c9b443d4STobin Davis 1134c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1135c9b443d4STobin Davis 1136c9b443d4STobin Davis switch (board_config) { 113715908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11387f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1139c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1140c9b443d4STobin Davis spec->num_init_verbs = 2; 11417f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11427f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11437f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11447f29673bSTobin Davis break; 114515908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 114686376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11477f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11487f29673bSTobin Davis spec->num_init_verbs = 2; 11497f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1150c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1151c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1152c9b443d4STobin Davis break; 115315908c36SMarc Boucher default: 115415908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 115515908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 115615908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 115715908c36SMarc Boucher spec->num_init_verbs = 3; 115815908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 115915908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 116015908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 116115908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 116215908c36SMarc Boucher break; 11635218c892SJiang Zhe case CXT5045_BENQ: 11645218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11655218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11665218c892SJiang Zhe spec->num_init_verbs = 1; 11675218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11685218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11695218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11705218c892SJiang Zhe spec->num_mixers = 2; 11715218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11725218c892SJiang Zhe break; 11732de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11742de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11752de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11762de3c232SJiang zhe spec->num_init_verbs = 2; 11772de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11782de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11792de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11802de3c232SJiang zhe break; 1181c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1182c9b443d4STobin Davis case CXT5045_TEST: 1183c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1184c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1185c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 118615908c36SMarc Boucher break; 118715908c36SMarc Boucher 1188c9b443d4STobin Davis #endif 1189c9b443d4STobin Davis } 119048ecb7e8STakashi Iwai 1191031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1192031005f7STakashi Iwai case 0x103c: 11938f0f5ff6SDaniel T Chen case 0x1631: 11940b587fc4SDaniel T Chen case 0x1734: 11950ebf9e36SDaniel T Chen case 0x17aa: 11960ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 11970ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 11980ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 119948ecb7e8STakashi Iwai */ 120048ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 120148ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 120248ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 120348ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 120448ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1205031005f7STakashi Iwai break; 1206031005f7STakashi Iwai } 120748ecb7e8STakashi Iwai 12083507e2a8STakashi Iwai if (spec->beep_amp) 12093507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12103507e2a8STakashi Iwai 1211c9b443d4STobin Davis return 0; 1212c9b443d4STobin Davis } 1213c9b443d4STobin Davis 1214c9b443d4STobin Davis 1215c9b443d4STobin Davis /* Conexant 5047 specific */ 121682f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1217c9b443d4STobin Davis 121834cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 121934cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 122034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1221c9b443d4STobin Davis 122234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12235cd57529STobin Davis { 2, NULL }, 12245cd57529STobin Davis }; 1225c9b443d4STobin Davis 122634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 122782f30040STobin Davis .num_items = 2, 122882f30040STobin Davis .items = { 122982f30040STobin Davis { "ExtMic", 0x2 }, 123082f30040STobin Davis { "Line-In", 0x1 }, 1231c9b443d4STobin Davis } 1232c9b443d4STobin Davis }; 1233c9b443d4STobin Davis 1234c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1235c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1236c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1237c9b443d4STobin Davis { 1238c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1239c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 124082f30040STobin Davis unsigned int bits; 1241c9b443d4STobin Davis 124282f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1243c9b443d4STobin Davis return 0; 1244c9b443d4STobin Davis 124582f30040STobin Davis /* toggle internal speakers mute depending of presence of 124682f30040STobin Davis * the headphone jack 124782f30040STobin Davis */ 124847fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12493b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12503b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12513b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12523b7523fcSTakashi Iwai */ 12535d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 125447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 125547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 125647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 125747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1258c9b443d4STobin Davis return 1; 1259c9b443d4STobin Davis } 1260c9b443d4STobin Davis 1261c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1262c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1263c9b443d4STobin Davis { 126482f30040STobin Davis struct conexant_spec *spec = codec->spec; 1265dd87da1cSTobin Davis unsigned int bits; 1266c9b443d4STobin Davis 1267d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1268dd87da1cSTobin Davis 126947fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12703b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12715d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 127247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1273c9b443d4STobin Davis } 1274c9b443d4STobin Davis 1275c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1276c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1277c9b443d4STobin Davis { 127834cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12799f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12809f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1281c9b443d4STobin Davis {} 1282c9b443d4STobin Davis }; 128334cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12849f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12859f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1286c9b443d4STobin Davis {} 1287c9b443d4STobin Davis }; 1288c9b443d4STobin Davis unsigned int present; 1289c9b443d4STobin Davis 1290d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1291c9b443d4STobin Davis if (present) 1292c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1293c9b443d4STobin Davis else 1294c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1295c9b443d4STobin Davis } 1296c9b443d4STobin Davis 1297c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1298c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1299c9b443d4STobin Davis unsigned int res) 1300c9b443d4STobin Davis { 13019f113e0eSMarc Boucher switch (res >> 26) { 1302c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1303c9b443d4STobin Davis cxt5047_hp_automute(codec); 1304c9b443d4STobin Davis break; 1305c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1306c9b443d4STobin Davis cxt5047_hp_automic(codec); 1307c9b443d4STobin Davis break; 1308c9b443d4STobin Davis } 1309c9b443d4STobin Davis } 1310c9b443d4STobin Davis 131134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1312df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1313df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13145f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1315c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1316c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1317c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1318c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 131982f30040STobin Davis { 132082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 132182f30040STobin Davis .name = "Master Playback Switch", 132282f30040STobin Davis .info = cxt_eapd_info, 132382f30040STobin Davis .get = cxt_eapd_get, 1324c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1325c9b443d4STobin Davis .private_value = 0x13, 1326c9b443d4STobin Davis }, 1327c9b443d4STobin Davis 1328c9b443d4STobin Davis {} 1329c9b443d4STobin Davis }; 1330c9b443d4STobin Davis 133134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13323b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13335d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1334df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1335df481e41STakashi Iwai {} 1336df481e41STakashi Iwai }; 1337df481e41STakashi Iwai 133834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1339c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1340c9b443d4STobin Davis { } /* end */ 1341c9b443d4STobin Davis }; 1342c9b443d4STobin Davis 134334cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1344c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1345c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1346c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1347c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13487f29673bSTobin Davis /* HP, Speaker */ 1349b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13505b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13515b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13527f29673bSTobin Davis /* Record selector: Mic */ 13537f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13547f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13557f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13567f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1357c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1358c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1359c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1360c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1361c9b443d4STobin Davis /* SPDIF route: PCM */ 1362c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 136382f30040STobin Davis /* Enable unsolicited events */ 136482f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 136582f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1366c9b443d4STobin Davis { } /* end */ 1367c9b443d4STobin Davis }; 1368c9b443d4STobin Davis 1369c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 137034cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13713b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1372c9b443d4STobin Davis {} 1373c9b443d4STobin Davis }; 1374c9b443d4STobin Davis 1375c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1376c9b443d4STobin Davis * configuration. 1377c9b443d4STobin Davis */ 1378c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 137934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 138082f30040STobin Davis .num_items = 4, 1381c9b443d4STobin Davis .items = { 138282f30040STobin Davis { "LINE1 pin", 0x0 }, 138382f30040STobin Davis { "MIC1 pin", 0x1 }, 138482f30040STobin Davis { "MIC2 pin", 0x2 }, 138582f30040STobin Davis { "CD pin", 0x3 }, 1386c9b443d4STobin Davis }, 1387c9b443d4STobin Davis }; 1388c9b443d4STobin Davis 138934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1390c9b443d4STobin Davis 1391c9b443d4STobin Davis /* Output only controls */ 139282f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 139382f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 139482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 139582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1396c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1397c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1398c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1399c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 140082f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 140182f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 140282f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 140382f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1404c9b443d4STobin Davis 1405c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1406c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1407c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1408c9b443d4STobin Davis 140982f30040STobin Davis /* EAPD Switch Control */ 141082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 141182f30040STobin Davis 1412c9b443d4STobin Davis /* Loopback mixer controls */ 141382f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 141482f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 141582f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 141682f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 141782f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 141882f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 141982f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 142082f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1421c9b443d4STobin Davis 142282f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 142382f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 142482f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 142582f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 142682f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 142782f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 142882f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 142982f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1430c9b443d4STobin Davis { 1431c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1432c9b443d4STobin Davis .name = "Input Source", 1433c9b443d4STobin Davis .info = conexant_mux_enum_info, 1434c9b443d4STobin Davis .get = conexant_mux_enum_get, 1435c9b443d4STobin Davis .put = conexant_mux_enum_put, 1436c9b443d4STobin Davis }, 1437854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14389f113e0eSMarc Boucher 1439c9b443d4STobin Davis { } /* end */ 1440c9b443d4STobin Davis }; 1441c9b443d4STobin Davis 144234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1443c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1444c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1445c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1446c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1447c9b443d4STobin Davis 1448c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1449c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1450c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1451c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1452c9b443d4STobin Davis * control. 1453c9b443d4STobin Davis */ 1454c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1455c9b443d4STobin Davis 1456c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1457c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1458c9b443d4STobin Davis */ 1459c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1460c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1463c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1464c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1465c9b443d4STobin Davis 1466c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1467c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1468c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1469c9b443d4STobin Davis * input/output buffers as needed. 1470c9b443d4STobin Davis */ 1471c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1472c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1473c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1474c9b443d4STobin Davis 1475c9b443d4STobin Davis /* Mute capture amp left and right */ 1476c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1477c9b443d4STobin Davis 1478c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1479c9b443d4STobin Davis * pin) 1480c9b443d4STobin Davis */ 1481c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1482c9b443d4STobin Davis 1483c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1484c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1485c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1486c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1487c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1488c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1489c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1490c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1491c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1492c9b443d4STobin Davis 1493c9b443d4STobin Davis { } 1494c9b443d4STobin Davis }; 1495c9b443d4STobin Davis #endif 1496c9b443d4STobin Davis 1497c9b443d4STobin Davis 1498c9b443d4STobin Davis /* initialize jack-sensing, too */ 1499c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1500c9b443d4STobin Davis { 1501c9b443d4STobin Davis conexant_init(codec); 1502c9b443d4STobin Davis cxt5047_hp_automute(codec); 1503c9b443d4STobin Davis return 0; 1504c9b443d4STobin Davis } 1505c9b443d4STobin Davis 1506c9b443d4STobin Davis 1507c9b443d4STobin Davis enum { 1508f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1509f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1510f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1511c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1512c9b443d4STobin Davis CXT5047_TEST, 1513c9b443d4STobin Davis #endif 1514fa5dadcbSTakashi Iwai CXT5047_AUTO, 1515f5fcc13cSTakashi Iwai CXT5047_MODELS 1516c9b443d4STobin Davis }; 1517c9b443d4STobin Davis 1518ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1519f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1520f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1521f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1522c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1523f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1524c9b443d4STobin Davis #endif 1525fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1526f5fcc13cSTakashi Iwai }; 1527c9b443d4STobin Davis 152834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1529ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1530dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1531dea0a509STakashi Iwai CXT5047_LAPTOP), 1532f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1533c9b443d4STobin Davis {} 1534c9b443d4STobin Davis }; 1535c9b443d4STobin Davis 1536c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1537c9b443d4STobin Davis { 1538c9b443d4STobin Davis struct conexant_spec *spec; 1539c9b443d4STobin Davis int board_config; 1540c9b443d4STobin Davis 1541fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1542fa5dadcbSTakashi Iwai cxt5047_models, 1543fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1544fa5dadcbSTakashi Iwai if (board_config < 0) 1545c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1546fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1547fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1548fa5dadcbSTakashi Iwai 1549c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1550c9b443d4STobin Davis if (!spec) 1551c9b443d4STobin Davis return -ENOMEM; 1552c9b443d4STobin Davis codec->spec = spec; 15539421f954STakashi Iwai codec->pin_amp_workaround = 1; 1554c9b443d4STobin Davis 1555c9b443d4STobin Davis spec->multiout.max_channels = 2; 1556c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1557c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1558c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1559c9b443d4STobin Davis spec->num_adc_nids = 1; 1560c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1561c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1562c9b443d4STobin Davis spec->num_mixers = 1; 1563df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1564c9b443d4STobin Davis spec->num_init_verbs = 1; 1565c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1566c9b443d4STobin Davis spec->spdif_route = 0; 15675cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15685cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1569c9b443d4STobin Davis 1570c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1571c9b443d4STobin Davis 1572c9b443d4STobin Davis switch (board_config) { 1573c9b443d4STobin Davis case CXT5047_LAPTOP: 1574df481e41STakashi Iwai spec->num_mixers = 2; 1575df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1576df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1577c9b443d4STobin Davis break; 1578c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1579df481e41STakashi Iwai spec->num_mixers = 2; 1580df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1581fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1582c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1583c9b443d4STobin Davis break; 1584c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 158582f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1586df481e41STakashi Iwai spec->num_mixers = 2; 1587df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1588c9b443d4STobin Davis spec->num_init_verbs = 2; 1589c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1590fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1591c9b443d4STobin Davis break; 1592c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1593c9b443d4STobin Davis case CXT5047_TEST: 1594c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1595c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1596c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1597fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1598c9b443d4STobin Davis #endif 1599c9b443d4STobin Davis } 1600dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1601025f206cSDaniel T Chen 1602025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1603025f206cSDaniel T Chen case 0x103c: 1604025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1605025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1606025f206cSDaniel T Chen * with 0 dB offset 0x17) 1607025f206cSDaniel T Chen */ 1608025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1609025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1610025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1611025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1612025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1613025f206cSDaniel T Chen break; 1614025f206cSDaniel T Chen } 1615025f206cSDaniel T Chen 1616c9b443d4STobin Davis return 0; 1617c9b443d4STobin Davis } 1618c9b443d4STobin Davis 1619461e2c78STakashi Iwai /* Conexant 5051 specific */ 162034cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 162134cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1622461e2c78STakashi Iwai 162334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1624461e2c78STakashi Iwai { 2, NULL }, 1625461e2c78STakashi Iwai }; 1626461e2c78STakashi Iwai 1627461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1628461e2c78STakashi Iwai { 1629461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1630461e2c78STakashi Iwai unsigned int pinctl; 163123d2df5bSTakashi Iwai /* headphone pin */ 163223d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 163323d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 163423d2df5bSTakashi Iwai pinctl); 163523d2df5bSTakashi Iwai /* speaker pin */ 1636461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1637461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1638461e2c78STakashi Iwai pinctl); 1639a80581d0SJustin P. Mattock /* on ideapad there is an additional speaker (subwoofer) to mute */ 1640f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1641f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1642f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1643f7154de2SHerton Ronaldo Krzesinski pinctl); 1644461e2c78STakashi Iwai } 1645461e2c78STakashi Iwai 1646461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1647461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1648461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1649461e2c78STakashi Iwai { 1650461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1651461e2c78STakashi Iwai 1652461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1653461e2c78STakashi Iwai return 0; 1654461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1655461e2c78STakashi Iwai return 1; 1656461e2c78STakashi Iwai } 1657461e2c78STakashi Iwai 1658461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1659461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1660461e2c78STakashi Iwai { 166179d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1662461e2c78STakashi Iwai unsigned int present; 1663461e2c78STakashi Iwai 1664faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 166579d7d533STakashi Iwai return; 1666d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1667461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1668461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1669461e2c78STakashi Iwai present ? 0x01 : 0x00); 1670461e2c78STakashi Iwai } 1671461e2c78STakashi Iwai 1672461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1673461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1674461e2c78STakashi Iwai { 1675461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1676461e2c78STakashi Iwai unsigned int present; 1677461e2c78STakashi Iwai hda_nid_t new_adc; 1678461e2c78STakashi Iwai 1679faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 168079d7d533STakashi Iwai return; 1681d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1682461e2c78STakashi Iwai if (present) 1683461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1684461e2c78STakashi Iwai else 1685461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1686461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1687461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1688461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1689f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1690461e2c78STakashi Iwai spec->cur_adc = new_adc; 1691461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1692461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1693461e2c78STakashi Iwai spec->cur_adc_format); 1694461e2c78STakashi Iwai } 1695461e2c78STakashi Iwai } 1696461e2c78STakashi Iwai 1697461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1698461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1699461e2c78STakashi Iwai { 1700461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1701461e2c78STakashi Iwai 1702d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1703461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1704461e2c78STakashi Iwai } 1705461e2c78STakashi Iwai 1706461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1707461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1708461e2c78STakashi Iwai unsigned int res) 1709461e2c78STakashi Iwai { 1710461e2c78STakashi Iwai switch (res >> 26) { 1711461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1712461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1713461e2c78STakashi Iwai break; 1714461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1715461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1716461e2c78STakashi Iwai break; 1717461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1718461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1719461e2c78STakashi Iwai break; 1720461e2c78STakashi Iwai } 1721461e2c78STakashi Iwai } 1722461e2c78STakashi Iwai 172334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1724461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1725461e2c78STakashi Iwai { 1726461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1727461e2c78STakashi Iwai .name = "Master Playback Switch", 1728461e2c78STakashi Iwai .info = cxt_eapd_info, 1729461e2c78STakashi Iwai .get = cxt_eapd_get, 1730461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1731461e2c78STakashi Iwai .private_value = 0x1a, 1732461e2c78STakashi Iwai }, 17332c7a3fb3STakashi Iwai {} 17342c7a3fb3STakashi Iwai }; 1735461e2c78STakashi Iwai 173634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17372c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17382c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17398607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17408607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17412c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17422c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1743461e2c78STakashi Iwai {} 1744461e2c78STakashi Iwai }; 1745461e2c78STakashi Iwai 174634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1747461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1748461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17498607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17508607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1751461e2c78STakashi Iwai {} 1752461e2c78STakashi Iwai }; 1753461e2c78STakashi Iwai 175434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17554e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17564e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 175779d7d533STakashi Iwai {} 175879d7d533STakashi Iwai }; 175979d7d533STakashi Iwai 176034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17615f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17625f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1763cd9d95a5SKen Prox {} 1764cd9d95a5SKen Prox }; 1765cd9d95a5SKen Prox 176634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1767faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1768faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17698607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17708607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1771faddaa5dSTakashi Iwai {} 1772faddaa5dSTakashi Iwai }; 1773faddaa5dSTakashi Iwai 177434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1775461e2c78STakashi Iwai /* Line in, Mic */ 1776461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1777461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1778461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1779461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1780461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1781461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1782461e2c78STakashi Iwai /* SPK */ 1783461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1784461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1785461e2c78STakashi Iwai /* HP, Amp */ 1786461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1787461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1788461e2c78STakashi Iwai /* DAC1 */ 1789461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 179028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1791461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1792461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1793461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1794461e2c78STakashi Iwai /* SPDIF route: PCM */ 17951965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1796461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1797461e2c78STakashi Iwai /* EAPD */ 1798461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1799461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1800461e2c78STakashi Iwai { } /* end */ 1801461e2c78STakashi Iwai }; 1802461e2c78STakashi Iwai 180334cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 180479d7d533STakashi Iwai /* Line in, Mic */ 180579d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 180679d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 180779d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 180879d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 180979d7d533STakashi Iwai /* SPK */ 181079d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 181179d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 181279d7d533STakashi Iwai /* HP, Amp */ 181379d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 181479d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 181579d7d533STakashi Iwai /* DAC1 */ 181679d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 181728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 181879d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 181979d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 182079d7d533STakashi Iwai /* SPDIF route: PCM */ 182179d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 182279d7d533STakashi Iwai /* EAPD */ 182379d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 182479d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 182579d7d533STakashi Iwai { } /* end */ 182679d7d533STakashi Iwai }; 182779d7d533STakashi Iwai 182834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1829cd9d95a5SKen Prox /* Line in, Mic */ 183030ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1831cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1832cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1833cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1834cd9d95a5SKen Prox /* SPK */ 1835cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1836cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1837cd9d95a5SKen Prox /* HP, Amp */ 1838cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1839cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1840cd9d95a5SKen Prox /* DAC1 */ 1841cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 184228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1843cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1844cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1845cd9d95a5SKen Prox /* SPDIF route: PCM */ 1846cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1847cd9d95a5SKen Prox /* EAPD */ 1848cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1849cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1850cd9d95a5SKen Prox { } /* end */ 1851cd9d95a5SKen Prox }; 1852cd9d95a5SKen Prox 18536953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18546953e552STakashi Iwai unsigned int event) 18556953e552STakashi Iwai { 18566953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18576953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18586953e552STakashi Iwai AC_USRSP_EN | event); 18596953e552STakashi Iwai } 18606953e552STakashi Iwai 186134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1862f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1863f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1864f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1865f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1866f7154de2SHerton Ronaldo Krzesinski }; 1867f7154de2SHerton Ronaldo Krzesinski 1868461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1869461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1870461e2c78STakashi Iwai { 18716953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18726953e552STakashi Iwai 1873461e2c78STakashi Iwai conexant_init(codec); 18746953e552STakashi Iwai 18756953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18766953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18776953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18786953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18796953e552STakashi Iwai 1880461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1881461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1882461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1883461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1884461e2c78STakashi Iwai } 1885461e2c78STakashi Iwai return 0; 1886461e2c78STakashi Iwai } 1887461e2c78STakashi Iwai 1888461e2c78STakashi Iwai 1889461e2c78STakashi Iwai enum { 1890461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1891461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 189279d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1893cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1894faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1895f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 18966764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1897461e2c78STakashi Iwai CXT5051_MODELS 1898461e2c78STakashi Iwai }; 1899461e2c78STakashi Iwai 1900ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1901461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1902461e2c78STakashi Iwai [CXT5051_HP] = "hp", 190379d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 19045f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1905faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1906f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19076764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1908461e2c78STakashi Iwai }; 1909461e2c78STakashi Iwai 191034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 191179d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19121812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19135f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1914faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1915461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1916461e2c78STakashi Iwai CXT5051_LAPTOP), 1917461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1918f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1919461e2c78STakashi Iwai {} 1920461e2c78STakashi Iwai }; 1921461e2c78STakashi Iwai 1922461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1923461e2c78STakashi Iwai { 1924461e2c78STakashi Iwai struct conexant_spec *spec; 1925461e2c78STakashi Iwai int board_config; 1926461e2c78STakashi Iwai 19276764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19286764bcefSTakashi Iwai cxt5051_models, 19296764bcefSTakashi Iwai cxt5051_cfg_tbl); 19306764bcefSTakashi Iwai if (board_config < 0) 1931c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19321f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19336764bcefSTakashi Iwai return patch_conexant_auto(codec); 19346764bcefSTakashi Iwai 1935461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1936461e2c78STakashi Iwai if (!spec) 1937461e2c78STakashi Iwai return -ENOMEM; 1938461e2c78STakashi Iwai codec->spec = spec; 19399421f954STakashi Iwai codec->pin_amp_workaround = 1; 1940461e2c78STakashi Iwai 1941461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1942461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1943461e2c78STakashi Iwai 1944461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1945461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1946461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1947461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1948461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1949461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19502c7a3fb3STakashi Iwai spec->num_mixers = 2; 19512c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19522c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1953461e2c78STakashi Iwai spec->num_init_verbs = 1; 1954461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1955461e2c78STakashi Iwai spec->spdif_route = 0; 1956461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1957461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1958461e2c78STakashi Iwai spec->cur_adc = 0; 1959461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1960461e2c78STakashi Iwai 19613507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 19623507e2a8STakashi Iwai 196379d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 196479d7d533STakashi Iwai 1965faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1966461e2c78STakashi Iwai switch (board_config) { 1967461e2c78STakashi Iwai case CXT5051_HP: 1968461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1969461e2c78STakashi Iwai break; 197079d7d533STakashi Iwai case CXT5051_HP_DV6736: 197179d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 197279d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1973faddaa5dSTakashi Iwai spec->auto_mic = 0; 197479d7d533STakashi Iwai break; 1975cd9d95a5SKen Prox case CXT5051_F700: 1976cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1977cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1978faddaa5dSTakashi Iwai spec->auto_mic = 0; 1979faddaa5dSTakashi Iwai break; 1980faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1981faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1982faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1983cd9d95a5SKen Prox break; 1984f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 1985f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 1986f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 1987f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 1988f7154de2SHerton Ronaldo Krzesinski break; 1989461e2c78STakashi Iwai } 1990461e2c78STakashi Iwai 19913507e2a8STakashi Iwai if (spec->beep_amp) 19923507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 19933507e2a8STakashi Iwai 1994461e2c78STakashi Iwai return 0; 1995461e2c78STakashi Iwai } 1996461e2c78STakashi Iwai 19970fb67e98SDaniel Drake /* Conexant 5066 specific */ 19980fb67e98SDaniel Drake 199934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 200034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 200134cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 200234cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 20030fb67e98SDaniel Drake 2004dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2005dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2006dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2007dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2008dbaccc0cSDaniel Drake 200934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20100fb67e98SDaniel Drake { 2, NULL }, 20110fb67e98SDaniel Drake }; 20120fb67e98SDaniel Drake 2013a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2014a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2015a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2016a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2017a3de8ab8STakashi Iwai 20180fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20190fb67e98SDaniel Drake { 20200fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20210fb67e98SDaniel Drake unsigned int pinctl; 20220fb67e98SDaniel Drake 20233a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20243a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20250fb67e98SDaniel Drake 20260fb67e98SDaniel Drake /* Port A (HP) */ 2027a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20280fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20290fb67e98SDaniel Drake pinctl); 20300fb67e98SDaniel Drake 20310fb67e98SDaniel Drake /* Port D (HP/LO) */ 2032a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2033a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2034a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2035a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20363a253445SJohn Baboval pinctl = 0; 20373a253445SJohn Baboval } else { 2038a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2039a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2040a3de8ab8STakashi Iwai pinctl = 0; 20413a253445SJohn Baboval } 20420fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20430fb67e98SDaniel Drake pinctl); 20440fb67e98SDaniel Drake 20450fb67e98SDaniel Drake /* CLASS_D AMP */ 20460fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20470fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20480fb67e98SDaniel Drake pinctl); 20490fb67e98SDaniel Drake } 20500fb67e98SDaniel Drake 20510fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20520fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20530fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20540fb67e98SDaniel Drake { 20550fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20560fb67e98SDaniel Drake 20570fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20580fb67e98SDaniel Drake return 0; 20590fb67e98SDaniel Drake 20600fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20610fb67e98SDaniel Drake return 1; 20620fb67e98SDaniel Drake } 20630fb67e98SDaniel Drake 2064c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2065c4cfe66cSDaniel Drake .num_items = 3, 2066c4cfe66cSDaniel Drake .items = { 2067c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2068c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2069c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2070c4cfe66cSDaniel Drake }, 2071c4cfe66cSDaniel Drake }; 2072c4cfe66cSDaniel Drake 2073c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2074c4cfe66cSDaniel Drake { 2075c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2076c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2077c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2078c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2079c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2080c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2081c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2082c4cfe66cSDaniel Drake } 2083c4cfe66cSDaniel Drake 208475f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 208575f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 208675f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 208775f8991dSDaniel Drake * is happening when it is not. */ 208875f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20890fb67e98SDaniel Drake { 2090dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 209175f8991dSDaniel Drake if (!spec->recording) 209275f8991dSDaniel Drake return; 20930fb67e98SDaniel Drake 2094c4cfe66cSDaniel Drake if (spec->dc_enable) { 2095c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2096c4cfe66cSDaniel Drake * through our special DC port */ 2097c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2098c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2099c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2100c4cfe66cSDaniel Drake 2101c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2102c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2103c4cfe66cSDaniel Drake {}, 2104c4cfe66cSDaniel Drake }; 2105c4cfe66cSDaniel Drake 2106c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2107c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2108c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2109c4cfe66cSDaniel Drake return; 2110c4cfe66cSDaniel Drake } 2111c4cfe66cSDaniel Drake 2112c4cfe66cSDaniel Drake /* disable DC (port F) */ 2113c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2114c4cfe66cSDaniel Drake 211575f8991dSDaniel Drake /* external mic, port B */ 211675f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 211775f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21180fb67e98SDaniel Drake 211975f8991dSDaniel Drake /* internal mic, port C */ 212075f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 212175f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 212275f8991dSDaniel Drake } 21230fb67e98SDaniel Drake 212475f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 212575f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 212675f8991dSDaniel Drake { 212775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21280fb67e98SDaniel Drake unsigned int present; 21290fb67e98SDaniel Drake 2130c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2131c4cfe66cSDaniel Drake return; 2132c4cfe66cSDaniel Drake 213375f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 213475f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 213575f8991dSDaniel Drake if (present) 21360fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 213775f8991dSDaniel Drake else 21380fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 213975f8991dSDaniel Drake 214075f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 214175f8991dSDaniel Drake present ? 0 : 1); 214275f8991dSDaniel Drake spec->ext_mic_present = !!present; 214375f8991dSDaniel Drake 214475f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21450fb67e98SDaniel Drake } 21460fb67e98SDaniel Drake 214795a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 214895a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 214995a618bdSEinar Rünkaru { 215095a618bdSEinar Rünkaru unsigned int present; 215195a618bdSEinar Rünkaru 215295a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 215395a618bdSEinar Rünkaru /* enable external mic, port B */ 215475f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 215595a618bdSEinar Rünkaru 215695a618bdSEinar Rünkaru /* switch to external mic input */ 215795a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 215895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 215995a618bdSEinar Rünkaru 216095a618bdSEinar Rünkaru /* disable internal digital mic */ 216195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 216295a618bdSEinar Rünkaru {} 216395a618bdSEinar Rünkaru }; 216434cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 216595a618bdSEinar Rünkaru /* enable internal mic, port C */ 216695a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 216795a618bdSEinar Rünkaru 216895a618bdSEinar Rünkaru /* switch to internal mic input */ 216995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 217095a618bdSEinar Rünkaru 217195a618bdSEinar Rünkaru /* disable external mic, port B */ 217295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 217395a618bdSEinar Rünkaru {} 217495a618bdSEinar Rünkaru }; 217595a618bdSEinar Rünkaru 217695a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 217795a618bdSEinar Rünkaru if (present) { 217895a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 217995a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 218095a618bdSEinar Rünkaru } else { 218195a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 218295a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 218395a618bdSEinar Rünkaru } 218495a618bdSEinar Rünkaru } 218595a618bdSEinar Rünkaru 2186cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2187cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2188cfd3d8dcSGreg Alexander { 2189cfd3d8dcSGreg Alexander unsigned int present; 2190cfd3d8dcSGreg Alexander 2191cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2192cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2193cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2194cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2195cfd3d8dcSGreg Alexander {} 2196cfd3d8dcSGreg Alexander }; 219734cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2198cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2199cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2200cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2201cfd3d8dcSGreg Alexander {} 2202cfd3d8dcSGreg Alexander }; 2203cfd3d8dcSGreg Alexander 2204cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2205cfd3d8dcSGreg Alexander if (present) { 2206cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2207cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2208cfd3d8dcSGreg Alexander } else { 2209cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2210cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2211cfd3d8dcSGreg Alexander } 2212cfd3d8dcSGreg Alexander } 2213cfd3d8dcSGreg Alexander 2214a1d6906eSDavid Henningsson 2215a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2216a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2217a1d6906eSDavid Henningsson { 2218a1d6906eSDavid Henningsson unsigned int present; 2219a1d6906eSDavid Henningsson 2220a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2221a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2222a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2223a1d6906eSDavid Henningsson present ? 1 : 0); 2224a1d6906eSDavid Henningsson } 2225a1d6906eSDavid Henningsson 2226a1d6906eSDavid Henningsson 2227048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2228048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2229048e78a5SDavid Henningsson { 2230048e78a5SDavid Henningsson unsigned int present; 2231048e78a5SDavid Henningsson 2232048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2233048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2234048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2235048e78a5SDavid Henningsson present ? 1 : 3); 2236048e78a5SDavid Henningsson } 2237048e78a5SDavid Henningsson 2238048e78a5SDavid Henningsson 22397b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22407b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22417b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22427b2bfdbcSJens Taprogge { 22437b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22447b2bfdbcSJens Taprogge 224534cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22467b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22477b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22487b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22497b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22507b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22517b2bfdbcSJens Taprogge {} 22527b2bfdbcSJens Taprogge }; 225334cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 22547b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22557b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 22567b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22577b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22587b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22597b2bfdbcSJens Taprogge {} 22607b2bfdbcSJens Taprogge }; 226134cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 22627b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 22637b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 22647b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22657b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22667b2bfdbcSJens Taprogge {} 22677b2bfdbcSJens Taprogge }; 22687b2bfdbcSJens Taprogge 22697b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 22707b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 22717b2bfdbcSJens Taprogge if (ext_present) { 22727b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 22737b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 22747b2bfdbcSJens Taprogge } else if (dock_present) { 22757b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 22767b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 22777b2bfdbcSJens Taprogge } else { 22787b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 22797b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 22807b2bfdbcSJens Taprogge } 22817b2bfdbcSJens Taprogge } 22827b2bfdbcSJens Taprogge 22830fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22840fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22850fb67e98SDaniel Drake { 22860fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22870fb67e98SDaniel Drake unsigned int portA, portD; 22880fb67e98SDaniel Drake 22890fb67e98SDaniel Drake /* Port A */ 2290d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22910fb67e98SDaniel Drake 22920fb67e98SDaniel Drake /* Port D */ 2293d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 22940fb67e98SDaniel Drake 2295a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2296a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 22970fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 22980fb67e98SDaniel Drake portA, portD, spec->hp_present); 22990fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23000fb67e98SDaniel Drake } 23010fb67e98SDaniel Drake 230202b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 230302b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 230402b6b5b6SDavid Henningsson { 230502b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 230602b6b5b6SDavid Henningsson 230702b6b5b6SDavid Henningsson if (spec->dell_vostro) 230802b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 230902b6b5b6SDavid Henningsson else if (spec->ideapad) 231002b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 231102b6b5b6SDavid Henningsson else if (spec->thinkpad) 231202b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 231302b6b5b6SDavid Henningsson else if (spec->hp_laptop) 231402b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2315a1d6906eSDavid Henningsson else if (spec->asus) 2316a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 231702b6b5b6SDavid Henningsson } 231802b6b5b6SDavid Henningsson 23190fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 232075f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23210fb67e98SDaniel Drake { 2322c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23230fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23240fb67e98SDaniel Drake switch (res >> 26) { 23250fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23260fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23270fb67e98SDaniel Drake break; 23280fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2329c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2330c4cfe66cSDaniel Drake if (!spec->dc_enable) 233175f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23320fb67e98SDaniel Drake break; 23330fb67e98SDaniel Drake } 23340fb67e98SDaniel Drake } 23350fb67e98SDaniel Drake 233695a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 233702b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 233895a618bdSEinar Rünkaru { 233902b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 234095a618bdSEinar Rünkaru switch (res >> 26) { 234195a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 234295a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 234395a618bdSEinar Rünkaru break; 234495a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 234502b6b5b6SDavid Henningsson cxt5066_automic(codec); 234695a618bdSEinar Rünkaru break; 234795a618bdSEinar Rünkaru } 234895a618bdSEinar Rünkaru } 234995a618bdSEinar Rünkaru 23507b2bfdbcSJens Taprogge 23510fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 23520fb67e98SDaniel Drake .num_items = 5, 23530fb67e98SDaniel Drake .items = { 23540fb67e98SDaniel Drake { "0dB", 0 }, 23550fb67e98SDaniel Drake { "10dB", 1 }, 23560fb67e98SDaniel Drake { "20dB", 2 }, 23570fb67e98SDaniel Drake { "30dB", 3 }, 23580fb67e98SDaniel Drake { "40dB", 4 }, 23590fb67e98SDaniel Drake }, 23600fb67e98SDaniel Drake }; 23610fb67e98SDaniel Drake 2362cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2363c4cfe66cSDaniel Drake { 2364c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2365cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2366c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2367c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2368c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 23697b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2370cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2371cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2372cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2373cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2374cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2375cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2376cfd3d8dcSGreg Alexander } 2377c4cfe66cSDaniel Drake } 2378c4cfe66cSDaniel Drake 23790fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 23800fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 23810fb67e98SDaniel Drake { 23820fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 23830fb67e98SDaniel Drake } 23840fb67e98SDaniel Drake 23850fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 23860fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23870fb67e98SDaniel Drake { 23880fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2389c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2390c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23910fb67e98SDaniel Drake return 0; 23920fb67e98SDaniel Drake } 23930fb67e98SDaniel Drake 23940fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 23950fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23960fb67e98SDaniel Drake { 23970fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2398c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23990fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 24000fb67e98SDaniel Drake unsigned int idx; 24010fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 24020fb67e98SDaniel Drake if (idx >= imux->num_items) 24030fb67e98SDaniel Drake idx = imux->num_items - 1; 24040fb67e98SDaniel Drake 2405c4cfe66cSDaniel Drake spec->mic_boost = idx; 2406c4cfe66cSDaniel Drake if (!spec->dc_enable) 2407c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2408c4cfe66cSDaniel Drake return 1; 2409c4cfe66cSDaniel Drake } 24100fb67e98SDaniel Drake 2411c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2412c4cfe66cSDaniel Drake { 2413c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2414c4cfe66cSDaniel Drake /* disable gain */ 2415c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2416c4cfe66cSDaniel Drake 2417c4cfe66cSDaniel Drake /* switch to DC input */ 2418c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2419c4cfe66cSDaniel Drake {} 2420c4cfe66cSDaniel Drake }; 2421c4cfe66cSDaniel Drake 2422c4cfe66cSDaniel Drake /* configure as input source */ 2423c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2424c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2425c4cfe66cSDaniel Drake } 2426c4cfe66cSDaniel Drake 2427c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2428c4cfe66cSDaniel Drake { 2429c4cfe66cSDaniel Drake /* reconfigure input source */ 2430c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2431c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2432c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2433c4cfe66cSDaniel Drake } 2434c4cfe66cSDaniel Drake 2435c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2436c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2437c4cfe66cSDaniel Drake { 2438c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2439c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2440c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2441c4cfe66cSDaniel Drake return 0; 2442c4cfe66cSDaniel Drake } 2443c4cfe66cSDaniel Drake 2444c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2445c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2446c4cfe66cSDaniel Drake { 2447c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2448c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2449c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2450c4cfe66cSDaniel Drake 2451c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2452c4cfe66cSDaniel Drake return 0; 2453c4cfe66cSDaniel Drake 2454c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2455c4cfe66cSDaniel Drake if (dc_enable) 2456c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2457c4cfe66cSDaniel Drake else 2458c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2459c4cfe66cSDaniel Drake 2460c4cfe66cSDaniel Drake return 1; 2461c4cfe66cSDaniel Drake } 2462c4cfe66cSDaniel Drake 2463c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2464c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2465c4cfe66cSDaniel Drake { 2466c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2467c4cfe66cSDaniel Drake } 2468c4cfe66cSDaniel Drake 2469c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2470c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2471c4cfe66cSDaniel Drake { 2472c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2473c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2474c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2475c4cfe66cSDaniel Drake return 0; 2476c4cfe66cSDaniel Drake } 2477c4cfe66cSDaniel Drake 2478c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2479c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2480c4cfe66cSDaniel Drake { 2481c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2482c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2483c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2484c4cfe66cSDaniel Drake unsigned int idx; 2485c4cfe66cSDaniel Drake 2486c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2487c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2488c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2489c4cfe66cSDaniel Drake 2490c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2491c4cfe66cSDaniel Drake if (spec->dc_enable) 2492c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 24930fb67e98SDaniel Drake return 1; 24940fb67e98SDaniel Drake } 24950fb67e98SDaniel Drake 249675f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 249775f8991dSDaniel Drake { 249875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 249975f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 250075f8991dSDaniel Drake * recording LED comes on. */ 250175f8991dSDaniel Drake spec->recording = 1; 250275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 250375f8991dSDaniel Drake } 250475f8991dSDaniel Drake 250575f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 250675f8991dSDaniel Drake { 250775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 250875f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 250975f8991dSDaniel Drake /* disable external mic, port B */ 251075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 251175f8991dSDaniel Drake 251275f8991dSDaniel Drake /* disble internal mic, port C */ 251375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2514c4cfe66cSDaniel Drake 2515c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2516c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 251775f8991dSDaniel Drake {}, 251875f8991dSDaniel Drake }; 251975f8991dSDaniel Drake 252075f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 252175f8991dSDaniel Drake spec->recording = 0; 252275f8991dSDaniel Drake } 252375f8991dSDaniel Drake 2524f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 252534cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2526f6a2491cSAndy Robinson int num_pins) 2527f6a2491cSAndy Robinson { 2528f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2529f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2530f6a2491cSAndy Robinson int i; 2531f6a2491cSAndy Robinson 2532f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2533f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2534f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2535f6a2491cSAndy Robinson continue; 2536f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2537f6a2491cSAndy Robinson continue; 2538f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2539f6a2491cSAndy Robinson nid_loc++; 2540f6a2491cSAndy Robinson else 2541f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2542f6a2491cSAndy Robinson } 2543f6a2491cSAndy Robinson } 2544f6a2491cSAndy Robinson 254534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25460fb67e98SDaniel Drake .num_items = 4, 25470fb67e98SDaniel Drake .items = { 25480fb67e98SDaniel Drake { "Mic B", 0 }, 25490fb67e98SDaniel Drake { "Mic C", 1 }, 25500fb67e98SDaniel Drake { "Mic E", 2 }, 25510fb67e98SDaniel Drake { "Mic F", 3 }, 25520fb67e98SDaniel Drake }, 25530fb67e98SDaniel Drake }; 25540fb67e98SDaniel Drake 255534cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 25560fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 25570fb67e98SDaniel Drake .values = { 25580fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25590fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25600fb67e98SDaniel Drake 0 25610fb67e98SDaniel Drake }, 25620fb67e98SDaniel Drake }; 25630fb67e98SDaniel Drake 256434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 25650fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 25660fb67e98SDaniel Drake .values = { 25670fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25680fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25690fb67e98SDaniel Drake 0 25700fb67e98SDaniel Drake }, 25710fb67e98SDaniel Drake }; 25720fb67e98SDaniel Drake 257334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 25740fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 25750fb67e98SDaniel Drake {} 25760fb67e98SDaniel Drake }; 25770fb67e98SDaniel Drake 257834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 25790fb67e98SDaniel Drake { 25800fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25810fb67e98SDaniel Drake .name = "Master Playback Volume", 25820fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 25830fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 25840fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 25855e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 25860fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 25870fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 25880fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 25890fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 25900fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 25910fb67e98SDaniel Drake .private_value = 25920fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 25930fb67e98SDaniel Drake }, 25940fb67e98SDaniel Drake {} 25950fb67e98SDaniel Drake }; 25960fb67e98SDaniel Drake 259734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2598c4cfe66cSDaniel Drake { 2599c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2600c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2601c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2602c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2603c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2604c4cfe66cSDaniel Drake }, 2605c4cfe66cSDaniel Drake { 2606c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2607c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2608c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2609c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2610c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2611c4cfe66cSDaniel Drake }, 2612c4cfe66cSDaniel Drake {} 2613c4cfe66cSDaniel Drake }; 2614c4cfe66cSDaniel Drake 261534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 26160fb67e98SDaniel Drake { 26170fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26180fb67e98SDaniel Drake .name = "Master Playback Switch", 26190fb67e98SDaniel Drake .info = cxt_eapd_info, 26200fb67e98SDaniel Drake .get = cxt_eapd_get, 26210fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26220fb67e98SDaniel Drake .private_value = 0x1d, 26230fb67e98SDaniel Drake }, 26240fb67e98SDaniel Drake 26250fb67e98SDaniel Drake { 26260fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2627c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26280fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26290fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26300fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26310fb67e98SDaniel Drake }, 26320fb67e98SDaniel Drake 26330fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26340fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26350fb67e98SDaniel Drake {} 26360fb67e98SDaniel Drake }; 26370fb67e98SDaniel Drake 263834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2639254bba6aSEinar Rünkaru { 2640254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 264128c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2642254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2643254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2644254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2645254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2646254bba6aSEinar Rünkaru }, 2647254bba6aSEinar Rünkaru {} 2648254bba6aSEinar Rünkaru }; 2649254bba6aSEinar Rünkaru 265034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 26510fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 26520fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 26530fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 26540fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 26550fb67e98SDaniel Drake 26560fb67e98SDaniel Drake /* Speakers */ 26570fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26580fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26590fb67e98SDaniel Drake 26600fb67e98SDaniel Drake /* HP, Amp */ 26610fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26620fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26630fb67e98SDaniel Drake 26640fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26650fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26660fb67e98SDaniel Drake 26670fb67e98SDaniel Drake /* DAC1 */ 26680fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26690fb67e98SDaniel Drake 26700fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 26710fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26720fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26730fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 26740fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26750fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 26760fb67e98SDaniel Drake 26770fb67e98SDaniel Drake /* no digital microphone support yet */ 26780fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26790fb67e98SDaniel Drake 26800fb67e98SDaniel Drake /* Audio input selector */ 26810fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26820fb67e98SDaniel Drake 26830fb67e98SDaniel Drake /* SPDIF route: PCM */ 26840fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 26850fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 26860fb67e98SDaniel Drake 26870fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26880fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26890fb67e98SDaniel Drake 26900fb67e98SDaniel Drake /* EAPD */ 26910fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26920fb67e98SDaniel Drake 26930fb67e98SDaniel Drake /* not handling these yet */ 26940fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26950fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26960fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26970fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26980fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26990fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27000fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27010fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27020fb67e98SDaniel Drake { } /* end */ 27030fb67e98SDaniel Drake }; 27040fb67e98SDaniel Drake 270534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27060fb67e98SDaniel Drake /* Port A: headphones */ 27070fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27080fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27090fb67e98SDaniel Drake 27100fb67e98SDaniel Drake /* Port B: external microphone */ 271175f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27120fb67e98SDaniel Drake 27130fb67e98SDaniel Drake /* Port C: internal microphone */ 271475f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27150fb67e98SDaniel Drake 27160fb67e98SDaniel Drake /* Port D: unused */ 27170fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27180fb67e98SDaniel Drake 27190fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27200fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27210fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27220fb67e98SDaniel Drake 2723c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27240fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27250fb67e98SDaniel Drake 27260fb67e98SDaniel Drake /* Port G: internal speakers */ 27270fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27280fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27290fb67e98SDaniel Drake 27300fb67e98SDaniel Drake /* DAC1 */ 27310fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27320fb67e98SDaniel Drake 27330fb67e98SDaniel Drake /* DAC2: unused */ 27340fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27350fb67e98SDaniel Drake 27360fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27370fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27380fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27390fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27400fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27410fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27420fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27430fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27440fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27450fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27460fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27470fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27480fb67e98SDaniel Drake 27490fb67e98SDaniel Drake /* Disable digital microphone port */ 27500fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27510fb67e98SDaniel Drake 27520fb67e98SDaniel Drake /* Audio input selectors */ 27530fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27540fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 27550fb67e98SDaniel Drake 27560fb67e98SDaniel Drake /* Disable SPDIF */ 27570fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27580fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27590fb67e98SDaniel Drake 27600fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 27610fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 27620fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 27630fb67e98SDaniel Drake { } /* end */ 27640fb67e98SDaniel Drake }; 27650fb67e98SDaniel Drake 276634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 276795a618bdSEinar Rünkaru /* Port A: headphones */ 276895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 276995a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 277095a618bdSEinar Rünkaru 277195a618bdSEinar Rünkaru /* Port B: external microphone */ 277295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277395a618bdSEinar Rünkaru 277495a618bdSEinar Rünkaru /* Port C: unused */ 277595a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277695a618bdSEinar Rünkaru 277795a618bdSEinar Rünkaru /* Port D: unused */ 277895a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277995a618bdSEinar Rünkaru 278095a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 278195a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278295a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 278395a618bdSEinar Rünkaru 278495a618bdSEinar Rünkaru /* Port F: unused */ 278595a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278695a618bdSEinar Rünkaru 278795a618bdSEinar Rünkaru /* Port G: internal speakers */ 278895a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 278995a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 279095a618bdSEinar Rünkaru 279195a618bdSEinar Rünkaru /* DAC1 */ 279295a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 279395a618bdSEinar Rünkaru 279495a618bdSEinar Rünkaru /* DAC2: unused */ 279595a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 279695a618bdSEinar Rünkaru 279795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 279895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 279995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280095a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 280295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 280395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280495a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 280695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 280795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280895a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280995a618bdSEinar Rünkaru 281095a618bdSEinar Rünkaru /* Digital microphone port */ 281195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 281295a618bdSEinar Rünkaru 281395a618bdSEinar Rünkaru /* Audio input selectors */ 281495a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 281595a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 281695a618bdSEinar Rünkaru 281795a618bdSEinar Rünkaru /* Disable SPDIF */ 281895a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 281995a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282095a618bdSEinar Rünkaru 282195a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 282295a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 282395a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 282495a618bdSEinar Rünkaru { } /* end */ 282595a618bdSEinar Rünkaru }; 282695a618bdSEinar Rünkaru 282734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2828cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2829cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2830cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2831cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2832cfd3d8dcSGreg Alexander 2833cfd3d8dcSGreg Alexander /* Speakers */ 2834cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2835cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2836cfd3d8dcSGreg Alexander 2837cfd3d8dcSGreg Alexander /* HP, Amp */ 2838cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2839cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2840cfd3d8dcSGreg Alexander 2841cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2842cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2843cfd3d8dcSGreg Alexander 2844cfd3d8dcSGreg Alexander /* DAC1 */ 2845cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2846cfd3d8dcSGreg Alexander 2847cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2848cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2849cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2850cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2851cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2852cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2853cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2854cfd3d8dcSGreg Alexander 2855cfd3d8dcSGreg Alexander /* Audio input selector */ 2856cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2857cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2858cfd3d8dcSGreg Alexander 2859cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2860cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2861cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2862cfd3d8dcSGreg Alexander 2863cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2864cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2865cfd3d8dcSGreg Alexander 2866cfd3d8dcSGreg Alexander /* internal microphone */ 286728c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2868cfd3d8dcSGreg Alexander 2869cfd3d8dcSGreg Alexander /* EAPD */ 2870cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2871cfd3d8dcSGreg Alexander 2872cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2873cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2874cfd3d8dcSGreg Alexander { } /* end */ 2875cfd3d8dcSGreg Alexander }; 2876cfd3d8dcSGreg Alexander 287734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 28787b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 28797b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 28807b2bfdbcSJens Taprogge 28817b2bfdbcSJens Taprogge /* Port G: internal speakers */ 28827b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28837b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28847b2bfdbcSJens Taprogge 28857b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 28867b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28877b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28887b2bfdbcSJens Taprogge 28897b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 28907b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28917b2bfdbcSJens Taprogge 28927b2bfdbcSJens Taprogge /* Port C: Mic */ 28937b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28947b2bfdbcSJens Taprogge 28957b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 28967b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28977b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28987b2bfdbcSJens Taprogge 28997b2bfdbcSJens Taprogge /* DAC1 */ 29007b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29017b2bfdbcSJens Taprogge 29027b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29037b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29047b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29057b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29067b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29077b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29087b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29097b2bfdbcSJens Taprogge 29107b2bfdbcSJens Taprogge /* Audio input selector */ 29117b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29127b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29137b2bfdbcSJens Taprogge 29147b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29157b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29167b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29177b2bfdbcSJens Taprogge 29187b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29197b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29207b2bfdbcSJens Taprogge 29217b2bfdbcSJens Taprogge /* internal microphone */ 292228c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29237b2bfdbcSJens Taprogge 29247b2bfdbcSJens Taprogge /* EAPD */ 29257b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29267b2bfdbcSJens Taprogge 29277b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29287b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29297b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29307b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29317b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29327b2bfdbcSJens Taprogge { } /* end */ 29337b2bfdbcSJens Taprogge }; 29347b2bfdbcSJens Taprogge 293534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29360fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29370fb67e98SDaniel Drake { } /* end */ 29380fb67e98SDaniel Drake }; 29390fb67e98SDaniel Drake 2940048e78a5SDavid Henningsson 294134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2942048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2943048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2944048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2945048e78a5SDavid Henningsson { } /* end */ 2946048e78a5SDavid Henningsson }; 2947048e78a5SDavid Henningsson 29480fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29490fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29500fb67e98SDaniel Drake { 29510fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 29520fb67e98SDaniel Drake conexant_init(codec); 29530fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 29540fb67e98SDaniel Drake cxt5066_hp_automute(codec); 295502b6b5b6SDavid Henningsson cxt5066_automic(codec); 29560fb67e98SDaniel Drake } 2957c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 29580fb67e98SDaniel Drake return 0; 29590fb67e98SDaniel Drake } 29600fb67e98SDaniel Drake 296175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 296275f8991dSDaniel Drake { 2963c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 296475f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 296575f8991dSDaniel Drake conexant_init(codec); 296675f8991dSDaniel Drake cxt5066_hp_automute(codec); 2967c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2968c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 296975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2970c4cfe66cSDaniel Drake } else { 2971c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2972c4cfe66cSDaniel Drake } 297375f8991dSDaniel Drake return 0; 297475f8991dSDaniel Drake } 297575f8991dSDaniel Drake 29760fb67e98SDaniel Drake enum { 29770fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 29780fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 29790fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 29801feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2981cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 29827b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2983a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2984048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 2985fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 29860fb67e98SDaniel Drake CXT5066_MODELS 29870fb67e98SDaniel Drake }; 29880fb67e98SDaniel Drake 2989ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 29900fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 29910fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 29920fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 29931feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 2994cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 29957b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 2996a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 2997048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 2998fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 29990fb67e98SDaniel Drake }; 30000fb67e98SDaniel Drake 300134cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30029966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 300300cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30041feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30058a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3006ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30071feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3008231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3009ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3010ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3011048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3012f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3013a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3014f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 30152ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3016c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30175637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30185637edb2SDavid Henningsson CXT5066_LAPTOP), 30195637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30204d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3021ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 302219593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 302329c5fbbcSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), 3024ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 302584012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3026b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3027d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3028a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3029af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 30307ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 30310fb67e98SDaniel Drake {} 30320fb67e98SDaniel Drake }; 30330fb67e98SDaniel Drake 30340fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30350fb67e98SDaniel Drake { 30360fb67e98SDaniel Drake struct conexant_spec *spec; 30370fb67e98SDaniel Drake int board_config; 30380fb67e98SDaniel Drake 3039fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3040fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3041fea4a4f9STakashi Iwai if (board_config < 0) 3042c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3043fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3044fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3045fea4a4f9STakashi Iwai 30460fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30470fb67e98SDaniel Drake if (!spec) 30480fb67e98SDaniel Drake return -ENOMEM; 30490fb67e98SDaniel Drake codec->spec = spec; 30500fb67e98SDaniel Drake 30510fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 305275f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 30530fb67e98SDaniel Drake 30540fb67e98SDaniel Drake spec->dell_automute = 0; 30550fb67e98SDaniel Drake spec->multiout.max_channels = 2; 30560fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 30570fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3058f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3059f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 30600fb67e98SDaniel Drake spec->num_adc_nids = 1; 30610fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 30620fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 30630fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 30640fb67e98SDaniel Drake 30650fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 30660fb67e98SDaniel Drake 30670fb67e98SDaniel Drake spec->num_init_verbs = 1; 30680fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 30690fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 30700fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 30710fb67e98SDaniel Drake spec->cur_adc = 0; 30720fb67e98SDaniel Drake spec->cur_adc_idx = 0; 30730fb67e98SDaniel Drake 30743507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 30753507e2a8STakashi Iwai 30760fb67e98SDaniel Drake switch (board_config) { 30770fb67e98SDaniel Drake default: 30780fb67e98SDaniel Drake case CXT5066_LAPTOP: 30790fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30800fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30810fb67e98SDaniel Drake break; 30820fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 30830fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30840fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30850fb67e98SDaniel Drake 30860fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 30870fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 30880fb67e98SDaniel Drake spec->num_init_verbs++; 30890fb67e98SDaniel Drake spec->dell_automute = 1; 30900fb67e98SDaniel Drake break; 3091a1d6906eSDavid Henningsson case CXT5066_ASUS: 3092048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3093048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 309402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3095048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3096048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3097048e78a5SDavid Henningsson spec->num_init_verbs++; 3098a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3099a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3100048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3101048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3102048e78a5SDavid Henningsson /* no S/PDIF out */ 3103f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3104048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3105048e78a5SDavid Henningsson /* input source automatically selected */ 3106048e78a5SDavid Henningsson spec->input_mux = NULL; 3107048e78a5SDavid Henningsson spec->port_d_mode = 0; 3108048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3109048e78a5SDavid Henningsson break; 3110048e78a5SDavid Henningsson 31110fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 311275f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 311375f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31140fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31150fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3116c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31170fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31180fb67e98SDaniel Drake spec->port_d_mode = 0; 3119c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31200fb67e98SDaniel Drake 31210fb67e98SDaniel Drake /* no S/PDIF out */ 31220fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31230fb67e98SDaniel Drake 31240fb67e98SDaniel Drake /* input source automatically selected */ 31250fb67e98SDaniel Drake spec->input_mux = NULL; 312675f8991dSDaniel Drake 312775f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 312875f8991dSDaniel Drake * at the right time */ 312975f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 313075f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31310fb67e98SDaniel Drake break; 31321feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 313375f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 313402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 313595a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 313695a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 313795a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3138254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 313995a618bdSEinar Rünkaru spec->port_d_mode = 0; 3140254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3141c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 314295a618bdSEinar Rünkaru 314395a618bdSEinar Rünkaru /* no S/PDIF out */ 314495a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 314595a618bdSEinar Rünkaru 314695a618bdSEinar Rünkaru /* input source automatically selected */ 314795a618bdSEinar Rünkaru spec->input_mux = NULL; 314895a618bdSEinar Rünkaru break; 3149cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3150cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 315102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3152cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3153cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3154cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3155cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3156cfd3d8dcSGreg Alexander spec->ideapad = 1; 3157cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3158cfd3d8dcSGreg Alexander 3159cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3160cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3161cfd3d8dcSGreg Alexander 3162cfd3d8dcSGreg Alexander /* input source automatically selected */ 3163cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3164cfd3d8dcSGreg Alexander break; 31657b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 31667b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 316702b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 31687b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31697b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31707b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 31717b2bfdbcSJens Taprogge spec->thinkpad = 1; 31727b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 31737b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 31747b2bfdbcSJens Taprogge 31757b2bfdbcSJens Taprogge /* no S/PDIF out */ 31767b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 31777b2bfdbcSJens Taprogge 31787b2bfdbcSJens Taprogge /* input source automatically selected */ 31797b2bfdbcSJens Taprogge spec->input_mux = NULL; 31807b2bfdbcSJens Taprogge break; 31810fb67e98SDaniel Drake } 31820fb67e98SDaniel Drake 31833507e2a8STakashi Iwai if (spec->beep_amp) 31843507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 31853507e2a8STakashi Iwai 31860fb67e98SDaniel Drake return 0; 31870fb67e98SDaniel Drake } 3188461e2c78STakashi Iwai 3189461e2c78STakashi Iwai /* 3190f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3191f2e5731dSTakashi Iwai */ 3192f2e5731dSTakashi Iwai 31936764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 31946764bcefSTakashi Iwai struct hda_codec *codec, 31956764bcefSTakashi Iwai unsigned int stream_tag, 31966764bcefSTakashi Iwai unsigned int format, 31976764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31986764bcefSTakashi Iwai { 31996764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 320047ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 32016764bcefSTakashi Iwai if (spec->adc_switching) { 32026764bcefSTakashi Iwai spec->cur_adc = adc; 32036764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32046764bcefSTakashi Iwai spec->cur_adc_format = format; 32056764bcefSTakashi Iwai } 32066764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32076764bcefSTakashi Iwai return 0; 32086764bcefSTakashi Iwai } 32096764bcefSTakashi Iwai 32106764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 32116764bcefSTakashi Iwai struct hda_codec *codec, 32126764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32136764bcefSTakashi Iwai { 32146764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32156764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 32166764bcefSTakashi Iwai spec->cur_adc = 0; 32176764bcefSTakashi Iwai return 0; 32186764bcefSTakashi Iwai } 32196764bcefSTakashi Iwai 32206764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32216764bcefSTakashi Iwai .substreams = 1, 32226764bcefSTakashi Iwai .channels_min = 2, 32236764bcefSTakashi Iwai .channels_max = 2, 32246764bcefSTakashi Iwai .nid = 0, /* fill later */ 32256764bcefSTakashi Iwai .ops = { 32266764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32276764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32286764bcefSTakashi Iwai }, 32296764bcefSTakashi Iwai }; 32306764bcefSTakashi Iwai 323134cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3232f2e5731dSTakashi Iwai 32338d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 32348d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3235f2e5731dSTakashi Iwai 3236f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3237f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3238f2e5731dSTakashi Iwai * not found 3239f2e5731dSTakashi Iwai */ 3240f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3241f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3242f2e5731dSTakashi Iwai { 3243f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3244f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3245f2e5731dSTakashi Iwai 3246f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3247f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3248f2e5731dSTakashi Iwai ret = dacs[i]; 3249f2e5731dSTakashi Iwai break; 3250f2e5731dSTakashi Iwai } 3251f2e5731dSTakashi Iwai } 3252f2e5731dSTakashi Iwai if (!ret) 3253f2e5731dSTakashi Iwai return 0; 3254f2e5731dSTakashi Iwai if (--nums > 0) 3255f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3256f2e5731dSTakashi Iwai *num_dacs = nums; 3257f2e5731dSTakashi Iwai return ret; 3258f2e5731dSTakashi Iwai } 3259f2e5731dSTakashi Iwai 3260f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3261f2e5731dSTakashi Iwai 32621f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 32631f015f5fSTakashi Iwai 3264f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3265f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3266f2e5731dSTakashi Iwai { 3267f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3268f2e5731dSTakashi Iwai int nums = 0; 3269f2e5731dSTakashi Iwai 3270f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3271f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3272f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3273f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3274f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3275f2e5731dSTakashi Iwai dacs[nums++] = nid; 3276f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3277f2e5731dSTakashi Iwai break; 3278f2e5731dSTakashi Iwai } 3279f2e5731dSTakashi Iwai } 3280f2e5731dSTakashi Iwai return nums; 3281f2e5731dSTakashi Iwai } 3282f2e5731dSTakashi Iwai 3283f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3284f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3285f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3286468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3287468c5458SDavid Henningsson int type) 3288f2e5731dSTakashi Iwai { 3289468c5458SDavid Henningsson int i, start = nums; 3290f2e5731dSTakashi Iwai 3291468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3292f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3293f2e5731dSTakashi Iwai filled[nums].type = type; 3294f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3295468c5458SDavid Henningsson if (filled[nums].dac) 3296468c5458SDavid Henningsson continue; 3297468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3298468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3299468c5458SDavid Henningsson continue; 3300468c5458SDavid Henningsson } 3301468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 33021f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3303468c5458SDavid Henningsson continue; 3304468c5458SDavid Henningsson } 3305468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3306f2e5731dSTakashi Iwai } 3307f2e5731dSTakashi Iwai return nums; 3308f2e5731dSTakashi Iwai } 3309f2e5731dSTakashi Iwai 3310f2e5731dSTakashi Iwai /* parse analog output paths */ 3311f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3312f2e5731dSTakashi Iwai { 3313f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3314f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3315f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3316f2e5731dSTakashi Iwai int i, j, nums, rest; 3317f2e5731dSTakashi Iwai 3318f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3319f2e5731dSTakashi Iwai /* parse all analog output pins */ 3320f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3321468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3322f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3323468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3324468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3325f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3326468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3327468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3328f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3329f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3330f2e5731dSTakashi Iwai /* fill multiout struct */ 3331f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3332f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 33331f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3334f2e5731dSTakashi Iwai continue; 3335f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3336f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3337f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3338f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3339f2e5731dSTakashi Iwai break; 3340f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3341f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3342f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3343f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3344f2e5731dSTakashi Iwai break; 3345f2e5731dSTakashi Iwai } 3346f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3347f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3348f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3349f2e5731dSTakashi Iwai break; 3350f2e5731dSTakashi Iwai } 3351f2e5731dSTakashi Iwai break; 3352f2e5731dSTakashi Iwai } 3353f2e5731dSTakashi Iwai } 3354f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 335589724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3356f2e5731dSTakashi Iwai 335703697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 335803697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3359f2e5731dSTakashi Iwai spec->auto_mute = 1; 336003697e2aSTakashi Iwai break; 336103697e2aSTakashi Iwai } 336203697e2aSTakashi Iwai } 3363e2df82ffSTakashi Iwai if (spec->auto_mute && 3364e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3365e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 336603697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 336703697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 336803697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 336903697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 337003697e2aSTakashi Iwai spec->detect_line = 1; 337103697e2aSTakashi Iwai break; 337203697e2aSTakashi Iwai } 337303697e2aSTakashi Iwai } 337403697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 337503697e2aSTakashi Iwai } 337603697e2aSTakashi Iwai 3377f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3378f2e5731dSTakashi Iwai } 3379f2e5731dSTakashi Iwai 3380da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3381da339866STakashi Iwai hda_nid_t *pins, bool on); 3382da339866STakashi Iwai 338303697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 338403697e2aSTakashi Iwai hda_nid_t *pins, bool on) 338503697e2aSTakashi Iwai { 3386254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 338703697e2aSTakashi Iwai int i; 338803697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 338903697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 339003697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 339103697e2aSTakashi Iwai on ? PIN_OUT : 0); 3392254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 339303697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 339403697e2aSTakashi Iwai } 339503697e2aSTakashi Iwai 339603697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 339703697e2aSTakashi Iwai { 339803697e2aSTakashi Iwai int i, present = 0; 339903697e2aSTakashi Iwai 340003697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 340103697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 340203697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 340303697e2aSTakashi Iwai break; 340403697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 340503697e2aSTakashi Iwai } 340603697e2aSTakashi Iwai return present; 340703697e2aSTakashi Iwai } 340803697e2aSTakashi Iwai 3409f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 341003697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 341103697e2aSTakashi Iwai { 341203697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 341303697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3414e2df82ffSTakashi Iwai int on = 1; 341503697e2aSTakashi Iwai 3416e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3417254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3418e2df82ffSTakashi Iwai if (spec->auto_mute) 3419e2df82ffSTakashi Iwai on = spec->hp_present; 342003697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3421254f2968STakashi Iwai } 3422254f2968STakashi Iwai 3423e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3424e2df82ffSTakashi Iwai if (spec->auto_mute) 3425e2df82ffSTakashi Iwai on = !(spec->hp_present || 3426e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3427e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 342803697e2aSTakashi Iwai 342903697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 343003697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 343103697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 343203697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 343303697e2aSTakashi Iwai return; 3434e2df82ffSTakashi Iwai if (spec->auto_mute) { 3435e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3436e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3437e2df82ffSTakashi Iwai spec->automute_lines) 3438e2df82ffSTakashi Iwai on = !spec->hp_present; 343903697e2aSTakashi Iwai else 3440e2df82ffSTakashi Iwai on = 1; 3441e2df82ffSTakashi Iwai } 3442e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 344303697e2aSTakashi Iwai } 344403697e2aSTakashi Iwai 3445f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3446f2e5731dSTakashi Iwai { 3447f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3448f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3449f2e5731dSTakashi Iwai 3450f2e5731dSTakashi Iwai if (!spec->auto_mute) 3451f2e5731dSTakashi Iwai return; 345203697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 345303697e2aSTakashi Iwai cx_auto_update_speakers(codec); 345403697e2aSTakashi Iwai } 345503697e2aSTakashi Iwai 345603697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 345703697e2aSTakashi Iwai { 345803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 345903697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 346003697e2aSTakashi Iwai 346103697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 346203697e2aSTakashi Iwai return; 346303697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 346403697e2aSTakashi Iwai cfg->line_out_pins); 346503697e2aSTakashi Iwai cx_auto_update_speakers(codec); 346603697e2aSTakashi Iwai } 346703697e2aSTakashi Iwai 346803697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 346903697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 347003697e2aSTakashi Iwai { 347103697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 347203697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 347303697e2aSTakashi Iwai static const char * const texts2[] = { 347403697e2aSTakashi Iwai "Disabled", "Enabled" 347503697e2aSTakashi Iwai }; 347603697e2aSTakashi Iwai static const char * const texts3[] = { 3477e49a3434STakashi Iwai "Disabled", "Speaker Only", "Line Out+Speaker" 347803697e2aSTakashi Iwai }; 347903697e2aSTakashi Iwai const char * const *texts; 348003697e2aSTakashi Iwai 348103697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 348203697e2aSTakashi Iwai uinfo->count = 1; 348303697e2aSTakashi Iwai if (spec->automute_hp_lo) { 348403697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 348503697e2aSTakashi Iwai texts = texts3; 348603697e2aSTakashi Iwai } else { 348703697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 348803697e2aSTakashi Iwai texts = texts2; 348903697e2aSTakashi Iwai } 349003697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 349103697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 349203697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 349303697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 349403697e2aSTakashi Iwai return 0; 349503697e2aSTakashi Iwai } 349603697e2aSTakashi Iwai 349703697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 349803697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 349903697e2aSTakashi Iwai { 350003697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 350103697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 350203697e2aSTakashi Iwai unsigned int val; 350303697e2aSTakashi Iwai if (!spec->auto_mute) 350403697e2aSTakashi Iwai val = 0; 350503697e2aSTakashi Iwai else if (!spec->automute_lines) 350603697e2aSTakashi Iwai val = 1; 350703697e2aSTakashi Iwai else 350803697e2aSTakashi Iwai val = 2; 350903697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 351003697e2aSTakashi Iwai return 0; 351103697e2aSTakashi Iwai } 351203697e2aSTakashi Iwai 351303697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 351403697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 351503697e2aSTakashi Iwai { 351603697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 351703697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 351803697e2aSTakashi Iwai 351903697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 352003697e2aSTakashi Iwai case 0: 352103697e2aSTakashi Iwai if (!spec->auto_mute) 352203697e2aSTakashi Iwai return 0; 352303697e2aSTakashi Iwai spec->auto_mute = 0; 3524f2e5731dSTakashi Iwai break; 352503697e2aSTakashi Iwai case 1: 352603697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 352703697e2aSTakashi Iwai return 0; 352803697e2aSTakashi Iwai spec->auto_mute = 1; 352903697e2aSTakashi Iwai spec->automute_lines = 0; 353003697e2aSTakashi Iwai break; 353103697e2aSTakashi Iwai case 2: 353203697e2aSTakashi Iwai if (!spec->automute_hp_lo) 353303697e2aSTakashi Iwai return -EINVAL; 353403697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 353503697e2aSTakashi Iwai return 0; 353603697e2aSTakashi Iwai spec->auto_mute = 1; 353703697e2aSTakashi Iwai spec->automute_lines = 1; 353803697e2aSTakashi Iwai break; 353903697e2aSTakashi Iwai default: 354003697e2aSTakashi Iwai return -EINVAL; 3541f2e5731dSTakashi Iwai } 354203697e2aSTakashi Iwai cx_auto_update_speakers(codec); 354303697e2aSTakashi Iwai return 1; 3544f2e5731dSTakashi Iwai } 354503697e2aSTakashi Iwai 354603697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 354703697e2aSTakashi Iwai { 354803697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 354903697e2aSTakashi Iwai .name = "Auto-Mute Mode", 355003697e2aSTakashi Iwai .info = cx_automute_mode_info, 355103697e2aSTakashi Iwai .get = cx_automute_mode_get, 355203697e2aSTakashi Iwai .put = cx_automute_mode_put, 355303697e2aSTakashi Iwai }, 355403697e2aSTakashi Iwai { } 355503697e2aSTakashi Iwai }; 3556f2e5731dSTakashi Iwai 35576764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 35586764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 35596764bcefSTakashi Iwai { 35606764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35616764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35626764bcefSTakashi Iwai 35636764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 35646764bcefSTakashi Iwai } 35656764bcefSTakashi Iwai 35666764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 35676764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35686764bcefSTakashi Iwai { 35696764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35706764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35716764bcefSTakashi Iwai 35726764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 35736764bcefSTakashi Iwai return 0; 35746764bcefSTakashi Iwai } 35756764bcefSTakashi Iwai 35765c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 35775c9887e0STakashi Iwai * if do_select is set, actually select the route. 35785c9887e0STakashi Iwai */ 35795c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3580cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3581cf27f29aSTakashi Iwai bool do_select, int depth) 35825c9887e0STakashi Iwai { 35835c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 35845c9887e0STakashi Iwai int i, nums; 35855c9887e0STakashi Iwai 3586cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3587cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3588cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3589cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3590cf27f29aSTakashi Iwai break; 3591cf27f29aSTakashi Iwai default: 3592cf27f29aSTakashi Iwai return -1; 3593cf27f29aSTakashi Iwai } 3594cf27f29aSTakashi Iwai 35955c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 35965c9887e0STakashi Iwai for (i = 0; i < nums; i++) 35975c9887e0STakashi Iwai if (conn[i] == pin) { 35985c9887e0STakashi Iwai if (do_select) 35995c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36005c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3601cf27f29aSTakashi Iwai if (srcp) 3602cf27f29aSTakashi Iwai *srcp = mux; 36035c9887e0STakashi Iwai return i; 36045c9887e0STakashi Iwai } 36055c9887e0STakashi Iwai depth++; 36065c9887e0STakashi Iwai if (depth == 2) 36075c9887e0STakashi Iwai return -1; 36085c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3609cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 36105c9887e0STakashi Iwai do_select, depth); 36115c9887e0STakashi Iwai if (ret >= 0) { 36125c9887e0STakashi Iwai if (do_select) 36135c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36145c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3615cf27f29aSTakashi Iwai return i; 36165c9887e0STakashi Iwai } 36175c9887e0STakashi Iwai } 36185c9887e0STakashi Iwai return -1; 36195c9887e0STakashi Iwai } 36205c9887e0STakashi Iwai 36215c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36225c9887e0STakashi Iwai hda_nid_t pin) 36235c9887e0STakashi Iwai { 3624cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36255c9887e0STakashi Iwai } 36265c9887e0STakashi Iwai 36275c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 36285c9887e0STakashi Iwai hda_nid_t pin) 36295c9887e0STakashi Iwai { 3630cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 36315c9887e0STakashi Iwai } 36325c9887e0STakashi Iwai 36336764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 36346764bcefSTakashi Iwai const struct hda_input_mux *imux, 36356764bcefSTakashi Iwai unsigned int idx) 36366764bcefSTakashi Iwai { 36376764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36386764bcefSTakashi Iwai hda_nid_t adc; 3639313d2c06STakashi Iwai int changed = 1; 36406764bcefSTakashi Iwai 36416764bcefSTakashi Iwai if (!imux->num_items) 36426764bcefSTakashi Iwai return 0; 36436764bcefSTakashi Iwai if (idx >= imux->num_items) 36446764bcefSTakashi Iwai idx = imux->num_items - 1; 36456764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3646313d2c06STakashi Iwai changed = 0; 364747ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 364847ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 364947ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 36506764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 36516764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 36526764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 36536764bcefSTakashi Iwai spec->cur_adc = adc; 36546764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 36556764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 36566764bcefSTakashi Iwai spec->cur_adc_format); 36576764bcefSTakashi Iwai } 36586764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3659313d2c06STakashi Iwai return changed; 36606764bcefSTakashi Iwai } 36616764bcefSTakashi Iwai 36626764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 36636764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36646764bcefSTakashi Iwai { 36656764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36666764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36676764bcefSTakashi Iwai 36686764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 36696764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 36706764bcefSTakashi Iwai } 36716764bcefSTakashi Iwai 36726764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 36736764bcefSTakashi Iwai { 36746764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 36756764bcefSTakashi Iwai .name = "Capture Source", 36766764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 36776764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 36786764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 36796764bcefSTakashi Iwai }, 36806764bcefSTakashi Iwai {} 36816764bcefSTakashi Iwai }; 36826764bcefSTakashi Iwai 368343c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 368443c1b2e9STakashi Iwai { 368543c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 368643c1b2e9STakashi Iwai if (idx < 0) 368743c1b2e9STakashi Iwai return false; 368843c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 368943c1b2e9STakashi Iwai return false; 369043c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 369143c1b2e9STakashi Iwai return true; 369243c1b2e9STakashi Iwai } 369343c1b2e9STakashi Iwai 3694f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3695f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3696f2e5731dSTakashi Iwai { 3697f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3698f2e5731dSTakashi Iwai 3699f2e5731dSTakashi Iwai if (!spec->auto_mic) 3700f2e5731dSTakashi Iwai return; 370143c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 370243c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 370343c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3704f2e5731dSTakashi Iwai } 3705f2e5731dSTakashi Iwai 3706f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3707f2e5731dSTakashi Iwai { 37083a93897eSTakashi Iwai switch (snd_hda_jack_get_action(codec, res >> 26)) { 3709f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3710f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 371103697e2aSTakashi Iwai break; 371203697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 371303697e2aSTakashi Iwai cx_auto_line_automute(codec); 3714f2e5731dSTakashi Iwai break; 3715f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3716f2e5731dSTakashi Iwai cx_auto_automic(codec); 3717f2e5731dSTakashi Iwai break; 3718f2e5731dSTakashi Iwai } 371901a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3720f2e5731dSTakashi Iwai } 3721f2e5731dSTakashi Iwai 3722f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 372343c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 372443c1b2e9STakashi Iwai * one dock-mic exist 3725f2e5731dSTakashi Iwai */ 3726f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3727f2e5731dSTakashi Iwai { 3728f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 372943c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 373043c1b2e9STakashi Iwai int i; 3731f2e5731dSTakashi Iwai 3732506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 373343c1b2e9STakashi Iwai pset[i] = -1; 373443c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 373543c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 373643c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3737b55fcb50STakashi Iwai int type, attr; 373843c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 373943c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3740b55fcb50STakashi Iwai return; /* invalid entry */ 374143c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 374243c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 374343c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 374443c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3745b55fcb50STakashi Iwai return; /* non-detectable pin */ 3746b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3747b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3748b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3749b55fcb50STakashi Iwai return; /* no valid input type */ 375043c1b2e9STakashi Iwai if (pset[attr] >= 0) 375143c1b2e9STakashi Iwai return; /* already occupied */ 375243c1b2e9STakashi Iwai pset[attr] = i; 3753f2e5731dSTakashi Iwai } 375443c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 375543c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 375643c1b2e9STakashi Iwai return; /* no input to switch*/ 3757f2e5731dSTakashi Iwai spec->auto_mic = 1; 375843c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 375943c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 376043c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3761f2e5731dSTakashi Iwai } 3762f2e5731dSTakashi Iwai 3763f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3764f2e5731dSTakashi Iwai { 3765f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3766f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3767f2e5731dSTakashi Iwai struct hda_input_mux *imux; 37686764bcefSTakashi Iwai int i, j; 3769f2e5731dSTakashi Iwai 3770f2e5731dSTakashi Iwai imux = &spec->private_imux; 3771f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 37726764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 37736764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 37745c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3775f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3776f2e5731dSTakashi Iwai if (idx >= 0) { 3777f2e5731dSTakashi Iwai const char *label; 3778f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 377947ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 378047ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 378147ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 378247ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3783f6100bb4STakashi Iwai cfg->inputs[i].pin; 3784f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 37856764bcefSTakashi Iwai break; 37866764bcefSTakashi Iwai } 3787f2e5731dSTakashi Iwai } 3788f2e5731dSTakashi Iwai } 378943c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3790f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 379176755359STakashi Iwai if (imux->num_items > 1) { 37926764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 379347ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 37946764bcefSTakashi Iwai spec->adc_switching = 1; 37956764bcefSTakashi Iwai break; 37966764bcefSTakashi Iwai } 37976764bcefSTakashi Iwai } 37986764bcefSTakashi Iwai } 3799f2e5731dSTakashi Iwai } 3800f2e5731dSTakashi Iwai 3801f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3802f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3803f2e5731dSTakashi Iwai { 3804f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3805f2e5731dSTakashi Iwai 3806f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3807f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3808f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3809f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3810f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3811f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3812f2e5731dSTakashi Iwai return nid; 3813f2e5731dSTakashi Iwai } 3814f2e5731dSTakashi Iwai } 3815f2e5731dSTakashi Iwai return 0; 3816f2e5731dSTakashi Iwai } 3817f2e5731dSTakashi Iwai 3818f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3819f2e5731dSTakashi Iwai { 3820f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3821f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3822f2e5731dSTakashi Iwai hda_nid_t nid; 3823f2e5731dSTakashi Iwai 3824f2e5731dSTakashi Iwai if (cfg->dig_outs && 3825f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3826f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3827f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3828f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3829f2e5731dSTakashi Iwai } 3830f2e5731dSTakashi Iwai 3831f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3832f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3833f2e5731dSTakashi Iwai { 3834f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3835f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3836f2e5731dSTakashi Iwai 3837f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3838f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3839f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3840f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3841f2e5731dSTakashi Iwai break; 3842f2e5731dSTakashi Iwai } 3843f2e5731dSTakashi Iwai } 3844f2e5731dSTakashi Iwai #else 3845f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3846f2e5731dSTakashi Iwai #endif 3847f2e5731dSTakashi Iwai 3848254f2968STakashi Iwai /* parse EAPDs */ 384919110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 385019110595STakashi Iwai { 385119110595STakashi Iwai struct conexant_spec *spec = codec->spec; 385219110595STakashi Iwai hda_nid_t nid, end_nid; 385319110595STakashi Iwai 385419110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 385519110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 385619110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 385719110595STakashi Iwai continue; 385819110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 385919110595STakashi Iwai continue; 386019110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 386119110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 386219110595STakashi Iwai break; 386319110595STakashi Iwai } 3864254f2968STakashi Iwai 3865254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3866254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3867254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3868254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3869254f2968STakashi Iwai * thus it might control over all pins. 3870254f2968STakashi Iwai */ 3871254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 387219110595STakashi Iwai } 387319110595STakashi Iwai 3874f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3875f2e5731dSTakashi Iwai { 3876f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3877f2e5731dSTakashi Iwai int err; 3878f2e5731dSTakashi Iwai 3879f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3880f2e5731dSTakashi Iwai if (err < 0) 3881f2e5731dSTakashi Iwai return err; 3882f2e5731dSTakashi Iwai 3883f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3884f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3885f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3886f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 388719110595STakashi Iwai cx_auto_parse_eapd(codec); 3888f2e5731dSTakashi Iwai return 0; 3889f2e5731dSTakashi Iwai } 3890f2e5731dSTakashi Iwai 3891da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3892da339866STakashi Iwai hda_nid_t *pins, bool on) 3893f2e5731dSTakashi Iwai { 3894f2e5731dSTakashi Iwai int i; 3895f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3896f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3897f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3898da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3899da339866STakashi Iwai on ? 0x02 : 0); 3900f2e5731dSTakashi Iwai } 3901f2e5731dSTakashi Iwai } 3902f2e5731dSTakashi Iwai 3903f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3904f2e5731dSTakashi Iwai hda_nid_t src) 3905f2e5731dSTakashi Iwai { 3906f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3907f2e5731dSTakashi Iwai if (idx >= 0) 3908f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3909f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3910f2e5731dSTakashi Iwai } 3911f2e5731dSTakashi Iwai 39121f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 39131f8458a2STakashi Iwai const hda_nid_t *nids) 3914f2e5731dSTakashi Iwai { 39150ad1b5b6STakashi Iwai int i, val; 3916f2e5731dSTakashi Iwai 39171f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 39181f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 39191f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 39201f8458a2STakashi Iwai continue; 39210ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 39220ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 39230ad1b5b6STakashi Iwai else 39240ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 39250ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 39260ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 39270ad1b5b6STakashi Iwai } 39281f8458a2STakashi Iwai } 3929f2e5731dSTakashi Iwai 393003697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 39313a93897eSTakashi Iwai hda_nid_t *pins, unsigned int action) 393203697e2aSTakashi Iwai { 393303697e2aSTakashi Iwai int i; 393403697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 39353a93897eSTakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], action); 393603697e2aSTakashi Iwai } 393703697e2aSTakashi Iwai 393807cafff2STakashi Iwai static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 393907cafff2STakashi Iwai { 394007cafff2STakashi Iwai int i; 394107cafff2STakashi Iwai for (i = 0; i < nums; i++) 394207cafff2STakashi Iwai if (list[i] == nid) 394307cafff2STakashi Iwai return true; 394407cafff2STakashi Iwai return false; 394507cafff2STakashi Iwai } 394607cafff2STakashi Iwai 394707cafff2STakashi Iwai /* is the given NID found in any of autocfg items? */ 394807cafff2STakashi Iwai static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) 394907cafff2STakashi Iwai { 395007cafff2STakashi Iwai int i; 395107cafff2STakashi Iwai 395207cafff2STakashi Iwai if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || 395307cafff2STakashi Iwai found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || 395407cafff2STakashi Iwai found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || 395507cafff2STakashi Iwai found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) 395607cafff2STakashi Iwai return true; 395707cafff2STakashi Iwai for (i = 0; i < cfg->num_inputs; i++) 395807cafff2STakashi Iwai if (cfg->inputs[i].pin == nid) 395907cafff2STakashi Iwai return true; 396007cafff2STakashi Iwai if (cfg->dig_in_pin == nid) 396107cafff2STakashi Iwai return true; 396207cafff2STakashi Iwai return false; 396307cafff2STakashi Iwai } 396407cafff2STakashi Iwai 396507cafff2STakashi Iwai /* clear unsol-event tags on unused pins; Conexant codecs seem to leave 396607cafff2STakashi Iwai * invalid unsol tags by some reason 396707cafff2STakashi Iwai */ 396807cafff2STakashi Iwai static void clear_unsol_on_unused_pins(struct hda_codec *codec) 396907cafff2STakashi Iwai { 397007cafff2STakashi Iwai struct conexant_spec *spec = codec->spec; 397107cafff2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 397207cafff2STakashi Iwai int i; 397307cafff2STakashi Iwai 397407cafff2STakashi Iwai for (i = 0; i < codec->init_pins.used; i++) { 397507cafff2STakashi Iwai struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 397607cafff2STakashi Iwai if (!found_in_autocfg(cfg, pin->nid)) 397707cafff2STakashi Iwai snd_hda_codec_write(codec, pin->nid, 0, 397807cafff2STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 0); 397907cafff2STakashi Iwai } 398007cafff2STakashi Iwai } 398107cafff2STakashi Iwai 3982527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */ 3983527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled) 3984527c73baSTakashi Iwai { 3985527c73baSTakashi Iwai struct hda_codec *codec = private_data; 3986527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 3987527c73baSTakashi Iwai 3988527c73baSTakashi Iwai if (enabled && spec->pin_eapd_ctrls) { 3989527c73baSTakashi Iwai cx_auto_update_speakers(codec); 3990527c73baSTakashi Iwai return; 3991527c73baSTakashi Iwai } 3992527c73baSTakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 3993527c73baSTakashi Iwai } 3994527c73baSTakashi Iwai 39951f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39961f8458a2STakashi Iwai { 39971f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39981f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39991f8458a2STakashi Iwai hda_nid_t nid; 40001f8458a2STakashi Iwai int i; 40011f8458a2STakashi Iwai 40021f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 4003f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 4004f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 4005f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 40061f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 40071f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 40081f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 4009f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4010f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 4011f2e5731dSTakashi Iwai if (!nid) 4012f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 40131f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 40141f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 4015f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 4016f2e5731dSTakashi Iwai } 401703697e2aSTakashi Iwai if (spec->auto_mute) { 401803697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 401903697e2aSTakashi Iwai CONEXANT_HP_EVENT); 402003697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 402103697e2aSTakashi Iwai cfg->hp_pins); 402203697e2aSTakashi Iwai if (spec->detect_line) { 402303697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 402403697e2aSTakashi Iwai cfg->line_out_pins, 402503697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 402603697e2aSTakashi Iwai spec->line_present = 402703697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 402803697e2aSTakashi Iwai cfg->line_out_pins); 402903697e2aSTakashi Iwai } 403003697e2aSTakashi Iwai } 403103697e2aSTakashi Iwai cx_auto_update_speakers(codec); 4032254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 4033254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 403419110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 403507cafff2STakashi Iwai clear_unsol_on_unused_pins(codec); 4036f2e5731dSTakashi Iwai } 4037f2e5731dSTakashi Iwai 4038f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 4039f2e5731dSTakashi Iwai { 4040f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4041f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40420ad1b5b6STakashi Iwai int i, val; 4043f2e5731dSTakashi Iwai 40440ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 40450ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 40461f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 40471f8458a2STakashi Iwai continue; 40480ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 40490ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40500ad1b5b6STakashi Iwai else 40510ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40520ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40530ad1b5b6STakashi Iwai val); 40540ad1b5b6STakashi Iwai } 4055f2e5731dSTakashi Iwai 4056f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4057f2e5731dSTakashi Iwai unsigned int type; 4058f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4059f2e5731dSTakashi Iwai type = PIN_VREF80; 4060f2e5731dSTakashi Iwai else 4061f2e5731dSTakashi Iwai type = PIN_IN; 4062f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4063f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4064f2e5731dSTakashi Iwai } 4065f2e5731dSTakashi Iwai 4066f2e5731dSTakashi Iwai if (spec->auto_mic) { 406743c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40681835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40691835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40701835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 407143c1b2e9STakashi Iwai } 407243c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40731835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40741835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40751835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 407643c1b2e9STakashi Iwai } 4077f2e5731dSTakashi Iwai cx_auto_automic(codec); 4078f2e5731dSTakashi Iwai } else { 407947ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 408047ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4081f2e5731dSTakashi Iwai } 4082f2e5731dSTakashi Iwai } 4083f2e5731dSTakashi Iwai 4084f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4085f2e5731dSTakashi Iwai { 4086f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4087f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4088f2e5731dSTakashi Iwai 4089f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4090f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4091f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4092f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4093f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4094f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4095f2e5731dSTakashi Iwai } 4096f2e5731dSTakashi Iwai 4097f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4098f2e5731dSTakashi Iwai { 4099527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 4100f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4101f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4102f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4103f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 410401a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4105d2f344b5STakashi Iwai snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4106f2e5731dSTakashi Iwai return 0; 4107f2e5731dSTakashi Iwai } 4108f2e5731dSTakashi Iwai 4109983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4110f2e5731dSTakashi Iwai const char *dir, int cidx, 4111*18dcd304SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx, int chs) 4112f2e5731dSTakashi Iwai { 4113*18dcd304SDavid Henningsson static char name[44]; 4114f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4115f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4116f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4117f2e5731dSTakashi Iwai }; 411834cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4119f2e5731dSTakashi Iwai int i, err; 4120f2e5731dSTakashi Iwai 4121f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4122f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4123*18dcd304SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, 4124983345e5SDavid Henningsson hda_dir); 4125f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4126f2e5731dSTakashi Iwai knew[i].index = cidx; 4127f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4128f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4129f2e5731dSTakashi Iwai if (!kctl) 4130f2e5731dSTakashi Iwai return -ENOMEM; 4131f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4132f2e5731dSTakashi Iwai if (err < 0) 4133f2e5731dSTakashi Iwai return err; 41343868137eSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & 41353868137eSTakashi Iwai (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) 4136f2e5731dSTakashi Iwai break; 4137f2e5731dSTakashi Iwai } 4138f2e5731dSTakashi Iwai return 0; 4139f2e5731dSTakashi Iwai } 4140f2e5731dSTakashi Iwai 4141983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4142*18dcd304SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) 4143983345e5SDavid Henningsson 4144f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4145f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4146f2e5731dSTakashi Iwai 41471f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 41481f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 41491f8458a2STakashi Iwai { 41501f8458a2STakashi Iwai unsigned int caps; 4151468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 41521f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41531f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41541f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4155468c5458SDavid Henningsson } 41561f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41571f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41581f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41591f8458a2STakashi Iwai return 0; 41601f8458a2STakashi Iwai } 41611f8458a2STakashi Iwai 4162f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4163f2e5731dSTakashi Iwai { 4164f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4165f2e5731dSTakashi Iwai int i, err; 4166f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4167ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4168f2e5731dSTakashi Iwai 4169f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41701f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41711f8458a2STakashi Iwai spec->dac_info[0].pin, 4172f2e5731dSTakashi Iwai "Master", 0); 41731f8458a2STakashi Iwai 4174f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4175f2e5731dSTakashi Iwai const char *label; 4176f2e5731dSTakashi Iwai int idx, type; 41771f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4178f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4179f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4180f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4181f2e5731dSTakashi Iwai switch (type) { 4182f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4183f2e5731dSTakashi Iwai default: 4184f2e5731dSTakashi Iwai label = texts[num_line++]; 4185f2e5731dSTakashi Iwai idx = 0; 4186f2e5731dSTakashi Iwai break; 4187f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4188f2e5731dSTakashi Iwai label = "Headphone"; 4189f2e5731dSTakashi Iwai idx = num_hp++; 4190f2e5731dSTakashi Iwai break; 4191f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4192f2e5731dSTakashi Iwai label = "Speaker"; 4193f2e5731dSTakashi Iwai idx = num_spk++; 4194f2e5731dSTakashi Iwai break; 4195f2e5731dSTakashi Iwai } 41961f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41971f8458a2STakashi Iwai spec->dac_info[i].pin, 4198f2e5731dSTakashi Iwai label, idx); 4199f2e5731dSTakashi Iwai if (err < 0) 4200f2e5731dSTakashi Iwai return err; 4201f2e5731dSTakashi Iwai } 420203697e2aSTakashi Iwai 420303697e2aSTakashi Iwai if (spec->auto_mute) { 420403697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 420503697e2aSTakashi Iwai if (err < 0) 420603697e2aSTakashi Iwai return err; 420703697e2aSTakashi Iwai } 420803697e2aSTakashi Iwai 4209f2e5731dSTakashi Iwai return 0; 4210f2e5731dSTakashi Iwai } 4211f2e5731dSTakashi Iwai 4212*18dcd304SDavid Henningsson /* Returns zero if this is a normal stereo channel, and non-zero if it should 4213*18dcd304SDavid Henningsson be split in two independent channels. 4214*18dcd304SDavid Henningsson dest_label must be at least 44 characters. */ 4215*18dcd304SDavid Henningsson static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, 4216*18dcd304SDavid Henningsson char *dest_label, int nid) 4217*18dcd304SDavid Henningsson { 4218*18dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 4219*18dcd304SDavid Henningsson int i; 4220*18dcd304SDavid Henningsson 4221*18dcd304SDavid Henningsson if (!spec->fixup_stereo_dmic) 4222*18dcd304SDavid Henningsson return 0; 4223*18dcd304SDavid Henningsson 4224*18dcd304SDavid Henningsson for (i = 0; i < AUTO_CFG_MAX_INS; i++) { 4225*18dcd304SDavid Henningsson int def_conf; 4226*18dcd304SDavid Henningsson if (spec->autocfg.inputs[i].pin != nid) 4227*18dcd304SDavid Henningsson continue; 4228*18dcd304SDavid Henningsson 4229*18dcd304SDavid Henningsson if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) 4230*18dcd304SDavid Henningsson return 0; 4231*18dcd304SDavid Henningsson def_conf = snd_hda_codec_get_pincfg(codec, nid); 4232*18dcd304SDavid Henningsson if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) 4233*18dcd304SDavid Henningsson return 0; 4234*18dcd304SDavid Henningsson 4235*18dcd304SDavid Henningsson /* Finally found the inverted internal mic! */ 4236*18dcd304SDavid Henningsson snprintf(dest_label, 44, "Inverted %s", label); 4237*18dcd304SDavid Henningsson return 1; 4238*18dcd304SDavid Henningsson } 4239*18dcd304SDavid Henningsson return 0; 4240*18dcd304SDavid Henningsson } 4241*18dcd304SDavid Henningsson 42426764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 42436764bcefSTakashi Iwai const char *label, const char *pfx, 42446764bcefSTakashi Iwai int cidx) 42456764bcefSTakashi Iwai { 42466764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 42476764bcefSTakashi Iwai int i; 42486764bcefSTakashi Iwai 42496764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 4250*18dcd304SDavid Henningsson char rightch_label[44]; 42516764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 42525c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 42536764bcefSTakashi Iwai if (idx < 0) 42546764bcefSTakashi Iwai continue; 42556b452142STakashi Iwai if (spec->single_adc_amp) 42566b452142STakashi Iwai idx = 0; 4257*18dcd304SDavid Henningsson 4258*18dcd304SDavid Henningsson if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4259*18dcd304SDavid Henningsson /* Make two independent kcontrols for left and right */ 4260*18dcd304SDavid Henningsson int err = cx_auto_add_volume_idx(codec, label, pfx, 4261*18dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 1); 4262*18dcd304SDavid Henningsson if (err < 0) 4263*18dcd304SDavid Henningsson return err; 4264*18dcd304SDavid Henningsson return cx_auto_add_volume_idx(codec, rightch_label, pfx, 4265*18dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 2); 4266*18dcd304SDavid Henningsson } 42676764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 4268*18dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 3); 42696764bcefSTakashi Iwai } 42706764bcefSTakashi Iwai return 0; 42716764bcefSTakashi Iwai } 42726764bcefSTakashi Iwai 4273cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4274cf27f29aSTakashi Iwai const char *label, int cidx) 4275cf27f29aSTakashi Iwai { 4276cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4277cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4278f9759301STakashi Iwai int i, con; 4279cf27f29aSTakashi Iwai 428047ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4281*18dcd304SDavid Henningsson if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 4282*18dcd304SDavid Henningsson char rightch_label[44]; 4283*18dcd304SDavid Henningsson if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 4284*18dcd304SDavid Henningsson int err = cx_auto_add_volume_idx(codec, label, " Boost", 4285*18dcd304SDavid Henningsson cidx, nid, HDA_INPUT, 0, 1); 4286*18dcd304SDavid Henningsson if (err < 0) 4287*18dcd304SDavid Henningsson return err; 4288*18dcd304SDavid Henningsson return cx_auto_add_volume_idx(codec, rightch_label, " Boost", 4289*18dcd304SDavid Henningsson cidx, nid, HDA_INPUT, 0, 2); 4290*18dcd304SDavid Henningsson } 4291cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4292cf27f29aSTakashi Iwai nid, HDA_INPUT); 4293*18dcd304SDavid Henningsson } 429447ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 429547ad1f4eSTakashi Iwai &mux, false, 0); 4296cf27f29aSTakashi Iwai if (con < 0) 4297cf27f29aSTakashi Iwai return 0; 4298f9759301STakashi Iwai for (i = 0; i < idx; i++) { 429947ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4300f9759301STakashi Iwai return 0; /* already present */ 4301f9759301STakashi Iwai } 4302f9759301STakashi Iwai 4303f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 430447ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4305cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4306cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4307f9759301STakashi Iwai } 4308cf27f29aSTakashi Iwai return 0; 4309cf27f29aSTakashi Iwai } 4310cf27f29aSTakashi Iwai 4311f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4312f2e5731dSTakashi Iwai { 4313f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4314cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4315cf27f29aSTakashi Iwai const char *prev_label; 4316cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 43176b452142STakashi Iwai int i, j, err, cidx; 4318cf27f29aSTakashi Iwai int multi_connection; 4319cf27f29aSTakashi Iwai 43206b452142STakashi Iwai if (!imux->num_items) 43216b452142STakashi Iwai return 0; 43226b452142STakashi Iwai 4323cf27f29aSTakashi Iwai multi_connection = 0; 4324cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 432547ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 432647ad1f4eSTakashi Iwai spec->imux_info[i].pin); 43276b452142STakashi Iwai if (cidx < 0) 43286b452142STakashi Iwai continue; 43296b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 43306b452142STakashi Iwai if (!spec->single_adc_amp) 43316b452142STakashi Iwai input_conn[i] |= cidx << 8; 4332cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4333cf27f29aSTakashi Iwai multi_connection = 1; 4334cf27f29aSTakashi Iwai } 4335983345e5SDavid Henningsson 4336f2e5731dSTakashi Iwai prev_label = NULL; 4337f2e5731dSTakashi Iwai cidx = 0; 4338cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 433947ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4340f2e5731dSTakashi Iwai const char *label; 4341983345e5SDavid Henningsson 4342cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 434347ad1f4eSTakashi Iwai spec->imux_info[i].index); 4344f2e5731dSTakashi Iwai if (label == prev_label) 4345f2e5731dSTakashi Iwai cidx++; 4346f2e5731dSTakashi Iwai else 4347f2e5731dSTakashi Iwai cidx = 0; 4348f2e5731dSTakashi Iwai prev_label = label; 4349983345e5SDavid Henningsson 4350cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4351f2e5731dSTakashi Iwai if (err < 0) 4352f2e5731dSTakashi Iwai return err; 4353983345e5SDavid Henningsson 4354cf27f29aSTakashi Iwai if (!multi_connection) { 4355f9759301STakashi Iwai if (i > 0) 4356f9759301STakashi Iwai continue; 43576764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43586764bcefSTakashi Iwai "Capture", "", cidx); 43596764bcefSTakashi Iwai } else { 43606b452142STakashi Iwai bool dup_found = false; 43616b452142STakashi Iwai for (j = 0; j < i; j++) { 43626b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 43636b452142STakashi Iwai dup_found = true; 43646b452142STakashi Iwai break; 43656b452142STakashi Iwai } 43666b452142STakashi Iwai } 43676b452142STakashi Iwai if (dup_found) 43686b452142STakashi Iwai continue; 43696764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43706764bcefSTakashi Iwai label, " Capture", cidx); 43716764bcefSTakashi Iwai } 4372983345e5SDavid Henningsson if (err < 0) 4373983345e5SDavid Henningsson return err; 4374983345e5SDavid Henningsson } 43756764bcefSTakashi Iwai 43766764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 43776764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 43786764bcefSTakashi Iwai if (err < 0) 43796764bcefSTakashi Iwai return err; 4380983345e5SDavid Henningsson } 43816764bcefSTakashi Iwai 4382f2e5731dSTakashi Iwai return 0; 4383f2e5731dSTakashi Iwai } 4384f2e5731dSTakashi Iwai 4385f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4386f2e5731dSTakashi Iwai { 438731ef2257STakashi Iwai struct conexant_spec *spec = codec->spec; 4388f2e5731dSTakashi Iwai int err; 4389f2e5731dSTakashi Iwai 4390f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4391f2e5731dSTakashi Iwai if (err < 0) 4392f2e5731dSTakashi Iwai return err; 4393f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4394f2e5731dSTakashi Iwai if (err < 0) 4395f2e5731dSTakashi Iwai return err; 439631ef2257STakashi Iwai err = conexant_build_controls(codec); 439731ef2257STakashi Iwai if (err < 0) 439831ef2257STakashi Iwai return err; 439931ef2257STakashi Iwai err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 440031ef2257STakashi Iwai if (err < 0) 440131ef2257STakashi Iwai return err; 4402f29735cbSTakashi Iwai if (spec->vmaster_mute.sw_kctl) { 4403f29735cbSTakashi Iwai spec->vmaster_mute.hook = cx_auto_vmaster_hook; 4404f29735cbSTakashi Iwai err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4405f29735cbSTakashi Iwai spec->vmaster_mute_led); 4406d2f344b5STakashi Iwai if (err < 0) 4407d2f344b5STakashi Iwai return err; 4408527c73baSTakashi Iwai } 440931ef2257STakashi Iwai return 0; 4410f2e5731dSTakashi Iwai } 4411f2e5731dSTakashi Iwai 441222ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 441322ce5f74STakashi Iwai { 441422ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 441522ce5f74STakashi Iwai hda_nid_t nid, end_nid; 441622ce5f74STakashi Iwai 441722ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 441822ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 441922ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 442022ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 442122ce5f74STakashi Iwai continue; 442222ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 442322ce5f74STakashi Iwai continue; 442422ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 442522ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 442622ce5f74STakashi Iwai break; 442722ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 442822ce5f74STakashi Iwai } 442922ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 443022ce5f74STakashi Iwai return 0; 443122ce5f74STakashi Iwai } 443222ce5f74STakashi Iwai 443334cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4434f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4435f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4436f2e5731dSTakashi Iwai .init = cx_auto_init, 4437f2e5731dSTakashi Iwai .free = conexant_free, 4438f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4439f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4440f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4441f2e5731dSTakashi Iwai #endif 4442f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4443f2e5731dSTakashi Iwai }; 4444f2e5731dSTakashi Iwai 4445e92d4b08STakashi Iwai /* 4446e92d4b08STakashi Iwai * pin fix-up 4447e92d4b08STakashi Iwai */ 4448e92d4b08STakashi Iwai struct cxt_pincfg { 4449e92d4b08STakashi Iwai hda_nid_t nid; 4450e92d4b08STakashi Iwai u32 val; 4451e92d4b08STakashi Iwai }; 4452e92d4b08STakashi Iwai 4453e92d4b08STakashi Iwai static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4454e92d4b08STakashi Iwai { 4455e92d4b08STakashi Iwai for (; cfg->nid; cfg++) 4456e92d4b08STakashi Iwai snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4457e92d4b08STakashi Iwai 4458e92d4b08STakashi Iwai } 4459e92d4b08STakashi Iwai 4460*18dcd304SDavid Henningsson enum { 4461*18dcd304SDavid Henningsson CXT_PINCFG_LENOVO_X200, 4462*18dcd304SDavid Henningsson CXT_FIXUP_STEREO_DMIC, 4463*18dcd304SDavid Henningsson }; 4464*18dcd304SDavid Henningsson 4465*18dcd304SDavid Henningsson static void apply_fixup(struct hda_codec *codec, 4466e92d4b08STakashi Iwai const struct snd_pci_quirk *quirk, 4467e92d4b08STakashi Iwai const struct cxt_pincfg **table) 4468e92d4b08STakashi Iwai { 4469*18dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 4470*18dcd304SDavid Henningsson 4471e92d4b08STakashi Iwai quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 4472*18dcd304SDavid Henningsson if (quirk && table[quirk->value]) { 4473e92d4b08STakashi Iwai snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4474e92d4b08STakashi Iwai quirk->name); 4475e92d4b08STakashi Iwai apply_pincfg(codec, table[quirk->value]); 4476e92d4b08STakashi Iwai } 4477*18dcd304SDavid Henningsson if (quirk->value == CXT_FIXUP_STEREO_DMIC) { 4478*18dcd304SDavid Henningsson snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n", 4479*18dcd304SDavid Henningsson quirk->name); 4480*18dcd304SDavid Henningsson spec->fixup_stereo_dmic = 1; 4481e92d4b08STakashi Iwai } 4482*18dcd304SDavid Henningsson } 4483e92d4b08STakashi Iwai 4484e92d4b08STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4485e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4486e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 4487e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 44883e93f5efSTakashi Iwai { 0x1c, 0x21440100 }, /* dock SPDIF out */ 4489e92d4b08STakashi Iwai {} 4490e92d4b08STakashi Iwai }; 4491e92d4b08STakashi Iwai 4492e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4493e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4494*18dcd304SDavid Henningsson [CXT_FIXUP_STEREO_DMIC] = NULL, 4495e92d4b08STakashi Iwai }; 4496e92d4b08STakashi Iwai 4497e92d4b08STakashi Iwai static const struct snd_pci_quirk cxt_fixups[] = { 4498e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4499*18dcd304SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 4500e92d4b08STakashi Iwai {} 4501e92d4b08STakashi Iwai }; 4502e92d4b08STakashi Iwai 45033868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 45043868137eSTakashi Iwai * can be created (bko#42825) 45053868137eSTakashi Iwai */ 45063868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec) 45073868137eSTakashi Iwai { 45083868137eSTakashi Iwai static hda_nid_t out_nids[] = { 45093868137eSTakashi Iwai 0x10, 0x11, 0 45103868137eSTakashi Iwai }; 45113868137eSTakashi Iwai hda_nid_t *p; 45123868137eSTakashi Iwai 45133868137eSTakashi Iwai for (p = out_nids; *p; p++) 45143868137eSTakashi Iwai snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 45153868137eSTakashi Iwai AC_AMPCAP_MIN_MUTE | 45163868137eSTakashi Iwai query_amp_caps(codec, *p, HDA_OUTPUT)); 45173868137eSTakashi Iwai } 45183868137eSTakashi Iwai 4519f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4520f2e5731dSTakashi Iwai { 4521f2e5731dSTakashi Iwai struct conexant_spec *spec; 4522f2e5731dSTakashi Iwai int err; 4523f2e5731dSTakashi Iwai 45241f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 45251f8458a2STakashi Iwai codec->chip_name); 45261f8458a2STakashi Iwai 4527f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4528f2e5731dSTakashi Iwai if (!spec) 4529f2e5731dSTakashi Iwai return -ENOMEM; 4530f2e5731dSTakashi Iwai codec->spec = spec; 45311387cde5STakashi Iwai codec->pin_amp_workaround = 1; 4532e92d4b08STakashi Iwai 45336b452142STakashi Iwai switch (codec->vendor_id) { 45346b452142STakashi Iwai case 0x14f15045: 45356b452142STakashi Iwai spec->single_adc_amp = 1; 45366b452142STakashi Iwai break; 45373868137eSTakashi Iwai case 0x14f15051: 45383868137eSTakashi Iwai add_cx5051_fake_mutes(codec); 45393868137eSTakashi Iwai break; 45406b452142STakashi Iwai } 45416b452142STakashi Iwai 4542*18dcd304SDavid Henningsson apply_fixup(codec, cxt_fixups, cxt_pincfg_tbl); 4543e92d4b08STakashi Iwai 4544f29735cbSTakashi Iwai /* Show mute-led control only on HP laptops 4545f29735cbSTakashi Iwai * This is a sort of white-list: on HP laptops, EAPD corresponds 4546f29735cbSTakashi Iwai * only to the mute-LED without actualy amp function. Meanwhile, 4547f29735cbSTakashi Iwai * others may use EAPD really as an amp switch, so it might be 4548f29735cbSTakashi Iwai * not good to expose it blindly. 4549527c73baSTakashi Iwai */ 4550f29735cbSTakashi Iwai switch (codec->subsystem_id >> 16) { 4551f29735cbSTakashi Iwai case 0x103c: 4552f29735cbSTakashi Iwai spec->vmaster_mute_led = 1; 4553f29735cbSTakashi Iwai break; 4554f29735cbSTakashi Iwai } 4555527c73baSTakashi Iwai 455622ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 455722ce5f74STakashi Iwai if (err < 0) 455822ce5f74STakashi Iwai return err; 4559f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4560f2e5731dSTakashi Iwai if (err < 0) { 4561f2e5731dSTakashi Iwai kfree(codec->spec); 4562f2e5731dSTakashi Iwai codec->spec = NULL; 4563f2e5731dSTakashi Iwai return err; 4564f2e5731dSTakashi Iwai } 45656764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4566f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4567f2e5731dSTakashi Iwai if (spec->beep_amp) 4568f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 45694f2864a4STakashi Iwai 45704f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 45714f2864a4STakashi Iwai * which falls into the single-cmd mode. 45724f2864a4STakashi Iwai * Better to make reset, then. 45734f2864a4STakashi Iwai */ 45744f2864a4STakashi Iwai if (!codec->bus->sync_write) { 45754f2864a4STakashi Iwai snd_printd("hda_codec: " 45764f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 45774f2864a4STakashi Iwai codec->bus->sync_write = 1; 45784f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 45794f2864a4STakashi Iwai } 45804f2864a4STakashi Iwai 4581f2e5731dSTakashi Iwai return 0; 4582f2e5731dSTakashi Iwai } 4583f2e5731dSTakashi Iwai 4584f2e5731dSTakashi Iwai /* 4585461e2c78STakashi Iwai */ 4586461e2c78STakashi Iwai 458734cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 458882f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 458982f30040STobin Davis .patch = patch_cxt5045 }, 459082f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 459182f30040STobin Davis .patch = patch_cxt5047 }, 4592461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4593461e2c78STakashi Iwai .patch = patch_cxt5051 }, 45940fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 45950fb67e98SDaniel Drake .patch = patch_cxt5066 }, 459695a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 459795a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4598850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4599850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 46007b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 46017b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4602f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4603f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 46046da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 46056da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4606f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4607f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4608f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4609f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4610f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4611f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4612f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4613f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4614f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4615f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4616f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4617f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4618f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4619f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4620f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4621f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4622c9b443d4STobin Davis {} /* terminator */ 4623c9b443d4STobin Davis }; 46241289e9e8STakashi Iwai 46251289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 46261289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 46271289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 46280fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 462995a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4630850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 46317b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4632f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 46336da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4634f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4635f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4636f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4637f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4638f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4639f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4640f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4641f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 46421289e9e8STakashi Iwai 46431289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 46441289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 46451289e9e8STakashi Iwai 46461289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 46471289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 46481289e9e8STakashi Iwai .owner = THIS_MODULE, 46491289e9e8STakashi Iwai }; 46501289e9e8STakashi Iwai 46511289e9e8STakashi Iwai static int __init patch_conexant_init(void) 46521289e9e8STakashi Iwai { 46531289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 46541289e9e8STakashi Iwai } 46551289e9e8STakashi Iwai 46561289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 46571289e9e8STakashi Iwai { 46581289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 46591289e9e8STakashi Iwai } 46601289e9e8STakashi Iwai 46611289e9e8STakashi Iwai module_init(patch_conexant_init) 46621289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4663