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; 116cfd3d8dcSGreg Alexander unsigned int dell_vostro:1; 117cfd3d8dcSGreg Alexander unsigned int ideapad:1; 1187b2bfdbcSJens Taprogge unsigned int thinkpad:1; 119048e78a5SDavid Henningsson unsigned int hp_laptop:1; 12075f8991dSDaniel Drake 12175f8991dSDaniel Drake unsigned int ext_mic_present; 12275f8991dSDaniel Drake unsigned int recording; 12375f8991dSDaniel Drake void (*capture_prepare)(struct hda_codec *codec); 12475f8991dSDaniel Drake void (*capture_cleanup)(struct hda_codec *codec); 125c4cfe66cSDaniel Drake 126c4cfe66cSDaniel Drake /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors) 127c4cfe66cSDaniel Drake * through the microphone jack. 128c4cfe66cSDaniel Drake * When the user enables this through a mixer switch, both internal and 129c4cfe66cSDaniel Drake * external microphones are disabled. Gain is fixed at 0dB. In this mode, 130c4cfe66cSDaniel Drake * we also allow the bias to be configured through a separate mixer 131c4cfe66cSDaniel Drake * control. */ 132c4cfe66cSDaniel Drake unsigned int dc_enable; 133c4cfe66cSDaniel Drake unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */ 134c4cfe66cSDaniel Drake unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */ 1353507e2a8STakashi Iwai 1363507e2a8STakashi Iwai unsigned int beep_amp; 137c9b443d4STobin Davis }; 138c9b443d4STobin Davis 139c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 140c9b443d4STobin Davis struct hda_codec *codec, 141c9b443d4STobin Davis struct snd_pcm_substream *substream) 142c9b443d4STobin Davis { 143c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1449a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1459a08160bSTakashi Iwai hinfo); 146c9b443d4STobin Davis } 147c9b443d4STobin Davis 148c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 149c9b443d4STobin Davis struct hda_codec *codec, 150c9b443d4STobin Davis unsigned int stream_tag, 151c9b443d4STobin Davis unsigned int format, 152c9b443d4STobin Davis struct snd_pcm_substream *substream) 153c9b443d4STobin Davis { 154c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 155c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 156c9b443d4STobin Davis stream_tag, 157c9b443d4STobin Davis format, substream); 158c9b443d4STobin Davis } 159c9b443d4STobin Davis 160c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 161c9b443d4STobin Davis struct hda_codec *codec, 162c9b443d4STobin Davis struct snd_pcm_substream *substream) 163c9b443d4STobin Davis { 164c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 165c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 166c9b443d4STobin Davis } 167c9b443d4STobin Davis 168c9b443d4STobin Davis /* 169c9b443d4STobin Davis * Digital out 170c9b443d4STobin Davis */ 171c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 172c9b443d4STobin Davis struct hda_codec *codec, 173c9b443d4STobin Davis struct snd_pcm_substream *substream) 174c9b443d4STobin Davis { 175c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 176c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 177c9b443d4STobin Davis } 178c9b443d4STobin Davis 179c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 180c9b443d4STobin Davis struct hda_codec *codec, 181c9b443d4STobin Davis struct snd_pcm_substream *substream) 182c9b443d4STobin Davis { 183c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 184c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 185c9b443d4STobin Davis } 186c9b443d4STobin Davis 1876b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1886b97eb45STakashi Iwai struct hda_codec *codec, 1896b97eb45STakashi Iwai unsigned int stream_tag, 1906b97eb45STakashi Iwai unsigned int format, 1916b97eb45STakashi Iwai struct snd_pcm_substream *substream) 1926b97eb45STakashi Iwai { 1936b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 1946b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 1956b97eb45STakashi Iwai stream_tag, 1966b97eb45STakashi Iwai format, substream); 1976b97eb45STakashi Iwai } 1986b97eb45STakashi Iwai 199c9b443d4STobin Davis /* 200c9b443d4STobin Davis * Analog capture 201c9b443d4STobin Davis */ 202c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 203c9b443d4STobin Davis struct hda_codec *codec, 204c9b443d4STobin Davis unsigned int stream_tag, 205c9b443d4STobin Davis unsigned int format, 206c9b443d4STobin Davis struct snd_pcm_substream *substream) 207c9b443d4STobin Davis { 208c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 20975f8991dSDaniel Drake if (spec->capture_prepare) 21075f8991dSDaniel Drake spec->capture_prepare(codec); 211c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 212c9b443d4STobin Davis stream_tag, 0, format); 213c9b443d4STobin Davis return 0; 214c9b443d4STobin Davis } 215c9b443d4STobin Davis 216c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 217c9b443d4STobin Davis struct hda_codec *codec, 218c9b443d4STobin Davis struct snd_pcm_substream *substream) 219c9b443d4STobin Davis { 220c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 221888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 22275f8991dSDaniel Drake if (spec->capture_cleanup) 22375f8991dSDaniel Drake spec->capture_cleanup(codec); 224c9b443d4STobin Davis return 0; 225c9b443d4STobin Davis } 226c9b443d4STobin Davis 227c9b443d4STobin Davis 228c9b443d4STobin Davis 229c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 230c9b443d4STobin Davis .substreams = 1, 231c9b443d4STobin Davis .channels_min = 2, 232c9b443d4STobin Davis .channels_max = 2, 233c9b443d4STobin Davis .nid = 0, /* fill later */ 234c9b443d4STobin Davis .ops = { 235c9b443d4STobin Davis .open = conexant_playback_pcm_open, 236c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 237c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 238c9b443d4STobin Davis }, 239c9b443d4STobin Davis }; 240c9b443d4STobin Davis 241c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 242c9b443d4STobin Davis .substreams = 1, 243c9b443d4STobin Davis .channels_min = 2, 244c9b443d4STobin Davis .channels_max = 2, 245c9b443d4STobin Davis .nid = 0, /* fill later */ 246c9b443d4STobin Davis .ops = { 247c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 248c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 249c9b443d4STobin Davis }, 250c9b443d4STobin Davis }; 251c9b443d4STobin Davis 252c9b443d4STobin Davis 253c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 254c9b443d4STobin Davis .substreams = 1, 255c9b443d4STobin Davis .channels_min = 2, 256c9b443d4STobin Davis .channels_max = 2, 257c9b443d4STobin Davis .nid = 0, /* fill later */ 258c9b443d4STobin Davis .ops = { 259c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2606b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2616b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 262c9b443d4STobin Davis }, 263c9b443d4STobin Davis }; 264c9b443d4STobin Davis 265c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 266c9b443d4STobin Davis .substreams = 1, 267c9b443d4STobin Davis .channels_min = 2, 268c9b443d4STobin Davis .channels_max = 2, 269c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 270c9b443d4STobin Davis }; 271c9b443d4STobin Davis 272461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 273461e2c78STakashi Iwai struct hda_codec *codec, 274461e2c78STakashi Iwai unsigned int stream_tag, 275461e2c78STakashi Iwai unsigned int format, 276461e2c78STakashi Iwai struct snd_pcm_substream *substream) 277461e2c78STakashi Iwai { 278461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 279461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 280461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 281461e2c78STakashi Iwai spec->cur_adc_format = format; 282461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 283461e2c78STakashi Iwai return 0; 284461e2c78STakashi Iwai } 285461e2c78STakashi Iwai 286461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 287461e2c78STakashi Iwai struct hda_codec *codec, 288461e2c78STakashi Iwai struct snd_pcm_substream *substream) 289461e2c78STakashi Iwai { 290461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 291888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 292461e2c78STakashi Iwai spec->cur_adc = 0; 293461e2c78STakashi Iwai return 0; 294461e2c78STakashi Iwai } 295461e2c78STakashi Iwai 296461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 297461e2c78STakashi Iwai .substreams = 1, 298461e2c78STakashi Iwai .channels_min = 2, 299461e2c78STakashi Iwai .channels_max = 2, 300461e2c78STakashi Iwai .nid = 0, /* fill later */ 301461e2c78STakashi Iwai .ops = { 302461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 303461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 304461e2c78STakashi Iwai }, 305461e2c78STakashi Iwai }; 306461e2c78STakashi Iwai 307c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 308c9b443d4STobin Davis { 309c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 310c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 311c9b443d4STobin Davis 312c9b443d4STobin Davis codec->num_pcms = 1; 313c9b443d4STobin Davis codec->pcm_info = info; 314c9b443d4STobin Davis 315c9b443d4STobin Davis info->name = "CONEXANT Analog"; 316c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 317c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 318c9b443d4STobin Davis spec->multiout.max_channels; 319c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 320c9b443d4STobin Davis spec->multiout.dac_nids[0]; 321461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 322461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 323461e2c78STakashi Iwai cx5051_pcm_analog_capture; 324461e2c78STakashi Iwai else 325461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 326461e2c78STakashi Iwai conexant_pcm_analog_capture; 327c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 328c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 329c9b443d4STobin Davis 330c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 331c9b443d4STobin Davis info++; 332c9b443d4STobin Davis codec->num_pcms++; 333c9b443d4STobin Davis info->name = "Conexant Digital"; 3347ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 335c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 336c9b443d4STobin Davis conexant_pcm_digital_playback; 337c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 338c9b443d4STobin Davis spec->multiout.dig_out_nid; 339c9b443d4STobin Davis if (spec->dig_in_nid) { 340c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 341c9b443d4STobin Davis conexant_pcm_digital_capture; 342c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 343c9b443d4STobin Davis spec->dig_in_nid; 344c9b443d4STobin Davis } 345c9b443d4STobin Davis } 346c9b443d4STobin Davis 347c9b443d4STobin Davis return 0; 348c9b443d4STobin Davis } 349c9b443d4STobin Davis 350c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 351c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 352c9b443d4STobin Davis { 353c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 354c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 355c9b443d4STobin Davis 356c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 357c9b443d4STobin Davis } 358c9b443d4STobin Davis 359c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 360c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 361c9b443d4STobin Davis { 362c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 363c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 364c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 365c9b443d4STobin Davis 366c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 367c9b443d4STobin Davis return 0; 368c9b443d4STobin Davis } 369c9b443d4STobin Davis 370c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 371c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 372c9b443d4STobin Davis { 373c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 374c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 375c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 376c9b443d4STobin Davis 377c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 378c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 379c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 380c9b443d4STobin Davis } 381c9b443d4STobin Davis 3828c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 38395c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack) 38495c09099STakashi Iwai { 38595c09099STakashi Iwai struct conexant_jack *jacks = jack->private_data; 38695c09099STakashi Iwai jacks->nid = 0; 38795c09099STakashi Iwai jacks->jack = NULL; 38895c09099STakashi Iwai } 38995c09099STakashi Iwai 390bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 391bc7a166dSUlrich Dangel hda_nid_t nid, int type) 392bc7a166dSUlrich Dangel { 393bc7a166dSUlrich Dangel struct conexant_spec *spec; 394bc7a166dSUlrich Dangel struct conexant_jack *jack; 395bc7a166dSUlrich Dangel const char *name; 39695c09099STakashi Iwai int err; 397bc7a166dSUlrich Dangel 398bc7a166dSUlrich Dangel spec = codec->spec; 399bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 400bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 401bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 402bc7a166dSUlrich Dangel 403bc7a166dSUlrich Dangel if (!jack) 404bc7a166dSUlrich Dangel return -ENOMEM; 405bc7a166dSUlrich Dangel 406bc7a166dSUlrich Dangel jack->nid = nid; 407bc7a166dSUlrich Dangel jack->type = type; 408bc7a166dSUlrich Dangel 40995c09099STakashi Iwai err = snd_jack_new(codec->bus->card, name, type, &jack->jack); 41095c09099STakashi Iwai if (err < 0) 41195c09099STakashi Iwai return err; 41295c09099STakashi Iwai jack->jack->private_data = jack; 41395c09099STakashi Iwai jack->jack->private_free = conexant_free_jack_priv; 41495c09099STakashi Iwai return 0; 415bc7a166dSUlrich Dangel } 416bc7a166dSUlrich Dangel 417bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 418bc7a166dSUlrich Dangel { 419bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 420bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 421bc7a166dSUlrich Dangel 422bc7a166dSUlrich Dangel if (jacks) { 423bc7a166dSUlrich Dangel int i; 424bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 425bc7a166dSUlrich Dangel if (jacks->nid == nid) { 426bc7a166dSUlrich Dangel unsigned int present; 427d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, nid); 428bc7a166dSUlrich Dangel 429bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 430bc7a166dSUlrich Dangel 431bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 432bc7a166dSUlrich Dangel present); 433bc7a166dSUlrich Dangel } 434bc7a166dSUlrich Dangel jacks++; 435bc7a166dSUlrich Dangel } 436bc7a166dSUlrich Dangel } 437bc7a166dSUlrich Dangel } 438bc7a166dSUlrich Dangel 439bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 440bc7a166dSUlrich Dangel { 441bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 442bc7a166dSUlrich Dangel int i; 443bc7a166dSUlrich Dangel 444bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 445bc7a166dSUlrich Dangel const struct hda_verb *hv; 446bc7a166dSUlrich Dangel 447bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 448bc7a166dSUlrich Dangel while (hv->nid) { 449bc7a166dSUlrich Dangel int err = 0; 450bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 451bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 452bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 453bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 454bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 455bc7a166dSUlrich Dangel break; 456bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 457bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 458bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 459bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 460bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 461bc7a166dSUlrich Dangel break; 462bc7a166dSUlrich Dangel } 463bc7a166dSUlrich Dangel if (err < 0) 464bc7a166dSUlrich Dangel return err; 465bc7a166dSUlrich Dangel ++hv; 466bc7a166dSUlrich Dangel } 467bc7a166dSUlrich Dangel } 468bc7a166dSUlrich Dangel return 0; 469bc7a166dSUlrich Dangel 470bc7a166dSUlrich Dangel } 4715801f992STakashi Iwai #else 4725801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4735801f992STakashi Iwai { 4745801f992STakashi Iwai } 4755801f992STakashi Iwai 4765801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4775801f992STakashi Iwai { 4785801f992STakashi Iwai return 0; 4795801f992STakashi Iwai } 4805801f992STakashi Iwai #endif 481bc7a166dSUlrich Dangel 482c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 483c9b443d4STobin Davis { 484c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 485c9b443d4STobin Davis int i; 486c9b443d4STobin Davis 487c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 488c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 489c9b443d4STobin Davis return 0; 490c9b443d4STobin Davis } 491c9b443d4STobin Davis 492c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 493c9b443d4STobin Davis { 4948c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 495bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 496bc7a166dSUlrich Dangel if (spec->jacks.list) { 497bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 498bc7a166dSUlrich Dangel int i; 49995c09099STakashi Iwai for (i = 0; i < spec->jacks.used; i++, jacks++) { 50095c09099STakashi Iwai if (jacks->jack) 50195c09099STakashi Iwai snd_device_free(codec->bus->card, jacks->jack); 50295c09099STakashi Iwai } 503bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 504bc7a166dSUlrich Dangel } 505bc7a166dSUlrich Dangel #endif 506c0f8faf0SEinar Rünkaru snd_hda_detach_beep_device(codec); 507c9b443d4STobin Davis kfree(codec->spec); 508c9b443d4STobin Davis } 509c9b443d4STobin Davis 510b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = { 511b880c74aSTakashi Iwai { 512b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 513b880c74aSTakashi Iwai .name = "Capture Source", 514b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 515b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 516b880c74aSTakashi Iwai .put = conexant_mux_enum_put 517b880c74aSTakashi Iwai }, 518b880c74aSTakashi Iwai {} 519b880c74aSTakashi Iwai }; 520b880c74aSTakashi Iwai 5213507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5223507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */ 5233507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = { 5243507e2a8STakashi Iwai HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), 5253507e2a8STakashi Iwai HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), 5263507e2a8STakashi Iwai { } /* end */ 5273507e2a8STakashi Iwai }; 5283507e2a8STakashi Iwai #endif 5293507e2a8STakashi Iwai 530dd5746a8STakashi Iwai static const char *slave_vols[] = { 531dd5746a8STakashi Iwai "Headphone Playback Volume", 532dd5746a8STakashi Iwai "Speaker Playback Volume", 533dd5746a8STakashi Iwai NULL 534dd5746a8STakashi Iwai }; 535dd5746a8STakashi Iwai 536dd5746a8STakashi Iwai static const char *slave_sws[] = { 537dd5746a8STakashi Iwai "Headphone Playback Switch", 538dd5746a8STakashi Iwai "Speaker Playback Switch", 539dd5746a8STakashi Iwai NULL 540dd5746a8STakashi Iwai }; 541dd5746a8STakashi Iwai 542c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 543c9b443d4STobin Davis { 544c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 545c9b443d4STobin Davis unsigned int i; 546c9b443d4STobin Davis int err; 547c9b443d4STobin Davis 548c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 549c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 550c9b443d4STobin Davis if (err < 0) 551c9b443d4STobin Davis return err; 552c9b443d4STobin Davis } 553c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 554c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 555c9b443d4STobin Davis spec->multiout.dig_out_nid); 556c9b443d4STobin Davis if (err < 0) 557c9b443d4STobin Davis return err; 5589a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5599a08160bSTakashi Iwai &spec->multiout); 5609a08160bSTakashi Iwai if (err < 0) 5619a08160bSTakashi Iwai return err; 5629a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 563c9b443d4STobin Davis } 564c9b443d4STobin Davis if (spec->dig_in_nid) { 565c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 566c9b443d4STobin Davis if (err < 0) 567c9b443d4STobin Davis return err; 568c9b443d4STobin Davis } 569dd5746a8STakashi Iwai 570dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 571dd5746a8STakashi Iwai if (spec->vmaster_nid && 572dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 573dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 574dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 575dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 576dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 577dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 578dd5746a8STakashi Iwai if (err < 0) 579dd5746a8STakashi Iwai return err; 580dd5746a8STakashi Iwai } 581dd5746a8STakashi Iwai if (spec->vmaster_nid && 582dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 583dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 584dd5746a8STakashi Iwai NULL, slave_sws); 585dd5746a8STakashi Iwai if (err < 0) 586dd5746a8STakashi Iwai return err; 587dd5746a8STakashi Iwai } 588dd5746a8STakashi Iwai 589b880c74aSTakashi Iwai if (spec->input_mux) { 590b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 591b880c74aSTakashi Iwai if (err < 0) 592b880c74aSTakashi Iwai return err; 593b880c74aSTakashi Iwai } 594b880c74aSTakashi Iwai 5953507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 5963507e2a8STakashi Iwai /* create beep controls if needed */ 5973507e2a8STakashi Iwai if (spec->beep_amp) { 5983507e2a8STakashi Iwai struct snd_kcontrol_new *knew; 5993507e2a8STakashi Iwai for (knew = cxt_beep_mixer; knew->name; knew++) { 6003507e2a8STakashi Iwai struct snd_kcontrol *kctl; 6013507e2a8STakashi Iwai kctl = snd_ctl_new1(knew, codec); 6023507e2a8STakashi Iwai if (!kctl) 6033507e2a8STakashi Iwai return -ENOMEM; 6043507e2a8STakashi Iwai kctl->private_value = spec->beep_amp; 6053507e2a8STakashi Iwai err = snd_hda_ctl_add(codec, 0, kctl); 6063507e2a8STakashi Iwai if (err < 0) 6073507e2a8STakashi Iwai return err; 6083507e2a8STakashi Iwai } 6093507e2a8STakashi Iwai } 6103507e2a8STakashi Iwai #endif 6113507e2a8STakashi Iwai 612c9b443d4STobin Davis return 0; 613c9b443d4STobin Davis } 614c9b443d4STobin Davis 615697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 616697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state) 617697c373eSTakashi Iwai { 618697c373eSTakashi Iwai snd_hda_shutup_pins(codec); 619697c373eSTakashi Iwai return 0; 620697c373eSTakashi Iwai } 621697c373eSTakashi Iwai #endif 622697c373eSTakashi Iwai 623c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 624c9b443d4STobin Davis .build_controls = conexant_build_controls, 625c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 626c9b443d4STobin Davis .init = conexant_init, 627c9b443d4STobin Davis .free = conexant_free, 628697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE 629697c373eSTakashi Iwai .suspend = conexant_suspend, 630697c373eSTakashi Iwai #endif 631697c373eSTakashi Iwai .reboot_notify = snd_hda_shutup_pins, 632c9b443d4STobin Davis }; 633c9b443d4STobin Davis 6343507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP 6353507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \ 6363507e2a8STakashi Iwai ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) 6373507e2a8STakashi Iwai #else 6383507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */ 6393507e2a8STakashi Iwai #endif 6403507e2a8STakashi Iwai 641c9b443d4STobin Davis /* 642c9b443d4STobin Davis * EAPD control 643c9b443d4STobin Davis * the private value = nid | (invert << 8) 644c9b443d4STobin Davis */ 645c9b443d4STobin Davis 646a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 647c9b443d4STobin Davis 64882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 649c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 650c9b443d4STobin Davis { 651c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 652c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 653c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 654c9b443d4STobin Davis if (invert) 655c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 656c9b443d4STobin Davis else 657c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 658c9b443d4STobin Davis return 0; 65982f30040STobin Davis 660c9b443d4STobin Davis } 661c9b443d4STobin Davis 66282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 663c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 664c9b443d4STobin Davis { 665c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 666c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 667c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 668c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 669c9b443d4STobin Davis unsigned int eapd; 67082f30040STobin Davis 67168ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 672c9b443d4STobin Davis if (invert) 673c9b443d4STobin Davis eapd = !eapd; 67482beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 675c9b443d4STobin Davis return 0; 67682f30040STobin Davis 677c9b443d4STobin Davis spec->cur_eapd = eapd; 67882beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 679c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 680c9b443d4STobin Davis eapd ? 0x02 : 0x00); 681c9b443d4STobin Davis return 1; 682c9b443d4STobin Davis } 683c9b443d4STobin Davis 68486d72bdfSTakashi Iwai /* controls for test mode */ 68586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 68686d72bdfSTakashi Iwai 68782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 68882f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 68982f30040STobin Davis .info = cxt_eapd_info, \ 69082f30040STobin Davis .get = cxt_eapd_get, \ 69182f30040STobin Davis .put = cxt_eapd_put, \ 69282f30040STobin Davis .private_value = nid | (mask<<16) } 69382f30040STobin Davis 69482f30040STobin Davis 69582f30040STobin Davis 696c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 697c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 698c9b443d4STobin Davis { 699c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 700c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 701c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 702c9b443d4STobin Davis spec->num_channel_mode); 703c9b443d4STobin Davis } 704c9b443d4STobin Davis 705c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 706c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 707c9b443d4STobin Davis { 708c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 709c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 710c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 711c9b443d4STobin Davis spec->num_channel_mode, 712c9b443d4STobin Davis spec->multiout.max_channels); 713c9b443d4STobin Davis } 714c9b443d4STobin Davis 715c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 716c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 717c9b443d4STobin Davis { 718c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 719c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 720c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 721c9b443d4STobin Davis spec->num_channel_mode, 722c9b443d4STobin Davis &spec->multiout.max_channels); 723c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 724c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 725c9b443d4STobin Davis return err; 726c9b443d4STobin Davis } 727c9b443d4STobin Davis 728c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 729c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 730c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 731c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 732c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 733c9b443d4STobin Davis .private_value = nid | (dir<<16) } 734c9b443d4STobin Davis 73586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 73686d72bdfSTakashi Iwai 737c9b443d4STobin Davis /* Conexant 5045 specific */ 738c9b443d4STobin Davis 739c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 740c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 741c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 742cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 743c9b443d4STobin Davis 7445cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 7455cd57529STobin Davis { 2, NULL }, 7465cd57529STobin Davis }; 747c9b443d4STobin Davis 748c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 749c9b443d4STobin Davis .num_items = 2, 750c9b443d4STobin Davis .items = { 75182f30040STobin Davis { "IntMic", 0x1 }, 752f4beee94SJiang zhe { "ExtMic", 0x2 }, 753c9b443d4STobin Davis } 754c9b443d4STobin Davis }; 755c9b443d4STobin Davis 7565218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 75722e14130SLukasz Marcinowski .num_items = 5, 7585218c892SJiang Zhe .items = { 7595218c892SJiang Zhe { "IntMic", 0x1 }, 7605218c892SJiang Zhe { "ExtMic", 0x2 }, 7615218c892SJiang Zhe { "LineIn", 0x3 }, 76222e14130SLukasz Marcinowski { "CD", 0x4 }, 76322e14130SLukasz Marcinowski { "Mixer", 0x0 }, 7645218c892SJiang Zhe } 7655218c892SJiang Zhe }; 7665218c892SJiang Zhe 7672de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 7682de3c232SJiang zhe .num_items = 2, 7692de3c232SJiang zhe .items = { 7702de3c232SJiang zhe { "ExtMic", 0x1 }, 7712de3c232SJiang zhe { "IntMic", 0x2 }, 7722de3c232SJiang zhe } 7732de3c232SJiang zhe }; 7742de3c232SJiang zhe 775c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 776c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 777c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 778c9b443d4STobin Davis { 779c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 780c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 78182f30040STobin Davis unsigned int bits; 782c9b443d4STobin Davis 78382f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 784c9b443d4STobin Davis return 0; 785c9b443d4STobin Davis 78682f30040STobin Davis /* toggle internal speakers mute depending of presence of 78782f30040STobin Davis * the headphone jack 78882f30040STobin Davis */ 78947fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 79047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 79147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7927f29673bSTobin Davis 79347fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 79447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 79547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 796c9b443d4STobin Davis return 1; 797c9b443d4STobin Davis } 798c9b443d4STobin Davis 799c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 800cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 801cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 802cca3b371STakashi Iwai .values = { 803cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 804cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 805cca3b371STakashi Iwai 0 806cca3b371STakashi Iwai }, 807cca3b371STakashi Iwai }; 808c9b443d4STobin Davis 8097f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 8107f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 8117f29673bSTobin Davis { 8127f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 8137f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8147f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8157f29673bSTobin Davis {} 8167f29673bSTobin Davis }; 8177f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 8187f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 8197f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 8207f29673bSTobin Davis {} 8217f29673bSTobin Davis }; 8227f29673bSTobin Davis unsigned int present; 8237f29673bSTobin Davis 824d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x12); 8257f29673bSTobin Davis if (present) 8267f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 8277f29673bSTobin Davis else 8287f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 8297f29673bSTobin Davis } 8307f29673bSTobin Davis 831c9b443d4STobin Davis 832c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 833c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 834c9b443d4STobin Davis { 83582f30040STobin Davis struct conexant_spec *spec = codec->spec; 836dd87da1cSTobin Davis unsigned int bits; 837c9b443d4STobin Davis 838d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x11); 839dd87da1cSTobin Davis 84047fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 84147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 84247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 843c9b443d4STobin Davis } 844c9b443d4STobin Davis 845c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 846c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 847c9b443d4STobin Davis unsigned int res) 848c9b443d4STobin Davis { 849c9b443d4STobin Davis res >>= 26; 850c9b443d4STobin Davis switch (res) { 851c9b443d4STobin Davis case CONEXANT_HP_EVENT: 852c9b443d4STobin Davis cxt5045_hp_automute(codec); 853c9b443d4STobin Davis break; 8547f29673bSTobin Davis case CONEXANT_MIC_EVENT: 8557f29673bSTobin Davis cxt5045_hp_automic(codec); 8567f29673bSTobin Davis break; 8577f29673bSTobin Davis 858c9b443d4STobin Davis } 859c9b443d4STobin Davis } 860c9b443d4STobin Davis 861c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 862c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 863c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 864c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 865c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 866c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 867c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 868c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 869c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 870c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 871c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 872cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 873c9b443d4STobin Davis { 874c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 875c9b443d4STobin Davis .name = "Master Playback Switch", 87682f30040STobin Davis .info = cxt_eapd_info, 87782f30040STobin Davis .get = cxt_eapd_get, 878c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 87982f30040STobin Davis .private_value = 0x10, 880c9b443d4STobin Davis }, 881c9b443d4STobin Davis 882c9b443d4STobin Davis {} 883c9b443d4STobin Davis }; 884c9b443d4STobin Davis 8855218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 88622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT), 88722e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT), 88822e14130SLukasz Marcinowski HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT), 88922e14130SLukasz Marcinowski HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT), 89022e14130SLukasz Marcinowski 8915218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8925218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8935218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8945218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8955218c892SJiang Zhe 89622e14130SLukasz Marcinowski HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT), 89722e14130SLukasz Marcinowski HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT), 89822e14130SLukasz Marcinowski 8995218c892SJiang Zhe {} 9005218c892SJiang Zhe }; 9015218c892SJiang Zhe 9022de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 9032de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 9042de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 9052de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 9062de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 9072de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 9082de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 9092de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 9102de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 9112de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 9122de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 9132de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 9142de3c232SJiang zhe { 9152de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 9162de3c232SJiang zhe .name = "Master Playback Switch", 9172de3c232SJiang zhe .info = cxt_eapd_info, 9182de3c232SJiang zhe .get = cxt_eapd_get, 9192de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 9202de3c232SJiang zhe .private_value = 0x10, 9212de3c232SJiang zhe }, 9222de3c232SJiang zhe 9232de3c232SJiang zhe {} 9242de3c232SJiang zhe }; 9252de3c232SJiang zhe 926c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 927c9b443d4STobin Davis /* Line in, Mic */ 9284090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9297f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 930c9b443d4STobin Davis /* HP, Amp */ 931c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 932c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 93382f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 934c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 935c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 936c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 937c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 938c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 939c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 94082f30040STobin Davis /* Record selector: Int mic */ 9417f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 94282f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 943c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 944c9b443d4STobin Davis /* SPDIF route: PCM */ 945cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 946c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 947c9b443d4STobin Davis /* EAPD */ 94882f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 949c9b443d4STobin Davis { } /* end */ 950c9b443d4STobin Davis }; 951c9b443d4STobin Davis 9525218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 9535218c892SJiang Zhe /* Int Mic, Mic */ 9545218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9555218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 9565218c892SJiang Zhe /* Line In,HP, Amp */ 9575218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9585218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 9595218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 9605218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 9615218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 9625218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 9635218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 9645218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 9655218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 9665218c892SJiang Zhe /* Record selector: Int mic */ 9675218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 9685218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 9695218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 9705218c892SJiang Zhe /* SPDIF route: PCM */ 971cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9725218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 9735218c892SJiang Zhe /* EAPD */ 9745218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 9755218c892SJiang Zhe { } /* end */ 9765218c892SJiang Zhe }; 9777f29673bSTobin Davis 9787f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 9797f29673bSTobin Davis /* pin sensing on HP jack */ 9807f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 981d3091fadSTakashi Iwai { } /* end */ 9827f29673bSTobin Davis }; 9837f29673bSTobin Davis 9847f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9857f29673bSTobin Davis /* pin sensing on HP jack */ 9867f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 987d3091fadSTakashi Iwai { } /* end */ 9887f29673bSTobin Davis }; 9897f29673bSTobin Davis 990c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 991c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 992c9b443d4STobin Davis * configuration. 993c9b443d4STobin Davis */ 994c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 995c9b443d4STobin Davis .num_items = 5, 996c9b443d4STobin Davis .items = { 997c9b443d4STobin Davis { "MIXER", 0x0 }, 998c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 999c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 1000c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 1001c9b443d4STobin Davis { "CD pin", 0x4 }, 1002c9b443d4STobin Davis }, 1003c9b443d4STobin Davis }; 1004c9b443d4STobin Davis 1005c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 1006c9b443d4STobin Davis 1007c9b443d4STobin Davis /* Output controls */ 1008c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 1009c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 10107f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 10117f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 10127f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 10137f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1014c9b443d4STobin Davis 1015c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1016c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 1017c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 1018c9b443d4STobin Davis 101982f30040STobin Davis /* EAPD Switch Control */ 102082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 102182f30040STobin Davis 1022c9b443d4STobin Davis /* Loopback mixer controls */ 1023c9b443d4STobin Davis 10247f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 10257f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 10267f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 10277f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 10287f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 10297f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 10307f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 10317f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 10327f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 10337f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 1034c9b443d4STobin Davis { 1035c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1036c9b443d4STobin Davis .name = "Input Source", 1037c9b443d4STobin Davis .info = conexant_mux_enum_info, 1038c9b443d4STobin Davis .get = conexant_mux_enum_get, 1039c9b443d4STobin Davis .put = conexant_mux_enum_put, 1040c9b443d4STobin Davis }, 1041fb3409e7STobin Davis /* Audio input controls */ 1042fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 1043fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 1044fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 1045fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 1046fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 1047fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 1048fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 1049fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 1050fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 1051fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 1052c9b443d4STobin Davis { } /* end */ 1053c9b443d4STobin Davis }; 1054c9b443d4STobin Davis 1055c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 10567f29673bSTobin Davis /* Set connections */ 10577f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10587f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 10597f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1060c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1061c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 10627f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1063c9b443d4STobin Davis 1064c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1065c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1066c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1067c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1068c9b443d4STobin Davis * control. 1069c9b443d4STobin Davis */ 1070cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1071cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1072c9b443d4STobin Davis 1073c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1074c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1075c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1076c9b443d4STobin Davis 1077c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1078c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1079c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1080c9b443d4STobin Davis * input/output buffers as needed. 1081c9b443d4STobin Davis */ 1082c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1083c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1084c9b443d4STobin Davis 1085c9b443d4STobin Davis /* Mute capture amp left and right */ 1086c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1087c9b443d4STobin Davis 1088c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1089c9b443d4STobin Davis * pin) 1090c9b443d4STobin Davis */ 1091c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10927f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1093c9b443d4STobin Davis 1094c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1095c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1096c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1097c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1098c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1099c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1100c9b443d4STobin Davis 1101c9b443d4STobin Davis { } 1102c9b443d4STobin Davis }; 1103c9b443d4STobin Davis #endif 1104c9b443d4STobin Davis 1105c9b443d4STobin Davis 1106c9b443d4STobin Davis /* initialize jack-sensing, too */ 1107c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1108c9b443d4STobin Davis { 1109c9b443d4STobin Davis conexant_init(codec); 1110c9b443d4STobin Davis cxt5045_hp_automute(codec); 1111c9b443d4STobin Davis return 0; 1112c9b443d4STobin Davis } 1113c9b443d4STobin Davis 1114c9b443d4STobin Davis 1115c9b443d4STobin Davis enum { 111615908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 111715908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 111815908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 11195218c892SJiang Zhe CXT5045_BENQ, 11202de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1121c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1122c9b443d4STobin Davis CXT5045_TEST, 1123c9b443d4STobin Davis #endif 1124f5fcc13cSTakashi Iwai CXT5045_MODELS 1125c9b443d4STobin Davis }; 1126c9b443d4STobin Davis 1127f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 112815908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 112915908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 113015908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 11315218c892SJiang Zhe [CXT5045_BENQ] = "benq", 11322de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1133c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1134f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1135c9b443d4STobin Davis #endif 1136f5fcc13cSTakashi Iwai }; 1137c9b443d4STobin Davis 1138f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 11392de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1140dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1141dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 11426a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 11435218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 114415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 114515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 11469e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 11479e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 114815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 114915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 115015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1151dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1152dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 115315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1154c9b443d4STobin Davis {} 1155c9b443d4STobin Davis }; 1156c9b443d4STobin Davis 1157c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1158c9b443d4STobin Davis { 1159c9b443d4STobin Davis struct conexant_spec *spec; 1160c9b443d4STobin Davis int board_config; 1161c9b443d4STobin Davis 1162c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1163c9b443d4STobin Davis if (!spec) 1164c9b443d4STobin Davis return -ENOMEM; 1165c9b443d4STobin Davis codec->spec = spec; 11669421f954STakashi Iwai codec->pin_amp_workaround = 1; 1167c9b443d4STobin Davis 1168c9b443d4STobin Davis spec->multiout.max_channels = 2; 1169c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1170c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1171c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1172c9b443d4STobin Davis spec->num_adc_nids = 1; 1173c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1174c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1175c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1176c9b443d4STobin Davis spec->num_mixers = 1; 1177c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1178c9b443d4STobin Davis spec->num_init_verbs = 1; 1179c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1180c9b443d4STobin Davis spec->spdif_route = 0; 11813507e2a8STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes); 11823507e2a8STakashi Iwai spec->channel_mode = cxt5045_modes; 11835cd57529STobin Davis 11843507e2a8STakashi Iwai set_beep_amp(spec, 0x16, 0, 1); 1185c9b443d4STobin Davis 1186c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1187c9b443d4STobin Davis 1188f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1189f5fcc13cSTakashi Iwai cxt5045_models, 1190f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1191c9b443d4STobin Davis switch (board_config) { 119215908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11937f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1194c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1195c9b443d4STobin Davis spec->num_init_verbs = 2; 11967f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11977f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11987f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11997f29673bSTobin Davis break; 120015908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 120186376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12027f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 12037f29673bSTobin Davis spec->num_init_verbs = 2; 12047f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1205c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1206c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1207c9b443d4STobin Davis break; 120815908c36SMarc Boucher default: 120915908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 121015908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 121115908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 121215908c36SMarc Boucher spec->num_init_verbs = 3; 121315908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 121415908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 121515908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 121615908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 121715908c36SMarc Boucher break; 12185218c892SJiang Zhe case CXT5045_BENQ: 12195218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12205218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 12215218c892SJiang Zhe spec->num_init_verbs = 1; 12225218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 12235218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 12245218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 12255218c892SJiang Zhe spec->num_mixers = 2; 12265218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 12275218c892SJiang Zhe break; 12282de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 12292de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 12302de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 12312de3c232SJiang zhe spec->num_init_verbs = 2; 12322de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 12332de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 12342de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 12352de3c232SJiang zhe break; 1236c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1237c9b443d4STobin Davis case CXT5045_TEST: 1238c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1239c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1240c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 124115908c36SMarc Boucher break; 124215908c36SMarc Boucher 1243c9b443d4STobin Davis #endif 1244c9b443d4STobin Davis } 124548ecb7e8STakashi Iwai 1246031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1247031005f7STakashi Iwai case 0x103c: 12488f0f5ff6SDaniel T Chen case 0x1631: 12490b587fc4SDaniel T Chen case 0x1734: 12500ebf9e36SDaniel T Chen case 0x17aa: 12510ebf9e36SDaniel T Chen /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have 12520ebf9e36SDaniel T Chen * really bad sound over 0dB on NID 0x17. Fix max PCM level to 12530ebf9e36SDaniel T Chen * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) 125448ecb7e8STakashi Iwai */ 125548ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 125648ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 125748ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 125848ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 125948ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1260031005f7STakashi Iwai break; 1261031005f7STakashi Iwai } 126248ecb7e8STakashi Iwai 12633507e2a8STakashi Iwai if (spec->beep_amp) 12643507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 12653507e2a8STakashi Iwai 1266c9b443d4STobin Davis return 0; 1267c9b443d4STobin Davis } 1268c9b443d4STobin Davis 1269c9b443d4STobin Davis 1270c9b443d4STobin Davis /* Conexant 5047 specific */ 127182f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1272c9b443d4STobin Davis 12735b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1274c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1275c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1276c9b443d4STobin Davis 12775cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 12785cd57529STobin Davis { 2, NULL }, 12795cd57529STobin Davis }; 1280c9b443d4STobin Davis 128182f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 128282f30040STobin Davis .num_items = 2, 128382f30040STobin Davis .items = { 128482f30040STobin Davis { "ExtMic", 0x2 }, 128582f30040STobin Davis { "Line-In", 0x1 }, 1286c9b443d4STobin Davis } 1287c9b443d4STobin Davis }; 1288c9b443d4STobin Davis 1289c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1290c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1291c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1292c9b443d4STobin Davis { 1293c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1294c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 129582f30040STobin Davis unsigned int bits; 1296c9b443d4STobin Davis 129782f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1298c9b443d4STobin Davis return 0; 1299c9b443d4STobin Davis 130082f30040STobin Davis /* toggle internal speakers mute depending of presence of 130182f30040STobin Davis * the headphone jack 130282f30040STobin Davis */ 130347fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 13043b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 13053b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 13063b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 13073b7523fcSTakashi Iwai */ 13085d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 130947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 131047fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 131147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 131247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1313c9b443d4STobin Davis return 1; 1314c9b443d4STobin Davis } 1315c9b443d4STobin Davis 1316c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1317c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1318c9b443d4STobin Davis { 131982f30040STobin Davis struct conexant_spec *spec = codec->spec; 1320dd87da1cSTobin Davis unsigned int bits; 1321c9b443d4STobin Davis 1322d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x13); 1323dd87da1cSTobin Davis 132447fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 13253b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13265d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 132747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1328c9b443d4STobin Davis } 1329c9b443d4STobin Davis 1330c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1331c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1332c9b443d4STobin Davis { 1333c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 13349f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13359f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1336c9b443d4STobin Davis {} 1337c9b443d4STobin Davis }; 1338c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 13399f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 13409f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1341c9b443d4STobin Davis {} 1342c9b443d4STobin Davis }; 1343c9b443d4STobin Davis unsigned int present; 1344c9b443d4STobin Davis 1345d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x15); 1346c9b443d4STobin Davis if (present) 1347c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1348c9b443d4STobin Davis else 1349c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1350c9b443d4STobin Davis } 1351c9b443d4STobin Davis 1352c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1353c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1354c9b443d4STobin Davis unsigned int res) 1355c9b443d4STobin Davis { 13569f113e0eSMarc Boucher switch (res >> 26) { 1357c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1358c9b443d4STobin Davis cxt5047_hp_automute(codec); 1359c9b443d4STobin Davis break; 1360c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1361c9b443d4STobin Davis cxt5047_hp_automic(codec); 1362c9b443d4STobin Davis break; 1363c9b443d4STobin Davis } 1364c9b443d4STobin Davis } 1365c9b443d4STobin Davis 1366df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1367df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1368df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1369df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT), 1370c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1371c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1372c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1373c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 137482f30040STobin Davis { 137582f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 137682f30040STobin Davis .name = "Master Playback Switch", 137782f30040STobin Davis .info = cxt_eapd_info, 137882f30040STobin Davis .get = cxt_eapd_get, 1379c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1380c9b443d4STobin Davis .private_value = 0x13, 1381c9b443d4STobin Davis }, 1382c9b443d4STobin Davis 1383c9b443d4STobin Davis {} 1384c9b443d4STobin Davis }; 1385c9b443d4STobin Davis 1386df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13873b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13885d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1389df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1390df481e41STakashi Iwai {} 1391df481e41STakashi Iwai }; 1392df481e41STakashi Iwai 1393df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1394c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1395c9b443d4STobin Davis { } /* end */ 1396c9b443d4STobin Davis }; 1397c9b443d4STobin Davis 1398c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1399c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1400c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1401c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1402c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 14037f29673bSTobin Davis /* HP, Speaker */ 1404b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 14055b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 14065b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 14077f29673bSTobin Davis /* Record selector: Mic */ 14087f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 14097f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 14107f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 14117f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1412c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1413c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1414c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1415c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1416c9b443d4STobin Davis /* SPDIF route: PCM */ 1417c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 141882f30040STobin Davis /* Enable unsolicited events */ 141982f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 142082f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1421c9b443d4STobin Davis { } /* end */ 1422c9b443d4STobin Davis }; 1423c9b443d4STobin Davis 1424c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1425c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 14263b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1427c9b443d4STobin Davis {} 1428c9b443d4STobin Davis }; 1429c9b443d4STobin Davis 1430c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1431c9b443d4STobin Davis * configuration. 1432c9b443d4STobin Davis */ 1433c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1434c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 143582f30040STobin Davis .num_items = 4, 1436c9b443d4STobin Davis .items = { 143782f30040STobin Davis { "LINE1 pin", 0x0 }, 143882f30040STobin Davis { "MIC1 pin", 0x1 }, 143982f30040STobin Davis { "MIC2 pin", 0x2 }, 144082f30040STobin Davis { "CD pin", 0x3 }, 1441c9b443d4STobin Davis }, 1442c9b443d4STobin Davis }; 1443c9b443d4STobin Davis 1444c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1445c9b443d4STobin Davis 1446c9b443d4STobin Davis /* Output only controls */ 144782f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 144882f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 144982f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 145082f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1451c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1452c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1453c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1454c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 145582f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 145682f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 145782f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 145882f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1459c9b443d4STobin Davis 1460c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1461c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1462c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1463c9b443d4STobin Davis 146482f30040STobin Davis /* EAPD Switch Control */ 146582f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 146682f30040STobin Davis 1467c9b443d4STobin Davis /* Loopback mixer controls */ 146882f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 146982f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 147082f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 147182f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 147282f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 147382f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 147482f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 147582f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1476c9b443d4STobin Davis 147782f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 147882f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 147982f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 148082f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 148182f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 148282f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 148382f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 148482f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1485c9b443d4STobin Davis { 1486c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1487c9b443d4STobin Davis .name = "Input Source", 1488c9b443d4STobin Davis .info = conexant_mux_enum_info, 1489c9b443d4STobin Davis .get = conexant_mux_enum_get, 1490c9b443d4STobin Davis .put = conexant_mux_enum_put, 1491c9b443d4STobin Davis }, 1492854206b0STakashi Iwai HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT), 14939f113e0eSMarc Boucher 1494c9b443d4STobin Davis { } /* end */ 1495c9b443d4STobin Davis }; 1496c9b443d4STobin Davis 1497c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1498c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1499c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1500c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1501c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1502c9b443d4STobin Davis 1503c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1504c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1505c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1506c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1507c9b443d4STobin Davis * control. 1508c9b443d4STobin Davis */ 1509c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1510c9b443d4STobin Davis 1511c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1512c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1513c9b443d4STobin Davis */ 1514c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1515c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1516c9b443d4STobin Davis 1517c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1518c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1519c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1520c9b443d4STobin Davis 1521c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1522c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1523c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1524c9b443d4STobin Davis * input/output buffers as needed. 1525c9b443d4STobin Davis */ 1526c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1527c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1528c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1529c9b443d4STobin Davis 1530c9b443d4STobin Davis /* Mute capture amp left and right */ 1531c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1532c9b443d4STobin Davis 1533c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1534c9b443d4STobin Davis * pin) 1535c9b443d4STobin Davis */ 1536c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1537c9b443d4STobin Davis 1538c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1539c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1540c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1541c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1542c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1543c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1544c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1545c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1546c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1547c9b443d4STobin Davis 1548c9b443d4STobin Davis { } 1549c9b443d4STobin Davis }; 1550c9b443d4STobin Davis #endif 1551c9b443d4STobin Davis 1552c9b443d4STobin Davis 1553c9b443d4STobin Davis /* initialize jack-sensing, too */ 1554c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1555c9b443d4STobin Davis { 1556c9b443d4STobin Davis conexant_init(codec); 1557c9b443d4STobin Davis cxt5047_hp_automute(codec); 1558c9b443d4STobin Davis return 0; 1559c9b443d4STobin Davis } 1560c9b443d4STobin Davis 1561c9b443d4STobin Davis 1562c9b443d4STobin Davis enum { 1563f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1564f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1565f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1566c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1567c9b443d4STobin Davis CXT5047_TEST, 1568c9b443d4STobin Davis #endif 1569f5fcc13cSTakashi Iwai CXT5047_MODELS 1570c9b443d4STobin Davis }; 1571c9b443d4STobin Davis 1572f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1573f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1574f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1575f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1576c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1577f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1578c9b443d4STobin Davis #endif 1579f5fcc13cSTakashi Iwai }; 1580c9b443d4STobin Davis 1581f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1582ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1583dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1584dea0a509STakashi Iwai CXT5047_LAPTOP), 1585f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1586c9b443d4STobin Davis {} 1587c9b443d4STobin Davis }; 1588c9b443d4STobin Davis 1589c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1590c9b443d4STobin Davis { 1591c9b443d4STobin Davis struct conexant_spec *spec; 1592c9b443d4STobin Davis int board_config; 1593c9b443d4STobin Davis 1594c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1595c9b443d4STobin Davis if (!spec) 1596c9b443d4STobin Davis return -ENOMEM; 1597c9b443d4STobin Davis codec->spec = spec; 15989421f954STakashi Iwai codec->pin_amp_workaround = 1; 1599c9b443d4STobin Davis 1600c9b443d4STobin Davis spec->multiout.max_channels = 2; 1601c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1602c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1603c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1604c9b443d4STobin Davis spec->num_adc_nids = 1; 1605c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1606c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1607c9b443d4STobin Davis spec->num_mixers = 1; 1608df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1609c9b443d4STobin Davis spec->num_init_verbs = 1; 1610c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1611c9b443d4STobin Davis spec->spdif_route = 0; 16125cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16135cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1614c9b443d4STobin Davis 1615c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1616c9b443d4STobin Davis 1617f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1618f5fcc13cSTakashi Iwai cxt5047_models, 1619f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1620c9b443d4STobin Davis switch (board_config) { 1621c9b443d4STobin Davis case CXT5047_LAPTOP: 1622df481e41STakashi Iwai spec->num_mixers = 2; 1623df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1624df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1625c9b443d4STobin Davis break; 1626c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1627df481e41STakashi Iwai spec->num_mixers = 2; 1628df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1629fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1630c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1631c9b443d4STobin Davis break; 1632c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 163382f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1634df481e41STakashi Iwai spec->num_mixers = 2; 1635df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1636c9b443d4STobin Davis spec->num_init_verbs = 2; 1637c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1638fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1639c9b443d4STobin Davis break; 1640c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1641c9b443d4STobin Davis case CXT5047_TEST: 1642c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1643c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1644c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1645fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1646c9b443d4STobin Davis #endif 1647c9b443d4STobin Davis } 1648dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1649025f206cSDaniel T Chen 1650025f206cSDaniel T Chen switch (codec->subsystem_id >> 16) { 1651025f206cSDaniel T Chen case 0x103c: 1652025f206cSDaniel T Chen /* HP laptops have really bad sound over 0 dB on NID 0x10. 1653025f206cSDaniel T Chen * Fix max PCM level to 0 dB (originally it has 0x1e steps 1654025f206cSDaniel T Chen * with 0 dB offset 0x17) 1655025f206cSDaniel T Chen */ 1656025f206cSDaniel T Chen snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT, 1657025f206cSDaniel T Chen (0x17 << AC_AMPCAP_OFFSET_SHIFT) | 1658025f206cSDaniel T Chen (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | 1659025f206cSDaniel T Chen (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 1660025f206cSDaniel T Chen (1 << AC_AMPCAP_MUTE_SHIFT)); 1661025f206cSDaniel T Chen break; 1662025f206cSDaniel T Chen } 1663025f206cSDaniel T Chen 1664c9b443d4STobin Davis return 0; 1665c9b443d4STobin Davis } 1666c9b443d4STobin Davis 1667461e2c78STakashi Iwai /* Conexant 5051 specific */ 1668461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1669461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1670461e2c78STakashi Iwai 1671461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1672461e2c78STakashi Iwai { 2, NULL }, 1673461e2c78STakashi Iwai }; 1674461e2c78STakashi Iwai 1675461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1676461e2c78STakashi Iwai { 1677461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1678461e2c78STakashi Iwai unsigned int pinctl; 167923d2df5bSTakashi Iwai /* headphone pin */ 168023d2df5bSTakashi Iwai pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0; 168123d2df5bSTakashi Iwai snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 168223d2df5bSTakashi Iwai pinctl); 168323d2df5bSTakashi Iwai /* speaker pin */ 1684461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1685461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1686461e2c78STakashi Iwai pinctl); 1687f7154de2SHerton Ronaldo Krzesinski /* on ideapad there is an aditional speaker (subwoofer) to mute */ 1688f7154de2SHerton Ronaldo Krzesinski if (spec->ideapad) 1689f7154de2SHerton Ronaldo Krzesinski snd_hda_codec_write(codec, 0x1b, 0, 1690f7154de2SHerton Ronaldo Krzesinski AC_VERB_SET_PIN_WIDGET_CONTROL, 1691f7154de2SHerton Ronaldo Krzesinski pinctl); 1692461e2c78STakashi Iwai } 1693461e2c78STakashi Iwai 1694461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1695461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1696461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1697461e2c78STakashi Iwai { 1698461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1699461e2c78STakashi Iwai 1700461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1701461e2c78STakashi Iwai return 0; 1702461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1703461e2c78STakashi Iwai return 1; 1704461e2c78STakashi Iwai } 1705461e2c78STakashi Iwai 1706461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1707461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1708461e2c78STakashi Iwai { 170979d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1710461e2c78STakashi Iwai unsigned int present; 1711461e2c78STakashi Iwai 1712faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTB)) 171379d7d533STakashi Iwai return; 1714d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x17); 1715461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1716461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1717461e2c78STakashi Iwai present ? 0x01 : 0x00); 1718461e2c78STakashi Iwai } 1719461e2c78STakashi Iwai 1720461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1721461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1722461e2c78STakashi Iwai { 1723461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1724461e2c78STakashi Iwai unsigned int present; 1725461e2c78STakashi Iwai hda_nid_t new_adc; 1726461e2c78STakashi Iwai 1727faddaa5dSTakashi Iwai if (!(spec->auto_mic & AUTO_MIC_PORTC)) 172879d7d533STakashi Iwai return; 1729d56757abSTakashi Iwai present = snd_hda_jack_detect(codec, 0x18); 1730461e2c78STakashi Iwai if (present) 1731461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1732461e2c78STakashi Iwai else 1733461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1734461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1735461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1736461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1737f0cea797STakashi Iwai __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); 1738461e2c78STakashi Iwai spec->cur_adc = new_adc; 1739461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1740461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1741461e2c78STakashi Iwai spec->cur_adc_format); 1742461e2c78STakashi Iwai } 1743461e2c78STakashi Iwai } 1744461e2c78STakashi Iwai 1745461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1746461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1747461e2c78STakashi Iwai { 1748461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1749461e2c78STakashi Iwai 1750d56757abSTakashi Iwai spec->hp_present = snd_hda_jack_detect(codec, 0x16); 1751461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1752461e2c78STakashi Iwai } 1753461e2c78STakashi Iwai 1754461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1755461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1756461e2c78STakashi Iwai unsigned int res) 1757461e2c78STakashi Iwai { 1758acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1759461e2c78STakashi Iwai switch (res >> 26) { 1760461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1761461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1762461e2c78STakashi Iwai break; 1763461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1764461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1765461e2c78STakashi Iwai break; 1766461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1767461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1768461e2c78STakashi Iwai break; 1769461e2c78STakashi Iwai } 1770acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1771461e2c78STakashi Iwai } 1772461e2c78STakashi Iwai 17732c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1774461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1775461e2c78STakashi Iwai { 1776461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1777461e2c78STakashi Iwai .name = "Master Playback Switch", 1778461e2c78STakashi Iwai .info = cxt_eapd_info, 1779461e2c78STakashi Iwai .get = cxt_eapd_get, 1780461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1781461e2c78STakashi Iwai .private_value = 0x1a, 1782461e2c78STakashi Iwai }, 17832c7a3fb3STakashi Iwai {} 17842c7a3fb3STakashi Iwai }; 1785461e2c78STakashi Iwai 17862c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = { 17872c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 17882c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 17892c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 17902c7a3fb3STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 17912c7a3fb3STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 17922c7a3fb3STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1793461e2c78STakashi Iwai {} 1794461e2c78STakashi Iwai }; 1795461e2c78STakashi Iwai 1796461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1797461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1798461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1799461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1800461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1801461e2c78STakashi Iwai {} 1802461e2c78STakashi Iwai }; 1803461e2c78STakashi Iwai 180479d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 18054e4ac600STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT), 18064e4ac600STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT), 180779d7d533STakashi Iwai {} 180879d7d533STakashi Iwai }; 180979d7d533STakashi Iwai 1810cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = { 18115f6c3de6STakashi Iwai HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT), 18125f6c3de6STakashi Iwai HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT), 1813cd9d95a5SKen Prox {} 1814cd9d95a5SKen Prox }; 1815cd9d95a5SKen Prox 1816faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = { 1817faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1818faddaa5dSTakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1819faddaa5dSTakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1820faddaa5dSTakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1821faddaa5dSTakashi Iwai {} 1822faddaa5dSTakashi Iwai }; 1823faddaa5dSTakashi Iwai 1824461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1825461e2c78STakashi Iwai /* Line in, Mic */ 1826461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1827461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1828461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1829461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1830461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1831461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1832461e2c78STakashi Iwai /* SPK */ 1833461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1834461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1835461e2c78STakashi Iwai /* HP, Amp */ 1836461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1837461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1838461e2c78STakashi Iwai /* DAC1 */ 1839461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1840461e2c78STakashi Iwai /* Record selector: Int mic */ 1841461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1842461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1843461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1844461e2c78STakashi Iwai /* SPDIF route: PCM */ 18451965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1846461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1847461e2c78STakashi Iwai /* EAPD */ 1848461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1849461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1850461e2c78STakashi Iwai { } /* end */ 1851461e2c78STakashi Iwai }; 1852461e2c78STakashi Iwai 185379d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 185479d7d533STakashi Iwai /* Line in, Mic */ 185579d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 185679d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 185779d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185879d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185979d7d533STakashi Iwai /* SPK */ 186079d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 186179d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 186279d7d533STakashi Iwai /* HP, Amp */ 186379d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 186479d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 186579d7d533STakashi Iwai /* DAC1 */ 186679d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 186779d7d533STakashi Iwai /* Record selector: Int mic */ 186879d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 186979d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 187079d7d533STakashi Iwai /* SPDIF route: PCM */ 187179d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 187279d7d533STakashi Iwai /* EAPD */ 187379d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 187479d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 187579d7d533STakashi Iwai { } /* end */ 187679d7d533STakashi Iwai }; 187779d7d533STakashi Iwai 187827e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 187927e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 188027e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 188127e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 188227e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 188327e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 188427e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 188527e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 188627e08988SAristeu Sergio Rozanski Filho /* SPK */ 188727e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 188827e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 188927e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 189027e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 189127e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 189227e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 189327e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 189427e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 189527e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 189627e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 189727e08988SAristeu Sergio Rozanski Filho /* Record selector: Int mic */ 189827e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 189927e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 190027e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 190127e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 19021965c441SPierre-Louis Bossart {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */ 190327e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 190427e08988SAristeu Sergio Rozanski Filho /* EAPD */ 190527e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 190627e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 190727e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 190827e08988SAristeu Sergio Rozanski Filho { } /* end */ 190927e08988SAristeu Sergio Rozanski Filho }; 191027e08988SAristeu Sergio Rozanski Filho 1911cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = { 1912cd9d95a5SKen Prox /* Line in, Mic */ 191330ed7ed1STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1914cd9d95a5SKen Prox {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1915cd9d95a5SKen Prox {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1916cd9d95a5SKen Prox {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 1917cd9d95a5SKen Prox /* SPK */ 1918cd9d95a5SKen Prox {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1919cd9d95a5SKen Prox {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1920cd9d95a5SKen Prox /* HP, Amp */ 1921cd9d95a5SKen Prox {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1922cd9d95a5SKen Prox {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1923cd9d95a5SKen Prox /* DAC1 */ 1924cd9d95a5SKen Prox {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1925cd9d95a5SKen Prox /* Record selector: Int mic */ 1926cd9d95a5SKen Prox {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1927cd9d95a5SKen Prox {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 1928cd9d95a5SKen Prox /* SPDIF route: PCM */ 1929cd9d95a5SKen Prox {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1930cd9d95a5SKen Prox /* EAPD */ 1931cd9d95a5SKen Prox {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1932cd9d95a5SKen Prox {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1933cd9d95a5SKen Prox { } /* end */ 1934cd9d95a5SKen Prox }; 1935cd9d95a5SKen Prox 19366953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid, 19376953e552STakashi Iwai unsigned int event) 19386953e552STakashi Iwai { 19396953e552STakashi Iwai snd_hda_codec_write(codec, nid, 0, 19406953e552STakashi Iwai AC_VERB_SET_UNSOLICITED_ENABLE, 19416953e552STakashi Iwai AC_USRSP_EN | event); 19426953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 19436953e552STakashi Iwai conexant_add_jack(codec, nid, SND_JACK_MICROPHONE); 19446953e552STakashi Iwai conexant_report_jack(codec, nid); 19456953e552STakashi Iwai #endif 19466953e552STakashi Iwai } 19476953e552STakashi Iwai 1948f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = { 1949f7154de2SHerton Ronaldo Krzesinski /* Subwoofer */ 1950f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1951f7154de2SHerton Ronaldo Krzesinski {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, 1952f7154de2SHerton Ronaldo Krzesinski { } /* end */ 1953f7154de2SHerton Ronaldo Krzesinski }; 1954f7154de2SHerton Ronaldo Krzesinski 1955461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1956461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1957461e2c78STakashi Iwai { 19586953e552STakashi Iwai struct conexant_spec *spec = codec->spec; 19596953e552STakashi Iwai 1960461e2c78STakashi Iwai conexant_init(codec); 1961acf26c0cSUlrich Dangel conexant_init_jacks(codec); 19626953e552STakashi Iwai 19636953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTB) 19646953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 19656953e552STakashi Iwai if (spec->auto_mic & AUTO_MIC_PORTC) 19666953e552STakashi Iwai cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT); 19676953e552STakashi Iwai 1968461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1969461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1970461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1971461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1972461e2c78STakashi Iwai } 1973461e2c78STakashi Iwai return 0; 1974461e2c78STakashi Iwai } 1975461e2c78STakashi Iwai 1976461e2c78STakashi Iwai 1977461e2c78STakashi Iwai enum { 1978461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1979461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 198079d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 19811965c441SPierre-Louis Bossart CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */ 1982cd9d95a5SKen Prox CXT5051_F700, /* HP Compaq Presario F700 */ 1983faddaa5dSTakashi Iwai CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1984f7154de2SHerton Ronaldo Krzesinski CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 1985461e2c78STakashi Iwai CXT5051_MODELS 1986461e2c78STakashi Iwai }; 1987461e2c78STakashi Iwai 1988461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1989461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1990461e2c78STakashi Iwai [CXT5051_HP] = "hp", 199179d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 199227e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 19935f6c3de6STakashi Iwai [CXT5051_F700] = "hp-700", 1994faddaa5dSTakashi Iwai [CXT5051_TOSHIBA] = "toshiba", 1995f7154de2SHerton Ronaldo Krzesinski [CXT5051_IDEAPAD] = "ideapad", 1996461e2c78STakashi Iwai }; 1997461e2c78STakashi Iwai 1998461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 199979d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 20001812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 20015f6c3de6STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700), 2002faddaa5dSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA), 2003461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2004461e2c78STakashi Iwai CXT5051_LAPTOP), 2005461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 200627e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 2007f7154de2SHerton Ronaldo Krzesinski SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 2008461e2c78STakashi Iwai {} 2009461e2c78STakashi Iwai }; 2010461e2c78STakashi Iwai 2011461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 2012461e2c78STakashi Iwai { 2013461e2c78STakashi Iwai struct conexant_spec *spec; 2014461e2c78STakashi Iwai int board_config; 2015461e2c78STakashi Iwai 2016461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2017461e2c78STakashi Iwai if (!spec) 2018461e2c78STakashi Iwai return -ENOMEM; 2019461e2c78STakashi Iwai codec->spec = spec; 20209421f954STakashi Iwai codec->pin_amp_workaround = 1; 2021461e2c78STakashi Iwai 2022461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 2023461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 2024461e2c78STakashi Iwai 2025461e2c78STakashi Iwai spec->multiout.max_channels = 2; 2026461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 2027461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 2028461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 2029461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 2030461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 20312c7a3fb3STakashi Iwai spec->num_mixers = 2; 20322c7a3fb3STakashi Iwai spec->mixers[0] = cxt5051_capture_mixers; 20332c7a3fb3STakashi Iwai spec->mixers[1] = cxt5051_playback_mixers; 2034461e2c78STakashi Iwai spec->num_init_verbs = 1; 2035461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 2036461e2c78STakashi Iwai spec->spdif_route = 0; 2037461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 2038461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 2039461e2c78STakashi Iwai spec->cur_adc = 0; 2040461e2c78STakashi Iwai spec->cur_adc_idx = 0; 2041461e2c78STakashi Iwai 20423507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 20433507e2a8STakashi Iwai 204479d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 204579d7d533STakashi Iwai 2046461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 2047461e2c78STakashi Iwai cxt5051_models, 2048461e2c78STakashi Iwai cxt5051_cfg_tbl); 2049faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC; 2050461e2c78STakashi Iwai switch (board_config) { 2051461e2c78STakashi Iwai case CXT5051_HP: 2052461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 2053461e2c78STakashi Iwai break; 205479d7d533STakashi Iwai case CXT5051_HP_DV6736: 205579d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 205679d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2057faddaa5dSTakashi Iwai spec->auto_mic = 0; 205879d7d533STakashi Iwai break; 205927e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 206027e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 2061607bc3e4SJerone Young /* Thinkpad X301 does not have S/PDIF wired and no ability 2062607bc3e4SJerone Young to use a docking station. */ 2063607bc3e4SJerone Young if (codec->subsystem_id == 0x17aa211f) 2064607bc3e4SJerone Young spec->multiout.dig_out_nid = 0; 2065461e2c78STakashi Iwai break; 2066cd9d95a5SKen Prox case CXT5051_F700: 2067cd9d95a5SKen Prox spec->init_verbs[0] = cxt5051_f700_init_verbs; 2068cd9d95a5SKen Prox spec->mixers[0] = cxt5051_f700_mixers; 2069faddaa5dSTakashi Iwai spec->auto_mic = 0; 2070faddaa5dSTakashi Iwai break; 2071faddaa5dSTakashi Iwai case CXT5051_TOSHIBA: 2072faddaa5dSTakashi Iwai spec->mixers[0] = cxt5051_toshiba_mixers; 2073faddaa5dSTakashi Iwai spec->auto_mic = AUTO_MIC_PORTB; 2074cd9d95a5SKen Prox break; 2075f7154de2SHerton Ronaldo Krzesinski case CXT5051_IDEAPAD: 2076f7154de2SHerton Ronaldo Krzesinski spec->init_verbs[spec->num_init_verbs++] = 2077f7154de2SHerton Ronaldo Krzesinski cxt5051_ideapad_init_verbs; 2078f7154de2SHerton Ronaldo Krzesinski spec->ideapad = 1; 2079f7154de2SHerton Ronaldo Krzesinski break; 2080461e2c78STakashi Iwai } 2081461e2c78STakashi Iwai 20823507e2a8STakashi Iwai if (spec->beep_amp) 20833507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 20843507e2a8STakashi Iwai 2085461e2c78STakashi Iwai return 0; 2086461e2c78STakashi Iwai } 2087461e2c78STakashi Iwai 20880fb67e98SDaniel Drake /* Conexant 5066 specific */ 20890fb67e98SDaniel Drake 20900fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 20910fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 20920fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 20930fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT 0x21 20940fb67e98SDaniel Drake 2095dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors, 2096dbaccc0cSDaniel Drake * therefore we use a 50% mic bias in order to center the input signal with 2097dbaccc0cSDaniel Drake * the DC input range of the codec. */ 2098dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50 2099dbaccc0cSDaniel Drake 21000fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = { 21010fb67e98SDaniel Drake { 2, NULL }, 21020fb67e98SDaniel Drake }; 21030fb67e98SDaniel Drake 21040fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 21050fb67e98SDaniel Drake { 21060fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 21070fb67e98SDaniel Drake unsigned int pinctl; 21080fb67e98SDaniel Drake 21090fb67e98SDaniel Drake snd_printdd("CXT5066: update speaker, hp_present=%d\n", 21100fb67e98SDaniel Drake spec->hp_present); 21110fb67e98SDaniel Drake 21120fb67e98SDaniel Drake /* Port A (HP) */ 21130fb67e98SDaniel Drake pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 21140fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21150fb67e98SDaniel Drake pinctl); 21160fb67e98SDaniel Drake 21170fb67e98SDaniel Drake /* Port D (HP/LO) */ 21180fb67e98SDaniel Drake pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 21190fb67e98SDaniel Drake ? spec->port_d_mode : 0; 21207b2bfdbcSJens Taprogge /* Mute if Port A is connected on Thinkpad */ 21217b2bfdbcSJens Taprogge if (spec->thinkpad && (spec->hp_present & 1)) 21227b2bfdbcSJens Taprogge pinctl = 0; 21230fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21240fb67e98SDaniel Drake pinctl); 21250fb67e98SDaniel Drake 21260fb67e98SDaniel Drake /* CLASS_D AMP */ 21270fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 21280fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 21290fb67e98SDaniel Drake pinctl); 21300fb67e98SDaniel Drake 21310fb67e98SDaniel Drake if (spec->dell_automute) { 21320fb67e98SDaniel Drake /* DELL AIO Port Rule: PortA > PortD > IntSpk */ 21330fb67e98SDaniel Drake pinctl = (!(spec->hp_present & 1) && spec->cur_eapd) 21340fb67e98SDaniel Drake ? PIN_OUT : 0; 21350fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, 21360fb67e98SDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); 21370fb67e98SDaniel Drake } 21380fb67e98SDaniel Drake } 21390fb67e98SDaniel Drake 21400fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 21410fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 21420fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 21430fb67e98SDaniel Drake { 21440fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 21450fb67e98SDaniel Drake 21460fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 21470fb67e98SDaniel Drake return 0; 21480fb67e98SDaniel Drake 21490fb67e98SDaniel Drake cxt5066_update_speaker(codec); 21500fb67e98SDaniel Drake return 1; 21510fb67e98SDaniel Drake } 21520fb67e98SDaniel Drake 2153c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = { 2154c4cfe66cSDaniel Drake .num_items = 3, 2155c4cfe66cSDaniel Drake .items = { 2156c4cfe66cSDaniel Drake { "Off", PIN_IN }, 2157c4cfe66cSDaniel Drake { "50%", PIN_VREF50 }, 2158c4cfe66cSDaniel Drake { "80%", PIN_VREF80 }, 2159c4cfe66cSDaniel Drake }, 2160c4cfe66cSDaniel Drake }; 2161c4cfe66cSDaniel Drake 2162c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec) 2163c4cfe66cSDaniel Drake { 2164c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2165c4cfe66cSDaniel Drake /* Even though port F is the DC input, the bias is controlled on port B. 2166c4cfe66cSDaniel Drake * we also leave that port as an active input (but unselected) in DC mode 2167c4cfe66cSDaniel Drake * just in case that is necessary to make the bias setting take effect. */ 2168c4cfe66cSDaniel Drake return snd_hda_codec_write_cache(codec, 0x1a, 0, 2169c4cfe66cSDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, 2170c4cfe66cSDaniel Drake cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index); 2171c4cfe66cSDaniel Drake } 2172c4cfe66cSDaniel Drake 217375f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the 217475f8991dSDaniel Drake * microphone LED comes on as soon as these settings are put in place. if we 217575f8991dSDaniel Drake * did this before recording, it would give the false indication that recording 217675f8991dSDaniel Drake * is happening when it is not. */ 217775f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec) 21780fb67e98SDaniel Drake { 2179dbaccc0cSDaniel Drake struct conexant_spec *spec = codec->spec; 218075f8991dSDaniel Drake if (!spec->recording) 218175f8991dSDaniel Drake return; 21820fb67e98SDaniel Drake 2183c4cfe66cSDaniel Drake if (spec->dc_enable) { 2184c4cfe66cSDaniel Drake /* in DC mode we ignore presence detection and just use the jack 2185c4cfe66cSDaniel Drake * through our special DC port */ 2186c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2187c4cfe66cSDaniel Drake /* disble internal mic, port C */ 2188c4cfe66cSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2189c4cfe66cSDaniel Drake 2190c4cfe66cSDaniel Drake /* enable DC capture, port F */ 2191c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2192c4cfe66cSDaniel Drake {}, 2193c4cfe66cSDaniel Drake }; 2194c4cfe66cSDaniel Drake 2195c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2196c4cfe66cSDaniel Drake /* port B input disabled (and bias set) through the following call */ 2197c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 2198c4cfe66cSDaniel Drake return; 2199c4cfe66cSDaniel Drake } 2200c4cfe66cSDaniel Drake 2201c4cfe66cSDaniel Drake /* disable DC (port F) */ 2202c4cfe66cSDaniel Drake snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0); 2203c4cfe66cSDaniel Drake 220475f8991dSDaniel Drake /* external mic, port B */ 220575f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 220675f8991dSDaniel Drake spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0); 22070fb67e98SDaniel Drake 220875f8991dSDaniel Drake /* internal mic, port C */ 220975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 221075f8991dSDaniel Drake spec->ext_mic_present ? 0 : PIN_VREF80); 221175f8991dSDaniel Drake } 22120fb67e98SDaniel Drake 221375f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */ 221475f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec) 221575f8991dSDaniel Drake { 221675f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 22170fb67e98SDaniel Drake unsigned int present; 22180fb67e98SDaniel Drake 2219c4cfe66cSDaniel Drake if (spec->dc_enable) /* don't do presence detection in DC mode */ 2220c4cfe66cSDaniel Drake return; 2221c4cfe66cSDaniel Drake 222275f8991dSDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 222375f8991dSDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 222475f8991dSDaniel Drake if (present) 22250fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 222675f8991dSDaniel Drake else 22270fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 222875f8991dSDaniel Drake 222975f8991dSDaniel Drake snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 223075f8991dSDaniel Drake present ? 0 : 1); 223175f8991dSDaniel Drake spec->ext_mic_present = !!present; 223275f8991dSDaniel Drake 223375f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 22340fb67e98SDaniel Drake } 22350fb67e98SDaniel Drake 223695a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */ 223795a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec) 223895a618bdSEinar Rünkaru { 223995a618bdSEinar Rünkaru unsigned int present; 224095a618bdSEinar Rünkaru 224195a618bdSEinar Rünkaru struct hda_verb ext_mic_present[] = { 224295a618bdSEinar Rünkaru /* enable external mic, port B */ 224375f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 224495a618bdSEinar Rünkaru 224595a618bdSEinar Rünkaru /* switch to external mic input */ 224695a618bdSEinar Rünkaru {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 224795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 224895a618bdSEinar Rünkaru 224995a618bdSEinar Rünkaru /* disable internal digital mic */ 225095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 225195a618bdSEinar Rünkaru {} 225295a618bdSEinar Rünkaru }; 225395a618bdSEinar Rünkaru static struct hda_verb ext_mic_absent[] = { 225495a618bdSEinar Rünkaru /* enable internal mic, port C */ 225595a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 225695a618bdSEinar Rünkaru 225795a618bdSEinar Rünkaru /* switch to internal mic input */ 225895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 225995a618bdSEinar Rünkaru 226095a618bdSEinar Rünkaru /* disable external mic, port B */ 226195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 226295a618bdSEinar Rünkaru {} 226395a618bdSEinar Rünkaru }; 226495a618bdSEinar Rünkaru 226595a618bdSEinar Rünkaru present = snd_hda_jack_detect(codec, 0x1a); 226695a618bdSEinar Rünkaru if (present) { 226795a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone detected\n"); 226895a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_present); 226995a618bdSEinar Rünkaru } else { 227095a618bdSEinar Rünkaru snd_printdd("CXT5066: external microphone absent\n"); 227195a618bdSEinar Rünkaru snd_hda_sequence_write(codec, ext_mic_absent); 227295a618bdSEinar Rünkaru } 227395a618bdSEinar Rünkaru } 227495a618bdSEinar Rünkaru 2275cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */ 2276cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec) 2277cfd3d8dcSGreg Alexander { 2278cfd3d8dcSGreg Alexander unsigned int present; 2279cfd3d8dcSGreg Alexander 2280cfd3d8dcSGreg Alexander struct hda_verb ext_mic_present[] = { 2281cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 2282cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2283cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2284cfd3d8dcSGreg Alexander {} 2285cfd3d8dcSGreg Alexander }; 2286cfd3d8dcSGreg Alexander static struct hda_verb ext_mic_absent[] = { 2287cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 2288cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2289cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2290cfd3d8dcSGreg Alexander {} 2291cfd3d8dcSGreg Alexander }; 2292cfd3d8dcSGreg Alexander 2293cfd3d8dcSGreg Alexander present = snd_hda_jack_detect(codec, 0x1b); 2294cfd3d8dcSGreg Alexander if (present) { 2295cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone detected\n"); 2296cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_present); 2297cfd3d8dcSGreg Alexander } else { 2298cfd3d8dcSGreg Alexander snd_printdd("CXT5066: external microphone absent\n"); 2299cfd3d8dcSGreg Alexander snd_hda_sequence_write(codec, ext_mic_absent); 2300cfd3d8dcSGreg Alexander } 2301cfd3d8dcSGreg Alexander } 2302cfd3d8dcSGreg Alexander 2303048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */ 2304048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec) 2305048e78a5SDavid Henningsson { 2306048e78a5SDavid Henningsson unsigned int present; 2307048e78a5SDavid Henningsson 2308048e78a5SDavid Henningsson present = snd_hda_jack_detect(codec, 0x1b); 2309048e78a5SDavid Henningsson snd_printdd("CXT5066: external microphone present=%d\n", present); 2310048e78a5SDavid Henningsson snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL, 2311048e78a5SDavid Henningsson present ? 1 : 3); 2312048e78a5SDavid Henningsson } 2313048e78a5SDavid Henningsson 2314048e78a5SDavid Henningsson 23157b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately 23167b2bfdbcSJens Taprogge order is: external mic -> dock mic -> interal mic */ 23177b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec) 23187b2bfdbcSJens Taprogge { 23197b2bfdbcSJens Taprogge unsigned int ext_present, dock_present; 23207b2bfdbcSJens Taprogge 23217b2bfdbcSJens Taprogge static struct hda_verb ext_mic_present[] = { 23227b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23237b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 23247b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23257b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23267b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23277b2bfdbcSJens Taprogge {} 23287b2bfdbcSJens Taprogge }; 23297b2bfdbcSJens Taprogge static struct hda_verb dock_mic_present[] = { 23307b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 0}, 23317b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 23327b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 23337b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23347b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23357b2bfdbcSJens Taprogge {} 23367b2bfdbcSJens Taprogge }; 23377b2bfdbcSJens Taprogge static struct hda_verb ext_mic_absent[] = { 23387b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, 23397b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 23407b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23417b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 23427b2bfdbcSJens Taprogge {} 23437b2bfdbcSJens Taprogge }; 23447b2bfdbcSJens Taprogge 23457b2bfdbcSJens Taprogge ext_present = snd_hda_jack_detect(codec, 0x1b); 23467b2bfdbcSJens Taprogge dock_present = snd_hda_jack_detect(codec, 0x1a); 23477b2bfdbcSJens Taprogge if (ext_present) { 23487b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone detected\n"); 23497b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_present); 23507b2bfdbcSJens Taprogge } else if (dock_present) { 23517b2bfdbcSJens Taprogge snd_printdd("CXT5066: dock microphone detected\n"); 23527b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, dock_mic_present); 23537b2bfdbcSJens Taprogge } else { 23547b2bfdbcSJens Taprogge snd_printdd("CXT5066: external microphone absent\n"); 23557b2bfdbcSJens Taprogge snd_hda_sequence_write(codec, ext_mic_absent); 23567b2bfdbcSJens Taprogge } 23577b2bfdbcSJens Taprogge } 23587b2bfdbcSJens Taprogge 23590fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 23600fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 23610fb67e98SDaniel Drake { 23620fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 23630fb67e98SDaniel Drake unsigned int portA, portD; 23640fb67e98SDaniel Drake 23650fb67e98SDaniel Drake /* Port A */ 2366d56757abSTakashi Iwai portA = snd_hda_jack_detect(codec, 0x19); 23670fb67e98SDaniel Drake 23680fb67e98SDaniel Drake /* Port D */ 2369d56757abSTakashi Iwai portD = snd_hda_jack_detect(codec, 0x1c); 23700fb67e98SDaniel Drake 23717b2bfdbcSJens Taprogge spec->hp_present = !!(portA); 23727b2bfdbcSJens Taprogge spec->hp_present |= portD ? 2 : 0; 23730fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 23740fb67e98SDaniel Drake portA, portD, spec->hp_present); 23750fb67e98SDaniel Drake cxt5066_update_speaker(codec); 23760fb67e98SDaniel Drake } 23770fb67e98SDaniel Drake 23780fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 237975f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res) 23800fb67e98SDaniel Drake { 2381c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 23820fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 23830fb67e98SDaniel Drake switch (res >> 26) { 23840fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 23850fb67e98SDaniel Drake cxt5066_hp_automute(codec); 23860fb67e98SDaniel Drake break; 23870fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2388c4cfe66cSDaniel Drake /* ignore mic events in DC mode; we're always using the jack */ 2389c4cfe66cSDaniel Drake if (!spec->dc_enable) 239075f8991dSDaniel Drake cxt5066_olpc_automic(codec); 23910fb67e98SDaniel Drake break; 23920fb67e98SDaniel Drake } 23930fb67e98SDaniel Drake } 23940fb67e98SDaniel Drake 239595a618bdSEinar Rünkaru /* unsolicited event for jack sensing */ 239695a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res) 239795a618bdSEinar Rünkaru { 239895a618bdSEinar Rünkaru snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26); 239995a618bdSEinar Rünkaru switch (res >> 26) { 240095a618bdSEinar Rünkaru case CONEXANT_HP_EVENT: 240195a618bdSEinar Rünkaru cxt5066_hp_automute(codec); 240295a618bdSEinar Rünkaru break; 240395a618bdSEinar Rünkaru case CONEXANT_MIC_EVENT: 240495a618bdSEinar Rünkaru cxt5066_vostro_automic(codec); 240595a618bdSEinar Rünkaru break; 240695a618bdSEinar Rünkaru } 240795a618bdSEinar Rünkaru } 240895a618bdSEinar Rünkaru 2409cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */ 2410cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res) 2411cfd3d8dcSGreg Alexander { 2412cfd3d8dcSGreg Alexander snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26); 2413cfd3d8dcSGreg Alexander switch (res >> 26) { 2414cfd3d8dcSGreg Alexander case CONEXANT_HP_EVENT: 2415cfd3d8dcSGreg Alexander cxt5066_hp_automute(codec); 2416cfd3d8dcSGreg Alexander break; 2417cfd3d8dcSGreg Alexander case CONEXANT_MIC_EVENT: 2418cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 2419cfd3d8dcSGreg Alexander break; 2420cfd3d8dcSGreg Alexander } 2421cfd3d8dcSGreg Alexander } 2422cfd3d8dcSGreg Alexander 24237b2bfdbcSJens Taprogge /* unsolicited event for jack sensing */ 2424048e78a5SDavid Henningsson static void cxt5066_hp_laptop_event(struct hda_codec *codec, unsigned int res) 2425048e78a5SDavid Henningsson { 2426048e78a5SDavid Henningsson snd_printdd("CXT5066_hp_laptop: unsol event %x (%x)\n", res, res >> 26); 2427048e78a5SDavid Henningsson switch (res >> 26) { 2428048e78a5SDavid Henningsson case CONEXANT_HP_EVENT: 2429048e78a5SDavid Henningsson cxt5066_hp_automute(codec); 2430048e78a5SDavid Henningsson break; 2431048e78a5SDavid Henningsson case CONEXANT_MIC_EVENT: 2432048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 2433048e78a5SDavid Henningsson break; 2434048e78a5SDavid Henningsson } 2435048e78a5SDavid Henningsson } 2436048e78a5SDavid Henningsson 2437048e78a5SDavid Henningsson /* unsolicited event for jack sensing */ 24387b2bfdbcSJens Taprogge static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res) 24397b2bfdbcSJens Taprogge { 24407b2bfdbcSJens Taprogge snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26); 24417b2bfdbcSJens Taprogge switch (res >> 26) { 24427b2bfdbcSJens Taprogge case CONEXANT_HP_EVENT: 24437b2bfdbcSJens Taprogge cxt5066_hp_automute(codec); 24447b2bfdbcSJens Taprogge break; 24457b2bfdbcSJens Taprogge case CONEXANT_MIC_EVENT: 24467b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 24477b2bfdbcSJens Taprogge break; 24487b2bfdbcSJens Taprogge } 24497b2bfdbcSJens Taprogge } 24507b2bfdbcSJens Taprogge 24510fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 24520fb67e98SDaniel Drake .num_items = 5, 24530fb67e98SDaniel Drake .items = { 24540fb67e98SDaniel Drake { "0dB", 0 }, 24550fb67e98SDaniel Drake { "10dB", 1 }, 24560fb67e98SDaniel Drake { "20dB", 2 }, 24570fb67e98SDaniel Drake { "30dB", 3 }, 24580fb67e98SDaniel Drake { "40dB", 4 }, 24590fb67e98SDaniel Drake }, 24600fb67e98SDaniel Drake }; 24610fb67e98SDaniel Drake 2462cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec) 2463c4cfe66cSDaniel Drake { 2464c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2465cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x17, 0, 2466c4cfe66cSDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2467c4cfe66cSDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2468c4cfe66cSDaniel Drake cxt5066_analog_mic_boost.items[spec->mic_boost].index); 24697b2bfdbcSJens Taprogge if (spec->ideapad || spec->thinkpad) { 2470cfd3d8dcSGreg Alexander /* adjust the internal mic as well...it is not through 0x17 */ 2471cfd3d8dcSGreg Alexander snd_hda_codec_write_cache(codec, 0x23, 0, 2472cfd3d8dcSGreg Alexander AC_VERB_SET_AMP_GAIN_MUTE, 2473cfd3d8dcSGreg Alexander AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT | 2474cfd3d8dcSGreg Alexander cxt5066_analog_mic_boost. 2475cfd3d8dcSGreg Alexander items[spec->mic_boost].index); 2476cfd3d8dcSGreg Alexander } 2477c4cfe66cSDaniel Drake } 2478c4cfe66cSDaniel Drake 24790fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 24800fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 24810fb67e98SDaniel Drake { 24820fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 24830fb67e98SDaniel Drake } 24840fb67e98SDaniel Drake 24850fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 24860fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24870fb67e98SDaniel Drake { 24880fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2489c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2490c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->mic_boost; 24910fb67e98SDaniel Drake return 0; 24920fb67e98SDaniel Drake } 24930fb67e98SDaniel Drake 24940fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 24950fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 24960fb67e98SDaniel Drake { 24970fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2498c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 24990fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 25000fb67e98SDaniel Drake unsigned int idx; 25010fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 25020fb67e98SDaniel Drake if (idx >= imux->num_items) 25030fb67e98SDaniel Drake idx = imux->num_items - 1; 25040fb67e98SDaniel Drake 2505c4cfe66cSDaniel Drake spec->mic_boost = idx; 2506c4cfe66cSDaniel Drake if (!spec->dc_enable) 2507c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2508c4cfe66cSDaniel Drake return 1; 2509c4cfe66cSDaniel Drake } 25100fb67e98SDaniel Drake 2511c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec) 2512c4cfe66cSDaniel Drake { 2513c4cfe66cSDaniel Drake const struct hda_verb enable_dc_mode[] = { 2514c4cfe66cSDaniel Drake /* disable gain */ 2515c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2516c4cfe66cSDaniel Drake 2517c4cfe66cSDaniel Drake /* switch to DC input */ 2518c4cfe66cSDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 3}, 2519c4cfe66cSDaniel Drake {} 2520c4cfe66cSDaniel Drake }; 2521c4cfe66cSDaniel Drake 2522c4cfe66cSDaniel Drake /* configure as input source */ 2523c4cfe66cSDaniel Drake snd_hda_sequence_write(codec, enable_dc_mode); 2524c4cfe66cSDaniel Drake cxt5066_olpc_select_mic(codec); /* also sets configured bias */ 2525c4cfe66cSDaniel Drake } 2526c4cfe66cSDaniel Drake 2527c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec) 2528c4cfe66cSDaniel Drake { 2529c4cfe66cSDaniel Drake /* reconfigure input source */ 2530c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 2531c4cfe66cSDaniel Drake /* automic also selects the right mic if we're recording */ 2532c4cfe66cSDaniel Drake cxt5066_olpc_automic(codec); 2533c4cfe66cSDaniel Drake } 2534c4cfe66cSDaniel Drake 2535c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol, 2536c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2537c4cfe66cSDaniel Drake { 2538c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2539c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2540c4cfe66cSDaniel Drake ucontrol->value.integer.value[0] = spec->dc_enable; 2541c4cfe66cSDaniel Drake return 0; 2542c4cfe66cSDaniel Drake } 2543c4cfe66cSDaniel Drake 2544c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol, 2545c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2546c4cfe66cSDaniel Drake { 2547c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2548c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2549c4cfe66cSDaniel Drake int dc_enable = !!ucontrol->value.integer.value[0]; 2550c4cfe66cSDaniel Drake 2551c4cfe66cSDaniel Drake if (dc_enable == spec->dc_enable) 2552c4cfe66cSDaniel Drake return 0; 2553c4cfe66cSDaniel Drake 2554c4cfe66cSDaniel Drake spec->dc_enable = dc_enable; 2555c4cfe66cSDaniel Drake if (dc_enable) 2556c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 2557c4cfe66cSDaniel Drake else 2558c4cfe66cSDaniel Drake cxt5066_disable_dc(codec); 2559c4cfe66cSDaniel Drake 2560c4cfe66cSDaniel Drake return 1; 2561c4cfe66cSDaniel Drake } 2562c4cfe66cSDaniel Drake 2563c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol, 2564c4cfe66cSDaniel Drake struct snd_ctl_elem_info *uinfo) 2565c4cfe66cSDaniel Drake { 2566c4cfe66cSDaniel Drake return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo); 2567c4cfe66cSDaniel Drake } 2568c4cfe66cSDaniel Drake 2569c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol, 2570c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2571c4cfe66cSDaniel Drake { 2572c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2573c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2574c4cfe66cSDaniel Drake ucontrol->value.enumerated.item[0] = spec->dc_input_bias; 2575c4cfe66cSDaniel Drake return 0; 2576c4cfe66cSDaniel Drake } 2577c4cfe66cSDaniel Drake 2578c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol, 2579c4cfe66cSDaniel Drake struct snd_ctl_elem_value *ucontrol) 2580c4cfe66cSDaniel Drake { 2581c4cfe66cSDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2582c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 2583c4cfe66cSDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2584c4cfe66cSDaniel Drake unsigned int idx; 2585c4cfe66cSDaniel Drake 2586c4cfe66cSDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2587c4cfe66cSDaniel Drake if (idx >= imux->num_items) 2588c4cfe66cSDaniel Drake idx = imux->num_items - 1; 2589c4cfe66cSDaniel Drake 2590c4cfe66cSDaniel Drake spec->dc_input_bias = idx; 2591c4cfe66cSDaniel Drake if (spec->dc_enable) 2592c4cfe66cSDaniel Drake cxt5066_set_olpc_dc_bias(codec); 25930fb67e98SDaniel Drake return 1; 25940fb67e98SDaniel Drake } 25950fb67e98SDaniel Drake 259675f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec) 259775f8991dSDaniel Drake { 259875f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 259975f8991dSDaniel Drake /* mark as recording and configure the microphone widget so that the 260075f8991dSDaniel Drake * recording LED comes on. */ 260175f8991dSDaniel Drake spec->recording = 1; 260275f8991dSDaniel Drake cxt5066_olpc_select_mic(codec); 260375f8991dSDaniel Drake } 260475f8991dSDaniel Drake 260575f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec) 260675f8991dSDaniel Drake { 260775f8991dSDaniel Drake struct conexant_spec *spec = codec->spec; 260875f8991dSDaniel Drake const struct hda_verb disable_mics[] = { 260975f8991dSDaniel Drake /* disable external mic, port B */ 261075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 261175f8991dSDaniel Drake 261275f8991dSDaniel Drake /* disble internal mic, port C */ 261375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2614c4cfe66cSDaniel Drake 2615c4cfe66cSDaniel Drake /* disable DC capture, port F */ 2616c4cfe66cSDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 261775f8991dSDaniel Drake {}, 261875f8991dSDaniel Drake }; 261975f8991dSDaniel Drake 262075f8991dSDaniel Drake snd_hda_sequence_write(codec, disable_mics); 262175f8991dSDaniel Drake spec->recording = 0; 262275f8991dSDaniel Drake } 262375f8991dSDaniel Drake 26240fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 26250fb67e98SDaniel Drake .num_items = 4, 26260fb67e98SDaniel Drake .items = { 26270fb67e98SDaniel Drake { "Mic B", 0 }, 26280fb67e98SDaniel Drake { "Mic C", 1 }, 26290fb67e98SDaniel Drake { "Mic E", 2 }, 26300fb67e98SDaniel Drake { "Mic F", 3 }, 26310fb67e98SDaniel Drake }, 26320fb67e98SDaniel Drake }; 26330fb67e98SDaniel Drake 26340fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 26350fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 26360fb67e98SDaniel Drake .values = { 26370fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26380fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26390fb67e98SDaniel Drake 0 26400fb67e98SDaniel Drake }, 26410fb67e98SDaniel Drake }; 26420fb67e98SDaniel Drake 26430fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 26440fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 26450fb67e98SDaniel Drake .values = { 26460fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 26470fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 26480fb67e98SDaniel Drake 0 26490fb67e98SDaniel Drake }, 26500fb67e98SDaniel Drake }; 26510fb67e98SDaniel Drake 26520fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 26530fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 26540fb67e98SDaniel Drake {} 26550fb67e98SDaniel Drake }; 26560fb67e98SDaniel Drake 26570fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 26580fb67e98SDaniel Drake { 26590fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26600fb67e98SDaniel Drake .name = "Master Playback Volume", 26610fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 26620fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 26630fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 26645e26dfd0SJaroslav Kysela .subdevice = HDA_SUBDEV_AMP_FLAG, 26650fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 26660fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 26670fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 26680fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 26690fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 26700fb67e98SDaniel Drake .private_value = 26710fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 26720fb67e98SDaniel Drake }, 26730fb67e98SDaniel Drake {} 26740fb67e98SDaniel Drake }; 26750fb67e98SDaniel Drake 2676c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = { 2677c4cfe66cSDaniel Drake { 2678c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2679c4cfe66cSDaniel Drake .name = "DC Mode Enable Switch", 2680c4cfe66cSDaniel Drake .info = snd_ctl_boolean_mono_info, 2681c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_get, 2682c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_put, 2683c4cfe66cSDaniel Drake }, 2684c4cfe66cSDaniel Drake { 2685c4cfe66cSDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2686c4cfe66cSDaniel Drake .name = "DC Input Bias Enum", 2687c4cfe66cSDaniel Drake .info = cxt5066_olpc_dc_bias_enum_info, 2688c4cfe66cSDaniel Drake .get = cxt5066_olpc_dc_bias_enum_get, 2689c4cfe66cSDaniel Drake .put = cxt5066_olpc_dc_bias_enum_put, 2690c4cfe66cSDaniel Drake }, 2691c4cfe66cSDaniel Drake {} 2692c4cfe66cSDaniel Drake }; 2693c4cfe66cSDaniel Drake 26940fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 26950fb67e98SDaniel Drake { 26960fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 26970fb67e98SDaniel Drake .name = "Master Playback Switch", 26980fb67e98SDaniel Drake .info = cxt_eapd_info, 26990fb67e98SDaniel Drake .get = cxt_eapd_get, 27000fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 27010fb67e98SDaniel Drake .private_value = 0x1d, 27020fb67e98SDaniel Drake }, 27030fb67e98SDaniel Drake 27040fb67e98SDaniel Drake { 27050fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2706c4cfe66cSDaniel Drake .name = "Analog Mic Boost Capture Enum", 27070fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 27080fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 27090fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 27100fb67e98SDaniel Drake }, 27110fb67e98SDaniel Drake 27120fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 27130fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 27140fb67e98SDaniel Drake {} 27150fb67e98SDaniel Drake }; 27160fb67e98SDaniel Drake 2717254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = { 2718254bba6aSEinar Rünkaru { 2719254bba6aSEinar Rünkaru .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2720254bba6aSEinar Rünkaru .name = "Int Mic Boost Capture Enum", 2721254bba6aSEinar Rünkaru .info = cxt5066_mic_boost_mux_enum_info, 2722254bba6aSEinar Rünkaru .get = cxt5066_mic_boost_mux_enum_get, 2723254bba6aSEinar Rünkaru .put = cxt5066_mic_boost_mux_enum_put, 2724254bba6aSEinar Rünkaru .private_value = 0x23 | 0x100, 2725254bba6aSEinar Rünkaru }, 2726254bba6aSEinar Rünkaru {} 2727254bba6aSEinar Rünkaru }; 2728254bba6aSEinar Rünkaru 27290fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 27300fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 27310fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 27320fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 27330fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 27340fb67e98SDaniel Drake 27350fb67e98SDaniel Drake /* Speakers */ 27360fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27370fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27380fb67e98SDaniel Drake 27390fb67e98SDaniel Drake /* HP, Amp */ 27400fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27410fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27420fb67e98SDaniel Drake 27430fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27440fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27450fb67e98SDaniel Drake 27460fb67e98SDaniel Drake /* DAC1 */ 27470fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 27480fb67e98SDaniel Drake 27490fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 27500fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 27510fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 27520fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 27530fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 27540fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 27550fb67e98SDaniel Drake 27560fb67e98SDaniel Drake /* no digital microphone support yet */ 27570fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27580fb67e98SDaniel Drake 27590fb67e98SDaniel Drake /* Audio input selector */ 27600fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 27610fb67e98SDaniel Drake 27620fb67e98SDaniel Drake /* SPDIF route: PCM */ 27630fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 27640fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 27650fb67e98SDaniel Drake 27660fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27670fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 27680fb67e98SDaniel Drake 27690fb67e98SDaniel Drake /* EAPD */ 27700fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 27710fb67e98SDaniel Drake 27720fb67e98SDaniel Drake /* not handling these yet */ 27730fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27740fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27750fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27760fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27770fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27780fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27790fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27800fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 27810fb67e98SDaniel Drake { } /* end */ 27820fb67e98SDaniel Drake }; 27830fb67e98SDaniel Drake 27840fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 27850fb67e98SDaniel Drake /* Port A: headphones */ 27860fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 27870fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 27880fb67e98SDaniel Drake 27890fb67e98SDaniel Drake /* Port B: external microphone */ 279075f8991dSDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27910fb67e98SDaniel Drake 27920fb67e98SDaniel Drake /* Port C: internal microphone */ 279375f8991dSDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27940fb67e98SDaniel Drake 27950fb67e98SDaniel Drake /* Port D: unused */ 27960fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 27970fb67e98SDaniel Drake 27980fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 27990fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28000fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 28010fb67e98SDaniel Drake 2802c4cfe66cSDaniel Drake /* Port F: external DC input through microphone port */ 28030fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28040fb67e98SDaniel Drake 28050fb67e98SDaniel Drake /* Port G: internal speakers */ 28060fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 28070fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 28080fb67e98SDaniel Drake 28090fb67e98SDaniel Drake /* DAC1 */ 28100fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 28110fb67e98SDaniel Drake 28120fb67e98SDaniel Drake /* DAC2: unused */ 28130fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 28140fb67e98SDaniel Drake 28150fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 28160fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28170fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28180fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28190fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28200fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28210fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28220fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28230fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 28240fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 28250fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 28260fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 28270fb67e98SDaniel Drake 28280fb67e98SDaniel Drake /* Disable digital microphone port */ 28290fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28300fb67e98SDaniel Drake 28310fb67e98SDaniel Drake /* Audio input selectors */ 28320fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 28330fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 28340fb67e98SDaniel Drake 28350fb67e98SDaniel Drake /* Disable SPDIF */ 28360fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28370fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 28380fb67e98SDaniel Drake 28390fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 28400fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 28410fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 28420fb67e98SDaniel Drake { } /* end */ 28430fb67e98SDaniel Drake }; 28440fb67e98SDaniel Drake 284595a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = { 284695a618bdSEinar Rünkaru /* Port A: headphones */ 284795a618bdSEinar Rünkaru {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 284895a618bdSEinar Rünkaru {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 284995a618bdSEinar Rünkaru 285095a618bdSEinar Rünkaru /* Port B: external microphone */ 285195a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 285295a618bdSEinar Rünkaru 285395a618bdSEinar Rünkaru /* Port C: unused */ 285495a618bdSEinar Rünkaru {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 285595a618bdSEinar Rünkaru 285695a618bdSEinar Rünkaru /* Port D: unused */ 285795a618bdSEinar Rünkaru {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 285895a618bdSEinar Rünkaru 285995a618bdSEinar Rünkaru /* Port E: unused, but has primary EAPD */ 286095a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286195a618bdSEinar Rünkaru {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 286295a618bdSEinar Rünkaru 286395a618bdSEinar Rünkaru /* Port F: unused */ 286495a618bdSEinar Rünkaru {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 286595a618bdSEinar Rünkaru 286695a618bdSEinar Rünkaru /* Port G: internal speakers */ 286795a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 286895a618bdSEinar Rünkaru {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 286995a618bdSEinar Rünkaru 287095a618bdSEinar Rünkaru /* DAC1 */ 287195a618bdSEinar Rünkaru {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 287295a618bdSEinar Rünkaru 287395a618bdSEinar Rünkaru /* DAC2: unused */ 287495a618bdSEinar Rünkaru {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 287595a618bdSEinar Rünkaru 287695a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 287795a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 287895a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 287995a618bdSEinar Rünkaru {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 288095a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 288195a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 288295a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 288395a618bdSEinar Rünkaru {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 288495a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 288595a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 288695a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 288795a618bdSEinar Rünkaru {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 288895a618bdSEinar Rünkaru 288995a618bdSEinar Rünkaru /* Digital microphone port */ 289095a618bdSEinar Rünkaru {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 289195a618bdSEinar Rünkaru 289295a618bdSEinar Rünkaru /* Audio input selectors */ 289395a618bdSEinar Rünkaru {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 289495a618bdSEinar Rünkaru {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 289595a618bdSEinar Rünkaru 289695a618bdSEinar Rünkaru /* Disable SPDIF */ 289795a618bdSEinar Rünkaru {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 289895a618bdSEinar Rünkaru {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 289995a618bdSEinar Rünkaru 290095a618bdSEinar Rünkaru /* enable unsolicited events for Port A and B */ 290195a618bdSEinar Rünkaru {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 290295a618bdSEinar Rünkaru {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 290395a618bdSEinar Rünkaru { } /* end */ 290495a618bdSEinar Rünkaru }; 290595a618bdSEinar Rünkaru 2906cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = { 2907cfd3d8dcSGreg Alexander {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2908cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2909cfd3d8dcSGreg Alexander {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2910cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2911cfd3d8dcSGreg Alexander 2912cfd3d8dcSGreg Alexander /* Speakers */ 2913cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2914cfd3d8dcSGreg Alexander {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2915cfd3d8dcSGreg Alexander 2916cfd3d8dcSGreg Alexander /* HP, Amp */ 2917cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2918cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2919cfd3d8dcSGreg Alexander 2920cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2921cfd3d8dcSGreg Alexander {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2922cfd3d8dcSGreg Alexander 2923cfd3d8dcSGreg Alexander /* DAC1 */ 2924cfd3d8dcSGreg Alexander {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2925cfd3d8dcSGreg Alexander 2926cfd3d8dcSGreg Alexander /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2927cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2928cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2929cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2930cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2931cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2932cfd3d8dcSGreg Alexander {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 2933cfd3d8dcSGreg Alexander 2934cfd3d8dcSGreg Alexander /* Audio input selector */ 2935cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 2936cfd3d8dcSGreg Alexander {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 2937cfd3d8dcSGreg Alexander 2938cfd3d8dcSGreg Alexander /* SPDIF route: PCM */ 2939cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2940cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2941cfd3d8dcSGreg Alexander 2942cfd3d8dcSGreg Alexander {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2943cfd3d8dcSGreg Alexander {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2944cfd3d8dcSGreg Alexander 2945cfd3d8dcSGreg Alexander /* internal microphone */ 2946cfd3d8dcSGreg Alexander {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 2947cfd3d8dcSGreg Alexander 2948cfd3d8dcSGreg Alexander /* EAPD */ 2949cfd3d8dcSGreg Alexander {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2950cfd3d8dcSGreg Alexander 2951cfd3d8dcSGreg Alexander {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2952cfd3d8dcSGreg Alexander {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2953cfd3d8dcSGreg Alexander { } /* end */ 2954cfd3d8dcSGreg Alexander }; 2955cfd3d8dcSGreg Alexander 29567b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = { 29577b2bfdbcSJens Taprogge {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 29587b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 29597b2bfdbcSJens Taprogge 29607b2bfdbcSJens Taprogge /* Port G: internal speakers */ 29617b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29627b2bfdbcSJens Taprogge {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29637b2bfdbcSJens Taprogge 29647b2bfdbcSJens Taprogge /* Port A: HP, Amp */ 29657b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29667b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29677b2bfdbcSJens Taprogge 29687b2bfdbcSJens Taprogge /* Port B: Mic Dock */ 29697b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29707b2bfdbcSJens Taprogge 29717b2bfdbcSJens Taprogge /* Port C: Mic */ 29727b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29737b2bfdbcSJens Taprogge 29747b2bfdbcSJens Taprogge /* Port D: HP Dock, Amp */ 29757b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 29767b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 29777b2bfdbcSJens Taprogge 29787b2bfdbcSJens Taprogge /* DAC1 */ 29797b2bfdbcSJens Taprogge {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 29807b2bfdbcSJens Taprogge 29817b2bfdbcSJens Taprogge /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 29827b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 29837b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 29847b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 29857b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 29867b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 29877b2bfdbcSJens Taprogge {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */ 29887b2bfdbcSJens Taprogge 29897b2bfdbcSJens Taprogge /* Audio input selector */ 29907b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2}, 29917b2bfdbcSJens Taprogge {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */ 29927b2bfdbcSJens Taprogge 29937b2bfdbcSJens Taprogge /* SPDIF route: PCM */ 29947b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 29957b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 29967b2bfdbcSJens Taprogge 29977b2bfdbcSJens Taprogge {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29987b2bfdbcSJens Taprogge {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 29997b2bfdbcSJens Taprogge 30007b2bfdbcSJens Taprogge /* internal microphone */ 30017b2bfdbcSJens Taprogge {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */ 30027b2bfdbcSJens Taprogge 30037b2bfdbcSJens Taprogge /* EAPD */ 30047b2bfdbcSJens Taprogge {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 30057b2bfdbcSJens Taprogge 30067b2bfdbcSJens Taprogge /* enable unsolicited events for Port A, B, C and D */ 30077b2bfdbcSJens Taprogge {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30087b2bfdbcSJens Taprogge {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 30097b2bfdbcSJens Taprogge {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30107b2bfdbcSJens Taprogge {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 30117b2bfdbcSJens Taprogge { } /* end */ 30127b2bfdbcSJens Taprogge }; 30137b2bfdbcSJens Taprogge 30140fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 30150fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 30160fb67e98SDaniel Drake { } /* end */ 30170fb67e98SDaniel Drake }; 30180fb67e98SDaniel Drake 3019048e78a5SDavid Henningsson 3020048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = { 3021048e78a5SDavid Henningsson {0x14, AC_VERB_SET_CONNECT_SEL, 0x0}, 3022048e78a5SDavid Henningsson {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 3023048e78a5SDavid Henningsson {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 3024048e78a5SDavid Henningsson { } /* end */ 3025048e78a5SDavid Henningsson }; 3026048e78a5SDavid Henningsson 30270fb67e98SDaniel Drake /* initialize jack-sensing, too */ 30280fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 30290fb67e98SDaniel Drake { 3030254bba6aSEinar Rünkaru struct conexant_spec *spec = codec->spec; 3031254bba6aSEinar Rünkaru 30320fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 30330fb67e98SDaniel Drake conexant_init(codec); 30340fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 30350fb67e98SDaniel Drake cxt5066_hp_automute(codec); 3036254bba6aSEinar Rünkaru if (spec->dell_vostro) 3037254bba6aSEinar Rünkaru cxt5066_vostro_automic(codec); 3038cfd3d8dcSGreg Alexander else if (spec->ideapad) 3039cfd3d8dcSGreg Alexander cxt5066_ideapad_automic(codec); 30407b2bfdbcSJens Taprogge else if (spec->thinkpad) 30417b2bfdbcSJens Taprogge cxt5066_thinkpad_automic(codec); 3042048e78a5SDavid Henningsson else if (spec->hp_laptop) 3043048e78a5SDavid Henningsson cxt5066_hp_laptop_automic(codec); 30440fb67e98SDaniel Drake } 3045c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 30460fb67e98SDaniel Drake return 0; 30470fb67e98SDaniel Drake } 30480fb67e98SDaniel Drake 304975f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec) 305075f8991dSDaniel Drake { 3051c4cfe66cSDaniel Drake struct conexant_spec *spec = codec->spec; 305275f8991dSDaniel Drake snd_printdd("CXT5066: init\n"); 305375f8991dSDaniel Drake conexant_init(codec); 305475f8991dSDaniel Drake cxt5066_hp_automute(codec); 3055c4cfe66cSDaniel Drake if (!spec->dc_enable) { 3056c4cfe66cSDaniel Drake cxt5066_set_mic_boost(codec); 305775f8991dSDaniel Drake cxt5066_olpc_automic(codec); 3058c4cfe66cSDaniel Drake } else { 3059c4cfe66cSDaniel Drake cxt5066_enable_dc(codec); 3060c4cfe66cSDaniel Drake } 306175f8991dSDaniel Drake return 0; 306275f8991dSDaniel Drake } 306375f8991dSDaniel Drake 30640fb67e98SDaniel Drake enum { 30650fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 30660fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 30670fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 306895a618bdSEinar Rünkaru CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */ 3069cfd3d8dcSGreg Alexander CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */ 30707b2bfdbcSJens Taprogge CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */ 3071048e78a5SDavid Henningsson CXT5066_HP_LAPTOP, /* HP Laptop */ 30720fb67e98SDaniel Drake CXT5066_MODELS 30730fb67e98SDaniel Drake }; 30740fb67e98SDaniel Drake 30750fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = { 30760fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 30770fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 30780fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 3079cfd3d8dcSGreg Alexander [CXT5066_DELL_VOSTO] = "dell-vostro", 3080cfd3d8dcSGreg Alexander [CXT5066_IDEAPAD] = "ideapad", 30817b2bfdbcSJens Taprogge [CXT5066_THINKPAD] = "thinkpad", 3082048e78a5SDavid Henningsson [CXT5066_HP_LAPTOP] = "hp-laptop", 30830fb67e98SDaniel Drake }; 30840fb67e98SDaniel Drake 30850fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 30860fb67e98SDaniel Drake SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 30870fb67e98SDaniel Drake CXT5066_LAPTOP), 30880fb67e98SDaniel Drake SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 30890fb67e98SDaniel Drake CXT5066_DELL_LAPTOP), 3090798a8a15SDaniel Drake SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5), 3091c3e68fadSTakashi Iwai SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTO), 309295a618bdSEinar Rünkaru SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO), 3093231f50bcSAnisse Astier SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD), 3094048e78a5SDavid Henningsson SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP), 3095c5366681SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5), 30964442dd46SDaniel T Chen SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5), 3097*4d155641STakashi Iwai SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD), 30980217f149SAndrej Gelenberg SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD), 3099badf18b5SAndreas Herrmann SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD), 3100a39e33ebSJerone Young SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD), 31017b2bfdbcSJens Taprogge SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3102ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD), 31036f0ef6eaSJerone Young SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD), 3104ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD), 3105ab85457fSJerone Young SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD), 31060fb67e98SDaniel Drake {} 31070fb67e98SDaniel Drake }; 31080fb67e98SDaniel Drake 31090fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 31100fb67e98SDaniel Drake { 31110fb67e98SDaniel Drake struct conexant_spec *spec; 31120fb67e98SDaniel Drake int board_config; 31130fb67e98SDaniel Drake 31140fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 31150fb67e98SDaniel Drake if (!spec) 31160fb67e98SDaniel Drake return -ENOMEM; 31170fb67e98SDaniel Drake codec->spec = spec; 31180fb67e98SDaniel Drake 31190fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 312075f8991dSDaniel Drake codec->patch_ops.init = conexant_init; 31210fb67e98SDaniel Drake 31220fb67e98SDaniel Drake spec->dell_automute = 0; 31230fb67e98SDaniel Drake spec->multiout.max_channels = 2; 31240fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 31250fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 31260fb67e98SDaniel Drake spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT; 31270fb67e98SDaniel Drake spec->num_adc_nids = 1; 31280fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 31290fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 31300fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 31310fb67e98SDaniel Drake 31320fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 31330fb67e98SDaniel Drake 31340fb67e98SDaniel Drake spec->num_init_verbs = 1; 31350fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 31360fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 31370fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 31380fb67e98SDaniel Drake spec->cur_adc = 0; 31390fb67e98SDaniel Drake spec->cur_adc_idx = 0; 31400fb67e98SDaniel Drake 31413507e2a8STakashi Iwai set_beep_amp(spec, 0x13, 0, HDA_OUTPUT); 31423507e2a8STakashi Iwai 31430fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 31440fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 31450fb67e98SDaniel Drake switch (board_config) { 31460fb67e98SDaniel Drake default: 31470fb67e98SDaniel Drake case CXT5066_LAPTOP: 31480fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31490fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31500fb67e98SDaniel Drake break; 31510fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 31520fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 31530fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31540fb67e98SDaniel Drake 31550fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 31560fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 31570fb67e98SDaniel Drake spec->num_init_verbs++; 31580fb67e98SDaniel Drake spec->dell_automute = 1; 31590fb67e98SDaniel Drake break; 3160048e78a5SDavid Henningsson case CXT5066_HP_LAPTOP: 3161048e78a5SDavid Henningsson codec->patch_ops.init = cxt5066_init; 3162048e78a5SDavid Henningsson codec->patch_ops.unsol_event = cxt5066_hp_laptop_event; 3163048e78a5SDavid Henningsson spec->init_verbs[spec->num_init_verbs] = 3164048e78a5SDavid Henningsson cxt5066_init_verbs_hp_laptop; 3165048e78a5SDavid Henningsson spec->num_init_verbs++; 3166048e78a5SDavid Henningsson spec->hp_laptop = 1; 3167048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3168048e78a5SDavid Henningsson spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3169048e78a5SDavid Henningsson /* no S/PDIF out */ 3170048e78a5SDavid Henningsson spec->multiout.dig_out_nid = 0; 3171048e78a5SDavid Henningsson /* input source automatically selected */ 3172048e78a5SDavid Henningsson spec->input_mux = NULL; 3173048e78a5SDavid Henningsson spec->port_d_mode = 0; 3174048e78a5SDavid Henningsson spec->mic_boost = 3; /* default 30dB gain */ 3175048e78a5SDavid Henningsson break; 3176048e78a5SDavid Henningsson 31770fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 317875f8991dSDaniel Drake codec->patch_ops.init = cxt5066_olpc_init; 317975f8991dSDaniel Drake codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event; 31800fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 31810fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 3182c4cfe66cSDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc; 31830fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 31840fb67e98SDaniel Drake spec->port_d_mode = 0; 3185c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 31860fb67e98SDaniel Drake 31870fb67e98SDaniel Drake /* no S/PDIF out */ 31880fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 31890fb67e98SDaniel Drake 31900fb67e98SDaniel Drake /* input source automatically selected */ 31910fb67e98SDaniel Drake spec->input_mux = NULL; 319275f8991dSDaniel Drake 319375f8991dSDaniel Drake /* our capture hooks which allow us to turn on the microphone LED 319475f8991dSDaniel Drake * at the right time */ 319575f8991dSDaniel Drake spec->capture_prepare = cxt5066_olpc_capture_prepare; 319675f8991dSDaniel Drake spec->capture_cleanup = cxt5066_olpc_capture_cleanup; 31970fb67e98SDaniel Drake break; 319895a618bdSEinar Rünkaru case CXT5066_DELL_VOSTO: 319975f8991dSDaniel Drake codec->patch_ops.init = cxt5066_init; 320095a618bdSEinar Rünkaru codec->patch_ops.unsol_event = cxt5066_vostro_event; 320195a618bdSEinar Rünkaru spec->init_verbs[0] = cxt5066_init_verbs_vostro; 320295a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 320395a618bdSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3204254bba6aSEinar Rünkaru spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers; 320595a618bdSEinar Rünkaru spec->port_d_mode = 0; 3206254bba6aSEinar Rünkaru spec->dell_vostro = 1; 3207c4cfe66cSDaniel Drake spec->mic_boost = 3; /* default 30dB gain */ 320895a618bdSEinar Rünkaru 320995a618bdSEinar Rünkaru /* no S/PDIF out */ 321095a618bdSEinar Rünkaru spec->multiout.dig_out_nid = 0; 321195a618bdSEinar Rünkaru 321295a618bdSEinar Rünkaru /* input source automatically selected */ 321395a618bdSEinar Rünkaru spec->input_mux = NULL; 321495a618bdSEinar Rünkaru break; 3215cfd3d8dcSGreg Alexander case CXT5066_IDEAPAD: 3216cfd3d8dcSGreg Alexander codec->patch_ops.init = cxt5066_init; 3217cfd3d8dcSGreg Alexander codec->patch_ops.unsol_event = cxt5066_ideapad_event; 3218cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 3219cfd3d8dcSGreg Alexander spec->mixers[spec->num_mixers++] = cxt5066_mixers; 3220cfd3d8dcSGreg Alexander spec->init_verbs[0] = cxt5066_init_verbs_ideapad; 3221cfd3d8dcSGreg Alexander spec->port_d_mode = 0; 3222cfd3d8dcSGreg Alexander spec->ideapad = 1; 3223cfd3d8dcSGreg Alexander spec->mic_boost = 2; /* default 20dB gain */ 3224cfd3d8dcSGreg Alexander 3225cfd3d8dcSGreg Alexander /* no S/PDIF out */ 3226cfd3d8dcSGreg Alexander spec->multiout.dig_out_nid = 0; 3227cfd3d8dcSGreg Alexander 3228cfd3d8dcSGreg Alexander /* input source automatically selected */ 3229cfd3d8dcSGreg Alexander spec->input_mux = NULL; 3230cfd3d8dcSGreg Alexander break; 32317b2bfdbcSJens Taprogge case CXT5066_THINKPAD: 32327b2bfdbcSJens Taprogge codec->patch_ops.init = cxt5066_init; 32337b2bfdbcSJens Taprogge codec->patch_ops.unsol_event = cxt5066_thinkpad_event; 32347b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 32357b2bfdbcSJens Taprogge spec->mixers[spec->num_mixers++] = cxt5066_mixers; 32367b2bfdbcSJens Taprogge spec->init_verbs[0] = cxt5066_init_verbs_thinkpad; 32377b2bfdbcSJens Taprogge spec->thinkpad = 1; 32387b2bfdbcSJens Taprogge spec->port_d_mode = PIN_OUT; 32397b2bfdbcSJens Taprogge spec->mic_boost = 2; /* default 20dB gain */ 32407b2bfdbcSJens Taprogge 32417b2bfdbcSJens Taprogge /* no S/PDIF out */ 32427b2bfdbcSJens Taprogge spec->multiout.dig_out_nid = 0; 32437b2bfdbcSJens Taprogge 32447b2bfdbcSJens Taprogge /* input source automatically selected */ 32457b2bfdbcSJens Taprogge spec->input_mux = NULL; 32467b2bfdbcSJens Taprogge break; 32470fb67e98SDaniel Drake } 32480fb67e98SDaniel Drake 32493507e2a8STakashi Iwai if (spec->beep_amp) 32503507e2a8STakashi Iwai snd_hda_attach_beep_device(codec, spec->beep_amp); 32513507e2a8STakashi Iwai 32520fb67e98SDaniel Drake return 0; 32530fb67e98SDaniel Drake } 3254461e2c78STakashi Iwai 3255461e2c78STakashi Iwai /* 3256461e2c78STakashi Iwai */ 3257461e2c78STakashi Iwai 32581289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 325982f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 326082f30040STobin Davis .patch = patch_cxt5045 }, 326182f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 326282f30040STobin Davis .patch = patch_cxt5047 }, 3263461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 3264461e2c78STakashi Iwai .patch = patch_cxt5051 }, 32650fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 32660fb67e98SDaniel Drake .patch = patch_cxt5066 }, 326795a618bdSEinar Rünkaru { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)", 326895a618bdSEinar Rünkaru .patch = patch_cxt5066 }, 3269850eab9dSTakashi Iwai { .id = 0x14f15068, .name = "CX20584", 3270850eab9dSTakashi Iwai .patch = patch_cxt5066 }, 32717b2bfdbcSJens Taprogge { .id = 0x14f15069, .name = "CX20585", 32727b2bfdbcSJens Taprogge .patch = patch_cxt5066 }, 3273c9b443d4STobin Davis {} /* terminator */ 3274c9b443d4STobin Davis }; 32751289e9e8STakashi Iwai 32761289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 32771289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 32781289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 32790fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 328095a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067"); 3281850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068"); 32827b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069"); 32831289e9e8STakashi Iwai 32841289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 32851289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 32861289e9e8STakashi Iwai 32871289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 32881289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 32891289e9e8STakashi Iwai .owner = THIS_MODULE, 32901289e9e8STakashi Iwai }; 32911289e9e8STakashi Iwai 32921289e9e8STakashi Iwai static int __init patch_conexant_init(void) 32931289e9e8STakashi Iwai { 32941289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 32951289e9e8STakashi Iwai } 32961289e9e8STakashi Iwai 32971289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 32981289e9e8STakashi Iwai { 32991289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 33001289e9e8STakashi Iwai } 33011289e9e8STakashi Iwai 33021289e9e8STakashi Iwai module_init(patch_conexant_init) 33031289e9e8STakashi Iwai module_exit(patch_conexant_exit) 3304