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" 32c9b443d4STobin Davis 33c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 34c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 35c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 36c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 37c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 38c9b443d4STobin Davis 39c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 40c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 41c9b443d4STobin Davis 42bc7a166dSUlrich Dangel /* Conexant 5051 specific */ 43c9b443d4STobin Davis 44bc7a166dSUlrich Dangel #define CXT5051_SPDIF_OUT 0x1C 45bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT 0x38 46bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT 0x39 47bc7a166dSUlrich Dangel 48bc7a166dSUlrich Dangel 49bc7a166dSUlrich Dangel struct conexant_jack { 50bc7a166dSUlrich Dangel 51bc7a166dSUlrich Dangel hda_nid_t nid; 52bc7a166dSUlrich Dangel int type; 53bc7a166dSUlrich Dangel struct snd_jack *jack; 54bc7a166dSUlrich Dangel 55bc7a166dSUlrich Dangel }; 56c9b443d4STobin Davis 57c9b443d4STobin Davis struct conexant_spec { 58c9b443d4STobin Davis 59c9b443d4STobin Davis struct snd_kcontrol_new *mixers[5]; 60c9b443d4STobin Davis int num_mixers; 61*dd5746a8STakashi Iwai hda_nid_t vmaster_nid; 62c9b443d4STobin Davis 63c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 64c9b443d4STobin Davis * don't forget NULL 65c9b443d4STobin Davis * termination! 66c9b443d4STobin Davis */ 67c9b443d4STobin Davis unsigned int num_init_verbs; 68c9b443d4STobin Davis 69c9b443d4STobin Davis /* playback */ 70c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 71c9b443d4STobin Davis * max_channels, dacs must be set 72c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 73c9b443d4STobin Davis */ 74c9b443d4STobin Davis unsigned int cur_eapd; 7582f30040STobin Davis unsigned int hp_present; 7679d7d533STakashi Iwai unsigned int no_auto_mic; 77c9b443d4STobin Davis unsigned int need_dac_fix; 78c9b443d4STobin Davis 79c9b443d4STobin Davis /* capture */ 80c9b443d4STobin Davis unsigned int num_adc_nids; 81c9b443d4STobin Davis hda_nid_t *adc_nids; 82c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 83c9b443d4STobin Davis 84461e2c78STakashi Iwai unsigned int cur_adc_idx; 85461e2c78STakashi Iwai hda_nid_t cur_adc; 86461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 87461e2c78STakashi Iwai unsigned int cur_adc_format; 88461e2c78STakashi Iwai 89c9b443d4STobin Davis /* capture source */ 90c9b443d4STobin Davis const struct hda_input_mux *input_mux; 91c9b443d4STobin Davis hda_nid_t *capsrc_nids; 92c9b443d4STobin Davis unsigned int cur_mux[3]; 93c9b443d4STobin Davis 94c9b443d4STobin Davis /* channel model */ 95c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 96c9b443d4STobin Davis int num_channel_mode; 97c9b443d4STobin Davis 98c9b443d4STobin Davis /* PCM information */ 99c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 100c9b443d4STobin Davis 101c9b443d4STobin Davis unsigned int spdif_route; 102c9b443d4STobin Davis 103bc7a166dSUlrich Dangel /* jack detection */ 104bc7a166dSUlrich Dangel struct snd_array jacks; 105bc7a166dSUlrich Dangel 106c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 107c9b443d4STobin Davis struct auto_pin_cfg autocfg; 108c9b443d4STobin Davis struct hda_input_mux private_imux; 10941923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 110c9b443d4STobin Davis 111c9b443d4STobin Davis }; 112c9b443d4STobin Davis 113c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 114c9b443d4STobin Davis struct hda_codec *codec, 115c9b443d4STobin Davis struct snd_pcm_substream *substream) 116c9b443d4STobin Davis { 117c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1189a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1199a08160bSTakashi Iwai hinfo); 120c9b443d4STobin Davis } 121c9b443d4STobin Davis 122c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 123c9b443d4STobin Davis struct hda_codec *codec, 124c9b443d4STobin Davis unsigned int stream_tag, 125c9b443d4STobin Davis unsigned int format, 126c9b443d4STobin Davis struct snd_pcm_substream *substream) 127c9b443d4STobin Davis { 128c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 129c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 130c9b443d4STobin Davis stream_tag, 131c9b443d4STobin Davis format, substream); 132c9b443d4STobin Davis } 133c9b443d4STobin Davis 134c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 135c9b443d4STobin Davis struct hda_codec *codec, 136c9b443d4STobin Davis struct snd_pcm_substream *substream) 137c9b443d4STobin Davis { 138c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 139c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 140c9b443d4STobin Davis } 141c9b443d4STobin Davis 142c9b443d4STobin Davis /* 143c9b443d4STobin Davis * Digital out 144c9b443d4STobin Davis */ 145c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 146c9b443d4STobin Davis struct hda_codec *codec, 147c9b443d4STobin Davis struct snd_pcm_substream *substream) 148c9b443d4STobin Davis { 149c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 150c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 151c9b443d4STobin Davis } 152c9b443d4STobin Davis 153c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 154c9b443d4STobin Davis struct hda_codec *codec, 155c9b443d4STobin Davis struct snd_pcm_substream *substream) 156c9b443d4STobin Davis { 157c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 158c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 159c9b443d4STobin Davis } 160c9b443d4STobin Davis 1616b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1626b97eb45STakashi Iwai struct hda_codec *codec, 1636b97eb45STakashi Iwai unsigned int stream_tag, 1646b97eb45STakashi Iwai unsigned int format, 1656b97eb45STakashi Iwai struct snd_pcm_substream *substream) 1666b97eb45STakashi Iwai { 1676b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 1686b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 1696b97eb45STakashi Iwai stream_tag, 1706b97eb45STakashi Iwai format, substream); 1716b97eb45STakashi Iwai } 1726b97eb45STakashi Iwai 173c9b443d4STobin Davis /* 174c9b443d4STobin Davis * Analog capture 175c9b443d4STobin Davis */ 176c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 177c9b443d4STobin Davis struct hda_codec *codec, 178c9b443d4STobin Davis unsigned int stream_tag, 179c9b443d4STobin Davis unsigned int format, 180c9b443d4STobin Davis struct snd_pcm_substream *substream) 181c9b443d4STobin Davis { 182c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 183c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 184c9b443d4STobin Davis stream_tag, 0, format); 185c9b443d4STobin Davis return 0; 186c9b443d4STobin Davis } 187c9b443d4STobin Davis 188c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 189c9b443d4STobin Davis struct hda_codec *codec, 190c9b443d4STobin Davis struct snd_pcm_substream *substream) 191c9b443d4STobin Davis { 192c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 193888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 194c9b443d4STobin Davis return 0; 195c9b443d4STobin Davis } 196c9b443d4STobin Davis 197c9b443d4STobin Davis 198c9b443d4STobin Davis 199c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 200c9b443d4STobin Davis .substreams = 1, 201c9b443d4STobin Davis .channels_min = 2, 202c9b443d4STobin Davis .channels_max = 2, 203c9b443d4STobin Davis .nid = 0, /* fill later */ 204c9b443d4STobin Davis .ops = { 205c9b443d4STobin Davis .open = conexant_playback_pcm_open, 206c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 207c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 208c9b443d4STobin Davis }, 209c9b443d4STobin Davis }; 210c9b443d4STobin Davis 211c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 212c9b443d4STobin Davis .substreams = 1, 213c9b443d4STobin Davis .channels_min = 2, 214c9b443d4STobin Davis .channels_max = 2, 215c9b443d4STobin Davis .nid = 0, /* fill later */ 216c9b443d4STobin Davis .ops = { 217c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 218c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 219c9b443d4STobin Davis }, 220c9b443d4STobin Davis }; 221c9b443d4STobin Davis 222c9b443d4STobin Davis 223c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 224c9b443d4STobin Davis .substreams = 1, 225c9b443d4STobin Davis .channels_min = 2, 226c9b443d4STobin Davis .channels_max = 2, 227c9b443d4STobin Davis .nid = 0, /* fill later */ 228c9b443d4STobin Davis .ops = { 229c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2306b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2316b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 232c9b443d4STobin Davis }, 233c9b443d4STobin Davis }; 234c9b443d4STobin Davis 235c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 236c9b443d4STobin Davis .substreams = 1, 237c9b443d4STobin Davis .channels_min = 2, 238c9b443d4STobin Davis .channels_max = 2, 239c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 240c9b443d4STobin Davis }; 241c9b443d4STobin Davis 242461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 243461e2c78STakashi Iwai struct hda_codec *codec, 244461e2c78STakashi Iwai unsigned int stream_tag, 245461e2c78STakashi Iwai unsigned int format, 246461e2c78STakashi Iwai struct snd_pcm_substream *substream) 247461e2c78STakashi Iwai { 248461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 249461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 250461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 251461e2c78STakashi Iwai spec->cur_adc_format = format; 252461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 253461e2c78STakashi Iwai return 0; 254461e2c78STakashi Iwai } 255461e2c78STakashi Iwai 256461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 257461e2c78STakashi Iwai struct hda_codec *codec, 258461e2c78STakashi Iwai struct snd_pcm_substream *substream) 259461e2c78STakashi Iwai { 260461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 261888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 262461e2c78STakashi Iwai spec->cur_adc = 0; 263461e2c78STakashi Iwai return 0; 264461e2c78STakashi Iwai } 265461e2c78STakashi Iwai 266461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 267461e2c78STakashi Iwai .substreams = 1, 268461e2c78STakashi Iwai .channels_min = 2, 269461e2c78STakashi Iwai .channels_max = 2, 270461e2c78STakashi Iwai .nid = 0, /* fill later */ 271461e2c78STakashi Iwai .ops = { 272461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 273461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 274461e2c78STakashi Iwai }, 275461e2c78STakashi Iwai }; 276461e2c78STakashi Iwai 277c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 278c9b443d4STobin Davis { 279c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 280c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 281c9b443d4STobin Davis 282c9b443d4STobin Davis codec->num_pcms = 1; 283c9b443d4STobin Davis codec->pcm_info = info; 284c9b443d4STobin Davis 285c9b443d4STobin Davis info->name = "CONEXANT Analog"; 286c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 287c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 288c9b443d4STobin Davis spec->multiout.max_channels; 289c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 290c9b443d4STobin Davis spec->multiout.dac_nids[0]; 291461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 292461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 293461e2c78STakashi Iwai cx5051_pcm_analog_capture; 294461e2c78STakashi Iwai else 295461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 296461e2c78STakashi Iwai conexant_pcm_analog_capture; 297c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 298c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 299c9b443d4STobin Davis 300c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 301c9b443d4STobin Davis info++; 302c9b443d4STobin Davis codec->num_pcms++; 303c9b443d4STobin Davis info->name = "Conexant Digital"; 3047ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 305c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 306c9b443d4STobin Davis conexant_pcm_digital_playback; 307c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 308c9b443d4STobin Davis spec->multiout.dig_out_nid; 309c9b443d4STobin Davis if (spec->dig_in_nid) { 310c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 311c9b443d4STobin Davis conexant_pcm_digital_capture; 312c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 313c9b443d4STobin Davis spec->dig_in_nid; 314c9b443d4STobin Davis } 315c9b443d4STobin Davis } 316c9b443d4STobin Davis 317c9b443d4STobin Davis return 0; 318c9b443d4STobin Davis } 319c9b443d4STobin Davis 320c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 321c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 322c9b443d4STobin Davis { 323c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 324c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 325c9b443d4STobin Davis 326c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 327c9b443d4STobin Davis } 328c9b443d4STobin Davis 329c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 330c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 331c9b443d4STobin Davis { 332c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 333c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 334c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 335c9b443d4STobin Davis 336c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 337c9b443d4STobin Davis return 0; 338c9b443d4STobin Davis } 339c9b443d4STobin Davis 340c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 341c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 342c9b443d4STobin Davis { 343c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 344c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 345c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 346c9b443d4STobin Davis 347c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 348c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 349c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 350c9b443d4STobin Davis } 351c9b443d4STobin Davis 3525801f992STakashi Iwai #ifdef CONFIG_SND_JACK 353bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 354bc7a166dSUlrich Dangel hda_nid_t nid, int type) 355bc7a166dSUlrich Dangel { 356bc7a166dSUlrich Dangel struct conexant_spec *spec; 357bc7a166dSUlrich Dangel struct conexant_jack *jack; 358bc7a166dSUlrich Dangel const char *name; 359bc7a166dSUlrich Dangel 360bc7a166dSUlrich Dangel spec = codec->spec; 361bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 362bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 363bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 364bc7a166dSUlrich Dangel 365bc7a166dSUlrich Dangel if (!jack) 366bc7a166dSUlrich Dangel return -ENOMEM; 367bc7a166dSUlrich Dangel 368bc7a166dSUlrich Dangel jack->nid = nid; 369bc7a166dSUlrich Dangel jack->type = type; 370bc7a166dSUlrich Dangel 371bc7a166dSUlrich Dangel return snd_jack_new(codec->bus->card, name, type, &jack->jack); 372bc7a166dSUlrich Dangel } 373bc7a166dSUlrich Dangel 374bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 375bc7a166dSUlrich Dangel { 376bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 377bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 378bc7a166dSUlrich Dangel 379bc7a166dSUlrich Dangel if (jacks) { 380bc7a166dSUlrich Dangel int i; 381bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 382bc7a166dSUlrich Dangel if (jacks->nid == nid) { 383bc7a166dSUlrich Dangel unsigned int present; 384bc7a166dSUlrich Dangel present = snd_hda_codec_read(codec, nid, 0, 385bc7a166dSUlrich Dangel AC_VERB_GET_PIN_SENSE, 0) & 386bc7a166dSUlrich Dangel AC_PINSENSE_PRESENCE; 387bc7a166dSUlrich Dangel 388bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 389bc7a166dSUlrich Dangel 390bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 391bc7a166dSUlrich Dangel present); 392bc7a166dSUlrich Dangel } 393bc7a166dSUlrich Dangel jacks++; 394bc7a166dSUlrich Dangel } 395bc7a166dSUlrich Dangel } 396bc7a166dSUlrich Dangel } 397bc7a166dSUlrich Dangel 398bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 399bc7a166dSUlrich Dangel { 400bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 401bc7a166dSUlrich Dangel int i; 402bc7a166dSUlrich Dangel 403bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 404bc7a166dSUlrich Dangel const struct hda_verb *hv; 405bc7a166dSUlrich Dangel 406bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 407bc7a166dSUlrich Dangel while (hv->nid) { 408bc7a166dSUlrich Dangel int err = 0; 409bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 410bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 411bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 412bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 413bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 414bc7a166dSUlrich Dangel break; 415bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 416bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 417bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 418bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 419bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 420bc7a166dSUlrich Dangel break; 421bc7a166dSUlrich Dangel } 422bc7a166dSUlrich Dangel if (err < 0) 423bc7a166dSUlrich Dangel return err; 424bc7a166dSUlrich Dangel ++hv; 425bc7a166dSUlrich Dangel } 426bc7a166dSUlrich Dangel } 427bc7a166dSUlrich Dangel return 0; 428bc7a166dSUlrich Dangel 429bc7a166dSUlrich Dangel } 4305801f992STakashi Iwai #else 4315801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4325801f992STakashi Iwai { 4335801f992STakashi Iwai } 4345801f992STakashi Iwai 4355801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4365801f992STakashi Iwai { 4375801f992STakashi Iwai return 0; 4385801f992STakashi Iwai } 4395801f992STakashi Iwai #endif 440bc7a166dSUlrich Dangel 441c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 442c9b443d4STobin Davis { 443c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 444c9b443d4STobin Davis int i; 445c9b443d4STobin Davis 446c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 447c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 448c9b443d4STobin Davis return 0; 449c9b443d4STobin Davis } 450c9b443d4STobin Davis 451c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 452c9b443d4STobin Davis { 453bc7a166dSUlrich Dangel #ifdef CONFIG_SND_JACK 454bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 455bc7a166dSUlrich Dangel if (spec->jacks.list) { 456bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 457bc7a166dSUlrich Dangel int i; 458bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) 459bc7a166dSUlrich Dangel snd_device_free(codec->bus->card, &jacks[i].jack); 460bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 461bc7a166dSUlrich Dangel } 462bc7a166dSUlrich Dangel #endif 463c9b443d4STobin Davis kfree(codec->spec); 464c9b443d4STobin Davis } 465c9b443d4STobin Davis 466*dd5746a8STakashi Iwai static const char *slave_vols[] = { 467*dd5746a8STakashi Iwai "Headphone Playback Volume", 468*dd5746a8STakashi Iwai "Speaker Playback Volume", 469*dd5746a8STakashi Iwai NULL 470*dd5746a8STakashi Iwai }; 471*dd5746a8STakashi Iwai 472*dd5746a8STakashi Iwai static const char *slave_sws[] = { 473*dd5746a8STakashi Iwai "Headphone Playback Switch", 474*dd5746a8STakashi Iwai "Speaker Playback Switch", 475*dd5746a8STakashi Iwai NULL 476*dd5746a8STakashi Iwai }; 477*dd5746a8STakashi Iwai 478c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 479c9b443d4STobin Davis { 480c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 481c9b443d4STobin Davis unsigned int i; 482c9b443d4STobin Davis int err; 483c9b443d4STobin Davis 484c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 485c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 486c9b443d4STobin Davis if (err < 0) 487c9b443d4STobin Davis return err; 488c9b443d4STobin Davis } 489c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 490c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 491c9b443d4STobin Davis spec->multiout.dig_out_nid); 492c9b443d4STobin Davis if (err < 0) 493c9b443d4STobin Davis return err; 4949a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 4959a08160bSTakashi Iwai &spec->multiout); 4969a08160bSTakashi Iwai if (err < 0) 4979a08160bSTakashi Iwai return err; 4989a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 499c9b443d4STobin Davis } 500c9b443d4STobin Davis if (spec->dig_in_nid) { 501c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 502c9b443d4STobin Davis if (err < 0) 503c9b443d4STobin Davis return err; 504c9b443d4STobin Davis } 505*dd5746a8STakashi Iwai 506*dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 507*dd5746a8STakashi Iwai if (spec->vmaster_nid && 508*dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 509*dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 510*dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 511*dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 512*dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 513*dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 514*dd5746a8STakashi Iwai if (err < 0) 515*dd5746a8STakashi Iwai return err; 516*dd5746a8STakashi Iwai } 517*dd5746a8STakashi Iwai if (spec->vmaster_nid && 518*dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 519*dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 520*dd5746a8STakashi Iwai NULL, slave_sws); 521*dd5746a8STakashi Iwai if (err < 0) 522*dd5746a8STakashi Iwai return err; 523*dd5746a8STakashi Iwai } 524*dd5746a8STakashi Iwai 525c9b443d4STobin Davis return 0; 526c9b443d4STobin Davis } 527c9b443d4STobin Davis 528c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 529c9b443d4STobin Davis .build_controls = conexant_build_controls, 530c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 531c9b443d4STobin Davis .init = conexant_init, 532c9b443d4STobin Davis .free = conexant_free, 533c9b443d4STobin Davis }; 534c9b443d4STobin Davis 535c9b443d4STobin Davis /* 536c9b443d4STobin Davis * EAPD control 537c9b443d4STobin Davis * the private value = nid | (invert << 8) 538c9b443d4STobin Davis */ 539c9b443d4STobin Davis 540a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 541c9b443d4STobin Davis 54282f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 543c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 544c9b443d4STobin Davis { 545c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 546c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 547c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 548c9b443d4STobin Davis if (invert) 549c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 550c9b443d4STobin Davis else 551c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 552c9b443d4STobin Davis return 0; 55382f30040STobin Davis 554c9b443d4STobin Davis } 555c9b443d4STobin Davis 55682f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 557c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 558c9b443d4STobin Davis { 559c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 560c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 561c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 562c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 563c9b443d4STobin Davis unsigned int eapd; 56482f30040STobin Davis 56568ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 566c9b443d4STobin Davis if (invert) 567c9b443d4STobin Davis eapd = !eapd; 56882beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 569c9b443d4STobin Davis return 0; 57082f30040STobin Davis 571c9b443d4STobin Davis spec->cur_eapd = eapd; 57282beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 573c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 574c9b443d4STobin Davis eapd ? 0x02 : 0x00); 575c9b443d4STobin Davis return 1; 576c9b443d4STobin Davis } 577c9b443d4STobin Davis 57886d72bdfSTakashi Iwai /* controls for test mode */ 57986d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 58086d72bdfSTakashi Iwai 58182f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 58282f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 58382f30040STobin Davis .info = cxt_eapd_info, \ 58482f30040STobin Davis .get = cxt_eapd_get, \ 58582f30040STobin Davis .put = cxt_eapd_put, \ 58682f30040STobin Davis .private_value = nid | (mask<<16) } 58782f30040STobin Davis 58882f30040STobin Davis 58982f30040STobin Davis 590c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 591c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 592c9b443d4STobin Davis { 593c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 594c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 595c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 596c9b443d4STobin Davis spec->num_channel_mode); 597c9b443d4STobin Davis } 598c9b443d4STobin Davis 599c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 600c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 601c9b443d4STobin Davis { 602c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 603c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 604c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 605c9b443d4STobin Davis spec->num_channel_mode, 606c9b443d4STobin Davis spec->multiout.max_channels); 607c9b443d4STobin Davis } 608c9b443d4STobin Davis 609c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 610c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 611c9b443d4STobin Davis { 612c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 613c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 614c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 615c9b443d4STobin Davis spec->num_channel_mode, 616c9b443d4STobin Davis &spec->multiout.max_channels); 617c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 618c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 619c9b443d4STobin Davis return err; 620c9b443d4STobin Davis } 621c9b443d4STobin Davis 622c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 623c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 624c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 625c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 626c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 627c9b443d4STobin Davis .private_value = nid | (dir<<16) } 628c9b443d4STobin Davis 62986d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 63086d72bdfSTakashi Iwai 631c9b443d4STobin Davis /* Conexant 5045 specific */ 632c9b443d4STobin Davis 633c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 634c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 635c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 636cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 637c9b443d4STobin Davis 6385cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 6395cd57529STobin Davis { 2, NULL }, 6405cd57529STobin Davis }; 641c9b443d4STobin Davis 642c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 643c9b443d4STobin Davis .num_items = 2, 644c9b443d4STobin Davis .items = { 64582f30040STobin Davis { "IntMic", 0x1 }, 646f4beee94SJiang zhe { "ExtMic", 0x2 }, 647c9b443d4STobin Davis } 648c9b443d4STobin Davis }; 649c9b443d4STobin Davis 6505218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 6515218c892SJiang Zhe .num_items = 3, 6525218c892SJiang Zhe .items = { 6535218c892SJiang Zhe { "IntMic", 0x1 }, 6545218c892SJiang Zhe { "ExtMic", 0x2 }, 6555218c892SJiang Zhe { "LineIn", 0x3 }, 6565218c892SJiang Zhe } 6575218c892SJiang Zhe }; 6585218c892SJiang Zhe 6592de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 6602de3c232SJiang zhe .num_items = 2, 6612de3c232SJiang zhe .items = { 6622de3c232SJiang zhe { "ExtMic", 0x1 }, 6632de3c232SJiang zhe { "IntMic", 0x2 }, 6642de3c232SJiang zhe } 6652de3c232SJiang zhe }; 6662de3c232SJiang zhe 667c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 668c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 669c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 670c9b443d4STobin Davis { 671c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 672c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 67382f30040STobin Davis unsigned int bits; 674c9b443d4STobin Davis 67582f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 676c9b443d4STobin Davis return 0; 677c9b443d4STobin Davis 67882f30040STobin Davis /* toggle internal speakers mute depending of presence of 67982f30040STobin Davis * the headphone jack 68082f30040STobin Davis */ 68147fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 68247fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 68347fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 6847f29673bSTobin Davis 68547fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 68647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 68747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 688c9b443d4STobin Davis return 1; 689c9b443d4STobin Davis } 690c9b443d4STobin Davis 691c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 692cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 693cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 694cca3b371STakashi Iwai .values = { 695cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 696cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 697cca3b371STakashi Iwai 0 698cca3b371STakashi Iwai }, 699cca3b371STakashi Iwai }; 700c9b443d4STobin Davis 7017f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7027f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7037f29673bSTobin Davis { 7047f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 7057f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7067f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7077f29673bSTobin Davis {} 7087f29673bSTobin Davis }; 7097f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 7107f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7117f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7127f29673bSTobin Davis {} 7137f29673bSTobin Davis }; 7147f29673bSTobin Davis unsigned int present; 7157f29673bSTobin Davis 7167f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x12, 0, 7177f29673bSTobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7187f29673bSTobin Davis if (present) 7197f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7207f29673bSTobin Davis else 7217f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7227f29673bSTobin Davis } 7237f29673bSTobin Davis 724c9b443d4STobin Davis 725c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 726c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 727c9b443d4STobin Davis { 72882f30040STobin Davis struct conexant_spec *spec = codec->spec; 729dd87da1cSTobin Davis unsigned int bits; 730c9b443d4STobin Davis 73182f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 732c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 733dd87da1cSTobin Davis 73447fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 73547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 73647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 737c9b443d4STobin Davis } 738c9b443d4STobin Davis 739c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 740c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 741c9b443d4STobin Davis unsigned int res) 742c9b443d4STobin Davis { 743c9b443d4STobin Davis res >>= 26; 744c9b443d4STobin Davis switch (res) { 745c9b443d4STobin Davis case CONEXANT_HP_EVENT: 746c9b443d4STobin Davis cxt5045_hp_automute(codec); 747c9b443d4STobin Davis break; 7487f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7497f29673bSTobin Davis cxt5045_hp_automic(codec); 7507f29673bSTobin Davis break; 7517f29673bSTobin Davis 752c9b443d4STobin Davis } 753c9b443d4STobin Davis } 754c9b443d4STobin Davis 755c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 756c9b443d4STobin Davis { 757c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 758c9b443d4STobin Davis .name = "Capture Source", 759c9b443d4STobin Davis .info = conexant_mux_enum_info, 760c9b443d4STobin Davis .get = conexant_mux_enum_get, 761c9b443d4STobin Davis .put = conexant_mux_enum_put 762c9b443d4STobin Davis }, 763c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 764c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 765c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 766c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 767c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 768c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 769c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 770c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 771c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 772c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 773cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 774c9b443d4STobin Davis { 775c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 776c9b443d4STobin Davis .name = "Master Playback Switch", 77782f30040STobin Davis .info = cxt_eapd_info, 77882f30040STobin Davis .get = cxt_eapd_get, 779c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 78082f30040STobin Davis .private_value = 0x10, 781c9b443d4STobin Davis }, 782c9b443d4STobin Davis 783c9b443d4STobin Davis {} 784c9b443d4STobin Davis }; 785c9b443d4STobin Davis 7865218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 7875218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 7885218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 7895218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 7905218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 7915218c892SJiang Zhe 7925218c892SJiang Zhe {} 7935218c892SJiang Zhe }; 7945218c892SJiang Zhe 7952de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 7962de3c232SJiang zhe { 7972de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 7982de3c232SJiang zhe .name = "Capture Source", 7992de3c232SJiang zhe .info = conexant_mux_enum_info, 8002de3c232SJiang zhe .get = conexant_mux_enum_get, 8012de3c232SJiang zhe .put = conexant_mux_enum_put 8022de3c232SJiang zhe }, 8032de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8042de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8052de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8062de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8072de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8082de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 8092de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8102de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8112de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8122de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8132de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8142de3c232SJiang zhe { 8152de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8162de3c232SJiang zhe .name = "Master Playback Switch", 8172de3c232SJiang zhe .info = cxt_eapd_info, 8182de3c232SJiang zhe .get = cxt_eapd_get, 8192de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8202de3c232SJiang zhe .private_value = 0x10, 8212de3c232SJiang zhe }, 8222de3c232SJiang zhe 8232de3c232SJiang zhe {} 8242de3c232SJiang zhe }; 8252de3c232SJiang zhe 826c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 827c9b443d4STobin Davis /* Line in, Mic */ 8284090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8297f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 830c9b443d4STobin Davis /* HP, Amp */ 831c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 832c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 83382f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 834c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 835c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 836c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 837c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 838c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 839c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 84082f30040STobin Davis /* Record selector: Int mic */ 8417f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 84282f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 843c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 844c9b443d4STobin Davis /* SPDIF route: PCM */ 845cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 846c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 847c9b443d4STobin Davis /* EAPD */ 84882f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 849c9b443d4STobin Davis { } /* end */ 850c9b443d4STobin Davis }; 851c9b443d4STobin Davis 8525218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 8535218c892SJiang Zhe /* Int Mic, Mic */ 8545218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8555218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8565218c892SJiang Zhe /* Line In,HP, Amp */ 8575218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8585218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8595218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 8605218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 8615218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8625218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 8635218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 8645218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 8655218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 8665218c892SJiang Zhe /* Record selector: Int mic */ 8675218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 8685218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 8695218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 8705218c892SJiang Zhe /* SPDIF route: PCM */ 871cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8725218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 8735218c892SJiang Zhe /* EAPD */ 8745218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 8755218c892SJiang Zhe { } /* end */ 8765218c892SJiang Zhe }; 8777f29673bSTobin Davis 8787f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 8797f29673bSTobin Davis /* pin sensing on HP jack */ 8807f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 881d3091fadSTakashi Iwai { } /* end */ 8827f29673bSTobin Davis }; 8837f29673bSTobin Davis 8847f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 8857f29673bSTobin Davis /* pin sensing on HP jack */ 8867f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 887d3091fadSTakashi Iwai { } /* end */ 8887f29673bSTobin Davis }; 8897f29673bSTobin Davis 890c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 891c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 892c9b443d4STobin Davis * configuration. 893c9b443d4STobin Davis */ 894c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 895c9b443d4STobin Davis .num_items = 5, 896c9b443d4STobin Davis .items = { 897c9b443d4STobin Davis { "MIXER", 0x0 }, 898c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 899c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 900c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 901c9b443d4STobin Davis { "CD pin", 0x4 }, 902c9b443d4STobin Davis }, 903c9b443d4STobin Davis }; 904c9b443d4STobin Davis 905c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 906c9b443d4STobin Davis 907c9b443d4STobin Davis /* Output controls */ 908c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 909c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9107f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9117f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9127f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9137f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 914c9b443d4STobin Davis 915c9b443d4STobin Davis /* Modes for retasking pin widgets */ 916c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 917c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 918c9b443d4STobin Davis 91982f30040STobin Davis /* EAPD Switch Control */ 92082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 92182f30040STobin Davis 922c9b443d4STobin Davis /* Loopback mixer controls */ 923c9b443d4STobin Davis 9247f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9257f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9267f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9277f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9287f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9297f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9307f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9317f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9327f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9337f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 934c9b443d4STobin Davis { 935c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 936c9b443d4STobin Davis .name = "Input Source", 937c9b443d4STobin Davis .info = conexant_mux_enum_info, 938c9b443d4STobin Davis .get = conexant_mux_enum_get, 939c9b443d4STobin Davis .put = conexant_mux_enum_put, 940c9b443d4STobin Davis }, 941fb3409e7STobin Davis /* Audio input controls */ 942fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 943fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 944fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 945fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 946fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 947fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 948fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 949fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 950fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 951fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 952c9b443d4STobin Davis { } /* end */ 953c9b443d4STobin Davis }; 954c9b443d4STobin Davis 955c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 9567f29673bSTobin Davis /* Set connections */ 9577f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9587f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9597f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 960c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 961c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9627f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 963c9b443d4STobin Davis 964c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 965c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 966c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 967c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 968c9b443d4STobin Davis * control. 969c9b443d4STobin Davis */ 970cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 971cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 972c9b443d4STobin Davis 973c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 974c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 975c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 976c9b443d4STobin Davis 977c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 978c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 979c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 980c9b443d4STobin Davis * input/output buffers as needed. 981c9b443d4STobin Davis */ 982c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 983c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 984c9b443d4STobin Davis 985c9b443d4STobin Davis /* Mute capture amp left and right */ 986c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 987c9b443d4STobin Davis 988c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 989c9b443d4STobin Davis * pin) 990c9b443d4STobin Davis */ 991c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 9927f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 993c9b443d4STobin Davis 994c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 995c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 996c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 997c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 998c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 999c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1000c9b443d4STobin Davis 1001c9b443d4STobin Davis { } 1002c9b443d4STobin Davis }; 1003c9b443d4STobin Davis #endif 1004c9b443d4STobin Davis 1005c9b443d4STobin Davis 1006c9b443d4STobin Davis /* initialize jack-sensing, too */ 1007c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1008c9b443d4STobin Davis { 1009c9b443d4STobin Davis conexant_init(codec); 1010c9b443d4STobin Davis cxt5045_hp_automute(codec); 1011c9b443d4STobin Davis return 0; 1012c9b443d4STobin Davis } 1013c9b443d4STobin Davis 1014c9b443d4STobin Davis 1015c9b443d4STobin Davis enum { 101615908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 101715908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 101815908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10195218c892SJiang Zhe CXT5045_BENQ, 10202de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1021c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1022c9b443d4STobin Davis CXT5045_TEST, 1023c9b443d4STobin Davis #endif 1024f5fcc13cSTakashi Iwai CXT5045_MODELS 1025c9b443d4STobin Davis }; 1026c9b443d4STobin Davis 1027f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 102815908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 102915908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 103015908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10315218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10322de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1033c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1034f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1035c9b443d4STobin Davis #endif 1036f5fcc13cSTakashi Iwai }; 1037c9b443d4STobin Davis 1038f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10392de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1040dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1041dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 10426a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10435218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 104415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 104515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10469e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10479e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 104815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 104915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 105015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1051dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1052dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 105315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1054c9b443d4STobin Davis {} 1055c9b443d4STobin Davis }; 1056c9b443d4STobin Davis 1057c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1058c9b443d4STobin Davis { 1059c9b443d4STobin Davis struct conexant_spec *spec; 1060c9b443d4STobin Davis int board_config; 1061c9b443d4STobin Davis 1062c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1063c9b443d4STobin Davis if (!spec) 1064c9b443d4STobin Davis return -ENOMEM; 1065c9b443d4STobin Davis codec->spec = spec; 1066c9b443d4STobin Davis 1067c9b443d4STobin Davis spec->multiout.max_channels = 2; 1068c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1069c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1070c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1071c9b443d4STobin Davis spec->num_adc_nids = 1; 1072c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1073c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1074c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1075c9b443d4STobin Davis spec->num_mixers = 1; 1076c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1077c9b443d4STobin Davis spec->num_init_verbs = 1; 1078c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1079c9b443d4STobin Davis spec->spdif_route = 0; 10805cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), 10815cd57529STobin Davis spec->channel_mode = cxt5045_modes, 10825cd57529STobin Davis 1083c9b443d4STobin Davis 1084c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1085c9b443d4STobin Davis 1086f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1087f5fcc13cSTakashi Iwai cxt5045_models, 1088f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1089c9b443d4STobin Davis switch (board_config) { 109015908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 10917f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1092c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1093c9b443d4STobin Davis spec->num_init_verbs = 2; 10947f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 10957f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 10967f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 10977f29673bSTobin Davis break; 109815908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 109986376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11007f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11017f29673bSTobin Davis spec->num_init_verbs = 2; 11027f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1103c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1104c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1105c9b443d4STobin Davis break; 110615908c36SMarc Boucher default: 110715908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 110815908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 110915908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 111015908c36SMarc Boucher spec->num_init_verbs = 3; 111115908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 111215908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 111315908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 111415908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 111515908c36SMarc Boucher break; 11165218c892SJiang Zhe case CXT5045_BENQ: 11175218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11185218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11195218c892SJiang Zhe spec->num_init_verbs = 1; 11205218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11215218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11225218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11235218c892SJiang Zhe spec->num_mixers = 2; 11245218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11255218c892SJiang Zhe break; 11262de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11272de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11282de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11292de3c232SJiang zhe spec->num_init_verbs = 2; 11302de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11312de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11322de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11332de3c232SJiang zhe break; 1134c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1135c9b443d4STobin Davis case CXT5045_TEST: 1136c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1137c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1138c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 113915908c36SMarc Boucher break; 114015908c36SMarc Boucher 1141c9b443d4STobin Davis #endif 1142c9b443d4STobin Davis } 114348ecb7e8STakashi Iwai 1144031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1145031005f7STakashi Iwai case 0x103c: 1146031005f7STakashi Iwai /* HP laptop has a really bad sound over 0dB on NID 0x17. 114748ecb7e8STakashi Iwai * Fix max PCM level to 0 dB 114848ecb7e8STakashi Iwai * (originall it has 0x2b steps with 0dB offset 0x14) 114948ecb7e8STakashi Iwai */ 115048ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 115148ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 115248ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 115348ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 115448ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1155031005f7STakashi Iwai break; 1156031005f7STakashi Iwai } 115748ecb7e8STakashi Iwai 1158c9b443d4STobin Davis return 0; 1159c9b443d4STobin Davis } 1160c9b443d4STobin Davis 1161c9b443d4STobin Davis 1162c9b443d4STobin Davis /* Conexant 5047 specific */ 116382f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1164c9b443d4STobin Davis 116582f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; 1166c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1167c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1168c9b443d4STobin Davis 11695cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 11705cd57529STobin Davis { 2, NULL }, 11715cd57529STobin Davis }; 1172c9b443d4STobin Davis 1173c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = { 11747f29673bSTobin Davis .num_items = 1, 1175c9b443d4STobin Davis .items = { 11767f29673bSTobin Davis { "Mic", 0x2 }, 1177c9b443d4STobin Davis } 1178c9b443d4STobin Davis }; 1179c9b443d4STobin Davis 1180c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = { 1181c9b443d4STobin Davis .num_items = 1, 1182c9b443d4STobin Davis .items = { 118382f30040STobin Davis { "ExtMic", 0x2 }, 118482f30040STobin Davis } 118582f30040STobin Davis }; 118682f30040STobin Davis 118782f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 118882f30040STobin Davis .num_items = 2, 118982f30040STobin Davis .items = { 119082f30040STobin Davis { "ExtMic", 0x2 }, 119182f30040STobin Davis { "Line-In", 0x1 }, 1192c9b443d4STobin Davis } 1193c9b443d4STobin Davis }; 1194c9b443d4STobin Davis 1195c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1196c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1197c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1198c9b443d4STobin Davis { 1199c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1200c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 120182f30040STobin Davis unsigned int bits; 1202c9b443d4STobin Davis 120382f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1204c9b443d4STobin Davis return 0; 1205c9b443d4STobin Davis 120682f30040STobin Davis /* toggle internal speakers mute depending of presence of 120782f30040STobin Davis * the headphone jack 120882f30040STobin Davis */ 120947fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 121047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 121147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 121247fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 121347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 121447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1215c9b443d4STobin Davis return 1; 1216c9b443d4STobin Davis } 1217c9b443d4STobin Davis 1218c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1219c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1220c9b443d4STobin Davis { 122182f30040STobin Davis struct conexant_spec *spec = codec->spec; 1222dd87da1cSTobin Davis unsigned int bits; 1223c9b443d4STobin Davis 122482f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1225c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1226dd87da1cSTobin Davis 122747fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 122847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 122947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 123082f30040STobin Davis /* Mute/Unmute PCM 2 for good measure - some systems need this */ 123147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, 123247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1233c9b443d4STobin Davis } 1234c9b443d4STobin Davis 1235fb3409e7STobin Davis /* mute internal speaker if HP is plugged */ 1236fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec) 1237fb3409e7STobin Davis { 1238fb3409e7STobin Davis struct conexant_spec *spec = codec->spec; 1239fb3409e7STobin Davis unsigned int bits; 1240fb3409e7STobin Davis 1241fb3409e7STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1242fb3409e7STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1243fb3409e7STobin Davis 124447fd830aSTakashi Iwai bits = spec->hp_present ? HDA_AMP_MUTE : 0; 124547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 124647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1247fb3409e7STobin Davis /* Mute/Unmute PCM 2 for good measure - some systems need this */ 124847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, 124947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1250fb3409e7STobin Davis } 1251fb3409e7STobin Davis 1252c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1253c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1254c9b443d4STobin Davis { 1255c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 12569f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12579f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1258c9b443d4STobin Davis {} 1259c9b443d4STobin Davis }; 1260c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 12619f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12629f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1263c9b443d4STobin Davis {} 1264c9b443d4STobin Davis }; 1265c9b443d4STobin Davis unsigned int present; 1266c9b443d4STobin Davis 12677f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x15, 0, 1268c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1269c9b443d4STobin Davis if (present) 1270c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1271c9b443d4STobin Davis else 1272c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1273c9b443d4STobin Davis } 1274c9b443d4STobin Davis 1275c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1276c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1277c9b443d4STobin Davis unsigned int res) 1278c9b443d4STobin Davis { 12799f113e0eSMarc Boucher switch (res >> 26) { 1280c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1281c9b443d4STobin Davis cxt5047_hp_automute(codec); 1282c9b443d4STobin Davis break; 1283c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1284c9b443d4STobin Davis cxt5047_hp_automic(codec); 1285c9b443d4STobin Davis break; 1286c9b443d4STobin Davis } 1287c9b443d4STobin Davis } 1288c9b443d4STobin Davis 1289fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */ 1290fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec, 1291fb3409e7STobin Davis unsigned int res) 1292fb3409e7STobin Davis { 1293fb3409e7STobin Davis res >>= 26; 1294fb3409e7STobin Davis switch (res) { 1295fb3409e7STobin Davis case CONEXANT_HP_EVENT: 1296fb3409e7STobin Davis cxt5047_hp2_automute(codec); 1297fb3409e7STobin Davis break; 1298fb3409e7STobin Davis case CONEXANT_MIC_EVENT: 1299fb3409e7STobin Davis cxt5047_hp_automic(codec); 1300fb3409e7STobin Davis break; 1301fb3409e7STobin Davis } 1302fb3409e7STobin Davis } 1303fb3409e7STobin Davis 1304c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = { 1305c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1306c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), 13077f29673bSTobin Davis HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT), 13087f29673bSTobin Davis HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT), 1309c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1310c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1311c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1312c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 131382f30040STobin Davis HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT), 131482f30040STobin Davis HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT), 1315b7589cebSTobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), 1316b7589cebSTobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT), 1317b7589cebSTobin Davis HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1318b7589cebSTobin Davis HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT), 131982f30040STobin Davis 132082f30040STobin Davis {} 132182f30040STobin Davis }; 132282f30040STobin Davis 132382f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = { 132482f30040STobin Davis { 132582f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 132682f30040STobin Davis .name = "Capture Source", 132782f30040STobin Davis .info = conexant_mux_enum_info, 132882f30040STobin Davis .get = conexant_mux_enum_get, 132982f30040STobin Davis .put = conexant_mux_enum_put 133082f30040STobin Davis }, 133182f30040STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 133282f30040STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), 133382f30040STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 133482f30040STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 133582f30040STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 133682f30040STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1337*dd5746a8STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1338*dd5746a8STakashi Iwai HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), 133982f30040STobin Davis { 134082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 134182f30040STobin Davis .name = "Master Playback Switch", 134282f30040STobin Davis .info = cxt_eapd_info, 134382f30040STobin Davis .get = cxt_eapd_get, 1344c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1345c9b443d4STobin Davis .private_value = 0x13, 1346c9b443d4STobin Davis }, 1347c9b443d4STobin Davis 1348c9b443d4STobin Davis {} 1349c9b443d4STobin Davis }; 1350c9b443d4STobin Davis 1351c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = { 1352c9b443d4STobin Davis { 1353c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1354c9b443d4STobin Davis .name = "Capture Source", 1355c9b443d4STobin Davis .info = conexant_mux_enum_info, 1356c9b443d4STobin Davis .get = conexant_mux_enum_get, 1357c9b443d4STobin Davis .put = conexant_mux_enum_put 1358c9b443d4STobin Davis }, 1359c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1360c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), 1361c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1362c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1363c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1364c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1365c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1366c9b443d4STobin Davis { 1367c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1368c9b443d4STobin Davis .name = "Master Playback Switch", 136982f30040STobin Davis .info = cxt_eapd_info, 137082f30040STobin Davis .get = cxt_eapd_get, 1371c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1372c9b443d4STobin Davis .private_value = 0x13, 1373c9b443d4STobin Davis }, 1374c9b443d4STobin Davis { } /* end */ 1375c9b443d4STobin Davis }; 1376c9b443d4STobin Davis 1377c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1378c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1379c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1380c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1381c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13827f29673bSTobin Davis /* HP, Speaker */ 1383b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 1384b7589cebSTobin Davis {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, 13857f29673bSTobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, 13867f29673bSTobin Davis /* Record selector: Mic */ 13877f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13887f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13897f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13907f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1391c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1392c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1393c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1394c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1395c9b443d4STobin Davis /* SPDIF route: PCM */ 1396c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 139782f30040STobin Davis /* Enable unsolicited events */ 139882f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 139982f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1400c9b443d4STobin Davis { } /* end */ 1401c9b443d4STobin Davis }; 1402c9b443d4STobin Davis 1403c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1404c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 1405c9b443d4STobin Davis {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ 1406c9b443d4STobin Davis /* pin sensing on HP and Mic jacks */ 1407c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1408c9b443d4STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 140982f30040STobin Davis /* Speaker routing */ 141082f30040STobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, 1411c9b443d4STobin Davis {} 1412c9b443d4STobin Davis }; 1413c9b443d4STobin Davis 1414c9b443d4STobin Davis /* configuration for HP Laptops */ 1415c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = { 141682f30040STobin Davis /* pin sensing on HP jack */ 1417c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1418b84f08d4STakashi Iwai /* 0x13 is actually shared by both HP and speaker; 1419b84f08d4STakashi Iwai * setting the connection to 0 (=0x19) makes the master volume control 1420b84f08d4STakashi Iwai * working mysteriouslly... 1421b84f08d4STakashi Iwai */ 1422b84f08d4STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 142382f30040STobin Davis /* Record selector: Ext Mic */ 142482f30040STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 142582f30040STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 142682f30040STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 142782f30040STobin Davis /* Speaker routing */ 142882f30040STobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, 1429c9b443d4STobin Davis {} 1430c9b443d4STobin Davis }; 1431c9b443d4STobin Davis 1432c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1433c9b443d4STobin Davis * configuration. 1434c9b443d4STobin Davis */ 1435c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1436c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 143782f30040STobin Davis .num_items = 4, 1438c9b443d4STobin Davis .items = { 143982f30040STobin Davis { "LINE1 pin", 0x0 }, 144082f30040STobin Davis { "MIC1 pin", 0x1 }, 144182f30040STobin Davis { "MIC2 pin", 0x2 }, 144282f30040STobin Davis { "CD pin", 0x3 }, 1443c9b443d4STobin Davis }, 1444c9b443d4STobin Davis }; 1445c9b443d4STobin Davis 1446c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1447c9b443d4STobin Davis 1448c9b443d4STobin Davis /* Output only controls */ 144982f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 145082f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 145182f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 145282f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1453c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1454c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1455c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1456c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 145782f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 145882f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 145982f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 146082f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1463c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1464c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1465c9b443d4STobin Davis 146682f30040STobin Davis /* EAPD Switch Control */ 146782f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 146882f30040STobin Davis 1469c9b443d4STobin Davis /* Loopback mixer controls */ 147082f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 147182f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 147282f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 147382f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 147482f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 147582f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 147682f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 147782f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1478c9b443d4STobin Davis 147982f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 148082f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 148182f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 148282f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 148382f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 148482f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 148582f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 148682f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1487c9b443d4STobin Davis { 1488c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1489c9b443d4STobin Davis .name = "Input Source", 1490c9b443d4STobin Davis .info = conexant_mux_enum_info, 1491c9b443d4STobin Davis .get = conexant_mux_enum_get, 1492c9b443d4STobin Davis .put = conexant_mux_enum_put, 1493c9b443d4STobin Davis }, 14949f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 14959f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 14969f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 14979f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 14989f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 14999f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 15009f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 15019f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 15029f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 15039f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 15049f113e0eSMarc Boucher 1505c9b443d4STobin Davis { } /* end */ 1506c9b443d4STobin Davis }; 1507c9b443d4STobin Davis 1508c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1509c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1510c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1511c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1512c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1513c9b443d4STobin Davis 1514c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1515c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1516c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1517c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1518c9b443d4STobin Davis * control. 1519c9b443d4STobin Davis */ 1520c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1521c9b443d4STobin Davis 1522c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1523c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1524c9b443d4STobin Davis */ 1525c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1526c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1527c9b443d4STobin Davis 1528c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1529c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1530c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1531c9b443d4STobin Davis 1532c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1533c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1534c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1535c9b443d4STobin Davis * input/output buffers as needed. 1536c9b443d4STobin Davis */ 1537c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1538c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1539c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1540c9b443d4STobin Davis 1541c9b443d4STobin Davis /* Mute capture amp left and right */ 1542c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1543c9b443d4STobin Davis 1544c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1545c9b443d4STobin Davis * pin) 1546c9b443d4STobin Davis */ 1547c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1548c9b443d4STobin Davis 1549c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1550c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1551c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1552c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1553c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1554c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1555c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1556c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1557c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1558c9b443d4STobin Davis 1559c9b443d4STobin Davis { } 1560c9b443d4STobin Davis }; 1561c9b443d4STobin Davis #endif 1562c9b443d4STobin Davis 1563c9b443d4STobin Davis 1564c9b443d4STobin Davis /* initialize jack-sensing, too */ 1565c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1566c9b443d4STobin Davis { 1567c9b443d4STobin Davis conexant_init(codec); 1568c9b443d4STobin Davis cxt5047_hp_automute(codec); 1569c9b443d4STobin Davis return 0; 1570c9b443d4STobin Davis } 1571c9b443d4STobin Davis 1572c9b443d4STobin Davis 1573c9b443d4STobin Davis enum { 1574f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1575f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1576f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1577c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1578c9b443d4STobin Davis CXT5047_TEST, 1579c9b443d4STobin Davis #endif 1580f5fcc13cSTakashi Iwai CXT5047_MODELS 1581c9b443d4STobin Davis }; 1582c9b443d4STobin Davis 1583f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1584f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1585f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1586f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1587c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1588f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1589c9b443d4STobin Davis #endif 1590f5fcc13cSTakashi Iwai }; 1591c9b443d4STobin Davis 1592f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1593ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1594dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1595dea0a509STakashi Iwai CXT5047_LAPTOP), 1596f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1597c9b443d4STobin Davis {} 1598c9b443d4STobin Davis }; 1599c9b443d4STobin Davis 1600c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1601c9b443d4STobin Davis { 1602c9b443d4STobin Davis struct conexant_spec *spec; 1603c9b443d4STobin Davis int board_config; 1604c9b443d4STobin Davis 1605c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1606c9b443d4STobin Davis if (!spec) 1607c9b443d4STobin Davis return -ENOMEM; 1608c9b443d4STobin Davis codec->spec = spec; 1609c9b443d4STobin Davis 1610c9b443d4STobin Davis spec->multiout.max_channels = 2; 1611c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1612c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1613c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1614c9b443d4STobin Davis spec->num_adc_nids = 1; 1615c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1616c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1617c9b443d4STobin Davis spec->input_mux = &cxt5047_capture_source; 1618c9b443d4STobin Davis spec->num_mixers = 1; 1619c9b443d4STobin Davis spec->mixers[0] = cxt5047_mixers; 1620c9b443d4STobin Davis spec->num_init_verbs = 1; 1621c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1622c9b443d4STobin Davis spec->spdif_route = 0; 16235cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 16245cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1625c9b443d4STobin Davis 1626c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1627c9b443d4STobin Davis 1628f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1629f5fcc13cSTakashi Iwai cxt5047_models, 1630f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1631c9b443d4STobin Davis switch (board_config) { 1632c9b443d4STobin Davis case CXT5047_LAPTOP: 1633fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; 1634c9b443d4STobin Davis break; 1635c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1636c9b443d4STobin Davis spec->input_mux = &cxt5047_hp_capture_source; 1637c9b443d4STobin Davis spec->num_init_verbs = 2; 1638c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_hp_init_verbs; 1639c9b443d4STobin Davis spec->mixers[0] = cxt5047_hp_mixers; 1640fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1641c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1642c9b443d4STobin Davis break; 1643c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 164482f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1645c9b443d4STobin Davis spec->num_init_verbs = 2; 1646c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 164782f30040STobin Davis spec->mixers[0] = cxt5047_toshiba_mixers; 1648fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1649c9b443d4STobin Davis break; 1650c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1651c9b443d4STobin Davis case CXT5047_TEST: 1652c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1653c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1654c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1655fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1656c9b443d4STobin Davis #endif 1657c9b443d4STobin Davis } 1658*dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1659c9b443d4STobin Davis return 0; 1660c9b443d4STobin Davis } 1661c9b443d4STobin Davis 1662461e2c78STakashi Iwai /* Conexant 5051 specific */ 1663461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1664461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1665461e2c78STakashi Iwai 1666461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1667461e2c78STakashi Iwai { 2, NULL }, 1668461e2c78STakashi Iwai }; 1669461e2c78STakashi Iwai 1670461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1671461e2c78STakashi Iwai { 1672461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1673461e2c78STakashi Iwai unsigned int pinctl; 1674461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1675461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1676461e2c78STakashi Iwai pinctl); 1677461e2c78STakashi Iwai } 1678461e2c78STakashi Iwai 1679461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1680461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1681461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1682461e2c78STakashi Iwai { 1683461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1684461e2c78STakashi Iwai 1685461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1686461e2c78STakashi Iwai return 0; 1687461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1688461e2c78STakashi Iwai return 1; 1689461e2c78STakashi Iwai } 1690461e2c78STakashi Iwai 1691461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1692461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1693461e2c78STakashi Iwai { 169479d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1695461e2c78STakashi Iwai unsigned int present; 1696461e2c78STakashi Iwai 169779d7d533STakashi Iwai if (spec->no_auto_mic) 169879d7d533STakashi Iwai return; 1699461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x17, 0, 1700461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1701461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1702461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1703461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1704461e2c78STakashi Iwai present ? 0x01 : 0x00); 1705461e2c78STakashi Iwai } 1706461e2c78STakashi Iwai 1707461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1708461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1709461e2c78STakashi Iwai { 1710461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1711461e2c78STakashi Iwai unsigned int present; 1712461e2c78STakashi Iwai hda_nid_t new_adc; 1713461e2c78STakashi Iwai 171479d7d533STakashi Iwai if (spec->no_auto_mic) 171579d7d533STakashi Iwai return; 1716461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x18, 0, 1717461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1718461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1719461e2c78STakashi Iwai if (present) 1720461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1721461e2c78STakashi Iwai else 1722461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1723461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1724461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1725461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1726888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 1727461e2c78STakashi Iwai spec->cur_adc = new_adc; 1728461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1729461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1730461e2c78STakashi Iwai spec->cur_adc_format); 1731461e2c78STakashi Iwai } 1732461e2c78STakashi Iwai } 1733461e2c78STakashi Iwai 1734461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1735461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1736461e2c78STakashi Iwai { 1737461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1738461e2c78STakashi Iwai 1739461e2c78STakashi Iwai spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1740461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1741461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1742461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1743461e2c78STakashi Iwai } 1744461e2c78STakashi Iwai 1745461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1746461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1747461e2c78STakashi Iwai unsigned int res) 1748461e2c78STakashi Iwai { 1749acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1750461e2c78STakashi Iwai switch (res >> 26) { 1751461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1752461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1753461e2c78STakashi Iwai break; 1754461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1755461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1756461e2c78STakashi Iwai break; 1757461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1758461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1759461e2c78STakashi Iwai break; 1760461e2c78STakashi Iwai } 1761acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1762461e2c78STakashi Iwai } 1763461e2c78STakashi Iwai 1764461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = { 1765461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1766461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1767461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1768461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1769461e2c78STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 1770461e2c78STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1771461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1772461e2c78STakashi Iwai { 1773461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1774461e2c78STakashi Iwai .name = "Master Playback Switch", 1775461e2c78STakashi Iwai .info = cxt_eapd_info, 1776461e2c78STakashi Iwai .get = cxt_eapd_get, 1777461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1778461e2c78STakashi Iwai .private_value = 0x1a, 1779461e2c78STakashi Iwai }, 1780461e2c78STakashi Iwai 1781461e2c78STakashi Iwai {} 1782461e2c78STakashi Iwai }; 1783461e2c78STakashi Iwai 1784461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1785461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1786461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1787461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1788461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1789461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1790461e2c78STakashi Iwai { 1791461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1792461e2c78STakashi Iwai .name = "Master Playback Switch", 1793461e2c78STakashi Iwai .info = cxt_eapd_info, 1794461e2c78STakashi Iwai .get = cxt_eapd_get, 1795461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1796461e2c78STakashi Iwai .private_value = 0x1a, 1797461e2c78STakashi Iwai }, 1798461e2c78STakashi Iwai 1799461e2c78STakashi Iwai {} 1800461e2c78STakashi Iwai }; 1801461e2c78STakashi Iwai 180279d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 180379d7d533STakashi Iwai HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT), 180479d7d533STakashi Iwai HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT), 180579d7d533STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 180679d7d533STakashi Iwai { 180779d7d533STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 180879d7d533STakashi Iwai .name = "Master Playback Switch", 180979d7d533STakashi Iwai .info = cxt_eapd_info, 181079d7d533STakashi Iwai .get = cxt_eapd_get, 181179d7d533STakashi Iwai .put = cxt5051_hp_master_sw_put, 181279d7d533STakashi Iwai .private_value = 0x1a, 181379d7d533STakashi Iwai }, 181479d7d533STakashi Iwai 181579d7d533STakashi Iwai {} 181679d7d533STakashi Iwai }; 181779d7d533STakashi Iwai 1818461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1819461e2c78STakashi Iwai /* Line in, Mic */ 1820461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1821461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1822461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1823461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1824461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1825461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1826461e2c78STakashi Iwai /* SPK */ 1827461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1828461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1829461e2c78STakashi Iwai /* HP, Amp */ 1830461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1831461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1832461e2c78STakashi Iwai /* DAC1 */ 1833461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1834461e2c78STakashi Iwai /* Record selector: Int mic */ 1835461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1836461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1837461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1838461e2c78STakashi Iwai /* SPDIF route: PCM */ 1839461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1840461e2c78STakashi Iwai /* EAPD */ 1841461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1842461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1843461e2c78STakashi Iwai {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 1844461e2c78STakashi Iwai {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, 1845461e2c78STakashi Iwai { } /* end */ 1846461e2c78STakashi Iwai }; 1847461e2c78STakashi Iwai 184879d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 184979d7d533STakashi Iwai /* Line in, Mic */ 185079d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 185179d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 185279d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185379d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 185479d7d533STakashi Iwai /* SPK */ 185579d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 185679d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 185779d7d533STakashi Iwai /* HP, Amp */ 185879d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 185979d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 186079d7d533STakashi Iwai /* DAC1 */ 186179d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 186279d7d533STakashi Iwai /* Record selector: Int mic */ 186379d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 186479d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 186579d7d533STakashi Iwai /* SPDIF route: PCM */ 186679d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 186779d7d533STakashi Iwai /* EAPD */ 186879d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 186979d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 187079d7d533STakashi Iwai {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 187179d7d533STakashi Iwai { } /* end */ 187279d7d533STakashi Iwai }; 187379d7d533STakashi Iwai 187427e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 187527e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 187627e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187727e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 187827e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 187927e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 188027e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 188127e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 188227e08988SAristeu Sergio Rozanski Filho /* SPK */ 188327e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 188427e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 188527e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 188627e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 188727e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 188827e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 188927e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 189027e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 189127e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 189227e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 189327e08988SAristeu Sergio Rozanski Filho /* Record selector: Int mic */ 189427e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 189527e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 189627e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 189727e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 189827e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 189927e08988SAristeu Sergio Rozanski Filho /* EAPD */ 190027e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 190127e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 190227e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 190327e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, 190427e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 190527e08988SAristeu Sergio Rozanski Filho { } /* end */ 190627e08988SAristeu Sergio Rozanski Filho }; 190727e08988SAristeu Sergio Rozanski Filho 1908461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1909461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1910461e2c78STakashi Iwai { 1911461e2c78STakashi Iwai conexant_init(codec); 1912acf26c0cSUlrich Dangel conexant_init_jacks(codec); 1913461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1914461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1915461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1916461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1917461e2c78STakashi Iwai } 1918461e2c78STakashi Iwai return 0; 1919461e2c78STakashi Iwai } 1920461e2c78STakashi Iwai 1921461e2c78STakashi Iwai 1922461e2c78STakashi Iwai enum { 1923461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1924461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 192579d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 192627e08988SAristeu Sergio Rozanski Filho CXT5051_LENOVO_X200, /* Lenovo X200 laptop */ 1927461e2c78STakashi Iwai CXT5051_MODELS 1928461e2c78STakashi Iwai }; 1929461e2c78STakashi Iwai 1930461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1931461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1932461e2c78STakashi Iwai [CXT5051_HP] = "hp", 193379d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 193427e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 1935461e2c78STakashi Iwai }; 1936461e2c78STakashi Iwai 1937461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 193879d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 1939461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1940461e2c78STakashi Iwai CXT5051_LAPTOP), 1941461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 194227e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 1943461e2c78STakashi Iwai {} 1944461e2c78STakashi Iwai }; 1945461e2c78STakashi Iwai 1946461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1947461e2c78STakashi Iwai { 1948461e2c78STakashi Iwai struct conexant_spec *spec; 1949461e2c78STakashi Iwai int board_config; 1950461e2c78STakashi Iwai 1951461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1952461e2c78STakashi Iwai if (!spec) 1953461e2c78STakashi Iwai return -ENOMEM; 1954461e2c78STakashi Iwai codec->spec = spec; 1955461e2c78STakashi Iwai 1956461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1957461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1958461e2c78STakashi Iwai 1959461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1960461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1961461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1962461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1963461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1964461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 1965461e2c78STakashi Iwai spec->num_mixers = 1; 1966461e2c78STakashi Iwai spec->mixers[0] = cxt5051_mixers; 1967461e2c78STakashi Iwai spec->num_init_verbs = 1; 1968461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1969461e2c78STakashi Iwai spec->spdif_route = 0; 1970461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1971461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1972461e2c78STakashi Iwai spec->cur_adc = 0; 1973461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1974461e2c78STakashi Iwai 197579d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 197679d7d533STakashi Iwai 1977461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1978461e2c78STakashi Iwai cxt5051_models, 1979461e2c78STakashi Iwai cxt5051_cfg_tbl); 1980461e2c78STakashi Iwai switch (board_config) { 1981461e2c78STakashi Iwai case CXT5051_HP: 1982461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1983461e2c78STakashi Iwai break; 198479d7d533STakashi Iwai case CXT5051_HP_DV6736: 198579d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 198679d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 198779d7d533STakashi Iwai spec->no_auto_mic = 1; 198879d7d533STakashi Iwai break; 198927e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 199027e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 1991461e2c78STakashi Iwai break; 1992461e2c78STakashi Iwai } 1993461e2c78STakashi Iwai 1994461e2c78STakashi Iwai return 0; 1995461e2c78STakashi Iwai } 1996461e2c78STakashi Iwai 1997461e2c78STakashi Iwai 1998461e2c78STakashi Iwai /* 1999461e2c78STakashi Iwai */ 2000461e2c78STakashi Iwai 20011289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 200282f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 200382f30040STobin Davis .patch = patch_cxt5045 }, 200482f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 200582f30040STobin Davis .patch = patch_cxt5047 }, 2006461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 2007461e2c78STakashi Iwai .patch = patch_cxt5051 }, 2008c9b443d4STobin Davis {} /* terminator */ 2009c9b443d4STobin Davis }; 20101289e9e8STakashi Iwai 20111289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 20121289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 20131289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 20141289e9e8STakashi Iwai 20151289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 20161289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 20171289e9e8STakashi Iwai 20181289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 20191289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 20201289e9e8STakashi Iwai .owner = THIS_MODULE, 20211289e9e8STakashi Iwai }; 20221289e9e8STakashi Iwai 20231289e9e8STakashi Iwai static int __init patch_conexant_init(void) 20241289e9e8STakashi Iwai { 20251289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 20261289e9e8STakashi Iwai } 20271289e9e8STakashi Iwai 20281289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 20291289e9e8STakashi Iwai { 20301289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 20311289e9e8STakashi Iwai } 20321289e9e8STakashi Iwai 20331289e9e8STakashi Iwai module_init(patch_conexant_init) 20341289e9e8STakashi Iwai module_exit(patch_conexant_exit) 2035