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> 28c9b443d4STobin Davis #include "hda_codec.h" 29c9b443d4STobin Davis #include "hda_local.h" 30c9b443d4STobin Davis 31c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 32c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 33c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 34c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 35c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 36c9b443d4STobin Davis 37c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 38c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 39c9b443d4STobin Davis 40c9b443d4STobin Davis 41c9b443d4STobin Davis 42c9b443d4STobin Davis struct conexant_spec { 43c9b443d4STobin Davis 44c9b443d4STobin Davis struct snd_kcontrol_new *mixers[5]; 45c9b443d4STobin Davis int num_mixers; 46c9b443d4STobin Davis 47c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 48c9b443d4STobin Davis * don't forget NULL 49c9b443d4STobin Davis * termination! 50c9b443d4STobin Davis */ 51c9b443d4STobin Davis unsigned int num_init_verbs; 52c9b443d4STobin Davis 53c9b443d4STobin Davis /* playback */ 54c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 55c9b443d4STobin Davis * max_channels, dacs must be set 56c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 57c9b443d4STobin Davis */ 58c9b443d4STobin Davis unsigned int cur_eapd; 5982f30040STobin Davis unsigned int hp_present; 60c9b443d4STobin Davis unsigned int need_dac_fix; 61c9b443d4STobin Davis 62c9b443d4STobin Davis /* capture */ 63c9b443d4STobin Davis unsigned int num_adc_nids; 64c9b443d4STobin Davis hda_nid_t *adc_nids; 65c9b443d4STobin Davis hda_nid_t dig_in_nid; /* digital-in NID; optional */ 66c9b443d4STobin Davis 67461e2c78STakashi Iwai unsigned int cur_adc_idx; 68461e2c78STakashi Iwai hda_nid_t cur_adc; 69461e2c78STakashi Iwai unsigned int cur_adc_stream_tag; 70461e2c78STakashi Iwai unsigned int cur_adc_format; 71461e2c78STakashi Iwai 72c9b443d4STobin Davis /* capture source */ 73c9b443d4STobin Davis const struct hda_input_mux *input_mux; 74c9b443d4STobin Davis hda_nid_t *capsrc_nids; 75c9b443d4STobin Davis unsigned int cur_mux[3]; 76c9b443d4STobin Davis 77c9b443d4STobin Davis /* channel model */ 78c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 79c9b443d4STobin Davis int num_channel_mode; 80c9b443d4STobin Davis 81c9b443d4STobin Davis /* PCM information */ 82c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 83c9b443d4STobin Davis 84c9b443d4STobin Davis unsigned int spdif_route; 85c9b443d4STobin Davis 86c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 87c9b443d4STobin Davis struct auto_pin_cfg autocfg; 88c9b443d4STobin Davis struct hda_input_mux private_imux; 8941923e44STakashi Iwai hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 90c9b443d4STobin Davis 91c9b443d4STobin Davis }; 92c9b443d4STobin Davis 93c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 94c9b443d4STobin Davis struct hda_codec *codec, 95c9b443d4STobin Davis struct snd_pcm_substream *substream) 96c9b443d4STobin Davis { 97c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 989a08160bSTakashi Iwai return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 999a08160bSTakashi Iwai hinfo); 100c9b443d4STobin Davis } 101c9b443d4STobin Davis 102c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 103c9b443d4STobin Davis struct hda_codec *codec, 104c9b443d4STobin Davis unsigned int stream_tag, 105c9b443d4STobin Davis unsigned int format, 106c9b443d4STobin Davis struct snd_pcm_substream *substream) 107c9b443d4STobin Davis { 108c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 109c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 110c9b443d4STobin Davis stream_tag, 111c9b443d4STobin Davis format, substream); 112c9b443d4STobin Davis } 113c9b443d4STobin Davis 114c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 115c9b443d4STobin Davis struct hda_codec *codec, 116c9b443d4STobin Davis struct snd_pcm_substream *substream) 117c9b443d4STobin Davis { 118c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 119c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 120c9b443d4STobin Davis } 121c9b443d4STobin Davis 122c9b443d4STobin Davis /* 123c9b443d4STobin Davis * Digital out 124c9b443d4STobin Davis */ 125c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 126c9b443d4STobin Davis struct hda_codec *codec, 127c9b443d4STobin Davis struct snd_pcm_substream *substream) 128c9b443d4STobin Davis { 129c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 130c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 131c9b443d4STobin Davis } 132c9b443d4STobin Davis 133c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 134c9b443d4STobin Davis struct hda_codec *codec, 135c9b443d4STobin Davis struct snd_pcm_substream *substream) 136c9b443d4STobin Davis { 137c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 138c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 139c9b443d4STobin Davis } 140c9b443d4STobin Davis 1416b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1426b97eb45STakashi Iwai struct hda_codec *codec, 1436b97eb45STakashi Iwai unsigned int stream_tag, 1446b97eb45STakashi Iwai unsigned int format, 1456b97eb45STakashi Iwai struct snd_pcm_substream *substream) 1466b97eb45STakashi Iwai { 1476b97eb45STakashi Iwai struct conexant_spec *spec = codec->spec; 1486b97eb45STakashi Iwai return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, 1496b97eb45STakashi Iwai stream_tag, 1506b97eb45STakashi Iwai format, substream); 1516b97eb45STakashi Iwai } 1526b97eb45STakashi Iwai 153c9b443d4STobin Davis /* 154c9b443d4STobin Davis * Analog capture 155c9b443d4STobin Davis */ 156c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 157c9b443d4STobin Davis struct hda_codec *codec, 158c9b443d4STobin Davis unsigned int stream_tag, 159c9b443d4STobin Davis unsigned int format, 160c9b443d4STobin Davis struct snd_pcm_substream *substream) 161c9b443d4STobin Davis { 162c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 163c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 164c9b443d4STobin Davis stream_tag, 0, format); 165c9b443d4STobin Davis return 0; 166c9b443d4STobin Davis } 167c9b443d4STobin Davis 168c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 169c9b443d4STobin Davis struct hda_codec *codec, 170c9b443d4STobin Davis struct snd_pcm_substream *substream) 171c9b443d4STobin Davis { 172c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 173888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); 174c9b443d4STobin Davis return 0; 175c9b443d4STobin Davis } 176c9b443d4STobin Davis 177c9b443d4STobin Davis 178c9b443d4STobin Davis 179c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 180c9b443d4STobin Davis .substreams = 1, 181c9b443d4STobin Davis .channels_min = 2, 182c9b443d4STobin Davis .channels_max = 2, 183c9b443d4STobin Davis .nid = 0, /* fill later */ 184c9b443d4STobin Davis .ops = { 185c9b443d4STobin Davis .open = conexant_playback_pcm_open, 186c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 187c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 188c9b443d4STobin Davis }, 189c9b443d4STobin Davis }; 190c9b443d4STobin Davis 191c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 192c9b443d4STobin Davis .substreams = 1, 193c9b443d4STobin Davis .channels_min = 2, 194c9b443d4STobin Davis .channels_max = 2, 195c9b443d4STobin Davis .nid = 0, /* fill later */ 196c9b443d4STobin Davis .ops = { 197c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 198c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 199c9b443d4STobin Davis }, 200c9b443d4STobin Davis }; 201c9b443d4STobin Davis 202c9b443d4STobin Davis 203c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 204c9b443d4STobin Davis .substreams = 1, 205c9b443d4STobin Davis .channels_min = 2, 206c9b443d4STobin Davis .channels_max = 2, 207c9b443d4STobin Davis .nid = 0, /* fill later */ 208c9b443d4STobin Davis .ops = { 209c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 2106b97eb45STakashi Iwai .close = conexant_dig_playback_pcm_close, 2116b97eb45STakashi Iwai .prepare = conexant_dig_playback_pcm_prepare 212c9b443d4STobin Davis }, 213c9b443d4STobin Davis }; 214c9b443d4STobin Davis 215c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 216c9b443d4STobin Davis .substreams = 1, 217c9b443d4STobin Davis .channels_min = 2, 218c9b443d4STobin Davis .channels_max = 2, 219c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 220c9b443d4STobin Davis }; 221c9b443d4STobin Davis 222461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 223461e2c78STakashi Iwai struct hda_codec *codec, 224461e2c78STakashi Iwai unsigned int stream_tag, 225461e2c78STakashi Iwai unsigned int format, 226461e2c78STakashi Iwai struct snd_pcm_substream *substream) 227461e2c78STakashi Iwai { 228461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 229461e2c78STakashi Iwai spec->cur_adc = spec->adc_nids[spec->cur_adc_idx]; 230461e2c78STakashi Iwai spec->cur_adc_stream_tag = stream_tag; 231461e2c78STakashi Iwai spec->cur_adc_format = format; 232461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); 233461e2c78STakashi Iwai return 0; 234461e2c78STakashi Iwai } 235461e2c78STakashi Iwai 236461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 237461e2c78STakashi Iwai struct hda_codec *codec, 238461e2c78STakashi Iwai struct snd_pcm_substream *substream) 239461e2c78STakashi Iwai { 240461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 241888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 242461e2c78STakashi Iwai spec->cur_adc = 0; 243461e2c78STakashi Iwai return 0; 244461e2c78STakashi Iwai } 245461e2c78STakashi Iwai 246461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = { 247461e2c78STakashi Iwai .substreams = 1, 248461e2c78STakashi Iwai .channels_min = 2, 249461e2c78STakashi Iwai .channels_max = 2, 250461e2c78STakashi Iwai .nid = 0, /* fill later */ 251461e2c78STakashi Iwai .ops = { 252461e2c78STakashi Iwai .prepare = cx5051_capture_pcm_prepare, 253461e2c78STakashi Iwai .cleanup = cx5051_capture_pcm_cleanup 254461e2c78STakashi Iwai }, 255461e2c78STakashi Iwai }; 256461e2c78STakashi Iwai 257c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 258c9b443d4STobin Davis { 259c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 260c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 261c9b443d4STobin Davis 262c9b443d4STobin Davis codec->num_pcms = 1; 263c9b443d4STobin Davis codec->pcm_info = info; 264c9b443d4STobin Davis 265c9b443d4STobin Davis info->name = "CONEXANT Analog"; 266c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 267c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 268c9b443d4STobin Davis spec->multiout.max_channels; 269c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 270c9b443d4STobin Davis spec->multiout.dac_nids[0]; 271461e2c78STakashi Iwai if (codec->vendor_id == 0x14f15051) 272461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 273461e2c78STakashi Iwai cx5051_pcm_analog_capture; 274461e2c78STakashi Iwai else 275461e2c78STakashi Iwai info->stream[SNDRV_PCM_STREAM_CAPTURE] = 276461e2c78STakashi Iwai conexant_pcm_analog_capture; 277c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 278c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 279c9b443d4STobin Davis 280c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 281c9b443d4STobin Davis info++; 282c9b443d4STobin Davis codec->num_pcms++; 283c9b443d4STobin Davis info->name = "Conexant Digital"; 2847ba72ba1STakashi Iwai info->pcm_type = HDA_PCM_TYPE_SPDIF; 285c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 286c9b443d4STobin Davis conexant_pcm_digital_playback; 287c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 288c9b443d4STobin Davis spec->multiout.dig_out_nid; 289c9b443d4STobin Davis if (spec->dig_in_nid) { 290c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 291c9b443d4STobin Davis conexant_pcm_digital_capture; 292c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 293c9b443d4STobin Davis spec->dig_in_nid; 294c9b443d4STobin Davis } 295c9b443d4STobin Davis } 296c9b443d4STobin Davis 297c9b443d4STobin Davis return 0; 298c9b443d4STobin Davis } 299c9b443d4STobin Davis 300c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 301c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 302c9b443d4STobin Davis { 303c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 304c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 305c9b443d4STobin Davis 306c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 307c9b443d4STobin Davis } 308c9b443d4STobin Davis 309c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 310c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 311c9b443d4STobin Davis { 312c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 313c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 314c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 315c9b443d4STobin Davis 316c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 317c9b443d4STobin Davis return 0; 318c9b443d4STobin Davis } 319c9b443d4STobin Davis 320c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 321c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 322c9b443d4STobin Davis { 323c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 324c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 325c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 326c9b443d4STobin Davis 327c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 328c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 329c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 330c9b443d4STobin Davis } 331c9b443d4STobin Davis 332c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 333c9b443d4STobin Davis { 334c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 335c9b443d4STobin Davis int i; 336c9b443d4STobin Davis 337c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 338c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 339c9b443d4STobin Davis return 0; 340c9b443d4STobin Davis } 341c9b443d4STobin Davis 342c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 343c9b443d4STobin Davis { 344c9b443d4STobin Davis kfree(codec->spec); 345c9b443d4STobin Davis } 346c9b443d4STobin Davis 347c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 348c9b443d4STobin Davis { 349c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 350c9b443d4STobin Davis unsigned int i; 351c9b443d4STobin Davis int err; 352c9b443d4STobin Davis 353c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 354c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 355c9b443d4STobin Davis if (err < 0) 356c9b443d4STobin Davis return err; 357c9b443d4STobin Davis } 358c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 359c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 360c9b443d4STobin Davis spec->multiout.dig_out_nid); 361c9b443d4STobin Davis if (err < 0) 362c9b443d4STobin Davis return err; 3639a08160bSTakashi Iwai err = snd_hda_create_spdif_share_sw(codec, 3649a08160bSTakashi Iwai &spec->multiout); 3659a08160bSTakashi Iwai if (err < 0) 3669a08160bSTakashi Iwai return err; 3679a08160bSTakashi Iwai spec->multiout.share_spdif = 1; 368c9b443d4STobin Davis } 369c9b443d4STobin Davis if (spec->dig_in_nid) { 370c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 371c9b443d4STobin Davis if (err < 0) 372c9b443d4STobin Davis return err; 373c9b443d4STobin Davis } 374c9b443d4STobin Davis return 0; 375c9b443d4STobin Davis } 376c9b443d4STobin Davis 377c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 378c9b443d4STobin Davis .build_controls = conexant_build_controls, 379c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 380c9b443d4STobin Davis .init = conexant_init, 381c9b443d4STobin Davis .free = conexant_free, 382c9b443d4STobin Davis }; 383c9b443d4STobin Davis 384c9b443d4STobin Davis /* 385c9b443d4STobin Davis * EAPD control 386c9b443d4STobin Davis * the private value = nid | (invert << 8) 387c9b443d4STobin Davis */ 388c9b443d4STobin Davis 389a5ce8890STakashi Iwai #define cxt_eapd_info snd_ctl_boolean_mono_info 390c9b443d4STobin Davis 39182f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol, 392c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 393c9b443d4STobin Davis { 394c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 395c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 396c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 397c9b443d4STobin Davis if (invert) 398c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 399c9b443d4STobin Davis else 400c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 401c9b443d4STobin Davis return 0; 40282f30040STobin Davis 403c9b443d4STobin Davis } 404c9b443d4STobin Davis 40582f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol, 406c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 407c9b443d4STobin Davis { 408c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 409c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 410c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 411c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 412c9b443d4STobin Davis unsigned int eapd; 41382f30040STobin Davis 41468ea7b2fSTakashi Iwai eapd = !!ucontrol->value.integer.value[0]; 415c9b443d4STobin Davis if (invert) 416c9b443d4STobin Davis eapd = !eapd; 41782beb8fdSTakashi Iwai if (eapd == spec->cur_eapd) 418c9b443d4STobin Davis return 0; 41982f30040STobin Davis 420c9b443d4STobin Davis spec->cur_eapd = eapd; 42182beb8fdSTakashi Iwai snd_hda_codec_write_cache(codec, nid, 422c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 423c9b443d4STobin Davis eapd ? 0x02 : 0x00); 424c9b443d4STobin Davis return 1; 425c9b443d4STobin Davis } 426c9b443d4STobin Davis 42786d72bdfSTakashi Iwai /* controls for test mode */ 42886d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 42986d72bdfSTakashi Iwai 43082f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \ 43182f30040STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 43282f30040STobin Davis .info = cxt_eapd_info, \ 43382f30040STobin Davis .get = cxt_eapd_get, \ 43482f30040STobin Davis .put = cxt_eapd_put, \ 43582f30040STobin Davis .private_value = nid | (mask<<16) } 43682f30040STobin Davis 43782f30040STobin Davis 43882f30040STobin Davis 439c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 440c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 441c9b443d4STobin Davis { 442c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 443c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 444c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 445c9b443d4STobin Davis spec->num_channel_mode); 446c9b443d4STobin Davis } 447c9b443d4STobin Davis 448c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 449c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 450c9b443d4STobin Davis { 451c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 452c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 453c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 454c9b443d4STobin Davis spec->num_channel_mode, 455c9b443d4STobin Davis spec->multiout.max_channels); 456c9b443d4STobin Davis } 457c9b443d4STobin Davis 458c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 459c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 460c9b443d4STobin Davis { 461c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 462c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 463c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 464c9b443d4STobin Davis spec->num_channel_mode, 465c9b443d4STobin Davis &spec->multiout.max_channels); 466c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 467c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 468c9b443d4STobin Davis return err; 469c9b443d4STobin Davis } 470c9b443d4STobin Davis 471c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 472c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 473c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 474c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 475c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 476c9b443d4STobin Davis .private_value = nid | (dir<<16) } 477c9b443d4STobin Davis 47886d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 47986d72bdfSTakashi Iwai 480c9b443d4STobin Davis /* Conexant 5045 specific */ 481c9b443d4STobin Davis 482c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 483c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 484c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 485cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT 0x18 486c9b443d4STobin Davis 4875cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 4885cd57529STobin Davis { 2, NULL }, 4895cd57529STobin Davis }; 490c9b443d4STobin Davis 491c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 492c9b443d4STobin Davis .num_items = 2, 493c9b443d4STobin Davis .items = { 49482f30040STobin Davis { "IntMic", 0x1 }, 495f4beee94SJiang zhe { "ExtMic", 0x2 }, 496c9b443d4STobin Davis } 497c9b443d4STobin Davis }; 498c9b443d4STobin Davis 4995218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = { 5005218c892SJiang Zhe .num_items = 3, 5015218c892SJiang Zhe .items = { 5025218c892SJiang Zhe { "IntMic", 0x1 }, 5035218c892SJiang Zhe { "ExtMic", 0x2 }, 5045218c892SJiang Zhe { "LineIn", 0x3 }, 5055218c892SJiang Zhe } 5065218c892SJiang Zhe }; 5075218c892SJiang Zhe 5082de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = { 5092de3c232SJiang zhe .num_items = 2, 5102de3c232SJiang zhe .items = { 5112de3c232SJiang zhe { "ExtMic", 0x1 }, 5122de3c232SJiang zhe { "IntMic", 0x2 }, 5132de3c232SJiang zhe } 5142de3c232SJiang zhe }; 5152de3c232SJiang zhe 516c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 517c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 518c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 519c9b443d4STobin Davis { 520c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 521c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 52282f30040STobin Davis unsigned int bits; 523c9b443d4STobin Davis 52482f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 525c9b443d4STobin Davis return 0; 526c9b443d4STobin Davis 52782f30040STobin Davis /* toggle internal speakers mute depending of presence of 52882f30040STobin Davis * the headphone jack 52982f30040STobin Davis */ 53047fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 53147fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 53247fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 5337f29673bSTobin Davis 53447fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 53547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0, 53647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 537c9b443d4STobin Davis return 1; 538c9b443d4STobin Davis } 539c9b443d4STobin Davis 540c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 541cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = { 542cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 543cca3b371STakashi Iwai .values = { 544cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT), 545cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 546cca3b371STakashi Iwai 0 547cca3b371STakashi Iwai }, 548cca3b371STakashi Iwai }; 549c9b443d4STobin Davis 5507f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */ 5517f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec) 5527f29673bSTobin Davis { 5537f29673bSTobin Davis static struct hda_verb mic_jack_on[] = { 5547f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 5557f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 5567f29673bSTobin Davis {} 5577f29673bSTobin Davis }; 5587f29673bSTobin Davis static struct hda_verb mic_jack_off[] = { 5597f29673bSTobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 5607f29673bSTobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 5617f29673bSTobin Davis {} 5627f29673bSTobin Davis }; 5637f29673bSTobin Davis unsigned int present; 5647f29673bSTobin Davis 5657f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x12, 0, 5667f29673bSTobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 5677f29673bSTobin Davis if (present) 5687f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_on); 5697f29673bSTobin Davis else 5707f29673bSTobin Davis snd_hda_sequence_write(codec, mic_jack_off); 5717f29673bSTobin Davis } 5727f29673bSTobin Davis 573c9b443d4STobin Davis 574c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 575c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 576c9b443d4STobin Davis { 57782f30040STobin Davis struct conexant_spec *spec = codec->spec; 578dd87da1cSTobin Davis unsigned int bits; 579c9b443d4STobin Davis 58082f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x11, 0, 581c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 582dd87da1cSTobin Davis 58347fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 58447fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0, 58547fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 586c9b443d4STobin Davis } 587c9b443d4STobin Davis 588c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 589c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 590c9b443d4STobin Davis unsigned int res) 591c9b443d4STobin Davis { 592c9b443d4STobin Davis res >>= 26; 593c9b443d4STobin Davis switch (res) { 594c9b443d4STobin Davis case CONEXANT_HP_EVENT: 595c9b443d4STobin Davis cxt5045_hp_automute(codec); 596c9b443d4STobin Davis break; 5977f29673bSTobin Davis case CONEXANT_MIC_EVENT: 5987f29673bSTobin Davis cxt5045_hp_automic(codec); 5997f29673bSTobin Davis break; 6007f29673bSTobin Davis 601c9b443d4STobin Davis } 602c9b443d4STobin Davis } 603c9b443d4STobin Davis 604c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 605c9b443d4STobin Davis { 606c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 607c9b443d4STobin Davis .name = "Capture Source", 608c9b443d4STobin Davis .info = conexant_mux_enum_info, 609c9b443d4STobin Davis .get = conexant_mux_enum_get, 610c9b443d4STobin Davis .put = conexant_mux_enum_put 611c9b443d4STobin Davis }, 612c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 613c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 614c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 615c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 616c8229c38STakashi Iwai HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 617c8229c38STakashi Iwai HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 618c8229c38STakashi Iwai HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 619c8229c38STakashi Iwai HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 620c8229c38STakashi Iwai HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 621c8229c38STakashi Iwai HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 622cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 623c9b443d4STobin Davis { 624c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 625c9b443d4STobin Davis .name = "Master Playback Switch", 62682f30040STobin Davis .info = cxt_eapd_info, 62782f30040STobin Davis .get = cxt_eapd_get, 628c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 62982f30040STobin Davis .private_value = 0x10, 630c9b443d4STobin Davis }, 631c9b443d4STobin Davis 632c9b443d4STobin Davis {} 633c9b443d4STobin Davis }; 634c9b443d4STobin Davis 6355218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = { 6365218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT), 6375218c892SJiang Zhe HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT), 6385218c892SJiang Zhe HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT), 6395218c892SJiang Zhe HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT), 6405218c892SJiang Zhe 6415218c892SJiang Zhe {} 6425218c892SJiang Zhe }; 6435218c892SJiang Zhe 6442de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 6452de3c232SJiang zhe { 6462de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 6472de3c232SJiang zhe .name = "Capture Source", 6482de3c232SJiang zhe .info = conexant_mux_enum_info, 6492de3c232SJiang zhe .get = conexant_mux_enum_get, 6502de3c232SJiang zhe .put = conexant_mux_enum_put 6512de3c232SJiang zhe }, 6522de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 6532de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 6542de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 6552de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 6562de3c232SJiang zhe HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT), 6572de3c232SJiang zhe HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT), 6582de3c232SJiang zhe HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT), 6592de3c232SJiang zhe HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT), 6602de3c232SJiang zhe HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT), 6612de3c232SJiang zhe HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT), 6622de3c232SJiang zhe HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol), 6632de3c232SJiang zhe { 6642de3c232SJiang zhe .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 6652de3c232SJiang zhe .name = "Master Playback Switch", 6662de3c232SJiang zhe .info = cxt_eapd_info, 6672de3c232SJiang zhe .get = cxt_eapd_get, 6682de3c232SJiang zhe .put = cxt5045_hp_master_sw_put, 6692de3c232SJiang zhe .private_value = 0x10, 6702de3c232SJiang zhe }, 6712de3c232SJiang zhe 6722de3c232SJiang zhe {} 6732de3c232SJiang zhe }; 6742de3c232SJiang zhe 675c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 676c9b443d4STobin Davis /* Line in, Mic */ 6774090dffbSTakashi Iwai {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 6787f29673bSTobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 679c9b443d4STobin Davis /* HP, Amp */ 680c8229c38STakashi Iwai {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 681c8229c38STakashi Iwai {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 68282f30040STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 683c8229c38STakashi Iwai {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 684c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 685c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 686c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 687c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 688c8229c38STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 68982f30040STobin Davis /* Record selector: Int mic */ 6907f29673bSTobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL,0x1}, 69182f30040STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 692c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 693c9b443d4STobin Davis /* SPDIF route: PCM */ 694cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 695c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 696c9b443d4STobin Davis /* EAPD */ 69782f30040STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */ 698c9b443d4STobin Davis { } /* end */ 699c9b443d4STobin Davis }; 700c9b443d4STobin Davis 7015218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = { 7025218c892SJiang Zhe /* Int Mic, Mic */ 7035218c892SJiang Zhe {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 7045218c892SJiang Zhe {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 }, 7055218c892SJiang Zhe /* Line In,HP, Amp */ 7065218c892SJiang Zhe {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7075218c892SJiang Zhe {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, 7085218c892SJiang Zhe {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 7095218c892SJiang Zhe {0x11, AC_VERB_SET_CONNECT_SEL, 0x1}, 7105218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 7115218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 7125218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, 7135218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, 7145218c892SJiang Zhe {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 7155218c892SJiang Zhe /* Record selector: Int mic */ 7165218c892SJiang Zhe {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1}, 7175218c892SJiang Zhe {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 7185218c892SJiang Zhe AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 7195218c892SJiang Zhe /* SPDIF route: PCM */ 720cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 7215218c892SJiang Zhe {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 7225218c892SJiang Zhe /* EAPD */ 7235218c892SJiang Zhe {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 7245218c892SJiang Zhe { } /* end */ 7255218c892SJiang Zhe }; 7267f29673bSTobin Davis 7277f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = { 7287f29673bSTobin Davis /* pin sensing on HP jack */ 7297f29673bSTobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 730d3091fadSTakashi Iwai { } /* end */ 7317f29673bSTobin Davis }; 7327f29673bSTobin Davis 7337f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = { 7347f29673bSTobin Davis /* pin sensing on HP jack */ 7357f29673bSTobin Davis {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 736d3091fadSTakashi Iwai { } /* end */ 7377f29673bSTobin Davis }; 7387f29673bSTobin Davis 739c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 740c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 741c9b443d4STobin Davis * configuration. 742c9b443d4STobin Davis */ 743c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 744c9b443d4STobin Davis .num_items = 5, 745c9b443d4STobin Davis .items = { 746c9b443d4STobin Davis { "MIXER", 0x0 }, 747c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 748c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 749c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 750c9b443d4STobin Davis { "CD pin", 0x4 }, 751c9b443d4STobin Davis }, 752c9b443d4STobin Davis }; 753c9b443d4STobin Davis 754c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 755c9b443d4STobin Davis 756c9b443d4STobin Davis /* Output controls */ 757c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 758c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 7597f29673bSTobin Davis HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT), 7607f29673bSTobin Davis HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT), 7617f29673bSTobin Davis HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT), 7627f29673bSTobin Davis HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT), 763c9b443d4STobin Davis 764c9b443d4STobin Davis /* Modes for retasking pin widgets */ 765c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 766c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 767c9b443d4STobin Davis 76882f30040STobin Davis /* EAPD Switch Control */ 76982f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0), 77082f30040STobin Davis 771c9b443d4STobin Davis /* Loopback mixer controls */ 772c9b443d4STobin Davis 7737f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT), 7747f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT), 7757f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT), 7767f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT), 7777f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT), 7787f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT), 7797f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT), 7807f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT), 7817f29673bSTobin Davis HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT), 7827f29673bSTobin Davis HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT), 783c9b443d4STobin Davis { 784c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 785c9b443d4STobin Davis .name = "Input Source", 786c9b443d4STobin Davis .info = conexant_mux_enum_info, 787c9b443d4STobin Davis .get = conexant_mux_enum_get, 788c9b443d4STobin Davis .put = conexant_mux_enum_put, 789c9b443d4STobin Davis }, 790fb3409e7STobin Davis /* Audio input controls */ 791fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 792fb3409e7STobin Davis HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 793fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 794fb3409e7STobin Davis HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 795fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 796fb3409e7STobin Davis HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 797fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 798fb3409e7STobin Davis HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 799fb3409e7STobin Davis HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 800fb3409e7STobin Davis HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 801c9b443d4STobin Davis { } /* end */ 802c9b443d4STobin Davis }; 803c9b443d4STobin Davis 804c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 8057f29673bSTobin Davis /* Set connections */ 8067f29673bSTobin Davis { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 }, 8077f29673bSTobin Davis { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 }, 8087f29673bSTobin Davis { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 }, 809c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 810c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 8117f29673bSTobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 812c9b443d4STobin Davis 813c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 814c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 815c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 816c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 817c9b443d4STobin Davis * control. 818c9b443d4STobin Davis */ 819cbef9789STakashi Iwai {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 820cbef9789STakashi Iwai {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 821c9b443d4STobin Davis 822c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 823c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 824c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 825c9b443d4STobin Davis 826c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 827c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 828c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 829c9b443d4STobin Davis * input/output buffers as needed. 830c9b443d4STobin Davis */ 831c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 832c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 833c9b443d4STobin Davis 834c9b443d4STobin Davis /* Mute capture amp left and right */ 835c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 836c9b443d4STobin Davis 837c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 838c9b443d4STobin Davis * pin) 839c9b443d4STobin Davis */ 840c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 8417f29673bSTobin Davis {0x17, AC_VERB_SET_CONNECT_SEL, 0x00}, 842c9b443d4STobin Davis 843c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 844c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 845c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 846c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 847c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 848c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 849c9b443d4STobin Davis 850c9b443d4STobin Davis { } 851c9b443d4STobin Davis }; 852c9b443d4STobin Davis #endif 853c9b443d4STobin Davis 854c9b443d4STobin Davis 855c9b443d4STobin Davis /* initialize jack-sensing, too */ 856c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 857c9b443d4STobin Davis { 858c9b443d4STobin Davis conexant_init(codec); 859c9b443d4STobin Davis cxt5045_hp_automute(codec); 860c9b443d4STobin Davis return 0; 861c9b443d4STobin Davis } 862c9b443d4STobin Davis 863c9b443d4STobin Davis 864c9b443d4STobin Davis enum { 86515908c36SMarc Boucher CXT5045_LAPTOP_HPSENSE, 86615908c36SMarc Boucher CXT5045_LAPTOP_MICSENSE, 86715908c36SMarc Boucher CXT5045_LAPTOP_HPMICSENSE, 8685218c892SJiang Zhe CXT5045_BENQ, 8692de3c232SJiang zhe CXT5045_LAPTOP_HP530, 870c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 871c9b443d4STobin Davis CXT5045_TEST, 872c9b443d4STobin Davis #endif 873f5fcc13cSTakashi Iwai CXT5045_MODELS 874c9b443d4STobin Davis }; 875c9b443d4STobin Davis 876f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 87715908c36SMarc Boucher [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense", 87815908c36SMarc Boucher [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 87915908c36SMarc Boucher [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 8805218c892SJiang Zhe [CXT5045_BENQ] = "benq", 8812de3c232SJiang zhe [CXT5045_LAPTOP_HP530] = "laptop-hp530", 882c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 883f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 884c9b443d4STobin Davis #endif 885f5fcc13cSTakashi Iwai }; 886c9b443d4STobin Davis 887f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 88815908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE), 88915908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE), 89015908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE), 89115908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE), 89215908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), 89315908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), 8940f6a5156STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), 8952de3c232SJiang zhe SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 89615908c36SMarc Boucher SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), 8976a9dccd6STakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 8985218c892SJiang Zhe SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 89915908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 90015908c36SMarc Boucher SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE), 9019e464154STakashi Iwai SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", 9029e464154STakashi Iwai CXT5045_LAPTOP_HPMICSENSE), 90315908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 90415908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 90515908c36SMarc Boucher SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 90615908c36SMarc Boucher SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), 90715908c36SMarc Boucher SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), 90815908c36SMarc Boucher SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 909c9b443d4STobin Davis {} 910c9b443d4STobin Davis }; 911c9b443d4STobin Davis 912c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 913c9b443d4STobin Davis { 914c9b443d4STobin Davis struct conexant_spec *spec; 915c9b443d4STobin Davis int board_config; 916c9b443d4STobin Davis 917c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 918c9b443d4STobin Davis if (!spec) 919c9b443d4STobin Davis return -ENOMEM; 920c9b443d4STobin Davis codec->spec = spec; 921c9b443d4STobin Davis 922c9b443d4STobin Davis spec->multiout.max_channels = 2; 923c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 924c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 925c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 926c9b443d4STobin Davis spec->num_adc_nids = 1; 927c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 928c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 929c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 930c9b443d4STobin Davis spec->num_mixers = 1; 931c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 932c9b443d4STobin Davis spec->num_init_verbs = 1; 933c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 934c9b443d4STobin Davis spec->spdif_route = 0; 9355cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), 9365cd57529STobin Davis spec->channel_mode = cxt5045_modes, 9375cd57529STobin Davis 938c9b443d4STobin Davis 939c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 940c9b443d4STobin Davis 941f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 942f5fcc13cSTakashi Iwai cxt5045_models, 943f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 944c9b443d4STobin Davis switch (board_config) { 94515908c36SMarc Boucher case CXT5045_LAPTOP_HPSENSE: 9467f29673bSTobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 947c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 948c9b443d4STobin Davis spec->num_init_verbs = 2; 9497f29673bSTobin Davis spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 9507f29673bSTobin Davis spec->mixers[0] = cxt5045_mixers; 9517f29673bSTobin Davis codec->patch_ops.init = cxt5045_init; 9527f29673bSTobin Davis break; 95315908c36SMarc Boucher case CXT5045_LAPTOP_MICSENSE: 95486376df6STakashi Iwai codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 9557f29673bSTobin Davis spec->input_mux = &cxt5045_capture_source; 9567f29673bSTobin Davis spec->num_init_verbs = 2; 9577f29673bSTobin Davis spec->init_verbs[1] = cxt5045_mic_sense_init_verbs; 958c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 959c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 960c9b443d4STobin Davis break; 96115908c36SMarc Boucher default: 96215908c36SMarc Boucher case CXT5045_LAPTOP_HPMICSENSE: 96315908c36SMarc Boucher codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 96415908c36SMarc Boucher spec->input_mux = &cxt5045_capture_source; 96515908c36SMarc Boucher spec->num_init_verbs = 3; 96615908c36SMarc Boucher spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 96715908c36SMarc Boucher spec->init_verbs[2] = cxt5045_mic_sense_init_verbs; 96815908c36SMarc Boucher spec->mixers[0] = cxt5045_mixers; 96915908c36SMarc Boucher codec->patch_ops.init = cxt5045_init; 97015908c36SMarc Boucher break; 9715218c892SJiang Zhe case CXT5045_BENQ: 9725218c892SJiang Zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 9735218c892SJiang Zhe spec->input_mux = &cxt5045_capture_source_benq; 9745218c892SJiang Zhe spec->num_init_verbs = 1; 9755218c892SJiang Zhe spec->init_verbs[0] = cxt5045_benq_init_verbs; 9765218c892SJiang Zhe spec->mixers[0] = cxt5045_mixers; 9775218c892SJiang Zhe spec->mixers[1] = cxt5045_benq_mixers; 9785218c892SJiang Zhe spec->num_mixers = 2; 9795218c892SJiang Zhe codec->patch_ops.init = cxt5045_init; 9805218c892SJiang Zhe break; 9812de3c232SJiang zhe case CXT5045_LAPTOP_HP530: 9822de3c232SJiang zhe codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 9832de3c232SJiang zhe spec->input_mux = &cxt5045_capture_source_hp530; 9842de3c232SJiang zhe spec->num_init_verbs = 2; 9852de3c232SJiang zhe spec->init_verbs[1] = cxt5045_hp_sense_init_verbs; 9862de3c232SJiang zhe spec->mixers[0] = cxt5045_mixers_hp530; 9872de3c232SJiang zhe codec->patch_ops.init = cxt5045_init; 9882de3c232SJiang zhe break; 989c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 990c9b443d4STobin Davis case CXT5045_TEST: 991c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 992c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 993c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 99415908c36SMarc Boucher break; 99515908c36SMarc Boucher 996c9b443d4STobin Davis #endif 997c9b443d4STobin Davis } 99848ecb7e8STakashi Iwai 999031005f7STakashi Iwai switch (codec->subsystem_id >> 16) { 1000031005f7STakashi Iwai case 0x103c: 1001031005f7STakashi Iwai /* HP laptop has a really bad sound over 0dB on NID 0x17. 100248ecb7e8STakashi Iwai * Fix max PCM level to 0 dB 100348ecb7e8STakashi Iwai * (originall it has 0x2b steps with 0dB offset 0x14) 100448ecb7e8STakashi Iwai */ 100548ecb7e8STakashi Iwai snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, 100648ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_OFFSET_SHIFT) | 100748ecb7e8STakashi Iwai (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) | 100848ecb7e8STakashi Iwai (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | 100948ecb7e8STakashi Iwai (1 << AC_AMPCAP_MUTE_SHIFT)); 1010031005f7STakashi Iwai break; 1011031005f7STakashi Iwai } 101248ecb7e8STakashi Iwai 1013c9b443d4STobin Davis return 0; 1014c9b443d4STobin Davis } 1015c9b443d4STobin Davis 1016c9b443d4STobin Davis 1017c9b443d4STobin Davis /* Conexant 5047 specific */ 101882f30040STobin Davis #define CXT5047_SPDIF_OUT 0x11 1019c9b443d4STobin Davis 102082f30040STobin Davis static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; 1021c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1022c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1023c9b443d4STobin Davis 10245cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 10255cd57529STobin Davis { 2, NULL }, 10265cd57529STobin Davis }; 1027c9b443d4STobin Davis 1028c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = { 10297f29673bSTobin Davis .num_items = 1, 1030c9b443d4STobin Davis .items = { 10317f29673bSTobin Davis { "Mic", 0x2 }, 1032c9b443d4STobin Davis } 1033c9b443d4STobin Davis }; 1034c9b443d4STobin Davis 1035c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = { 1036c9b443d4STobin Davis .num_items = 1, 1037c9b443d4STobin Davis .items = { 103882f30040STobin Davis { "ExtMic", 0x2 }, 103982f30040STobin Davis } 104082f30040STobin Davis }; 104182f30040STobin Davis 104282f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = { 104382f30040STobin Davis .num_items = 2, 104482f30040STobin Davis .items = { 104582f30040STobin Davis { "ExtMic", 0x2 }, 104682f30040STobin Davis { "Line-In", 0x1 }, 1047c9b443d4STobin Davis } 1048c9b443d4STobin Davis }; 1049c9b443d4STobin Davis 1050c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 1051c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1052c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 1053c9b443d4STobin Davis { 1054c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1055c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 105682f30040STobin Davis unsigned int bits; 1057c9b443d4STobin Davis 105882f30040STobin Davis if (!cxt_eapd_put(kcontrol, ucontrol)) 1059c9b443d4STobin Davis return 0; 1060c9b443d4STobin Davis 106182f30040STobin Davis /* toggle internal speakers mute depending of presence of 106282f30040STobin Davis * the headphone jack 106382f30040STobin Davis */ 106447fd830aSTakashi Iwai bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 106547fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 106647fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 106747fd830aSTakashi Iwai bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 106847fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 106947fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1070c9b443d4STobin Davis return 1; 1071c9b443d4STobin Davis } 1072c9b443d4STobin Davis 107382f30040STobin Davis /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */ 1074cca3b371STakashi Iwai static struct hda_bind_ctls cxt5047_bind_master_vol = { 1075cca3b371STakashi Iwai .ops = &snd_hda_bind_vol, 1076cca3b371STakashi Iwai .values = { 1077cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT), 1078cca3b371STakashi Iwai HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT), 1079cca3b371STakashi Iwai 0 1080cca3b371STakashi Iwai }, 1081cca3b371STakashi Iwai }; 1082c9b443d4STobin Davis 1083c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 1084c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 1085c9b443d4STobin Davis { 108682f30040STobin Davis struct conexant_spec *spec = codec->spec; 1087dd87da1cSTobin Davis unsigned int bits; 1088c9b443d4STobin Davis 108982f30040STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1090c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1091dd87da1cSTobin Davis 109247fd830aSTakashi Iwai bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 109347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 109447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 109582f30040STobin Davis /* Mute/Unmute PCM 2 for good measure - some systems need this */ 109647fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, 109747fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1098c9b443d4STobin Davis } 1099c9b443d4STobin Davis 1100fb3409e7STobin Davis /* mute internal speaker if HP is plugged */ 1101fb3409e7STobin Davis static void cxt5047_hp2_automute(struct hda_codec *codec) 1102fb3409e7STobin Davis { 1103fb3409e7STobin Davis struct conexant_spec *spec = codec->spec; 1104fb3409e7STobin Davis unsigned int bits; 1105fb3409e7STobin Davis 1106fb3409e7STobin Davis spec->hp_present = snd_hda_codec_read(codec, 0x13, 0, 1107fb3409e7STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1108fb3409e7STobin Davis 110947fd830aSTakashi Iwai bits = spec->hp_present ? HDA_AMP_MUTE : 0; 111047fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 111147fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1112fb3409e7STobin Davis /* Mute/Unmute PCM 2 for good measure - some systems need this */ 111347fd830aSTakashi Iwai snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0, 111447fd830aSTakashi Iwai HDA_AMP_MUTE, bits); 1115fb3409e7STobin Davis } 1116fb3409e7STobin Davis 1117c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 1118c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 1119c9b443d4STobin Davis { 1120c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 11219f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11229f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1123c9b443d4STobin Davis {} 1124c9b443d4STobin Davis }; 1125c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 11269f113e0eSMarc Boucher {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11279f113e0eSMarc Boucher {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1128c9b443d4STobin Davis {} 1129c9b443d4STobin Davis }; 1130c9b443d4STobin Davis unsigned int present; 1131c9b443d4STobin Davis 11327f29673bSTobin Davis present = snd_hda_codec_read(codec, 0x15, 0, 1133c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1134c9b443d4STobin Davis if (present) 1135c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 1136c9b443d4STobin Davis else 1137c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 1138c9b443d4STobin Davis } 1139c9b443d4STobin Davis 1140c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 1141c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 1142c9b443d4STobin Davis unsigned int res) 1143c9b443d4STobin Davis { 11449f113e0eSMarc Boucher switch (res >> 26) { 1145c9b443d4STobin Davis case CONEXANT_HP_EVENT: 1146c9b443d4STobin Davis cxt5047_hp_automute(codec); 1147c9b443d4STobin Davis break; 1148c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 1149c9b443d4STobin Davis cxt5047_hp_automic(codec); 1150c9b443d4STobin Davis break; 1151c9b443d4STobin Davis } 1152c9b443d4STobin Davis } 1153c9b443d4STobin Davis 1154fb3409e7STobin Davis /* unsolicited event for HP jack sensing - non-EAPD systems */ 1155fb3409e7STobin Davis static void cxt5047_hp2_unsol_event(struct hda_codec *codec, 1156fb3409e7STobin Davis unsigned int res) 1157fb3409e7STobin Davis { 1158fb3409e7STobin Davis res >>= 26; 1159fb3409e7STobin Davis switch (res) { 1160fb3409e7STobin Davis case CONEXANT_HP_EVENT: 1161fb3409e7STobin Davis cxt5047_hp2_automute(codec); 1162fb3409e7STobin Davis break; 1163fb3409e7STobin Davis case CONEXANT_MIC_EVENT: 1164fb3409e7STobin Davis cxt5047_hp_automic(codec); 1165fb3409e7STobin Davis break; 1166fb3409e7STobin Davis } 1167fb3409e7STobin Davis } 1168fb3409e7STobin Davis 1169c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = { 1170c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1171c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), 11727f29673bSTobin Davis HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT), 11737f29673bSTobin Davis HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT), 1174c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1175c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1176c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1177c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 117882f30040STobin Davis HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT), 117982f30040STobin Davis HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT), 1180b7589cebSTobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT), 1181b7589cebSTobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT), 1182b7589cebSTobin Davis HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1183b7589cebSTobin Davis HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT), 118482f30040STobin Davis 118582f30040STobin Davis {} 118682f30040STobin Davis }; 118782f30040STobin Davis 118882f30040STobin Davis static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = { 118982f30040STobin Davis { 119082f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 119182f30040STobin Davis .name = "Capture Source", 119282f30040STobin Davis .info = conexant_mux_enum_info, 119382f30040STobin Davis .get = conexant_mux_enum_get, 119482f30040STobin Davis .put = conexant_mux_enum_put 119582f30040STobin Davis }, 119682f30040STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 119782f30040STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), 119882f30040STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 119982f30040STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 120082f30040STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 120182f30040STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1202cca3b371STakashi Iwai HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol), 120382f30040STobin Davis { 120482f30040STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 120582f30040STobin Davis .name = "Master Playback Switch", 120682f30040STobin Davis .info = cxt_eapd_info, 120782f30040STobin Davis .get = cxt_eapd_get, 1208c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1209c9b443d4STobin Davis .private_value = 0x13, 1210c9b443d4STobin Davis }, 1211c9b443d4STobin Davis 1212c9b443d4STobin Davis {} 1213c9b443d4STobin Davis }; 1214c9b443d4STobin Davis 1215c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = { 1216c9b443d4STobin Davis { 1217c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1218c9b443d4STobin Davis .name = "Capture Source", 1219c9b443d4STobin Davis .info = conexant_mux_enum_info, 1220c9b443d4STobin Davis .get = conexant_mux_enum_get, 1221c9b443d4STobin Davis .put = conexant_mux_enum_put 1222c9b443d4STobin Davis }, 1223c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1224c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), 1225c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1226c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1227c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1228c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1229c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1230c9b443d4STobin Davis { 1231c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1232c9b443d4STobin Davis .name = "Master Playback Switch", 123382f30040STobin Davis .info = cxt_eapd_info, 123482f30040STobin Davis .get = cxt_eapd_get, 1235c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1236c9b443d4STobin Davis .private_value = 0x13, 1237c9b443d4STobin Davis }, 1238c9b443d4STobin Davis { } /* end */ 1239c9b443d4STobin Davis }; 1240c9b443d4STobin Davis 1241c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1242c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1243c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1244c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1245c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 12467f29673bSTobin Davis /* HP, Speaker */ 1247b7589cebSTobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 1248b7589cebSTobin Davis {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, 12497f29673bSTobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, 12507f29673bSTobin Davis /* Record selector: Mic */ 12517f29673bSTobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 12527f29673bSTobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 12537f29673bSTobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 12547f29673bSTobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x02}, 1255c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1256c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1257c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1258c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1259c9b443d4STobin Davis /* SPDIF route: PCM */ 1260c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 126182f30040STobin Davis /* Enable unsolicited events */ 126282f30040STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 126382f30040STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1264c9b443d4STobin Davis { } /* end */ 1265c9b443d4STobin Davis }; 1266c9b443d4STobin Davis 1267c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1268c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 1269c9b443d4STobin Davis {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ 1270c9b443d4STobin Davis /* pin sensing on HP and Mic jacks */ 1271c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1272c9b443d4STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 127382f30040STobin Davis /* Speaker routing */ 127482f30040STobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, 1275c9b443d4STobin Davis {} 1276c9b443d4STobin Davis }; 1277c9b443d4STobin Davis 1278c9b443d4STobin Davis /* configuration for HP Laptops */ 1279c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = { 128082f30040STobin Davis /* pin sensing on HP jack */ 1281c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1282b84f08d4STakashi Iwai /* 0x13 is actually shared by both HP and speaker; 1283b84f08d4STakashi Iwai * setting the connection to 0 (=0x19) makes the master volume control 1284b84f08d4STakashi Iwai * working mysteriouslly... 1285b84f08d4STakashi Iwai */ 1286b84f08d4STakashi Iwai {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, 128782f30040STobin Davis /* Record selector: Ext Mic */ 128882f30040STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 128982f30040STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 129082f30040STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 129182f30040STobin Davis /* Speaker routing */ 129282f30040STobin Davis {0x1d, AC_VERB_SET_CONNECT_SEL,0x1}, 1293c9b443d4STobin Davis {} 1294c9b443d4STobin Davis }; 1295c9b443d4STobin Davis 1296c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1297c9b443d4STobin Davis * configuration. 1298c9b443d4STobin Davis */ 1299c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1300c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 130182f30040STobin Davis .num_items = 4, 1302c9b443d4STobin Davis .items = { 130382f30040STobin Davis { "LINE1 pin", 0x0 }, 130482f30040STobin Davis { "MIC1 pin", 0x1 }, 130582f30040STobin Davis { "MIC2 pin", 0x2 }, 130682f30040STobin Davis { "CD pin", 0x3 }, 1307c9b443d4STobin Davis }, 1308c9b443d4STobin Davis }; 1309c9b443d4STobin Davis 1310c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1311c9b443d4STobin Davis 1312c9b443d4STobin Davis /* Output only controls */ 131382f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT), 131482f30040STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT), 131582f30040STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT), 131682f30040STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT), 1317c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1318c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1319c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1320c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 132182f30040STobin Davis HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT), 132282f30040STobin Davis HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT), 132382f30040STobin Davis HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT), 132482f30040STobin Davis HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT), 1325c9b443d4STobin Davis 1326c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1327c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1328c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1329c9b443d4STobin Davis 133082f30040STobin Davis /* EAPD Switch Control */ 133182f30040STobin Davis CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0), 133282f30040STobin Davis 1333c9b443d4STobin Davis /* Loopback mixer controls */ 133482f30040STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT), 133582f30040STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT), 133682f30040STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT), 133782f30040STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT), 133882f30040STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT), 133982f30040STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT), 134082f30040STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT), 134182f30040STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT), 1342c9b443d4STobin Davis 134382f30040STobin Davis HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT), 134482f30040STobin Davis HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT), 134582f30040STobin Davis HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT), 134682f30040STobin Davis HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT), 134782f30040STobin Davis HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT), 134882f30040STobin Davis HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT), 134982f30040STobin Davis HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT), 135082f30040STobin Davis HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT), 1351c9b443d4STobin Davis { 1352c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1353c9b443d4STobin Davis .name = "Input Source", 1354c9b443d4STobin Davis .info = conexant_mux_enum_info, 1355c9b443d4STobin Davis .get = conexant_mux_enum_get, 1356c9b443d4STobin Davis .put = conexant_mux_enum_put, 1357c9b443d4STobin Davis }, 13589f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT), 13599f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT), 13609f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT), 13619f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT), 13629f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT), 13639f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT), 13649f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT), 13659f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT), 13669f113e0eSMarc Boucher HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT), 13679f113e0eSMarc Boucher HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT), 13689f113e0eSMarc Boucher 1369c9b443d4STobin Davis { } /* end */ 1370c9b443d4STobin Davis }; 1371c9b443d4STobin Davis 1372c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1373c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1374c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1375c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1376c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1377c9b443d4STobin Davis 1378c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1379c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1380c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1381c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1382c9b443d4STobin Davis * control. 1383c9b443d4STobin Davis */ 1384c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1385c9b443d4STobin Davis 1386c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1387c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1388c9b443d4STobin Davis */ 1389c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1390c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1391c9b443d4STobin Davis 1392c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1393c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1394c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1395c9b443d4STobin Davis 1396c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1397c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1398c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1399c9b443d4STobin Davis * input/output buffers as needed. 1400c9b443d4STobin Davis */ 1401c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1402c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1403c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1404c9b443d4STobin Davis 1405c9b443d4STobin Davis /* Mute capture amp left and right */ 1406c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1407c9b443d4STobin Davis 1408c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1409c9b443d4STobin Davis * pin) 1410c9b443d4STobin Davis */ 1411c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1412c9b443d4STobin Davis 1413c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1414c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1415c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1416c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1417c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1418c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1419c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1420c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1421c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1422c9b443d4STobin Davis 1423c9b443d4STobin Davis { } 1424c9b443d4STobin Davis }; 1425c9b443d4STobin Davis #endif 1426c9b443d4STobin Davis 1427c9b443d4STobin Davis 1428c9b443d4STobin Davis /* initialize jack-sensing, too */ 1429c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1430c9b443d4STobin Davis { 1431c9b443d4STobin Davis conexant_init(codec); 1432c9b443d4STobin Davis cxt5047_hp_automute(codec); 1433c9b443d4STobin Davis return 0; 1434c9b443d4STobin Davis } 1435c9b443d4STobin Davis 1436c9b443d4STobin Davis 1437c9b443d4STobin Davis enum { 1438f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1439f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1440f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1441c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1442c9b443d4STobin Davis CXT5047_TEST, 1443c9b443d4STobin Davis #endif 1444f5fcc13cSTakashi Iwai CXT5047_MODELS 1445c9b443d4STobin Davis }; 1446c9b443d4STobin Davis 1447f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1448f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1449f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1450f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1451c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1452f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1453c9b443d4STobin Davis #endif 1454f5fcc13cSTakashi Iwai }; 1455c9b443d4STobin Davis 1456f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1457f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), 1458ac3e3741STakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1459f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), 146082f30040STobin Davis SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP), 1461f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1462c9b443d4STobin Davis {} 1463c9b443d4STobin Davis }; 1464c9b443d4STobin Davis 1465c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1466c9b443d4STobin Davis { 1467c9b443d4STobin Davis struct conexant_spec *spec; 1468c9b443d4STobin Davis int board_config; 1469c9b443d4STobin Davis 1470c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1471c9b443d4STobin Davis if (!spec) 1472c9b443d4STobin Davis return -ENOMEM; 1473c9b443d4STobin Davis codec->spec = spec; 1474c9b443d4STobin Davis 1475c9b443d4STobin Davis spec->multiout.max_channels = 2; 1476c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1477c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1478c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1479c9b443d4STobin Davis spec->num_adc_nids = 1; 1480c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1481c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1482c9b443d4STobin Davis spec->input_mux = &cxt5047_capture_source; 1483c9b443d4STobin Davis spec->num_mixers = 1; 1484c9b443d4STobin Davis spec->mixers[0] = cxt5047_mixers; 1485c9b443d4STobin Davis spec->num_init_verbs = 1; 1486c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1487c9b443d4STobin Davis spec->spdif_route = 0; 14885cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 14895cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1490c9b443d4STobin Davis 1491c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1492c9b443d4STobin Davis 1493f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1494f5fcc13cSTakashi Iwai cxt5047_models, 1495f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1496c9b443d4STobin Davis switch (board_config) { 1497c9b443d4STobin Davis case CXT5047_LAPTOP: 1498fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; 1499c9b443d4STobin Davis break; 1500c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1501c9b443d4STobin Davis spec->input_mux = &cxt5047_hp_capture_source; 1502c9b443d4STobin Davis spec->num_init_verbs = 2; 1503c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_hp_init_verbs; 1504c9b443d4STobin Davis spec->mixers[0] = cxt5047_hp_mixers; 1505fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1506c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1507c9b443d4STobin Davis break; 1508c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 150982f30040STobin Davis spec->input_mux = &cxt5047_toshiba_capture_source; 1510c9b443d4STobin Davis spec->num_init_verbs = 2; 1511c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 151282f30040STobin Davis spec->mixers[0] = cxt5047_toshiba_mixers; 1513fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1514c9b443d4STobin Davis break; 1515c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1516c9b443d4STobin Davis case CXT5047_TEST: 1517c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1518c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1519c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1520fb3409e7STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1521c9b443d4STobin Davis #endif 1522c9b443d4STobin Davis } 1523c9b443d4STobin Davis return 0; 1524c9b443d4STobin Davis } 1525c9b443d4STobin Davis 1526461e2c78STakashi Iwai /* Conexant 5051 specific */ 1527461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 }; 1528461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 }; 1529461e2c78STakashi Iwai #define CXT5051_SPDIF_OUT 0x1C 1530461e2c78STakashi Iwai #define CXT5051_PORTB_EVENT 0x38 1531461e2c78STakashi Iwai #define CXT5051_PORTC_EVENT 0x39 1532461e2c78STakashi Iwai 1533461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = { 1534461e2c78STakashi Iwai { 2, NULL }, 1535461e2c78STakashi Iwai }; 1536461e2c78STakashi Iwai 1537461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec) 1538461e2c78STakashi Iwai { 1539461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1540461e2c78STakashi Iwai unsigned int pinctl; 1541461e2c78STakashi Iwai pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0; 1542461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 1543461e2c78STakashi Iwai pinctl); 1544461e2c78STakashi Iwai } 1545461e2c78STakashi Iwai 1546461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */ 1547461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol, 1548461e2c78STakashi Iwai struct snd_ctl_elem_value *ucontrol) 1549461e2c78STakashi Iwai { 1550461e2c78STakashi Iwai struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1551461e2c78STakashi Iwai 1552461e2c78STakashi Iwai if (!cxt_eapd_put(kcontrol, ucontrol)) 1553461e2c78STakashi Iwai return 0; 1554461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1555461e2c78STakashi Iwai return 1; 1556461e2c78STakashi Iwai } 1557461e2c78STakashi Iwai 1558461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */ 1559461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec) 1560461e2c78STakashi Iwai { 1561461e2c78STakashi Iwai unsigned int present; 1562461e2c78STakashi Iwai 1563461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x17, 0, 1564461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1565461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1566461e2c78STakashi Iwai snd_hda_codec_write(codec, 0x14, 0, 1567461e2c78STakashi Iwai AC_VERB_SET_CONNECT_SEL, 1568461e2c78STakashi Iwai present ? 0x01 : 0x00); 1569461e2c78STakashi Iwai } 1570461e2c78STakashi Iwai 1571461e2c78STakashi Iwai /* switch the current ADC according to the jack state */ 1572461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec) 1573461e2c78STakashi Iwai { 1574461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1575461e2c78STakashi Iwai unsigned int present; 1576461e2c78STakashi Iwai hda_nid_t new_adc; 1577461e2c78STakashi Iwai 1578461e2c78STakashi Iwai present = snd_hda_codec_read(codec, 0x18, 0, 1579461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1580461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1581461e2c78STakashi Iwai if (present) 1582461e2c78STakashi Iwai spec->cur_adc_idx = 1; 1583461e2c78STakashi Iwai else 1584461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1585461e2c78STakashi Iwai new_adc = spec->adc_nids[spec->cur_adc_idx]; 1586461e2c78STakashi Iwai if (spec->cur_adc && spec->cur_adc != new_adc) { 1587461e2c78STakashi Iwai /* stream is running, let's swap the current ADC */ 1588888afa15STakashi Iwai snd_hda_codec_cleanup_stream(codec, spec->cur_adc); 1589461e2c78STakashi Iwai spec->cur_adc = new_adc; 1590461e2c78STakashi Iwai snd_hda_codec_setup_stream(codec, new_adc, 1591461e2c78STakashi Iwai spec->cur_adc_stream_tag, 0, 1592461e2c78STakashi Iwai spec->cur_adc_format); 1593461e2c78STakashi Iwai } 1594461e2c78STakashi Iwai } 1595461e2c78STakashi Iwai 1596461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */ 1597461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec) 1598461e2c78STakashi Iwai { 1599461e2c78STakashi Iwai struct conexant_spec *spec = codec->spec; 1600461e2c78STakashi Iwai 1601461e2c78STakashi Iwai spec->hp_present = snd_hda_codec_read(codec, 0x16, 0, 1602461e2c78STakashi Iwai AC_VERB_GET_PIN_SENSE, 0) & 1603461e2c78STakashi Iwai AC_PINSENSE_PRESENCE; 1604461e2c78STakashi Iwai cxt5051_update_speaker(codec); 1605461e2c78STakashi Iwai } 1606461e2c78STakashi Iwai 1607461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */ 1608461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1609461e2c78STakashi Iwai unsigned int res) 1610461e2c78STakashi Iwai { 1611461e2c78STakashi Iwai switch (res >> 26) { 1612461e2c78STakashi Iwai case CONEXANT_HP_EVENT: 1613461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1614461e2c78STakashi Iwai break; 1615461e2c78STakashi Iwai case CXT5051_PORTB_EVENT: 1616461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1617461e2c78STakashi Iwai break; 1618461e2c78STakashi Iwai case CXT5051_PORTC_EVENT: 1619461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1620461e2c78STakashi Iwai break; 1621461e2c78STakashi Iwai } 1622461e2c78STakashi Iwai } 1623461e2c78STakashi Iwai 1624461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = { 1625461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1626461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1627461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT), 1628461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT), 1629461e2c78STakashi Iwai HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT), 1630461e2c78STakashi Iwai HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT), 1631461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1632461e2c78STakashi Iwai { 1633461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1634461e2c78STakashi Iwai .name = "Master Playback Switch", 1635461e2c78STakashi Iwai .info = cxt_eapd_info, 1636461e2c78STakashi Iwai .get = cxt_eapd_get, 1637461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1638461e2c78STakashi Iwai .private_value = 0x1a, 1639461e2c78STakashi Iwai }, 1640461e2c78STakashi Iwai 1641461e2c78STakashi Iwai {} 1642461e2c78STakashi Iwai }; 1643461e2c78STakashi Iwai 1644461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = { 1645461e2c78STakashi Iwai HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT), 1646461e2c78STakashi Iwai HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT), 1647461e2c78STakashi Iwai HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT), 1648461e2c78STakashi Iwai HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT), 1649461e2c78STakashi Iwai HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT), 1650461e2c78STakashi Iwai { 1651461e2c78STakashi Iwai .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1652461e2c78STakashi Iwai .name = "Master Playback Switch", 1653461e2c78STakashi Iwai .info = cxt_eapd_info, 1654461e2c78STakashi Iwai .get = cxt_eapd_get, 1655461e2c78STakashi Iwai .put = cxt5051_hp_master_sw_put, 1656461e2c78STakashi Iwai .private_value = 0x1a, 1657461e2c78STakashi Iwai }, 1658461e2c78STakashi Iwai 1659461e2c78STakashi Iwai {} 1660461e2c78STakashi Iwai }; 1661461e2c78STakashi Iwai 1662461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = { 1663461e2c78STakashi Iwai /* Line in, Mic */ 1664461e2c78STakashi Iwai {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1665461e2c78STakashi Iwai {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1666461e2c78STakashi Iwai {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1667461e2c78STakashi Iwai {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1668461e2c78STakashi Iwai {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1669461e2c78STakashi Iwai {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1670461e2c78STakashi Iwai /* SPK */ 1671461e2c78STakashi Iwai {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1672461e2c78STakashi Iwai {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 1673461e2c78STakashi Iwai /* HP, Amp */ 1674461e2c78STakashi Iwai {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1675461e2c78STakashi Iwai {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, 1676461e2c78STakashi Iwai /* DAC1 */ 1677461e2c78STakashi Iwai {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1678461e2c78STakashi Iwai /* Record selector: Int mic */ 1679461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1680461e2c78STakashi Iwai {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44}, 1681461e2c78STakashi Iwai {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44}, 1682461e2c78STakashi Iwai /* SPDIF route: PCM */ 1683461e2c78STakashi Iwai {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0}, 1684461e2c78STakashi Iwai /* EAPD */ 1685461e2c78STakashi Iwai {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 1686461e2c78STakashi Iwai {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT}, 1687461e2c78STakashi Iwai {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT}, 1688461e2c78STakashi Iwai {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT}, 1689461e2c78STakashi Iwai { } /* end */ 1690461e2c78STakashi Iwai }; 1691461e2c78STakashi Iwai 1692461e2c78STakashi Iwai /* initialize jack-sensing, too */ 1693461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec) 1694461e2c78STakashi Iwai { 1695461e2c78STakashi Iwai conexant_init(codec); 1696461e2c78STakashi Iwai if (codec->patch_ops.unsol_event) { 1697461e2c78STakashi Iwai cxt5051_hp_automute(codec); 1698461e2c78STakashi Iwai cxt5051_portb_automic(codec); 1699461e2c78STakashi Iwai cxt5051_portc_automic(codec); 1700461e2c78STakashi Iwai } 1701461e2c78STakashi Iwai return 0; 1702461e2c78STakashi Iwai } 1703461e2c78STakashi Iwai 1704461e2c78STakashi Iwai 1705461e2c78STakashi Iwai enum { 1706461e2c78STakashi Iwai CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1707461e2c78STakashi Iwai CXT5051_HP, /* no docking */ 1708461e2c78STakashi Iwai CXT5051_MODELS 1709461e2c78STakashi Iwai }; 1710461e2c78STakashi Iwai 1711461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = { 1712461e2c78STakashi Iwai [CXT5051_LAPTOP] = "laptop", 1713461e2c78STakashi Iwai [CXT5051_HP] = "hp", 1714461e2c78STakashi Iwai }; 1715461e2c78STakashi Iwai 1716461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 1717461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1718461e2c78STakashi Iwai CXT5051_LAPTOP), 1719461e2c78STakashi Iwai SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1720461e2c78STakashi Iwai {} 1721461e2c78STakashi Iwai }; 1722461e2c78STakashi Iwai 1723461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec) 1724461e2c78STakashi Iwai { 1725461e2c78STakashi Iwai struct conexant_spec *spec; 1726461e2c78STakashi Iwai int board_config; 1727461e2c78STakashi Iwai 1728461e2c78STakashi Iwai spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1729461e2c78STakashi Iwai if (!spec) 1730461e2c78STakashi Iwai return -ENOMEM; 1731461e2c78STakashi Iwai codec->spec = spec; 1732461e2c78STakashi Iwai 1733461e2c78STakashi Iwai codec->patch_ops = conexant_patch_ops; 1734461e2c78STakashi Iwai codec->patch_ops.init = cxt5051_init; 1735461e2c78STakashi Iwai 1736461e2c78STakashi Iwai spec->multiout.max_channels = 2; 1737461e2c78STakashi Iwai spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids); 1738461e2c78STakashi Iwai spec->multiout.dac_nids = cxt5051_dac_nids; 1739461e2c78STakashi Iwai spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT; 1740461e2c78STakashi Iwai spec->num_adc_nids = 1; /* not 2; via auto-mic switch */ 1741461e2c78STakashi Iwai spec->adc_nids = cxt5051_adc_nids; 1742461e2c78STakashi Iwai spec->num_mixers = 1; 1743461e2c78STakashi Iwai spec->mixers[0] = cxt5051_mixers; 1744461e2c78STakashi Iwai spec->num_init_verbs = 1; 1745461e2c78STakashi Iwai spec->init_verbs[0] = cxt5051_init_verbs; 1746461e2c78STakashi Iwai spec->spdif_route = 0; 1747461e2c78STakashi Iwai spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes); 1748461e2c78STakashi Iwai spec->channel_mode = cxt5051_modes; 1749461e2c78STakashi Iwai spec->cur_adc = 0; 1750461e2c78STakashi Iwai spec->cur_adc_idx = 0; 1751461e2c78STakashi Iwai 1752461e2c78STakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1753461e2c78STakashi Iwai cxt5051_models, 1754461e2c78STakashi Iwai cxt5051_cfg_tbl); 1755461e2c78STakashi Iwai switch (board_config) { 1756461e2c78STakashi Iwai case CXT5051_HP: 1757461e2c78STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 1758461e2c78STakashi Iwai spec->mixers[0] = cxt5051_hp_mixers; 1759461e2c78STakashi Iwai break; 1760461e2c78STakashi Iwai default: 1761461e2c78STakashi Iwai case CXT5051_LAPTOP: 1762461e2c78STakashi Iwai codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 1763461e2c78STakashi Iwai break; 1764461e2c78STakashi Iwai } 1765461e2c78STakashi Iwai 1766461e2c78STakashi Iwai return 0; 1767461e2c78STakashi Iwai } 1768461e2c78STakashi Iwai 1769461e2c78STakashi Iwai 1770461e2c78STakashi Iwai /* 1771461e2c78STakashi Iwai */ 1772461e2c78STakashi Iwai 1773*1289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = { 177482f30040STobin Davis { .id = 0x14f15045, .name = "CX20549 (Venice)", 177582f30040STobin Davis .patch = patch_cxt5045 }, 177682f30040STobin Davis { .id = 0x14f15047, .name = "CX20551 (Waikiki)", 177782f30040STobin Davis .patch = patch_cxt5047 }, 1778461e2c78STakashi Iwai { .id = 0x14f15051, .name = "CX20561 (Hermosa)", 1779461e2c78STakashi Iwai .patch = patch_cxt5051 }, 1780c9b443d4STobin Davis {} /* terminator */ 1781c9b443d4STobin Davis }; 1782*1289e9e8STakashi Iwai 1783*1289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045"); 1784*1289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047"); 1785*1289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051"); 1786*1289e9e8STakashi Iwai 1787*1289e9e8STakashi Iwai MODULE_LICENSE("GPL"); 1788*1289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec"); 1789*1289e9e8STakashi Iwai 1790*1289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = { 1791*1289e9e8STakashi Iwai .preset = snd_hda_preset_conexant, 1792*1289e9e8STakashi Iwai .owner = THIS_MODULE, 1793*1289e9e8STakashi Iwai }; 1794*1289e9e8STakashi Iwai 1795*1289e9e8STakashi Iwai static int __init patch_conexant_init(void) 1796*1289e9e8STakashi Iwai { 1797*1289e9e8STakashi Iwai return snd_hda_add_codec_preset(&conexant_list); 1798*1289e9e8STakashi Iwai } 1799*1289e9e8STakashi Iwai 1800*1289e9e8STakashi Iwai static void __exit patch_conexant_exit(void) 1801*1289e9e8STakashi Iwai { 1802*1289e9e8STakashi Iwai snd_hda_delete_codec_preset(&conexant_list); 1803*1289e9e8STakashi Iwai } 1804*1289e9e8STakashi Iwai 1805*1289e9e8STakashi Iwai module_init(patch_conexant_init) 1806*1289e9e8STakashi Iwai module_exit(patch_conexant_exit) 1807