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 4194d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 4204d7fbdbcSTakashi Iwai unsigned int power_state) 4214d7fbdbcSTakashi Iwai { 4224d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D3) 4234d7fbdbcSTakashi Iwai msleep(100); 4244d7fbdbcSTakashi Iwai snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, 4254d7fbdbcSTakashi Iwai power_state); 4264d7fbdbcSTakashi Iwai /* partial workaround for "azx_get_response timeout" */ 4274d7fbdbcSTakashi Iwai if (power_state == AC_PWRST_D0) 4284d7fbdbcSTakashi Iwai msleep(10); 4294d7fbdbcSTakashi Iwai snd_hda_codec_set_power_to_all(codec, fg, power_state, true); 4304d7fbdbcSTakashi Iwai } 4314d7fbdbcSTakashi Iwai 432c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 433c9b443d4STobin Davis { 434c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 435c9b443d4STobin Davis int i; 436c9b443d4STobin Davis 437c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 438c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 439c9b443d4STobin Davis return 0; 440c9b443d4STobin Davis } 441c9b443d4STobin Davis 442c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 443c9b443d4STobin Davis { 444c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 445c9b443d4STobin Davis kfree(codec->spec); 446c9b443d4STobin Davis } 447c9b443d4STobin Davis 44834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = { 449b880c74aSTakashi Iwai { 450b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 451b880c74aSTakashi Iwai .name = "Capture Source", 452b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 453b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 454b880c74aSTakashi Iwai .put = conexant_mux_enum_put 455b880c74aSTakashi Iwai }, 456b880c74aSTakashi Iwai {} 457b880c74aSTakashi Iwai }; 458b880c74aSTakashi Iwai 4593507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 4603507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 46134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = { 4623507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 4633507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 4643507e2a8STakashi Iwai { } /* end */ 4653507e2a8STakashi Iwai }; 4663507e2a8STakashi Iwai #endif 4673507e2a8STakashi Iwai 468*9322ca54STakashi Iwai static const char * const slave_pfxs[] = { 469*9322ca54STakashi Iwai "Headphone", "Speaker", "Front", "Surround", "CLFE", 470dd5746a8STakashi Iwai NULL 471dd5746a8STakashi Iwai }; 472dd5746a8STakashi Iwai 473c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 474c9b443d4STobin Davis { 475c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 476c9b443d4STobin Davis unsigned int i; 477c9b443d4STobin Davis int err; 478c9b443d4STobin Davis 479c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 480c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 481c9b443d4STobin Davis if (err < 0) 482c9b443d4STobin Davis return err; 483c9b443d4STobin Davis } 484c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 485c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 48674b654c9SStephen Warren spec->multiout.dig_out_nid, 487c9b443d4STobin Davis spec->multiout.dig_out_nid); 488c9b443d4STobin Davis if (err < 0) 489c9b443d4STobin Davis return err; 4909a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 4919a08160bSTakashi Iwai &spec->multiout); 4929a08160bSTakashi Iwai if (err < 0) 4939a08160bSTakashi Iwai return err; 4949a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 495c9b443d4STobin Davis } 496c9b443d4STobin Davis if (spec->dig_in_nid) { 497c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 498c9b443d4STobin Davis if (err < 0) 499c9b443d4STobin Davis return err; 500c9b443d4STobin Davis } 501dd5746a8STakashi Iwai 502dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 503dd5746a8STakashi Iwai if (spec->vmaster_nid && 504dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 505dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 506dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 507dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 508dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 509*9322ca54STakashi Iwai vmaster_tlv, slave_pfxs, 510*9322ca54STakashi Iwai "Playback Volume"); 511dd5746a8STakashi Iwai if (err < 0) 512dd5746a8STakashi Iwai return err; 513dd5746a8STakashi Iwai } 514dd5746a8STakashi Iwai if (spec->vmaster_nid && 515dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 516dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 517*9322ca54STakashi Iwai NULL, slave_pfxs, 518*9322ca54STakashi Iwai "Playback Switch"); 519dd5746a8STakashi Iwai if (err < 0) 520dd5746a8STakashi Iwai return err; 521dd5746a8STakashi Iwai } 522dd5746a8STakashi Iwai 523b880c74aSTakashi Iwai if (spec->input_mux) { 524b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 525b880c74aSTakashi Iwai if (err < 0) 526b880c74aSTakashi Iwai return err; 527b880c74aSTakashi Iwai } 528b880c74aSTakashi Iwai 5293507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5303507e2a8STakashi Iwai /* create beep controls if needed */ 5313507e2a8STakashi Iwai if (spec->beep_amp) { 53234cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5333507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5343507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5353507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5363507e2a8STakashi Iwai if (!kctl) 5373507e2a8STakashi Iwai return -ENOMEM; 5383507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5393507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5403507e2a8STakashi Iwai if (err < 0) 5413507e2a8STakashi Iwai return err; 5423507e2a8STakashi Iwai } 5433507e2a8STakashi Iwai } 5443507e2a8STakashi Iwai #endif 5453507e2a8STakashi Iwai 546c9b443d4STobin Davis return 0; 547c9b443d4STobin Davis } 548c9b443d4STobin Davis 549697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 550697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 551697c373eSTakashi Iwai { 552697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 553697c373eSTakashi Iwai return 0; 554697c373eSTakashi Iwai } 555697c373eSTakashi Iwai #endif 556697c373eSTakashi Iwai 55734cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 558c9b443d4STobin Davis .build_controls = conexant_build_controls, 559c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 560c9b443d4STobin Davis .init = conexant_init, 561c9b443d4STobin Davis .free = conexant_free, 5624d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 563697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 564697c373eSTakashi Iwai .suspend = conexant_suspend, 565697c373eSTakashi Iwai #endif 566697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 567c9b443d4STobin Davis }; 568c9b443d4STobin Davis 5693507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5703507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5713507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5723507e2a8STakashi Iwai #else 5733507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5743507e2a8STakashi Iwai #endif 5753507e2a8STakashi Iwai 5766764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 577c9b443d4STobin Davis /* 578c9b443d4STobin Davis * EAPD control 579c9b443d4STobin Davis * the private value = nid | (invert << 8) 580c9b443d4STobin Davis */ 581c9b443d4STobin Davis 582a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 583c9b443d4STobin Davis 58482f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 585c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 586c9b443d4STobin Davis { 587c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 588c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 589c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 590c9b443d4STobin Davis if (invert) 591c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 592c9b443d4STobin Davis else 593c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 594c9b443d4STobin Davis return 0; 59582f30040STobin Davis 596c9b443d4STobin Davis } 597c9b443d4STobin Davis 59882f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 599c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 600c9b443d4STobin Davis { 601c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 602c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 603c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 604c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 605c9b443d4STobin Davis unsigned int eapd; 60682f30040STobin Davis 60768ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 608c9b443d4STobin Davis if (invert) 609c9b443d4STobin Davis eapd = !eapd; 61082beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 611c9b443d4STobin Davis return 0; 61282f30040STobin Davis 613c9b443d4STobin Davis spec->cur_eapd = eapd; 61482beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 615c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 616c9b443d4STobin Davis eapd ? 0x02 : 0x00); 617c9b443d4STobin Davis return 1; 618c9b443d4STobin Davis } 619c9b443d4STobin Davis 62086d72bdfSTakashi Iwai /* controls for test mode */ 62186d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 62286d72bdfSTakashi Iwai 62382f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 62482f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 62582f30040STobin Davis .info = cxt_eapd_info, \ 62682f30040STobin Davis .get = cxt_eapd_get, \ 62782f30040STobin Davis .put = cxt_eapd_put, \ 62882f30040STobin Davis .private_value = nid | (mask<<16) } 62982f30040STobin Davis 63082f30040STobin Davis 63182f30040STobin Davis 632c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 633c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 634c9b443d4STobin Davis { 635c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 636c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 637c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 638c9b443d4STobin Davis spec->num_channel_mode); 639c9b443d4STobin Davis } 640c9b443d4STobin Davis 641c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 642c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 643c9b443d4STobin Davis { 644c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 645c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 646c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 647c9b443d4STobin Davis spec->num_channel_mode, 648c9b443d4STobin Davis spec->multiout.max_channels); 649c9b443d4STobin Davis } 650c9b443d4STobin Davis 651c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 652c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 653c9b443d4STobin Davis { 654c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 655c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 656c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 657c9b443d4STobin Davis spec->num_channel_mode, 658c9b443d4STobin Davis &spec->multiout.max_channels); 659c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 660c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 661c9b443d4STobin Davis return err; 662c9b443d4STobin Davis } 663c9b443d4STobin Davis 664c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 665c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 666c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 667c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 668c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 669c9b443d4STobin Davis .private_value = nid | (dir<<16) } 670c9b443d4STobin Davis 67186d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 67286d72bdfSTakashi Iwai 673c9b443d4STobin Davis /* Conexant 5045 specific */ 674c9b443d4STobin Davis 67534cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 67634cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 67734cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 678cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 679c9b443d4STobin Davis 68034cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6815cd57529STobin Davis { 2, NULL }, 6825cd57529STobin Davis }; 683c9b443d4STobin Davis 68434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 685c9b443d4STobin Davis .num_items = 2, 686c9b443d4STobin Davis .items = { 68782f30040STobin Davis { "IntMic", 0x1 }, 688f4beee94SJiang zhe { "ExtMic", 0x2 }, 689c9b443d4STobin Davis } 690c9b443d4STobin Davis }; 691c9b443d4STobin Davis 69234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 69322e14130SLukasz Marcinowski .num_items = 5, 6945218c892SJiang Zhe .items = { 6955218c892SJiang Zhe { "IntMic", 0x1 }, 6965218c892SJiang Zhe { "ExtMic", 0x2 }, 6975218c892SJiang Zhe { "LineIn", 0x3 }, 69822e14130SLukasz Marcinowski { "CD", 0x4 }, 69922e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7005218c892SJiang Zhe } 7015218c892SJiang Zhe }; 7025218c892SJiang Zhe 70334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7042de3c232SJiang zhe .num_items = 2, 7052de3c232SJiang zhe .items = { 7062de3c232SJiang zhe { "ExtMic", 0x1 }, 7072de3c232SJiang zhe { "IntMic", 0x2 }, 7082de3c232SJiang zhe } 7092de3c232SJiang zhe }; 7102de3c232SJiang zhe 711c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 712c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 713c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 714c9b443d4STobin Davis { 715c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 716c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 71782f30040STobin Davis unsigned int bits; 718c9b443d4STobin Davis 71982f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 720c9b443d4STobin Davis return 0; 721c9b443d4STobin Davis 72282f30040STobin Davis /* toggle internal speakers mute depending of presence of 72382f30040STobin Davis * the headphone jack 72482f30040STobin Davis */ 72547fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 72647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 72747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7287f29673bSTobin Davis 72947fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 73047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 73147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 732c9b443d4STobin Davis return 1; 733c9b443d4STobin Davis } 734c9b443d4STobin Davis 735c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 73634cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 737cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 738cca3b371STakashi Iwai .values = { 739cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 740cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 741cca3b371STakashi Iwai 0 742cca3b371STakashi Iwai }, 743cca3b371STakashi Iwai }; 744c9b443d4STobin Davis 7457f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7467f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7477f29673bSTobin Davis { 74834cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7497f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7507f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7517f29673bSTobin Davis {} 7527f29673bSTobin Davis }; 75334cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7547f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7557f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7567f29673bSTobin Davis {} 7577f29673bSTobin Davis }; 7587f29673bSTobin Davis unsigned int present; 7597f29673bSTobin Davis 760d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7617f29673bSTobin Davis if (present) 7627f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7637f29673bSTobin Davis else 7647f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7657f29673bSTobin Davis } 7667f29673bSTobin Davis 767c9b443d4STobin Davis 768c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 769c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 770c9b443d4STobin Davis { 77182f30040STobin Davis struct conexant_spec *spec = codec->spec; 772dd87da1cSTobin Davis unsigned int bits; 773c9b443d4STobin Davis 774d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 775dd87da1cSTobin Davis 77647fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 77747fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 77847fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 779c9b443d4STobin Davis } 780c9b443d4STobin Davis 781c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 782c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 783c9b443d4STobin Davis unsigned int res) 784c9b443d4STobin Davis { 785c9b443d4STobin Davis res >>= 26; 786c9b443d4STobin Davis switch (res) { 787c9b443d4STobin Davis case CONEXANT_HP_EVENT: 788c9b443d4STobin Davis cxt5045_hp_automute(codec); 789c9b443d4STobin Davis break; 7907f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7917f29673bSTobin Davis cxt5045_hp_automic(codec); 7927f29673bSTobin Davis break; 7937f29673bSTobin Davis 794c9b443d4STobin Davis } 795c9b443d4STobin Davis } 796c9b443d4STobin Davis 79734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 79828c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 79928c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8008607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8018607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 802c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 803c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 80428c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 80528c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8068607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8078607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 808cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 809c9b443d4STobin Davis { 810c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 811c9b443d4STobin Davis .name = "Master Playback Switch", 81282f30040STobin Davis .info = cxt_eapd_info, 81382f30040STobin Davis .get = cxt_eapd_get, 814c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 81582f30040STobin Davis .private_value = 0x10, 816c9b443d4STobin Davis }, 817c9b443d4STobin Davis 818c9b443d4STobin Davis {} 819c9b443d4STobin Davis }; 820c9b443d4STobin Davis 82134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 82222e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 82322e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 82422e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 82522e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 82622e14130SLukasz Marcinowski 8275218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8285218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8295218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8305218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8315218c892SJiang Zhe 83222e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 83322e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 83422e14130SLukasz Marcinowski 8355218c892SJiang Zhe {} 8365218c892SJiang Zhe }; 8375218c892SJiang Zhe 83834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 83928c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 84028c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8418607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8428607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8432de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8442de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 84528c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 84628c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8478607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8488607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8492de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8502de3c232SJiang zhe { 8512de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8522de3c232SJiang zhe .name = "Master Playback Switch", 8532de3c232SJiang zhe .info = cxt_eapd_info, 8542de3c232SJiang zhe .get = cxt_eapd_get, 8552de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8562de3c232SJiang zhe .private_value = 0x10, 8572de3c232SJiang zhe }, 8582de3c232SJiang zhe 8592de3c232SJiang zhe {} 8602de3c232SJiang zhe }; 8612de3c232SJiang zhe 86234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 863c9b443d4STobin Davis /* Line in, Mic */ 8644090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8657f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 866c9b443d4STobin Davis /* HP, Amp */ 867c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 868c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 86982f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 870c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 871c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 872c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 873c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 874c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 875c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 87628c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8777f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 87882f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 879c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 880c9b443d4STobin Davis /* SPDIF route: PCM */ 881cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 882c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 883c9b443d4STobin Davis /* EAPD */ 88482f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 885c9b443d4STobin Davis { } /* end */ 886c9b443d4STobin Davis }; 887c9b443d4STobin Davis 88834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 88928c4edb7SDavid Henningsson /* Internal Mic, Mic */ 8905218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8915218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8925218c892SJiang Zhe /* Line In,HP, Amp */ 8935218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8945218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8955218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 8965218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 8975218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8985218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 8995218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9005218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9015218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 90228c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9035218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9045218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9055218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9065218c892SJiang Zhe /* SPDIF route: PCM */ 907cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9085218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9095218c892SJiang Zhe /* EAPD */ 9105218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9115218c892SJiang Zhe { } /* end */ 9125218c892SJiang Zhe }; 9137f29673bSTobin Davis 91434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9157f29673bSTobin Davis /* pin sensing on HP jack */ 9167f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 917d3091fadSTakashi Iwai { } /* end */ 9187f29673bSTobin Davis }; 9197f29673bSTobin Davis 92034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9217f29673bSTobin Davis /* pin sensing on HP jack */ 9227f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 923d3091fadSTakashi Iwai { } /* end */ 9247f29673bSTobin Davis }; 9257f29673bSTobin Davis 926c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 927c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 928c9b443d4STobin Davis * configuration. 929c9b443d4STobin Davis */ 93034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 931c9b443d4STobin Davis .num_items = 5, 932c9b443d4STobin Davis .items = { 933c9b443d4STobin Davis { "MIXER", 0x0 }, 934c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 935c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 936c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 937c9b443d4STobin Davis { "CD pin", 0x4 }, 938c9b443d4STobin Davis }, 939c9b443d4STobin Davis }; 940c9b443d4STobin Davis 94134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 942c9b443d4STobin Davis 943c9b443d4STobin Davis /* Output controls */ 944c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 945c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9467f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9477f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9487f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9497f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 950c9b443d4STobin Davis 951c9b443d4STobin Davis /* Modes for retasking pin widgets */ 952c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 953c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 954c9b443d4STobin Davis 95582f30040STobin Davis /* EAPD Switch Control */ 95682f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 95782f30040STobin Davis 958c9b443d4STobin Davis /* Loopback mixer controls */ 959c9b443d4STobin Davis 9607f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9617f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9627f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9637f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9647f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9657f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9667f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9677f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9687f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9697f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 970c9b443d4STobin Davis { 971c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 972c9b443d4STobin Davis .name = "Input Source", 973c9b443d4STobin Davis .info = conexant_mux_enum_info, 974c9b443d4STobin Davis .get = conexant_mux_enum_get, 975c9b443d4STobin Davis .put = conexant_mux_enum_put, 976c9b443d4STobin Davis }, 977fb3409e7STobin Davis /* Audio input controls */ 978fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 979fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 980fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 981fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 982fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 983fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 984fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 985fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 986fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 987fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 988c9b443d4STobin Davis { } /* end */ 989c9b443d4STobin Davis }; 990c9b443d4STobin Davis 99134cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 9927f29673bSTobin Davis /* Set connections */ 9937f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9947f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9957f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 996c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 997c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9987f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 999c9b443d4STobin Davis 1000c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1001c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1002c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1003c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1004c9b443d4STobin Davis * control. 1005c9b443d4STobin Davis */ 1006cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1007cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1008c9b443d4STobin Davis 1009c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1010c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1011c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1012c9b443d4STobin Davis 1013c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1014c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1015c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1016c9b443d4STobin Davis * input/output buffers as needed. 1017c9b443d4STobin Davis */ 1018c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1019c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1020c9b443d4STobin Davis 1021c9b443d4STobin Davis /* Mute capture amp left and right */ 1022c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1023c9b443d4STobin Davis 1024c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1025c9b443d4STobin Davis * pin) 1026c9b443d4STobin Davis */ 1027c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10287f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1029c9b443d4STobin Davis 1030c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1031c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1032c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1033c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1034c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1035c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1036c9b443d4STobin Davis 1037c9b443d4STobin Davis { } 1038c9b443d4STobin Davis }; 1039c9b443d4STobin Davis #endif 1040c9b443d4STobin Davis 1041c9b443d4STobin Davis 1042c9b443d4STobin Davis /* initialize jack-sensing, too */ 1043c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1044c9b443d4STobin Davis { 1045c9b443d4STobin Davis conexant_init(codec); 1046c9b443d4STobin Davis cxt5045_hp_automute(codec); 1047c9b443d4STobin Davis return 0; 1048c9b443d4STobin Davis } 1049c9b443d4STobin Davis 1050c9b443d4STobin Davis 1051c9b443d4STobin Davis enum { 105215908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 105315908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 105415908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10555218c892SJiang Zhe CXT5045_BENQ, 10562de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1057c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1058c9b443d4STobin Davis CXT5045_TEST, 1059c9b443d4STobin Davis #endif 10601f8458a2STakashi Iwai CXT5045_AUTO, 1061f5fcc13cSTakashi Iwai CXT5045_MODELS 1062c9b443d4STobin Davis }; 1063c9b443d4STobin Davis 1064ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 106515908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 106615908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 106715908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10685218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10692de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1070c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1071f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1072c9b443d4STobin Davis #endif 10731f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1074f5fcc13cSTakashi Iwai }; 1075c9b443d4STobin Davis 107634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10772de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 10786a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10795218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 108015908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 108115908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10829e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10839e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 108415908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 108515908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 108615908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1087dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1088dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 108915908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1090c9b443d4STobin Davis {} 1091c9b443d4STobin Davis }; 1092c9b443d4STobin Davis 1093c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1094c9b443d4STobin Davis { 1095c9b443d4STobin Davis struct conexant_spec *spec; 1096c9b443d4STobin Davis int board_config; 1097c9b443d4STobin Davis 10981f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 10991f8458a2STakashi Iwai cxt5045_models, 11001f8458a2STakashi Iwai cxt5045_cfg_tbl); 11011f8458a2STakashi Iwai if (board_config < 0) 1102c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 11031f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11041f8458a2STakashi Iwai return patch_conexant_auto(codec); 11051f8458a2STakashi Iwai 1106c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1107c9b443d4STobin Davis if (!spec) 1108c9b443d4STobin Davis return -ENOMEM; 1109c9b443d4STobin Davis codec->spec = spec; 11109421f954STakashi Iwai codec->pin_amp_workaround = 1; 1111c9b443d4STobin Davis 1112c9b443d4STobin Davis spec->multiout.max_channels = 2; 1113c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1114c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1115c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1116c9b443d4STobin Davis spec->num_adc_nids = 1; 1117c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1118c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1119c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1120c9b443d4STobin Davis spec->num_mixers = 1; 1121c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1122c9b443d4STobin Davis spec->num_init_verbs = 1; 1123c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1124c9b443d4STobin Davis spec->spdif_route = 0; 11253507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11263507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11275cd57529STobin Davis 11283507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1129c9b443d4STobin Davis 1130c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1131c9b443d4STobin Davis 1132c9b443d4STobin Davis switch (board_config) { 113315908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11347f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1135c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1136c9b443d4STobin Davis spec->num_init_verbs = 2; 11377f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11387f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11397f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11407f29673bSTobin Davis break; 114115908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 114286376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11437f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11447f29673bSTobin Davis spec->num_init_verbs = 2; 11457f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1146c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1147c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1148c9b443d4STobin Davis break; 114915908c36SMarc Boucher default: 115015908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 115115908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 115215908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 115315908c36SMarc Boucher spec->num_init_verbs = 3; 115415908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 115515908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 115615908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 115715908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 115815908c36SMarc Boucher break; 11595218c892SJiang Zhe case CXT5045_BENQ: 11605218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11615218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11625218c892SJiang Zhe spec->num_init_verbs = 1; 11635218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11645218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11655218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11665218c892SJiang Zhe spec->num_mixers = 2; 11675218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11685218c892SJiang Zhe break; 11692de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11702de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11712de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11722de3c232SJiang zhe spec->num_init_verbs = 2; 11732de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11742de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11752de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11762de3c232SJiang zhe break; 1177c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1178c9b443d4STobin Davis case CXT5045_TEST: 1179c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1180c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1181c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 118215908c36SMarc Boucher break; 118315908c36SMarc Boucher 1184c9b443d4STobin Davis #endif 1185c9b443d4STobin Davis } 118648ecb7e8STakashi Iwai 1187031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1188031005f7STakashi Iwai case 0x103c: 11898f0f5ff6SDaniel T Chen case 0x1631: 11900b587fc4SDaniel T Chen case 0x1734: 11910ebf9e36SDaniel T Chen case 0x17aa: 11920ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 11930ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 11940ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 119548ecb7e8STakashi Iwai */ 119648ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 119748ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 119848ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 119948ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 120048ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1201031005f7STakashi Iwai break; 1202031005f7STakashi Iwai } 120348ecb7e8STakashi Iwai 12043507e2a8STakashi Iwai if (spec->beep_amp) 12053507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12063507e2a8STakashi Iwai 1207c9b443d4STobin Davis return 0; 1208c9b443d4STobin Davis } 1209c9b443d4STobin Davis 1210c9b443d4STobin Davis 1211c9b443d4STobin Davis /* Conexant 5047 specific */ 121282f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1213c9b443d4STobin Davis 121434cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 121534cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 121634cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1217c9b443d4STobin Davis 121834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12195cd57529STobin Davis { 2, NULL }, 12205cd57529STobin Davis }; 1221c9b443d4STobin Davis 122234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 122382f30040STobin Davis .num_items = 2, 122482f30040STobin Davis .items = { 122582f30040STobin Davis { "ExtMic", 0x2 }, 122682f30040STobin Davis { "Line-In", 0x1 }, 1227c9b443d4STobin Davis } 1228c9b443d4STobin Davis }; 1229c9b443d4STobin Davis 1230c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1231c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1232c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1233c9b443d4STobin Davis { 1234c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1235c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 123682f30040STobin Davis unsigned int bits; 1237c9b443d4STobin Davis 123882f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1239c9b443d4STobin Davis return 0; 1240c9b443d4STobin Davis 124182f30040STobin Davis /* toggle internal speakers mute depending of presence of 124282f30040STobin Davis * the headphone jack 124382f30040STobin Davis */ 124447fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12453b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12463b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12473b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12483b7523fcSTakashi Iwai */ 12495d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 125047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 125147fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 125247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 125347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1254c9b443d4STobin Davis return 1; 1255c9b443d4STobin Davis } 1256c9b443d4STobin Davis 1257c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1258c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1259c9b443d4STobin Davis { 126082f30040STobin Davis struct conexant_spec *spec = codec->spec; 1261dd87da1cSTobin Davis unsigned int bits; 1262c9b443d4STobin Davis 1263d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1264dd87da1cSTobin Davis 126547fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12663b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12675d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 126847fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1269c9b443d4STobin Davis } 1270c9b443d4STobin Davis 1271c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1272c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1273c9b443d4STobin Davis { 127434cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12759f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12769f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1277c9b443d4STobin Davis {} 1278c9b443d4STobin Davis }; 127934cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12809f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12819f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1282c9b443d4STobin Davis {} 1283c9b443d4STobin Davis }; 1284c9b443d4STobin Davis unsigned int present; 1285c9b443d4STobin Davis 1286d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1287c9b443d4STobin Davis if (present) 1288c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1289c9b443d4STobin Davis else 1290c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1291c9b443d4STobin Davis } 1292c9b443d4STobin Davis 1293c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1294c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1295c9b443d4STobin Davis unsigned int res) 1296c9b443d4STobin Davis { 12979f113e0eSMarc Boucher switch (res >> 26) { 1298c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1299c9b443d4STobin Davis cxt5047_hp_automute(codec); 1300c9b443d4STobin Davis break; 1301c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1302c9b443d4STobin Davis cxt5047_hp_automic(codec); 1303c9b443d4STobin Davis break; 1304c9b443d4STobin Davis } 1305c9b443d4STobin Davis } 1306c9b443d4STobin Davis 130734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1308df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1309df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13105f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1311c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1312c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1313c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1314c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 131582f30040STobin Davis { 131682f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 131782f30040STobin Davis .name = "Master Playback Switch", 131882f30040STobin Davis .info = cxt_eapd_info, 131982f30040STobin Davis .get = cxt_eapd_get, 1320c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1321c9b443d4STobin Davis .private_value = 0x13, 1322c9b443d4STobin Davis }, 1323c9b443d4STobin Davis 1324c9b443d4STobin Davis {} 1325c9b443d4STobin Davis }; 1326c9b443d4STobin Davis 132734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13283b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13295d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1330df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1331df481e41STakashi Iwai {} 1332df481e41STakashi Iwai }; 1333df481e41STakashi Iwai 133434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1335c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1336c9b443d4STobin Davis { } /* end */ 1337c9b443d4STobin Davis }; 1338c9b443d4STobin Davis 133934cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1340c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1341c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1342c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1343c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13447f29673bSTobin Davis /* HP, Speaker */ 1345b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13465b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13475b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13487f29673bSTobin Davis /* Record selector: Mic */ 13497f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13507f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13517f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13527f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1353c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1354c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1355c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1356c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1357c9b443d4STobin Davis /* SPDIF route: PCM */ 1358c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 135982f30040STobin Davis /* Enable unsolicited events */ 136082f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 136182f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1362c9b443d4STobin Davis { } /* end */ 1363c9b443d4STobin Davis }; 1364c9b443d4STobin Davis 1365c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 136634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13673b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1368c9b443d4STobin Davis {} 1369c9b443d4STobin Davis }; 1370c9b443d4STobin Davis 1371c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1372c9b443d4STobin Davis * configuration. 1373c9b443d4STobin Davis */ 1374c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 137534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 137682f30040STobin Davis .num_items = 4, 1377c9b443d4STobin Davis .items = { 137882f30040STobin Davis { "LINE1 pin", 0x0 }, 137982f30040STobin Davis { "MIC1 pin", 0x1 }, 138082f30040STobin Davis { "MIC2 pin", 0x2 }, 138182f30040STobin Davis { "CD pin", 0x3 }, 1382c9b443d4STobin Davis }, 1383c9b443d4STobin Davis }; 1384c9b443d4STobin Davis 138534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1386c9b443d4STobin Davis 1387c9b443d4STobin Davis /* Output only controls */ 138882f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 138982f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 139082f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 139182f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1392c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1393c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1394c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1395c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 139682f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 139782f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 139882f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 139982f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1400c9b443d4STobin Davis 1401c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1402c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1403c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1404c9b443d4STobin Davis 140582f30040STobin Davis /* EAPD Switch Control */ 140682f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 140782f30040STobin Davis 1408c9b443d4STobin Davis /* Loopback mixer controls */ 140982f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 141082f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 141182f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 141282f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 141382f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 141482f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 141582f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 141682f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1417c9b443d4STobin Davis 141882f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 141982f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 142082f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 142182f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 142282f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 142382f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 142482f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 142582f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1426c9b443d4STobin Davis { 1427c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1428c9b443d4STobin Davis .name = "Input Source", 1429c9b443d4STobin Davis .info = conexant_mux_enum_info, 1430c9b443d4STobin Davis .get = conexant_mux_enum_get, 1431c9b443d4STobin Davis .put = conexant_mux_enum_put, 1432c9b443d4STobin Davis }, 1433854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14349f113e0eSMarc Boucher 1435c9b443d4STobin Davis { } /* end */ 1436c9b443d4STobin Davis }; 1437c9b443d4STobin Davis 143834cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1439c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1440c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1441c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1442c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1443c9b443d4STobin Davis 1444c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1445c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1446c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1447c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1448c9b443d4STobin Davis * control. 1449c9b443d4STobin Davis */ 1450c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1451c9b443d4STobin Davis 1452c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1453c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1454c9b443d4STobin Davis */ 1455c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1456c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1457c9b443d4STobin Davis 1458c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1459c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1460c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1463c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1464c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1465c9b443d4STobin Davis * input/output buffers as needed. 1466c9b443d4STobin Davis */ 1467c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1468c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1469c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1470c9b443d4STobin Davis 1471c9b443d4STobin Davis /* Mute capture amp left and right */ 1472c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1473c9b443d4STobin Davis 1474c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1475c9b443d4STobin Davis * pin) 1476c9b443d4STobin Davis */ 1477c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1478c9b443d4STobin Davis 1479c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1480c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1481c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1482c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1483c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1484c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1485c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1486c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1487c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1488c9b443d4STobin Davis 1489c9b443d4STobin Davis { } 1490c9b443d4STobin Davis }; 1491c9b443d4STobin Davis #endif 1492c9b443d4STobin Davis 1493c9b443d4STobin Davis 1494c9b443d4STobin Davis /* initialize jack-sensing, too */ 1495c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1496c9b443d4STobin Davis { 1497c9b443d4STobin Davis conexant_init(codec); 1498c9b443d4STobin Davis cxt5047_hp_automute(codec); 1499c9b443d4STobin Davis return 0; 1500c9b443d4STobin Davis } 1501c9b443d4STobin Davis 1502c9b443d4STobin Davis 1503c9b443d4STobin Davis enum { 1504f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1505f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1506f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1507c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1508c9b443d4STobin Davis CXT5047_TEST, 1509c9b443d4STobin Davis #endif 1510fa5dadcbSTakashi Iwai CXT5047_AUTO, 1511f5fcc13cSTakashi Iwai CXT5047_MODELS 1512c9b443d4STobin Davis }; 1513c9b443d4STobin Davis 1514ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1515f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1516f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1517f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1518c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1519f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1520c9b443d4STobin Davis #endif 1521fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1522f5fcc13cSTakashi Iwai }; 1523c9b443d4STobin Davis 152434cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1525ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1526dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1527dea0a509STakashi Iwai CXT5047_LAPTOP), 1528f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1529c9b443d4STobin Davis {} 1530c9b443d4STobin Davis }; 1531c9b443d4STobin Davis 1532c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1533c9b443d4STobin Davis { 1534c9b443d4STobin Davis struct conexant_spec *spec; 1535c9b443d4STobin Davis int board_config; 1536c9b443d4STobin Davis 1537fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1538fa5dadcbSTakashi Iwai cxt5047_models, 1539fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1540fa5dadcbSTakashi Iwai if (board_config < 0) 1541c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1542fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1543fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1544fa5dadcbSTakashi Iwai 1545c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1546c9b443d4STobin Davis if (!spec) 1547c9b443d4STobin Davis return -ENOMEM; 1548c9b443d4STobin Davis codec->spec = spec; 15499421f954STakashi Iwai codec->pin_amp_workaround = 1; 1550c9b443d4STobin Davis 1551c9b443d4STobin Davis spec->multiout.max_channels = 2; 1552c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1553c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1554c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1555c9b443d4STobin Davis spec->num_adc_nids = 1; 1556c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1557c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1558c9b443d4STobin Davis spec->num_mixers = 1; 1559df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1560c9b443d4STobin Davis spec->num_init_verbs = 1; 1561c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1562c9b443d4STobin Davis spec->spdif_route = 0; 15635cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15645cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1565c9b443d4STobin Davis 1566c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1567c9b443d4STobin Davis 1568c9b443d4STobin Davis switch (board_config) { 1569c9b443d4STobin Davis case CXT5047_LAPTOP: 1570df481e41STakashi Iwai spec->num_mixers = 2; 1571df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1572df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1573c9b443d4STobin Davis break; 1574c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1575df481e41STakashi Iwai spec->num_mixers = 2; 1576df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1577fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1578c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1579c9b443d4STobin Davis break; 1580c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 158182f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1582df481e41STakashi Iwai spec->num_mixers = 2; 1583df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1584c9b443d4STobin Davis spec->num_init_verbs = 2; 1585c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1586fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1587c9b443d4STobin Davis break; 1588c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1589c9b443d4STobin Davis case CXT5047_TEST: 1590c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1591c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1592c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1593fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1594c9b443d4STobin Davis #endif 1595c9b443d4STobin Davis } 1596dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1597025f206cSDaniel T Chen 1598025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1599025f206cSDaniel T Chen case 0x103c: 1600025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1601025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1602025f206cSDaniel T Chen * with 0 dB offset 0x17) 1603025f206cSDaniel T Chen */ 1604025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1605025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1606025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1607025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1608025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1609025f206cSDaniel T Chen break; 1610025f206cSDaniel T Chen } 1611025f206cSDaniel T Chen 1612c9b443d4STobin Davis return 0; 1613c9b443d4STobin Davis } 1614c9b443d4STobin Davis 1615461e2c78STakashi Iwai /* Conexant 5051 specific */ 161634cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 161734cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1618461e2c78STakashi Iwai 161934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1620461e2c78STakashi Iwai { 2, NULL }, 1621461e2c78STakashi Iwai }; 1622461e2c78STakashi Iwai 1623461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1624461e2c78STakashi Iwai { 1625461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1626461e2c78STakashi Iwai unsigned int pinctl; 162723d2df5bSTakashi Iwai /* headphone pin */ 162823d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 162923d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 163023d2df5bSTakashi Iwai pinctl); 163123d2df5bSTakashi Iwai /* speaker pin */ 1632461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1633461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1634461e2c78STakashi Iwai pinctl); 1635f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1636f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1637f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1638f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1639f7154de2SHerton Ronaldo Krzesinski pinctl); 1640461e2c78STakashi Iwai } 1641461e2c78STakashi Iwai 1642461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1643461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1644461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1645461e2c78STakashi Iwai { 1646461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1647461e2c78STakashi Iwai 1648461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1649461e2c78STakashi Iwai return 0; 1650461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1651461e2c78STakashi Iwai return 1; 1652461e2c78STakashi Iwai } 1653461e2c78STakashi Iwai 1654461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1655461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1656461e2c78STakashi Iwai { 165779d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1658461e2c78STakashi Iwai unsigned int present; 1659461e2c78STakashi Iwai 1660faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 166179d7d533STakashi Iwai return; 1662d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1663461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1664461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1665461e2c78STakashi Iwai present ? 0x01 : 0x00); 1666461e2c78STakashi Iwai } 1667461e2c78STakashi Iwai 1668461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1669461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1670461e2c78STakashi Iwai { 1671461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1672461e2c78STakashi Iwai unsigned int present; 1673461e2c78STakashi Iwai hda_nid_t new_adc; 1674461e2c78STakashi Iwai 1675faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 167679d7d533STakashi Iwai return; 1677d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1678461e2c78STakashi Iwai if (present) 1679461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1680461e2c78STakashi Iwai else 1681461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1682461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1683461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1684461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1685f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1686461e2c78STakashi Iwai spec->cur_adc = new_adc; 1687461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1688461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1689461e2c78STakashi Iwai spec->cur_adc_format); 1690461e2c78STakashi Iwai } 1691461e2c78STakashi Iwai } 1692461e2c78STakashi Iwai 1693461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1694461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1695461e2c78STakashi Iwai { 1696461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1697461e2c78STakashi Iwai 1698d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1699461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1700461e2c78STakashi Iwai } 1701461e2c78STakashi Iwai 1702461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1703461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1704461e2c78STakashi Iwai unsigned int res) 1705461e2c78STakashi Iwai { 1706461e2c78STakashi Iwai switch (res >> 26) { 1707461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1708461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1709461e2c78STakashi Iwai break; 1710461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1711461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1712461e2c78STakashi Iwai break; 1713461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1714461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1715461e2c78STakashi Iwai break; 1716461e2c78STakashi Iwai } 1717461e2c78STakashi Iwai } 1718461e2c78STakashi Iwai 171934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1720461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1721461e2c78STakashi Iwai { 1722461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1723461e2c78STakashi Iwai .name = "Master Playback Switch", 1724461e2c78STakashi Iwai .info = cxt_eapd_info, 1725461e2c78STakashi Iwai .get = cxt_eapd_get, 1726461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1727461e2c78STakashi Iwai .private_value = 0x1a, 1728461e2c78STakashi Iwai }, 17292c7a3fb3STakashi Iwai {} 17302c7a3fb3STakashi Iwai }; 1731461e2c78STakashi Iwai 173234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17332c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17342c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17358607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17368607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17372c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17382c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1739461e2c78STakashi Iwai {} 1740461e2c78STakashi Iwai }; 1741461e2c78STakashi Iwai 174234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1743461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1744461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17458607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17468607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1747461e2c78STakashi Iwai {} 1748461e2c78STakashi Iwai }; 1749461e2c78STakashi Iwai 175034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17514e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17524e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 175379d7d533STakashi Iwai {} 175479d7d533STakashi Iwai }; 175579d7d533STakashi Iwai 175634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17575f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17585f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1759cd9d95a5SKen Prox {} 1760cd9d95a5SKen Prox }; 1761cd9d95a5SKen Prox 176234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1763faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1764faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17658607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17668607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1767faddaa5dSTakashi Iwai {} 1768faddaa5dSTakashi Iwai }; 1769faddaa5dSTakashi Iwai 177034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1771461e2c78STakashi Iwai /* Line in, Mic */ 1772461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1773461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1774461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1775461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1776461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1777461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1778461e2c78STakashi Iwai /* SPK */ 1779461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1780461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1781461e2c78STakashi Iwai /* HP, Amp */ 1782461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1783461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1784461e2c78STakashi Iwai /* DAC1 */ 1785461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 178628c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1787461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1788461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1789461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1790461e2c78STakashi Iwai /* SPDIF route: PCM */ 17911965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1792461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1793461e2c78STakashi Iwai /* EAPD */ 1794461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1795461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1796461e2c78STakashi Iwai { } /* end */ 1797461e2c78STakashi Iwai }; 1798461e2c78STakashi Iwai 179934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 180079d7d533STakashi Iwai /* Line in, Mic */ 180179d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 180279d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 180379d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 180479d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 180579d7d533STakashi Iwai /* SPK */ 180679d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 180779d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 180879d7d533STakashi Iwai /* HP, Amp */ 180979d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 181079d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 181179d7d533STakashi Iwai /* DAC1 */ 181279d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 181328c4edb7SDavid Henningsson /* Record selector: Internal mic */ 181479d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 181579d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 181679d7d533STakashi Iwai /* SPDIF route: PCM */ 181779d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 181879d7d533STakashi Iwai /* EAPD */ 181979d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 182079d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 182179d7d533STakashi Iwai { } /* end */ 182279d7d533STakashi Iwai }; 182379d7d533STakashi Iwai 182434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1825cd9d95a5SKen Prox /* Line in, Mic */ 182630ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1827cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1828cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1829cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1830cd9d95a5SKen Prox /* SPK */ 1831cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1832cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1833cd9d95a5SKen Prox /* HP, Amp */ 1834cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1835cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1836cd9d95a5SKen Prox /* DAC1 */ 1837cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 183828c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1839cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1840cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1841cd9d95a5SKen Prox /* SPDIF route: PCM */ 1842cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1843cd9d95a5SKen Prox /* EAPD */ 1844cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1845cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1846cd9d95a5SKen Prox { } /* end */ 1847cd9d95a5SKen Prox }; 1848cd9d95a5SKen Prox 18496953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18506953e552STakashi Iwai unsigned int event) 18516953e552STakashi Iwai { 18526953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18536953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18546953e552STakashi Iwai AC_USRSP_EN | event); 18556953e552STakashi Iwai } 18566953e552STakashi Iwai 185734cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1858f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1859f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1860f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1861f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1862f7154de2SHerton Ronaldo Krzesinski }; 1863f7154de2SHerton Ronaldo Krzesinski 1864461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1865461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1866461e2c78STakashi Iwai { 18676953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18686953e552STakashi Iwai 1869461e2c78STakashi Iwai conexant_init(codec); 18706953e552STakashi Iwai 18716953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18726953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18736953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18746953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18756953e552STakashi Iwai 1876461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1877461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1878461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1879461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1880461e2c78STakashi Iwai } 1881461e2c78STakashi Iwai return 0; 1882461e2c78STakashi Iwai } 1883461e2c78STakashi Iwai 1884461e2c78STakashi Iwai 1885461e2c78STakashi Iwai enum { 1886461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1887461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 188879d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1889cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1890faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1891f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 18926764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1893461e2c78STakashi Iwai CXT5051_MODELS 1894461e2c78STakashi Iwai }; 1895461e2c78STakashi Iwai 1896ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1897461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1898461e2c78STakashi Iwai [CXT5051_HP] = "hp", 189979d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 19005f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1901faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1902f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19036764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1904461e2c78STakashi Iwai }; 1905461e2c78STakashi Iwai 190634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 190779d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19081812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19095f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1910faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1911461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1912461e2c78STakashi Iwai CXT5051_LAPTOP), 1913461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1914f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1915461e2c78STakashi Iwai {} 1916461e2c78STakashi Iwai }; 1917461e2c78STakashi Iwai 1918461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1919461e2c78STakashi Iwai { 1920461e2c78STakashi Iwai struct conexant_spec *spec; 1921461e2c78STakashi Iwai int board_config; 1922461e2c78STakashi Iwai 19236764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19246764bcefSTakashi Iwai cxt5051_models, 19256764bcefSTakashi Iwai cxt5051_cfg_tbl); 19266764bcefSTakashi Iwai if (board_config < 0) 1927c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19281f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19296764bcefSTakashi Iwai return patch_conexant_auto(codec); 19306764bcefSTakashi Iwai 1931461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1932461e2c78STakashi Iwai if (!spec) 1933461e2c78STakashi Iwai return -ENOMEM; 1934461e2c78STakashi Iwai codec->spec = spec; 19359421f954STakashi Iwai codec->pin_amp_workaround = 1; 1936461e2c78STakashi Iwai 1937461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1938461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1939461e2c78STakashi Iwai 1940461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1941461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1942461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1943461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1944461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1945461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19462c7a3fb3STakashi Iwai spec->num_mixers = 2; 19472c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19482c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1949461e2c78STakashi Iwai spec->num_init_verbs = 1; 1950461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1951461e2c78STakashi Iwai spec->spdif_route = 0; 1952461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1953461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1954461e2c78STakashi Iwai spec->cur_adc = 0; 1955461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1956461e2c78STakashi Iwai 19573507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 19583507e2a8STakashi Iwai 195979d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 196079d7d533STakashi Iwai 1961faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1962461e2c78STakashi Iwai switch (board_config) { 1963461e2c78STakashi Iwai case CXT5051_HP: 1964461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1965461e2c78STakashi Iwai break; 196679d7d533STakashi Iwai case CXT5051_HP_DV6736: 196779d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 196879d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1969faddaa5dSTakashi Iwai spec->auto_mic = 0; 197079d7d533STakashi Iwai break; 1971cd9d95a5SKen Prox case CXT5051_F700: 1972cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1973cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1974faddaa5dSTakashi Iwai spec->auto_mic = 0; 1975faddaa5dSTakashi Iwai break; 1976faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1977faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1978faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1979cd9d95a5SKen Prox break; 1980f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 1981f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 1982f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 1983f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 1984f7154de2SHerton Ronaldo Krzesinski break; 1985461e2c78STakashi Iwai } 1986461e2c78STakashi Iwai 19873507e2a8STakashi Iwai if (spec->beep_amp) 19883507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 19893507e2a8STakashi Iwai 1990461e2c78STakashi Iwai return 0; 1991461e2c78STakashi Iwai } 1992461e2c78STakashi Iwai 19930fb67e98SDaniel Drake /* Conexant 5066 specific */ 19940fb67e98SDaniel Drake 199534cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 199634cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 199734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 199834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 19990fb67e98SDaniel Drake 2000dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2001dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2002dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2003dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2004dbaccc0cSDaniel Drake 200534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20060fb67e98SDaniel Drake { 2, NULL }, 20070fb67e98SDaniel Drake }; 20080fb67e98SDaniel Drake 2009a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2010a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2011a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2012a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2013a3de8ab8STakashi Iwai 20140fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20150fb67e98SDaniel Drake { 20160fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20170fb67e98SDaniel Drake unsigned int pinctl; 20180fb67e98SDaniel Drake 20193a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20203a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20210fb67e98SDaniel Drake 20220fb67e98SDaniel Drake /* Port A (HP) */ 2023a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20240fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20250fb67e98SDaniel Drake pinctl); 20260fb67e98SDaniel Drake 20270fb67e98SDaniel Drake /* Port D (HP/LO) */ 2028a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2029a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2030a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2031a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20323a253445SJohn Baboval pinctl = 0; 20333a253445SJohn Baboval } else { 2034a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2035a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2036a3de8ab8STakashi Iwai pinctl = 0; 20373a253445SJohn Baboval } 20380fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20390fb67e98SDaniel Drake pinctl); 20400fb67e98SDaniel Drake 20410fb67e98SDaniel Drake /* CLASS_D AMP */ 20420fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20430fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20440fb67e98SDaniel Drake pinctl); 20450fb67e98SDaniel Drake } 20460fb67e98SDaniel Drake 20470fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20480fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20490fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20500fb67e98SDaniel Drake { 20510fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20520fb67e98SDaniel Drake 20530fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20540fb67e98SDaniel Drake return 0; 20550fb67e98SDaniel Drake 20560fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20570fb67e98SDaniel Drake return 1; 20580fb67e98SDaniel Drake } 20590fb67e98SDaniel Drake 2060c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2061c4cfe66cSDaniel Drake .num_items = 3, 2062c4cfe66cSDaniel Drake .items = { 2063c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2064c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2065c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2066c4cfe66cSDaniel Drake }, 2067c4cfe66cSDaniel Drake }; 2068c4cfe66cSDaniel Drake 2069c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2070c4cfe66cSDaniel Drake { 2071c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2072c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2073c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2074c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2075c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2076c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2077c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2078c4cfe66cSDaniel Drake } 2079c4cfe66cSDaniel Drake 208075f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 208175f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 208275f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 208375f8991dSDaniel Drake * is happening when it is not. */ 208475f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20850fb67e98SDaniel Drake { 2086dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 208775f8991dSDaniel Drake if (!spec->recording) 208875f8991dSDaniel Drake return; 20890fb67e98SDaniel Drake 2090c4cfe66cSDaniel Drake if (spec->dc_enable) { 2091c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2092c4cfe66cSDaniel Drake * through our special DC port */ 2093c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2094c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2095c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2096c4cfe66cSDaniel Drake 2097c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2098c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2099c4cfe66cSDaniel Drake {}, 2100c4cfe66cSDaniel Drake }; 2101c4cfe66cSDaniel Drake 2102c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2103c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2104c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2105c4cfe66cSDaniel Drake return; 2106c4cfe66cSDaniel Drake } 2107c4cfe66cSDaniel Drake 2108c4cfe66cSDaniel Drake /* disable DC (port F) */ 2109c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2110c4cfe66cSDaniel Drake 211175f8991dSDaniel Drake /* external mic, port B */ 211275f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 211375f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21140fb67e98SDaniel Drake 211575f8991dSDaniel Drake /* internal mic, port C */ 211675f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 211775f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 211875f8991dSDaniel Drake } 21190fb67e98SDaniel Drake 212075f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 212175f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 212275f8991dSDaniel Drake { 212375f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21240fb67e98SDaniel Drake unsigned int present; 21250fb67e98SDaniel Drake 2126c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2127c4cfe66cSDaniel Drake return; 2128c4cfe66cSDaniel Drake 212975f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 213075f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 213175f8991dSDaniel Drake if (present) 21320fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 213375f8991dSDaniel Drake else 21340fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 213575f8991dSDaniel Drake 213675f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 213775f8991dSDaniel Drake present ? 0 : 1); 213875f8991dSDaniel Drake spec->ext_mic_present = !!present; 213975f8991dSDaniel Drake 214075f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21410fb67e98SDaniel Drake } 21420fb67e98SDaniel Drake 214395a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 214495a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 214595a618bdSEinar Rünkaru { 214695a618bdSEinar Rünkaru unsigned int present; 214795a618bdSEinar Rünkaru 214895a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 214995a618bdSEinar Rünkaru /* enable external mic, port B */ 215075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 215195a618bdSEinar Rünkaru 215295a618bdSEinar Rünkaru /* switch to external mic input */ 215395a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 215495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 215595a618bdSEinar Rünkaru 215695a618bdSEinar Rünkaru /* disable internal digital mic */ 215795a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 215895a618bdSEinar Rünkaru {} 215995a618bdSEinar Rünkaru }; 216034cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 216195a618bdSEinar Rünkaru /* enable internal mic, port C */ 216295a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 216395a618bdSEinar Rünkaru 216495a618bdSEinar Rünkaru /* switch to internal mic input */ 216595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 216695a618bdSEinar Rünkaru 216795a618bdSEinar Rünkaru /* disable external mic, port B */ 216895a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 216995a618bdSEinar Rünkaru {} 217095a618bdSEinar Rünkaru }; 217195a618bdSEinar Rünkaru 217295a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 217395a618bdSEinar Rünkaru if (present) { 217495a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 217595a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 217695a618bdSEinar Rünkaru } else { 217795a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 217895a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 217995a618bdSEinar Rünkaru } 218095a618bdSEinar Rünkaru } 218195a618bdSEinar Rünkaru 2182cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2183cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2184cfd3d8dcSGreg Alexander { 2185cfd3d8dcSGreg Alexander unsigned int present; 2186cfd3d8dcSGreg Alexander 2187cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2188cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2189cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2190cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2191cfd3d8dcSGreg Alexander {} 2192cfd3d8dcSGreg Alexander }; 219334cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2194cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2195cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2196cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2197cfd3d8dcSGreg Alexander {} 2198cfd3d8dcSGreg Alexander }; 2199cfd3d8dcSGreg Alexander 2200cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2201cfd3d8dcSGreg Alexander if (present) { 2202cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2203cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2204cfd3d8dcSGreg Alexander } else { 2205cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2206cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2207cfd3d8dcSGreg Alexander } 2208cfd3d8dcSGreg Alexander } 2209cfd3d8dcSGreg Alexander 2210a1d6906eSDavid Henningsson 2211a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2212a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2213a1d6906eSDavid Henningsson { 2214a1d6906eSDavid Henningsson unsigned int present; 2215a1d6906eSDavid Henningsson 2216a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2217a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2218a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2219a1d6906eSDavid Henningsson present ? 1 : 0); 2220a1d6906eSDavid Henningsson } 2221a1d6906eSDavid Henningsson 2222a1d6906eSDavid Henningsson 2223048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2224048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2225048e78a5SDavid Henningsson { 2226048e78a5SDavid Henningsson unsigned int present; 2227048e78a5SDavid Henningsson 2228048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2229048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2230048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2231048e78a5SDavid Henningsson present ? 1 : 3); 2232048e78a5SDavid Henningsson } 2233048e78a5SDavid Henningsson 2234048e78a5SDavid Henningsson 22357b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22367b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22377b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22387b2bfdbcSJens Taprogge { 22397b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22407b2bfdbcSJens Taprogge 224134cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22427b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22437b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22447b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22457b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22467b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22477b2bfdbcSJens Taprogge {} 22487b2bfdbcSJens Taprogge }; 224934cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 22507b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22517b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 22527b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22537b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22547b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22557b2bfdbcSJens Taprogge {} 22567b2bfdbcSJens Taprogge }; 225734cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 22587b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 22597b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 22607b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22617b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22627b2bfdbcSJens Taprogge {} 22637b2bfdbcSJens Taprogge }; 22647b2bfdbcSJens Taprogge 22657b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 22667b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 22677b2bfdbcSJens Taprogge if (ext_present) { 22687b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 22697b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 22707b2bfdbcSJens Taprogge } else if (dock_present) { 22717b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 22727b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 22737b2bfdbcSJens Taprogge } else { 22747b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 22757b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 22767b2bfdbcSJens Taprogge } 22777b2bfdbcSJens Taprogge } 22787b2bfdbcSJens Taprogge 22790fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22800fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22810fb67e98SDaniel Drake { 22820fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22830fb67e98SDaniel Drake unsigned int portA, portD; 22840fb67e98SDaniel Drake 22850fb67e98SDaniel Drake /* Port A */ 2286d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22870fb67e98SDaniel Drake 22880fb67e98SDaniel Drake /* Port D */ 2289d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 22900fb67e98SDaniel Drake 2291a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2292a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 22930fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 22940fb67e98SDaniel Drake portA, portD, spec->hp_present); 22950fb67e98SDaniel Drake cxt5066_update_speaker(codec); 22960fb67e98SDaniel Drake } 22970fb67e98SDaniel Drake 229802b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 229902b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 230002b6b5b6SDavid Henningsson { 230102b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 230202b6b5b6SDavid Henningsson 230302b6b5b6SDavid Henningsson if (spec->dell_vostro) 230402b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 230502b6b5b6SDavid Henningsson else if (spec->ideapad) 230602b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 230702b6b5b6SDavid Henningsson else if (spec->thinkpad) 230802b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 230902b6b5b6SDavid Henningsson else if (spec->hp_laptop) 231002b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2311a1d6906eSDavid Henningsson else if (spec->asus) 2312a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 231302b6b5b6SDavid Henningsson } 231402b6b5b6SDavid Henningsson 23150fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 231675f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23170fb67e98SDaniel Drake { 2318c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23190fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23200fb67e98SDaniel Drake switch (res >> 26) { 23210fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23220fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23230fb67e98SDaniel Drake break; 23240fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2325c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2326c4cfe66cSDaniel Drake if (!spec->dc_enable) 232775f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23280fb67e98SDaniel Drake break; 23290fb67e98SDaniel Drake } 23300fb67e98SDaniel Drake } 23310fb67e98SDaniel Drake 233295a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 233302b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 233495a618bdSEinar Rünkaru { 233502b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 233695a618bdSEinar Rünkaru switch (res >> 26) { 233795a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 233895a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 233995a618bdSEinar Rünkaru break; 234095a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 234102b6b5b6SDavid Henningsson cxt5066_automic(codec); 234295a618bdSEinar Rünkaru break; 234395a618bdSEinar Rünkaru } 234495a618bdSEinar Rünkaru } 234595a618bdSEinar Rünkaru 23467b2bfdbcSJens Taprogge 23470fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 23480fb67e98SDaniel Drake .num_items = 5, 23490fb67e98SDaniel Drake .items = { 23500fb67e98SDaniel Drake { "0dB", 0 }, 23510fb67e98SDaniel Drake { "10dB", 1 }, 23520fb67e98SDaniel Drake { "20dB", 2 }, 23530fb67e98SDaniel Drake { "30dB", 3 }, 23540fb67e98SDaniel Drake { "40dB", 4 }, 23550fb67e98SDaniel Drake }, 23560fb67e98SDaniel Drake }; 23570fb67e98SDaniel Drake 2358cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2359c4cfe66cSDaniel Drake { 2360c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2361cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2362c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2363c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2364c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 23657b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2366cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2367cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2368cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2369cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2370cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2371cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2372cfd3d8dcSGreg Alexander } 2373c4cfe66cSDaniel Drake } 2374c4cfe66cSDaniel Drake 23750fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 23760fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 23770fb67e98SDaniel Drake { 23780fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 23790fb67e98SDaniel Drake } 23800fb67e98SDaniel Drake 23810fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 23820fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23830fb67e98SDaniel Drake { 23840fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2385c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2386c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23870fb67e98SDaniel Drake return 0; 23880fb67e98SDaniel Drake } 23890fb67e98SDaniel Drake 23900fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 23910fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23920fb67e98SDaniel Drake { 23930fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2394c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23950fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 23960fb67e98SDaniel Drake unsigned int idx; 23970fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 23980fb67e98SDaniel Drake if (idx >= imux->num_items) 23990fb67e98SDaniel Drake idx = imux->num_items - 1; 24000fb67e98SDaniel Drake 2401c4cfe66cSDaniel Drake spec->mic_boost = idx; 2402c4cfe66cSDaniel Drake if (!spec->dc_enable) 2403c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2404c4cfe66cSDaniel Drake return 1; 2405c4cfe66cSDaniel Drake } 24060fb67e98SDaniel Drake 2407c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2408c4cfe66cSDaniel Drake { 2409c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2410c4cfe66cSDaniel Drake /* disable gain */ 2411c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2412c4cfe66cSDaniel Drake 2413c4cfe66cSDaniel Drake /* switch to DC input */ 2414c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2415c4cfe66cSDaniel Drake {} 2416c4cfe66cSDaniel Drake }; 2417c4cfe66cSDaniel Drake 2418c4cfe66cSDaniel Drake /* configure as input source */ 2419c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2420c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2421c4cfe66cSDaniel Drake } 2422c4cfe66cSDaniel Drake 2423c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2424c4cfe66cSDaniel Drake { 2425c4cfe66cSDaniel Drake /* reconfigure input source */ 2426c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2427c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2428c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2429c4cfe66cSDaniel Drake } 2430c4cfe66cSDaniel Drake 2431c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2432c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2433c4cfe66cSDaniel Drake { 2434c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2435c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2436c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2437c4cfe66cSDaniel Drake return 0; 2438c4cfe66cSDaniel Drake } 2439c4cfe66cSDaniel Drake 2440c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2441c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2442c4cfe66cSDaniel Drake { 2443c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2444c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2445c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2446c4cfe66cSDaniel Drake 2447c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2448c4cfe66cSDaniel Drake return 0; 2449c4cfe66cSDaniel Drake 2450c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2451c4cfe66cSDaniel Drake if (dc_enable) 2452c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2453c4cfe66cSDaniel Drake else 2454c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2455c4cfe66cSDaniel Drake 2456c4cfe66cSDaniel Drake return 1; 2457c4cfe66cSDaniel Drake } 2458c4cfe66cSDaniel Drake 2459c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2460c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2461c4cfe66cSDaniel Drake { 2462c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2463c4cfe66cSDaniel Drake } 2464c4cfe66cSDaniel Drake 2465c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2466c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2467c4cfe66cSDaniel Drake { 2468c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2469c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2470c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2471c4cfe66cSDaniel Drake return 0; 2472c4cfe66cSDaniel Drake } 2473c4cfe66cSDaniel Drake 2474c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2475c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2476c4cfe66cSDaniel Drake { 2477c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2478c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2479c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2480c4cfe66cSDaniel Drake unsigned int idx; 2481c4cfe66cSDaniel Drake 2482c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2483c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2484c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2485c4cfe66cSDaniel Drake 2486c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2487c4cfe66cSDaniel Drake if (spec->dc_enable) 2488c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 24890fb67e98SDaniel Drake return 1; 24900fb67e98SDaniel Drake } 24910fb67e98SDaniel Drake 249275f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 249375f8991dSDaniel Drake { 249475f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 249575f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 249675f8991dSDaniel Drake * recording LED comes on. */ 249775f8991dSDaniel Drake spec->recording = 1; 249875f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 249975f8991dSDaniel Drake } 250075f8991dSDaniel Drake 250175f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 250275f8991dSDaniel Drake { 250375f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 250475f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 250575f8991dSDaniel Drake /* disable external mic, port B */ 250675f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 250775f8991dSDaniel Drake 250875f8991dSDaniel Drake /* disble internal mic, port C */ 250975f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2510c4cfe66cSDaniel Drake 2511c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2512c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 251375f8991dSDaniel Drake {}, 251475f8991dSDaniel Drake }; 251575f8991dSDaniel Drake 251675f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 251775f8991dSDaniel Drake spec->recording = 0; 251875f8991dSDaniel Drake } 251975f8991dSDaniel Drake 2520f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 252134cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2522f6a2491cSAndy Robinson int num_pins) 2523f6a2491cSAndy Robinson { 2524f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2525f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2526f6a2491cSAndy Robinson int i; 2527f6a2491cSAndy Robinson 2528f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2529f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2530f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2531f6a2491cSAndy Robinson continue; 2532f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2533f6a2491cSAndy Robinson continue; 2534f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2535f6a2491cSAndy Robinson nid_loc++; 2536f6a2491cSAndy Robinson else 2537f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2538f6a2491cSAndy Robinson } 2539f6a2491cSAndy Robinson } 2540f6a2491cSAndy Robinson 254134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25420fb67e98SDaniel Drake .num_items = 4, 25430fb67e98SDaniel Drake .items = { 25440fb67e98SDaniel Drake { "Mic B", 0 }, 25450fb67e98SDaniel Drake { "Mic C", 1 }, 25460fb67e98SDaniel Drake { "Mic E", 2 }, 25470fb67e98SDaniel Drake { "Mic F", 3 }, 25480fb67e98SDaniel Drake }, 25490fb67e98SDaniel Drake }; 25500fb67e98SDaniel Drake 255134cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 25520fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 25530fb67e98SDaniel Drake .values = { 25540fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25550fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25560fb67e98SDaniel Drake 0 25570fb67e98SDaniel Drake }, 25580fb67e98SDaniel Drake }; 25590fb67e98SDaniel Drake 256034cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 25610fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 25620fb67e98SDaniel Drake .values = { 25630fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25640fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25650fb67e98SDaniel Drake 0 25660fb67e98SDaniel Drake }, 25670fb67e98SDaniel Drake }; 25680fb67e98SDaniel Drake 256934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 25700fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 25710fb67e98SDaniel Drake {} 25720fb67e98SDaniel Drake }; 25730fb67e98SDaniel Drake 257434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 25750fb67e98SDaniel Drake { 25760fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25770fb67e98SDaniel Drake .name = "Master Playback Volume", 25780fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 25790fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 25800fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 25815e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 25820fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 25830fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 25840fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 25850fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 25860fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 25870fb67e98SDaniel Drake .private_value = 25880fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 25890fb67e98SDaniel Drake }, 25900fb67e98SDaniel Drake {} 25910fb67e98SDaniel Drake }; 25920fb67e98SDaniel Drake 259334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2594c4cfe66cSDaniel Drake { 2595c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2596c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2597c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2598c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2599c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2600c4cfe66cSDaniel Drake }, 2601c4cfe66cSDaniel Drake { 2602c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2603c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2604c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2605c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2606c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2607c4cfe66cSDaniel Drake }, 2608c4cfe66cSDaniel Drake {} 2609c4cfe66cSDaniel Drake }; 2610c4cfe66cSDaniel Drake 261134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 26120fb67e98SDaniel Drake { 26130fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26140fb67e98SDaniel Drake .name = "Master Playback Switch", 26150fb67e98SDaniel Drake .info = cxt_eapd_info, 26160fb67e98SDaniel Drake .get = cxt_eapd_get, 26170fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26180fb67e98SDaniel Drake .private_value = 0x1d, 26190fb67e98SDaniel Drake }, 26200fb67e98SDaniel Drake 26210fb67e98SDaniel Drake { 26220fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2623c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26240fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26250fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26260fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26270fb67e98SDaniel Drake }, 26280fb67e98SDaniel Drake 26290fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26300fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26310fb67e98SDaniel Drake {} 26320fb67e98SDaniel Drake }; 26330fb67e98SDaniel Drake 263434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2635254bba6aSEinar Rünkaru { 2636254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 263728c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2638254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2639254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2640254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2641254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2642254bba6aSEinar Rünkaru }, 2643254bba6aSEinar Rünkaru {} 2644254bba6aSEinar Rünkaru }; 2645254bba6aSEinar Rünkaru 264634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 26470fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 26480fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 26490fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 26500fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 26510fb67e98SDaniel Drake 26520fb67e98SDaniel Drake /* Speakers */ 26530fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26540fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26550fb67e98SDaniel Drake 26560fb67e98SDaniel Drake /* HP, Amp */ 26570fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26580fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26590fb67e98SDaniel Drake 26600fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26610fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26620fb67e98SDaniel Drake 26630fb67e98SDaniel Drake /* DAC1 */ 26640fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26650fb67e98SDaniel Drake 26660fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 26670fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26680fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26690fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 26700fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26710fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 26720fb67e98SDaniel Drake 26730fb67e98SDaniel Drake /* no digital microphone support yet */ 26740fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26750fb67e98SDaniel Drake 26760fb67e98SDaniel Drake /* Audio input selector */ 26770fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26780fb67e98SDaniel Drake 26790fb67e98SDaniel Drake /* SPDIF route: PCM */ 26800fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 26810fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 26820fb67e98SDaniel Drake 26830fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26840fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26850fb67e98SDaniel Drake 26860fb67e98SDaniel Drake /* EAPD */ 26870fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26880fb67e98SDaniel Drake 26890fb67e98SDaniel Drake /* not handling these yet */ 26900fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26910fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26920fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26930fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26940fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26950fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26960fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26970fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 26980fb67e98SDaniel Drake { } /* end */ 26990fb67e98SDaniel Drake }; 27000fb67e98SDaniel Drake 270134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27020fb67e98SDaniel Drake /* Port A: headphones */ 27030fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27040fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27050fb67e98SDaniel Drake 27060fb67e98SDaniel Drake /* Port B: external microphone */ 270775f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27080fb67e98SDaniel Drake 27090fb67e98SDaniel Drake /* Port C: internal microphone */ 271075f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27110fb67e98SDaniel Drake 27120fb67e98SDaniel Drake /* Port D: unused */ 27130fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27140fb67e98SDaniel Drake 27150fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27160fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27170fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27180fb67e98SDaniel Drake 2719c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27200fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27210fb67e98SDaniel Drake 27220fb67e98SDaniel Drake /* Port G: internal speakers */ 27230fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27240fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27250fb67e98SDaniel Drake 27260fb67e98SDaniel Drake /* DAC1 */ 27270fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27280fb67e98SDaniel Drake 27290fb67e98SDaniel Drake /* DAC2: unused */ 27300fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27310fb67e98SDaniel Drake 27320fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27330fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27340fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27350fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27360fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27370fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27380fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27390fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27400fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27410fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27420fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27430fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27440fb67e98SDaniel Drake 27450fb67e98SDaniel Drake /* Disable digital microphone port */ 27460fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27470fb67e98SDaniel Drake 27480fb67e98SDaniel Drake /* Audio input selectors */ 27490fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27500fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 27510fb67e98SDaniel Drake 27520fb67e98SDaniel Drake /* Disable SPDIF */ 27530fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27540fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27550fb67e98SDaniel Drake 27560fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 27570fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 27580fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 27590fb67e98SDaniel Drake { } /* end */ 27600fb67e98SDaniel Drake }; 27610fb67e98SDaniel Drake 276234cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 276395a618bdSEinar Rünkaru /* Port A: headphones */ 276495a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 276595a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 276695a618bdSEinar Rünkaru 276795a618bdSEinar Rünkaru /* Port B: external microphone */ 276895a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 276995a618bdSEinar Rünkaru 277095a618bdSEinar Rünkaru /* Port C: unused */ 277195a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277295a618bdSEinar Rünkaru 277395a618bdSEinar Rünkaru /* Port D: unused */ 277495a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277595a618bdSEinar Rünkaru 277695a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 277795a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277895a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 277995a618bdSEinar Rünkaru 278095a618bdSEinar Rünkaru /* Port F: unused */ 278195a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278295a618bdSEinar Rünkaru 278395a618bdSEinar Rünkaru /* Port G: internal speakers */ 278495a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 278595a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 278695a618bdSEinar Rünkaru 278795a618bdSEinar Rünkaru /* DAC1 */ 278895a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 278995a618bdSEinar Rünkaru 279095a618bdSEinar Rünkaru /* DAC2: unused */ 279195a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 279295a618bdSEinar Rünkaru 279395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 279495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 279595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 279695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 279795a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 279895a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 279995a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280195a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 280295a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 280395a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280595a618bdSEinar Rünkaru 280695a618bdSEinar Rünkaru /* Digital microphone port */ 280795a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 280895a618bdSEinar Rünkaru 280995a618bdSEinar Rünkaru /* Audio input selectors */ 281095a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 281195a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 281295a618bdSEinar Rünkaru 281395a618bdSEinar Rünkaru /* Disable SPDIF */ 281495a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 281595a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 281695a618bdSEinar Rünkaru 281795a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 281895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 281995a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 282095a618bdSEinar Rünkaru { } /* end */ 282195a618bdSEinar Rünkaru }; 282295a618bdSEinar Rünkaru 282334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2824cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2825cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2826cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2827cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2828cfd3d8dcSGreg Alexander 2829cfd3d8dcSGreg Alexander /* Speakers */ 2830cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2831cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2832cfd3d8dcSGreg Alexander 2833cfd3d8dcSGreg Alexander /* HP, Amp */ 2834cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2835cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2836cfd3d8dcSGreg Alexander 2837cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2838cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2839cfd3d8dcSGreg Alexander 2840cfd3d8dcSGreg Alexander /* DAC1 */ 2841cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2842cfd3d8dcSGreg Alexander 2843cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2844cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2845cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2846cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2847cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2848cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2849cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2850cfd3d8dcSGreg Alexander 2851cfd3d8dcSGreg Alexander /* Audio input selector */ 2852cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2853cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2854cfd3d8dcSGreg Alexander 2855cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2856cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2857cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2858cfd3d8dcSGreg Alexander 2859cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2860cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2861cfd3d8dcSGreg Alexander 2862cfd3d8dcSGreg Alexander /* internal microphone */ 286328c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2864cfd3d8dcSGreg Alexander 2865cfd3d8dcSGreg Alexander /* EAPD */ 2866cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2867cfd3d8dcSGreg Alexander 2868cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2869cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2870cfd3d8dcSGreg Alexander { } /* end */ 2871cfd3d8dcSGreg Alexander }; 2872cfd3d8dcSGreg Alexander 287334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 28747b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 28757b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 28767b2bfdbcSJens Taprogge 28777b2bfdbcSJens Taprogge /* Port G: internal speakers */ 28787b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28797b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28807b2bfdbcSJens Taprogge 28817b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 28827b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28837b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28847b2bfdbcSJens Taprogge 28857b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 28867b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28877b2bfdbcSJens Taprogge 28887b2bfdbcSJens Taprogge /* Port C: Mic */ 28897b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28907b2bfdbcSJens Taprogge 28917b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 28927b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28937b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28947b2bfdbcSJens Taprogge 28957b2bfdbcSJens Taprogge /* DAC1 */ 28967b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28977b2bfdbcSJens Taprogge 28987b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 28997b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29007b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29017b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29027b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29037b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29047b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29057b2bfdbcSJens Taprogge 29067b2bfdbcSJens Taprogge /* Audio input selector */ 29077b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29087b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29097b2bfdbcSJens Taprogge 29107b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29117b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29127b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29137b2bfdbcSJens Taprogge 29147b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29157b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29167b2bfdbcSJens Taprogge 29177b2bfdbcSJens Taprogge /* internal microphone */ 291828c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29197b2bfdbcSJens Taprogge 29207b2bfdbcSJens Taprogge /* EAPD */ 29217b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29227b2bfdbcSJens Taprogge 29237b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29247b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29257b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29267b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29277b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29287b2bfdbcSJens Taprogge { } /* end */ 29297b2bfdbcSJens Taprogge }; 29307b2bfdbcSJens Taprogge 293134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29320fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29330fb67e98SDaniel Drake { } /* end */ 29340fb67e98SDaniel Drake }; 29350fb67e98SDaniel Drake 2936048e78a5SDavid Henningsson 293734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2938048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2939048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2940048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2941048e78a5SDavid Henningsson { } /* end */ 2942048e78a5SDavid Henningsson }; 2943048e78a5SDavid Henningsson 29440fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29450fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29460fb67e98SDaniel Drake { 29470fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 29480fb67e98SDaniel Drake conexant_init(codec); 29490fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 29500fb67e98SDaniel Drake cxt5066_hp_automute(codec); 295102b6b5b6SDavid Henningsson cxt5066_automic(codec); 29520fb67e98SDaniel Drake } 2953c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 29540fb67e98SDaniel Drake return 0; 29550fb67e98SDaniel Drake } 29560fb67e98SDaniel Drake 295775f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 295875f8991dSDaniel Drake { 2959c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 296075f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 296175f8991dSDaniel Drake conexant_init(codec); 296275f8991dSDaniel Drake cxt5066_hp_automute(codec); 2963c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2964c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 296575f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2966c4cfe66cSDaniel Drake } else { 2967c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2968c4cfe66cSDaniel Drake } 296975f8991dSDaniel Drake return 0; 297075f8991dSDaniel Drake } 297175f8991dSDaniel Drake 29720fb67e98SDaniel Drake enum { 29730fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 29740fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 29750fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 29761feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2977cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 29787b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2979a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2980048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 2981fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 29820fb67e98SDaniel Drake CXT5066_MODELS 29830fb67e98SDaniel Drake }; 29840fb67e98SDaniel Drake 2985ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 29860fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 29870fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 29880fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 29891feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 2990cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 29917b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 2992a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 2993048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 2994fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 29950fb67e98SDaniel Drake }; 29960fb67e98SDaniel Drake 299734cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 29989966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 299900cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30001feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30018a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3002ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30031feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3004231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3005ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3006ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3007048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3008f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3009a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3010f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 30112ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3012c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30135637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30145637edb2SDavid Henningsson CXT5066_LAPTOP), 30155637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30164d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3017ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 301819593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 301929c5fbbcSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), 3020ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 302184012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3022b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3023d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3024a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3025af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 30267ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 30270fb67e98SDaniel Drake {} 30280fb67e98SDaniel Drake }; 30290fb67e98SDaniel Drake 30300fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30310fb67e98SDaniel Drake { 30320fb67e98SDaniel Drake struct conexant_spec *spec; 30330fb67e98SDaniel Drake int board_config; 30340fb67e98SDaniel Drake 3035fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3036fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3037fea4a4f9STakashi Iwai if (board_config < 0) 3038c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3039fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3040fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3041fea4a4f9STakashi Iwai 30420fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30430fb67e98SDaniel Drake if (!spec) 30440fb67e98SDaniel Drake return -ENOMEM; 30450fb67e98SDaniel Drake codec->spec = spec; 30460fb67e98SDaniel Drake 30470fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 304875f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 30490fb67e98SDaniel Drake 30500fb67e98SDaniel Drake spec->dell_automute = 0; 30510fb67e98SDaniel Drake spec->multiout.max_channels = 2; 30520fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 30530fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3054f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3055f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 30560fb67e98SDaniel Drake spec->num_adc_nids = 1; 30570fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 30580fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 30590fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 30600fb67e98SDaniel Drake 30610fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 30620fb67e98SDaniel Drake 30630fb67e98SDaniel Drake spec->num_init_verbs = 1; 30640fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 30650fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 30660fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 30670fb67e98SDaniel Drake spec->cur_adc = 0; 30680fb67e98SDaniel Drake spec->cur_adc_idx = 0; 30690fb67e98SDaniel Drake 30703507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 30713507e2a8STakashi Iwai 30720fb67e98SDaniel Drake switch (board_config) { 30730fb67e98SDaniel Drake default: 30740fb67e98SDaniel Drake case CXT5066_LAPTOP: 30750fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30760fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30770fb67e98SDaniel Drake break; 30780fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 30790fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30800fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30810fb67e98SDaniel Drake 30820fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 30830fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 30840fb67e98SDaniel Drake spec->num_init_verbs++; 30850fb67e98SDaniel Drake spec->dell_automute = 1; 30860fb67e98SDaniel Drake break; 3087a1d6906eSDavid Henningsson case CXT5066_ASUS: 3088048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3089048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 309002b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3091048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3092048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3093048e78a5SDavid Henningsson spec->num_init_verbs++; 3094a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3095a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3096048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3097048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3098048e78a5SDavid Henningsson /* no S/PDIF out */ 3099f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3100048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3101048e78a5SDavid Henningsson /* input source automatically selected */ 3102048e78a5SDavid Henningsson spec->input_mux = NULL; 3103048e78a5SDavid Henningsson spec->port_d_mode = 0; 3104048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3105048e78a5SDavid Henningsson break; 3106048e78a5SDavid Henningsson 31070fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 310875f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 310975f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31100fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31110fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3112c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31130fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31140fb67e98SDaniel Drake spec->port_d_mode = 0; 3115c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31160fb67e98SDaniel Drake 31170fb67e98SDaniel Drake /* no S/PDIF out */ 31180fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31190fb67e98SDaniel Drake 31200fb67e98SDaniel Drake /* input source automatically selected */ 31210fb67e98SDaniel Drake spec->input_mux = NULL; 312275f8991dSDaniel Drake 312375f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 312475f8991dSDaniel Drake * at the right time */ 312575f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 312675f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31270fb67e98SDaniel Drake break; 31281feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 312975f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 313002b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 313195a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 313295a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 313395a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3134254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 313595a618bdSEinar Rünkaru spec->port_d_mode = 0; 3136254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3137c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 313895a618bdSEinar Rünkaru 313995a618bdSEinar Rünkaru /* no S/PDIF out */ 314095a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 314195a618bdSEinar Rünkaru 314295a618bdSEinar Rünkaru /* input source automatically selected */ 314395a618bdSEinar Rünkaru spec->input_mux = NULL; 314495a618bdSEinar Rünkaru break; 3145cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3146cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 314702b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3148cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3149cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3150cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3151cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3152cfd3d8dcSGreg Alexander spec->ideapad = 1; 3153cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3154cfd3d8dcSGreg Alexander 3155cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3156cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3157cfd3d8dcSGreg Alexander 3158cfd3d8dcSGreg Alexander /* input source automatically selected */ 3159cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3160cfd3d8dcSGreg Alexander break; 31617b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 31627b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 316302b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 31647b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31657b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31667b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 31677b2bfdbcSJens Taprogge spec->thinkpad = 1; 31687b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 31697b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 31707b2bfdbcSJens Taprogge 31717b2bfdbcSJens Taprogge /* no S/PDIF out */ 31727b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 31737b2bfdbcSJens Taprogge 31747b2bfdbcSJens Taprogge /* input source automatically selected */ 31757b2bfdbcSJens Taprogge spec->input_mux = NULL; 31767b2bfdbcSJens Taprogge break; 31770fb67e98SDaniel Drake } 31780fb67e98SDaniel Drake 31793507e2a8STakashi Iwai if (spec->beep_amp) 31803507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 31813507e2a8STakashi Iwai 31820fb67e98SDaniel Drake return 0; 31830fb67e98SDaniel Drake } 3184461e2c78STakashi Iwai 3185461e2c78STakashi Iwai /* 3186f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3187f2e5731dSTakashi Iwai */ 3188f2e5731dSTakashi Iwai 31896764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 31906764bcefSTakashi Iwai struct hda_codec *codec, 31916764bcefSTakashi Iwai unsigned int stream_tag, 31926764bcefSTakashi Iwai unsigned int format, 31936764bcefSTakashi Iwai struct snd_pcm_substream *substream) 31946764bcefSTakashi Iwai { 31956764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 319647ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 31976764bcefSTakashi Iwai if (spec->adc_switching) { 31986764bcefSTakashi Iwai spec->cur_adc = adc; 31996764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32006764bcefSTakashi Iwai spec->cur_adc_format = format; 32016764bcefSTakashi Iwai } 32026764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32036764bcefSTakashi Iwai return 0; 32046764bcefSTakashi Iwai } 32056764bcefSTakashi Iwai 32066764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 32076764bcefSTakashi Iwai struct hda_codec *codec, 32086764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32096764bcefSTakashi Iwai { 32106764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32116764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 32126764bcefSTakashi Iwai spec->cur_adc = 0; 32136764bcefSTakashi Iwai return 0; 32146764bcefSTakashi Iwai } 32156764bcefSTakashi Iwai 32166764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32176764bcefSTakashi Iwai .substreams = 1, 32186764bcefSTakashi Iwai .channels_min = 2, 32196764bcefSTakashi Iwai .channels_max = 2, 32206764bcefSTakashi Iwai .nid = 0, /* fill later */ 32216764bcefSTakashi Iwai .ops = { 32226764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32236764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32246764bcefSTakashi Iwai }, 32256764bcefSTakashi Iwai }; 32266764bcefSTakashi Iwai 322734cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3228f2e5731dSTakashi Iwai 32298d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 32308d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3231f2e5731dSTakashi Iwai 3232f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3233f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3234f2e5731dSTakashi Iwai * not found 3235f2e5731dSTakashi Iwai */ 3236f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3237f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3238f2e5731dSTakashi Iwai { 3239f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3240f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3241f2e5731dSTakashi Iwai 3242f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3243f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3244f2e5731dSTakashi Iwai ret = dacs[i]; 3245f2e5731dSTakashi Iwai break; 3246f2e5731dSTakashi Iwai } 3247f2e5731dSTakashi Iwai } 3248f2e5731dSTakashi Iwai if (!ret) 3249f2e5731dSTakashi Iwai return 0; 3250f2e5731dSTakashi Iwai if (--nums > 0) 3251f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3252f2e5731dSTakashi Iwai *num_dacs = nums; 3253f2e5731dSTakashi Iwai return ret; 3254f2e5731dSTakashi Iwai } 3255f2e5731dSTakashi Iwai 3256f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3257f2e5731dSTakashi Iwai 32581f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 32591f015f5fSTakashi Iwai 3260f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3261f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3262f2e5731dSTakashi Iwai { 3263f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3264f2e5731dSTakashi Iwai int nums = 0; 3265f2e5731dSTakashi Iwai 3266f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3267f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3268f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3269f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3270f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3271f2e5731dSTakashi Iwai dacs[nums++] = nid; 3272f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3273f2e5731dSTakashi Iwai break; 3274f2e5731dSTakashi Iwai } 3275f2e5731dSTakashi Iwai } 3276f2e5731dSTakashi Iwai return nums; 3277f2e5731dSTakashi Iwai } 3278f2e5731dSTakashi Iwai 3279f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3280f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3281f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3282468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3283468c5458SDavid Henningsson int type) 3284f2e5731dSTakashi Iwai { 3285468c5458SDavid Henningsson int i, start = nums; 3286f2e5731dSTakashi Iwai 3287468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3288f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3289f2e5731dSTakashi Iwai filled[nums].type = type; 3290f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3291468c5458SDavid Henningsson if (filled[nums].dac) 3292468c5458SDavid Henningsson continue; 3293468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3294468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3295468c5458SDavid Henningsson continue; 3296468c5458SDavid Henningsson } 3297468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 32981f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3299468c5458SDavid Henningsson continue; 3300468c5458SDavid Henningsson } 3301468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3302f2e5731dSTakashi Iwai } 3303f2e5731dSTakashi Iwai return nums; 3304f2e5731dSTakashi Iwai } 3305f2e5731dSTakashi Iwai 3306f2e5731dSTakashi Iwai /* parse analog output paths */ 3307f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3308f2e5731dSTakashi Iwai { 3309f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3310f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3311f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3312f2e5731dSTakashi Iwai int i, j, nums, rest; 3313f2e5731dSTakashi Iwai 3314f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3315f2e5731dSTakashi Iwai /* parse all analog output pins */ 3316f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3317468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3318f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3319468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3320468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3321f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3322468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3323468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3324f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3325f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3326f2e5731dSTakashi Iwai /* fill multiout struct */ 3327f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3328f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 33291f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3330f2e5731dSTakashi Iwai continue; 3331f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3332f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3333f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3334f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3335f2e5731dSTakashi Iwai break; 3336f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3337f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3338f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3339f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3340f2e5731dSTakashi Iwai break; 3341f2e5731dSTakashi Iwai } 3342f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3343f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3344f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3345f2e5731dSTakashi Iwai break; 3346f2e5731dSTakashi Iwai } 3347f2e5731dSTakashi Iwai break; 3348f2e5731dSTakashi Iwai } 3349f2e5731dSTakashi Iwai } 3350f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 335189724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3352f2e5731dSTakashi Iwai 335303697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 335403697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3355f2e5731dSTakashi Iwai spec->auto_mute = 1; 335603697e2aSTakashi Iwai break; 335703697e2aSTakashi Iwai } 335803697e2aSTakashi Iwai } 3359e2df82ffSTakashi Iwai if (spec->auto_mute && 3360e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3361e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 336203697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 336303697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 336403697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 336503697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 336603697e2aSTakashi Iwai spec->detect_line = 1; 336703697e2aSTakashi Iwai break; 336803697e2aSTakashi Iwai } 336903697e2aSTakashi Iwai } 337003697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 337103697e2aSTakashi Iwai } 337203697e2aSTakashi Iwai 3373f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3374f2e5731dSTakashi Iwai } 3375f2e5731dSTakashi Iwai 3376da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3377da339866STakashi Iwai hda_nid_t *pins, bool on); 3378da339866STakashi Iwai 337903697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 338003697e2aSTakashi Iwai hda_nid_t *pins, bool on) 338103697e2aSTakashi Iwai { 3382254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 338303697e2aSTakashi Iwai int i; 338403697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 338503697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 338603697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 338703697e2aSTakashi Iwai on ? PIN_OUT : 0); 3388254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 338903697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 339003697e2aSTakashi Iwai } 339103697e2aSTakashi Iwai 339203697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 339303697e2aSTakashi Iwai { 339403697e2aSTakashi Iwai int i, present = 0; 339503697e2aSTakashi Iwai 339603697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 339703697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 339803697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 339903697e2aSTakashi Iwai break; 340003697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 340103697e2aSTakashi Iwai } 340203697e2aSTakashi Iwai return present; 340303697e2aSTakashi Iwai } 340403697e2aSTakashi Iwai 3405f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 340603697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 340703697e2aSTakashi Iwai { 340803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 340903697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3410e2df82ffSTakashi Iwai int on = 1; 341103697e2aSTakashi Iwai 3412e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3413254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3414e2df82ffSTakashi Iwai if (spec->auto_mute) 3415e2df82ffSTakashi Iwai on = spec->hp_present; 341603697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3417254f2968STakashi Iwai } 3418254f2968STakashi Iwai 3419e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3420e2df82ffSTakashi Iwai if (spec->auto_mute) 3421e2df82ffSTakashi Iwai on = !(spec->hp_present || 3422e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3423e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 342403697e2aSTakashi Iwai 342503697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 342603697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 342703697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 342803697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 342903697e2aSTakashi Iwai return; 3430e2df82ffSTakashi Iwai if (spec->auto_mute) { 3431e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3432e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3433e2df82ffSTakashi Iwai spec->automute_lines) 3434e2df82ffSTakashi Iwai on = !spec->hp_present; 343503697e2aSTakashi Iwai else 3436e2df82ffSTakashi Iwai on = 1; 3437e2df82ffSTakashi Iwai } 3438e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 343903697e2aSTakashi Iwai } 344003697e2aSTakashi Iwai 3441f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3442f2e5731dSTakashi Iwai { 3443f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3444f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3445f2e5731dSTakashi Iwai 3446f2e5731dSTakashi Iwai if (!spec->auto_mute) 3447f2e5731dSTakashi Iwai return; 344803697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 344903697e2aSTakashi Iwai cx_auto_update_speakers(codec); 345003697e2aSTakashi Iwai } 345103697e2aSTakashi Iwai 345203697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 345303697e2aSTakashi Iwai { 345403697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 345503697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 345603697e2aSTakashi Iwai 345703697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 345803697e2aSTakashi Iwai return; 345903697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 346003697e2aSTakashi Iwai cfg->line_out_pins); 346103697e2aSTakashi Iwai cx_auto_update_speakers(codec); 346203697e2aSTakashi Iwai } 346303697e2aSTakashi Iwai 346403697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 346503697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 346603697e2aSTakashi Iwai { 346703697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 346803697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 346903697e2aSTakashi Iwai static const char * const texts2[] = { 347003697e2aSTakashi Iwai "Disabled", "Enabled" 347103697e2aSTakashi Iwai }; 347203697e2aSTakashi Iwai static const char * const texts3[] = { 347303697e2aSTakashi Iwai "Disabled", "Speaker Only", "Line-Out+Speaker" 347403697e2aSTakashi Iwai }; 347503697e2aSTakashi Iwai const char * const *texts; 347603697e2aSTakashi Iwai 347703697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 347803697e2aSTakashi Iwai uinfo->count = 1; 347903697e2aSTakashi Iwai if (spec->automute_hp_lo) { 348003697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 348103697e2aSTakashi Iwai texts = texts3; 348203697e2aSTakashi Iwai } else { 348303697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 348403697e2aSTakashi Iwai texts = texts2; 348503697e2aSTakashi Iwai } 348603697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 348703697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 348803697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 348903697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 349003697e2aSTakashi Iwai return 0; 349103697e2aSTakashi Iwai } 349203697e2aSTakashi Iwai 349303697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 349403697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 349503697e2aSTakashi Iwai { 349603697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 349703697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 349803697e2aSTakashi Iwai unsigned int val; 349903697e2aSTakashi Iwai if (!spec->auto_mute) 350003697e2aSTakashi Iwai val = 0; 350103697e2aSTakashi Iwai else if (!spec->automute_lines) 350203697e2aSTakashi Iwai val = 1; 350303697e2aSTakashi Iwai else 350403697e2aSTakashi Iwai val = 2; 350503697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 350603697e2aSTakashi Iwai return 0; 350703697e2aSTakashi Iwai } 350803697e2aSTakashi Iwai 350903697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 351003697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 351103697e2aSTakashi Iwai { 351203697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 351303697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 351403697e2aSTakashi Iwai 351503697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 351603697e2aSTakashi Iwai case 0: 351703697e2aSTakashi Iwai if (!spec->auto_mute) 351803697e2aSTakashi Iwai return 0; 351903697e2aSTakashi Iwai spec->auto_mute = 0; 3520f2e5731dSTakashi Iwai break; 352103697e2aSTakashi Iwai case 1: 352203697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 352303697e2aSTakashi Iwai return 0; 352403697e2aSTakashi Iwai spec->auto_mute = 1; 352503697e2aSTakashi Iwai spec->automute_lines = 0; 352603697e2aSTakashi Iwai break; 352703697e2aSTakashi Iwai case 2: 352803697e2aSTakashi Iwai if (!spec->automute_hp_lo) 352903697e2aSTakashi Iwai return -EINVAL; 353003697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 353103697e2aSTakashi Iwai return 0; 353203697e2aSTakashi Iwai spec->auto_mute = 1; 353303697e2aSTakashi Iwai spec->automute_lines = 1; 353403697e2aSTakashi Iwai break; 353503697e2aSTakashi Iwai default: 353603697e2aSTakashi Iwai return -EINVAL; 3537f2e5731dSTakashi Iwai } 353803697e2aSTakashi Iwai cx_auto_update_speakers(codec); 353903697e2aSTakashi Iwai return 1; 3540f2e5731dSTakashi Iwai } 354103697e2aSTakashi Iwai 354203697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 354303697e2aSTakashi Iwai { 354403697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 354503697e2aSTakashi Iwai .name = "Auto-Mute Mode", 354603697e2aSTakashi Iwai .info = cx_automute_mode_info, 354703697e2aSTakashi Iwai .get = cx_automute_mode_get, 354803697e2aSTakashi Iwai .put = cx_automute_mode_put, 354903697e2aSTakashi Iwai }, 355003697e2aSTakashi Iwai { } 355103697e2aSTakashi Iwai }; 3552f2e5731dSTakashi Iwai 35536764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 35546764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 35556764bcefSTakashi Iwai { 35566764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35576764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35586764bcefSTakashi Iwai 35596764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 35606764bcefSTakashi Iwai } 35616764bcefSTakashi Iwai 35626764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 35636764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35646764bcefSTakashi Iwai { 35656764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35666764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35676764bcefSTakashi Iwai 35686764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 35696764bcefSTakashi Iwai return 0; 35706764bcefSTakashi Iwai } 35716764bcefSTakashi Iwai 35725c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 35735c9887e0STakashi Iwai * if do_select is set, actually select the route. 35745c9887e0STakashi Iwai */ 35755c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3576cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3577cf27f29aSTakashi Iwai bool do_select, int depth) 35785c9887e0STakashi Iwai { 35795c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 35805c9887e0STakashi Iwai int i, nums; 35815c9887e0STakashi Iwai 3582cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3583cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3584cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3585cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3586cf27f29aSTakashi Iwai break; 3587cf27f29aSTakashi Iwai default: 3588cf27f29aSTakashi Iwai return -1; 3589cf27f29aSTakashi Iwai } 3590cf27f29aSTakashi Iwai 35915c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 35925c9887e0STakashi Iwai for (i = 0; i < nums; i++) 35935c9887e0STakashi Iwai if (conn[i] == pin) { 35945c9887e0STakashi Iwai if (do_select) 35955c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 35965c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3597cf27f29aSTakashi Iwai if (srcp) 3598cf27f29aSTakashi Iwai *srcp = mux; 35995c9887e0STakashi Iwai return i; 36005c9887e0STakashi Iwai } 36015c9887e0STakashi Iwai depth++; 36025c9887e0STakashi Iwai if (depth == 2) 36035c9887e0STakashi Iwai return -1; 36045c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3605cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 36065c9887e0STakashi Iwai do_select, depth); 36075c9887e0STakashi Iwai if (ret >= 0) { 36085c9887e0STakashi Iwai if (do_select) 36095c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36105c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3611cf27f29aSTakashi Iwai return i; 36125c9887e0STakashi Iwai } 36135c9887e0STakashi Iwai } 36145c9887e0STakashi Iwai return -1; 36155c9887e0STakashi Iwai } 36165c9887e0STakashi Iwai 36175c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36185c9887e0STakashi Iwai hda_nid_t pin) 36195c9887e0STakashi Iwai { 3620cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36215c9887e0STakashi Iwai } 36225c9887e0STakashi Iwai 36235c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 36245c9887e0STakashi Iwai hda_nid_t pin) 36255c9887e0STakashi Iwai { 3626cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 36275c9887e0STakashi Iwai } 36285c9887e0STakashi Iwai 36296764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 36306764bcefSTakashi Iwai const struct hda_input_mux *imux, 36316764bcefSTakashi Iwai unsigned int idx) 36326764bcefSTakashi Iwai { 36336764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36346764bcefSTakashi Iwai hda_nid_t adc; 3635313d2c06STakashi Iwai int changed = 1; 36366764bcefSTakashi Iwai 36376764bcefSTakashi Iwai if (!imux->num_items) 36386764bcefSTakashi Iwai return 0; 36396764bcefSTakashi Iwai if (idx >= imux->num_items) 36406764bcefSTakashi Iwai idx = imux->num_items - 1; 36416764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3642313d2c06STakashi Iwai changed = 0; 364347ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 364447ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 364547ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 36466764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 36476764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 36486764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 36496764bcefSTakashi Iwai spec->cur_adc = adc; 36506764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 36516764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 36526764bcefSTakashi Iwai spec->cur_adc_format); 36536764bcefSTakashi Iwai } 36546764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3655313d2c06STakashi Iwai return changed; 36566764bcefSTakashi Iwai } 36576764bcefSTakashi Iwai 36586764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 36596764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36606764bcefSTakashi Iwai { 36616764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36626764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36636764bcefSTakashi Iwai 36646764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 36656764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 36666764bcefSTakashi Iwai } 36676764bcefSTakashi Iwai 36686764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 36696764bcefSTakashi Iwai { 36706764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 36716764bcefSTakashi Iwai .name = "Capture Source", 36726764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 36736764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 36746764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 36756764bcefSTakashi Iwai }, 36766764bcefSTakashi Iwai {} 36776764bcefSTakashi Iwai }; 36786764bcefSTakashi Iwai 367943c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 368043c1b2e9STakashi Iwai { 368143c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 368243c1b2e9STakashi Iwai if (idx < 0) 368343c1b2e9STakashi Iwai return false; 368443c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 368543c1b2e9STakashi Iwai return false; 368643c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 368743c1b2e9STakashi Iwai return true; 368843c1b2e9STakashi Iwai } 368943c1b2e9STakashi Iwai 3690f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3691f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3692f2e5731dSTakashi Iwai { 3693f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3694f2e5731dSTakashi Iwai 3695f2e5731dSTakashi Iwai if (!spec->auto_mic) 3696f2e5731dSTakashi Iwai return; 369743c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 369843c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 369943c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3700f2e5731dSTakashi Iwai } 3701f2e5731dSTakashi Iwai 3702f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3703f2e5731dSTakashi Iwai { 37043a93897eSTakashi Iwai switch (snd_hda_jack_get_action(codec, res >> 26)) { 3705f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3706f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 370703697e2aSTakashi Iwai break; 370803697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 370903697e2aSTakashi Iwai cx_auto_line_automute(codec); 3710f2e5731dSTakashi Iwai break; 3711f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3712f2e5731dSTakashi Iwai cx_auto_automic(codec); 3713f2e5731dSTakashi Iwai break; 3714f2e5731dSTakashi Iwai } 371501a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3716f2e5731dSTakashi Iwai } 3717f2e5731dSTakashi Iwai 3718f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 371943c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 372043c1b2e9STakashi Iwai * one dock-mic exist 3721f2e5731dSTakashi Iwai */ 3722f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3723f2e5731dSTakashi Iwai { 3724f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 372543c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 372643c1b2e9STakashi Iwai int i; 3727f2e5731dSTakashi Iwai 3728506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 372943c1b2e9STakashi Iwai pset[i] = -1; 373043c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 373143c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 373243c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3733b55fcb50STakashi Iwai int type, attr; 373443c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 373543c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3736b55fcb50STakashi Iwai return; /* invalid entry */ 373743c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 373843c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 373943c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 374043c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3741b55fcb50STakashi Iwai return; /* non-detectable pin */ 3742b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3743b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3744b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3745b55fcb50STakashi Iwai return; /* no valid input type */ 374643c1b2e9STakashi Iwai if (pset[attr] >= 0) 374743c1b2e9STakashi Iwai return; /* already occupied */ 374843c1b2e9STakashi Iwai pset[attr] = i; 3749f2e5731dSTakashi Iwai } 375043c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 375143c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 375243c1b2e9STakashi Iwai return; /* no input to switch*/ 3753f2e5731dSTakashi Iwai spec->auto_mic = 1; 375443c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 375543c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 375643c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3757f2e5731dSTakashi Iwai } 3758f2e5731dSTakashi Iwai 3759f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3760f2e5731dSTakashi Iwai { 3761f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3762f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3763f2e5731dSTakashi Iwai struct hda_input_mux *imux; 37646764bcefSTakashi Iwai int i, j; 3765f2e5731dSTakashi Iwai 3766f2e5731dSTakashi Iwai imux = &spec->private_imux; 3767f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 37686764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 37696764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 37705c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3771f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3772f2e5731dSTakashi Iwai if (idx >= 0) { 3773f2e5731dSTakashi Iwai const char *label; 3774f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 377547ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 377647ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 377747ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 377847ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3779f6100bb4STakashi Iwai cfg->inputs[i].pin; 3780f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 37816764bcefSTakashi Iwai break; 37826764bcefSTakashi Iwai } 3783f2e5731dSTakashi Iwai } 3784f2e5731dSTakashi Iwai } 378543c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3786f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 378776755359STakashi Iwai if (imux->num_items > 1) { 37886764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 378947ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 37906764bcefSTakashi Iwai spec->adc_switching = 1; 37916764bcefSTakashi Iwai break; 37926764bcefSTakashi Iwai } 37936764bcefSTakashi Iwai } 37946764bcefSTakashi Iwai } 3795f2e5731dSTakashi Iwai } 3796f2e5731dSTakashi Iwai 3797f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3798f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3799f2e5731dSTakashi Iwai { 3800f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3801f2e5731dSTakashi Iwai 3802f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3803f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3804f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3805f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3806f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3807f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3808f2e5731dSTakashi Iwai return nid; 3809f2e5731dSTakashi Iwai } 3810f2e5731dSTakashi Iwai } 3811f2e5731dSTakashi Iwai return 0; 3812f2e5731dSTakashi Iwai } 3813f2e5731dSTakashi Iwai 3814f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3815f2e5731dSTakashi Iwai { 3816f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3817f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3818f2e5731dSTakashi Iwai hda_nid_t nid; 3819f2e5731dSTakashi Iwai 3820f2e5731dSTakashi Iwai if (cfg->dig_outs && 3821f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3822f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3823f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3824f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3825f2e5731dSTakashi Iwai } 3826f2e5731dSTakashi Iwai 3827f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3828f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3829f2e5731dSTakashi Iwai { 3830f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3831f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3832f2e5731dSTakashi Iwai 3833f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3834f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3835f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3836f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3837f2e5731dSTakashi Iwai break; 3838f2e5731dSTakashi Iwai } 3839f2e5731dSTakashi Iwai } 3840f2e5731dSTakashi Iwai #else 3841f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3842f2e5731dSTakashi Iwai #endif 3843f2e5731dSTakashi Iwai 3844254f2968STakashi Iwai /* parse EAPDs */ 384519110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 384619110595STakashi Iwai { 384719110595STakashi Iwai struct conexant_spec *spec = codec->spec; 384819110595STakashi Iwai hda_nid_t nid, end_nid; 384919110595STakashi Iwai 385019110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 385119110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 385219110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 385319110595STakashi Iwai continue; 385419110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 385519110595STakashi Iwai continue; 385619110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 385719110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 385819110595STakashi Iwai break; 385919110595STakashi Iwai } 3860254f2968STakashi Iwai 3861254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3862254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3863254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3864254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3865254f2968STakashi Iwai * thus it might control over all pins. 3866254f2968STakashi Iwai */ 3867254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 386819110595STakashi Iwai } 386919110595STakashi Iwai 3870f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3871f2e5731dSTakashi Iwai { 3872f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3873f2e5731dSTakashi Iwai int err; 3874f2e5731dSTakashi Iwai 3875f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3876f2e5731dSTakashi Iwai if (err < 0) 3877f2e5731dSTakashi Iwai return err; 3878f2e5731dSTakashi Iwai 3879f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3880f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3881f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3882f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 388319110595STakashi Iwai cx_auto_parse_eapd(codec); 3884f2e5731dSTakashi Iwai return 0; 3885f2e5731dSTakashi Iwai } 3886f2e5731dSTakashi Iwai 3887da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3888da339866STakashi Iwai hda_nid_t *pins, bool on) 3889f2e5731dSTakashi Iwai { 3890f2e5731dSTakashi Iwai int i; 3891f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3892f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3893f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3894da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3895da339866STakashi Iwai on ? 0x02 : 0); 3896f2e5731dSTakashi Iwai } 3897f2e5731dSTakashi Iwai } 3898f2e5731dSTakashi Iwai 3899f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3900f2e5731dSTakashi Iwai hda_nid_t src) 3901f2e5731dSTakashi Iwai { 3902f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3903f2e5731dSTakashi Iwai if (idx >= 0) 3904f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3905f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3906f2e5731dSTakashi Iwai } 3907f2e5731dSTakashi Iwai 39081f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 39091f8458a2STakashi Iwai const hda_nid_t *nids) 3910f2e5731dSTakashi Iwai { 39110ad1b5b6STakashi Iwai int i, val; 3912f2e5731dSTakashi Iwai 39131f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 39141f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 39151f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 39161f8458a2STakashi Iwai continue; 39170ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 39180ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 39190ad1b5b6STakashi Iwai else 39200ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 39210ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 39220ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 39230ad1b5b6STakashi Iwai } 39241f8458a2STakashi Iwai } 3925f2e5731dSTakashi Iwai 392603697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 39273a93897eSTakashi Iwai hda_nid_t *pins, unsigned int action) 392803697e2aSTakashi Iwai { 392903697e2aSTakashi Iwai int i; 393003697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 39313a93897eSTakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], action); 393203697e2aSTakashi Iwai } 393303697e2aSTakashi Iwai 39341f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39351f8458a2STakashi Iwai { 39361f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39371f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39381f8458a2STakashi Iwai hda_nid_t nid; 39391f8458a2STakashi Iwai int i; 39401f8458a2STakashi Iwai 39411f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3942f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3943f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3944f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 39451f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 39461f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 39471f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3948f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3949f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3950f2e5731dSTakashi Iwai if (!nid) 3951f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 39521f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 39531f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 3954f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3955f2e5731dSTakashi Iwai } 395603697e2aSTakashi Iwai if (spec->auto_mute) { 395703697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 395803697e2aSTakashi Iwai CONEXANT_HP_EVENT); 395903697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 396003697e2aSTakashi Iwai cfg->hp_pins); 396103697e2aSTakashi Iwai if (spec->detect_line) { 396203697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 396303697e2aSTakashi Iwai cfg->line_out_pins, 396403697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 396503697e2aSTakashi Iwai spec->line_present = 396603697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 396703697e2aSTakashi Iwai cfg->line_out_pins); 396803697e2aSTakashi Iwai } 396903697e2aSTakashi Iwai } 397003697e2aSTakashi Iwai cx_auto_update_speakers(codec); 3971254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 3972254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 397319110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 3974f2e5731dSTakashi Iwai } 3975f2e5731dSTakashi Iwai 3976f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3977f2e5731dSTakashi Iwai { 3978f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3979f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39800ad1b5b6STakashi Iwai int i, val; 3981f2e5731dSTakashi Iwai 39820ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 39830ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 39841f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 39851f8458a2STakashi Iwai continue; 39860ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 39870ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 39880ad1b5b6STakashi Iwai else 39890ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 39900ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 39910ad1b5b6STakashi Iwai val); 39920ad1b5b6STakashi Iwai } 3993f2e5731dSTakashi Iwai 3994f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 3995f2e5731dSTakashi Iwai unsigned int type; 3996f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 3997f2e5731dSTakashi Iwai type = PIN_VREF80; 3998f2e5731dSTakashi Iwai else 3999f2e5731dSTakashi Iwai type = PIN_IN; 4000f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4001f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4002f2e5731dSTakashi Iwai } 4003f2e5731dSTakashi Iwai 4004f2e5731dSTakashi Iwai if (spec->auto_mic) { 400543c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40061835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40071835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40081835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 400943c1b2e9STakashi Iwai } 401043c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40111835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40121835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40131835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 401443c1b2e9STakashi Iwai } 4015f2e5731dSTakashi Iwai cx_auto_automic(codec); 4016f2e5731dSTakashi Iwai } else { 401747ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 401847ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4019f2e5731dSTakashi Iwai } 4020f2e5731dSTakashi Iwai } 4021f2e5731dSTakashi Iwai 4022f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4023f2e5731dSTakashi Iwai { 4024f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4025f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4026f2e5731dSTakashi Iwai 4027f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4028f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4029f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4030f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4031f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4032f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4033f2e5731dSTakashi Iwai } 4034f2e5731dSTakashi Iwai 4035f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4036f2e5731dSTakashi Iwai { 4037f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4038f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4039f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4040f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 404101a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4042f2e5731dSTakashi Iwai return 0; 4043f2e5731dSTakashi Iwai } 4044f2e5731dSTakashi Iwai 4045983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4046f2e5731dSTakashi Iwai const char *dir, int cidx, 4047983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 4048f2e5731dSTakashi Iwai { 4049f2e5731dSTakashi Iwai static char name[32]; 4050f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4051f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4052f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4053f2e5731dSTakashi Iwai }; 405434cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4055f2e5731dSTakashi Iwai int i, err; 4056f2e5731dSTakashi Iwai 4057f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4058f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4059983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4060983345e5SDavid Henningsson hda_dir); 4061f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4062f2e5731dSTakashi Iwai knew[i].index = cidx; 4063f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4064f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4065f2e5731dSTakashi Iwai if (!kctl) 4066f2e5731dSTakashi Iwai return -ENOMEM; 4067f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4068f2e5731dSTakashi Iwai if (err < 0) 4069f2e5731dSTakashi Iwai return err; 4070f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 4071f2e5731dSTakashi Iwai break; 4072f2e5731dSTakashi Iwai } 4073f2e5731dSTakashi Iwai return 0; 4074f2e5731dSTakashi Iwai } 4075f2e5731dSTakashi Iwai 4076983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4077983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4078983345e5SDavid Henningsson 4079f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4080f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4081f2e5731dSTakashi Iwai 40821f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 40831f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 40841f8458a2STakashi Iwai { 40851f8458a2STakashi Iwai unsigned int caps; 4086468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 40871f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 40881f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 40891f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4090468c5458SDavid Henningsson } 40911f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 40921f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 40931f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 40941f8458a2STakashi Iwai return 0; 40951f8458a2STakashi Iwai } 40961f8458a2STakashi Iwai 4097f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4098f2e5731dSTakashi Iwai { 4099f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4100f2e5731dSTakashi Iwai int i, err; 4101f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4102ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4103f2e5731dSTakashi Iwai 4104f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41051f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41061f8458a2STakashi Iwai spec->dac_info[0].pin, 4107f2e5731dSTakashi Iwai "Master", 0); 41081f8458a2STakashi Iwai 4109f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4110f2e5731dSTakashi Iwai const char *label; 4111f2e5731dSTakashi Iwai int idx, type; 41121f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4113f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4114f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4115f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4116f2e5731dSTakashi Iwai switch (type) { 4117f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4118f2e5731dSTakashi Iwai default: 4119f2e5731dSTakashi Iwai label = texts[num_line++]; 4120f2e5731dSTakashi Iwai idx = 0; 4121f2e5731dSTakashi Iwai break; 4122f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4123f2e5731dSTakashi Iwai label = "Headphone"; 4124f2e5731dSTakashi Iwai idx = num_hp++; 4125f2e5731dSTakashi Iwai break; 4126f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4127f2e5731dSTakashi Iwai label = "Speaker"; 4128f2e5731dSTakashi Iwai idx = num_spk++; 4129f2e5731dSTakashi Iwai break; 4130f2e5731dSTakashi Iwai } 41311f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41321f8458a2STakashi Iwai spec->dac_info[i].pin, 4133f2e5731dSTakashi Iwai label, idx); 4134f2e5731dSTakashi Iwai if (err < 0) 4135f2e5731dSTakashi Iwai return err; 4136f2e5731dSTakashi Iwai } 413703697e2aSTakashi Iwai 413803697e2aSTakashi Iwai if (spec->auto_mute) { 413903697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 414003697e2aSTakashi Iwai if (err < 0) 414103697e2aSTakashi Iwai return err; 414203697e2aSTakashi Iwai } 414303697e2aSTakashi Iwai 4144f2e5731dSTakashi Iwai return 0; 4145f2e5731dSTakashi Iwai } 4146f2e5731dSTakashi Iwai 41476764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 41486764bcefSTakashi Iwai const char *label, const char *pfx, 41496764bcefSTakashi Iwai int cidx) 41506764bcefSTakashi Iwai { 41516764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 41526764bcefSTakashi Iwai int i; 41536764bcefSTakashi Iwai 41546764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 41556764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 41565c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 41576764bcefSTakashi Iwai if (idx < 0) 41586764bcefSTakashi Iwai continue; 41596b452142STakashi Iwai if (spec->single_adc_amp) 41606b452142STakashi Iwai idx = 0; 41616764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 41626764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 41636764bcefSTakashi Iwai } 41646764bcefSTakashi Iwai return 0; 41656764bcefSTakashi Iwai } 41666764bcefSTakashi Iwai 4167cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4168cf27f29aSTakashi Iwai const char *label, int cidx) 4169cf27f29aSTakashi Iwai { 4170cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4171cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4172f9759301STakashi Iwai int i, con; 4173cf27f29aSTakashi Iwai 417447ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4175cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4176cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4177cf27f29aSTakashi Iwai nid, HDA_INPUT); 417847ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 417947ad1f4eSTakashi Iwai &mux, false, 0); 4180cf27f29aSTakashi Iwai if (con < 0) 4181cf27f29aSTakashi Iwai return 0; 4182f9759301STakashi Iwai for (i = 0; i < idx; i++) { 418347ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4184f9759301STakashi Iwai return 0; /* already present */ 4185f9759301STakashi Iwai } 4186f9759301STakashi Iwai 4187f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 418847ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4189cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4190cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4191f9759301STakashi Iwai } 4192cf27f29aSTakashi Iwai return 0; 4193cf27f29aSTakashi Iwai } 4194cf27f29aSTakashi Iwai 4195f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4196f2e5731dSTakashi Iwai { 4197f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4198cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4199cf27f29aSTakashi Iwai const char *prev_label; 4200cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42016b452142STakashi Iwai int i, j, err, cidx; 4202cf27f29aSTakashi Iwai int multi_connection; 4203cf27f29aSTakashi Iwai 42046b452142STakashi Iwai if (!imux->num_items) 42056b452142STakashi Iwai return 0; 42066b452142STakashi Iwai 4207cf27f29aSTakashi Iwai multi_connection = 0; 4208cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 420947ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 421047ad1f4eSTakashi Iwai spec->imux_info[i].pin); 42116b452142STakashi Iwai if (cidx < 0) 42126b452142STakashi Iwai continue; 42136b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 42146b452142STakashi Iwai if (!spec->single_adc_amp) 42156b452142STakashi Iwai input_conn[i] |= cidx << 8; 4216cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4217cf27f29aSTakashi Iwai multi_connection = 1; 4218cf27f29aSTakashi Iwai } 4219983345e5SDavid Henningsson 4220f2e5731dSTakashi Iwai prev_label = NULL; 4221f2e5731dSTakashi Iwai cidx = 0; 4222cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 422347ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4224f2e5731dSTakashi Iwai const char *label; 4225983345e5SDavid Henningsson 4226cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 422747ad1f4eSTakashi Iwai spec->imux_info[i].index); 4228f2e5731dSTakashi Iwai if (label == prev_label) 4229f2e5731dSTakashi Iwai cidx++; 4230f2e5731dSTakashi Iwai else 4231f2e5731dSTakashi Iwai cidx = 0; 4232f2e5731dSTakashi Iwai prev_label = label; 4233983345e5SDavid Henningsson 4234cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4235f2e5731dSTakashi Iwai if (err < 0) 4236f2e5731dSTakashi Iwai return err; 4237983345e5SDavid Henningsson 4238cf27f29aSTakashi Iwai if (!multi_connection) { 4239f9759301STakashi Iwai if (i > 0) 4240f9759301STakashi Iwai continue; 42416764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42426764bcefSTakashi Iwai "Capture", "", cidx); 42436764bcefSTakashi Iwai } else { 42446b452142STakashi Iwai bool dup_found = false; 42456b452142STakashi Iwai for (j = 0; j < i; j++) { 42466b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 42476b452142STakashi Iwai dup_found = true; 42486b452142STakashi Iwai break; 42496b452142STakashi Iwai } 42506b452142STakashi Iwai } 42516b452142STakashi Iwai if (dup_found) 42526b452142STakashi Iwai continue; 42536764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42546764bcefSTakashi Iwai label, " Capture", cidx); 42556764bcefSTakashi Iwai } 4256983345e5SDavid Henningsson if (err < 0) 4257983345e5SDavid Henningsson return err; 4258983345e5SDavid Henningsson } 42596764bcefSTakashi Iwai 42606764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 42616764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 42626764bcefSTakashi Iwai if (err < 0) 42636764bcefSTakashi Iwai return err; 4264983345e5SDavid Henningsson } 42656764bcefSTakashi Iwai 4266f2e5731dSTakashi Iwai return 0; 4267f2e5731dSTakashi Iwai } 4268f2e5731dSTakashi Iwai 4269f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4270f2e5731dSTakashi Iwai { 427131ef2257STakashi Iwai struct conexant_spec *spec = codec->spec; 4272f2e5731dSTakashi Iwai int err; 4273f2e5731dSTakashi Iwai 4274f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4275f2e5731dSTakashi Iwai if (err < 0) 4276f2e5731dSTakashi Iwai return err; 4277f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4278f2e5731dSTakashi Iwai if (err < 0) 4279f2e5731dSTakashi Iwai return err; 428031ef2257STakashi Iwai err = conexant_build_controls(codec); 428131ef2257STakashi Iwai if (err < 0) 428231ef2257STakashi Iwai return err; 428331ef2257STakashi Iwai err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 428431ef2257STakashi Iwai if (err < 0) 428531ef2257STakashi Iwai return err; 428631ef2257STakashi Iwai return 0; 4287f2e5731dSTakashi Iwai } 4288f2e5731dSTakashi Iwai 428922ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 429022ce5f74STakashi Iwai { 429122ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 429222ce5f74STakashi Iwai hda_nid_t nid, end_nid; 429322ce5f74STakashi Iwai 429422ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 429522ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 429622ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 429722ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 429822ce5f74STakashi Iwai continue; 429922ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 430022ce5f74STakashi Iwai continue; 430122ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 430222ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 430322ce5f74STakashi Iwai break; 430422ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 430522ce5f74STakashi Iwai } 430622ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 430722ce5f74STakashi Iwai return 0; 430822ce5f74STakashi Iwai } 430922ce5f74STakashi Iwai 431022ce5f74STakashi Iwai 431134cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4312f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4313f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4314f2e5731dSTakashi Iwai .init = cx_auto_init, 4315f2e5731dSTakashi Iwai .free = conexant_free, 4316f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4317f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4318f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4319f2e5731dSTakashi Iwai #endif 4320f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4321f2e5731dSTakashi Iwai }; 4322f2e5731dSTakashi Iwai 4323e92d4b08STakashi Iwai /* 4324e92d4b08STakashi Iwai * pin fix-up 4325e92d4b08STakashi Iwai */ 4326e92d4b08STakashi Iwai struct cxt_pincfg { 4327e92d4b08STakashi Iwai hda_nid_t nid; 4328e92d4b08STakashi Iwai u32 val; 4329e92d4b08STakashi Iwai }; 4330e92d4b08STakashi Iwai 4331e92d4b08STakashi Iwai static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4332e92d4b08STakashi Iwai { 4333e92d4b08STakashi Iwai for (; cfg->nid; cfg++) 4334e92d4b08STakashi Iwai snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4335e92d4b08STakashi Iwai 4336e92d4b08STakashi Iwai } 4337e92d4b08STakashi Iwai 4338e92d4b08STakashi Iwai static void apply_pin_fixup(struct hda_codec *codec, 4339e92d4b08STakashi Iwai const struct snd_pci_quirk *quirk, 4340e92d4b08STakashi Iwai const struct cxt_pincfg **table) 4341e92d4b08STakashi Iwai { 4342e92d4b08STakashi Iwai quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 4343e92d4b08STakashi Iwai if (quirk) { 4344e92d4b08STakashi Iwai snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4345e92d4b08STakashi Iwai quirk->name); 4346e92d4b08STakashi Iwai apply_pincfg(codec, table[quirk->value]); 4347e92d4b08STakashi Iwai } 4348e92d4b08STakashi Iwai } 4349e92d4b08STakashi Iwai 4350e92d4b08STakashi Iwai enum { 4351e92d4b08STakashi Iwai CXT_PINCFG_LENOVO_X200, 4352e92d4b08STakashi Iwai }; 4353e92d4b08STakashi Iwai 4354e92d4b08STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4355e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4356e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 4357e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 4358e92d4b08STakashi Iwai {} 4359e92d4b08STakashi Iwai }; 4360e92d4b08STakashi Iwai 4361e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4362e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4363e92d4b08STakashi Iwai }; 4364e92d4b08STakashi Iwai 4365e92d4b08STakashi Iwai static const struct snd_pci_quirk cxt_fixups[] = { 4366e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4367e92d4b08STakashi Iwai {} 4368e92d4b08STakashi Iwai }; 4369e92d4b08STakashi Iwai 4370f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4371f2e5731dSTakashi Iwai { 4372f2e5731dSTakashi Iwai struct conexant_spec *spec; 4373f2e5731dSTakashi Iwai int err; 4374f2e5731dSTakashi Iwai 43751f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 43761f8458a2STakashi Iwai codec->chip_name); 43771f8458a2STakashi Iwai 4378f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4379f2e5731dSTakashi Iwai if (!spec) 4380f2e5731dSTakashi Iwai return -ENOMEM; 4381f2e5731dSTakashi Iwai codec->spec = spec; 43821387cde5STakashi Iwai codec->pin_amp_workaround = 1; 4383e92d4b08STakashi Iwai 43846b452142STakashi Iwai switch (codec->vendor_id) { 43856b452142STakashi Iwai case 0x14f15045: 43866b452142STakashi Iwai spec->single_adc_amp = 1; 43876b452142STakashi Iwai break; 43886b452142STakashi Iwai } 43896b452142STakashi Iwai 4390e92d4b08STakashi Iwai apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl); 4391e92d4b08STakashi Iwai 439222ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 439322ce5f74STakashi Iwai if (err < 0) 439422ce5f74STakashi Iwai return err; 4395f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4396f2e5731dSTakashi Iwai if (err < 0) { 4397f2e5731dSTakashi Iwai kfree(codec->spec); 4398f2e5731dSTakashi Iwai codec->spec = NULL; 4399f2e5731dSTakashi Iwai return err; 4400f2e5731dSTakashi Iwai } 44016764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4402f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4403f2e5731dSTakashi Iwai if (spec->beep_amp) 4404f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 44054f2864a4STakashi Iwai 44064f2864a4STakashi Iwai /* Some laptops with Conexant chips show stalls in S3 resume, 44074f2864a4STakashi Iwai * which falls into the single-cmd mode. 44084f2864a4STakashi Iwai * Better to make reset, then. 44094f2864a4STakashi Iwai */ 44104f2864a4STakashi Iwai if (!codec->bus->sync_write) { 44114f2864a4STakashi Iwai snd_printd("hda_codec: " 44124f2864a4STakashi Iwai "Enable sync_write for stable communication\n"); 44134f2864a4STakashi Iwai codec->bus->sync_write = 1; 44144f2864a4STakashi Iwai codec->bus->allow_bus_reset = 1; 44154f2864a4STakashi Iwai } 44164f2864a4STakashi Iwai 4417f2e5731dSTakashi Iwai return 0; 4418f2e5731dSTakashi Iwai } 4419f2e5731dSTakashi Iwai 4420f2e5731dSTakashi Iwai /* 4421461e2c78STakashi Iwai */ 4422461e2c78STakashi Iwai 442334cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = { 442482f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 442582f30040STobin Davis .patch = patch_cxt5045 }, 442682f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 442782f30040STobin Davis .patch = patch_cxt5047 }, 4428461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 4429461e2c78STakashi Iwai .patch = patch_cxt5051 }, 44300fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 44310fb67e98SDaniel Drake .patch = patch_cxt5066 }, 443295a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 443395a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 4434850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 4435850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 44367b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 44377b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 4438f0ca89b0SDavid Henningsson { .id = 0x14f1506c, .name = "CX20588", 4439f0ca89b0SDavid Henningsson .patch = patch_cxt5066 }, 44406da8b516SDavid Henningsson { .id = 0x14f1506e, .name = "CX20590", 44416da8b516SDavid Henningsson .patch = patch_cxt5066 }, 4442f2e5731dSTakashi Iwai { .id = 0x14f15097, .name = "CX20631", 4443f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4444f2e5731dSTakashi Iwai { .id = 0x14f15098, .name = "CX20632", 4445f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4446f2e5731dSTakashi Iwai { .id = 0x14f150a1, .name = "CX20641", 4447f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4448f2e5731dSTakashi Iwai { .id = 0x14f150a2, .name = "CX20642", 4449f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4450f2e5731dSTakashi Iwai { .id = 0x14f150ab, .name = "CX20651", 4451f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4452f2e5731dSTakashi Iwai { .id = 0x14f150ac, .name = "CX20652", 4453f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4454f2e5731dSTakashi Iwai { .id = 0x14f150b8, .name = "CX20664", 4455f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4456f2e5731dSTakashi Iwai { .id = 0x14f150b9, .name = "CX20665", 4457f2e5731dSTakashi Iwai .patch = patch_conexant_auto }, 4458c9b443d4STobin Davis {} /* terminator */ 4459c9b443d4STobin Davis }; 44601289e9e8STakashi Iwai 44611289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 44621289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 44631289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 44640fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 446595a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 4466850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 44677b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 4468f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c"); 44696da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e"); 4470f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097"); 4471f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098"); 4472f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1"); 4473f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2"); 4474f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab"); 4475f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac"); 4476f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8"); 4477f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9"); 44781289e9e8STakashi Iwai 44791289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 44801289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 44811289e9e8STakashi Iwai 44821289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 44831289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 44841289e9e8STakashi Iwai .owner = THIS_MODULE, 44851289e9e8STakashi Iwai }; 44861289e9e8STakashi Iwai 44871289e9e8STakashi Iwai static int __init patch_conexant_init(void) 44881289e9e8STakashi Iwai { 44891289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 44901289e9e8STakashi Iwai } 44911289e9e8STakashi Iwai 44921289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 44931289e9e8STakashi Iwai { 44941289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 44951289e9e8STakashi Iwai } 44961289e9e8STakashi Iwai 44971289e9e8STakashi Iwai module_init(patch_conexant_init) 44981289e9e8STakashi Iwai module_exit(patch_conexant_exit) 4499