1c9b443d4STobin Davis /* 2c9b443d4STobin Davis * HD audio interface patch for Conexant HDA audio codec 3c9b443d4STobin Davis * 4c9b443d4STobin Davis * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5c9b443d4STobin Davis * Takashi Iwai <tiwai@suse.de> 6c9b443d4STobin Davis * Tobin Davis <tdavis@dsl-only.net> 7c9b443d4STobin Davis * 8c9b443d4STobin Davis * This driver is free software; you can redistribute it and/or modify 9c9b443d4STobin Davis * it under the terms of the GNU General Public License as published by 10c9b443d4STobin Davis * the Free Software Foundation; either version 2 of the License, or 11c9b443d4STobin Davis * (at your option) any later version. 12c9b443d4STobin Davis * 13c9b443d4STobin Davis * This driver is distributed in the hope that it will be useful, 14c9b443d4STobin Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9b443d4STobin Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9b443d4STobin Davis * GNU General Public License for more details. 17c9b443d4STobin Davis * 18c9b443d4STobin Davis * You should have received a copy of the GNU General Public License 19c9b443d4STobin Davis * along with this program; if not, write to the Free Software 20c9b443d4STobin Davis * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c9b443d4STobin Davis */ 22c9b443d4STobin Davis 23c9b443d4STobin Davis #include <linux/init.h> 24c9b443d4STobin Davis #include <linux/delay.h> 25c9b443d4STobin Davis #include <linux/slab.h> 26c9b443d4STobin Davis #include <linux/pci.h> 27da155d5bSPaul Gortmaker #include <linux/module.h> 28c9b443d4STobin Davis #include <sound/core.h> 29bc7a166dSUlrich Dangel #include <sound/jack.h> 30bc7a166dSUlrich Dangel 31c9b443d4STobin Davis #include "hda_codec.h" 32c9b443d4STobin Davis #include "hda_local.h" 33c0f8faf0SEinar Rünkaru #include "hda_beep.h" 341835a0f9STakashi Iwai #include "hda_jack.h" 35c9b443d4STobin Davis 36c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 37c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 39c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 40c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 41c9b443d4STobin Davis 42c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 43c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 4403697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT 0x39 45c9b443d4STobin Davis 46bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 47c9b443d4STobin Davis 48ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT 0x12 49bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 50bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 51bc7a166dSUlrich Dangel 52faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB (1 << 1) 53faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC (1 << 2) 54bc7a166dSUlrich Dangel 55f2e5731dSTakashi Iwai struct pin_dac_pair { 56f2e5731dSTakashi Iwai hda_nid_t pin; 57f2e5731dSTakashi Iwai hda_nid_t dac; 58f2e5731dSTakashi Iwai int type; 59f2e5731dSTakashi Iwai }; 60f2e5731dSTakashi Iwai 6147ad1f4eSTakashi Iwai struct imux_info { 6247ad1f4eSTakashi Iwai hda_nid_t pin; /* input pin NID */ 6347ad1f4eSTakashi Iwai hda_nid_t adc; /* connected ADC NID */ 6447ad1f4eSTakashi Iwai hda_nid_t boost; /* optional boost volume NID */ 6547ad1f4eSTakashi Iwai int index; /* corresponding to autocfg.input */ 6647ad1f4eSTakashi Iwai }; 6747ad1f4eSTakashi Iwai 68c9b443d4STobin Davis struct conexant_spec { 69c9b443d4STobin Davis 7034cbe3a6STakashi Iwai const struct snd_kcontrol_new *mixers[5]; 71c9b443d4STobin Davis int num_mixers; 72dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 73d2f344b5STakashi Iwai struct hda_vmaster_mute_hook vmaster_mute; 74f29735cbSTakashi Iwai bool vmaster_mute_led; 75c9b443d4STobin Davis 76c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 77c9b443d4STobin Davis * don't forget NULL 78c9b443d4STobin Davis * termination! 79c9b443d4STobin Davis */ 80c9b443d4STobin Davis unsigned int num_init_verbs; 81c9b443d4STobin Davis 82c9b443d4STobin Davis /* playback */ 83c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 84c9b443d4STobin Davis * max_channels, dacs must be set 85c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 86c9b443d4STobin Davis */ 87c9b443d4STobin Davis unsigned int cur_eapd; 8882f30040STobin Davis unsigned int hp_present; 8903697e2aSTakashi Iwai unsigned int line_present; 90faddaa5dSTakashi Iwai unsigned int auto_mic; 91f6100bb4STakashi Iwai int auto_mic_ext; /* imux_pins[] index for ext mic */ 9243c1b2e9STakashi Iwai int auto_mic_dock; /* imux_pins[] index for dock mic */ 9343c1b2e9STakashi Iwai int auto_mic_int; /* imux_pins[] index for int mic */ 94c9b443d4STobin Davis unsigned int need_dac_fix; 95f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 96c9b443d4STobin Davis 97c9b443d4STobin Davis /* capture */ 98c9b443d4STobin Davis unsigned int num_adc_nids; 9934cbe3a6STakashi Iwai const hda_nid_t *adc_nids; 100c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 101c9b443d4STobin Davis 102461e2c78STakashi Iwai unsigned int cur_adc_idx; 103461e2c78STakashi Iwai hda_nid_t cur_adc; 104461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 105461e2c78STakashi Iwai unsigned int cur_adc_format; 106461e2c78STakashi Iwai 1076764bcefSTakashi Iwai const struct hda_pcm_stream *capture_stream; 1086764bcefSTakashi Iwai 109c9b443d4STobin Davis /* capture source */ 110c9b443d4STobin Davis const struct hda_input_mux *input_mux; 11134cbe3a6STakashi Iwai const hda_nid_t *capsrc_nids; 112c9b443d4STobin Davis unsigned int cur_mux[3]; 113c9b443d4STobin Davis 114c9b443d4STobin Davis /* channel model */ 115c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 116c9b443d4STobin Davis int num_channel_mode; 117c9b443d4STobin Davis 118c9b443d4STobin Davis /* PCM information */ 119c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 120c9b443d4STobin Davis 121c9b443d4STobin Davis unsigned int spdif_route; 122c9b443d4STobin Davis 123c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 124c9b443d4STobin Davis struct auto_pin_cfg autocfg; 125c9b443d4STobin Davis struct hda_input_mux private_imux; 12647ad1f4eSTakashi Iwai struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; 12722ce5f74STakashi Iwai hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 12841923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 129f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 130f2e5731dSTakashi Iwai int dac_info_filled; 131c9b443d4STobin Davis 1320fb67e98SDaniel Drake unsigned int port_d_mode; 133f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 13403697e2aSTakashi Iwai unsigned int detect_line:1; /* Line-out detection enabled */ 13503697e2aSTakashi Iwai unsigned int automute_lines:1; /* automute line-out as well */ 13603697e2aSTakashi Iwai unsigned int automute_hp_lo:1; /* both HP and LO available */ 137f2e5731dSTakashi Iwai unsigned int dell_automute:1; 138cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 139cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1407b2bfdbcSJens Taprogge unsigned int thinkpad:1; 141048e78a5SDavid Henningsson unsigned int hp_laptop:1; 142a1d6906eSDavid Henningsson unsigned int asus:1; 143254f2968STakashi Iwai unsigned int pin_eapd_ctrls:1; 14475f8991dSDaniel Drake 1456764bcefSTakashi Iwai unsigned int adc_switching:1; 1466764bcefSTakashi Iwai 14775f8991dSDaniel Drake unsigned int ext_mic_present; 14875f8991dSDaniel Drake unsigned int recording; 14975f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 15075f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 151c4cfe66cSDaniel Drake 152c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 153c4cfe66cSDaniel Drake * through the microphone jack. 154c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 155c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 156c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 157c4cfe66cSDaniel Drake * control. */ 158c4cfe66cSDaniel Drake unsigned int dc_enable; 159c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 160c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1613507e2a8STakashi Iwai 1623507e2a8STakashi Iwai unsigned int beep_amp; 16319110595STakashi Iwai 16419110595STakashi Iwai /* extra EAPD pins */ 16519110595STakashi Iwai unsigned int num_eapds; 16619110595STakashi Iwai hda_nid_t eapds[4]; 167c9b443d4STobin Davis }; 168c9b443d4STobin Davis 169c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 170c9b443d4STobin Davis struct hda_codec *codec, 171c9b443d4STobin Davis struct snd_pcm_substream *substream) 172c9b443d4STobin Davis { 173c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1749a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1759a08160bSTakashi Iwai hinfo); 176c9b443d4STobin Davis } 177c9b443d4STobin Davis 178c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 179c9b443d4STobin Davis struct hda_codec *codec, 180c9b443d4STobin Davis unsigned int stream_tag, 181c9b443d4STobin Davis unsigned int format, 182c9b443d4STobin Davis struct snd_pcm_substream *substream) 183c9b443d4STobin Davis { 184c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 185c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 186c9b443d4STobin Davis stream_tag, 187c9b443d4STobin Davis format, substream); 188c9b443d4STobin Davis } 189c9b443d4STobin Davis 190c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 191c9b443d4STobin Davis struct hda_codec *codec, 192c9b443d4STobin Davis struct snd_pcm_substream *substream) 193c9b443d4STobin Davis { 194c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 195c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 196c9b443d4STobin Davis } 197c9b443d4STobin Davis 198c9b443d4STobin Davis /* 199c9b443d4STobin Davis * Digital out 200c9b443d4STobin Davis */ 201c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 202c9b443d4STobin Davis struct hda_codec *codec, 203c9b443d4STobin Davis struct snd_pcm_substream *substream) 204c9b443d4STobin Davis { 205c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 206c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 207c9b443d4STobin Davis } 208c9b443d4STobin Davis 209c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 210c9b443d4STobin Davis struct hda_codec *codec, 211c9b443d4STobin Davis struct snd_pcm_substream *substream) 212c9b443d4STobin Davis { 213c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 214c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 215c9b443d4STobin Davis } 216c9b443d4STobin Davis 2176b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2186b97eb45STakashi Iwai struct hda_codec *codec, 2196b97eb45STakashi Iwai unsigned int stream_tag, 2206b97eb45STakashi Iwai unsigned int format, 2216b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2226b97eb45STakashi Iwai { 2236b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2246b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2256b97eb45STakashi Iwai stream_tag, 2266b97eb45STakashi Iwai format, substream); 2276b97eb45STakashi Iwai } 2286b97eb45STakashi Iwai 229c9b443d4STobin Davis /* 230c9b443d4STobin Davis * Analog capture 231c9b443d4STobin Davis */ 232c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 233c9b443d4STobin Davis struct hda_codec *codec, 234c9b443d4STobin Davis unsigned int stream_tag, 235c9b443d4STobin Davis unsigned int format, 236c9b443d4STobin Davis struct snd_pcm_substream *substream) 237c9b443d4STobin Davis { 238c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 23975f8991dSDaniel Drake if (spec->capture_prepare) 24075f8991dSDaniel Drake spec->capture_prepare(codec); 241c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 242c9b443d4STobin Davis stream_tag, 0, format); 243c9b443d4STobin Davis return 0; 244c9b443d4STobin Davis } 245c9b443d4STobin Davis 246c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 247c9b443d4STobin Davis struct hda_codec *codec, 248c9b443d4STobin Davis struct snd_pcm_substream *substream) 249c9b443d4STobin Davis { 250c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 251888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 25275f8991dSDaniel Drake if (spec->capture_cleanup) 25375f8991dSDaniel Drake spec->capture_cleanup(codec); 254c9b443d4STobin Davis return 0; 255c9b443d4STobin Davis } 256c9b443d4STobin Davis 257c9b443d4STobin Davis 258c9b443d4STobin Davis 25934cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 260c9b443d4STobin Davis .substreams = 1, 261c9b443d4STobin Davis .channels_min = 2, 262c9b443d4STobin Davis .channels_max = 2, 263c9b443d4STobin Davis .nid = 0, /* fill later */ 264c9b443d4STobin Davis .ops = { 265c9b443d4STobin Davis .open = conexant_playback_pcm_open, 266c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 267c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 268c9b443d4STobin Davis }, 269c9b443d4STobin Davis }; 270c9b443d4STobin Davis 27134cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 272c9b443d4STobin Davis .substreams = 1, 273c9b443d4STobin Davis .channels_min = 2, 274c9b443d4STobin Davis .channels_max = 2, 275c9b443d4STobin Davis .nid = 0, /* fill later */ 276c9b443d4STobin Davis .ops = { 277c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 278c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 279c9b443d4STobin Davis }, 280c9b443d4STobin Davis }; 281c9b443d4STobin Davis 282c9b443d4STobin Davis 28334cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 284c9b443d4STobin Davis .substreams = 1, 285c9b443d4STobin Davis .channels_min = 2, 286c9b443d4STobin Davis .channels_max = 2, 287c9b443d4STobin Davis .nid = 0, /* fill later */ 288c9b443d4STobin Davis .ops = { 289c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2906b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2916b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 292c9b443d4STobin Davis }, 293c9b443d4STobin Davis }; 294c9b443d4STobin Davis 29534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 296c9b443d4STobin Davis .substreams = 1, 297c9b443d4STobin Davis .channels_min = 2, 298c9b443d4STobin Davis .channels_max = 2, 299c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 300c9b443d4STobin Davis }; 301c9b443d4STobin Davis 302461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 303461e2c78STakashi Iwai struct hda_codec *codec, 304461e2c78STakashi Iwai unsigned int stream_tag, 305461e2c78STakashi Iwai unsigned int format, 306461e2c78STakashi Iwai struct snd_pcm_substream *substream) 307461e2c78STakashi Iwai { 308461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 309461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 310461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 311461e2c78STakashi Iwai spec->cur_adc_format = format; 312461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 313461e2c78STakashi Iwai return 0; 314461e2c78STakashi Iwai } 315461e2c78STakashi Iwai 316461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 317461e2c78STakashi Iwai struct hda_codec *codec, 318461e2c78STakashi Iwai struct snd_pcm_substream *substream) 319461e2c78STakashi Iwai { 320461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 321888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 322461e2c78STakashi Iwai spec->cur_adc = 0; 323461e2c78STakashi Iwai return 0; 324461e2c78STakashi Iwai } 325461e2c78STakashi Iwai 32634cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 327461e2c78STakashi Iwai .substreams = 1, 328461e2c78STakashi Iwai .channels_min = 2, 329461e2c78STakashi Iwai .channels_max = 2, 330461e2c78STakashi Iwai .nid = 0, /* fill later */ 331461e2c78STakashi Iwai .ops = { 332461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 333461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 334461e2c78STakashi Iwai }, 335461e2c78STakashi Iwai }; 336461e2c78STakashi Iwai 337c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 338c9b443d4STobin Davis { 339c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 340c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 341c9b443d4STobin Davis 342c9b443d4STobin Davis codec->num_pcms = 1; 343c9b443d4STobin Davis codec->pcm_info = info; 344c9b443d4STobin Davis 345c9b443d4STobin Davis info->name = "CONEXANT Analog"; 346c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 347c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 348c9b443d4STobin Davis spec->multiout.max_channels; 349c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 350c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3516764bcefSTakashi Iwai if (spec->capture_stream) 3526764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3536764bcefSTakashi Iwai else { 354461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 355461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 356461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3576764bcefSTakashi Iwai else { 358461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 359461e2c78STakashi Iwai conexant_pcm_analog_capture; 3606764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3616764bcefSTakashi Iwai spec->num_adc_nids; 3626764bcefSTakashi Iwai } 3636764bcefSTakashi Iwai } 364c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 365c9b443d4STobin Davis 366c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 367c9b443d4STobin Davis info++; 368c9b443d4STobin Davis codec->num_pcms++; 369c9b443d4STobin Davis info->name = "Conexant Digital"; 3707ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 371c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 372c9b443d4STobin Davis conexant_pcm_digital_playback; 373c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 374c9b443d4STobin Davis spec->multiout.dig_out_nid; 375c9b443d4STobin Davis if (spec->dig_in_nid) { 376c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 377c9b443d4STobin Davis conexant_pcm_digital_capture; 378c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 379c9b443d4STobin Davis spec->dig_in_nid; 380c9b443d4STobin Davis } 381f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 382f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 383c9b443d4STobin Davis } 384c9b443d4STobin Davis 385c9b443d4STobin Davis return 0; 386c9b443d4STobin Davis } 387c9b443d4STobin Davis 388c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 389c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 390c9b443d4STobin Davis { 391c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 392c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 393c9b443d4STobin Davis 394c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 395c9b443d4STobin Davis } 396c9b443d4STobin Davis 397c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 398c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 399c9b443d4STobin Davis { 400c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 401c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 402c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 403c9b443d4STobin Davis 404c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 405c9b443d4STobin Davis return 0; 406c9b443d4STobin Davis } 407c9b443d4STobin Davis 408c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 409c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 410c9b443d4STobin Davis { 411c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 412c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 413c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 414c9b443d4STobin Davis 415c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 416c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 417c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 418c9b443d4STobin Davis } 419c9b443d4STobin Davis 4204d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 4214d7fbdbcSTakashi Iwai unsigned int power_state) 4224d7fbdbcSTakashi Iwai { 4234d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 4244d7fbdbcSTakashi Iwai msleep(100); 4254d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 4264d7fbdbcSTakashi Iwai power_state); 4274d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 4284d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 4294d7fbdbcSTakashi Iwai msleep(10); 4304d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 4314d7fbdbcSTakashi Iwai } 4324d7fbdbcSTakashi Iwai 433c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 434c9b443d4STobin Davis { 435c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 436c9b443d4STobin Davis int i; 437c9b443d4STobin Davis 438c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 439c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 440c9b443d4STobin Davis return 0; 441c9b443d4STobin Davis } 442c9b443d4STobin Davis 443c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 444c9b443d4STobin Davis { 445c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 446c9b443d4STobin Davis kfree(codec->spec); 447c9b443d4STobin Davis } 448c9b443d4STobin Davis 44934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 450b880c74aSTakashi Iwai { 451b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 452b880c74aSTakashi Iwai .name = "Capture Source", 453b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 454b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 455b880c74aSTakashi Iwai .put = conexant_mux_enum_put 456b880c74aSTakashi Iwai }, 457b880c74aSTakashi Iwai {} 458b880c74aSTakashi Iwai }; 459b880c74aSTakashi Iwai 4603507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4613507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 46234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4633507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4643507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4653507e2a8STakashi Iwai { } /* end */ 4663507e2a8STakashi Iwai }; 4673507e2a8STakashi Iwai #endif 4683507e2a8STakashi Iwai 4699322ca54STakashi Iwai static const char * const slave_pfxs[] = { 4709322ca54STakashi Iwai "Headphone", "Speaker", "Front", "Surround", "CLFE", 471dd5746a8STakashi Iwai NULL 472dd5746a8STakashi Iwai }; 473dd5746a8STakashi Iwai 474c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 475c9b443d4STobin Davis { 476c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 477c9b443d4STobin Davis unsigned int i; 478c9b443d4STobin Davis int err; 479c9b443d4STobin Davis 480c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 481c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 482c9b443d4STobin Davis if (err < 0) 483c9b443d4STobin Davis return err; 484c9b443d4STobin Davis } 485c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 486c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 48774b654c9SStephen Warren spec->multiout.dig_out_nid, 488c9b443d4STobin Davis spec->multiout.dig_out_nid); 489c9b443d4STobin Davis if (err < 0) 490c9b443d4STobin Davis return err; 4919a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 4929a08160bSTakashi Iwai &spec->multiout); 4939a08160bSTakashi Iwai if (err < 0) 4949a08160bSTakashi Iwai return err; 4959a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 496c9b443d4STobin Davis } 497c9b443d4STobin Davis if (spec->dig_in_nid) { 498c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 499c9b443d4STobin Davis if (err < 0) 500c9b443d4STobin Davis return err; 501c9b443d4STobin Davis } 502dd5746a8STakashi Iwai 503dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 504dd5746a8STakashi Iwai if (spec->vmaster_nid && 505dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 506dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 507dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 508dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 509dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 5109322ca54STakashi Iwai vmaster_tlv, slave_pfxs, 5119322ca54STakashi Iwai "Playback Volume"); 512dd5746a8STakashi Iwai if (err < 0) 513dd5746a8STakashi Iwai return err; 514dd5746a8STakashi Iwai } 515dd5746a8STakashi Iwai if (spec->vmaster_nid && 516dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 517527c73baSTakashi Iwai err = __snd_hda_add_vmaster(codec, "Master Playback Switch", 5189322ca54STakashi Iwai NULL, slave_pfxs, 519527c73baSTakashi Iwai "Playback Switch", true, 520d2f344b5STakashi Iwai &spec->vmaster_mute.sw_kctl); 521dd5746a8STakashi Iwai if (err < 0) 522dd5746a8STakashi Iwai return err; 523dd5746a8STakashi Iwai } 524dd5746a8STakashi Iwai 525b880c74aSTakashi Iwai if (spec->input_mux) { 526b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 527b880c74aSTakashi Iwai if (err < 0) 528b880c74aSTakashi Iwai return err; 529b880c74aSTakashi Iwai } 530b880c74aSTakashi Iwai 5313507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5323507e2a8STakashi Iwai /* create beep controls if needed */ 5333507e2a8STakashi Iwai if (spec->beep_amp) { 53434cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5353507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5363507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5373507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5383507e2a8STakashi Iwai if (!kctl) 5393507e2a8STakashi Iwai return -ENOMEM; 5403507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5413507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5423507e2a8STakashi Iwai if (err < 0) 5433507e2a8STakashi Iwai return err; 5443507e2a8STakashi Iwai } 5453507e2a8STakashi Iwai } 5463507e2a8STakashi Iwai #endif 5473507e2a8STakashi Iwai 548c9b443d4STobin Davis return 0; 549c9b443d4STobin Davis } 550c9b443d4STobin Davis 551697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 552697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 553697c373eSTakashi Iwai { 554697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 555697c373eSTakashi Iwai return 0; 556697c373eSTakashi Iwai } 557697c373eSTakashi Iwai #endif 558697c373eSTakashi Iwai 55934cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 560c9b443d4STobin Davis .build_controls = conexant_build_controls, 561c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 562c9b443d4STobin Davis .init = conexant_init, 563c9b443d4STobin Davis .free = conexant_free, 5644d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 565697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 566697c373eSTakashi Iwai .suspend = conexant_suspend, 567697c373eSTakashi Iwai #endif 568697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 569c9b443d4STobin Davis }; 570c9b443d4STobin Davis 5713507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5723507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5733507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5743507e2a8STakashi Iwai #else 5753507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5763507e2a8STakashi Iwai #endif 5773507e2a8STakashi Iwai 5786764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 579c9b443d4STobin Davis /* 580c9b443d4STobin Davis * EAPD control 581c9b443d4STobin Davis * the private value = nid | (invert << 8) 582c9b443d4STobin Davis */ 583c9b443d4STobin Davis 584a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 585c9b443d4STobin Davis 58682f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 587c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 588c9b443d4STobin Davis { 589c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 590c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 591c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 592c9b443d4STobin Davis if (invert) 593c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 594c9b443d4STobin Davis else 595c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 596c9b443d4STobin Davis return 0; 59782f30040STobin Davis 598c9b443d4STobin Davis } 599c9b443d4STobin Davis 60082f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 601c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 602c9b443d4STobin Davis { 603c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 604c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 605c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 606c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 607c9b443d4STobin Davis unsigned int eapd; 60882f30040STobin Davis 60968ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 610c9b443d4STobin Davis if (invert) 611c9b443d4STobin Davis eapd = !eapd; 61282beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 613c9b443d4STobin Davis return 0; 61482f30040STobin Davis 615c9b443d4STobin Davis spec->cur_eapd = eapd; 61682beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 617c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 618c9b443d4STobin Davis eapd ? 0x02 : 0x00); 619c9b443d4STobin Davis return 1; 620c9b443d4STobin Davis } 621c9b443d4STobin Davis 62286d72bdfSTakashi Iwai /* controls for test mode */ 62386d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 62486d72bdfSTakashi Iwai 62582f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 62682f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 62782f30040STobin Davis .info = cxt_eapd_info, \ 62882f30040STobin Davis .get = cxt_eapd_get, \ 62982f30040STobin Davis .put = cxt_eapd_put, \ 63082f30040STobin Davis .private_value = nid | (mask<<16) } 63182f30040STobin Davis 63282f30040STobin Davis 63382f30040STobin Davis 634c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 635c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 636c9b443d4STobin Davis { 637c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 638c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 639c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 640c9b443d4STobin Davis spec->num_channel_mode); 641c9b443d4STobin Davis } 642c9b443d4STobin Davis 643c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 644c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 645c9b443d4STobin Davis { 646c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 647c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 648c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 649c9b443d4STobin Davis spec->num_channel_mode, 650c9b443d4STobin Davis spec->multiout.max_channels); 651c9b443d4STobin Davis } 652c9b443d4STobin Davis 653c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 654c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 655c9b443d4STobin Davis { 656c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 657c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 658c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 659c9b443d4STobin Davis spec->num_channel_mode, 660c9b443d4STobin Davis &spec->multiout.max_channels); 661c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 662c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 663c9b443d4STobin Davis return err; 664c9b443d4STobin Davis } 665c9b443d4STobin Davis 666c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 667c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 668c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 669c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 670c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 671c9b443d4STobin Davis .private_value = nid | (dir<<16) } 672c9b443d4STobin Davis 67386d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 67486d72bdfSTakashi Iwai 675c9b443d4STobin Davis /* Conexant 5045 specific */ 676c9b443d4STobin Davis 67734cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 67834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 67934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 680cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 681c9b443d4STobin Davis 68234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6835cd57529STobin Davis { 2, NULL }, 6845cd57529STobin Davis }; 685c9b443d4STobin Davis 68634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 687c9b443d4STobin Davis .num_items = 2, 688c9b443d4STobin Davis .items = { 6893edbbb9eSMichael Karcher { "Internal Mic", 0x1 }, 6903edbbb9eSMichael Karcher { "Mic", 0x2 }, 691c9b443d4STobin Davis } 692c9b443d4STobin Davis }; 693c9b443d4STobin Davis 69434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 69522e14130SLukasz Marcinowski .num_items = 5, 6965218c892SJiang Zhe .items = { 69722e14130SLukasz Marcinowski { "CD", 0x4 }, 6983edbbb9eSMichael Karcher { "Internal Mic", 0x1 }, 6993edbbb9eSMichael Karcher { "Mic", 0x2 }, 7003edbbb9eSMichael Karcher { "Line", 0x3 }, 70122e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7025218c892SJiang Zhe } 7035218c892SJiang Zhe }; 7045218c892SJiang Zhe 70534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7062de3c232SJiang zhe .num_items = 2, 7072de3c232SJiang zhe .items = { 7083edbbb9eSMichael Karcher { "Mic", 0x1 }, 7093edbbb9eSMichael Karcher { "Internal Mic", 0x2 }, 7102de3c232SJiang zhe } 7112de3c232SJiang zhe }; 7122de3c232SJiang zhe 713c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 714c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 715c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 716c9b443d4STobin Davis { 717c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 718c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 71982f30040STobin Davis unsigned int bits; 720c9b443d4STobin Davis 72182f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 722c9b443d4STobin Davis return 0; 723c9b443d4STobin Davis 72482f30040STobin Davis /* toggle internal speakers mute depending of presence of 72582f30040STobin Davis * the headphone jack 72682f30040STobin Davis */ 72747fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 72847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 72947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7307f29673bSTobin Davis 73147fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 73247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 73347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 734c9b443d4STobin Davis return 1; 735c9b443d4STobin Davis } 736c9b443d4STobin Davis 737c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 73834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 739cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 740cca3b371STakashi Iwai .values = { 741cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 742cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 743cca3b371STakashi Iwai 0 744cca3b371STakashi Iwai }, 745cca3b371STakashi Iwai }; 746c9b443d4STobin Davis 7477f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7487f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7497f29673bSTobin Davis { 75034cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7517f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7527f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7537f29673bSTobin Davis {} 7547f29673bSTobin Davis }; 75534cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7567f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7577f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7587f29673bSTobin Davis {} 7597f29673bSTobin Davis }; 7607f29673bSTobin Davis unsigned int present; 7617f29673bSTobin Davis 762d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7637f29673bSTobin Davis if (present) 7647f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7657f29673bSTobin Davis else 7667f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7677f29673bSTobin Davis } 7687f29673bSTobin Davis 769c9b443d4STobin Davis 770c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 771c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 772c9b443d4STobin Davis { 77382f30040STobin Davis struct conexant_spec *spec = codec->spec; 774dd87da1cSTobin Davis unsigned int bits; 775c9b443d4STobin Davis 776d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 777dd87da1cSTobin Davis 77847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 77947fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 78047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 781c9b443d4STobin Davis } 782c9b443d4STobin Davis 783c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 784c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 785c9b443d4STobin Davis unsigned int res) 786c9b443d4STobin Davis { 787c9b443d4STobin Davis res >>= 26; 788c9b443d4STobin Davis switch (res) { 789c9b443d4STobin Davis case CONEXANT_HP_EVENT: 790c9b443d4STobin Davis cxt5045_hp_automute(codec); 791c9b443d4STobin Davis break; 7927f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7937f29673bSTobin Davis cxt5045_hp_automic(codec); 7947f29673bSTobin Davis break; 7957f29673bSTobin Davis 796c9b443d4STobin Davis } 797c9b443d4STobin Davis } 798c9b443d4STobin Davis 79934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 800*cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 801*cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 802c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 803c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 80428c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 80528c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8068607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8078607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 808cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 809c9b443d4STobin Davis { 810c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 811c9b443d4STobin Davis .name = "Master Playback Switch", 81282f30040STobin Davis .info = cxt_eapd_info, 81382f30040STobin Davis .get = cxt_eapd_get, 814c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 81582f30040STobin Davis .private_value = 0x10, 816c9b443d4STobin Davis }, 817c9b443d4STobin Davis 818c9b443d4STobin Davis {} 819c9b443d4STobin Davis }; 820c9b443d4STobin Davis 82134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 82222e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 82322e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 82422e14130SLukasz Marcinowski 8253edbbb9eSMichael Karcher HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT), 8263edbbb9eSMichael Karcher HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT), 8275218c892SJiang Zhe 8285218c892SJiang Zhe {} 8295218c892SJiang Zhe }; 8305218c892SJiang Zhe 83134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 832*cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT), 833*cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 8342de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8352de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 83628c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 83728c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8388607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8398607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8402de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8412de3c232SJiang zhe { 8422de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8432de3c232SJiang zhe .name = "Master Playback Switch", 8442de3c232SJiang zhe .info = cxt_eapd_info, 8452de3c232SJiang zhe .get = cxt_eapd_get, 8462de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8472de3c232SJiang zhe .private_value = 0x10, 8482de3c232SJiang zhe }, 8492de3c232SJiang zhe 8502de3c232SJiang zhe {} 8512de3c232SJiang zhe }; 8522de3c232SJiang zhe 85334cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 854c9b443d4STobin Davis /* Line in, Mic */ 8554090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8567f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 857c9b443d4STobin Davis /* HP, Amp */ 858c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 859c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 86082f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 861c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 862c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 863c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 864c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 865c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 866c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 86728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8687f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 86982f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 870c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 871c9b443d4STobin Davis /* SPDIF route: PCM */ 872cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 873c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 874c9b443d4STobin Davis /* EAPD */ 87582f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 876c9b443d4STobin Davis { } /* end */ 877c9b443d4STobin Davis }; 878c9b443d4STobin Davis 87934cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 88028c4edb7SDavid Henningsson /* Internal Mic, Mic */ 8815218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8825218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8835218c892SJiang Zhe /* Line In,HP, Amp */ 8845218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8855218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8865218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 8875218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 8885218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8895218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 8905218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 8915218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 8925218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 89328c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8945218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 8955218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 8965218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 8975218c892SJiang Zhe /* SPDIF route: PCM */ 898cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8995218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9005218c892SJiang Zhe /* EAPD */ 9015218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9025218c892SJiang Zhe { } /* end */ 9035218c892SJiang Zhe }; 9047f29673bSTobin Davis 90534cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9067f29673bSTobin Davis /* pin sensing on HP jack */ 9077f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 908d3091fadSTakashi Iwai { } /* end */ 9097f29673bSTobin Davis }; 9107f29673bSTobin Davis 91134cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9127f29673bSTobin Davis /* pin sensing on HP jack */ 9137f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 914d3091fadSTakashi Iwai { } /* end */ 9157f29673bSTobin Davis }; 9167f29673bSTobin Davis 917c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 918c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 919c9b443d4STobin Davis * configuration. 920c9b443d4STobin Davis */ 92134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 922c9b443d4STobin Davis .num_items = 5, 923c9b443d4STobin Davis .items = { 924c9b443d4STobin Davis { "MIXER", 0x0 }, 925c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 926c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 927c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 928c9b443d4STobin Davis { "CD pin", 0x4 }, 929c9b443d4STobin Davis }, 930c9b443d4STobin Davis }; 931c9b443d4STobin Davis 93234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 933c9b443d4STobin Davis 934c9b443d4STobin Davis /* Output controls */ 935c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 936c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9377f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9387f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9397f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9407f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 941c9b443d4STobin Davis 942c9b443d4STobin Davis /* Modes for retasking pin widgets */ 943c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 944c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 945c9b443d4STobin Davis 94682f30040STobin Davis /* EAPD Switch Control */ 94782f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 94882f30040STobin Davis 949c9b443d4STobin Davis /* Loopback mixer controls */ 950c9b443d4STobin Davis 9517f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9527f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9537f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9547f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9557f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9567f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9577f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9587f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9597f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9607f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 961c9b443d4STobin Davis { 962c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 963c9b443d4STobin Davis .name = "Input Source", 964c9b443d4STobin Davis .info = conexant_mux_enum_info, 965c9b443d4STobin Davis .get = conexant_mux_enum_get, 966c9b443d4STobin Davis .put = conexant_mux_enum_put, 967c9b443d4STobin Davis }, 968fb3409e7STobin Davis /* Audio input controls */ 969*cbf2d28eSMichael Karcher HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT), 970*cbf2d28eSMichael Karcher HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT), 971c9b443d4STobin Davis { } /* end */ 972c9b443d4STobin Davis }; 973c9b443d4STobin Davis 97434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 9757f29673bSTobin Davis /* Set connections */ 9767f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9777f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9787f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 979c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 980c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9817f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 982c9b443d4STobin Davis 983c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 984c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 985c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 986c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 987c9b443d4STobin Davis * control. 988c9b443d4STobin Davis */ 989cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 990cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 991c9b443d4STobin Davis 992c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 993c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 994c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 995c9b443d4STobin Davis 996c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 997c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 998c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 999c9b443d4STobin Davis * input/output buffers as needed. 1000c9b443d4STobin Davis */ 1001c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1002c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1003c9b443d4STobin Davis 1004c9b443d4STobin Davis /* Mute capture amp left and right */ 1005c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1006c9b443d4STobin Davis 1007c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1008c9b443d4STobin Davis * pin) 1009c9b443d4STobin Davis */ 1010c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10117f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1012c9b443d4STobin Davis 1013c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1014c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1015c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1016c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1017c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1018c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1019c9b443d4STobin Davis 1020c9b443d4STobin Davis { } 1021c9b443d4STobin Davis }; 1022c9b443d4STobin Davis #endif 1023c9b443d4STobin Davis 1024c9b443d4STobin Davis 1025c9b443d4STobin Davis /* initialize jack-sensing, too */ 1026c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1027c9b443d4STobin Davis { 1028c9b443d4STobin Davis conexant_init(codec); 1029c9b443d4STobin Davis cxt5045_hp_automute(codec); 1030c9b443d4STobin Davis return 0; 1031c9b443d4STobin Davis } 1032c9b443d4STobin Davis 1033c9b443d4STobin Davis 1034c9b443d4STobin Davis enum { 103515908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 103615908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 103715908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10385218c892SJiang Zhe CXT5045_BENQ, 10392de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1040c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1041c9b443d4STobin Davis CXT5045_TEST, 1042c9b443d4STobin Davis #endif 10431f8458a2STakashi Iwai CXT5045_AUTO, 1044f5fcc13cSTakashi Iwai CXT5045_MODELS 1045c9b443d4STobin Davis }; 1046c9b443d4STobin Davis 1047ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 104815908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 104915908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 105015908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10515218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10522de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1053c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1054f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1055c9b443d4STobin Davis #endif 10561f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1057f5fcc13cSTakashi Iwai }; 1058c9b443d4STobin Davis 105934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10602de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 10616a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10625218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 106315908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 106415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10659e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10669e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 106715908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 106815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 106915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1070dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1071dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 107215908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1073c9b443d4STobin Davis {} 1074c9b443d4STobin Davis }; 1075c9b443d4STobin Davis 1076c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1077c9b443d4STobin Davis { 1078c9b443d4STobin Davis struct conexant_spec *spec; 1079c9b443d4STobin Davis int board_config; 1080c9b443d4STobin Davis 10811f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 10821f8458a2STakashi Iwai cxt5045_models, 10831f8458a2STakashi Iwai cxt5045_cfg_tbl); 10841f8458a2STakashi Iwai if (board_config < 0) 1085c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 10861f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 10871f8458a2STakashi Iwai return patch_conexant_auto(codec); 10881f8458a2STakashi Iwai 1089c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1090c9b443d4STobin Davis if (!spec) 1091c9b443d4STobin Davis return -ENOMEM; 1092c9b443d4STobin Davis codec->spec = spec; 10939421f954STakashi Iwai codec->pin_amp_workaround = 1; 10944f32456eSMichael Karcher codec->single_adc_amp = 1; 1095c9b443d4STobin Davis 1096c9b443d4STobin Davis spec->multiout.max_channels = 2; 1097c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1098c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1099c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1100c9b443d4STobin Davis spec->num_adc_nids = 1; 1101c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1102c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1103c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1104c9b443d4STobin Davis spec->num_mixers = 1; 1105c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1106c9b443d4STobin Davis spec->num_init_verbs = 1; 1107c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1108c9b443d4STobin Davis spec->spdif_route = 0; 11093507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11103507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11115cd57529STobin Davis 11123507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1113c9b443d4STobin Davis 1114c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1115c9b443d4STobin Davis 1116c9b443d4STobin Davis switch (board_config) { 111715908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11187f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1119c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1120c9b443d4STobin Davis spec->num_init_verbs = 2; 11217f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11227f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11237f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11247f29673bSTobin Davis break; 112515908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 112686376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11277f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11287f29673bSTobin Davis spec->num_init_verbs = 2; 11297f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1130c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1131c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1132c9b443d4STobin Davis break; 113315908c36SMarc Boucher default: 113415908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 113515908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 113615908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 113715908c36SMarc Boucher spec->num_init_verbs = 3; 113815908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 113915908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 114015908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 114115908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 114215908c36SMarc Boucher break; 11435218c892SJiang Zhe case CXT5045_BENQ: 11445218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11455218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11465218c892SJiang Zhe spec->num_init_verbs = 1; 11475218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11485218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11495218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11505218c892SJiang Zhe spec->num_mixers = 2; 11515218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11525218c892SJiang Zhe break; 11532de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11542de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11552de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11562de3c232SJiang zhe spec->num_init_verbs = 2; 11572de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11582de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11592de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11602de3c232SJiang zhe break; 1161c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1162c9b443d4STobin Davis case CXT5045_TEST: 1163c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1164c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1165c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 116615908c36SMarc Boucher break; 116715908c36SMarc Boucher 1168c9b443d4STobin Davis #endif 1169c9b443d4STobin Davis } 117048ecb7e8STakashi Iwai 1171031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1172031005f7STakashi Iwai case 0x103c: 11738f0f5ff6SDaniel T Chen case 0x1631: 11740b587fc4SDaniel T Chen case 0x1734: 11750ebf9e36SDaniel T Chen case 0x17aa: 11760ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 11770ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 11780ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 117948ecb7e8STakashi Iwai */ 118048ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 118148ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 118248ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 118348ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 118448ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1185031005f7STakashi Iwai break; 1186031005f7STakashi Iwai } 118748ecb7e8STakashi Iwai 11883507e2a8STakashi Iwai if (spec->beep_amp) 11893507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 11903507e2a8STakashi Iwai 1191c9b443d4STobin Davis return 0; 1192c9b443d4STobin Davis } 1193c9b443d4STobin Davis 1194c9b443d4STobin Davis 1195c9b443d4STobin Davis /* Conexant 5047 specific */ 119682f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1197c9b443d4STobin Davis 119834cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 119934cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 120034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1201c9b443d4STobin Davis 120234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12035cd57529STobin Davis { 2, NULL }, 12045cd57529STobin Davis }; 1205c9b443d4STobin Davis 120634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 120782f30040STobin Davis .num_items = 2, 120882f30040STobin Davis .items = { 120982f30040STobin Davis { "ExtMic", 0x2 }, 121082f30040STobin Davis { "Line-In", 0x1 }, 1211c9b443d4STobin Davis } 1212c9b443d4STobin Davis }; 1213c9b443d4STobin Davis 1214c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1215c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1216c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1217c9b443d4STobin Davis { 1218c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1219c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 122082f30040STobin Davis unsigned int bits; 1221c9b443d4STobin Davis 122282f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1223c9b443d4STobin Davis return 0; 1224c9b443d4STobin Davis 122582f30040STobin Davis /* toggle internal speakers mute depending of presence of 122682f30040STobin Davis * the headphone jack 122782f30040STobin Davis */ 122847fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12293b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12303b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12313b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12323b7523fcSTakashi Iwai */ 12335d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 123447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 123547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 123647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 123747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1238c9b443d4STobin Davis return 1; 1239c9b443d4STobin Davis } 1240c9b443d4STobin Davis 1241c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1242c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1243c9b443d4STobin Davis { 124482f30040STobin Davis struct conexant_spec *spec = codec->spec; 1245dd87da1cSTobin Davis unsigned int bits; 1246c9b443d4STobin Davis 1247d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1248dd87da1cSTobin Davis 124947fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12503b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12515d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 125247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1253c9b443d4STobin Davis } 1254c9b443d4STobin Davis 1255c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1256c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1257c9b443d4STobin Davis { 125834cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12599f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12609f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1261c9b443d4STobin Davis {} 1262c9b443d4STobin Davis }; 126334cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12649f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12659f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1266c9b443d4STobin Davis {} 1267c9b443d4STobin Davis }; 1268c9b443d4STobin Davis unsigned int present; 1269c9b443d4STobin Davis 1270d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1271c9b443d4STobin Davis if (present) 1272c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1273c9b443d4STobin Davis else 1274c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1275c9b443d4STobin Davis } 1276c9b443d4STobin Davis 1277c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1278c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1279c9b443d4STobin Davis unsigned int res) 1280c9b443d4STobin Davis { 12819f113e0eSMarc Boucher switch (res >> 26) { 1282c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1283c9b443d4STobin Davis cxt5047_hp_automute(codec); 1284c9b443d4STobin Davis break; 1285c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1286c9b443d4STobin Davis cxt5047_hp_automic(codec); 1287c9b443d4STobin Davis break; 1288c9b443d4STobin Davis } 1289c9b443d4STobin Davis } 1290c9b443d4STobin Davis 129134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1292df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1293df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 12945f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1295c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1296c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1297c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1298c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 129982f30040STobin Davis { 130082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 130182f30040STobin Davis .name = "Master Playback Switch", 130282f30040STobin Davis .info = cxt_eapd_info, 130382f30040STobin Davis .get = cxt_eapd_get, 1304c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1305c9b443d4STobin Davis .private_value = 0x13, 1306c9b443d4STobin Davis }, 1307c9b443d4STobin Davis 1308c9b443d4STobin Davis {} 1309c9b443d4STobin Davis }; 1310c9b443d4STobin Davis 131134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13123b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13135d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1314df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1315df481e41STakashi Iwai {} 1316df481e41STakashi Iwai }; 1317df481e41STakashi Iwai 131834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1319c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1320c9b443d4STobin Davis { } /* end */ 1321c9b443d4STobin Davis }; 1322c9b443d4STobin Davis 132334cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1324c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1325c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1326c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1327c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13287f29673bSTobin Davis /* HP, Speaker */ 1329b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13305b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13315b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13327f29673bSTobin Davis /* Record selector: Mic */ 13337f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13347f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13357f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13367f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1337c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1338c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1339c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1340c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1341c9b443d4STobin Davis /* SPDIF route: PCM */ 1342c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 134382f30040STobin Davis /* Enable unsolicited events */ 134482f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 134582f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1346c9b443d4STobin Davis { } /* end */ 1347c9b443d4STobin Davis }; 1348c9b443d4STobin Davis 1349c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 135034cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13513b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1352c9b443d4STobin Davis {} 1353c9b443d4STobin Davis }; 1354c9b443d4STobin Davis 1355c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1356c9b443d4STobin Davis * configuration. 1357c9b443d4STobin Davis */ 1358c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 135934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 136082f30040STobin Davis .num_items = 4, 1361c9b443d4STobin Davis .items = { 136282f30040STobin Davis { "LINE1 pin", 0x0 }, 136382f30040STobin Davis { "MIC1 pin", 0x1 }, 136482f30040STobin Davis { "MIC2 pin", 0x2 }, 136582f30040STobin Davis { "CD pin", 0x3 }, 1366c9b443d4STobin Davis }, 1367c9b443d4STobin Davis }; 1368c9b443d4STobin Davis 136934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1370c9b443d4STobin Davis 1371c9b443d4STobin Davis /* Output only controls */ 137282f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 137382f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 137482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 137582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1376c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1377c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1378c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1379c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 138082f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 138182f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 138282f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 138382f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1384c9b443d4STobin Davis 1385c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1386c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1387c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1388c9b443d4STobin Davis 138982f30040STobin Davis /* EAPD Switch Control */ 139082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 139182f30040STobin Davis 1392c9b443d4STobin Davis /* Loopback mixer controls */ 139382f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 139482f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 139582f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 139682f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 139782f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 139882f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 139982f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 140082f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1401c9b443d4STobin Davis 140282f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 140382f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 140482f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 140582f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 140682f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 140782f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 140882f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 140982f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1410c9b443d4STobin Davis { 1411c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1412c9b443d4STobin Davis .name = "Input Source", 1413c9b443d4STobin Davis .info = conexant_mux_enum_info, 1414c9b443d4STobin Davis .get = conexant_mux_enum_get, 1415c9b443d4STobin Davis .put = conexant_mux_enum_put, 1416c9b443d4STobin Davis }, 1417854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14189f113e0eSMarc Boucher 1419c9b443d4STobin Davis { } /* end */ 1420c9b443d4STobin Davis }; 1421c9b443d4STobin Davis 142234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1423c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1424c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1425c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1426c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1427c9b443d4STobin Davis 1428c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1429c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1430c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1431c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1432c9b443d4STobin Davis * control. 1433c9b443d4STobin Davis */ 1434c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1435c9b443d4STobin Davis 1436c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1437c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1438c9b443d4STobin Davis */ 1439c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1440c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1441c9b443d4STobin Davis 1442c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1443c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1444c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1445c9b443d4STobin Davis 1446c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1447c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1448c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1449c9b443d4STobin Davis * input/output buffers as needed. 1450c9b443d4STobin Davis */ 1451c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1452c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1453c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1454c9b443d4STobin Davis 1455c9b443d4STobin Davis /* Mute capture amp left and right */ 1456c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1457c9b443d4STobin Davis 1458c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1459c9b443d4STobin Davis * pin) 1460c9b443d4STobin Davis */ 1461c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1462c9b443d4STobin Davis 1463c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1464c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1465c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1466c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1467c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1468c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1469c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1470c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1471c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1472c9b443d4STobin Davis 1473c9b443d4STobin Davis { } 1474c9b443d4STobin Davis }; 1475c9b443d4STobin Davis #endif 1476c9b443d4STobin Davis 1477c9b443d4STobin Davis 1478c9b443d4STobin Davis /* initialize jack-sensing, too */ 1479c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1480c9b443d4STobin Davis { 1481c9b443d4STobin Davis conexant_init(codec); 1482c9b443d4STobin Davis cxt5047_hp_automute(codec); 1483c9b443d4STobin Davis return 0; 1484c9b443d4STobin Davis } 1485c9b443d4STobin Davis 1486c9b443d4STobin Davis 1487c9b443d4STobin Davis enum { 1488f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1489f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1490f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1491c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1492c9b443d4STobin Davis CXT5047_TEST, 1493c9b443d4STobin Davis #endif 1494fa5dadcbSTakashi Iwai CXT5047_AUTO, 1495f5fcc13cSTakashi Iwai CXT5047_MODELS 1496c9b443d4STobin Davis }; 1497c9b443d4STobin Davis 1498ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1499f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1500f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1501f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1502c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1503f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1504c9b443d4STobin Davis #endif 1505fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1506f5fcc13cSTakashi Iwai }; 1507c9b443d4STobin Davis 150834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1509ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1510dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1511dea0a509STakashi Iwai CXT5047_LAPTOP), 1512f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1513c9b443d4STobin Davis {} 1514c9b443d4STobin Davis }; 1515c9b443d4STobin Davis 1516c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1517c9b443d4STobin Davis { 1518c9b443d4STobin Davis struct conexant_spec *spec; 1519c9b443d4STobin Davis int board_config; 1520c9b443d4STobin Davis 1521fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1522fa5dadcbSTakashi Iwai cxt5047_models, 1523fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1524fa5dadcbSTakashi Iwai if (board_config < 0) 1525c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1526fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1527fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1528fa5dadcbSTakashi Iwai 1529c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1530c9b443d4STobin Davis if (!spec) 1531c9b443d4STobin Davis return -ENOMEM; 1532c9b443d4STobin Davis codec->spec = spec; 15339421f954STakashi Iwai codec->pin_amp_workaround = 1; 1534c9b443d4STobin Davis 1535c9b443d4STobin Davis spec->multiout.max_channels = 2; 1536c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1537c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1538c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1539c9b443d4STobin Davis spec->num_adc_nids = 1; 1540c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1541c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1542c9b443d4STobin Davis spec->num_mixers = 1; 1543df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1544c9b443d4STobin Davis spec->num_init_verbs = 1; 1545c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1546c9b443d4STobin Davis spec->spdif_route = 0; 15475cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15485cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1549c9b443d4STobin Davis 1550c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1551c9b443d4STobin Davis 1552c9b443d4STobin Davis switch (board_config) { 1553c9b443d4STobin Davis case CXT5047_LAPTOP: 1554df481e41STakashi Iwai spec->num_mixers = 2; 1555df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1556df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1557c9b443d4STobin Davis break; 1558c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1559df481e41STakashi Iwai spec->num_mixers = 2; 1560df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1561fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1562c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1563c9b443d4STobin Davis break; 1564c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 156582f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1566df481e41STakashi Iwai spec->num_mixers = 2; 1567df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1568c9b443d4STobin Davis spec->num_init_verbs = 2; 1569c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1570fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1571c9b443d4STobin Davis break; 1572c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1573c9b443d4STobin Davis case CXT5047_TEST: 1574c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1575c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1576c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1577fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1578c9b443d4STobin Davis #endif 1579c9b443d4STobin Davis } 1580dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1581025f206cSDaniel T Chen 1582025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1583025f206cSDaniel T Chen case 0x103c: 1584025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1585025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1586025f206cSDaniel T Chen * with 0 dB offset 0x17) 1587025f206cSDaniel T Chen */ 1588025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1589025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1590025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1591025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1592025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1593025f206cSDaniel T Chen break; 1594025f206cSDaniel T Chen } 1595025f206cSDaniel T Chen 1596c9b443d4STobin Davis return 0; 1597c9b443d4STobin Davis } 1598c9b443d4STobin Davis 1599461e2c78STakashi Iwai /* Conexant 5051 specific */ 160034cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 160134cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1602461e2c78STakashi Iwai 160334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1604461e2c78STakashi Iwai { 2, NULL }, 1605461e2c78STakashi Iwai }; 1606461e2c78STakashi Iwai 1607461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1608461e2c78STakashi Iwai { 1609461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1610461e2c78STakashi Iwai unsigned int pinctl; 161123d2df5bSTakashi Iwai /* headphone pin */ 161223d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 161323d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 161423d2df5bSTakashi Iwai pinctl); 161523d2df5bSTakashi Iwai /* speaker pin */ 1616461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1617461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1618461e2c78STakashi Iwai pinctl); 1619f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1620f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1621f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1622f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1623f7154de2SHerton Ronaldo Krzesinski pinctl); 1624461e2c78STakashi Iwai } 1625461e2c78STakashi Iwai 1626461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1627461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1628461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1629461e2c78STakashi Iwai { 1630461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1631461e2c78STakashi Iwai 1632461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1633461e2c78STakashi Iwai return 0; 1634461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1635461e2c78STakashi Iwai return 1; 1636461e2c78STakashi Iwai } 1637461e2c78STakashi Iwai 1638461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1639461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1640461e2c78STakashi Iwai { 164179d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1642461e2c78STakashi Iwai unsigned int present; 1643461e2c78STakashi Iwai 1644faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 164579d7d533STakashi Iwai return; 1646d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1647461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1648461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1649461e2c78STakashi Iwai present ? 0x01 : 0x00); 1650461e2c78STakashi Iwai } 1651461e2c78STakashi Iwai 1652461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1653461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1654461e2c78STakashi Iwai { 1655461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1656461e2c78STakashi Iwai unsigned int present; 1657461e2c78STakashi Iwai hda_nid_t new_adc; 1658461e2c78STakashi Iwai 1659faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 166079d7d533STakashi Iwai return; 1661d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1662461e2c78STakashi Iwai if (present) 1663461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1664461e2c78STakashi Iwai else 1665461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1666461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1667461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1668461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1669f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1670461e2c78STakashi Iwai spec->cur_adc = new_adc; 1671461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1672461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1673461e2c78STakashi Iwai spec->cur_adc_format); 1674461e2c78STakashi Iwai } 1675461e2c78STakashi Iwai } 1676461e2c78STakashi Iwai 1677461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1678461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1679461e2c78STakashi Iwai { 1680461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1681461e2c78STakashi Iwai 1682d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1683461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1684461e2c78STakashi Iwai } 1685461e2c78STakashi Iwai 1686461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1687461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1688461e2c78STakashi Iwai unsigned int res) 1689461e2c78STakashi Iwai { 1690461e2c78STakashi Iwai switch (res >> 26) { 1691461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1692461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1693461e2c78STakashi Iwai break; 1694461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1695461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1696461e2c78STakashi Iwai break; 1697461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1698461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1699461e2c78STakashi Iwai break; 1700461e2c78STakashi Iwai } 1701461e2c78STakashi Iwai } 1702461e2c78STakashi Iwai 170334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1704461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1705461e2c78STakashi Iwai { 1706461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1707461e2c78STakashi Iwai .name = "Master Playback Switch", 1708461e2c78STakashi Iwai .info = cxt_eapd_info, 1709461e2c78STakashi Iwai .get = cxt_eapd_get, 1710461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1711461e2c78STakashi Iwai .private_value = 0x1a, 1712461e2c78STakashi Iwai }, 17132c7a3fb3STakashi Iwai {} 17142c7a3fb3STakashi Iwai }; 1715461e2c78STakashi Iwai 171634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17172c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17182c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17198607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17208607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17212c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17222c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1723461e2c78STakashi Iwai {} 1724461e2c78STakashi Iwai }; 1725461e2c78STakashi Iwai 172634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1727461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1728461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17298607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17308607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1731461e2c78STakashi Iwai {} 1732461e2c78STakashi Iwai }; 1733461e2c78STakashi Iwai 173434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17354e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17364e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 173779d7d533STakashi Iwai {} 173879d7d533STakashi Iwai }; 173979d7d533STakashi Iwai 174034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17415f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17425f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1743cd9d95a5SKen Prox {} 1744cd9d95a5SKen Prox }; 1745cd9d95a5SKen Prox 174634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1747faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1748faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17498607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17508607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1751faddaa5dSTakashi Iwai {} 1752faddaa5dSTakashi Iwai }; 1753faddaa5dSTakashi Iwai 175434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1755461e2c78STakashi Iwai /* Line in, Mic */ 1756461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1757461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1758461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1759461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1760461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1761461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1762461e2c78STakashi Iwai /* SPK */ 1763461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1764461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1765461e2c78STakashi Iwai /* HP, Amp */ 1766461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1767461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1768461e2c78STakashi Iwai /* DAC1 */ 1769461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 177028c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1771461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1772461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1773461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1774461e2c78STakashi Iwai /* SPDIF route: PCM */ 17751965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1776461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1777461e2c78STakashi Iwai /* EAPD */ 1778461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1779461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1780461e2c78STakashi Iwai { } /* end */ 1781461e2c78STakashi Iwai }; 1782461e2c78STakashi Iwai 178334cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 178479d7d533STakashi Iwai /* Line in, Mic */ 178579d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 178679d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 178779d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 178879d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 178979d7d533STakashi Iwai /* SPK */ 179079d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 179179d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 179279d7d533STakashi Iwai /* HP, Amp */ 179379d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 179479d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 179579d7d533STakashi Iwai /* DAC1 */ 179679d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 179728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 179879d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 179979d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 180079d7d533STakashi Iwai /* SPDIF route: PCM */ 180179d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 180279d7d533STakashi Iwai /* EAPD */ 180379d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 180479d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 180579d7d533STakashi Iwai { } /* end */ 180679d7d533STakashi Iwai }; 180779d7d533STakashi Iwai 180834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1809cd9d95a5SKen Prox /* Line in, Mic */ 181030ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1811cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1812cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1813cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1814cd9d95a5SKen Prox /* SPK */ 1815cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1816cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1817cd9d95a5SKen Prox /* HP, Amp */ 1818cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1819cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1820cd9d95a5SKen Prox /* DAC1 */ 1821cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 182228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1823cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1824cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1825cd9d95a5SKen Prox /* SPDIF route: PCM */ 1826cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1827cd9d95a5SKen Prox /* EAPD */ 1828cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1829cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1830cd9d95a5SKen Prox { } /* end */ 1831cd9d95a5SKen Prox }; 1832cd9d95a5SKen Prox 18336953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18346953e552STakashi Iwai unsigned int event) 18356953e552STakashi Iwai { 18366953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18376953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18386953e552STakashi Iwai AC_USRSP_EN | event); 18396953e552STakashi Iwai } 18406953e552STakashi Iwai 184134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1842f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1843f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1844f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1845f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1846f7154de2SHerton Ronaldo Krzesinski }; 1847f7154de2SHerton Ronaldo Krzesinski 1848461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1849461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1850461e2c78STakashi Iwai { 18516953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18526953e552STakashi Iwai 1853461e2c78STakashi Iwai conexant_init(codec); 18546953e552STakashi Iwai 18556953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18566953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18576953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18586953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18596953e552STakashi Iwai 1860461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1861461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1862461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1863461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1864461e2c78STakashi Iwai } 1865461e2c78STakashi Iwai return 0; 1866461e2c78STakashi Iwai } 1867461e2c78STakashi Iwai 1868461e2c78STakashi Iwai 1869461e2c78STakashi Iwai enum { 1870461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1871461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 187279d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1873cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1874faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1875f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 18766764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1877461e2c78STakashi Iwai CXT5051_MODELS 1878461e2c78STakashi Iwai }; 1879461e2c78STakashi Iwai 1880ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1881461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1882461e2c78STakashi Iwai [CXT5051_HP] = "hp", 188379d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 18845f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1885faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1886f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 18876764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1888461e2c78STakashi Iwai }; 1889461e2c78STakashi Iwai 189034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 189179d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 18921812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 18935f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1894faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1895461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1896461e2c78STakashi Iwai CXT5051_LAPTOP), 1897461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1898f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1899461e2c78STakashi Iwai {} 1900461e2c78STakashi Iwai }; 1901461e2c78STakashi Iwai 1902461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1903461e2c78STakashi Iwai { 1904461e2c78STakashi Iwai struct conexant_spec *spec; 1905461e2c78STakashi Iwai int board_config; 1906461e2c78STakashi Iwai 19076764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19086764bcefSTakashi Iwai cxt5051_models, 19096764bcefSTakashi Iwai cxt5051_cfg_tbl); 19106764bcefSTakashi Iwai if (board_config < 0) 1911c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19121f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19136764bcefSTakashi Iwai return patch_conexant_auto(codec); 19146764bcefSTakashi Iwai 1915461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1916461e2c78STakashi Iwai if (!spec) 1917461e2c78STakashi Iwai return -ENOMEM; 1918461e2c78STakashi Iwai codec->spec = spec; 19199421f954STakashi Iwai codec->pin_amp_workaround = 1; 1920461e2c78STakashi Iwai 1921461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1922461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1923461e2c78STakashi Iwai 1924461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1925461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1926461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1927461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1928461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1929461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19302c7a3fb3STakashi Iwai spec->num_mixers = 2; 19312c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19322c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1933461e2c78STakashi Iwai spec->num_init_verbs = 1; 1934461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1935461e2c78STakashi Iwai spec->spdif_route = 0; 1936461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1937461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1938461e2c78STakashi Iwai spec->cur_adc = 0; 1939461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1940461e2c78STakashi Iwai 19413507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 19423507e2a8STakashi Iwai 194379d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 194479d7d533STakashi Iwai 1945faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1946461e2c78STakashi Iwai switch (board_config) { 1947461e2c78STakashi Iwai case CXT5051_HP: 1948461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1949461e2c78STakashi Iwai break; 195079d7d533STakashi Iwai case CXT5051_HP_DV6736: 195179d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 195279d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1953faddaa5dSTakashi Iwai spec->auto_mic = 0; 195479d7d533STakashi Iwai break; 1955cd9d95a5SKen Prox case CXT5051_F700: 1956cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1957cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1958faddaa5dSTakashi Iwai spec->auto_mic = 0; 1959faddaa5dSTakashi Iwai break; 1960faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1961faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1962faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1963cd9d95a5SKen Prox break; 1964f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 1965f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 1966f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 1967f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 1968f7154de2SHerton Ronaldo Krzesinski break; 1969461e2c78STakashi Iwai } 1970461e2c78STakashi Iwai 19713507e2a8STakashi Iwai if (spec->beep_amp) 19723507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 19733507e2a8STakashi Iwai 1974461e2c78STakashi Iwai return 0; 1975461e2c78STakashi Iwai } 1976461e2c78STakashi Iwai 19770fb67e98SDaniel Drake /* Conexant 5066 specific */ 19780fb67e98SDaniel Drake 197934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 198034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 198134cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 198234cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 19830fb67e98SDaniel Drake 1984dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 1985dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 1986dbaccc0cSDaniel Drake * the DC input range of the codec. */ 1987dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 1988dbaccc0cSDaniel Drake 198934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 19900fb67e98SDaniel Drake { 2, NULL }, 19910fb67e98SDaniel Drake }; 19920fb67e98SDaniel Drake 1993a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 1994a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 1995a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 1996a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 1997a3de8ab8STakashi Iwai 19980fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 19990fb67e98SDaniel Drake { 20000fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20010fb67e98SDaniel Drake unsigned int pinctl; 20020fb67e98SDaniel Drake 20033a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20043a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20050fb67e98SDaniel Drake 20060fb67e98SDaniel Drake /* Port A (HP) */ 2007a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20080fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20090fb67e98SDaniel Drake pinctl); 20100fb67e98SDaniel Drake 20110fb67e98SDaniel Drake /* Port D (HP/LO) */ 2012a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2013a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2014a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2015a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20163a253445SJohn Baboval pinctl = 0; 20173a253445SJohn Baboval } else { 2018a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2019a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2020a3de8ab8STakashi Iwai pinctl = 0; 20213a253445SJohn Baboval } 20220fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20230fb67e98SDaniel Drake pinctl); 20240fb67e98SDaniel Drake 20250fb67e98SDaniel Drake /* CLASS_D AMP */ 20260fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20270fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20280fb67e98SDaniel Drake pinctl); 20290fb67e98SDaniel Drake } 20300fb67e98SDaniel Drake 20310fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20320fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20330fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20340fb67e98SDaniel Drake { 20350fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20360fb67e98SDaniel Drake 20370fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20380fb67e98SDaniel Drake return 0; 20390fb67e98SDaniel Drake 20400fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20410fb67e98SDaniel Drake return 1; 20420fb67e98SDaniel Drake } 20430fb67e98SDaniel Drake 2044c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2045c4cfe66cSDaniel Drake .num_items = 3, 2046c4cfe66cSDaniel Drake .items = { 2047c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2048c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2049c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2050c4cfe66cSDaniel Drake }, 2051c4cfe66cSDaniel Drake }; 2052c4cfe66cSDaniel Drake 2053c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2054c4cfe66cSDaniel Drake { 2055c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2056c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2057c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2058c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2059c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2060c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2061c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2062c4cfe66cSDaniel Drake } 2063c4cfe66cSDaniel Drake 206475f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 206575f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 206675f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 206775f8991dSDaniel Drake * is happening when it is not. */ 206875f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20690fb67e98SDaniel Drake { 2070dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 207175f8991dSDaniel Drake if (!spec->recording) 207275f8991dSDaniel Drake return; 20730fb67e98SDaniel Drake 2074c4cfe66cSDaniel Drake if (spec->dc_enable) { 2075c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2076c4cfe66cSDaniel Drake * through our special DC port */ 2077c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2078c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2079c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2080c4cfe66cSDaniel Drake 2081c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2082c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2083c4cfe66cSDaniel Drake {}, 2084c4cfe66cSDaniel Drake }; 2085c4cfe66cSDaniel Drake 2086c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2087c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2088c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2089c4cfe66cSDaniel Drake return; 2090c4cfe66cSDaniel Drake } 2091c4cfe66cSDaniel Drake 2092c4cfe66cSDaniel Drake /* disable DC (port F) */ 2093c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2094c4cfe66cSDaniel Drake 209575f8991dSDaniel Drake /* external mic, port B */ 209675f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 209775f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 20980fb67e98SDaniel Drake 209975f8991dSDaniel Drake /* internal mic, port C */ 210075f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 210175f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 210275f8991dSDaniel Drake } 21030fb67e98SDaniel Drake 210475f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 210575f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 210675f8991dSDaniel Drake { 210775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21080fb67e98SDaniel Drake unsigned int present; 21090fb67e98SDaniel Drake 2110c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2111c4cfe66cSDaniel Drake return; 2112c4cfe66cSDaniel Drake 211375f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 211475f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 211575f8991dSDaniel Drake if (present) 21160fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 211775f8991dSDaniel Drake else 21180fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 211975f8991dSDaniel Drake 212075f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 212175f8991dSDaniel Drake present ? 0 : 1); 212275f8991dSDaniel Drake spec->ext_mic_present = !!present; 212375f8991dSDaniel Drake 212475f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21250fb67e98SDaniel Drake } 21260fb67e98SDaniel Drake 212795a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 212895a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 212995a618bdSEinar Rünkaru { 213095a618bdSEinar Rünkaru unsigned int present; 213195a618bdSEinar Rünkaru 213295a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 213395a618bdSEinar Rünkaru /* enable external mic, port B */ 213475f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 213595a618bdSEinar Rünkaru 213695a618bdSEinar Rünkaru /* switch to external mic input */ 213795a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 213895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 213995a618bdSEinar Rünkaru 214095a618bdSEinar Rünkaru /* disable internal digital mic */ 214195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 214295a618bdSEinar Rünkaru {} 214395a618bdSEinar Rünkaru }; 214434cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 214595a618bdSEinar Rünkaru /* enable internal mic, port C */ 214695a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 214795a618bdSEinar Rünkaru 214895a618bdSEinar Rünkaru /* switch to internal mic input */ 214995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 215095a618bdSEinar Rünkaru 215195a618bdSEinar Rünkaru /* disable external mic, port B */ 215295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 215395a618bdSEinar Rünkaru {} 215495a618bdSEinar Rünkaru }; 215595a618bdSEinar Rünkaru 215695a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 215795a618bdSEinar Rünkaru if (present) { 215895a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 215995a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 216095a618bdSEinar Rünkaru } else { 216195a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 216295a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 216395a618bdSEinar Rünkaru } 216495a618bdSEinar Rünkaru } 216595a618bdSEinar Rünkaru 2166cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2167cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2168cfd3d8dcSGreg Alexander { 2169cfd3d8dcSGreg Alexander unsigned int present; 2170cfd3d8dcSGreg Alexander 2171cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2172cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2173cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2174cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2175cfd3d8dcSGreg Alexander {} 2176cfd3d8dcSGreg Alexander }; 217734cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2178cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2179cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2180cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2181cfd3d8dcSGreg Alexander {} 2182cfd3d8dcSGreg Alexander }; 2183cfd3d8dcSGreg Alexander 2184cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2185cfd3d8dcSGreg Alexander if (present) { 2186cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2187cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2188cfd3d8dcSGreg Alexander } else { 2189cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2190cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2191cfd3d8dcSGreg Alexander } 2192cfd3d8dcSGreg Alexander } 2193cfd3d8dcSGreg Alexander 2194a1d6906eSDavid Henningsson 2195a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2196a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2197a1d6906eSDavid Henningsson { 2198a1d6906eSDavid Henningsson unsigned int present; 2199a1d6906eSDavid Henningsson 2200a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2201a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2202a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2203a1d6906eSDavid Henningsson present ? 1 : 0); 2204a1d6906eSDavid Henningsson } 2205a1d6906eSDavid Henningsson 2206a1d6906eSDavid Henningsson 2207048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2208048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2209048e78a5SDavid Henningsson { 2210048e78a5SDavid Henningsson unsigned int present; 2211048e78a5SDavid Henningsson 2212048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2213048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2214048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2215048e78a5SDavid Henningsson present ? 1 : 3); 2216048e78a5SDavid Henningsson } 2217048e78a5SDavid Henningsson 2218048e78a5SDavid Henningsson 22197b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22207b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22217b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22227b2bfdbcSJens Taprogge { 22237b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22247b2bfdbcSJens Taprogge 222534cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22267b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22277b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22287b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22297b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22307b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22317b2bfdbcSJens Taprogge {} 22327b2bfdbcSJens Taprogge }; 223334cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 22347b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22357b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 22367b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22377b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22387b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22397b2bfdbcSJens Taprogge {} 22407b2bfdbcSJens Taprogge }; 224134cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 22427b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 22437b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 22447b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22457b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22467b2bfdbcSJens Taprogge {} 22477b2bfdbcSJens Taprogge }; 22487b2bfdbcSJens Taprogge 22497b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 22507b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 22517b2bfdbcSJens Taprogge if (ext_present) { 22527b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 22537b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 22547b2bfdbcSJens Taprogge } else if (dock_present) { 22557b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 22567b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 22577b2bfdbcSJens Taprogge } else { 22587b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 22597b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 22607b2bfdbcSJens Taprogge } 22617b2bfdbcSJens Taprogge } 22627b2bfdbcSJens Taprogge 22630fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22640fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22650fb67e98SDaniel Drake { 22660fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22670fb67e98SDaniel Drake unsigned int portA, portD; 22680fb67e98SDaniel Drake 22690fb67e98SDaniel Drake /* Port A */ 2270d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22710fb67e98SDaniel Drake 22720fb67e98SDaniel Drake /* Port D */ 2273d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 22740fb67e98SDaniel Drake 2275a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2276a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 22770fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 22780fb67e98SDaniel Drake portA, portD, spec->hp_present); 22790fb67e98SDaniel Drake cxt5066_update_speaker(codec); 22800fb67e98SDaniel Drake } 22810fb67e98SDaniel Drake 228202b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 228302b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 228402b6b5b6SDavid Henningsson { 228502b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 228602b6b5b6SDavid Henningsson 228702b6b5b6SDavid Henningsson if (spec->dell_vostro) 228802b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 228902b6b5b6SDavid Henningsson else if (spec->ideapad) 229002b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 229102b6b5b6SDavid Henningsson else if (spec->thinkpad) 229202b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 229302b6b5b6SDavid Henningsson else if (spec->hp_laptop) 229402b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2295a1d6906eSDavid Henningsson else if (spec->asus) 2296a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 229702b6b5b6SDavid Henningsson } 229802b6b5b6SDavid Henningsson 22990fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 230075f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23010fb67e98SDaniel Drake { 2302c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23030fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23040fb67e98SDaniel Drake switch (res >> 26) { 23050fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23060fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23070fb67e98SDaniel Drake break; 23080fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2309c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2310c4cfe66cSDaniel Drake if (!spec->dc_enable) 231175f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23120fb67e98SDaniel Drake break; 23130fb67e98SDaniel Drake } 23140fb67e98SDaniel Drake } 23150fb67e98SDaniel Drake 231695a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 231702b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 231895a618bdSEinar Rünkaru { 231902b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 232095a618bdSEinar Rünkaru switch (res >> 26) { 232195a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 232295a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 232395a618bdSEinar Rünkaru break; 232495a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 232502b6b5b6SDavid Henningsson cxt5066_automic(codec); 232695a618bdSEinar Rünkaru break; 232795a618bdSEinar Rünkaru } 232895a618bdSEinar Rünkaru } 232995a618bdSEinar Rünkaru 23307b2bfdbcSJens Taprogge 23310fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 23320fb67e98SDaniel Drake .num_items = 5, 23330fb67e98SDaniel Drake .items = { 23340fb67e98SDaniel Drake { "0dB", 0 }, 23350fb67e98SDaniel Drake { "10dB", 1 }, 23360fb67e98SDaniel Drake { "20dB", 2 }, 23370fb67e98SDaniel Drake { "30dB", 3 }, 23380fb67e98SDaniel Drake { "40dB", 4 }, 23390fb67e98SDaniel Drake }, 23400fb67e98SDaniel Drake }; 23410fb67e98SDaniel Drake 2342cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2343c4cfe66cSDaniel Drake { 2344c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2345cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2346c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2347c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2348c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 23497b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2350cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2351cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2352cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2353cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2354cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2355cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2356cfd3d8dcSGreg Alexander } 2357c4cfe66cSDaniel Drake } 2358c4cfe66cSDaniel Drake 23590fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 23600fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 23610fb67e98SDaniel Drake { 23620fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 23630fb67e98SDaniel Drake } 23640fb67e98SDaniel Drake 23650fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 23660fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23670fb67e98SDaniel Drake { 23680fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2369c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2370c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23710fb67e98SDaniel Drake return 0; 23720fb67e98SDaniel Drake } 23730fb67e98SDaniel Drake 23740fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 23750fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23760fb67e98SDaniel Drake { 23770fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2378c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23790fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 23800fb67e98SDaniel Drake unsigned int idx; 23810fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 23820fb67e98SDaniel Drake if (idx >= imux->num_items) 23830fb67e98SDaniel Drake idx = imux->num_items - 1; 23840fb67e98SDaniel Drake 2385c4cfe66cSDaniel Drake spec->mic_boost = idx; 2386c4cfe66cSDaniel Drake if (!spec->dc_enable) 2387c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2388c4cfe66cSDaniel Drake return 1; 2389c4cfe66cSDaniel Drake } 23900fb67e98SDaniel Drake 2391c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2392c4cfe66cSDaniel Drake { 2393c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2394c4cfe66cSDaniel Drake /* disable gain */ 2395c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2396c4cfe66cSDaniel Drake 2397c4cfe66cSDaniel Drake /* switch to DC input */ 2398c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2399c4cfe66cSDaniel Drake {} 2400c4cfe66cSDaniel Drake }; 2401c4cfe66cSDaniel Drake 2402c4cfe66cSDaniel Drake /* configure as input source */ 2403c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2404c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2405c4cfe66cSDaniel Drake } 2406c4cfe66cSDaniel Drake 2407c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2408c4cfe66cSDaniel Drake { 2409c4cfe66cSDaniel Drake /* reconfigure input source */ 2410c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2411c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2412c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2413c4cfe66cSDaniel Drake } 2414c4cfe66cSDaniel Drake 2415c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2416c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2417c4cfe66cSDaniel Drake { 2418c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2419c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2420c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2421c4cfe66cSDaniel Drake return 0; 2422c4cfe66cSDaniel Drake } 2423c4cfe66cSDaniel Drake 2424c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2425c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2426c4cfe66cSDaniel Drake { 2427c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2428c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2429c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2430c4cfe66cSDaniel Drake 2431c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2432c4cfe66cSDaniel Drake return 0; 2433c4cfe66cSDaniel Drake 2434c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2435c4cfe66cSDaniel Drake if (dc_enable) 2436c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2437c4cfe66cSDaniel Drake else 2438c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2439c4cfe66cSDaniel Drake 2440c4cfe66cSDaniel Drake return 1; 2441c4cfe66cSDaniel Drake } 2442c4cfe66cSDaniel Drake 2443c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2444c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2445c4cfe66cSDaniel Drake { 2446c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2447c4cfe66cSDaniel Drake } 2448c4cfe66cSDaniel Drake 2449c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2450c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2451c4cfe66cSDaniel Drake { 2452c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2453c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2454c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2455c4cfe66cSDaniel Drake return 0; 2456c4cfe66cSDaniel Drake } 2457c4cfe66cSDaniel Drake 2458c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2459c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2460c4cfe66cSDaniel Drake { 2461c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2462c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2463c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2464c4cfe66cSDaniel Drake unsigned int idx; 2465c4cfe66cSDaniel Drake 2466c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2467c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2468c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2469c4cfe66cSDaniel Drake 2470c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2471c4cfe66cSDaniel Drake if (spec->dc_enable) 2472c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 24730fb67e98SDaniel Drake return 1; 24740fb67e98SDaniel Drake } 24750fb67e98SDaniel Drake 247675f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 247775f8991dSDaniel Drake { 247875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 247975f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 248075f8991dSDaniel Drake * recording LED comes on. */ 248175f8991dSDaniel Drake spec->recording = 1; 248275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 248375f8991dSDaniel Drake } 248475f8991dSDaniel Drake 248575f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 248675f8991dSDaniel Drake { 248775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 248875f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 248975f8991dSDaniel Drake /* disable external mic, port B */ 249075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 249175f8991dSDaniel Drake 249275f8991dSDaniel Drake /* disble internal mic, port C */ 249375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2494c4cfe66cSDaniel Drake 2495c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2496c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 249775f8991dSDaniel Drake {}, 249875f8991dSDaniel Drake }; 249975f8991dSDaniel Drake 250075f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 250175f8991dSDaniel Drake spec->recording = 0; 250275f8991dSDaniel Drake } 250375f8991dSDaniel Drake 2504f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 250534cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2506f6a2491cSAndy Robinson int num_pins) 2507f6a2491cSAndy Robinson { 2508f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2509f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2510f6a2491cSAndy Robinson int i; 2511f6a2491cSAndy Robinson 2512f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2513f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2514f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2515f6a2491cSAndy Robinson continue; 2516f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2517f6a2491cSAndy Robinson continue; 2518f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2519f6a2491cSAndy Robinson nid_loc++; 2520f6a2491cSAndy Robinson else 2521f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2522f6a2491cSAndy Robinson } 2523f6a2491cSAndy Robinson } 2524f6a2491cSAndy Robinson 252534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25260fb67e98SDaniel Drake .num_items = 4, 25270fb67e98SDaniel Drake .items = { 25280fb67e98SDaniel Drake { "Mic B", 0 }, 25290fb67e98SDaniel Drake { "Mic C", 1 }, 25300fb67e98SDaniel Drake { "Mic E", 2 }, 25310fb67e98SDaniel Drake { "Mic F", 3 }, 25320fb67e98SDaniel Drake }, 25330fb67e98SDaniel Drake }; 25340fb67e98SDaniel Drake 253534cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 25360fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 25370fb67e98SDaniel Drake .values = { 25380fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25390fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25400fb67e98SDaniel Drake 0 25410fb67e98SDaniel Drake }, 25420fb67e98SDaniel Drake }; 25430fb67e98SDaniel Drake 254434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 25450fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 25460fb67e98SDaniel Drake .values = { 25470fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25480fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25490fb67e98SDaniel Drake 0 25500fb67e98SDaniel Drake }, 25510fb67e98SDaniel Drake }; 25520fb67e98SDaniel Drake 255334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 25540fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 25550fb67e98SDaniel Drake {} 25560fb67e98SDaniel Drake }; 25570fb67e98SDaniel Drake 255834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 25590fb67e98SDaniel Drake { 25600fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25610fb67e98SDaniel Drake .name = "Master Playback Volume", 25620fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 25630fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 25640fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 25655e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 25660fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 25670fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 25680fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 25690fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 25700fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 25710fb67e98SDaniel Drake .private_value = 25720fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 25730fb67e98SDaniel Drake }, 25740fb67e98SDaniel Drake {} 25750fb67e98SDaniel Drake }; 25760fb67e98SDaniel Drake 257734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2578c4cfe66cSDaniel Drake { 2579c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2580c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2581c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2582c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2583c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2584c4cfe66cSDaniel Drake }, 2585c4cfe66cSDaniel Drake { 2586c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2587c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2588c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2589c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2590c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2591c4cfe66cSDaniel Drake }, 2592c4cfe66cSDaniel Drake {} 2593c4cfe66cSDaniel Drake }; 2594c4cfe66cSDaniel Drake 259534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 25960fb67e98SDaniel Drake { 25970fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25980fb67e98SDaniel Drake .name = "Master Playback Switch", 25990fb67e98SDaniel Drake .info = cxt_eapd_info, 26000fb67e98SDaniel Drake .get = cxt_eapd_get, 26010fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26020fb67e98SDaniel Drake .private_value = 0x1d, 26030fb67e98SDaniel Drake }, 26040fb67e98SDaniel Drake 26050fb67e98SDaniel Drake { 26060fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2607c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26080fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26090fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26100fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26110fb67e98SDaniel Drake }, 26120fb67e98SDaniel Drake 26130fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26140fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26150fb67e98SDaniel Drake {} 26160fb67e98SDaniel Drake }; 26170fb67e98SDaniel Drake 261834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2619254bba6aSEinar Rünkaru { 2620254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 262128c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2622254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2623254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2624254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2625254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2626254bba6aSEinar Rünkaru }, 2627254bba6aSEinar Rünkaru {} 2628254bba6aSEinar Rünkaru }; 2629254bba6aSEinar Rünkaru 263034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 26310fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 26320fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 26330fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 26340fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 26350fb67e98SDaniel Drake 26360fb67e98SDaniel Drake /* Speakers */ 26370fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26380fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26390fb67e98SDaniel Drake 26400fb67e98SDaniel Drake /* HP, Amp */ 26410fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26420fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26430fb67e98SDaniel Drake 26440fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26450fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26460fb67e98SDaniel Drake 26470fb67e98SDaniel Drake /* DAC1 */ 26480fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26490fb67e98SDaniel Drake 26500fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 26510fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26520fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26530fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 26540fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26550fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 26560fb67e98SDaniel Drake 26570fb67e98SDaniel Drake /* no digital microphone support yet */ 26580fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26590fb67e98SDaniel Drake 26600fb67e98SDaniel Drake /* Audio input selector */ 26610fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26620fb67e98SDaniel Drake 26630fb67e98SDaniel Drake /* SPDIF route: PCM */ 26640fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 26650fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 26660fb67e98SDaniel Drake 26670fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26680fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26690fb67e98SDaniel Drake 26700fb67e98SDaniel Drake /* EAPD */ 26710fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26720fb67e98SDaniel Drake 26730fb67e98SDaniel Drake /* not handling these yet */ 26740fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26750fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26760fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26770fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26780fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26790fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26800fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26810fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26820fb67e98SDaniel Drake { } /* end */ 26830fb67e98SDaniel Drake }; 26840fb67e98SDaniel Drake 268534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 26860fb67e98SDaniel Drake /* Port A: headphones */ 26870fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26880fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26890fb67e98SDaniel Drake 26900fb67e98SDaniel Drake /* Port B: external microphone */ 269175f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26920fb67e98SDaniel Drake 26930fb67e98SDaniel Drake /* Port C: internal microphone */ 269475f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26950fb67e98SDaniel Drake 26960fb67e98SDaniel Drake /* Port D: unused */ 26970fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26980fb67e98SDaniel Drake 26990fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27000fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27010fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27020fb67e98SDaniel Drake 2703c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27040fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27050fb67e98SDaniel Drake 27060fb67e98SDaniel Drake /* Port G: internal speakers */ 27070fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27080fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27090fb67e98SDaniel Drake 27100fb67e98SDaniel Drake /* DAC1 */ 27110fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27120fb67e98SDaniel Drake 27130fb67e98SDaniel Drake /* DAC2: unused */ 27140fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27150fb67e98SDaniel Drake 27160fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27170fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27180fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27190fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27200fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27210fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27220fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27230fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27240fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27250fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27260fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27270fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27280fb67e98SDaniel Drake 27290fb67e98SDaniel Drake /* Disable digital microphone port */ 27300fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27310fb67e98SDaniel Drake 27320fb67e98SDaniel Drake /* Audio input selectors */ 27330fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27340fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 27350fb67e98SDaniel Drake 27360fb67e98SDaniel Drake /* Disable SPDIF */ 27370fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27380fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27390fb67e98SDaniel Drake 27400fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 27410fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 27420fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 27430fb67e98SDaniel Drake { } /* end */ 27440fb67e98SDaniel Drake }; 27450fb67e98SDaniel Drake 274634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 274795a618bdSEinar Rünkaru /* Port A: headphones */ 274895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 274995a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 275095a618bdSEinar Rünkaru 275195a618bdSEinar Rünkaru /* Port B: external microphone */ 275295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 275395a618bdSEinar Rünkaru 275495a618bdSEinar Rünkaru /* Port C: unused */ 275595a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 275695a618bdSEinar Rünkaru 275795a618bdSEinar Rünkaru /* Port D: unused */ 275895a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 275995a618bdSEinar Rünkaru 276095a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 276195a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 276295a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 276395a618bdSEinar Rünkaru 276495a618bdSEinar Rünkaru /* Port F: unused */ 276595a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 276695a618bdSEinar Rünkaru 276795a618bdSEinar Rünkaru /* Port G: internal speakers */ 276895a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 276995a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 277095a618bdSEinar Rünkaru 277195a618bdSEinar Rünkaru /* DAC1 */ 277295a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 277395a618bdSEinar Rünkaru 277495a618bdSEinar Rünkaru /* DAC2: unused */ 277595a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 277695a618bdSEinar Rünkaru 277795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 277895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 277995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 278095a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 278195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 278295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 278395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 278495a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 278595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 278695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 278795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 278895a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 278995a618bdSEinar Rünkaru 279095a618bdSEinar Rünkaru /* Digital microphone port */ 279195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 279295a618bdSEinar Rünkaru 279395a618bdSEinar Rünkaru /* Audio input selectors */ 279495a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 279595a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 279695a618bdSEinar Rünkaru 279795a618bdSEinar Rünkaru /* Disable SPDIF */ 279895a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 279995a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 280095a618bdSEinar Rünkaru 280195a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 280295a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 280395a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 280495a618bdSEinar Rünkaru { } /* end */ 280595a618bdSEinar Rünkaru }; 280695a618bdSEinar Rünkaru 280734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2808cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2809cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2810cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2811cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2812cfd3d8dcSGreg Alexander 2813cfd3d8dcSGreg Alexander /* Speakers */ 2814cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2815cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2816cfd3d8dcSGreg Alexander 2817cfd3d8dcSGreg Alexander /* HP, Amp */ 2818cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2819cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2820cfd3d8dcSGreg Alexander 2821cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2822cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2823cfd3d8dcSGreg Alexander 2824cfd3d8dcSGreg Alexander /* DAC1 */ 2825cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2826cfd3d8dcSGreg Alexander 2827cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2828cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2829cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2830cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2831cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2832cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2833cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2834cfd3d8dcSGreg Alexander 2835cfd3d8dcSGreg Alexander /* Audio input selector */ 2836cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2837cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2838cfd3d8dcSGreg Alexander 2839cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2840cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2841cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2842cfd3d8dcSGreg Alexander 2843cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2844cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2845cfd3d8dcSGreg Alexander 2846cfd3d8dcSGreg Alexander /* internal microphone */ 284728c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2848cfd3d8dcSGreg Alexander 2849cfd3d8dcSGreg Alexander /* EAPD */ 2850cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2851cfd3d8dcSGreg Alexander 2852cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2853cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2854cfd3d8dcSGreg Alexander { } /* end */ 2855cfd3d8dcSGreg Alexander }; 2856cfd3d8dcSGreg Alexander 285734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 28587b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 28597b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 28607b2bfdbcSJens Taprogge 28617b2bfdbcSJens Taprogge /* Port G: internal speakers */ 28627b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28637b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28647b2bfdbcSJens Taprogge 28657b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 28667b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28677b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28687b2bfdbcSJens Taprogge 28697b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 28707b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28717b2bfdbcSJens Taprogge 28727b2bfdbcSJens Taprogge /* Port C: Mic */ 28737b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28747b2bfdbcSJens Taprogge 28757b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 28767b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28777b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28787b2bfdbcSJens Taprogge 28797b2bfdbcSJens Taprogge /* DAC1 */ 28807b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28817b2bfdbcSJens Taprogge 28827b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 28837b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28847b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28857b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 28867b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28877b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 28887b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 28897b2bfdbcSJens Taprogge 28907b2bfdbcSJens Taprogge /* Audio input selector */ 28917b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 28927b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 28937b2bfdbcSJens Taprogge 28947b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 28957b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 28967b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 28977b2bfdbcSJens Taprogge 28987b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28997b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29007b2bfdbcSJens Taprogge 29017b2bfdbcSJens Taprogge /* internal microphone */ 290228c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29037b2bfdbcSJens Taprogge 29047b2bfdbcSJens Taprogge /* EAPD */ 29057b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29067b2bfdbcSJens Taprogge 29077b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29087b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29097b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29107b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29117b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29127b2bfdbcSJens Taprogge { } /* end */ 29137b2bfdbcSJens Taprogge }; 29147b2bfdbcSJens Taprogge 291534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29160fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29170fb67e98SDaniel Drake { } /* end */ 29180fb67e98SDaniel Drake }; 29190fb67e98SDaniel Drake 2920048e78a5SDavid Henningsson 292134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2922048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2923048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2924048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2925048e78a5SDavid Henningsson { } /* end */ 2926048e78a5SDavid Henningsson }; 2927048e78a5SDavid Henningsson 29280fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29290fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29300fb67e98SDaniel Drake { 29310fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 29320fb67e98SDaniel Drake conexant_init(codec); 29330fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 29340fb67e98SDaniel Drake cxt5066_hp_automute(codec); 293502b6b5b6SDavid Henningsson cxt5066_automic(codec); 29360fb67e98SDaniel Drake } 2937c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 29380fb67e98SDaniel Drake return 0; 29390fb67e98SDaniel Drake } 29400fb67e98SDaniel Drake 294175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 294275f8991dSDaniel Drake { 2943c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 294475f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 294575f8991dSDaniel Drake conexant_init(codec); 294675f8991dSDaniel Drake cxt5066_hp_automute(codec); 2947c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2948c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 294975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2950c4cfe66cSDaniel Drake } else { 2951c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2952c4cfe66cSDaniel Drake } 295375f8991dSDaniel Drake return 0; 295475f8991dSDaniel Drake } 295575f8991dSDaniel Drake 29560fb67e98SDaniel Drake enum { 29570fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 29580fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 29590fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 29601feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2961cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 29627b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2963a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2964048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 2965fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 29660fb67e98SDaniel Drake CXT5066_MODELS 29670fb67e98SDaniel Drake }; 29680fb67e98SDaniel Drake 2969ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 29700fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 29710fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 29720fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 29731feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 2974cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 29757b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 2976a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 2977048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 2978fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 29790fb67e98SDaniel Drake }; 29800fb67e98SDaniel Drake 298134cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 29829966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 298300cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 29841feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 29858a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 2986ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 29871feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 2988231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 2989ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 2990ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 2991048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 2992f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 2993a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 2994f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 29952ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 2996c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 29975637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 29985637edb2SDavid Henningsson CXT5066_LAPTOP), 29995637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30004d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3001ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 300219593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 300329c5fbbcSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), 3004ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 300584012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3006b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3007d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3008a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3009af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 30107ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 30110fb67e98SDaniel Drake {} 30120fb67e98SDaniel Drake }; 30130fb67e98SDaniel Drake 30140fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30150fb67e98SDaniel Drake { 30160fb67e98SDaniel Drake struct conexant_spec *spec; 30170fb67e98SDaniel Drake int board_config; 30180fb67e98SDaniel Drake 3019fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3020fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3021fea4a4f9STakashi Iwai if (board_config < 0) 3022c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3023fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3024fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3025fea4a4f9STakashi Iwai 30260fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30270fb67e98SDaniel Drake if (!spec) 30280fb67e98SDaniel Drake return -ENOMEM; 30290fb67e98SDaniel Drake codec->spec = spec; 30300fb67e98SDaniel Drake 30310fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 303275f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 30330fb67e98SDaniel Drake 30340fb67e98SDaniel Drake spec->dell_automute = 0; 30350fb67e98SDaniel Drake spec->multiout.max_channels = 2; 30360fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 30370fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3038f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3039f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 30400fb67e98SDaniel Drake spec->num_adc_nids = 1; 30410fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 30420fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 30430fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 30440fb67e98SDaniel Drake 30450fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 30460fb67e98SDaniel Drake 30470fb67e98SDaniel Drake spec->num_init_verbs = 1; 30480fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 30490fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 30500fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 30510fb67e98SDaniel Drake spec->cur_adc = 0; 30520fb67e98SDaniel Drake spec->cur_adc_idx = 0; 30530fb67e98SDaniel Drake 30543507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 30553507e2a8STakashi Iwai 30560fb67e98SDaniel Drake switch (board_config) { 30570fb67e98SDaniel Drake default: 30580fb67e98SDaniel Drake case CXT5066_LAPTOP: 30590fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30600fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30610fb67e98SDaniel Drake break; 30620fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 30630fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30640fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30650fb67e98SDaniel Drake 30660fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 30670fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 30680fb67e98SDaniel Drake spec->num_init_verbs++; 30690fb67e98SDaniel Drake spec->dell_automute = 1; 30700fb67e98SDaniel Drake break; 3071a1d6906eSDavid Henningsson case CXT5066_ASUS: 3072048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3073048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 307402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3075048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3076048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3077048e78a5SDavid Henningsson spec->num_init_verbs++; 3078a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3079a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3080048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3081048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3082048e78a5SDavid Henningsson /* no S/PDIF out */ 3083f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3084048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3085048e78a5SDavid Henningsson /* input source automatically selected */ 3086048e78a5SDavid Henningsson spec->input_mux = NULL; 3087048e78a5SDavid Henningsson spec->port_d_mode = 0; 3088048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3089048e78a5SDavid Henningsson break; 3090048e78a5SDavid Henningsson 30910fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 309275f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 309375f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 30940fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 30950fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3096c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 30970fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30980fb67e98SDaniel Drake spec->port_d_mode = 0; 3099c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31000fb67e98SDaniel Drake 31010fb67e98SDaniel Drake /* no S/PDIF out */ 31020fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31030fb67e98SDaniel Drake 31040fb67e98SDaniel Drake /* input source automatically selected */ 31050fb67e98SDaniel Drake spec->input_mux = NULL; 310675f8991dSDaniel Drake 310775f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 310875f8991dSDaniel Drake * at the right time */ 310975f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 311075f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31110fb67e98SDaniel Drake break; 31121feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 311375f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 311402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 311595a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 311695a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 311795a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3118254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 311995a618bdSEinar Rünkaru spec->port_d_mode = 0; 3120254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3121c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 312295a618bdSEinar Rünkaru 312395a618bdSEinar Rünkaru /* no S/PDIF out */ 312495a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 312595a618bdSEinar Rünkaru 312695a618bdSEinar Rünkaru /* input source automatically selected */ 312795a618bdSEinar Rünkaru spec->input_mux = NULL; 312895a618bdSEinar Rünkaru break; 3129cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3130cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 313102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3132cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3133cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3134cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3135cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3136cfd3d8dcSGreg Alexander spec->ideapad = 1; 3137cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3138cfd3d8dcSGreg Alexander 3139cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3140cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3141cfd3d8dcSGreg Alexander 3142cfd3d8dcSGreg Alexander /* input source automatically selected */ 3143cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3144cfd3d8dcSGreg Alexander break; 31457b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 31467b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 314702b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 31487b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31497b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31507b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 31517b2bfdbcSJens Taprogge spec->thinkpad = 1; 31527b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 31537b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 31547b2bfdbcSJens Taprogge 31557b2bfdbcSJens Taprogge /* no S/PDIF out */ 31567b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 31577b2bfdbcSJens Taprogge 31587b2bfdbcSJens Taprogge /* input source automatically selected */ 31597b2bfdbcSJens Taprogge spec->input_mux = NULL; 31607b2bfdbcSJens Taprogge break; 31610fb67e98SDaniel Drake } 31620fb67e98SDaniel Drake 31633507e2a8STakashi Iwai if (spec->beep_amp) 31643507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 31653507e2a8STakashi Iwai 31660fb67e98SDaniel Drake return 0; 31670fb67e98SDaniel Drake } 3168461e2c78STakashi Iwai 3169461e2c78STakashi Iwai /* 3170f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3171f2e5731dSTakashi Iwai */ 3172f2e5731dSTakashi Iwai 31736764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 31746764bcefSTakashi Iwai struct hda_codec *codec, 31756764bcefSTakashi Iwai unsigned int stream_tag, 31766764bcefSTakashi Iwai unsigned int format, 31776764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31786764bcefSTakashi Iwai { 31796764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 318047ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 31816764bcefSTakashi Iwai if (spec->adc_switching) { 31826764bcefSTakashi Iwai spec->cur_adc = adc; 31836764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 31846764bcefSTakashi Iwai spec->cur_adc_format = format; 31856764bcefSTakashi Iwai } 31866764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 31876764bcefSTakashi Iwai return 0; 31886764bcefSTakashi Iwai } 31896764bcefSTakashi Iwai 31906764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 31916764bcefSTakashi Iwai struct hda_codec *codec, 31926764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31936764bcefSTakashi Iwai { 31946764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 31956764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 31966764bcefSTakashi Iwai spec->cur_adc = 0; 31976764bcefSTakashi Iwai return 0; 31986764bcefSTakashi Iwai } 31996764bcefSTakashi Iwai 32006764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32016764bcefSTakashi Iwai .substreams = 1, 32026764bcefSTakashi Iwai .channels_min = 2, 32036764bcefSTakashi Iwai .channels_max = 2, 32046764bcefSTakashi Iwai .nid = 0, /* fill later */ 32056764bcefSTakashi Iwai .ops = { 32066764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32076764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32086764bcefSTakashi Iwai }, 32096764bcefSTakashi Iwai }; 32106764bcefSTakashi Iwai 321134cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3212f2e5731dSTakashi Iwai 32138d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 32148d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3215f2e5731dSTakashi Iwai 3216f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3217f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3218f2e5731dSTakashi Iwai * not found 3219f2e5731dSTakashi Iwai */ 3220f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3221f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3222f2e5731dSTakashi Iwai { 3223f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3224f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3225f2e5731dSTakashi Iwai 3226f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3227f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3228f2e5731dSTakashi Iwai ret = dacs[i]; 3229f2e5731dSTakashi Iwai break; 3230f2e5731dSTakashi Iwai } 3231f2e5731dSTakashi Iwai } 3232f2e5731dSTakashi Iwai if (!ret) 3233f2e5731dSTakashi Iwai return 0; 3234f2e5731dSTakashi Iwai if (--nums > 0) 3235f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3236f2e5731dSTakashi Iwai *num_dacs = nums; 3237f2e5731dSTakashi Iwai return ret; 3238f2e5731dSTakashi Iwai } 3239f2e5731dSTakashi Iwai 3240f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3241f2e5731dSTakashi Iwai 32421f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 32431f015f5fSTakashi Iwai 3244f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3245f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3246f2e5731dSTakashi Iwai { 3247f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3248f2e5731dSTakashi Iwai int nums = 0; 3249f2e5731dSTakashi Iwai 3250f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3251f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3252f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3253f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3254f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3255f2e5731dSTakashi Iwai dacs[nums++] = nid; 3256f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3257f2e5731dSTakashi Iwai break; 3258f2e5731dSTakashi Iwai } 3259f2e5731dSTakashi Iwai } 3260f2e5731dSTakashi Iwai return nums; 3261f2e5731dSTakashi Iwai } 3262f2e5731dSTakashi Iwai 3263f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3264f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3265f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3266468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3267468c5458SDavid Henningsson int type) 3268f2e5731dSTakashi Iwai { 3269468c5458SDavid Henningsson int i, start = nums; 3270f2e5731dSTakashi Iwai 3271468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3272f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3273f2e5731dSTakashi Iwai filled[nums].type = type; 3274f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3275468c5458SDavid Henningsson if (filled[nums].dac) 3276468c5458SDavid Henningsson continue; 3277468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3278468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3279468c5458SDavid Henningsson continue; 3280468c5458SDavid Henningsson } 3281468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 32821f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3283468c5458SDavid Henningsson continue; 3284468c5458SDavid Henningsson } 3285468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3286f2e5731dSTakashi Iwai } 3287f2e5731dSTakashi Iwai return nums; 3288f2e5731dSTakashi Iwai } 3289f2e5731dSTakashi Iwai 3290f2e5731dSTakashi Iwai /* parse analog output paths */ 3291f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3292f2e5731dSTakashi Iwai { 3293f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3294f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3295f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3296f2e5731dSTakashi Iwai int i, j, nums, rest; 3297f2e5731dSTakashi Iwai 3298f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3299f2e5731dSTakashi Iwai /* parse all analog output pins */ 3300f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3301468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3302f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3303468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3304468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3305f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3306468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3307468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3308f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3309f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3310f2e5731dSTakashi Iwai /* fill multiout struct */ 3311f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3312f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 33131f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3314f2e5731dSTakashi Iwai continue; 3315f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3316f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3317f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3318f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3319f2e5731dSTakashi Iwai break; 3320f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3321f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3322f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3323f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3324f2e5731dSTakashi Iwai break; 3325f2e5731dSTakashi Iwai } 3326f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3327f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3328f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3329f2e5731dSTakashi Iwai break; 3330f2e5731dSTakashi Iwai } 3331f2e5731dSTakashi Iwai break; 3332f2e5731dSTakashi Iwai } 3333f2e5731dSTakashi Iwai } 3334f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 333589724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3336f2e5731dSTakashi Iwai 333703697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 333803697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3339f2e5731dSTakashi Iwai spec->auto_mute = 1; 334003697e2aSTakashi Iwai break; 334103697e2aSTakashi Iwai } 334203697e2aSTakashi Iwai } 3343e2df82ffSTakashi Iwai if (spec->auto_mute && 3344e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3345e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 334603697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 334703697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 334803697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 334903697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 335003697e2aSTakashi Iwai spec->detect_line = 1; 335103697e2aSTakashi Iwai break; 335203697e2aSTakashi Iwai } 335303697e2aSTakashi Iwai } 335403697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 335503697e2aSTakashi Iwai } 335603697e2aSTakashi Iwai 3357f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3358f2e5731dSTakashi Iwai } 3359f2e5731dSTakashi Iwai 3360da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3361da339866STakashi Iwai hda_nid_t *pins, bool on); 3362da339866STakashi Iwai 336303697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 336403697e2aSTakashi Iwai hda_nid_t *pins, bool on) 336503697e2aSTakashi Iwai { 3366254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 336703697e2aSTakashi Iwai int i; 336803697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 336903697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 337003697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 337103697e2aSTakashi Iwai on ? PIN_OUT : 0); 3372254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 337303697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 337403697e2aSTakashi Iwai } 337503697e2aSTakashi Iwai 337603697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 337703697e2aSTakashi Iwai { 337803697e2aSTakashi Iwai int i, present = 0; 337903697e2aSTakashi Iwai 338003697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 338103697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 338203697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 338303697e2aSTakashi Iwai break; 338403697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 338503697e2aSTakashi Iwai } 338603697e2aSTakashi Iwai return present; 338703697e2aSTakashi Iwai } 338803697e2aSTakashi Iwai 3389f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 339003697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 339103697e2aSTakashi Iwai { 339203697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 339303697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3394e2df82ffSTakashi Iwai int on = 1; 339503697e2aSTakashi Iwai 3396e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3397254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3398e2df82ffSTakashi Iwai if (spec->auto_mute) 3399e2df82ffSTakashi Iwai on = spec->hp_present; 340003697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3401254f2968STakashi Iwai } 3402254f2968STakashi Iwai 3403e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3404e2df82ffSTakashi Iwai if (spec->auto_mute) 3405e2df82ffSTakashi Iwai on = !(spec->hp_present || 3406e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3407e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 340803697e2aSTakashi Iwai 340903697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 341003697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 341103697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 341203697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 341303697e2aSTakashi Iwai return; 3414e2df82ffSTakashi Iwai if (spec->auto_mute) { 3415e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3416e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3417e2df82ffSTakashi Iwai spec->automute_lines) 3418e2df82ffSTakashi Iwai on = !spec->hp_present; 341903697e2aSTakashi Iwai else 3420e2df82ffSTakashi Iwai on = 1; 3421e2df82ffSTakashi Iwai } 3422e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 342303697e2aSTakashi Iwai } 342403697e2aSTakashi Iwai 3425f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3426f2e5731dSTakashi Iwai { 3427f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3428f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3429f2e5731dSTakashi Iwai 3430f2e5731dSTakashi Iwai if (!spec->auto_mute) 3431f2e5731dSTakashi Iwai return; 343203697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 343303697e2aSTakashi Iwai cx_auto_update_speakers(codec); 343403697e2aSTakashi Iwai } 343503697e2aSTakashi Iwai 343603697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 343703697e2aSTakashi Iwai { 343803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 343903697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 344003697e2aSTakashi Iwai 344103697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 344203697e2aSTakashi Iwai return; 344303697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 344403697e2aSTakashi Iwai cfg->line_out_pins); 344503697e2aSTakashi Iwai cx_auto_update_speakers(codec); 344603697e2aSTakashi Iwai } 344703697e2aSTakashi Iwai 344803697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 344903697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 345003697e2aSTakashi Iwai { 345103697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 345203697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 345303697e2aSTakashi Iwai static const char * const texts2[] = { 345403697e2aSTakashi Iwai "Disabled", "Enabled" 345503697e2aSTakashi Iwai }; 345603697e2aSTakashi Iwai static const char * const texts3[] = { 3457e49a3434STakashi Iwai "Disabled", "Speaker Only", "Line Out+Speaker" 345803697e2aSTakashi Iwai }; 345903697e2aSTakashi Iwai const char * const *texts; 346003697e2aSTakashi Iwai 346103697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 346203697e2aSTakashi Iwai uinfo->count = 1; 346303697e2aSTakashi Iwai if (spec->automute_hp_lo) { 346403697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 346503697e2aSTakashi Iwai texts = texts3; 346603697e2aSTakashi Iwai } else { 346703697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 346803697e2aSTakashi Iwai texts = texts2; 346903697e2aSTakashi Iwai } 347003697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 347103697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 347203697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 347303697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 347403697e2aSTakashi Iwai return 0; 347503697e2aSTakashi Iwai } 347603697e2aSTakashi Iwai 347703697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 347803697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 347903697e2aSTakashi Iwai { 348003697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 348103697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 348203697e2aSTakashi Iwai unsigned int val; 348303697e2aSTakashi Iwai if (!spec->auto_mute) 348403697e2aSTakashi Iwai val = 0; 348503697e2aSTakashi Iwai else if (!spec->automute_lines) 348603697e2aSTakashi Iwai val = 1; 348703697e2aSTakashi Iwai else 348803697e2aSTakashi Iwai val = 2; 348903697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 349003697e2aSTakashi Iwai return 0; 349103697e2aSTakashi Iwai } 349203697e2aSTakashi Iwai 349303697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 349403697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 349503697e2aSTakashi Iwai { 349603697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 349703697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 349803697e2aSTakashi Iwai 349903697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 350003697e2aSTakashi Iwai case 0: 350103697e2aSTakashi Iwai if (!spec->auto_mute) 350203697e2aSTakashi Iwai return 0; 350303697e2aSTakashi Iwai spec->auto_mute = 0; 3504f2e5731dSTakashi Iwai break; 350503697e2aSTakashi Iwai case 1: 350603697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 350703697e2aSTakashi Iwai return 0; 350803697e2aSTakashi Iwai spec->auto_mute = 1; 350903697e2aSTakashi Iwai spec->automute_lines = 0; 351003697e2aSTakashi Iwai break; 351103697e2aSTakashi Iwai case 2: 351203697e2aSTakashi Iwai if (!spec->automute_hp_lo) 351303697e2aSTakashi Iwai return -EINVAL; 351403697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 351503697e2aSTakashi Iwai return 0; 351603697e2aSTakashi Iwai spec->auto_mute = 1; 351703697e2aSTakashi Iwai spec->automute_lines = 1; 351803697e2aSTakashi Iwai break; 351903697e2aSTakashi Iwai default: 352003697e2aSTakashi Iwai return -EINVAL; 3521f2e5731dSTakashi Iwai } 352203697e2aSTakashi Iwai cx_auto_update_speakers(codec); 352303697e2aSTakashi Iwai return 1; 3524f2e5731dSTakashi Iwai } 352503697e2aSTakashi Iwai 352603697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 352703697e2aSTakashi Iwai { 352803697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 352903697e2aSTakashi Iwai .name = "Auto-Mute Mode", 353003697e2aSTakashi Iwai .info = cx_automute_mode_info, 353103697e2aSTakashi Iwai .get = cx_automute_mode_get, 353203697e2aSTakashi Iwai .put = cx_automute_mode_put, 353303697e2aSTakashi Iwai }, 353403697e2aSTakashi Iwai { } 353503697e2aSTakashi Iwai }; 3536f2e5731dSTakashi Iwai 35376764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 35386764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 35396764bcefSTakashi Iwai { 35406764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35416764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35426764bcefSTakashi Iwai 35436764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 35446764bcefSTakashi Iwai } 35456764bcefSTakashi Iwai 35466764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 35476764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35486764bcefSTakashi Iwai { 35496764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35506764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35516764bcefSTakashi Iwai 35526764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 35536764bcefSTakashi Iwai return 0; 35546764bcefSTakashi Iwai } 35556764bcefSTakashi Iwai 35565c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 35575c9887e0STakashi Iwai * if do_select is set, actually select the route. 35585c9887e0STakashi Iwai */ 35595c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3560cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3561cf27f29aSTakashi Iwai bool do_select, int depth) 35625c9887e0STakashi Iwai { 35635c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 35645c9887e0STakashi Iwai int i, nums; 35655c9887e0STakashi Iwai 3566cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3567cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3568cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3569cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3570cf27f29aSTakashi Iwai break; 3571cf27f29aSTakashi Iwai default: 3572cf27f29aSTakashi Iwai return -1; 3573cf27f29aSTakashi Iwai } 3574cf27f29aSTakashi Iwai 35755c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 35765c9887e0STakashi Iwai for (i = 0; i < nums; i++) 35775c9887e0STakashi Iwai if (conn[i] == pin) { 35785c9887e0STakashi Iwai if (do_select) 35795c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35805c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3581cf27f29aSTakashi Iwai if (srcp) 3582cf27f29aSTakashi Iwai *srcp = mux; 35835c9887e0STakashi Iwai return i; 35845c9887e0STakashi Iwai } 35855c9887e0STakashi Iwai depth++; 35865c9887e0STakashi Iwai if (depth == 2) 35875c9887e0STakashi Iwai return -1; 35885c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3589cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 35905c9887e0STakashi Iwai do_select, depth); 35915c9887e0STakashi Iwai if (ret >= 0) { 35925c9887e0STakashi Iwai if (do_select) 35935c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35945c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3595cf27f29aSTakashi Iwai return i; 35965c9887e0STakashi Iwai } 35975c9887e0STakashi Iwai } 35985c9887e0STakashi Iwai return -1; 35995c9887e0STakashi Iwai } 36005c9887e0STakashi Iwai 36015c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36025c9887e0STakashi Iwai hda_nid_t pin) 36035c9887e0STakashi Iwai { 3604cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36055c9887e0STakashi Iwai } 36065c9887e0STakashi Iwai 36075c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 36085c9887e0STakashi Iwai hda_nid_t pin) 36095c9887e0STakashi Iwai { 3610cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 36115c9887e0STakashi Iwai } 36125c9887e0STakashi Iwai 36136764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 36146764bcefSTakashi Iwai const struct hda_input_mux *imux, 36156764bcefSTakashi Iwai unsigned int idx) 36166764bcefSTakashi Iwai { 36176764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36186764bcefSTakashi Iwai hda_nid_t adc; 3619313d2c06STakashi Iwai int changed = 1; 36206764bcefSTakashi Iwai 36216764bcefSTakashi Iwai if (!imux->num_items) 36226764bcefSTakashi Iwai return 0; 36236764bcefSTakashi Iwai if (idx >= imux->num_items) 36246764bcefSTakashi Iwai idx = imux->num_items - 1; 36256764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3626313d2c06STakashi Iwai changed = 0; 362747ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 362847ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 362947ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 36306764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 36316764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 36326764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 36336764bcefSTakashi Iwai spec->cur_adc = adc; 36346764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 36356764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 36366764bcefSTakashi Iwai spec->cur_adc_format); 36376764bcefSTakashi Iwai } 36386764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3639313d2c06STakashi Iwai return changed; 36406764bcefSTakashi Iwai } 36416764bcefSTakashi Iwai 36426764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 36436764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36446764bcefSTakashi Iwai { 36456764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36466764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36476764bcefSTakashi Iwai 36486764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 36496764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 36506764bcefSTakashi Iwai } 36516764bcefSTakashi Iwai 36526764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 36536764bcefSTakashi Iwai { 36546764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 36556764bcefSTakashi Iwai .name = "Capture Source", 36566764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 36576764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 36586764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 36596764bcefSTakashi Iwai }, 36606764bcefSTakashi Iwai {} 36616764bcefSTakashi Iwai }; 36626764bcefSTakashi Iwai 366343c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 366443c1b2e9STakashi Iwai { 366543c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 366643c1b2e9STakashi Iwai if (idx < 0) 366743c1b2e9STakashi Iwai return false; 366843c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 366943c1b2e9STakashi Iwai return false; 367043c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 367143c1b2e9STakashi Iwai return true; 367243c1b2e9STakashi Iwai } 367343c1b2e9STakashi Iwai 3674f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3675f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3676f2e5731dSTakashi Iwai { 3677f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3678f2e5731dSTakashi Iwai 3679f2e5731dSTakashi Iwai if (!spec->auto_mic) 3680f2e5731dSTakashi Iwai return; 368143c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 368243c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 368343c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3684f2e5731dSTakashi Iwai } 3685f2e5731dSTakashi Iwai 3686f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3687f2e5731dSTakashi Iwai { 36883a93897eSTakashi Iwai switch (snd_hda_jack_get_action(codec, res >> 26)) { 3689f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3690f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 369103697e2aSTakashi Iwai break; 369203697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 369303697e2aSTakashi Iwai cx_auto_line_automute(codec); 3694f2e5731dSTakashi Iwai break; 3695f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3696f2e5731dSTakashi Iwai cx_auto_automic(codec); 3697f2e5731dSTakashi Iwai break; 3698f2e5731dSTakashi Iwai } 369901a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3700f2e5731dSTakashi Iwai } 3701f2e5731dSTakashi Iwai 3702f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 370343c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 370443c1b2e9STakashi Iwai * one dock-mic exist 3705f2e5731dSTakashi Iwai */ 3706f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3707f2e5731dSTakashi Iwai { 3708f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 370943c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 371043c1b2e9STakashi Iwai int i; 3711f2e5731dSTakashi Iwai 3712506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 371343c1b2e9STakashi Iwai pset[i] = -1; 371443c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 371543c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 371643c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3717b55fcb50STakashi Iwai int type, attr; 371843c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 371943c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3720b55fcb50STakashi Iwai return; /* invalid entry */ 372143c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 372243c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 372343c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 372443c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3725b55fcb50STakashi Iwai return; /* non-detectable pin */ 3726b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3727b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3728b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3729b55fcb50STakashi Iwai return; /* no valid input type */ 373043c1b2e9STakashi Iwai if (pset[attr] >= 0) 373143c1b2e9STakashi Iwai return; /* already occupied */ 373243c1b2e9STakashi Iwai pset[attr] = i; 3733f2e5731dSTakashi Iwai } 373443c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 373543c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 373643c1b2e9STakashi Iwai return; /* no input to switch*/ 3737f2e5731dSTakashi Iwai spec->auto_mic = 1; 373843c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 373943c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 374043c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3741f2e5731dSTakashi Iwai } 3742f2e5731dSTakashi Iwai 3743f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3744f2e5731dSTakashi Iwai { 3745f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3746f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3747f2e5731dSTakashi Iwai struct hda_input_mux *imux; 37486764bcefSTakashi Iwai int i, j; 3749f2e5731dSTakashi Iwai 3750f2e5731dSTakashi Iwai imux = &spec->private_imux; 3751f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 37526764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 37536764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 37545c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3755f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3756f2e5731dSTakashi Iwai if (idx >= 0) { 3757f2e5731dSTakashi Iwai const char *label; 3758f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 375947ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 376047ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 376147ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 376247ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3763f6100bb4STakashi Iwai cfg->inputs[i].pin; 3764f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 37656764bcefSTakashi Iwai break; 37666764bcefSTakashi Iwai } 3767f2e5731dSTakashi Iwai } 3768f2e5731dSTakashi Iwai } 376943c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3770f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 377176755359STakashi Iwai if (imux->num_items > 1) { 37726764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 377347ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 37746764bcefSTakashi Iwai spec->adc_switching = 1; 37756764bcefSTakashi Iwai break; 37766764bcefSTakashi Iwai } 37776764bcefSTakashi Iwai } 37786764bcefSTakashi Iwai } 3779f2e5731dSTakashi Iwai } 3780f2e5731dSTakashi Iwai 3781f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3782f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3783f2e5731dSTakashi Iwai { 3784f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3785f2e5731dSTakashi Iwai 3786f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3787f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3788f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3789f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3790f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3791f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3792f2e5731dSTakashi Iwai return nid; 3793f2e5731dSTakashi Iwai } 3794f2e5731dSTakashi Iwai } 3795f2e5731dSTakashi Iwai return 0; 3796f2e5731dSTakashi Iwai } 3797f2e5731dSTakashi Iwai 3798f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3799f2e5731dSTakashi Iwai { 3800f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3801f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3802f2e5731dSTakashi Iwai hda_nid_t nid; 3803f2e5731dSTakashi Iwai 3804f2e5731dSTakashi Iwai if (cfg->dig_outs && 3805f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3806f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3807f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3808f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3809f2e5731dSTakashi Iwai } 3810f2e5731dSTakashi Iwai 3811f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3812f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3813f2e5731dSTakashi Iwai { 3814f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3815f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3816f2e5731dSTakashi Iwai 3817f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3818f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3819f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3820f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3821f2e5731dSTakashi Iwai break; 3822f2e5731dSTakashi Iwai } 3823f2e5731dSTakashi Iwai } 3824f2e5731dSTakashi Iwai #else 3825f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3826f2e5731dSTakashi Iwai #endif 3827f2e5731dSTakashi Iwai 3828254f2968STakashi Iwai /* parse EAPDs */ 382919110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 383019110595STakashi Iwai { 383119110595STakashi Iwai struct conexant_spec *spec = codec->spec; 383219110595STakashi Iwai hda_nid_t nid, end_nid; 383319110595STakashi Iwai 383419110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 383519110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 383619110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 383719110595STakashi Iwai continue; 383819110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 383919110595STakashi Iwai continue; 384019110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 384119110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 384219110595STakashi Iwai break; 384319110595STakashi Iwai } 3844254f2968STakashi Iwai 3845254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3846254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3847254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3848254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3849254f2968STakashi Iwai * thus it might control over all pins. 3850254f2968STakashi Iwai */ 3851254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 385219110595STakashi Iwai } 385319110595STakashi Iwai 3854f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3855f2e5731dSTakashi Iwai { 3856f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3857f2e5731dSTakashi Iwai int err; 3858f2e5731dSTakashi Iwai 3859f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3860f2e5731dSTakashi Iwai if (err < 0) 3861f2e5731dSTakashi Iwai return err; 3862f2e5731dSTakashi Iwai 3863f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3864f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3865f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3866f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 386719110595STakashi Iwai cx_auto_parse_eapd(codec); 3868f2e5731dSTakashi Iwai return 0; 3869f2e5731dSTakashi Iwai } 3870f2e5731dSTakashi Iwai 3871da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3872da339866STakashi Iwai hda_nid_t *pins, bool on) 3873f2e5731dSTakashi Iwai { 3874f2e5731dSTakashi Iwai int i; 3875f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3876f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3877f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3878da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3879da339866STakashi Iwai on ? 0x02 : 0); 3880f2e5731dSTakashi Iwai } 3881f2e5731dSTakashi Iwai } 3882f2e5731dSTakashi Iwai 3883f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3884f2e5731dSTakashi Iwai hda_nid_t src) 3885f2e5731dSTakashi Iwai { 3886f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3887f2e5731dSTakashi Iwai if (idx >= 0) 3888f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3889f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3890f2e5731dSTakashi Iwai } 3891f2e5731dSTakashi Iwai 38921f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 38931f8458a2STakashi Iwai const hda_nid_t *nids) 3894f2e5731dSTakashi Iwai { 38950ad1b5b6STakashi Iwai int i, val; 3896f2e5731dSTakashi Iwai 38971f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 38981f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 38991f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 39001f8458a2STakashi Iwai continue; 39010ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 39020ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 39030ad1b5b6STakashi Iwai else 39040ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 39050ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 39060ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 39070ad1b5b6STakashi Iwai } 39081f8458a2STakashi Iwai } 3909f2e5731dSTakashi Iwai 391003697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 39113a93897eSTakashi Iwai hda_nid_t *pins, unsigned int action) 391203697e2aSTakashi Iwai { 391303697e2aSTakashi Iwai int i; 391403697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 39153a93897eSTakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], action); 391603697e2aSTakashi Iwai } 391703697e2aSTakashi Iwai 391807cafff2STakashi Iwai static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 391907cafff2STakashi Iwai { 392007cafff2STakashi Iwai int i; 392107cafff2STakashi Iwai for (i = 0; i < nums; i++) 392207cafff2STakashi Iwai if (list[i] == nid) 392307cafff2STakashi Iwai return true; 392407cafff2STakashi Iwai return false; 392507cafff2STakashi Iwai } 392607cafff2STakashi Iwai 392707cafff2STakashi Iwai /* is the given NID found in any of autocfg items? */ 392807cafff2STakashi Iwai static bool found_in_autocfg(struct auto_pin_cfg *cfg, hda_nid_t nid) 392907cafff2STakashi Iwai { 393007cafff2STakashi Iwai int i; 393107cafff2STakashi Iwai 393207cafff2STakashi Iwai if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) || 393307cafff2STakashi Iwai found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) || 393407cafff2STakashi Iwai found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs) || 393507cafff2STakashi Iwai found_in_nid_list(nid, cfg->dig_out_pins, cfg->dig_outs)) 393607cafff2STakashi Iwai return true; 393707cafff2STakashi Iwai for (i = 0; i < cfg->num_inputs; i++) 393807cafff2STakashi Iwai if (cfg->inputs[i].pin == nid) 393907cafff2STakashi Iwai return true; 394007cafff2STakashi Iwai if (cfg->dig_in_pin == nid) 394107cafff2STakashi Iwai return true; 394207cafff2STakashi Iwai return false; 394307cafff2STakashi Iwai } 394407cafff2STakashi Iwai 394507cafff2STakashi Iwai /* clear unsol-event tags on unused pins; Conexant codecs seem to leave 394607cafff2STakashi Iwai * invalid unsol tags by some reason 394707cafff2STakashi Iwai */ 394807cafff2STakashi Iwai static void clear_unsol_on_unused_pins(struct hda_codec *codec) 394907cafff2STakashi Iwai { 395007cafff2STakashi Iwai struct conexant_spec *spec = codec->spec; 395107cafff2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 395207cafff2STakashi Iwai int i; 395307cafff2STakashi Iwai 395407cafff2STakashi Iwai for (i = 0; i < codec->init_pins.used; i++) { 395507cafff2STakashi Iwai struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 395607cafff2STakashi Iwai if (!found_in_autocfg(cfg, pin->nid)) 395707cafff2STakashi Iwai snd_hda_codec_write(codec, pin->nid, 0, 395807cafff2STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 0); 395907cafff2STakashi Iwai } 396007cafff2STakashi Iwai } 396107cafff2STakashi Iwai 3962527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */ 3963527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled) 3964527c73baSTakashi Iwai { 3965527c73baSTakashi Iwai struct hda_codec *codec = private_data; 3966527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 3967527c73baSTakashi Iwai 3968527c73baSTakashi Iwai if (enabled && spec->pin_eapd_ctrls) { 3969527c73baSTakashi Iwai cx_auto_update_speakers(codec); 3970527c73baSTakashi Iwai return; 3971527c73baSTakashi Iwai } 3972527c73baSTakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 3973527c73baSTakashi Iwai } 3974527c73baSTakashi Iwai 39751f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39761f8458a2STakashi Iwai { 39771f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39781f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39791f8458a2STakashi Iwai hda_nid_t nid; 39801f8458a2STakashi Iwai int i; 39811f8458a2STakashi Iwai 39821f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3983f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3984f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3985f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 39861f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 39871f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 39881f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3989f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3990f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3991f2e5731dSTakashi Iwai if (!nid) 3992f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 39931f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 39941f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 3995f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3996f2e5731dSTakashi Iwai } 399703697e2aSTakashi Iwai if (spec->auto_mute) { 399803697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 399903697e2aSTakashi Iwai CONEXANT_HP_EVENT); 400003697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 400103697e2aSTakashi Iwai cfg->hp_pins); 400203697e2aSTakashi Iwai if (spec->detect_line) { 400303697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 400403697e2aSTakashi Iwai cfg->line_out_pins, 400503697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 400603697e2aSTakashi Iwai spec->line_present = 400703697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 400803697e2aSTakashi Iwai cfg->line_out_pins); 400903697e2aSTakashi Iwai } 401003697e2aSTakashi Iwai } 401103697e2aSTakashi Iwai cx_auto_update_speakers(codec); 4012254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 4013254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 401419110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 401507cafff2STakashi Iwai clear_unsol_on_unused_pins(codec); 4016f2e5731dSTakashi Iwai } 4017f2e5731dSTakashi Iwai 4018f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 4019f2e5731dSTakashi Iwai { 4020f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4021f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40220ad1b5b6STakashi Iwai int i, val; 4023f2e5731dSTakashi Iwai 40240ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 40250ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 40261f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 40271f8458a2STakashi Iwai continue; 40280ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 40290ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40300ad1b5b6STakashi Iwai else 40310ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40320ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40330ad1b5b6STakashi Iwai val); 40340ad1b5b6STakashi Iwai } 4035f2e5731dSTakashi Iwai 4036f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4037f2e5731dSTakashi Iwai unsigned int type; 4038f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4039f2e5731dSTakashi Iwai type = PIN_VREF80; 4040f2e5731dSTakashi Iwai else 4041f2e5731dSTakashi Iwai type = PIN_IN; 4042f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4043f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4044f2e5731dSTakashi Iwai } 4045f2e5731dSTakashi Iwai 4046f2e5731dSTakashi Iwai if (spec->auto_mic) { 404743c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40481835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40491835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40501835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 405143c1b2e9STakashi Iwai } 405243c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40531835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40541835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40551835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 405643c1b2e9STakashi Iwai } 4057f2e5731dSTakashi Iwai cx_auto_automic(codec); 4058f2e5731dSTakashi Iwai } else { 405947ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 406047ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4061f2e5731dSTakashi Iwai } 4062f2e5731dSTakashi Iwai } 4063f2e5731dSTakashi Iwai 4064f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4065f2e5731dSTakashi Iwai { 4066f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4067f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4068f2e5731dSTakashi Iwai 4069f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4070f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4071f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4072f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4073f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4074f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4075f2e5731dSTakashi Iwai } 4076f2e5731dSTakashi Iwai 4077f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4078f2e5731dSTakashi Iwai { 4079527c73baSTakashi Iwai struct conexant_spec *spec = codec->spec; 4080f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4081f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4082f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4083f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 408401a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4085d2f344b5STakashi Iwai snd_hda_sync_vmaster_hook(&spec->vmaster_mute); 4086f2e5731dSTakashi Iwai return 0; 4087f2e5731dSTakashi Iwai } 4088f2e5731dSTakashi Iwai 4089983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4090f2e5731dSTakashi Iwai const char *dir, int cidx, 4091983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 4092f2e5731dSTakashi Iwai { 4093f2e5731dSTakashi Iwai static char name[32]; 4094f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4095f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4096f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4097f2e5731dSTakashi Iwai }; 409834cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4099f2e5731dSTakashi Iwai int i, err; 4100f2e5731dSTakashi Iwai 4101f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4102f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4103983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4104983345e5SDavid Henningsson hda_dir); 4105f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4106f2e5731dSTakashi Iwai knew[i].index = cidx; 4107f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4108f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4109f2e5731dSTakashi Iwai if (!kctl) 4110f2e5731dSTakashi Iwai return -ENOMEM; 4111f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4112f2e5731dSTakashi Iwai if (err < 0) 4113f2e5731dSTakashi Iwai return err; 41143868137eSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & 41153868137eSTakashi Iwai (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))) 4116f2e5731dSTakashi Iwai break; 4117f2e5731dSTakashi Iwai } 4118f2e5731dSTakashi Iwai return 0; 4119f2e5731dSTakashi Iwai } 4120f2e5731dSTakashi Iwai 4121983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4122983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4123983345e5SDavid Henningsson 4124f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4125f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4126f2e5731dSTakashi Iwai 41271f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 41281f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 41291f8458a2STakashi Iwai { 41301f8458a2STakashi Iwai unsigned int caps; 4131468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 41321f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41331f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41341f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4135468c5458SDavid Henningsson } 41361f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41371f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41381f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41391f8458a2STakashi Iwai return 0; 41401f8458a2STakashi Iwai } 41411f8458a2STakashi Iwai 4142f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4143f2e5731dSTakashi Iwai { 4144f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4145f2e5731dSTakashi Iwai int i, err; 4146f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4147ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4148f2e5731dSTakashi Iwai 4149f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41501f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41511f8458a2STakashi Iwai spec->dac_info[0].pin, 4152f2e5731dSTakashi Iwai "Master", 0); 41531f8458a2STakashi Iwai 4154f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4155f2e5731dSTakashi Iwai const char *label; 4156f2e5731dSTakashi Iwai int idx, type; 41571f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4158f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4159f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4160f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4161f2e5731dSTakashi Iwai switch (type) { 4162f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4163f2e5731dSTakashi Iwai default: 4164f2e5731dSTakashi Iwai label = texts[num_line++]; 4165f2e5731dSTakashi Iwai idx = 0; 4166f2e5731dSTakashi Iwai break; 4167f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4168f2e5731dSTakashi Iwai label = "Headphone"; 4169f2e5731dSTakashi Iwai idx = num_hp++; 4170f2e5731dSTakashi Iwai break; 4171f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4172f2e5731dSTakashi Iwai label = "Speaker"; 4173f2e5731dSTakashi Iwai idx = num_spk++; 4174f2e5731dSTakashi Iwai break; 4175f2e5731dSTakashi Iwai } 41761f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41771f8458a2STakashi Iwai spec->dac_info[i].pin, 4178f2e5731dSTakashi Iwai label, idx); 4179f2e5731dSTakashi Iwai if (err < 0) 4180f2e5731dSTakashi Iwai return err; 4181f2e5731dSTakashi Iwai } 418203697e2aSTakashi Iwai 418303697e2aSTakashi Iwai if (spec->auto_mute) { 418403697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 418503697e2aSTakashi Iwai if (err < 0) 418603697e2aSTakashi Iwai return err; 418703697e2aSTakashi Iwai } 418803697e2aSTakashi Iwai 4189f2e5731dSTakashi Iwai return 0; 4190f2e5731dSTakashi Iwai } 4191f2e5731dSTakashi Iwai 41926764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 41936764bcefSTakashi Iwai const char *label, const char *pfx, 41946764bcefSTakashi Iwai int cidx) 41956764bcefSTakashi Iwai { 41966764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 41976764bcefSTakashi Iwai int i; 41986764bcefSTakashi Iwai 41996764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 42006764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 42015c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 42026764bcefSTakashi Iwai if (idx < 0) 42036764bcefSTakashi Iwai continue; 42044f32456eSMichael Karcher if (codec->single_adc_amp) 42056b452142STakashi Iwai idx = 0; 42066764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 42076764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 42086764bcefSTakashi Iwai } 42096764bcefSTakashi Iwai return 0; 42106764bcefSTakashi Iwai } 42116764bcefSTakashi Iwai 4212cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4213cf27f29aSTakashi Iwai const char *label, int cidx) 4214cf27f29aSTakashi Iwai { 4215cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4216cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4217f9759301STakashi Iwai int i, con; 4218cf27f29aSTakashi Iwai 421947ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4220cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4221cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4222cf27f29aSTakashi Iwai nid, HDA_INPUT); 422347ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 422447ad1f4eSTakashi Iwai &mux, false, 0); 4225cf27f29aSTakashi Iwai if (con < 0) 4226cf27f29aSTakashi Iwai return 0; 4227f9759301STakashi Iwai for (i = 0; i < idx; i++) { 422847ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4229f9759301STakashi Iwai return 0; /* already present */ 4230f9759301STakashi Iwai } 4231f9759301STakashi Iwai 4232f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 423347ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4234cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4235cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4236f9759301STakashi Iwai } 4237cf27f29aSTakashi Iwai return 0; 4238cf27f29aSTakashi Iwai } 4239cf27f29aSTakashi Iwai 4240f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4241f2e5731dSTakashi Iwai { 4242f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4243cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4244cf27f29aSTakashi Iwai const char *prev_label; 4245cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42466b452142STakashi Iwai int i, j, err, cidx; 4247cf27f29aSTakashi Iwai int multi_connection; 4248cf27f29aSTakashi Iwai 42496b452142STakashi Iwai if (!imux->num_items) 42506b452142STakashi Iwai return 0; 42516b452142STakashi Iwai 4252cf27f29aSTakashi Iwai multi_connection = 0; 4253cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 425447ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 425547ad1f4eSTakashi Iwai spec->imux_info[i].pin); 42566b452142STakashi Iwai if (cidx < 0) 42576b452142STakashi Iwai continue; 42586b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 42594f32456eSMichael Karcher if (!codec->single_adc_amp) 42606b452142STakashi Iwai input_conn[i] |= cidx << 8; 4261cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4262cf27f29aSTakashi Iwai multi_connection = 1; 4263cf27f29aSTakashi Iwai } 4264983345e5SDavid Henningsson 4265f2e5731dSTakashi Iwai prev_label = NULL; 4266f2e5731dSTakashi Iwai cidx = 0; 4267cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 426847ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4269f2e5731dSTakashi Iwai const char *label; 4270983345e5SDavid Henningsson 4271cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 427247ad1f4eSTakashi Iwai spec->imux_info[i].index); 4273f2e5731dSTakashi Iwai if (label == prev_label) 4274f2e5731dSTakashi Iwai cidx++; 4275f2e5731dSTakashi Iwai else 4276f2e5731dSTakashi Iwai cidx = 0; 4277f2e5731dSTakashi Iwai prev_label = label; 4278983345e5SDavid Henningsson 4279cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4280f2e5731dSTakashi Iwai if (err < 0) 4281f2e5731dSTakashi Iwai return err; 4282983345e5SDavid Henningsson 4283cf27f29aSTakashi Iwai if (!multi_connection) { 4284f9759301STakashi Iwai if (i > 0) 4285f9759301STakashi Iwai continue; 42866764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42876764bcefSTakashi Iwai "Capture", "", cidx); 42886764bcefSTakashi Iwai } else { 42896b452142STakashi Iwai bool dup_found = false; 42906b452142STakashi Iwai for (j = 0; j < i; j++) { 42916b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 42926b452142STakashi Iwai dup_found = true; 42936b452142STakashi Iwai break; 42946b452142STakashi Iwai } 42956b452142STakashi Iwai } 42966b452142STakashi Iwai if (dup_found) 42976b452142STakashi Iwai continue; 42986764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42996764bcefSTakashi Iwai label, " Capture", cidx); 43006764bcefSTakashi Iwai } 4301983345e5SDavid Henningsson if (err < 0) 4302983345e5SDavid Henningsson return err; 4303983345e5SDavid Henningsson } 43046764bcefSTakashi Iwai 43056764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 43066764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 43076764bcefSTakashi Iwai if (err < 0) 43086764bcefSTakashi Iwai return err; 4309983345e5SDavid Henningsson } 43106764bcefSTakashi Iwai 4311f2e5731dSTakashi Iwai return 0; 4312f2e5731dSTakashi Iwai } 4313f2e5731dSTakashi Iwai 4314f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4315f2e5731dSTakashi Iwai { 431631ef2257STakashi Iwai struct conexant_spec *spec = codec->spec; 4317f2e5731dSTakashi Iwai int err; 4318f2e5731dSTakashi Iwai 4319f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4320f2e5731dSTakashi Iwai if (err < 0) 4321f2e5731dSTakashi Iwai return err; 4322f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4323f2e5731dSTakashi Iwai if (err < 0) 4324f2e5731dSTakashi Iwai return err; 432531ef2257STakashi Iwai err = conexant_build_controls(codec); 432631ef2257STakashi Iwai if (err < 0) 432731ef2257STakashi Iwai return err; 432831ef2257STakashi Iwai err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 432931ef2257STakashi Iwai if (err < 0) 433031ef2257STakashi Iwai return err; 4331f29735cbSTakashi Iwai if (spec->vmaster_mute.sw_kctl) { 4332f29735cbSTakashi Iwai spec->vmaster_mute.hook = cx_auto_vmaster_hook; 4333f29735cbSTakashi Iwai err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4334f29735cbSTakashi Iwai spec->vmaster_mute_led); 4335d2f344b5STakashi Iwai if (err < 0) 4336d2f344b5STakashi Iwai return err; 4337527c73baSTakashi Iwai } 433831ef2257STakashi Iwai return 0; 4339f2e5731dSTakashi Iwai } 4340f2e5731dSTakashi Iwai 434122ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 434222ce5f74STakashi Iwai { 434322ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 434422ce5f74STakashi Iwai hda_nid_t nid, end_nid; 434522ce5f74STakashi Iwai 434622ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 434722ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 434822ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 434922ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 435022ce5f74STakashi Iwai continue; 435122ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 435222ce5f74STakashi Iwai continue; 435322ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 435422ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 435522ce5f74STakashi Iwai break; 435622ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 435722ce5f74STakashi Iwai } 435822ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 435922ce5f74STakashi Iwai return 0; 436022ce5f74STakashi Iwai } 436122ce5f74STakashi Iwai 436234cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4363f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4364f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4365f2e5731dSTakashi Iwai .init = cx_auto_init, 4366f2e5731dSTakashi Iwai .free = conexant_free, 4367f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4368f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4369f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4370f2e5731dSTakashi Iwai #endif 4371f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4372f2e5731dSTakashi Iwai }; 4373f2e5731dSTakashi Iwai 4374e92d4b08STakashi Iwai /* 4375e92d4b08STakashi Iwai * pin fix-up 4376e92d4b08STakashi Iwai */ 4377e92d4b08STakashi Iwai struct cxt_pincfg { 4378e92d4b08STakashi Iwai hda_nid_t nid; 4379e92d4b08STakashi Iwai u32 val; 4380e92d4b08STakashi Iwai }; 4381e92d4b08STakashi Iwai 4382e92d4b08STakashi Iwai static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4383e92d4b08STakashi Iwai { 4384e92d4b08STakashi Iwai for (; cfg->nid; cfg++) 4385e92d4b08STakashi Iwai snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4386e92d4b08STakashi Iwai 4387e92d4b08STakashi Iwai } 4388e92d4b08STakashi Iwai 4389e92d4b08STakashi Iwai static void apply_pin_fixup(struct hda_codec *codec, 4390e92d4b08STakashi Iwai const struct snd_pci_quirk *quirk, 4391e92d4b08STakashi Iwai const struct cxt_pincfg **table) 4392e92d4b08STakashi Iwai { 4393e92d4b08STakashi Iwai quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 4394e92d4b08STakashi Iwai if (quirk) { 4395e92d4b08STakashi Iwai snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4396e92d4b08STakashi Iwai quirk->name); 4397e92d4b08STakashi Iwai apply_pincfg(codec, table[quirk->value]); 4398e92d4b08STakashi Iwai } 4399e92d4b08STakashi Iwai } 4400e92d4b08STakashi Iwai 4401e92d4b08STakashi Iwai enum { 4402e92d4b08STakashi Iwai CXT_PINCFG_LENOVO_X200, 4403e92d4b08STakashi Iwai }; 4404e92d4b08STakashi Iwai 4405e92d4b08STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4406e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4407e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 4408e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 44093e93f5efSTakashi Iwai { 0x1c, 0x21440100 }, /* dock SPDIF out */ 4410e92d4b08STakashi Iwai {} 4411e92d4b08STakashi Iwai }; 4412e92d4b08STakashi Iwai 4413e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4414e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4415e92d4b08STakashi Iwai }; 4416e92d4b08STakashi Iwai 4417e92d4b08STakashi Iwai static const struct snd_pci_quirk cxt_fixups[] = { 4418e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4419e92d4b08STakashi Iwai {} 4420e92d4b08STakashi Iwai }; 4421e92d4b08STakashi Iwai 44223868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches 44233868137eSTakashi Iwai * can be created (bko#42825) 44243868137eSTakashi Iwai */ 44253868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec) 44263868137eSTakashi Iwai { 44273868137eSTakashi Iwai static hda_nid_t out_nids[] = { 44283868137eSTakashi Iwai 0x10, 0x11, 0 44293868137eSTakashi Iwai }; 44303868137eSTakashi Iwai hda_nid_t *p; 44313868137eSTakashi Iwai 44323868137eSTakashi Iwai for (p = out_nids; *p; p++) 44333868137eSTakashi Iwai snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT, 44343868137eSTakashi Iwai AC_AMPCAP_MIN_MUTE | 44353868137eSTakashi Iwai query_amp_caps(codec, *p, HDA_OUTPUT)); 44363868137eSTakashi Iwai } 44373868137eSTakashi Iwai 4438f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4439f2e5731dSTakashi Iwai { 4440f2e5731dSTakashi Iwai struct conexant_spec *spec; 4441f2e5731dSTakashi Iwai int err; 4442f2e5731dSTakashi Iwai 44431f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 44441f8458a2STakashi Iwai codec->chip_name); 44451f8458a2STakashi Iwai 4446f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4447f2e5731dSTakashi Iwai if (!spec) 4448f2e5731dSTakashi Iwai return -ENOMEM; 4449f2e5731dSTakashi Iwai codec->spec = spec; 44501387cde5STakashi Iwai codec->pin_amp_workaround = 1; 4451e92d4b08STakashi Iwai 44526b452142STakashi Iwai switch (codec->vendor_id) { 44536b452142STakashi Iwai case 0x14f15045: 44544f32456eSMichael Karcher codec->single_adc_amp = 1; 44556b452142STakashi Iwai break; 44563868137eSTakashi Iwai case 0x14f15051: 44573868137eSTakashi Iwai add_cx5051_fake_mutes(codec); 44583868137eSTakashi Iwai break; 44596b452142STakashi Iwai } 44606b452142STakashi Iwai 4461e92d4b08STakashi Iwai apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl); 4462e92d4b08STakashi Iwai 4463f29735cbSTakashi Iwai /* Show mute-led control only on HP laptops 4464f29735cbSTakashi Iwai * This is a sort of white-list: on HP laptops, EAPD corresponds 4465f29735cbSTakashi Iwai * only to the mute-LED without actualy amp function. Meanwhile, 4466f29735cbSTakashi Iwai * others may use EAPD really as an amp switch, so it might be 4467f29735cbSTakashi Iwai * not good to expose it blindly. 4468527c73baSTakashi Iwai */ 4469f29735cbSTakashi Iwai switch (codec->subsystem_id >> 16) { 4470f29735cbSTakashi Iwai case 0x103c: 4471f29735cbSTakashi Iwai spec->vmaster_mute_led = 1; 4472f29735cbSTakashi Iwai break; 4473f29735cbSTakashi Iwai } 4474527c73baSTakashi Iwai 447522ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 447622ce5f74STakashi Iwai if (err < 0) 447722ce5f74STakashi Iwai return err; 4478f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4479f2e5731dSTakashi Iwai if (err < 0) { 4480f2e5731dSTakashi Iwai kfree(codec->spec); 4481f2e5731dSTakashi Iwai codec->spec = NULL; 4482f2e5731dSTakashi Iwai return err; 4483f2e5731dSTakashi Iwai } 44846764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4485f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4486f2e5731dSTakashi Iwai if (spec->beep_amp) 4487f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 44884f2864a4STakashi Iwai 44894f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 44904f2864a4STakashi Iwai * which falls into the single-cmd mode. 44914f2864a4STakashi Iwai * Better to make reset, then. 44924f2864a4STakashi Iwai */ 44934f2864a4STakashi Iwai if (!codec->bus->sync_write) { 44944f2864a4STakashi Iwai snd_printd("hda_codec: " 44954f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 44964f2864a4STakashi Iwai codec->bus->sync_write = 1; 44974f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 44984f2864a4STakashi Iwai } 44994f2864a4STakashi Iwai 4500f2e5731dSTakashi Iwai return 0; 4501f2e5731dSTakashi Iwai } 4502f2e5731dSTakashi Iwai 4503f2e5731dSTakashi Iwai /* 4504461e2c78STakashi Iwai */ 4505461e2c78STakashi Iwai 450634cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 450782f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 450882f30040STobin Davis .patch = patch_cxt5045 }, 450982f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 451082f30040STobin Davis .patch = patch_cxt5047 }, 4511461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4512461e2c78STakashi Iwai .patch = patch_cxt5051 }, 45130fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 45140fb67e98SDaniel Drake .patch = patch_cxt5066 }, 451595a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 451695a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4517850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4518850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 45197b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 45207b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4521f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4522f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 45236da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 45246da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4525f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4526f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4527f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4528f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4529f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4530f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4531f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4532f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4533f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4534f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4535f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4536f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4537f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4538f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4539f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4540f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4541c9b443d4STobin Davis {} /* terminator */ 4542c9b443d4STobin Davis }; 45431289e9e8STakashi Iwai 45441289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 45451289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 45461289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 45470fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 454895a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4549850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 45507b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4551f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 45526da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4553f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4554f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4555f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4556f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4557f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4558f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4559f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4560f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 45611289e9e8STakashi Iwai 45621289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 45631289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 45641289e9e8STakashi Iwai 45651289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 45661289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 45671289e9e8STakashi Iwai .owner = THIS_MODULE, 45681289e9e8STakashi Iwai }; 45691289e9e8STakashi Iwai 45701289e9e8STakashi Iwai static int __init patch_conexant_init(void) 45711289e9e8STakashi Iwai { 45721289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 45731289e9e8STakashi Iwai } 45741289e9e8STakashi Iwai 45751289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 45761289e9e8STakashi Iwai { 45771289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 45781289e9e8STakashi Iwai } 45791289e9e8STakashi Iwai 45801289e9e8STakashi Iwai module_init(patch_conexant_init) 45811289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4582