1c9b443d4STobin Davis /* 2c9b443d4STobin Davis * HD audio interface patch for Conexant HDA audio codec 3c9b443d4STobin Davis * 4c9b443d4STobin Davis * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com> 5c9b443d4STobin Davis * Takashi Iwai <tiwai@suse.de> 6c9b443d4STobin Davis * Tobin Davis <tdavis@dsl-only.net> 7c9b443d4STobin Davis * 8c9b443d4STobin Davis * This driver is free software; you can redistribute it and/or modify 9c9b443d4STobin Davis * it under the terms of the GNU General Public License as published by 10c9b443d4STobin Davis * the Free Software Foundation; either version 2 of the License, or 11c9b443d4STobin Davis * (at your option) any later version. 12c9b443d4STobin Davis * 13c9b443d4STobin Davis * This driver is distributed in the hope that it will be useful, 14c9b443d4STobin Davis * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c9b443d4STobin Davis * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c9b443d4STobin Davis * GNU General Public License for more details. 17c9b443d4STobin Davis * 18c9b443d4STobin Davis * You should have received a copy of the GNU General Public License 19c9b443d4STobin Davis * along with this program; if not, write to the Free Software 20c9b443d4STobin Davis * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c9b443d4STobin Davis */ 22c9b443d4STobin Davis 23c9b443d4STobin Davis #include <linux/init.h> 24c9b443d4STobin Davis #include <linux/delay.h> 25c9b443d4STobin Davis #include <linux/slab.h> 26c9b443d4STobin Davis #include <linux/pci.h> 27c9b443d4STobin Davis #include <sound/core.h> 28bc7a166dSUlrich Dangel #include <sound/jack.h> 29bc7a166dSUlrich Dangel 30c9b443d4STobin Davis #include "hda_codec.h" 31c9b443d4STobin Davis #include "hda_local.h" 32c0f8faf0SEinar Rünkaru #include "hda_beep.h" 33c9b443d4STobin Davis 34c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 39c9b443d4STobin Davis 40c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 42c9b443d4STobin Davis 43bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 44c9b443d4STobin Davis 45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT 0x12 46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 48bc7a166dSUlrich Dangel 49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB (1 << 1) 50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC (1 << 2) 51bc7a166dSUlrich Dangel 52bc7a166dSUlrich Dangel struct conexant_jack { 53bc7a166dSUlrich Dangel 54bc7a166dSUlrich Dangel hda_nid_t nid; 55bc7a166dSUlrich Dangel int type; 56bc7a166dSUlrich Dangel struct snd_jack *jack; 57bc7a166dSUlrich Dangel 58bc7a166dSUlrich Dangel }; 59c9b443d4STobin Davis 60c9b443d4STobin Davis struct conexant_spec { 61c9b443d4STobin Davis 62c9b443d4STobin Davis struct snd_kcontrol_new *mixers[5]; 63c9b443d4STobin Davis int num_mixers; 64dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 65c9b443d4STobin Davis 66c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 67c9b443d4STobin Davis * don't forget NULL 68c9b443d4STobin Davis * termination! 69c9b443d4STobin Davis */ 70c9b443d4STobin Davis unsigned int num_init_verbs; 71c9b443d4STobin Davis 72c9b443d4STobin Davis /* playback */ 73c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 74c9b443d4STobin Davis * max_channels, dacs must be set 75c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 76c9b443d4STobin Davis */ 77c9b443d4STobin Davis unsigned int cur_eapd; 7882f30040STobin Davis unsigned int hp_present; 79faddaa5dSTakashi Iwai unsigned int auto_mic; 80c9b443d4STobin Davis unsigned int need_dac_fix; 81c9b443d4STobin Davis 82c9b443d4STobin Davis /* capture */ 83c9b443d4STobin Davis unsigned int num_adc_nids; 84c9b443d4STobin Davis hda_nid_t *adc_nids; 85c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 86c9b443d4STobin Davis 87461e2c78STakashi Iwai unsigned int cur_adc_idx; 88461e2c78STakashi Iwai hda_nid_t cur_adc; 89461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 90461e2c78STakashi Iwai unsigned int cur_adc_format; 91461e2c78STakashi Iwai 92c9b443d4STobin Davis /* capture source */ 93c9b443d4STobin Davis const struct hda_input_mux *input_mux; 94c9b443d4STobin Davis hda_nid_t *capsrc_nids; 95c9b443d4STobin Davis unsigned int cur_mux[3]; 96c9b443d4STobin Davis 97c9b443d4STobin Davis /* channel model */ 98c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 99c9b443d4STobin Davis int num_channel_mode; 100c9b443d4STobin Davis 101c9b443d4STobin Davis /* PCM information */ 102c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 103c9b443d4STobin Davis 104c9b443d4STobin Davis unsigned int spdif_route; 105c9b443d4STobin Davis 106bc7a166dSUlrich Dangel /* jack detection */ 107bc7a166dSUlrich Dangel struct snd_array jacks; 108bc7a166dSUlrich Dangel 109c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 110c9b443d4STobin Davis struct auto_pin_cfg autocfg; 111c9b443d4STobin Davis struct hda_input_mux private_imux; 11241923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 113c9b443d4STobin Davis 1140fb67e98SDaniel Drake unsigned int dell_automute; 1150fb67e98SDaniel Drake unsigned int port_d_mode; 116*cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 117*cfd3d8dcSGreg Alexander unsigned int ideapad:1; 11875f8991dSDaniel Drake 11975f8991dSDaniel Drake unsigned int ext_mic_present; 12075f8991dSDaniel Drake unsigned int recording; 12175f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 12275f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 123c4cfe66cSDaniel Drake 124c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 125c4cfe66cSDaniel Drake * through the microphone jack. 126c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 127c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 128c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 129c4cfe66cSDaniel Drake * control. */ 130c4cfe66cSDaniel Drake unsigned int dc_enable; 131c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 132c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 133c9b443d4STobin Davis }; 134c9b443d4STobin Davis 135c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 136c9b443d4STobin Davis struct hda_codec *codec, 137c9b443d4STobin Davis struct snd_pcm_substream *substream) 138c9b443d4STobin Davis { 139c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1409a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1419a08160bSTakashi Iwai hinfo); 142c9b443d4STobin Davis } 143c9b443d4STobin Davis 144c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 145c9b443d4STobin Davis struct hda_codec *codec, 146c9b443d4STobin Davis unsigned int stream_tag, 147c9b443d4STobin Davis unsigned int format, 148c9b443d4STobin Davis struct snd_pcm_substream *substream) 149c9b443d4STobin Davis { 150c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 151c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 152c9b443d4STobin Davis stream_tag, 153c9b443d4STobin Davis format, substream); 154c9b443d4STobin Davis } 155c9b443d4STobin Davis 156c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 157c9b443d4STobin Davis struct hda_codec *codec, 158c9b443d4STobin Davis struct snd_pcm_substream *substream) 159c9b443d4STobin Davis { 160c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 161c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 162c9b443d4STobin Davis } 163c9b443d4STobin Davis 164c9b443d4STobin Davis /* 165c9b443d4STobin Davis * Digital out 166c9b443d4STobin Davis */ 167c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 168c9b443d4STobin Davis struct hda_codec *codec, 169c9b443d4STobin Davis struct snd_pcm_substream *substream) 170c9b443d4STobin Davis { 171c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 172c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 173c9b443d4STobin Davis } 174c9b443d4STobin Davis 175c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 176c9b443d4STobin Davis struct hda_codec *codec, 177c9b443d4STobin Davis struct snd_pcm_substream *substream) 178c9b443d4STobin Davis { 179c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 180c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 181c9b443d4STobin Davis } 182c9b443d4STobin Davis 1836b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1846b97eb45STakashi Iwai struct hda_codec *codec, 1856b97eb45STakashi Iwai unsigned int stream_tag, 1866b97eb45STakashi Iwai unsigned int format, 1876b97eb45STakashi Iwai struct snd_pcm_substream *substream) 1886b97eb45STakashi Iwai { 1896b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 1906b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 1916b97eb45STakashi Iwai stream_tag, 1926b97eb45STakashi Iwai format, substream); 1936b97eb45STakashi Iwai } 1946b97eb45STakashi Iwai 195c9b443d4STobin Davis /* 196c9b443d4STobin Davis * Analog capture 197c9b443d4STobin Davis */ 198c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 199c9b443d4STobin Davis struct hda_codec *codec, 200c9b443d4STobin Davis unsigned int stream_tag, 201c9b443d4STobin Davis unsigned int format, 202c9b443d4STobin Davis struct snd_pcm_substream *substream) 203c9b443d4STobin Davis { 204c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 20575f8991dSDaniel Drake if (spec->capture_prepare) 20675f8991dSDaniel Drake spec->capture_prepare(codec); 207c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 208c9b443d4STobin Davis stream_tag, 0, format); 209c9b443d4STobin Davis return 0; 210c9b443d4STobin Davis } 211c9b443d4STobin Davis 212c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 213c9b443d4STobin Davis struct hda_codec *codec, 214c9b443d4STobin Davis struct snd_pcm_substream *substream) 215c9b443d4STobin Davis { 216c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 217888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 21875f8991dSDaniel Drake if (spec->capture_cleanup) 21975f8991dSDaniel Drake spec->capture_cleanup(codec); 220c9b443d4STobin Davis return 0; 221c9b443d4STobin Davis } 222c9b443d4STobin Davis 223c9b443d4STobin Davis 224c9b443d4STobin Davis 225c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 226c9b443d4STobin Davis .substreams = 1, 227c9b443d4STobin Davis .channels_min = 2, 228c9b443d4STobin Davis .channels_max = 2, 229c9b443d4STobin Davis .nid = 0, /* fill later */ 230c9b443d4STobin Davis .ops = { 231c9b443d4STobin Davis .open = conexant_playback_pcm_open, 232c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 233c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 234c9b443d4STobin Davis }, 235c9b443d4STobin Davis }; 236c9b443d4STobin Davis 237c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 238c9b443d4STobin Davis .substreams = 1, 239c9b443d4STobin Davis .channels_min = 2, 240c9b443d4STobin Davis .channels_max = 2, 241c9b443d4STobin Davis .nid = 0, /* fill later */ 242c9b443d4STobin Davis .ops = { 243c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 244c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 245c9b443d4STobin Davis }, 246c9b443d4STobin Davis }; 247c9b443d4STobin Davis 248c9b443d4STobin Davis 249c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 250c9b443d4STobin Davis .substreams = 1, 251c9b443d4STobin Davis .channels_min = 2, 252c9b443d4STobin Davis .channels_max = 2, 253c9b443d4STobin Davis .nid = 0, /* fill later */ 254c9b443d4STobin Davis .ops = { 255c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2566b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2576b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 258c9b443d4STobin Davis }, 259c9b443d4STobin Davis }; 260c9b443d4STobin Davis 261c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 262c9b443d4STobin Davis .substreams = 1, 263c9b443d4STobin Davis .channels_min = 2, 264c9b443d4STobin Davis .channels_max = 2, 265c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 266c9b443d4STobin Davis }; 267c9b443d4STobin Davis 268461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 269461e2c78STakashi Iwai struct hda_codec *codec, 270461e2c78STakashi Iwai unsigned int stream_tag, 271461e2c78STakashi Iwai unsigned int format, 272461e2c78STakashi Iwai struct snd_pcm_substream *substream) 273461e2c78STakashi Iwai { 274461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 275461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 276461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 277461e2c78STakashi Iwai spec->cur_adc_format = format; 278461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 279461e2c78STakashi Iwai return 0; 280461e2c78STakashi Iwai } 281461e2c78STakashi Iwai 282461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 283461e2c78STakashi Iwai struct hda_codec *codec, 284461e2c78STakashi Iwai struct snd_pcm_substream *substream) 285461e2c78STakashi Iwai { 286461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 287888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 288461e2c78STakashi Iwai spec->cur_adc = 0; 289461e2c78STakashi Iwai return 0; 290461e2c78STakashi Iwai } 291461e2c78STakashi Iwai 292461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 293461e2c78STakashi Iwai .substreams = 1, 294461e2c78STakashi Iwai .channels_min = 2, 295461e2c78STakashi Iwai .channels_max = 2, 296461e2c78STakashi Iwai .nid = 0, /* fill later */ 297461e2c78STakashi Iwai .ops = { 298461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 299461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 300461e2c78STakashi Iwai }, 301461e2c78STakashi Iwai }; 302461e2c78STakashi Iwai 303c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 304c9b443d4STobin Davis { 305c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 306c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 307c9b443d4STobin Davis 308c9b443d4STobin Davis codec->num_pcms = 1; 309c9b443d4STobin Davis codec->pcm_info = info; 310c9b443d4STobin Davis 311c9b443d4STobin Davis info->name = "CONEXANT Analog"; 312c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 313c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 314c9b443d4STobin Davis spec->multiout.max_channels; 315c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 316c9b443d4STobin Davis spec->multiout.dac_nids[0]; 317461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 318461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 319461e2c78STakashi Iwai cx5051_pcm_analog_capture; 320461e2c78STakashi Iwai else 321461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 322461e2c78STakashi Iwai conexant_pcm_analog_capture; 323c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 324c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 325c9b443d4STobin Davis 326c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 327c9b443d4STobin Davis info++; 328c9b443d4STobin Davis codec->num_pcms++; 329c9b443d4STobin Davis info->name = "Conexant Digital"; 3307ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 331c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 332c9b443d4STobin Davis conexant_pcm_digital_playback; 333c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 334c9b443d4STobin Davis spec->multiout.dig_out_nid; 335c9b443d4STobin Davis if (spec->dig_in_nid) { 336c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 337c9b443d4STobin Davis conexant_pcm_digital_capture; 338c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 339c9b443d4STobin Davis spec->dig_in_nid; 340c9b443d4STobin Davis } 341c9b443d4STobin Davis } 342c9b443d4STobin Davis 343c9b443d4STobin Davis return 0; 344c9b443d4STobin Davis } 345c9b443d4STobin Davis 346c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 347c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 348c9b443d4STobin Davis { 349c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 350c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 351c9b443d4STobin Davis 352c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 353c9b443d4STobin Davis } 354c9b443d4STobin Davis 355c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 356c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 357c9b443d4STobin Davis { 358c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 359c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 360c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 361c9b443d4STobin Davis 362c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 363c9b443d4STobin Davis return 0; 364c9b443d4STobin Davis } 365c9b443d4STobin Davis 366c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 367c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 368c9b443d4STobin Davis { 369c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 370c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 371c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 372c9b443d4STobin Davis 373c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 374c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 375c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 376c9b443d4STobin Davis } 377c9b443d4STobin Davis 3788c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 37995c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack) 38095c09099STakashi Iwai { 38195c09099STakashi Iwai struct conexant_jack *jacks = jack->private_data; 38295c09099STakashi Iwai jacks->nid = 0; 38395c09099STakashi Iwai jacks->jack = NULL; 38495c09099STakashi Iwai } 38595c09099STakashi Iwai 386bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 387bc7a166dSUlrich Dangel hda_nid_t nid, int type) 388bc7a166dSUlrich Dangel { 389bc7a166dSUlrich Dangel struct conexant_spec *spec; 390bc7a166dSUlrich Dangel struct conexant_jack *jack; 391bc7a166dSUlrich Dangel const char *name; 39295c09099STakashi Iwai int err; 393bc7a166dSUlrich Dangel 394bc7a166dSUlrich Dangel spec = codec->spec; 395bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 396bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 397bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 398bc7a166dSUlrich Dangel 399bc7a166dSUlrich Dangel if (!jack) 400bc7a166dSUlrich Dangel return -ENOMEM; 401bc7a166dSUlrich Dangel 402bc7a166dSUlrich Dangel jack->nid = nid; 403bc7a166dSUlrich Dangel jack->type = type; 404bc7a166dSUlrich Dangel 40595c09099STakashi Iwai err = snd_jack_new(codec->bus->card, name, type, &jack->jack); 40695c09099STakashi Iwai if (err < 0) 40795c09099STakashi Iwai return err; 40895c09099STakashi Iwai jack->jack->private_data = jack; 40995c09099STakashi Iwai jack->jack->private_free = conexant_free_jack_priv; 41095c09099STakashi Iwai return 0; 411bc7a166dSUlrich Dangel } 412bc7a166dSUlrich Dangel 413bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 414bc7a166dSUlrich Dangel { 415bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 416bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 417bc7a166dSUlrich Dangel 418bc7a166dSUlrich Dangel if (jacks) { 419bc7a166dSUlrich Dangel int i; 420bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 421bc7a166dSUlrich Dangel if (jacks->nid == nid) { 422bc7a166dSUlrich Dangel unsigned int present; 423d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, nid); 424bc7a166dSUlrich Dangel 425bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 426bc7a166dSUlrich Dangel 427bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 428bc7a166dSUlrich Dangel present); 429bc7a166dSUlrich Dangel } 430bc7a166dSUlrich Dangel jacks++; 431bc7a166dSUlrich Dangel } 432bc7a166dSUlrich Dangel } 433bc7a166dSUlrich Dangel } 434bc7a166dSUlrich Dangel 435bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 436bc7a166dSUlrich Dangel { 437bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 438bc7a166dSUlrich Dangel int i; 439bc7a166dSUlrich Dangel 440bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 441bc7a166dSUlrich Dangel const struct hda_verb *hv; 442bc7a166dSUlrich Dangel 443bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 444bc7a166dSUlrich Dangel while (hv->nid) { 445bc7a166dSUlrich Dangel int err = 0; 446bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 447bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 448bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 449bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 450bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 451bc7a166dSUlrich Dangel break; 452bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 453bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 454bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 455bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 456bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 457bc7a166dSUlrich Dangel break; 458bc7a166dSUlrich Dangel } 459bc7a166dSUlrich Dangel if (err < 0) 460bc7a166dSUlrich Dangel return err; 461bc7a166dSUlrich Dangel ++hv; 462bc7a166dSUlrich Dangel } 463bc7a166dSUlrich Dangel } 464bc7a166dSUlrich Dangel return 0; 465bc7a166dSUlrich Dangel 466bc7a166dSUlrich Dangel } 4675801f992STakashi Iwai #else 4685801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4695801f992STakashi Iwai { 4705801f992STakashi Iwai } 4715801f992STakashi Iwai 4725801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4735801f992STakashi Iwai { 4745801f992STakashi Iwai return 0; 4755801f992STakashi Iwai } 4765801f992STakashi Iwai #endif 477bc7a166dSUlrich Dangel 478c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 479c9b443d4STobin Davis { 480c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 481c9b443d4STobin Davis int i; 482c9b443d4STobin Davis 483c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 484c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 485c9b443d4STobin Davis return 0; 486c9b443d4STobin Davis } 487c9b443d4STobin Davis 488c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 489c9b443d4STobin Davis { 4908c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 491bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 492bc7a166dSUlrich Dangel if (spec->jacks.list) { 493bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 494bc7a166dSUlrich Dangel int i; 49595c09099STakashi Iwai for (i = 0; i < spec->jacks.used; i++, jacks++) { 49695c09099STakashi Iwai if (jacks->jack) 49795c09099STakashi Iwai snd_device_free(codec->bus->card, jacks->jack); 49895c09099STakashi Iwai } 499bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 500bc7a166dSUlrich Dangel } 501bc7a166dSUlrich Dangel #endif 502c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 503c9b443d4STobin Davis kfree(codec->spec); 504c9b443d4STobin Davis } 505c9b443d4STobin Davis 506b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = { 507b880c74aSTakashi Iwai { 508b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 509b880c74aSTakashi Iwai .name = "Capture Source", 510b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 511b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 512b880c74aSTakashi Iwai .put = conexant_mux_enum_put 513b880c74aSTakashi Iwai }, 514b880c74aSTakashi Iwai {} 515b880c74aSTakashi Iwai }; 516b880c74aSTakashi Iwai 517dd5746a8STakashi Iwai static const char *slave_vols[] = { 518dd5746a8STakashi Iwai "Headphone Playback Volume", 519dd5746a8STakashi Iwai "Speaker Playback Volume", 520dd5746a8STakashi Iwai NULL 521dd5746a8STakashi Iwai }; 522dd5746a8STakashi Iwai 523dd5746a8STakashi Iwai static const char *slave_sws[] = { 524dd5746a8STakashi Iwai "Headphone Playback Switch", 525dd5746a8STakashi Iwai "Speaker Playback Switch", 526dd5746a8STakashi Iwai NULL 527dd5746a8STakashi Iwai }; 528dd5746a8STakashi Iwai 529c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 530c9b443d4STobin Davis { 531c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 532c9b443d4STobin Davis unsigned int i; 533c9b443d4STobin Davis int err; 534c9b443d4STobin Davis 535c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 536c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 537c9b443d4STobin Davis if (err < 0) 538c9b443d4STobin Davis return err; 539c9b443d4STobin Davis } 540c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 541c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 542c9b443d4STobin Davis spec->multiout.dig_out_nid); 543c9b443d4STobin Davis if (err < 0) 544c9b443d4STobin Davis return err; 5459a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5469a08160bSTakashi Iwai &spec->multiout); 5479a08160bSTakashi Iwai if (err < 0) 5489a08160bSTakashi Iwai return err; 5499a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 550c9b443d4STobin Davis } 551c9b443d4STobin Davis if (spec->dig_in_nid) { 552c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 553c9b443d4STobin Davis if (err < 0) 554c9b443d4STobin Davis return err; 555c9b443d4STobin Davis } 556dd5746a8STakashi Iwai 557dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 558dd5746a8STakashi Iwai if (spec->vmaster_nid && 559dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 560dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 561dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 562dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 563dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 564dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 565dd5746a8STakashi Iwai if (err < 0) 566dd5746a8STakashi Iwai return err; 567dd5746a8STakashi Iwai } 568dd5746a8STakashi Iwai if (spec->vmaster_nid && 569dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 570dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 571dd5746a8STakashi Iwai NULL, slave_sws); 572dd5746a8STakashi Iwai if (err < 0) 573dd5746a8STakashi Iwai return err; 574dd5746a8STakashi Iwai } 575dd5746a8STakashi Iwai 576b880c74aSTakashi Iwai if (spec->input_mux) { 577b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 578b880c74aSTakashi Iwai if (err < 0) 579b880c74aSTakashi Iwai return err; 580b880c74aSTakashi Iwai } 581b880c74aSTakashi Iwai 582c9b443d4STobin Davis return 0; 583c9b443d4STobin Davis } 584c9b443d4STobin Davis 585c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 586c9b443d4STobin Davis .build_controls = conexant_build_controls, 587c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 588c9b443d4STobin Davis .init = conexant_init, 589c9b443d4STobin Davis .free = conexant_free, 590c9b443d4STobin Davis }; 591c9b443d4STobin Davis 592c9b443d4STobin Davis /* 593c9b443d4STobin Davis * EAPD control 594c9b443d4STobin Davis * the private value = nid | (invert << 8) 595c9b443d4STobin Davis */ 596c9b443d4STobin Davis 597a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 598c9b443d4STobin Davis 59982f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 600c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 601c9b443d4STobin Davis { 602c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 603c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 604c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 605c9b443d4STobin Davis if (invert) 606c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 607c9b443d4STobin Davis else 608c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 609c9b443d4STobin Davis return 0; 61082f30040STobin Davis 611c9b443d4STobin Davis } 612c9b443d4STobin Davis 61382f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 614c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 615c9b443d4STobin Davis { 616c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 617c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 618c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 619c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 620c9b443d4STobin Davis unsigned int eapd; 62182f30040STobin Davis 62268ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 623c9b443d4STobin Davis if (invert) 624c9b443d4STobin Davis eapd = !eapd; 62582beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 626c9b443d4STobin Davis return 0; 62782f30040STobin Davis 628c9b443d4STobin Davis spec->cur_eapd = eapd; 62982beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 630c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 631c9b443d4STobin Davis eapd ? 0x02 : 0x00); 632c9b443d4STobin Davis return 1; 633c9b443d4STobin Davis } 634c9b443d4STobin Davis 63586d72bdfSTakashi Iwai /* controls for test mode */ 63686d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 63786d72bdfSTakashi Iwai 63882f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 63982f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 64082f30040STobin Davis .info = cxt_eapd_info, \ 64182f30040STobin Davis .get = cxt_eapd_get, \ 64282f30040STobin Davis .put = cxt_eapd_put, \ 64382f30040STobin Davis .private_value = nid | (mask<<16) } 64482f30040STobin Davis 64582f30040STobin Davis 64682f30040STobin Davis 647c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 648c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 649c9b443d4STobin Davis { 650c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 651c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 652c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 653c9b443d4STobin Davis spec->num_channel_mode); 654c9b443d4STobin Davis } 655c9b443d4STobin Davis 656c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 657c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 658c9b443d4STobin Davis { 659c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 660c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 661c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 662c9b443d4STobin Davis spec->num_channel_mode, 663c9b443d4STobin Davis spec->multiout.max_channels); 664c9b443d4STobin Davis } 665c9b443d4STobin Davis 666c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 667c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 668c9b443d4STobin Davis { 669c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 670c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 671c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 672c9b443d4STobin Davis spec->num_channel_mode, 673c9b443d4STobin Davis &spec->multiout.max_channels); 674c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 675c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 676c9b443d4STobin Davis return err; 677c9b443d4STobin Davis } 678c9b443d4STobin Davis 679c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 680c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 681c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 682c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 683c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 684c9b443d4STobin Davis .private_value = nid | (dir<<16) } 685c9b443d4STobin Davis 68686d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 68786d72bdfSTakashi Iwai 688c9b443d4STobin Davis /* Conexant 5045 specific */ 689c9b443d4STobin Davis 690c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 691c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 692c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 693cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 694c9b443d4STobin Davis 6955cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 6965cd57529STobin Davis { 2, NULL }, 6975cd57529STobin Davis }; 698c9b443d4STobin Davis 699c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 700c9b443d4STobin Davis .num_items = 2, 701c9b443d4STobin Davis .items = { 70282f30040STobin Davis { "IntMic", 0x1 }, 703f4beee94SJiang zhe { "ExtMic", 0x2 }, 704c9b443d4STobin Davis } 705c9b443d4STobin Davis }; 706c9b443d4STobin Davis 7075218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 70822e14130SLukasz Marcinowski .num_items = 5, 7095218c892SJiang Zhe .items = { 7105218c892SJiang Zhe { "IntMic", 0x1 }, 7115218c892SJiang Zhe { "ExtMic", 0x2 }, 7125218c892SJiang Zhe { "LineIn", 0x3 }, 71322e14130SLukasz Marcinowski { "CD", 0x4 }, 71422e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7155218c892SJiang Zhe } 7165218c892SJiang Zhe }; 7175218c892SJiang Zhe 7182de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 7192de3c232SJiang zhe .num_items = 2, 7202de3c232SJiang zhe .items = { 7212de3c232SJiang zhe { "ExtMic", 0x1 }, 7222de3c232SJiang zhe { "IntMic", 0x2 }, 7232de3c232SJiang zhe } 7242de3c232SJiang zhe }; 7252de3c232SJiang zhe 726c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 727c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 728c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 729c9b443d4STobin Davis { 730c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 731c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 73282f30040STobin Davis unsigned int bits; 733c9b443d4STobin Davis 73482f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 735c9b443d4STobin Davis return 0; 736c9b443d4STobin Davis 73782f30040STobin Davis /* toggle internal speakers mute depending of presence of 73882f30040STobin Davis * the headphone jack 73982f30040STobin Davis */ 74047fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 74147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 74247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7437f29673bSTobin Davis 74447fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 74547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 74647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 747c9b443d4STobin Davis return 1; 748c9b443d4STobin Davis } 749c9b443d4STobin Davis 750c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 751cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 752cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 753cca3b371STakashi Iwai .values = { 754cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 755cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 756cca3b371STakashi Iwai 0 757cca3b371STakashi Iwai }, 758cca3b371STakashi Iwai }; 759c9b443d4STobin Davis 7607f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7617f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7627f29673bSTobin Davis { 7637f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 7647f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7657f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7667f29673bSTobin Davis {} 7677f29673bSTobin Davis }; 7687f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 7697f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7707f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7717f29673bSTobin Davis {} 7727f29673bSTobin Davis }; 7737f29673bSTobin Davis unsigned int present; 7747f29673bSTobin Davis 775d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 7767f29673bSTobin Davis if (present) 7777f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7787f29673bSTobin Davis else 7797f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7807f29673bSTobin Davis } 7817f29673bSTobin Davis 782c9b443d4STobin Davis 783c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 784c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 785c9b443d4STobin Davis { 78682f30040STobin Davis struct conexant_spec *spec = codec->spec; 787dd87da1cSTobin Davis unsigned int bits; 788c9b443d4STobin Davis 789d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 790dd87da1cSTobin Davis 79147fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 79247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 79347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 794c9b443d4STobin Davis } 795c9b443d4STobin Davis 796c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 797c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 798c9b443d4STobin Davis unsigned int res) 799c9b443d4STobin Davis { 800c9b443d4STobin Davis res >>= 26; 801c9b443d4STobin Davis switch (res) { 802c9b443d4STobin Davis case CONEXANT_HP_EVENT: 803c9b443d4STobin Davis cxt5045_hp_automute(codec); 804c9b443d4STobin Davis break; 8057f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8067f29673bSTobin Davis cxt5045_hp_automic(codec); 8077f29673bSTobin Davis break; 8087f29673bSTobin Davis 809c9b443d4STobin Davis } 810c9b443d4STobin Davis } 811c9b443d4STobin Davis 812c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 813c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 814c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 815c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 816c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 817c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 818c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 819c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 820c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 821c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 822c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 823cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 824c9b443d4STobin Davis { 825c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 826c9b443d4STobin Davis .name = "Master Playback Switch", 82782f30040STobin Davis .info = cxt_eapd_info, 82882f30040STobin Davis .get = cxt_eapd_get, 829c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 83082f30040STobin Davis .private_value = 0x10, 831c9b443d4STobin Davis }, 832c9b443d4STobin Davis 833c9b443d4STobin Davis {} 834c9b443d4STobin Davis }; 835c9b443d4STobin Davis 8365218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 83722e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 83822e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 83922e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 84022e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 84122e14130SLukasz Marcinowski 8425218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8435218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8445218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8455218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8465218c892SJiang Zhe 84722e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 84822e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 84922e14130SLukasz Marcinowski 8505218c892SJiang Zhe {} 8515218c892SJiang Zhe }; 8525218c892SJiang Zhe 8532de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 8542de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8552de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8562de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8572de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8582de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8592de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 8602de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8612de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8622de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8632de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8642de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8652de3c232SJiang zhe { 8662de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8672de3c232SJiang zhe .name = "Master Playback Switch", 8682de3c232SJiang zhe .info = cxt_eapd_info, 8692de3c232SJiang zhe .get = cxt_eapd_get, 8702de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8712de3c232SJiang zhe .private_value = 0x10, 8722de3c232SJiang zhe }, 8732de3c232SJiang zhe 8742de3c232SJiang zhe {} 8752de3c232SJiang zhe }; 8762de3c232SJiang zhe 877c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 878c9b443d4STobin Davis /* Line in, Mic */ 8794090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8807f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 881c9b443d4STobin Davis /* HP, Amp */ 882c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 883c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 88482f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 885c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 886c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 887c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 888c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 889c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 890c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 89182f30040STobin Davis /* Record selector: Int mic */ 8927f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 89382f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 894c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 895c9b443d4STobin Davis /* SPDIF route: PCM */ 896cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 897c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 898c9b443d4STobin Davis /* EAPD */ 89982f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 900c9b443d4STobin Davis { } /* end */ 901c9b443d4STobin Davis }; 902c9b443d4STobin Davis 9035218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 9045218c892SJiang Zhe /* Int Mic, Mic */ 9055218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9065218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9075218c892SJiang Zhe /* Line In,HP, Amp */ 9085218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9095218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9105218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9115218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9125218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9135218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9145218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9155218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9165218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 9175218c892SJiang Zhe /* Record selector: Int mic */ 9185218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9195218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9205218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9215218c892SJiang Zhe /* SPDIF route: PCM */ 922cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9235218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9245218c892SJiang Zhe /* EAPD */ 9255218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9265218c892SJiang Zhe { } /* end */ 9275218c892SJiang Zhe }; 9287f29673bSTobin Davis 9297f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9307f29673bSTobin Davis /* pin sensing on HP jack */ 9317f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 932d3091fadSTakashi Iwai { } /* end */ 9337f29673bSTobin Davis }; 9347f29673bSTobin Davis 9357f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9367f29673bSTobin Davis /* pin sensing on HP jack */ 9377f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 938d3091fadSTakashi Iwai { } /* end */ 9397f29673bSTobin Davis }; 9407f29673bSTobin Davis 941c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 942c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 943c9b443d4STobin Davis * configuration. 944c9b443d4STobin Davis */ 945c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 946c9b443d4STobin Davis .num_items = 5, 947c9b443d4STobin Davis .items = { 948c9b443d4STobin Davis { "MIXER", 0x0 }, 949c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 950c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 951c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 952c9b443d4STobin Davis { "CD pin", 0x4 }, 953c9b443d4STobin Davis }, 954c9b443d4STobin Davis }; 955c9b443d4STobin Davis 956c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 957c9b443d4STobin Davis 958c9b443d4STobin Davis /* Output controls */ 959c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 960c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9617f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9627f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9637f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9647f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 965c9b443d4STobin Davis 966c9b443d4STobin Davis /* Modes for retasking pin widgets */ 967c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 968c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 969c9b443d4STobin Davis 97082f30040STobin Davis /* EAPD Switch Control */ 97182f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 97282f30040STobin Davis 973c9b443d4STobin Davis /* Loopback mixer controls */ 974c9b443d4STobin Davis 9757f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9767f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9777f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9787f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9797f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9807f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9817f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9827f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9837f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9847f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 985c9b443d4STobin Davis { 986c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 987c9b443d4STobin Davis .name = "Input Source", 988c9b443d4STobin Davis .info = conexant_mux_enum_info, 989c9b443d4STobin Davis .get = conexant_mux_enum_get, 990c9b443d4STobin Davis .put = conexant_mux_enum_put, 991c9b443d4STobin Davis }, 992fb3409e7STobin Davis /* Audio input controls */ 993fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 994fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 995fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 996fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 997fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 998fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 999fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1000fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1001fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1002fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1003c9b443d4STobin Davis { } /* end */ 1004c9b443d4STobin Davis }; 1005c9b443d4STobin Davis 1006c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 10077f29673bSTobin Davis /* Set connections */ 10087f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10097f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10107f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1011c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1012c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10137f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1014c9b443d4STobin Davis 1015c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1016c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1017c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1018c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1019c9b443d4STobin Davis * control. 1020c9b443d4STobin Davis */ 1021cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1022cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1023c9b443d4STobin Davis 1024c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1025c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1026c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1027c9b443d4STobin Davis 1028c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1029c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1030c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1031c9b443d4STobin Davis * input/output buffers as needed. 1032c9b443d4STobin Davis */ 1033c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1034c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1035c9b443d4STobin Davis 1036c9b443d4STobin Davis /* Mute capture amp left and right */ 1037c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1038c9b443d4STobin Davis 1039c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1040c9b443d4STobin Davis * pin) 1041c9b443d4STobin Davis */ 1042c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10437f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1044c9b443d4STobin Davis 1045c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1046c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1047c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1048c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1049c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1050c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1051c9b443d4STobin Davis 1052c9b443d4STobin Davis { } 1053c9b443d4STobin Davis }; 1054c9b443d4STobin Davis #endif 1055c9b443d4STobin Davis 1056c9b443d4STobin Davis 1057c9b443d4STobin Davis /* initialize jack-sensing, too */ 1058c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1059c9b443d4STobin Davis { 1060c9b443d4STobin Davis conexant_init(codec); 1061c9b443d4STobin Davis cxt5045_hp_automute(codec); 1062c9b443d4STobin Davis return 0; 1063c9b443d4STobin Davis } 1064c9b443d4STobin Davis 1065c9b443d4STobin Davis 1066c9b443d4STobin Davis enum { 106715908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 106815908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 106915908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10705218c892SJiang Zhe CXT5045_BENQ, 10712de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1072c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1073c9b443d4STobin Davis CXT5045_TEST, 1074c9b443d4STobin Davis #endif 1075f5fcc13cSTakashi Iwai CXT5045_MODELS 1076c9b443d4STobin Davis }; 1077c9b443d4STobin Davis 1078f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 107915908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 108015908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 108115908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10825218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10832de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1084c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1085f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1086c9b443d4STobin Davis #endif 1087f5fcc13cSTakashi Iwai }; 1088c9b443d4STobin Davis 1089f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10902de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1091dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1092dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 10936a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10945218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 109515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 109615908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10979e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10989e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 109915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 110015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 110115908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1102dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1103dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 110415908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1105c9b443d4STobin Davis {} 1106c9b443d4STobin Davis }; 1107c9b443d4STobin Davis 1108c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1109c9b443d4STobin Davis { 1110c9b443d4STobin Davis struct conexant_spec *spec; 1111c9b443d4STobin Davis int board_config; 1112c9b443d4STobin Davis 1113c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1114c9b443d4STobin Davis if (!spec) 1115c9b443d4STobin Davis return -ENOMEM; 1116c9b443d4STobin Davis codec->spec = spec; 11179421f954STakashi Iwai codec->pin_amp_workaround = 1; 1118c9b443d4STobin Davis 1119c9b443d4STobin Davis spec->multiout.max_channels = 2; 1120c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1121c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1122c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1123c9b443d4STobin Davis spec->num_adc_nids = 1; 1124c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1125c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1126c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1127c9b443d4STobin Davis spec->num_mixers = 1; 1128c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1129c9b443d4STobin Davis spec->num_init_verbs = 1; 1130c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1131c9b443d4STobin Davis spec->spdif_route = 0; 11325cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), 11335cd57529STobin Davis spec->channel_mode = cxt5045_modes, 11345cd57529STobin Davis 1135c9b443d4STobin Davis 1136c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1137c9b443d4STobin Davis 1138f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1139f5fcc13cSTakashi Iwai cxt5045_models, 1140f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1141c9b443d4STobin Davis switch (board_config) { 114215908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11437f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1144c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1145c9b443d4STobin Davis spec->num_init_verbs = 2; 11467f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11477f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11487f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11497f29673bSTobin Davis break; 115015908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 115186376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11527f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11537f29673bSTobin Davis spec->num_init_verbs = 2; 11547f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1155c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1156c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1157c9b443d4STobin Davis break; 115815908c36SMarc Boucher default: 115915908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 116015908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 116115908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 116215908c36SMarc Boucher spec->num_init_verbs = 3; 116315908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 116415908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 116515908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 116615908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 116715908c36SMarc Boucher break; 11685218c892SJiang Zhe case CXT5045_BENQ: 11695218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11705218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11715218c892SJiang Zhe spec->num_init_verbs = 1; 11725218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11735218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11745218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11755218c892SJiang Zhe spec->num_mixers = 2; 11765218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11775218c892SJiang Zhe break; 11782de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11792de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11802de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11812de3c232SJiang zhe spec->num_init_verbs = 2; 11822de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11832de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11842de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11852de3c232SJiang zhe break; 1186c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1187c9b443d4STobin Davis case CXT5045_TEST: 1188c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1189c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1190c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 119115908c36SMarc Boucher break; 119215908c36SMarc Boucher 1193c9b443d4STobin Davis #endif 1194c9b443d4STobin Davis } 119548ecb7e8STakashi Iwai 1196031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1197031005f7STakashi Iwai case 0x103c: 11980b587fc4SDaniel T Chen case 0x1734: 11990b587fc4SDaniel T Chen /* HP & Fujitsu-Siemens laptops have really bad sound over 0dB 12000b587fc4SDaniel T Chen * on NID 0x17. Fix max PCM level to 0 dB 12010b587fc4SDaniel T Chen * (originally it has 0x2b steps with 0dB offset 0x14) 120248ecb7e8STakashi Iwai */ 120348ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 120448ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 120548ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 120648ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 120748ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1208031005f7STakashi Iwai break; 1209031005f7STakashi Iwai } 121048ecb7e8STakashi Iwai 1211c9b443d4STobin Davis return 0; 1212c9b443d4STobin Davis } 1213c9b443d4STobin Davis 1214c9b443d4STobin Davis 1215c9b443d4STobin Davis /* Conexant 5047 specific */ 121682f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1217c9b443d4STobin Davis 12185b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1219c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1220c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1221c9b443d4STobin Davis 12225cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 12235cd57529STobin Davis { 2, NULL }, 12245cd57529STobin Davis }; 1225c9b443d4STobin Davis 122682f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 122782f30040STobin Davis .num_items = 2, 122882f30040STobin Davis .items = { 122982f30040STobin Davis { "ExtMic", 0x2 }, 123082f30040STobin Davis { "Line-In", 0x1 }, 1231c9b443d4STobin Davis } 1232c9b443d4STobin Davis }; 1233c9b443d4STobin Davis 1234c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1235c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1236c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1237c9b443d4STobin Davis { 1238c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1239c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 124082f30040STobin Davis unsigned int bits; 1241c9b443d4STobin Davis 124282f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1243c9b443d4STobin Davis return 0; 1244c9b443d4STobin Davis 124582f30040STobin Davis /* toggle internal speakers mute depending of presence of 124682f30040STobin Davis * the headphone jack 124782f30040STobin Davis */ 124847fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12493b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12503b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12513b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12523b7523fcSTakashi Iwai */ 12535d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 125447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 125547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 125647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 125747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1258c9b443d4STobin Davis return 1; 1259c9b443d4STobin Davis } 1260c9b443d4STobin Davis 1261c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1262c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1263c9b443d4STobin Davis { 126482f30040STobin Davis struct conexant_spec *spec = codec->spec; 1265dd87da1cSTobin Davis unsigned int bits; 1266c9b443d4STobin Davis 1267d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1268dd87da1cSTobin Davis 126947fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12703b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12715d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 127247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1273c9b443d4STobin Davis } 1274c9b443d4STobin Davis 1275c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1276c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1277c9b443d4STobin Davis { 1278c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 12799f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12809f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1281c9b443d4STobin Davis {} 1282c9b443d4STobin Davis }; 1283c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 12849f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12859f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1286c9b443d4STobin Davis {} 1287c9b443d4STobin Davis }; 1288c9b443d4STobin Davis unsigned int present; 1289c9b443d4STobin Davis 1290d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1291c9b443d4STobin Davis if (present) 1292c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1293c9b443d4STobin Davis else 1294c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1295c9b443d4STobin Davis } 1296c9b443d4STobin Davis 1297c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1298c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1299c9b443d4STobin Davis unsigned int res) 1300c9b443d4STobin Davis { 13019f113e0eSMarc Boucher switch (res >> 26) { 1302c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1303c9b443d4STobin Davis cxt5047_hp_automute(codec); 1304c9b443d4STobin Davis break; 1305c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1306c9b443d4STobin Davis cxt5047_hp_automic(codec); 1307c9b443d4STobin Davis break; 1308c9b443d4STobin Davis } 1309c9b443d4STobin Davis } 1310c9b443d4STobin Davis 1311df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1312df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1313df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1314df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT), 1315c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1316c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1317c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1318c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 131982f30040STobin Davis { 132082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 132182f30040STobin Davis .name = "Master Playback Switch", 132282f30040STobin Davis .info = cxt_eapd_info, 132382f30040STobin Davis .get = cxt_eapd_get, 1324c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1325c9b443d4STobin Davis .private_value = 0x13, 1326c9b443d4STobin Davis }, 1327c9b443d4STobin Davis 1328c9b443d4STobin Davis {} 1329c9b443d4STobin Davis }; 1330c9b443d4STobin Davis 1331df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13323b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13335d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1334df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1335df481e41STakashi Iwai {} 1336df481e41STakashi Iwai }; 1337df481e41STakashi Iwai 1338df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1339c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1340c9b443d4STobin Davis { } /* end */ 1341c9b443d4STobin Davis }; 1342c9b443d4STobin Davis 1343c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1344c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1345c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1346c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1347c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13487f29673bSTobin Davis /* HP, Speaker */ 1349b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13505b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13515b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13527f29673bSTobin Davis /* Record selector: Mic */ 13537f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13547f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13557f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13567f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1357c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1358c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1359c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1360c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1361c9b443d4STobin Davis /* SPDIF route: PCM */ 1362c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 136382f30040STobin Davis /* Enable unsolicited events */ 136482f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 136582f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1366c9b443d4STobin Davis { } /* end */ 1367c9b443d4STobin Davis }; 1368c9b443d4STobin Davis 1369c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1370c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 13713b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1372c9b443d4STobin Davis {} 1373c9b443d4STobin Davis }; 1374c9b443d4STobin Davis 1375c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1376c9b443d4STobin Davis * configuration. 1377c9b443d4STobin Davis */ 1378c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1379c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 138082f30040STobin Davis .num_items = 4, 1381c9b443d4STobin Davis .items = { 138282f30040STobin Davis { "LINE1 pin", 0x0 }, 138382f30040STobin Davis { "MIC1 pin", 0x1 }, 138482f30040STobin Davis { "MIC2 pin", 0x2 }, 138582f30040STobin Davis { "CD pin", 0x3 }, 1386c9b443d4STobin Davis }, 1387c9b443d4STobin Davis }; 1388c9b443d4STobin Davis 1389c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1390c9b443d4STobin Davis 1391c9b443d4STobin Davis /* Output only controls */ 139282f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 139382f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 139482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 139582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1396c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1397c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1398c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1399c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 140082f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 140182f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 140282f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 140382f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1404c9b443d4STobin Davis 1405c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1406c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1407c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1408c9b443d4STobin Davis 140982f30040STobin Davis /* EAPD Switch Control */ 141082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 141182f30040STobin Davis 1412c9b443d4STobin Davis /* Loopback mixer controls */ 141382f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 141482f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 141582f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 141682f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 141782f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 141882f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 141982f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 142082f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1421c9b443d4STobin Davis 142282f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 142382f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 142482f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 142582f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 142682f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 142782f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 142882f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 142982f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1430c9b443d4STobin Davis { 1431c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1432c9b443d4STobin Davis .name = "Input Source", 1433c9b443d4STobin Davis .info = conexant_mux_enum_info, 1434c9b443d4STobin Davis .get = conexant_mux_enum_get, 1435c9b443d4STobin Davis .put = conexant_mux_enum_put, 1436c9b443d4STobin Davis }, 1437854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14389f113e0eSMarc Boucher 1439c9b443d4STobin Davis { } /* end */ 1440c9b443d4STobin Davis }; 1441c9b443d4STobin Davis 1442c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1443c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1444c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1445c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1446c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1447c9b443d4STobin Davis 1448c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1449c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1450c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1451c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1452c9b443d4STobin Davis * control. 1453c9b443d4STobin Davis */ 1454c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1455c9b443d4STobin Davis 1456c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1457c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1458c9b443d4STobin Davis */ 1459c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1460c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1463c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1464c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1465c9b443d4STobin Davis 1466c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1467c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1468c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1469c9b443d4STobin Davis * input/output buffers as needed. 1470c9b443d4STobin Davis */ 1471c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1472c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1473c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1474c9b443d4STobin Davis 1475c9b443d4STobin Davis /* Mute capture amp left and right */ 1476c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1477c9b443d4STobin Davis 1478c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1479c9b443d4STobin Davis * pin) 1480c9b443d4STobin Davis */ 1481c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1482c9b443d4STobin Davis 1483c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1484c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1485c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1486c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1487c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1488c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1489c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1490c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1491c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1492c9b443d4STobin Davis 1493c9b443d4STobin Davis { } 1494c9b443d4STobin Davis }; 1495c9b443d4STobin Davis #endif 1496c9b443d4STobin Davis 1497c9b443d4STobin Davis 1498c9b443d4STobin Davis /* initialize jack-sensing, too */ 1499c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1500c9b443d4STobin Davis { 1501c9b443d4STobin Davis conexant_init(codec); 1502c9b443d4STobin Davis cxt5047_hp_automute(codec); 1503c9b443d4STobin Davis return 0; 1504c9b443d4STobin Davis } 1505c9b443d4STobin Davis 1506c9b443d4STobin Davis 1507c9b443d4STobin Davis enum { 1508f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1509f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1510f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1511c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1512c9b443d4STobin Davis CXT5047_TEST, 1513c9b443d4STobin Davis #endif 1514f5fcc13cSTakashi Iwai CXT5047_MODELS 1515c9b443d4STobin Davis }; 1516c9b443d4STobin Davis 1517f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1518f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1519f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1520f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1521c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1522f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1523c9b443d4STobin Davis #endif 1524f5fcc13cSTakashi Iwai }; 1525c9b443d4STobin Davis 1526f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1527ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1528dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1529dea0a509STakashi Iwai CXT5047_LAPTOP), 1530f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1531c9b443d4STobin Davis {} 1532c9b443d4STobin Davis }; 1533c9b443d4STobin Davis 1534c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1535c9b443d4STobin Davis { 1536c9b443d4STobin Davis struct conexant_spec *spec; 1537c9b443d4STobin Davis int board_config; 1538c9b443d4STobin Davis 1539c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1540c9b443d4STobin Davis if (!spec) 1541c9b443d4STobin Davis return -ENOMEM; 1542c9b443d4STobin Davis codec->spec = spec; 15439421f954STakashi Iwai codec->pin_amp_workaround = 1; 1544c9b443d4STobin Davis 1545c9b443d4STobin Davis spec->multiout.max_channels = 2; 1546c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1547c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1548c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1549c9b443d4STobin Davis spec->num_adc_nids = 1; 1550c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1551c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1552c9b443d4STobin Davis spec->num_mixers = 1; 1553df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1554c9b443d4STobin Davis spec->num_init_verbs = 1; 1555c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1556c9b443d4STobin Davis spec->spdif_route = 0; 15575cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15585cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1559c9b443d4STobin Davis 1560c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1561c9b443d4STobin Davis 1562f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1563f5fcc13cSTakashi Iwai cxt5047_models, 1564f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1565c9b443d4STobin Davis switch (board_config) { 1566c9b443d4STobin Davis case CXT5047_LAPTOP: 1567df481e41STakashi Iwai spec->num_mixers = 2; 1568df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1569df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1570c9b443d4STobin Davis break; 1571c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1572df481e41STakashi Iwai spec->num_mixers = 2; 1573df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1574fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1575c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1576c9b443d4STobin Davis break; 1577c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 157882f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1579df481e41STakashi Iwai spec->num_mixers = 2; 1580df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1581c9b443d4STobin Davis spec->num_init_verbs = 2; 1582c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1583fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1584c9b443d4STobin Davis break; 1585c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1586c9b443d4STobin Davis case CXT5047_TEST: 1587c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1588c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1589c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1590fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1591c9b443d4STobin Davis #endif 1592c9b443d4STobin Davis } 1593dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1594c9b443d4STobin Davis return 0; 1595c9b443d4STobin Davis } 1596c9b443d4STobin Davis 1597461e2c78STakashi Iwai /* Conexant 5051 specific */ 1598461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1599461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1600461e2c78STakashi Iwai 1601461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1602461e2c78STakashi Iwai { 2, NULL }, 1603461e2c78STakashi Iwai }; 1604461e2c78STakashi Iwai 1605461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1606461e2c78STakashi Iwai { 1607461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1608461e2c78STakashi Iwai unsigned int pinctl; 160923d2df5bSTakashi Iwai /* headphone pin */ 161023d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 161123d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 161223d2df5bSTakashi Iwai pinctl); 161323d2df5bSTakashi Iwai /* speaker pin */ 1614461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1615461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1616461e2c78STakashi Iwai pinctl); 1617461e2c78STakashi Iwai } 1618461e2c78STakashi Iwai 1619461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1620461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1621461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1622461e2c78STakashi Iwai { 1623461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1624461e2c78STakashi Iwai 1625461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1626461e2c78STakashi Iwai return 0; 1627461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1628461e2c78STakashi Iwai return 1; 1629461e2c78STakashi Iwai } 1630461e2c78STakashi Iwai 1631461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1632461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1633461e2c78STakashi Iwai { 163479d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1635461e2c78STakashi Iwai unsigned int present; 1636461e2c78STakashi Iwai 1637faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 163879d7d533STakashi Iwai return; 1639d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1640461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1641461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1642461e2c78STakashi Iwai present ? 0x01 : 0x00); 1643461e2c78STakashi Iwai } 1644461e2c78STakashi Iwai 1645461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1646461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1647461e2c78STakashi Iwai { 1648461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1649461e2c78STakashi Iwai unsigned int present; 1650461e2c78STakashi Iwai hda_nid_t new_adc; 1651461e2c78STakashi Iwai 1652faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 165379d7d533STakashi Iwai return; 1654d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1655461e2c78STakashi Iwai if (present) 1656461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1657461e2c78STakashi Iwai else 1658461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1659461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1660461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1661461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1662888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 1663461e2c78STakashi Iwai spec->cur_adc = new_adc; 1664461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1665461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1666461e2c78STakashi Iwai spec->cur_adc_format); 1667461e2c78STakashi Iwai } 1668461e2c78STakashi Iwai } 1669461e2c78STakashi Iwai 1670461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1671461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1672461e2c78STakashi Iwai { 1673461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1674461e2c78STakashi Iwai 1675d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1676461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1677461e2c78STakashi Iwai } 1678461e2c78STakashi Iwai 1679461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1680461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1681461e2c78STakashi Iwai unsigned int res) 1682461e2c78STakashi Iwai { 1683acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1684461e2c78STakashi Iwai switch (res >> 26) { 1685461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1686461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1687461e2c78STakashi Iwai break; 1688461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1689461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1690461e2c78STakashi Iwai break; 1691461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1692461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1693461e2c78STakashi Iwai break; 1694461e2c78STakashi Iwai } 1695acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1696461e2c78STakashi Iwai } 1697461e2c78STakashi Iwai 16982c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1699461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1700461e2c78STakashi Iwai { 1701461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1702461e2c78STakashi Iwai .name = "Master Playback Switch", 1703461e2c78STakashi Iwai .info = cxt_eapd_info, 1704461e2c78STakashi Iwai .get = cxt_eapd_get, 1705461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1706461e2c78STakashi Iwai .private_value = 0x1a, 1707461e2c78STakashi Iwai }, 17082c7a3fb3STakashi Iwai {} 17092c7a3fb3STakashi Iwai }; 1710461e2c78STakashi Iwai 17112c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17122c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17132c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17142c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 17152c7a3fb3STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 17162c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17172c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1718461e2c78STakashi Iwai {} 1719461e2c78STakashi Iwai }; 1720461e2c78STakashi Iwai 1721461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1722461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1723461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1724461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1725461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1726461e2c78STakashi Iwai {} 1727461e2c78STakashi Iwai }; 1728461e2c78STakashi Iwai 172979d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 17304e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 17314e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 173279d7d533STakashi Iwai {} 173379d7d533STakashi Iwai }; 173479d7d533STakashi Iwai 1735cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = { 17365f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 17375f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1738cd9d95a5SKen Prox {} 1739cd9d95a5SKen Prox }; 1740cd9d95a5SKen Prox 1741faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1742faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1743faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1744faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1745faddaa5dSTakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1746faddaa5dSTakashi Iwai {} 1747faddaa5dSTakashi Iwai }; 1748faddaa5dSTakashi Iwai 1749461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1750461e2c78STakashi Iwai /* Line in, Mic */ 1751461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1752461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1753461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1754461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1755461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1756461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1757461e2c78STakashi Iwai /* SPK */ 1758461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1759461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1760461e2c78STakashi Iwai /* HP, Amp */ 1761461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1762461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1763461e2c78STakashi Iwai /* DAC1 */ 1764461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1765461e2c78STakashi Iwai /* Record selector: Int mic */ 1766461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1767461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1768461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1769461e2c78STakashi Iwai /* SPDIF route: PCM */ 1770461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1771461e2c78STakashi Iwai /* EAPD */ 1772461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1773461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1774461e2c78STakashi Iwai { } /* end */ 1775461e2c78STakashi Iwai }; 1776461e2c78STakashi Iwai 177779d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 177879d7d533STakashi Iwai /* Line in, Mic */ 177979d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 178079d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 178179d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 178279d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 178379d7d533STakashi Iwai /* SPK */ 178479d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 178579d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 178679d7d533STakashi Iwai /* HP, Amp */ 178779d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 178879d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 178979d7d533STakashi Iwai /* DAC1 */ 179079d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 179179d7d533STakashi Iwai /* Record selector: Int mic */ 179279d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 179379d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 179479d7d533STakashi Iwai /* SPDIF route: PCM */ 179579d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 179679d7d533STakashi Iwai /* EAPD */ 179779d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 179879d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 179979d7d533STakashi Iwai { } /* end */ 180079d7d533STakashi Iwai }; 180179d7d533STakashi Iwai 180227e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 180327e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 180427e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 180527e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 180627e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 180727e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 180827e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 180927e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 181027e08988SAristeu Sergio Rozanski Filho /* SPK */ 181127e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 181227e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 181327e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 181427e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 181527e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 181627e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 181727e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 181827e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 181927e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 182027e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 182127e08988SAristeu Sergio Rozanski Filho /* Record selector: Int mic */ 182227e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 182327e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 182427e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 182527e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 182627e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 182727e08988SAristeu Sergio Rozanski Filho /* EAPD */ 182827e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 182927e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 183027e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 183127e08988SAristeu Sergio Rozanski Filho { } /* end */ 183227e08988SAristeu Sergio Rozanski Filho }; 183327e08988SAristeu Sergio Rozanski Filho 1834cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = { 1835cd9d95a5SKen Prox /* Line in, Mic */ 183630ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1837cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1838cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1839cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1840cd9d95a5SKen Prox /* SPK */ 1841cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1842cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1843cd9d95a5SKen Prox /* HP, Amp */ 1844cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1845cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1846cd9d95a5SKen Prox /* DAC1 */ 1847cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1848cd9d95a5SKen Prox /* Record selector: Int mic */ 1849cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1850cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1851cd9d95a5SKen Prox /* SPDIF route: PCM */ 1852cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1853cd9d95a5SKen Prox /* EAPD */ 1854cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1855cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1856cd9d95a5SKen Prox { } /* end */ 1857cd9d95a5SKen Prox }; 1858cd9d95a5SKen Prox 18596953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 18606953e552STakashi Iwai unsigned int event) 18616953e552STakashi Iwai { 18626953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 18636953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 18646953e552STakashi Iwai AC_USRSP_EN | event); 18656953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 18666953e552STakashi Iwai conexant_add_jack(codec, nid, SND_JACK_MICROPHONE); 18676953e552STakashi Iwai conexant_report_jack(codec, nid); 18686953e552STakashi Iwai #endif 18696953e552STakashi Iwai } 18706953e552STakashi Iwai 1871461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1872461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1873461e2c78STakashi Iwai { 18746953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 18756953e552STakashi Iwai 1876461e2c78STakashi Iwai conexant_init(codec); 1877acf26c0cSUlrich Dangel conexant_init_jacks(codec); 18786953e552STakashi Iwai 18796953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 18806953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 18816953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 18826953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 18836953e552STakashi Iwai 1884461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1885461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1886461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1887461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1888461e2c78STakashi Iwai } 1889461e2c78STakashi Iwai return 0; 1890461e2c78STakashi Iwai } 1891461e2c78STakashi Iwai 1892461e2c78STakashi Iwai 1893461e2c78STakashi Iwai enum { 1894461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1895461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 189679d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 189727e08988SAristeu Sergio Rozanski Filho CXT5051_LENOVO_X200, /* Lenovo X200 laptop */ 1898cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1899faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1900461e2c78STakashi Iwai CXT5051_MODELS 1901461e2c78STakashi Iwai }; 1902461e2c78STakashi Iwai 1903461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1904461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1905461e2c78STakashi Iwai [CXT5051_HP] = "hp", 190679d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 190727e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 19085f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1909faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1910461e2c78STakashi Iwai }; 1911461e2c78STakashi Iwai 1912461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 191379d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 19141812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 19155f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 1916faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 1917461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1918461e2c78STakashi Iwai CXT5051_LAPTOP), 1919461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 192027e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 1921461e2c78STakashi Iwai {} 1922461e2c78STakashi Iwai }; 1923461e2c78STakashi Iwai 1924461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1925461e2c78STakashi Iwai { 1926461e2c78STakashi Iwai struct conexant_spec *spec; 1927461e2c78STakashi Iwai int board_config; 1928461e2c78STakashi Iwai 1929461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1930461e2c78STakashi Iwai if (!spec) 1931461e2c78STakashi Iwai return -ENOMEM; 1932461e2c78STakashi Iwai codec->spec = spec; 19339421f954STakashi Iwai codec->pin_amp_workaround = 1; 1934461e2c78STakashi Iwai 1935461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1936461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1937461e2c78STakashi Iwai 1938461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1939461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1940461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1941461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1942461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1943461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 19442c7a3fb3STakashi Iwai spec->num_mixers = 2; 19452c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 19462c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 1947461e2c78STakashi Iwai spec->num_init_verbs = 1; 1948461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1949461e2c78STakashi Iwai spec->spdif_route = 0; 1950461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1951461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1952461e2c78STakashi Iwai spec->cur_adc = 0; 1953461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1954461e2c78STakashi Iwai 195579d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 195679d7d533STakashi Iwai 1957461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1958461e2c78STakashi Iwai cxt5051_models, 1959461e2c78STakashi Iwai cxt5051_cfg_tbl); 1960faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 1961461e2c78STakashi Iwai switch (board_config) { 1962461e2c78STakashi Iwai case CXT5051_HP: 1963461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1964461e2c78STakashi Iwai break; 196579d7d533STakashi Iwai case CXT5051_HP_DV6736: 196679d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 196779d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 1968faddaa5dSTakashi Iwai spec->auto_mic = 0; 196979d7d533STakashi Iwai break; 197027e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 197127e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 1972461e2c78STakashi Iwai break; 1973cd9d95a5SKen Prox case CXT5051_F700: 1974cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 1975cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 1976faddaa5dSTakashi Iwai spec->auto_mic = 0; 1977faddaa5dSTakashi Iwai break; 1978faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 1979faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 1980faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 1981cd9d95a5SKen Prox break; 1982461e2c78STakashi Iwai } 1983461e2c78STakashi Iwai 1984461e2c78STakashi Iwai return 0; 1985461e2c78STakashi Iwai } 1986461e2c78STakashi Iwai 19870fb67e98SDaniel Drake /* Conexant 5066 specific */ 19880fb67e98SDaniel Drake 19890fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 19900fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 19910fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 19920fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT 0x21 19930fb67e98SDaniel Drake 1994dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 1995dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 1996dbaccc0cSDaniel Drake * the DC input range of the codec. */ 1997dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 1998dbaccc0cSDaniel Drake 19990fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = { 20000fb67e98SDaniel Drake { 2, NULL }, 20010fb67e98SDaniel Drake }; 20020fb67e98SDaniel Drake 20030fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 20040fb67e98SDaniel Drake { 20050fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 20060fb67e98SDaniel Drake unsigned int pinctl; 20070fb67e98SDaniel Drake 20080fb67e98SDaniel Drake snd_printdd("CXT5066: update speaker, hp_present=%d\n", 20090fb67e98SDaniel Drake spec->hp_present); 20100fb67e98SDaniel Drake 20110fb67e98SDaniel Drake /* Port A (HP) */ 20120fb67e98SDaniel Drake pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 20130fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20140fb67e98SDaniel Drake pinctl); 20150fb67e98SDaniel Drake 20160fb67e98SDaniel Drake /* Port D (HP/LO) */ 20170fb67e98SDaniel Drake pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 20180fb67e98SDaniel Drake ? spec->port_d_mode : 0; 20190fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20200fb67e98SDaniel Drake pinctl); 20210fb67e98SDaniel Drake 20220fb67e98SDaniel Drake /* CLASS_D AMP */ 20230fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 20240fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 20250fb67e98SDaniel Drake pinctl); 20260fb67e98SDaniel Drake 20270fb67e98SDaniel Drake if (spec->dell_automute) { 20280fb67e98SDaniel Drake /* DELL AIO Port Rule: PortA > PortD > IntSpk */ 20290fb67e98SDaniel Drake pinctl = (!(spec->hp_present & 1) && spec->cur_eapd) 20300fb67e98SDaniel Drake ? PIN_OUT : 0; 20310fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, 20320fb67e98SDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); 20330fb67e98SDaniel Drake } 20340fb67e98SDaniel Drake } 20350fb67e98SDaniel Drake 20360fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 20370fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 20380fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 20390fb67e98SDaniel Drake { 20400fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 20410fb67e98SDaniel Drake 20420fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 20430fb67e98SDaniel Drake return 0; 20440fb67e98SDaniel Drake 20450fb67e98SDaniel Drake cxt5066_update_speaker(codec); 20460fb67e98SDaniel Drake return 1; 20470fb67e98SDaniel Drake } 20480fb67e98SDaniel Drake 2049c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2050c4cfe66cSDaniel Drake .num_items = 3, 2051c4cfe66cSDaniel Drake .items = { 2052c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2053c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2054c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2055c4cfe66cSDaniel Drake }, 2056c4cfe66cSDaniel Drake }; 2057c4cfe66cSDaniel Drake 2058c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2059c4cfe66cSDaniel Drake { 2060c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2061c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2062c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2063c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2064c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2065c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2066c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2067c4cfe66cSDaniel Drake } 2068c4cfe66cSDaniel Drake 206975f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 207075f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 207175f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 207275f8991dSDaniel Drake * is happening when it is not. */ 207375f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 20740fb67e98SDaniel Drake { 2075dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 207675f8991dSDaniel Drake if (!spec->recording) 207775f8991dSDaniel Drake return; 20780fb67e98SDaniel Drake 2079c4cfe66cSDaniel Drake if (spec->dc_enable) { 2080c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2081c4cfe66cSDaniel Drake * through our special DC port */ 2082c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2083c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2084c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2085c4cfe66cSDaniel Drake 2086c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2087c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2088c4cfe66cSDaniel Drake {}, 2089c4cfe66cSDaniel Drake }; 2090c4cfe66cSDaniel Drake 2091c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2092c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2093c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2094c4cfe66cSDaniel Drake return; 2095c4cfe66cSDaniel Drake } 2096c4cfe66cSDaniel Drake 2097c4cfe66cSDaniel Drake /* disable DC (port F) */ 2098c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2099c4cfe66cSDaniel Drake 210075f8991dSDaniel Drake /* external mic, port B */ 210175f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 210275f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 21030fb67e98SDaniel Drake 210475f8991dSDaniel Drake /* internal mic, port C */ 210575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 210675f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 210775f8991dSDaniel Drake } 21080fb67e98SDaniel Drake 210975f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 211075f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 211175f8991dSDaniel Drake { 211275f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 21130fb67e98SDaniel Drake unsigned int present; 21140fb67e98SDaniel Drake 2115c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2116c4cfe66cSDaniel Drake return; 2117c4cfe66cSDaniel Drake 211875f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 211975f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 212075f8991dSDaniel Drake if (present) 21210fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 212275f8991dSDaniel Drake else 21230fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 212475f8991dSDaniel Drake 212575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 212675f8991dSDaniel Drake present ? 0 : 1); 212775f8991dSDaniel Drake spec->ext_mic_present = !!present; 212875f8991dSDaniel Drake 212975f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 21300fb67e98SDaniel Drake } 21310fb67e98SDaniel Drake 213295a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 213395a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 213495a618bdSEinar Rünkaru { 213595a618bdSEinar Rünkaru unsigned int present; 213695a618bdSEinar Rünkaru 213795a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 213895a618bdSEinar Rünkaru /* enable external mic, port B */ 213975f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 214095a618bdSEinar Rünkaru 214195a618bdSEinar Rünkaru /* switch to external mic input */ 214295a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 214395a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 214495a618bdSEinar Rünkaru 214595a618bdSEinar Rünkaru /* disable internal digital mic */ 214695a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 214795a618bdSEinar Rünkaru {} 214895a618bdSEinar Rünkaru }; 214995a618bdSEinar Rünkaru static struct hda_verb ext_mic_absent[] = { 215095a618bdSEinar Rünkaru /* enable internal mic, port C */ 215195a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 215295a618bdSEinar Rünkaru 215395a618bdSEinar Rünkaru /* switch to internal mic input */ 215495a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 215595a618bdSEinar Rünkaru 215695a618bdSEinar Rünkaru /* disable external mic, port B */ 215795a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 215895a618bdSEinar Rünkaru {} 215995a618bdSEinar Rünkaru }; 216095a618bdSEinar Rünkaru 216195a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 216295a618bdSEinar Rünkaru if (present) { 216395a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 216495a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 216595a618bdSEinar Rünkaru } else { 216695a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 216795a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 216895a618bdSEinar Rünkaru } 216995a618bdSEinar Rünkaru } 217095a618bdSEinar Rünkaru 2171*cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2172*cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2173*cfd3d8dcSGreg Alexander { 2174*cfd3d8dcSGreg Alexander unsigned int present; 2175*cfd3d8dcSGreg Alexander 2176*cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2177*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2178*cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2179*cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2180*cfd3d8dcSGreg Alexander {} 2181*cfd3d8dcSGreg Alexander }; 2182*cfd3d8dcSGreg Alexander static struct hda_verb ext_mic_absent[] = { 2183*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2184*cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2185*cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2186*cfd3d8dcSGreg Alexander {} 2187*cfd3d8dcSGreg Alexander }; 2188*cfd3d8dcSGreg Alexander 2189*cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2190*cfd3d8dcSGreg Alexander if (present) { 2191*cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2192*cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2193*cfd3d8dcSGreg Alexander } else { 2194*cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2195*cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2196*cfd3d8dcSGreg Alexander } 2197*cfd3d8dcSGreg Alexander } 2198*cfd3d8dcSGreg Alexander 21990fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 22000fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 22010fb67e98SDaniel Drake { 22020fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 22030fb67e98SDaniel Drake unsigned int portA, portD; 22040fb67e98SDaniel Drake 22050fb67e98SDaniel Drake /* Port A */ 2206d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 22070fb67e98SDaniel Drake 22080fb67e98SDaniel Drake /* Port D */ 2209d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 22100fb67e98SDaniel Drake 22110fb67e98SDaniel Drake spec->hp_present = !!(portA | portD); 22120fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 22130fb67e98SDaniel Drake portA, portD, spec->hp_present); 22140fb67e98SDaniel Drake cxt5066_update_speaker(codec); 22150fb67e98SDaniel Drake } 22160fb67e98SDaniel Drake 22170fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 221875f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 22190fb67e98SDaniel Drake { 2220c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 22210fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 22220fb67e98SDaniel Drake switch (res >> 26) { 22230fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 22240fb67e98SDaniel Drake cxt5066_hp_automute(codec); 22250fb67e98SDaniel Drake break; 22260fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2227c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2228c4cfe66cSDaniel Drake if (!spec->dc_enable) 222975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 22300fb67e98SDaniel Drake break; 22310fb67e98SDaniel Drake } 22320fb67e98SDaniel Drake } 22330fb67e98SDaniel Drake 223495a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 223595a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res) 223695a618bdSEinar Rünkaru { 223795a618bdSEinar Rünkaru snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26); 223895a618bdSEinar Rünkaru switch (res >> 26) { 223995a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 224095a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 224195a618bdSEinar Rünkaru break; 224295a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 224395a618bdSEinar Rünkaru cxt5066_vostro_automic(codec); 224495a618bdSEinar Rünkaru break; 224595a618bdSEinar Rünkaru } 224695a618bdSEinar Rünkaru } 224795a618bdSEinar Rünkaru 2248*cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */ 2249*cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res) 2250*cfd3d8dcSGreg Alexander { 2251*cfd3d8dcSGreg Alexander snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26); 2252*cfd3d8dcSGreg Alexander switch (res >> 26) { 2253*cfd3d8dcSGreg Alexander case CONEXANT_HP_EVENT: 2254*cfd3d8dcSGreg Alexander cxt5066_hp_automute(codec); 2255*cfd3d8dcSGreg Alexander break; 2256*cfd3d8dcSGreg Alexander case CONEXANT_MIC_EVENT: 2257*cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 2258*cfd3d8dcSGreg Alexander break; 2259*cfd3d8dcSGreg Alexander } 2260*cfd3d8dcSGreg Alexander } 2261*cfd3d8dcSGreg Alexander 22620fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 22630fb67e98SDaniel Drake .num_items = 5, 22640fb67e98SDaniel Drake .items = { 22650fb67e98SDaniel Drake { "0dB", 0 }, 22660fb67e98SDaniel Drake { "10dB", 1 }, 22670fb67e98SDaniel Drake { "20dB", 2 }, 22680fb67e98SDaniel Drake { "30dB", 3 }, 22690fb67e98SDaniel Drake { "40dB", 4 }, 22700fb67e98SDaniel Drake }, 22710fb67e98SDaniel Drake }; 22720fb67e98SDaniel Drake 2273*cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2274c4cfe66cSDaniel Drake { 2275c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2276*cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2277c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2278c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2279c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 2280*cfd3d8dcSGreg Alexander if (spec->ideapad) { 2281*cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2282*cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2283*cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2284*cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2285*cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2286*cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2287*cfd3d8dcSGreg Alexander } 2288c4cfe66cSDaniel Drake } 2289c4cfe66cSDaniel Drake 22900fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 22910fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 22920fb67e98SDaniel Drake { 22930fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 22940fb67e98SDaniel Drake } 22950fb67e98SDaniel Drake 22960fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 22970fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 22980fb67e98SDaniel Drake { 22990fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2300c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2301c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 23020fb67e98SDaniel Drake return 0; 23030fb67e98SDaniel Drake } 23040fb67e98SDaniel Drake 23050fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 23060fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 23070fb67e98SDaniel Drake { 23080fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2309c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23100fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 23110fb67e98SDaniel Drake unsigned int idx; 23120fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 23130fb67e98SDaniel Drake if (idx >= imux->num_items) 23140fb67e98SDaniel Drake idx = imux->num_items - 1; 23150fb67e98SDaniel Drake 2316c4cfe66cSDaniel Drake spec->mic_boost = idx; 2317c4cfe66cSDaniel Drake if (!spec->dc_enable) 2318c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2319c4cfe66cSDaniel Drake return 1; 2320c4cfe66cSDaniel Drake } 23210fb67e98SDaniel Drake 2322c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2323c4cfe66cSDaniel Drake { 2324c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2325c4cfe66cSDaniel Drake /* disable gain */ 2326c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2327c4cfe66cSDaniel Drake 2328c4cfe66cSDaniel Drake /* switch to DC input */ 2329c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2330c4cfe66cSDaniel Drake {} 2331c4cfe66cSDaniel Drake }; 2332c4cfe66cSDaniel Drake 2333c4cfe66cSDaniel Drake /* configure as input source */ 2334c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2335c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2336c4cfe66cSDaniel Drake } 2337c4cfe66cSDaniel Drake 2338c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2339c4cfe66cSDaniel Drake { 2340c4cfe66cSDaniel Drake /* reconfigure input source */ 2341c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2342c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2343c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2344c4cfe66cSDaniel Drake } 2345c4cfe66cSDaniel Drake 2346c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2347c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2348c4cfe66cSDaniel Drake { 2349c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2350c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2351c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2352c4cfe66cSDaniel Drake return 0; 2353c4cfe66cSDaniel Drake } 2354c4cfe66cSDaniel Drake 2355c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2356c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2357c4cfe66cSDaniel Drake { 2358c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2359c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2360c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2361c4cfe66cSDaniel Drake 2362c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2363c4cfe66cSDaniel Drake return 0; 2364c4cfe66cSDaniel Drake 2365c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2366c4cfe66cSDaniel Drake if (dc_enable) 2367c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2368c4cfe66cSDaniel Drake else 2369c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2370c4cfe66cSDaniel Drake 2371c4cfe66cSDaniel Drake return 1; 2372c4cfe66cSDaniel Drake } 2373c4cfe66cSDaniel Drake 2374c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2375c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2376c4cfe66cSDaniel Drake { 2377c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2378c4cfe66cSDaniel Drake } 2379c4cfe66cSDaniel Drake 2380c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2381c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2382c4cfe66cSDaniel Drake { 2383c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2384c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2385c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2386c4cfe66cSDaniel Drake return 0; 2387c4cfe66cSDaniel Drake } 2388c4cfe66cSDaniel Drake 2389c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2390c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2391c4cfe66cSDaniel Drake { 2392c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2393c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2394c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2395c4cfe66cSDaniel Drake unsigned int idx; 2396c4cfe66cSDaniel Drake 2397c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2398c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2399c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2400c4cfe66cSDaniel Drake 2401c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2402c4cfe66cSDaniel Drake if (spec->dc_enable) 2403c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 24040fb67e98SDaniel Drake return 1; 24050fb67e98SDaniel Drake } 24060fb67e98SDaniel Drake 240775f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 240875f8991dSDaniel Drake { 240975f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 241075f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 241175f8991dSDaniel Drake * recording LED comes on. */ 241275f8991dSDaniel Drake spec->recording = 1; 241375f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 241475f8991dSDaniel Drake } 241575f8991dSDaniel Drake 241675f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 241775f8991dSDaniel Drake { 241875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 241975f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 242075f8991dSDaniel Drake /* disable external mic, port B */ 242175f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 242275f8991dSDaniel Drake 242375f8991dSDaniel Drake /* disble internal mic, port C */ 242475f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2425c4cfe66cSDaniel Drake 2426c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2427c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 242875f8991dSDaniel Drake {}, 242975f8991dSDaniel Drake }; 243075f8991dSDaniel Drake 243175f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 243275f8991dSDaniel Drake spec->recording = 0; 243375f8991dSDaniel Drake } 243475f8991dSDaniel Drake 24350fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 24360fb67e98SDaniel Drake .num_items = 4, 24370fb67e98SDaniel Drake .items = { 24380fb67e98SDaniel Drake { "Mic B", 0 }, 24390fb67e98SDaniel Drake { "Mic C", 1 }, 24400fb67e98SDaniel Drake { "Mic E", 2 }, 24410fb67e98SDaniel Drake { "Mic F", 3 }, 24420fb67e98SDaniel Drake }, 24430fb67e98SDaniel Drake }; 24440fb67e98SDaniel Drake 24450fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 24460fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 24470fb67e98SDaniel Drake .values = { 24480fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 24490fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 24500fb67e98SDaniel Drake 0 24510fb67e98SDaniel Drake }, 24520fb67e98SDaniel Drake }; 24530fb67e98SDaniel Drake 24540fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 24550fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 24560fb67e98SDaniel Drake .values = { 24570fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 24580fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 24590fb67e98SDaniel Drake 0 24600fb67e98SDaniel Drake }, 24610fb67e98SDaniel Drake }; 24620fb67e98SDaniel Drake 24630fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 24640fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 24650fb67e98SDaniel Drake {} 24660fb67e98SDaniel Drake }; 24670fb67e98SDaniel Drake 24680fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 24690fb67e98SDaniel Drake { 24700fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 24710fb67e98SDaniel Drake .name = "Master Playback Volume", 24720fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 24730fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 24740fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 24755e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 24760fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 24770fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 24780fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 24790fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 24800fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 24810fb67e98SDaniel Drake .private_value = 24820fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 24830fb67e98SDaniel Drake }, 24840fb67e98SDaniel Drake {} 24850fb67e98SDaniel Drake }; 24860fb67e98SDaniel Drake 2487c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2488c4cfe66cSDaniel Drake { 2489c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2490c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2491c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2492c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2493c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2494c4cfe66cSDaniel Drake }, 2495c4cfe66cSDaniel Drake { 2496c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2497c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2498c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2499c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2500c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2501c4cfe66cSDaniel Drake }, 2502c4cfe66cSDaniel Drake {} 2503c4cfe66cSDaniel Drake }; 2504c4cfe66cSDaniel Drake 25050fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 25060fb67e98SDaniel Drake { 25070fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 25080fb67e98SDaniel Drake .name = "Master Playback Switch", 25090fb67e98SDaniel Drake .info = cxt_eapd_info, 25100fb67e98SDaniel Drake .get = cxt_eapd_get, 25110fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 25120fb67e98SDaniel Drake .private_value = 0x1d, 25130fb67e98SDaniel Drake }, 25140fb67e98SDaniel Drake 25150fb67e98SDaniel Drake { 25160fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2517c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 25180fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 25190fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 25200fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 25210fb67e98SDaniel Drake }, 25220fb67e98SDaniel Drake 25230fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 25240fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 25250fb67e98SDaniel Drake {} 25260fb67e98SDaniel Drake }; 25270fb67e98SDaniel Drake 2528254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2529254bba6aSEinar Rünkaru { 2530254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2531254bba6aSEinar Rünkaru .name = "Int Mic Boost Capture Enum", 2532254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2533254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2534254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2535254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2536254bba6aSEinar Rünkaru }, 2537c0f8faf0SEinar Rünkaru HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT), 2538254bba6aSEinar Rünkaru {} 2539254bba6aSEinar Rünkaru }; 2540254bba6aSEinar Rünkaru 25410fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 25420fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 25430fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 25440fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 25450fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 25460fb67e98SDaniel Drake 25470fb67e98SDaniel Drake /* Speakers */ 25480fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 25490fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 25500fb67e98SDaniel Drake 25510fb67e98SDaniel Drake /* HP, Amp */ 25520fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 25530fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 25540fb67e98SDaniel Drake 25550fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 25560fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 25570fb67e98SDaniel Drake 25580fb67e98SDaniel Drake /* DAC1 */ 25590fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 25600fb67e98SDaniel Drake 25610fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 25620fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 25630fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 25640fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 25650fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 25660fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 25670fb67e98SDaniel Drake 25680fb67e98SDaniel Drake /* no digital microphone support yet */ 25690fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 25700fb67e98SDaniel Drake 25710fb67e98SDaniel Drake /* Audio input selector */ 25720fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 25730fb67e98SDaniel Drake 25740fb67e98SDaniel Drake /* SPDIF route: PCM */ 25750fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 25760fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 25770fb67e98SDaniel Drake 25780fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 25790fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 25800fb67e98SDaniel Drake 25810fb67e98SDaniel Drake /* EAPD */ 25820fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 25830fb67e98SDaniel Drake 25840fb67e98SDaniel Drake /* not handling these yet */ 25850fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25860fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25870fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25880fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25890fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25900fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25910fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25920fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 25930fb67e98SDaniel Drake { } /* end */ 25940fb67e98SDaniel Drake }; 25950fb67e98SDaniel Drake 25960fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 25970fb67e98SDaniel Drake /* Port A: headphones */ 25980fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 25990fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26000fb67e98SDaniel Drake 26010fb67e98SDaniel Drake /* Port B: external microphone */ 260275f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26030fb67e98SDaniel Drake 26040fb67e98SDaniel Drake /* Port C: internal microphone */ 260575f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26060fb67e98SDaniel Drake 26070fb67e98SDaniel Drake /* Port D: unused */ 26080fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26090fb67e98SDaniel Drake 26100fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 26110fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26120fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 26130fb67e98SDaniel Drake 2614c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 26150fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26160fb67e98SDaniel Drake 26170fb67e98SDaniel Drake /* Port G: internal speakers */ 26180fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 26190fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 26200fb67e98SDaniel Drake 26210fb67e98SDaniel Drake /* DAC1 */ 26220fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 26230fb67e98SDaniel Drake 26240fb67e98SDaniel Drake /* DAC2: unused */ 26250fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 26260fb67e98SDaniel Drake 26270fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 26280fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26290fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 26300fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26310fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 26320fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26330fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 26340fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26350fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 26360fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 26370fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 26380fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 26390fb67e98SDaniel Drake 26400fb67e98SDaniel Drake /* Disable digital microphone port */ 26410fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26420fb67e98SDaniel Drake 26430fb67e98SDaniel Drake /* Audio input selectors */ 26440fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 26450fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 26460fb67e98SDaniel Drake 26470fb67e98SDaniel Drake /* Disable SPDIF */ 26480fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26490fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 26500fb67e98SDaniel Drake 26510fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 26520fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 26530fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 26540fb67e98SDaniel Drake { } /* end */ 26550fb67e98SDaniel Drake }; 26560fb67e98SDaniel Drake 265795a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = { 265895a618bdSEinar Rünkaru /* Port A: headphones */ 265995a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 266095a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 266195a618bdSEinar Rünkaru 266295a618bdSEinar Rünkaru /* Port B: external microphone */ 266395a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 266495a618bdSEinar Rünkaru 266595a618bdSEinar Rünkaru /* Port C: unused */ 266695a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 266795a618bdSEinar Rünkaru 266895a618bdSEinar Rünkaru /* Port D: unused */ 266995a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 267095a618bdSEinar Rünkaru 267195a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 267295a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 267395a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 267495a618bdSEinar Rünkaru 267595a618bdSEinar Rünkaru /* Port F: unused */ 267695a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 267795a618bdSEinar Rünkaru 267895a618bdSEinar Rünkaru /* Port G: internal speakers */ 267995a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 268095a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 268195a618bdSEinar Rünkaru 268295a618bdSEinar Rünkaru /* DAC1 */ 268395a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 268495a618bdSEinar Rünkaru 268595a618bdSEinar Rünkaru /* DAC2: unused */ 268695a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 268795a618bdSEinar Rünkaru 268895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 268995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 269095a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 269195a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 269295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 269395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 269495a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 269595a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 269695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 269795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 269895a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 269995a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 270095a618bdSEinar Rünkaru 270195a618bdSEinar Rünkaru /* Digital microphone port */ 270295a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 270395a618bdSEinar Rünkaru 270495a618bdSEinar Rünkaru /* Audio input selectors */ 270595a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 270695a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 270795a618bdSEinar Rünkaru 270895a618bdSEinar Rünkaru /* Disable SPDIF */ 270995a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 271095a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 271195a618bdSEinar Rünkaru 271295a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 271395a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 271495a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 271595a618bdSEinar Rünkaru { } /* end */ 271695a618bdSEinar Rünkaru }; 271795a618bdSEinar Rünkaru 2718*cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = { 2719*cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2720*cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2721*cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2722*cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2723*cfd3d8dcSGreg Alexander 2724*cfd3d8dcSGreg Alexander /* Speakers */ 2725*cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2726*cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2727*cfd3d8dcSGreg Alexander 2728*cfd3d8dcSGreg Alexander /* HP, Amp */ 2729*cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2730*cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2731*cfd3d8dcSGreg Alexander 2732*cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2733*cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2734*cfd3d8dcSGreg Alexander 2735*cfd3d8dcSGreg Alexander /* DAC1 */ 2736*cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2737*cfd3d8dcSGreg Alexander 2738*cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2739*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2740*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2741*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2742*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2743*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2744*cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2745*cfd3d8dcSGreg Alexander 2746*cfd3d8dcSGreg Alexander /* Audio input selector */ 2747*cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2748*cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2749*cfd3d8dcSGreg Alexander 2750*cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2751*cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2752*cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2753*cfd3d8dcSGreg Alexander 2754*cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2755*cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2756*cfd3d8dcSGreg Alexander 2757*cfd3d8dcSGreg Alexander /* internal microphone */ 2758*cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 2759*cfd3d8dcSGreg Alexander 2760*cfd3d8dcSGreg Alexander /* EAPD */ 2761*cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2762*cfd3d8dcSGreg Alexander 2763*cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2764*cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2765*cfd3d8dcSGreg Alexander { } /* end */ 2766*cfd3d8dcSGreg Alexander }; 2767*cfd3d8dcSGreg Alexander 27680fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 27690fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27700fb67e98SDaniel Drake { } /* end */ 27710fb67e98SDaniel Drake }; 27720fb67e98SDaniel Drake 27730fb67e98SDaniel Drake /* initialize jack-sensing, too */ 27740fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 27750fb67e98SDaniel Drake { 2776254bba6aSEinar Rünkaru struct conexant_spec *spec = codec->spec; 2777254bba6aSEinar Rünkaru 27780fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 27790fb67e98SDaniel Drake conexant_init(codec); 27800fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 27810fb67e98SDaniel Drake cxt5066_hp_automute(codec); 2782254bba6aSEinar Rünkaru if (spec->dell_vostro) 2783254bba6aSEinar Rünkaru cxt5066_vostro_automic(codec); 2784*cfd3d8dcSGreg Alexander else if (spec->ideapad) 2785*cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 27860fb67e98SDaniel Drake } 2787c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 27880fb67e98SDaniel Drake return 0; 27890fb67e98SDaniel Drake } 27900fb67e98SDaniel Drake 279175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 279275f8991dSDaniel Drake { 2793c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 279475f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 279575f8991dSDaniel Drake conexant_init(codec); 279675f8991dSDaniel Drake cxt5066_hp_automute(codec); 2797c4cfe66cSDaniel Drake if (!spec->dc_enable) { 2798c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 279975f8991dSDaniel Drake cxt5066_olpc_automic(codec); 2800c4cfe66cSDaniel Drake } else { 2801c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2802c4cfe66cSDaniel Drake } 280375f8991dSDaniel Drake return 0; 280475f8991dSDaniel Drake } 280575f8991dSDaniel Drake 28060fb67e98SDaniel Drake enum { 28070fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 28080fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 28090fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 281095a618bdSEinar Rünkaru CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */ 2811*cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 28120fb67e98SDaniel Drake CXT5066_MODELS 28130fb67e98SDaniel Drake }; 28140fb67e98SDaniel Drake 28150fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = { 28160fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 28170fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 28180fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2819*cfd3d8dcSGreg Alexander [CXT5066_DELL_VOSTO] = "dell-vostro", 2820*cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 28210fb67e98SDaniel Drake }; 28220fb67e98SDaniel Drake 28230fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 28240fb67e98SDaniel Drake SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 28250fb67e98SDaniel Drake CXT5066_LAPTOP), 28260fb67e98SDaniel Drake SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 28270fb67e98SDaniel Drake CXT5066_DELL_LAPTOP), 2828798a8a15SDaniel Drake SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 282995a618bdSEinar Rünkaru SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO), 2830*cfd3d8dcSGreg Alexander SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD), 28310fb67e98SDaniel Drake {} 28320fb67e98SDaniel Drake }; 28330fb67e98SDaniel Drake 28340fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 28350fb67e98SDaniel Drake { 28360fb67e98SDaniel Drake struct conexant_spec *spec; 28370fb67e98SDaniel Drake int board_config; 28380fb67e98SDaniel Drake 28390fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 28400fb67e98SDaniel Drake if (!spec) 28410fb67e98SDaniel Drake return -ENOMEM; 28420fb67e98SDaniel Drake codec->spec = spec; 28430fb67e98SDaniel Drake 28440fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 284575f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 28460fb67e98SDaniel Drake 28470fb67e98SDaniel Drake spec->dell_automute = 0; 28480fb67e98SDaniel Drake spec->multiout.max_channels = 2; 28490fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 28500fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 28510fb67e98SDaniel Drake spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT; 28520fb67e98SDaniel Drake spec->num_adc_nids = 1; 28530fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 28540fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 28550fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 28560fb67e98SDaniel Drake 28570fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 28580fb67e98SDaniel Drake 28590fb67e98SDaniel Drake spec->num_init_verbs = 1; 28600fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 28610fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 28620fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 28630fb67e98SDaniel Drake spec->cur_adc = 0; 28640fb67e98SDaniel Drake spec->cur_adc_idx = 0; 28650fb67e98SDaniel Drake 28660fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 28670fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 28680fb67e98SDaniel Drake switch (board_config) { 28690fb67e98SDaniel Drake default: 28700fb67e98SDaniel Drake case CXT5066_LAPTOP: 28710fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 28720fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 28730fb67e98SDaniel Drake break; 28740fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 28750fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 28760fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 28770fb67e98SDaniel Drake 28780fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 28790fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 28800fb67e98SDaniel Drake spec->num_init_verbs++; 28810fb67e98SDaniel Drake spec->dell_automute = 1; 28820fb67e98SDaniel Drake break; 28830fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 288475f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 288575f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 28860fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 28870fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 2888c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 28890fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 28900fb67e98SDaniel Drake spec->port_d_mode = 0; 2891c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 28920fb67e98SDaniel Drake 28930fb67e98SDaniel Drake /* no S/PDIF out */ 28940fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 28950fb67e98SDaniel Drake 28960fb67e98SDaniel Drake /* input source automatically selected */ 28970fb67e98SDaniel Drake spec->input_mux = NULL; 289875f8991dSDaniel Drake 289975f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 290075f8991dSDaniel Drake * at the right time */ 290175f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 290275f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 29030fb67e98SDaniel Drake break; 290495a618bdSEinar Rünkaru case CXT5066_DELL_VOSTO: 290575f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 290695a618bdSEinar Rünkaru codec->patch_ops.unsol_event = cxt5066_vostro_event; 290795a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 290895a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 290995a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2910254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 291195a618bdSEinar Rünkaru spec->port_d_mode = 0; 2912254bba6aSEinar Rünkaru spec->dell_vostro = 1; 2913c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 2914c0f8faf0SEinar Rünkaru snd_hda_attach_beep_device(codec, 0x13); 291595a618bdSEinar Rünkaru 291695a618bdSEinar Rünkaru /* no S/PDIF out */ 291795a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 291895a618bdSEinar Rünkaru 291995a618bdSEinar Rünkaru /* input source automatically selected */ 292095a618bdSEinar Rünkaru spec->input_mux = NULL; 292195a618bdSEinar Rünkaru break; 2922*cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 2923*cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 2924*cfd3d8dcSGreg Alexander codec->patch_ops.unsol_event = cxt5066_ideapad_event; 2925*cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 2926*cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2927*cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 2928*cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 2929*cfd3d8dcSGreg Alexander spec->ideapad = 1; 2930*cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 2931*cfd3d8dcSGreg Alexander 2932*cfd3d8dcSGreg Alexander /* no S/PDIF out */ 2933*cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 2934*cfd3d8dcSGreg Alexander 2935*cfd3d8dcSGreg Alexander /* input source automatically selected */ 2936*cfd3d8dcSGreg Alexander spec->input_mux = NULL; 2937*cfd3d8dcSGreg Alexander break; 29380fb67e98SDaniel Drake } 29390fb67e98SDaniel Drake 29400fb67e98SDaniel Drake return 0; 29410fb67e98SDaniel Drake } 2942461e2c78STakashi Iwai 2943461e2c78STakashi Iwai /* 2944461e2c78STakashi Iwai */ 2945461e2c78STakashi Iwai 29461289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 294782f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 294882f30040STobin Davis .patch = patch_cxt5045 }, 294982f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 295082f30040STobin Davis .patch = patch_cxt5047 }, 2951461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 2952461e2c78STakashi Iwai .patch = patch_cxt5051 }, 29530fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 29540fb67e98SDaniel Drake .patch = patch_cxt5066 }, 295595a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 295695a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 2957c9b443d4STobin Davis {} /* terminator */ 2958c9b443d4STobin Davis }; 29591289e9e8STakashi Iwai 29601289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 29611289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 29621289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 29630fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 296495a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 29651289e9e8STakashi Iwai 29661289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 29671289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 29681289e9e8STakashi Iwai 29691289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 29701289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 29711289e9e8STakashi Iwai .owner = THIS_MODULE, 29721289e9e8STakashi Iwai }; 29731289e9e8STakashi Iwai 29741289e9e8STakashi Iwai static int __init patch_conexant_init(void) 29751289e9e8STakashi Iwai { 29761289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 29771289e9e8STakashi Iwai } 29781289e9e8STakashi Iwai 29791289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 29801289e9e8STakashi Iwai { 29811289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 29821289e9e8STakashi Iwai } 29831289e9e8STakashi Iwai 29841289e9e8STakashi Iwai module_init(patch_conexant_init) 29851289e9e8STakashi Iwai module_exit(patch_conexant_exit) 2986