1c9b443d4STobin Davis /* 2c9b443d4STobin Davis * HD audio interface patch for Conexant HDA audio codec 3c9b443d4STobin Davis * 4c9b443d4STobin Davis * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5c9b443d4STobin Davis * Takashi Iwai <tiwai@suse.de> 6c9b443d4STobin Davis * Tobin Davis <tdavis@dsl-only.net> 7c9b443d4STobin Davis * 8c9b443d4STobin Davis * This driver is free software; you can redistribute it and/or modify 9c9b443d4STobin Davis * it under the terms of the GNU General Public License as published by 10c9b443d4STobin Davis * the Free Software Foundation; either version 2 of the License, or 11c9b443d4STobin Davis * (at your option) any later version. 12c9b443d4STobin Davis * 13c9b443d4STobin Davis * This driver is distributed in the hope that it will be useful, 14c9b443d4STobin Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9b443d4STobin Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9b443d4STobin Davis * GNU General Public License for more details. 17c9b443d4STobin Davis * 18c9b443d4STobin Davis * You should have received a copy of the GNU General Public License 19c9b443d4STobin Davis * along with this program; if not, write to the Free Software 20c9b443d4STobin Davis * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c9b443d4STobin Davis */ 22c9b443d4STobin Davis 23c9b443d4STobin Davis #include <linux/init.h> 24c9b443d4STobin Davis #include <linux/delay.h> 25c9b443d4STobin Davis #include <linux/slab.h> 26c9b443d4STobin Davis #include <linux/pci.h> 27c9b443d4STobin Davis #include <sound/core.h> 28bc7a166dSUlrich Dangel #include <sound/jack.h> 29bc7a166dSUlrich Dangel 30c9b443d4STobin Davis #include "hda_codec.h" 31c9b443d4STobin Davis #include "hda_local.h" 32c0f8faf0SEinar Rünkaru #include "hda_beep.h" 33c9b443d4STobin Davis 34c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 39c9b443d4STobin Davis 40c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 4203697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT 0x39 43c9b443d4STobin Davis 44bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 45c9b443d4STobin Davis 46ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT 0x12 47bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 48bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 49bc7a166dSUlrich Dangel 50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB (1 << 1) 51faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC (1 << 2) 52bc7a166dSUlrich Dangel 53f2e5731dSTakashi Iwai struct pin_dac_pair { 54f2e5731dSTakashi Iwai hda_nid_t pin; 55f2e5731dSTakashi Iwai hda_nid_t dac; 56f2e5731dSTakashi Iwai int type; 57f2e5731dSTakashi Iwai }; 58f2e5731dSTakashi Iwai 5947ad1f4eSTakashi Iwai struct imux_info { 6047ad1f4eSTakashi Iwai hda_nid_t pin; /* input pin NID */ 6147ad1f4eSTakashi Iwai hda_nid_t adc; /* connected ADC NID */ 6247ad1f4eSTakashi Iwai hda_nid_t boost; /* optional boost volume NID */ 6347ad1f4eSTakashi Iwai int index; /* corresponding to autocfg.input */ 6447ad1f4eSTakashi Iwai }; 6547ad1f4eSTakashi Iwai 66c9b443d4STobin Davis struct conexant_spec { 67c9b443d4STobin Davis 6834cbe3a6STakashi Iwai const struct snd_kcontrol_new *mixers[5]; 69c9b443d4STobin Davis int num_mixers; 70dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 71c9b443d4STobin Davis 72c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 73c9b443d4STobin Davis * don't forget NULL 74c9b443d4STobin Davis * termination! 75c9b443d4STobin Davis */ 76c9b443d4STobin Davis unsigned int num_init_verbs; 77c9b443d4STobin Davis 78c9b443d4STobin Davis /* playback */ 79c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 80c9b443d4STobin Davis * max_channels, dacs must be set 81c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 82c9b443d4STobin Davis */ 83c9b443d4STobin Davis unsigned int cur_eapd; 8482f30040STobin Davis unsigned int hp_present; 8503697e2aSTakashi Iwai unsigned int line_present; 86faddaa5dSTakashi Iwai unsigned int auto_mic; 87f6100bb4STakashi Iwai int auto_mic_ext; /* imux_pins[] index for ext mic */ 8843c1b2e9STakashi Iwai int auto_mic_dock; /* imux_pins[] index for dock mic */ 8943c1b2e9STakashi Iwai int auto_mic_int; /* imux_pins[] index for int mic */ 90c9b443d4STobin Davis unsigned int need_dac_fix; 91f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 92c9b443d4STobin Davis 93c9b443d4STobin Davis /* capture */ 94c9b443d4STobin Davis unsigned int num_adc_nids; 9534cbe3a6STakashi Iwai const hda_nid_t *adc_nids; 96c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 97c9b443d4STobin Davis 98461e2c78STakashi Iwai unsigned int cur_adc_idx; 99461e2c78STakashi Iwai hda_nid_t cur_adc; 100461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 101461e2c78STakashi Iwai unsigned int cur_adc_format; 102461e2c78STakashi Iwai 1036764bcefSTakashi Iwai const struct hda_pcm_stream *capture_stream; 1046764bcefSTakashi Iwai 105c9b443d4STobin Davis /* capture source */ 106c9b443d4STobin Davis const struct hda_input_mux *input_mux; 10734cbe3a6STakashi Iwai const hda_nid_t *capsrc_nids; 108c9b443d4STobin Davis unsigned int cur_mux[3]; 109c9b443d4STobin Davis 110c9b443d4STobin Davis /* channel model */ 111c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 112c9b443d4STobin Davis int num_channel_mode; 113c9b443d4STobin Davis 114c9b443d4STobin Davis /* PCM information */ 115c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 116c9b443d4STobin Davis 117c9b443d4STobin Davis unsigned int spdif_route; 118c9b443d4STobin Davis 119c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 120c9b443d4STobin Davis struct auto_pin_cfg autocfg; 121c9b443d4STobin Davis struct hda_input_mux private_imux; 12247ad1f4eSTakashi Iwai struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; 12322ce5f74STakashi Iwai hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 12441923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 125f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 126f2e5731dSTakashi Iwai int dac_info_filled; 127c9b443d4STobin Davis 1280fb67e98SDaniel Drake unsigned int port_d_mode; 129f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 13003697e2aSTakashi Iwai unsigned int detect_line:1; /* Line-out detection enabled */ 13103697e2aSTakashi Iwai unsigned int automute_lines:1; /* automute line-out as well */ 13203697e2aSTakashi Iwai unsigned int automute_hp_lo:1; /* both HP and LO available */ 133f2e5731dSTakashi Iwai unsigned int dell_automute:1; 134cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 135cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1367b2bfdbcSJens Taprogge unsigned int thinkpad:1; 137048e78a5SDavid Henningsson unsigned int hp_laptop:1; 138a1d6906eSDavid Henningsson unsigned int asus:1; 13975f8991dSDaniel Drake 1406764bcefSTakashi Iwai unsigned int adc_switching:1; 1416764bcefSTakashi Iwai 14275f8991dSDaniel Drake unsigned int ext_mic_present; 14375f8991dSDaniel Drake unsigned int recording; 14475f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 14575f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 146c4cfe66cSDaniel Drake 147c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 148c4cfe66cSDaniel Drake * through the microphone jack. 149c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 150c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 151c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 152c4cfe66cSDaniel Drake * control. */ 153c4cfe66cSDaniel Drake unsigned int dc_enable; 154c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 155c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1563507e2a8STakashi Iwai 1573507e2a8STakashi Iwai unsigned int beep_amp; 15819110595STakashi Iwai 15919110595STakashi Iwai /* extra EAPD pins */ 16019110595STakashi Iwai unsigned int num_eapds; 16119110595STakashi Iwai hda_nid_t eapds[4]; 162c9b443d4STobin Davis }; 163c9b443d4STobin Davis 164c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 165c9b443d4STobin Davis struct hda_codec *codec, 166c9b443d4STobin Davis struct snd_pcm_substream *substream) 167c9b443d4STobin Davis { 168c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1699a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1709a08160bSTakashi Iwai hinfo); 171c9b443d4STobin Davis } 172c9b443d4STobin Davis 173c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 174c9b443d4STobin Davis struct hda_codec *codec, 175c9b443d4STobin Davis unsigned int stream_tag, 176c9b443d4STobin Davis unsigned int format, 177c9b443d4STobin Davis struct snd_pcm_substream *substream) 178c9b443d4STobin Davis { 179c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 180c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 181c9b443d4STobin Davis stream_tag, 182c9b443d4STobin Davis format, substream); 183c9b443d4STobin Davis } 184c9b443d4STobin Davis 185c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 186c9b443d4STobin Davis struct hda_codec *codec, 187c9b443d4STobin Davis struct snd_pcm_substream *substream) 188c9b443d4STobin Davis { 189c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 190c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 191c9b443d4STobin Davis } 192c9b443d4STobin Davis 193c9b443d4STobin Davis /* 194c9b443d4STobin Davis * Digital out 195c9b443d4STobin Davis */ 196c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 197c9b443d4STobin Davis struct hda_codec *codec, 198c9b443d4STobin Davis struct snd_pcm_substream *substream) 199c9b443d4STobin Davis { 200c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 201c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 202c9b443d4STobin Davis } 203c9b443d4STobin Davis 204c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 205c9b443d4STobin Davis struct hda_codec *codec, 206c9b443d4STobin Davis struct snd_pcm_substream *substream) 207c9b443d4STobin Davis { 208c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 209c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 210c9b443d4STobin Davis } 211c9b443d4STobin Davis 2126b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2136b97eb45STakashi Iwai struct hda_codec *codec, 2146b97eb45STakashi Iwai unsigned int stream_tag, 2156b97eb45STakashi Iwai unsigned int format, 2166b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2176b97eb45STakashi Iwai { 2186b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2196b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2206b97eb45STakashi Iwai stream_tag, 2216b97eb45STakashi Iwai format, substream); 2226b97eb45STakashi Iwai } 2236b97eb45STakashi Iwai 224c9b443d4STobin Davis /* 225c9b443d4STobin Davis * Analog capture 226c9b443d4STobin Davis */ 227c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 228c9b443d4STobin Davis struct hda_codec *codec, 229c9b443d4STobin Davis unsigned int stream_tag, 230c9b443d4STobin Davis unsigned int format, 231c9b443d4STobin Davis struct snd_pcm_substream *substream) 232c9b443d4STobin Davis { 233c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 23475f8991dSDaniel Drake if (spec->capture_prepare) 23575f8991dSDaniel Drake spec->capture_prepare(codec); 236c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 237c9b443d4STobin Davis stream_tag, 0, format); 238c9b443d4STobin Davis return 0; 239c9b443d4STobin Davis } 240c9b443d4STobin Davis 241c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 242c9b443d4STobin Davis struct hda_codec *codec, 243c9b443d4STobin Davis struct snd_pcm_substream *substream) 244c9b443d4STobin Davis { 245c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 246888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 24775f8991dSDaniel Drake if (spec->capture_cleanup) 24875f8991dSDaniel Drake spec->capture_cleanup(codec); 249c9b443d4STobin Davis return 0; 250c9b443d4STobin Davis } 251c9b443d4STobin Davis 252c9b443d4STobin Davis 253c9b443d4STobin Davis 25434cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 255c9b443d4STobin Davis .substreams = 1, 256c9b443d4STobin Davis .channels_min = 2, 257c9b443d4STobin Davis .channels_max = 2, 258c9b443d4STobin Davis .nid = 0, /* fill later */ 259c9b443d4STobin Davis .ops = { 260c9b443d4STobin Davis .open = conexant_playback_pcm_open, 261c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 262c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 263c9b443d4STobin Davis }, 264c9b443d4STobin Davis }; 265c9b443d4STobin Davis 26634cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 267c9b443d4STobin Davis .substreams = 1, 268c9b443d4STobin Davis .channels_min = 2, 269c9b443d4STobin Davis .channels_max = 2, 270c9b443d4STobin Davis .nid = 0, /* fill later */ 271c9b443d4STobin Davis .ops = { 272c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 273c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 274c9b443d4STobin Davis }, 275c9b443d4STobin Davis }; 276c9b443d4STobin Davis 277c9b443d4STobin Davis 27834cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 279c9b443d4STobin Davis .substreams = 1, 280c9b443d4STobin Davis .channels_min = 2, 281c9b443d4STobin Davis .channels_max = 2, 282c9b443d4STobin Davis .nid = 0, /* fill later */ 283c9b443d4STobin Davis .ops = { 284c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2856b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2866b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 287c9b443d4STobin Davis }, 288c9b443d4STobin Davis }; 289c9b443d4STobin Davis 29034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 291c9b443d4STobin Davis .substreams = 1, 292c9b443d4STobin Davis .channels_min = 2, 293c9b443d4STobin Davis .channels_max = 2, 294c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 295c9b443d4STobin Davis }; 296c9b443d4STobin Davis 297461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 298461e2c78STakashi Iwai struct hda_codec *codec, 299461e2c78STakashi Iwai unsigned int stream_tag, 300461e2c78STakashi Iwai unsigned int format, 301461e2c78STakashi Iwai struct snd_pcm_substream *substream) 302461e2c78STakashi Iwai { 303461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 304461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 305461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 306461e2c78STakashi Iwai spec->cur_adc_format = format; 307461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 308461e2c78STakashi Iwai return 0; 309461e2c78STakashi Iwai } 310461e2c78STakashi Iwai 311461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 312461e2c78STakashi Iwai struct hda_codec *codec, 313461e2c78STakashi Iwai struct snd_pcm_substream *substream) 314461e2c78STakashi Iwai { 315461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 316888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 317461e2c78STakashi Iwai spec->cur_adc = 0; 318461e2c78STakashi Iwai return 0; 319461e2c78STakashi Iwai } 320461e2c78STakashi Iwai 32134cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 322461e2c78STakashi Iwai .substreams = 1, 323461e2c78STakashi Iwai .channels_min = 2, 324461e2c78STakashi Iwai .channels_max = 2, 325461e2c78STakashi Iwai .nid = 0, /* fill later */ 326461e2c78STakashi Iwai .ops = { 327461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 328461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 329461e2c78STakashi Iwai }, 330461e2c78STakashi Iwai }; 331461e2c78STakashi Iwai 332c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 333c9b443d4STobin Davis { 334c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 335c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 336c9b443d4STobin Davis 337c9b443d4STobin Davis codec->num_pcms = 1; 338c9b443d4STobin Davis codec->pcm_info = info; 339c9b443d4STobin Davis 340c9b443d4STobin Davis info->name = "CONEXANT Analog"; 341c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 342c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 343c9b443d4STobin Davis spec->multiout.max_channels; 344c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 345c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3466764bcefSTakashi Iwai if (spec->capture_stream) 3476764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3486764bcefSTakashi Iwai else { 349461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 350461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 351461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3526764bcefSTakashi Iwai else { 353461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 354461e2c78STakashi Iwai conexant_pcm_analog_capture; 3556764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3566764bcefSTakashi Iwai spec->num_adc_nids; 3576764bcefSTakashi Iwai } 3586764bcefSTakashi Iwai } 359c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 360c9b443d4STobin Davis 361c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 362c9b443d4STobin Davis info++; 363c9b443d4STobin Davis codec->num_pcms++; 364c9b443d4STobin Davis info->name = "Conexant Digital"; 3657ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 366c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 367c9b443d4STobin Davis conexant_pcm_digital_playback; 368c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 369c9b443d4STobin Davis spec->multiout.dig_out_nid; 370c9b443d4STobin Davis if (spec->dig_in_nid) { 371c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 372c9b443d4STobin Davis conexant_pcm_digital_capture; 373c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 374c9b443d4STobin Davis spec->dig_in_nid; 375c9b443d4STobin Davis } 376f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 377f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 378c9b443d4STobin Davis } 379c9b443d4STobin Davis 380c9b443d4STobin Davis return 0; 381c9b443d4STobin Davis } 382c9b443d4STobin Davis 383c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 384c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 385c9b443d4STobin Davis { 386c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 387c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 388c9b443d4STobin Davis 389c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 390c9b443d4STobin Davis } 391c9b443d4STobin Davis 392c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 393c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 394c9b443d4STobin Davis { 395c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 396c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 397c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 398c9b443d4STobin Davis 399c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 400c9b443d4STobin Davis return 0; 401c9b443d4STobin Davis } 402c9b443d4STobin Davis 403c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 404c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 405c9b443d4STobin Davis { 406c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 407c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 408c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 409c9b443d4STobin Davis 410c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 411c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 412c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 413c9b443d4STobin Davis } 414c9b443d4STobin Davis 415bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 416bc7a166dSUlrich Dangel { 417cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 418bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 419bc7a166dSUlrich Dangel int i; 420bc7a166dSUlrich Dangel 421bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 422bc7a166dSUlrich Dangel const struct hda_verb *hv; 423bc7a166dSUlrich Dangel 424bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 425bc7a166dSUlrich Dangel while (hv->nid) { 426bc7a166dSUlrich Dangel int err = 0; 427bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 428bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 429cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 430cd372fb3STakashi Iwai SND_JACK_HEADPHONE, NULL); 431cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 432bc7a166dSUlrich Dangel break; 433bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 434bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 435cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 436cd372fb3STakashi Iwai SND_JACK_MICROPHONE, NULL); 437cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 438bc7a166dSUlrich Dangel break; 439bc7a166dSUlrich Dangel } 440bc7a166dSUlrich Dangel if (err < 0) 441bc7a166dSUlrich Dangel return err; 442bc7a166dSUlrich Dangel ++hv; 443bc7a166dSUlrich Dangel } 444bc7a166dSUlrich Dangel } 445cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */ 4465801f992STakashi Iwai return 0; 4475801f992STakashi Iwai } 448bc7a166dSUlrich Dangel 449*4d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 450*4d7fbdbcSTakashi Iwai unsigned int power_state) 451*4d7fbdbcSTakashi Iwai { 452*4d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 453*4d7fbdbcSTakashi Iwai msleep(100); 454*4d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 455*4d7fbdbcSTakashi Iwai power_state); 456*4d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 457*4d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 458*4d7fbdbcSTakashi Iwai msleep(10); 459*4d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 460*4d7fbdbcSTakashi Iwai } 461*4d7fbdbcSTakashi Iwai 462c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 463c9b443d4STobin Davis { 464c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 465c9b443d4STobin Davis int i; 466c9b443d4STobin Davis 467c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 468c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 469c9b443d4STobin Davis return 0; 470c9b443d4STobin Davis } 471c9b443d4STobin Davis 472c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 473c9b443d4STobin Davis { 474cd372fb3STakashi Iwai snd_hda_input_jack_free(codec); 475c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 476c9b443d4STobin Davis kfree(codec->spec); 477c9b443d4STobin Davis } 478c9b443d4STobin Davis 47934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 480b880c74aSTakashi Iwai { 481b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 482b880c74aSTakashi Iwai .name = "Capture Source", 483b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 484b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 485b880c74aSTakashi Iwai .put = conexant_mux_enum_put 486b880c74aSTakashi Iwai }, 487b880c74aSTakashi Iwai {} 488b880c74aSTakashi Iwai }; 489b880c74aSTakashi Iwai 4903507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4913507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 49234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4933507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4943507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4953507e2a8STakashi Iwai { } /* end */ 4963507e2a8STakashi Iwai }; 4973507e2a8STakashi Iwai #endif 4983507e2a8STakashi Iwai 499ea734963STakashi Iwai static const char * const slave_vols[] = { 500dd5746a8STakashi Iwai "Headphone Playback Volume", 501dd5746a8STakashi Iwai "Speaker Playback Volume", 502a3a85d39STakashi Iwai "Front Playback Volume", 503a3a85d39STakashi Iwai "Surround Playback Volume", 504a3a85d39STakashi Iwai "CLFE Playback Volume", 505dd5746a8STakashi Iwai NULL 506dd5746a8STakashi Iwai }; 507dd5746a8STakashi Iwai 508ea734963STakashi Iwai static const char * const slave_sws[] = { 509dd5746a8STakashi Iwai "Headphone Playback Switch", 510dd5746a8STakashi Iwai "Speaker Playback Switch", 511a3a85d39STakashi Iwai "Front Playback Switch", 512a3a85d39STakashi Iwai "Surround Playback Switch", 513a3a85d39STakashi Iwai "CLFE Playback Switch", 514dd5746a8STakashi Iwai NULL 515dd5746a8STakashi Iwai }; 516dd5746a8STakashi Iwai 517c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 518c9b443d4STobin Davis { 519c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 520c9b443d4STobin Davis unsigned int i; 521c9b443d4STobin Davis int err; 522c9b443d4STobin Davis 523c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 524c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 525c9b443d4STobin Davis if (err < 0) 526c9b443d4STobin Davis return err; 527c9b443d4STobin Davis } 528c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 529c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 53074b654c9SStephen Warren spec->multiout.dig_out_nid, 531c9b443d4STobin Davis spec->multiout.dig_out_nid); 532c9b443d4STobin Davis if (err < 0) 533c9b443d4STobin Davis return err; 5349a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5359a08160bSTakashi Iwai &spec->multiout); 5369a08160bSTakashi Iwai if (err < 0) 5379a08160bSTakashi Iwai return err; 5389a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 539c9b443d4STobin Davis } 540c9b443d4STobin Davis if (spec->dig_in_nid) { 541c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 542c9b443d4STobin Davis if (err < 0) 543c9b443d4STobin Davis return err; 544c9b443d4STobin Davis } 545dd5746a8STakashi Iwai 546dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 547dd5746a8STakashi Iwai if (spec->vmaster_nid && 548dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 549dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 550dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 551dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 552dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 553dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 554dd5746a8STakashi Iwai if (err < 0) 555dd5746a8STakashi Iwai return err; 556dd5746a8STakashi Iwai } 557dd5746a8STakashi Iwai if (spec->vmaster_nid && 558dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 559dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 560dd5746a8STakashi Iwai NULL, slave_sws); 561dd5746a8STakashi Iwai if (err < 0) 562dd5746a8STakashi Iwai return err; 563dd5746a8STakashi Iwai } 564dd5746a8STakashi Iwai 565b880c74aSTakashi Iwai if (spec->input_mux) { 566b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 567b880c74aSTakashi Iwai if (err < 0) 568b880c74aSTakashi Iwai return err; 569b880c74aSTakashi Iwai } 570b880c74aSTakashi Iwai 5713507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5723507e2a8STakashi Iwai /* create beep controls if needed */ 5733507e2a8STakashi Iwai if (spec->beep_amp) { 57434cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5753507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5763507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5773507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5783507e2a8STakashi Iwai if (!kctl) 5793507e2a8STakashi Iwai return -ENOMEM; 5803507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5813507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5823507e2a8STakashi Iwai if (err < 0) 5833507e2a8STakashi Iwai return err; 5843507e2a8STakashi Iwai } 5853507e2a8STakashi Iwai } 5863507e2a8STakashi Iwai #endif 5873507e2a8STakashi Iwai 588c9b443d4STobin Davis return 0; 589c9b443d4STobin Davis } 590c9b443d4STobin Davis 591697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 592697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 593697c373eSTakashi Iwai { 594697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 595697c373eSTakashi Iwai return 0; 596697c373eSTakashi Iwai } 597697c373eSTakashi Iwai #endif 598697c373eSTakashi Iwai 59934cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 600c9b443d4STobin Davis .build_controls = conexant_build_controls, 601c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 602c9b443d4STobin Davis .init = conexant_init, 603c9b443d4STobin Davis .free = conexant_free, 604*4d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 605697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 606697c373eSTakashi Iwai .suspend = conexant_suspend, 607697c373eSTakashi Iwai #endif 608697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 609c9b443d4STobin Davis }; 610c9b443d4STobin Davis 6113507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6123507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 6133507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 6143507e2a8STakashi Iwai #else 6153507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 6163507e2a8STakashi Iwai #endif 6173507e2a8STakashi Iwai 6186764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 619c9b443d4STobin Davis /* 620c9b443d4STobin Davis * EAPD control 621c9b443d4STobin Davis * the private value = nid | (invert << 8) 622c9b443d4STobin Davis */ 623c9b443d4STobin Davis 624a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 625c9b443d4STobin Davis 62682f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 627c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 628c9b443d4STobin Davis { 629c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 630c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 631c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 632c9b443d4STobin Davis if (invert) 633c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 634c9b443d4STobin Davis else 635c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 636c9b443d4STobin Davis return 0; 63782f30040STobin Davis 638c9b443d4STobin Davis } 639c9b443d4STobin Davis 64082f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 641c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 642c9b443d4STobin Davis { 643c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 644c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 645c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 646c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 647c9b443d4STobin Davis unsigned int eapd; 64882f30040STobin Davis 64968ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 650c9b443d4STobin Davis if (invert) 651c9b443d4STobin Davis eapd = !eapd; 65282beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 653c9b443d4STobin Davis return 0; 65482f30040STobin Davis 655c9b443d4STobin Davis spec->cur_eapd = eapd; 65682beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 657c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 658c9b443d4STobin Davis eapd ? 0x02 : 0x00); 659c9b443d4STobin Davis return 1; 660c9b443d4STobin Davis } 661c9b443d4STobin Davis 66286d72bdfSTakashi Iwai /* controls for test mode */ 66386d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 66486d72bdfSTakashi Iwai 66582f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 66682f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 66782f30040STobin Davis .info = cxt_eapd_info, \ 66882f30040STobin Davis .get = cxt_eapd_get, \ 66982f30040STobin Davis .put = cxt_eapd_put, \ 67082f30040STobin Davis .private_value = nid | (mask<<16) } 67182f30040STobin Davis 67282f30040STobin Davis 67382f30040STobin Davis 674c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 675c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 676c9b443d4STobin Davis { 677c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 678c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 679c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 680c9b443d4STobin Davis spec->num_channel_mode); 681c9b443d4STobin Davis } 682c9b443d4STobin Davis 683c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 684c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 685c9b443d4STobin Davis { 686c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 687c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 688c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 689c9b443d4STobin Davis spec->num_channel_mode, 690c9b443d4STobin Davis spec->multiout.max_channels); 691c9b443d4STobin Davis } 692c9b443d4STobin Davis 693c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 694c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 695c9b443d4STobin Davis { 696c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 697c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 698c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 699c9b443d4STobin Davis spec->num_channel_mode, 700c9b443d4STobin Davis &spec->multiout.max_channels); 701c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 702c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 703c9b443d4STobin Davis return err; 704c9b443d4STobin Davis } 705c9b443d4STobin Davis 706c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 707c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 708c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 709c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 710c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 711c9b443d4STobin Davis .private_value = nid | (dir<<16) } 712c9b443d4STobin Davis 71386d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 71486d72bdfSTakashi Iwai 715c9b443d4STobin Davis /* Conexant 5045 specific */ 716c9b443d4STobin Davis 71734cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 71834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 71934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 720cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 721c9b443d4STobin Davis 72234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 7235cd57529STobin Davis { 2, NULL }, 7245cd57529STobin Davis }; 725c9b443d4STobin Davis 72634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 727c9b443d4STobin Davis .num_items = 2, 728c9b443d4STobin Davis .items = { 72982f30040STobin Davis { "IntMic", 0x1 }, 730f4beee94SJiang zhe { "ExtMic", 0x2 }, 731c9b443d4STobin Davis } 732c9b443d4STobin Davis }; 733c9b443d4STobin Davis 73434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 73522e14130SLukasz Marcinowski .num_items = 5, 7365218c892SJiang Zhe .items = { 7375218c892SJiang Zhe { "IntMic", 0x1 }, 7385218c892SJiang Zhe { "ExtMic", 0x2 }, 7395218c892SJiang Zhe { "LineIn", 0x3 }, 74022e14130SLukasz Marcinowski { "CD", 0x4 }, 74122e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7425218c892SJiang Zhe } 7435218c892SJiang Zhe }; 7445218c892SJiang Zhe 74534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7462de3c232SJiang zhe .num_items = 2, 7472de3c232SJiang zhe .items = { 7482de3c232SJiang zhe { "ExtMic", 0x1 }, 7492de3c232SJiang zhe { "IntMic", 0x2 }, 7502de3c232SJiang zhe } 7512de3c232SJiang zhe }; 7522de3c232SJiang zhe 753c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 754c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 755c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 756c9b443d4STobin Davis { 757c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 758c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 75982f30040STobin Davis unsigned int bits; 760c9b443d4STobin Davis 76182f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 762c9b443d4STobin Davis return 0; 763c9b443d4STobin Davis 76482f30040STobin Davis /* toggle internal speakers mute depending of presence of 76582f30040STobin Davis * the headphone jack 76682f30040STobin Davis */ 76747fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 76847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 76947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7707f29673bSTobin Davis 77147fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 77247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 77347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 774c9b443d4STobin Davis return 1; 775c9b443d4STobin Davis } 776c9b443d4STobin Davis 777c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 77834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 779cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 780cca3b371STakashi Iwai .values = { 781cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 782cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 783cca3b371STakashi Iwai 0 784cca3b371STakashi Iwai }, 785cca3b371STakashi Iwai }; 786c9b443d4STobin Davis 7877f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7887f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7897f29673bSTobin Davis { 79034cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7917f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7927f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7937f29673bSTobin Davis {} 7947f29673bSTobin Davis }; 79534cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7967f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7977f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7987f29673bSTobin Davis {} 7997f29673bSTobin Davis }; 8007f29673bSTobin Davis unsigned int present; 8017f29673bSTobin Davis 802d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 8037f29673bSTobin Davis if (present) 8047f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 8057f29673bSTobin Davis else 8067f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 8077f29673bSTobin Davis } 8087f29673bSTobin Davis 809c9b443d4STobin Davis 810c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 811c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 812c9b443d4STobin Davis { 81382f30040STobin Davis struct conexant_spec *spec = codec->spec; 814dd87da1cSTobin Davis unsigned int bits; 815c9b443d4STobin Davis 816d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 817dd87da1cSTobin Davis 81847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 81947fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 82047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 821c9b443d4STobin Davis } 822c9b443d4STobin Davis 823c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 824c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 825c9b443d4STobin Davis unsigned int res) 826c9b443d4STobin Davis { 827c9b443d4STobin Davis res >>= 26; 828c9b443d4STobin Davis switch (res) { 829c9b443d4STobin Davis case CONEXANT_HP_EVENT: 830c9b443d4STobin Davis cxt5045_hp_automute(codec); 831c9b443d4STobin Davis break; 8327f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8337f29673bSTobin Davis cxt5045_hp_automic(codec); 8347f29673bSTobin Davis break; 8357f29673bSTobin Davis 836c9b443d4STobin Davis } 837c9b443d4STobin Davis } 838c9b443d4STobin Davis 83934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 84028c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 84128c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8428607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8438607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 844c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 845c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 84628c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 84728c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8488607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8498607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 850cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 851c9b443d4STobin Davis { 852c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 853c9b443d4STobin Davis .name = "Master Playback Switch", 85482f30040STobin Davis .info = cxt_eapd_info, 85582f30040STobin Davis .get = cxt_eapd_get, 856c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 85782f30040STobin Davis .private_value = 0x10, 858c9b443d4STobin Davis }, 859c9b443d4STobin Davis 860c9b443d4STobin Davis {} 861c9b443d4STobin Davis }; 862c9b443d4STobin Davis 86334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 86422e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 86522e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 86622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 86722e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 86822e14130SLukasz Marcinowski 8695218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8705218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8715218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8725218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8735218c892SJiang Zhe 87422e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 87522e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 87622e14130SLukasz Marcinowski 8775218c892SJiang Zhe {} 8785218c892SJiang Zhe }; 8795218c892SJiang Zhe 88034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 88128c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 88228c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8838607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8848607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8852de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8862de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 88728c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 88828c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8898607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8908607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8912de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8922de3c232SJiang zhe { 8932de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8942de3c232SJiang zhe .name = "Master Playback Switch", 8952de3c232SJiang zhe .info = cxt_eapd_info, 8962de3c232SJiang zhe .get = cxt_eapd_get, 8972de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8982de3c232SJiang zhe .private_value = 0x10, 8992de3c232SJiang zhe }, 9002de3c232SJiang zhe 9012de3c232SJiang zhe {} 9022de3c232SJiang zhe }; 9032de3c232SJiang zhe 90434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 905c9b443d4STobin Davis /* Line in, Mic */ 9064090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9077f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 908c9b443d4STobin Davis /* HP, Amp */ 909c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 910c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 91182f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 912c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 913c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 914c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 915c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 916c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 917c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 91828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9197f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 92082f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 921c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 922c9b443d4STobin Davis /* SPDIF route: PCM */ 923cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 924c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 925c9b443d4STobin Davis /* EAPD */ 92682f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 927c9b443d4STobin Davis { } /* end */ 928c9b443d4STobin Davis }; 929c9b443d4STobin Davis 93034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 93128c4edb7SDavid Henningsson /* Internal Mic, Mic */ 9325218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9335218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9345218c892SJiang Zhe /* Line In,HP, Amp */ 9355218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9365218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9375218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9385218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9395218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9405218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9415218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9425218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9435218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 94428c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9455218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9465218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9475218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9485218c892SJiang Zhe /* SPDIF route: PCM */ 949cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9505218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9515218c892SJiang Zhe /* EAPD */ 9525218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9535218c892SJiang Zhe { } /* end */ 9545218c892SJiang Zhe }; 9557f29673bSTobin Davis 95634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9577f29673bSTobin Davis /* pin sensing on HP jack */ 9587f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 959d3091fadSTakashi Iwai { } /* end */ 9607f29673bSTobin Davis }; 9617f29673bSTobin Davis 96234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9637f29673bSTobin Davis /* pin sensing on HP jack */ 9647f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 965d3091fadSTakashi Iwai { } /* end */ 9667f29673bSTobin Davis }; 9677f29673bSTobin Davis 968c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 969c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 970c9b443d4STobin Davis * configuration. 971c9b443d4STobin Davis */ 97234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 973c9b443d4STobin Davis .num_items = 5, 974c9b443d4STobin Davis .items = { 975c9b443d4STobin Davis { "MIXER", 0x0 }, 976c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 977c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 978c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 979c9b443d4STobin Davis { "CD pin", 0x4 }, 980c9b443d4STobin Davis }, 981c9b443d4STobin Davis }; 982c9b443d4STobin Davis 98334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 984c9b443d4STobin Davis 985c9b443d4STobin Davis /* Output controls */ 986c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 987c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9887f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9897f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9907f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9917f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 992c9b443d4STobin Davis 993c9b443d4STobin Davis /* Modes for retasking pin widgets */ 994c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 995c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 996c9b443d4STobin Davis 99782f30040STobin Davis /* EAPD Switch Control */ 99882f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 99982f30040STobin Davis 1000c9b443d4STobin Davis /* Loopback mixer controls */ 1001c9b443d4STobin Davis 10027f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 10037f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 10047f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 10057f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 10067f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 10077f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 10087f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 10097f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 10107f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 10117f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 1012c9b443d4STobin Davis { 1013c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1014c9b443d4STobin Davis .name = "Input Source", 1015c9b443d4STobin Davis .info = conexant_mux_enum_info, 1016c9b443d4STobin Davis .get = conexant_mux_enum_get, 1017c9b443d4STobin Davis .put = conexant_mux_enum_put, 1018c9b443d4STobin Davis }, 1019fb3409e7STobin Davis /* Audio input controls */ 1020fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1021fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 1022fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 1023fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 1024fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 1025fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 1026fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1027fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1028fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1029fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1030c9b443d4STobin Davis { } /* end */ 1031c9b443d4STobin Davis }; 1032c9b443d4STobin Davis 103334cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 10347f29673bSTobin Davis /* Set connections */ 10357f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10367f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10377f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1038c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1039c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10407f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1041c9b443d4STobin Davis 1042c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1043c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1044c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1045c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1046c9b443d4STobin Davis * control. 1047c9b443d4STobin Davis */ 1048cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1049cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1050c9b443d4STobin Davis 1051c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1052c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1053c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1054c9b443d4STobin Davis 1055c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1056c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1057c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1058c9b443d4STobin Davis * input/output buffers as needed. 1059c9b443d4STobin Davis */ 1060c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1061c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1062c9b443d4STobin Davis 1063c9b443d4STobin Davis /* Mute capture amp left and right */ 1064c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1065c9b443d4STobin Davis 1066c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1067c9b443d4STobin Davis * pin) 1068c9b443d4STobin Davis */ 1069c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10707f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1071c9b443d4STobin Davis 1072c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1073c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1074c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1075c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1076c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1077c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1078c9b443d4STobin Davis 1079c9b443d4STobin Davis { } 1080c9b443d4STobin Davis }; 1081c9b443d4STobin Davis #endif 1082c9b443d4STobin Davis 1083c9b443d4STobin Davis 1084c9b443d4STobin Davis /* initialize jack-sensing, too */ 1085c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1086c9b443d4STobin Davis { 1087c9b443d4STobin Davis conexant_init(codec); 1088c9b443d4STobin Davis cxt5045_hp_automute(codec); 1089c9b443d4STobin Davis return 0; 1090c9b443d4STobin Davis } 1091c9b443d4STobin Davis 1092c9b443d4STobin Davis 1093c9b443d4STobin Davis enum { 109415908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 109515908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 109615908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10975218c892SJiang Zhe CXT5045_BENQ, 10982de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1099c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1100c9b443d4STobin Davis CXT5045_TEST, 1101c9b443d4STobin Davis #endif 11021f8458a2STakashi Iwai CXT5045_AUTO, 1103f5fcc13cSTakashi Iwai CXT5045_MODELS 1104c9b443d4STobin Davis }; 1105c9b443d4STobin Davis 1106ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 110715908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 110815908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 110915908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 11105218c892SJiang Zhe [CXT5045_BENQ] = "benq", 11112de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1112c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1113f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1114c9b443d4STobin Davis #endif 11151f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1116f5fcc13cSTakashi Iwai }; 1117c9b443d4STobin Davis 111834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 11192de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1120dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1121dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 11226a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 11235218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 112415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 112515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 11269e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 11279e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 112815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 112915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 113015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1131dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1132dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 113315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1134c9b443d4STobin Davis {} 1135c9b443d4STobin Davis }; 1136c9b443d4STobin Davis 1137c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1138c9b443d4STobin Davis { 1139c9b443d4STobin Davis struct conexant_spec *spec; 1140c9b443d4STobin Davis int board_config; 1141c9b443d4STobin Davis 11421f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 11431f8458a2STakashi Iwai cxt5045_models, 11441f8458a2STakashi Iwai cxt5045_cfg_tbl); 11451f8458a2STakashi Iwai if (board_config < 0) 1146c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 11471f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11481f8458a2STakashi Iwai return patch_conexant_auto(codec); 11491f8458a2STakashi Iwai 1150c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1151c9b443d4STobin Davis if (!spec) 1152c9b443d4STobin Davis return -ENOMEM; 1153c9b443d4STobin Davis codec->spec = spec; 11549421f954STakashi Iwai codec->pin_amp_workaround = 1; 1155c9b443d4STobin Davis 1156c9b443d4STobin Davis spec->multiout.max_channels = 2; 1157c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1158c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1159c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1160c9b443d4STobin Davis spec->num_adc_nids = 1; 1161c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1162c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1163c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1164c9b443d4STobin Davis spec->num_mixers = 1; 1165c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1166c9b443d4STobin Davis spec->num_init_verbs = 1; 1167c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1168c9b443d4STobin Davis spec->spdif_route = 0; 11693507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11703507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11715cd57529STobin Davis 11723507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1173c9b443d4STobin Davis 1174c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1175c9b443d4STobin Davis 1176c9b443d4STobin Davis switch (board_config) { 117715908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11787f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1179c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1180c9b443d4STobin Davis spec->num_init_verbs = 2; 11817f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11827f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11837f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11847f29673bSTobin Davis break; 118515908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 118686376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11877f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11887f29673bSTobin Davis spec->num_init_verbs = 2; 11897f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1190c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1191c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1192c9b443d4STobin Davis break; 119315908c36SMarc Boucher default: 119415908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 119515908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 119615908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 119715908c36SMarc Boucher spec->num_init_verbs = 3; 119815908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 119915908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 120015908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 120115908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 120215908c36SMarc Boucher break; 12035218c892SJiang Zhe case CXT5045_BENQ: 12045218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12055218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 12065218c892SJiang Zhe spec->num_init_verbs = 1; 12075218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 12085218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 12095218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 12105218c892SJiang Zhe spec->num_mixers = 2; 12115218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 12125218c892SJiang Zhe break; 12132de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 12142de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12152de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 12162de3c232SJiang zhe spec->num_init_verbs = 2; 12172de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12182de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 12192de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 12202de3c232SJiang zhe break; 1221c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1222c9b443d4STobin Davis case CXT5045_TEST: 1223c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1224c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1225c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 122615908c36SMarc Boucher break; 122715908c36SMarc Boucher 1228c9b443d4STobin Davis #endif 1229c9b443d4STobin Davis } 123048ecb7e8STakashi Iwai 1231031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1232031005f7STakashi Iwai case 0x103c: 12338f0f5ff6SDaniel T Chen case 0x1631: 12340b587fc4SDaniel T Chen case 0x1734: 12350ebf9e36SDaniel T Chen case 0x17aa: 12360ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12370ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12380ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 123948ecb7e8STakashi Iwai */ 124048ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 124148ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 124248ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 124348ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 124448ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1245031005f7STakashi Iwai break; 1246031005f7STakashi Iwai } 124748ecb7e8STakashi Iwai 12483507e2a8STakashi Iwai if (spec->beep_amp) 12493507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12503507e2a8STakashi Iwai 1251c9b443d4STobin Davis return 0; 1252c9b443d4STobin Davis } 1253c9b443d4STobin Davis 1254c9b443d4STobin Davis 1255c9b443d4STobin Davis /* Conexant 5047 specific */ 125682f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1257c9b443d4STobin Davis 125834cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 125934cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 126034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1261c9b443d4STobin Davis 126234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12635cd57529STobin Davis { 2, NULL }, 12645cd57529STobin Davis }; 1265c9b443d4STobin Davis 126634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 126782f30040STobin Davis .num_items = 2, 126882f30040STobin Davis .items = { 126982f30040STobin Davis { "ExtMic", 0x2 }, 127082f30040STobin Davis { "Line-In", 0x1 }, 1271c9b443d4STobin Davis } 1272c9b443d4STobin Davis }; 1273c9b443d4STobin Davis 1274c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1275c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1276c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1277c9b443d4STobin Davis { 1278c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1279c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 128082f30040STobin Davis unsigned int bits; 1281c9b443d4STobin Davis 128282f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1283c9b443d4STobin Davis return 0; 1284c9b443d4STobin Davis 128582f30040STobin Davis /* toggle internal speakers mute depending of presence of 128682f30040STobin Davis * the headphone jack 128782f30040STobin Davis */ 128847fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12893b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12903b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12913b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12923b7523fcSTakashi Iwai */ 12935d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 129447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 129547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 129647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 129747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1298c9b443d4STobin Davis return 1; 1299c9b443d4STobin Davis } 1300c9b443d4STobin Davis 1301c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1302c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1303c9b443d4STobin Davis { 130482f30040STobin Davis struct conexant_spec *spec = codec->spec; 1305dd87da1cSTobin Davis unsigned int bits; 1306c9b443d4STobin Davis 1307d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1308dd87da1cSTobin Davis 130947fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 13103b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13115d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 131247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1313c9b443d4STobin Davis } 1314c9b443d4STobin Davis 1315c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1316c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1317c9b443d4STobin Davis { 131834cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 13199f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13209f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1321c9b443d4STobin Davis {} 1322c9b443d4STobin Davis }; 132334cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 13249f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13259f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1326c9b443d4STobin Davis {} 1327c9b443d4STobin Davis }; 1328c9b443d4STobin Davis unsigned int present; 1329c9b443d4STobin Davis 1330d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1331c9b443d4STobin Davis if (present) 1332c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1333c9b443d4STobin Davis else 1334c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1335c9b443d4STobin Davis } 1336c9b443d4STobin Davis 1337c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1338c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1339c9b443d4STobin Davis unsigned int res) 1340c9b443d4STobin Davis { 13419f113e0eSMarc Boucher switch (res >> 26) { 1342c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1343c9b443d4STobin Davis cxt5047_hp_automute(codec); 1344c9b443d4STobin Davis break; 1345c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1346c9b443d4STobin Davis cxt5047_hp_automic(codec); 1347c9b443d4STobin Davis break; 1348c9b443d4STobin Davis } 1349c9b443d4STobin Davis } 1350c9b443d4STobin Davis 135134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1352df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1353df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13545f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1355c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1356c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1357c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1358c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 135982f30040STobin Davis { 136082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 136182f30040STobin Davis .name = "Master Playback Switch", 136282f30040STobin Davis .info = cxt_eapd_info, 136382f30040STobin Davis .get = cxt_eapd_get, 1364c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1365c9b443d4STobin Davis .private_value = 0x13, 1366c9b443d4STobin Davis }, 1367c9b443d4STobin Davis 1368c9b443d4STobin Davis {} 1369c9b443d4STobin Davis }; 1370c9b443d4STobin Davis 137134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13723b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13735d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1374df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1375df481e41STakashi Iwai {} 1376df481e41STakashi Iwai }; 1377df481e41STakashi Iwai 137834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1379c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1380c9b443d4STobin Davis { } /* end */ 1381c9b443d4STobin Davis }; 1382c9b443d4STobin Davis 138334cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1384c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1385c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1386c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1387c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13887f29673bSTobin Davis /* HP, Speaker */ 1389b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13905b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13915b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13927f29673bSTobin Davis /* Record selector: Mic */ 13937f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13947f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13957f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13967f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1397c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1398c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1399c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1400c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1401c9b443d4STobin Davis /* SPDIF route: PCM */ 1402c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 140382f30040STobin Davis /* Enable unsolicited events */ 140482f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 140582f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1406c9b443d4STobin Davis { } /* end */ 1407c9b443d4STobin Davis }; 1408c9b443d4STobin Davis 1409c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 141034cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 14113b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1412c9b443d4STobin Davis {} 1413c9b443d4STobin Davis }; 1414c9b443d4STobin Davis 1415c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1416c9b443d4STobin Davis * configuration. 1417c9b443d4STobin Davis */ 1418c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 141934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 142082f30040STobin Davis .num_items = 4, 1421c9b443d4STobin Davis .items = { 142282f30040STobin Davis { "LINE1 pin", 0x0 }, 142382f30040STobin Davis { "MIC1 pin", 0x1 }, 142482f30040STobin Davis { "MIC2 pin", 0x2 }, 142582f30040STobin Davis { "CD pin", 0x3 }, 1426c9b443d4STobin Davis }, 1427c9b443d4STobin Davis }; 1428c9b443d4STobin Davis 142934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1430c9b443d4STobin Davis 1431c9b443d4STobin Davis /* Output only controls */ 143282f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 143382f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 143482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 143582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1436c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1437c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1438c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1439c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 144082f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 144182f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 144282f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 144382f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1444c9b443d4STobin Davis 1445c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1446c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1447c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1448c9b443d4STobin Davis 144982f30040STobin Davis /* EAPD Switch Control */ 145082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 145182f30040STobin Davis 1452c9b443d4STobin Davis /* Loopback mixer controls */ 145382f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 145482f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 145582f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 145682f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 145782f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 145882f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 145982f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 146082f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1461c9b443d4STobin Davis 146282f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 146382f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 146482f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 146582f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 146682f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 146782f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 146882f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 146982f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1470c9b443d4STobin Davis { 1471c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1472c9b443d4STobin Davis .name = "Input Source", 1473c9b443d4STobin Davis .info = conexant_mux_enum_info, 1474c9b443d4STobin Davis .get = conexant_mux_enum_get, 1475c9b443d4STobin Davis .put = conexant_mux_enum_put, 1476c9b443d4STobin Davis }, 1477854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14789f113e0eSMarc Boucher 1479c9b443d4STobin Davis { } /* end */ 1480c9b443d4STobin Davis }; 1481c9b443d4STobin Davis 148234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1483c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1484c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1485c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1486c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1487c9b443d4STobin Davis 1488c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1489c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1490c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1491c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1492c9b443d4STobin Davis * control. 1493c9b443d4STobin Davis */ 1494c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1495c9b443d4STobin Davis 1496c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1497c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1498c9b443d4STobin Davis */ 1499c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1500c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1501c9b443d4STobin Davis 1502c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1503c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1504c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1505c9b443d4STobin Davis 1506c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1507c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1508c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1509c9b443d4STobin Davis * input/output buffers as needed. 1510c9b443d4STobin Davis */ 1511c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1512c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1513c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1514c9b443d4STobin Davis 1515c9b443d4STobin Davis /* Mute capture amp left and right */ 1516c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1517c9b443d4STobin Davis 1518c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1519c9b443d4STobin Davis * pin) 1520c9b443d4STobin Davis */ 1521c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1522c9b443d4STobin Davis 1523c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1524c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1525c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1526c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1527c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1528c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1529c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1530c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1531c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1532c9b443d4STobin Davis 1533c9b443d4STobin Davis { } 1534c9b443d4STobin Davis }; 1535c9b443d4STobin Davis #endif 1536c9b443d4STobin Davis 1537c9b443d4STobin Davis 1538c9b443d4STobin Davis /* initialize jack-sensing, too */ 1539c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1540c9b443d4STobin Davis { 1541c9b443d4STobin Davis conexant_init(codec); 1542c9b443d4STobin Davis cxt5047_hp_automute(codec); 1543c9b443d4STobin Davis return 0; 1544c9b443d4STobin Davis } 1545c9b443d4STobin Davis 1546c9b443d4STobin Davis 1547c9b443d4STobin Davis enum { 1548f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1549f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1550f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1551c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1552c9b443d4STobin Davis CXT5047_TEST, 1553c9b443d4STobin Davis #endif 1554fa5dadcbSTakashi Iwai CXT5047_AUTO, 1555f5fcc13cSTakashi Iwai CXT5047_MODELS 1556c9b443d4STobin Davis }; 1557c9b443d4STobin Davis 1558ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1559f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1560f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1561f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1562c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1563f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1564c9b443d4STobin Davis #endif 1565fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1566f5fcc13cSTakashi Iwai }; 1567c9b443d4STobin Davis 156834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1569ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1570dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1571dea0a509STakashi Iwai CXT5047_LAPTOP), 1572f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1573c9b443d4STobin Davis {} 1574c9b443d4STobin Davis }; 1575c9b443d4STobin Davis 1576c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1577c9b443d4STobin Davis { 1578c9b443d4STobin Davis struct conexant_spec *spec; 1579c9b443d4STobin Davis int board_config; 1580c9b443d4STobin Davis 1581fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1582fa5dadcbSTakashi Iwai cxt5047_models, 1583fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1584fa5dadcbSTakashi Iwai if (board_config < 0) 1585c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1586fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1587fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1588fa5dadcbSTakashi Iwai 1589c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1590c9b443d4STobin Davis if (!spec) 1591c9b443d4STobin Davis return -ENOMEM; 1592c9b443d4STobin Davis codec->spec = spec; 15939421f954STakashi Iwai codec->pin_amp_workaround = 1; 1594c9b443d4STobin Davis 1595c9b443d4STobin Davis spec->multiout.max_channels = 2; 1596c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1597c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1598c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1599c9b443d4STobin Davis spec->num_adc_nids = 1; 1600c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1601c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1602c9b443d4STobin Davis spec->num_mixers = 1; 1603df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1604c9b443d4STobin Davis spec->num_init_verbs = 1; 1605c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1606c9b443d4STobin Davis spec->spdif_route = 0; 16075cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16085cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1609c9b443d4STobin Davis 1610c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1611c9b443d4STobin Davis 1612c9b443d4STobin Davis switch (board_config) { 1613c9b443d4STobin Davis case CXT5047_LAPTOP: 1614df481e41STakashi Iwai spec->num_mixers = 2; 1615df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1616df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1617c9b443d4STobin Davis break; 1618c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1619df481e41STakashi Iwai spec->num_mixers = 2; 1620df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1621fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1622c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1623c9b443d4STobin Davis break; 1624c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 162582f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1626df481e41STakashi Iwai spec->num_mixers = 2; 1627df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1628c9b443d4STobin Davis spec->num_init_verbs = 2; 1629c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1630fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1631c9b443d4STobin Davis break; 1632c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1633c9b443d4STobin Davis case CXT5047_TEST: 1634c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1635c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1636c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1637fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1638c9b443d4STobin Davis #endif 1639c9b443d4STobin Davis } 1640dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1641025f206cSDaniel T Chen 1642025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1643025f206cSDaniel T Chen case 0x103c: 1644025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1645025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1646025f206cSDaniel T Chen * with 0 dB offset 0x17) 1647025f206cSDaniel T Chen */ 1648025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1649025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1650025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1651025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1652025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1653025f206cSDaniel T Chen break; 1654025f206cSDaniel T Chen } 1655025f206cSDaniel T Chen 1656c9b443d4STobin Davis return 0; 1657c9b443d4STobin Davis } 1658c9b443d4STobin Davis 1659461e2c78STakashi Iwai /* Conexant 5051 specific */ 166034cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 166134cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1662461e2c78STakashi Iwai 166334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1664461e2c78STakashi Iwai { 2, NULL }, 1665461e2c78STakashi Iwai }; 1666461e2c78STakashi Iwai 1667461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1668461e2c78STakashi Iwai { 1669461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1670461e2c78STakashi Iwai unsigned int pinctl; 167123d2df5bSTakashi Iwai /* headphone pin */ 167223d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 167323d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 167423d2df5bSTakashi Iwai pinctl); 167523d2df5bSTakashi Iwai /* speaker pin */ 1676461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1677461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1678461e2c78STakashi Iwai pinctl); 1679f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1680f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1681f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1682f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1683f7154de2SHerton Ronaldo Krzesinski pinctl); 1684461e2c78STakashi Iwai } 1685461e2c78STakashi Iwai 1686461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1687461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1688461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1689461e2c78STakashi Iwai { 1690461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1691461e2c78STakashi Iwai 1692461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1693461e2c78STakashi Iwai return 0; 1694461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1695461e2c78STakashi Iwai return 1; 1696461e2c78STakashi Iwai } 1697461e2c78STakashi Iwai 1698461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1699461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1700461e2c78STakashi Iwai { 170179d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1702461e2c78STakashi Iwai unsigned int present; 1703461e2c78STakashi Iwai 1704faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 170579d7d533STakashi Iwai return; 1706d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1707461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1708461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1709461e2c78STakashi Iwai present ? 0x01 : 0x00); 1710461e2c78STakashi Iwai } 1711461e2c78STakashi Iwai 1712461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1713461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1714461e2c78STakashi Iwai { 1715461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1716461e2c78STakashi Iwai unsigned int present; 1717461e2c78STakashi Iwai hda_nid_t new_adc; 1718461e2c78STakashi Iwai 1719faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 172079d7d533STakashi Iwai return; 1721d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1722461e2c78STakashi Iwai if (present) 1723461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1724461e2c78STakashi Iwai else 1725461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1726461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1727461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1728461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1729f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1730461e2c78STakashi Iwai spec->cur_adc = new_adc; 1731461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1732461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1733461e2c78STakashi Iwai spec->cur_adc_format); 1734461e2c78STakashi Iwai } 1735461e2c78STakashi Iwai } 1736461e2c78STakashi Iwai 1737461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1738461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1739461e2c78STakashi Iwai { 1740461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1741461e2c78STakashi Iwai 1742d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1743461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1744461e2c78STakashi Iwai } 1745461e2c78STakashi Iwai 1746461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1747461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1748461e2c78STakashi Iwai unsigned int res) 1749461e2c78STakashi Iwai { 1750acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1751461e2c78STakashi Iwai switch (res >> 26) { 1752461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1753461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1754461e2c78STakashi Iwai break; 1755461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1756461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1757461e2c78STakashi Iwai break; 1758461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1759461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1760461e2c78STakashi Iwai break; 1761461e2c78STakashi Iwai } 1762cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 1763461e2c78STakashi Iwai } 1764461e2c78STakashi Iwai 176534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1766461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1767461e2c78STakashi Iwai { 1768461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1769461e2c78STakashi Iwai .name = "Master Playback Switch", 1770461e2c78STakashi Iwai .info = cxt_eapd_info, 1771461e2c78STakashi Iwai .get = cxt_eapd_get, 1772461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1773461e2c78STakashi Iwai .private_value = 0x1a, 1774461e2c78STakashi Iwai }, 17752c7a3fb3STakashi Iwai {} 17762c7a3fb3STakashi Iwai }; 1777461e2c78STakashi Iwai 177834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17792c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17802c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17818607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17828607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17832c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17842c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1785461e2c78STakashi Iwai {} 1786461e2c78STakashi Iwai }; 1787461e2c78STakashi Iwai 178834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1789461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1790461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17918607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17928607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1793461e2c78STakashi Iwai {} 1794461e2c78STakashi Iwai }; 1795461e2c78STakashi Iwai 179634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17974e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17984e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 179979d7d533STakashi Iwai {} 180079d7d533STakashi Iwai }; 180179d7d533STakashi Iwai 180234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 18035f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 18045f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1805cd9d95a5SKen Prox {} 1806cd9d95a5SKen Prox }; 1807cd9d95a5SKen Prox 180834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1809faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1810faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 18118607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 18128607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1813faddaa5dSTakashi Iwai {} 1814faddaa5dSTakashi Iwai }; 1815faddaa5dSTakashi Iwai 181634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1817461e2c78STakashi Iwai /* Line in, Mic */ 1818461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1819461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1820461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1821461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1822461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1823461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1824461e2c78STakashi Iwai /* SPK */ 1825461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1826461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1827461e2c78STakashi Iwai /* HP, Amp */ 1828461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1829461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1830461e2c78STakashi Iwai /* DAC1 */ 1831461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 183228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1833461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1834461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1835461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1836461e2c78STakashi Iwai /* SPDIF route: PCM */ 18371965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1838461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1839461e2c78STakashi Iwai /* EAPD */ 1840461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1841461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1842461e2c78STakashi Iwai { } /* end */ 1843461e2c78STakashi Iwai }; 1844461e2c78STakashi Iwai 184534cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 184679d7d533STakashi Iwai /* Line in, Mic */ 184779d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 184879d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 184979d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185079d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185179d7d533STakashi Iwai /* SPK */ 185279d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 185379d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 185479d7d533STakashi Iwai /* HP, Amp */ 185579d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 185679d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 185779d7d533STakashi Iwai /* DAC1 */ 185879d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 185928c4edb7SDavid Henningsson /* Record selector: Internal mic */ 186079d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 186179d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 186279d7d533STakashi Iwai /* SPDIF route: PCM */ 186379d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 186479d7d533STakashi Iwai /* EAPD */ 186579d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 186679d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 186779d7d533STakashi Iwai { } /* end */ 186879d7d533STakashi Iwai }; 186979d7d533STakashi Iwai 187034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 187127e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 187227e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187327e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 187427e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187527e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 187627e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 187727e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187827e08988SAristeu Sergio Rozanski Filho /* SPK */ 187927e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 188027e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 188127e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 188227e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 188327e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 188427e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 188527e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 188627e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 188727e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 188827e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 188928c4edb7SDavid Henningsson /* Record selector: Internal mic */ 189027e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 189127e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 189227e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 189327e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 18941965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ 189527e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 189627e08988SAristeu Sergio Rozanski Filho /* EAPD */ 189727e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 189827e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 189927e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 190027e08988SAristeu Sergio Rozanski Filho { } /* end */ 190127e08988SAristeu Sergio Rozanski Filho }; 190227e08988SAristeu Sergio Rozanski Filho 190334cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1904cd9d95a5SKen Prox /* Line in, Mic */ 190530ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1906cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1907cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1908cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1909cd9d95a5SKen Prox /* SPK */ 1910cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1911cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1912cd9d95a5SKen Prox /* HP, Amp */ 1913cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1914cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1915cd9d95a5SKen Prox /* DAC1 */ 1916cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 191728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1918cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1919cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1920cd9d95a5SKen Prox /* SPDIF route: PCM */ 1921cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1922cd9d95a5SKen Prox /* EAPD */ 1923cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1924cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1925cd9d95a5SKen Prox { } /* end */ 1926cd9d95a5SKen Prox }; 1927cd9d95a5SKen Prox 19286953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 19296953e552STakashi Iwai unsigned int event) 19306953e552STakashi Iwai { 19316953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19326953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19336953e552STakashi Iwai AC_USRSP_EN | event); 1934cd372fb3STakashi Iwai snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL); 1935cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 19366953e552STakashi Iwai } 19376953e552STakashi Iwai 193834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1939f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1940f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1941f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1942f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1943f7154de2SHerton Ronaldo Krzesinski }; 1944f7154de2SHerton Ronaldo Krzesinski 1945461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1946461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1947461e2c78STakashi Iwai { 19486953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19496953e552STakashi Iwai 1950461e2c78STakashi Iwai conexant_init(codec); 1951acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19526953e552STakashi Iwai 19536953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19546953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19556953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19566953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19576953e552STakashi Iwai 1958461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1959461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1960461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1961461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1962461e2c78STakashi Iwai } 1963461e2c78STakashi Iwai return 0; 1964461e2c78STakashi Iwai } 1965461e2c78STakashi Iwai 1966461e2c78STakashi Iwai 1967461e2c78STakashi Iwai enum { 1968461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1969461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 197079d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 19711965c441SPierre-Louis Bossart CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ 1972cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1973faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1974f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 19756764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1976461e2c78STakashi Iwai CXT5051_MODELS 1977461e2c78STakashi Iwai }; 1978461e2c78STakashi Iwai 1979ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1980461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1981461e2c78STakashi Iwai [CXT5051_HP] = "hp", 198279d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 198327e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 19845f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1985faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1986f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19876764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1988461e2c78STakashi Iwai }; 1989461e2c78STakashi Iwai 199034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 199179d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19921812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19935f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1994faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1995461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1996461e2c78STakashi Iwai CXT5051_LAPTOP), 1997461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 199827e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 1999f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 2000461e2c78STakashi Iwai {} 2001461e2c78STakashi Iwai }; 2002461e2c78STakashi Iwai 2003461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 2004461e2c78STakashi Iwai { 2005461e2c78STakashi Iwai struct conexant_spec *spec; 2006461e2c78STakashi Iwai int board_config; 2007461e2c78STakashi Iwai 20086764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 20096764bcefSTakashi Iwai cxt5051_models, 20106764bcefSTakashi Iwai cxt5051_cfg_tbl); 20116764bcefSTakashi Iwai if (board_config < 0) 2012c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 20131f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 20146764bcefSTakashi Iwai return patch_conexant_auto(codec); 20156764bcefSTakashi Iwai 2016461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2017461e2c78STakashi Iwai if (!spec) 2018461e2c78STakashi Iwai return -ENOMEM; 2019461e2c78STakashi Iwai codec->spec = spec; 20209421f954STakashi Iwai codec->pin_amp_workaround = 1; 2021461e2c78STakashi Iwai 2022461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 2023461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 2024461e2c78STakashi Iwai 2025461e2c78STakashi Iwai spec->multiout.max_channels = 2; 2026461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 2027461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 2028461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 2029461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 2030461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 20312c7a3fb3STakashi Iwai spec->num_mixers = 2; 20322c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20332c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2034461e2c78STakashi Iwai spec->num_init_verbs = 1; 2035461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2036461e2c78STakashi Iwai spec->spdif_route = 0; 2037461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2038461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2039461e2c78STakashi Iwai spec->cur_adc = 0; 2040461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2041461e2c78STakashi Iwai 20423507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20433507e2a8STakashi Iwai 204479d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 204579d7d533STakashi Iwai 2046faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2047461e2c78STakashi Iwai switch (board_config) { 2048461e2c78STakashi Iwai case CXT5051_HP: 2049461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2050461e2c78STakashi Iwai break; 205179d7d533STakashi Iwai case CXT5051_HP_DV6736: 205279d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 205379d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2054faddaa5dSTakashi Iwai spec->auto_mic = 0; 205579d7d533STakashi Iwai break; 205627e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 205727e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 2058607bc3e4SJerone Young /* Thinkpad X301 does not have S/PDIF wired and no ability 2059607bc3e4SJerone Young to use a docking station. */ 2060607bc3e4SJerone Young if (codec->subsystem_id == 0x17aa211f) 2061607bc3e4SJerone Young spec->multiout.dig_out_nid = 0; 2062461e2c78STakashi Iwai break; 2063cd9d95a5SKen Prox case CXT5051_F700: 2064cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2065cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2066faddaa5dSTakashi Iwai spec->auto_mic = 0; 2067faddaa5dSTakashi Iwai break; 2068faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2069faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2070faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2071cd9d95a5SKen Prox break; 2072f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2073f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2074f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2075f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2076f7154de2SHerton Ronaldo Krzesinski break; 2077461e2c78STakashi Iwai } 2078461e2c78STakashi Iwai 20793507e2a8STakashi Iwai if (spec->beep_amp) 20803507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20813507e2a8STakashi Iwai 2082461e2c78STakashi Iwai return 0; 2083461e2c78STakashi Iwai } 2084461e2c78STakashi Iwai 20850fb67e98SDaniel Drake /* Conexant 5066 specific */ 20860fb67e98SDaniel Drake 208734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 208834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 208934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 209034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 20910fb67e98SDaniel Drake 2092dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2093dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2094dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2095dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2096dbaccc0cSDaniel Drake 209734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20980fb67e98SDaniel Drake { 2, NULL }, 20990fb67e98SDaniel Drake }; 21000fb67e98SDaniel Drake 2101a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2102a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2103a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2104a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2105a3de8ab8STakashi Iwai 21060fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 21070fb67e98SDaniel Drake { 21080fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 21090fb67e98SDaniel Drake unsigned int pinctl; 21100fb67e98SDaniel Drake 21113a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 21123a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 21130fb67e98SDaniel Drake 21140fb67e98SDaniel Drake /* Port A (HP) */ 2115a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 21160fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21170fb67e98SDaniel Drake pinctl); 21180fb67e98SDaniel Drake 21190fb67e98SDaniel Drake /* Port D (HP/LO) */ 2120a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2121a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2122a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2123a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 21243a253445SJohn Baboval pinctl = 0; 21253a253445SJohn Baboval } else { 2126a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2127a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2128a3de8ab8STakashi Iwai pinctl = 0; 21293a253445SJohn Baboval } 21300fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21310fb67e98SDaniel Drake pinctl); 21320fb67e98SDaniel Drake 21330fb67e98SDaniel Drake /* CLASS_D AMP */ 21340fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21350fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21360fb67e98SDaniel Drake pinctl); 21370fb67e98SDaniel Drake } 21380fb67e98SDaniel Drake 21390fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21400fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21410fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21420fb67e98SDaniel Drake { 21430fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21440fb67e98SDaniel Drake 21450fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21460fb67e98SDaniel Drake return 0; 21470fb67e98SDaniel Drake 21480fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21490fb67e98SDaniel Drake return 1; 21500fb67e98SDaniel Drake } 21510fb67e98SDaniel Drake 2152c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2153c4cfe66cSDaniel Drake .num_items = 3, 2154c4cfe66cSDaniel Drake .items = { 2155c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2156c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2157c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2158c4cfe66cSDaniel Drake }, 2159c4cfe66cSDaniel Drake }; 2160c4cfe66cSDaniel Drake 2161c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2162c4cfe66cSDaniel Drake { 2163c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2164c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2165c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2166c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2167c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2168c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2169c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2170c4cfe66cSDaniel Drake } 2171c4cfe66cSDaniel Drake 217275f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 217375f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 217475f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 217575f8991dSDaniel Drake * is happening when it is not. */ 217675f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21770fb67e98SDaniel Drake { 2178dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 217975f8991dSDaniel Drake if (!spec->recording) 218075f8991dSDaniel Drake return; 21810fb67e98SDaniel Drake 2182c4cfe66cSDaniel Drake if (spec->dc_enable) { 2183c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2184c4cfe66cSDaniel Drake * through our special DC port */ 2185c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2186c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2187c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2188c4cfe66cSDaniel Drake 2189c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2190c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2191c4cfe66cSDaniel Drake {}, 2192c4cfe66cSDaniel Drake }; 2193c4cfe66cSDaniel Drake 2194c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2195c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2196c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2197c4cfe66cSDaniel Drake return; 2198c4cfe66cSDaniel Drake } 2199c4cfe66cSDaniel Drake 2200c4cfe66cSDaniel Drake /* disable DC (port F) */ 2201c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2202c4cfe66cSDaniel Drake 220375f8991dSDaniel Drake /* external mic, port B */ 220475f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 220575f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 22060fb67e98SDaniel Drake 220775f8991dSDaniel Drake /* internal mic, port C */ 220875f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 220975f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 221075f8991dSDaniel Drake } 22110fb67e98SDaniel Drake 221275f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 221375f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 221475f8991dSDaniel Drake { 221575f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 22160fb67e98SDaniel Drake unsigned int present; 22170fb67e98SDaniel Drake 2218c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2219c4cfe66cSDaniel Drake return; 2220c4cfe66cSDaniel Drake 222175f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 222275f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 222375f8991dSDaniel Drake if (present) 22240fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 222575f8991dSDaniel Drake else 22260fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 222775f8991dSDaniel Drake 222875f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 222975f8991dSDaniel Drake present ? 0 : 1); 223075f8991dSDaniel Drake spec->ext_mic_present = !!present; 223175f8991dSDaniel Drake 223275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22330fb67e98SDaniel Drake } 22340fb67e98SDaniel Drake 223595a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 223695a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 223795a618bdSEinar Rünkaru { 223895a618bdSEinar Rünkaru unsigned int present; 223995a618bdSEinar Rünkaru 224095a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 224195a618bdSEinar Rünkaru /* enable external mic, port B */ 224275f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 224395a618bdSEinar Rünkaru 224495a618bdSEinar Rünkaru /* switch to external mic input */ 224595a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 224695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 224795a618bdSEinar Rünkaru 224895a618bdSEinar Rünkaru /* disable internal digital mic */ 224995a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 225095a618bdSEinar Rünkaru {} 225195a618bdSEinar Rünkaru }; 225234cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 225395a618bdSEinar Rünkaru /* enable internal mic, port C */ 225495a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 225595a618bdSEinar Rünkaru 225695a618bdSEinar Rünkaru /* switch to internal mic input */ 225795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 225895a618bdSEinar Rünkaru 225995a618bdSEinar Rünkaru /* disable external mic, port B */ 226095a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 226195a618bdSEinar Rünkaru {} 226295a618bdSEinar Rünkaru }; 226395a618bdSEinar Rünkaru 226495a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 226595a618bdSEinar Rünkaru if (present) { 226695a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 226795a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 226895a618bdSEinar Rünkaru } else { 226995a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 227095a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 227195a618bdSEinar Rünkaru } 227295a618bdSEinar Rünkaru } 227395a618bdSEinar Rünkaru 2274cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2275cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2276cfd3d8dcSGreg Alexander { 2277cfd3d8dcSGreg Alexander unsigned int present; 2278cfd3d8dcSGreg Alexander 2279cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2280cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2281cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2282cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2283cfd3d8dcSGreg Alexander {} 2284cfd3d8dcSGreg Alexander }; 228534cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2286cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2287cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2288cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2289cfd3d8dcSGreg Alexander {} 2290cfd3d8dcSGreg Alexander }; 2291cfd3d8dcSGreg Alexander 2292cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2293cfd3d8dcSGreg Alexander if (present) { 2294cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2295cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2296cfd3d8dcSGreg Alexander } else { 2297cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2298cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2299cfd3d8dcSGreg Alexander } 2300cfd3d8dcSGreg Alexander } 2301cfd3d8dcSGreg Alexander 2302a1d6906eSDavid Henningsson 2303a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2304a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2305a1d6906eSDavid Henningsson { 2306a1d6906eSDavid Henningsson unsigned int present; 2307a1d6906eSDavid Henningsson 2308a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2309a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2310a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2311a1d6906eSDavid Henningsson present ? 1 : 0); 2312a1d6906eSDavid Henningsson } 2313a1d6906eSDavid Henningsson 2314a1d6906eSDavid Henningsson 2315048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2316048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2317048e78a5SDavid Henningsson { 2318048e78a5SDavid Henningsson unsigned int present; 2319048e78a5SDavid Henningsson 2320048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2321048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2322048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2323048e78a5SDavid Henningsson present ? 1 : 3); 2324048e78a5SDavid Henningsson } 2325048e78a5SDavid Henningsson 2326048e78a5SDavid Henningsson 23277b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 23287b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 23297b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23307b2bfdbcSJens Taprogge { 23317b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23327b2bfdbcSJens Taprogge 233334cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 23347b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23357b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23367b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23377b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23387b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23397b2bfdbcSJens Taprogge {} 23407b2bfdbcSJens Taprogge }; 234134cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 23427b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23437b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23447b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23457b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23467b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23477b2bfdbcSJens Taprogge {} 23487b2bfdbcSJens Taprogge }; 234934cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 23507b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23517b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23527b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23537b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23547b2bfdbcSJens Taprogge {} 23557b2bfdbcSJens Taprogge }; 23567b2bfdbcSJens Taprogge 23577b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23587b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23597b2bfdbcSJens Taprogge if (ext_present) { 23607b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23617b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23627b2bfdbcSJens Taprogge } else if (dock_present) { 23637b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23647b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23657b2bfdbcSJens Taprogge } else { 23667b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23677b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23687b2bfdbcSJens Taprogge } 23697b2bfdbcSJens Taprogge } 23707b2bfdbcSJens Taprogge 23710fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23720fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23730fb67e98SDaniel Drake { 23740fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23750fb67e98SDaniel Drake unsigned int portA, portD; 23760fb67e98SDaniel Drake 23770fb67e98SDaniel Drake /* Port A */ 2378d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23790fb67e98SDaniel Drake 23800fb67e98SDaniel Drake /* Port D */ 2381d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23820fb67e98SDaniel Drake 2383a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2384a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 23850fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23860fb67e98SDaniel Drake portA, portD, spec->hp_present); 23870fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23880fb67e98SDaniel Drake } 23890fb67e98SDaniel Drake 239002b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 239102b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 239202b6b5b6SDavid Henningsson { 239302b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 239402b6b5b6SDavid Henningsson 239502b6b5b6SDavid Henningsson if (spec->dell_vostro) 239602b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 239702b6b5b6SDavid Henningsson else if (spec->ideapad) 239802b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 239902b6b5b6SDavid Henningsson else if (spec->thinkpad) 240002b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 240102b6b5b6SDavid Henningsson else if (spec->hp_laptop) 240202b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2403a1d6906eSDavid Henningsson else if (spec->asus) 2404a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 240502b6b5b6SDavid Henningsson } 240602b6b5b6SDavid Henningsson 24070fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 240875f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 24090fb67e98SDaniel Drake { 2410c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24110fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 24120fb67e98SDaniel Drake switch (res >> 26) { 24130fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 24140fb67e98SDaniel Drake cxt5066_hp_automute(codec); 24150fb67e98SDaniel Drake break; 24160fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2417c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2418c4cfe66cSDaniel Drake if (!spec->dc_enable) 241975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 24200fb67e98SDaniel Drake break; 24210fb67e98SDaniel Drake } 24220fb67e98SDaniel Drake } 24230fb67e98SDaniel Drake 242495a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 242502b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 242695a618bdSEinar Rünkaru { 242702b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 242895a618bdSEinar Rünkaru switch (res >> 26) { 242995a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 243095a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 243195a618bdSEinar Rünkaru break; 243295a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 243302b6b5b6SDavid Henningsson cxt5066_automic(codec); 243495a618bdSEinar Rünkaru break; 243595a618bdSEinar Rünkaru } 243695a618bdSEinar Rünkaru } 243795a618bdSEinar Rünkaru 24387b2bfdbcSJens Taprogge 24390fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24400fb67e98SDaniel Drake .num_items = 5, 24410fb67e98SDaniel Drake .items = { 24420fb67e98SDaniel Drake { "0dB", 0 }, 24430fb67e98SDaniel Drake { "10dB", 1 }, 24440fb67e98SDaniel Drake { "20dB", 2 }, 24450fb67e98SDaniel Drake { "30dB", 3 }, 24460fb67e98SDaniel Drake { "40dB", 4 }, 24470fb67e98SDaniel Drake }, 24480fb67e98SDaniel Drake }; 24490fb67e98SDaniel Drake 2450cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2451c4cfe66cSDaniel Drake { 2452c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2453cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2454c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2455c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2456c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24577b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2458cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2459cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2460cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2461cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2462cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2463cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2464cfd3d8dcSGreg Alexander } 2465c4cfe66cSDaniel Drake } 2466c4cfe66cSDaniel Drake 24670fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24680fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24690fb67e98SDaniel Drake { 24700fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24710fb67e98SDaniel Drake } 24720fb67e98SDaniel Drake 24730fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24740fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24750fb67e98SDaniel Drake { 24760fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2477c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2478c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 24790fb67e98SDaniel Drake return 0; 24800fb67e98SDaniel Drake } 24810fb67e98SDaniel Drake 24820fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 24830fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24840fb67e98SDaniel Drake { 24850fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2486c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24870fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 24880fb67e98SDaniel Drake unsigned int idx; 24890fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 24900fb67e98SDaniel Drake if (idx >= imux->num_items) 24910fb67e98SDaniel Drake idx = imux->num_items - 1; 24920fb67e98SDaniel Drake 2493c4cfe66cSDaniel Drake spec->mic_boost = idx; 2494c4cfe66cSDaniel Drake if (!spec->dc_enable) 2495c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2496c4cfe66cSDaniel Drake return 1; 2497c4cfe66cSDaniel Drake } 24980fb67e98SDaniel Drake 2499c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2500c4cfe66cSDaniel Drake { 2501c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2502c4cfe66cSDaniel Drake /* disable gain */ 2503c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2504c4cfe66cSDaniel Drake 2505c4cfe66cSDaniel Drake /* switch to DC input */ 2506c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2507c4cfe66cSDaniel Drake {} 2508c4cfe66cSDaniel Drake }; 2509c4cfe66cSDaniel Drake 2510c4cfe66cSDaniel Drake /* configure as input source */ 2511c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2512c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2513c4cfe66cSDaniel Drake } 2514c4cfe66cSDaniel Drake 2515c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2516c4cfe66cSDaniel Drake { 2517c4cfe66cSDaniel Drake /* reconfigure input source */ 2518c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2519c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2520c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2521c4cfe66cSDaniel Drake } 2522c4cfe66cSDaniel Drake 2523c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2524c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2525c4cfe66cSDaniel Drake { 2526c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2527c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2528c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2529c4cfe66cSDaniel Drake return 0; 2530c4cfe66cSDaniel Drake } 2531c4cfe66cSDaniel Drake 2532c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2533c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2534c4cfe66cSDaniel Drake { 2535c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2536c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2537c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2538c4cfe66cSDaniel Drake 2539c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2540c4cfe66cSDaniel Drake return 0; 2541c4cfe66cSDaniel Drake 2542c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2543c4cfe66cSDaniel Drake if (dc_enable) 2544c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2545c4cfe66cSDaniel Drake else 2546c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2547c4cfe66cSDaniel Drake 2548c4cfe66cSDaniel Drake return 1; 2549c4cfe66cSDaniel Drake } 2550c4cfe66cSDaniel Drake 2551c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2552c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2553c4cfe66cSDaniel Drake { 2554c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2555c4cfe66cSDaniel Drake } 2556c4cfe66cSDaniel Drake 2557c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2558c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2559c4cfe66cSDaniel Drake { 2560c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2561c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2562c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2563c4cfe66cSDaniel Drake return 0; 2564c4cfe66cSDaniel Drake } 2565c4cfe66cSDaniel Drake 2566c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2567c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2568c4cfe66cSDaniel Drake { 2569c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2570c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2571c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2572c4cfe66cSDaniel Drake unsigned int idx; 2573c4cfe66cSDaniel Drake 2574c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2575c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2576c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2577c4cfe66cSDaniel Drake 2578c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2579c4cfe66cSDaniel Drake if (spec->dc_enable) 2580c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25810fb67e98SDaniel Drake return 1; 25820fb67e98SDaniel Drake } 25830fb67e98SDaniel Drake 258475f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 258575f8991dSDaniel Drake { 258675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 258775f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 258875f8991dSDaniel Drake * recording LED comes on. */ 258975f8991dSDaniel Drake spec->recording = 1; 259075f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 259175f8991dSDaniel Drake } 259275f8991dSDaniel Drake 259375f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 259475f8991dSDaniel Drake { 259575f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 259675f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 259775f8991dSDaniel Drake /* disable external mic, port B */ 259875f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 259975f8991dSDaniel Drake 260075f8991dSDaniel Drake /* disble internal mic, port C */ 260175f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2602c4cfe66cSDaniel Drake 2603c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2604c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 260575f8991dSDaniel Drake {}, 260675f8991dSDaniel Drake }; 260775f8991dSDaniel Drake 260875f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 260975f8991dSDaniel Drake spec->recording = 0; 261075f8991dSDaniel Drake } 261175f8991dSDaniel Drake 2612f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 261334cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2614f6a2491cSAndy Robinson int num_pins) 2615f6a2491cSAndy Robinson { 2616f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2617f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2618f6a2491cSAndy Robinson int i; 2619f6a2491cSAndy Robinson 2620f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2621f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2622f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2623f6a2491cSAndy Robinson continue; 2624f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2625f6a2491cSAndy Robinson continue; 2626f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2627f6a2491cSAndy Robinson nid_loc++; 2628f6a2491cSAndy Robinson else 2629f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2630f6a2491cSAndy Robinson } 2631f6a2491cSAndy Robinson } 2632f6a2491cSAndy Robinson 263334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 26340fb67e98SDaniel Drake .num_items = 4, 26350fb67e98SDaniel Drake .items = { 26360fb67e98SDaniel Drake { "Mic B", 0 }, 26370fb67e98SDaniel Drake { "Mic C", 1 }, 26380fb67e98SDaniel Drake { "Mic E", 2 }, 26390fb67e98SDaniel Drake { "Mic F", 3 }, 26400fb67e98SDaniel Drake }, 26410fb67e98SDaniel Drake }; 26420fb67e98SDaniel Drake 264334cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26440fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26450fb67e98SDaniel Drake .values = { 26460fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26470fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26480fb67e98SDaniel Drake 0 26490fb67e98SDaniel Drake }, 26500fb67e98SDaniel Drake }; 26510fb67e98SDaniel Drake 265234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26530fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26540fb67e98SDaniel Drake .values = { 26550fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26560fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26570fb67e98SDaniel Drake 0 26580fb67e98SDaniel Drake }, 26590fb67e98SDaniel Drake }; 26600fb67e98SDaniel Drake 266134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 26620fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26630fb67e98SDaniel Drake {} 26640fb67e98SDaniel Drake }; 26650fb67e98SDaniel Drake 266634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26670fb67e98SDaniel Drake { 26680fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26690fb67e98SDaniel Drake .name = "Master Playback Volume", 26700fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26710fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26720fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26735e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26740fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26750fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26760fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26770fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26780fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26790fb67e98SDaniel Drake .private_value = 26800fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26810fb67e98SDaniel Drake }, 26820fb67e98SDaniel Drake {} 26830fb67e98SDaniel Drake }; 26840fb67e98SDaniel Drake 268534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2686c4cfe66cSDaniel Drake { 2687c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2688c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2689c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2690c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2691c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2692c4cfe66cSDaniel Drake }, 2693c4cfe66cSDaniel Drake { 2694c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2695c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2696c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2697c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2698c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2699c4cfe66cSDaniel Drake }, 2700c4cfe66cSDaniel Drake {} 2701c4cfe66cSDaniel Drake }; 2702c4cfe66cSDaniel Drake 270334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 27040fb67e98SDaniel Drake { 27050fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 27060fb67e98SDaniel Drake .name = "Master Playback Switch", 27070fb67e98SDaniel Drake .info = cxt_eapd_info, 27080fb67e98SDaniel Drake .get = cxt_eapd_get, 27090fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 27100fb67e98SDaniel Drake .private_value = 0x1d, 27110fb67e98SDaniel Drake }, 27120fb67e98SDaniel Drake 27130fb67e98SDaniel Drake { 27140fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2715c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 27160fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 27170fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 27180fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 27190fb67e98SDaniel Drake }, 27200fb67e98SDaniel Drake 27210fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 27220fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 27230fb67e98SDaniel Drake {} 27240fb67e98SDaniel Drake }; 27250fb67e98SDaniel Drake 272634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2727254bba6aSEinar Rünkaru { 2728254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 272928c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2730254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2731254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2732254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2733254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2734254bba6aSEinar Rünkaru }, 2735254bba6aSEinar Rünkaru {} 2736254bba6aSEinar Rünkaru }; 2737254bba6aSEinar Rünkaru 273834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 27390fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27400fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27410fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27420fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27430fb67e98SDaniel Drake 27440fb67e98SDaniel Drake /* Speakers */ 27450fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27460fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27470fb67e98SDaniel Drake 27480fb67e98SDaniel Drake /* HP, Amp */ 27490fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27500fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27510fb67e98SDaniel Drake 27520fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27530fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27540fb67e98SDaniel Drake 27550fb67e98SDaniel Drake /* DAC1 */ 27560fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27570fb67e98SDaniel Drake 27580fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27590fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27600fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27610fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27620fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27630fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27640fb67e98SDaniel Drake 27650fb67e98SDaniel Drake /* no digital microphone support yet */ 27660fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27670fb67e98SDaniel Drake 27680fb67e98SDaniel Drake /* Audio input selector */ 27690fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27700fb67e98SDaniel Drake 27710fb67e98SDaniel Drake /* SPDIF route: PCM */ 27720fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27730fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27740fb67e98SDaniel Drake 27750fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27760fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27770fb67e98SDaniel Drake 27780fb67e98SDaniel Drake /* EAPD */ 27790fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27800fb67e98SDaniel Drake 27810fb67e98SDaniel Drake /* not handling these yet */ 27820fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27830fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27840fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27850fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27860fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27870fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27880fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27890fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27900fb67e98SDaniel Drake { } /* end */ 27910fb67e98SDaniel Drake }; 27920fb67e98SDaniel Drake 279334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27940fb67e98SDaniel Drake /* Port A: headphones */ 27950fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27960fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27970fb67e98SDaniel Drake 27980fb67e98SDaniel Drake /* Port B: external microphone */ 279975f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28000fb67e98SDaniel Drake 28010fb67e98SDaniel Drake /* Port C: internal microphone */ 280275f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28030fb67e98SDaniel Drake 28040fb67e98SDaniel Drake /* Port D: unused */ 28050fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28060fb67e98SDaniel Drake 28070fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 28080fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28090fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28100fb67e98SDaniel Drake 2811c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 28120fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28130fb67e98SDaniel Drake 28140fb67e98SDaniel Drake /* Port G: internal speakers */ 28150fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28160fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28170fb67e98SDaniel Drake 28180fb67e98SDaniel Drake /* DAC1 */ 28190fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28200fb67e98SDaniel Drake 28210fb67e98SDaniel Drake /* DAC2: unused */ 28220fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 28230fb67e98SDaniel Drake 28240fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28250fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28260fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28270fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28280fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28290fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28300fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28310fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28320fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28330fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28340fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28350fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28360fb67e98SDaniel Drake 28370fb67e98SDaniel Drake /* Disable digital microphone port */ 28380fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28390fb67e98SDaniel Drake 28400fb67e98SDaniel Drake /* Audio input selectors */ 28410fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28420fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28430fb67e98SDaniel Drake 28440fb67e98SDaniel Drake /* Disable SPDIF */ 28450fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28460fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28470fb67e98SDaniel Drake 28480fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28490fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28500fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28510fb67e98SDaniel Drake { } /* end */ 28520fb67e98SDaniel Drake }; 28530fb67e98SDaniel Drake 285434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 285595a618bdSEinar Rünkaru /* Port A: headphones */ 285695a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 285795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 285895a618bdSEinar Rünkaru 285995a618bdSEinar Rünkaru /* Port B: external microphone */ 286095a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286195a618bdSEinar Rünkaru 286295a618bdSEinar Rünkaru /* Port C: unused */ 286395a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286495a618bdSEinar Rünkaru 286595a618bdSEinar Rünkaru /* Port D: unused */ 286695a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286795a618bdSEinar Rünkaru 286895a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 286995a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287095a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 287195a618bdSEinar Rünkaru 287295a618bdSEinar Rünkaru /* Port F: unused */ 287395a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 287495a618bdSEinar Rünkaru 287595a618bdSEinar Rünkaru /* Port G: internal speakers */ 287695a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 287795a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 287895a618bdSEinar Rünkaru 287995a618bdSEinar Rünkaru /* DAC1 */ 288095a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 288195a618bdSEinar Rünkaru 288295a618bdSEinar Rünkaru /* DAC2: unused */ 288395a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 288495a618bdSEinar Rünkaru 288595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 288695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 288795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 288895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 288995a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289395a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 289495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 289595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 289695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 289795a618bdSEinar Rünkaru 289895a618bdSEinar Rünkaru /* Digital microphone port */ 289995a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 290095a618bdSEinar Rünkaru 290195a618bdSEinar Rünkaru /* Audio input selectors */ 290295a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 290395a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 290495a618bdSEinar Rünkaru 290595a618bdSEinar Rünkaru /* Disable SPDIF */ 290695a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 290795a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 290895a618bdSEinar Rünkaru 290995a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 291095a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 291195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 291295a618bdSEinar Rünkaru { } /* end */ 291395a618bdSEinar Rünkaru }; 291495a618bdSEinar Rünkaru 291534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2916cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2917cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2918cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2919cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2920cfd3d8dcSGreg Alexander 2921cfd3d8dcSGreg Alexander /* Speakers */ 2922cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2923cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2924cfd3d8dcSGreg Alexander 2925cfd3d8dcSGreg Alexander /* HP, Amp */ 2926cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2927cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2928cfd3d8dcSGreg Alexander 2929cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2930cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2931cfd3d8dcSGreg Alexander 2932cfd3d8dcSGreg Alexander /* DAC1 */ 2933cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2934cfd3d8dcSGreg Alexander 2935cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2936cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2937cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2938cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2939cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2940cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2941cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2942cfd3d8dcSGreg Alexander 2943cfd3d8dcSGreg Alexander /* Audio input selector */ 2944cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2945cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2946cfd3d8dcSGreg Alexander 2947cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2948cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2949cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2950cfd3d8dcSGreg Alexander 2951cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2952cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2953cfd3d8dcSGreg Alexander 2954cfd3d8dcSGreg Alexander /* internal microphone */ 295528c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2956cfd3d8dcSGreg Alexander 2957cfd3d8dcSGreg Alexander /* EAPD */ 2958cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2959cfd3d8dcSGreg Alexander 2960cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2961cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2962cfd3d8dcSGreg Alexander { } /* end */ 2963cfd3d8dcSGreg Alexander }; 2964cfd3d8dcSGreg Alexander 296534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29667b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29677b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29687b2bfdbcSJens Taprogge 29697b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29707b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29717b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29727b2bfdbcSJens Taprogge 29737b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29747b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29757b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29767b2bfdbcSJens Taprogge 29777b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29787b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29797b2bfdbcSJens Taprogge 29807b2bfdbcSJens Taprogge /* Port C: Mic */ 29817b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29827b2bfdbcSJens Taprogge 29837b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29847b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29857b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29867b2bfdbcSJens Taprogge 29877b2bfdbcSJens Taprogge /* DAC1 */ 29887b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29897b2bfdbcSJens Taprogge 29907b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29917b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29927b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29937b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29947b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29957b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29967b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29977b2bfdbcSJens Taprogge 29987b2bfdbcSJens Taprogge /* Audio input selector */ 29997b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 30007b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 30017b2bfdbcSJens Taprogge 30027b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 30037b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 30047b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 30057b2bfdbcSJens Taprogge 30067b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30077b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30087b2bfdbcSJens Taprogge 30097b2bfdbcSJens Taprogge /* internal microphone */ 301028c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 30117b2bfdbcSJens Taprogge 30127b2bfdbcSJens Taprogge /* EAPD */ 30137b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 30147b2bfdbcSJens Taprogge 30157b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 30167b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30177b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30187b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30197b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30207b2bfdbcSJens Taprogge { } /* end */ 30217b2bfdbcSJens Taprogge }; 30227b2bfdbcSJens Taprogge 302334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 30240fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30250fb67e98SDaniel Drake { } /* end */ 30260fb67e98SDaniel Drake }; 30270fb67e98SDaniel Drake 3028048e78a5SDavid Henningsson 302934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3030048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3031048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3032048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3033048e78a5SDavid Henningsson { } /* end */ 3034048e78a5SDavid Henningsson }; 3035048e78a5SDavid Henningsson 30360fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30370fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30380fb67e98SDaniel Drake { 30390fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30400fb67e98SDaniel Drake conexant_init(codec); 30410fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30420fb67e98SDaniel Drake cxt5066_hp_automute(codec); 304302b6b5b6SDavid Henningsson cxt5066_automic(codec); 30440fb67e98SDaniel Drake } 3045c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30460fb67e98SDaniel Drake return 0; 30470fb67e98SDaniel Drake } 30480fb67e98SDaniel Drake 304975f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 305075f8991dSDaniel Drake { 3051c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 305275f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 305375f8991dSDaniel Drake conexant_init(codec); 305475f8991dSDaniel Drake cxt5066_hp_automute(codec); 3055c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3056c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 305775f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3058c4cfe66cSDaniel Drake } else { 3059c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3060c4cfe66cSDaniel Drake } 306175f8991dSDaniel Drake return 0; 306275f8991dSDaniel Drake } 306375f8991dSDaniel Drake 30640fb67e98SDaniel Drake enum { 30650fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30660fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30670fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 30681feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 3069cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30707b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3071a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 3072048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 3073fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 30740fb67e98SDaniel Drake CXT5066_MODELS 30750fb67e98SDaniel Drake }; 30760fb67e98SDaniel Drake 3077ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 30780fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30790fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30800fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30811feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3082cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30837b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3084a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 3085048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 3086fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 30870fb67e98SDaniel Drake }; 30880fb67e98SDaniel Drake 308934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30909966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 309100cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30921feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30938a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3094ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30951feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3096231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3097ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3098ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3099048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3100f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3101a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3102f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 31032ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3104c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 31054442dd46SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 31065637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 31075637edb2SDavid Henningsson CXT5066_LAPTOP), 31085637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 31094d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3110ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 311119593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 31127b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 311384012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3114b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3115d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3116a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3117af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 311822f21d51SDavid Henningsson SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ 31197ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 31200fb67e98SDaniel Drake {} 31210fb67e98SDaniel Drake }; 31220fb67e98SDaniel Drake 31230fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 31240fb67e98SDaniel Drake { 31250fb67e98SDaniel Drake struct conexant_spec *spec; 31260fb67e98SDaniel Drake int board_config; 31270fb67e98SDaniel Drake 3128fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3129fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3130fea4a4f9STakashi Iwai if (board_config < 0) 3131c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3132fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3133fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3134fea4a4f9STakashi Iwai 31350fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31360fb67e98SDaniel Drake if (!spec) 31370fb67e98SDaniel Drake return -ENOMEM; 31380fb67e98SDaniel Drake codec->spec = spec; 31390fb67e98SDaniel Drake 31400fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 314175f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31420fb67e98SDaniel Drake 31430fb67e98SDaniel Drake spec->dell_automute = 0; 31440fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31450fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31460fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3147f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3148f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 31490fb67e98SDaniel Drake spec->num_adc_nids = 1; 31500fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31510fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31520fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31530fb67e98SDaniel Drake 31540fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31550fb67e98SDaniel Drake 31560fb67e98SDaniel Drake spec->num_init_verbs = 1; 31570fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31580fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31590fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31600fb67e98SDaniel Drake spec->cur_adc = 0; 31610fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31620fb67e98SDaniel Drake 31633507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31643507e2a8STakashi Iwai 31650fb67e98SDaniel Drake switch (board_config) { 31660fb67e98SDaniel Drake default: 31670fb67e98SDaniel Drake case CXT5066_LAPTOP: 31680fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31690fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31700fb67e98SDaniel Drake break; 31710fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31720fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31730fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31740fb67e98SDaniel Drake 31750fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31760fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31770fb67e98SDaniel Drake spec->num_init_verbs++; 31780fb67e98SDaniel Drake spec->dell_automute = 1; 31790fb67e98SDaniel Drake break; 3180a1d6906eSDavid Henningsson case CXT5066_ASUS: 3181048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3182048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 318302b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3184048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3185048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3186048e78a5SDavid Henningsson spec->num_init_verbs++; 3187a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3188a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3189048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3190048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3191048e78a5SDavid Henningsson /* no S/PDIF out */ 3192f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3193048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3194048e78a5SDavid Henningsson /* input source automatically selected */ 3195048e78a5SDavid Henningsson spec->input_mux = NULL; 3196048e78a5SDavid Henningsson spec->port_d_mode = 0; 3197048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3198048e78a5SDavid Henningsson break; 3199048e78a5SDavid Henningsson 32000fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 320175f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 320275f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 32030fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 32040fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3205c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 32060fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32070fb67e98SDaniel Drake spec->port_d_mode = 0; 3208c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 32090fb67e98SDaniel Drake 32100fb67e98SDaniel Drake /* no S/PDIF out */ 32110fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 32120fb67e98SDaniel Drake 32130fb67e98SDaniel Drake /* input source automatically selected */ 32140fb67e98SDaniel Drake spec->input_mux = NULL; 321575f8991dSDaniel Drake 321675f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 321775f8991dSDaniel Drake * at the right time */ 321875f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 321975f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 32200fb67e98SDaniel Drake break; 32211feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 322275f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 322302b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 322495a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 322595a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 322695a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3227254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 322895a618bdSEinar Rünkaru spec->port_d_mode = 0; 3229254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3230c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 323195a618bdSEinar Rünkaru 323295a618bdSEinar Rünkaru /* no S/PDIF out */ 323395a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 323495a618bdSEinar Rünkaru 323595a618bdSEinar Rünkaru /* input source automatically selected */ 323695a618bdSEinar Rünkaru spec->input_mux = NULL; 323795a618bdSEinar Rünkaru break; 3238cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3239cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 324002b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3241cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3242cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3243cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3244cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3245cfd3d8dcSGreg Alexander spec->ideapad = 1; 3246cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3247cfd3d8dcSGreg Alexander 3248cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3249cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3250cfd3d8dcSGreg Alexander 3251cfd3d8dcSGreg Alexander /* input source automatically selected */ 3252cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3253cfd3d8dcSGreg Alexander break; 32547b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32557b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 325602b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 32577b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32587b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32597b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32607b2bfdbcSJens Taprogge spec->thinkpad = 1; 32617b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32627b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32637b2bfdbcSJens Taprogge 32647b2bfdbcSJens Taprogge /* no S/PDIF out */ 32657b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32667b2bfdbcSJens Taprogge 32677b2bfdbcSJens Taprogge /* input source automatically selected */ 32687b2bfdbcSJens Taprogge spec->input_mux = NULL; 32697b2bfdbcSJens Taprogge break; 32700fb67e98SDaniel Drake } 32710fb67e98SDaniel Drake 32723507e2a8STakashi Iwai if (spec->beep_amp) 32733507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32743507e2a8STakashi Iwai 32750fb67e98SDaniel Drake return 0; 32760fb67e98SDaniel Drake } 3277461e2c78STakashi Iwai 3278461e2c78STakashi Iwai /* 3279f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3280f2e5731dSTakashi Iwai */ 3281f2e5731dSTakashi Iwai 32826764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 32836764bcefSTakashi Iwai struct hda_codec *codec, 32846764bcefSTakashi Iwai unsigned int stream_tag, 32856764bcefSTakashi Iwai unsigned int format, 32866764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32876764bcefSTakashi Iwai { 32886764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 328947ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 32906764bcefSTakashi Iwai if (spec->adc_switching) { 32916764bcefSTakashi Iwai spec->cur_adc = adc; 32926764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32936764bcefSTakashi Iwai spec->cur_adc_format = format; 32946764bcefSTakashi Iwai } 32956764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32966764bcefSTakashi Iwai return 0; 32976764bcefSTakashi Iwai } 32986764bcefSTakashi Iwai 32996764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 33006764bcefSTakashi Iwai struct hda_codec *codec, 33016764bcefSTakashi Iwai struct snd_pcm_substream *substream) 33026764bcefSTakashi Iwai { 33036764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 33046764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 33056764bcefSTakashi Iwai spec->cur_adc = 0; 33066764bcefSTakashi Iwai return 0; 33076764bcefSTakashi Iwai } 33086764bcefSTakashi Iwai 33096764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 33106764bcefSTakashi Iwai .substreams = 1, 33116764bcefSTakashi Iwai .channels_min = 2, 33126764bcefSTakashi Iwai .channels_max = 2, 33136764bcefSTakashi Iwai .nid = 0, /* fill later */ 33146764bcefSTakashi Iwai .ops = { 33156764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 33166764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 33176764bcefSTakashi Iwai }, 33186764bcefSTakashi Iwai }; 33196764bcefSTakashi Iwai 332034cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3321f2e5731dSTakashi Iwai 33228d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 33238d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3324f2e5731dSTakashi Iwai 3325f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3326f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3327f2e5731dSTakashi Iwai * not found 3328f2e5731dSTakashi Iwai */ 3329f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3330f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3331f2e5731dSTakashi Iwai { 3332f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3333f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3334f2e5731dSTakashi Iwai 3335f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3336f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3337f2e5731dSTakashi Iwai ret = dacs[i]; 3338f2e5731dSTakashi Iwai break; 3339f2e5731dSTakashi Iwai } 3340f2e5731dSTakashi Iwai } 3341f2e5731dSTakashi Iwai if (!ret) 3342f2e5731dSTakashi Iwai return 0; 3343f2e5731dSTakashi Iwai if (--nums > 0) 3344f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3345f2e5731dSTakashi Iwai *num_dacs = nums; 3346f2e5731dSTakashi Iwai return ret; 3347f2e5731dSTakashi Iwai } 3348f2e5731dSTakashi Iwai 3349f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3350f2e5731dSTakashi Iwai 3351f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3352f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3353f2e5731dSTakashi Iwai { 3354f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3355f2e5731dSTakashi Iwai int nums = 0; 3356f2e5731dSTakashi Iwai 3357f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3358f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3359f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3360f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3361f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3362f2e5731dSTakashi Iwai dacs[nums++] = nid; 3363f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3364f2e5731dSTakashi Iwai break; 3365f2e5731dSTakashi Iwai } 3366f2e5731dSTakashi Iwai } 3367f2e5731dSTakashi Iwai return nums; 3368f2e5731dSTakashi Iwai } 3369f2e5731dSTakashi Iwai 3370f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3371f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3372f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3373f2e5731dSTakashi Iwai struct pin_dac_pair *filled, int type) 3374f2e5731dSTakashi Iwai { 3375f2e5731dSTakashi Iwai int i, nums; 3376f2e5731dSTakashi Iwai 3377f2e5731dSTakashi Iwai nums = 0; 3378f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3379f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3380f2e5731dSTakashi Iwai filled[nums].type = type; 3381f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3382f2e5731dSTakashi Iwai nums++; 3383f2e5731dSTakashi Iwai } 3384f2e5731dSTakashi Iwai return nums; 3385f2e5731dSTakashi Iwai } 3386f2e5731dSTakashi Iwai 3387f2e5731dSTakashi Iwai /* parse analog output paths */ 3388f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3389f2e5731dSTakashi Iwai { 3390f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3391f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3392f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3393f2e5731dSTakashi Iwai int i, j, nums, rest; 3394f2e5731dSTakashi Iwai 3395f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3396f2e5731dSTakashi Iwai /* parse all analog output pins */ 3397f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3398f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info, 3399f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3400f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3401f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3402f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3403f2e5731dSTakashi Iwai nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3404f2e5731dSTakashi Iwai dacs, &rest, spec->dac_info + nums, 3405f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3406f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3407f2e5731dSTakashi Iwai /* fill multiout struct */ 3408f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3409f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 3410f2e5731dSTakashi Iwai if (!dac) 3411f2e5731dSTakashi Iwai continue; 3412f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3413f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3414f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3415f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3416f2e5731dSTakashi Iwai break; 3417f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3418f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3419f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3420f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3421f2e5731dSTakashi Iwai break; 3422f2e5731dSTakashi Iwai } 3423f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3424f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3425f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3426f2e5731dSTakashi Iwai break; 3427f2e5731dSTakashi Iwai } 3428f2e5731dSTakashi Iwai break; 3429f2e5731dSTakashi Iwai } 3430f2e5731dSTakashi Iwai } 3431f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 343289724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3433f2e5731dSTakashi Iwai 343403697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 343503697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3436f2e5731dSTakashi Iwai spec->auto_mute = 1; 343703697e2aSTakashi Iwai break; 343803697e2aSTakashi Iwai } 343903697e2aSTakashi Iwai } 3440e2df82ffSTakashi Iwai if (spec->auto_mute && 3441e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3442e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 344303697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 344403697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 344503697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 344603697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 344703697e2aSTakashi Iwai spec->detect_line = 1; 344803697e2aSTakashi Iwai break; 344903697e2aSTakashi Iwai } 345003697e2aSTakashi Iwai } 345103697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 345203697e2aSTakashi Iwai } 345303697e2aSTakashi Iwai 3454f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3455f2e5731dSTakashi Iwai } 3456f2e5731dSTakashi Iwai 3457da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3458da339866STakashi Iwai hda_nid_t *pins, bool on); 3459da339866STakashi Iwai 346003697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 346103697e2aSTakashi Iwai hda_nid_t *pins, bool on) 346203697e2aSTakashi Iwai { 346303697e2aSTakashi Iwai int i; 346403697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 346503697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 346603697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 346703697e2aSTakashi Iwai on ? PIN_OUT : 0); 346803697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 346903697e2aSTakashi Iwai } 347003697e2aSTakashi Iwai 347103697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 347203697e2aSTakashi Iwai { 347303697e2aSTakashi Iwai int i, present = 0; 347403697e2aSTakashi Iwai 347503697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 347603697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 347703697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 347803697e2aSTakashi Iwai break; 347903697e2aSTakashi Iwai snd_hda_input_jack_report(codec, nid); 348003697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 348103697e2aSTakashi Iwai } 348203697e2aSTakashi Iwai return present; 348303697e2aSTakashi Iwai } 348403697e2aSTakashi Iwai 3485f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 348603697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 348703697e2aSTakashi Iwai { 348803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 348903697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3490e2df82ffSTakashi Iwai int on = 1; 349103697e2aSTakashi Iwai 3492e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3493e2df82ffSTakashi Iwai if (spec->auto_mute) 3494e2df82ffSTakashi Iwai on = spec->hp_present; 349503697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3496e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3497e2df82ffSTakashi Iwai if (spec->auto_mute) 3498e2df82ffSTakashi Iwai on = !(spec->hp_present || 3499e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3500e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 350103697e2aSTakashi Iwai 350203697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 350303697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 350403697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 350503697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 350603697e2aSTakashi Iwai return; 3507e2df82ffSTakashi Iwai if (spec->auto_mute) { 3508e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3509e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3510e2df82ffSTakashi Iwai spec->automute_lines) 3511e2df82ffSTakashi Iwai on = !spec->hp_present; 351203697e2aSTakashi Iwai else 3513e2df82ffSTakashi Iwai on = 1; 3514e2df82ffSTakashi Iwai } 3515e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 351603697e2aSTakashi Iwai } 351703697e2aSTakashi Iwai 3518f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3519f2e5731dSTakashi Iwai { 3520f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3521f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3522f2e5731dSTakashi Iwai 3523f2e5731dSTakashi Iwai if (!spec->auto_mute) 3524f2e5731dSTakashi Iwai return; 352503697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 352603697e2aSTakashi Iwai cx_auto_update_speakers(codec); 352703697e2aSTakashi Iwai } 352803697e2aSTakashi Iwai 352903697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 353003697e2aSTakashi Iwai { 353103697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 353203697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 353303697e2aSTakashi Iwai 353403697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 353503697e2aSTakashi Iwai return; 353603697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 353703697e2aSTakashi Iwai cfg->line_out_pins); 353803697e2aSTakashi Iwai cx_auto_update_speakers(codec); 353903697e2aSTakashi Iwai } 354003697e2aSTakashi Iwai 354103697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 354203697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 354303697e2aSTakashi Iwai { 354403697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 354503697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 354603697e2aSTakashi Iwai static const char * const texts2[] = { 354703697e2aSTakashi Iwai "Disabled", "Enabled" 354803697e2aSTakashi Iwai }; 354903697e2aSTakashi Iwai static const char * const texts3[] = { 355003697e2aSTakashi Iwai "Disabled", "Speaker Only", "Line-Out+Speaker" 355103697e2aSTakashi Iwai }; 355203697e2aSTakashi Iwai const char * const *texts; 355303697e2aSTakashi Iwai 355403697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 355503697e2aSTakashi Iwai uinfo->count = 1; 355603697e2aSTakashi Iwai if (spec->automute_hp_lo) { 355703697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 355803697e2aSTakashi Iwai texts = texts3; 355903697e2aSTakashi Iwai } else { 356003697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 356103697e2aSTakashi Iwai texts = texts2; 356203697e2aSTakashi Iwai } 356303697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 356403697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 356503697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 356603697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 356703697e2aSTakashi Iwai return 0; 356803697e2aSTakashi Iwai } 356903697e2aSTakashi Iwai 357003697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 357103697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 357203697e2aSTakashi Iwai { 357303697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 357403697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 357503697e2aSTakashi Iwai unsigned int val; 357603697e2aSTakashi Iwai if (!spec->auto_mute) 357703697e2aSTakashi Iwai val = 0; 357803697e2aSTakashi Iwai else if (!spec->automute_lines) 357903697e2aSTakashi Iwai val = 1; 358003697e2aSTakashi Iwai else 358103697e2aSTakashi Iwai val = 2; 358203697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 358303697e2aSTakashi Iwai return 0; 358403697e2aSTakashi Iwai } 358503697e2aSTakashi Iwai 358603697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 358703697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 358803697e2aSTakashi Iwai { 358903697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 359003697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 359103697e2aSTakashi Iwai 359203697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 359303697e2aSTakashi Iwai case 0: 359403697e2aSTakashi Iwai if (!spec->auto_mute) 359503697e2aSTakashi Iwai return 0; 359603697e2aSTakashi Iwai spec->auto_mute = 0; 3597f2e5731dSTakashi Iwai break; 359803697e2aSTakashi Iwai case 1: 359903697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 360003697e2aSTakashi Iwai return 0; 360103697e2aSTakashi Iwai spec->auto_mute = 1; 360203697e2aSTakashi Iwai spec->automute_lines = 0; 360303697e2aSTakashi Iwai break; 360403697e2aSTakashi Iwai case 2: 360503697e2aSTakashi Iwai if (!spec->automute_hp_lo) 360603697e2aSTakashi Iwai return -EINVAL; 360703697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 360803697e2aSTakashi Iwai return 0; 360903697e2aSTakashi Iwai spec->auto_mute = 1; 361003697e2aSTakashi Iwai spec->automute_lines = 1; 361103697e2aSTakashi Iwai break; 361203697e2aSTakashi Iwai default: 361303697e2aSTakashi Iwai return -EINVAL; 3614f2e5731dSTakashi Iwai } 361503697e2aSTakashi Iwai cx_auto_update_speakers(codec); 361603697e2aSTakashi Iwai return 1; 3617f2e5731dSTakashi Iwai } 361803697e2aSTakashi Iwai 361903697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 362003697e2aSTakashi Iwai { 362103697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 362203697e2aSTakashi Iwai .name = "Auto-Mute Mode", 362303697e2aSTakashi Iwai .info = cx_automute_mode_info, 362403697e2aSTakashi Iwai .get = cx_automute_mode_get, 362503697e2aSTakashi Iwai .put = cx_automute_mode_put, 362603697e2aSTakashi Iwai }, 362703697e2aSTakashi Iwai { } 362803697e2aSTakashi Iwai }; 3629f2e5731dSTakashi Iwai 36306764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 36316764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 36326764bcefSTakashi Iwai { 36336764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36346764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36356764bcefSTakashi Iwai 36366764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 36376764bcefSTakashi Iwai } 36386764bcefSTakashi Iwai 36396764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 36406764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36416764bcefSTakashi Iwai { 36426764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36436764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36446764bcefSTakashi Iwai 36456764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 36466764bcefSTakashi Iwai return 0; 36476764bcefSTakashi Iwai } 36486764bcefSTakashi Iwai 36495c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 36505c9887e0STakashi Iwai * if do_select is set, actually select the route. 36515c9887e0STakashi Iwai */ 36525c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3653cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3654cf27f29aSTakashi Iwai bool do_select, int depth) 36555c9887e0STakashi Iwai { 36565c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 36575c9887e0STakashi Iwai int i, nums; 36585c9887e0STakashi Iwai 3659cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3660cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3661cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3662cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3663cf27f29aSTakashi Iwai break; 3664cf27f29aSTakashi Iwai default: 3665cf27f29aSTakashi Iwai return -1; 3666cf27f29aSTakashi Iwai } 3667cf27f29aSTakashi Iwai 36685c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 36695c9887e0STakashi Iwai for (i = 0; i < nums; i++) 36705c9887e0STakashi Iwai if (conn[i] == pin) { 36715c9887e0STakashi Iwai if (do_select) 36725c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36735c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3674cf27f29aSTakashi Iwai if (srcp) 3675cf27f29aSTakashi Iwai *srcp = mux; 36765c9887e0STakashi Iwai return i; 36775c9887e0STakashi Iwai } 36785c9887e0STakashi Iwai depth++; 36795c9887e0STakashi Iwai if (depth == 2) 36805c9887e0STakashi Iwai return -1; 36815c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3682cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 36835c9887e0STakashi Iwai do_select, depth); 36845c9887e0STakashi Iwai if (ret >= 0) { 36855c9887e0STakashi Iwai if (do_select) 36865c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36875c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3688cf27f29aSTakashi Iwai return i; 36895c9887e0STakashi Iwai } 36905c9887e0STakashi Iwai } 36915c9887e0STakashi Iwai return -1; 36925c9887e0STakashi Iwai } 36935c9887e0STakashi Iwai 36945c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36955c9887e0STakashi Iwai hda_nid_t pin) 36965c9887e0STakashi Iwai { 3697cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36985c9887e0STakashi Iwai } 36995c9887e0STakashi Iwai 37005c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 37015c9887e0STakashi Iwai hda_nid_t pin) 37025c9887e0STakashi Iwai { 3703cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 37045c9887e0STakashi Iwai } 37055c9887e0STakashi Iwai 37066764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 37076764bcefSTakashi Iwai const struct hda_input_mux *imux, 37086764bcefSTakashi Iwai unsigned int idx) 37096764bcefSTakashi Iwai { 37106764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 37116764bcefSTakashi Iwai hda_nid_t adc; 3712313d2c06STakashi Iwai int changed = 1; 37136764bcefSTakashi Iwai 37146764bcefSTakashi Iwai if (!imux->num_items) 37156764bcefSTakashi Iwai return 0; 37166764bcefSTakashi Iwai if (idx >= imux->num_items) 37176764bcefSTakashi Iwai idx = imux->num_items - 1; 37186764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3719313d2c06STakashi Iwai changed = 0; 372047ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 372147ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 372247ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 37236764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 37246764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 37256764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 37266764bcefSTakashi Iwai spec->cur_adc = adc; 37276764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 37286764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 37296764bcefSTakashi Iwai spec->cur_adc_format); 37306764bcefSTakashi Iwai } 37316764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3732313d2c06STakashi Iwai return changed; 37336764bcefSTakashi Iwai } 37346764bcefSTakashi Iwai 37356764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 37366764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 37376764bcefSTakashi Iwai { 37386764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 37396764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 37406764bcefSTakashi Iwai 37416764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 37426764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 37436764bcefSTakashi Iwai } 37446764bcefSTakashi Iwai 37456764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 37466764bcefSTakashi Iwai { 37476764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37486764bcefSTakashi Iwai .name = "Capture Source", 37496764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 37506764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 37516764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 37526764bcefSTakashi Iwai }, 37536764bcefSTakashi Iwai {} 37546764bcefSTakashi Iwai }; 37556764bcefSTakashi Iwai 375643c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 375743c1b2e9STakashi Iwai { 375843c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 375943c1b2e9STakashi Iwai if (idx < 0) 376043c1b2e9STakashi Iwai return false; 376143c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 376243c1b2e9STakashi Iwai return false; 376343c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 376443c1b2e9STakashi Iwai return true; 376543c1b2e9STakashi Iwai } 376643c1b2e9STakashi Iwai 3767f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3768f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3769f2e5731dSTakashi Iwai { 3770f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3771f2e5731dSTakashi Iwai 3772f2e5731dSTakashi Iwai if (!spec->auto_mic) 3773f2e5731dSTakashi Iwai return; 377443c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 377543c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 377643c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3777f2e5731dSTakashi Iwai } 3778f2e5731dSTakashi Iwai 3779f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3780f2e5731dSTakashi Iwai { 3781f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3782f2e5731dSTakashi Iwai switch (res >> 26) { 3783f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3784f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 378503697e2aSTakashi Iwai break; 378603697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 378703697e2aSTakashi Iwai cx_auto_line_automute(codec); 3788f2e5731dSTakashi Iwai break; 3789f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3790f2e5731dSTakashi Iwai cx_auto_automic(codec); 3791cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 3792f2e5731dSTakashi Iwai break; 3793f2e5731dSTakashi Iwai } 3794f2e5731dSTakashi Iwai } 3795f2e5731dSTakashi Iwai 3796f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 379743c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 379843c1b2e9STakashi Iwai * one dock-mic exist 3799f2e5731dSTakashi Iwai */ 3800f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3801f2e5731dSTakashi Iwai { 3802f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 380343c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 380443c1b2e9STakashi Iwai int i; 3805f2e5731dSTakashi Iwai 3806506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 380743c1b2e9STakashi Iwai pset[i] = -1; 380843c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 380943c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 381043c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3811b55fcb50STakashi Iwai int type, attr; 381243c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 381343c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3814b55fcb50STakashi Iwai return; /* invalid entry */ 381543c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 381643c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 381743c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 381843c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3819b55fcb50STakashi Iwai return; /* non-detectable pin */ 3820b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3821b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3822b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3823b55fcb50STakashi Iwai return; /* no valid input type */ 382443c1b2e9STakashi Iwai if (pset[attr] >= 0) 382543c1b2e9STakashi Iwai return; /* already occupied */ 382643c1b2e9STakashi Iwai pset[attr] = i; 3827f2e5731dSTakashi Iwai } 382843c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 382943c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 383043c1b2e9STakashi Iwai return; /* no input to switch*/ 3831f2e5731dSTakashi Iwai spec->auto_mic = 1; 383243c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 383343c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 383443c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3835f2e5731dSTakashi Iwai } 3836f2e5731dSTakashi Iwai 3837f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3838f2e5731dSTakashi Iwai { 3839f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3840f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3841f2e5731dSTakashi Iwai struct hda_input_mux *imux; 38426764bcefSTakashi Iwai int i, j; 3843f2e5731dSTakashi Iwai 3844f2e5731dSTakashi Iwai imux = &spec->private_imux; 3845f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 38466764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 38476764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 38485c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3849f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3850f2e5731dSTakashi Iwai if (idx >= 0) { 3851f2e5731dSTakashi Iwai const char *label; 3852f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 385347ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 385447ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 385547ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 385647ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3857f6100bb4STakashi Iwai cfg->inputs[i].pin; 3858f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 38596764bcefSTakashi Iwai break; 38606764bcefSTakashi Iwai } 3861f2e5731dSTakashi Iwai } 3862f2e5731dSTakashi Iwai } 386343c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3864f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 38656764bcefSTakashi Iwai if (imux->num_items > 1 && !spec->auto_mic) { 38666764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 386747ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 38686764bcefSTakashi Iwai spec->adc_switching = 1; 38696764bcefSTakashi Iwai break; 38706764bcefSTakashi Iwai } 38716764bcefSTakashi Iwai } 38726764bcefSTakashi Iwai } 3873f2e5731dSTakashi Iwai } 3874f2e5731dSTakashi Iwai 3875f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3876f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3877f2e5731dSTakashi Iwai { 3878f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3879f2e5731dSTakashi Iwai 3880f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3881f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3882f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3883f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3884f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3885f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3886f2e5731dSTakashi Iwai return nid; 3887f2e5731dSTakashi Iwai } 3888f2e5731dSTakashi Iwai } 3889f2e5731dSTakashi Iwai return 0; 3890f2e5731dSTakashi Iwai } 3891f2e5731dSTakashi Iwai 3892f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3893f2e5731dSTakashi Iwai { 3894f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3895f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3896f2e5731dSTakashi Iwai hda_nid_t nid; 3897f2e5731dSTakashi Iwai 3898f2e5731dSTakashi Iwai if (cfg->dig_outs && 3899f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3900f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3901f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3902f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3903f2e5731dSTakashi Iwai } 3904f2e5731dSTakashi Iwai 3905f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3906f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3907f2e5731dSTakashi Iwai { 3908f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3909f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3910f2e5731dSTakashi Iwai 3911f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3912f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3913f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3914f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3915f2e5731dSTakashi Iwai break; 3916f2e5731dSTakashi Iwai } 3917f2e5731dSTakashi Iwai } 3918f2e5731dSTakashi Iwai #else 3919f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3920f2e5731dSTakashi Iwai #endif 3921f2e5731dSTakashi Iwai 392219110595STakashi Iwai static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 392319110595STakashi Iwai { 392419110595STakashi Iwai int i; 392519110595STakashi Iwai for (i = 0; i < nums; i++) 392619110595STakashi Iwai if (list[i] == nid) 392719110595STakashi Iwai return true; 392819110595STakashi Iwai return false; 392919110595STakashi Iwai } 393019110595STakashi Iwai 393119110595STakashi Iwai /* parse extra-EAPD that aren't assigned to any pins */ 393219110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 393319110595STakashi Iwai { 393419110595STakashi Iwai struct conexant_spec *spec = codec->spec; 393519110595STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 393619110595STakashi Iwai hda_nid_t nid, end_nid; 393719110595STakashi Iwai 393819110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 393919110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 394019110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 394119110595STakashi Iwai continue; 394219110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 394319110595STakashi Iwai continue; 394419110595STakashi Iwai if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || 394519110595STakashi Iwai found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || 394619110595STakashi Iwai found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs)) 394719110595STakashi Iwai continue; 394819110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 394919110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 395019110595STakashi Iwai break; 395119110595STakashi Iwai } 395219110595STakashi Iwai } 395319110595STakashi Iwai 3954f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3955f2e5731dSTakashi Iwai { 3956f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3957f2e5731dSTakashi Iwai int err; 3958f2e5731dSTakashi Iwai 3959f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3960f2e5731dSTakashi Iwai if (err < 0) 3961f2e5731dSTakashi Iwai return err; 3962f2e5731dSTakashi Iwai 3963f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3964f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3965f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3966f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 396719110595STakashi Iwai cx_auto_parse_eapd(codec); 3968f2e5731dSTakashi Iwai return 0; 3969f2e5731dSTakashi Iwai } 3970f2e5731dSTakashi Iwai 3971da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3972da339866STakashi Iwai hda_nid_t *pins, bool on) 3973f2e5731dSTakashi Iwai { 3974f2e5731dSTakashi Iwai int i; 3975f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3976f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3977f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3978da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3979da339866STakashi Iwai on ? 0x02 : 0); 3980f2e5731dSTakashi Iwai } 3981f2e5731dSTakashi Iwai } 3982f2e5731dSTakashi Iwai 3983f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3984f2e5731dSTakashi Iwai hda_nid_t src) 3985f2e5731dSTakashi Iwai { 3986f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3987f2e5731dSTakashi Iwai if (idx >= 0) 3988f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3989f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3990f2e5731dSTakashi Iwai } 3991f2e5731dSTakashi Iwai 39921f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 39931f8458a2STakashi Iwai const hda_nid_t *nids) 3994f2e5731dSTakashi Iwai { 39950ad1b5b6STakashi Iwai int i, val; 3996f2e5731dSTakashi Iwai 39971f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 39981f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 39991f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 40001f8458a2STakashi Iwai continue; 40010ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 40020ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 40030ad1b5b6STakashi Iwai else 40040ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 40050ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 40060ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 40070ad1b5b6STakashi Iwai } 40081f8458a2STakashi Iwai } 4009f2e5731dSTakashi Iwai 401003697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 401103697e2aSTakashi Iwai hda_nid_t *pins, unsigned int tag) 401203697e2aSTakashi Iwai { 401303697e2aSTakashi Iwai int i; 401403697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 401503697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 401603697e2aSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 401703697e2aSTakashi Iwai AC_USRSP_EN | tag); 401803697e2aSTakashi Iwai } 401903697e2aSTakashi Iwai 40201f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 40211f8458a2STakashi Iwai { 40221f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 40231f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40241f8458a2STakashi Iwai hda_nid_t nid; 40251f8458a2STakashi Iwai int i; 40261f8458a2STakashi Iwai 40271f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 4028f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 4029f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 4030f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 40311f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 40321f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 40331f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 4034f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4035f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 4036f2e5731dSTakashi Iwai if (!nid) 4037f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 4038f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 4039f2e5731dSTakashi Iwai } 404003697e2aSTakashi Iwai if (spec->auto_mute) { 404103697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 404203697e2aSTakashi Iwai CONEXANT_HP_EVENT); 404303697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 404403697e2aSTakashi Iwai cfg->hp_pins); 404503697e2aSTakashi Iwai if (spec->detect_line) { 404603697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 404703697e2aSTakashi Iwai cfg->line_out_pins, 404803697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 404903697e2aSTakashi Iwai spec->line_present = 405003697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 405103697e2aSTakashi Iwai cfg->line_out_pins); 405203697e2aSTakashi Iwai } 405303697e2aSTakashi Iwai } 405403697e2aSTakashi Iwai cx_auto_update_speakers(codec); 405519110595STakashi Iwai /* turn on/off extra EAPDs, too */ 405619110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 4057f2e5731dSTakashi Iwai } 4058f2e5731dSTakashi Iwai 4059f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 4060f2e5731dSTakashi Iwai { 4061f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4062f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40630ad1b5b6STakashi Iwai int i, val; 4064f2e5731dSTakashi Iwai 40650ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 40660ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 40671f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 40681f8458a2STakashi Iwai continue; 40690ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 40700ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40710ad1b5b6STakashi Iwai else 40720ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40730ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40740ad1b5b6STakashi Iwai val); 40750ad1b5b6STakashi Iwai } 4076f2e5731dSTakashi Iwai 4077f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4078f2e5731dSTakashi Iwai unsigned int type; 4079f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4080f2e5731dSTakashi Iwai type = PIN_VREF80; 4081f2e5731dSTakashi Iwai else 4082f2e5731dSTakashi Iwai type = PIN_IN; 4083f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4084f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4085f2e5731dSTakashi Iwai } 4086f2e5731dSTakashi Iwai 4087f2e5731dSTakashi Iwai if (spec->auto_mic) { 408843c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 408943c1b2e9STakashi Iwai snd_hda_codec_write(codec, 409043c1b2e9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 0, 4091f2e5731dSTakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 4092f2e5731dSTakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 409343c1b2e9STakashi Iwai } 409443c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 409543c1b2e9STakashi Iwai snd_hda_codec_write(codec, 409643c1b2e9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 0, 409743c1b2e9STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 409843c1b2e9STakashi Iwai AC_USRSP_EN | CONEXANT_MIC_EVENT); 409943c1b2e9STakashi Iwai } 4100f2e5731dSTakashi Iwai cx_auto_automic(codec); 4101f2e5731dSTakashi Iwai } else { 410247ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 410347ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4104f2e5731dSTakashi Iwai } 4105f2e5731dSTakashi Iwai } 4106f2e5731dSTakashi Iwai 4107f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4108f2e5731dSTakashi Iwai { 4109f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4110f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4111f2e5731dSTakashi Iwai 4112f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4113f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4114f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4115f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4116f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4117f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4118f2e5731dSTakashi Iwai } 4119f2e5731dSTakashi Iwai 4120f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4121f2e5731dSTakashi Iwai { 4122f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4123f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4124f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4125f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 4126f2e5731dSTakashi Iwai return 0; 4127f2e5731dSTakashi Iwai } 4128f2e5731dSTakashi Iwai 4129983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4130f2e5731dSTakashi Iwai const char *dir, int cidx, 4131983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 4132f2e5731dSTakashi Iwai { 4133f2e5731dSTakashi Iwai static char name[32]; 4134f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4135f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4136f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4137f2e5731dSTakashi Iwai }; 413834cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4139f2e5731dSTakashi Iwai int i, err; 4140f2e5731dSTakashi Iwai 4141f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4142f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4143983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4144983345e5SDavid Henningsson hda_dir); 4145f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4146f2e5731dSTakashi Iwai knew[i].index = cidx; 4147f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4148f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4149f2e5731dSTakashi Iwai if (!kctl) 4150f2e5731dSTakashi Iwai return -ENOMEM; 4151f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4152f2e5731dSTakashi Iwai if (err < 0) 4153f2e5731dSTakashi Iwai return err; 4154f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 4155f2e5731dSTakashi Iwai break; 4156f2e5731dSTakashi Iwai } 4157f2e5731dSTakashi Iwai return 0; 4158f2e5731dSTakashi Iwai } 4159f2e5731dSTakashi Iwai 4160983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4161983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4162983345e5SDavid Henningsson 4163f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4164f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4165f2e5731dSTakashi Iwai 41661f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 41671f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 41681f8458a2STakashi Iwai { 41691f8458a2STakashi Iwai unsigned int caps; 41701f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41711f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41721f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 41731f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41741f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41751f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41761f8458a2STakashi Iwai return 0; 41771f8458a2STakashi Iwai } 41781f8458a2STakashi Iwai 4179f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4180f2e5731dSTakashi Iwai { 4181f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4182f2e5731dSTakashi Iwai int i, err; 4183f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4184ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4185f2e5731dSTakashi Iwai 4186f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41871f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41881f8458a2STakashi Iwai spec->dac_info[0].pin, 4189f2e5731dSTakashi Iwai "Master", 0); 41901f8458a2STakashi Iwai 4191f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4192f2e5731dSTakashi Iwai const char *label; 4193f2e5731dSTakashi Iwai int idx, type; 4194f2e5731dSTakashi Iwai if (!spec->dac_info[i].dac) 4195f2e5731dSTakashi Iwai continue; 4196f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4197f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4198f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4199f2e5731dSTakashi Iwai switch (type) { 4200f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4201f2e5731dSTakashi Iwai default: 4202f2e5731dSTakashi Iwai label = texts[num_line++]; 4203f2e5731dSTakashi Iwai idx = 0; 4204f2e5731dSTakashi Iwai break; 4205f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4206f2e5731dSTakashi Iwai label = "Headphone"; 4207f2e5731dSTakashi Iwai idx = num_hp++; 4208f2e5731dSTakashi Iwai break; 4209f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4210f2e5731dSTakashi Iwai label = "Speaker"; 4211f2e5731dSTakashi Iwai idx = num_spk++; 4212f2e5731dSTakashi Iwai break; 4213f2e5731dSTakashi Iwai } 42141f8458a2STakashi Iwai err = try_add_pb_volume(codec, spec->dac_info[i].dac, 42151f8458a2STakashi Iwai spec->dac_info[i].pin, 4216f2e5731dSTakashi Iwai label, idx); 4217f2e5731dSTakashi Iwai if (err < 0) 4218f2e5731dSTakashi Iwai return err; 4219f2e5731dSTakashi Iwai } 422003697e2aSTakashi Iwai 422103697e2aSTakashi Iwai if (spec->auto_mute) { 422203697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 422303697e2aSTakashi Iwai if (err < 0) 422403697e2aSTakashi Iwai return err; 422503697e2aSTakashi Iwai } 422603697e2aSTakashi Iwai 4227f2e5731dSTakashi Iwai return 0; 4228f2e5731dSTakashi Iwai } 4229f2e5731dSTakashi Iwai 42306764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 42316764bcefSTakashi Iwai const char *label, const char *pfx, 42326764bcefSTakashi Iwai int cidx) 42336764bcefSTakashi Iwai { 42346764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 42356764bcefSTakashi Iwai int i; 42366764bcefSTakashi Iwai 42376764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 42386764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 42395c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 42406764bcefSTakashi Iwai if (idx < 0) 42416764bcefSTakashi Iwai continue; 42426764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 42436764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 42446764bcefSTakashi Iwai } 42456764bcefSTakashi Iwai return 0; 42466764bcefSTakashi Iwai } 42476764bcefSTakashi Iwai 4248cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4249cf27f29aSTakashi Iwai const char *label, int cidx) 4250cf27f29aSTakashi Iwai { 4251cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4252cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4253f9759301STakashi Iwai int i, con; 4254cf27f29aSTakashi Iwai 425547ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4256cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4257cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4258cf27f29aSTakashi Iwai nid, HDA_INPUT); 425947ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 426047ad1f4eSTakashi Iwai &mux, false, 0); 4261cf27f29aSTakashi Iwai if (con < 0) 4262cf27f29aSTakashi Iwai return 0; 4263f9759301STakashi Iwai for (i = 0; i < idx; i++) { 426447ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4265f9759301STakashi Iwai return 0; /* already present */ 4266f9759301STakashi Iwai } 4267f9759301STakashi Iwai 4268f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 426947ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4270cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4271cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4272f9759301STakashi Iwai } 4273cf27f29aSTakashi Iwai return 0; 4274cf27f29aSTakashi Iwai } 4275cf27f29aSTakashi Iwai 4276f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4277f2e5731dSTakashi Iwai { 4278f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4279cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4280cf27f29aSTakashi Iwai const char *prev_label; 4281cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42826764bcefSTakashi Iwai int i, err, cidx; 4283cf27f29aSTakashi Iwai int multi_connection; 4284cf27f29aSTakashi Iwai 4285cf27f29aSTakashi Iwai multi_connection = 0; 4286cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 428747ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 428847ad1f4eSTakashi Iwai spec->imux_info[i].pin); 428947ad1f4eSTakashi Iwai input_conn[i] = (spec->imux_info[i].adc << 8) | cidx; 4290cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4291cf27f29aSTakashi Iwai multi_connection = 1; 4292cf27f29aSTakashi Iwai } 4293983345e5SDavid Henningsson 4294f2e5731dSTakashi Iwai prev_label = NULL; 4295f2e5731dSTakashi Iwai cidx = 0; 4296cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 429747ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4298f2e5731dSTakashi Iwai const char *label; 4299983345e5SDavid Henningsson 4300cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 430147ad1f4eSTakashi Iwai spec->imux_info[i].index); 4302f2e5731dSTakashi Iwai if (label == prev_label) 4303f2e5731dSTakashi Iwai cidx++; 4304f2e5731dSTakashi Iwai else 4305f2e5731dSTakashi Iwai cidx = 0; 4306f2e5731dSTakashi Iwai prev_label = label; 4307983345e5SDavid Henningsson 4308cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4309f2e5731dSTakashi Iwai if (err < 0) 4310f2e5731dSTakashi Iwai return err; 4311983345e5SDavid Henningsson 4312cf27f29aSTakashi Iwai if (!multi_connection) { 4313f9759301STakashi Iwai if (i > 0) 4314f9759301STakashi Iwai continue; 43156764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43166764bcefSTakashi Iwai "Capture", "", cidx); 43176764bcefSTakashi Iwai } else { 43186764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43196764bcefSTakashi Iwai label, " Capture", cidx); 43206764bcefSTakashi Iwai } 4321983345e5SDavid Henningsson if (err < 0) 4322983345e5SDavid Henningsson return err; 4323983345e5SDavid Henningsson } 43246764bcefSTakashi Iwai 43256764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 43266764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 43276764bcefSTakashi Iwai if (err < 0) 43286764bcefSTakashi Iwai return err; 4329983345e5SDavid Henningsson } 43306764bcefSTakashi Iwai 4331f2e5731dSTakashi Iwai return 0; 4332f2e5731dSTakashi Iwai } 4333f2e5731dSTakashi Iwai 4334f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4335f2e5731dSTakashi Iwai { 4336f2e5731dSTakashi Iwai int err; 4337f2e5731dSTakashi Iwai 4338f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4339f2e5731dSTakashi Iwai if (err < 0) 4340f2e5731dSTakashi Iwai return err; 4341f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4342f2e5731dSTakashi Iwai if (err < 0) 4343f2e5731dSTakashi Iwai return err; 4344f2e5731dSTakashi Iwai return conexant_build_controls(codec); 4345f2e5731dSTakashi Iwai } 4346f2e5731dSTakashi Iwai 434722ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 434822ce5f74STakashi Iwai { 434922ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 435022ce5f74STakashi Iwai hda_nid_t nid, end_nid; 435122ce5f74STakashi Iwai 435222ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 435322ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 435422ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 435522ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 435622ce5f74STakashi Iwai continue; 435722ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 435822ce5f74STakashi Iwai continue; 435922ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 436022ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 436122ce5f74STakashi Iwai break; 436222ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 436322ce5f74STakashi Iwai } 436422ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 436522ce5f74STakashi Iwai return 0; 436622ce5f74STakashi Iwai } 436722ce5f74STakashi Iwai 436822ce5f74STakashi Iwai 436934cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4370f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4371f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4372f2e5731dSTakashi Iwai .init = cx_auto_init, 4373f2e5731dSTakashi Iwai .free = conexant_free, 4374f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4375f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4376f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4377f2e5731dSTakashi Iwai #endif 4378f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4379f2e5731dSTakashi Iwai }; 4380f2e5731dSTakashi Iwai 4381f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4382f2e5731dSTakashi Iwai { 4383f2e5731dSTakashi Iwai struct conexant_spec *spec; 4384f2e5731dSTakashi Iwai int err; 4385f2e5731dSTakashi Iwai 43861f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 43871f8458a2STakashi Iwai codec->chip_name); 43881f8458a2STakashi Iwai 4389f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4390f2e5731dSTakashi Iwai if (!spec) 4391f2e5731dSTakashi Iwai return -ENOMEM; 4392f2e5731dSTakashi Iwai codec->spec = spec; 43931387cde5STakashi Iwai codec->pin_amp_workaround = 1; 439422ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 439522ce5f74STakashi Iwai if (err < 0) 439622ce5f74STakashi Iwai return err; 4397f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4398f2e5731dSTakashi Iwai if (err < 0) { 4399f2e5731dSTakashi Iwai kfree(codec->spec); 4400f2e5731dSTakashi Iwai codec->spec = NULL; 4401f2e5731dSTakashi Iwai return err; 4402f2e5731dSTakashi Iwai } 44036764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4404f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4405f2e5731dSTakashi Iwai if (spec->beep_amp) 4406f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 4407f2e5731dSTakashi Iwai return 0; 4408f2e5731dSTakashi Iwai } 4409f2e5731dSTakashi Iwai 4410f2e5731dSTakashi Iwai /* 4411461e2c78STakashi Iwai */ 4412461e2c78STakashi Iwai 441334cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 441482f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 441582f30040STobin Davis .patch = patch_cxt5045 }, 441682f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 441782f30040STobin Davis .patch = patch_cxt5047 }, 4418461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4419461e2c78STakashi Iwai .patch = patch_cxt5051 }, 44200fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 44210fb67e98SDaniel Drake .patch = patch_cxt5066 }, 442295a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 442395a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4424850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4425850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 44267b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 44277b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4428f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4429f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 44306da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 44316da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4432f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4433f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4434f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4435f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4436f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4437f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4438f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4439f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4440f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4441f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4442f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4443f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4444f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4445f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4446f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4447f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4448c9b443d4STobin Davis {} /* terminator */ 4449c9b443d4STobin Davis }; 44501289e9e8STakashi Iwai 44511289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 44521289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 44531289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 44540fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 445595a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4456850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 44577b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4458f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 44596da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4460f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4461f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4462f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4463f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4464f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4465f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4466f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4467f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 44681289e9e8STakashi Iwai 44691289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 44701289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 44711289e9e8STakashi Iwai 44721289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 44731289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 44741289e9e8STakashi Iwai .owner = THIS_MODULE, 44751289e9e8STakashi Iwai }; 44761289e9e8STakashi Iwai 44771289e9e8STakashi Iwai static int __init patch_conexant_init(void) 44781289e9e8STakashi Iwai { 44791289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 44801289e9e8STakashi Iwai } 44811289e9e8STakashi Iwai 44821289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 44831289e9e8STakashi Iwai { 44841289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 44851289e9e8STakashi Iwai } 44861289e9e8STakashi Iwai 44871289e9e8STakashi Iwai module_init(patch_conexant_init) 44881289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4489