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; 73c9b443d4STobin Davis 74c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 75c9b443d4STobin Davis * don't forget NULL 76c9b443d4STobin Davis * termination! 77c9b443d4STobin Davis */ 78c9b443d4STobin Davis unsigned int num_init_verbs; 79c9b443d4STobin Davis 80c9b443d4STobin Davis /* playback */ 81c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 82c9b443d4STobin Davis * max_channels, dacs must be set 83c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 84c9b443d4STobin Davis */ 85c9b443d4STobin Davis unsigned int cur_eapd; 8682f30040STobin Davis unsigned int hp_present; 8703697e2aSTakashi Iwai unsigned int line_present; 88faddaa5dSTakashi Iwai unsigned int auto_mic; 89f6100bb4STakashi Iwai int auto_mic_ext; /* imux_pins[] index for ext mic */ 9043c1b2e9STakashi Iwai int auto_mic_dock; /* imux_pins[] index for dock mic */ 9143c1b2e9STakashi Iwai int auto_mic_int; /* imux_pins[] index for int mic */ 92c9b443d4STobin Davis unsigned int need_dac_fix; 93f6a2491cSAndy Robinson hda_nid_t slave_dig_outs[2]; 94c9b443d4STobin Davis 95c9b443d4STobin Davis /* capture */ 96c9b443d4STobin Davis unsigned int num_adc_nids; 9734cbe3a6STakashi Iwai const hda_nid_t *adc_nids; 98c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 99c9b443d4STobin Davis 100461e2c78STakashi Iwai unsigned int cur_adc_idx; 101461e2c78STakashi Iwai hda_nid_t cur_adc; 102461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 103461e2c78STakashi Iwai unsigned int cur_adc_format; 104461e2c78STakashi Iwai 1056764bcefSTakashi Iwai const struct hda_pcm_stream *capture_stream; 1066764bcefSTakashi Iwai 107c9b443d4STobin Davis /* capture source */ 108c9b443d4STobin Davis const struct hda_input_mux *input_mux; 10934cbe3a6STakashi Iwai const hda_nid_t *capsrc_nids; 110c9b443d4STobin Davis unsigned int cur_mux[3]; 111c9b443d4STobin Davis 112c9b443d4STobin Davis /* channel model */ 113c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 114c9b443d4STobin Davis int num_channel_mode; 115c9b443d4STobin Davis 116c9b443d4STobin Davis /* PCM information */ 117c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 118c9b443d4STobin Davis 119c9b443d4STobin Davis unsigned int spdif_route; 120c9b443d4STobin Davis 121c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 122c9b443d4STobin Davis struct auto_pin_cfg autocfg; 123c9b443d4STobin Davis struct hda_input_mux private_imux; 12447ad1f4eSTakashi Iwai struct imux_info imux_info[HDA_MAX_NUM_INPUTS]; 12522ce5f74STakashi Iwai hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS]; 12641923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 127f2e5731dSTakashi Iwai struct pin_dac_pair dac_info[8]; 128f2e5731dSTakashi Iwai int dac_info_filled; 129c9b443d4STobin Davis 1300fb67e98SDaniel Drake unsigned int port_d_mode; 131f2e5731dSTakashi Iwai unsigned int auto_mute:1; /* used in auto-parser */ 13203697e2aSTakashi Iwai unsigned int detect_line:1; /* Line-out detection enabled */ 13303697e2aSTakashi Iwai unsigned int automute_lines:1; /* automute line-out as well */ 13403697e2aSTakashi Iwai unsigned int automute_hp_lo:1; /* both HP and LO available */ 135f2e5731dSTakashi Iwai unsigned int dell_automute:1; 136cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 137cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1387b2bfdbcSJens Taprogge unsigned int thinkpad:1; 139048e78a5SDavid Henningsson unsigned int hp_laptop:1; 140a1d6906eSDavid Henningsson unsigned int asus:1; 141254f2968STakashi Iwai unsigned int pin_eapd_ctrls:1; 1426b452142STakashi Iwai unsigned int single_adc_amp:1; 14375f8991dSDaniel Drake 1446764bcefSTakashi Iwai unsigned int adc_switching:1; 1456764bcefSTakashi Iwai 14675f8991dSDaniel Drake unsigned int ext_mic_present; 14775f8991dSDaniel Drake unsigned int recording; 14875f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 14975f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 150c4cfe66cSDaniel Drake 151c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 152c4cfe66cSDaniel Drake * through the microphone jack. 153c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 154c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 155c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 156c4cfe66cSDaniel Drake * control. */ 157c4cfe66cSDaniel Drake unsigned int dc_enable; 158c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 159c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1603507e2a8STakashi Iwai 1613507e2a8STakashi Iwai unsigned int beep_amp; 16219110595STakashi Iwai 16319110595STakashi Iwai /* extra EAPD pins */ 16419110595STakashi Iwai unsigned int num_eapds; 16519110595STakashi Iwai hda_nid_t eapds[4]; 166c9b443d4STobin Davis }; 167c9b443d4STobin Davis 168c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 169c9b443d4STobin Davis struct hda_codec *codec, 170c9b443d4STobin Davis struct snd_pcm_substream *substream) 171c9b443d4STobin Davis { 172c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1739a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1749a08160bSTakashi Iwai hinfo); 175c9b443d4STobin Davis } 176c9b443d4STobin Davis 177c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 178c9b443d4STobin Davis struct hda_codec *codec, 179c9b443d4STobin Davis unsigned int stream_tag, 180c9b443d4STobin Davis unsigned int format, 181c9b443d4STobin Davis struct snd_pcm_substream *substream) 182c9b443d4STobin Davis { 183c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 184c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 185c9b443d4STobin Davis stream_tag, 186c9b443d4STobin Davis format, substream); 187c9b443d4STobin Davis } 188c9b443d4STobin Davis 189c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 190c9b443d4STobin Davis struct hda_codec *codec, 191c9b443d4STobin Davis struct snd_pcm_substream *substream) 192c9b443d4STobin Davis { 193c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 194c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 195c9b443d4STobin Davis } 196c9b443d4STobin Davis 197c9b443d4STobin Davis /* 198c9b443d4STobin Davis * Digital out 199c9b443d4STobin Davis */ 200c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 201c9b443d4STobin Davis struct hda_codec *codec, 202c9b443d4STobin Davis struct snd_pcm_substream *substream) 203c9b443d4STobin Davis { 204c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 205c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 206c9b443d4STobin Davis } 207c9b443d4STobin Davis 208c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 209c9b443d4STobin Davis struct hda_codec *codec, 210c9b443d4STobin Davis struct snd_pcm_substream *substream) 211c9b443d4STobin Davis { 212c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 213c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 214c9b443d4STobin Davis } 215c9b443d4STobin Davis 2166b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2176b97eb45STakashi Iwai struct hda_codec *codec, 2186b97eb45STakashi Iwai unsigned int stream_tag, 2196b97eb45STakashi Iwai unsigned int format, 2206b97eb45STakashi Iwai struct snd_pcm_substream *substream) 2216b97eb45STakashi Iwai { 2226b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 2236b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 2246b97eb45STakashi Iwai stream_tag, 2256b97eb45STakashi Iwai format, substream); 2266b97eb45STakashi Iwai } 2276b97eb45STakashi Iwai 228c9b443d4STobin Davis /* 229c9b443d4STobin Davis * Analog capture 230c9b443d4STobin Davis */ 231c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 232c9b443d4STobin Davis struct hda_codec *codec, 233c9b443d4STobin Davis unsigned int stream_tag, 234c9b443d4STobin Davis unsigned int format, 235c9b443d4STobin Davis struct snd_pcm_substream *substream) 236c9b443d4STobin Davis { 237c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 23875f8991dSDaniel Drake if (spec->capture_prepare) 23975f8991dSDaniel Drake spec->capture_prepare(codec); 240c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 241c9b443d4STobin Davis stream_tag, 0, format); 242c9b443d4STobin Davis return 0; 243c9b443d4STobin Davis } 244c9b443d4STobin Davis 245c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 246c9b443d4STobin Davis struct hda_codec *codec, 247c9b443d4STobin Davis struct snd_pcm_substream *substream) 248c9b443d4STobin Davis { 249c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 250888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 25175f8991dSDaniel Drake if (spec->capture_cleanup) 25275f8991dSDaniel Drake spec->capture_cleanup(codec); 253c9b443d4STobin Davis return 0; 254c9b443d4STobin Davis } 255c9b443d4STobin Davis 256c9b443d4STobin Davis 257c9b443d4STobin Davis 25834cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = { 259c9b443d4STobin Davis .substreams = 1, 260c9b443d4STobin Davis .channels_min = 2, 261c9b443d4STobin Davis .channels_max = 2, 262c9b443d4STobin Davis .nid = 0, /* fill later */ 263c9b443d4STobin Davis .ops = { 264c9b443d4STobin Davis .open = conexant_playback_pcm_open, 265c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 266c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 267c9b443d4STobin Davis }, 268c9b443d4STobin Davis }; 269c9b443d4STobin Davis 27034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = { 271c9b443d4STobin Davis .substreams = 1, 272c9b443d4STobin Davis .channels_min = 2, 273c9b443d4STobin Davis .channels_max = 2, 274c9b443d4STobin Davis .nid = 0, /* fill later */ 275c9b443d4STobin Davis .ops = { 276c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 277c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 278c9b443d4STobin Davis }, 279c9b443d4STobin Davis }; 280c9b443d4STobin Davis 281c9b443d4STobin Davis 28234cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = { 283c9b443d4STobin Davis .substreams = 1, 284c9b443d4STobin Davis .channels_min = 2, 285c9b443d4STobin Davis .channels_max = 2, 286c9b443d4STobin Davis .nid = 0, /* fill later */ 287c9b443d4STobin Davis .ops = { 288c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2896b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2906b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 291c9b443d4STobin Davis }, 292c9b443d4STobin Davis }; 293c9b443d4STobin Davis 29434cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = { 295c9b443d4STobin Davis .substreams = 1, 296c9b443d4STobin Davis .channels_min = 2, 297c9b443d4STobin Davis .channels_max = 2, 298c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 299c9b443d4STobin Davis }; 300c9b443d4STobin Davis 301461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 302461e2c78STakashi Iwai struct hda_codec *codec, 303461e2c78STakashi Iwai unsigned int stream_tag, 304461e2c78STakashi Iwai unsigned int format, 305461e2c78STakashi Iwai struct snd_pcm_substream *substream) 306461e2c78STakashi Iwai { 307461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 308461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 309461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 310461e2c78STakashi Iwai spec->cur_adc_format = format; 311461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 312461e2c78STakashi Iwai return 0; 313461e2c78STakashi Iwai } 314461e2c78STakashi Iwai 315461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 316461e2c78STakashi Iwai struct hda_codec *codec, 317461e2c78STakashi Iwai struct snd_pcm_substream *substream) 318461e2c78STakashi Iwai { 319461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 320888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 321461e2c78STakashi Iwai spec->cur_adc = 0; 322461e2c78STakashi Iwai return 0; 323461e2c78STakashi Iwai } 324461e2c78STakashi Iwai 32534cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = { 326461e2c78STakashi Iwai .substreams = 1, 327461e2c78STakashi Iwai .channels_min = 2, 328461e2c78STakashi Iwai .channels_max = 2, 329461e2c78STakashi Iwai .nid = 0, /* fill later */ 330461e2c78STakashi Iwai .ops = { 331461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 332461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 333461e2c78STakashi Iwai }, 334461e2c78STakashi Iwai }; 335461e2c78STakashi Iwai 336c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 337c9b443d4STobin Davis { 338c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 339c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 340c9b443d4STobin Davis 341c9b443d4STobin Davis codec->num_pcms = 1; 342c9b443d4STobin Davis codec->pcm_info = info; 343c9b443d4STobin Davis 344c9b443d4STobin Davis info->name = "CONEXANT Analog"; 345c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 346c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 347c9b443d4STobin Davis spec->multiout.max_channels; 348c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 349c9b443d4STobin Davis spec->multiout.dac_nids[0]; 3506764bcefSTakashi Iwai if (spec->capture_stream) 3516764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream; 3526764bcefSTakashi Iwai else { 353461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 354461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 355461e2c78STakashi Iwai cx5051_pcm_analog_capture; 3566764bcefSTakashi Iwai else { 357461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 358461e2c78STakashi Iwai conexant_pcm_analog_capture; 3596764bcefSTakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 3606764bcefSTakashi Iwai spec->num_adc_nids; 3616764bcefSTakashi Iwai } 3626764bcefSTakashi Iwai } 363c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 364c9b443d4STobin Davis 365c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 366c9b443d4STobin Davis info++; 367c9b443d4STobin Davis codec->num_pcms++; 368c9b443d4STobin Davis info->name = "Conexant Digital"; 3697ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 370c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 371c9b443d4STobin Davis conexant_pcm_digital_playback; 372c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 373c9b443d4STobin Davis spec->multiout.dig_out_nid; 374c9b443d4STobin Davis if (spec->dig_in_nid) { 375c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 376c9b443d4STobin Davis conexant_pcm_digital_capture; 377c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 378c9b443d4STobin Davis spec->dig_in_nid; 379c9b443d4STobin Davis } 380f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 381f6a2491cSAndy Robinson codec->slave_dig_outs = spec->slave_dig_outs; 382c9b443d4STobin Davis } 383c9b443d4STobin Davis 384c9b443d4STobin Davis return 0; 385c9b443d4STobin Davis } 386c9b443d4STobin Davis 387c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 388c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 389c9b443d4STobin Davis { 390c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 391c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 392c9b443d4STobin Davis 393c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 394c9b443d4STobin Davis } 395c9b443d4STobin Davis 396c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 397c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 398c9b443d4STobin Davis { 399c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 400c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 401c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 402c9b443d4STobin Davis 403c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 404c9b443d4STobin Davis return 0; 405c9b443d4STobin Davis } 406c9b443d4STobin Davis 407c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 408c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 409c9b443d4STobin Davis { 410c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 411c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 412c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 413c9b443d4STobin Davis 414c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 415c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 416c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 417c9b443d4STobin Davis } 418c9b443d4STobin Davis 419bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 420bc7a166dSUlrich Dangel { 421cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 422bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 423bc7a166dSUlrich Dangel int i; 424bc7a166dSUlrich Dangel 425bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 426bc7a166dSUlrich Dangel const struct hda_verb *hv; 427bc7a166dSUlrich Dangel 428bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 429bc7a166dSUlrich Dangel while (hv->nid) { 430bc7a166dSUlrich Dangel int err = 0; 431bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 432bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 433cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 434cd372fb3STakashi Iwai SND_JACK_HEADPHONE, NULL); 435cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 436bc7a166dSUlrich Dangel break; 437bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 438bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 439cd372fb3STakashi Iwai err = snd_hda_input_jack_add(codec, hv->nid, 440cd372fb3STakashi Iwai SND_JACK_MICROPHONE, NULL); 441cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, hv->nid); 442bc7a166dSUlrich Dangel break; 443bc7a166dSUlrich Dangel } 444bc7a166dSUlrich Dangel if (err < 0) 445bc7a166dSUlrich Dangel return err; 446bc7a166dSUlrich Dangel ++hv; 447bc7a166dSUlrich Dangel } 448bc7a166dSUlrich Dangel } 449cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */ 4505801f992STakashi Iwai return 0; 4515801f992STakashi Iwai } 452bc7a166dSUlrich Dangel 4534d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 4544d7fbdbcSTakashi Iwai unsigned int power_state) 4554d7fbdbcSTakashi Iwai { 4564d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 4574d7fbdbcSTakashi Iwai msleep(100); 4584d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 4594d7fbdbcSTakashi Iwai power_state); 4604d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 4614d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 4624d7fbdbcSTakashi Iwai msleep(10); 4634d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 4644d7fbdbcSTakashi Iwai } 4654d7fbdbcSTakashi Iwai 466c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 467c9b443d4STobin Davis { 468c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 469c9b443d4STobin Davis int i; 470c9b443d4STobin Davis 471c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 472c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 473c9b443d4STobin Davis return 0; 474c9b443d4STobin Davis } 475c9b443d4STobin Davis 476c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 477c9b443d4STobin Davis { 478cd372fb3STakashi Iwai snd_hda_input_jack_free(codec); 479c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 480c9b443d4STobin Davis kfree(codec->spec); 481c9b443d4STobin Davis } 482c9b443d4STobin Davis 48334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 484b880c74aSTakashi Iwai { 485b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 486b880c74aSTakashi Iwai .name = "Capture Source", 487b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 488b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 489b880c74aSTakashi Iwai .put = conexant_mux_enum_put 490b880c74aSTakashi Iwai }, 491b880c74aSTakashi Iwai {} 492b880c74aSTakashi Iwai }; 493b880c74aSTakashi Iwai 4943507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4953507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 49634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4973507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4983507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4993507e2a8STakashi Iwai { } /* end */ 5003507e2a8STakashi Iwai }; 5013507e2a8STakashi Iwai #endif 5023507e2a8STakashi Iwai 503ea734963STakashi Iwai static const char * const slave_vols[] = { 504dd5746a8STakashi Iwai "Headphone Playback Volume", 505dd5746a8STakashi Iwai "Speaker Playback Volume", 506a3a85d39STakashi Iwai "Front Playback Volume", 507a3a85d39STakashi Iwai "Surround Playback Volume", 508a3a85d39STakashi Iwai "CLFE Playback Volume", 509dd5746a8STakashi Iwai NULL 510dd5746a8STakashi Iwai }; 511dd5746a8STakashi Iwai 512ea734963STakashi Iwai static const char * const slave_sws[] = { 513dd5746a8STakashi Iwai "Headphone Playback Switch", 514dd5746a8STakashi Iwai "Speaker Playback Switch", 515a3a85d39STakashi Iwai "Front Playback Switch", 516a3a85d39STakashi Iwai "Surround Playback Switch", 517a3a85d39STakashi Iwai "CLFE Playback Switch", 518dd5746a8STakashi Iwai NULL 519dd5746a8STakashi Iwai }; 520dd5746a8STakashi Iwai 521c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 522c9b443d4STobin Davis { 523c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 524c9b443d4STobin Davis unsigned int i; 525c9b443d4STobin Davis int err; 526c9b443d4STobin Davis 527c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 528c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 529c9b443d4STobin Davis if (err < 0) 530c9b443d4STobin Davis return err; 531c9b443d4STobin Davis } 532c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 533c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 53474b654c9SStephen Warren spec->multiout.dig_out_nid, 535c9b443d4STobin Davis spec->multiout.dig_out_nid); 536c9b443d4STobin Davis if (err < 0) 537c9b443d4STobin Davis return err; 5389a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5399a08160bSTakashi Iwai &spec->multiout); 5409a08160bSTakashi Iwai if (err < 0) 5419a08160bSTakashi Iwai return err; 5429a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 543c9b443d4STobin Davis } 544c9b443d4STobin Davis if (spec->dig_in_nid) { 545c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 546c9b443d4STobin Davis if (err < 0) 547c9b443d4STobin Davis return err; 548c9b443d4STobin Davis } 549dd5746a8STakashi Iwai 550dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 551dd5746a8STakashi Iwai if (spec->vmaster_nid && 552dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 553dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 554dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 555dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 556dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 557dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 558dd5746a8STakashi Iwai if (err < 0) 559dd5746a8STakashi Iwai return err; 560dd5746a8STakashi Iwai } 561dd5746a8STakashi Iwai if (spec->vmaster_nid && 562dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 563dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 564dd5746a8STakashi Iwai NULL, slave_sws); 565dd5746a8STakashi Iwai if (err < 0) 566dd5746a8STakashi Iwai return err; 567dd5746a8STakashi Iwai } 568dd5746a8STakashi Iwai 569b880c74aSTakashi Iwai if (spec->input_mux) { 570b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 571b880c74aSTakashi Iwai if (err < 0) 572b880c74aSTakashi Iwai return err; 573b880c74aSTakashi Iwai } 574b880c74aSTakashi Iwai 5753507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5763507e2a8STakashi Iwai /* create beep controls if needed */ 5773507e2a8STakashi Iwai if (spec->beep_amp) { 57834cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5793507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5803507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5813507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5823507e2a8STakashi Iwai if (!kctl) 5833507e2a8STakashi Iwai return -ENOMEM; 5843507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5853507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5863507e2a8STakashi Iwai if (err < 0) 5873507e2a8STakashi Iwai return err; 5883507e2a8STakashi Iwai } 5893507e2a8STakashi Iwai } 5903507e2a8STakashi Iwai #endif 5913507e2a8STakashi Iwai 592c9b443d4STobin Davis return 0; 593c9b443d4STobin Davis } 594c9b443d4STobin Davis 595697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 596697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 597697c373eSTakashi Iwai { 598697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 599697c373eSTakashi Iwai return 0; 600697c373eSTakashi Iwai } 601697c373eSTakashi Iwai #endif 602697c373eSTakashi Iwai 60334cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 604c9b443d4STobin Davis .build_controls = conexant_build_controls, 605c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 606c9b443d4STobin Davis .init = conexant_init, 607c9b443d4STobin Davis .free = conexant_free, 6084d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 609697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 610697c373eSTakashi Iwai .suspend = conexant_suspend, 611697c373eSTakashi Iwai #endif 612697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 613c9b443d4STobin Davis }; 614c9b443d4STobin Davis 6153507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6163507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 6173507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 6183507e2a8STakashi Iwai #else 6193507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 6203507e2a8STakashi Iwai #endif 6213507e2a8STakashi Iwai 6226764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 623c9b443d4STobin Davis /* 624c9b443d4STobin Davis * EAPD control 625c9b443d4STobin Davis * the private value = nid | (invert << 8) 626c9b443d4STobin Davis */ 627c9b443d4STobin Davis 628a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 629c9b443d4STobin Davis 63082f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 631c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 632c9b443d4STobin Davis { 633c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 634c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 635c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 636c9b443d4STobin Davis if (invert) 637c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 638c9b443d4STobin Davis else 639c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 640c9b443d4STobin Davis return 0; 64182f30040STobin Davis 642c9b443d4STobin Davis } 643c9b443d4STobin Davis 64482f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 645c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 646c9b443d4STobin Davis { 647c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 648c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 649c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 650c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 651c9b443d4STobin Davis unsigned int eapd; 65282f30040STobin Davis 65368ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 654c9b443d4STobin Davis if (invert) 655c9b443d4STobin Davis eapd = !eapd; 65682beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 657c9b443d4STobin Davis return 0; 65882f30040STobin Davis 659c9b443d4STobin Davis spec->cur_eapd = eapd; 66082beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 661c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 662c9b443d4STobin Davis eapd ? 0x02 : 0x00); 663c9b443d4STobin Davis return 1; 664c9b443d4STobin Davis } 665c9b443d4STobin Davis 66686d72bdfSTakashi Iwai /* controls for test mode */ 66786d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 66886d72bdfSTakashi Iwai 66982f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 67082f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 67182f30040STobin Davis .info = cxt_eapd_info, \ 67282f30040STobin Davis .get = cxt_eapd_get, \ 67382f30040STobin Davis .put = cxt_eapd_put, \ 67482f30040STobin Davis .private_value = nid | (mask<<16) } 67582f30040STobin Davis 67682f30040STobin Davis 67782f30040STobin Davis 678c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 679c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 680c9b443d4STobin Davis { 681c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 682c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 683c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 684c9b443d4STobin Davis spec->num_channel_mode); 685c9b443d4STobin Davis } 686c9b443d4STobin Davis 687c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 688c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 689c9b443d4STobin Davis { 690c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 691c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 692c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 693c9b443d4STobin Davis spec->num_channel_mode, 694c9b443d4STobin Davis spec->multiout.max_channels); 695c9b443d4STobin Davis } 696c9b443d4STobin Davis 697c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 698c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 699c9b443d4STobin Davis { 700c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 701c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 702c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 703c9b443d4STobin Davis spec->num_channel_mode, 704c9b443d4STobin Davis &spec->multiout.max_channels); 705c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 706c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 707c9b443d4STobin Davis return err; 708c9b443d4STobin Davis } 709c9b443d4STobin Davis 710c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 711c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 712c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 713c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 714c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 715c9b443d4STobin Davis .private_value = nid | (dir<<16) } 716c9b443d4STobin Davis 71786d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 71886d72bdfSTakashi Iwai 719c9b443d4STobin Davis /* Conexant 5045 specific */ 720c9b443d4STobin Davis 72134cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 72234cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 72334cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 724cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 725c9b443d4STobin Davis 72634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 7275cd57529STobin Davis { 2, NULL }, 7285cd57529STobin Davis }; 729c9b443d4STobin Davis 73034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 731c9b443d4STobin Davis .num_items = 2, 732c9b443d4STobin Davis .items = { 73382f30040STobin Davis { "IntMic", 0x1 }, 734f4beee94SJiang zhe { "ExtMic", 0x2 }, 735c9b443d4STobin Davis } 736c9b443d4STobin Davis }; 737c9b443d4STobin Davis 73834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 73922e14130SLukasz Marcinowski .num_items = 5, 7405218c892SJiang Zhe .items = { 7415218c892SJiang Zhe { "IntMic", 0x1 }, 7425218c892SJiang Zhe { "ExtMic", 0x2 }, 7435218c892SJiang Zhe { "LineIn", 0x3 }, 74422e14130SLukasz Marcinowski { "CD", 0x4 }, 74522e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7465218c892SJiang Zhe } 7475218c892SJiang Zhe }; 7485218c892SJiang Zhe 74934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7502de3c232SJiang zhe .num_items = 2, 7512de3c232SJiang zhe .items = { 7522de3c232SJiang zhe { "ExtMic", 0x1 }, 7532de3c232SJiang zhe { "IntMic", 0x2 }, 7542de3c232SJiang zhe } 7552de3c232SJiang zhe }; 7562de3c232SJiang zhe 757c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 758c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 759c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 760c9b443d4STobin Davis { 761c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 762c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 76382f30040STobin Davis unsigned int bits; 764c9b443d4STobin Davis 76582f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 766c9b443d4STobin Davis return 0; 767c9b443d4STobin Davis 76882f30040STobin Davis /* toggle internal speakers mute depending of presence of 76982f30040STobin Davis * the headphone jack 77082f30040STobin Davis */ 77147fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 77247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 77347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7747f29673bSTobin Davis 77547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 77647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 77747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 778c9b443d4STobin Davis return 1; 779c9b443d4STobin Davis } 780c9b443d4STobin Davis 781c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 78234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 783cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 784cca3b371STakashi Iwai .values = { 785cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 786cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 787cca3b371STakashi Iwai 0 788cca3b371STakashi Iwai }, 789cca3b371STakashi Iwai }; 790c9b443d4STobin Davis 7917f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7927f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7937f29673bSTobin Davis { 79434cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7957f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7967f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7977f29673bSTobin Davis {} 7987f29673bSTobin Davis }; 79934cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 8007f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8017f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8027f29673bSTobin Davis {} 8037f29673bSTobin Davis }; 8047f29673bSTobin Davis unsigned int present; 8057f29673bSTobin Davis 806d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 8077f29673bSTobin Davis if (present) 8087f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 8097f29673bSTobin Davis else 8107f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 8117f29673bSTobin Davis } 8127f29673bSTobin Davis 813c9b443d4STobin Davis 814c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 815c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 816c9b443d4STobin Davis { 81782f30040STobin Davis struct conexant_spec *spec = codec->spec; 818dd87da1cSTobin Davis unsigned int bits; 819c9b443d4STobin Davis 820d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 821dd87da1cSTobin Davis 82247fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 82347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 82447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 825c9b443d4STobin Davis } 826c9b443d4STobin Davis 827c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 828c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 829c9b443d4STobin Davis unsigned int res) 830c9b443d4STobin Davis { 831c9b443d4STobin Davis res >>= 26; 832c9b443d4STobin Davis switch (res) { 833c9b443d4STobin Davis case CONEXANT_HP_EVENT: 834c9b443d4STobin Davis cxt5045_hp_automute(codec); 835c9b443d4STobin Davis break; 8367f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8377f29673bSTobin Davis cxt5045_hp_automic(codec); 8387f29673bSTobin Davis break; 8397f29673bSTobin Davis 840c9b443d4STobin Davis } 841c9b443d4STobin Davis } 842c9b443d4STobin Davis 84334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 84428c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 84528c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8468607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8478607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 848c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 849c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 85028c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 85128c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8528607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8538607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 854cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 855c9b443d4STobin Davis { 856c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 857c9b443d4STobin Davis .name = "Master Playback Switch", 85882f30040STobin Davis .info = cxt_eapd_info, 85982f30040STobin Davis .get = cxt_eapd_get, 860c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 86182f30040STobin Davis .private_value = 0x10, 862c9b443d4STobin Davis }, 863c9b443d4STobin Davis 864c9b443d4STobin Davis {} 865c9b443d4STobin Davis }; 866c9b443d4STobin Davis 86734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 86822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 86922e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 87022e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 87122e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 87222e14130SLukasz Marcinowski 8735218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8745218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8755218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8765218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8775218c892SJiang Zhe 87822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 87922e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 88022e14130SLukasz Marcinowski 8815218c892SJiang Zhe {} 8825218c892SJiang Zhe }; 8835218c892SJiang Zhe 88434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 88528c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 88628c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8878607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8888607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8892de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8902de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 89128c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 89228c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8938607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8948607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8952de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8962de3c232SJiang zhe { 8972de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8982de3c232SJiang zhe .name = "Master Playback Switch", 8992de3c232SJiang zhe .info = cxt_eapd_info, 9002de3c232SJiang zhe .get = cxt_eapd_get, 9012de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 9022de3c232SJiang zhe .private_value = 0x10, 9032de3c232SJiang zhe }, 9042de3c232SJiang zhe 9052de3c232SJiang zhe {} 9062de3c232SJiang zhe }; 9072de3c232SJiang zhe 90834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 909c9b443d4STobin Davis /* Line in, Mic */ 9104090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9117f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 912c9b443d4STobin Davis /* HP, Amp */ 913c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 914c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 91582f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 916c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 917c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 918c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 919c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 920c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 921c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 92228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9237f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 92482f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 925c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 926c9b443d4STobin Davis /* SPDIF route: PCM */ 927cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 928c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 929c9b443d4STobin Davis /* EAPD */ 93082f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 931c9b443d4STobin Davis { } /* end */ 932c9b443d4STobin Davis }; 933c9b443d4STobin Davis 93434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 93528c4edb7SDavid Henningsson /* Internal Mic, Mic */ 9365218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9375218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9385218c892SJiang Zhe /* Line In,HP, Amp */ 9395218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9405218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9415218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9425218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9435218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9445218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9455218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9465218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9475218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 94828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9495218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9505218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9515218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9525218c892SJiang Zhe /* SPDIF route: PCM */ 953cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9545218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9555218c892SJiang Zhe /* EAPD */ 9565218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9575218c892SJiang Zhe { } /* end */ 9585218c892SJiang Zhe }; 9597f29673bSTobin Davis 96034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9617f29673bSTobin Davis /* pin sensing on HP jack */ 9627f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 963d3091fadSTakashi Iwai { } /* end */ 9647f29673bSTobin Davis }; 9657f29673bSTobin Davis 96634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9677f29673bSTobin Davis /* pin sensing on HP jack */ 9687f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 969d3091fadSTakashi Iwai { } /* end */ 9707f29673bSTobin Davis }; 9717f29673bSTobin Davis 972c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 973c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 974c9b443d4STobin Davis * configuration. 975c9b443d4STobin Davis */ 97634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 977c9b443d4STobin Davis .num_items = 5, 978c9b443d4STobin Davis .items = { 979c9b443d4STobin Davis { "MIXER", 0x0 }, 980c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 981c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 982c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 983c9b443d4STobin Davis { "CD pin", 0x4 }, 984c9b443d4STobin Davis }, 985c9b443d4STobin Davis }; 986c9b443d4STobin Davis 98734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 988c9b443d4STobin Davis 989c9b443d4STobin Davis /* Output controls */ 990c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 991c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9927f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9937f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9947f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9957f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 996c9b443d4STobin Davis 997c9b443d4STobin Davis /* Modes for retasking pin widgets */ 998c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 999c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 1000c9b443d4STobin Davis 100182f30040STobin Davis /* EAPD Switch Control */ 100282f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 100382f30040STobin Davis 1004c9b443d4STobin Davis /* Loopback mixer controls */ 1005c9b443d4STobin Davis 10067f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 10077f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 10087f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 10097f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 10107f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 10117f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 10127f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 10137f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 10147f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 10157f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 1016c9b443d4STobin Davis { 1017c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1018c9b443d4STobin Davis .name = "Input Source", 1019c9b443d4STobin Davis .info = conexant_mux_enum_info, 1020c9b443d4STobin Davis .get = conexant_mux_enum_get, 1021c9b443d4STobin Davis .put = conexant_mux_enum_put, 1022c9b443d4STobin Davis }, 1023fb3409e7STobin Davis /* Audio input controls */ 1024fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1025fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 1026fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 1027fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 1028fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 1029fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 1030fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1031fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1032fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1033fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1034c9b443d4STobin Davis { } /* end */ 1035c9b443d4STobin Davis }; 1036c9b443d4STobin Davis 103734cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 10387f29673bSTobin Davis /* Set connections */ 10397f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10407f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10417f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1042c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1043c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10447f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1045c9b443d4STobin Davis 1046c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1047c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1048c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1049c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1050c9b443d4STobin Davis * control. 1051c9b443d4STobin Davis */ 1052cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1053cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1054c9b443d4STobin Davis 1055c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1056c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1057c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1058c9b443d4STobin Davis 1059c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1060c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1061c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1062c9b443d4STobin Davis * input/output buffers as needed. 1063c9b443d4STobin Davis */ 1064c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1065c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1066c9b443d4STobin Davis 1067c9b443d4STobin Davis /* Mute capture amp left and right */ 1068c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1069c9b443d4STobin Davis 1070c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1071c9b443d4STobin Davis * pin) 1072c9b443d4STobin Davis */ 1073c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10747f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1075c9b443d4STobin Davis 1076c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1077c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1078c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1079c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1080c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1081c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1082c9b443d4STobin Davis 1083c9b443d4STobin Davis { } 1084c9b443d4STobin Davis }; 1085c9b443d4STobin Davis #endif 1086c9b443d4STobin Davis 1087c9b443d4STobin Davis 1088c9b443d4STobin Davis /* initialize jack-sensing, too */ 1089c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1090c9b443d4STobin Davis { 1091c9b443d4STobin Davis conexant_init(codec); 1092c9b443d4STobin Davis cxt5045_hp_automute(codec); 1093c9b443d4STobin Davis return 0; 1094c9b443d4STobin Davis } 1095c9b443d4STobin Davis 1096c9b443d4STobin Davis 1097c9b443d4STobin Davis enum { 109815908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 109915908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 110015908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 11015218c892SJiang Zhe CXT5045_BENQ, 11022de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1103c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1104c9b443d4STobin Davis CXT5045_TEST, 1105c9b443d4STobin Davis #endif 11061f8458a2STakashi Iwai CXT5045_AUTO, 1107f5fcc13cSTakashi Iwai CXT5045_MODELS 1108c9b443d4STobin Davis }; 1109c9b443d4STobin Davis 1110ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 111115908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 111215908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 111315908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 11145218c892SJiang Zhe [CXT5045_BENQ] = "benq", 11152de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1116c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1117f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1118c9b443d4STobin Davis #endif 11191f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1120f5fcc13cSTakashi Iwai }; 1121c9b443d4STobin Davis 112234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 11232de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1124dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1125dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 11266a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 11275218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 112815908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 112915908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 11309e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 11319e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 113215908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 113315908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 113415908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1135dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1136dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 113715908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1138c9b443d4STobin Davis {} 1139c9b443d4STobin Davis }; 1140c9b443d4STobin Davis 1141c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1142c9b443d4STobin Davis { 1143c9b443d4STobin Davis struct conexant_spec *spec; 1144c9b443d4STobin Davis int board_config; 1145c9b443d4STobin Davis 11461f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 11471f8458a2STakashi Iwai cxt5045_models, 11481f8458a2STakashi Iwai cxt5045_cfg_tbl); 11491f8458a2STakashi Iwai if (board_config < 0) 1150c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 11511f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11521f8458a2STakashi Iwai return patch_conexant_auto(codec); 11531f8458a2STakashi Iwai 1154c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1155c9b443d4STobin Davis if (!spec) 1156c9b443d4STobin Davis return -ENOMEM; 1157c9b443d4STobin Davis codec->spec = spec; 11589421f954STakashi Iwai codec->pin_amp_workaround = 1; 1159c9b443d4STobin Davis 1160c9b443d4STobin Davis spec->multiout.max_channels = 2; 1161c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1162c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1163c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1164c9b443d4STobin Davis spec->num_adc_nids = 1; 1165c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1166c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1167c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1168c9b443d4STobin Davis spec->num_mixers = 1; 1169c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1170c9b443d4STobin Davis spec->num_init_verbs = 1; 1171c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1172c9b443d4STobin Davis spec->spdif_route = 0; 11733507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11743507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11755cd57529STobin Davis 11763507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1177c9b443d4STobin Davis 1178c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1179c9b443d4STobin Davis 1180c9b443d4STobin Davis switch (board_config) { 118115908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11827f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1183c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1184c9b443d4STobin Davis spec->num_init_verbs = 2; 11857f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11867f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11877f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11887f29673bSTobin Davis break; 118915908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 119086376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11917f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11927f29673bSTobin Davis spec->num_init_verbs = 2; 11937f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1194c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1195c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1196c9b443d4STobin Davis break; 119715908c36SMarc Boucher default: 119815908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 119915908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 120015908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 120115908c36SMarc Boucher spec->num_init_verbs = 3; 120215908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 120315908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 120415908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 120515908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 120615908c36SMarc Boucher break; 12075218c892SJiang Zhe case CXT5045_BENQ: 12085218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12095218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 12105218c892SJiang Zhe spec->num_init_verbs = 1; 12115218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 12125218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 12135218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 12145218c892SJiang Zhe spec->num_mixers = 2; 12155218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 12165218c892SJiang Zhe break; 12172de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 12182de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12192de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 12202de3c232SJiang zhe spec->num_init_verbs = 2; 12212de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12222de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 12232de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 12242de3c232SJiang zhe break; 1225c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1226c9b443d4STobin Davis case CXT5045_TEST: 1227c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1228c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1229c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 123015908c36SMarc Boucher break; 123115908c36SMarc Boucher 1232c9b443d4STobin Davis #endif 1233c9b443d4STobin Davis } 123448ecb7e8STakashi Iwai 1235031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1236031005f7STakashi Iwai case 0x103c: 12378f0f5ff6SDaniel T Chen case 0x1631: 12380b587fc4SDaniel T Chen case 0x1734: 12390ebf9e36SDaniel T Chen case 0x17aa: 12400ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12410ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12420ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 124348ecb7e8STakashi Iwai */ 124448ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 124548ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 124648ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 124748ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 124848ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1249031005f7STakashi Iwai break; 1250031005f7STakashi Iwai } 125148ecb7e8STakashi Iwai 12523507e2a8STakashi Iwai if (spec->beep_amp) 12533507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12543507e2a8STakashi Iwai 1255c9b443d4STobin Davis return 0; 1256c9b443d4STobin Davis } 1257c9b443d4STobin Davis 1258c9b443d4STobin Davis 1259c9b443d4STobin Davis /* Conexant 5047 specific */ 126082f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1261c9b443d4STobin Davis 126234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 126334cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 126434cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1265c9b443d4STobin Davis 126634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12675cd57529STobin Davis { 2, NULL }, 12685cd57529STobin Davis }; 1269c9b443d4STobin Davis 127034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 127182f30040STobin Davis .num_items = 2, 127282f30040STobin Davis .items = { 127382f30040STobin Davis { "ExtMic", 0x2 }, 127482f30040STobin Davis { "Line-In", 0x1 }, 1275c9b443d4STobin Davis } 1276c9b443d4STobin Davis }; 1277c9b443d4STobin Davis 1278c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1279c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1280c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1281c9b443d4STobin Davis { 1282c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1283c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 128482f30040STobin Davis unsigned int bits; 1285c9b443d4STobin Davis 128682f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1287c9b443d4STobin Davis return 0; 1288c9b443d4STobin Davis 128982f30040STobin Davis /* toggle internal speakers mute depending of presence of 129082f30040STobin Davis * the headphone jack 129182f30040STobin Davis */ 129247fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12933b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12943b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12953b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12963b7523fcSTakashi Iwai */ 12975d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 129847fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 129947fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 130047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 130147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1302c9b443d4STobin Davis return 1; 1303c9b443d4STobin Davis } 1304c9b443d4STobin Davis 1305c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1306c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1307c9b443d4STobin Davis { 130882f30040STobin Davis struct conexant_spec *spec = codec->spec; 1309dd87da1cSTobin Davis unsigned int bits; 1310c9b443d4STobin Davis 1311d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1312dd87da1cSTobin Davis 131347fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 13143b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13155d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 131647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1317c9b443d4STobin Davis } 1318c9b443d4STobin Davis 1319c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1320c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1321c9b443d4STobin Davis { 132234cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 13239f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13249f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1325c9b443d4STobin Davis {} 1326c9b443d4STobin Davis }; 132734cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 13289f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13299f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1330c9b443d4STobin Davis {} 1331c9b443d4STobin Davis }; 1332c9b443d4STobin Davis unsigned int present; 1333c9b443d4STobin Davis 1334d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1335c9b443d4STobin Davis if (present) 1336c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1337c9b443d4STobin Davis else 1338c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1339c9b443d4STobin Davis } 1340c9b443d4STobin Davis 1341c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1342c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1343c9b443d4STobin Davis unsigned int res) 1344c9b443d4STobin Davis { 13459f113e0eSMarc Boucher switch (res >> 26) { 1346c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1347c9b443d4STobin Davis cxt5047_hp_automute(codec); 1348c9b443d4STobin Davis break; 1349c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1350c9b443d4STobin Davis cxt5047_hp_automic(codec); 1351c9b443d4STobin Davis break; 1352c9b443d4STobin Davis } 1353c9b443d4STobin Davis } 1354c9b443d4STobin Davis 135534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1356df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1357df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13585f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1359c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1360c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1361c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1362c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 136382f30040STobin Davis { 136482f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 136582f30040STobin Davis .name = "Master Playback Switch", 136682f30040STobin Davis .info = cxt_eapd_info, 136782f30040STobin Davis .get = cxt_eapd_get, 1368c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1369c9b443d4STobin Davis .private_value = 0x13, 1370c9b443d4STobin Davis }, 1371c9b443d4STobin Davis 1372c9b443d4STobin Davis {} 1373c9b443d4STobin Davis }; 1374c9b443d4STobin Davis 137534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13763b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13775d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1378df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1379df481e41STakashi Iwai {} 1380df481e41STakashi Iwai }; 1381df481e41STakashi Iwai 138234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1383c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1384c9b443d4STobin Davis { } /* end */ 1385c9b443d4STobin Davis }; 1386c9b443d4STobin Davis 138734cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1388c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1389c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1390c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1391c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13927f29673bSTobin Davis /* HP, Speaker */ 1393b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13945b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13955b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13967f29673bSTobin Davis /* Record selector: Mic */ 13977f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13987f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13997f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 14007f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1401c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1402c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1403c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1404c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1405c9b443d4STobin Davis /* SPDIF route: PCM */ 1406c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 140782f30040STobin Davis /* Enable unsolicited events */ 140882f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 140982f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1410c9b443d4STobin Davis { } /* end */ 1411c9b443d4STobin Davis }; 1412c9b443d4STobin Davis 1413c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 141434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 14153b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1416c9b443d4STobin Davis {} 1417c9b443d4STobin Davis }; 1418c9b443d4STobin Davis 1419c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1420c9b443d4STobin Davis * configuration. 1421c9b443d4STobin Davis */ 1422c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 142334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 142482f30040STobin Davis .num_items = 4, 1425c9b443d4STobin Davis .items = { 142682f30040STobin Davis { "LINE1 pin", 0x0 }, 142782f30040STobin Davis { "MIC1 pin", 0x1 }, 142882f30040STobin Davis { "MIC2 pin", 0x2 }, 142982f30040STobin Davis { "CD pin", 0x3 }, 1430c9b443d4STobin Davis }, 1431c9b443d4STobin Davis }; 1432c9b443d4STobin Davis 143334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1434c9b443d4STobin Davis 1435c9b443d4STobin Davis /* Output only controls */ 143682f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 143782f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 143882f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 143982f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1440c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1441c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1442c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1443c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 144482f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 144582f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 144682f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 144782f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1448c9b443d4STobin Davis 1449c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1450c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1451c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1452c9b443d4STobin Davis 145382f30040STobin Davis /* EAPD Switch Control */ 145482f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 145582f30040STobin Davis 1456c9b443d4STobin Davis /* Loopback mixer controls */ 145782f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 145882f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 145982f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 146082f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 146182f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 146282f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 146382f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 146482f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1465c9b443d4STobin Davis 146682f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 146782f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 146882f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 146982f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 147082f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 147182f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 147282f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 147382f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1474c9b443d4STobin Davis { 1475c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1476c9b443d4STobin Davis .name = "Input Source", 1477c9b443d4STobin Davis .info = conexant_mux_enum_info, 1478c9b443d4STobin Davis .get = conexant_mux_enum_get, 1479c9b443d4STobin Davis .put = conexant_mux_enum_put, 1480c9b443d4STobin Davis }, 1481854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14829f113e0eSMarc Boucher 1483c9b443d4STobin Davis { } /* end */ 1484c9b443d4STobin Davis }; 1485c9b443d4STobin Davis 148634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1487c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1488c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1489c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1490c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1491c9b443d4STobin Davis 1492c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1493c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1494c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1495c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1496c9b443d4STobin Davis * control. 1497c9b443d4STobin Davis */ 1498c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1499c9b443d4STobin Davis 1500c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1501c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1502c9b443d4STobin Davis */ 1503c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1504c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1505c9b443d4STobin Davis 1506c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1507c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1508c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1509c9b443d4STobin Davis 1510c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1511c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1512c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1513c9b443d4STobin Davis * input/output buffers as needed. 1514c9b443d4STobin Davis */ 1515c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1516c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1517c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1518c9b443d4STobin Davis 1519c9b443d4STobin Davis /* Mute capture amp left and right */ 1520c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1521c9b443d4STobin Davis 1522c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1523c9b443d4STobin Davis * pin) 1524c9b443d4STobin Davis */ 1525c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1526c9b443d4STobin Davis 1527c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1528c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1529c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1530c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1531c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1532c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1533c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1534c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1535c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1536c9b443d4STobin Davis 1537c9b443d4STobin Davis { } 1538c9b443d4STobin Davis }; 1539c9b443d4STobin Davis #endif 1540c9b443d4STobin Davis 1541c9b443d4STobin Davis 1542c9b443d4STobin Davis /* initialize jack-sensing, too */ 1543c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1544c9b443d4STobin Davis { 1545c9b443d4STobin Davis conexant_init(codec); 1546c9b443d4STobin Davis cxt5047_hp_automute(codec); 1547c9b443d4STobin Davis return 0; 1548c9b443d4STobin Davis } 1549c9b443d4STobin Davis 1550c9b443d4STobin Davis 1551c9b443d4STobin Davis enum { 1552f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1553f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1554f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1555c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1556c9b443d4STobin Davis CXT5047_TEST, 1557c9b443d4STobin Davis #endif 1558fa5dadcbSTakashi Iwai CXT5047_AUTO, 1559f5fcc13cSTakashi Iwai CXT5047_MODELS 1560c9b443d4STobin Davis }; 1561c9b443d4STobin Davis 1562ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1563f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1564f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1565f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1566c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1567f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1568c9b443d4STobin Davis #endif 1569fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1570f5fcc13cSTakashi Iwai }; 1571c9b443d4STobin Davis 157234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1573ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1574dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1575dea0a509STakashi Iwai CXT5047_LAPTOP), 1576f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1577c9b443d4STobin Davis {} 1578c9b443d4STobin Davis }; 1579c9b443d4STobin Davis 1580c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1581c9b443d4STobin Davis { 1582c9b443d4STobin Davis struct conexant_spec *spec; 1583c9b443d4STobin Davis int board_config; 1584c9b443d4STobin Davis 1585fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1586fa5dadcbSTakashi Iwai cxt5047_models, 1587fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1588fa5dadcbSTakashi Iwai if (board_config < 0) 1589c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1590fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1591fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1592fa5dadcbSTakashi Iwai 1593c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1594c9b443d4STobin Davis if (!spec) 1595c9b443d4STobin Davis return -ENOMEM; 1596c9b443d4STobin Davis codec->spec = spec; 15979421f954STakashi Iwai codec->pin_amp_workaround = 1; 1598c9b443d4STobin Davis 1599c9b443d4STobin Davis spec->multiout.max_channels = 2; 1600c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1601c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1602c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1603c9b443d4STobin Davis spec->num_adc_nids = 1; 1604c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1605c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1606c9b443d4STobin Davis spec->num_mixers = 1; 1607df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1608c9b443d4STobin Davis spec->num_init_verbs = 1; 1609c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1610c9b443d4STobin Davis spec->spdif_route = 0; 16115cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16125cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1613c9b443d4STobin Davis 1614c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1615c9b443d4STobin Davis 1616c9b443d4STobin Davis switch (board_config) { 1617c9b443d4STobin Davis case CXT5047_LAPTOP: 1618df481e41STakashi Iwai spec->num_mixers = 2; 1619df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1620df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1621c9b443d4STobin Davis break; 1622c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1623df481e41STakashi Iwai spec->num_mixers = 2; 1624df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1625fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1626c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1627c9b443d4STobin Davis break; 1628c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 162982f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1630df481e41STakashi Iwai spec->num_mixers = 2; 1631df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1632c9b443d4STobin Davis spec->num_init_verbs = 2; 1633c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1634fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1635c9b443d4STobin Davis break; 1636c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1637c9b443d4STobin Davis case CXT5047_TEST: 1638c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1639c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1640c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1641fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1642c9b443d4STobin Davis #endif 1643c9b443d4STobin Davis } 1644dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1645025f206cSDaniel T Chen 1646025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1647025f206cSDaniel T Chen case 0x103c: 1648025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1649025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1650025f206cSDaniel T Chen * with 0 dB offset 0x17) 1651025f206cSDaniel T Chen */ 1652025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1653025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1654025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1655025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1656025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1657025f206cSDaniel T Chen break; 1658025f206cSDaniel T Chen } 1659025f206cSDaniel T Chen 1660c9b443d4STobin Davis return 0; 1661c9b443d4STobin Davis } 1662c9b443d4STobin Davis 1663461e2c78STakashi Iwai /* Conexant 5051 specific */ 166434cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 166534cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1666461e2c78STakashi Iwai 166734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1668461e2c78STakashi Iwai { 2, NULL }, 1669461e2c78STakashi Iwai }; 1670461e2c78STakashi Iwai 1671461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1672461e2c78STakashi Iwai { 1673461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1674461e2c78STakashi Iwai unsigned int pinctl; 167523d2df5bSTakashi Iwai /* headphone pin */ 167623d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 167723d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 167823d2df5bSTakashi Iwai pinctl); 167923d2df5bSTakashi Iwai /* speaker pin */ 1680461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1681461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1682461e2c78STakashi Iwai pinctl); 1683f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1684f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1685f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1686f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1687f7154de2SHerton Ronaldo Krzesinski pinctl); 1688461e2c78STakashi Iwai } 1689461e2c78STakashi Iwai 1690461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1691461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1692461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1693461e2c78STakashi Iwai { 1694461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1695461e2c78STakashi Iwai 1696461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1697461e2c78STakashi Iwai return 0; 1698461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1699461e2c78STakashi Iwai return 1; 1700461e2c78STakashi Iwai } 1701461e2c78STakashi Iwai 1702461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1703461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1704461e2c78STakashi Iwai { 170579d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1706461e2c78STakashi Iwai unsigned int present; 1707461e2c78STakashi Iwai 1708faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 170979d7d533STakashi Iwai return; 1710d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1711461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1712461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1713461e2c78STakashi Iwai present ? 0x01 : 0x00); 1714461e2c78STakashi Iwai } 1715461e2c78STakashi Iwai 1716461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1717461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1718461e2c78STakashi Iwai { 1719461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1720461e2c78STakashi Iwai unsigned int present; 1721461e2c78STakashi Iwai hda_nid_t new_adc; 1722461e2c78STakashi Iwai 1723faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 172479d7d533STakashi Iwai return; 1725d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1726461e2c78STakashi Iwai if (present) 1727461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1728461e2c78STakashi Iwai else 1729461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1730461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1731461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1732461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1733f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1734461e2c78STakashi Iwai spec->cur_adc = new_adc; 1735461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1736461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1737461e2c78STakashi Iwai spec->cur_adc_format); 1738461e2c78STakashi Iwai } 1739461e2c78STakashi Iwai } 1740461e2c78STakashi Iwai 1741461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1742461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1743461e2c78STakashi Iwai { 1744461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1745461e2c78STakashi Iwai 1746d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1747461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1748461e2c78STakashi Iwai } 1749461e2c78STakashi Iwai 1750461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1751461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1752461e2c78STakashi Iwai unsigned int res) 1753461e2c78STakashi Iwai { 1754acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1755461e2c78STakashi Iwai switch (res >> 26) { 1756461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1757461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1758461e2c78STakashi Iwai break; 1759461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1760461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1761461e2c78STakashi Iwai break; 1762461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1763461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1764461e2c78STakashi Iwai break; 1765461e2c78STakashi Iwai } 1766cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 1767461e2c78STakashi Iwai } 1768461e2c78STakashi Iwai 176934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1770461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1771461e2c78STakashi Iwai { 1772461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1773461e2c78STakashi Iwai .name = "Master Playback Switch", 1774461e2c78STakashi Iwai .info = cxt_eapd_info, 1775461e2c78STakashi Iwai .get = cxt_eapd_get, 1776461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1777461e2c78STakashi Iwai .private_value = 0x1a, 1778461e2c78STakashi Iwai }, 17792c7a3fb3STakashi Iwai {} 17802c7a3fb3STakashi Iwai }; 1781461e2c78STakashi Iwai 178234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17832c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17842c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17858607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17868607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17872c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17882c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1789461e2c78STakashi Iwai {} 1790461e2c78STakashi Iwai }; 1791461e2c78STakashi Iwai 179234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1793461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1794461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17958607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17968607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1797461e2c78STakashi Iwai {} 1798461e2c78STakashi Iwai }; 1799461e2c78STakashi Iwai 180034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 18014e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 18024e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 180379d7d533STakashi Iwai {} 180479d7d533STakashi Iwai }; 180579d7d533STakashi Iwai 180634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 18075f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 18085f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1809cd9d95a5SKen Prox {} 1810cd9d95a5SKen Prox }; 1811cd9d95a5SKen Prox 181234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1813faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1814faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 18158607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 18168607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1817faddaa5dSTakashi Iwai {} 1818faddaa5dSTakashi Iwai }; 1819faddaa5dSTakashi Iwai 182034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1821461e2c78STakashi Iwai /* Line in, Mic */ 1822461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1823461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1824461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1825461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1826461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1827461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1828461e2c78STakashi Iwai /* SPK */ 1829461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1830461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1831461e2c78STakashi Iwai /* HP, Amp */ 1832461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1833461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1834461e2c78STakashi Iwai /* DAC1 */ 1835461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 183628c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1837461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1838461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1839461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1840461e2c78STakashi Iwai /* SPDIF route: PCM */ 18411965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1842461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1843461e2c78STakashi Iwai /* EAPD */ 1844461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1845461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1846461e2c78STakashi Iwai { } /* end */ 1847461e2c78STakashi Iwai }; 1848461e2c78STakashi Iwai 184934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 185079d7d533STakashi Iwai /* Line in, Mic */ 185179d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 185279d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 185379d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185479d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185579d7d533STakashi Iwai /* SPK */ 185679d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 185779d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 185879d7d533STakashi Iwai /* HP, Amp */ 185979d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 186079d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 186179d7d533STakashi Iwai /* DAC1 */ 186279d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 186328c4edb7SDavid Henningsson /* Record selector: Internal mic */ 186479d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 186579d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 186679d7d533STakashi Iwai /* SPDIF route: PCM */ 186779d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 186879d7d533STakashi Iwai /* EAPD */ 186979d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 187079d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 187179d7d533STakashi Iwai { } /* end */ 187279d7d533STakashi Iwai }; 187379d7d533STakashi Iwai 187434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1875cd9d95a5SKen Prox /* Line in, Mic */ 187630ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1877cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1878cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1879cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1880cd9d95a5SKen Prox /* SPK */ 1881cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1882cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1883cd9d95a5SKen Prox /* HP, Amp */ 1884cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1885cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1886cd9d95a5SKen Prox /* DAC1 */ 1887cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 188828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1889cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1890cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1891cd9d95a5SKen Prox /* SPDIF route: PCM */ 1892cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1893cd9d95a5SKen Prox /* EAPD */ 1894cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1895cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1896cd9d95a5SKen Prox { } /* end */ 1897cd9d95a5SKen Prox }; 1898cd9d95a5SKen Prox 18996953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 19006953e552STakashi Iwai unsigned int event) 19016953e552STakashi Iwai { 19026953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19036953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19046953e552STakashi Iwai AC_USRSP_EN | event); 1905cd372fb3STakashi Iwai snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL); 1906cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 19076953e552STakashi Iwai } 19086953e552STakashi Iwai 190934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1910f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1911f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1912f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1913f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1914f7154de2SHerton Ronaldo Krzesinski }; 1915f7154de2SHerton Ronaldo Krzesinski 1916461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1917461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1918461e2c78STakashi Iwai { 19196953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19206953e552STakashi Iwai 1921461e2c78STakashi Iwai conexant_init(codec); 1922acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19236953e552STakashi Iwai 19246953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19256953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19266953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19276953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19286953e552STakashi Iwai 1929461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1930461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1931461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1932461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1933461e2c78STakashi Iwai } 1934461e2c78STakashi Iwai return 0; 1935461e2c78STakashi Iwai } 1936461e2c78STakashi Iwai 1937461e2c78STakashi Iwai 1938461e2c78STakashi Iwai enum { 1939461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1940461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 194179d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1942cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1943faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1944f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 19456764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1946461e2c78STakashi Iwai CXT5051_MODELS 1947461e2c78STakashi Iwai }; 1948461e2c78STakashi Iwai 1949ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1950461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1951461e2c78STakashi Iwai [CXT5051_HP] = "hp", 195279d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 19535f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1954faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1955f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19566764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1957461e2c78STakashi Iwai }; 1958461e2c78STakashi Iwai 195934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 196079d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19611812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19625f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1963faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1964461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1965461e2c78STakashi Iwai CXT5051_LAPTOP), 1966461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1967f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1968461e2c78STakashi Iwai {} 1969461e2c78STakashi Iwai }; 1970461e2c78STakashi Iwai 1971461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1972461e2c78STakashi Iwai { 1973461e2c78STakashi Iwai struct conexant_spec *spec; 1974461e2c78STakashi Iwai int board_config; 1975461e2c78STakashi Iwai 19766764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19776764bcefSTakashi Iwai cxt5051_models, 19786764bcefSTakashi Iwai cxt5051_cfg_tbl); 19796764bcefSTakashi Iwai if (board_config < 0) 1980c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19811f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19826764bcefSTakashi Iwai return patch_conexant_auto(codec); 19836764bcefSTakashi Iwai 1984461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1985461e2c78STakashi Iwai if (!spec) 1986461e2c78STakashi Iwai return -ENOMEM; 1987461e2c78STakashi Iwai codec->spec = spec; 19889421f954STakashi Iwai codec->pin_amp_workaround = 1; 1989461e2c78STakashi Iwai 1990461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1991461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1992461e2c78STakashi Iwai 1993461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1994461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1995461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1996461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1997461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1998461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19992c7a3fb3STakashi Iwai spec->num_mixers = 2; 20002c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20012c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2002461e2c78STakashi Iwai spec->num_init_verbs = 1; 2003461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2004461e2c78STakashi Iwai spec->spdif_route = 0; 2005461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2006461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2007461e2c78STakashi Iwai spec->cur_adc = 0; 2008461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2009461e2c78STakashi Iwai 20103507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20113507e2a8STakashi Iwai 201279d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 201379d7d533STakashi Iwai 2014faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2015461e2c78STakashi Iwai switch (board_config) { 2016461e2c78STakashi Iwai case CXT5051_HP: 2017461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2018461e2c78STakashi Iwai break; 201979d7d533STakashi Iwai case CXT5051_HP_DV6736: 202079d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 202179d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2022faddaa5dSTakashi Iwai spec->auto_mic = 0; 202379d7d533STakashi Iwai break; 2024cd9d95a5SKen Prox case CXT5051_F700: 2025cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2026cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2027faddaa5dSTakashi Iwai spec->auto_mic = 0; 2028faddaa5dSTakashi Iwai break; 2029faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2030faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2031faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2032cd9d95a5SKen Prox break; 2033f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2034f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2035f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2036f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2037f7154de2SHerton Ronaldo Krzesinski break; 2038461e2c78STakashi Iwai } 2039461e2c78STakashi Iwai 20403507e2a8STakashi Iwai if (spec->beep_amp) 20413507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20423507e2a8STakashi Iwai 2043461e2c78STakashi Iwai return 0; 2044461e2c78STakashi Iwai } 2045461e2c78STakashi Iwai 20460fb67e98SDaniel Drake /* Conexant 5066 specific */ 20470fb67e98SDaniel Drake 204834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 204934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 205034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 205134cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 20520fb67e98SDaniel Drake 2053dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2054dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2055dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2056dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2057dbaccc0cSDaniel Drake 205834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20590fb67e98SDaniel Drake { 2, NULL }, 20600fb67e98SDaniel Drake }; 20610fb67e98SDaniel Drake 2062a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2063a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2064a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2065a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2066a3de8ab8STakashi Iwai 20670fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20680fb67e98SDaniel Drake { 20690fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20700fb67e98SDaniel Drake unsigned int pinctl; 20710fb67e98SDaniel Drake 20723a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20733a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20740fb67e98SDaniel Drake 20750fb67e98SDaniel Drake /* Port A (HP) */ 2076a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20770fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20780fb67e98SDaniel Drake pinctl); 20790fb67e98SDaniel Drake 20800fb67e98SDaniel Drake /* Port D (HP/LO) */ 2081a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2082a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2083a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2084a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20853a253445SJohn Baboval pinctl = 0; 20863a253445SJohn Baboval } else { 2087a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2088a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2089a3de8ab8STakashi Iwai pinctl = 0; 20903a253445SJohn Baboval } 20910fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20920fb67e98SDaniel Drake pinctl); 20930fb67e98SDaniel Drake 20940fb67e98SDaniel Drake /* CLASS_D AMP */ 20950fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20960fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20970fb67e98SDaniel Drake pinctl); 20980fb67e98SDaniel Drake } 20990fb67e98SDaniel Drake 21000fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21010fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21020fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21030fb67e98SDaniel Drake { 21040fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21050fb67e98SDaniel Drake 21060fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21070fb67e98SDaniel Drake return 0; 21080fb67e98SDaniel Drake 21090fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21100fb67e98SDaniel Drake return 1; 21110fb67e98SDaniel Drake } 21120fb67e98SDaniel Drake 2113c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2114c4cfe66cSDaniel Drake .num_items = 3, 2115c4cfe66cSDaniel Drake .items = { 2116c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2117c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2118c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2119c4cfe66cSDaniel Drake }, 2120c4cfe66cSDaniel Drake }; 2121c4cfe66cSDaniel Drake 2122c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2123c4cfe66cSDaniel Drake { 2124c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2125c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2126c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2127c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2128c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2129c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2130c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2131c4cfe66cSDaniel Drake } 2132c4cfe66cSDaniel Drake 213375f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 213475f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 213575f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 213675f8991dSDaniel Drake * is happening when it is not. */ 213775f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21380fb67e98SDaniel Drake { 2139dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 214075f8991dSDaniel Drake if (!spec->recording) 214175f8991dSDaniel Drake return; 21420fb67e98SDaniel Drake 2143c4cfe66cSDaniel Drake if (spec->dc_enable) { 2144c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2145c4cfe66cSDaniel Drake * through our special DC port */ 2146c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2147c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2148c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2149c4cfe66cSDaniel Drake 2150c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2151c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2152c4cfe66cSDaniel Drake {}, 2153c4cfe66cSDaniel Drake }; 2154c4cfe66cSDaniel Drake 2155c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2156c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2157c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2158c4cfe66cSDaniel Drake return; 2159c4cfe66cSDaniel Drake } 2160c4cfe66cSDaniel Drake 2161c4cfe66cSDaniel Drake /* disable DC (port F) */ 2162c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2163c4cfe66cSDaniel Drake 216475f8991dSDaniel Drake /* external mic, port B */ 216575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 216675f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21670fb67e98SDaniel Drake 216875f8991dSDaniel Drake /* internal mic, port C */ 216975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 217075f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 217175f8991dSDaniel Drake } 21720fb67e98SDaniel Drake 217375f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 217475f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 217575f8991dSDaniel Drake { 217675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21770fb67e98SDaniel Drake unsigned int present; 21780fb67e98SDaniel Drake 2179c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2180c4cfe66cSDaniel Drake return; 2181c4cfe66cSDaniel Drake 218275f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 218375f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 218475f8991dSDaniel Drake if (present) 21850fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 218675f8991dSDaniel Drake else 21870fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 218875f8991dSDaniel Drake 218975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 219075f8991dSDaniel Drake present ? 0 : 1); 219175f8991dSDaniel Drake spec->ext_mic_present = !!present; 219275f8991dSDaniel Drake 219375f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21940fb67e98SDaniel Drake } 21950fb67e98SDaniel Drake 219695a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 219795a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 219895a618bdSEinar Rünkaru { 219995a618bdSEinar Rünkaru unsigned int present; 220095a618bdSEinar Rünkaru 220195a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 220295a618bdSEinar Rünkaru /* enable external mic, port B */ 220375f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 220495a618bdSEinar Rünkaru 220595a618bdSEinar Rünkaru /* switch to external mic input */ 220695a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 220795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 220895a618bdSEinar Rünkaru 220995a618bdSEinar Rünkaru /* disable internal digital mic */ 221095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 221195a618bdSEinar Rünkaru {} 221295a618bdSEinar Rünkaru }; 221334cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 221495a618bdSEinar Rünkaru /* enable internal mic, port C */ 221595a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 221695a618bdSEinar Rünkaru 221795a618bdSEinar Rünkaru /* switch to internal mic input */ 221895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 221995a618bdSEinar Rünkaru 222095a618bdSEinar Rünkaru /* disable external mic, port B */ 222195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 222295a618bdSEinar Rünkaru {} 222395a618bdSEinar Rünkaru }; 222495a618bdSEinar Rünkaru 222595a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 222695a618bdSEinar Rünkaru if (present) { 222795a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 222895a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 222995a618bdSEinar Rünkaru } else { 223095a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 223195a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 223295a618bdSEinar Rünkaru } 223395a618bdSEinar Rünkaru } 223495a618bdSEinar Rünkaru 2235cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2236cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2237cfd3d8dcSGreg Alexander { 2238cfd3d8dcSGreg Alexander unsigned int present; 2239cfd3d8dcSGreg Alexander 2240cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2241cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2242cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2243cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2244cfd3d8dcSGreg Alexander {} 2245cfd3d8dcSGreg Alexander }; 224634cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2247cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2248cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2249cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2250cfd3d8dcSGreg Alexander {} 2251cfd3d8dcSGreg Alexander }; 2252cfd3d8dcSGreg Alexander 2253cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2254cfd3d8dcSGreg Alexander if (present) { 2255cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2256cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2257cfd3d8dcSGreg Alexander } else { 2258cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2259cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2260cfd3d8dcSGreg Alexander } 2261cfd3d8dcSGreg Alexander } 2262cfd3d8dcSGreg Alexander 2263a1d6906eSDavid Henningsson 2264a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2265a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2266a1d6906eSDavid Henningsson { 2267a1d6906eSDavid Henningsson unsigned int present; 2268a1d6906eSDavid Henningsson 2269a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2270a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2271a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2272a1d6906eSDavid Henningsson present ? 1 : 0); 2273a1d6906eSDavid Henningsson } 2274a1d6906eSDavid Henningsson 2275a1d6906eSDavid Henningsson 2276048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2277048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2278048e78a5SDavid Henningsson { 2279048e78a5SDavid Henningsson unsigned int present; 2280048e78a5SDavid Henningsson 2281048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2282048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2283048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2284048e78a5SDavid Henningsson present ? 1 : 3); 2285048e78a5SDavid Henningsson } 2286048e78a5SDavid Henningsson 2287048e78a5SDavid Henningsson 22887b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22897b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22907b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22917b2bfdbcSJens Taprogge { 22927b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22937b2bfdbcSJens Taprogge 229434cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22957b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22967b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22977b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22987b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22997b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23007b2bfdbcSJens Taprogge {} 23017b2bfdbcSJens Taprogge }; 230234cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 23037b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23047b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23057b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23067b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23077b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23087b2bfdbcSJens Taprogge {} 23097b2bfdbcSJens Taprogge }; 231034cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 23117b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23127b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23137b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23147b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23157b2bfdbcSJens Taprogge {} 23167b2bfdbcSJens Taprogge }; 23177b2bfdbcSJens Taprogge 23187b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23197b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23207b2bfdbcSJens Taprogge if (ext_present) { 23217b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23227b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23237b2bfdbcSJens Taprogge } else if (dock_present) { 23247b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23257b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23267b2bfdbcSJens Taprogge } else { 23277b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23287b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23297b2bfdbcSJens Taprogge } 23307b2bfdbcSJens Taprogge } 23317b2bfdbcSJens Taprogge 23320fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23330fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23340fb67e98SDaniel Drake { 23350fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23360fb67e98SDaniel Drake unsigned int portA, portD; 23370fb67e98SDaniel Drake 23380fb67e98SDaniel Drake /* Port A */ 2339d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23400fb67e98SDaniel Drake 23410fb67e98SDaniel Drake /* Port D */ 2342d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23430fb67e98SDaniel Drake 2344a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2345a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 23460fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23470fb67e98SDaniel Drake portA, portD, spec->hp_present); 23480fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23490fb67e98SDaniel Drake } 23500fb67e98SDaniel Drake 235102b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 235202b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 235302b6b5b6SDavid Henningsson { 235402b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 235502b6b5b6SDavid Henningsson 235602b6b5b6SDavid Henningsson if (spec->dell_vostro) 235702b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 235802b6b5b6SDavid Henningsson else if (spec->ideapad) 235902b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 236002b6b5b6SDavid Henningsson else if (spec->thinkpad) 236102b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 236202b6b5b6SDavid Henningsson else if (spec->hp_laptop) 236302b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2364a1d6906eSDavid Henningsson else if (spec->asus) 2365a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 236602b6b5b6SDavid Henningsson } 236702b6b5b6SDavid Henningsson 23680fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 236975f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23700fb67e98SDaniel Drake { 2371c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23720fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23730fb67e98SDaniel Drake switch (res >> 26) { 23740fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23750fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23760fb67e98SDaniel Drake break; 23770fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2378c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2379c4cfe66cSDaniel Drake if (!spec->dc_enable) 238075f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23810fb67e98SDaniel Drake break; 23820fb67e98SDaniel Drake } 23830fb67e98SDaniel Drake } 23840fb67e98SDaniel Drake 238595a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 238602b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 238795a618bdSEinar Rünkaru { 238802b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 238995a618bdSEinar Rünkaru switch (res >> 26) { 239095a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 239195a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 239295a618bdSEinar Rünkaru break; 239395a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 239402b6b5b6SDavid Henningsson cxt5066_automic(codec); 239595a618bdSEinar Rünkaru break; 239695a618bdSEinar Rünkaru } 239795a618bdSEinar Rünkaru } 239895a618bdSEinar Rünkaru 23997b2bfdbcSJens Taprogge 24000fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24010fb67e98SDaniel Drake .num_items = 5, 24020fb67e98SDaniel Drake .items = { 24030fb67e98SDaniel Drake { "0dB", 0 }, 24040fb67e98SDaniel Drake { "10dB", 1 }, 24050fb67e98SDaniel Drake { "20dB", 2 }, 24060fb67e98SDaniel Drake { "30dB", 3 }, 24070fb67e98SDaniel Drake { "40dB", 4 }, 24080fb67e98SDaniel Drake }, 24090fb67e98SDaniel Drake }; 24100fb67e98SDaniel Drake 2411cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2412c4cfe66cSDaniel Drake { 2413c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2414cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2415c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2416c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2417c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24187b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2419cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2420cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2421cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2422cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2423cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2424cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2425cfd3d8dcSGreg Alexander } 2426c4cfe66cSDaniel Drake } 2427c4cfe66cSDaniel Drake 24280fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24290fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24300fb67e98SDaniel Drake { 24310fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24320fb67e98SDaniel Drake } 24330fb67e98SDaniel Drake 24340fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24350fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24360fb67e98SDaniel Drake { 24370fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2438c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2439c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 24400fb67e98SDaniel Drake return 0; 24410fb67e98SDaniel Drake } 24420fb67e98SDaniel Drake 24430fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 24440fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24450fb67e98SDaniel Drake { 24460fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2447c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24480fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 24490fb67e98SDaniel Drake unsigned int idx; 24500fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 24510fb67e98SDaniel Drake if (idx >= imux->num_items) 24520fb67e98SDaniel Drake idx = imux->num_items - 1; 24530fb67e98SDaniel Drake 2454c4cfe66cSDaniel Drake spec->mic_boost = idx; 2455c4cfe66cSDaniel Drake if (!spec->dc_enable) 2456c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2457c4cfe66cSDaniel Drake return 1; 2458c4cfe66cSDaniel Drake } 24590fb67e98SDaniel Drake 2460c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2461c4cfe66cSDaniel Drake { 2462c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2463c4cfe66cSDaniel Drake /* disable gain */ 2464c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2465c4cfe66cSDaniel Drake 2466c4cfe66cSDaniel Drake /* switch to DC input */ 2467c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2468c4cfe66cSDaniel Drake {} 2469c4cfe66cSDaniel Drake }; 2470c4cfe66cSDaniel Drake 2471c4cfe66cSDaniel Drake /* configure as input source */ 2472c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2473c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2474c4cfe66cSDaniel Drake } 2475c4cfe66cSDaniel Drake 2476c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2477c4cfe66cSDaniel Drake { 2478c4cfe66cSDaniel Drake /* reconfigure input source */ 2479c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2480c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2481c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2482c4cfe66cSDaniel Drake } 2483c4cfe66cSDaniel Drake 2484c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2485c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2486c4cfe66cSDaniel Drake { 2487c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2488c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2489c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2490c4cfe66cSDaniel Drake return 0; 2491c4cfe66cSDaniel Drake } 2492c4cfe66cSDaniel Drake 2493c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2494c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2495c4cfe66cSDaniel Drake { 2496c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2497c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2498c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2499c4cfe66cSDaniel Drake 2500c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2501c4cfe66cSDaniel Drake return 0; 2502c4cfe66cSDaniel Drake 2503c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2504c4cfe66cSDaniel Drake if (dc_enable) 2505c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2506c4cfe66cSDaniel Drake else 2507c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2508c4cfe66cSDaniel Drake 2509c4cfe66cSDaniel Drake return 1; 2510c4cfe66cSDaniel Drake } 2511c4cfe66cSDaniel Drake 2512c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2513c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2514c4cfe66cSDaniel Drake { 2515c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2516c4cfe66cSDaniel Drake } 2517c4cfe66cSDaniel Drake 2518c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2519c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2520c4cfe66cSDaniel Drake { 2521c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2522c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2523c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2524c4cfe66cSDaniel Drake return 0; 2525c4cfe66cSDaniel Drake } 2526c4cfe66cSDaniel Drake 2527c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2528c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2529c4cfe66cSDaniel Drake { 2530c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2531c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2532c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2533c4cfe66cSDaniel Drake unsigned int idx; 2534c4cfe66cSDaniel Drake 2535c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2536c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2537c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2538c4cfe66cSDaniel Drake 2539c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2540c4cfe66cSDaniel Drake if (spec->dc_enable) 2541c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25420fb67e98SDaniel Drake return 1; 25430fb67e98SDaniel Drake } 25440fb67e98SDaniel Drake 254575f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 254675f8991dSDaniel Drake { 254775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 254875f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 254975f8991dSDaniel Drake * recording LED comes on. */ 255075f8991dSDaniel Drake spec->recording = 1; 255175f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 255275f8991dSDaniel Drake } 255375f8991dSDaniel Drake 255475f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 255575f8991dSDaniel Drake { 255675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 255775f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 255875f8991dSDaniel Drake /* disable external mic, port B */ 255975f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 256075f8991dSDaniel Drake 256175f8991dSDaniel Drake /* disble internal mic, port C */ 256275f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2563c4cfe66cSDaniel Drake 2564c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2565c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 256675f8991dSDaniel Drake {}, 256775f8991dSDaniel Drake }; 256875f8991dSDaniel Drake 256975f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 257075f8991dSDaniel Drake spec->recording = 0; 257175f8991dSDaniel Drake } 257275f8991dSDaniel Drake 2573f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 257434cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2575f6a2491cSAndy Robinson int num_pins) 2576f6a2491cSAndy Robinson { 2577f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2578f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2579f6a2491cSAndy Robinson int i; 2580f6a2491cSAndy Robinson 2581f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2582f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2583f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2584f6a2491cSAndy Robinson continue; 2585f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2586f6a2491cSAndy Robinson continue; 2587f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2588f6a2491cSAndy Robinson nid_loc++; 2589f6a2491cSAndy Robinson else 2590f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2591f6a2491cSAndy Robinson } 2592f6a2491cSAndy Robinson } 2593f6a2491cSAndy Robinson 259434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25950fb67e98SDaniel Drake .num_items = 4, 25960fb67e98SDaniel Drake .items = { 25970fb67e98SDaniel Drake { "Mic B", 0 }, 25980fb67e98SDaniel Drake { "Mic C", 1 }, 25990fb67e98SDaniel Drake { "Mic E", 2 }, 26000fb67e98SDaniel Drake { "Mic F", 3 }, 26010fb67e98SDaniel Drake }, 26020fb67e98SDaniel Drake }; 26030fb67e98SDaniel Drake 260434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26050fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26060fb67e98SDaniel Drake .values = { 26070fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26080fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26090fb67e98SDaniel Drake 0 26100fb67e98SDaniel Drake }, 26110fb67e98SDaniel Drake }; 26120fb67e98SDaniel Drake 261334cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26140fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26150fb67e98SDaniel Drake .values = { 26160fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26170fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26180fb67e98SDaniel Drake 0 26190fb67e98SDaniel Drake }, 26200fb67e98SDaniel Drake }; 26210fb67e98SDaniel Drake 262234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 26230fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26240fb67e98SDaniel Drake {} 26250fb67e98SDaniel Drake }; 26260fb67e98SDaniel Drake 262734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26280fb67e98SDaniel Drake { 26290fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26300fb67e98SDaniel Drake .name = "Master Playback Volume", 26310fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26320fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26330fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26345e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26350fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26360fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26370fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26380fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26390fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26400fb67e98SDaniel Drake .private_value = 26410fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26420fb67e98SDaniel Drake }, 26430fb67e98SDaniel Drake {} 26440fb67e98SDaniel Drake }; 26450fb67e98SDaniel Drake 264634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2647c4cfe66cSDaniel Drake { 2648c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2649c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2650c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2651c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2652c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2653c4cfe66cSDaniel Drake }, 2654c4cfe66cSDaniel Drake { 2655c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2656c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2657c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2658c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2659c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2660c4cfe66cSDaniel Drake }, 2661c4cfe66cSDaniel Drake {} 2662c4cfe66cSDaniel Drake }; 2663c4cfe66cSDaniel Drake 266434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 26650fb67e98SDaniel Drake { 26660fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26670fb67e98SDaniel Drake .name = "Master Playback Switch", 26680fb67e98SDaniel Drake .info = cxt_eapd_info, 26690fb67e98SDaniel Drake .get = cxt_eapd_get, 26700fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26710fb67e98SDaniel Drake .private_value = 0x1d, 26720fb67e98SDaniel Drake }, 26730fb67e98SDaniel Drake 26740fb67e98SDaniel Drake { 26750fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2676c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26770fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26780fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26790fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26800fb67e98SDaniel Drake }, 26810fb67e98SDaniel Drake 26820fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26830fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26840fb67e98SDaniel Drake {} 26850fb67e98SDaniel Drake }; 26860fb67e98SDaniel Drake 268734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2688254bba6aSEinar Rünkaru { 2689254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 269028c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2691254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2692254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2693254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2694254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2695254bba6aSEinar Rünkaru }, 2696254bba6aSEinar Rünkaru {} 2697254bba6aSEinar Rünkaru }; 2698254bba6aSEinar Rünkaru 269934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 27000fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27010fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27020fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27030fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27040fb67e98SDaniel Drake 27050fb67e98SDaniel Drake /* Speakers */ 27060fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27070fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27080fb67e98SDaniel Drake 27090fb67e98SDaniel Drake /* HP, Amp */ 27100fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27110fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27120fb67e98SDaniel Drake 27130fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27140fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27150fb67e98SDaniel Drake 27160fb67e98SDaniel Drake /* DAC1 */ 27170fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27180fb67e98SDaniel Drake 27190fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27200fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27210fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27220fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27230fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27240fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27250fb67e98SDaniel Drake 27260fb67e98SDaniel Drake /* no digital microphone support yet */ 27270fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27280fb67e98SDaniel Drake 27290fb67e98SDaniel Drake /* Audio input selector */ 27300fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27310fb67e98SDaniel Drake 27320fb67e98SDaniel Drake /* SPDIF route: PCM */ 27330fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27340fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27350fb67e98SDaniel Drake 27360fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27370fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27380fb67e98SDaniel Drake 27390fb67e98SDaniel Drake /* EAPD */ 27400fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27410fb67e98SDaniel Drake 27420fb67e98SDaniel Drake /* not handling these yet */ 27430fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27440fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27450fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27460fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27470fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27480fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27490fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27500fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27510fb67e98SDaniel Drake { } /* end */ 27520fb67e98SDaniel Drake }; 27530fb67e98SDaniel Drake 275434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27550fb67e98SDaniel Drake /* Port A: headphones */ 27560fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27570fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27580fb67e98SDaniel Drake 27590fb67e98SDaniel Drake /* Port B: external microphone */ 276075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27610fb67e98SDaniel Drake 27620fb67e98SDaniel Drake /* Port C: internal microphone */ 276375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27640fb67e98SDaniel Drake 27650fb67e98SDaniel Drake /* Port D: unused */ 27660fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27670fb67e98SDaniel Drake 27680fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27690fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27700fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27710fb67e98SDaniel Drake 2772c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27730fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27740fb67e98SDaniel Drake 27750fb67e98SDaniel Drake /* Port G: internal speakers */ 27760fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27770fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27780fb67e98SDaniel Drake 27790fb67e98SDaniel Drake /* DAC1 */ 27800fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27810fb67e98SDaniel Drake 27820fb67e98SDaniel Drake /* DAC2: unused */ 27830fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27840fb67e98SDaniel Drake 27850fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27860fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27870fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27880fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27890fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27900fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27910fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27920fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27930fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27940fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27950fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27960fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27970fb67e98SDaniel Drake 27980fb67e98SDaniel Drake /* Disable digital microphone port */ 27990fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28000fb67e98SDaniel Drake 28010fb67e98SDaniel Drake /* Audio input selectors */ 28020fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28030fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28040fb67e98SDaniel Drake 28050fb67e98SDaniel Drake /* Disable SPDIF */ 28060fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28070fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28080fb67e98SDaniel Drake 28090fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28100fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28110fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28120fb67e98SDaniel Drake { } /* end */ 28130fb67e98SDaniel Drake }; 28140fb67e98SDaniel Drake 281534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 281695a618bdSEinar Rünkaru /* Port A: headphones */ 281795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 281895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 281995a618bdSEinar Rünkaru 282095a618bdSEinar Rünkaru /* Port B: external microphone */ 282195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282295a618bdSEinar Rünkaru 282395a618bdSEinar Rünkaru /* Port C: unused */ 282495a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282595a618bdSEinar Rünkaru 282695a618bdSEinar Rünkaru /* Port D: unused */ 282795a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282895a618bdSEinar Rünkaru 282995a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 283095a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 283195a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 283295a618bdSEinar Rünkaru 283395a618bdSEinar Rünkaru /* Port F: unused */ 283495a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 283595a618bdSEinar Rünkaru 283695a618bdSEinar Rünkaru /* Port G: internal speakers */ 283795a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 283895a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 283995a618bdSEinar Rünkaru 284095a618bdSEinar Rünkaru /* DAC1 */ 284195a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 284295a618bdSEinar Rünkaru 284395a618bdSEinar Rünkaru /* DAC2: unused */ 284495a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 284595a618bdSEinar Rünkaru 284695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 284795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 284895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 284995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 285095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 285195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 285295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 285395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 285495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 285595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 285695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 285795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 285895a618bdSEinar Rünkaru 285995a618bdSEinar Rünkaru /* Digital microphone port */ 286095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 286195a618bdSEinar Rünkaru 286295a618bdSEinar Rünkaru /* Audio input selectors */ 286395a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 286495a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 286595a618bdSEinar Rünkaru 286695a618bdSEinar Rünkaru /* Disable SPDIF */ 286795a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286895a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286995a618bdSEinar Rünkaru 287095a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 287195a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 287295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 287395a618bdSEinar Rünkaru { } /* end */ 287495a618bdSEinar Rünkaru }; 287595a618bdSEinar Rünkaru 287634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2877cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2878cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2879cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2880cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2881cfd3d8dcSGreg Alexander 2882cfd3d8dcSGreg Alexander /* Speakers */ 2883cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2884cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2885cfd3d8dcSGreg Alexander 2886cfd3d8dcSGreg Alexander /* HP, Amp */ 2887cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2888cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2889cfd3d8dcSGreg Alexander 2890cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2891cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2892cfd3d8dcSGreg Alexander 2893cfd3d8dcSGreg Alexander /* DAC1 */ 2894cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2895cfd3d8dcSGreg Alexander 2896cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2897cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2898cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2899cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2900cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2901cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2902cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2903cfd3d8dcSGreg Alexander 2904cfd3d8dcSGreg Alexander /* Audio input selector */ 2905cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2906cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2907cfd3d8dcSGreg Alexander 2908cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2909cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2910cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2911cfd3d8dcSGreg Alexander 2912cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2913cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2914cfd3d8dcSGreg Alexander 2915cfd3d8dcSGreg Alexander /* internal microphone */ 291628c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2917cfd3d8dcSGreg Alexander 2918cfd3d8dcSGreg Alexander /* EAPD */ 2919cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2920cfd3d8dcSGreg Alexander 2921cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2922cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2923cfd3d8dcSGreg Alexander { } /* end */ 2924cfd3d8dcSGreg Alexander }; 2925cfd3d8dcSGreg Alexander 292634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29277b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29287b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29297b2bfdbcSJens Taprogge 29307b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29317b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29327b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29337b2bfdbcSJens Taprogge 29347b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29357b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29367b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29377b2bfdbcSJens Taprogge 29387b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29397b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29407b2bfdbcSJens Taprogge 29417b2bfdbcSJens Taprogge /* Port C: Mic */ 29427b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29437b2bfdbcSJens Taprogge 29447b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29457b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29467b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29477b2bfdbcSJens Taprogge 29487b2bfdbcSJens Taprogge /* DAC1 */ 29497b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29507b2bfdbcSJens Taprogge 29517b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29527b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29537b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29547b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29557b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29567b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29577b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29587b2bfdbcSJens Taprogge 29597b2bfdbcSJens Taprogge /* Audio input selector */ 29607b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29617b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29627b2bfdbcSJens Taprogge 29637b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29647b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29657b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29667b2bfdbcSJens Taprogge 29677b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29687b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29697b2bfdbcSJens Taprogge 29707b2bfdbcSJens Taprogge /* internal microphone */ 297128c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29727b2bfdbcSJens Taprogge 29737b2bfdbcSJens Taprogge /* EAPD */ 29747b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29757b2bfdbcSJens Taprogge 29767b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29777b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29787b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29797b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29807b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29817b2bfdbcSJens Taprogge { } /* end */ 29827b2bfdbcSJens Taprogge }; 29837b2bfdbcSJens Taprogge 298434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29850fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29860fb67e98SDaniel Drake { } /* end */ 29870fb67e98SDaniel Drake }; 29880fb67e98SDaniel Drake 2989048e78a5SDavid Henningsson 299034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2991048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2992048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2993048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2994048e78a5SDavid Henningsson { } /* end */ 2995048e78a5SDavid Henningsson }; 2996048e78a5SDavid Henningsson 29970fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29980fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29990fb67e98SDaniel Drake { 30000fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30010fb67e98SDaniel Drake conexant_init(codec); 30020fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30030fb67e98SDaniel Drake cxt5066_hp_automute(codec); 300402b6b5b6SDavid Henningsson cxt5066_automic(codec); 30050fb67e98SDaniel Drake } 3006c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30070fb67e98SDaniel Drake return 0; 30080fb67e98SDaniel Drake } 30090fb67e98SDaniel Drake 301075f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 301175f8991dSDaniel Drake { 3012c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 301375f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 301475f8991dSDaniel Drake conexant_init(codec); 301575f8991dSDaniel Drake cxt5066_hp_automute(codec); 3016c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3017c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 301875f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3019c4cfe66cSDaniel Drake } else { 3020c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3021c4cfe66cSDaniel Drake } 302275f8991dSDaniel Drake return 0; 302375f8991dSDaniel Drake } 302475f8991dSDaniel Drake 30250fb67e98SDaniel Drake enum { 30260fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30270fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30280fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 30291feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 3030cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30317b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3032a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 3033048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 3034fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 30350fb67e98SDaniel Drake CXT5066_MODELS 30360fb67e98SDaniel Drake }; 30370fb67e98SDaniel Drake 3038ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 30390fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30400fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30410fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30421feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3043cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30447b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3045a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 3046048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 3047fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 30480fb67e98SDaniel Drake }; 30490fb67e98SDaniel Drake 305034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30519966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 305200cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30531feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30548a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3055ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30561feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3057231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3058ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3059ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3060048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3061f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3062a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3063f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 30642ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3065c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30665637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30675637edb2SDavid Henningsson CXT5066_LAPTOP), 30685637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30694d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3070ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 307119593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 30727b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3073ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 307484012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3075b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3076d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3077a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3078af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 307922f21d51SDavid Henningsson SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ 30807ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 30810fb67e98SDaniel Drake {} 30820fb67e98SDaniel Drake }; 30830fb67e98SDaniel Drake 30840fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30850fb67e98SDaniel Drake { 30860fb67e98SDaniel Drake struct conexant_spec *spec; 30870fb67e98SDaniel Drake int board_config; 30880fb67e98SDaniel Drake 3089fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3090fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3091fea4a4f9STakashi Iwai if (board_config < 0) 3092c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3093fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3094fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3095fea4a4f9STakashi Iwai 30960fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30970fb67e98SDaniel Drake if (!spec) 30980fb67e98SDaniel Drake return -ENOMEM; 30990fb67e98SDaniel Drake codec->spec = spec; 31000fb67e98SDaniel Drake 31010fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 310275f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31030fb67e98SDaniel Drake 31040fb67e98SDaniel Drake spec->dell_automute = 0; 31050fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31060fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31070fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3108f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3109f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 31100fb67e98SDaniel Drake spec->num_adc_nids = 1; 31110fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31120fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31130fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31140fb67e98SDaniel Drake 31150fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31160fb67e98SDaniel Drake 31170fb67e98SDaniel Drake spec->num_init_verbs = 1; 31180fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31190fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31200fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31210fb67e98SDaniel Drake spec->cur_adc = 0; 31220fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31230fb67e98SDaniel Drake 31243507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31253507e2a8STakashi Iwai 31260fb67e98SDaniel Drake switch (board_config) { 31270fb67e98SDaniel Drake default: 31280fb67e98SDaniel Drake case CXT5066_LAPTOP: 31290fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31300fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31310fb67e98SDaniel Drake break; 31320fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31330fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31340fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31350fb67e98SDaniel Drake 31360fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31370fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31380fb67e98SDaniel Drake spec->num_init_verbs++; 31390fb67e98SDaniel Drake spec->dell_automute = 1; 31400fb67e98SDaniel Drake break; 3141a1d6906eSDavid Henningsson case CXT5066_ASUS: 3142048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3143048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 314402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3145048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3146048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3147048e78a5SDavid Henningsson spec->num_init_verbs++; 3148a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3149a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3150048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3151048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3152048e78a5SDavid Henningsson /* no S/PDIF out */ 3153f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3154048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3155048e78a5SDavid Henningsson /* input source automatically selected */ 3156048e78a5SDavid Henningsson spec->input_mux = NULL; 3157048e78a5SDavid Henningsson spec->port_d_mode = 0; 3158048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3159048e78a5SDavid Henningsson break; 3160048e78a5SDavid Henningsson 31610fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 316275f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 316375f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31640fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31650fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3166c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31670fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31680fb67e98SDaniel Drake spec->port_d_mode = 0; 3169c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31700fb67e98SDaniel Drake 31710fb67e98SDaniel Drake /* no S/PDIF out */ 31720fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31730fb67e98SDaniel Drake 31740fb67e98SDaniel Drake /* input source automatically selected */ 31750fb67e98SDaniel Drake spec->input_mux = NULL; 317675f8991dSDaniel Drake 317775f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 317875f8991dSDaniel Drake * at the right time */ 317975f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 318075f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31810fb67e98SDaniel Drake break; 31821feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 318375f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 318402b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 318595a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 318695a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 318795a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3188254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 318995a618bdSEinar Rünkaru spec->port_d_mode = 0; 3190254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3191c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 319295a618bdSEinar Rünkaru 319395a618bdSEinar Rünkaru /* no S/PDIF out */ 319495a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 319595a618bdSEinar Rünkaru 319695a618bdSEinar Rünkaru /* input source automatically selected */ 319795a618bdSEinar Rünkaru spec->input_mux = NULL; 319895a618bdSEinar Rünkaru break; 3199cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3200cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 320102b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3202cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3203cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3204cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3205cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3206cfd3d8dcSGreg Alexander spec->ideapad = 1; 3207cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3208cfd3d8dcSGreg Alexander 3209cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3210cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3211cfd3d8dcSGreg Alexander 3212cfd3d8dcSGreg Alexander /* input source automatically selected */ 3213cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3214cfd3d8dcSGreg Alexander break; 32157b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32167b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 321702b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 32187b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32197b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32207b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32217b2bfdbcSJens Taprogge spec->thinkpad = 1; 32227b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32237b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32247b2bfdbcSJens Taprogge 32257b2bfdbcSJens Taprogge /* no S/PDIF out */ 32267b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32277b2bfdbcSJens Taprogge 32287b2bfdbcSJens Taprogge /* input source automatically selected */ 32297b2bfdbcSJens Taprogge spec->input_mux = NULL; 32307b2bfdbcSJens Taprogge break; 32310fb67e98SDaniel Drake } 32320fb67e98SDaniel Drake 32333507e2a8STakashi Iwai if (spec->beep_amp) 32343507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32353507e2a8STakashi Iwai 32360fb67e98SDaniel Drake return 0; 32370fb67e98SDaniel Drake } 3238461e2c78STakashi Iwai 3239461e2c78STakashi Iwai /* 3240f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3241f2e5731dSTakashi Iwai */ 3242f2e5731dSTakashi Iwai 32436764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 32446764bcefSTakashi Iwai struct hda_codec *codec, 32456764bcefSTakashi Iwai unsigned int stream_tag, 32466764bcefSTakashi Iwai unsigned int format, 32476764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32486764bcefSTakashi Iwai { 32496764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 325047ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 32516764bcefSTakashi Iwai if (spec->adc_switching) { 32526764bcefSTakashi Iwai spec->cur_adc = adc; 32536764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32546764bcefSTakashi Iwai spec->cur_adc_format = format; 32556764bcefSTakashi Iwai } 32566764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32576764bcefSTakashi Iwai return 0; 32586764bcefSTakashi Iwai } 32596764bcefSTakashi Iwai 32606764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 32616764bcefSTakashi Iwai struct hda_codec *codec, 32626764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32636764bcefSTakashi Iwai { 32646764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32656764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 32666764bcefSTakashi Iwai spec->cur_adc = 0; 32676764bcefSTakashi Iwai return 0; 32686764bcefSTakashi Iwai } 32696764bcefSTakashi Iwai 32706764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32716764bcefSTakashi Iwai .substreams = 1, 32726764bcefSTakashi Iwai .channels_min = 2, 32736764bcefSTakashi Iwai .channels_max = 2, 32746764bcefSTakashi Iwai .nid = 0, /* fill later */ 32756764bcefSTakashi Iwai .ops = { 32766764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32776764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32786764bcefSTakashi Iwai }, 32796764bcefSTakashi Iwai }; 32806764bcefSTakashi Iwai 328134cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3282f2e5731dSTakashi Iwai 32838d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 32848d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3285f2e5731dSTakashi Iwai 3286f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3287f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3288f2e5731dSTakashi Iwai * not found 3289f2e5731dSTakashi Iwai */ 3290f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3291f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3292f2e5731dSTakashi Iwai { 3293f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3294f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3295f2e5731dSTakashi Iwai 3296f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3297f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3298f2e5731dSTakashi Iwai ret = dacs[i]; 3299f2e5731dSTakashi Iwai break; 3300f2e5731dSTakashi Iwai } 3301f2e5731dSTakashi Iwai } 3302f2e5731dSTakashi Iwai if (!ret) 3303f2e5731dSTakashi Iwai return 0; 3304f2e5731dSTakashi Iwai if (--nums > 0) 3305f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3306f2e5731dSTakashi Iwai *num_dacs = nums; 3307f2e5731dSTakashi Iwai return ret; 3308f2e5731dSTakashi Iwai } 3309f2e5731dSTakashi Iwai 3310f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3311f2e5731dSTakashi Iwai 33121f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 33131f015f5fSTakashi Iwai 3314f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3315f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3316f2e5731dSTakashi Iwai { 3317f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3318f2e5731dSTakashi Iwai int nums = 0; 3319f2e5731dSTakashi Iwai 3320f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3321f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3322f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3323f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3324f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3325f2e5731dSTakashi Iwai dacs[nums++] = nid; 3326f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3327f2e5731dSTakashi Iwai break; 3328f2e5731dSTakashi Iwai } 3329f2e5731dSTakashi Iwai } 3330f2e5731dSTakashi Iwai return nums; 3331f2e5731dSTakashi Iwai } 3332f2e5731dSTakashi Iwai 3333f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3334f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3335f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3336468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3337468c5458SDavid Henningsson int type) 3338f2e5731dSTakashi Iwai { 3339468c5458SDavid Henningsson int i, start = nums; 3340f2e5731dSTakashi Iwai 3341468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3342f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3343f2e5731dSTakashi Iwai filled[nums].type = type; 3344f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3345468c5458SDavid Henningsson if (filled[nums].dac) 3346468c5458SDavid Henningsson continue; 3347468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3348468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3349468c5458SDavid Henningsson continue; 3350468c5458SDavid Henningsson } 3351468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 33521f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3353468c5458SDavid Henningsson continue; 3354468c5458SDavid Henningsson } 3355468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3356f2e5731dSTakashi Iwai } 3357f2e5731dSTakashi Iwai return nums; 3358f2e5731dSTakashi Iwai } 3359f2e5731dSTakashi Iwai 3360f2e5731dSTakashi Iwai /* parse analog output paths */ 3361f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3362f2e5731dSTakashi Iwai { 3363f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3364f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3365f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3366f2e5731dSTakashi Iwai int i, j, nums, rest; 3367f2e5731dSTakashi Iwai 3368f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3369f2e5731dSTakashi Iwai /* parse all analog output pins */ 3370f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3371468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3372f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3373468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3374468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3375f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3376468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3377468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3378f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3379f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3380f2e5731dSTakashi Iwai /* fill multiout struct */ 3381f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3382f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 33831f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3384f2e5731dSTakashi Iwai continue; 3385f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3386f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3387f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3388f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3389f2e5731dSTakashi Iwai break; 3390f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3391f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3392f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3393f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3394f2e5731dSTakashi Iwai break; 3395f2e5731dSTakashi Iwai } 3396f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3397f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3398f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3399f2e5731dSTakashi Iwai break; 3400f2e5731dSTakashi Iwai } 3401f2e5731dSTakashi Iwai break; 3402f2e5731dSTakashi Iwai } 3403f2e5731dSTakashi Iwai } 3404f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 340589724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3406f2e5731dSTakashi Iwai 340703697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 340803697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3409f2e5731dSTakashi Iwai spec->auto_mute = 1; 341003697e2aSTakashi Iwai break; 341103697e2aSTakashi Iwai } 341203697e2aSTakashi Iwai } 3413e2df82ffSTakashi Iwai if (spec->auto_mute && 3414e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3415e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 341603697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 341703697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 341803697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 341903697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 342003697e2aSTakashi Iwai spec->detect_line = 1; 342103697e2aSTakashi Iwai break; 342203697e2aSTakashi Iwai } 342303697e2aSTakashi Iwai } 342403697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 342503697e2aSTakashi Iwai } 342603697e2aSTakashi Iwai 3427f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3428f2e5731dSTakashi Iwai } 3429f2e5731dSTakashi Iwai 3430da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3431da339866STakashi Iwai hda_nid_t *pins, bool on); 3432da339866STakashi Iwai 343303697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 343403697e2aSTakashi Iwai hda_nid_t *pins, bool on) 343503697e2aSTakashi Iwai { 3436254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 343703697e2aSTakashi Iwai int i; 343803697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 343903697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 344003697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 344103697e2aSTakashi Iwai on ? PIN_OUT : 0); 3442254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 344303697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 344403697e2aSTakashi Iwai } 344503697e2aSTakashi Iwai 344603697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 344703697e2aSTakashi Iwai { 344803697e2aSTakashi Iwai int i, present = 0; 344903697e2aSTakashi Iwai 345003697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 345103697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 345203697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 345303697e2aSTakashi Iwai break; 345403697e2aSTakashi Iwai snd_hda_input_jack_report(codec, nid); 345503697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 345603697e2aSTakashi Iwai } 345703697e2aSTakashi Iwai return present; 345803697e2aSTakashi Iwai } 345903697e2aSTakashi Iwai 3460f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 346103697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 346203697e2aSTakashi Iwai { 346303697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 346403697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3465e2df82ffSTakashi Iwai int on = 1; 346603697e2aSTakashi Iwai 3467e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3468254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3469e2df82ffSTakashi Iwai if (spec->auto_mute) 3470e2df82ffSTakashi Iwai on = spec->hp_present; 347103697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3472254f2968STakashi Iwai } 3473254f2968STakashi Iwai 3474e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3475e2df82ffSTakashi Iwai if (spec->auto_mute) 3476e2df82ffSTakashi Iwai on = !(spec->hp_present || 3477e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3478e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 347903697e2aSTakashi Iwai 348003697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 348103697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 348203697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 348303697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 348403697e2aSTakashi Iwai return; 3485e2df82ffSTakashi Iwai if (spec->auto_mute) { 3486e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3487e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3488e2df82ffSTakashi Iwai spec->automute_lines) 3489e2df82ffSTakashi Iwai on = !spec->hp_present; 349003697e2aSTakashi Iwai else 3491e2df82ffSTakashi Iwai on = 1; 3492e2df82ffSTakashi Iwai } 3493e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 349403697e2aSTakashi Iwai } 349503697e2aSTakashi Iwai 3496f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3497f2e5731dSTakashi Iwai { 3498f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3499f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3500f2e5731dSTakashi Iwai 3501f2e5731dSTakashi Iwai if (!spec->auto_mute) 3502f2e5731dSTakashi Iwai return; 350303697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 350403697e2aSTakashi Iwai cx_auto_update_speakers(codec); 350503697e2aSTakashi Iwai } 350603697e2aSTakashi Iwai 350703697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 350803697e2aSTakashi Iwai { 350903697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 351003697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 351103697e2aSTakashi Iwai 351203697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 351303697e2aSTakashi Iwai return; 351403697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 351503697e2aSTakashi Iwai cfg->line_out_pins); 351603697e2aSTakashi Iwai cx_auto_update_speakers(codec); 351703697e2aSTakashi Iwai } 351803697e2aSTakashi Iwai 351903697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 352003697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 352103697e2aSTakashi Iwai { 352203697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 352303697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 352403697e2aSTakashi Iwai static const char * const texts2[] = { 352503697e2aSTakashi Iwai "Disabled", "Enabled" 352603697e2aSTakashi Iwai }; 352703697e2aSTakashi Iwai static const char * const texts3[] = { 352803697e2aSTakashi Iwai "Disabled", "Speaker Only", "Line-Out+Speaker" 352903697e2aSTakashi Iwai }; 353003697e2aSTakashi Iwai const char * const *texts; 353103697e2aSTakashi Iwai 353203697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 353303697e2aSTakashi Iwai uinfo->count = 1; 353403697e2aSTakashi Iwai if (spec->automute_hp_lo) { 353503697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 353603697e2aSTakashi Iwai texts = texts3; 353703697e2aSTakashi Iwai } else { 353803697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 353903697e2aSTakashi Iwai texts = texts2; 354003697e2aSTakashi Iwai } 354103697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 354203697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 354303697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 354403697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 354503697e2aSTakashi Iwai return 0; 354603697e2aSTakashi Iwai } 354703697e2aSTakashi Iwai 354803697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 354903697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 355003697e2aSTakashi Iwai { 355103697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 355203697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 355303697e2aSTakashi Iwai unsigned int val; 355403697e2aSTakashi Iwai if (!spec->auto_mute) 355503697e2aSTakashi Iwai val = 0; 355603697e2aSTakashi Iwai else if (!spec->automute_lines) 355703697e2aSTakashi Iwai val = 1; 355803697e2aSTakashi Iwai else 355903697e2aSTakashi Iwai val = 2; 356003697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 356103697e2aSTakashi Iwai return 0; 356203697e2aSTakashi Iwai } 356303697e2aSTakashi Iwai 356403697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 356503697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 356603697e2aSTakashi Iwai { 356703697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 356803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 356903697e2aSTakashi Iwai 357003697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 357103697e2aSTakashi Iwai case 0: 357203697e2aSTakashi Iwai if (!spec->auto_mute) 357303697e2aSTakashi Iwai return 0; 357403697e2aSTakashi Iwai spec->auto_mute = 0; 3575f2e5731dSTakashi Iwai break; 357603697e2aSTakashi Iwai case 1: 357703697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 357803697e2aSTakashi Iwai return 0; 357903697e2aSTakashi Iwai spec->auto_mute = 1; 358003697e2aSTakashi Iwai spec->automute_lines = 0; 358103697e2aSTakashi Iwai break; 358203697e2aSTakashi Iwai case 2: 358303697e2aSTakashi Iwai if (!spec->automute_hp_lo) 358403697e2aSTakashi Iwai return -EINVAL; 358503697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 358603697e2aSTakashi Iwai return 0; 358703697e2aSTakashi Iwai spec->auto_mute = 1; 358803697e2aSTakashi Iwai spec->automute_lines = 1; 358903697e2aSTakashi Iwai break; 359003697e2aSTakashi Iwai default: 359103697e2aSTakashi Iwai return -EINVAL; 3592f2e5731dSTakashi Iwai } 359303697e2aSTakashi Iwai cx_auto_update_speakers(codec); 359403697e2aSTakashi Iwai return 1; 3595f2e5731dSTakashi Iwai } 359603697e2aSTakashi Iwai 359703697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 359803697e2aSTakashi Iwai { 359903697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 360003697e2aSTakashi Iwai .name = "Auto-Mute Mode", 360103697e2aSTakashi Iwai .info = cx_automute_mode_info, 360203697e2aSTakashi Iwai .get = cx_automute_mode_get, 360303697e2aSTakashi Iwai .put = cx_automute_mode_put, 360403697e2aSTakashi Iwai }, 360503697e2aSTakashi Iwai { } 360603697e2aSTakashi Iwai }; 3607f2e5731dSTakashi Iwai 36086764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 36096764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 36106764bcefSTakashi Iwai { 36116764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36126764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36136764bcefSTakashi Iwai 36146764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 36156764bcefSTakashi Iwai } 36166764bcefSTakashi Iwai 36176764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 36186764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36196764bcefSTakashi Iwai { 36206764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36216764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36226764bcefSTakashi Iwai 36236764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 36246764bcefSTakashi Iwai return 0; 36256764bcefSTakashi Iwai } 36266764bcefSTakashi Iwai 36275c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 36285c9887e0STakashi Iwai * if do_select is set, actually select the route. 36295c9887e0STakashi Iwai */ 36305c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3631cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3632cf27f29aSTakashi Iwai bool do_select, int depth) 36335c9887e0STakashi Iwai { 36345c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 36355c9887e0STakashi Iwai int i, nums; 36365c9887e0STakashi Iwai 3637cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3638cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3639cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3640cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3641cf27f29aSTakashi Iwai break; 3642cf27f29aSTakashi Iwai default: 3643cf27f29aSTakashi Iwai return -1; 3644cf27f29aSTakashi Iwai } 3645cf27f29aSTakashi Iwai 36465c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 36475c9887e0STakashi Iwai for (i = 0; i < nums; i++) 36485c9887e0STakashi Iwai if (conn[i] == pin) { 36495c9887e0STakashi Iwai if (do_select) 36505c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36515c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3652cf27f29aSTakashi Iwai if (srcp) 3653cf27f29aSTakashi Iwai *srcp = mux; 36545c9887e0STakashi Iwai return i; 36555c9887e0STakashi Iwai } 36565c9887e0STakashi Iwai depth++; 36575c9887e0STakashi Iwai if (depth == 2) 36585c9887e0STakashi Iwai return -1; 36595c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3660cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 36615c9887e0STakashi Iwai do_select, depth); 36625c9887e0STakashi Iwai if (ret >= 0) { 36635c9887e0STakashi Iwai if (do_select) 36645c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36655c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3666cf27f29aSTakashi Iwai return i; 36675c9887e0STakashi Iwai } 36685c9887e0STakashi Iwai } 36695c9887e0STakashi Iwai return -1; 36705c9887e0STakashi Iwai } 36715c9887e0STakashi Iwai 36725c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36735c9887e0STakashi Iwai hda_nid_t pin) 36745c9887e0STakashi Iwai { 3675cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36765c9887e0STakashi Iwai } 36775c9887e0STakashi Iwai 36785c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 36795c9887e0STakashi Iwai hda_nid_t pin) 36805c9887e0STakashi Iwai { 3681cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 36825c9887e0STakashi Iwai } 36835c9887e0STakashi Iwai 36846764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 36856764bcefSTakashi Iwai const struct hda_input_mux *imux, 36866764bcefSTakashi Iwai unsigned int idx) 36876764bcefSTakashi Iwai { 36886764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36896764bcefSTakashi Iwai hda_nid_t adc; 3690313d2c06STakashi Iwai int changed = 1; 36916764bcefSTakashi Iwai 36926764bcefSTakashi Iwai if (!imux->num_items) 36936764bcefSTakashi Iwai return 0; 36946764bcefSTakashi Iwai if (idx >= imux->num_items) 36956764bcefSTakashi Iwai idx = imux->num_items - 1; 36966764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3697313d2c06STakashi Iwai changed = 0; 369847ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 369947ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 370047ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 37016764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 37026764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 37036764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 37046764bcefSTakashi Iwai spec->cur_adc = adc; 37056764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 37066764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 37076764bcefSTakashi Iwai spec->cur_adc_format); 37086764bcefSTakashi Iwai } 37096764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3710313d2c06STakashi Iwai return changed; 37116764bcefSTakashi Iwai } 37126764bcefSTakashi Iwai 37136764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 37146764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 37156764bcefSTakashi Iwai { 37166764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 37176764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 37186764bcefSTakashi Iwai 37196764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 37206764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 37216764bcefSTakashi Iwai } 37226764bcefSTakashi Iwai 37236764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 37246764bcefSTakashi Iwai { 37256764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 37266764bcefSTakashi Iwai .name = "Capture Source", 37276764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 37286764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 37296764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 37306764bcefSTakashi Iwai }, 37316764bcefSTakashi Iwai {} 37326764bcefSTakashi Iwai }; 37336764bcefSTakashi Iwai 373443c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 373543c1b2e9STakashi Iwai { 373643c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 373743c1b2e9STakashi Iwai if (idx < 0) 373843c1b2e9STakashi Iwai return false; 373943c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 374043c1b2e9STakashi Iwai return false; 374143c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 374243c1b2e9STakashi Iwai return true; 374343c1b2e9STakashi Iwai } 374443c1b2e9STakashi Iwai 3745f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3746f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3747f2e5731dSTakashi Iwai { 3748f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3749f2e5731dSTakashi Iwai 3750f2e5731dSTakashi Iwai if (!spec->auto_mic) 3751f2e5731dSTakashi Iwai return; 375243c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 375343c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 375443c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3755f2e5731dSTakashi Iwai } 3756f2e5731dSTakashi Iwai 3757f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3758f2e5731dSTakashi Iwai { 3759f2e5731dSTakashi Iwai int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 37601835a0f9STakashi Iwai snd_hda_jack_set_dirty(codec, nid); 3761f2e5731dSTakashi Iwai switch (res >> 26) { 3762f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3763f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 376403697e2aSTakashi Iwai break; 376503697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 376603697e2aSTakashi Iwai cx_auto_line_automute(codec); 3767f2e5731dSTakashi Iwai break; 3768f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3769f2e5731dSTakashi Iwai cx_auto_automic(codec); 3770cd372fb3STakashi Iwai snd_hda_input_jack_report(codec, nid); 3771f2e5731dSTakashi Iwai break; 3772f2e5731dSTakashi Iwai } 3773*01a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3774f2e5731dSTakashi Iwai } 3775f2e5731dSTakashi Iwai 3776f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 377743c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 377843c1b2e9STakashi Iwai * one dock-mic exist 3779f2e5731dSTakashi Iwai */ 3780f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3781f2e5731dSTakashi Iwai { 3782f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 378343c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 378443c1b2e9STakashi Iwai int i; 3785f2e5731dSTakashi Iwai 3786506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 378743c1b2e9STakashi Iwai pset[i] = -1; 378843c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 378943c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 379043c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3791b55fcb50STakashi Iwai int type, attr; 379243c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 379343c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3794b55fcb50STakashi Iwai return; /* invalid entry */ 379543c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 379643c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 379743c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 379843c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3799b55fcb50STakashi Iwai return; /* non-detectable pin */ 3800b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3801b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3802b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3803b55fcb50STakashi Iwai return; /* no valid input type */ 380443c1b2e9STakashi Iwai if (pset[attr] >= 0) 380543c1b2e9STakashi Iwai return; /* already occupied */ 380643c1b2e9STakashi Iwai pset[attr] = i; 3807f2e5731dSTakashi Iwai } 380843c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 380943c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 381043c1b2e9STakashi Iwai return; /* no input to switch*/ 3811f2e5731dSTakashi Iwai spec->auto_mic = 1; 381243c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 381343c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 381443c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3815f2e5731dSTakashi Iwai } 3816f2e5731dSTakashi Iwai 3817f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3818f2e5731dSTakashi Iwai { 3819f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3820f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3821f2e5731dSTakashi Iwai struct hda_input_mux *imux; 38226764bcefSTakashi Iwai int i, j; 3823f2e5731dSTakashi Iwai 3824f2e5731dSTakashi Iwai imux = &spec->private_imux; 3825f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 38266764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 38276764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 38285c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3829f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3830f2e5731dSTakashi Iwai if (idx >= 0) { 3831f2e5731dSTakashi Iwai const char *label; 3832f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 383347ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 383447ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 383547ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 383647ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3837f6100bb4STakashi Iwai cfg->inputs[i].pin; 3838f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 38396764bcefSTakashi Iwai break; 38406764bcefSTakashi Iwai } 3841f2e5731dSTakashi Iwai } 3842f2e5731dSTakashi Iwai } 384343c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3844f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 384576755359STakashi Iwai if (imux->num_items > 1) { 38466764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 384747ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 38486764bcefSTakashi Iwai spec->adc_switching = 1; 38496764bcefSTakashi Iwai break; 38506764bcefSTakashi Iwai } 38516764bcefSTakashi Iwai } 38526764bcefSTakashi Iwai } 3853f2e5731dSTakashi Iwai } 3854f2e5731dSTakashi Iwai 3855f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3856f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3857f2e5731dSTakashi Iwai { 3858f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3859f2e5731dSTakashi Iwai 3860f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3861f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3862f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3863f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3864f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3865f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3866f2e5731dSTakashi Iwai return nid; 3867f2e5731dSTakashi Iwai } 3868f2e5731dSTakashi Iwai } 3869f2e5731dSTakashi Iwai return 0; 3870f2e5731dSTakashi Iwai } 3871f2e5731dSTakashi Iwai 3872f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3873f2e5731dSTakashi Iwai { 3874f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3875f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3876f2e5731dSTakashi Iwai hda_nid_t nid; 3877f2e5731dSTakashi Iwai 3878f2e5731dSTakashi Iwai if (cfg->dig_outs && 3879f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3880f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3881f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3882f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3883f2e5731dSTakashi Iwai } 3884f2e5731dSTakashi Iwai 3885f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3886f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3887f2e5731dSTakashi Iwai { 3888f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3889f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3890f2e5731dSTakashi Iwai 3891f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3892f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3893f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3894f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3895f2e5731dSTakashi Iwai break; 3896f2e5731dSTakashi Iwai } 3897f2e5731dSTakashi Iwai } 3898f2e5731dSTakashi Iwai #else 3899f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3900f2e5731dSTakashi Iwai #endif 3901f2e5731dSTakashi Iwai 3902254f2968STakashi Iwai /* parse EAPDs */ 390319110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 390419110595STakashi Iwai { 390519110595STakashi Iwai struct conexant_spec *spec = codec->spec; 390619110595STakashi Iwai hda_nid_t nid, end_nid; 390719110595STakashi Iwai 390819110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 390919110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 391019110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 391119110595STakashi Iwai continue; 391219110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 391319110595STakashi Iwai continue; 391419110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 391519110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 391619110595STakashi Iwai break; 391719110595STakashi Iwai } 3918254f2968STakashi Iwai 3919254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3920254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3921254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3922254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3923254f2968STakashi Iwai * thus it might control over all pins. 3924254f2968STakashi Iwai */ 3925254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 392619110595STakashi Iwai } 392719110595STakashi Iwai 3928f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3929f2e5731dSTakashi Iwai { 3930f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3931f2e5731dSTakashi Iwai int err; 3932f2e5731dSTakashi Iwai 3933f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3934f2e5731dSTakashi Iwai if (err < 0) 3935f2e5731dSTakashi Iwai return err; 3936f2e5731dSTakashi Iwai 3937f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3938f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3939f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3940f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 394119110595STakashi Iwai cx_auto_parse_eapd(codec); 3942f2e5731dSTakashi Iwai return 0; 3943f2e5731dSTakashi Iwai } 3944f2e5731dSTakashi Iwai 3945da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3946da339866STakashi Iwai hda_nid_t *pins, bool on) 3947f2e5731dSTakashi Iwai { 3948f2e5731dSTakashi Iwai int i; 3949f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3950f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3951f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3952da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3953da339866STakashi Iwai on ? 0x02 : 0); 3954f2e5731dSTakashi Iwai } 3955f2e5731dSTakashi Iwai } 3956f2e5731dSTakashi Iwai 3957f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3958f2e5731dSTakashi Iwai hda_nid_t src) 3959f2e5731dSTakashi Iwai { 3960f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3961f2e5731dSTakashi Iwai if (idx >= 0) 3962f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3963f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3964f2e5731dSTakashi Iwai } 3965f2e5731dSTakashi Iwai 39661f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 39671f8458a2STakashi Iwai const hda_nid_t *nids) 3968f2e5731dSTakashi Iwai { 39690ad1b5b6STakashi Iwai int i, val; 3970f2e5731dSTakashi Iwai 39711f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 39721f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 39731f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 39741f8458a2STakashi Iwai continue; 39750ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 39760ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 39770ad1b5b6STakashi Iwai else 39780ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 39790ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 39800ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 39810ad1b5b6STakashi Iwai } 39821f8458a2STakashi Iwai } 3983f2e5731dSTakashi Iwai 398403697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 398503697e2aSTakashi Iwai hda_nid_t *pins, unsigned int tag) 398603697e2aSTakashi Iwai { 398703697e2aSTakashi Iwai int i; 398803697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 39891835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], tag); 399003697e2aSTakashi Iwai } 399103697e2aSTakashi Iwai 39921f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39931f8458a2STakashi Iwai { 39941f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39951f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39961f8458a2STakashi Iwai hda_nid_t nid; 39971f8458a2STakashi Iwai int i; 39981f8458a2STakashi Iwai 39991f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 4000f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 4001f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 4002f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 40031f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 40041f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 40051f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 4006f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4007f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 4008f2e5731dSTakashi Iwai if (!nid) 4009f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 40101f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 40111f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 4012f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 4013f2e5731dSTakashi Iwai } 401403697e2aSTakashi Iwai if (spec->auto_mute) { 401503697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 401603697e2aSTakashi Iwai CONEXANT_HP_EVENT); 401703697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 401803697e2aSTakashi Iwai cfg->hp_pins); 401903697e2aSTakashi Iwai if (spec->detect_line) { 402003697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 402103697e2aSTakashi Iwai cfg->line_out_pins, 402203697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 402303697e2aSTakashi Iwai spec->line_present = 402403697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 402503697e2aSTakashi Iwai cfg->line_out_pins); 402603697e2aSTakashi Iwai } 402703697e2aSTakashi Iwai } 402803697e2aSTakashi Iwai cx_auto_update_speakers(codec); 4029254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 4030254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 403119110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 4032f2e5731dSTakashi Iwai } 4033f2e5731dSTakashi Iwai 4034f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 4035f2e5731dSTakashi Iwai { 4036f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4037f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 40380ad1b5b6STakashi Iwai int i, val; 4039f2e5731dSTakashi Iwai 40400ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 40410ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 40421f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 40431f8458a2STakashi Iwai continue; 40440ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 40450ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40460ad1b5b6STakashi Iwai else 40470ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40480ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40490ad1b5b6STakashi Iwai val); 40500ad1b5b6STakashi Iwai } 4051f2e5731dSTakashi Iwai 4052f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4053f2e5731dSTakashi Iwai unsigned int type; 4054f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4055f2e5731dSTakashi Iwai type = PIN_VREF80; 4056f2e5731dSTakashi Iwai else 4057f2e5731dSTakashi Iwai type = PIN_IN; 4058f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4059f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4060f2e5731dSTakashi Iwai } 4061f2e5731dSTakashi Iwai 4062f2e5731dSTakashi Iwai if (spec->auto_mic) { 406343c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40641835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40651835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40661835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 406743c1b2e9STakashi Iwai } 406843c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40691835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40701835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40711835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 407243c1b2e9STakashi Iwai } 4073f2e5731dSTakashi Iwai cx_auto_automic(codec); 4074f2e5731dSTakashi Iwai } else { 407547ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 407647ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4077f2e5731dSTakashi Iwai } 4078f2e5731dSTakashi Iwai } 4079f2e5731dSTakashi Iwai 4080f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4081f2e5731dSTakashi Iwai { 4082f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4083f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4084f2e5731dSTakashi Iwai 4085f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4086f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4087f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4088f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4089f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4090f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4091f2e5731dSTakashi Iwai } 4092f2e5731dSTakashi Iwai 4093f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4094f2e5731dSTakashi Iwai { 4095f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4096f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4097f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4098f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 4099*01a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4100f2e5731dSTakashi Iwai return 0; 4101f2e5731dSTakashi Iwai } 4102f2e5731dSTakashi Iwai 4103983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4104f2e5731dSTakashi Iwai const char *dir, int cidx, 4105983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 4106f2e5731dSTakashi Iwai { 4107f2e5731dSTakashi Iwai static char name[32]; 4108f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4109f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4110f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4111f2e5731dSTakashi Iwai }; 411234cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4113f2e5731dSTakashi Iwai int i, err; 4114f2e5731dSTakashi Iwai 4115f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4116f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4117983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4118983345e5SDavid Henningsson hda_dir); 4119f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4120f2e5731dSTakashi Iwai knew[i].index = cidx; 4121f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4122f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4123f2e5731dSTakashi Iwai if (!kctl) 4124f2e5731dSTakashi Iwai return -ENOMEM; 4125f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4126f2e5731dSTakashi Iwai if (err < 0) 4127f2e5731dSTakashi Iwai return err; 4128f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 4129f2e5731dSTakashi Iwai break; 4130f2e5731dSTakashi Iwai } 4131f2e5731dSTakashi Iwai return 0; 4132f2e5731dSTakashi Iwai } 4133f2e5731dSTakashi Iwai 4134983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4135983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4136983345e5SDavid Henningsson 4137f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4138f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4139f2e5731dSTakashi Iwai 41401f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 41411f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 41421f8458a2STakashi Iwai { 41431f8458a2STakashi Iwai unsigned int caps; 4144468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 41451f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41461f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41471f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4148468c5458SDavid Henningsson } 41491f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41501f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41511f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41521f8458a2STakashi Iwai return 0; 41531f8458a2STakashi Iwai } 41541f8458a2STakashi Iwai 4155f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4156f2e5731dSTakashi Iwai { 4157f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4158f2e5731dSTakashi Iwai int i, err; 4159f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4160ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4161f2e5731dSTakashi Iwai 4162f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41631f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41641f8458a2STakashi Iwai spec->dac_info[0].pin, 4165f2e5731dSTakashi Iwai "Master", 0); 41661f8458a2STakashi Iwai 4167f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4168f2e5731dSTakashi Iwai const char *label; 4169f2e5731dSTakashi Iwai int idx, type; 41701f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4171f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4172f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4173f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4174f2e5731dSTakashi Iwai switch (type) { 4175f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4176f2e5731dSTakashi Iwai default: 4177f2e5731dSTakashi Iwai label = texts[num_line++]; 4178f2e5731dSTakashi Iwai idx = 0; 4179f2e5731dSTakashi Iwai break; 4180f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4181f2e5731dSTakashi Iwai label = "Headphone"; 4182f2e5731dSTakashi Iwai idx = num_hp++; 4183f2e5731dSTakashi Iwai break; 4184f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4185f2e5731dSTakashi Iwai label = "Speaker"; 4186f2e5731dSTakashi Iwai idx = num_spk++; 4187f2e5731dSTakashi Iwai break; 4188f2e5731dSTakashi Iwai } 41891f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41901f8458a2STakashi Iwai spec->dac_info[i].pin, 4191f2e5731dSTakashi Iwai label, idx); 4192f2e5731dSTakashi Iwai if (err < 0) 4193f2e5731dSTakashi Iwai return err; 4194f2e5731dSTakashi Iwai } 419503697e2aSTakashi Iwai 419603697e2aSTakashi Iwai if (spec->auto_mute) { 419703697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 419803697e2aSTakashi Iwai if (err < 0) 419903697e2aSTakashi Iwai return err; 420003697e2aSTakashi Iwai } 420103697e2aSTakashi Iwai 4202f2e5731dSTakashi Iwai return 0; 4203f2e5731dSTakashi Iwai } 4204f2e5731dSTakashi Iwai 42056764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 42066764bcefSTakashi Iwai const char *label, const char *pfx, 42076764bcefSTakashi Iwai int cidx) 42086764bcefSTakashi Iwai { 42096764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 42106764bcefSTakashi Iwai int i; 42116764bcefSTakashi Iwai 42126764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 42136764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 42145c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 42156764bcefSTakashi Iwai if (idx < 0) 42166764bcefSTakashi Iwai continue; 42176b452142STakashi Iwai if (spec->single_adc_amp) 42186b452142STakashi Iwai idx = 0; 42196764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 42206764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 42216764bcefSTakashi Iwai } 42226764bcefSTakashi Iwai return 0; 42236764bcefSTakashi Iwai } 42246764bcefSTakashi Iwai 4225cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4226cf27f29aSTakashi Iwai const char *label, int cidx) 4227cf27f29aSTakashi Iwai { 4228cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4229cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4230f9759301STakashi Iwai int i, con; 4231cf27f29aSTakashi Iwai 423247ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4233cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4234cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4235cf27f29aSTakashi Iwai nid, HDA_INPUT); 423647ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 423747ad1f4eSTakashi Iwai &mux, false, 0); 4238cf27f29aSTakashi Iwai if (con < 0) 4239cf27f29aSTakashi Iwai return 0; 4240f9759301STakashi Iwai for (i = 0; i < idx; i++) { 424147ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4242f9759301STakashi Iwai return 0; /* already present */ 4243f9759301STakashi Iwai } 4244f9759301STakashi Iwai 4245f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 424647ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4247cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4248cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4249f9759301STakashi Iwai } 4250cf27f29aSTakashi Iwai return 0; 4251cf27f29aSTakashi Iwai } 4252cf27f29aSTakashi Iwai 4253f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4254f2e5731dSTakashi Iwai { 4255f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4256cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4257cf27f29aSTakashi Iwai const char *prev_label; 4258cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42596b452142STakashi Iwai int i, j, err, cidx; 4260cf27f29aSTakashi Iwai int multi_connection; 4261cf27f29aSTakashi Iwai 42626b452142STakashi Iwai if (!imux->num_items) 42636b452142STakashi Iwai return 0; 42646b452142STakashi Iwai 4265cf27f29aSTakashi Iwai multi_connection = 0; 4266cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 426747ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 426847ad1f4eSTakashi Iwai spec->imux_info[i].pin); 42696b452142STakashi Iwai if (cidx < 0) 42706b452142STakashi Iwai continue; 42716b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 42726b452142STakashi Iwai if (!spec->single_adc_amp) 42736b452142STakashi Iwai input_conn[i] |= cidx << 8; 4274cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4275cf27f29aSTakashi Iwai multi_connection = 1; 4276cf27f29aSTakashi Iwai } 4277983345e5SDavid Henningsson 4278f2e5731dSTakashi Iwai prev_label = NULL; 4279f2e5731dSTakashi Iwai cidx = 0; 4280cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 428147ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4282f2e5731dSTakashi Iwai const char *label; 4283983345e5SDavid Henningsson 4284cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 428547ad1f4eSTakashi Iwai spec->imux_info[i].index); 4286f2e5731dSTakashi Iwai if (label == prev_label) 4287f2e5731dSTakashi Iwai cidx++; 4288f2e5731dSTakashi Iwai else 4289f2e5731dSTakashi Iwai cidx = 0; 4290f2e5731dSTakashi Iwai prev_label = label; 4291983345e5SDavid Henningsson 4292cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4293f2e5731dSTakashi Iwai if (err < 0) 4294f2e5731dSTakashi Iwai return err; 4295983345e5SDavid Henningsson 4296cf27f29aSTakashi Iwai if (!multi_connection) { 4297f9759301STakashi Iwai if (i > 0) 4298f9759301STakashi Iwai continue; 42996764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43006764bcefSTakashi Iwai "Capture", "", cidx); 43016764bcefSTakashi Iwai } else { 43026b452142STakashi Iwai bool dup_found = false; 43036b452142STakashi Iwai for (j = 0; j < i; j++) { 43046b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 43056b452142STakashi Iwai dup_found = true; 43066b452142STakashi Iwai break; 43076b452142STakashi Iwai } 43086b452142STakashi Iwai } 43096b452142STakashi Iwai if (dup_found) 43106b452142STakashi Iwai continue; 43116764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 43126764bcefSTakashi Iwai label, " Capture", cidx); 43136764bcefSTakashi Iwai } 4314983345e5SDavid Henningsson if (err < 0) 4315983345e5SDavid Henningsson return err; 4316983345e5SDavid Henningsson } 43176764bcefSTakashi Iwai 43186764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 43196764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 43206764bcefSTakashi Iwai if (err < 0) 43216764bcefSTakashi Iwai return err; 4322983345e5SDavid Henningsson } 43236764bcefSTakashi Iwai 4324f2e5731dSTakashi Iwai return 0; 4325f2e5731dSTakashi Iwai } 4326f2e5731dSTakashi Iwai 4327f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4328f2e5731dSTakashi Iwai { 4329f2e5731dSTakashi Iwai int err; 4330f2e5731dSTakashi Iwai 4331f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4332f2e5731dSTakashi Iwai if (err < 0) 4333f2e5731dSTakashi Iwai return err; 4334f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4335f2e5731dSTakashi Iwai if (err < 0) 4336f2e5731dSTakashi Iwai return err; 4337f2e5731dSTakashi Iwai return conexant_build_controls(codec); 4338f2e5731dSTakashi Iwai } 4339f2e5731dSTakashi Iwai 434022ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 434122ce5f74STakashi Iwai { 434222ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 434322ce5f74STakashi Iwai hda_nid_t nid, end_nid; 434422ce5f74STakashi Iwai 434522ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 434622ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 434722ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 434822ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 434922ce5f74STakashi Iwai continue; 435022ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 435122ce5f74STakashi Iwai continue; 435222ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 435322ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 435422ce5f74STakashi Iwai break; 435522ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 435622ce5f74STakashi Iwai } 435722ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 435822ce5f74STakashi Iwai return 0; 435922ce5f74STakashi Iwai } 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 */ 4409e92d4b08STakashi Iwai {} 4410e92d4b08STakashi Iwai }; 4411e92d4b08STakashi Iwai 4412e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4413e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4414e92d4b08STakashi Iwai }; 4415e92d4b08STakashi Iwai 4416e92d4b08STakashi Iwai static const struct snd_pci_quirk cxt_fixups[] = { 4417e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4418e92d4b08STakashi Iwai {} 4419e92d4b08STakashi Iwai }; 4420e92d4b08STakashi Iwai 4421f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4422f2e5731dSTakashi Iwai { 4423f2e5731dSTakashi Iwai struct conexant_spec *spec; 4424f2e5731dSTakashi Iwai int err; 4425f2e5731dSTakashi Iwai 44261f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 44271f8458a2STakashi Iwai codec->chip_name); 44281f8458a2STakashi Iwai 4429f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4430f2e5731dSTakashi Iwai if (!spec) 4431f2e5731dSTakashi Iwai return -ENOMEM; 4432f2e5731dSTakashi Iwai codec->spec = spec; 44331387cde5STakashi Iwai codec->pin_amp_workaround = 1; 4434e92d4b08STakashi Iwai 44356b452142STakashi Iwai switch (codec->vendor_id) { 44366b452142STakashi Iwai case 0x14f15045: 44376b452142STakashi Iwai spec->single_adc_amp = 1; 44386b452142STakashi Iwai break; 44396b452142STakashi Iwai } 44406b452142STakashi Iwai 4441e92d4b08STakashi Iwai apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl); 4442e92d4b08STakashi Iwai 444322ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 444422ce5f74STakashi Iwai if (err < 0) 444522ce5f74STakashi Iwai return err; 4446f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4447f2e5731dSTakashi Iwai if (err < 0) { 4448f2e5731dSTakashi Iwai kfree(codec->spec); 4449f2e5731dSTakashi Iwai codec->spec = NULL; 4450f2e5731dSTakashi Iwai return err; 4451f2e5731dSTakashi Iwai } 44526764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4453f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4454f2e5731dSTakashi Iwai if (spec->beep_amp) 4455f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 4456f2e5731dSTakashi Iwai return 0; 4457f2e5731dSTakashi Iwai } 4458f2e5731dSTakashi Iwai 4459f2e5731dSTakashi Iwai /* 4460461e2c78STakashi Iwai */ 4461461e2c78STakashi Iwai 446234cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 446382f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 446482f30040STobin Davis .patch = patch_cxt5045 }, 446582f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 446682f30040STobin Davis .patch = patch_cxt5047 }, 4467461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4468461e2c78STakashi Iwai .patch = patch_cxt5051 }, 44690fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 44700fb67e98SDaniel Drake .patch = patch_cxt5066 }, 447195a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 447295a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4473850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4474850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 44757b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 44767b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4477f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4478f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 44796da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 44806da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4481f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4482f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4483f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4484f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4485f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4486f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4487f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4488f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4489f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4490f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4491f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4492f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4493f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4494f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4495f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4496f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4497c9b443d4STobin Davis {} /* terminator */ 4498c9b443d4STobin Davis }; 44991289e9e8STakashi Iwai 45001289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 45011289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 45021289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 45030fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 450495a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4505850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 45067b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4507f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 45086da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4509f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4510f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4511f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4512f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4513f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4514f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4515f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4516f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 45171289e9e8STakashi Iwai 45181289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 45191289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 45201289e9e8STakashi Iwai 45211289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 45221289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 45231289e9e8STakashi Iwai .owner = THIS_MODULE, 45241289e9e8STakashi Iwai }; 45251289e9e8STakashi Iwai 45261289e9e8STakashi Iwai static int __init patch_conexant_init(void) 45271289e9e8STakashi Iwai { 45281289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 45291289e9e8STakashi Iwai } 45301289e9e8STakashi Iwai 45311289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 45321289e9e8STakashi Iwai { 45331289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 45341289e9e8STakashi Iwai } 45351289e9e8STakashi Iwai 45361289e9e8STakashi Iwai module_init(patch_conexant_init) 45371289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4538