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 468ea734963STakashi Iwai static const char * const slave_vols[] = { 469dd5746a8STakashi Iwai "Headphone Playback Volume", 470dd5746a8STakashi Iwai "Speaker Playback Volume", 471a3a85d39STakashi Iwai "Front Playback Volume", 472a3a85d39STakashi Iwai "Surround Playback Volume", 473a3a85d39STakashi Iwai "CLFE Playback Volume", 474dd5746a8STakashi Iwai NULL 475dd5746a8STakashi Iwai }; 476dd5746a8STakashi Iwai 477ea734963STakashi Iwai static const char * const slave_sws[] = { 478dd5746a8STakashi Iwai "Headphone Playback Switch", 479dd5746a8STakashi Iwai "Speaker Playback Switch", 480a3a85d39STakashi Iwai "Front Playback Switch", 481a3a85d39STakashi Iwai "Surround Playback Switch", 482a3a85d39STakashi Iwai "CLFE Playback Switch", 483dd5746a8STakashi Iwai NULL 484dd5746a8STakashi Iwai }; 485dd5746a8STakashi Iwai 486c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 487c9b443d4STobin Davis { 488c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 489c9b443d4STobin Davis unsigned int i; 490c9b443d4STobin Davis int err; 491c9b443d4STobin Davis 492c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 493c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 494c9b443d4STobin Davis if (err < 0) 495c9b443d4STobin Davis return err; 496c9b443d4STobin Davis } 497c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 498c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 49974b654c9SStephen Warren spec->multiout.dig_out_nid, 500c9b443d4STobin Davis spec->multiout.dig_out_nid); 501c9b443d4STobin Davis if (err < 0) 502c9b443d4STobin Davis return err; 5039a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5049a08160bSTakashi Iwai &spec->multiout); 5059a08160bSTakashi Iwai if (err < 0) 5069a08160bSTakashi Iwai return err; 5079a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 508c9b443d4STobin Davis } 509c9b443d4STobin Davis if (spec->dig_in_nid) { 510c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 511c9b443d4STobin Davis if (err < 0) 512c9b443d4STobin Davis return err; 513c9b443d4STobin Davis } 514dd5746a8STakashi Iwai 515dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 516dd5746a8STakashi Iwai if (spec->vmaster_nid && 517dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 518dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 519dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 520dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 521dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 522dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 523dd5746a8STakashi Iwai if (err < 0) 524dd5746a8STakashi Iwai return err; 525dd5746a8STakashi Iwai } 526dd5746a8STakashi Iwai if (spec->vmaster_nid && 527dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 528dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 529dd5746a8STakashi Iwai NULL, slave_sws); 530dd5746a8STakashi Iwai if (err < 0) 531dd5746a8STakashi Iwai return err; 532dd5746a8STakashi Iwai } 533dd5746a8STakashi Iwai 534b880c74aSTakashi Iwai if (spec->input_mux) { 535b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 536b880c74aSTakashi Iwai if (err < 0) 537b880c74aSTakashi Iwai return err; 538b880c74aSTakashi Iwai } 539b880c74aSTakashi Iwai 5403507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5413507e2a8STakashi Iwai /* create beep controls if needed */ 5423507e2a8STakashi Iwai if (spec->beep_amp) { 54334cbe3a6STakashi Iwai const struct snd_kcontrol_new *knew; 5443507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 5453507e2a8STakashi Iwai struct snd_kcontrol *kctl; 5463507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 5473507e2a8STakashi Iwai if (!kctl) 5483507e2a8STakashi Iwai return -ENOMEM; 5493507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 5503507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 5513507e2a8STakashi Iwai if (err < 0) 5523507e2a8STakashi Iwai return err; 5533507e2a8STakashi Iwai } 5543507e2a8STakashi Iwai } 5553507e2a8STakashi Iwai #endif 5563507e2a8STakashi Iwai 557c9b443d4STobin Davis return 0; 558c9b443d4STobin Davis } 559c9b443d4STobin Davis 560697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 561697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 562697c373eSTakashi Iwai { 563697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 564697c373eSTakashi Iwai return 0; 565697c373eSTakashi Iwai } 566697c373eSTakashi Iwai #endif 567697c373eSTakashi Iwai 56834cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = { 569c9b443d4STobin Davis .build_controls = conexant_build_controls, 570c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 571c9b443d4STobin Davis .init = conexant_init, 572c9b443d4STobin Davis .free = conexant_free, 5734d7fbdbcSTakashi Iwai .set_power_state = conexant_set_power, 574697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 575697c373eSTakashi Iwai .suspend = conexant_suspend, 576697c373eSTakashi Iwai #endif 577697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 578c9b443d4STobin Davis }; 579c9b443d4STobin Davis 5803507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5813507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 5823507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 5833507e2a8STakashi Iwai #else 5843507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 5853507e2a8STakashi Iwai #endif 5863507e2a8STakashi Iwai 5876764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec); 588c9b443d4STobin Davis /* 589c9b443d4STobin Davis * EAPD control 590c9b443d4STobin Davis * the private value = nid | (invert << 8) 591c9b443d4STobin Davis */ 592c9b443d4STobin Davis 593a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 594c9b443d4STobin Davis 59582f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 596c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 597c9b443d4STobin Davis { 598c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 599c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 600c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 601c9b443d4STobin Davis if (invert) 602c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 603c9b443d4STobin Davis else 604c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 605c9b443d4STobin Davis return 0; 60682f30040STobin Davis 607c9b443d4STobin Davis } 608c9b443d4STobin Davis 60982f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 610c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 611c9b443d4STobin Davis { 612c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 613c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 614c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 615c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 616c9b443d4STobin Davis unsigned int eapd; 61782f30040STobin Davis 61868ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 619c9b443d4STobin Davis if (invert) 620c9b443d4STobin Davis eapd = !eapd; 62182beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 622c9b443d4STobin Davis return 0; 62382f30040STobin Davis 624c9b443d4STobin Davis spec->cur_eapd = eapd; 62582beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 626c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 627c9b443d4STobin Davis eapd ? 0x02 : 0x00); 628c9b443d4STobin Davis return 1; 629c9b443d4STobin Davis } 630c9b443d4STobin Davis 63186d72bdfSTakashi Iwai /* controls for test mode */ 63286d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 63386d72bdfSTakashi Iwai 63482f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 63582f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 63682f30040STobin Davis .info = cxt_eapd_info, \ 63782f30040STobin Davis .get = cxt_eapd_get, \ 63882f30040STobin Davis .put = cxt_eapd_put, \ 63982f30040STobin Davis .private_value = nid | (mask<<16) } 64082f30040STobin Davis 64182f30040STobin Davis 64282f30040STobin Davis 643c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 644c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 645c9b443d4STobin Davis { 646c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 647c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 648c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 649c9b443d4STobin Davis spec->num_channel_mode); 650c9b443d4STobin Davis } 651c9b443d4STobin Davis 652c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 653c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 654c9b443d4STobin Davis { 655c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 656c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 657c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 658c9b443d4STobin Davis spec->num_channel_mode, 659c9b443d4STobin Davis spec->multiout.max_channels); 660c9b443d4STobin Davis } 661c9b443d4STobin Davis 662c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 663c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 664c9b443d4STobin Davis { 665c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 666c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 667c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 668c9b443d4STobin Davis spec->num_channel_mode, 669c9b443d4STobin Davis &spec->multiout.max_channels); 670c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 671c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 672c9b443d4STobin Davis return err; 673c9b443d4STobin Davis } 674c9b443d4STobin Davis 675c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 676c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 677c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 678c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 679c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 680c9b443d4STobin Davis .private_value = nid | (dir<<16) } 681c9b443d4STobin Davis 68286d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 68386d72bdfSTakashi Iwai 684c9b443d4STobin Davis /* Conexant 5045 specific */ 685c9b443d4STobin Davis 68634cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 68734cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 68834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 689cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 690c9b443d4STobin Davis 69134cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = { 6925cd57529STobin Davis { 2, NULL }, 6935cd57529STobin Davis }; 694c9b443d4STobin Davis 69534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = { 696c9b443d4STobin Davis .num_items = 2, 697c9b443d4STobin Davis .items = { 69882f30040STobin Davis { "IntMic", 0x1 }, 699f4beee94SJiang zhe { "ExtMic", 0x2 }, 700c9b443d4STobin Davis } 701c9b443d4STobin Davis }; 702c9b443d4STobin Davis 70334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = { 70422e14130SLukasz Marcinowski .num_items = 5, 7055218c892SJiang Zhe .items = { 7065218c892SJiang Zhe { "IntMic", 0x1 }, 7075218c892SJiang Zhe { "ExtMic", 0x2 }, 7085218c892SJiang Zhe { "LineIn", 0x3 }, 70922e14130SLukasz Marcinowski { "CD", 0x4 }, 71022e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7115218c892SJiang Zhe } 7125218c892SJiang Zhe }; 7135218c892SJiang Zhe 71434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = { 7152de3c232SJiang zhe .num_items = 2, 7162de3c232SJiang zhe .items = { 7172de3c232SJiang zhe { "ExtMic", 0x1 }, 7182de3c232SJiang zhe { "IntMic", 0x2 }, 7192de3c232SJiang zhe } 7202de3c232SJiang zhe }; 7212de3c232SJiang zhe 722c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 723c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 724c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 725c9b443d4STobin Davis { 726c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 727c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 72882f30040STobin Davis unsigned int bits; 729c9b443d4STobin Davis 73082f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 731c9b443d4STobin Davis return 0; 732c9b443d4STobin Davis 73382f30040STobin Davis /* toggle internal speakers mute depending of presence of 73482f30040STobin Davis * the headphone jack 73582f30040STobin Davis */ 73647fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 73747fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 73847fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7397f29673bSTobin Davis 74047fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 74147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 74247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 743c9b443d4STobin Davis return 1; 744c9b443d4STobin Davis } 745c9b443d4STobin Davis 746c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 74734cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 748cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 749cca3b371STakashi Iwai .values = { 750cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 751cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 752cca3b371STakashi Iwai 0 753cca3b371STakashi Iwai }, 754cca3b371STakashi Iwai }; 755c9b443d4STobin Davis 7567f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7577f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7587f29673bSTobin Davis { 75934cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 7607f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7617f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7627f29673bSTobin Davis {} 7637f29673bSTobin Davis }; 76434cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 7657f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7667f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7677f29673bSTobin Davis {} 7687f29673bSTobin Davis }; 7697f29673bSTobin Davis unsigned int present; 7707f29673bSTobin Davis 771d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7727f29673bSTobin Davis if (present) 7737f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7747f29673bSTobin Davis else 7757f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7767f29673bSTobin Davis } 7777f29673bSTobin Davis 778c9b443d4STobin Davis 779c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 780c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 781c9b443d4STobin Davis { 78282f30040STobin Davis struct conexant_spec *spec = codec->spec; 783dd87da1cSTobin Davis unsigned int bits; 784c9b443d4STobin Davis 785d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 786dd87da1cSTobin Davis 78747fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 78847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 78947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 790c9b443d4STobin Davis } 791c9b443d4STobin Davis 792c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 793c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 794c9b443d4STobin Davis unsigned int res) 795c9b443d4STobin Davis { 796c9b443d4STobin Davis res >>= 26; 797c9b443d4STobin Davis switch (res) { 798c9b443d4STobin Davis case CONEXANT_HP_EVENT: 799c9b443d4STobin Davis cxt5045_hp_automute(codec); 800c9b443d4STobin Davis break; 8017f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8027f29673bSTobin Davis cxt5045_hp_automic(codec); 8037f29673bSTobin Davis break; 8047f29673bSTobin Davis 805c9b443d4STobin Davis } 806c9b443d4STobin Davis } 807c9b443d4STobin Davis 80834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = { 80928c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 81028c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8118607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8128607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 813c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 814c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 81528c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 81628c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8178607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8188607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 819cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 820c9b443d4STobin Davis { 821c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 822c9b443d4STobin Davis .name = "Master Playback Switch", 82382f30040STobin Davis .info = cxt_eapd_info, 82482f30040STobin Davis .get = cxt_eapd_get, 825c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 82682f30040STobin Davis .private_value = 0x10, 827c9b443d4STobin Davis }, 828c9b443d4STobin Davis 829c9b443d4STobin Davis {} 830c9b443d4STobin Davis }; 831c9b443d4STobin Davis 83234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = { 83322e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 83422e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 83522e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 83622e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 83722e14130SLukasz Marcinowski 8385218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8395218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8405218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8415218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8425218c892SJiang Zhe 84322e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 84422e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 84522e14130SLukasz Marcinowski 8465218c892SJiang Zhe {} 8475218c892SJiang Zhe }; 8485218c892SJiang Zhe 84934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 85028c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 85128c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8528607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8538607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8542de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8552de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 85628c4edb7SDavid Henningsson HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 85728c4edb7SDavid Henningsson HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8588607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8598607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8602de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8612de3c232SJiang zhe { 8622de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8632de3c232SJiang zhe .name = "Master Playback Switch", 8642de3c232SJiang zhe .info = cxt_eapd_info, 8652de3c232SJiang zhe .get = cxt_eapd_get, 8662de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8672de3c232SJiang zhe .private_value = 0x10, 8682de3c232SJiang zhe }, 8692de3c232SJiang zhe 8702de3c232SJiang zhe {} 8712de3c232SJiang zhe }; 8722de3c232SJiang zhe 87334cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = { 874c9b443d4STobin Davis /* Line in, Mic */ 8754090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8767f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 877c9b443d4STobin Davis /* HP, Amp */ 878c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 879c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 88082f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 881c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 882c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 883c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 884c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 885c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 886c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 88728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 8887f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 88982f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 890c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 891c9b443d4STobin Davis /* SPDIF route: PCM */ 892cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 893c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 894c9b443d4STobin Davis /* EAPD */ 89582f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 896c9b443d4STobin Davis { } /* end */ 897c9b443d4STobin Davis }; 898c9b443d4STobin Davis 89934cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = { 90028c4edb7SDavid Henningsson /* Internal Mic, Mic */ 9015218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9025218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9035218c892SJiang Zhe /* Line In,HP, Amp */ 9045218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9055218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9065218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9075218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9085218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9095218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9105218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9115218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9125218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 91328c4edb7SDavid Henningsson /* Record selector: Internal mic */ 9145218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9155218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9165218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9175218c892SJiang Zhe /* SPDIF route: PCM */ 918cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9195218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9205218c892SJiang Zhe /* EAPD */ 9215218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9225218c892SJiang Zhe { } /* end */ 9235218c892SJiang Zhe }; 9247f29673bSTobin Davis 92534cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9267f29673bSTobin Davis /* pin sensing on HP jack */ 9277f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 928d3091fadSTakashi Iwai { } /* end */ 9297f29673bSTobin Davis }; 9307f29673bSTobin Davis 93134cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9327f29673bSTobin Davis /* pin sensing on HP jack */ 9337f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 934d3091fadSTakashi Iwai { } /* end */ 9357f29673bSTobin Davis }; 9367f29673bSTobin Davis 937c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 938c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 939c9b443d4STobin Davis * configuration. 940c9b443d4STobin Davis */ 94134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = { 942c9b443d4STobin Davis .num_items = 5, 943c9b443d4STobin Davis .items = { 944c9b443d4STobin Davis { "MIXER", 0x0 }, 945c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 946c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 947c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 948c9b443d4STobin Davis { "CD pin", 0x4 }, 949c9b443d4STobin Davis }, 950c9b443d4STobin Davis }; 951c9b443d4STobin Davis 95234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = { 953c9b443d4STobin Davis 954c9b443d4STobin Davis /* Output controls */ 955c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 956c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9577f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9587f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9597f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9607f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 961c9b443d4STobin Davis 962c9b443d4STobin Davis /* Modes for retasking pin widgets */ 963c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 964c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 965c9b443d4STobin Davis 96682f30040STobin Davis /* EAPD Switch Control */ 96782f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 96882f30040STobin Davis 969c9b443d4STobin Davis /* Loopback mixer controls */ 970c9b443d4STobin Davis 9717f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9727f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9737f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9747f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9757f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9767f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9777f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9787f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9797f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9807f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 981c9b443d4STobin Davis { 982c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 983c9b443d4STobin Davis .name = "Input Source", 984c9b443d4STobin Davis .info = conexant_mux_enum_info, 985c9b443d4STobin Davis .get = conexant_mux_enum_get, 986c9b443d4STobin Davis .put = conexant_mux_enum_put, 987c9b443d4STobin Davis }, 988fb3409e7STobin Davis /* Audio input controls */ 989fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 990fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 991fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 992fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 993fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 994fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 995fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 996fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 997fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 998fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 999c9b443d4STobin Davis { } /* end */ 1000c9b443d4STobin Davis }; 1001c9b443d4STobin Davis 100234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = { 10037f29673bSTobin Davis /* Set connections */ 10047f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10057f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10067f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1007c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1008c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10097f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1010c9b443d4STobin Davis 1011c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1012c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1013c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1014c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1015c9b443d4STobin Davis * control. 1016c9b443d4STobin Davis */ 1017cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1018cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1019c9b443d4STobin Davis 1020c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1021c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1022c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1023c9b443d4STobin Davis 1024c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1025c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1026c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1027c9b443d4STobin Davis * input/output buffers as needed. 1028c9b443d4STobin Davis */ 1029c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1030c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1031c9b443d4STobin Davis 1032c9b443d4STobin Davis /* Mute capture amp left and right */ 1033c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1034c9b443d4STobin Davis 1035c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1036c9b443d4STobin Davis * pin) 1037c9b443d4STobin Davis */ 1038c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10397f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1040c9b443d4STobin Davis 1041c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1042c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1043c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1044c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1045c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1046c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1047c9b443d4STobin Davis 1048c9b443d4STobin Davis { } 1049c9b443d4STobin Davis }; 1050c9b443d4STobin Davis #endif 1051c9b443d4STobin Davis 1052c9b443d4STobin Davis 1053c9b443d4STobin Davis /* initialize jack-sensing, too */ 1054c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1055c9b443d4STobin Davis { 1056c9b443d4STobin Davis conexant_init(codec); 1057c9b443d4STobin Davis cxt5045_hp_automute(codec); 1058c9b443d4STobin Davis return 0; 1059c9b443d4STobin Davis } 1060c9b443d4STobin Davis 1061c9b443d4STobin Davis 1062c9b443d4STobin Davis enum { 106315908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 106415908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 106515908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10665218c892SJiang Zhe CXT5045_BENQ, 10672de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1068c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1069c9b443d4STobin Davis CXT5045_TEST, 1070c9b443d4STobin Davis #endif 10711f8458a2STakashi Iwai CXT5045_AUTO, 1072f5fcc13cSTakashi Iwai CXT5045_MODELS 1073c9b443d4STobin Davis }; 1074c9b443d4STobin Davis 1075ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = { 107615908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 107715908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 107815908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10795218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10802de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1081c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1082f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1083c9b443d4STobin Davis #endif 10841f8458a2STakashi Iwai [CXT5045_AUTO] = "auto", 1085f5fcc13cSTakashi Iwai }; 1086c9b443d4STobin Davis 108734cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10882de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 10896a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10905218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 109115908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 109215908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10939e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10949e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 109515908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 109615908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 109715908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1098dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1099dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 110015908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1101c9b443d4STobin Davis {} 1102c9b443d4STobin Davis }; 1103c9b443d4STobin Davis 1104c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1105c9b443d4STobin Davis { 1106c9b443d4STobin Davis struct conexant_spec *spec; 1107c9b443d4STobin Davis int board_config; 1108c9b443d4STobin Davis 11091f8458a2STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 11101f8458a2STakashi Iwai cxt5045_models, 11111f8458a2STakashi Iwai cxt5045_cfg_tbl); 11121f8458a2STakashi Iwai if (board_config < 0) 1113c82693dbSTakashi Iwai board_config = CXT5045_AUTO; /* model=auto as default */ 11141f8458a2STakashi Iwai if (board_config == CXT5045_AUTO) 11151f8458a2STakashi Iwai return patch_conexant_auto(codec); 11161f8458a2STakashi Iwai 1117c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1118c9b443d4STobin Davis if (!spec) 1119c9b443d4STobin Davis return -ENOMEM; 1120c9b443d4STobin Davis codec->spec = spec; 11219421f954STakashi Iwai codec->pin_amp_workaround = 1; 1122c9b443d4STobin Davis 1123c9b443d4STobin Davis spec->multiout.max_channels = 2; 1124c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1125c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1126c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1127c9b443d4STobin Davis spec->num_adc_nids = 1; 1128c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1129c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1130c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1131c9b443d4STobin Davis spec->num_mixers = 1; 1132c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1133c9b443d4STobin Davis spec->num_init_verbs = 1; 1134c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1135c9b443d4STobin Davis spec->spdif_route = 0; 11363507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11373507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11385cd57529STobin Davis 11393507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1140c9b443d4STobin Davis 1141c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1142c9b443d4STobin Davis 1143c9b443d4STobin Davis switch (board_config) { 114415908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11457f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1146c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1147c9b443d4STobin Davis spec->num_init_verbs = 2; 11487f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11497f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11507f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11517f29673bSTobin Davis break; 115215908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 115386376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11547f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11557f29673bSTobin Davis spec->num_init_verbs = 2; 11567f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1157c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1158c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1159c9b443d4STobin Davis break; 116015908c36SMarc Boucher default: 116115908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 116215908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 116315908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 116415908c36SMarc Boucher spec->num_init_verbs = 3; 116515908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 116615908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 116715908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 116815908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 116915908c36SMarc Boucher break; 11705218c892SJiang Zhe case CXT5045_BENQ: 11715218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11725218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11735218c892SJiang Zhe spec->num_init_verbs = 1; 11745218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11755218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11765218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11775218c892SJiang Zhe spec->num_mixers = 2; 11785218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11795218c892SJiang Zhe break; 11802de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11812de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11822de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11832de3c232SJiang zhe spec->num_init_verbs = 2; 11842de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11852de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11862de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11872de3c232SJiang zhe break; 1188c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1189c9b443d4STobin Davis case CXT5045_TEST: 1190c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1191c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1192c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 119315908c36SMarc Boucher break; 119415908c36SMarc Boucher 1195c9b443d4STobin Davis #endif 1196c9b443d4STobin Davis } 119748ecb7e8STakashi Iwai 1198031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1199031005f7STakashi Iwai case 0x103c: 12008f0f5ff6SDaniel T Chen case 0x1631: 12010b587fc4SDaniel T Chen case 0x1734: 12020ebf9e36SDaniel T Chen case 0x17aa: 12030ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12040ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12050ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 120648ecb7e8STakashi Iwai */ 120748ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 120848ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 120948ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 121048ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 121148ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1212031005f7STakashi Iwai break; 1213031005f7STakashi Iwai } 121448ecb7e8STakashi Iwai 12153507e2a8STakashi Iwai if (spec->beep_amp) 12163507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12173507e2a8STakashi Iwai 1218c9b443d4STobin Davis return 0; 1219c9b443d4STobin Davis } 1220c9b443d4STobin Davis 1221c9b443d4STobin Davis 1222c9b443d4STobin Davis /* Conexant 5047 specific */ 122382f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1224c9b443d4STobin Davis 122534cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 122634cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 122734cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1228c9b443d4STobin Davis 122934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = { 12305cd57529STobin Davis { 2, NULL }, 12315cd57529STobin Davis }; 1232c9b443d4STobin Davis 123334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = { 123482f30040STobin Davis .num_items = 2, 123582f30040STobin Davis .items = { 123682f30040STobin Davis { "ExtMic", 0x2 }, 123782f30040STobin Davis { "Line-In", 0x1 }, 1238c9b443d4STobin Davis } 1239c9b443d4STobin Davis }; 1240c9b443d4STobin Davis 1241c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1242c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1243c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1244c9b443d4STobin Davis { 1245c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1246c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 124782f30040STobin Davis unsigned int bits; 1248c9b443d4STobin Davis 124982f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1250c9b443d4STobin Davis return 0; 1251c9b443d4STobin Davis 125282f30040STobin Davis /* toggle internal speakers mute depending of presence of 125382f30040STobin Davis * the headphone jack 125482f30040STobin Davis */ 125547fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12563b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12573b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12583b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12593b7523fcSTakashi Iwai */ 12605d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 126147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 126247fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 126347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 126447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1265c9b443d4STobin Davis return 1; 1266c9b443d4STobin Davis } 1267c9b443d4STobin Davis 1268c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1269c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1270c9b443d4STobin Davis { 127182f30040STobin Davis struct conexant_spec *spec = codec->spec; 1272dd87da1cSTobin Davis unsigned int bits; 1273c9b443d4STobin Davis 1274d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1275dd87da1cSTobin Davis 127647fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12773b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12785d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 127947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1280c9b443d4STobin Davis } 1281c9b443d4STobin Davis 1282c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1283c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1284c9b443d4STobin Davis { 128534cbe3a6STakashi Iwai static const struct hda_verb mic_jack_on[] = { 12869f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12879f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1288c9b443d4STobin Davis {} 1289c9b443d4STobin Davis }; 129034cbe3a6STakashi Iwai static const struct hda_verb mic_jack_off[] = { 12919f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12929f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1293c9b443d4STobin Davis {} 1294c9b443d4STobin Davis }; 1295c9b443d4STobin Davis unsigned int present; 1296c9b443d4STobin Davis 1297d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1298c9b443d4STobin Davis if (present) 1299c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1300c9b443d4STobin Davis else 1301c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1302c9b443d4STobin Davis } 1303c9b443d4STobin Davis 1304c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1305c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1306c9b443d4STobin Davis unsigned int res) 1307c9b443d4STobin Davis { 13089f113e0eSMarc Boucher switch (res >> 26) { 1309c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1310c9b443d4STobin Davis cxt5047_hp_automute(codec); 1311c9b443d4STobin Davis break; 1312c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1313c9b443d4STobin Davis cxt5047_hp_automic(codec); 1314c9b443d4STobin Davis break; 1315c9b443d4STobin Davis } 1316c9b443d4STobin Davis } 1317c9b443d4STobin Davis 131834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = { 1319df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1320df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 13215f99f86aSDavid Henningsson HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 1322c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1323c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1324c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1325c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 132682f30040STobin Davis { 132782f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 132882f30040STobin Davis .name = "Master Playback Switch", 132982f30040STobin Davis .info = cxt_eapd_info, 133082f30040STobin Davis .get = cxt_eapd_get, 1331c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1332c9b443d4STobin Davis .private_value = 0x13, 1333c9b443d4STobin Davis }, 1334c9b443d4STobin Davis 1335c9b443d4STobin Davis {} 1336c9b443d4STobin Davis }; 1337c9b443d4STobin Davis 133834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13393b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13405d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1341df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1342df481e41STakashi Iwai {} 1343df481e41STakashi Iwai }; 1344df481e41STakashi Iwai 134534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1346c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1347c9b443d4STobin Davis { } /* end */ 1348c9b443d4STobin Davis }; 1349c9b443d4STobin Davis 135034cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = { 1351c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1352c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1353c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1354c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13557f29673bSTobin Davis /* HP, Speaker */ 1356b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13575b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13585b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13597f29673bSTobin Davis /* Record selector: Mic */ 13607f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13617f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13627f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13637f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1364c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1365c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1366c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1367c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1368c9b443d4STobin Davis /* SPDIF route: PCM */ 1369c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 137082f30040STobin Davis /* Enable unsolicited events */ 137182f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 137282f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1373c9b443d4STobin Davis { } /* end */ 1374c9b443d4STobin Davis }; 1375c9b443d4STobin Davis 1376c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 137734cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = { 13783b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1379c9b443d4STobin Davis {} 1380c9b443d4STobin Davis }; 1381c9b443d4STobin Davis 1382c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1383c9b443d4STobin Davis * configuration. 1384c9b443d4STobin Davis */ 1385c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 138634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = { 138782f30040STobin Davis .num_items = 4, 1388c9b443d4STobin Davis .items = { 138982f30040STobin Davis { "LINE1 pin", 0x0 }, 139082f30040STobin Davis { "MIC1 pin", 0x1 }, 139182f30040STobin Davis { "MIC2 pin", 0x2 }, 139282f30040STobin Davis { "CD pin", 0x3 }, 1393c9b443d4STobin Davis }, 1394c9b443d4STobin Davis }; 1395c9b443d4STobin Davis 139634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = { 1397c9b443d4STobin Davis 1398c9b443d4STobin Davis /* Output only controls */ 139982f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 140082f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 140182f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 140282f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1403c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1404c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1405c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1406c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 140782f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 140882f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 140982f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 141082f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1411c9b443d4STobin Davis 1412c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1413c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1414c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1415c9b443d4STobin Davis 141682f30040STobin Davis /* EAPD Switch Control */ 141782f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 141882f30040STobin Davis 1419c9b443d4STobin Davis /* Loopback mixer controls */ 142082f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 142182f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 142282f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 142382f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 142482f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 142582f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 142682f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 142782f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1428c9b443d4STobin Davis 142982f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 143082f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 143182f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 143282f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 143382f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 143482f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 143582f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 143682f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1437c9b443d4STobin Davis { 1438c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1439c9b443d4STobin Davis .name = "Input Source", 1440c9b443d4STobin Davis .info = conexant_mux_enum_info, 1441c9b443d4STobin Davis .get = conexant_mux_enum_get, 1442c9b443d4STobin Davis .put = conexant_mux_enum_put, 1443c9b443d4STobin Davis }, 1444854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14459f113e0eSMarc Boucher 1446c9b443d4STobin Davis { } /* end */ 1447c9b443d4STobin Davis }; 1448c9b443d4STobin Davis 144934cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = { 1450c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1451c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1452c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1453c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1454c9b443d4STobin Davis 1455c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1456c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1457c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1458c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1459c9b443d4STobin Davis * control. 1460c9b443d4STobin Davis */ 1461c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1462c9b443d4STobin Davis 1463c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1464c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1465c9b443d4STobin Davis */ 1466c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1467c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1468c9b443d4STobin Davis 1469c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1470c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1471c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1472c9b443d4STobin Davis 1473c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1474c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1475c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1476c9b443d4STobin Davis * input/output buffers as needed. 1477c9b443d4STobin Davis */ 1478c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1479c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1480c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1481c9b443d4STobin Davis 1482c9b443d4STobin Davis /* Mute capture amp left and right */ 1483c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1484c9b443d4STobin Davis 1485c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1486c9b443d4STobin Davis * pin) 1487c9b443d4STobin Davis */ 1488c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1489c9b443d4STobin Davis 1490c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1491c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1492c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1493c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1494c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1495c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1496c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1497c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1498c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1499c9b443d4STobin Davis 1500c9b443d4STobin Davis { } 1501c9b443d4STobin Davis }; 1502c9b443d4STobin Davis #endif 1503c9b443d4STobin Davis 1504c9b443d4STobin Davis 1505c9b443d4STobin Davis /* initialize jack-sensing, too */ 1506c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1507c9b443d4STobin Davis { 1508c9b443d4STobin Davis conexant_init(codec); 1509c9b443d4STobin Davis cxt5047_hp_automute(codec); 1510c9b443d4STobin Davis return 0; 1511c9b443d4STobin Davis } 1512c9b443d4STobin Davis 1513c9b443d4STobin Davis 1514c9b443d4STobin Davis enum { 1515f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1516f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1517f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1518c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1519c9b443d4STobin Davis CXT5047_TEST, 1520c9b443d4STobin Davis #endif 1521fa5dadcbSTakashi Iwai CXT5047_AUTO, 1522f5fcc13cSTakashi Iwai CXT5047_MODELS 1523c9b443d4STobin Davis }; 1524c9b443d4STobin Davis 1525ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = { 1526f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1527f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1528f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1529c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1530f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1531c9b443d4STobin Davis #endif 1532fa5dadcbSTakashi Iwai [CXT5047_AUTO] = "auto", 1533f5fcc13cSTakashi Iwai }; 1534c9b443d4STobin Davis 153534cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1536ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1537dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1538dea0a509STakashi Iwai CXT5047_LAPTOP), 1539f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1540c9b443d4STobin Davis {} 1541c9b443d4STobin Davis }; 1542c9b443d4STobin Davis 1543c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1544c9b443d4STobin Davis { 1545c9b443d4STobin Davis struct conexant_spec *spec; 1546c9b443d4STobin Davis int board_config; 1547c9b443d4STobin Davis 1548fa5dadcbSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1549fa5dadcbSTakashi Iwai cxt5047_models, 1550fa5dadcbSTakashi Iwai cxt5047_cfg_tbl); 1551fa5dadcbSTakashi Iwai if (board_config < 0) 1552c82693dbSTakashi Iwai board_config = CXT5047_AUTO; /* model=auto as default */ 1553fa5dadcbSTakashi Iwai if (board_config == CXT5047_AUTO) 1554fa5dadcbSTakashi Iwai return patch_conexant_auto(codec); 1555fa5dadcbSTakashi Iwai 1556c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1557c9b443d4STobin Davis if (!spec) 1558c9b443d4STobin Davis return -ENOMEM; 1559c9b443d4STobin Davis codec->spec = spec; 15609421f954STakashi Iwai codec->pin_amp_workaround = 1; 1561c9b443d4STobin Davis 1562c9b443d4STobin Davis spec->multiout.max_channels = 2; 1563c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1564c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1565c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1566c9b443d4STobin Davis spec->num_adc_nids = 1; 1567c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1568c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1569c9b443d4STobin Davis spec->num_mixers = 1; 1570df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1571c9b443d4STobin Davis spec->num_init_verbs = 1; 1572c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1573c9b443d4STobin Davis spec->spdif_route = 0; 15745cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15755cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1576c9b443d4STobin Davis 1577c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1578c9b443d4STobin Davis 1579c9b443d4STobin Davis switch (board_config) { 1580c9b443d4STobin Davis case CXT5047_LAPTOP: 1581df481e41STakashi Iwai spec->num_mixers = 2; 1582df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1583df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1584c9b443d4STobin Davis break; 1585c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1586df481e41STakashi Iwai spec->num_mixers = 2; 1587df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1588fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1589c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1590c9b443d4STobin Davis break; 1591c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 159282f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1593df481e41STakashi Iwai spec->num_mixers = 2; 1594df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1595c9b443d4STobin Davis spec->num_init_verbs = 2; 1596c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1597fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1598c9b443d4STobin Davis break; 1599c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1600c9b443d4STobin Davis case CXT5047_TEST: 1601c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1602c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1603c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1604fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1605c9b443d4STobin Davis #endif 1606c9b443d4STobin Davis } 1607dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1608025f206cSDaniel T Chen 1609025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1610025f206cSDaniel T Chen case 0x103c: 1611025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1612025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1613025f206cSDaniel T Chen * with 0 dB offset 0x17) 1614025f206cSDaniel T Chen */ 1615025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1616025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1617025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1618025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1619025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1620025f206cSDaniel T Chen break; 1621025f206cSDaniel T Chen } 1622025f206cSDaniel T Chen 1623c9b443d4STobin Davis return 0; 1624c9b443d4STobin Davis } 1625c9b443d4STobin Davis 1626461e2c78STakashi Iwai /* Conexant 5051 specific */ 162734cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 162834cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1629461e2c78STakashi Iwai 163034cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = { 1631461e2c78STakashi Iwai { 2, NULL }, 1632461e2c78STakashi Iwai }; 1633461e2c78STakashi Iwai 1634461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1635461e2c78STakashi Iwai { 1636461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1637461e2c78STakashi Iwai unsigned int pinctl; 163823d2df5bSTakashi Iwai /* headphone pin */ 163923d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 164023d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 164123d2df5bSTakashi Iwai pinctl); 164223d2df5bSTakashi Iwai /* speaker pin */ 1643461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1644461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1645461e2c78STakashi Iwai pinctl); 1646*a80581d0SJustin P. Mattock /* on ideapad there is an additional speaker (subwoofer) to mute */ 1647f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1648f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1649f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1650f7154de2SHerton Ronaldo Krzesinski pinctl); 1651461e2c78STakashi Iwai } 1652461e2c78STakashi Iwai 1653461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1654461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1655461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1656461e2c78STakashi Iwai { 1657461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1658461e2c78STakashi Iwai 1659461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1660461e2c78STakashi Iwai return 0; 1661461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1662461e2c78STakashi Iwai return 1; 1663461e2c78STakashi Iwai } 1664461e2c78STakashi Iwai 1665461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1666461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1667461e2c78STakashi Iwai { 166879d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1669461e2c78STakashi Iwai unsigned int present; 1670461e2c78STakashi Iwai 1671faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 167279d7d533STakashi Iwai return; 1673d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1674461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1675461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1676461e2c78STakashi Iwai present ? 0x01 : 0x00); 1677461e2c78STakashi Iwai } 1678461e2c78STakashi Iwai 1679461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1680461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1681461e2c78STakashi Iwai { 1682461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1683461e2c78STakashi Iwai unsigned int present; 1684461e2c78STakashi Iwai hda_nid_t new_adc; 1685461e2c78STakashi Iwai 1686faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 168779d7d533STakashi Iwai return; 1688d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1689461e2c78STakashi Iwai if (present) 1690461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1691461e2c78STakashi Iwai else 1692461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1693461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1694461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1695461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1696f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1697461e2c78STakashi Iwai spec->cur_adc = new_adc; 1698461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1699461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1700461e2c78STakashi Iwai spec->cur_adc_format); 1701461e2c78STakashi Iwai } 1702461e2c78STakashi Iwai } 1703461e2c78STakashi Iwai 1704461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1705461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1706461e2c78STakashi Iwai { 1707461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1708461e2c78STakashi Iwai 1709d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1710461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1711461e2c78STakashi Iwai } 1712461e2c78STakashi Iwai 1713461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1714461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1715461e2c78STakashi Iwai unsigned int res) 1716461e2c78STakashi Iwai { 1717461e2c78STakashi Iwai switch (res >> 26) { 1718461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1719461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1720461e2c78STakashi Iwai break; 1721461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1722461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1723461e2c78STakashi Iwai break; 1724461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1725461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1726461e2c78STakashi Iwai break; 1727461e2c78STakashi Iwai } 1728461e2c78STakashi Iwai } 1729461e2c78STakashi Iwai 173034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1731461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1732461e2c78STakashi Iwai { 1733461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1734461e2c78STakashi Iwai .name = "Master Playback Switch", 1735461e2c78STakashi Iwai .info = cxt_eapd_info, 1736461e2c78STakashi Iwai .get = cxt_eapd_get, 1737461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1738461e2c78STakashi Iwai .private_value = 0x1a, 1739461e2c78STakashi Iwai }, 17402c7a3fb3STakashi Iwai {} 17412c7a3fb3STakashi Iwai }; 1742461e2c78STakashi Iwai 174334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17442c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17452c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17468607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17478607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 17482c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17492c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1750461e2c78STakashi Iwai {} 1751461e2c78STakashi Iwai }; 1752461e2c78STakashi Iwai 175334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1754461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1755461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17568607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT), 17578607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT), 1758461e2c78STakashi Iwai {} 1759461e2c78STakashi Iwai }; 1760461e2c78STakashi Iwai 176134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17624e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17634e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 176479d7d533STakashi Iwai {} 176579d7d533STakashi Iwai }; 176679d7d533STakashi Iwai 176734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17685f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17695f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1770cd9d95a5SKen Prox {} 1771cd9d95a5SKen Prox }; 1772cd9d95a5SKen Prox 177334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1774faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1775faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17768607f7c4SDavid Henningsson HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT), 17778607f7c4SDavid Henningsson HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT), 1778faddaa5dSTakashi Iwai {} 1779faddaa5dSTakashi Iwai }; 1780faddaa5dSTakashi Iwai 178134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = { 1782461e2c78STakashi Iwai /* Line in, Mic */ 1783461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1784461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1785461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1786461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1787461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1788461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1789461e2c78STakashi Iwai /* SPK */ 1790461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1791461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1792461e2c78STakashi Iwai /* HP, Amp */ 1793461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1794461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1795461e2c78STakashi Iwai /* DAC1 */ 1796461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 179728c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1798461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1799461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1800461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1801461e2c78STakashi Iwai /* SPDIF route: PCM */ 18021965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1803461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1804461e2c78STakashi Iwai /* EAPD */ 1805461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1806461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1807461e2c78STakashi Iwai { } /* end */ 1808461e2c78STakashi Iwai }; 1809461e2c78STakashi Iwai 181034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 181179d7d533STakashi Iwai /* Line in, Mic */ 181279d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 181379d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 181479d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 181579d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 181679d7d533STakashi Iwai /* SPK */ 181779d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 181879d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 181979d7d533STakashi Iwai /* HP, Amp */ 182079d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 182179d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 182279d7d533STakashi Iwai /* DAC1 */ 182379d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 182428c4edb7SDavid Henningsson /* Record selector: Internal mic */ 182579d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 182679d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 182779d7d533STakashi Iwai /* SPDIF route: PCM */ 182879d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 182979d7d533STakashi Iwai /* EAPD */ 183079d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 183179d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 183279d7d533STakashi Iwai { } /* end */ 183379d7d533STakashi Iwai }; 183479d7d533STakashi Iwai 183534cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = { 1836cd9d95a5SKen Prox /* Line in, Mic */ 183730ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1838cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1839cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1840cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1841cd9d95a5SKen Prox /* SPK */ 1842cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1843cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1844cd9d95a5SKen Prox /* HP, Amp */ 1845cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1846cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1847cd9d95a5SKen Prox /* DAC1 */ 1848cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 184928c4edb7SDavid Henningsson /* Record selector: Internal mic */ 1850cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1851cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1852cd9d95a5SKen Prox /* SPDIF route: PCM */ 1853cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1854cd9d95a5SKen Prox /* EAPD */ 1855cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1856cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1857cd9d95a5SKen Prox { } /* end */ 1858cd9d95a5SKen Prox }; 1859cd9d95a5SKen Prox 18606953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18616953e552STakashi Iwai unsigned int event) 18626953e552STakashi Iwai { 18636953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18646953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18656953e552STakashi Iwai AC_USRSP_EN | event); 18666953e552STakashi Iwai } 18676953e552STakashi Iwai 186834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1869f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1870f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1871f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1872f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1873f7154de2SHerton Ronaldo Krzesinski }; 1874f7154de2SHerton Ronaldo Krzesinski 1875461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1876461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1877461e2c78STakashi Iwai { 18786953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18796953e552STakashi Iwai 1880461e2c78STakashi Iwai conexant_init(codec); 18816953e552STakashi Iwai 18826953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18836953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18846953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18856953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18866953e552STakashi Iwai 1887461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1888461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1889461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1890461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1891461e2c78STakashi Iwai } 1892461e2c78STakashi Iwai return 0; 1893461e2c78STakashi Iwai } 1894461e2c78STakashi Iwai 1895461e2c78STakashi Iwai 1896461e2c78STakashi Iwai enum { 1897461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1898461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 189979d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 1900cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1901faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1902f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 19036764bcefSTakashi Iwai CXT5051_AUTO, /* auto-parser */ 1904461e2c78STakashi Iwai CXT5051_MODELS 1905461e2c78STakashi Iwai }; 1906461e2c78STakashi Iwai 1907ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = { 1908461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1909461e2c78STakashi Iwai [CXT5051_HP] = "hp", 191079d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 19115f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1912faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1913f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 19146764bcefSTakashi Iwai [CXT5051_AUTO] = "auto", 1915461e2c78STakashi Iwai }; 1916461e2c78STakashi Iwai 191734cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = { 191879d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19191812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19205f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1921faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1922461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1923461e2c78STakashi Iwai CXT5051_LAPTOP), 1924461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1925f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1926461e2c78STakashi Iwai {} 1927461e2c78STakashi Iwai }; 1928461e2c78STakashi Iwai 1929461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1930461e2c78STakashi Iwai { 1931461e2c78STakashi Iwai struct conexant_spec *spec; 1932461e2c78STakashi Iwai int board_config; 1933461e2c78STakashi Iwai 19346764bcefSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 19356764bcefSTakashi Iwai cxt5051_models, 19366764bcefSTakashi Iwai cxt5051_cfg_tbl); 19376764bcefSTakashi Iwai if (board_config < 0) 1938c82693dbSTakashi Iwai board_config = CXT5051_AUTO; /* model=auto as default */ 19391f8458a2STakashi Iwai if (board_config == CXT5051_AUTO) 19406764bcefSTakashi Iwai return patch_conexant_auto(codec); 19416764bcefSTakashi Iwai 1942461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1943461e2c78STakashi Iwai if (!spec) 1944461e2c78STakashi Iwai return -ENOMEM; 1945461e2c78STakashi Iwai codec->spec = spec; 19469421f954STakashi Iwai codec->pin_amp_workaround = 1; 1947461e2c78STakashi Iwai 1948461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1949461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1950461e2c78STakashi Iwai 1951461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1952461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1953461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1954461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1955461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1956461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19572c7a3fb3STakashi Iwai spec->num_mixers = 2; 19582c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19592c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1960461e2c78STakashi Iwai spec->num_init_verbs = 1; 1961461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1962461e2c78STakashi Iwai spec->spdif_route = 0; 1963461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1964461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1965461e2c78STakashi Iwai spec->cur_adc = 0; 1966461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1967461e2c78STakashi Iwai 19683507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 19693507e2a8STakashi Iwai 197079d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 197179d7d533STakashi Iwai 1972faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1973461e2c78STakashi Iwai switch (board_config) { 1974461e2c78STakashi Iwai case CXT5051_HP: 1975461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1976461e2c78STakashi Iwai break; 197779d7d533STakashi Iwai case CXT5051_HP_DV6736: 197879d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 197979d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1980faddaa5dSTakashi Iwai spec->auto_mic = 0; 198179d7d533STakashi Iwai break; 1982cd9d95a5SKen Prox case CXT5051_F700: 1983cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1984cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1985faddaa5dSTakashi Iwai spec->auto_mic = 0; 1986faddaa5dSTakashi Iwai break; 1987faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1988faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1989faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1990cd9d95a5SKen Prox break; 1991f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 1992f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 1993f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 1994f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 1995f7154de2SHerton Ronaldo Krzesinski break; 1996461e2c78STakashi Iwai } 1997461e2c78STakashi Iwai 19983507e2a8STakashi Iwai if (spec->beep_amp) 19993507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20003507e2a8STakashi Iwai 2001461e2c78STakashi Iwai return 0; 2002461e2c78STakashi Iwai } 2003461e2c78STakashi Iwai 20040fb67e98SDaniel Drake /* Conexant 5066 specific */ 20050fb67e98SDaniel Drake 200634cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 200734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 200834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 200934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 }; 20100fb67e98SDaniel Drake 2011dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2012dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2013dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2014dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2015dbaccc0cSDaniel Drake 201634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = { 20170fb67e98SDaniel Drake { 2, NULL }, 20180fb67e98SDaniel Drake }; 20190fb67e98SDaniel Drake 2020a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A (1 << 0) 2021a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D (1 << 1) 2022a3de8ab8STakashi Iwai #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A) 2023a3de8ab8STakashi Iwai #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D) 2024a3de8ab8STakashi Iwai 20250fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20260fb67e98SDaniel Drake { 20270fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20280fb67e98SDaniel Drake unsigned int pinctl; 20290fb67e98SDaniel Drake 20303a253445SJohn Baboval snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n", 20313a253445SJohn Baboval spec->hp_present, spec->cur_eapd); 20320fb67e98SDaniel Drake 20330fb67e98SDaniel Drake /* Port A (HP) */ 2034a3de8ab8STakashi Iwai pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0; 20350fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20360fb67e98SDaniel Drake pinctl); 20370fb67e98SDaniel Drake 20380fb67e98SDaniel Drake /* Port D (HP/LO) */ 2039a3de8ab8STakashi Iwai pinctl = spec->cur_eapd ? spec->port_d_mode : 0; 2040a3de8ab8STakashi Iwai if (spec->dell_automute || spec->thinkpad) { 2041a3de8ab8STakashi Iwai /* Mute if Port A is connected */ 2042a3de8ab8STakashi Iwai if (hp_port_a_present(spec)) 20433a253445SJohn Baboval pinctl = 0; 20443a253445SJohn Baboval } else { 2045a3de8ab8STakashi Iwai /* Thinkpad/Dell doesn't give pin-D status */ 2046a3de8ab8STakashi Iwai if (!hp_port_d_present(spec)) 2047a3de8ab8STakashi Iwai pinctl = 0; 20483a253445SJohn Baboval } 20490fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20500fb67e98SDaniel Drake pinctl); 20510fb67e98SDaniel Drake 20520fb67e98SDaniel Drake /* CLASS_D AMP */ 20530fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20540fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20550fb67e98SDaniel Drake pinctl); 20560fb67e98SDaniel Drake } 20570fb67e98SDaniel Drake 20580fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20590fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20600fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20610fb67e98SDaniel Drake { 20620fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20630fb67e98SDaniel Drake 20640fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20650fb67e98SDaniel Drake return 0; 20660fb67e98SDaniel Drake 20670fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20680fb67e98SDaniel Drake return 1; 20690fb67e98SDaniel Drake } 20700fb67e98SDaniel Drake 2071c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2072c4cfe66cSDaniel Drake .num_items = 3, 2073c4cfe66cSDaniel Drake .items = { 2074c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2075c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2076c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2077c4cfe66cSDaniel Drake }, 2078c4cfe66cSDaniel Drake }; 2079c4cfe66cSDaniel Drake 2080c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2081c4cfe66cSDaniel Drake { 2082c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2083c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2084c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2085c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2086c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2087c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2088c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2089c4cfe66cSDaniel Drake } 2090c4cfe66cSDaniel Drake 209175f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 209275f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 209375f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 209475f8991dSDaniel Drake * is happening when it is not. */ 209575f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20960fb67e98SDaniel Drake { 2097dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 209875f8991dSDaniel Drake if (!spec->recording) 209975f8991dSDaniel Drake return; 21000fb67e98SDaniel Drake 2101c4cfe66cSDaniel Drake if (spec->dc_enable) { 2102c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2103c4cfe66cSDaniel Drake * through our special DC port */ 2104c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2105c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2106c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2107c4cfe66cSDaniel Drake 2108c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2109c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2110c4cfe66cSDaniel Drake {}, 2111c4cfe66cSDaniel Drake }; 2112c4cfe66cSDaniel Drake 2113c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2114c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2115c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2116c4cfe66cSDaniel Drake return; 2117c4cfe66cSDaniel Drake } 2118c4cfe66cSDaniel Drake 2119c4cfe66cSDaniel Drake /* disable DC (port F) */ 2120c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2121c4cfe66cSDaniel Drake 212275f8991dSDaniel Drake /* external mic, port B */ 212375f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 212475f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21250fb67e98SDaniel Drake 212675f8991dSDaniel Drake /* internal mic, port C */ 212775f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 212875f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 212975f8991dSDaniel Drake } 21300fb67e98SDaniel Drake 213175f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 213275f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 213375f8991dSDaniel Drake { 213475f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21350fb67e98SDaniel Drake unsigned int present; 21360fb67e98SDaniel Drake 2137c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2138c4cfe66cSDaniel Drake return; 2139c4cfe66cSDaniel Drake 214075f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 214175f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 214275f8991dSDaniel Drake if (present) 21430fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 214475f8991dSDaniel Drake else 21450fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 214675f8991dSDaniel Drake 214775f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 214875f8991dSDaniel Drake present ? 0 : 1); 214975f8991dSDaniel Drake spec->ext_mic_present = !!present; 215075f8991dSDaniel Drake 215175f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21520fb67e98SDaniel Drake } 21530fb67e98SDaniel Drake 215495a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 215595a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 215695a618bdSEinar Rünkaru { 215795a618bdSEinar Rünkaru unsigned int present; 215895a618bdSEinar Rünkaru 215995a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 216095a618bdSEinar Rünkaru /* enable external mic, port B */ 216175f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 216295a618bdSEinar Rünkaru 216395a618bdSEinar Rünkaru /* switch to external mic input */ 216495a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 216595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 216695a618bdSEinar Rünkaru 216795a618bdSEinar Rünkaru /* disable internal digital mic */ 216895a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 216995a618bdSEinar Rünkaru {} 217095a618bdSEinar Rünkaru }; 217134cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 217295a618bdSEinar Rünkaru /* enable internal mic, port C */ 217395a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 217495a618bdSEinar Rünkaru 217595a618bdSEinar Rünkaru /* switch to internal mic input */ 217695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 217795a618bdSEinar Rünkaru 217895a618bdSEinar Rünkaru /* disable external mic, port B */ 217995a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 218095a618bdSEinar Rünkaru {} 218195a618bdSEinar Rünkaru }; 218295a618bdSEinar Rünkaru 218395a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 218495a618bdSEinar Rünkaru if (present) { 218595a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 218695a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 218795a618bdSEinar Rünkaru } else { 218895a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 218995a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 219095a618bdSEinar Rünkaru } 219195a618bdSEinar Rünkaru } 219295a618bdSEinar Rünkaru 2193cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2194cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2195cfd3d8dcSGreg Alexander { 2196cfd3d8dcSGreg Alexander unsigned int present; 2197cfd3d8dcSGreg Alexander 2198cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2199cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2200cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2201cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2202cfd3d8dcSGreg Alexander {} 2203cfd3d8dcSGreg Alexander }; 220434cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 2205cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2206cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2207cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2208cfd3d8dcSGreg Alexander {} 2209cfd3d8dcSGreg Alexander }; 2210cfd3d8dcSGreg Alexander 2211cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2212cfd3d8dcSGreg Alexander if (present) { 2213cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2214cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2215cfd3d8dcSGreg Alexander } else { 2216cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2217cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2218cfd3d8dcSGreg Alexander } 2219cfd3d8dcSGreg Alexander } 2220cfd3d8dcSGreg Alexander 2221a1d6906eSDavid Henningsson 2222a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2223a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec) 2224a1d6906eSDavid Henningsson { 2225a1d6906eSDavid Henningsson unsigned int present; 2226a1d6906eSDavid Henningsson 2227a1d6906eSDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2228a1d6906eSDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2229a1d6906eSDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2230a1d6906eSDavid Henningsson present ? 1 : 0); 2231a1d6906eSDavid Henningsson } 2232a1d6906eSDavid Henningsson 2233a1d6906eSDavid Henningsson 2234048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2235048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2236048e78a5SDavid Henningsson { 2237048e78a5SDavid Henningsson unsigned int present; 2238048e78a5SDavid Henningsson 2239048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2240048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2241048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2242048e78a5SDavid Henningsson present ? 1 : 3); 2243048e78a5SDavid Henningsson } 2244048e78a5SDavid Henningsson 2245048e78a5SDavid Henningsson 22467b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 22477b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 22487b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 22497b2bfdbcSJens Taprogge { 22507b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 22517b2bfdbcSJens Taprogge 225234cbe3a6STakashi Iwai static const struct hda_verb ext_mic_present[] = { 22537b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22547b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 22557b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22567b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22577b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22587b2bfdbcSJens Taprogge {} 22597b2bfdbcSJens Taprogge }; 226034cbe3a6STakashi Iwai static const struct hda_verb dock_mic_present[] = { 22617b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 22627b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 22637b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 22647b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22657b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22667b2bfdbcSJens Taprogge {} 22677b2bfdbcSJens Taprogge }; 226834cbe3a6STakashi Iwai static const struct hda_verb ext_mic_absent[] = { 22697b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 22707b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 22717b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22727b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 22737b2bfdbcSJens Taprogge {} 22747b2bfdbcSJens Taprogge }; 22757b2bfdbcSJens Taprogge 22767b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 22777b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 22787b2bfdbcSJens Taprogge if (ext_present) { 22797b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 22807b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 22817b2bfdbcSJens Taprogge } else if (dock_present) { 22827b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 22837b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 22847b2bfdbcSJens Taprogge } else { 22857b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 22867b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 22877b2bfdbcSJens Taprogge } 22887b2bfdbcSJens Taprogge } 22897b2bfdbcSJens Taprogge 22900fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22910fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22920fb67e98SDaniel Drake { 22930fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22940fb67e98SDaniel Drake unsigned int portA, portD; 22950fb67e98SDaniel Drake 22960fb67e98SDaniel Drake /* Port A */ 2297d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22980fb67e98SDaniel Drake 22990fb67e98SDaniel Drake /* Port D */ 2300d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23010fb67e98SDaniel Drake 2302a3de8ab8STakashi Iwai spec->hp_present = portA ? HP_PRESENT_PORT_A : 0; 2303a3de8ab8STakashi Iwai spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0; 23040fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23050fb67e98SDaniel Drake portA, portD, spec->hp_present); 23060fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23070fb67e98SDaniel Drake } 23080fb67e98SDaniel Drake 230902b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */ 231002b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec) 231102b6b5b6SDavid Henningsson { 231202b6b5b6SDavid Henningsson struct conexant_spec *spec = codec->spec; 231302b6b5b6SDavid Henningsson 231402b6b5b6SDavid Henningsson if (spec->dell_vostro) 231502b6b5b6SDavid Henningsson cxt5066_vostro_automic(codec); 231602b6b5b6SDavid Henningsson else if (spec->ideapad) 231702b6b5b6SDavid Henningsson cxt5066_ideapad_automic(codec); 231802b6b5b6SDavid Henningsson else if (spec->thinkpad) 231902b6b5b6SDavid Henningsson cxt5066_thinkpad_automic(codec); 232002b6b5b6SDavid Henningsson else if (spec->hp_laptop) 232102b6b5b6SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2322a1d6906eSDavid Henningsson else if (spec->asus) 2323a1d6906eSDavid Henningsson cxt5066_asus_automic(codec); 232402b6b5b6SDavid Henningsson } 232502b6b5b6SDavid Henningsson 23260fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 232775f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23280fb67e98SDaniel Drake { 2329c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23300fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23310fb67e98SDaniel Drake switch (res >> 26) { 23320fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23330fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23340fb67e98SDaniel Drake break; 23350fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2336c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2337c4cfe66cSDaniel Drake if (!spec->dc_enable) 233875f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23390fb67e98SDaniel Drake break; 23400fb67e98SDaniel Drake } 23410fb67e98SDaniel Drake } 23420fb67e98SDaniel Drake 234395a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 234402b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 234595a618bdSEinar Rünkaru { 234602b6b5b6SDavid Henningsson snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 234795a618bdSEinar Rünkaru switch (res >> 26) { 234895a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 234995a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 235095a618bdSEinar Rünkaru break; 235195a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 235202b6b5b6SDavid Henningsson cxt5066_automic(codec); 235395a618bdSEinar Rünkaru break; 235495a618bdSEinar Rünkaru } 235595a618bdSEinar Rünkaru } 235695a618bdSEinar Rünkaru 23577b2bfdbcSJens Taprogge 23580fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 23590fb67e98SDaniel Drake .num_items = 5, 23600fb67e98SDaniel Drake .items = { 23610fb67e98SDaniel Drake { "0dB", 0 }, 23620fb67e98SDaniel Drake { "10dB", 1 }, 23630fb67e98SDaniel Drake { "20dB", 2 }, 23640fb67e98SDaniel Drake { "30dB", 3 }, 23650fb67e98SDaniel Drake { "40dB", 4 }, 23660fb67e98SDaniel Drake }, 23670fb67e98SDaniel Drake }; 23680fb67e98SDaniel Drake 2369cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2370c4cfe66cSDaniel Drake { 2371c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2372cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2373c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2374c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2375c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 23767b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2377cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2378cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2379cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2380cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2381cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2382cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2383cfd3d8dcSGreg Alexander } 2384c4cfe66cSDaniel Drake } 2385c4cfe66cSDaniel Drake 23860fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 23870fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 23880fb67e98SDaniel Drake { 23890fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 23900fb67e98SDaniel Drake } 23910fb67e98SDaniel Drake 23920fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 23930fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23940fb67e98SDaniel Drake { 23950fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2396c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2397c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23980fb67e98SDaniel Drake return 0; 23990fb67e98SDaniel Drake } 24000fb67e98SDaniel Drake 24010fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 24020fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24030fb67e98SDaniel Drake { 24040fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2405c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24060fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 24070fb67e98SDaniel Drake unsigned int idx; 24080fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 24090fb67e98SDaniel Drake if (idx >= imux->num_items) 24100fb67e98SDaniel Drake idx = imux->num_items - 1; 24110fb67e98SDaniel Drake 2412c4cfe66cSDaniel Drake spec->mic_boost = idx; 2413c4cfe66cSDaniel Drake if (!spec->dc_enable) 2414c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2415c4cfe66cSDaniel Drake return 1; 2416c4cfe66cSDaniel Drake } 24170fb67e98SDaniel Drake 2418c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2419c4cfe66cSDaniel Drake { 2420c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2421c4cfe66cSDaniel Drake /* disable gain */ 2422c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2423c4cfe66cSDaniel Drake 2424c4cfe66cSDaniel Drake /* switch to DC input */ 2425c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2426c4cfe66cSDaniel Drake {} 2427c4cfe66cSDaniel Drake }; 2428c4cfe66cSDaniel Drake 2429c4cfe66cSDaniel Drake /* configure as input source */ 2430c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2431c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2432c4cfe66cSDaniel Drake } 2433c4cfe66cSDaniel Drake 2434c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2435c4cfe66cSDaniel Drake { 2436c4cfe66cSDaniel Drake /* reconfigure input source */ 2437c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2438c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2439c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2440c4cfe66cSDaniel Drake } 2441c4cfe66cSDaniel Drake 2442c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2443c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2444c4cfe66cSDaniel Drake { 2445c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2446c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2447c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2448c4cfe66cSDaniel Drake return 0; 2449c4cfe66cSDaniel Drake } 2450c4cfe66cSDaniel Drake 2451c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2452c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2453c4cfe66cSDaniel Drake { 2454c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2455c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2456c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2457c4cfe66cSDaniel Drake 2458c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2459c4cfe66cSDaniel Drake return 0; 2460c4cfe66cSDaniel Drake 2461c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2462c4cfe66cSDaniel Drake if (dc_enable) 2463c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2464c4cfe66cSDaniel Drake else 2465c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2466c4cfe66cSDaniel Drake 2467c4cfe66cSDaniel Drake return 1; 2468c4cfe66cSDaniel Drake } 2469c4cfe66cSDaniel Drake 2470c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2471c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2472c4cfe66cSDaniel Drake { 2473c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2474c4cfe66cSDaniel Drake } 2475c4cfe66cSDaniel Drake 2476c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2477c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2478c4cfe66cSDaniel Drake { 2479c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2480c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2481c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2482c4cfe66cSDaniel Drake return 0; 2483c4cfe66cSDaniel Drake } 2484c4cfe66cSDaniel Drake 2485c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2486c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2487c4cfe66cSDaniel Drake { 2488c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2489c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2490c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2491c4cfe66cSDaniel Drake unsigned int idx; 2492c4cfe66cSDaniel Drake 2493c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2494c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2495c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2496c4cfe66cSDaniel Drake 2497c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2498c4cfe66cSDaniel Drake if (spec->dc_enable) 2499c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25000fb67e98SDaniel Drake return 1; 25010fb67e98SDaniel Drake } 25020fb67e98SDaniel Drake 250375f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 250475f8991dSDaniel Drake { 250575f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 250675f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 250775f8991dSDaniel Drake * recording LED comes on. */ 250875f8991dSDaniel Drake spec->recording = 1; 250975f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 251075f8991dSDaniel Drake } 251175f8991dSDaniel Drake 251275f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 251375f8991dSDaniel Drake { 251475f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 251575f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 251675f8991dSDaniel Drake /* disable external mic, port B */ 251775f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 251875f8991dSDaniel Drake 251975f8991dSDaniel Drake /* disble internal mic, port C */ 252075f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2521c4cfe66cSDaniel Drake 2522c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2523c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 252475f8991dSDaniel Drake {}, 252575f8991dSDaniel Drake }; 252675f8991dSDaniel Drake 252775f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 252875f8991dSDaniel Drake spec->recording = 0; 252975f8991dSDaniel Drake } 253075f8991dSDaniel Drake 2531f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec, 253234cbe3a6STakashi Iwai const hda_nid_t *dig_pins, 2533f6a2491cSAndy Robinson int num_pins) 2534f6a2491cSAndy Robinson { 2535f6a2491cSAndy Robinson struct conexant_spec *spec = codec->spec; 2536f6a2491cSAndy Robinson hda_nid_t *nid_loc = &spec->multiout.dig_out_nid; 2537f6a2491cSAndy Robinson int i; 2538f6a2491cSAndy Robinson 2539f6a2491cSAndy Robinson for (i = 0; i < num_pins; i++, dig_pins++) { 2540f6a2491cSAndy Robinson unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins); 2541f6a2491cSAndy Robinson if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE) 2542f6a2491cSAndy Robinson continue; 2543f6a2491cSAndy Robinson if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1) 2544f6a2491cSAndy Robinson continue; 2545f6a2491cSAndy Robinson if (spec->slave_dig_outs[0]) 2546f6a2491cSAndy Robinson nid_loc++; 2547f6a2491cSAndy Robinson else 2548f6a2491cSAndy Robinson nid_loc = spec->slave_dig_outs; 2549f6a2491cSAndy Robinson } 2550f6a2491cSAndy Robinson } 2551f6a2491cSAndy Robinson 255234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = { 25530fb67e98SDaniel Drake .num_items = 4, 25540fb67e98SDaniel Drake .items = { 25550fb67e98SDaniel Drake { "Mic B", 0 }, 25560fb67e98SDaniel Drake { "Mic C", 1 }, 25570fb67e98SDaniel Drake { "Mic E", 2 }, 25580fb67e98SDaniel Drake { "Mic F", 3 }, 25590fb67e98SDaniel Drake }, 25600fb67e98SDaniel Drake }; 25610fb67e98SDaniel Drake 256234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 25630fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 25640fb67e98SDaniel Drake .values = { 25650fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25660fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25670fb67e98SDaniel Drake 0 25680fb67e98SDaniel Drake }, 25690fb67e98SDaniel Drake }; 25700fb67e98SDaniel Drake 257134cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 25720fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 25730fb67e98SDaniel Drake .values = { 25740fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 25750fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 25760fb67e98SDaniel Drake 0 25770fb67e98SDaniel Drake }, 25780fb67e98SDaniel Drake }; 25790fb67e98SDaniel Drake 258034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = { 25810fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 25820fb67e98SDaniel Drake {} 25830fb67e98SDaniel Drake }; 25840fb67e98SDaniel Drake 258534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 25860fb67e98SDaniel Drake { 25870fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25880fb67e98SDaniel Drake .name = "Master Playback Volume", 25890fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 25900fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 25910fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 25925e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 25930fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 25940fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 25950fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 25960fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 25970fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 25980fb67e98SDaniel Drake .private_value = 25990fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26000fb67e98SDaniel Drake }, 26010fb67e98SDaniel Drake {} 26020fb67e98SDaniel Drake }; 26030fb67e98SDaniel Drake 260434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2605c4cfe66cSDaniel Drake { 2606c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2607c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2608c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2609c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2610c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2611c4cfe66cSDaniel Drake }, 2612c4cfe66cSDaniel Drake { 2613c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2614c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2615c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2616c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2617c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2618c4cfe66cSDaniel Drake }, 2619c4cfe66cSDaniel Drake {} 2620c4cfe66cSDaniel Drake }; 2621c4cfe66cSDaniel Drake 262234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = { 26230fb67e98SDaniel Drake { 26240fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26250fb67e98SDaniel Drake .name = "Master Playback Switch", 26260fb67e98SDaniel Drake .info = cxt_eapd_info, 26270fb67e98SDaniel Drake .get = cxt_eapd_get, 26280fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 26290fb67e98SDaniel Drake .private_value = 0x1d, 26300fb67e98SDaniel Drake }, 26310fb67e98SDaniel Drake 26320fb67e98SDaniel Drake { 26330fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2634c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 26350fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 26360fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 26370fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 26380fb67e98SDaniel Drake }, 26390fb67e98SDaniel Drake 26400fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 26410fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 26420fb67e98SDaniel Drake {} 26430fb67e98SDaniel Drake }; 26440fb67e98SDaniel Drake 264534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2646254bba6aSEinar Rünkaru { 2647254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 264828c4edb7SDavid Henningsson .name = "Internal Mic Boost Capture Enum", 2649254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2650254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2651254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2652254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2653254bba6aSEinar Rünkaru }, 2654254bba6aSEinar Rünkaru {} 2655254bba6aSEinar Rünkaru }; 2656254bba6aSEinar Rünkaru 265734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = { 26580fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 26590fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 26600fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 26610fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 26620fb67e98SDaniel Drake 26630fb67e98SDaniel Drake /* Speakers */ 26640fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26650fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26660fb67e98SDaniel Drake 26670fb67e98SDaniel Drake /* HP, Amp */ 26680fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26690fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26700fb67e98SDaniel Drake 26710fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 26720fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26730fb67e98SDaniel Drake 26740fb67e98SDaniel Drake /* DAC1 */ 26750fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26760fb67e98SDaniel Drake 26770fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 26780fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26790fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26800fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 26810fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26820fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 26830fb67e98SDaniel Drake 26840fb67e98SDaniel Drake /* no digital microphone support yet */ 26850fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26860fb67e98SDaniel Drake 26870fb67e98SDaniel Drake /* Audio input selector */ 26880fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26890fb67e98SDaniel Drake 26900fb67e98SDaniel Drake /* SPDIF route: PCM */ 26910fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 26920fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 26930fb67e98SDaniel Drake 26940fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26950fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26960fb67e98SDaniel Drake 26970fb67e98SDaniel Drake /* EAPD */ 26980fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26990fb67e98SDaniel Drake 27000fb67e98SDaniel Drake /* not handling these yet */ 27010fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27020fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27030fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27040fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27050fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27060fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27070fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27080fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27090fb67e98SDaniel Drake { } /* end */ 27100fb67e98SDaniel Drake }; 27110fb67e98SDaniel Drake 271234cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = { 27130fb67e98SDaniel Drake /* Port A: headphones */ 27140fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27150fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27160fb67e98SDaniel Drake 27170fb67e98SDaniel Drake /* Port B: external microphone */ 271875f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27190fb67e98SDaniel Drake 27200fb67e98SDaniel Drake /* Port C: internal microphone */ 272175f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27220fb67e98SDaniel Drake 27230fb67e98SDaniel Drake /* Port D: unused */ 27240fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27250fb67e98SDaniel Drake 27260fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27270fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27280fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27290fb67e98SDaniel Drake 2730c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 27310fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27320fb67e98SDaniel Drake 27330fb67e98SDaniel Drake /* Port G: internal speakers */ 27340fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27350fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27360fb67e98SDaniel Drake 27370fb67e98SDaniel Drake /* DAC1 */ 27380fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27390fb67e98SDaniel Drake 27400fb67e98SDaniel Drake /* DAC2: unused */ 27410fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 27420fb67e98SDaniel Drake 27430fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27440fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27450fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27460fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27470fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27480fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27490fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27500fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27510fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 27520fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27530fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 27540fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27550fb67e98SDaniel Drake 27560fb67e98SDaniel Drake /* Disable digital microphone port */ 27570fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27580fb67e98SDaniel Drake 27590fb67e98SDaniel Drake /* Audio input selectors */ 27600fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27610fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 27620fb67e98SDaniel Drake 27630fb67e98SDaniel Drake /* Disable SPDIF */ 27640fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27650fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27660fb67e98SDaniel Drake 27670fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 27680fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 27690fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 27700fb67e98SDaniel Drake { } /* end */ 27710fb67e98SDaniel Drake }; 27720fb67e98SDaniel Drake 277334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = { 277495a618bdSEinar Rünkaru /* Port A: headphones */ 277595a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 277695a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 277795a618bdSEinar Rünkaru 277895a618bdSEinar Rünkaru /* Port B: external microphone */ 277995a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278095a618bdSEinar Rünkaru 278195a618bdSEinar Rünkaru /* Port C: unused */ 278295a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278395a618bdSEinar Rünkaru 278495a618bdSEinar Rünkaru /* Port D: unused */ 278595a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278695a618bdSEinar Rünkaru 278795a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 278895a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 278995a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 279095a618bdSEinar Rünkaru 279195a618bdSEinar Rünkaru /* Port F: unused */ 279295a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 279395a618bdSEinar Rünkaru 279495a618bdSEinar Rünkaru /* Port G: internal speakers */ 279595a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 279695a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 279795a618bdSEinar Rünkaru 279895a618bdSEinar Rünkaru /* DAC1 */ 279995a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 280095a618bdSEinar Rünkaru 280195a618bdSEinar Rünkaru /* DAC2: unused */ 280295a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 280395a618bdSEinar Rünkaru 280495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 280595a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 280695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 280795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 280895a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 280995a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 281095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 281195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 281295a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 281395a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 281495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 281595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 281695a618bdSEinar Rünkaru 281795a618bdSEinar Rünkaru /* Digital microphone port */ 281895a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 281995a618bdSEinar Rünkaru 282095a618bdSEinar Rünkaru /* Audio input selectors */ 282195a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 282295a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 282395a618bdSEinar Rünkaru 282495a618bdSEinar Rünkaru /* Disable SPDIF */ 282595a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282695a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 282795a618bdSEinar Rünkaru 282895a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 282995a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 283095a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 283195a618bdSEinar Rünkaru { } /* end */ 283295a618bdSEinar Rünkaru }; 283395a618bdSEinar Rünkaru 283434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = { 2835cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2836cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2837cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2838cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2839cfd3d8dcSGreg Alexander 2840cfd3d8dcSGreg Alexander /* Speakers */ 2841cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2842cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2843cfd3d8dcSGreg Alexander 2844cfd3d8dcSGreg Alexander /* HP, Amp */ 2845cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2846cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2847cfd3d8dcSGreg Alexander 2848cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2849cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2850cfd3d8dcSGreg Alexander 2851cfd3d8dcSGreg Alexander /* DAC1 */ 2852cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2853cfd3d8dcSGreg Alexander 2854cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2855cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2856cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2857cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2858cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2859cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2860cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2861cfd3d8dcSGreg Alexander 2862cfd3d8dcSGreg Alexander /* Audio input selector */ 2863cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2864cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2865cfd3d8dcSGreg Alexander 2866cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2867cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2868cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2869cfd3d8dcSGreg Alexander 2870cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2871cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2872cfd3d8dcSGreg Alexander 2873cfd3d8dcSGreg Alexander /* internal microphone */ 287428c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 2875cfd3d8dcSGreg Alexander 2876cfd3d8dcSGreg Alexander /* EAPD */ 2877cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2878cfd3d8dcSGreg Alexander 2879cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2880cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2881cfd3d8dcSGreg Alexander { } /* end */ 2882cfd3d8dcSGreg Alexander }; 2883cfd3d8dcSGreg Alexander 288434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = { 28857b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 28867b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 28877b2bfdbcSJens Taprogge 28887b2bfdbcSJens Taprogge /* Port G: internal speakers */ 28897b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28907b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28917b2bfdbcSJens Taprogge 28927b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 28937b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28947b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28957b2bfdbcSJens Taprogge 28967b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 28977b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28987b2bfdbcSJens Taprogge 28997b2bfdbcSJens Taprogge /* Port C: Mic */ 29007b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29017b2bfdbcSJens Taprogge 29027b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29037b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29047b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29057b2bfdbcSJens Taprogge 29067b2bfdbcSJens Taprogge /* DAC1 */ 29077b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29087b2bfdbcSJens Taprogge 29097b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29107b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29117b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29127b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29137b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29147b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29157b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29167b2bfdbcSJens Taprogge 29177b2bfdbcSJens Taprogge /* Audio input selector */ 29187b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29197b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29207b2bfdbcSJens Taprogge 29217b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29227b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29237b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29247b2bfdbcSJens Taprogge 29257b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29267b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29277b2bfdbcSJens Taprogge 29287b2bfdbcSJens Taprogge /* internal microphone */ 292928c4edb7SDavid Henningsson {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */ 29307b2bfdbcSJens Taprogge 29317b2bfdbcSJens Taprogge /* EAPD */ 29327b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 29337b2bfdbcSJens Taprogge 29347b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 29357b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29367b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 29377b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29387b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 29397b2bfdbcSJens Taprogge { } /* end */ 29407b2bfdbcSJens Taprogge }; 29417b2bfdbcSJens Taprogge 294234cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = { 29430fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29440fb67e98SDaniel Drake { } /* end */ 29450fb67e98SDaniel Drake }; 29460fb67e98SDaniel Drake 2947048e78a5SDavid Henningsson 294834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 2949048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 2950048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2951048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2952048e78a5SDavid Henningsson { } /* end */ 2953048e78a5SDavid Henningsson }; 2954048e78a5SDavid Henningsson 29550fb67e98SDaniel Drake /* initialize jack-sensing, too */ 29560fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 29570fb67e98SDaniel Drake { 29580fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 29590fb67e98SDaniel Drake conexant_init(codec); 29600fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 29610fb67e98SDaniel Drake cxt5066_hp_automute(codec); 296202b6b5b6SDavid Henningsson cxt5066_automic(codec); 29630fb67e98SDaniel Drake } 2964c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 29650fb67e98SDaniel Drake return 0; 29660fb67e98SDaniel Drake } 29670fb67e98SDaniel Drake 296875f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 296975f8991dSDaniel Drake { 2970c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 297175f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 297275f8991dSDaniel Drake conexant_init(codec); 297375f8991dSDaniel Drake cxt5066_hp_automute(codec); 2974c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2975c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 297675f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2977c4cfe66cSDaniel Drake } else { 2978c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2979c4cfe66cSDaniel Drake } 298075f8991dSDaniel Drake return 0; 298175f8991dSDaniel Drake } 298275f8991dSDaniel Drake 29830fb67e98SDaniel Drake enum { 29840fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 29850fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 29860fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 29871feba3b7SDavid Henningsson CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */ 2988cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 29897b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 2990a1d6906eSDavid Henningsson CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */ 2991048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 2992fea4a4f9STakashi Iwai CXT5066_AUTO, /* BIOS auto-parser */ 29930fb67e98SDaniel Drake CXT5066_MODELS 29940fb67e98SDaniel Drake }; 29950fb67e98SDaniel Drake 2996ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = { 29970fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 29980fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 29990fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 30001feba3b7SDavid Henningsson [CXT5066_DELL_VOSTRO] = "dell-vostro", 3001cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30027b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3003a1d6906eSDavid Henningsson [CXT5066_ASUS] = "asus", 3004048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 3005fea4a4f9STakashi Iwai [CXT5066_AUTO] = "auto", 30060fb67e98SDaniel Drake }; 30070fb67e98SDaniel Drake 300834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30099966db22SDavid Henningsson SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO), 301000cd0bb7STakashi Iwai SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD), 30111feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO), 30128a96b1e0SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD), 3013ca6cd851SDaniel T Chen SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO), 30141feba3b7SDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO), 3015231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3016ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD), 3017ebbd224cSDavid Henningsson SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD), 3018048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3019f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS), 3020a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS), 3021f6a2491cSAndy Robinson SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS), 30222ca9cac9SAnisse Astier SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD), 3023c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30245637edb2SDavid Henningsson SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30255637edb2SDavid Henningsson CXT5066_LAPTOP), 30265637edb2SDavid Henningsson SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 30274d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 3028ef61d4e6SManoj Iyer SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 302919593875SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 303029c5fbbcSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T510", CXT5066_AUTO), 3031ca201c09SDaniel Suchy SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO), 303284012657SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3033b2cb1292SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3034d2859fd4SDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3035a1d6906eSDavid Henningsson SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), 3036af4ccf4fSTakashi Iwai SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO), 303722f21d51SDavid Henningsson SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ 30387ab1fc0aSDaniel T Chen SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO), 30390fb67e98SDaniel Drake {} 30400fb67e98SDaniel Drake }; 30410fb67e98SDaniel Drake 30420fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 30430fb67e98SDaniel Drake { 30440fb67e98SDaniel Drake struct conexant_spec *spec; 30450fb67e98SDaniel Drake int board_config; 30460fb67e98SDaniel Drake 3047fea4a4f9STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 3048fea4a4f9STakashi Iwai cxt5066_models, cxt5066_cfg_tbl); 3049fea4a4f9STakashi Iwai if (board_config < 0) 3050c82693dbSTakashi Iwai board_config = CXT5066_AUTO; /* model=auto as default */ 3051fea4a4f9STakashi Iwai if (board_config == CXT5066_AUTO) 3052fea4a4f9STakashi Iwai return patch_conexant_auto(codec); 3053fea4a4f9STakashi Iwai 30540fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 30550fb67e98SDaniel Drake if (!spec) 30560fb67e98SDaniel Drake return -ENOMEM; 30570fb67e98SDaniel Drake codec->spec = spec; 30580fb67e98SDaniel Drake 30590fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 306075f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 30610fb67e98SDaniel Drake 30620fb67e98SDaniel Drake spec->dell_automute = 0; 30630fb67e98SDaniel Drake spec->multiout.max_channels = 2; 30640fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 30650fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 3066f6a2491cSAndy Robinson conexant_check_dig_outs(codec, cxt5066_digout_pin_nids, 3067f6a2491cSAndy Robinson ARRAY_SIZE(cxt5066_digout_pin_nids)); 30680fb67e98SDaniel Drake spec->num_adc_nids = 1; 30690fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 30700fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 30710fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 30720fb67e98SDaniel Drake 30730fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 30740fb67e98SDaniel Drake 30750fb67e98SDaniel Drake spec->num_init_verbs = 1; 30760fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 30770fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 30780fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 30790fb67e98SDaniel Drake spec->cur_adc = 0; 30800fb67e98SDaniel Drake spec->cur_adc_idx = 0; 30810fb67e98SDaniel Drake 30823507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 30833507e2a8STakashi Iwai 30840fb67e98SDaniel Drake switch (board_config) { 30850fb67e98SDaniel Drake default: 30860fb67e98SDaniel Drake case CXT5066_LAPTOP: 30870fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30880fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30890fb67e98SDaniel Drake break; 30900fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 30910fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 30920fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 30930fb67e98SDaniel Drake 30940fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 30950fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 30960fb67e98SDaniel Drake spec->num_init_verbs++; 30970fb67e98SDaniel Drake spec->dell_automute = 1; 30980fb67e98SDaniel Drake break; 3099a1d6906eSDavid Henningsson case CXT5066_ASUS: 3100048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3101048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 310202b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3103048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3104048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3105048e78a5SDavid Henningsson spec->num_init_verbs++; 3106a1d6906eSDavid Henningsson spec->hp_laptop = board_config == CXT5066_HP_LAPTOP; 3107a1d6906eSDavid Henningsson spec->asus = board_config == CXT5066_ASUS; 3108048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3109048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3110048e78a5SDavid Henningsson /* no S/PDIF out */ 3111f6a2491cSAndy Robinson if (board_config == CXT5066_HP_LAPTOP) 3112048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3113048e78a5SDavid Henningsson /* input source automatically selected */ 3114048e78a5SDavid Henningsson spec->input_mux = NULL; 3115048e78a5SDavid Henningsson spec->port_d_mode = 0; 3116048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3117048e78a5SDavid Henningsson break; 3118048e78a5SDavid Henningsson 31190fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 312075f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 312175f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31220fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31230fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3124c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31250fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31260fb67e98SDaniel Drake spec->port_d_mode = 0; 3127c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31280fb67e98SDaniel Drake 31290fb67e98SDaniel Drake /* no S/PDIF out */ 31300fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31310fb67e98SDaniel Drake 31320fb67e98SDaniel Drake /* input source automatically selected */ 31330fb67e98SDaniel Drake spec->input_mux = NULL; 313475f8991dSDaniel Drake 313575f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 313675f8991dSDaniel Drake * at the right time */ 313775f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 313875f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31390fb67e98SDaniel Drake break; 31401feba3b7SDavid Henningsson case CXT5066_DELL_VOSTRO: 314175f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 314202b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 314395a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 314495a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 314595a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3146254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 314795a618bdSEinar Rünkaru spec->port_d_mode = 0; 3148254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3149c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 315095a618bdSEinar Rünkaru 315195a618bdSEinar Rünkaru /* no S/PDIF out */ 315295a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 315395a618bdSEinar Rünkaru 315495a618bdSEinar Rünkaru /* input source automatically selected */ 315595a618bdSEinar Rünkaru spec->input_mux = NULL; 315695a618bdSEinar Rünkaru break; 3157cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3158cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 315902b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 3160cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3161cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3162cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3163cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3164cfd3d8dcSGreg Alexander spec->ideapad = 1; 3165cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3166cfd3d8dcSGreg Alexander 3167cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3168cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3169cfd3d8dcSGreg Alexander 3170cfd3d8dcSGreg Alexander /* input source automatically selected */ 3171cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3172cfd3d8dcSGreg Alexander break; 31737b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 31747b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 317502b6b5b6SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_unsol_event; 31767b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31777b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31787b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 31797b2bfdbcSJens Taprogge spec->thinkpad = 1; 31807b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 31817b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 31827b2bfdbcSJens Taprogge 31837b2bfdbcSJens Taprogge /* no S/PDIF out */ 31847b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 31857b2bfdbcSJens Taprogge 31867b2bfdbcSJens Taprogge /* input source automatically selected */ 31877b2bfdbcSJens Taprogge spec->input_mux = NULL; 31887b2bfdbcSJens Taprogge break; 31890fb67e98SDaniel Drake } 31900fb67e98SDaniel Drake 31913507e2a8STakashi Iwai if (spec->beep_amp) 31923507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 31933507e2a8STakashi Iwai 31940fb67e98SDaniel Drake return 0; 31950fb67e98SDaniel Drake } 3196461e2c78STakashi Iwai 3197461e2c78STakashi Iwai /* 3198f2e5731dSTakashi Iwai * Automatic parser for CX20641 & co 3199f2e5731dSTakashi Iwai */ 3200f2e5731dSTakashi Iwai 32016764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 32026764bcefSTakashi Iwai struct hda_codec *codec, 32036764bcefSTakashi Iwai unsigned int stream_tag, 32046764bcefSTakashi Iwai unsigned int format, 32056764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32066764bcefSTakashi Iwai { 32076764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 320847ad1f4eSTakashi Iwai hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc; 32096764bcefSTakashi Iwai if (spec->adc_switching) { 32106764bcefSTakashi Iwai spec->cur_adc = adc; 32116764bcefSTakashi Iwai spec->cur_adc_stream_tag = stream_tag; 32126764bcefSTakashi Iwai spec->cur_adc_format = format; 32136764bcefSTakashi Iwai } 32146764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format); 32156764bcefSTakashi Iwai return 0; 32166764bcefSTakashi Iwai } 32176764bcefSTakashi Iwai 32186764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 32196764bcefSTakashi Iwai struct hda_codec *codec, 32206764bcefSTakashi Iwai struct snd_pcm_substream *substream) 32216764bcefSTakashi Iwai { 32226764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 32236764bcefSTakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 32246764bcefSTakashi Iwai spec->cur_adc = 0; 32256764bcefSTakashi Iwai return 0; 32266764bcefSTakashi Iwai } 32276764bcefSTakashi Iwai 32286764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = { 32296764bcefSTakashi Iwai .substreams = 1, 32306764bcefSTakashi Iwai .channels_min = 2, 32316764bcefSTakashi Iwai .channels_max = 2, 32326764bcefSTakashi Iwai .nid = 0, /* fill later */ 32336764bcefSTakashi Iwai .ops = { 32346764bcefSTakashi Iwai .prepare = cx_auto_capture_pcm_prepare, 32356764bcefSTakashi Iwai .cleanup = cx_auto_capture_pcm_cleanup 32366764bcefSTakashi Iwai }, 32376764bcefSTakashi Iwai }; 32386764bcefSTakashi Iwai 323934cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 }; 3240f2e5731dSTakashi Iwai 32418d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\ 32428d087c76STakashi Iwai snd_hda_get_conn_index(codec, mux, nid, 0) 3243f2e5731dSTakashi Iwai 3244f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list. 3245f2e5731dSTakashi Iwai * Return the nid if found and reduce the DAC list, or return zero if 3246f2e5731dSTakashi Iwai * not found 3247f2e5731dSTakashi Iwai */ 3248f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin, 3249f2e5731dSTakashi Iwai hda_nid_t *dacs, int *num_dacs) 3250f2e5731dSTakashi Iwai { 3251f2e5731dSTakashi Iwai int i, nums = *num_dacs; 3252f2e5731dSTakashi Iwai hda_nid_t ret = 0; 3253f2e5731dSTakashi Iwai 3254f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3255f2e5731dSTakashi Iwai if (get_connection_index(codec, pin, dacs[i]) >= 0) { 3256f2e5731dSTakashi Iwai ret = dacs[i]; 3257f2e5731dSTakashi Iwai break; 3258f2e5731dSTakashi Iwai } 3259f2e5731dSTakashi Iwai } 3260f2e5731dSTakashi Iwai if (!ret) 3261f2e5731dSTakashi Iwai return 0; 3262f2e5731dSTakashi Iwai if (--nums > 0) 3263f2e5731dSTakashi Iwai memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t)); 3264f2e5731dSTakashi Iwai *num_dacs = nums; 3265f2e5731dSTakashi Iwai return ret; 3266f2e5731dSTakashi Iwai } 3267f2e5731dSTakashi Iwai 3268f2e5731dSTakashi Iwai #define MAX_AUTO_DACS 5 3269f2e5731dSTakashi Iwai 32701f015f5fSTakashi Iwai #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */ 32711f015f5fSTakashi Iwai 3272f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */ 3273f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3274f2e5731dSTakashi Iwai { 3275f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3276f2e5731dSTakashi Iwai int nums = 0; 3277f2e5731dSTakashi Iwai 3278f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3279f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3280f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3281f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3282f2e5731dSTakashi Iwai if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) { 3283f2e5731dSTakashi Iwai dacs[nums++] = nid; 3284f2e5731dSTakashi Iwai if (nums >= MAX_AUTO_DACS) 3285f2e5731dSTakashi Iwai break; 3286f2e5731dSTakashi Iwai } 3287f2e5731dSTakashi Iwai } 3288f2e5731dSTakashi Iwai return nums; 3289f2e5731dSTakashi Iwai } 3290f2e5731dSTakashi Iwai 3291f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */ 3292f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3293f2e5731dSTakashi Iwai int num_pins, hda_nid_t *dacs, int *rest, 3294468c5458SDavid Henningsson struct pin_dac_pair *filled, int nums, 3295468c5458SDavid Henningsson int type) 3296f2e5731dSTakashi Iwai { 3297468c5458SDavid Henningsson int i, start = nums; 3298f2e5731dSTakashi Iwai 3299468c5458SDavid Henningsson for (i = 0; i < num_pins; i++, nums++) { 3300f2e5731dSTakashi Iwai filled[nums].pin = pins[i]; 3301f2e5731dSTakashi Iwai filled[nums].type = type; 3302f2e5731dSTakashi Iwai filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3303468c5458SDavid Henningsson if (filled[nums].dac) 3304468c5458SDavid Henningsson continue; 3305468c5458SDavid Henningsson if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) { 3306468c5458SDavid Henningsson filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG; 3307468c5458SDavid Henningsson continue; 3308468c5458SDavid Henningsson } 3309468c5458SDavid Henningsson if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) { 33101f015f5fSTakashi Iwai filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG; 3311468c5458SDavid Henningsson continue; 3312468c5458SDavid Henningsson } 3313468c5458SDavid Henningsson snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]); 3314f2e5731dSTakashi Iwai } 3315f2e5731dSTakashi Iwai return nums; 3316f2e5731dSTakashi Iwai } 3317f2e5731dSTakashi Iwai 3318f2e5731dSTakashi Iwai /* parse analog output paths */ 3319f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec) 3320f2e5731dSTakashi Iwai { 3321f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3322f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3323f2e5731dSTakashi Iwai hda_nid_t dacs[MAX_AUTO_DACS]; 3324f2e5731dSTakashi Iwai int i, j, nums, rest; 3325f2e5731dSTakashi Iwai 3326f2e5731dSTakashi Iwai rest = fill_cx_auto_dacs(codec, dacs); 3327f2e5731dSTakashi Iwai /* parse all analog output pins */ 3328f2e5731dSTakashi Iwai nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3329468c5458SDavid Henningsson dacs, &rest, spec->dac_info, 0, 3330f2e5731dSTakashi Iwai AUTO_PIN_LINE_OUT); 3331468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3332468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3333f2e5731dSTakashi Iwai AUTO_PIN_HP_OUT); 3334468c5458SDavid Henningsson nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3335468c5458SDavid Henningsson dacs, &rest, spec->dac_info, nums, 3336f2e5731dSTakashi Iwai AUTO_PIN_SPEAKER_OUT); 3337f2e5731dSTakashi Iwai spec->dac_info_filled = nums; 3338f2e5731dSTakashi Iwai /* fill multiout struct */ 3339f2e5731dSTakashi Iwai for (i = 0; i < nums; i++) { 3340f2e5731dSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 33411f015f5fSTakashi Iwai if (!dac || (dac & DAC_SLAVE_FLAG)) 3342f2e5731dSTakashi Iwai continue; 3343f2e5731dSTakashi Iwai switch (spec->dac_info[i].type) { 3344f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 3345f2e5731dSTakashi Iwai spec->private_dac_nids[spec->multiout.num_dacs] = dac; 3346f2e5731dSTakashi Iwai spec->multiout.num_dacs++; 3347f2e5731dSTakashi Iwai break; 3348f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 3349f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 3350f2e5731dSTakashi Iwai if (!spec->multiout.hp_nid) { 3351f2e5731dSTakashi Iwai spec->multiout.hp_nid = dac; 3352f2e5731dSTakashi Iwai break; 3353f2e5731dSTakashi Iwai } 3354f2e5731dSTakashi Iwai for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++) 3355f2e5731dSTakashi Iwai if (!spec->multiout.extra_out_nid[j]) { 3356f2e5731dSTakashi Iwai spec->multiout.extra_out_nid[j] = dac; 3357f2e5731dSTakashi Iwai break; 3358f2e5731dSTakashi Iwai } 3359f2e5731dSTakashi Iwai break; 3360f2e5731dSTakashi Iwai } 3361f2e5731dSTakashi Iwai } 3362f2e5731dSTakashi Iwai spec->multiout.dac_nids = spec->private_dac_nids; 336389724958SDavid Henningsson spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3364f2e5731dSTakashi Iwai 336503697e2aSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) { 336603697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->hp_pins[i])) { 3367f2e5731dSTakashi Iwai spec->auto_mute = 1; 336803697e2aSTakashi Iwai break; 336903697e2aSTakashi Iwai } 337003697e2aSTakashi Iwai } 3371e2df82ffSTakashi Iwai if (spec->auto_mute && 3372e2df82ffSTakashi Iwai cfg->line_out_pins[0] && 3373e2df82ffSTakashi Iwai cfg->line_out_type != AUTO_PIN_SPEAKER_OUT && 337403697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->hp_pins[0] && 337503697e2aSTakashi Iwai cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 337603697e2aSTakashi Iwai for (i = 0; i < cfg->line_outs; i++) { 337703697e2aSTakashi Iwai if (is_jack_detectable(codec, cfg->line_out_pins[i])) { 337803697e2aSTakashi Iwai spec->detect_line = 1; 337903697e2aSTakashi Iwai break; 338003697e2aSTakashi Iwai } 338103697e2aSTakashi Iwai } 338203697e2aSTakashi Iwai spec->automute_lines = spec->detect_line; 338303697e2aSTakashi Iwai } 338403697e2aSTakashi Iwai 3385f2e5731dSTakashi Iwai spec->vmaster_nid = spec->private_dac_nids[0]; 3386f2e5731dSTakashi Iwai } 3387f2e5731dSTakashi Iwai 3388da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3389da339866STakashi Iwai hda_nid_t *pins, bool on); 3390da339866STakashi Iwai 339103697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins, 339203697e2aSTakashi Iwai hda_nid_t *pins, bool on) 339303697e2aSTakashi Iwai { 3394254f2968STakashi Iwai struct conexant_spec *spec = codec->spec; 339503697e2aSTakashi Iwai int i; 339603697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 339703697e2aSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 339803697e2aSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, 339903697e2aSTakashi Iwai on ? PIN_OUT : 0); 3400254f2968STakashi Iwai if (spec->pin_eapd_ctrls) 340103697e2aSTakashi Iwai cx_auto_turn_eapd(codec, num_pins, pins, on); 340203697e2aSTakashi Iwai } 340303697e2aSTakashi Iwai 340403697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 340503697e2aSTakashi Iwai { 340603697e2aSTakashi Iwai int i, present = 0; 340703697e2aSTakashi Iwai 340803697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) { 340903697e2aSTakashi Iwai hda_nid_t nid = pins[i]; 341003697e2aSTakashi Iwai if (!nid || !is_jack_detectable(codec, nid)) 341103697e2aSTakashi Iwai break; 341203697e2aSTakashi Iwai present |= snd_hda_jack_detect(codec, nid); 341303697e2aSTakashi Iwai } 341403697e2aSTakashi Iwai return present; 341503697e2aSTakashi Iwai } 341603697e2aSTakashi Iwai 3417f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */ 341803697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec) 341903697e2aSTakashi Iwai { 342003697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 342103697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3422e2df82ffSTakashi Iwai int on = 1; 342303697e2aSTakashi Iwai 3424e2df82ffSTakashi Iwai /* turn on HP EAPD when HP jacks are present */ 3425254f2968STakashi Iwai if (spec->pin_eapd_ctrls) { 3426e2df82ffSTakashi Iwai if (spec->auto_mute) 3427e2df82ffSTakashi Iwai on = spec->hp_present; 342803697e2aSTakashi Iwai cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3429254f2968STakashi Iwai } 3430254f2968STakashi Iwai 3431e2df82ffSTakashi Iwai /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3432e2df82ffSTakashi Iwai if (spec->auto_mute) 3433e2df82ffSTakashi Iwai on = !(spec->hp_present || 3434e2df82ffSTakashi Iwai (spec->detect_line && spec->line_present)); 3435e2df82ffSTakashi Iwai do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on); 343603697e2aSTakashi Iwai 343703697e2aSTakashi Iwai /* toggle line-out mutes if needed, too */ 343803697e2aSTakashi Iwai /* if LO is a copy of either HP or Speaker, don't need to handle it */ 343903697e2aSTakashi Iwai if (cfg->line_out_pins[0] == cfg->hp_pins[0] || 344003697e2aSTakashi Iwai cfg->line_out_pins[0] == cfg->speaker_pins[0]) 344103697e2aSTakashi Iwai return; 3442e2df82ffSTakashi Iwai if (spec->auto_mute) { 3443e2df82ffSTakashi Iwai /* mute LO in auto-mode when HP jack is present */ 3444e2df82ffSTakashi Iwai if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT || 3445e2df82ffSTakashi Iwai spec->automute_lines) 3446e2df82ffSTakashi Iwai on = !spec->hp_present; 344703697e2aSTakashi Iwai else 3448e2df82ffSTakashi Iwai on = 1; 3449e2df82ffSTakashi Iwai } 3450e2df82ffSTakashi Iwai do_automute(codec, cfg->line_outs, cfg->line_out_pins, on); 345103697e2aSTakashi Iwai } 345203697e2aSTakashi Iwai 3453f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec) 3454f2e5731dSTakashi Iwai { 3455f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3456f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3457f2e5731dSTakashi Iwai 3458f2e5731dSTakashi Iwai if (!spec->auto_mute) 3459f2e5731dSTakashi Iwai return; 346003697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins); 346103697e2aSTakashi Iwai cx_auto_update_speakers(codec); 346203697e2aSTakashi Iwai } 346303697e2aSTakashi Iwai 346403697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec) 346503697e2aSTakashi Iwai { 346603697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 346703697e2aSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 346803697e2aSTakashi Iwai 346903697e2aSTakashi Iwai if (!spec->auto_mute || !spec->detect_line) 347003697e2aSTakashi Iwai return; 347103697e2aSTakashi Iwai spec->line_present = detect_jacks(codec, cfg->line_outs, 347203697e2aSTakashi Iwai cfg->line_out_pins); 347303697e2aSTakashi Iwai cx_auto_update_speakers(codec); 347403697e2aSTakashi Iwai } 347503697e2aSTakashi Iwai 347603697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol, 347703697e2aSTakashi Iwai struct snd_ctl_elem_info *uinfo) 347803697e2aSTakashi Iwai { 347903697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 348003697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 348103697e2aSTakashi Iwai static const char * const texts2[] = { 348203697e2aSTakashi Iwai "Disabled", "Enabled" 348303697e2aSTakashi Iwai }; 348403697e2aSTakashi Iwai static const char * const texts3[] = { 348503697e2aSTakashi Iwai "Disabled", "Speaker Only", "Line-Out+Speaker" 348603697e2aSTakashi Iwai }; 348703697e2aSTakashi Iwai const char * const *texts; 348803697e2aSTakashi Iwai 348903697e2aSTakashi Iwai uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 349003697e2aSTakashi Iwai uinfo->count = 1; 349103697e2aSTakashi Iwai if (spec->automute_hp_lo) { 349203697e2aSTakashi Iwai uinfo->value.enumerated.items = 3; 349303697e2aSTakashi Iwai texts = texts3; 349403697e2aSTakashi Iwai } else { 349503697e2aSTakashi Iwai uinfo->value.enumerated.items = 2; 349603697e2aSTakashi Iwai texts = texts2; 349703697e2aSTakashi Iwai } 349803697e2aSTakashi Iwai if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 349903697e2aSTakashi Iwai uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 350003697e2aSTakashi Iwai strcpy(uinfo->value.enumerated.name, 350103697e2aSTakashi Iwai texts[uinfo->value.enumerated.item]); 350203697e2aSTakashi Iwai return 0; 350303697e2aSTakashi Iwai } 350403697e2aSTakashi Iwai 350503697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol, 350603697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 350703697e2aSTakashi Iwai { 350803697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 350903697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 351003697e2aSTakashi Iwai unsigned int val; 351103697e2aSTakashi Iwai if (!spec->auto_mute) 351203697e2aSTakashi Iwai val = 0; 351303697e2aSTakashi Iwai else if (!spec->automute_lines) 351403697e2aSTakashi Iwai val = 1; 351503697e2aSTakashi Iwai else 351603697e2aSTakashi Iwai val = 2; 351703697e2aSTakashi Iwai ucontrol->value.enumerated.item[0] = val; 351803697e2aSTakashi Iwai return 0; 351903697e2aSTakashi Iwai } 352003697e2aSTakashi Iwai 352103697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol, 352203697e2aSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 352303697e2aSTakashi Iwai { 352403697e2aSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 352503697e2aSTakashi Iwai struct conexant_spec *spec = codec->spec; 352603697e2aSTakashi Iwai 352703697e2aSTakashi Iwai switch (ucontrol->value.enumerated.item[0]) { 352803697e2aSTakashi Iwai case 0: 352903697e2aSTakashi Iwai if (!spec->auto_mute) 353003697e2aSTakashi Iwai return 0; 353103697e2aSTakashi Iwai spec->auto_mute = 0; 3532f2e5731dSTakashi Iwai break; 353303697e2aSTakashi Iwai case 1: 353403697e2aSTakashi Iwai if (spec->auto_mute && !spec->automute_lines) 353503697e2aSTakashi Iwai return 0; 353603697e2aSTakashi Iwai spec->auto_mute = 1; 353703697e2aSTakashi Iwai spec->automute_lines = 0; 353803697e2aSTakashi Iwai break; 353903697e2aSTakashi Iwai case 2: 354003697e2aSTakashi Iwai if (!spec->automute_hp_lo) 354103697e2aSTakashi Iwai return -EINVAL; 354203697e2aSTakashi Iwai if (spec->auto_mute && spec->automute_lines) 354303697e2aSTakashi Iwai return 0; 354403697e2aSTakashi Iwai spec->auto_mute = 1; 354503697e2aSTakashi Iwai spec->automute_lines = 1; 354603697e2aSTakashi Iwai break; 354703697e2aSTakashi Iwai default: 354803697e2aSTakashi Iwai return -EINVAL; 3549f2e5731dSTakashi Iwai } 355003697e2aSTakashi Iwai cx_auto_update_speakers(codec); 355103697e2aSTakashi Iwai return 1; 3552f2e5731dSTakashi Iwai } 355303697e2aSTakashi Iwai 355403697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = { 355503697e2aSTakashi Iwai { 355603697e2aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 355703697e2aSTakashi Iwai .name = "Auto-Mute Mode", 355803697e2aSTakashi Iwai .info = cx_automute_mode_info, 355903697e2aSTakashi Iwai .get = cx_automute_mode_get, 356003697e2aSTakashi Iwai .put = cx_automute_mode_put, 356103697e2aSTakashi Iwai }, 356203697e2aSTakashi Iwai { } 356303697e2aSTakashi Iwai }; 3564f2e5731dSTakashi Iwai 35656764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol, 35666764bcefSTakashi Iwai struct snd_ctl_elem_info *uinfo) 35676764bcefSTakashi Iwai { 35686764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35696764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35706764bcefSTakashi Iwai 35716764bcefSTakashi Iwai return snd_hda_input_mux_info(&spec->private_imux, uinfo); 35726764bcefSTakashi Iwai } 35736764bcefSTakashi Iwai 35746764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol, 35756764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 35766764bcefSTakashi Iwai { 35776764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 35786764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 35796764bcefSTakashi Iwai 35806764bcefSTakashi Iwai ucontrol->value.enumerated.item[0] = spec->cur_mux[0]; 35816764bcefSTakashi Iwai return 0; 35826764bcefSTakashi Iwai } 35836764bcefSTakashi Iwai 35845c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index; 35855c9887e0STakashi Iwai * if do_select is set, actually select the route. 35865c9887e0STakashi Iwai */ 35875c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux, 3588cf27f29aSTakashi Iwai hda_nid_t pin, hda_nid_t *srcp, 3589cf27f29aSTakashi Iwai bool do_select, int depth) 35905c9887e0STakashi Iwai { 35915c9887e0STakashi Iwai hda_nid_t conn[HDA_MAX_NUM_INPUTS]; 35925c9887e0STakashi Iwai int i, nums; 35935c9887e0STakashi Iwai 3594cf27f29aSTakashi Iwai switch (get_wcaps_type(get_wcaps(codec, mux))) { 3595cf27f29aSTakashi Iwai case AC_WID_AUD_IN: 3596cf27f29aSTakashi Iwai case AC_WID_AUD_SEL: 3597cf27f29aSTakashi Iwai case AC_WID_AUD_MIX: 3598cf27f29aSTakashi Iwai break; 3599cf27f29aSTakashi Iwai default: 3600cf27f29aSTakashi Iwai return -1; 3601cf27f29aSTakashi Iwai } 3602cf27f29aSTakashi Iwai 36035c9887e0STakashi Iwai nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); 36045c9887e0STakashi Iwai for (i = 0; i < nums; i++) 36055c9887e0STakashi Iwai if (conn[i] == pin) { 36065c9887e0STakashi Iwai if (do_select) 36075c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36085c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3609cf27f29aSTakashi Iwai if (srcp) 3610cf27f29aSTakashi Iwai *srcp = mux; 36115c9887e0STakashi Iwai return i; 36125c9887e0STakashi Iwai } 36135c9887e0STakashi Iwai depth++; 36145c9887e0STakashi Iwai if (depth == 2) 36155c9887e0STakashi Iwai return -1; 36165c9887e0STakashi Iwai for (i = 0; i < nums; i++) { 3617cf27f29aSTakashi Iwai int ret = __select_input_connection(codec, conn[i], pin, srcp, 36185c9887e0STakashi Iwai do_select, depth); 36195c9887e0STakashi Iwai if (ret >= 0) { 36205c9887e0STakashi Iwai if (do_select) 36215c9887e0STakashi Iwai snd_hda_codec_write(codec, mux, 0, 36225c9887e0STakashi Iwai AC_VERB_SET_CONNECT_SEL, i); 3623cf27f29aSTakashi Iwai return i; 36245c9887e0STakashi Iwai } 36255c9887e0STakashi Iwai } 36265c9887e0STakashi Iwai return -1; 36275c9887e0STakashi Iwai } 36285c9887e0STakashi Iwai 36295c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux, 36305c9887e0STakashi Iwai hda_nid_t pin) 36315c9887e0STakashi Iwai { 3632cf27f29aSTakashi Iwai __select_input_connection(codec, mux, pin, NULL, true, 0); 36335c9887e0STakashi Iwai } 36345c9887e0STakashi Iwai 36355c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux, 36365c9887e0STakashi Iwai hda_nid_t pin) 36375c9887e0STakashi Iwai { 3638cf27f29aSTakashi Iwai return __select_input_connection(codec, mux, pin, NULL, false, 0); 36395c9887e0STakashi Iwai } 36405c9887e0STakashi Iwai 36416764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec, 36426764bcefSTakashi Iwai const struct hda_input_mux *imux, 36436764bcefSTakashi Iwai unsigned int idx) 36446764bcefSTakashi Iwai { 36456764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36466764bcefSTakashi Iwai hda_nid_t adc; 3647313d2c06STakashi Iwai int changed = 1; 36486764bcefSTakashi Iwai 36496764bcefSTakashi Iwai if (!imux->num_items) 36506764bcefSTakashi Iwai return 0; 36516764bcefSTakashi Iwai if (idx >= imux->num_items) 36526764bcefSTakashi Iwai idx = imux->num_items - 1; 36536764bcefSTakashi Iwai if (spec->cur_mux[0] == idx) 3654313d2c06STakashi Iwai changed = 0; 365547ad1f4eSTakashi Iwai adc = spec->imux_info[idx].adc; 365647ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[idx].adc, 365747ad1f4eSTakashi Iwai spec->imux_info[idx].pin); 36586764bcefSTakashi Iwai if (spec->cur_adc && spec->cur_adc != adc) { 36596764bcefSTakashi Iwai /* stream is running, let's swap the current ADC */ 36606764bcefSTakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 36616764bcefSTakashi Iwai spec->cur_adc = adc; 36626764bcefSTakashi Iwai snd_hda_codec_setup_stream(codec, adc, 36636764bcefSTakashi Iwai spec->cur_adc_stream_tag, 0, 36646764bcefSTakashi Iwai spec->cur_adc_format); 36656764bcefSTakashi Iwai } 36666764bcefSTakashi Iwai spec->cur_mux[0] = idx; 3667313d2c06STakashi Iwai return changed; 36686764bcefSTakashi Iwai } 36696764bcefSTakashi Iwai 36706764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol, 36716764bcefSTakashi Iwai struct snd_ctl_elem_value *ucontrol) 36726764bcefSTakashi Iwai { 36736764bcefSTakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 36746764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 36756764bcefSTakashi Iwai 36766764bcefSTakashi Iwai return cx_auto_mux_enum_update(codec, &spec->private_imux, 36776764bcefSTakashi Iwai ucontrol->value.enumerated.item[0]); 36786764bcefSTakashi Iwai } 36796764bcefSTakashi Iwai 36806764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = { 36816764bcefSTakashi Iwai { 36826764bcefSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 36836764bcefSTakashi Iwai .name = "Capture Source", 36846764bcefSTakashi Iwai .info = cx_auto_mux_enum_info, 36856764bcefSTakashi Iwai .get = cx_auto_mux_enum_get, 36866764bcefSTakashi Iwai .put = cx_auto_mux_enum_put 36876764bcefSTakashi Iwai }, 36886764bcefSTakashi Iwai {} 36896764bcefSTakashi Iwai }; 36906764bcefSTakashi Iwai 369143c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect) 369243c1b2e9STakashi Iwai { 369343c1b2e9STakashi Iwai struct conexant_spec *spec = codec->spec; 369443c1b2e9STakashi Iwai if (idx < 0) 369543c1b2e9STakashi Iwai return false; 369643c1b2e9STakashi Iwai if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin)) 369743c1b2e9STakashi Iwai return false; 369843c1b2e9STakashi Iwai cx_auto_mux_enum_update(codec, &spec->private_imux, idx); 369943c1b2e9STakashi Iwai return true; 370043c1b2e9STakashi Iwai } 370143c1b2e9STakashi Iwai 3702f2e5731dSTakashi Iwai /* automatic switch internal and external mic */ 3703f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec) 3704f2e5731dSTakashi Iwai { 3705f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3706f2e5731dSTakashi Iwai 3707f2e5731dSTakashi Iwai if (!spec->auto_mic) 3708f2e5731dSTakashi Iwai return; 370943c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_ext, true)) 371043c1b2e9STakashi Iwai if (!select_automic(codec, spec->auto_mic_dock, true)) 371143c1b2e9STakashi Iwai select_automic(codec, spec->auto_mic_int, false); 3712f2e5731dSTakashi Iwai } 3713f2e5731dSTakashi Iwai 3714f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3715f2e5731dSTakashi Iwai { 37163a93897eSTakashi Iwai switch (snd_hda_jack_get_action(codec, res >> 26)) { 3717f2e5731dSTakashi Iwai case CONEXANT_HP_EVENT: 3718f2e5731dSTakashi Iwai cx_auto_hp_automute(codec); 371903697e2aSTakashi Iwai break; 372003697e2aSTakashi Iwai case CONEXANT_LINE_EVENT: 372103697e2aSTakashi Iwai cx_auto_line_automute(codec); 3722f2e5731dSTakashi Iwai break; 3723f2e5731dSTakashi Iwai case CONEXANT_MIC_EVENT: 3724f2e5731dSTakashi Iwai cx_auto_automic(codec); 3725f2e5731dSTakashi Iwai break; 3726f2e5731dSTakashi Iwai } 372701a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 3728f2e5731dSTakashi Iwai } 3729f2e5731dSTakashi Iwai 3730f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching; 373143c1b2e9STakashi Iwai * auto-mic is enabled only when one int-mic and one ext- and/or 373243c1b2e9STakashi Iwai * one dock-mic exist 3733f2e5731dSTakashi Iwai */ 3734f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec) 3735f2e5731dSTakashi Iwai { 3736f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 373743c1b2e9STakashi Iwai int pset[INPUT_PIN_ATTR_NORMAL + 1]; 373843c1b2e9STakashi Iwai int i; 3739f2e5731dSTakashi Iwai 3740506a4196STakashi Iwai for (i = 0; i < ARRAY_SIZE(pset); i++) 374143c1b2e9STakashi Iwai pset[i] = -1; 374243c1b2e9STakashi Iwai for (i = 0; i < spec->private_imux.num_items; i++) { 374343c1b2e9STakashi Iwai hda_nid_t pin = spec->imux_info[i].pin; 374443c1b2e9STakashi Iwai unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3745b55fcb50STakashi Iwai int type, attr; 374643c1b2e9STakashi Iwai attr = snd_hda_get_input_pin_attr(def_conf); 374743c1b2e9STakashi Iwai if (attr == INPUT_PIN_ATTR_UNUSED) 3748b55fcb50STakashi Iwai return; /* invalid entry */ 374943c1b2e9STakashi Iwai if (attr > INPUT_PIN_ATTR_NORMAL) 375043c1b2e9STakashi Iwai attr = INPUT_PIN_ATTR_NORMAL; 375143c1b2e9STakashi Iwai if (attr != INPUT_PIN_ATTR_INT && 375243c1b2e9STakashi Iwai !is_jack_detectable(codec, pin)) 3753b55fcb50STakashi Iwai return; /* non-detectable pin */ 3754b55fcb50STakashi Iwai type = get_defcfg_device(def_conf); 3755b55fcb50STakashi Iwai if (type != AC_JACK_MIC_IN && 3756b55fcb50STakashi Iwai (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN)) 3757b55fcb50STakashi Iwai return; /* no valid input type */ 375843c1b2e9STakashi Iwai if (pset[attr] >= 0) 375943c1b2e9STakashi Iwai return; /* already occupied */ 376043c1b2e9STakashi Iwai pset[attr] = i; 3761f2e5731dSTakashi Iwai } 376243c1b2e9STakashi Iwai if (pset[INPUT_PIN_ATTR_INT] < 0 || 376343c1b2e9STakashi Iwai (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK])) 376443c1b2e9STakashi Iwai return; /* no input to switch*/ 3765f2e5731dSTakashi Iwai spec->auto_mic = 1; 376643c1b2e9STakashi Iwai spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL]; 376743c1b2e9STakashi Iwai spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK]; 376843c1b2e9STakashi Iwai spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT]; 3769f2e5731dSTakashi Iwai } 3770f2e5731dSTakashi Iwai 3771f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec) 3772f2e5731dSTakashi Iwai { 3773f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3774f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3775f2e5731dSTakashi Iwai struct hda_input_mux *imux; 37766764bcefSTakashi Iwai int i, j; 3777f2e5731dSTakashi Iwai 3778f2e5731dSTakashi Iwai imux = &spec->private_imux; 3779f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 37806764bcefSTakashi Iwai for (j = 0; j < spec->num_adc_nids; j++) { 37816764bcefSTakashi Iwai hda_nid_t adc = spec->adc_nids[j]; 37825c9887e0STakashi Iwai int idx = get_input_connection(codec, adc, 3783f2e5731dSTakashi Iwai cfg->inputs[i].pin); 3784f2e5731dSTakashi Iwai if (idx >= 0) { 3785f2e5731dSTakashi Iwai const char *label; 3786f2e5731dSTakashi Iwai label = hda_get_autocfg_input_label(codec, cfg, i); 378747ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].index = i; 378847ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].boost = 0; 378947ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].adc = adc; 379047ad1f4eSTakashi Iwai spec->imux_info[imux->num_items].pin = 3791f6100bb4STakashi Iwai cfg->inputs[i].pin; 3792f2e5731dSTakashi Iwai snd_hda_add_imux_item(imux, label, idx, NULL); 37936764bcefSTakashi Iwai break; 37946764bcefSTakashi Iwai } 3795f2e5731dSTakashi Iwai } 3796f2e5731dSTakashi Iwai } 379743c1b2e9STakashi Iwai if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3798f2e5731dSTakashi Iwai cx_auto_check_auto_mic(codec); 379976755359STakashi Iwai if (imux->num_items > 1) { 38006764bcefSTakashi Iwai for (i = 1; i < imux->num_items; i++) { 380147ad1f4eSTakashi Iwai if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 38026764bcefSTakashi Iwai spec->adc_switching = 1; 38036764bcefSTakashi Iwai break; 38046764bcefSTakashi Iwai } 38056764bcefSTakashi Iwai } 38066764bcefSTakashi Iwai } 3807f2e5731dSTakashi Iwai } 3808f2e5731dSTakashi Iwai 3809f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */ 3810f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin) 3811f2e5731dSTakashi Iwai { 3812f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3813f2e5731dSTakashi Iwai 3814f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3815f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 3816f2e5731dSTakashi Iwai unsigned int wcaps = get_wcaps(codec, nid); 3817f2e5731dSTakashi Iwai unsigned int type = get_wcaps_type(wcaps); 3818f2e5731dSTakashi Iwai if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) { 3819f2e5731dSTakashi Iwai if (get_connection_index(codec, nid, pin) >= 0) 3820f2e5731dSTakashi Iwai return nid; 3821f2e5731dSTakashi Iwai } 3822f2e5731dSTakashi Iwai } 3823f2e5731dSTakashi Iwai return 0; 3824f2e5731dSTakashi Iwai } 3825f2e5731dSTakashi Iwai 3826f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec) 3827f2e5731dSTakashi Iwai { 3828f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3829f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 3830f2e5731dSTakashi Iwai hda_nid_t nid; 3831f2e5731dSTakashi Iwai 3832f2e5731dSTakashi Iwai if (cfg->dig_outs && 3833f2e5731dSTakashi Iwai snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1) 3834f2e5731dSTakashi Iwai spec->multiout.dig_out_nid = nid; 3835f2e5731dSTakashi Iwai if (cfg->dig_in_pin) 3836f2e5731dSTakashi Iwai spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin); 3837f2e5731dSTakashi Iwai } 3838f2e5731dSTakashi Iwai 3839f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 3840f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec) 3841f2e5731dSTakashi Iwai { 3842f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3843f2e5731dSTakashi Iwai hda_nid_t nid, end_nid; 3844f2e5731dSTakashi Iwai 3845f2e5731dSTakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 3846f2e5731dSTakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) 3847f2e5731dSTakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) { 3848f2e5731dSTakashi Iwai set_beep_amp(spec, nid, 0, HDA_OUTPUT); 3849f2e5731dSTakashi Iwai break; 3850f2e5731dSTakashi Iwai } 3851f2e5731dSTakashi Iwai } 3852f2e5731dSTakashi Iwai #else 3853f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec) 3854f2e5731dSTakashi Iwai #endif 3855f2e5731dSTakashi Iwai 3856254f2968STakashi Iwai /* parse EAPDs */ 385719110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec) 385819110595STakashi Iwai { 385919110595STakashi Iwai struct conexant_spec *spec = codec->spec; 386019110595STakashi Iwai hda_nid_t nid, end_nid; 386119110595STakashi Iwai 386219110595STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 386319110595STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 386419110595STakashi Iwai if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 386519110595STakashi Iwai continue; 386619110595STakashi Iwai if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 386719110595STakashi Iwai continue; 386819110595STakashi Iwai spec->eapds[spec->num_eapds++] = nid; 386919110595STakashi Iwai if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 387019110595STakashi Iwai break; 387119110595STakashi Iwai } 3872254f2968STakashi Iwai 3873254f2968STakashi Iwai /* NOTE: below is a wild guess; if we have more than two EAPDs, 3874254f2968STakashi Iwai * it's a new chip, where EAPDs are supposed to be associated to 3875254f2968STakashi Iwai * pins, and we can control EAPD per pin. 3876254f2968STakashi Iwai * OTOH, if only one or two EAPDs are found, it's an old chip, 3877254f2968STakashi Iwai * thus it might control over all pins. 3878254f2968STakashi Iwai */ 3879254f2968STakashi Iwai spec->pin_eapd_ctrls = spec->num_eapds > 2; 388019110595STakashi Iwai } 388119110595STakashi Iwai 3882f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec) 3883f2e5731dSTakashi Iwai { 3884f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3885f2e5731dSTakashi Iwai int err; 3886f2e5731dSTakashi Iwai 3887f2e5731dSTakashi Iwai err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); 3888f2e5731dSTakashi Iwai if (err < 0) 3889f2e5731dSTakashi Iwai return err; 3890f2e5731dSTakashi Iwai 3891f2e5731dSTakashi Iwai cx_auto_parse_output(codec); 3892f2e5731dSTakashi Iwai cx_auto_parse_input(codec); 3893f2e5731dSTakashi Iwai cx_auto_parse_digital(codec); 3894f2e5731dSTakashi Iwai cx_auto_parse_beep(codec); 389519110595STakashi Iwai cx_auto_parse_eapd(codec); 3896f2e5731dSTakashi Iwai return 0; 3897f2e5731dSTakashi Iwai } 3898f2e5731dSTakashi Iwai 3899da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins, 3900da339866STakashi Iwai hda_nid_t *pins, bool on) 3901f2e5731dSTakashi Iwai { 3902f2e5731dSTakashi Iwai int i; 3903f2e5731dSTakashi Iwai for (i = 0; i < num_pins; i++) { 3904f2e5731dSTakashi Iwai if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD) 3905f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pins[i], 0, 3906da339866STakashi Iwai AC_VERB_SET_EAPD_BTLENABLE, 3907da339866STakashi Iwai on ? 0x02 : 0); 3908f2e5731dSTakashi Iwai } 3909f2e5731dSTakashi Iwai } 3910f2e5731dSTakashi Iwai 3911f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin, 3912f2e5731dSTakashi Iwai hda_nid_t src) 3913f2e5731dSTakashi Iwai { 3914f2e5731dSTakashi Iwai int idx = get_connection_index(codec, pin, src); 3915f2e5731dSTakashi Iwai if (idx >= 0) 3916f2e5731dSTakashi Iwai snd_hda_codec_write(codec, pin, 0, 3917f2e5731dSTakashi Iwai AC_VERB_SET_CONNECT_SEL, idx); 3918f2e5731dSTakashi Iwai } 3919f2e5731dSTakashi Iwai 39201f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids, 39211f8458a2STakashi Iwai const hda_nid_t *nids) 3922f2e5731dSTakashi Iwai { 39230ad1b5b6STakashi Iwai int i, val; 3924f2e5731dSTakashi Iwai 39251f8458a2STakashi Iwai for (i = 0; i < num_nids; i++) { 39261f8458a2STakashi Iwai hda_nid_t nid = nids[i]; 39271f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)) 39281f8458a2STakashi Iwai continue; 39290ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE) 39300ad1b5b6STakashi Iwai val = AMP_OUT_MUTE; 39310ad1b5b6STakashi Iwai else 39320ad1b5b6STakashi Iwai val = AMP_OUT_ZERO; 39330ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, 39340ad1b5b6STakashi Iwai AC_VERB_SET_AMP_GAIN_MUTE, val); 39350ad1b5b6STakashi Iwai } 39361f8458a2STakashi Iwai } 3937f2e5731dSTakashi Iwai 393803697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 39393a93897eSTakashi Iwai hda_nid_t *pins, unsigned int action) 394003697e2aSTakashi Iwai { 394103697e2aSTakashi Iwai int i; 394203697e2aSTakashi Iwai for (i = 0; i < num_pins; i++) 39433a93897eSTakashi Iwai snd_hda_jack_detect_enable(codec, pins[i], action); 394403697e2aSTakashi Iwai } 394503697e2aSTakashi Iwai 39461f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec) 39471f8458a2STakashi Iwai { 39481f8458a2STakashi Iwai struct conexant_spec *spec = codec->spec; 39491f8458a2STakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39501f8458a2STakashi Iwai hda_nid_t nid; 39511f8458a2STakashi Iwai int i; 39521f8458a2STakashi Iwai 39531f8458a2STakashi Iwai mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids); 3954f2e5731dSTakashi Iwai for (i = 0; i < cfg->hp_outs; i++) 3955f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->hp_pins[i], 0, 3956f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP); 39571f8458a2STakashi Iwai mute_outputs(codec, cfg->hp_outs, cfg->hp_pins); 39581f8458a2STakashi Iwai mute_outputs(codec, cfg->line_outs, cfg->line_out_pins); 39591f8458a2STakashi Iwai mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins); 3960f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 3961f2e5731dSTakashi Iwai nid = spec->dac_info[i].dac; 3962f2e5731dSTakashi Iwai if (!nid) 3963f2e5731dSTakashi Iwai nid = spec->multiout.dac_nids[0]; 39641f015f5fSTakashi Iwai else if (nid & DAC_SLAVE_FLAG) 39651f015f5fSTakashi Iwai nid &= ~DAC_SLAVE_FLAG; 3966f2e5731dSTakashi Iwai select_connection(codec, spec->dac_info[i].pin, nid); 3967f2e5731dSTakashi Iwai } 396803697e2aSTakashi Iwai if (spec->auto_mute) { 396903697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins, 397003697e2aSTakashi Iwai CONEXANT_HP_EVENT); 397103697e2aSTakashi Iwai spec->hp_present = detect_jacks(codec, cfg->hp_outs, 397203697e2aSTakashi Iwai cfg->hp_pins); 397303697e2aSTakashi Iwai if (spec->detect_line) { 397403697e2aSTakashi Iwai enable_unsol_pins(codec, cfg->line_outs, 397503697e2aSTakashi Iwai cfg->line_out_pins, 397603697e2aSTakashi Iwai CONEXANT_LINE_EVENT); 397703697e2aSTakashi Iwai spec->line_present = 397803697e2aSTakashi Iwai detect_jacks(codec, cfg->line_outs, 397903697e2aSTakashi Iwai cfg->line_out_pins); 398003697e2aSTakashi Iwai } 398103697e2aSTakashi Iwai } 398203697e2aSTakashi Iwai cx_auto_update_speakers(codec); 3983254f2968STakashi Iwai /* turn on all EAPDs if no individual EAPD control is available */ 3984254f2968STakashi Iwai if (!spec->pin_eapd_ctrls) 398519110595STakashi Iwai cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 3986f2e5731dSTakashi Iwai } 3987f2e5731dSTakashi Iwai 3988f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec) 3989f2e5731dSTakashi Iwai { 3990f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 3991f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 39920ad1b5b6STakashi Iwai int i, val; 3993f2e5731dSTakashi Iwai 39940ad1b5b6STakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 39950ad1b5b6STakashi Iwai hda_nid_t nid = spec->adc_nids[i]; 39961f8458a2STakashi Iwai if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) 39971f8458a2STakashi Iwai continue; 39980ad1b5b6STakashi Iwai if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE) 39990ad1b5b6STakashi Iwai val = AMP_IN_MUTE(0); 40000ad1b5b6STakashi Iwai else 40010ad1b5b6STakashi Iwai val = AMP_IN_UNMUTE(0); 40020ad1b5b6STakashi Iwai snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 40030ad1b5b6STakashi Iwai val); 40040ad1b5b6STakashi Iwai } 4005f2e5731dSTakashi Iwai 4006f2e5731dSTakashi Iwai for (i = 0; i < cfg->num_inputs; i++) { 4007f2e5731dSTakashi Iwai unsigned int type; 4008f2e5731dSTakashi Iwai if (cfg->inputs[i].type == AUTO_PIN_MIC) 4009f2e5731dSTakashi Iwai type = PIN_VREF80; 4010f2e5731dSTakashi Iwai else 4011f2e5731dSTakashi Iwai type = PIN_IN; 4012f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 4013f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, type); 4014f2e5731dSTakashi Iwai } 4015f2e5731dSTakashi Iwai 4016f2e5731dSTakashi Iwai if (spec->auto_mic) { 401743c1b2e9STakashi Iwai if (spec->auto_mic_ext >= 0) { 40181835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40191835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_ext].pin, 40201835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 402143c1b2e9STakashi Iwai } 402243c1b2e9STakashi Iwai if (spec->auto_mic_dock >= 0) { 40231835a0f9STakashi Iwai snd_hda_jack_detect_enable(codec, 40241835a0f9STakashi Iwai cfg->inputs[spec->auto_mic_dock].pin, 40251835a0f9STakashi Iwai CONEXANT_MIC_EVENT); 402643c1b2e9STakashi Iwai } 4027f2e5731dSTakashi Iwai cx_auto_automic(codec); 4028f2e5731dSTakashi Iwai } else { 402947ad1f4eSTakashi Iwai select_input_connection(codec, spec->imux_info[0].adc, 403047ad1f4eSTakashi Iwai spec->imux_info[0].pin); 4031f2e5731dSTakashi Iwai } 4032f2e5731dSTakashi Iwai } 4033f2e5731dSTakashi Iwai 4034f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec) 4035f2e5731dSTakashi Iwai { 4036f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4037f2e5731dSTakashi Iwai struct auto_pin_cfg *cfg = &spec->autocfg; 4038f2e5731dSTakashi Iwai 4039f2e5731dSTakashi Iwai if (spec->multiout.dig_out_nid) 4040f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0, 4041f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); 4042f2e5731dSTakashi Iwai if (spec->dig_in_nid) 4043f2e5731dSTakashi Iwai snd_hda_codec_write(codec, cfg->dig_in_pin, 0, 4044f2e5731dSTakashi Iwai AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); 4045f2e5731dSTakashi Iwai } 4046f2e5731dSTakashi Iwai 4047f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec) 4048f2e5731dSTakashi Iwai { 4049f2e5731dSTakashi Iwai /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/ 4050f2e5731dSTakashi Iwai cx_auto_init_output(codec); 4051f2e5731dSTakashi Iwai cx_auto_init_input(codec); 4052f2e5731dSTakashi Iwai cx_auto_init_digital(codec); 405301a61e12STakashi Iwai snd_hda_jack_report_sync(codec); 4054f2e5731dSTakashi Iwai return 0; 4055f2e5731dSTakashi Iwai } 4056f2e5731dSTakashi Iwai 4057983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename, 4058f2e5731dSTakashi Iwai const char *dir, int cidx, 4059983345e5SDavid Henningsson hda_nid_t nid, int hda_dir, int amp_idx) 4060f2e5731dSTakashi Iwai { 4061f2e5731dSTakashi Iwai static char name[32]; 4062f2e5731dSTakashi Iwai static struct snd_kcontrol_new knew[] = { 4063f2e5731dSTakashi Iwai HDA_CODEC_VOLUME(name, 0, 0, 0), 4064f2e5731dSTakashi Iwai HDA_CODEC_MUTE(name, 0, 0, 0), 4065f2e5731dSTakashi Iwai }; 406634cbe3a6STakashi Iwai static const char * const sfx[2] = { "Volume", "Switch" }; 4067f2e5731dSTakashi Iwai int i, err; 4068f2e5731dSTakashi Iwai 4069f2e5731dSTakashi Iwai for (i = 0; i < 2; i++) { 4070f2e5731dSTakashi Iwai struct snd_kcontrol *kctl; 4071983345e5SDavid Henningsson knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx, 4072983345e5SDavid Henningsson hda_dir); 4073f2e5731dSTakashi Iwai knew[i].subdevice = HDA_SUBDEV_AMP_FLAG; 4074f2e5731dSTakashi Iwai knew[i].index = cidx; 4075f2e5731dSTakashi Iwai snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]); 4076f2e5731dSTakashi Iwai kctl = snd_ctl_new1(&knew[i], codec); 4077f2e5731dSTakashi Iwai if (!kctl) 4078f2e5731dSTakashi Iwai return -ENOMEM; 4079f2e5731dSTakashi Iwai err = snd_hda_ctl_add(codec, nid, kctl); 4080f2e5731dSTakashi Iwai if (err < 0) 4081f2e5731dSTakashi Iwai return err; 4082f2e5731dSTakashi Iwai if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE)) 4083f2e5731dSTakashi Iwai break; 4084f2e5731dSTakashi Iwai } 4085f2e5731dSTakashi Iwai return 0; 4086f2e5731dSTakashi Iwai } 4087f2e5731dSTakashi Iwai 4088983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \ 4089983345e5SDavid Henningsson cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0) 4090983345e5SDavid Henningsson 4091f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx) \ 4092f2e5731dSTakashi Iwai cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT) 4093f2e5731dSTakashi Iwai 40941f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac, 40951f8458a2STakashi Iwai hda_nid_t pin, const char *name, int idx) 40961f8458a2STakashi Iwai { 40971f8458a2STakashi Iwai unsigned int caps; 4098468c5458SDavid Henningsson if (dac && !(dac & DAC_SLAVE_FLAG)) { 40991f8458a2STakashi Iwai caps = query_amp_caps(codec, dac, HDA_OUTPUT); 41001f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41011f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, dac, name, idx); 4102468c5458SDavid Henningsson } 41031f8458a2STakashi Iwai caps = query_amp_caps(codec, pin, HDA_OUTPUT); 41041f8458a2STakashi Iwai if (caps & AC_AMPCAP_NUM_STEPS) 41051f8458a2STakashi Iwai return cx_auto_add_pb_volume(codec, pin, name, idx); 41061f8458a2STakashi Iwai return 0; 41071f8458a2STakashi Iwai } 41081f8458a2STakashi Iwai 4109f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec) 4110f2e5731dSTakashi Iwai { 4111f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4112f2e5731dSTakashi Iwai int i, err; 4113f2e5731dSTakashi Iwai int num_line = 0, num_hp = 0, num_spk = 0; 4114ea734963STakashi Iwai static const char * const texts[3] = { "Front", "Surround", "CLFE" }; 4115f2e5731dSTakashi Iwai 4116f2e5731dSTakashi Iwai if (spec->dac_info_filled == 1) 41171f8458a2STakashi Iwai return try_add_pb_volume(codec, spec->dac_info[0].dac, 41181f8458a2STakashi Iwai spec->dac_info[0].pin, 4119f2e5731dSTakashi Iwai "Master", 0); 41201f8458a2STakashi Iwai 4121f2e5731dSTakashi Iwai for (i = 0; i < spec->dac_info_filled; i++) { 4122f2e5731dSTakashi Iwai const char *label; 4123f2e5731dSTakashi Iwai int idx, type; 41241f015f5fSTakashi Iwai hda_nid_t dac = spec->dac_info[i].dac; 4125f2e5731dSTakashi Iwai type = spec->dac_info[i].type; 4126f2e5731dSTakashi Iwai if (type == AUTO_PIN_LINE_OUT) 4127f2e5731dSTakashi Iwai type = spec->autocfg.line_out_type; 4128f2e5731dSTakashi Iwai switch (type) { 4129f2e5731dSTakashi Iwai case AUTO_PIN_LINE_OUT: 4130f2e5731dSTakashi Iwai default: 4131f2e5731dSTakashi Iwai label = texts[num_line++]; 4132f2e5731dSTakashi Iwai idx = 0; 4133f2e5731dSTakashi Iwai break; 4134f2e5731dSTakashi Iwai case AUTO_PIN_HP_OUT: 4135f2e5731dSTakashi Iwai label = "Headphone"; 4136f2e5731dSTakashi Iwai idx = num_hp++; 4137f2e5731dSTakashi Iwai break; 4138f2e5731dSTakashi Iwai case AUTO_PIN_SPEAKER_OUT: 4139f2e5731dSTakashi Iwai label = "Speaker"; 4140f2e5731dSTakashi Iwai idx = num_spk++; 4141f2e5731dSTakashi Iwai break; 4142f2e5731dSTakashi Iwai } 41431f015f5fSTakashi Iwai err = try_add_pb_volume(codec, dac, 41441f8458a2STakashi Iwai spec->dac_info[i].pin, 4145f2e5731dSTakashi Iwai label, idx); 4146f2e5731dSTakashi Iwai if (err < 0) 4147f2e5731dSTakashi Iwai return err; 4148f2e5731dSTakashi Iwai } 414903697e2aSTakashi Iwai 415003697e2aSTakashi Iwai if (spec->auto_mute) { 415103697e2aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum); 415203697e2aSTakashi Iwai if (err < 0) 415303697e2aSTakashi Iwai return err; 415403697e2aSTakashi Iwai } 415503697e2aSTakashi Iwai 4156f2e5731dSTakashi Iwai return 0; 4157f2e5731dSTakashi Iwai } 4158f2e5731dSTakashi Iwai 41596764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid, 41606764bcefSTakashi Iwai const char *label, const char *pfx, 41616764bcefSTakashi Iwai int cidx) 41626764bcefSTakashi Iwai { 41636764bcefSTakashi Iwai struct conexant_spec *spec = codec->spec; 41646764bcefSTakashi Iwai int i; 41656764bcefSTakashi Iwai 41666764bcefSTakashi Iwai for (i = 0; i < spec->num_adc_nids; i++) { 41676764bcefSTakashi Iwai hda_nid_t adc_nid = spec->adc_nids[i]; 41685c9887e0STakashi Iwai int idx = get_input_connection(codec, adc_nid, nid); 41696764bcefSTakashi Iwai if (idx < 0) 41706764bcefSTakashi Iwai continue; 41716b452142STakashi Iwai if (spec->single_adc_amp) 41726b452142STakashi Iwai idx = 0; 41736764bcefSTakashi Iwai return cx_auto_add_volume_idx(codec, label, pfx, 41746764bcefSTakashi Iwai cidx, adc_nid, HDA_INPUT, idx); 41756764bcefSTakashi Iwai } 41766764bcefSTakashi Iwai return 0; 41776764bcefSTakashi Iwai } 41786764bcefSTakashi Iwai 4179cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx, 4180cf27f29aSTakashi Iwai const char *label, int cidx) 4181cf27f29aSTakashi Iwai { 4182cf27f29aSTakashi Iwai struct conexant_spec *spec = codec->spec; 4183cf27f29aSTakashi Iwai hda_nid_t mux, nid; 4184f9759301STakashi Iwai int i, con; 4185cf27f29aSTakashi Iwai 418647ad1f4eSTakashi Iwai nid = spec->imux_info[idx].pin; 4187cf27f29aSTakashi Iwai if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) 4188cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", cidx, 4189cf27f29aSTakashi Iwai nid, HDA_INPUT); 419047ad1f4eSTakashi Iwai con = __select_input_connection(codec, spec->imux_info[idx].adc, nid, 419147ad1f4eSTakashi Iwai &mux, false, 0); 4192cf27f29aSTakashi Iwai if (con < 0) 4193cf27f29aSTakashi Iwai return 0; 4194f9759301STakashi Iwai for (i = 0; i < idx; i++) { 419547ad1f4eSTakashi Iwai if (spec->imux_info[i].boost == mux) 4196f9759301STakashi Iwai return 0; /* already present */ 4197f9759301STakashi Iwai } 4198f9759301STakashi Iwai 4199f9759301STakashi Iwai if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) { 420047ad1f4eSTakashi Iwai spec->imux_info[idx].boost = mux; 4201cf27f29aSTakashi Iwai return cx_auto_add_volume(codec, label, " Boost", 0, 4202cf27f29aSTakashi Iwai mux, HDA_OUTPUT); 4203f9759301STakashi Iwai } 4204cf27f29aSTakashi Iwai return 0; 4205cf27f29aSTakashi Iwai } 4206cf27f29aSTakashi Iwai 4207f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec) 4208f2e5731dSTakashi Iwai { 4209f2e5731dSTakashi Iwai struct conexant_spec *spec = codec->spec; 4210cf27f29aSTakashi Iwai struct hda_input_mux *imux = &spec->private_imux; 4211cf27f29aSTakashi Iwai const char *prev_label; 4212cf27f29aSTakashi Iwai int input_conn[HDA_MAX_NUM_INPUTS]; 42136b452142STakashi Iwai int i, j, err, cidx; 4214cf27f29aSTakashi Iwai int multi_connection; 4215cf27f29aSTakashi Iwai 42166b452142STakashi Iwai if (!imux->num_items) 42176b452142STakashi Iwai return 0; 42186b452142STakashi Iwai 4219cf27f29aSTakashi Iwai multi_connection = 0; 4220cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 422147ad1f4eSTakashi Iwai cidx = get_input_connection(codec, spec->imux_info[i].adc, 422247ad1f4eSTakashi Iwai spec->imux_info[i].pin); 42236b452142STakashi Iwai if (cidx < 0) 42246b452142STakashi Iwai continue; 42256b452142STakashi Iwai input_conn[i] = spec->imux_info[i].adc; 42266b452142STakashi Iwai if (!spec->single_adc_amp) 42276b452142STakashi Iwai input_conn[i] |= cidx << 8; 4228cf27f29aSTakashi Iwai if (i > 0 && input_conn[i] != input_conn[0]) 4229cf27f29aSTakashi Iwai multi_connection = 1; 4230cf27f29aSTakashi Iwai } 4231983345e5SDavid Henningsson 4232f2e5731dSTakashi Iwai prev_label = NULL; 4233f2e5731dSTakashi Iwai cidx = 0; 4234cf27f29aSTakashi Iwai for (i = 0; i < imux->num_items; i++) { 423547ad1f4eSTakashi Iwai hda_nid_t nid = spec->imux_info[i].pin; 4236f2e5731dSTakashi Iwai const char *label; 4237983345e5SDavid Henningsson 4238cf27f29aSTakashi Iwai label = hda_get_autocfg_input_label(codec, &spec->autocfg, 423947ad1f4eSTakashi Iwai spec->imux_info[i].index); 4240f2e5731dSTakashi Iwai if (label == prev_label) 4241f2e5731dSTakashi Iwai cidx++; 4242f2e5731dSTakashi Iwai else 4243f2e5731dSTakashi Iwai cidx = 0; 4244f2e5731dSTakashi Iwai prev_label = label; 4245983345e5SDavid Henningsson 4246cf27f29aSTakashi Iwai err = cx_auto_add_boost_volume(codec, i, label, cidx); 4247f2e5731dSTakashi Iwai if (err < 0) 4248f2e5731dSTakashi Iwai return err; 4249983345e5SDavid Henningsson 4250cf27f29aSTakashi Iwai if (!multi_connection) { 4251f9759301STakashi Iwai if (i > 0) 4252f9759301STakashi Iwai continue; 42536764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42546764bcefSTakashi Iwai "Capture", "", cidx); 42556764bcefSTakashi Iwai } else { 42566b452142STakashi Iwai bool dup_found = false; 42576b452142STakashi Iwai for (j = 0; j < i; j++) { 42586b452142STakashi Iwai if (input_conn[j] == input_conn[i]) { 42596b452142STakashi Iwai dup_found = true; 42606b452142STakashi Iwai break; 42616b452142STakashi Iwai } 42626b452142STakashi Iwai } 42636b452142STakashi Iwai if (dup_found) 42646b452142STakashi Iwai continue; 42656764bcefSTakashi Iwai err = cx_auto_add_capture_volume(codec, nid, 42666764bcefSTakashi Iwai label, " Capture", cidx); 42676764bcefSTakashi Iwai } 4268983345e5SDavid Henningsson if (err < 0) 4269983345e5SDavid Henningsson return err; 4270983345e5SDavid Henningsson } 42716764bcefSTakashi Iwai 42726764bcefSTakashi Iwai if (spec->private_imux.num_items > 1 && !spec->auto_mic) { 42736764bcefSTakashi Iwai err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers); 42746764bcefSTakashi Iwai if (err < 0) 42756764bcefSTakashi Iwai return err; 4276983345e5SDavid Henningsson } 42776764bcefSTakashi Iwai 4278f2e5731dSTakashi Iwai return 0; 4279f2e5731dSTakashi Iwai } 4280f2e5731dSTakashi Iwai 4281f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec) 4282f2e5731dSTakashi Iwai { 428331ef2257STakashi Iwai struct conexant_spec *spec = codec->spec; 4284f2e5731dSTakashi Iwai int err; 4285f2e5731dSTakashi Iwai 4286f2e5731dSTakashi Iwai err = cx_auto_build_output_controls(codec); 4287f2e5731dSTakashi Iwai if (err < 0) 4288f2e5731dSTakashi Iwai return err; 4289f2e5731dSTakashi Iwai err = cx_auto_build_input_controls(codec); 4290f2e5731dSTakashi Iwai if (err < 0) 4291f2e5731dSTakashi Iwai return err; 429231ef2257STakashi Iwai err = conexant_build_controls(codec); 429331ef2257STakashi Iwai if (err < 0) 429431ef2257STakashi Iwai return err; 429531ef2257STakashi Iwai err = snd_hda_jack_add_kctls(codec, &spec->autocfg); 429631ef2257STakashi Iwai if (err < 0) 429731ef2257STakashi Iwai return err; 429831ef2257STakashi Iwai return 0; 4299f2e5731dSTakashi Iwai } 4300f2e5731dSTakashi Iwai 430122ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec) 430222ce5f74STakashi Iwai { 430322ce5f74STakashi Iwai struct conexant_spec *spec = codec->spec; 430422ce5f74STakashi Iwai hda_nid_t nid, end_nid; 430522ce5f74STakashi Iwai 430622ce5f74STakashi Iwai end_nid = codec->start_nid + codec->num_nodes; 430722ce5f74STakashi Iwai for (nid = codec->start_nid; nid < end_nid; nid++) { 430822ce5f74STakashi Iwai unsigned int caps = get_wcaps(codec, nid); 430922ce5f74STakashi Iwai if (get_wcaps_type(caps) != AC_WID_AUD_IN) 431022ce5f74STakashi Iwai continue; 431122ce5f74STakashi Iwai if (caps & AC_WCAP_DIGITAL) 431222ce5f74STakashi Iwai continue; 431322ce5f74STakashi Iwai if (snd_BUG_ON(spec->num_adc_nids >= 431422ce5f74STakashi Iwai ARRAY_SIZE(spec->private_adc_nids))) 431522ce5f74STakashi Iwai break; 431622ce5f74STakashi Iwai spec->private_adc_nids[spec->num_adc_nids++] = nid; 431722ce5f74STakashi Iwai } 431822ce5f74STakashi Iwai spec->adc_nids = spec->private_adc_nids; 431922ce5f74STakashi Iwai return 0; 432022ce5f74STakashi Iwai } 432122ce5f74STakashi Iwai 432222ce5f74STakashi Iwai 432334cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = { 4324f2e5731dSTakashi Iwai .build_controls = cx_auto_build_controls, 4325f2e5731dSTakashi Iwai .build_pcms = conexant_build_pcms, 4326f2e5731dSTakashi Iwai .init = cx_auto_init, 4327f2e5731dSTakashi Iwai .free = conexant_free, 4328f2e5731dSTakashi Iwai .unsol_event = cx_auto_unsol_event, 4329f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 4330f2e5731dSTakashi Iwai .suspend = conexant_suspend, 4331f2e5731dSTakashi Iwai #endif 4332f2e5731dSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 4333f2e5731dSTakashi Iwai }; 4334f2e5731dSTakashi Iwai 4335e92d4b08STakashi Iwai /* 4336e92d4b08STakashi Iwai * pin fix-up 4337e92d4b08STakashi Iwai */ 4338e92d4b08STakashi Iwai struct cxt_pincfg { 4339e92d4b08STakashi Iwai hda_nid_t nid; 4340e92d4b08STakashi Iwai u32 val; 4341e92d4b08STakashi Iwai }; 4342e92d4b08STakashi Iwai 4343e92d4b08STakashi Iwai static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg) 4344e92d4b08STakashi Iwai { 4345e92d4b08STakashi Iwai for (; cfg->nid; cfg++) 4346e92d4b08STakashi Iwai snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val); 4347e92d4b08STakashi Iwai 4348e92d4b08STakashi Iwai } 4349e92d4b08STakashi Iwai 4350e92d4b08STakashi Iwai static void apply_pin_fixup(struct hda_codec *codec, 4351e92d4b08STakashi Iwai const struct snd_pci_quirk *quirk, 4352e92d4b08STakashi Iwai const struct cxt_pincfg **table) 4353e92d4b08STakashi Iwai { 4354e92d4b08STakashi Iwai quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk); 4355e92d4b08STakashi Iwai if (quirk) { 4356e92d4b08STakashi Iwai snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n", 4357e92d4b08STakashi Iwai quirk->name); 4358e92d4b08STakashi Iwai apply_pincfg(codec, table[quirk->value]); 4359e92d4b08STakashi Iwai } 4360e92d4b08STakashi Iwai } 4361e92d4b08STakashi Iwai 4362e92d4b08STakashi Iwai enum { 4363e92d4b08STakashi Iwai CXT_PINCFG_LENOVO_X200, 4364e92d4b08STakashi Iwai }; 4365e92d4b08STakashi Iwai 4366e92d4b08STakashi Iwai static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = { 4367e92d4b08STakashi Iwai { 0x16, 0x042140ff }, /* HP (seq# overridden) */ 4368e92d4b08STakashi Iwai { 0x17, 0x21a11000 }, /* dock-mic */ 4369e92d4b08STakashi Iwai { 0x19, 0x2121103f }, /* dock-HP */ 4370e92d4b08STakashi Iwai {} 4371e92d4b08STakashi Iwai }; 4372e92d4b08STakashi Iwai 4373e92d4b08STakashi Iwai static const struct cxt_pincfg *cxt_pincfg_tbl[] = { 4374e92d4b08STakashi Iwai [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200, 4375e92d4b08STakashi Iwai }; 4376e92d4b08STakashi Iwai 4377e92d4b08STakashi Iwai static const struct snd_pci_quirk cxt_fixups[] = { 4378e92d4b08STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200), 4379e92d4b08STakashi Iwai {} 4380e92d4b08STakashi Iwai }; 4381e92d4b08STakashi Iwai 4382f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec) 4383f2e5731dSTakashi Iwai { 4384f2e5731dSTakashi Iwai struct conexant_spec *spec; 4385f2e5731dSTakashi Iwai int err; 4386f2e5731dSTakashi Iwai 43871f8458a2STakashi Iwai printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 43881f8458a2STakashi Iwai codec->chip_name); 43891f8458a2STakashi Iwai 4390f2e5731dSTakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4391f2e5731dSTakashi Iwai if (!spec) 4392f2e5731dSTakashi Iwai return -ENOMEM; 4393f2e5731dSTakashi Iwai codec->spec = spec; 43941387cde5STakashi Iwai codec->pin_amp_workaround = 1; 4395e92d4b08STakashi Iwai 43966b452142STakashi Iwai switch (codec->vendor_id) { 43976b452142STakashi Iwai case 0x14f15045: 43986b452142STakashi Iwai spec->single_adc_amp = 1; 43996b452142STakashi Iwai break; 44006b452142STakashi Iwai } 44016b452142STakashi Iwai 4402e92d4b08STakashi Iwai apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl); 4403e92d4b08STakashi Iwai 440422ce5f74STakashi Iwai err = cx_auto_search_adcs(codec); 440522ce5f74STakashi Iwai if (err < 0) 440622ce5f74STakashi Iwai return err; 4407f2e5731dSTakashi Iwai err = cx_auto_parse_auto_config(codec); 4408f2e5731dSTakashi Iwai if (err < 0) { 4409f2e5731dSTakashi Iwai kfree(codec->spec); 4410f2e5731dSTakashi Iwai codec->spec = NULL; 4411f2e5731dSTakashi Iwai return err; 4412f2e5731dSTakashi Iwai } 44136764bcefSTakashi Iwai spec->capture_stream = &cx_auto_pcm_analog_capture; 4414f2e5731dSTakashi Iwai codec->patch_ops = cx_auto_patch_ops; 4415f2e5731dSTakashi Iwai if (spec->beep_amp) 4416f2e5731dSTakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 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