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; 61dd5746a8STakashi 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 111*0fb67e98SDaniel Drake unsigned int dell_automute; 112*0fb67e98SDaniel Drake unsigned int port_d_mode; 113c9b443d4STobin Davis }; 114c9b443d4STobin Davis 115c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 116c9b443d4STobin Davis struct hda_codec *codec, 117c9b443d4STobin Davis struct snd_pcm_substream *substream) 118c9b443d4STobin Davis { 119c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 1209a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 1219a08160bSTakashi Iwai hinfo); 122c9b443d4STobin Davis } 123c9b443d4STobin Davis 124c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 125c9b443d4STobin Davis struct hda_codec *codec, 126c9b443d4STobin Davis unsigned int stream_tag, 127c9b443d4STobin Davis unsigned int format, 128c9b443d4STobin Davis struct snd_pcm_substream *substream) 129c9b443d4STobin Davis { 130c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 131c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 132c9b443d4STobin Davis stream_tag, 133c9b443d4STobin Davis format, substream); 134c9b443d4STobin Davis } 135c9b443d4STobin Davis 136c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 137c9b443d4STobin Davis struct hda_codec *codec, 138c9b443d4STobin Davis struct snd_pcm_substream *substream) 139c9b443d4STobin Davis { 140c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 141c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 142c9b443d4STobin Davis } 143c9b443d4STobin Davis 144c9b443d4STobin Davis /* 145c9b443d4STobin Davis * Digital out 146c9b443d4STobin Davis */ 147c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 148c9b443d4STobin Davis struct hda_codec *codec, 149c9b443d4STobin Davis struct snd_pcm_substream *substream) 150c9b443d4STobin Davis { 151c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 152c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 153c9b443d4STobin Davis } 154c9b443d4STobin Davis 155c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 156c9b443d4STobin Davis struct hda_codec *codec, 157c9b443d4STobin Davis struct snd_pcm_substream *substream) 158c9b443d4STobin Davis { 159c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 160c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 161c9b443d4STobin Davis } 162c9b443d4STobin Davis 1636b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1646b97eb45STakashi Iwai struct hda_codec *codec, 1656b97eb45STakashi Iwai unsigned int stream_tag, 1666b97eb45STakashi Iwai unsigned int format, 1676b97eb45STakashi Iwai struct snd_pcm_substream *substream) 1686b97eb45STakashi Iwai { 1696b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 1706b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 1716b97eb45STakashi Iwai stream_tag, 1726b97eb45STakashi Iwai format, substream); 1736b97eb45STakashi Iwai } 1746b97eb45STakashi Iwai 175c9b443d4STobin Davis /* 176c9b443d4STobin Davis * Analog capture 177c9b443d4STobin Davis */ 178c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 179c9b443d4STobin Davis struct hda_codec *codec, 180c9b443d4STobin Davis unsigned int stream_tag, 181c9b443d4STobin Davis unsigned int format, 182c9b443d4STobin Davis struct snd_pcm_substream *substream) 183c9b443d4STobin Davis { 184c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 185c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 186c9b443d4STobin Davis stream_tag, 0, format); 187c9b443d4STobin Davis return 0; 188c9b443d4STobin Davis } 189c9b443d4STobin Davis 190c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 191c9b443d4STobin Davis struct hda_codec *codec, 192c9b443d4STobin Davis struct snd_pcm_substream *substream) 193c9b443d4STobin Davis { 194c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 195888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 196c9b443d4STobin Davis return 0; 197c9b443d4STobin Davis } 198c9b443d4STobin Davis 199c9b443d4STobin Davis 200c9b443d4STobin Davis 201c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 202c9b443d4STobin Davis .substreams = 1, 203c9b443d4STobin Davis .channels_min = 2, 204c9b443d4STobin Davis .channels_max = 2, 205c9b443d4STobin Davis .nid = 0, /* fill later */ 206c9b443d4STobin Davis .ops = { 207c9b443d4STobin Davis .open = conexant_playback_pcm_open, 208c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 209c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 210c9b443d4STobin Davis }, 211c9b443d4STobin Davis }; 212c9b443d4STobin Davis 213c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 214c9b443d4STobin Davis .substreams = 1, 215c9b443d4STobin Davis .channels_min = 2, 216c9b443d4STobin Davis .channels_max = 2, 217c9b443d4STobin Davis .nid = 0, /* fill later */ 218c9b443d4STobin Davis .ops = { 219c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 220c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 221c9b443d4STobin Davis }, 222c9b443d4STobin Davis }; 223c9b443d4STobin Davis 224c9b443d4STobin Davis 225c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 226c9b443d4STobin Davis .substreams = 1, 227c9b443d4STobin Davis .channels_min = 2, 228c9b443d4STobin Davis .channels_max = 2, 229c9b443d4STobin Davis .nid = 0, /* fill later */ 230c9b443d4STobin Davis .ops = { 231c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2326b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2336b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 234c9b443d4STobin Davis }, 235c9b443d4STobin Davis }; 236c9b443d4STobin Davis 237c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 238c9b443d4STobin Davis .substreams = 1, 239c9b443d4STobin Davis .channels_min = 2, 240c9b443d4STobin Davis .channels_max = 2, 241c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 242c9b443d4STobin Davis }; 243c9b443d4STobin Davis 244461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 245461e2c78STakashi Iwai struct hda_codec *codec, 246461e2c78STakashi Iwai unsigned int stream_tag, 247461e2c78STakashi Iwai unsigned int format, 248461e2c78STakashi Iwai struct snd_pcm_substream *substream) 249461e2c78STakashi Iwai { 250461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 251461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 252461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 253461e2c78STakashi Iwai spec->cur_adc_format = format; 254461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 255461e2c78STakashi Iwai return 0; 256461e2c78STakashi Iwai } 257461e2c78STakashi Iwai 258461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 259461e2c78STakashi Iwai struct hda_codec *codec, 260461e2c78STakashi Iwai struct snd_pcm_substream *substream) 261461e2c78STakashi Iwai { 262461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 263888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 264461e2c78STakashi Iwai spec->cur_adc = 0; 265461e2c78STakashi Iwai return 0; 266461e2c78STakashi Iwai } 267461e2c78STakashi Iwai 268461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 269461e2c78STakashi Iwai .substreams = 1, 270461e2c78STakashi Iwai .channels_min = 2, 271461e2c78STakashi Iwai .channels_max = 2, 272461e2c78STakashi Iwai .nid = 0, /* fill later */ 273461e2c78STakashi Iwai .ops = { 274461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 275461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 276461e2c78STakashi Iwai }, 277461e2c78STakashi Iwai }; 278461e2c78STakashi Iwai 279c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 280c9b443d4STobin Davis { 281c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 282c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 283c9b443d4STobin Davis 284c9b443d4STobin Davis codec->num_pcms = 1; 285c9b443d4STobin Davis codec->pcm_info = info; 286c9b443d4STobin Davis 287c9b443d4STobin Davis info->name = "CONEXANT Analog"; 288c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 289c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 290c9b443d4STobin Davis spec->multiout.max_channels; 291c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 292c9b443d4STobin Davis spec->multiout.dac_nids[0]; 293461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 294461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 295461e2c78STakashi Iwai cx5051_pcm_analog_capture; 296461e2c78STakashi Iwai else 297461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 298461e2c78STakashi Iwai conexant_pcm_analog_capture; 299c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 300c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 301c9b443d4STobin Davis 302c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 303c9b443d4STobin Davis info++; 304c9b443d4STobin Davis codec->num_pcms++; 305c9b443d4STobin Davis info->name = "Conexant Digital"; 3067ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 307c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 308c9b443d4STobin Davis conexant_pcm_digital_playback; 309c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 310c9b443d4STobin Davis spec->multiout.dig_out_nid; 311c9b443d4STobin Davis if (spec->dig_in_nid) { 312c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 313c9b443d4STobin Davis conexant_pcm_digital_capture; 314c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 315c9b443d4STobin Davis spec->dig_in_nid; 316c9b443d4STobin Davis } 317c9b443d4STobin Davis } 318c9b443d4STobin Davis 319c9b443d4STobin Davis return 0; 320c9b443d4STobin Davis } 321c9b443d4STobin Davis 322c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 323c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 324c9b443d4STobin Davis { 325c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 326c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 327c9b443d4STobin Davis 328c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 329c9b443d4STobin Davis } 330c9b443d4STobin Davis 331c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 332c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 333c9b443d4STobin Davis { 334c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 335c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 336c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 337c9b443d4STobin Davis 338c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 339c9b443d4STobin Davis return 0; 340c9b443d4STobin Davis } 341c9b443d4STobin Davis 342c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 343c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 344c9b443d4STobin Davis { 345c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 346c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 347c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 348c9b443d4STobin Davis 349c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 350c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 351c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 352c9b443d4STobin Davis } 353c9b443d4STobin Davis 3548c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 35595c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack) 35695c09099STakashi Iwai { 35795c09099STakashi Iwai struct conexant_jack *jacks = jack->private_data; 35895c09099STakashi Iwai jacks->nid = 0; 35995c09099STakashi Iwai jacks->jack = NULL; 36095c09099STakashi Iwai } 36195c09099STakashi Iwai 362bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec, 363bc7a166dSUlrich Dangel hda_nid_t nid, int type) 364bc7a166dSUlrich Dangel { 365bc7a166dSUlrich Dangel struct conexant_spec *spec; 366bc7a166dSUlrich Dangel struct conexant_jack *jack; 367bc7a166dSUlrich Dangel const char *name; 36895c09099STakashi Iwai int err; 369bc7a166dSUlrich Dangel 370bc7a166dSUlrich Dangel spec = codec->spec; 371bc7a166dSUlrich Dangel snd_array_init(&spec->jacks, sizeof(*jack), 32); 372bc7a166dSUlrich Dangel jack = snd_array_new(&spec->jacks); 373bc7a166dSUlrich Dangel name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ; 374bc7a166dSUlrich Dangel 375bc7a166dSUlrich Dangel if (!jack) 376bc7a166dSUlrich Dangel return -ENOMEM; 377bc7a166dSUlrich Dangel 378bc7a166dSUlrich Dangel jack->nid = nid; 379bc7a166dSUlrich Dangel jack->type = type; 380bc7a166dSUlrich Dangel 38195c09099STakashi Iwai err = snd_jack_new(codec->bus->card, name, type, &jack->jack); 38295c09099STakashi Iwai if (err < 0) 38395c09099STakashi Iwai return err; 38495c09099STakashi Iwai jack->jack->private_data = jack; 38595c09099STakashi Iwai jack->jack->private_free = conexant_free_jack_priv; 38695c09099STakashi Iwai return 0; 387bc7a166dSUlrich Dangel } 388bc7a166dSUlrich Dangel 389bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 390bc7a166dSUlrich Dangel { 391bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 392bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 393bc7a166dSUlrich Dangel 394bc7a166dSUlrich Dangel if (jacks) { 395bc7a166dSUlrich Dangel int i; 396bc7a166dSUlrich Dangel for (i = 0; i < spec->jacks.used; i++) { 397bc7a166dSUlrich Dangel if (jacks->nid == nid) { 398bc7a166dSUlrich Dangel unsigned int present; 399bc7a166dSUlrich Dangel present = snd_hda_codec_read(codec, nid, 0, 400bc7a166dSUlrich Dangel AC_VERB_GET_PIN_SENSE, 0) & 401bc7a166dSUlrich Dangel AC_PINSENSE_PRESENCE; 402bc7a166dSUlrich Dangel 403bc7a166dSUlrich Dangel present = (present) ? jacks->type : 0 ; 404bc7a166dSUlrich Dangel 405bc7a166dSUlrich Dangel snd_jack_report(jacks->jack, 406bc7a166dSUlrich Dangel present); 407bc7a166dSUlrich Dangel } 408bc7a166dSUlrich Dangel jacks++; 409bc7a166dSUlrich Dangel } 410bc7a166dSUlrich Dangel } 411bc7a166dSUlrich Dangel } 412bc7a166dSUlrich Dangel 413bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec) 414bc7a166dSUlrich Dangel { 415bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 416bc7a166dSUlrich Dangel int i; 417bc7a166dSUlrich Dangel 418bc7a166dSUlrich Dangel for (i = 0; i < spec->num_init_verbs; i++) { 419bc7a166dSUlrich Dangel const struct hda_verb *hv; 420bc7a166dSUlrich Dangel 421bc7a166dSUlrich Dangel hv = spec->init_verbs[i]; 422bc7a166dSUlrich Dangel while (hv->nid) { 423bc7a166dSUlrich Dangel int err = 0; 424bc7a166dSUlrich Dangel switch (hv->param ^ AC_USRSP_EN) { 425bc7a166dSUlrich Dangel case CONEXANT_HP_EVENT: 426bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 427bc7a166dSUlrich Dangel SND_JACK_HEADPHONE); 428bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 429bc7a166dSUlrich Dangel break; 430bc7a166dSUlrich Dangel case CXT5051_PORTC_EVENT: 431bc7a166dSUlrich Dangel case CONEXANT_MIC_EVENT: 432bc7a166dSUlrich Dangel err = conexant_add_jack(codec, hv->nid, 433bc7a166dSUlrich Dangel SND_JACK_MICROPHONE); 434bc7a166dSUlrich Dangel conexant_report_jack(codec, hv->nid); 435bc7a166dSUlrich Dangel break; 436bc7a166dSUlrich Dangel } 437bc7a166dSUlrich Dangel if (err < 0) 438bc7a166dSUlrich Dangel return err; 439bc7a166dSUlrich Dangel ++hv; 440bc7a166dSUlrich Dangel } 441bc7a166dSUlrich Dangel } 442bc7a166dSUlrich Dangel return 0; 443bc7a166dSUlrich Dangel 444bc7a166dSUlrich Dangel } 4455801f992STakashi Iwai #else 4465801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid) 4475801f992STakashi Iwai { 4485801f992STakashi Iwai } 4495801f992STakashi Iwai 4505801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec) 4515801f992STakashi Iwai { 4525801f992STakashi Iwai return 0; 4535801f992STakashi Iwai } 4545801f992STakashi Iwai #endif 455bc7a166dSUlrich Dangel 456c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 457c9b443d4STobin Davis { 458c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 459c9b443d4STobin Davis int i; 460c9b443d4STobin Davis 461c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 462c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 463c9b443d4STobin Davis return 0; 464c9b443d4STobin Davis } 465c9b443d4STobin Davis 466c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 467c9b443d4STobin Davis { 4688c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK 469bc7a166dSUlrich Dangel struct conexant_spec *spec = codec->spec; 470bc7a166dSUlrich Dangel if (spec->jacks.list) { 471bc7a166dSUlrich Dangel struct conexant_jack *jacks = spec->jacks.list; 472bc7a166dSUlrich Dangel int i; 47395c09099STakashi Iwai for (i = 0; i < spec->jacks.used; i++, jacks++) { 47495c09099STakashi Iwai if (jacks->jack) 47595c09099STakashi Iwai snd_device_free(codec->bus->card, jacks->jack); 47695c09099STakashi Iwai } 477bc7a166dSUlrich Dangel snd_array_free(&spec->jacks); 478bc7a166dSUlrich Dangel } 479bc7a166dSUlrich Dangel #endif 480c9b443d4STobin Davis kfree(codec->spec); 481c9b443d4STobin Davis } 482c9b443d4STobin Davis 483b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = { 484b880c74aSTakashi Iwai { 485b880c74aSTakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 486b880c74aSTakashi Iwai .name = "Capture Source", 487b880c74aSTakashi Iwai .info = conexant_mux_enum_info, 488b880c74aSTakashi Iwai .get = conexant_mux_enum_get, 489b880c74aSTakashi Iwai .put = conexant_mux_enum_put 490b880c74aSTakashi Iwai }, 491b880c74aSTakashi Iwai {} 492b880c74aSTakashi Iwai }; 493b880c74aSTakashi Iwai 494dd5746a8STakashi Iwai static const char *slave_vols[] = { 495dd5746a8STakashi Iwai "Headphone Playback Volume", 496dd5746a8STakashi Iwai "Speaker Playback Volume", 497dd5746a8STakashi Iwai NULL 498dd5746a8STakashi Iwai }; 499dd5746a8STakashi Iwai 500dd5746a8STakashi Iwai static const char *slave_sws[] = { 501dd5746a8STakashi Iwai "Headphone Playback Switch", 502dd5746a8STakashi Iwai "Speaker Playback Switch", 503dd5746a8STakashi Iwai NULL 504dd5746a8STakashi Iwai }; 505dd5746a8STakashi Iwai 506c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 507c9b443d4STobin Davis { 508c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 509c9b443d4STobin Davis unsigned int i; 510c9b443d4STobin Davis int err; 511c9b443d4STobin Davis 512c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 513c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 514c9b443d4STobin Davis if (err < 0) 515c9b443d4STobin Davis return err; 516c9b443d4STobin Davis } 517c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 518c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 519c9b443d4STobin Davis spec->multiout.dig_out_nid); 520c9b443d4STobin Davis if (err < 0) 521c9b443d4STobin Davis return err; 5229a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 5239a08160bSTakashi Iwai &spec->multiout); 5249a08160bSTakashi Iwai if (err < 0) 5259a08160bSTakashi Iwai return err; 5269a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 527c9b443d4STobin Davis } 528c9b443d4STobin Davis if (spec->dig_in_nid) { 529c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 530c9b443d4STobin Davis if (err < 0) 531c9b443d4STobin Davis return err; 532c9b443d4STobin Davis } 533dd5746a8STakashi Iwai 534dd5746a8STakashi Iwai /* if we have no master control, let's create it */ 535dd5746a8STakashi Iwai if (spec->vmaster_nid && 536dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 537dd5746a8STakashi Iwai unsigned int vmaster_tlv[4]; 538dd5746a8STakashi Iwai snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 539dd5746a8STakashi Iwai HDA_OUTPUT, vmaster_tlv); 540dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Volume", 541dd5746a8STakashi Iwai vmaster_tlv, slave_vols); 542dd5746a8STakashi Iwai if (err < 0) 543dd5746a8STakashi Iwai return err; 544dd5746a8STakashi Iwai } 545dd5746a8STakashi Iwai if (spec->vmaster_nid && 546dd5746a8STakashi Iwai !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 547dd5746a8STakashi Iwai err = snd_hda_add_vmaster(codec, "Master Playback Switch", 548dd5746a8STakashi Iwai NULL, slave_sws); 549dd5746a8STakashi Iwai if (err < 0) 550dd5746a8STakashi Iwai return err; 551dd5746a8STakashi Iwai } 552dd5746a8STakashi Iwai 553b880c74aSTakashi Iwai if (spec->input_mux) { 554b880c74aSTakashi Iwai err = snd_hda_add_new_ctls(codec, cxt_capture_mixers); 555b880c74aSTakashi Iwai if (err < 0) 556b880c74aSTakashi Iwai return err; 557b880c74aSTakashi Iwai } 558b880c74aSTakashi Iwai 559c9b443d4STobin Davis return 0; 560c9b443d4STobin Davis } 561c9b443d4STobin Davis 562c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 563c9b443d4STobin Davis .build_controls = conexant_build_controls, 564c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 565c9b443d4STobin Davis .init = conexant_init, 566c9b443d4STobin Davis .free = conexant_free, 567c9b443d4STobin Davis }; 568c9b443d4STobin Davis 569c9b443d4STobin Davis /* 570c9b443d4STobin Davis * EAPD control 571c9b443d4STobin Davis * the private value = nid | (invert << 8) 572c9b443d4STobin Davis */ 573c9b443d4STobin Davis 574a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 575c9b443d4STobin Davis 57682f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 577c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 578c9b443d4STobin Davis { 579c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 580c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 581c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 582c9b443d4STobin Davis if (invert) 583c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 584c9b443d4STobin Davis else 585c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 586c9b443d4STobin Davis return 0; 58782f30040STobin Davis 588c9b443d4STobin Davis } 589c9b443d4STobin Davis 59082f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 591c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 592c9b443d4STobin Davis { 593c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 594c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 595c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 596c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 597c9b443d4STobin Davis unsigned int eapd; 59882f30040STobin Davis 59968ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 600c9b443d4STobin Davis if (invert) 601c9b443d4STobin Davis eapd = !eapd; 60282beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 603c9b443d4STobin Davis return 0; 60482f30040STobin Davis 605c9b443d4STobin Davis spec->cur_eapd = eapd; 60682beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 607c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 608c9b443d4STobin Davis eapd ? 0x02 : 0x00); 609c9b443d4STobin Davis return 1; 610c9b443d4STobin Davis } 611c9b443d4STobin Davis 61286d72bdfSTakashi Iwai /* controls for test mode */ 61386d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 61486d72bdfSTakashi Iwai 61582f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 61682f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 61782f30040STobin Davis .info = cxt_eapd_info, \ 61882f30040STobin Davis .get = cxt_eapd_get, \ 61982f30040STobin Davis .put = cxt_eapd_put, \ 62082f30040STobin Davis .private_value = nid | (mask<<16) } 62182f30040STobin Davis 62282f30040STobin Davis 62382f30040STobin Davis 624c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 625c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 626c9b443d4STobin Davis { 627c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 628c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 629c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 630c9b443d4STobin Davis spec->num_channel_mode); 631c9b443d4STobin Davis } 632c9b443d4STobin Davis 633c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 634c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 635c9b443d4STobin Davis { 636c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 637c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 638c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 639c9b443d4STobin Davis spec->num_channel_mode, 640c9b443d4STobin Davis spec->multiout.max_channels); 641c9b443d4STobin Davis } 642c9b443d4STobin Davis 643c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 644c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 645c9b443d4STobin Davis { 646c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 647c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 648c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 649c9b443d4STobin Davis spec->num_channel_mode, 650c9b443d4STobin Davis &spec->multiout.max_channels); 651c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 652c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 653c9b443d4STobin Davis return err; 654c9b443d4STobin Davis } 655c9b443d4STobin Davis 656c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 657c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 658c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 659c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 660c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 661c9b443d4STobin Davis .private_value = nid | (dir<<16) } 662c9b443d4STobin Davis 66386d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 66486d72bdfSTakashi Iwai 665c9b443d4STobin Davis /* Conexant 5045 specific */ 666c9b443d4STobin Davis 667c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 668c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 669c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 670cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 671c9b443d4STobin Davis 6725cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 6735cd57529STobin Davis { 2, NULL }, 6745cd57529STobin Davis }; 675c9b443d4STobin Davis 676c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 677c9b443d4STobin Davis .num_items = 2, 678c9b443d4STobin Davis .items = { 67982f30040STobin Davis { "IntMic", 0x1 }, 680f4beee94SJiang zhe { "ExtMic", 0x2 }, 681c9b443d4STobin Davis } 682c9b443d4STobin Davis }; 683c9b443d4STobin Davis 6845218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 6855218c892SJiang Zhe .num_items = 3, 6865218c892SJiang Zhe .items = { 6875218c892SJiang Zhe { "IntMic", 0x1 }, 6885218c892SJiang Zhe { "ExtMic", 0x2 }, 6895218c892SJiang Zhe { "LineIn", 0x3 }, 6905218c892SJiang Zhe } 6915218c892SJiang Zhe }; 6925218c892SJiang Zhe 6932de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 6942de3c232SJiang zhe .num_items = 2, 6952de3c232SJiang zhe .items = { 6962de3c232SJiang zhe { "ExtMic", 0x1 }, 6972de3c232SJiang zhe { "IntMic", 0x2 }, 6982de3c232SJiang zhe } 6992de3c232SJiang zhe }; 7002de3c232SJiang zhe 701c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 702c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 703c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 704c9b443d4STobin Davis { 705c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 706c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 70782f30040STobin Davis unsigned int bits; 708c9b443d4STobin Davis 70982f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 710c9b443d4STobin Davis return 0; 711c9b443d4STobin Davis 71282f30040STobin Davis /* toggle internal speakers mute depending of presence of 71382f30040STobin Davis * the headphone jack 71482f30040STobin Davis */ 71547fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 71647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 71747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 7187f29673bSTobin Davis 71947fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 72047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 72147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 722c9b443d4STobin Davis return 1; 723c9b443d4STobin Davis } 724c9b443d4STobin Davis 725c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 726cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 727cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 728cca3b371STakashi Iwai .values = { 729cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 730cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 731cca3b371STakashi Iwai 0 732cca3b371STakashi Iwai }, 733cca3b371STakashi Iwai }; 734c9b443d4STobin Davis 7357f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 7367f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 7377f29673bSTobin Davis { 7387f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 7397f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7407f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7417f29673bSTobin Davis {} 7427f29673bSTobin Davis }; 7437f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 7447f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 7457f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 7467f29673bSTobin Davis {} 7477f29673bSTobin Davis }; 7487f29673bSTobin Davis unsigned int present; 7497f29673bSTobin Davis 7507f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x12, 0, 7517f29673bSTobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 7527f29673bSTobin Davis if (present) 7537f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 7547f29673bSTobin Davis else 7557f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 7567f29673bSTobin Davis } 7577f29673bSTobin Davis 758c9b443d4STobin Davis 759c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 760c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 761c9b443d4STobin Davis { 76282f30040STobin Davis struct conexant_spec *spec = codec->spec; 763dd87da1cSTobin Davis unsigned int bits; 764c9b443d4STobin Davis 76582f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 766c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 767dd87da1cSTobin Davis 76847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 76947fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 77047fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 771c9b443d4STobin Davis } 772c9b443d4STobin Davis 773c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 774c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 775c9b443d4STobin Davis unsigned int res) 776c9b443d4STobin Davis { 777c9b443d4STobin Davis res >>= 26; 778c9b443d4STobin Davis switch (res) { 779c9b443d4STobin Davis case CONEXANT_HP_EVENT: 780c9b443d4STobin Davis cxt5045_hp_automute(codec); 781c9b443d4STobin Davis break; 7827f29673bSTobin Davis case CONEXANT_MIC_EVENT: 7837f29673bSTobin Davis cxt5045_hp_automic(codec); 7847f29673bSTobin Davis break; 7857f29673bSTobin Davis 786c9b443d4STobin Davis } 787c9b443d4STobin Davis } 788c9b443d4STobin Davis 789c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 790c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 791c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 792c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 793c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 794c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 795c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 796c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 797c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 798c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 799c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 800cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 801c9b443d4STobin Davis { 802c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 803c9b443d4STobin Davis .name = "Master Playback Switch", 80482f30040STobin Davis .info = cxt_eapd_info, 80582f30040STobin Davis .get = cxt_eapd_get, 806c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 80782f30040STobin Davis .private_value = 0x10, 808c9b443d4STobin Davis }, 809c9b443d4STobin Davis 810c9b443d4STobin Davis {} 811c9b443d4STobin Davis }; 812c9b443d4STobin Davis 8135218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 8145218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 8155218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 8165218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 8175218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 8185218c892SJiang Zhe 8195218c892SJiang Zhe {} 8205218c892SJiang Zhe }; 8215218c892SJiang Zhe 8222de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 8232de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 8242de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 8252de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 8262de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 8272de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 8282de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 8292de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 8302de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 8312de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 8322de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 8332de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 8342de3c232SJiang zhe { 8352de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 8362de3c232SJiang zhe .name = "Master Playback Switch", 8372de3c232SJiang zhe .info = cxt_eapd_info, 8382de3c232SJiang zhe .get = cxt_eapd_get, 8392de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 8402de3c232SJiang zhe .private_value = 0x10, 8412de3c232SJiang zhe }, 8422de3c232SJiang zhe 8432de3c232SJiang zhe {} 8442de3c232SJiang zhe }; 8452de3c232SJiang zhe 846c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 847c9b443d4STobin Davis /* Line in, Mic */ 8484090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8497f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 850c9b443d4STobin Davis /* HP, Amp */ 851c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 852c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 85382f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 854c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 855c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 856c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 857c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 858c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 859c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 86082f30040STobin Davis /* Record selector: Int mic */ 8617f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 86282f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 863c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 864c9b443d4STobin Davis /* SPDIF route: PCM */ 865cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 866c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 867c9b443d4STobin Davis /* EAPD */ 86882f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 869c9b443d4STobin Davis { } /* end */ 870c9b443d4STobin Davis }; 871c9b443d4STobin Davis 8725218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 8735218c892SJiang Zhe /* Int Mic, Mic */ 8745218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8755218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 8765218c892SJiang Zhe /* Line In,HP, Amp */ 8775218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8785218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 8795218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 8805218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 8815218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 8825218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 8835218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 8845218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 8855218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 8865218c892SJiang Zhe /* Record selector: Int mic */ 8875218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 8885218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 8895218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 8905218c892SJiang Zhe /* SPDIF route: PCM */ 891cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8925218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 8935218c892SJiang Zhe /* EAPD */ 8945218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 8955218c892SJiang Zhe { } /* end */ 8965218c892SJiang Zhe }; 8977f29673bSTobin Davis 8987f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 8997f29673bSTobin Davis /* pin sensing on HP jack */ 9007f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 901d3091fadSTakashi Iwai { } /* end */ 9027f29673bSTobin Davis }; 9037f29673bSTobin Davis 9047f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 9057f29673bSTobin Davis /* pin sensing on HP jack */ 9067f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 907d3091fadSTakashi Iwai { } /* end */ 9087f29673bSTobin Davis }; 9097f29673bSTobin Davis 910c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 911c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 912c9b443d4STobin Davis * configuration. 913c9b443d4STobin Davis */ 914c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 915c9b443d4STobin Davis .num_items = 5, 916c9b443d4STobin Davis .items = { 917c9b443d4STobin Davis { "MIXER", 0x0 }, 918c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 919c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 920c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 921c9b443d4STobin Davis { "CD pin", 0x4 }, 922c9b443d4STobin Davis }, 923c9b443d4STobin Davis }; 924c9b443d4STobin Davis 925c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 926c9b443d4STobin Davis 927c9b443d4STobin Davis /* Output controls */ 928c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 929c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 9307f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 9317f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 9327f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 9337f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 934c9b443d4STobin Davis 935c9b443d4STobin Davis /* Modes for retasking pin widgets */ 936c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 937c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 938c9b443d4STobin Davis 93982f30040STobin Davis /* EAPD Switch Control */ 94082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 94182f30040STobin Davis 942c9b443d4STobin Davis /* Loopback mixer controls */ 943c9b443d4STobin Davis 9447f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 9457f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 9467f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 9477f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 9487f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 9497f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 9507f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 9517f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 9527f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 9537f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 954c9b443d4STobin Davis { 955c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 956c9b443d4STobin Davis .name = "Input Source", 957c9b443d4STobin Davis .info = conexant_mux_enum_info, 958c9b443d4STobin Davis .get = conexant_mux_enum_get, 959c9b443d4STobin Davis .put = conexant_mux_enum_put, 960c9b443d4STobin Davis }, 961fb3409e7STobin Davis /* Audio input controls */ 962fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 963fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 964fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 965fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 966fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 967fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 968fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 969fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 970fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 971fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 972c9b443d4STobin Davis { } /* end */ 973c9b443d4STobin Davis }; 974c9b443d4STobin Davis 975c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 9767f29673bSTobin Davis /* Set connections */ 9777f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9787f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 9797f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 980c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 981c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9827f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 983c9b443d4STobin Davis 984c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 985c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 986c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 987c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 988c9b443d4STobin Davis * control. 989c9b443d4STobin Davis */ 990cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 991cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 992c9b443d4STobin Davis 993c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 994c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 995c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 996c9b443d4STobin Davis 997c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 998c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 999c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1000c9b443d4STobin Davis * input/output buffers as needed. 1001c9b443d4STobin Davis */ 1002c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1003c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1004c9b443d4STobin Davis 1005c9b443d4STobin Davis /* Mute capture amp left and right */ 1006c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1007c9b443d4STobin Davis 1008c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1009c9b443d4STobin Davis * pin) 1010c9b443d4STobin Davis */ 1011c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 10127f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 1013c9b443d4STobin Davis 1014c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1015c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 1016c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 1017c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 1018c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 1019c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1020c9b443d4STobin Davis 1021c9b443d4STobin Davis { } 1022c9b443d4STobin Davis }; 1023c9b443d4STobin Davis #endif 1024c9b443d4STobin Davis 1025c9b443d4STobin Davis 1026c9b443d4STobin Davis /* initialize jack-sensing, too */ 1027c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 1028c9b443d4STobin Davis { 1029c9b443d4STobin Davis conexant_init(codec); 1030c9b443d4STobin Davis cxt5045_hp_automute(codec); 1031c9b443d4STobin Davis return 0; 1032c9b443d4STobin Davis } 1033c9b443d4STobin Davis 1034c9b443d4STobin Davis 1035c9b443d4STobin Davis enum { 103615908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 103715908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 103815908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 10395218c892SJiang Zhe CXT5045_BENQ, 10402de3c232SJiang zhe CXT5045_LAPTOP_HP530, 1041c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1042c9b443d4STobin Davis CXT5045_TEST, 1043c9b443d4STobin Davis #endif 1044f5fcc13cSTakashi Iwai CXT5045_MODELS 1045c9b443d4STobin Davis }; 1046c9b443d4STobin Davis 1047f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 104815908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 104915908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 105015908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 10515218c892SJiang Zhe [CXT5045_BENQ] = "benq", 10522de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 1053c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1054f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 1055c9b443d4STobin Davis #endif 1056f5fcc13cSTakashi Iwai }; 1057c9b443d4STobin Davis 1058f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 10592de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1060dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1061dea0a509STakashi Iwai CXT5045_LAPTOP_HPSENSE), 10626a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 10635218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 106415908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 106515908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 10669e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 10679e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 106815908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 106915908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 107015908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1071dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell", 1072dea0a509STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 107315908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1074c9b443d4STobin Davis {} 1075c9b443d4STobin Davis }; 1076c9b443d4STobin Davis 1077c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 1078c9b443d4STobin Davis { 1079c9b443d4STobin Davis struct conexant_spec *spec; 1080c9b443d4STobin Davis int board_config; 1081c9b443d4STobin Davis 1082c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1083c9b443d4STobin Davis if (!spec) 1084c9b443d4STobin Davis return -ENOMEM; 1085c9b443d4STobin Davis codec->spec = spec; 10869421f954STakashi Iwai codec->pin_amp_workaround = 1; 1087c9b443d4STobin Davis 1088c9b443d4STobin Davis spec->multiout.max_channels = 2; 1089c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1090c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 1091c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 1092c9b443d4STobin Davis spec->num_adc_nids = 1; 1093c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 1094c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 1095c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1096c9b443d4STobin Davis spec->num_mixers = 1; 1097c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1098c9b443d4STobin Davis spec->num_init_verbs = 1; 1099c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 1100c9b443d4STobin Davis spec->spdif_route = 0; 11015cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), 11025cd57529STobin Davis spec->channel_mode = cxt5045_modes, 11035cd57529STobin Davis 1104c9b443d4STobin Davis 1105c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1106c9b443d4STobin Davis 1107f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 1108f5fcc13cSTakashi Iwai cxt5045_models, 1109f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 1110c9b443d4STobin Davis switch (board_config) { 111115908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 11127f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 1113c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 1114c9b443d4STobin Davis spec->num_init_verbs = 2; 11157f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11167f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 11177f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 11187f29673bSTobin Davis break; 111915908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 112086376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11217f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 11227f29673bSTobin Davis spec->num_init_verbs = 2; 11237f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 1124c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 1125c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 1126c9b443d4STobin Davis break; 112715908c36SMarc Boucher default: 112815908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 112915908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 113015908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 113115908c36SMarc Boucher spec->num_init_verbs = 3; 113215908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 113315908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 113415908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 113515908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 113615908c36SMarc Boucher break; 11375218c892SJiang Zhe case CXT5045_BENQ: 11385218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11395218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 11405218c892SJiang Zhe spec->num_init_verbs = 1; 11415218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 11425218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 11435218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 11445218c892SJiang Zhe spec->num_mixers = 2; 11455218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 11465218c892SJiang Zhe break; 11472de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 11482de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 11492de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 11502de3c232SJiang zhe spec->num_init_verbs = 2; 11512de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 11522de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 11532de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 11542de3c232SJiang zhe break; 1155c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1156c9b443d4STobin Davis case CXT5045_TEST: 1157c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 1158c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 1159c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 116015908c36SMarc Boucher break; 116115908c36SMarc Boucher 1162c9b443d4STobin Davis #endif 1163c9b443d4STobin Davis } 116448ecb7e8STakashi Iwai 1165031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1166031005f7STakashi Iwai case 0x103c: 1167031005f7STakashi Iwai /* HP laptop has a really bad sound over 0dB on NID 0x17. 116848ecb7e8STakashi Iwai * Fix max PCM level to 0 dB 116948ecb7e8STakashi Iwai * (originall it has 0x2b steps with 0dB offset 0x14) 117048ecb7e8STakashi Iwai */ 117148ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 117248ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 117348ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 117448ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 117548ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1176031005f7STakashi Iwai break; 1177031005f7STakashi Iwai } 117848ecb7e8STakashi Iwai 1179c9b443d4STobin Davis return 0; 1180c9b443d4STobin Davis } 1181c9b443d4STobin Davis 1182c9b443d4STobin Davis 1183c9b443d4STobin Davis /* Conexant 5047 specific */ 118482f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1185c9b443d4STobin Davis 11865b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */ 1187c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1188c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1189c9b443d4STobin Davis 11905cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 11915cd57529STobin Davis { 2, NULL }, 11925cd57529STobin Davis }; 1193c9b443d4STobin Davis 119482f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 119582f30040STobin Davis .num_items = 2, 119682f30040STobin Davis .items = { 119782f30040STobin Davis { "ExtMic", 0x2 }, 119882f30040STobin Davis { "Line-In", 0x1 }, 1199c9b443d4STobin Davis } 1200c9b443d4STobin Davis }; 1201c9b443d4STobin Davis 1202c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1203c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1204c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1205c9b443d4STobin Davis { 1206c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1207c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 120882f30040STobin Davis unsigned int bits; 1209c9b443d4STobin Davis 121082f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1211c9b443d4STobin Davis return 0; 1212c9b443d4STobin Davis 121382f30040STobin Davis /* toggle internal speakers mute depending of presence of 121482f30040STobin Davis * the headphone jack 121582f30040STobin Davis */ 121647fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 12173b7523fcSTakashi Iwai /* NOTE: Conexat codec needs the index for *OUTPUT* amp of 12183b7523fcSTakashi Iwai * pin widgets unlike other codecs. In this case, we need to 12193b7523fcSTakashi Iwai * set index 0x01 for the volume from the mixer amp 0x19. 12203b7523fcSTakashi Iwai */ 12215d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 122247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 122347fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 122447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 122547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1226c9b443d4STobin Davis return 1; 1227c9b443d4STobin Davis } 1228c9b443d4STobin Davis 1229c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1230c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1231c9b443d4STobin Davis { 123282f30040STobin Davis struct conexant_spec *spec = codec->spec; 1233dd87da1cSTobin Davis unsigned int bits; 1234c9b443d4STobin Davis 123582f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1236c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1237dd87da1cSTobin Davis 123847fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 12393b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 12405d75bc55SGregorio Guidi snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01, 124147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1242c9b443d4STobin Davis } 1243c9b443d4STobin Davis 1244c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1245c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1246c9b443d4STobin Davis { 1247c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 12489f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12499f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1250c9b443d4STobin Davis {} 1251c9b443d4STobin Davis }; 1252c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 12539f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 12549f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1255c9b443d4STobin Davis {} 1256c9b443d4STobin Davis }; 1257c9b443d4STobin Davis unsigned int present; 1258c9b443d4STobin Davis 12597f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x15, 0, 1260c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1261c9b443d4STobin Davis if (present) 1262c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1263c9b443d4STobin Davis else 1264c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1265c9b443d4STobin Davis } 1266c9b443d4STobin Davis 1267c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1268c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1269c9b443d4STobin Davis unsigned int res) 1270c9b443d4STobin Davis { 12719f113e0eSMarc Boucher switch (res >> 26) { 1272c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1273c9b443d4STobin Davis cxt5047_hp_automute(codec); 1274c9b443d4STobin Davis break; 1275c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1276c9b443d4STobin Davis cxt5047_hp_automic(codec); 1277c9b443d4STobin Davis break; 1278c9b443d4STobin Davis } 1279c9b443d4STobin Davis } 1280c9b443d4STobin Davis 1281df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = { 1282df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT), 1283df481e41STakashi Iwai HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT), 1284df481e41STakashi Iwai HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT), 1285c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1286c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1287c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1288c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 128982f30040STobin Davis { 129082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 129182f30040STobin Davis .name = "Master Playback Switch", 129282f30040STobin Davis .info = cxt_eapd_info, 129382f30040STobin Davis .get = cxt_eapd_get, 1294c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1295c9b443d4STobin Davis .private_value = 0x13, 1296c9b443d4STobin Davis }, 1297c9b443d4STobin Davis 1298c9b443d4STobin Davis {} 1299c9b443d4STobin Davis }; 1300c9b443d4STobin Davis 1301df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = { 13023b7523fcSTakashi Iwai /* See the note in cxt5047_hp_master_sw_put */ 13035d75bc55SGregorio Guidi HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT), 1304df481e41STakashi Iwai HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1305df481e41STakashi Iwai {} 1306df481e41STakashi Iwai }; 1307df481e41STakashi Iwai 1308df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = { 1309c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1310c9b443d4STobin Davis { } /* end */ 1311c9b443d4STobin Davis }; 1312c9b443d4STobin Davis 1313c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1314c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1315c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1316c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1317c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 13187f29673bSTobin Davis /* HP, Speaker */ 1319b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 13205b3a7440STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */ 13215b3a7440STakashi Iwai {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */ 13227f29673bSTobin Davis /* Record selector: Mic */ 13237f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 13247f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 13257f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 13267f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1327c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1328c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1329c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1330c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1331c9b443d4STobin Davis /* SPDIF route: PCM */ 1332c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 133382f30040STobin Davis /* Enable unsolicited events */ 133482f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 133582f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1336c9b443d4STobin Davis { } /* end */ 1337c9b443d4STobin Davis }; 1338c9b443d4STobin Davis 1339c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1340c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 13413b628867STakashi Iwai {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */ 1342c9b443d4STobin Davis {} 1343c9b443d4STobin Davis }; 1344c9b443d4STobin Davis 1345c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1346c9b443d4STobin Davis * configuration. 1347c9b443d4STobin Davis */ 1348c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1349c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 135082f30040STobin Davis .num_items = 4, 1351c9b443d4STobin Davis .items = { 135282f30040STobin Davis { "LINE1 pin", 0x0 }, 135382f30040STobin Davis { "MIC1 pin", 0x1 }, 135482f30040STobin Davis { "MIC2 pin", 0x2 }, 135582f30040STobin Davis { "CD pin", 0x3 }, 1356c9b443d4STobin Davis }, 1357c9b443d4STobin Davis }; 1358c9b443d4STobin Davis 1359c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1360c9b443d4STobin Davis 1361c9b443d4STobin Davis /* Output only controls */ 136282f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 136382f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 136482f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 136582f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1366c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1367c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1368c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1369c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 137082f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 137182f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 137282f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 137382f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1374c9b443d4STobin Davis 1375c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1376c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1377c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1378c9b443d4STobin Davis 137982f30040STobin Davis /* EAPD Switch Control */ 138082f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 138182f30040STobin Davis 1382c9b443d4STobin Davis /* Loopback mixer controls */ 138382f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 138482f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 138582f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 138682f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 138782f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 138882f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 138982f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 139082f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1391c9b443d4STobin Davis 139282f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 139382f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 139482f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 139582f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 139682f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 139782f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 139882f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 139982f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1400c9b443d4STobin Davis { 1401c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1402c9b443d4STobin Davis .name = "Input Source", 1403c9b443d4STobin Davis .info = conexant_mux_enum_info, 1404c9b443d4STobin Davis .get = conexant_mux_enum_get, 1405c9b443d4STobin Davis .put = conexant_mux_enum_put, 1406c9b443d4STobin Davis }, 14079f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 14089f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 14099f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 14109f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 14119f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 14129f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 14139f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 14149f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 14159f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 14169f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 14179f113e0eSMarc Boucher 1418c9b443d4STobin Davis { } /* end */ 1419c9b443d4STobin Davis }; 1420c9b443d4STobin Davis 1421c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1422c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1423c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1424c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1425c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1426c9b443d4STobin Davis 1427c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1428c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1429c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1430c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1431c9b443d4STobin Davis * control. 1432c9b443d4STobin Davis */ 1433c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1434c9b443d4STobin Davis 1435c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1436c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1437c9b443d4STobin Davis */ 1438c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1439c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1440c9b443d4STobin Davis 1441c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1442c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1443c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1444c9b443d4STobin Davis 1445c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1446c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1447c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1448c9b443d4STobin Davis * input/output buffers as needed. 1449c9b443d4STobin Davis */ 1450c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1451c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1452c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1453c9b443d4STobin Davis 1454c9b443d4STobin Davis /* Mute capture amp left and right */ 1455c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1456c9b443d4STobin Davis 1457c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1458c9b443d4STobin Davis * pin) 1459c9b443d4STobin Davis */ 1460c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1461c9b443d4STobin Davis 1462c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1463c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1464c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1465c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1466c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1467c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1468c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1469c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1470c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1471c9b443d4STobin Davis 1472c9b443d4STobin Davis { } 1473c9b443d4STobin Davis }; 1474c9b443d4STobin Davis #endif 1475c9b443d4STobin Davis 1476c9b443d4STobin Davis 1477c9b443d4STobin Davis /* initialize jack-sensing, too */ 1478c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1479c9b443d4STobin Davis { 1480c9b443d4STobin Davis conexant_init(codec); 1481c9b443d4STobin Davis cxt5047_hp_automute(codec); 1482c9b443d4STobin Davis return 0; 1483c9b443d4STobin Davis } 1484c9b443d4STobin Davis 1485c9b443d4STobin Davis 1486c9b443d4STobin Davis enum { 1487f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1488f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1489f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1490c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1491c9b443d4STobin Davis CXT5047_TEST, 1492c9b443d4STobin Davis #endif 1493f5fcc13cSTakashi Iwai CXT5047_MODELS 1494c9b443d4STobin Davis }; 1495c9b443d4STobin Davis 1496f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1497f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1498f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1499f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1500c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1501f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1502c9b443d4STobin Davis #endif 1503f5fcc13cSTakashi Iwai }; 1504c9b443d4STobin Davis 1505f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1506ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1507dea0a509STakashi Iwai SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series", 1508dea0a509STakashi Iwai CXT5047_LAPTOP), 1509f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1510c9b443d4STobin Davis {} 1511c9b443d4STobin Davis }; 1512c9b443d4STobin Davis 1513c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1514c9b443d4STobin Davis { 1515c9b443d4STobin Davis struct conexant_spec *spec; 1516c9b443d4STobin Davis int board_config; 1517c9b443d4STobin Davis 1518c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1519c9b443d4STobin Davis if (!spec) 1520c9b443d4STobin Davis return -ENOMEM; 1521c9b443d4STobin Davis codec->spec = spec; 15229421f954STakashi Iwai codec->pin_amp_workaround = 1; 1523c9b443d4STobin Davis 1524c9b443d4STobin Davis spec->multiout.max_channels = 2; 1525c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1526c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1527c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1528c9b443d4STobin Davis spec->num_adc_nids = 1; 1529c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1530c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1531c9b443d4STobin Davis spec->num_mixers = 1; 1532df481e41STakashi Iwai spec->mixers[0] = cxt5047_base_mixers; 1533c9b443d4STobin Davis spec->num_init_verbs = 1; 1534c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1535c9b443d4STobin Davis spec->spdif_route = 0; 15365cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 15375cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1538c9b443d4STobin Davis 1539c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1540c9b443d4STobin Davis 1541f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1542f5fcc13cSTakashi Iwai cxt5047_models, 1543f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1544c9b443d4STobin Davis switch (board_config) { 1545c9b443d4STobin Davis case CXT5047_LAPTOP: 1546df481e41STakashi Iwai spec->num_mixers = 2; 1547df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1548df481e41STakashi Iwai codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1549c9b443d4STobin Davis break; 1550c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1551df481e41STakashi Iwai spec->num_mixers = 2; 1552df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_only_mixers; 1553fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1554c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1555c9b443d4STobin Davis break; 1556c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 155782f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1558df481e41STakashi Iwai spec->num_mixers = 2; 1559df481e41STakashi Iwai spec->mixers[1] = cxt5047_hp_spk_mixers; 1560c9b443d4STobin Davis spec->num_init_verbs = 2; 1561c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1562fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1563c9b443d4STobin Davis break; 1564c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1565c9b443d4STobin Davis case CXT5047_TEST: 1566c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1567c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1568c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1569fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1570c9b443d4STobin Davis #endif 1571c9b443d4STobin Davis } 1572dd5746a8STakashi Iwai spec->vmaster_nid = 0x13; 1573c9b443d4STobin Davis return 0; 1574c9b443d4STobin Davis } 1575c9b443d4STobin Davis 1576461e2c78STakashi Iwai /* Conexant 5051 specific */ 1577461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1578461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1579461e2c78STakashi Iwai 1580461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1581461e2c78STakashi Iwai { 2, NULL }, 1582461e2c78STakashi Iwai }; 1583461e2c78STakashi Iwai 1584461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1585461e2c78STakashi Iwai { 1586461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1587461e2c78STakashi Iwai unsigned int pinctl; 1588461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1589461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1590461e2c78STakashi Iwai pinctl); 1591461e2c78STakashi Iwai } 1592461e2c78STakashi Iwai 1593461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1594461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1595461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1596461e2c78STakashi Iwai { 1597461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1598461e2c78STakashi Iwai 1599461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1600461e2c78STakashi Iwai return 0; 1601461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1602461e2c78STakashi Iwai return 1; 1603461e2c78STakashi Iwai } 1604461e2c78STakashi Iwai 1605461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1606461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1607461e2c78STakashi Iwai { 160879d7d533STakashi Iwai struct conexant_spec *spec = codec->spec; 1609461e2c78STakashi Iwai unsigned int present; 1610461e2c78STakashi Iwai 161179d7d533STakashi Iwai if (spec->no_auto_mic) 161279d7d533STakashi Iwai return; 1613461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x17, 0, 1614461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1615461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1616461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1617461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1618461e2c78STakashi Iwai present ? 0x01 : 0x00); 1619461e2c78STakashi Iwai } 1620461e2c78STakashi Iwai 1621461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1622461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1623461e2c78STakashi Iwai { 1624461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1625461e2c78STakashi Iwai unsigned int present; 1626461e2c78STakashi Iwai hda_nid_t new_adc; 1627461e2c78STakashi Iwai 162879d7d533STakashi Iwai if (spec->no_auto_mic) 162979d7d533STakashi Iwai return; 1630461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x18, 0, 1631461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1632461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1633461e2c78STakashi Iwai if (present) 1634461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1635461e2c78STakashi Iwai else 1636461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1637461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1638461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1639461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1640888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 1641461e2c78STakashi Iwai spec->cur_adc = new_adc; 1642461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1643461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1644461e2c78STakashi Iwai spec->cur_adc_format); 1645461e2c78STakashi Iwai } 1646461e2c78STakashi Iwai } 1647461e2c78STakashi Iwai 1648461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1649461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1650461e2c78STakashi Iwai { 1651461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1652461e2c78STakashi Iwai 1653461e2c78STakashi Iwai spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1654461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1655461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1656461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1657461e2c78STakashi Iwai } 1658461e2c78STakashi Iwai 1659461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1660461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1661461e2c78STakashi Iwai unsigned int res) 1662461e2c78STakashi Iwai { 1663acf26c0cSUlrich Dangel int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 1664461e2c78STakashi Iwai switch (res >> 26) { 1665461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1666461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1667461e2c78STakashi Iwai break; 1668461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1669461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1670461e2c78STakashi Iwai break; 1671461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1672461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1673461e2c78STakashi Iwai break; 1674461e2c78STakashi Iwai } 1675acf26c0cSUlrich Dangel conexant_report_jack(codec, nid); 1676461e2c78STakashi Iwai } 1677461e2c78STakashi Iwai 1678461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = { 1679461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1680461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1681461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1682461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1683461e2c78STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 1684461e2c78STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1685461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1686461e2c78STakashi Iwai { 1687461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1688461e2c78STakashi Iwai .name = "Master Playback Switch", 1689461e2c78STakashi Iwai .info = cxt_eapd_info, 1690461e2c78STakashi Iwai .get = cxt_eapd_get, 1691461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1692461e2c78STakashi Iwai .private_value = 0x1a, 1693461e2c78STakashi Iwai }, 1694461e2c78STakashi Iwai 1695461e2c78STakashi Iwai {} 1696461e2c78STakashi Iwai }; 1697461e2c78STakashi Iwai 1698461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1699461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1700461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1701461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1702461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1703461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1704461e2c78STakashi Iwai { 1705461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1706461e2c78STakashi Iwai .name = "Master Playback Switch", 1707461e2c78STakashi Iwai .info = cxt_eapd_info, 1708461e2c78STakashi Iwai .get = cxt_eapd_get, 1709461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1710461e2c78STakashi Iwai .private_value = 0x1a, 1711461e2c78STakashi Iwai }, 1712461e2c78STakashi Iwai 1713461e2c78STakashi Iwai {} 1714461e2c78STakashi Iwai }; 1715461e2c78STakashi Iwai 171679d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = { 171779d7d533STakashi Iwai HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT), 171879d7d533STakashi Iwai HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT), 171979d7d533STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 172079d7d533STakashi Iwai { 172179d7d533STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 172279d7d533STakashi Iwai .name = "Master Playback Switch", 172379d7d533STakashi Iwai .info = cxt_eapd_info, 172479d7d533STakashi Iwai .get = cxt_eapd_get, 172579d7d533STakashi Iwai .put = cxt5051_hp_master_sw_put, 172679d7d533STakashi Iwai .private_value = 0x1a, 172779d7d533STakashi Iwai }, 172879d7d533STakashi Iwai 172979d7d533STakashi Iwai {} 173079d7d533STakashi Iwai }; 173179d7d533STakashi Iwai 1732461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1733461e2c78STakashi Iwai /* Line in, Mic */ 1734461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1735461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1736461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1737461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1738461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1739461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1740461e2c78STakashi Iwai /* SPK */ 1741461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1742461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1743461e2c78STakashi Iwai /* HP, Amp */ 1744461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1745461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1746461e2c78STakashi Iwai /* DAC1 */ 1747461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1748461e2c78STakashi Iwai /* Record selector: Int mic */ 1749461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1750461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1751461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1752461e2c78STakashi Iwai /* SPDIF route: PCM */ 1753461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1754461e2c78STakashi Iwai /* EAPD */ 1755461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1756461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1757461e2c78STakashi Iwai {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 1758461e2c78STakashi Iwai {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, 1759461e2c78STakashi Iwai { } /* end */ 1760461e2c78STakashi Iwai }; 1761461e2c78STakashi Iwai 176279d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = { 176379d7d533STakashi Iwai /* Line in, Mic */ 176479d7d533STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 176579d7d533STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 176679d7d533STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 176779d7d533STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0}, 176879d7d533STakashi Iwai /* SPK */ 176979d7d533STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 177079d7d533STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 177179d7d533STakashi Iwai /* HP, Amp */ 177279d7d533STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 177379d7d533STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 177479d7d533STakashi Iwai /* DAC1 */ 177579d7d533STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 177679d7d533STakashi Iwai /* Record selector: Int mic */ 177779d7d533STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 177879d7d533STakashi Iwai {0x14, AC_VERB_SET_CONNECT_SEL, 0x1}, 177979d7d533STakashi Iwai /* SPDIF route: PCM */ 178079d7d533STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 178179d7d533STakashi Iwai /* EAPD */ 178279d7d533STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 178379d7d533STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 178479d7d533STakashi Iwai {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 178579d7d533STakashi Iwai { } /* end */ 178679d7d533STakashi Iwai }; 178779d7d533STakashi Iwai 178827e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = { 178927e08988SAristeu Sergio Rozanski Filho /* Line in, Mic */ 179027e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 179127e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 179227e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 179327e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 179427e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 179527e08988SAristeu Sergio Rozanski Filho {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 179627e08988SAristeu Sergio Rozanski Filho /* SPK */ 179727e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 179827e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 179927e08988SAristeu Sergio Rozanski Filho /* HP, Amp */ 180027e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 180127e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 180227e08988SAristeu Sergio Rozanski Filho /* Docking HP */ 180327e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 180427e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, 180527e08988SAristeu Sergio Rozanski Filho /* DAC1 */ 180627e08988SAristeu Sergio Rozanski Filho {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 180727e08988SAristeu Sergio Rozanski Filho /* Record selector: Int mic */ 180827e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 180927e08988SAristeu Sergio Rozanski Filho {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 181027e08988SAristeu Sergio Rozanski Filho {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 181127e08988SAristeu Sergio Rozanski Filho /* SPDIF route: PCM */ 181227e08988SAristeu Sergio Rozanski Filho {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 181327e08988SAristeu Sergio Rozanski Filho /* EAPD */ 181427e08988SAristeu Sergio Rozanski Filho {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 181527e08988SAristeu Sergio Rozanski Filho {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 181627e08988SAristeu Sergio Rozanski Filho {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 181727e08988SAristeu Sergio Rozanski Filho {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, 181827e08988SAristeu Sergio Rozanski Filho {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 181927e08988SAristeu Sergio Rozanski Filho { } /* end */ 182027e08988SAristeu Sergio Rozanski Filho }; 182127e08988SAristeu Sergio Rozanski Filho 1822461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1823461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1824461e2c78STakashi Iwai { 1825461e2c78STakashi Iwai conexant_init(codec); 1826acf26c0cSUlrich Dangel conexant_init_jacks(codec); 1827461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1828461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1829461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1830461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1831461e2c78STakashi Iwai } 1832461e2c78STakashi Iwai return 0; 1833461e2c78STakashi Iwai } 1834461e2c78STakashi Iwai 1835461e2c78STakashi Iwai 1836461e2c78STakashi Iwai enum { 1837461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1838461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 183979d7d533STakashi Iwai CXT5051_HP_DV6736, /* HP without mic switch */ 184027e08988SAristeu Sergio Rozanski Filho CXT5051_LENOVO_X200, /* Lenovo X200 laptop */ 1841461e2c78STakashi Iwai CXT5051_MODELS 1842461e2c78STakashi Iwai }; 1843461e2c78STakashi Iwai 1844461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1845461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1846461e2c78STakashi Iwai [CXT5051_HP] = "hp", 184779d7d533STakashi Iwai [CXT5051_HP_DV6736] = "hp-dv6736", 184827e08988SAristeu Sergio Rozanski Filho [CXT5051_LENOVO_X200] = "lenovo-x200", 1849461e2c78STakashi Iwai }; 1850461e2c78STakashi Iwai 1851461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 185279d7d533STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736), 18531812e67cSTony Vroon SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP), 1854461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1855461e2c78STakashi Iwai CXT5051_LAPTOP), 1856461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 185727e08988SAristeu Sergio Rozanski Filho SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200), 1858461e2c78STakashi Iwai {} 1859461e2c78STakashi Iwai }; 1860461e2c78STakashi Iwai 1861461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1862461e2c78STakashi Iwai { 1863461e2c78STakashi Iwai struct conexant_spec *spec; 1864461e2c78STakashi Iwai int board_config; 1865461e2c78STakashi Iwai 1866461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1867461e2c78STakashi Iwai if (!spec) 1868461e2c78STakashi Iwai return -ENOMEM; 1869461e2c78STakashi Iwai codec->spec = spec; 18709421f954STakashi Iwai codec->pin_amp_workaround = 1; 1871461e2c78STakashi Iwai 1872461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1873461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1874461e2c78STakashi Iwai 1875461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1876461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1877461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1878461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1879461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1880461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 1881461e2c78STakashi Iwai spec->num_mixers = 1; 1882461e2c78STakashi Iwai spec->mixers[0] = cxt5051_mixers; 1883461e2c78STakashi Iwai spec->num_init_verbs = 1; 1884461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1885461e2c78STakashi Iwai spec->spdif_route = 0; 1886461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1887461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1888461e2c78STakashi Iwai spec->cur_adc = 0; 1889461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1890461e2c78STakashi Iwai 189179d7d533STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 189279d7d533STakashi Iwai 1893461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1894461e2c78STakashi Iwai cxt5051_models, 1895461e2c78STakashi Iwai cxt5051_cfg_tbl); 1896461e2c78STakashi Iwai switch (board_config) { 1897461e2c78STakashi Iwai case CXT5051_HP: 1898461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1899461e2c78STakashi Iwai break; 190079d7d533STakashi Iwai case CXT5051_HP_DV6736: 190179d7d533STakashi Iwai spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs; 190279d7d533STakashi Iwai spec->mixers[0] = cxt5051_hp_dv6736_mixers; 190379d7d533STakashi Iwai spec->no_auto_mic = 1; 190479d7d533STakashi Iwai break; 190527e08988SAristeu Sergio Rozanski Filho case CXT5051_LENOVO_X200: 190627e08988SAristeu Sergio Rozanski Filho spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs; 1907461e2c78STakashi Iwai break; 1908461e2c78STakashi Iwai } 1909461e2c78STakashi Iwai 1910461e2c78STakashi Iwai return 0; 1911461e2c78STakashi Iwai } 1912461e2c78STakashi Iwai 1913*0fb67e98SDaniel Drake /* Conexant 5066 specific */ 1914*0fb67e98SDaniel Drake 1915*0fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 }; 1916*0fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 }; 1917*0fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 }; 1918*0fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT 0x21 1919*0fb67e98SDaniel Drake 1920*0fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = { 1921*0fb67e98SDaniel Drake { 2, NULL }, 1922*0fb67e98SDaniel Drake }; 1923*0fb67e98SDaniel Drake 1924*0fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec) 1925*0fb67e98SDaniel Drake { 1926*0fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 1927*0fb67e98SDaniel Drake unsigned int pinctl; 1928*0fb67e98SDaniel Drake 1929*0fb67e98SDaniel Drake snd_printdd("CXT5066: update speaker, hp_present=%d\n", 1930*0fb67e98SDaniel Drake spec->hp_present); 1931*0fb67e98SDaniel Drake 1932*0fb67e98SDaniel Drake /* Port A (HP) */ 1933*0fb67e98SDaniel Drake pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0; 1934*0fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1935*0fb67e98SDaniel Drake pinctl); 1936*0fb67e98SDaniel Drake 1937*0fb67e98SDaniel Drake /* Port D (HP/LO) */ 1938*0fb67e98SDaniel Drake pinctl = ((spec->hp_present & 2) && spec->cur_eapd) 1939*0fb67e98SDaniel Drake ? spec->port_d_mode : 0; 1940*0fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1941*0fb67e98SDaniel Drake pinctl); 1942*0fb67e98SDaniel Drake 1943*0fb67e98SDaniel Drake /* CLASS_D AMP */ 1944*0fb67e98SDaniel Drake pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1945*0fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1946*0fb67e98SDaniel Drake pinctl); 1947*0fb67e98SDaniel Drake 1948*0fb67e98SDaniel Drake if (spec->dell_automute) { 1949*0fb67e98SDaniel Drake /* DELL AIO Port Rule: PortA > PortD > IntSpk */ 1950*0fb67e98SDaniel Drake pinctl = (!(spec->hp_present & 1) && spec->cur_eapd) 1951*0fb67e98SDaniel Drake ? PIN_OUT : 0; 1952*0fb67e98SDaniel Drake snd_hda_codec_write(codec, 0x1c, 0, 1953*0fb67e98SDaniel Drake AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); 1954*0fb67e98SDaniel Drake } 1955*0fb67e98SDaniel Drake } 1956*0fb67e98SDaniel Drake 1957*0fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */ 1958*0fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1959*0fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 1960*0fb67e98SDaniel Drake { 1961*0fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1962*0fb67e98SDaniel Drake 1963*0fb67e98SDaniel Drake if (!cxt_eapd_put(kcontrol, ucontrol)) 1964*0fb67e98SDaniel Drake return 0; 1965*0fb67e98SDaniel Drake 1966*0fb67e98SDaniel Drake cxt5066_update_speaker(codec); 1967*0fb67e98SDaniel Drake return 1; 1968*0fb67e98SDaniel Drake } 1969*0fb67e98SDaniel Drake 1970*0fb67e98SDaniel Drake /* toggle input of built-in and mic jack appropriately */ 1971*0fb67e98SDaniel Drake static void cxt5066_automic(struct hda_codec *codec) 1972*0fb67e98SDaniel Drake { 1973*0fb67e98SDaniel Drake static struct hda_verb ext_mic_present[] = { 1974*0fb67e98SDaniel Drake /* enable external mic, port B */ 1975*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1976*0fb67e98SDaniel Drake 1977*0fb67e98SDaniel Drake /* switch to external mic input */ 1978*0fb67e98SDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 0}, 1979*0fb67e98SDaniel Drake 1980*0fb67e98SDaniel Drake /* disable internal mic, port C */ 1981*0fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 1982*0fb67e98SDaniel Drake {} 1983*0fb67e98SDaniel Drake }; 1984*0fb67e98SDaniel Drake static struct hda_verb ext_mic_absent[] = { 1985*0fb67e98SDaniel Drake /* enable internal mic, port C */ 1986*0fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1987*0fb67e98SDaniel Drake 1988*0fb67e98SDaniel Drake /* switch to internal mic input */ 1989*0fb67e98SDaniel Drake {0x17, AC_VERB_SET_CONNECT_SEL, 1}, 1990*0fb67e98SDaniel Drake 1991*0fb67e98SDaniel Drake /* disable external mic, port B */ 1992*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 1993*0fb67e98SDaniel Drake {} 1994*0fb67e98SDaniel Drake }; 1995*0fb67e98SDaniel Drake unsigned int present; 1996*0fb67e98SDaniel Drake 1997*0fb67e98SDaniel Drake present = snd_hda_codec_read(codec, 0x1a, 0, 1998*0fb67e98SDaniel Drake AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1999*0fb67e98SDaniel Drake if (present) { 2000*0fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone detected\n"); 2001*0fb67e98SDaniel Drake snd_hda_sequence_write(codec, ext_mic_present); 2002*0fb67e98SDaniel Drake } else { 2003*0fb67e98SDaniel Drake snd_printdd("CXT5066: external microphone absent\n"); 2004*0fb67e98SDaniel Drake snd_hda_sequence_write(codec, ext_mic_absent); 2005*0fb67e98SDaniel Drake } 2006*0fb67e98SDaniel Drake } 2007*0fb67e98SDaniel Drake 2008*0fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */ 2009*0fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec) 2010*0fb67e98SDaniel Drake { 2011*0fb67e98SDaniel Drake struct conexant_spec *spec = codec->spec; 2012*0fb67e98SDaniel Drake unsigned int portA, portD; 2013*0fb67e98SDaniel Drake 2014*0fb67e98SDaniel Drake /* Port A */ 2015*0fb67e98SDaniel Drake portA = snd_hda_codec_read(codec, 0x19, 0, AC_VERB_GET_PIN_SENSE, 0) 2016*0fb67e98SDaniel Drake & AC_PINSENSE_PRESENCE; 2017*0fb67e98SDaniel Drake 2018*0fb67e98SDaniel Drake /* Port D */ 2019*0fb67e98SDaniel Drake portD = (snd_hda_codec_read(codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) 2020*0fb67e98SDaniel Drake & AC_PINSENSE_PRESENCE) << 1; 2021*0fb67e98SDaniel Drake 2022*0fb67e98SDaniel Drake spec->hp_present = !!(portA | portD); 2023*0fb67e98SDaniel Drake snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n", 2024*0fb67e98SDaniel Drake portA, portD, spec->hp_present); 2025*0fb67e98SDaniel Drake cxt5066_update_speaker(codec); 2026*0fb67e98SDaniel Drake } 2027*0fb67e98SDaniel Drake 2028*0fb67e98SDaniel Drake /* unsolicited event for jack sensing */ 2029*0fb67e98SDaniel Drake static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res) 2030*0fb67e98SDaniel Drake { 2031*0fb67e98SDaniel Drake snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26); 2032*0fb67e98SDaniel Drake switch (res >> 26) { 2033*0fb67e98SDaniel Drake case CONEXANT_HP_EVENT: 2034*0fb67e98SDaniel Drake cxt5066_hp_automute(codec); 2035*0fb67e98SDaniel Drake break; 2036*0fb67e98SDaniel Drake case CONEXANT_MIC_EVENT: 2037*0fb67e98SDaniel Drake cxt5066_automic(codec); 2038*0fb67e98SDaniel Drake break; 2039*0fb67e98SDaniel Drake } 2040*0fb67e98SDaniel Drake } 2041*0fb67e98SDaniel Drake 2042*0fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = { 2043*0fb67e98SDaniel Drake .num_items = 5, 2044*0fb67e98SDaniel Drake .items = { 2045*0fb67e98SDaniel Drake { "0dB", 0 }, 2046*0fb67e98SDaniel Drake { "10dB", 1 }, 2047*0fb67e98SDaniel Drake { "20dB", 2 }, 2048*0fb67e98SDaniel Drake { "30dB", 3 }, 2049*0fb67e98SDaniel Drake { "40dB", 4 }, 2050*0fb67e98SDaniel Drake }, 2051*0fb67e98SDaniel Drake }; 2052*0fb67e98SDaniel Drake 2053*0fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol, 2054*0fb67e98SDaniel Drake struct snd_ctl_elem_info *uinfo) 2055*0fb67e98SDaniel Drake { 2056*0fb67e98SDaniel Drake return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo); 2057*0fb67e98SDaniel Drake } 2058*0fb67e98SDaniel Drake 2059*0fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol, 2060*0fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 2061*0fb67e98SDaniel Drake { 2062*0fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2063*0fb67e98SDaniel Drake int val; 2064*0fb67e98SDaniel Drake 2065*0fb67e98SDaniel Drake val = snd_hda_codec_read(codec, 0x17, 0, 2066*0fb67e98SDaniel Drake AC_VERB_GET_AMP_GAIN_MUTE, AC_AMP_GET_OUTPUT); 2067*0fb67e98SDaniel Drake 2068*0fb67e98SDaniel Drake ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN; 2069*0fb67e98SDaniel Drake return 0; 2070*0fb67e98SDaniel Drake } 2071*0fb67e98SDaniel Drake 2072*0fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol, 2073*0fb67e98SDaniel Drake struct snd_ctl_elem_value *ucontrol) 2074*0fb67e98SDaniel Drake { 2075*0fb67e98SDaniel Drake struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 2076*0fb67e98SDaniel Drake const struct hda_input_mux *imux = &cxt5066_analog_mic_boost; 2077*0fb67e98SDaniel Drake unsigned int idx; 2078*0fb67e98SDaniel Drake 2079*0fb67e98SDaniel Drake if (!imux->num_items) 2080*0fb67e98SDaniel Drake return 0; 2081*0fb67e98SDaniel Drake idx = ucontrol->value.enumerated.item[0]; 2082*0fb67e98SDaniel Drake if (idx >= imux->num_items) 2083*0fb67e98SDaniel Drake idx = imux->num_items - 1; 2084*0fb67e98SDaniel Drake 2085*0fb67e98SDaniel Drake snd_hda_codec_write_cache(codec, 0x17, 0, 2086*0fb67e98SDaniel Drake AC_VERB_SET_AMP_GAIN_MUTE, 2087*0fb67e98SDaniel Drake AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT | 2088*0fb67e98SDaniel Drake imux->items[idx].index); 2089*0fb67e98SDaniel Drake 2090*0fb67e98SDaniel Drake return 1; 2091*0fb67e98SDaniel Drake } 2092*0fb67e98SDaniel Drake 2093*0fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = { 2094*0fb67e98SDaniel Drake .num_items = 4, 2095*0fb67e98SDaniel Drake .items = { 2096*0fb67e98SDaniel Drake { "Mic B", 0 }, 2097*0fb67e98SDaniel Drake { "Mic C", 1 }, 2098*0fb67e98SDaniel Drake { "Mic E", 2 }, 2099*0fb67e98SDaniel Drake { "Mic F", 3 }, 2100*0fb67e98SDaniel Drake }, 2101*0fb67e98SDaniel Drake }; 2102*0fb67e98SDaniel Drake 2103*0fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = { 2104*0fb67e98SDaniel Drake .ops = &snd_hda_bind_vol, 2105*0fb67e98SDaniel Drake .values = { 2106*0fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 2107*0fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 2108*0fb67e98SDaniel Drake 0 2109*0fb67e98SDaniel Drake }, 2110*0fb67e98SDaniel Drake }; 2111*0fb67e98SDaniel Drake 2112*0fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = { 2113*0fb67e98SDaniel Drake .ops = &snd_hda_bind_sw, 2114*0fb67e98SDaniel Drake .values = { 2115*0fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT), 2116*0fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT), 2117*0fb67e98SDaniel Drake 0 2118*0fb67e98SDaniel Drake }, 2119*0fb67e98SDaniel Drake }; 2120*0fb67e98SDaniel Drake 2121*0fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = { 2122*0fb67e98SDaniel Drake HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 2123*0fb67e98SDaniel Drake {} 2124*0fb67e98SDaniel Drake }; 2125*0fb67e98SDaniel Drake 2126*0fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = { 2127*0fb67e98SDaniel Drake { 2128*0fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2129*0fb67e98SDaniel Drake .name = "Master Playback Volume", 2130*0fb67e98SDaniel Drake .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 2131*0fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_READ | 2132*0fb67e98SDaniel Drake SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, 2133*0fb67e98SDaniel Drake .info = snd_hda_mixer_amp_volume_info, 2134*0fb67e98SDaniel Drake .get = snd_hda_mixer_amp_volume_get, 2135*0fb67e98SDaniel Drake .put = snd_hda_mixer_amp_volume_put, 2136*0fb67e98SDaniel Drake .tlv = { .c = snd_hda_mixer_amp_tlv }, 2137*0fb67e98SDaniel Drake /* offset by 28 volume steps to limit minimum gain to -46dB */ 2138*0fb67e98SDaniel Drake .private_value = 2139*0fb67e98SDaniel Drake HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28), 2140*0fb67e98SDaniel Drake }, 2141*0fb67e98SDaniel Drake {} 2142*0fb67e98SDaniel Drake }; 2143*0fb67e98SDaniel Drake 2144*0fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = { 2145*0fb67e98SDaniel Drake { 2146*0fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2147*0fb67e98SDaniel Drake .name = "Master Playback Switch", 2148*0fb67e98SDaniel Drake .info = cxt_eapd_info, 2149*0fb67e98SDaniel Drake .get = cxt_eapd_get, 2150*0fb67e98SDaniel Drake .put = cxt5066_hp_master_sw_put, 2151*0fb67e98SDaniel Drake .private_value = 0x1d, 2152*0fb67e98SDaniel Drake }, 2153*0fb67e98SDaniel Drake 2154*0fb67e98SDaniel Drake { 2155*0fb67e98SDaniel Drake .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2156*0fb67e98SDaniel Drake .name = "Analog Mic Boost Capture Enum", 2157*0fb67e98SDaniel Drake .info = cxt5066_mic_boost_mux_enum_info, 2158*0fb67e98SDaniel Drake .get = cxt5066_mic_boost_mux_enum_get, 2159*0fb67e98SDaniel Drake .put = cxt5066_mic_boost_mux_enum_put, 2160*0fb67e98SDaniel Drake }, 2161*0fb67e98SDaniel Drake 2162*0fb67e98SDaniel Drake HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others), 2163*0fb67e98SDaniel Drake HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others), 2164*0fb67e98SDaniel Drake {} 2165*0fb67e98SDaniel Drake }; 2166*0fb67e98SDaniel Drake 2167*0fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = { 2168*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */ 2169*0fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */ 2170*0fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */ 2171*0fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */ 2172*0fb67e98SDaniel Drake 2173*0fb67e98SDaniel Drake /* Speakers */ 2174*0fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2175*0fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2176*0fb67e98SDaniel Drake 2177*0fb67e98SDaniel Drake /* HP, Amp */ 2178*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2179*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2180*0fb67e98SDaniel Drake 2181*0fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2182*0fb67e98SDaniel Drake {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2183*0fb67e98SDaniel Drake 2184*0fb67e98SDaniel Drake /* DAC1 */ 2185*0fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2186*0fb67e98SDaniel Drake 2187*0fb67e98SDaniel Drake /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */ 2188*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2189*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2190*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50}, 2191*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2192*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 2193*0fb67e98SDaniel Drake 2194*0fb67e98SDaniel Drake /* no digital microphone support yet */ 2195*0fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2196*0fb67e98SDaniel Drake 2197*0fb67e98SDaniel Drake /* Audio input selector */ 2198*0fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 2199*0fb67e98SDaniel Drake 2200*0fb67e98SDaniel Drake /* SPDIF route: PCM */ 2201*0fb67e98SDaniel Drake {0x20, AC_VERB_SET_CONNECT_SEL, 0x0}, 2202*0fb67e98SDaniel Drake {0x22, AC_VERB_SET_CONNECT_SEL, 0x0}, 2203*0fb67e98SDaniel Drake 2204*0fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2205*0fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2206*0fb67e98SDaniel Drake 2207*0fb67e98SDaniel Drake /* EAPD */ 2208*0fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2209*0fb67e98SDaniel Drake 2210*0fb67e98SDaniel Drake /* not handling these yet */ 2211*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2212*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2213*0fb67e98SDaniel Drake {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2214*0fb67e98SDaniel Drake {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2215*0fb67e98SDaniel Drake {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2216*0fb67e98SDaniel Drake {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2217*0fb67e98SDaniel Drake {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2218*0fb67e98SDaniel Drake {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0}, 2219*0fb67e98SDaniel Drake { } /* end */ 2220*0fb67e98SDaniel Drake }; 2221*0fb67e98SDaniel Drake 2222*0fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = { 2223*0fb67e98SDaniel Drake /* Port A: headphones */ 2224*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 2225*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2226*0fb67e98SDaniel Drake 2227*0fb67e98SDaniel Drake /* Port B: external microphone */ 2228*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2229*0fb67e98SDaniel Drake 2230*0fb67e98SDaniel Drake /* Port C: internal microphone */ 2231*0fb67e98SDaniel Drake {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 2232*0fb67e98SDaniel Drake 2233*0fb67e98SDaniel Drake /* Port D: unused */ 2234*0fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2235*0fb67e98SDaniel Drake 2236*0fb67e98SDaniel Drake /* Port E: unused, but has primary EAPD */ 2237*0fb67e98SDaniel Drake {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2238*0fb67e98SDaniel Drake {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 2239*0fb67e98SDaniel Drake 2240*0fb67e98SDaniel Drake /* Port F: unused */ 2241*0fb67e98SDaniel Drake {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2242*0fb67e98SDaniel Drake 2243*0fb67e98SDaniel Drake /* Port G: internal speakers */ 2244*0fb67e98SDaniel Drake {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2245*0fb67e98SDaniel Drake {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */ 2246*0fb67e98SDaniel Drake 2247*0fb67e98SDaniel Drake /* DAC1 */ 2248*0fb67e98SDaniel Drake {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2249*0fb67e98SDaniel Drake 2250*0fb67e98SDaniel Drake /* DAC2: unused */ 2251*0fb67e98SDaniel Drake {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 2252*0fb67e98SDaniel Drake 2253*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50}, 2254*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2255*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2256*0fb67e98SDaniel Drake {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2257*0fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2258*0fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2259*0fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2260*0fb67e98SDaniel Drake {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2261*0fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2262*0fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2263*0fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 2264*0fb67e98SDaniel Drake {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 2265*0fb67e98SDaniel Drake 2266*0fb67e98SDaniel Drake /* Disable digital microphone port */ 2267*0fb67e98SDaniel Drake {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2268*0fb67e98SDaniel Drake 2269*0fb67e98SDaniel Drake /* Audio input selectors */ 2270*0fb67e98SDaniel Drake {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3}, 2271*0fb67e98SDaniel Drake {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 2272*0fb67e98SDaniel Drake 2273*0fb67e98SDaniel Drake /* Disable SPDIF */ 2274*0fb67e98SDaniel Drake {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2275*0fb67e98SDaniel Drake {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0}, 2276*0fb67e98SDaniel Drake 2277*0fb67e98SDaniel Drake /* enable unsolicited events for Port A and B */ 2278*0fb67e98SDaniel Drake {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 2279*0fb67e98SDaniel Drake {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 2280*0fb67e98SDaniel Drake { } /* end */ 2281*0fb67e98SDaniel Drake }; 2282*0fb67e98SDaniel Drake 2283*0fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = { 2284*0fb67e98SDaniel Drake {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 2285*0fb67e98SDaniel Drake { } /* end */ 2286*0fb67e98SDaniel Drake }; 2287*0fb67e98SDaniel Drake 2288*0fb67e98SDaniel Drake /* initialize jack-sensing, too */ 2289*0fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec) 2290*0fb67e98SDaniel Drake { 2291*0fb67e98SDaniel Drake snd_printdd("CXT5066: init\n"); 2292*0fb67e98SDaniel Drake conexant_init(codec); 2293*0fb67e98SDaniel Drake if (codec->patch_ops.unsol_event) { 2294*0fb67e98SDaniel Drake cxt5066_hp_automute(codec); 2295*0fb67e98SDaniel Drake cxt5066_automic(codec); 2296*0fb67e98SDaniel Drake } 2297*0fb67e98SDaniel Drake return 0; 2298*0fb67e98SDaniel Drake } 2299*0fb67e98SDaniel Drake 2300*0fb67e98SDaniel Drake enum { 2301*0fb67e98SDaniel Drake CXT5066_LAPTOP, /* Laptops w/ EAPD support */ 2302*0fb67e98SDaniel Drake CXT5066_DELL_LAPTOP, /* Dell Laptop */ 2303*0fb67e98SDaniel Drake CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */ 2304*0fb67e98SDaniel Drake CXT5066_MODELS 2305*0fb67e98SDaniel Drake }; 2306*0fb67e98SDaniel Drake 2307*0fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = { 2308*0fb67e98SDaniel Drake [CXT5066_LAPTOP] = "laptop", 2309*0fb67e98SDaniel Drake [CXT5066_DELL_LAPTOP] = "dell-laptop", 2310*0fb67e98SDaniel Drake [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5", 2311*0fb67e98SDaniel Drake }; 2312*0fb67e98SDaniel Drake 2313*0fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = { 2314*0fb67e98SDaniel Drake SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 2315*0fb67e98SDaniel Drake CXT5066_LAPTOP), 2316*0fb67e98SDaniel Drake SND_PCI_QUIRK(0x1028, 0x02f5, "Dell", 2317*0fb67e98SDaniel Drake CXT5066_DELL_LAPTOP), 2318*0fb67e98SDaniel Drake {} 2319*0fb67e98SDaniel Drake }; 2320*0fb67e98SDaniel Drake 2321*0fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec) 2322*0fb67e98SDaniel Drake { 2323*0fb67e98SDaniel Drake struct conexant_spec *spec; 2324*0fb67e98SDaniel Drake int board_config; 2325*0fb67e98SDaniel Drake 2326*0fb67e98SDaniel Drake spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2327*0fb67e98SDaniel Drake if (!spec) 2328*0fb67e98SDaniel Drake return -ENOMEM; 2329*0fb67e98SDaniel Drake codec->spec = spec; 2330*0fb67e98SDaniel Drake 2331*0fb67e98SDaniel Drake codec->patch_ops = conexant_patch_ops; 2332*0fb67e98SDaniel Drake codec->patch_ops.init = cxt5066_init; 2333*0fb67e98SDaniel Drake 2334*0fb67e98SDaniel Drake spec->dell_automute = 0; 2335*0fb67e98SDaniel Drake spec->multiout.max_channels = 2; 2336*0fb67e98SDaniel Drake spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids); 2337*0fb67e98SDaniel Drake spec->multiout.dac_nids = cxt5066_dac_nids; 2338*0fb67e98SDaniel Drake spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT; 2339*0fb67e98SDaniel Drake spec->num_adc_nids = 1; 2340*0fb67e98SDaniel Drake spec->adc_nids = cxt5066_adc_nids; 2341*0fb67e98SDaniel Drake spec->capsrc_nids = cxt5066_capsrc_nids; 2342*0fb67e98SDaniel Drake spec->input_mux = &cxt5066_capture_source; 2343*0fb67e98SDaniel Drake 2344*0fb67e98SDaniel Drake spec->port_d_mode = PIN_HP; 2345*0fb67e98SDaniel Drake 2346*0fb67e98SDaniel Drake spec->num_init_verbs = 1; 2347*0fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs; 2348*0fb67e98SDaniel Drake spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes); 2349*0fb67e98SDaniel Drake spec->channel_mode = cxt5066_modes; 2350*0fb67e98SDaniel Drake spec->cur_adc = 0; 2351*0fb67e98SDaniel Drake spec->cur_adc_idx = 0; 2352*0fb67e98SDaniel Drake 2353*0fb67e98SDaniel Drake board_config = snd_hda_check_board_config(codec, CXT5066_MODELS, 2354*0fb67e98SDaniel Drake cxt5066_models, cxt5066_cfg_tbl); 2355*0fb67e98SDaniel Drake switch (board_config) { 2356*0fb67e98SDaniel Drake default: 2357*0fb67e98SDaniel Drake case CXT5066_LAPTOP: 2358*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 2359*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2360*0fb67e98SDaniel Drake break; 2361*0fb67e98SDaniel Drake case CXT5066_DELL_LAPTOP: 2362*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master; 2363*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2364*0fb67e98SDaniel Drake 2365*0fb67e98SDaniel Drake spec->port_d_mode = PIN_OUT; 2366*0fb67e98SDaniel Drake spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo; 2367*0fb67e98SDaniel Drake spec->num_init_verbs++; 2368*0fb67e98SDaniel Drake spec->dell_automute = 1; 2369*0fb67e98SDaniel Drake break; 2370*0fb67e98SDaniel Drake case CXT5066_OLPC_XO_1_5: 2371*0fb67e98SDaniel Drake codec->patch_ops.unsol_event = cxt5066_unsol_event; 2372*0fb67e98SDaniel Drake spec->init_verbs[0] = cxt5066_init_verbs_olpc; 2373*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc; 2374*0fb67e98SDaniel Drake spec->mixers[spec->num_mixers++] = cxt5066_mixers; 2375*0fb67e98SDaniel Drake spec->port_d_mode = 0; 2376*0fb67e98SDaniel Drake 2377*0fb67e98SDaniel Drake /* no S/PDIF out */ 2378*0fb67e98SDaniel Drake spec->multiout.dig_out_nid = 0; 2379*0fb67e98SDaniel Drake 2380*0fb67e98SDaniel Drake /* input source automatically selected */ 2381*0fb67e98SDaniel Drake spec->input_mux = NULL; 2382*0fb67e98SDaniel Drake break; 2383*0fb67e98SDaniel Drake } 2384*0fb67e98SDaniel Drake 2385*0fb67e98SDaniel Drake return 0; 2386*0fb67e98SDaniel Drake } 2387461e2c78STakashi Iwai 2388461e2c78STakashi Iwai /* 2389461e2c78STakashi Iwai */ 2390461e2c78STakashi Iwai 23911289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 239282f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 239382f30040STobin Davis .patch = patch_cxt5045 }, 239482f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 239582f30040STobin Davis .patch = patch_cxt5047 }, 2396461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 2397461e2c78STakashi Iwai .patch = patch_cxt5051 }, 2398*0fb67e98SDaniel Drake { .id = 0x14f15066, .name = "CX20582 (Pebble)", 2399*0fb67e98SDaniel Drake .patch = patch_cxt5066 }, 2400c9b443d4STobin Davis {} /* terminator */ 2401c9b443d4STobin Davis }; 24021289e9e8STakashi Iwai 24031289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 24041289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 24051289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 2406*0fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066"); 24071289e9e8STakashi Iwai 24081289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 24091289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 24101289e9e8STakashi Iwai 24111289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 24121289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 24131289e9e8STakashi Iwai .owner = THIS_MODULE, 24141289e9e8STakashi Iwai }; 24151289e9e8STakashi Iwai 24161289e9e8STakashi Iwai static int __init patch_conexant_init(void) 24171289e9e8STakashi Iwai { 24181289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 24191289e9e8STakashi Iwai } 24201289e9e8STakashi Iwai 24211289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 24221289e9e8STakashi Iwai { 24231289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 24241289e9e8STakashi Iwai } 24251289e9e8STakashi Iwai 24261289e9e8STakashi Iwai module_init(patch_conexant_init) 24271289e9e8STakashi Iwai module_exit(patch_conexant_exit) 2428