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; 14418dcd304SDavid Henningsson unsigned int fixup_stereo_dmic:1; 14575f8991dSDaniel Drake 1466764bcefSTakashi Iwai unsigned int adc_switching:1; 1476764bcefSTakashi Iwai 14875f8991dSDaniel Drake unsigned int ext_mic_present; 14975f8991dSDaniel Drake unsigned int recording; 15075f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 15175f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 152c4cfe66cSDaniel Drake 153c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 154c4cfe66cSDaniel Drake * through the microphone jack. 155c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 156c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 157c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 158c4cfe66cSDaniel Drake * control. */ 159c4cfe66cSDaniel Drake unsigned int dc_enable; 160c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 161c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1623507e2a8STakashi Iwai 1633507e2a8STakashi Iwai unsigned int beep_amp; 16419110595STakashi Iwai 16519110595STakashi Iwai /* extra EAPD pins */ 16619110595STakashi Iwai unsigned int num_eapds; 16719110595STakashi Iwai hda_nid_t eapds[4]; 168c9b443d4STobin Davis }; 169c9b443d4STobin Davis 170c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 171c9b443d4STobin Davis struct hda_codec *codec, 172c9b443d4STobin Davis struct snd_pcm_substream *substream) 173c9b443d4STobin Davis { 174c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1759a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1769a08160bSTakashi Iwai hinfo); 177c9b443d4STobin Davis } 178c9b443d4STobin Davis 179c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 180c9b443d4STobin Davis struct hda_codec *codec, 181c9b443d4STobin Davis unsigned int stream_tag, 182c9b443d4STobin Davis unsigned int format, 183c9b443d4STobin Davis struct snd_pcm_substream *substream) 184c9b443d4STobin Davis { 185c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 186c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 187c9b443d4STobin Davis stream_tag, 188c9b443d4STobin Davis format, substream); 189c9b443d4STobin Davis } 190c9b443d4STobin Davis 191c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 192c9b443d4STobin Davis struct hda_codec *codec, 193c9b443d4STobin Davis struct snd_pcm_substream *substream) 194c9b443d4STobin Davis { 195c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 196c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 197c9b443d4STobin Davis } 198c9b443d4STobin Davis 199c9b443d4STobin Davis /* 200c9b443d4STobin Davis * Digital out 201c9b443d4STobin Davis */ 202c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 203c9b443d4STobin Davis struct hda_codec *codec, 204c9b443d4STobin Davis struct snd_pcm_substream *substream) 205c9b443d4STobin Davis { 206c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 207c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 208c9b443d4STobin Davis } 209c9b443d4STobin Davis 210c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 211c9b443d4STobin Davis struct hda_codec *codec, 212c9b443d4STobin Davis struct snd_pcm_substream *substream) 213c9b443d4STobin Davis { 214c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 215c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 216c9b443d4STobin Davis } 217c9b443d4STobin Davis 2186b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2196b97eb45STakashi Iwai struct hda_codec *codec, 2206b97eb45STakashi Iwai unsigned int stream_tag, 2216b97eb45STakashi Iwai unsigned int format, 2226b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2236b97eb45STakashi Iwai { 2246b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2256b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2266b97eb45STakashi Iwai stream_tag, 2276b97eb45STakashi Iwai format, substream); 2286b97eb45STakashi Iwai } 2296b97eb45STakashi Iwai 230c9b443d4STobin Davis /* 231c9b443d4STobin Davis * Analog capture 232c9b443d4STobin Davis */ 233c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 234c9b443d4STobin Davis struct hda_codec *codec, 235c9b443d4STobin Davis unsigned int stream_tag, 236c9b443d4STobin Davis unsigned int format, 237c9b443d4STobin Davis struct snd_pcm_substream *substream) 238c9b443d4STobin Davis { 239c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 24075f8991dSDaniel Drake if (spec->capture_prepare) 24175f8991dSDaniel Drake spec->capture_prepare(codec); 242c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 243c9b443d4STobin Davis stream_tag, 0, format); 244c9b443d4STobin Davis return 0; 245c9b443d4STobin Davis } 246c9b443d4STobin Davis 247c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 248c9b443d4STobin Davis struct hda_codec *codec, 249c9b443d4STobin Davis struct snd_pcm_substream *substream) 250c9b443d4STobin Davis { 251c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 252888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 25375f8991dSDaniel Drake if (spec->capture_cleanup) 25475f8991dSDaniel Drake spec->capture_cleanup(codec); 255c9b443d4STobin Davis return 0; 256c9b443d4STobin Davis } 257c9b443d4STobin Davis 258c9b443d4STobin Davis 259c9b443d4STobin Davis 26034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 261c9b443d4STobin Davis .substreams = 1, 262c9b443d4STobin Davis .channels_min = 2, 263c9b443d4STobin Davis .channels_max = 2, 264c9b443d4STobin Davis .nid = 0, /* fill later */ 265c9b443d4STobin Davis .ops = { 266c9b443d4STobin Davis .open = conexant_playback_pcm_open, 267c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 268c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 269c9b443d4STobin Davis }, 270c9b443d4STobin Davis }; 271c9b443d4STobin Davis 27234cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 273c9b443d4STobin Davis .substreams = 1, 274c9b443d4STobin Davis .channels_min = 2, 275c9b443d4STobin Davis .channels_max = 2, 276c9b443d4STobin Davis .nid = 0, /* fill later */ 277c9b443d4STobin Davis .ops = { 278c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 279c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 280c9b443d4STobin Davis }, 281c9b443d4STobin Davis }; 282c9b443d4STobin Davis 283c9b443d4STobin Davis 28434cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 285c9b443d4STobin Davis .substreams = 1, 286c9b443d4STobin Davis .channels_min = 2, 287c9b443d4STobin Davis .channels_max = 2, 288c9b443d4STobin Davis .nid = 0, /* fill later */ 289c9b443d4STobin Davis .ops = { 290c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2916b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2926b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 293c9b443d4STobin Davis }, 294c9b443d4STobin Davis }; 295c9b443d4STobin Davis 29634cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 297c9b443d4STobin Davis .substreams = 1, 298c9b443d4STobin Davis .channels_min = 2, 299c9b443d4STobin Davis .channels_max = 2, 300c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 301c9b443d4STobin Davis }; 302c9b443d4STobin Davis 303461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 304461e2c78STakashi Iwai struct hda_codec *codec, 305461e2c78STakashi Iwai unsigned int stream_tag, 306461e2c78STakashi Iwai unsigned int format, 307461e2c78STakashi Iwai struct snd_pcm_substream *substream) 308461e2c78STakashi Iwai { 309461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 310461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 311461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 312461e2c78STakashi Iwai spec->cur_adc_format = format; 313461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 314461e2c78STakashi Iwai return 0; 315461e2c78STakashi Iwai } 316461e2c78STakashi Iwai 317461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 318461e2c78STakashi Iwai struct hda_codec *codec, 319461e2c78STakashi Iwai struct snd_pcm_substream *substream) 320461e2c78STakashi Iwai { 321461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 322888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 323461e2c78STakashi Iwai spec->cur_adc = 0; 324461e2c78STakashi Iwai return 0; 325461e2c78STakashi Iwai } 326461e2c78STakashi Iwai 32734cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 328461e2c78STakashi Iwai .substreams = 1, 329461e2c78STakashi Iwai .channels_min = 2, 330461e2c78STakashi Iwai .channels_max = 2, 331461e2c78STakashi Iwai .nid = 0, /* fill later */ 332461e2c78STakashi Iwai .ops = { 333461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 334461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 335461e2c78STakashi Iwai }, 336461e2c78STakashi Iwai }; 337461e2c78STakashi Iwai 338c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 339c9b443d4STobin Davis { 340c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 341c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 342c9b443d4STobin Davis 343c9b443d4STobin Davis codec->num_pcms = 1; 344c9b443d4STobin Davis codec->pcm_info = info; 345c9b443d4STobin Davis 346c9b443d4STobin Davis info->name = "CONEXANT Analog"; 347c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 348c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 349c9b443d4STobin Davis spec->multiout.max_channels; 350c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 351c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3526764bcefSTakashi Iwai if (spec->capture_stream) 3536764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3546764bcefSTakashi Iwai else { 355461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 356461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 357461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3586764bcefSTakashi Iwai else { 359461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 360461e2c78STakashi Iwai conexant_pcm_analog_capture; 3616764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3626764bcefSTakashi Iwai spec->num_adc_nids; 3636764bcefSTakashi Iwai } 3646764bcefSTakashi Iwai } 365c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 366c9b443d4STobin Davis 367c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 368c9b443d4STobin Davis info++; 369c9b443d4STobin Davis codec->num_pcms++; 370c9b443d4STobin Davis info->name = "Conexant Digital"; 3717ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 372c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 373c9b443d4STobin Davis conexant_pcm_digital_playback; 374c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 375c9b443d4STobin Davis spec->multiout.dig_out_nid; 376c9b443d4STobin Davis if (spec->dig_in_nid) { 377c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 378c9b443d4STobin Davis conexant_pcm_digital_capture; 379c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 380c9b443d4STobin Davis spec->dig_in_nid; 381c9b443d4STobin Davis } 382f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 383f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 384c9b443d4STobin Davis } 385c9b443d4STobin Davis 386c9b443d4STobin Davis return 0; 387c9b443d4STobin Davis } 388c9b443d4STobin Davis 389c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 390c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 391c9b443d4STobin Davis { 392c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 393c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 394c9b443d4STobin Davis 395c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 396c9b443d4STobin Davis } 397c9b443d4STobin Davis 398c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 399c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 400c9b443d4STobin Davis { 401c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 402c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 403c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 404c9b443d4STobin Davis 405c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 406c9b443d4STobin Davis return 0; 407c9b443d4STobin Davis } 408c9b443d4STobin Davis 409c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 410c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 411c9b443d4STobin Davis { 412c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 413c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 414c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 415c9b443d4STobin Davis 416c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 417c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 418c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 419c9b443d4STobin Davis } 420c9b443d4STobin Davis 4214d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 4224d7fbdbcSTakashi Iwai unsigned int power_state) 4234d7fbdbcSTakashi Iwai { 4244d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 4254d7fbdbcSTakashi Iwai msleep(100); 4264d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 4274d7fbdbcSTakashi Iwai power_state); 4284d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 4294d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 4304d7fbdbcSTakashi Iwai msleep(10); 4314d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 4324d7fbdbcSTakashi Iwai } 4334d7fbdbcSTakashi Iwai 434c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 435c9b443d4STobin Davis { 436c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 437c9b443d4STobin Davis int i; 438c9b443d4STobin Davis 439c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 440c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 441c9b443d4STobin Davis return 0; 442c9b443d4STobin Davis } 443c9b443d4STobin Davis 444c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 445c9b443d4STobin Davis { 446c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 447c9b443d4STobin Davis kfree(codec->spec); 448c9b443d4STobin Davis } 449c9b443d4STobin Davis 45034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 451b880c74aSTakashi Iwai { 452b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 453b880c74aSTakashi Iwai .name = "Capture Source", 454b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 455b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 456b880c74aSTakashi Iwai .put = conexant_mux_enum_put 457b880c74aSTakashi Iwai }, 458b880c74aSTakashi Iwai {} 459b880c74aSTakashi Iwai }; 460b880c74aSTakashi Iwai 4613507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4623507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 46334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4643507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4653507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4663507e2a8STakashi Iwai { } /* end */ 4673507e2a8STakashi Iwai }; 4683507e2a8STakashi Iwai #endif 4693507e2a8STakashi Iwai 4709322ca54STakashi Iwai static const char * const slave_pfxs[] = { 4719322ca54STakashi Iwai "Headphone", "Speaker", "Front", "Surround", "CLFE", 472dd5746a8STakashi Iwai NULL 473dd5746a8STakashi Iwai }; 474dd5746a8STakashi Iwai 475c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 476c9b443d4STobin Davis { 477c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 478c9b443d4STobin Davis unsigned int i; 479c9b443d4STobin Davis int err; 480c9b443d4STobin Davis 481c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 482c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 483c9b443d4STobin Davis if (err < 0) 484c9b443d4STobin Davis return err; 485c9b443d4STobin Davis } 486c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 487c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 48874b654c9SStephen Warren spec->multiout.dig_out_nid, 489c9b443d4STobin Davis spec->multiout.dig_out_nid); 490c9b443d4STobin Davis if (err < 0) 491c9b443d4STobin Davis return err; 4929a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 4939a08160bSTakashi Iwai &spec->multiout); 4949a08160bSTakashi Iwai if (err < 0) 4959a08160bSTakashi Iwai return err; 4969a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 497c9b443d4STobin Davis } 498c9b443d4STobin Davis if (spec->dig_in_nid) { 499c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 500c9b443d4STobin Davis if (err < 0) 501c9b443d4STobin Davis return err; 502c9b443d4STobin Davis } 503dd5746a8STakashi Iwai 504dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 505dd5746a8STakashi Iwai if (spec->vmaster_nid && 506dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 507dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 508dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 509dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 510dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 5119322ca54STakashi Iwai vmaster_tlv, slave_pfxs, 5129322ca54STakashi Iwai "Playback Volume"); 513dd5746a8STakashi Iwai if (err < 0) 514dd5746a8STakashi Iwai return err; 515dd5746a8STakashi Iwai } 516dd5746a8STakashi Iwai if (spec->vmaster_nid && 517dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 518527c73baSTakashi Iwai err = __snd_hda_add_vmaster(codec, "Master Playback Switch", 5199322ca54STakashi Iwai NULL, slave_pfxs, 520527c73baSTakashi Iwai "Playback Switch", true, 521d2f344b5STakashi Iwai &spec->vmaster_mute.sw_kctl); 522dd5746a8STakashi Iwai if (err < 0) 523dd5746a8STakashi Iwai return err; 524dd5746a8STakashi Iwai } 525dd5746a8STakashi Iwai 526b880c74aSTakashi Iwai if (spec->input_mux) { 527b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 528b880c74aSTakashi Iwai if (err < 0) 529b880c74aSTakashi Iwai return err; 530b880c74aSTakashi Iwai } 531b880c74aSTakashi Iwai 5323507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5333507e2a8STakashi Iwai /* create beep controls if needed */ 5343507e2a8STakashi Iwai if (spec->beep_amp) { 53534cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5363507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5373507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5383507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5393507e2a8STakashi Iwai if (!kctl) 5403507e2a8STakashi Iwai return -ENOMEM; 5413507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5423507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5433507e2a8STakashi Iwai if (err < 0) 5443507e2a8STakashi Iwai return err; 5453507e2a8STakashi Iwai } 5463507e2a8STakashi Iwai } 5473507e2a8STakashi Iwai #endif 5483507e2a8STakashi Iwai 549c9b443d4STobin Davis return 0; 550c9b443d4STobin Davis } 551c9b443d4STobin Davis 552697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 553697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 554697c373eSTakashi Iwai { 555697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 556697c373eSTakashi Iwai return 0; 557697c373eSTakashi Iwai } 558697c373eSTakashi Iwai #endif 559697c373eSTakashi Iwai 56034cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 561c9b443d4STobin Davis .build_controls = conexant_build_controls, 562c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 563c9b443d4STobin Davis .init = conexant_init, 564c9b443d4STobin Davis .free = conexant_free, 5654d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 566697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 567697c373eSTakashi Iwai .suspend = conexant_suspend, 568697c373eSTakashi Iwai #endif 569697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 570c9b443d4STobin Davis }; 571c9b443d4STobin Davis 5723507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5733507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5743507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5753507e2a8STakashi Iwai #else 5763507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5773507e2a8STakashi Iwai #endif 5783507e2a8STakashi Iwai 5796764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 580c9b443d4STobin Davis /* 581c9b443d4STobin Davis * EAPD control 582c9b443d4STobin Davis * the private value = nid | (invert << 8) 583c9b443d4STobin Davis */ 584c9b443d4STobin Davis 585a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 586c9b443d4STobin Davis 58782f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 588c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 589c9b443d4STobin Davis { 590c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 591c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 592c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 593c9b443d4STobin Davis if (invert) 594c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 595c9b443d4STobin Davis else 596c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 597c9b443d4STobin Davis return 0; 59882f30040STobin Davis 599c9b443d4STobin Davis } 600c9b443d4STobin Davis 60182f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 602c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 603c9b443d4STobin Davis { 604c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 605c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 606c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 607c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 608c9b443d4STobin Davis unsigned int eapd; 60982f30040STobin Davis 61068ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 611c9b443d4STobin Davis if (invert) 612c9b443d4STobin Davis eapd = !eapd; 61382beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 614c9b443d4STobin Davis return 0; 61582f30040STobin Davis 616c9b443d4STobin Davis spec->cur_eapd = eapd; 61782beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 618c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 619c9b443d4STobin Davis eapd ? 0x02 : 0x00); 620c9b443d4STobin Davis return 1; 621c9b443d4STobin Davis } 622c9b443d4STobin Davis 62386d72bdfSTakashi Iwai /* controls for test mode */ 62486d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 62586d72bdfSTakashi Iwai 62682f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 62782f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 62882f30040STobin Davis .info = cxt_eapd_info, \ 62982f30040STobin Davis .get = cxt_eapd_get, \ 63082f30040STobin Davis .put = cxt_eapd_put, \ 63182f30040STobin Davis .private_value = nid | (mask<<16) } 63282f30040STobin Davis 63382f30040STobin Davis 63482f30040STobin Davis 635c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 636c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 637c9b443d4STobin Davis { 638c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 639c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 640c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 641c9b443d4STobin Davis spec->num_channel_mode); 642c9b443d4STobin Davis } 643c9b443d4STobin Davis 644c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 645c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 646c9b443d4STobin Davis { 647c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 648c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 649c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 650c9b443d4STobin Davis spec->num_channel_mode, 651c9b443d4STobin Davis spec->multiout.max_channels); 652c9b443d4STobin Davis } 653c9b443d4STobin Davis 654c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 655c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 656c9b443d4STobin Davis { 657c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 658c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 659c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 660c9b443d4STobin Davis spec->num_channel_mode, 661c9b443d4STobin Davis &spec->multiout.max_channels); 662c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 663c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 664c9b443d4STobin Davis return err; 665c9b443d4STobin Davis } 666c9b443d4STobin Davis 667c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 668c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 669c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 670c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 671c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 672c9b443d4STobin Davis .private_value = nid | (dir<<16) } 673c9b443d4STobin Davis 67486d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 67586d72bdfSTakashi Iwai 676c9b443d4STobin Davis /* Conexant 5045 specific */ 677c9b443d4STobin Davis 67834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 67934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 68034cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 681cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 682c9b443d4STobin Davis 68334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6845cd57529STobin Davis { 2, NULL }, 6855cd57529STobin Davis }; 686c9b443d4STobin Davis 68734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 688c9b443d4STobin Davis .num_items = 2, 689c9b443d4STobin Davis .items = { 6903edbbb9eSMichael Karcher { "Internal Mic", 0x1 }, 6913edbbb9eSMichael Karcher { "Mic", 0x2 }, 692c9b443d4STobin Davis } 693c9b443d4STobin Davis }; 694c9b443d4STobin Davis 69534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 696e6e03daeSMichael Karcher .num_items = 4, 6975218c892SJiang Zhe .items = { 6983edbbb9eSMichael Karcher { "Internal Mic", 0x1 }, 6993edbbb9eSMichael Karcher { "Mic", 0x2 }, 7003edbbb9eSMichael Karcher { "Line", 0x3 }, 70122e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7025218c892SJiang Zhe } 7035218c892SJiang Zhe }; 7045218c892SJiang Zhe 70534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7062de3c232SJiang zhe .num_items = 2, 7072de3c232SJiang zhe .items = { 7083edbbb9eSMichael Karcher { "Mic", 0x1 }, 7093edbbb9eSMichael Karcher { "Internal Mic", 0x2 }, 7102de3c232SJiang zhe } 7112de3c232SJiang zhe }; 7122de3c232SJiang zhe 713c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 714c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 715c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 716c9b443d4STobin Davis { 717c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 718c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 71982f30040STobin Davis unsigned int bits; 720c9b443d4STobin Davis 72182f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 722c9b443d4STobin Davis return 0; 723c9b443d4STobin Davis 72482f30040STobin Davis /* toggle internal speakers mute depending of presence of 72582f30040STobin Davis * the headphone jack 72682f30040STobin Davis */ 72747fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 72847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 72947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7307f29673bSTobin Davis 73147fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 73247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 73347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 734c9b443d4STobin Davis return 1; 735c9b443d4STobin Davis } 736c9b443d4STobin Davis 737c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 73834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 739cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 740cca3b371STakashi Iwai .values = { 741cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 742cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 743cca3b371STakashi Iwai 0 744cca3b371STakashi Iwai }, 745cca3b371STakashi Iwai }; 746c9b443d4STobin Davis 7477f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7487f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7497f29673bSTobin Davis { 75034cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7517f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7527f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7537f29673bSTobin Davis {} 7547f29673bSTobin Davis }; 75534cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7567f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7577f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7587f29673bSTobin Davis {} 7597f29673bSTobin Davis }; 7607f29673bSTobin Davis unsigned int present; 7617f29673bSTobin Davis 762d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7637f29673bSTobin Davis if (present) 7647f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7657f29673bSTobin Davis else 7667f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7677f29673bSTobin Davis } 7687f29673bSTobin Davis 769c9b443d4STobin Davis 770c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 771c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 772c9b443d4STobin Davis { 77382f30040STobin Davis struct conexant_spec *spec = codec->spec; 774dd87da1cSTobin Davis unsigned int bits; 775c9b443d4STobin Davis 776d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 777dd87da1cSTobin Davis 77847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 77947fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 78047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 781c9b443d4STobin Davis } 782c9b443d4STobin Davis 783c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 784c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 785c9b443d4STobin Davis unsigned int res) 786c9b443d4STobin Davis { 787c9b443d4STobin Davis res >>= 26; 788c9b443d4STobin Davis switch (res) { 789c9b443d4STobin Davis case CONEXANT_HP_EVENT: 790c9b443d4STobin Davis cxt5045_hp_automute(codec); 791c9b443d4STobin Davis break; 7927f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7937f29673bSTobin Davis cxt5045_hp_automic(codec); 7947f29673bSTobin Davis break; 7957f29673bSTobin Davis 796c9b443d4STobin Davis } 797c9b443d4STobin Davis } 798c9b443d4STobin Davis 79934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 800cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 801cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 802c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 803c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 80428c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 80528c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8068607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8078607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 808cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 809c9b443d4STobin Davis { 810c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 811c9b443d4STobin Davis .name = "Master Playback Switch", 81282f30040STobin Davis .info = cxt_eapd_info, 81382f30040STobin Davis .get = cxt_eapd_get, 814c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 81582f30040STobin Davis .private_value = 0x10, 816c9b443d4STobin Davis }, 817c9b443d4STobin Davis 818c9b443d4STobin Davis {} 819c9b443d4STobin Davis }; 820c9b443d4STobin Davis 82134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 8223edbbb9eSMichael Karcher HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), 8233edbbb9eSMichael Karcher HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), 82422e14130SLukasz Marcinowski 8255218c892SJiang Zhe {} 8265218c892SJiang Zhe }; 8275218c892SJiang Zhe 82834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 829cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 830cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 8312de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8322de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 83328c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 83428c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8358607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8368607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8372de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8382de3c232SJiang zhe { 8392de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8402de3c232SJiang zhe .name = "Master Playback Switch", 8412de3c232SJiang zhe .info = cxt_eapd_info, 8422de3c232SJiang zhe .get = cxt_eapd_get, 8432de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8442de3c232SJiang zhe .private_value = 0x10, 8452de3c232SJiang zhe }, 8462de3c232SJiang zhe 8472de3c232SJiang zhe {} 8482de3c232SJiang zhe }; 8492de3c232SJiang zhe 85034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 851c9b443d4STobin Davis /* Line in, Mic */ 8524090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8537f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 854c9b443d4STobin Davis /* HP, Amp */ 855c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 856c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 85782f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 858c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 859c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 860c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 861c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 862c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 863c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 86428c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8657f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 86682f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 867c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 868c9b443d4STobin Davis /* SPDIF route: PCM */ 869cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 870c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 871c9b443d4STobin Davis /* EAPD */ 87282f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 873c9b443d4STobin Davis { } /* end */ 874c9b443d4STobin Davis }; 875c9b443d4STobin Davis 87634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 87728c4edb7SDavid Henningsson /* Internal Mic, Mic */ 8785218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8795218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8805218c892SJiang Zhe /* Line In,HP, Amp */ 8815218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8825218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8835218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 8845218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 8855218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8865218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 8875218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 8885218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 8895218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 89028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8915218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 8925218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 8935218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 8945218c892SJiang Zhe /* SPDIF route: PCM */ 895cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8965218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 8975218c892SJiang Zhe /* EAPD */ 8985218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 8995218c892SJiang Zhe { } /* end */ 9005218c892SJiang Zhe }; 9017f29673bSTobin Davis 90234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9037f29673bSTobin Davis /* pin sensing on HP jack */ 9047f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 905d3091fadSTakashi Iwai { } /* end */ 9067f29673bSTobin Davis }; 9077f29673bSTobin Davis 90834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9097f29673bSTobin Davis /* pin sensing on HP jack */ 9107f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 911d3091fadSTakashi Iwai { } /* end */ 9127f29673bSTobin Davis }; 9137f29673bSTobin Davis 914c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 915c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 916c9b443d4STobin Davis * configuration. 917c9b443d4STobin Davis */ 91834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 919c9b443d4STobin Davis .num_items = 5, 920c9b443d4STobin Davis .items = { 921c9b443d4STobin Davis { "MIXER", 0x0 }, 922c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 923c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 924c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 925c9b443d4STobin Davis { "CD pin", 0x4 }, 926c9b443d4STobin Davis }, 927c9b443d4STobin Davis }; 928c9b443d4STobin Davis 92934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 930c9b443d4STobin Davis 931c9b443d4STobin Davis /* Output controls */ 932c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 933c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 934250f3274SMichael Karcher HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT), 935250f3274SMichael Karcher HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT), 936250f3274SMichael Karcher HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 937250f3274SMichael Karcher HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 938c9b443d4STobin Davis 939c9b443d4STobin Davis /* Modes for retasking pin widgets */ 940c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 941c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 942c9b443d4STobin Davis 94382f30040STobin Davis /* EAPD Switch Control */ 94482f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 94582f30040STobin Davis 946c9b443d4STobin Davis /* Loopback mixer controls */ 947c9b443d4STobin Davis 948250f3274SMichael Karcher HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT), 949250f3274SMichael Karcher HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT), 950250f3274SMichael Karcher HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT), 951250f3274SMichael Karcher HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT), 952250f3274SMichael Karcher HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT), 953250f3274SMichael Karcher HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT), 954250f3274SMichael Karcher HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT), 955250f3274SMichael Karcher HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT), 956250f3274SMichael Karcher HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT), 957250f3274SMichael Karcher HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT), 958c9b443d4STobin Davis { 959c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 960c9b443d4STobin Davis .name = "Input Source", 961c9b443d4STobin Davis .info = conexant_mux_enum_info, 962c9b443d4STobin Davis .get = conexant_mux_enum_get, 963c9b443d4STobin Davis .put = conexant_mux_enum_put, 964c9b443d4STobin Davis }, 965fb3409e7STobin Davis /* Audio input controls */ 966cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), 967cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 968c9b443d4STobin Davis { } /* end */ 969c9b443d4STobin Davis }; 970c9b443d4STobin Davis 97134cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 9727f29673bSTobin Davis /* Set connections */ 9737f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9747f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9757f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 976c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 977c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9787f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 979c9b443d4STobin Davis 980c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 981c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 982c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 983c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 984c9b443d4STobin Davis * control. 985c9b443d4STobin Davis */ 986cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 987cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 988c9b443d4STobin Davis 989c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 990c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 991c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 992c9b443d4STobin Davis * input/output buffers as needed. 993c9b443d4STobin Davis */ 994c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 995c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 996c9b443d4STobin Davis 997c9b443d4STobin Davis /* Mute capture amp left and right */ 998c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 999c9b443d4STobin Davis 1000c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1001c9b443d4STobin Davis * pin) 1002c9b443d4STobin Davis */ 1003250f3274SMichael Karcher {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, 1004250f3274SMichael Karcher {0x17, AC_VERB_SET_CONNECT_SEL, 0x01}, 1005c9b443d4STobin Davis 1006c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1007250f3274SMichael Karcher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */ 1008c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1009c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1010c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1011c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1012c9b443d4STobin Davis 1013c9b443d4STobin Davis { } 1014c9b443d4STobin Davis }; 1015c9b443d4STobin Davis #endif 1016c9b443d4STobin Davis 1017c9b443d4STobin Davis 1018c9b443d4STobin Davis /* initialize jack-sensing, too */ 1019c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1020c9b443d4STobin Davis { 1021c9b443d4STobin Davis conexant_init(codec); 1022c9b443d4STobin Davis cxt5045_hp_automute(codec); 1023c9b443d4STobin Davis return 0; 1024c9b443d4STobin Davis } 1025c9b443d4STobin Davis 1026c9b443d4STobin Davis 1027c9b443d4STobin Davis enum { 102815908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 102915908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 103015908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10315218c892SJiang Zhe CXT5045_BENQ, 10322de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1033c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1034c9b443d4STobin Davis CXT5045_TEST, 1035c9b443d4STobin Davis #endif 10361f8458a2STakashi Iwai CXT5045_AUTO, 1037f5fcc13cSTakashi Iwai CXT5045_MODELS 1038c9b443d4STobin Davis }; 1039c9b443d4STobin Davis 1040ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 104115908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 104215908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 104315908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10445218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10452de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1046c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1047f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1048c9b443d4STobin Davis #endif 10491f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1050f5fcc13cSTakashi Iwai }; 1051c9b443d4STobin Davis 105234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10532de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 10546a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10555218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 105615908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 105715908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10589e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10599e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 106015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 106115908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 106215908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1063dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1064dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 106515908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1066c9b443d4STobin Davis {} 1067c9b443d4STobin Davis }; 1068c9b443d4STobin Davis 1069c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1070c9b443d4STobin Davis { 1071c9b443d4STobin Davis struct conexant_spec *spec; 1072c9b443d4STobin Davis int board_config; 1073c9b443d4STobin Davis 10741f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 10751f8458a2STakashi Iwai cxt5045_models, 10761f8458a2STakashi Iwai cxt5045_cfg_tbl); 10771f8458a2STakashi Iwai if (board_config < 0) 1078c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 10791f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 10801f8458a2STakashi Iwai return patch_conexant_auto(codec); 10811f8458a2STakashi Iwai 1082c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1083c9b443d4STobin Davis if (!spec) 1084c9b443d4STobin Davis return -ENOMEM; 1085c9b443d4STobin Davis codec->spec = spec; 10864f32456eSMichael Karcher codec->single_adc_amp = 1; 1087c9b443d4STobin Davis 1088c9b443d4STobin Davis spec->multiout.max_channels = 2; 1089c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1090c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1091c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1092c9b443d4STobin Davis spec->num_adc_nids = 1; 1093c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1094c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1095c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1096c9b443d4STobin Davis spec->num_mixers = 1; 1097c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1098c9b443d4STobin Davis spec->num_init_verbs = 1; 1099c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1100c9b443d4STobin Davis spec->spdif_route = 0; 11013507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11023507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11035cd57529STobin Davis 11043507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1105c9b443d4STobin Davis 1106c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1107c9b443d4STobin Davis 1108c9b443d4STobin Davis switch (board_config) { 110915908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11107f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1111c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1112c9b443d4STobin Davis spec->num_init_verbs = 2; 11137f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11147f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11157f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11167f29673bSTobin Davis break; 111715908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 111886376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11197f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11207f29673bSTobin Davis spec->num_init_verbs = 2; 11217f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1122c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1123c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1124c9b443d4STobin Davis break; 112515908c36SMarc Boucher default: 112615908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 112715908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 112815908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 112915908c36SMarc Boucher spec->num_init_verbs = 3; 113015908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 113115908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 113215908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 113315908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 113415908c36SMarc Boucher break; 11355218c892SJiang Zhe case CXT5045_BENQ: 11365218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11375218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11385218c892SJiang Zhe spec->num_init_verbs = 1; 11395218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11405218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11415218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11425218c892SJiang Zhe spec->num_mixers = 2; 11435218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11445218c892SJiang Zhe break; 11452de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11462de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11472de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11482de3c232SJiang zhe spec->num_init_verbs = 2; 11492de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11502de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11512de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11522de3c232SJiang zhe break; 1153c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1154c9b443d4STobin Davis case CXT5045_TEST: 1155c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1156c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1157c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 115815908c36SMarc Boucher break; 115915908c36SMarc Boucher 1160c9b443d4STobin Davis #endif 1161c9b443d4STobin Davis } 116248ecb7e8STakashi Iwai 1163031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1164031005f7STakashi Iwai case 0x103c: 11658f0f5ff6SDaniel T Chen case 0x1631: 11660b587fc4SDaniel T Chen case 0x1734: 11670ebf9e36SDaniel T Chen case 0x17aa: 11680ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 11690ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 11700ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 117148ecb7e8STakashi Iwai */ 117248ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 117348ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 117448ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 117548ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 117648ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1177031005f7STakashi Iwai break; 1178031005f7STakashi Iwai } 117948ecb7e8STakashi Iwai 11803507e2a8STakashi Iwai if (spec->beep_amp) 11813507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 11823507e2a8STakashi Iwai 1183c9b443d4STobin Davis return 0; 1184c9b443d4STobin Davis } 1185c9b443d4STobin Davis 1186c9b443d4STobin Davis 1187c9b443d4STobin Davis /* Conexant 5047 specific */ 118882f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1189c9b443d4STobin Davis 119034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 119134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 119234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1193c9b443d4STobin Davis 119434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 11955cd57529STobin Davis { 2, NULL }, 11965cd57529STobin Davis }; 1197c9b443d4STobin Davis 119834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 119982f30040STobin Davis .num_items = 2, 120082f30040STobin Davis .items = { 120182f30040STobin Davis { "ExtMic", 0x2 }, 120282f30040STobin Davis { "Line-In", 0x1 }, 1203c9b443d4STobin Davis } 1204c9b443d4STobin Davis }; 1205c9b443d4STobin Davis 1206c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1207c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1208c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1209c9b443d4STobin Davis { 1210c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1211c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 121282f30040STobin Davis unsigned int bits; 1213c9b443d4STobin Davis 121482f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1215c9b443d4STobin Davis return 0; 1216c9b443d4STobin Davis 121782f30040STobin Davis /* toggle internal speakers mute depending of presence of 121882f30040STobin Davis * the headphone jack 121982f30040STobin Davis */ 122047fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12213b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12223b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12233b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12243b7523fcSTakashi Iwai */ 12255d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 122647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 122747fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 122847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 122947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1230c9b443d4STobin Davis return 1; 1231c9b443d4STobin Davis } 1232c9b443d4STobin Davis 1233c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1234c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1235c9b443d4STobin Davis { 123682f30040STobin Davis struct conexant_spec *spec = codec->spec; 1237dd87da1cSTobin Davis unsigned int bits; 1238c9b443d4STobin Davis 1239d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1240dd87da1cSTobin Davis 124147fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12423b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12435d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 124447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1245c9b443d4STobin Davis } 1246c9b443d4STobin Davis 1247c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1248c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1249c9b443d4STobin Davis { 125034cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12519f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12529f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1253c9b443d4STobin Davis {} 1254c9b443d4STobin Davis }; 125534cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12569f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12579f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1258c9b443d4STobin Davis {} 1259c9b443d4STobin Davis }; 1260c9b443d4STobin Davis unsigned int present; 1261c9b443d4STobin Davis 1262d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1263c9b443d4STobin Davis if (present) 1264c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1265c9b443d4STobin Davis else 1266c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1267c9b443d4STobin Davis } 1268c9b443d4STobin Davis 1269c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1270c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1271c9b443d4STobin Davis unsigned int res) 1272c9b443d4STobin Davis { 12739f113e0eSMarc Boucher switch (res >> 26) { 1274c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1275c9b443d4STobin Davis cxt5047_hp_automute(codec); 1276c9b443d4STobin Davis break; 1277c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1278c9b443d4STobin Davis cxt5047_hp_automic(codec); 1279c9b443d4STobin Davis break; 1280c9b443d4STobin Davis } 1281c9b443d4STobin Davis } 1282c9b443d4STobin Davis 128334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1284df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1285df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 12865f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1287c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1288c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1289c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1290c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 129182f30040STobin Davis { 129282f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 129382f30040STobin Davis .name = "Master Playback Switch", 129482f30040STobin Davis .info = cxt_eapd_info, 129582f30040STobin Davis .get = cxt_eapd_get, 1296c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1297c9b443d4STobin Davis .private_value = 0x13, 1298c9b443d4STobin Davis }, 1299c9b443d4STobin Davis 1300c9b443d4STobin Davis {} 1301c9b443d4STobin Davis }; 1302c9b443d4STobin Davis 130334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13043b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13055d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1306df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1307df481e41STakashi Iwai {} 1308df481e41STakashi Iwai }; 1309df481e41STakashi Iwai 131034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1311c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1312c9b443d4STobin Davis { } /* end */ 1313c9b443d4STobin Davis }; 1314c9b443d4STobin Davis 131534cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1316c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1317c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1318c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1319c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13207f29673bSTobin Davis /* HP, Speaker */ 1321b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13225b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13235b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13247f29673bSTobin Davis /* Record selector: Mic */ 13257f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13267f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13277f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13287f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1329c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1330c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1331c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1332c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1333c9b443d4STobin Davis /* SPDIF route: PCM */ 1334c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 133582f30040STobin Davis /* Enable unsolicited events */ 133682f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 133782f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1338c9b443d4STobin Davis { } /* end */ 1339c9b443d4STobin Davis }; 1340c9b443d4STobin Davis 1341c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 134234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13433b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1344c9b443d4STobin Davis {} 1345c9b443d4STobin Davis }; 1346c9b443d4STobin Davis 1347c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1348c9b443d4STobin Davis * configuration. 1349c9b443d4STobin Davis */ 1350c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 135134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 135282f30040STobin Davis .num_items = 4, 1353c9b443d4STobin Davis .items = { 135482f30040STobin Davis { "LINE1 pin", 0x0 }, 135582f30040STobin Davis { "MIC1 pin", 0x1 }, 135682f30040STobin Davis { "MIC2 pin", 0x2 }, 135782f30040STobin Davis { "CD pin", 0x3 }, 1358c9b443d4STobin Davis }, 1359c9b443d4STobin Davis }; 1360c9b443d4STobin Davis 136134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1362c9b443d4STobin Davis 1363c9b443d4STobin Davis /* Output only controls */ 136482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 136582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 136682f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 136782f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1368c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1369c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1370c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1371c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 137282f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 137382f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 137482f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 137582f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1376c9b443d4STobin Davis 1377c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1378c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1379c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1380c9b443d4STobin Davis 138182f30040STobin Davis /* EAPD Switch Control */ 138282f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 138382f30040STobin Davis 1384c9b443d4STobin Davis /* Loopback mixer controls */ 138582f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 138682f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 138782f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 138882f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 138982f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 139082f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 139182f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 139282f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1393c9b443d4STobin Davis 139482f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 139582f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 139682f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 139782f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 139882f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 139982f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 140082f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 140182f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1402c9b443d4STobin Davis { 1403c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1404c9b443d4STobin Davis .name = "Input Source", 1405c9b443d4STobin Davis .info = conexant_mux_enum_info, 1406c9b443d4STobin Davis .get = conexant_mux_enum_get, 1407c9b443d4STobin Davis .put = conexant_mux_enum_put, 1408c9b443d4STobin Davis }, 1409854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14109f113e0eSMarc Boucher 1411c9b443d4STobin Davis { } /* end */ 1412c9b443d4STobin Davis }; 1413c9b443d4STobin Davis 141434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1415c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1416c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1417c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1418c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1419c9b443d4STobin Davis 1420c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1421c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1422c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1423c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1424c9b443d4STobin Davis * control. 1425c9b443d4STobin Davis */ 1426c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1427c9b443d4STobin Davis 1428c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1429c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1430c9b443d4STobin Davis */ 1431c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1432c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1433c9b443d4STobin Davis 1434c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1435c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1436c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1437c9b443d4STobin Davis 1438c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1439c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1440c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1441c9b443d4STobin Davis * input/output buffers as needed. 1442c9b443d4STobin Davis */ 1443c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1444c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1445c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1446c9b443d4STobin Davis 1447c9b443d4STobin Davis /* Mute capture amp left and right */ 1448c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1449c9b443d4STobin Davis 1450c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1451c9b443d4STobin Davis * pin) 1452c9b443d4STobin Davis */ 1453c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1454c9b443d4STobin Davis 1455c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1456c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1457c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1458c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1459c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1460c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1461c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1462c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1463c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1464c9b443d4STobin Davis 1465c9b443d4STobin Davis { } 1466c9b443d4STobin Davis }; 1467c9b443d4STobin Davis #endif 1468c9b443d4STobin Davis 1469c9b443d4STobin Davis 1470c9b443d4STobin Davis /* initialize jack-sensing, too */ 1471c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1472c9b443d4STobin Davis { 1473c9b443d4STobin Davis conexant_init(codec); 1474c9b443d4STobin Davis cxt5047_hp_automute(codec); 1475c9b443d4STobin Davis return 0; 1476c9b443d4STobin Davis } 1477c9b443d4STobin Davis 1478c9b443d4STobin Davis 1479c9b443d4STobin Davis enum { 1480f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1481f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1482f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1483c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1484c9b443d4STobin Davis CXT5047_TEST, 1485c9b443d4STobin Davis #endif 1486fa5dadcbSTakashi Iwai CXT5047_AUTO, 1487f5fcc13cSTakashi Iwai CXT5047_MODELS 1488c9b443d4STobin Davis }; 1489c9b443d4STobin Davis 1490ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1491f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1492f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1493f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1494c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1495f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1496c9b443d4STobin Davis #endif 1497fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1498f5fcc13cSTakashi Iwai }; 1499c9b443d4STobin Davis 150034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1501ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1502dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1503dea0a509STakashi Iwai CXT5047_LAPTOP), 1504f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1505c9b443d4STobin Davis {} 1506c9b443d4STobin Davis }; 1507c9b443d4STobin Davis 1508c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1509c9b443d4STobin Davis { 1510c9b443d4STobin Davis struct conexant_spec *spec; 1511c9b443d4STobin Davis int board_config; 1512c9b443d4STobin Davis 1513fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1514fa5dadcbSTakashi Iwai cxt5047_models, 1515fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1516fa5dadcbSTakashi Iwai if (board_config < 0) 1517c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1518fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1519fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1520fa5dadcbSTakashi Iwai 1521c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1522c9b443d4STobin Davis if (!spec) 1523c9b443d4STobin Davis return -ENOMEM; 1524c9b443d4STobin Davis codec->spec = spec; 15259421f954STakashi Iwai codec->pin_amp_workaround = 1; 1526c9b443d4STobin Davis 1527c9b443d4STobin Davis spec->multiout.max_channels = 2; 1528c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1529c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1530c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1531c9b443d4STobin Davis spec->num_adc_nids = 1; 1532c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1533c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1534c9b443d4STobin Davis spec->num_mixers = 1; 1535df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1536c9b443d4STobin Davis spec->num_init_verbs = 1; 1537c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1538c9b443d4STobin Davis spec->spdif_route = 0; 15395cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15405cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1541c9b443d4STobin Davis 1542c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1543c9b443d4STobin Davis 1544c9b443d4STobin Davis switch (board_config) { 1545c9b443d4STobin Davis case CXT5047_LAPTOP: 1546df481e41STakashi Iwai spec->num_mixers = 2; 1547df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1548df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1549c9b443d4STobin Davis break; 1550c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1551df481e41STakashi Iwai spec->num_mixers = 2; 1552df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1553fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1554c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1555c9b443d4STobin Davis break; 1556c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 155782f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1558df481e41STakashi Iwai spec->num_mixers = 2; 1559df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1560c9b443d4STobin Davis spec->num_init_verbs = 2; 1561c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1562fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1563c9b443d4STobin Davis break; 1564c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1565c9b443d4STobin Davis case CXT5047_TEST: 1566c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1567c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1568c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1569fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1570c9b443d4STobin Davis #endif 1571c9b443d4STobin Davis } 1572dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1573025f206cSDaniel T Chen 1574025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1575025f206cSDaniel T Chen case 0x103c: 1576025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1577025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1578025f206cSDaniel T Chen * with 0 dB offset 0x17) 1579025f206cSDaniel T Chen */ 1580025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1581025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1582025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1583025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1584025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1585025f206cSDaniel T Chen break; 1586025f206cSDaniel T Chen } 1587025f206cSDaniel T Chen 1588c9b443d4STobin Davis return 0; 1589c9b443d4STobin Davis } 1590c9b443d4STobin Davis 1591461e2c78STakashi Iwai /* Conexant 5051 specific */ 159234cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 159334cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1594461e2c78STakashi Iwai 159534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1596461e2c78STakashi Iwai { 2, NULL }, 1597461e2c78STakashi Iwai }; 1598461e2c78STakashi Iwai 1599461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1600461e2c78STakashi Iwai { 1601461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1602461e2c78STakashi Iwai unsigned int pinctl; 160323d2df5bSTakashi Iwai /* headphone pin */ 160423d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 1605*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x16, pinctl); 160623d2df5bSTakashi Iwai /* speaker pin */ 1607461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1608*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1a, pinctl); 1609a80581d0SJustin P. Mattock /* on ideapad there is an additional speaker (subwoofer) to mute */ 1610f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1611*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1b, pinctl); 1612461e2c78STakashi Iwai } 1613461e2c78STakashi Iwai 1614461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1615461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1616461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1617461e2c78STakashi Iwai { 1618461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1619461e2c78STakashi Iwai 1620461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1621461e2c78STakashi Iwai return 0; 1622461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1623461e2c78STakashi Iwai return 1; 1624461e2c78STakashi Iwai } 1625461e2c78STakashi Iwai 1626461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1627461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1628461e2c78STakashi Iwai { 162979d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1630461e2c78STakashi Iwai unsigned int present; 1631461e2c78STakashi Iwai 1632faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 163379d7d533STakashi Iwai return; 1634d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1635461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1636461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1637461e2c78STakashi Iwai present ? 0x01 : 0x00); 1638461e2c78STakashi Iwai } 1639461e2c78STakashi Iwai 1640461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1641461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1642461e2c78STakashi Iwai { 1643461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1644461e2c78STakashi Iwai unsigned int present; 1645461e2c78STakashi Iwai hda_nid_t new_adc; 1646461e2c78STakashi Iwai 1647faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 164879d7d533STakashi Iwai return; 1649d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1650461e2c78STakashi Iwai if (present) 1651461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1652461e2c78STakashi Iwai else 1653461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1654461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1655461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1656461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1657f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1658461e2c78STakashi Iwai spec->cur_adc = new_adc; 1659461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1660461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1661461e2c78STakashi Iwai spec->cur_adc_format); 1662461e2c78STakashi Iwai } 1663461e2c78STakashi Iwai } 1664461e2c78STakashi Iwai 1665461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1666461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1667461e2c78STakashi Iwai { 1668461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1669461e2c78STakashi Iwai 1670d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1671461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1672461e2c78STakashi Iwai } 1673461e2c78STakashi Iwai 1674461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1675461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1676461e2c78STakashi Iwai unsigned int res) 1677461e2c78STakashi Iwai { 1678461e2c78STakashi Iwai switch (res >> 26) { 1679461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1680461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1681461e2c78STakashi Iwai break; 1682461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1683461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1684461e2c78STakashi Iwai break; 1685461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1686461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1687461e2c78STakashi Iwai break; 1688461e2c78STakashi Iwai } 1689461e2c78STakashi Iwai } 1690461e2c78STakashi Iwai 169134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1692461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1693461e2c78STakashi Iwai { 1694461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1695461e2c78STakashi Iwai .name = "Master Playback Switch", 1696461e2c78STakashi Iwai .info = cxt_eapd_info, 1697461e2c78STakashi Iwai .get = cxt_eapd_get, 1698461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1699461e2c78STakashi Iwai .private_value = 0x1a, 1700461e2c78STakashi Iwai }, 17012c7a3fb3STakashi Iwai {} 17022c7a3fb3STakashi Iwai }; 1703461e2c78STakashi Iwai 170434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17052c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17062c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17078607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17088607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17092c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17102c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1711461e2c78STakashi Iwai {} 1712461e2c78STakashi Iwai }; 1713461e2c78STakashi Iwai 171434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1715461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1716461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17178607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17188607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1719461e2c78STakashi Iwai {} 1720461e2c78STakashi Iwai }; 1721461e2c78STakashi Iwai 172234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17234e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17244e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 172579d7d533STakashi Iwai {} 172679d7d533STakashi Iwai }; 172779d7d533STakashi Iwai 172834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17295f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17305f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1731cd9d95a5SKen Prox {} 1732cd9d95a5SKen Prox }; 1733cd9d95a5SKen Prox 173434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1735faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1736faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17378607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17388607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1739faddaa5dSTakashi Iwai {} 1740faddaa5dSTakashi Iwai }; 1741faddaa5dSTakashi Iwai 174234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1743461e2c78STakashi Iwai /* Line in, Mic */ 1744461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1745461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1746461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1747461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1748461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1749461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1750461e2c78STakashi Iwai /* SPK */ 1751461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1752461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1753461e2c78STakashi Iwai /* HP, Amp */ 1754461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1755461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1756461e2c78STakashi Iwai /* DAC1 */ 1757461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 175828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1759461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1760461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1761461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1762461e2c78STakashi Iwai /* SPDIF route: PCM */ 17631965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1764461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1765461e2c78STakashi Iwai /* EAPD */ 1766461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1767461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1768461e2c78STakashi Iwai { } /* end */ 1769461e2c78STakashi Iwai }; 1770461e2c78STakashi Iwai 177134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 177279d7d533STakashi Iwai /* Line in, Mic */ 177379d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 177479d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 177579d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 177679d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 177779d7d533STakashi Iwai /* SPK */ 177879d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 177979d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 178079d7d533STakashi Iwai /* HP, Amp */ 178179d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 178279d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 178379d7d533STakashi Iwai /* DAC1 */ 178479d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 178528c4edb7SDavid Henningsson /* Record selector: Internal mic */ 178679d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 178779d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 178879d7d533STakashi Iwai /* SPDIF route: PCM */ 178979d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 179079d7d533STakashi Iwai /* EAPD */ 179179d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 179279d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 179379d7d533STakashi Iwai { } /* end */ 179479d7d533STakashi Iwai }; 179579d7d533STakashi Iwai 179634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1797cd9d95a5SKen Prox /* Line in, Mic */ 179830ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1799cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1800cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1801cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1802cd9d95a5SKen Prox /* SPK */ 1803cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1804cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1805cd9d95a5SKen Prox /* HP, Amp */ 1806cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1807cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1808cd9d95a5SKen Prox /* DAC1 */ 1809cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 181028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1811cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1812cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1813cd9d95a5SKen Prox /* SPDIF route: PCM */ 1814cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1815cd9d95a5SKen Prox /* EAPD */ 1816cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1817cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1818cd9d95a5SKen Prox { } /* end */ 1819cd9d95a5SKen Prox }; 1820cd9d95a5SKen Prox 18216953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18226953e552STakashi Iwai unsigned int event) 18236953e552STakashi Iwai { 18246953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18256953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18266953e552STakashi Iwai AC_USRSP_EN | event); 18276953e552STakashi Iwai } 18286953e552STakashi Iwai 182934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1830f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1831f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1832f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1833f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1834f7154de2SHerton Ronaldo Krzesinski }; 1835f7154de2SHerton Ronaldo Krzesinski 1836461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1837461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1838461e2c78STakashi Iwai { 18396953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18406953e552STakashi Iwai 1841461e2c78STakashi Iwai conexant_init(codec); 18426953e552STakashi Iwai 18436953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18446953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18456953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18466953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18476953e552STakashi Iwai 1848461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1849461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1850461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1851461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1852461e2c78STakashi Iwai } 1853461e2c78STakashi Iwai return 0; 1854461e2c78STakashi Iwai } 1855461e2c78STakashi Iwai 1856461e2c78STakashi Iwai 1857461e2c78STakashi Iwai enum { 1858461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1859461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 186079d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1861cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1862faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1863f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 18646764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1865461e2c78STakashi Iwai CXT5051_MODELS 1866461e2c78STakashi Iwai }; 1867461e2c78STakashi Iwai 1868ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1869461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1870461e2c78STakashi Iwai [CXT5051_HP] = "hp", 187179d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 18725f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1873faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1874f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 18756764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1876461e2c78STakashi Iwai }; 1877461e2c78STakashi Iwai 187834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 187979d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 18801812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 18815f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1882faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1883461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1884461e2c78STakashi Iwai CXT5051_LAPTOP), 1885461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1886f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1887461e2c78STakashi Iwai {} 1888461e2c78STakashi Iwai }; 1889461e2c78STakashi Iwai 1890461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1891461e2c78STakashi Iwai { 1892461e2c78STakashi Iwai struct conexant_spec *spec; 1893461e2c78STakashi Iwai int board_config; 1894461e2c78STakashi Iwai 18956764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 18966764bcefSTakashi Iwai cxt5051_models, 18976764bcefSTakashi Iwai cxt5051_cfg_tbl); 18986764bcefSTakashi Iwai if (board_config < 0) 1899c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19001f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19016764bcefSTakashi Iwai return patch_conexant_auto(codec); 19026764bcefSTakashi Iwai 1903461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1904461e2c78STakashi Iwai if (!spec) 1905461e2c78STakashi Iwai return -ENOMEM; 1906461e2c78STakashi Iwai codec->spec = spec; 19079421f954STakashi Iwai codec->pin_amp_workaround = 1; 1908461e2c78STakashi Iwai 1909461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1910461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1911461e2c78STakashi Iwai 1912461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1913461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1914461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1915461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1916461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1917461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19182c7a3fb3STakashi Iwai spec->num_mixers = 2; 19192c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19202c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1921461e2c78STakashi Iwai spec->num_init_verbs = 1; 1922461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1923461e2c78STakashi Iwai spec->spdif_route = 0; 1924461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1925461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1926461e2c78STakashi Iwai spec->cur_adc = 0; 1927461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1928461e2c78STakashi Iwai 19293507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 19303507e2a8STakashi Iwai 193179d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 193279d7d533STakashi Iwai 1933faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1934461e2c78STakashi Iwai switch (board_config) { 1935461e2c78STakashi Iwai case CXT5051_HP: 1936461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1937461e2c78STakashi Iwai break; 193879d7d533STakashi Iwai case CXT5051_HP_DV6736: 193979d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 194079d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1941faddaa5dSTakashi Iwai spec->auto_mic = 0; 194279d7d533STakashi Iwai break; 1943cd9d95a5SKen Prox case CXT5051_F700: 1944cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1945cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1946faddaa5dSTakashi Iwai spec->auto_mic = 0; 1947faddaa5dSTakashi Iwai break; 1948faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1949faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1950faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1951cd9d95a5SKen Prox break; 1952f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 1953f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 1954f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 1955f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 1956f7154de2SHerton Ronaldo Krzesinski break; 1957461e2c78STakashi Iwai } 1958461e2c78STakashi Iwai 19593507e2a8STakashi Iwai if (spec->beep_amp) 19603507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 19613507e2a8STakashi Iwai 1962461e2c78STakashi Iwai return 0; 1963461e2c78STakashi Iwai } 1964461e2c78STakashi Iwai 19650fb67e98SDaniel Drake /* Conexant 5066 specific */ 19660fb67e98SDaniel Drake 196734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 196834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 196934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 197034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 19710fb67e98SDaniel Drake 1972dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 1973dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 1974dbaccc0cSDaniel Drake * the DC input range of the codec. */ 1975dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 1976dbaccc0cSDaniel Drake 197734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 19780fb67e98SDaniel Drake { 2, NULL }, 19790fb67e98SDaniel Drake }; 19800fb67e98SDaniel Drake 1981a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 1982a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 1983a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 1984a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 1985a3de8ab8STakashi Iwai 19860fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 19870fb67e98SDaniel Drake { 19880fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 19890fb67e98SDaniel Drake unsigned int pinctl; 19900fb67e98SDaniel Drake 19913a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 19923a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 19930fb67e98SDaniel Drake 19940fb67e98SDaniel Drake /* Port A (HP) */ 1995a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 1996*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x19, pinctl); 19970fb67e98SDaniel Drake 19980fb67e98SDaniel Drake /* Port D (HP/LO) */ 1999a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2000a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2001a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2002a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20033a253445SJohn Baboval pinctl = 0; 20043a253445SJohn Baboval } else { 2005a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2006a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2007a3de8ab8STakashi Iwai pinctl = 0; 20083a253445SJohn Baboval } 2009*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1c, pinctl); 20100fb67e98SDaniel Drake 20110fb67e98SDaniel Drake /* CLASS_D AMP */ 20120fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 2013*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1f, pinctl); 20140fb67e98SDaniel Drake } 20150fb67e98SDaniel Drake 20160fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20170fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20180fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20190fb67e98SDaniel Drake { 20200fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20210fb67e98SDaniel Drake 20220fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20230fb67e98SDaniel Drake return 0; 20240fb67e98SDaniel Drake 20250fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20260fb67e98SDaniel Drake return 1; 20270fb67e98SDaniel Drake } 20280fb67e98SDaniel Drake 2029c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2030c4cfe66cSDaniel Drake .num_items = 3, 2031c4cfe66cSDaniel Drake .items = { 2032c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2033c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2034c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2035c4cfe66cSDaniel Drake }, 2036c4cfe66cSDaniel Drake }; 2037c4cfe66cSDaniel Drake 2038c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2039c4cfe66cSDaniel Drake { 2040c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2041c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2042c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2043c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2044*cdd03cedSTakashi Iwai return snd_hda_set_pin_ctl_cache(codec, 0x1a, 2045c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2046c4cfe66cSDaniel Drake } 2047c4cfe66cSDaniel Drake 204875f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 204975f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 205075f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 205175f8991dSDaniel Drake * is happening when it is not. */ 205275f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20530fb67e98SDaniel Drake { 2054dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 205575f8991dSDaniel Drake if (!spec->recording) 205675f8991dSDaniel Drake return; 20570fb67e98SDaniel Drake 2058c4cfe66cSDaniel Drake if (spec->dc_enable) { 2059c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2060c4cfe66cSDaniel Drake * through our special DC port */ 2061c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2062c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2063c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2064c4cfe66cSDaniel Drake 2065c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2066c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2067c4cfe66cSDaniel Drake {}, 2068c4cfe66cSDaniel Drake }; 2069c4cfe66cSDaniel Drake 2070c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2071c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2072c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2073c4cfe66cSDaniel Drake return; 2074c4cfe66cSDaniel Drake } 2075c4cfe66cSDaniel Drake 2076c4cfe66cSDaniel Drake /* disable DC (port F) */ 2077*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1e, 0); 2078c4cfe66cSDaniel Drake 207975f8991dSDaniel Drake /* external mic, port B */ 2080*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1a, 208175f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 20820fb67e98SDaniel Drake 208375f8991dSDaniel Drake /* internal mic, port C */ 2084*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, 0x1b, 208575f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 208675f8991dSDaniel Drake } 20870fb67e98SDaniel Drake 208875f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 208975f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 209075f8991dSDaniel Drake { 209175f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 20920fb67e98SDaniel Drake unsigned int present; 20930fb67e98SDaniel Drake 2094c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2095c4cfe66cSDaniel Drake return; 2096c4cfe66cSDaniel Drake 209775f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 209875f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 209975f8991dSDaniel Drake if (present) 21000fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 210175f8991dSDaniel Drake else 21020fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 210375f8991dSDaniel Drake 210475f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 210575f8991dSDaniel Drake present ? 0 : 1); 210675f8991dSDaniel Drake spec->ext_mic_present = !!present; 210775f8991dSDaniel Drake 210875f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21090fb67e98SDaniel Drake } 21100fb67e98SDaniel Drake 211195a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 211295a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 211395a618bdSEinar Rünkaru { 211495a618bdSEinar Rünkaru unsigned int present; 211595a618bdSEinar Rünkaru 211695a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 211795a618bdSEinar Rünkaru /* enable external mic, port B */ 211875f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 211995a618bdSEinar Rünkaru 212095a618bdSEinar Rünkaru /* switch to external mic input */ 212195a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 212295a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 212395a618bdSEinar Rünkaru 212495a618bdSEinar Rünkaru /* disable internal digital mic */ 212595a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 212695a618bdSEinar Rünkaru {} 212795a618bdSEinar Rünkaru }; 212834cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 212995a618bdSEinar Rünkaru /* enable internal mic, port C */ 213095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 213195a618bdSEinar Rünkaru 213295a618bdSEinar Rünkaru /* switch to internal mic input */ 213395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 213495a618bdSEinar Rünkaru 213595a618bdSEinar Rünkaru /* disable external mic, port B */ 213695a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 213795a618bdSEinar Rünkaru {} 213895a618bdSEinar Rünkaru }; 213995a618bdSEinar Rünkaru 214095a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 214195a618bdSEinar Rünkaru if (present) { 214295a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 214395a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 214495a618bdSEinar Rünkaru } else { 214595a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 214695a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 214795a618bdSEinar Rünkaru } 214895a618bdSEinar Rünkaru } 214995a618bdSEinar Rünkaru 2150cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2151cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2152cfd3d8dcSGreg Alexander { 2153cfd3d8dcSGreg Alexander unsigned int present; 2154cfd3d8dcSGreg Alexander 2155cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2156cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2157cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2158cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2159cfd3d8dcSGreg Alexander {} 2160cfd3d8dcSGreg Alexander }; 216134cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2162cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2163cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2164cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2165cfd3d8dcSGreg Alexander {} 2166cfd3d8dcSGreg Alexander }; 2167cfd3d8dcSGreg Alexander 2168cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2169cfd3d8dcSGreg Alexander if (present) { 2170cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2171cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2172cfd3d8dcSGreg Alexander } else { 2173cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2174cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2175cfd3d8dcSGreg Alexander } 2176cfd3d8dcSGreg Alexander } 2177cfd3d8dcSGreg Alexander 2178a1d6906eSDavid Henningsson 2179a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2180a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2181a1d6906eSDavid Henningsson { 2182a1d6906eSDavid Henningsson unsigned int present; 2183a1d6906eSDavid Henningsson 2184a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2185a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2186a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2187a1d6906eSDavid Henningsson present ? 1 : 0); 2188a1d6906eSDavid Henningsson } 2189a1d6906eSDavid Henningsson 2190a1d6906eSDavid Henningsson 2191048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2192048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2193048e78a5SDavid Henningsson { 2194048e78a5SDavid Henningsson unsigned int present; 2195048e78a5SDavid Henningsson 2196048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2197048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2198048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2199048e78a5SDavid Henningsson present ? 1 : 3); 2200048e78a5SDavid Henningsson } 2201048e78a5SDavid Henningsson 2202048e78a5SDavid Henningsson 22037b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22047b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22057b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22067b2bfdbcSJens Taprogge { 22077b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22087b2bfdbcSJens Taprogge 220934cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22107b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22117b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22127b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22137b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22147b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22157b2bfdbcSJens Taprogge {} 22167b2bfdbcSJens Taprogge }; 221734cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 22187b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22197b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 22207b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22217b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22227b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22237b2bfdbcSJens Taprogge {} 22247b2bfdbcSJens Taprogge }; 222534cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 22267b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 22277b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 22287b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22297b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22307b2bfdbcSJens Taprogge {} 22317b2bfdbcSJens Taprogge }; 22327b2bfdbcSJens Taprogge 22337b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 22347b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 22357b2bfdbcSJens Taprogge if (ext_present) { 22367b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 22377b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 22387b2bfdbcSJens Taprogge } else if (dock_present) { 22397b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 22407b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 22417b2bfdbcSJens Taprogge } else { 22427b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 22437b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 22447b2bfdbcSJens Taprogge } 22457b2bfdbcSJens Taprogge } 22467b2bfdbcSJens Taprogge 22470fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22480fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22490fb67e98SDaniel Drake { 22500fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22510fb67e98SDaniel Drake unsigned int portA, portD; 22520fb67e98SDaniel Drake 22530fb67e98SDaniel Drake /* Port A */ 2254d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22550fb67e98SDaniel Drake 22560fb67e98SDaniel Drake /* Port D */ 2257d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 22580fb67e98SDaniel Drake 2259a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2260a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 22610fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 22620fb67e98SDaniel Drake portA, portD, spec->hp_present); 22630fb67e98SDaniel Drake cxt5066_update_speaker(codec); 22640fb67e98SDaniel Drake } 22650fb67e98SDaniel Drake 226602b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 226702b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 226802b6b5b6SDavid Henningsson { 226902b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 227002b6b5b6SDavid Henningsson 227102b6b5b6SDavid Henningsson if (spec->dell_vostro) 227202b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 227302b6b5b6SDavid Henningsson else if (spec->ideapad) 227402b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 227502b6b5b6SDavid Henningsson else if (spec->thinkpad) 227602b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 227702b6b5b6SDavid Henningsson else if (spec->hp_laptop) 227802b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2279a1d6906eSDavid Henningsson else if (spec->asus) 2280a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 228102b6b5b6SDavid Henningsson } 228202b6b5b6SDavid Henningsson 22830fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 228475f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 22850fb67e98SDaniel Drake { 2286c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 22870fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 22880fb67e98SDaniel Drake switch (res >> 26) { 22890fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 22900fb67e98SDaniel Drake cxt5066_hp_automute(codec); 22910fb67e98SDaniel Drake break; 22920fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2293c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2294c4cfe66cSDaniel Drake if (!spec->dc_enable) 229575f8991dSDaniel Drake cxt5066_olpc_automic(codec); 22960fb67e98SDaniel Drake break; 22970fb67e98SDaniel Drake } 22980fb67e98SDaniel Drake } 22990fb67e98SDaniel Drake 230095a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 230102b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 230295a618bdSEinar Rünkaru { 230302b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 230495a618bdSEinar Rünkaru switch (res >> 26) { 230595a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 230695a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 230795a618bdSEinar Rünkaru break; 230895a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 230902b6b5b6SDavid Henningsson cxt5066_automic(codec); 231095a618bdSEinar Rünkaru break; 231195a618bdSEinar Rünkaru } 231295a618bdSEinar Rünkaru } 231395a618bdSEinar Rünkaru 23147b2bfdbcSJens Taprogge 23150fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 23160fb67e98SDaniel Drake .num_items = 5, 23170fb67e98SDaniel Drake .items = { 23180fb67e98SDaniel Drake { "0dB", 0 }, 23190fb67e98SDaniel Drake { "10dB", 1 }, 23200fb67e98SDaniel Drake { "20dB", 2 }, 23210fb67e98SDaniel Drake { "30dB", 3 }, 23220fb67e98SDaniel Drake { "40dB", 4 }, 23230fb67e98SDaniel Drake }, 23240fb67e98SDaniel Drake }; 23250fb67e98SDaniel Drake 2326cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2327c4cfe66cSDaniel Drake { 2328c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2329cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2330c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2331c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2332c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 23337b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2334cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2335cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2336cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2337cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2338cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2339cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2340cfd3d8dcSGreg Alexander } 2341c4cfe66cSDaniel Drake } 2342c4cfe66cSDaniel Drake 23430fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 23440fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 23450fb67e98SDaniel Drake { 23460fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 23470fb67e98SDaniel Drake } 23480fb67e98SDaniel Drake 23490fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 23500fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23510fb67e98SDaniel Drake { 23520fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2353c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2354c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23550fb67e98SDaniel Drake return 0; 23560fb67e98SDaniel Drake } 23570fb67e98SDaniel Drake 23580fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 23590fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23600fb67e98SDaniel Drake { 23610fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2362c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23630fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 23640fb67e98SDaniel Drake unsigned int idx; 23650fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 23660fb67e98SDaniel Drake if (idx >= imux->num_items) 23670fb67e98SDaniel Drake idx = imux->num_items - 1; 23680fb67e98SDaniel Drake 2369c4cfe66cSDaniel Drake spec->mic_boost = idx; 2370c4cfe66cSDaniel Drake if (!spec->dc_enable) 2371c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2372c4cfe66cSDaniel Drake return 1; 2373c4cfe66cSDaniel Drake } 23740fb67e98SDaniel Drake 2375c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2376c4cfe66cSDaniel Drake { 2377c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2378c4cfe66cSDaniel Drake /* disable gain */ 2379c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2380c4cfe66cSDaniel Drake 2381c4cfe66cSDaniel Drake /* switch to DC input */ 2382c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2383c4cfe66cSDaniel Drake {} 2384c4cfe66cSDaniel Drake }; 2385c4cfe66cSDaniel Drake 2386c4cfe66cSDaniel Drake /* configure as input source */ 2387c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2388c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2389c4cfe66cSDaniel Drake } 2390c4cfe66cSDaniel Drake 2391c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2392c4cfe66cSDaniel Drake { 2393c4cfe66cSDaniel Drake /* reconfigure input source */ 2394c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2395c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2396c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2397c4cfe66cSDaniel Drake } 2398c4cfe66cSDaniel Drake 2399c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2400c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2401c4cfe66cSDaniel Drake { 2402c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2403c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2404c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2405c4cfe66cSDaniel Drake return 0; 2406c4cfe66cSDaniel Drake } 2407c4cfe66cSDaniel Drake 2408c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2409c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2410c4cfe66cSDaniel Drake { 2411c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2412c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2413c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2414c4cfe66cSDaniel Drake 2415c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2416c4cfe66cSDaniel Drake return 0; 2417c4cfe66cSDaniel Drake 2418c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2419c4cfe66cSDaniel Drake if (dc_enable) 2420c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2421c4cfe66cSDaniel Drake else 2422c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2423c4cfe66cSDaniel Drake 2424c4cfe66cSDaniel Drake return 1; 2425c4cfe66cSDaniel Drake } 2426c4cfe66cSDaniel Drake 2427c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2428c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2429c4cfe66cSDaniel Drake { 2430c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2431c4cfe66cSDaniel Drake } 2432c4cfe66cSDaniel Drake 2433c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2434c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2435c4cfe66cSDaniel Drake { 2436c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2437c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2438c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2439c4cfe66cSDaniel Drake return 0; 2440c4cfe66cSDaniel Drake } 2441c4cfe66cSDaniel Drake 2442c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2443c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2444c4cfe66cSDaniel Drake { 2445c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2446c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2447c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2448c4cfe66cSDaniel Drake unsigned int idx; 2449c4cfe66cSDaniel Drake 2450c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2451c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2452c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2453c4cfe66cSDaniel Drake 2454c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2455c4cfe66cSDaniel Drake if (spec->dc_enable) 2456c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 24570fb67e98SDaniel Drake return 1; 24580fb67e98SDaniel Drake } 24590fb67e98SDaniel Drake 246075f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 246175f8991dSDaniel Drake { 246275f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 246375f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 246475f8991dSDaniel Drake * recording LED comes on. */ 246575f8991dSDaniel Drake spec->recording = 1; 246675f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 246775f8991dSDaniel Drake } 246875f8991dSDaniel Drake 246975f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 247075f8991dSDaniel Drake { 247175f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 247275f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 247375f8991dSDaniel Drake /* disable external mic, port B */ 247475f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 247575f8991dSDaniel Drake 247675f8991dSDaniel Drake /* disble internal mic, port C */ 247775f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2478c4cfe66cSDaniel Drake 2479c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2480c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 248175f8991dSDaniel Drake {}, 248275f8991dSDaniel Drake }; 248375f8991dSDaniel Drake 248475f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 248575f8991dSDaniel Drake spec->recording = 0; 248675f8991dSDaniel Drake } 248775f8991dSDaniel Drake 2488f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 248934cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2490f6a2491cSAndy Robinson int num_pins) 2491f6a2491cSAndy Robinson { 2492f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2493f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2494f6a2491cSAndy Robinson int i; 2495f6a2491cSAndy Robinson 2496f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2497f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2498f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2499f6a2491cSAndy Robinson continue; 2500f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2501f6a2491cSAndy Robinson continue; 2502f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2503f6a2491cSAndy Robinson nid_loc++; 2504f6a2491cSAndy Robinson else 2505f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2506f6a2491cSAndy Robinson } 2507f6a2491cSAndy Robinson } 2508f6a2491cSAndy Robinson 250934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25100fb67e98SDaniel Drake .num_items = 4, 25110fb67e98SDaniel Drake .items = { 25120fb67e98SDaniel Drake { "Mic B", 0 }, 25130fb67e98SDaniel Drake { "Mic C", 1 }, 25140fb67e98SDaniel Drake { "Mic E", 2 }, 25150fb67e98SDaniel Drake { "Mic F", 3 }, 25160fb67e98SDaniel Drake }, 25170fb67e98SDaniel Drake }; 25180fb67e98SDaniel Drake 251934cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 25200fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 25210fb67e98SDaniel Drake .values = { 25220fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25230fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25240fb67e98SDaniel Drake 0 25250fb67e98SDaniel Drake }, 25260fb67e98SDaniel Drake }; 25270fb67e98SDaniel Drake 252834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 25290fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 25300fb67e98SDaniel Drake .values = { 25310fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25320fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25330fb67e98SDaniel Drake 0 25340fb67e98SDaniel Drake }, 25350fb67e98SDaniel Drake }; 25360fb67e98SDaniel Drake 253734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 25380fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 25390fb67e98SDaniel Drake {} 25400fb67e98SDaniel Drake }; 25410fb67e98SDaniel Drake 254234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 25430fb67e98SDaniel Drake { 25440fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25450fb67e98SDaniel Drake .name = "Master Playback Volume", 25460fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 25470fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 25480fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 25495e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 25500fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 25510fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 25520fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 25530fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 25540fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 25550fb67e98SDaniel Drake .private_value = 25560fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 25570fb67e98SDaniel Drake }, 25580fb67e98SDaniel Drake {} 25590fb67e98SDaniel Drake }; 25600fb67e98SDaniel Drake 256134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2562c4cfe66cSDaniel Drake { 2563c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2564c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2565c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2566c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2567c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2568c4cfe66cSDaniel Drake }, 2569c4cfe66cSDaniel Drake { 2570c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2571c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2572c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2573c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2574c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2575c4cfe66cSDaniel Drake }, 2576c4cfe66cSDaniel Drake {} 2577c4cfe66cSDaniel Drake }; 2578c4cfe66cSDaniel Drake 257934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 25800fb67e98SDaniel Drake { 25810fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25820fb67e98SDaniel Drake .name = "Master Playback Switch", 25830fb67e98SDaniel Drake .info = cxt_eapd_info, 25840fb67e98SDaniel Drake .get = cxt_eapd_get, 25850fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 25860fb67e98SDaniel Drake .private_value = 0x1d, 25870fb67e98SDaniel Drake }, 25880fb67e98SDaniel Drake 25890fb67e98SDaniel Drake { 25900fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2591c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 25920fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 25930fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 25940fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 25950fb67e98SDaniel Drake }, 25960fb67e98SDaniel Drake 25970fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 25980fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 25990fb67e98SDaniel Drake {} 26000fb67e98SDaniel Drake }; 26010fb67e98SDaniel Drake 260234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2603254bba6aSEinar Rünkaru { 2604254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 260528c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2606254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2607254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2608254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2609254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2610254bba6aSEinar Rünkaru }, 2611254bba6aSEinar Rünkaru {} 2612254bba6aSEinar Rünkaru }; 2613254bba6aSEinar Rünkaru 261434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 26150fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 26160fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 26170fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 26180fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 26190fb67e98SDaniel Drake 26200fb67e98SDaniel Drake /* Speakers */ 26210fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26220fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26230fb67e98SDaniel Drake 26240fb67e98SDaniel Drake /* HP, Amp */ 26250fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26260fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26270fb67e98SDaniel Drake 26280fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26290fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26300fb67e98SDaniel Drake 26310fb67e98SDaniel Drake /* DAC1 */ 26320fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26330fb67e98SDaniel Drake 26340fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 26350fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26360fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26370fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 26380fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26390fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 26400fb67e98SDaniel Drake 26410fb67e98SDaniel Drake /* no digital microphone support yet */ 26420fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26430fb67e98SDaniel Drake 26440fb67e98SDaniel Drake /* Audio input selector */ 26450fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26460fb67e98SDaniel Drake 26470fb67e98SDaniel Drake /* SPDIF route: PCM */ 26480fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 26490fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 26500fb67e98SDaniel Drake 26510fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26520fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26530fb67e98SDaniel Drake 26540fb67e98SDaniel Drake /* EAPD */ 26550fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26560fb67e98SDaniel Drake 26570fb67e98SDaniel Drake /* not handling these yet */ 26580fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26590fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26600fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26610fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26620fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26630fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26640fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26650fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26660fb67e98SDaniel Drake { } /* end */ 26670fb67e98SDaniel Drake }; 26680fb67e98SDaniel Drake 266934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 26700fb67e98SDaniel Drake /* Port A: headphones */ 26710fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26720fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26730fb67e98SDaniel Drake 26740fb67e98SDaniel Drake /* Port B: external microphone */ 267575f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26760fb67e98SDaniel Drake 26770fb67e98SDaniel Drake /* Port C: internal microphone */ 267875f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26790fb67e98SDaniel Drake 26800fb67e98SDaniel Drake /* Port D: unused */ 26810fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26820fb67e98SDaniel Drake 26830fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 26840fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26850fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26860fb67e98SDaniel Drake 2687c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 26880fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26890fb67e98SDaniel Drake 26900fb67e98SDaniel Drake /* Port G: internal speakers */ 26910fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26920fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26930fb67e98SDaniel Drake 26940fb67e98SDaniel Drake /* DAC1 */ 26950fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26960fb67e98SDaniel Drake 26970fb67e98SDaniel Drake /* DAC2: unused */ 26980fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 26990fb67e98SDaniel Drake 27000fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27010fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27020fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27030fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27040fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27050fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27060fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27070fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27080fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27090fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27100fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27110fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27120fb67e98SDaniel Drake 27130fb67e98SDaniel Drake /* Disable digital microphone port */ 27140fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27150fb67e98SDaniel Drake 27160fb67e98SDaniel Drake /* Audio input selectors */ 27170fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27180fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 27190fb67e98SDaniel Drake 27200fb67e98SDaniel Drake /* Disable SPDIF */ 27210fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27220fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27230fb67e98SDaniel Drake 27240fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 27250fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 27260fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 27270fb67e98SDaniel Drake { } /* end */ 27280fb67e98SDaniel Drake }; 27290fb67e98SDaniel Drake 273034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 273195a618bdSEinar Rünkaru /* Port A: headphones */ 273295a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 273395a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 273495a618bdSEinar Rünkaru 273595a618bdSEinar Rünkaru /* Port B: external microphone */ 273695a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 273795a618bdSEinar Rünkaru 273895a618bdSEinar Rünkaru /* Port C: unused */ 273995a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 274095a618bdSEinar Rünkaru 274195a618bdSEinar Rünkaru /* Port D: unused */ 274295a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 274395a618bdSEinar Rünkaru 274495a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 274595a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 274695a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 274795a618bdSEinar Rünkaru 274895a618bdSEinar Rünkaru /* Port F: unused */ 274995a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 275095a618bdSEinar Rünkaru 275195a618bdSEinar Rünkaru /* Port G: internal speakers */ 275295a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 275395a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 275495a618bdSEinar Rünkaru 275595a618bdSEinar Rünkaru /* DAC1 */ 275695a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 275795a618bdSEinar Rünkaru 275895a618bdSEinar Rünkaru /* DAC2: unused */ 275995a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 276095a618bdSEinar Rünkaru 276195a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 276295a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 276395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 276495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 276595a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 276695a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 276795a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 276895a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 276995a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 277095a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 277195a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 277295a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 277395a618bdSEinar Rünkaru 277495a618bdSEinar Rünkaru /* Digital microphone port */ 277595a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 277695a618bdSEinar Rünkaru 277795a618bdSEinar Rünkaru /* Audio input selectors */ 277895a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 277995a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 278095a618bdSEinar Rünkaru 278195a618bdSEinar Rünkaru /* Disable SPDIF */ 278295a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278395a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278495a618bdSEinar Rünkaru 278595a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 278695a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 278795a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 278895a618bdSEinar Rünkaru { } /* end */ 278995a618bdSEinar Rünkaru }; 279095a618bdSEinar Rünkaru 279134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2792cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2793cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2794cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2795cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2796cfd3d8dcSGreg Alexander 2797cfd3d8dcSGreg Alexander /* Speakers */ 2798cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2799cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2800cfd3d8dcSGreg Alexander 2801cfd3d8dcSGreg Alexander /* HP, Amp */ 2802cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2803cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2804cfd3d8dcSGreg Alexander 2805cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2806cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2807cfd3d8dcSGreg Alexander 2808cfd3d8dcSGreg Alexander /* DAC1 */ 2809cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2810cfd3d8dcSGreg Alexander 2811cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2812cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2813cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2814cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2815cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2816cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2817cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2818cfd3d8dcSGreg Alexander 2819cfd3d8dcSGreg Alexander /* Audio input selector */ 2820cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2821cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2822cfd3d8dcSGreg Alexander 2823cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2824cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2825cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2826cfd3d8dcSGreg Alexander 2827cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2828cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2829cfd3d8dcSGreg Alexander 2830cfd3d8dcSGreg Alexander /* internal microphone */ 283128c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2832cfd3d8dcSGreg Alexander 2833cfd3d8dcSGreg Alexander /* EAPD */ 2834cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2835cfd3d8dcSGreg Alexander 2836cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2837cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2838cfd3d8dcSGreg Alexander { } /* end */ 2839cfd3d8dcSGreg Alexander }; 2840cfd3d8dcSGreg Alexander 284134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 28427b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 28437b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 28447b2bfdbcSJens Taprogge 28457b2bfdbcSJens Taprogge /* Port G: internal speakers */ 28467b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28477b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28487b2bfdbcSJens Taprogge 28497b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 28507b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28517b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28527b2bfdbcSJens Taprogge 28537b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 28547b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28557b2bfdbcSJens Taprogge 28567b2bfdbcSJens Taprogge /* Port C: Mic */ 28577b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28587b2bfdbcSJens Taprogge 28597b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 28607b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28617b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28627b2bfdbcSJens Taprogge 28637b2bfdbcSJens Taprogge /* DAC1 */ 28647b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28657b2bfdbcSJens Taprogge 28667b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 28677b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28687b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28697b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 28707b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28717b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 28727b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 28737b2bfdbcSJens Taprogge 28747b2bfdbcSJens Taprogge /* Audio input selector */ 28757b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 28767b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 28777b2bfdbcSJens Taprogge 28787b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 28797b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 28807b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 28817b2bfdbcSJens Taprogge 28827b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28837b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28847b2bfdbcSJens Taprogge 28857b2bfdbcSJens Taprogge /* internal microphone */ 288628c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 28877b2bfdbcSJens Taprogge 28887b2bfdbcSJens Taprogge /* EAPD */ 28897b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28907b2bfdbcSJens Taprogge 28917b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 28927b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28937b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28947b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28957b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28967b2bfdbcSJens Taprogge { } /* end */ 28977b2bfdbcSJens Taprogge }; 28987b2bfdbcSJens Taprogge 289934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29000fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29010fb67e98SDaniel Drake { } /* end */ 29020fb67e98SDaniel Drake }; 29030fb67e98SDaniel Drake 2904048e78a5SDavid Henningsson 290534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2906048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2907048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2908048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2909048e78a5SDavid Henningsson { } /* end */ 2910048e78a5SDavid Henningsson }; 2911048e78a5SDavid Henningsson 29120fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29130fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29140fb67e98SDaniel Drake { 29150fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 29160fb67e98SDaniel Drake conexant_init(codec); 29170fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 29180fb67e98SDaniel Drake cxt5066_hp_automute(codec); 291902b6b5b6SDavid Henningsson cxt5066_automic(codec); 29200fb67e98SDaniel Drake } 2921c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 29220fb67e98SDaniel Drake return 0; 29230fb67e98SDaniel Drake } 29240fb67e98SDaniel Drake 292575f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 292675f8991dSDaniel Drake { 2927c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 292875f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 292975f8991dSDaniel Drake conexant_init(codec); 293075f8991dSDaniel Drake cxt5066_hp_automute(codec); 2931c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2932c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 293375f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2934c4cfe66cSDaniel Drake } else { 2935c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2936c4cfe66cSDaniel Drake } 293775f8991dSDaniel Drake return 0; 293875f8991dSDaniel Drake } 293975f8991dSDaniel Drake 29400fb67e98SDaniel Drake enum { 29410fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 29420fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 29430fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 29441feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2945cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 29467b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2947a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2948048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 2949fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 29500fb67e98SDaniel Drake CXT5066_MODELS 29510fb67e98SDaniel Drake }; 29520fb67e98SDaniel Drake 2953ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 29540fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 29550fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 29560fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 29571feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 2958cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 29597b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 2960a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 2961048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 2962fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 29630fb67e98SDaniel Drake }; 29640fb67e98SDaniel Drake 296534cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 29669966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 296700cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 29681feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 29698a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 2970ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 29711feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 2972231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 2973ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 2974ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 2975048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 2976f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 2977a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 2978f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 29792ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 2980c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 29815637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 29825637edb2SDavid Henningsson CXT5066_LAPTOP), 29835637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 29844d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 2985ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 298619593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 298729c5fbbcSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), 2988ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 298984012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 2990b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 2991d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 2992a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 2993af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 29947ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 29950fb67e98SDaniel Drake {} 29960fb67e98SDaniel Drake }; 29970fb67e98SDaniel Drake 29980fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 29990fb67e98SDaniel Drake { 30000fb67e98SDaniel Drake struct conexant_spec *spec; 30010fb67e98SDaniel Drake int board_config; 30020fb67e98SDaniel Drake 3003fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3004fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3005fea4a4f9STakashi Iwai if (board_config < 0) 3006c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3007fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3008fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3009fea4a4f9STakashi Iwai 30100fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30110fb67e98SDaniel Drake if (!spec) 30120fb67e98SDaniel Drake return -ENOMEM; 30130fb67e98SDaniel Drake codec->spec = spec; 30140fb67e98SDaniel Drake 30150fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 301675f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 30170fb67e98SDaniel Drake 30180fb67e98SDaniel Drake spec->dell_automute = 0; 30190fb67e98SDaniel Drake spec->multiout.max_channels = 2; 30200fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 30210fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3022f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3023f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 30240fb67e98SDaniel Drake spec->num_adc_nids = 1; 30250fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 30260fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 30270fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 30280fb67e98SDaniel Drake 30290fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 30300fb67e98SDaniel Drake 30310fb67e98SDaniel Drake spec->num_init_verbs = 1; 30320fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 30330fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 30340fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 30350fb67e98SDaniel Drake spec->cur_adc = 0; 30360fb67e98SDaniel Drake spec->cur_adc_idx = 0; 30370fb67e98SDaniel Drake 30383507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 30393507e2a8STakashi Iwai 30400fb67e98SDaniel Drake switch (board_config) { 30410fb67e98SDaniel Drake default: 30420fb67e98SDaniel Drake case CXT5066_LAPTOP: 30430fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30440fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30450fb67e98SDaniel Drake break; 30460fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 30470fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30480fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30490fb67e98SDaniel Drake 30500fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 30510fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 30520fb67e98SDaniel Drake spec->num_init_verbs++; 30530fb67e98SDaniel Drake spec->dell_automute = 1; 30540fb67e98SDaniel Drake break; 3055a1d6906eSDavid Henningsson case CXT5066_ASUS: 3056048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3057048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 305802b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3059048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3060048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3061048e78a5SDavid Henningsson spec->num_init_verbs++; 3062a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3063a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3064048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3065048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3066048e78a5SDavid Henningsson /* no S/PDIF out */ 3067f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3068048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3069048e78a5SDavid Henningsson /* input source automatically selected */ 3070048e78a5SDavid Henningsson spec->input_mux = NULL; 3071048e78a5SDavid Henningsson spec->port_d_mode = 0; 3072048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3073048e78a5SDavid Henningsson break; 3074048e78a5SDavid Henningsson 30750fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 307675f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 307775f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 30780fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 30790fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3080c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 30810fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30820fb67e98SDaniel Drake spec->port_d_mode = 0; 3083c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 30840fb67e98SDaniel Drake 30850fb67e98SDaniel Drake /* no S/PDIF out */ 30860fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 30870fb67e98SDaniel Drake 30880fb67e98SDaniel Drake /* input source automatically selected */ 30890fb67e98SDaniel Drake spec->input_mux = NULL; 309075f8991dSDaniel Drake 309175f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 309275f8991dSDaniel Drake * at the right time */ 309375f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 309475f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 30950fb67e98SDaniel Drake break; 30961feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 309775f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 309802b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 309995a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 310095a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 310195a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3102254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 310395a618bdSEinar Rünkaru spec->port_d_mode = 0; 3104254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3105c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 310695a618bdSEinar Rünkaru 310795a618bdSEinar Rünkaru /* no S/PDIF out */ 310895a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 310995a618bdSEinar Rünkaru 311095a618bdSEinar Rünkaru /* input source automatically selected */ 311195a618bdSEinar Rünkaru spec->input_mux = NULL; 311295a618bdSEinar Rünkaru break; 3113cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3114cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 311502b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3116cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3117cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3118cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3119cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3120cfd3d8dcSGreg Alexander spec->ideapad = 1; 3121cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3122cfd3d8dcSGreg Alexander 3123cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3124cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3125cfd3d8dcSGreg Alexander 3126cfd3d8dcSGreg Alexander /* input source automatically selected */ 3127cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3128cfd3d8dcSGreg Alexander break; 31297b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 31307b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 313102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 31327b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31337b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31347b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 31357b2bfdbcSJens Taprogge spec->thinkpad = 1; 31367b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 31377b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 31387b2bfdbcSJens Taprogge 31397b2bfdbcSJens Taprogge /* no S/PDIF out */ 31407b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 31417b2bfdbcSJens Taprogge 31427b2bfdbcSJens Taprogge /* input source automatically selected */ 31437b2bfdbcSJens Taprogge spec->input_mux = NULL; 31447b2bfdbcSJens Taprogge break; 31450fb67e98SDaniel Drake } 31460fb67e98SDaniel Drake 31473507e2a8STakashi Iwai if (spec->beep_amp) 31483507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 31493507e2a8STakashi Iwai 31500fb67e98SDaniel Drake return 0; 31510fb67e98SDaniel Drake } 3152461e2c78STakashi Iwai 3153461e2c78STakashi Iwai /* 3154f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3155f2e5731dSTakashi Iwai */ 3156f2e5731dSTakashi Iwai 31576764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 31586764bcefSTakashi Iwai struct hda_codec *codec, 31596764bcefSTakashi Iwai unsigned int stream_tag, 31606764bcefSTakashi Iwai unsigned int format, 31616764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31626764bcefSTakashi Iwai { 31636764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 316447ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 31656764bcefSTakashi Iwai if (spec->adc_switching) { 31666764bcefSTakashi Iwai spec->cur_adc = adc; 31676764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 31686764bcefSTakashi Iwai spec->cur_adc_format = format; 31696764bcefSTakashi Iwai } 31706764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 31716764bcefSTakashi Iwai return 0; 31726764bcefSTakashi Iwai } 31736764bcefSTakashi Iwai 31746764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 31756764bcefSTakashi Iwai struct hda_codec *codec, 31766764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31776764bcefSTakashi Iwai { 31786764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 31796764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 31806764bcefSTakashi Iwai spec->cur_adc = 0; 31816764bcefSTakashi Iwai return 0; 31826764bcefSTakashi Iwai } 31836764bcefSTakashi Iwai 31846764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 31856764bcefSTakashi Iwai .substreams = 1, 31866764bcefSTakashi Iwai .channels_min = 2, 31876764bcefSTakashi Iwai .channels_max = 2, 31886764bcefSTakashi Iwai .nid = 0, /* fill later */ 31896764bcefSTakashi Iwai .ops = { 31906764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 31916764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 31926764bcefSTakashi Iwai }, 31936764bcefSTakashi Iwai }; 31946764bcefSTakashi Iwai 319534cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3196f2e5731dSTakashi Iwai 31978d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 31988d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3199f2e5731dSTakashi Iwai 3200f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3201f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3202f2e5731dSTakashi Iwai * not found 3203f2e5731dSTakashi Iwai */ 3204f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3205f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3206f2e5731dSTakashi Iwai { 3207f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3208f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3209f2e5731dSTakashi Iwai 3210f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3211f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3212f2e5731dSTakashi Iwai ret = dacs[i]; 3213f2e5731dSTakashi Iwai break; 3214f2e5731dSTakashi Iwai } 3215f2e5731dSTakashi Iwai } 3216f2e5731dSTakashi Iwai if (!ret) 3217f2e5731dSTakashi Iwai return 0; 3218f2e5731dSTakashi Iwai if (--nums > 0) 3219f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3220f2e5731dSTakashi Iwai *num_dacs = nums; 3221f2e5731dSTakashi Iwai return ret; 3222f2e5731dSTakashi Iwai } 3223f2e5731dSTakashi Iwai 3224f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3225f2e5731dSTakashi Iwai 32261f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 32271f015f5fSTakashi Iwai 3228f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3229f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3230f2e5731dSTakashi Iwai { 3231f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3232f2e5731dSTakashi Iwai int nums = 0; 3233f2e5731dSTakashi Iwai 3234f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3235f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3236f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3237f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3238f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3239f2e5731dSTakashi Iwai dacs[nums++] = nid; 3240f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3241f2e5731dSTakashi Iwai break; 3242f2e5731dSTakashi Iwai } 3243f2e5731dSTakashi Iwai } 3244f2e5731dSTakashi Iwai return nums; 3245f2e5731dSTakashi Iwai } 3246f2e5731dSTakashi Iwai 3247f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3248f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3249f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3250468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3251468c5458SDavid Henningsson int type) 3252f2e5731dSTakashi Iwai { 3253468c5458SDavid Henningsson int i, start = nums; 3254f2e5731dSTakashi Iwai 3255468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3256f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3257f2e5731dSTakashi Iwai filled[nums].type = type; 3258f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3259468c5458SDavid Henningsson if (filled[nums].dac) 3260468c5458SDavid Henningsson continue; 3261468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3262468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3263468c5458SDavid Henningsson continue; 3264468c5458SDavid Henningsson } 3265468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 32661f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3267468c5458SDavid Henningsson continue; 3268468c5458SDavid Henningsson } 3269468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3270f2e5731dSTakashi Iwai } 3271f2e5731dSTakashi Iwai return nums; 3272f2e5731dSTakashi Iwai } 3273f2e5731dSTakashi Iwai 3274f2e5731dSTakashi Iwai /* parse analog output paths */ 3275f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3276f2e5731dSTakashi Iwai { 3277f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3278f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3279f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3280f2e5731dSTakashi Iwai int i, j, nums, rest; 3281f2e5731dSTakashi Iwai 3282f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3283f2e5731dSTakashi Iwai /* parse all analog output pins */ 3284f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3285468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3286f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3287468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3288468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3289f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3290468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3291468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3292f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3293f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3294f2e5731dSTakashi Iwai /* fill multiout struct */ 3295f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3296f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 32971f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3298f2e5731dSTakashi Iwai continue; 3299f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3300f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3301f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3302f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3303f2e5731dSTakashi Iwai break; 3304f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3305f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3306f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3307f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3308f2e5731dSTakashi Iwai break; 3309f2e5731dSTakashi Iwai } 3310f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3311f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3312f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3313f2e5731dSTakashi Iwai break; 3314f2e5731dSTakashi Iwai } 3315f2e5731dSTakashi Iwai break; 3316f2e5731dSTakashi Iwai } 3317f2e5731dSTakashi Iwai } 3318f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 331989724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3320f2e5731dSTakashi Iwai 332103697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 332203697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3323f2e5731dSTakashi Iwai spec->auto_mute = 1; 332403697e2aSTakashi Iwai break; 332503697e2aSTakashi Iwai } 332603697e2aSTakashi Iwai } 3327e2df82ffSTakashi Iwai if (spec->auto_mute && 3328e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3329e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 333003697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 333103697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 333203697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 333303697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 333403697e2aSTakashi Iwai spec->detect_line = 1; 333503697e2aSTakashi Iwai break; 333603697e2aSTakashi Iwai } 333703697e2aSTakashi Iwai } 333803697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 333903697e2aSTakashi Iwai } 334003697e2aSTakashi Iwai 3341f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3342f2e5731dSTakashi Iwai } 3343f2e5731dSTakashi Iwai 3344da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3345da339866STakashi Iwai hda_nid_t *pins, bool on); 3346da339866STakashi Iwai 334703697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 334803697e2aSTakashi Iwai hda_nid_t *pins, bool on) 334903697e2aSTakashi Iwai { 3350254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 335103697e2aSTakashi Iwai int i; 335203697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 3353*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, pins[i], on ? PIN_OUT : 0); 3354254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 335503697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 335603697e2aSTakashi Iwai } 335703697e2aSTakashi Iwai 335803697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 335903697e2aSTakashi Iwai { 336003697e2aSTakashi Iwai int i, present = 0; 336103697e2aSTakashi Iwai 336203697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 336303697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 336403697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 336503697e2aSTakashi Iwai break; 336603697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 336703697e2aSTakashi Iwai } 336803697e2aSTakashi Iwai return present; 336903697e2aSTakashi Iwai } 337003697e2aSTakashi Iwai 3371f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 337203697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 337303697e2aSTakashi Iwai { 337403697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 337503697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3376e2df82ffSTakashi Iwai int on = 1; 337703697e2aSTakashi Iwai 3378e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3379254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3380e2df82ffSTakashi Iwai if (spec->auto_mute) 3381e2df82ffSTakashi Iwai on = spec->hp_present; 338203697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3383254f2968STakashi Iwai } 3384254f2968STakashi Iwai 3385e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3386e2df82ffSTakashi Iwai if (spec->auto_mute) 3387e2df82ffSTakashi Iwai on = !(spec->hp_present || 3388e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3389e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 339003697e2aSTakashi Iwai 339103697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 339203697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 339303697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 339403697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 339503697e2aSTakashi Iwai return; 3396e2df82ffSTakashi Iwai if (spec->auto_mute) { 3397e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3398e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3399e2df82ffSTakashi Iwai spec->automute_lines) 3400e2df82ffSTakashi Iwai on = !spec->hp_present; 340103697e2aSTakashi Iwai else 3402e2df82ffSTakashi Iwai on = 1; 3403e2df82ffSTakashi Iwai } 3404e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 340503697e2aSTakashi Iwai } 340603697e2aSTakashi Iwai 3407f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3408f2e5731dSTakashi Iwai { 3409f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3410f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3411f2e5731dSTakashi Iwai 3412f2e5731dSTakashi Iwai if (!spec->auto_mute) 3413f2e5731dSTakashi Iwai return; 341403697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 341503697e2aSTakashi Iwai cx_auto_update_speakers(codec); 341603697e2aSTakashi Iwai } 341703697e2aSTakashi Iwai 341803697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 341903697e2aSTakashi Iwai { 342003697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 342103697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 342203697e2aSTakashi Iwai 342303697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 342403697e2aSTakashi Iwai return; 342503697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 342603697e2aSTakashi Iwai cfg->line_out_pins); 342703697e2aSTakashi Iwai cx_auto_update_speakers(codec); 342803697e2aSTakashi Iwai } 342903697e2aSTakashi Iwai 343003697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 343103697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 343203697e2aSTakashi Iwai { 343303697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 343403697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 343503697e2aSTakashi Iwai static const char * const texts2[] = { 343603697e2aSTakashi Iwai "Disabled", "Enabled" 343703697e2aSTakashi Iwai }; 343803697e2aSTakashi Iwai static const char * const texts3[] = { 3439e49a3434STakashi Iwai "Disabled", "Speaker Only", "Line Out+Speaker" 344003697e2aSTakashi Iwai }; 344103697e2aSTakashi Iwai const char * const *texts; 344203697e2aSTakashi Iwai 344303697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 344403697e2aSTakashi Iwai uinfo->count = 1; 344503697e2aSTakashi Iwai if (spec->automute_hp_lo) { 344603697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 344703697e2aSTakashi Iwai texts = texts3; 344803697e2aSTakashi Iwai } else { 344903697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 345003697e2aSTakashi Iwai texts = texts2; 345103697e2aSTakashi Iwai } 345203697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 345303697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 345403697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 345503697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 345603697e2aSTakashi Iwai return 0; 345703697e2aSTakashi Iwai } 345803697e2aSTakashi Iwai 345903697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 346003697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 346103697e2aSTakashi Iwai { 346203697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 346303697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 346403697e2aSTakashi Iwai unsigned int val; 346503697e2aSTakashi Iwai if (!spec->auto_mute) 346603697e2aSTakashi Iwai val = 0; 346703697e2aSTakashi Iwai else if (!spec->automute_lines) 346803697e2aSTakashi Iwai val = 1; 346903697e2aSTakashi Iwai else 347003697e2aSTakashi Iwai val = 2; 347103697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 347203697e2aSTakashi Iwai return 0; 347303697e2aSTakashi Iwai } 347403697e2aSTakashi Iwai 347503697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 347603697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 347703697e2aSTakashi Iwai { 347803697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 347903697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 348003697e2aSTakashi Iwai 348103697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 348203697e2aSTakashi Iwai case 0: 348303697e2aSTakashi Iwai if (!spec->auto_mute) 348403697e2aSTakashi Iwai return 0; 348503697e2aSTakashi Iwai spec->auto_mute = 0; 3486f2e5731dSTakashi Iwai break; 348703697e2aSTakashi Iwai case 1: 348803697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 348903697e2aSTakashi Iwai return 0; 349003697e2aSTakashi Iwai spec->auto_mute = 1; 349103697e2aSTakashi Iwai spec->automute_lines = 0; 349203697e2aSTakashi Iwai break; 349303697e2aSTakashi Iwai case 2: 349403697e2aSTakashi Iwai if (!spec->automute_hp_lo) 349503697e2aSTakashi Iwai return -EINVAL; 349603697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 349703697e2aSTakashi Iwai return 0; 349803697e2aSTakashi Iwai spec->auto_mute = 1; 349903697e2aSTakashi Iwai spec->automute_lines = 1; 350003697e2aSTakashi Iwai break; 350103697e2aSTakashi Iwai default: 350203697e2aSTakashi Iwai return -EINVAL; 3503f2e5731dSTakashi Iwai } 350403697e2aSTakashi Iwai cx_auto_update_speakers(codec); 350503697e2aSTakashi Iwai return 1; 3506f2e5731dSTakashi Iwai } 350703697e2aSTakashi Iwai 350803697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 350903697e2aSTakashi Iwai { 351003697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 351103697e2aSTakashi Iwai .name = "Auto-Mute Mode", 351203697e2aSTakashi Iwai .info = cx_automute_mode_info, 351303697e2aSTakashi Iwai .get = cx_automute_mode_get, 351403697e2aSTakashi Iwai .put = cx_automute_mode_put, 351503697e2aSTakashi Iwai }, 351603697e2aSTakashi Iwai { } 351703697e2aSTakashi Iwai }; 3518f2e5731dSTakashi Iwai 35196764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 35206764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 35216764bcefSTakashi Iwai { 35226764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35236764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35246764bcefSTakashi Iwai 35256764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 35266764bcefSTakashi Iwai } 35276764bcefSTakashi Iwai 35286764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 35296764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35306764bcefSTakashi Iwai { 35316764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35326764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35336764bcefSTakashi Iwai 35346764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 35356764bcefSTakashi Iwai return 0; 35366764bcefSTakashi Iwai } 35376764bcefSTakashi Iwai 35385c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 35395c9887e0STakashi Iwai * if do_select is set, actually select the route. 35405c9887e0STakashi Iwai */ 35415c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3542cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3543cf27f29aSTakashi Iwai bool do_select, int depth) 35445c9887e0STakashi Iwai { 35455c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 35465c9887e0STakashi Iwai int i, nums; 35475c9887e0STakashi Iwai 3548cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3549cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3550cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3551cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3552cf27f29aSTakashi Iwai break; 3553cf27f29aSTakashi Iwai default: 3554cf27f29aSTakashi Iwai return -1; 3555cf27f29aSTakashi Iwai } 3556cf27f29aSTakashi Iwai 35575c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 35585c9887e0STakashi Iwai for (i = 0; i < nums; i++) 35595c9887e0STakashi Iwai if (conn[i] == pin) { 35605c9887e0STakashi Iwai if (do_select) 35615c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35625c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3563cf27f29aSTakashi Iwai if (srcp) 3564cf27f29aSTakashi Iwai *srcp = mux; 35655c9887e0STakashi Iwai return i; 35665c9887e0STakashi Iwai } 35675c9887e0STakashi Iwai depth++; 35685c9887e0STakashi Iwai if (depth == 2) 35695c9887e0STakashi Iwai return -1; 35705c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3571cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 35725c9887e0STakashi Iwai do_select, depth); 35735c9887e0STakashi Iwai if (ret >= 0) { 35745c9887e0STakashi Iwai if (do_select) 35755c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35765c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3577cf27f29aSTakashi Iwai return i; 35785c9887e0STakashi Iwai } 35795c9887e0STakashi Iwai } 35805c9887e0STakashi Iwai return -1; 35815c9887e0STakashi Iwai } 35825c9887e0STakashi Iwai 35835c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 35845c9887e0STakashi Iwai hda_nid_t pin) 35855c9887e0STakashi Iwai { 3586cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 35875c9887e0STakashi Iwai } 35885c9887e0STakashi Iwai 35895c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 35905c9887e0STakashi Iwai hda_nid_t pin) 35915c9887e0STakashi Iwai { 3592cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 35935c9887e0STakashi Iwai } 35945c9887e0STakashi Iwai 35956764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 35966764bcefSTakashi Iwai const struct hda_input_mux *imux, 35976764bcefSTakashi Iwai unsigned int idx) 35986764bcefSTakashi Iwai { 35996764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36006764bcefSTakashi Iwai hda_nid_t adc; 3601313d2c06STakashi Iwai int changed = 1; 36026764bcefSTakashi Iwai 36036764bcefSTakashi Iwai if (!imux->num_items) 36046764bcefSTakashi Iwai return 0; 36056764bcefSTakashi Iwai if (idx >= imux->num_items) 36066764bcefSTakashi Iwai idx = imux->num_items - 1; 36076764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3608313d2c06STakashi Iwai changed = 0; 360947ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 361047ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 361147ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 36126764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 36136764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 36146764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 36156764bcefSTakashi Iwai spec->cur_adc = adc; 36166764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 36176764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 36186764bcefSTakashi Iwai spec->cur_adc_format); 36196764bcefSTakashi Iwai } 36206764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3621313d2c06STakashi Iwai return changed; 36226764bcefSTakashi Iwai } 36236764bcefSTakashi Iwai 36246764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 36256764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36266764bcefSTakashi Iwai { 36276764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36286764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36296764bcefSTakashi Iwai 36306764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 36316764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 36326764bcefSTakashi Iwai } 36336764bcefSTakashi Iwai 36346764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 36356764bcefSTakashi Iwai { 36366764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 36376764bcefSTakashi Iwai .name = "Capture Source", 36386764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 36396764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 36406764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 36416764bcefSTakashi Iwai }, 36426764bcefSTakashi Iwai {} 36436764bcefSTakashi Iwai }; 36446764bcefSTakashi Iwai 364543c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 364643c1b2e9STakashi Iwai { 364743c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 364843c1b2e9STakashi Iwai if (idx < 0) 364943c1b2e9STakashi Iwai return false; 365043c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 365143c1b2e9STakashi Iwai return false; 365243c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 365343c1b2e9STakashi Iwai return true; 365443c1b2e9STakashi Iwai } 365543c1b2e9STakashi Iwai 3656f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3657f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3658f2e5731dSTakashi Iwai { 3659f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3660f2e5731dSTakashi Iwai 3661f2e5731dSTakashi Iwai if (!spec->auto_mic) 3662f2e5731dSTakashi Iwai return; 366343c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 366443c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 366543c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3666f2e5731dSTakashi Iwai } 3667f2e5731dSTakashi Iwai 3668f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3669f2e5731dSTakashi Iwai { 36703a93897eSTakashi Iwai switch (snd_hda_jack_get_action(codec, res >> 26)) { 3671f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3672f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 367303697e2aSTakashi Iwai break; 367403697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 367503697e2aSTakashi Iwai cx_auto_line_automute(codec); 3676f2e5731dSTakashi Iwai break; 3677f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3678f2e5731dSTakashi Iwai cx_auto_automic(codec); 3679f2e5731dSTakashi Iwai break; 3680f2e5731dSTakashi Iwai } 368101a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3682f2e5731dSTakashi Iwai } 3683f2e5731dSTakashi Iwai 3684f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 368543c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 368643c1b2e9STakashi Iwai * one dock-mic exist 3687f2e5731dSTakashi Iwai */ 3688f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3689f2e5731dSTakashi Iwai { 3690f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 369143c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 369243c1b2e9STakashi Iwai int i; 3693f2e5731dSTakashi Iwai 3694506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 369543c1b2e9STakashi Iwai pset[i] = -1; 369643c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 369743c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 369843c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3699b55fcb50STakashi Iwai int type, attr; 370043c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 370143c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3702b55fcb50STakashi Iwai return; /* invalid entry */ 370343c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 370443c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 370543c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 370643c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3707b55fcb50STakashi Iwai return; /* non-detectable pin */ 3708b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3709b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3710b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3711b55fcb50STakashi Iwai return; /* no valid input type */ 371243c1b2e9STakashi Iwai if (pset[attr] >= 0) 371343c1b2e9STakashi Iwai return; /* already occupied */ 371443c1b2e9STakashi Iwai pset[attr] = i; 3715f2e5731dSTakashi Iwai } 371643c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 371743c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 371843c1b2e9STakashi Iwai return; /* no input to switch*/ 3719f2e5731dSTakashi Iwai spec->auto_mic = 1; 372043c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 372143c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 372243c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3723f2e5731dSTakashi Iwai } 3724f2e5731dSTakashi Iwai 3725f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3726f2e5731dSTakashi Iwai { 3727f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3728f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3729f2e5731dSTakashi Iwai struct hda_input_mux *imux; 37306764bcefSTakashi Iwai int i, j; 3731f2e5731dSTakashi Iwai 3732f2e5731dSTakashi Iwai imux = &spec->private_imux; 3733f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 37346764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 37356764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 37365c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3737f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3738f2e5731dSTakashi Iwai if (idx >= 0) { 3739f2e5731dSTakashi Iwai const char *label; 3740f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 374147ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 374247ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 374347ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 374447ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3745f6100bb4STakashi Iwai cfg->inputs[i].pin; 3746f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 37476764bcefSTakashi Iwai break; 37486764bcefSTakashi Iwai } 3749f2e5731dSTakashi Iwai } 3750f2e5731dSTakashi Iwai } 375143c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3752f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 375376755359STakashi Iwai if (imux->num_items > 1) { 37546764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 375547ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 37566764bcefSTakashi Iwai spec->adc_switching = 1; 37576764bcefSTakashi Iwai break; 37586764bcefSTakashi Iwai } 37596764bcefSTakashi Iwai } 37606764bcefSTakashi Iwai } 3761f2e5731dSTakashi Iwai } 3762f2e5731dSTakashi Iwai 3763f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3764f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3765f2e5731dSTakashi Iwai { 3766f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3767f2e5731dSTakashi Iwai 3768f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3769f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3770f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3771f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3772f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3773f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3774f2e5731dSTakashi Iwai return nid; 3775f2e5731dSTakashi Iwai } 3776f2e5731dSTakashi Iwai } 3777f2e5731dSTakashi Iwai return 0; 3778f2e5731dSTakashi Iwai } 3779f2e5731dSTakashi Iwai 3780f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3781f2e5731dSTakashi Iwai { 3782f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3783f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3784f2e5731dSTakashi Iwai hda_nid_t nid; 3785f2e5731dSTakashi Iwai 3786f2e5731dSTakashi Iwai if (cfg->dig_outs && 3787f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3788f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3789f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3790f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3791f2e5731dSTakashi Iwai } 3792f2e5731dSTakashi Iwai 3793f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3794f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3795f2e5731dSTakashi Iwai { 3796f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3797f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3798f2e5731dSTakashi Iwai 3799f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3800f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3801f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3802f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3803f2e5731dSTakashi Iwai break; 3804f2e5731dSTakashi Iwai } 3805f2e5731dSTakashi Iwai } 3806f2e5731dSTakashi Iwai #else 3807f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3808f2e5731dSTakashi Iwai #endif 3809f2e5731dSTakashi Iwai 3810254f2968STakashi Iwai /* parse EAPDs */ 381119110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 381219110595STakashi Iwai { 381319110595STakashi Iwai struct conexant_spec *spec = codec->spec; 381419110595STakashi Iwai hda_nid_t nid, end_nid; 381519110595STakashi Iwai 381619110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 381719110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 381819110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 381919110595STakashi Iwai continue; 382019110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 382119110595STakashi Iwai continue; 382219110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 382319110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 382419110595STakashi Iwai break; 382519110595STakashi Iwai } 3826254f2968STakashi Iwai 3827254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3828254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3829254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3830254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3831254f2968STakashi Iwai * thus it might control over all pins. 3832254f2968STakashi Iwai */ 3833254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 383419110595STakashi Iwai } 383519110595STakashi Iwai 3836f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3837f2e5731dSTakashi Iwai { 3838f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3839f2e5731dSTakashi Iwai int err; 3840f2e5731dSTakashi Iwai 3841f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3842f2e5731dSTakashi Iwai if (err < 0) 3843f2e5731dSTakashi Iwai return err; 3844f2e5731dSTakashi Iwai 3845f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3846f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3847f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3848f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 384919110595STakashi Iwai cx_auto_parse_eapd(codec); 3850f2e5731dSTakashi Iwai return 0; 3851f2e5731dSTakashi Iwai } 3852f2e5731dSTakashi Iwai 3853da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3854da339866STakashi Iwai hda_nid_t *pins, bool on) 3855f2e5731dSTakashi Iwai { 3856f2e5731dSTakashi Iwai int i; 3857f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3858f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3859f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3860da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3861da339866STakashi Iwai on ? 0x02 : 0); 3862f2e5731dSTakashi Iwai } 3863f2e5731dSTakashi Iwai } 3864f2e5731dSTakashi Iwai 3865f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3866f2e5731dSTakashi Iwai hda_nid_t src) 3867f2e5731dSTakashi Iwai { 3868f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3869f2e5731dSTakashi Iwai if (idx >= 0) 3870f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3871f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3872f2e5731dSTakashi Iwai } 3873f2e5731dSTakashi Iwai 38741f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 38751f8458a2STakashi Iwai const hda_nid_t *nids) 3876f2e5731dSTakashi Iwai { 38770ad1b5b6STakashi Iwai int i, val; 3878f2e5731dSTakashi Iwai 38791f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 38801f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 38811f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 38821f8458a2STakashi Iwai continue; 38830ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 38840ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 38850ad1b5b6STakashi Iwai else 38860ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 38870ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 38880ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 38890ad1b5b6STakashi Iwai } 38901f8458a2STakashi Iwai } 3891f2e5731dSTakashi Iwai 389203697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 38933a93897eSTakashi Iwai hda_nid_t *pins, unsigned int action) 389403697e2aSTakashi Iwai { 389503697e2aSTakashi Iwai int i; 389603697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 38973a93897eSTakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], action); 389803697e2aSTakashi Iwai } 389903697e2aSTakashi Iwai 390007cafff2STakashi Iwai static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 390107cafff2STakashi Iwai { 390207cafff2STakashi Iwai int i; 390307cafff2STakashi Iwai for (i = 0; i < nums; i++) 390407cafff2STakashi Iwai if (list[i] == nid) 390507cafff2STakashi Iwai return true; 390607cafff2STakashi Iwai return false; 390707cafff2STakashi Iwai } 390807cafff2STakashi Iwai 390907cafff2STakashi Iwai /* is the given NID found in any of autocfg items? */ 391007cafff2STakashi Iwai static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) 391107cafff2STakashi Iwai { 391207cafff2STakashi Iwai int i; 391307cafff2STakashi Iwai 391407cafff2STakashi Iwai if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || 391507cafff2STakashi Iwai found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || 391607cafff2STakashi Iwai found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || 391707cafff2STakashi Iwai found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) 391807cafff2STakashi Iwai return true; 391907cafff2STakashi Iwai for (i = 0; i < cfg->num_inputs; i++) 392007cafff2STakashi Iwai if (cfg->inputs[i].pin == nid) 392107cafff2STakashi Iwai return true; 392207cafff2STakashi Iwai if (cfg->dig_in_pin == nid) 392307cafff2STakashi Iwai return true; 392407cafff2STakashi Iwai return false; 392507cafff2STakashi Iwai } 392607cafff2STakashi Iwai 392707cafff2STakashi Iwai /* clear unsol-event tags on unused pins; Conexant codecs seem to leave 392807cafff2STakashi Iwai * invalid unsol tags by some reason 392907cafff2STakashi Iwai */ 393007cafff2STakashi Iwai static void clear_unsol_on_unused_pins(struct hda_codec *codec) 393107cafff2STakashi Iwai { 393207cafff2STakashi Iwai struct conexant_spec *spec = codec->spec; 393307cafff2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 393407cafff2STakashi Iwai int i; 393507cafff2STakashi Iwai 393607cafff2STakashi Iwai for (i = 0; i < codec->init_pins.used; i++) { 393707cafff2STakashi Iwai struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 393807cafff2STakashi Iwai if (!found_in_autocfg(cfg, pin->nid)) 393907cafff2STakashi Iwai snd_hda_codec_write(codec, pin->nid, 0, 394007cafff2STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 0); 394107cafff2STakashi Iwai } 394207cafff2STakashi Iwai } 394307cafff2STakashi Iwai 3944527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */ 3945527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled) 3946527c73baSTakashi Iwai { 3947527c73baSTakashi Iwai struct hda_codec *codec = private_data; 3948527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 3949527c73baSTakashi Iwai 3950527c73baSTakashi Iwai if (enabled && spec->pin_eapd_ctrls) { 3951527c73baSTakashi Iwai cx_auto_update_speakers(codec); 3952527c73baSTakashi Iwai return; 3953527c73baSTakashi Iwai } 3954527c73baSTakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 3955527c73baSTakashi Iwai } 3956527c73baSTakashi Iwai 39571f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39581f8458a2STakashi Iwai { 39591f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39601f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39611f8458a2STakashi Iwai hda_nid_t nid; 39621f8458a2STakashi Iwai int i; 39631f8458a2STakashi Iwai 39641f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3965ca3649deSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 3966ca3649deSTakashi Iwai unsigned int val = PIN_OUT; 3967ca3649deSTakashi Iwai if (snd_hda_query_pin_caps(codec, cfg->hp_pins[i]) & 3968ca3649deSTakashi Iwai AC_PINCAP_HP_DRV) 3969ca3649deSTakashi Iwai val |= AC_PINCTL_HP_EN; 3970*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, cfg->hp_pins[i], val); 3971ca3649deSTakashi Iwai } 39721f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 39731f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 39741f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3975f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3976f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3977f2e5731dSTakashi Iwai if (!nid) 3978f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 39791f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 39801f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 3981f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3982f2e5731dSTakashi Iwai } 398303697e2aSTakashi Iwai if (spec->auto_mute) { 398403697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 398503697e2aSTakashi Iwai CONEXANT_HP_EVENT); 398603697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 398703697e2aSTakashi Iwai cfg->hp_pins); 398803697e2aSTakashi Iwai if (spec->detect_line) { 398903697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 399003697e2aSTakashi Iwai cfg->line_out_pins, 399103697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 399203697e2aSTakashi Iwai spec->line_present = 399303697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 399403697e2aSTakashi Iwai cfg->line_out_pins); 399503697e2aSTakashi Iwai } 399603697e2aSTakashi Iwai } 399703697e2aSTakashi Iwai cx_auto_update_speakers(codec); 3998254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 3999254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 400019110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 400107cafff2STakashi Iwai clear_unsol_on_unused_pins(codec); 4002f2e5731dSTakashi Iwai } 4003f2e5731dSTakashi Iwai 4004f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 4005f2e5731dSTakashi Iwai { 4006f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4007f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40080ad1b5b6STakashi Iwai int i, val; 4009f2e5731dSTakashi Iwai 40100ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 40110ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 40121f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 40131f8458a2STakashi Iwai continue; 40140ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 40150ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40160ad1b5b6STakashi Iwai else 40170ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40180ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40190ad1b5b6STakashi Iwai val); 40200ad1b5b6STakashi Iwai } 4021f2e5731dSTakashi Iwai 4022f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4023f2e5731dSTakashi Iwai unsigned int type; 4024f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4025f2e5731dSTakashi Iwai type = PIN_VREF80; 4026f2e5731dSTakashi Iwai else 4027f2e5731dSTakashi Iwai type = PIN_IN; 4028*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, cfg->inputs[i].pin, type); 4029f2e5731dSTakashi Iwai } 4030f2e5731dSTakashi Iwai 4031f2e5731dSTakashi Iwai if (spec->auto_mic) { 403243c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40331835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40341835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40351835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 403643c1b2e9STakashi Iwai } 403743c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40381835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40391835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40401835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 404143c1b2e9STakashi Iwai } 4042f2e5731dSTakashi Iwai cx_auto_automic(codec); 4043f2e5731dSTakashi Iwai } else { 404447ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 404547ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4046f2e5731dSTakashi Iwai } 4047f2e5731dSTakashi Iwai } 4048f2e5731dSTakashi Iwai 4049f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4050f2e5731dSTakashi Iwai { 4051f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4052f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4053f2e5731dSTakashi Iwai 4054f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4055*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, cfg->dig_out_pins[0], PIN_OUT); 4056f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4057*cdd03cedSTakashi Iwai snd_hda_set_pin_ctl(codec, cfg->dig_in_pin, PIN_IN); 4058f2e5731dSTakashi Iwai } 4059f2e5731dSTakashi Iwai 4060f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4061f2e5731dSTakashi Iwai { 4062527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 4063f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4064f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4065f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4066f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 406701a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4068d2f344b5STakashi Iwai snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4069f2e5731dSTakashi Iwai return 0; 4070f2e5731dSTakashi Iwai } 4071f2e5731dSTakashi Iwai 4072983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4073f2e5731dSTakashi Iwai const char *dir, int cidx, 407418dcd304SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx, int chs) 4075f2e5731dSTakashi Iwai { 407618dcd304SDavid Henningsson static char name[44]; 4077f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4078f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4079f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4080f2e5731dSTakashi Iwai }; 408134cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4082f2e5731dSTakashi Iwai int i, err; 4083f2e5731dSTakashi Iwai 4084f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4085f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 408618dcd304SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, chs, amp_idx, 4087983345e5SDavid Henningsson hda_dir); 4088f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4089f2e5731dSTakashi Iwai knew[i].index = cidx; 4090f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4091f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4092f2e5731dSTakashi Iwai if (!kctl) 4093f2e5731dSTakashi Iwai return -ENOMEM; 4094f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4095f2e5731dSTakashi Iwai if (err < 0) 4096f2e5731dSTakashi Iwai return err; 40973868137eSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & 40983868137eSTakashi Iwai (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) 4099f2e5731dSTakashi Iwai break; 4100f2e5731dSTakashi Iwai } 4101f2e5731dSTakashi Iwai return 0; 4102f2e5731dSTakashi Iwai } 4103f2e5731dSTakashi Iwai 4104983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 410518dcd304SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0, 3) 4106983345e5SDavid Henningsson 4107f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4108f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4109f2e5731dSTakashi Iwai 41101f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 41111f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 41121f8458a2STakashi Iwai { 41131f8458a2STakashi Iwai unsigned int caps; 4114468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 41151f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41161f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41171f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4118468c5458SDavid Henningsson } 41191f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41201f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41211f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41221f8458a2STakashi Iwai return 0; 41231f8458a2STakashi Iwai } 41241f8458a2STakashi Iwai 4125f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4126f2e5731dSTakashi Iwai { 4127f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4128f2e5731dSTakashi Iwai int i, err; 4129f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4130ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4131f2e5731dSTakashi Iwai 4132f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41331f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41341f8458a2STakashi Iwai spec->dac_info[0].pin, 4135f2e5731dSTakashi Iwai "Master", 0); 41361f8458a2STakashi Iwai 4137f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4138f2e5731dSTakashi Iwai const char *label; 4139f2e5731dSTakashi Iwai int idx, type; 41401f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4141f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4142f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4143f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4144f2e5731dSTakashi Iwai switch (type) { 4145f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4146f2e5731dSTakashi Iwai default: 4147f2e5731dSTakashi Iwai label = texts[num_line++]; 4148f2e5731dSTakashi Iwai idx = 0; 4149f2e5731dSTakashi Iwai break; 4150f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4151f2e5731dSTakashi Iwai label = "Headphone"; 4152f2e5731dSTakashi Iwai idx = num_hp++; 4153f2e5731dSTakashi Iwai break; 4154f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4155f2e5731dSTakashi Iwai label = "Speaker"; 4156f2e5731dSTakashi Iwai idx = num_spk++; 4157f2e5731dSTakashi Iwai break; 4158f2e5731dSTakashi Iwai } 41591f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41601f8458a2STakashi Iwai spec->dac_info[i].pin, 4161f2e5731dSTakashi Iwai label, idx); 4162f2e5731dSTakashi Iwai if (err < 0) 4163f2e5731dSTakashi Iwai return err; 4164f2e5731dSTakashi Iwai } 416503697e2aSTakashi Iwai 416603697e2aSTakashi Iwai if (spec->auto_mute) { 416703697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 416803697e2aSTakashi Iwai if (err < 0) 416903697e2aSTakashi Iwai return err; 417003697e2aSTakashi Iwai } 417103697e2aSTakashi Iwai 4172f2e5731dSTakashi Iwai return 0; 4173f2e5731dSTakashi Iwai } 4174f2e5731dSTakashi Iwai 417518dcd304SDavid Henningsson /* Returns zero if this is a normal stereo channel, and non-zero if it should 417618dcd304SDavid Henningsson be split in two independent channels. 417718dcd304SDavid Henningsson dest_label must be at least 44 characters. */ 417818dcd304SDavid Henningsson static int cx_auto_get_rightch_label(struct hda_codec *codec, const char *label, 417918dcd304SDavid Henningsson char *dest_label, int nid) 418018dcd304SDavid Henningsson { 418118dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 418218dcd304SDavid Henningsson int i; 418318dcd304SDavid Henningsson 418418dcd304SDavid Henningsson if (!spec->fixup_stereo_dmic) 418518dcd304SDavid Henningsson return 0; 418618dcd304SDavid Henningsson 418718dcd304SDavid Henningsson for (i = 0; i < AUTO_CFG_MAX_INS; i++) { 418818dcd304SDavid Henningsson int def_conf; 418918dcd304SDavid Henningsson if (spec->autocfg.inputs[i].pin != nid) 419018dcd304SDavid Henningsson continue; 419118dcd304SDavid Henningsson 419218dcd304SDavid Henningsson if (spec->autocfg.inputs[i].type != AUTO_PIN_MIC) 419318dcd304SDavid Henningsson return 0; 419418dcd304SDavid Henningsson def_conf = snd_hda_codec_get_pincfg(codec, nid); 419518dcd304SDavid Henningsson if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) 419618dcd304SDavid Henningsson return 0; 419718dcd304SDavid Henningsson 419818dcd304SDavid Henningsson /* Finally found the inverted internal mic! */ 419918dcd304SDavid Henningsson snprintf(dest_label, 44, "Inverted %s", label); 420018dcd304SDavid Henningsson return 1; 420118dcd304SDavid Henningsson } 420218dcd304SDavid Henningsson return 0; 420318dcd304SDavid Henningsson } 420418dcd304SDavid Henningsson 42056764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 42066764bcefSTakashi Iwai const char *label, const char *pfx, 42076764bcefSTakashi Iwai int cidx) 42086764bcefSTakashi Iwai { 42096764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 42106764bcefSTakashi Iwai int i; 42116764bcefSTakashi Iwai 42126764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 421318dcd304SDavid Henningsson char rightch_label[44]; 42146764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 42155c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 42166764bcefSTakashi Iwai if (idx < 0) 42176764bcefSTakashi Iwai continue; 42184f32456eSMichael Karcher if (codec->single_adc_amp) 42196b452142STakashi Iwai idx = 0; 422018dcd304SDavid Henningsson 422118dcd304SDavid Henningsson if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 422218dcd304SDavid Henningsson /* Make two independent kcontrols for left and right */ 422318dcd304SDavid Henningsson int err = cx_auto_add_volume_idx(codec, label, pfx, 422418dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 1); 422518dcd304SDavid Henningsson if (err < 0) 422618dcd304SDavid Henningsson return err; 422718dcd304SDavid Henningsson return cx_auto_add_volume_idx(codec, rightch_label, pfx, 422818dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 2); 422918dcd304SDavid Henningsson } 42306764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 423118dcd304SDavid Henningsson cidx, adc_nid, HDA_INPUT, idx, 3); 42326764bcefSTakashi Iwai } 42336764bcefSTakashi Iwai return 0; 42346764bcefSTakashi Iwai } 42356764bcefSTakashi Iwai 4236cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4237cf27f29aSTakashi Iwai const char *label, int cidx) 4238cf27f29aSTakashi Iwai { 4239cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4240cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4241f9759301STakashi Iwai int i, con; 4242cf27f29aSTakashi Iwai 424347ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 424418dcd304SDavid Henningsson if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) { 424518dcd304SDavid Henningsson char rightch_label[44]; 424618dcd304SDavid Henningsson if (cx_auto_get_rightch_label(codec, label, rightch_label, nid)) { 424718dcd304SDavid Henningsson int err = cx_auto_add_volume_idx(codec, label, " Boost", 424818dcd304SDavid Henningsson cidx, nid, HDA_INPUT, 0, 1); 424918dcd304SDavid Henningsson if (err < 0) 425018dcd304SDavid Henningsson return err; 425118dcd304SDavid Henningsson return cx_auto_add_volume_idx(codec, rightch_label, " Boost", 425218dcd304SDavid Henningsson cidx, nid, HDA_INPUT, 0, 2); 425318dcd304SDavid Henningsson } 4254cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4255cf27f29aSTakashi Iwai nid, HDA_INPUT); 425618dcd304SDavid Henningsson } 425747ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 425847ad1f4eSTakashi Iwai &mux, false, 0); 4259cf27f29aSTakashi Iwai if (con < 0) 4260cf27f29aSTakashi Iwai return 0; 4261f9759301STakashi Iwai for (i = 0; i < idx; i++) { 426247ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4263f9759301STakashi Iwai return 0; /* already present */ 4264f9759301STakashi Iwai } 4265f9759301STakashi Iwai 4266f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 426747ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4268cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4269cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4270f9759301STakashi Iwai } 4271cf27f29aSTakashi Iwai return 0; 4272cf27f29aSTakashi Iwai } 4273cf27f29aSTakashi Iwai 4274f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4275f2e5731dSTakashi Iwai { 4276f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4277cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4278cf27f29aSTakashi Iwai const char *prev_label; 4279cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42806b452142STakashi Iwai int i, j, err, cidx; 4281cf27f29aSTakashi Iwai int multi_connection; 4282cf27f29aSTakashi Iwai 42836b452142STakashi Iwai if (!imux->num_items) 42846b452142STakashi Iwai return 0; 42856b452142STakashi Iwai 4286cf27f29aSTakashi Iwai multi_connection = 0; 4287cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 428847ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 428947ad1f4eSTakashi Iwai spec->imux_info[i].pin); 42906b452142STakashi Iwai if (cidx < 0) 42916b452142STakashi Iwai continue; 42926b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 42934f32456eSMichael Karcher if (!codec->single_adc_amp) 42946b452142STakashi Iwai input_conn[i] |= cidx << 8; 4295cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4296cf27f29aSTakashi Iwai multi_connection = 1; 4297cf27f29aSTakashi Iwai } 4298983345e5SDavid Henningsson 4299f2e5731dSTakashi Iwai prev_label = NULL; 4300f2e5731dSTakashi Iwai cidx = 0; 4301cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 430247ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4303f2e5731dSTakashi Iwai const char *label; 4304983345e5SDavid Henningsson 4305cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 430647ad1f4eSTakashi Iwai spec->imux_info[i].index); 4307f2e5731dSTakashi Iwai if (label == prev_label) 4308f2e5731dSTakashi Iwai cidx++; 4309f2e5731dSTakashi Iwai else 4310f2e5731dSTakashi Iwai cidx = 0; 4311f2e5731dSTakashi Iwai prev_label = label; 4312983345e5SDavid Henningsson 4313cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4314f2e5731dSTakashi Iwai if (err < 0) 4315f2e5731dSTakashi Iwai return err; 4316983345e5SDavid Henningsson 4317cf27f29aSTakashi Iwai if (!multi_connection) { 4318f9759301STakashi Iwai if (i > 0) 4319f9759301STakashi Iwai continue; 43206764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43216764bcefSTakashi Iwai "Capture", "", cidx); 43226764bcefSTakashi Iwai } else { 43236b452142STakashi Iwai bool dup_found = false; 43246b452142STakashi Iwai for (j = 0; j < i; j++) { 43256b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 43266b452142STakashi Iwai dup_found = true; 43276b452142STakashi Iwai break; 43286b452142STakashi Iwai } 43296b452142STakashi Iwai } 43306b452142STakashi Iwai if (dup_found) 43316b452142STakashi Iwai continue; 43326764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43336764bcefSTakashi Iwai label, " Capture", cidx); 43346764bcefSTakashi Iwai } 4335983345e5SDavid Henningsson if (err < 0) 4336983345e5SDavid Henningsson return err; 4337983345e5SDavid Henningsson } 43386764bcefSTakashi Iwai 43396764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 43406764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 43416764bcefSTakashi Iwai if (err < 0) 43426764bcefSTakashi Iwai return err; 4343983345e5SDavid Henningsson } 43446764bcefSTakashi Iwai 4345f2e5731dSTakashi Iwai return 0; 4346f2e5731dSTakashi Iwai } 4347f2e5731dSTakashi Iwai 4348f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4349f2e5731dSTakashi Iwai { 435031ef2257STakashi Iwai struct conexant_spec *spec = codec->spec; 4351f2e5731dSTakashi Iwai int err; 4352f2e5731dSTakashi Iwai 4353f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4354f2e5731dSTakashi Iwai if (err < 0) 4355f2e5731dSTakashi Iwai return err; 4356f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4357f2e5731dSTakashi Iwai if (err < 0) 4358f2e5731dSTakashi Iwai return err; 435931ef2257STakashi Iwai err = conexant_build_controls(codec); 436031ef2257STakashi Iwai if (err < 0) 436131ef2257STakashi Iwai return err; 436231ef2257STakashi Iwai err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 436331ef2257STakashi Iwai if (err < 0) 436431ef2257STakashi Iwai return err; 4365f29735cbSTakashi Iwai if (spec->vmaster_mute.sw_kctl) { 4366f29735cbSTakashi Iwai spec->vmaster_mute.hook = cx_auto_vmaster_hook; 4367f29735cbSTakashi Iwai err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4368f29735cbSTakashi Iwai spec->vmaster_mute_led); 4369d2f344b5STakashi Iwai if (err < 0) 4370d2f344b5STakashi Iwai return err; 4371527c73baSTakashi Iwai } 437231ef2257STakashi Iwai return 0; 4373f2e5731dSTakashi Iwai } 4374f2e5731dSTakashi Iwai 437522ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 437622ce5f74STakashi Iwai { 437722ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 437822ce5f74STakashi Iwai hda_nid_t nid, end_nid; 437922ce5f74STakashi Iwai 438022ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 438122ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 438222ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 438322ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 438422ce5f74STakashi Iwai continue; 438522ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 438622ce5f74STakashi Iwai continue; 438722ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 438822ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 438922ce5f74STakashi Iwai break; 439022ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 439122ce5f74STakashi Iwai } 439222ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 439322ce5f74STakashi Iwai return 0; 439422ce5f74STakashi Iwai } 439522ce5f74STakashi Iwai 439634cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4397f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4398f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4399f2e5731dSTakashi Iwai .init = cx_auto_init, 4400f2e5731dSTakashi Iwai .free = conexant_free, 4401f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4402f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4403f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4404f2e5731dSTakashi Iwai #endif 4405f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4406f2e5731dSTakashi Iwai }; 4407f2e5731dSTakashi Iwai 4408e92d4b08STakashi Iwai /* 4409e92d4b08STakashi Iwai * pin fix-up 4410e92d4b08STakashi Iwai */ 4411e92d4b08STakashi Iwai struct cxt_pincfg { 4412e92d4b08STakashi Iwai hda_nid_t nid; 4413e92d4b08STakashi Iwai u32 val; 4414e92d4b08STakashi Iwai }; 4415e92d4b08STakashi Iwai 4416e92d4b08STakashi Iwai static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4417e92d4b08STakashi Iwai { 4418e92d4b08STakashi Iwai for (; cfg->nid; cfg++) 4419e92d4b08STakashi Iwai snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4420e92d4b08STakashi Iwai 4421e92d4b08STakashi Iwai } 4422e92d4b08STakashi Iwai 442318dcd304SDavid Henningsson enum { 442418dcd304SDavid Henningsson CXT_PINCFG_LENOVO_X200, 4425d3980110STakashi Iwai CXT_PINCFG_LENOVO_TP410, 442618dcd304SDavid Henningsson CXT_FIXUP_STEREO_DMIC, 442718dcd304SDavid Henningsson }; 442818dcd304SDavid Henningsson 442918dcd304SDavid Henningsson static void apply_fixup(struct hda_codec *codec, 4430e92d4b08STakashi Iwai const struct snd_pci_quirk *quirk, 4431e92d4b08STakashi Iwai const struct cxt_pincfg **table) 4432e92d4b08STakashi Iwai { 443318dcd304SDavid Henningsson struct conexant_spec *spec = codec->spec; 443418dcd304SDavid Henningsson 4435e92d4b08STakashi Iwai quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 443683b0c6baSDavid Henningsson if (!quirk) 443783b0c6baSDavid Henningsson return; 443883b0c6baSDavid Henningsson if (table[quirk->value]) { 4439e92d4b08STakashi Iwai snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4440e92d4b08STakashi Iwai quirk->name); 4441e92d4b08STakashi Iwai apply_pincfg(codec, table[quirk->value]); 4442e92d4b08STakashi Iwai } 444318dcd304SDavid Henningsson if (quirk->value == CXT_FIXUP_STEREO_DMIC) { 444418dcd304SDavid Henningsson snd_printdd(KERN_INFO "hda_codec: applying internal mic workaround for %s\n", 444518dcd304SDavid Henningsson quirk->name); 444618dcd304SDavid Henningsson spec->fixup_stereo_dmic = 1; 4447e92d4b08STakashi Iwai } 444818dcd304SDavid Henningsson } 4449e92d4b08STakashi Iwai 4450d70f3632STakashi Iwai /* ThinkPad X200 & co with cxt5051 */ 4451e92d4b08STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4452e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4453e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 4454e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 44553e93f5efSTakashi Iwai { 0x1c, 0x21440100 }, /* dock SPDIF out */ 4456e92d4b08STakashi Iwai {} 4457e92d4b08STakashi Iwai }; 4458e92d4b08STakashi Iwai 4459d70f3632STakashi Iwai /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */ 4460d70f3632STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_tp410[] = { 4461d70f3632STakashi Iwai { 0x19, 0x042110ff }, /* HP (seq# overridden) */ 4462d70f3632STakashi Iwai { 0x1a, 0x21a190f0 }, /* dock-mic */ 4463d70f3632STakashi Iwai { 0x1c, 0x212140ff }, /* dock-HP */ 4464d70f3632STakashi Iwai {} 4465e92d4b08STakashi Iwai }; 4466e92d4b08STakashi Iwai 4467e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4468e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4469d70f3632STakashi Iwai [CXT_PINCFG_LENOVO_TP410] = cxt_pincfg_lenovo_tp410, 447018dcd304SDavid Henningsson [CXT_FIXUP_STEREO_DMIC] = NULL, 4471e92d4b08STakashi Iwai }; 4472e92d4b08STakashi Iwai 4473d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = { 4474e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4475e92d4b08STakashi Iwai {} 4476e92d4b08STakashi Iwai }; 4477e92d4b08STakashi Iwai 4478d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = { 4479d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410), 4480d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410), 4481d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410), 4482d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410), 4483d70f3632STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 448418dcd304SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 4485f2e5731dSTakashi Iwai {} 4486f2e5731dSTakashi Iwai }; 4487f2e5731dSTakashi Iwai 44883868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 44893868137eSTakashi Iwai * can be created (bko#42825) 44903868137eSTakashi Iwai */ 44913868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec) 44923868137eSTakashi Iwai { 44933868137eSTakashi Iwai static hda_nid_t out_nids[] = { 44943868137eSTakashi Iwai 0x10, 0x11, 0 44953868137eSTakashi Iwai }; 44963868137eSTakashi Iwai hda_nid_t *p; 44973868137eSTakashi Iwai 44983868137eSTakashi Iwai for (p = out_nids; *p; p++) 44993868137eSTakashi Iwai snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 45003868137eSTakashi Iwai AC_AMPCAP_MIN_MUTE | 45013868137eSTakashi Iwai query_amp_caps(codec, *p, HDA_OUTPUT)); 45023868137eSTakashi Iwai } 45033868137eSTakashi Iwai 4504f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4505f2e5731dSTakashi Iwai { 4506f2e5731dSTakashi Iwai struct conexant_spec *spec; 4507f2e5731dSTakashi Iwai int err; 4508f2e5731dSTakashi Iwai 45091f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 45101f8458a2STakashi Iwai codec->chip_name); 45111f8458a2STakashi Iwai 4512f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4513f2e5731dSTakashi Iwai if (!spec) 4514f2e5731dSTakashi Iwai return -ENOMEM; 4515f2e5731dSTakashi Iwai codec->spec = spec; 4516e92d4b08STakashi Iwai 45176b452142STakashi Iwai switch (codec->vendor_id) { 45186b452142STakashi Iwai case 0x14f15045: 45194f32456eSMichael Karcher codec->single_adc_amp = 1; 45206b452142STakashi Iwai break; 45213868137eSTakashi Iwai case 0x14f15051: 45223868137eSTakashi Iwai add_cx5051_fake_mutes(codec); 452351969d62SMichael Karcher codec->pin_amp_workaround = 1; 4524d3980110STakashi Iwai apply_fixup(codec, cxt5051_fixups, cxt_pincfg_tbl); 45253868137eSTakashi Iwai break; 452651969d62SMichael Karcher default: 452751969d62SMichael Karcher codec->pin_amp_workaround = 1; 4528d3980110STakashi Iwai apply_fixup(codec, cxt5066_fixups, cxt_pincfg_tbl); 45296b452142STakashi Iwai } 45306b452142STakashi Iwai 4531f29735cbSTakashi Iwai /* Show mute-led control only on HP laptops 4532f29735cbSTakashi Iwai * This is a sort of white-list: on HP laptops, EAPD corresponds 4533f29735cbSTakashi Iwai * only to the mute-LED without actualy amp function. Meanwhile, 4534f29735cbSTakashi Iwai * others may use EAPD really as an amp switch, so it might be 4535f29735cbSTakashi Iwai * not good to expose it blindly. 4536527c73baSTakashi Iwai */ 4537f29735cbSTakashi Iwai switch (codec->subsystem_id >> 16) { 4538f29735cbSTakashi Iwai case 0x103c: 4539f29735cbSTakashi Iwai spec->vmaster_mute_led = 1; 4540f29735cbSTakashi Iwai break; 4541f29735cbSTakashi Iwai } 4542527c73baSTakashi Iwai 454322ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 454422ce5f74STakashi Iwai if (err < 0) 454522ce5f74STakashi Iwai return err; 4546f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4547f2e5731dSTakashi Iwai if (err < 0) { 4548f2e5731dSTakashi Iwai kfree(codec->spec); 4549f2e5731dSTakashi Iwai codec->spec = NULL; 4550f2e5731dSTakashi Iwai return err; 4551f2e5731dSTakashi Iwai } 45526764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4553f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4554f2e5731dSTakashi Iwai if (spec->beep_amp) 4555f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 45564f2864a4STakashi Iwai 45574f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 45584f2864a4STakashi Iwai * which falls into the single-cmd mode. 45594f2864a4STakashi Iwai * Better to make reset, then. 45604f2864a4STakashi Iwai */ 45614f2864a4STakashi Iwai if (!codec->bus->sync_write) { 45624f2864a4STakashi Iwai snd_printd("hda_codec: " 45634f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 45644f2864a4STakashi Iwai codec->bus->sync_write = 1; 45654f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 45664f2864a4STakashi Iwai } 45674f2864a4STakashi Iwai 4568f2e5731dSTakashi Iwai return 0; 4569f2e5731dSTakashi Iwai } 4570f2e5731dSTakashi Iwai 4571f2e5731dSTakashi Iwai /* 4572461e2c78STakashi Iwai */ 4573461e2c78STakashi Iwai 457434cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 457582f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 457682f30040STobin Davis .patch = patch_cxt5045 }, 457782f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 457882f30040STobin Davis .patch = patch_cxt5047 }, 4579461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4580461e2c78STakashi Iwai .patch = patch_cxt5051 }, 45810fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 45820fb67e98SDaniel Drake .patch = patch_cxt5066 }, 458395a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 458495a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4585850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4586850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 45877b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 45887b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4589f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4590f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 45916da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 45926da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4593f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4594f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4595f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4596f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4597f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4598f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4599f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4600f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4601f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4602f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4603f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4604f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4605f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4606f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4607f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4608f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4609c9b443d4STobin Davis {} /* terminator */ 4610c9b443d4STobin Davis }; 46111289e9e8STakashi Iwai 46121289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 46131289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 46141289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 46150fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 461695a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4617850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 46187b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4619f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 46206da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4621f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4622f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4623f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4624f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4625f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4626f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4627f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4628f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 46291289e9e8STakashi Iwai 46301289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 46311289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 46321289e9e8STakashi Iwai 46331289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 46341289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 46351289e9e8STakashi Iwai .owner = THIS_MODULE, 46361289e9e8STakashi Iwai }; 46371289e9e8STakashi Iwai 46381289e9e8STakashi Iwai static int __init patch_conexant_init(void) 46391289e9e8STakashi Iwai { 46401289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 46411289e9e8STakashi Iwai } 46421289e9e8STakashi Iwai 46431289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 46441289e9e8STakashi Iwai { 46451289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 46461289e9e8STakashi Iwai } 46471289e9e8STakashi Iwai 46481289e9e8STakashi Iwai module_init(patch_conexant_init) 46491289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4650