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 <sound/driver.h> 24c9b443d4STobin Davis #include <linux/init.h> 25c9b443d4STobin Davis #include <linux/delay.h> 26c9b443d4STobin Davis #include <linux/slab.h> 27c9b443d4STobin Davis #include <linux/pci.h> 28c9b443d4STobin Davis #include <sound/core.h> 29c9b443d4STobin Davis #include "hda_codec.h" 30c9b443d4STobin Davis #include "hda_local.h" 31c9b443d4STobin Davis 32c9b443d4STobin Davis #define CXT_PIN_DIR_IN 0x00 33c9b443d4STobin Davis #define CXT_PIN_DIR_OUT 0x01 34c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT 0x02 35c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS 0x03 36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04 37c9b443d4STobin Davis 38c9b443d4STobin Davis #define CONEXANT_HP_EVENT 0x37 39c9b443d4STobin Davis #define CONEXANT_MIC_EVENT 0x38 40c9b443d4STobin Davis 41c9b443d4STobin Davis 42c9b443d4STobin Davis 43c9b443d4STobin Davis struct conexant_spec { 44c9b443d4STobin Davis 45c9b443d4STobin Davis struct snd_kcontrol_new *mixers[5]; 46c9b443d4STobin Davis int num_mixers; 47c9b443d4STobin Davis 48c9b443d4STobin Davis const struct hda_verb *init_verbs[5]; /* initialization verbs 49c9b443d4STobin Davis * don't forget NULL 50c9b443d4STobin Davis * termination! 51c9b443d4STobin Davis */ 52c9b443d4STobin Davis unsigned int num_init_verbs; 53c9b443d4STobin Davis 54c9b443d4STobin Davis /* playback */ 55c9b443d4STobin Davis struct hda_multi_out multiout; /* playback set-up 56c9b443d4STobin Davis * max_channels, dacs must be set 57c9b443d4STobin Davis * dig_out_nid and hp_nid are optional 58c9b443d4STobin Davis */ 59c9b443d4STobin Davis unsigned int cur_eapd; 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 67c9b443d4STobin Davis /* capture source */ 68c9b443d4STobin Davis const struct hda_input_mux *input_mux; 69c9b443d4STobin Davis hda_nid_t *capsrc_nids; 70c9b443d4STobin Davis unsigned int cur_mux[3]; 71c9b443d4STobin Davis 72c9b443d4STobin Davis /* channel model */ 73c9b443d4STobin Davis const struct hda_channel_mode *channel_mode; 74c9b443d4STobin Davis int num_channel_mode; 75c9b443d4STobin Davis 76c9b443d4STobin Davis /* PCM information */ 77c9b443d4STobin Davis struct hda_pcm pcm_rec[2]; /* used in build_pcms() */ 78c9b443d4STobin Davis 79c9b443d4STobin Davis struct mutex amp_mutex; /* PCM volume/mute control mutex */ 80c9b443d4STobin Davis unsigned int spdif_route; 81c9b443d4STobin Davis 82c9b443d4STobin Davis /* dynamic controls, init_verbs and input_mux */ 83c9b443d4STobin Davis struct auto_pin_cfg autocfg; 84c9b443d4STobin Davis unsigned int num_kctl_alloc, num_kctl_used; 85c9b443d4STobin Davis struct snd_kcontrol_new *kctl_alloc; 86c9b443d4STobin Davis struct hda_input_mux private_imux; 87c9b443d4STobin Davis hda_nid_t private_dac_nids[4]; 88c9b443d4STobin Davis 89c9b443d4STobin Davis }; 90c9b443d4STobin Davis 91c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo, 92c9b443d4STobin Davis struct hda_codec *codec, 93c9b443d4STobin Davis struct snd_pcm_substream *substream) 94c9b443d4STobin Davis { 95c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 96c9b443d4STobin Davis return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 97c9b443d4STobin Davis } 98c9b443d4STobin Davis 99c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 100c9b443d4STobin Davis struct hda_codec *codec, 101c9b443d4STobin Davis unsigned int stream_tag, 102c9b443d4STobin Davis unsigned int format, 103c9b443d4STobin Davis struct snd_pcm_substream *substream) 104c9b443d4STobin Davis { 105c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 106c9b443d4STobin Davis return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, 107c9b443d4STobin Davis stream_tag, 108c9b443d4STobin Davis format, substream); 109c9b443d4STobin Davis } 110c9b443d4STobin Davis 111c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, 112c9b443d4STobin Davis struct hda_codec *codec, 113c9b443d4STobin Davis struct snd_pcm_substream *substream) 114c9b443d4STobin Davis { 115c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 116c9b443d4STobin Davis return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 117c9b443d4STobin Davis } 118c9b443d4STobin Davis 119c9b443d4STobin Davis /* 120c9b443d4STobin Davis * Digital out 121c9b443d4STobin Davis */ 122c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, 123c9b443d4STobin Davis struct hda_codec *codec, 124c9b443d4STobin Davis struct snd_pcm_substream *substream) 125c9b443d4STobin Davis { 126c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 127c9b443d4STobin Davis return snd_hda_multi_out_dig_open(codec, &spec->multiout); 128c9b443d4STobin Davis } 129c9b443d4STobin Davis 130c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 131c9b443d4STobin Davis struct hda_codec *codec, 132c9b443d4STobin Davis struct snd_pcm_substream *substream) 133c9b443d4STobin Davis { 134c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 135c9b443d4STobin Davis return snd_hda_multi_out_dig_close(codec, &spec->multiout); 136c9b443d4STobin Davis } 137c9b443d4STobin Davis 138c9b443d4STobin Davis /* 139c9b443d4STobin Davis * Analog capture 140c9b443d4STobin Davis */ 141c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo, 142c9b443d4STobin Davis struct hda_codec *codec, 143c9b443d4STobin Davis unsigned int stream_tag, 144c9b443d4STobin Davis unsigned int format, 145c9b443d4STobin Davis struct snd_pcm_substream *substream) 146c9b443d4STobin Davis { 147c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 148c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 149c9b443d4STobin Davis stream_tag, 0, format); 150c9b443d4STobin Davis return 0; 151c9b443d4STobin Davis } 152c9b443d4STobin Davis 153c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, 154c9b443d4STobin Davis struct hda_codec *codec, 155c9b443d4STobin Davis struct snd_pcm_substream *substream) 156c9b443d4STobin Davis { 157c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 158c9b443d4STobin Davis snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 159c9b443d4STobin Davis 0, 0, 0); 160c9b443d4STobin Davis return 0; 161c9b443d4STobin Davis } 162c9b443d4STobin Davis 163c9b443d4STobin Davis 164c9b443d4STobin Davis 165c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = { 166c9b443d4STobin Davis .substreams = 1, 167c9b443d4STobin Davis .channels_min = 2, 168c9b443d4STobin Davis .channels_max = 2, 169c9b443d4STobin Davis .nid = 0, /* fill later */ 170c9b443d4STobin Davis .ops = { 171c9b443d4STobin Davis .open = conexant_playback_pcm_open, 172c9b443d4STobin Davis .prepare = conexant_playback_pcm_prepare, 173c9b443d4STobin Davis .cleanup = conexant_playback_pcm_cleanup 174c9b443d4STobin Davis }, 175c9b443d4STobin Davis }; 176c9b443d4STobin Davis 177c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = { 178c9b443d4STobin Davis .substreams = 1, 179c9b443d4STobin Davis .channels_min = 2, 180c9b443d4STobin Davis .channels_max = 2, 181c9b443d4STobin Davis .nid = 0, /* fill later */ 182c9b443d4STobin Davis .ops = { 183c9b443d4STobin Davis .prepare = conexant_capture_pcm_prepare, 184c9b443d4STobin Davis .cleanup = conexant_capture_pcm_cleanup 185c9b443d4STobin Davis }, 186c9b443d4STobin Davis }; 187c9b443d4STobin Davis 188c9b443d4STobin Davis 189c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = { 190c9b443d4STobin Davis .substreams = 1, 191c9b443d4STobin Davis .channels_min = 2, 192c9b443d4STobin Davis .channels_max = 2, 193c9b443d4STobin Davis .nid = 0, /* fill later */ 194c9b443d4STobin Davis .ops = { 195c9b443d4STobin Davis .open = conexant_dig_playback_pcm_open, 196c9b443d4STobin Davis .close = conexant_dig_playback_pcm_close 197c9b443d4STobin Davis }, 198c9b443d4STobin Davis }; 199c9b443d4STobin Davis 200c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = { 201c9b443d4STobin Davis .substreams = 1, 202c9b443d4STobin Davis .channels_min = 2, 203c9b443d4STobin Davis .channels_max = 2, 204c9b443d4STobin Davis /* NID is set in alc_build_pcms */ 205c9b443d4STobin Davis }; 206c9b443d4STobin Davis 207c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec) 208c9b443d4STobin Davis { 209c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 210c9b443d4STobin Davis struct hda_pcm *info = spec->pcm_rec; 211c9b443d4STobin Davis 212c9b443d4STobin Davis codec->num_pcms = 1; 213c9b443d4STobin Davis codec->pcm_info = info; 214c9b443d4STobin Davis 215c9b443d4STobin Davis info->name = "CONEXANT Analog"; 216c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback; 217c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 218c9b443d4STobin Davis spec->multiout.max_channels; 219c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 220c9b443d4STobin Davis spec->multiout.dac_nids[0]; 221c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = conexant_pcm_analog_capture; 222c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; 223c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; 224c9b443d4STobin Davis 225c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 226c9b443d4STobin Davis info++; 227c9b443d4STobin Davis codec->num_pcms++; 228c9b443d4STobin Davis info->name = "Conexant Digital"; 229c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 230c9b443d4STobin Davis conexant_pcm_digital_playback; 231c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 232c9b443d4STobin Davis spec->multiout.dig_out_nid; 233c9b443d4STobin Davis if (spec->dig_in_nid) { 234c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE] = 235c9b443d4STobin Davis conexant_pcm_digital_capture; 236c9b443d4STobin Davis info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 237c9b443d4STobin Davis spec->dig_in_nid; 238c9b443d4STobin Davis } 239c9b443d4STobin Davis } 240c9b443d4STobin Davis 241c9b443d4STobin Davis return 0; 242c9b443d4STobin Davis } 243c9b443d4STobin Davis 244c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol, 245c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 246c9b443d4STobin Davis { 247c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 248c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 249c9b443d4STobin Davis 250c9b443d4STobin Davis return snd_hda_input_mux_info(spec->input_mux, uinfo); 251c9b443d4STobin Davis } 252c9b443d4STobin Davis 253c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol, 254c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 255c9b443d4STobin Davis { 256c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 257c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 258c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 259c9b443d4STobin Davis 260c9b443d4STobin Davis ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; 261c9b443d4STobin Davis return 0; 262c9b443d4STobin Davis } 263c9b443d4STobin Davis 264c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol, 265c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 266c9b443d4STobin Davis { 267c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 268c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 269c9b443d4STobin Davis unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 270c9b443d4STobin Davis 271c9b443d4STobin Davis return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 272c9b443d4STobin Davis spec->capsrc_nids[adc_idx], 273c9b443d4STobin Davis &spec->cur_mux[adc_idx]); 274c9b443d4STobin Davis } 275c9b443d4STobin Davis 276c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec) 277c9b443d4STobin Davis { 278c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 279c9b443d4STobin Davis int i; 280c9b443d4STobin Davis 281c9b443d4STobin Davis for (i = 0; i < spec->num_init_verbs; i++) 282c9b443d4STobin Davis snd_hda_sequence_write(codec, spec->init_verbs[i]); 283c9b443d4STobin Davis return 0; 284c9b443d4STobin Davis } 285c9b443d4STobin Davis 286c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec) 287c9b443d4STobin Davis { 288c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 289c9b443d4STobin Davis unsigned int i; 290c9b443d4STobin Davis 291c9b443d4STobin Davis if (spec->kctl_alloc) { 292c9b443d4STobin Davis for (i = 0; i < spec->num_kctl_used; i++) 293c9b443d4STobin Davis kfree(spec->kctl_alloc[i].name); 294c9b443d4STobin Davis kfree(spec->kctl_alloc); 295c9b443d4STobin Davis } 296c9b443d4STobin Davis 297c9b443d4STobin Davis kfree(codec->spec); 298c9b443d4STobin Davis } 299c9b443d4STobin Davis 300c9b443d4STobin Davis #ifdef CONFIG_PM 301c9b443d4STobin Davis static int conexant_resume(struct hda_codec *codec) 302c9b443d4STobin Davis { 303c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 304c9b443d4STobin Davis int i; 305c9b443d4STobin Davis 306c9b443d4STobin Davis codec->patch_ops.init(codec); 307c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) 308c9b443d4STobin Davis snd_hda_resume_ctls(codec, spec->mixers[i]); 309c9b443d4STobin Davis if (spec->multiout.dig_out_nid) 310c9b443d4STobin Davis snd_hda_resume_spdif_out(codec); 311c9b443d4STobin Davis if (spec->dig_in_nid) 312c9b443d4STobin Davis snd_hda_resume_spdif_in(codec); 313c9b443d4STobin Davis return 0; 314c9b443d4STobin Davis } 315c9b443d4STobin Davis #endif 316c9b443d4STobin Davis 317c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec) 318c9b443d4STobin Davis { 319c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 320c9b443d4STobin Davis unsigned int i; 321c9b443d4STobin Davis int err; 322c9b443d4STobin Davis 323c9b443d4STobin Davis for (i = 0; i < spec->num_mixers; i++) { 324c9b443d4STobin Davis err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 325c9b443d4STobin Davis if (err < 0) 326c9b443d4STobin Davis return err; 327c9b443d4STobin Davis } 328c9b443d4STobin Davis if (spec->multiout.dig_out_nid) { 329c9b443d4STobin Davis err = snd_hda_create_spdif_out_ctls(codec, 330c9b443d4STobin Davis spec->multiout.dig_out_nid); 331c9b443d4STobin Davis if (err < 0) 332c9b443d4STobin Davis return err; 333c9b443d4STobin Davis } 334c9b443d4STobin Davis if (spec->dig_in_nid) { 335c9b443d4STobin Davis err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 336c9b443d4STobin Davis if (err < 0) 337c9b443d4STobin Davis return err; 338c9b443d4STobin Davis } 339c9b443d4STobin Davis return 0; 340c9b443d4STobin Davis } 341c9b443d4STobin Davis 342c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = { 343c9b443d4STobin Davis .build_controls = conexant_build_controls, 344c9b443d4STobin Davis .build_pcms = conexant_build_pcms, 345c9b443d4STobin Davis .init = conexant_init, 346c9b443d4STobin Davis .free = conexant_free, 347c9b443d4STobin Davis #ifdef CONFIG_PM 348c9b443d4STobin Davis .resume = conexant_resume, 349c9b443d4STobin Davis #endif 350c9b443d4STobin Davis }; 351c9b443d4STobin Davis 352c9b443d4STobin Davis /* 353c9b443d4STobin Davis * EAPD control 354c9b443d4STobin Davis * the private value = nid | (invert << 8) 355c9b443d4STobin Davis */ 356c9b443d4STobin Davis 357c9b443d4STobin Davis static int conexant_eapd_info(struct snd_kcontrol *kcontrol, 358c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 359c9b443d4STobin Davis { 360c9b443d4STobin Davis uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 361c9b443d4STobin Davis uinfo->count = 1; 362c9b443d4STobin Davis uinfo->value.integer.min = 0; 363c9b443d4STobin Davis uinfo->value.integer.max = 1; 364c9b443d4STobin Davis return 0; 365c9b443d4STobin Davis } 366c9b443d4STobin Davis 367c9b443d4STobin Davis static int conexant_eapd_get(struct snd_kcontrol *kcontrol, 368c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 369c9b443d4STobin Davis { 370c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 371c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 372c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 373c9b443d4STobin Davis if (invert) 374c9b443d4STobin Davis ucontrol->value.integer.value[0] = !spec->cur_eapd; 375c9b443d4STobin Davis else 376c9b443d4STobin Davis ucontrol->value.integer.value[0] = spec->cur_eapd; 377c9b443d4STobin Davis return 0; 378c9b443d4STobin Davis } 379c9b443d4STobin Davis 380c9b443d4STobin Davis static int conexant_eapd_put(struct snd_kcontrol *kcontrol, 381c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 382c9b443d4STobin Davis { 383c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 384c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 385c9b443d4STobin Davis int invert = (kcontrol->private_value >> 8) & 1; 386c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xff; 387c9b443d4STobin Davis unsigned int eapd; 388c9b443d4STobin Davis eapd = ucontrol->value.integer.value[0]; 389c9b443d4STobin Davis if (invert) 390c9b443d4STobin Davis eapd = !eapd; 391c9b443d4STobin Davis if (eapd == spec->cur_eapd && !codec->in_resume) 392c9b443d4STobin Davis return 0; 393c9b443d4STobin Davis spec->cur_eapd = eapd; 394c9b443d4STobin Davis snd_hda_codec_write(codec, nid, 395c9b443d4STobin Davis 0, AC_VERB_SET_EAPD_BTLENABLE, 396c9b443d4STobin Davis eapd ? 0x02 : 0x00); 397c9b443d4STobin Davis return 1; 398c9b443d4STobin Davis } 399c9b443d4STobin Davis 400*86d72bdfSTakashi Iwai /* controls for test mode */ 401*86d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG 402*86d72bdfSTakashi Iwai 403c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol, 404c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 405c9b443d4STobin Davis { 406c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 407c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 408c9b443d4STobin Davis return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, 409c9b443d4STobin Davis spec->num_channel_mode); 410c9b443d4STobin Davis } 411c9b443d4STobin Davis 412c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol, 413c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 414c9b443d4STobin Davis { 415c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 416c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 417c9b443d4STobin Davis return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, 418c9b443d4STobin Davis spec->num_channel_mode, 419c9b443d4STobin Davis spec->multiout.max_channels); 420c9b443d4STobin Davis } 421c9b443d4STobin Davis 422c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol, 423c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 424c9b443d4STobin Davis { 425c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 426c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 427c9b443d4STobin Davis int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 428c9b443d4STobin Davis spec->num_channel_mode, 429c9b443d4STobin Davis &spec->multiout.max_channels); 430c9b443d4STobin Davis if (err >= 0 && spec->need_dac_fix) 431c9b443d4STobin Davis spec->multiout.num_dacs = spec->multiout.max_channels / 2; 432c9b443d4STobin Davis return err; 433c9b443d4STobin Davis } 434c9b443d4STobin Davis 435c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \ 436c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 437c9b443d4STobin Davis .info = conexant_ch_mode_info, \ 438c9b443d4STobin Davis .get = conexant_ch_mode_get, \ 439c9b443d4STobin Davis .put = conexant_ch_mode_put, \ 440c9b443d4STobin Davis .private_value = nid | (dir<<16) } 441c9b443d4STobin Davis 442c9b443d4STobin Davis static int cxt_gpio_data_info(struct snd_kcontrol *kcontrol, 443c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 444c9b443d4STobin Davis { 445c9b443d4STobin Davis uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 446c9b443d4STobin Davis uinfo->count = 1; 447c9b443d4STobin Davis uinfo->value.integer.min = 0; 448c9b443d4STobin Davis uinfo->value.integer.max = 1; 449c9b443d4STobin Davis return 0; 450c9b443d4STobin Davis } 451c9b443d4STobin Davis 452c9b443d4STobin Davis static int cxt_gpio_data_get(struct snd_kcontrol *kcontrol, 453c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 454c9b443d4STobin Davis { 455c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 456c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xffff; 457c9b443d4STobin Davis unsigned char mask = (kcontrol->private_value >> 16) & 0xff; 458c9b443d4STobin Davis long *valp = ucontrol->value.integer.value; 459c9b443d4STobin Davis unsigned int val = snd_hda_codec_read(codec, nid, 0, 460c9b443d4STobin Davis AC_VERB_GET_GPIO_DATA, 0x00); 461c9b443d4STobin Davis 462c9b443d4STobin Davis *valp = (val & mask) != 0; 463c9b443d4STobin Davis return 0; 464c9b443d4STobin Davis } 465c9b443d4STobin Davis 466c9b443d4STobin Davis static int cxt_gpio_data_put(struct snd_kcontrol *kcontrol, 467c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 468c9b443d4STobin Davis { 469c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 470c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xffff; 471c9b443d4STobin Davis unsigned char mask = (kcontrol->private_value >> 16) & 0xff; 472c9b443d4STobin Davis long val = *ucontrol->value.integer.value; 473c9b443d4STobin Davis unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0, 474c9b443d4STobin Davis AC_VERB_GET_GPIO_DATA, 475c9b443d4STobin Davis 0x00); 476c9b443d4STobin Davis unsigned int old_data = gpio_data; 477c9b443d4STobin Davis 478c9b443d4STobin Davis /* Set/unset the masked GPIO bit(s) as needed */ 479c9b443d4STobin Davis if (val == 0) 480c9b443d4STobin Davis gpio_data &= ~mask; 481c9b443d4STobin Davis else 482c9b443d4STobin Davis gpio_data |= mask; 483c9b443d4STobin Davis if (gpio_data == old_data && !codec->in_resume) 484c9b443d4STobin Davis return 0; 485c9b443d4STobin Davis snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data); 486c9b443d4STobin Davis return 1; 487c9b443d4STobin Davis } 488c9b443d4STobin Davis 489c9b443d4STobin Davis #define CXT_GPIO_DATA_SWITCH(xname, nid, mask) \ 490c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 491c9b443d4STobin Davis .info = cxt_gpio_data_info, \ 492c9b443d4STobin Davis .get = cxt_gpio_data_get, \ 493c9b443d4STobin Davis .put = cxt_gpio_data_put, \ 494c9b443d4STobin Davis .private_value = nid | (mask<<16) } 495c9b443d4STobin Davis 496c9b443d4STobin Davis static int cxt_spdif_ctrl_info(struct snd_kcontrol *kcontrol, 497c9b443d4STobin Davis struct snd_ctl_elem_info *uinfo) 498c9b443d4STobin Davis { 499c9b443d4STobin Davis uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 500c9b443d4STobin Davis uinfo->count = 1; 501c9b443d4STobin Davis uinfo->value.integer.min = 0; 502c9b443d4STobin Davis uinfo->value.integer.max = 1; 503c9b443d4STobin Davis return 0; 504c9b443d4STobin Davis } 505c9b443d4STobin Davis 506c9b443d4STobin Davis static int cxt_spdif_ctrl_get(struct snd_kcontrol *kcontrol, 507c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 508c9b443d4STobin Davis { 509c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 510c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xffff; 511c9b443d4STobin Davis unsigned char mask = (kcontrol->private_value >> 16) & 0xff; 512c9b443d4STobin Davis long *valp = ucontrol->value.integer.value; 513c9b443d4STobin Davis unsigned int val = snd_hda_codec_read(codec, nid, 0, 514c9b443d4STobin Davis AC_VERB_GET_DIGI_CONVERT, 0x00); 515c9b443d4STobin Davis 516c9b443d4STobin Davis *valp = (val & mask) != 0; 517c9b443d4STobin Davis return 0; 518c9b443d4STobin Davis } 519c9b443d4STobin Davis 520c9b443d4STobin Davis static int cxt_spdif_ctrl_put(struct snd_kcontrol *kcontrol, 521c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 522c9b443d4STobin Davis { 523c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 524c9b443d4STobin Davis hda_nid_t nid = kcontrol->private_value & 0xffff; 525c9b443d4STobin Davis unsigned char mask = (kcontrol->private_value >> 16) & 0xff; 526c9b443d4STobin Davis long val = *ucontrol->value.integer.value; 527c9b443d4STobin Davis unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0, 528c9b443d4STobin Davis AC_VERB_GET_DIGI_CONVERT, 529c9b443d4STobin Davis 0x00); 530c9b443d4STobin Davis unsigned int old_data = ctrl_data; 531c9b443d4STobin Davis 532c9b443d4STobin Davis /* Set/unset the masked control bit(s) as needed */ 533c9b443d4STobin Davis if (val == 0) 534c9b443d4STobin Davis ctrl_data &= ~mask; 535c9b443d4STobin Davis else 536c9b443d4STobin Davis ctrl_data |= mask; 537c9b443d4STobin Davis if (ctrl_data == old_data && !codec->in_resume) 538c9b443d4STobin Davis return 0; 539c9b443d4STobin Davis snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1, 540c9b443d4STobin Davis ctrl_data); 541c9b443d4STobin Davis return 1; 542c9b443d4STobin Davis } 543c9b443d4STobin Davis 544c9b443d4STobin Davis #define CXT_SPDIF_CTRL_SWITCH(xname, nid, mask) \ 545c9b443d4STobin Davis { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 546c9b443d4STobin Davis .info = cxt_spdif_ctrl_info, \ 547c9b443d4STobin Davis .get = cxt_spdif_ctrl_get, \ 548c9b443d4STobin Davis .put = cxt_spdif_ctrl_put, \ 549c9b443d4STobin Davis .private_value = nid | (mask<<16) } 550c9b443d4STobin Davis 551*86d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */ 552*86d72bdfSTakashi Iwai 553c9b443d4STobin Davis /* Conexant 5045 specific */ 554c9b443d4STobin Davis 555c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 }; 556c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a }; 557c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a }; 558c9b443d4STobin Davis #define CXT5045_SPDIF_OUT 0x13 559c9b443d4STobin Davis 5605cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = { 5615cd57529STobin Davis { 2, NULL }, 5625cd57529STobin Davis }; 563c9b443d4STobin Davis 564c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = { 565c9b443d4STobin Davis .num_items = 2, 566c9b443d4STobin Davis .items = { 567c9b443d4STobin Davis { "ExtMic", 0x1 }, 568c9b443d4STobin Davis { "LineIn", 0x2 }, 569c9b443d4STobin Davis } 570c9b443d4STobin Davis }; 571c9b443d4STobin Davis 572c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 573c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 574c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 575c9b443d4STobin Davis { 576c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 577c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 578c9b443d4STobin Davis 579c9b443d4STobin Davis if (!conexant_eapd_put(kcontrol, ucontrol)) 580c9b443d4STobin Davis return 0; 581c9b443d4STobin Davis 582c9b443d4STobin Davis /* toggle HP mute appropriately */ 583c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 584c9b443d4STobin Davis 0x80, spec->cur_eapd ? 0 : 0x80); 585c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 586c9b443d4STobin Davis 0x80, spec->cur_eapd ? 0 : 0x80); 587c9b443d4STobin Davis return 1; 588c9b443d4STobin Davis } 589c9b443d4STobin Davis 590c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */ 591c9b443d4STobin Davis static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol, 592c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 593c9b443d4STobin Davis { 594c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 595c9b443d4STobin Davis long *valp = ucontrol->value.integer.value; 596c9b443d4STobin Davis int change; 597c9b443d4STobin Davis 598c9b443d4STobin Davis change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 599c9b443d4STobin Davis 0x7f, valp[0] & 0x7f); 600c9b443d4STobin Davis change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 601c9b443d4STobin Davis 0x7f, valp[1] & 0x7f); 602c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0, 603c9b443d4STobin Davis 0x7f, valp[0] & 0x7f); 604c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0, 605c9b443d4STobin Davis 0x7f, valp[1] & 0x7f); 606c9b443d4STobin Davis return change; 607c9b443d4STobin Davis } 608c9b443d4STobin Davis 609c9b443d4STobin Davis 610c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 611c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec) 612c9b443d4STobin Davis { 613c9b443d4STobin Davis unsigned int present; 614c9b443d4STobin Davis 615c9b443d4STobin Davis present = snd_hda_codec_read(codec, 0x11, 0, 616c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 617c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0, 618c9b443d4STobin Davis 0x80, present ? 0x80 : 0); 619c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0, 620c9b443d4STobin Davis 0x80, present ? 0x80 : 0); 621c9b443d4STobin Davis } 622c9b443d4STobin Davis 623c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 624c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec, 625c9b443d4STobin Davis unsigned int res) 626c9b443d4STobin Davis { 627c9b443d4STobin Davis res >>= 26; 628c9b443d4STobin Davis switch (res) { 629c9b443d4STobin Davis case CONEXANT_HP_EVENT: 630c9b443d4STobin Davis cxt5045_hp_automute(codec); 631c9b443d4STobin Davis break; 632c9b443d4STobin Davis } 633c9b443d4STobin Davis } 634c9b443d4STobin Davis 635c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = { 636c9b443d4STobin Davis { 637c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 638c9b443d4STobin Davis .name = "Capture Source", 639c9b443d4STobin Davis .info = conexant_mux_enum_info, 640c9b443d4STobin Davis .get = conexant_mux_enum_get, 641c9b443d4STobin Davis .put = conexant_mux_enum_put 642c9b443d4STobin Davis }, 643c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x17, 0x02, HDA_INPUT), 644c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x17, 0x02, HDA_INPUT), 645c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x02, HDA_INPUT), 646c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x02, HDA_INPUT), 647c9b443d4STobin Davis { 648c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 649c9b443d4STobin Davis .name = "Master Playback Volume", 650c9b443d4STobin Davis .info = snd_hda_mixer_amp_volume_info, 651c9b443d4STobin Davis .get = snd_hda_mixer_amp_volume_get, 652c9b443d4STobin Davis .put = cxt5045_hp_master_vol_put, 653c9b443d4STobin Davis .private_value = HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT), 654c9b443d4STobin Davis }, 655c9b443d4STobin Davis { 656c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 657c9b443d4STobin Davis .name = "Master Playback Switch", 658c9b443d4STobin Davis .info = conexant_eapd_info, 659c9b443d4STobin Davis .get = conexant_eapd_get, 660c9b443d4STobin Davis .put = cxt5045_hp_master_sw_put, 661c9b443d4STobin Davis .private_value = 0x11, 662c9b443d4STobin Davis }, 663c9b443d4STobin Davis 664c9b443d4STobin Davis {} 665c9b443d4STobin Davis }; 666c9b443d4STobin Davis 667c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = { 668c9b443d4STobin Davis /* Line in, Mic */ 669c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 670c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 671c9b443d4STobin Davis /* HP, Amp */ 672c9b443d4STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 673c9b443d4STobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x01}, 674c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 675c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 676c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 677c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 678c9b443d4STobin Davis /* Record selector: Front mic */ 679c9b443d4STobin Davis {0x14, AC_VERB_SET_CONNECT_SEL,0x03}, 680c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 681c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 682c9b443d4STobin Davis /* SPDIF route: PCM */ 683c9b443d4STobin Davis { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 }, 684c9b443d4STobin Davis /* pin sensing on HP and Mic jacks */ 685c9b443d4STobin Davis {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 686c9b443d4STobin Davis /* EAPD */ 687c9b443d4STobin Davis {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ 688c9b443d4STobin Davis { } /* end */ 689c9b443d4STobin Davis }; 690c9b443d4STobin Davis 691c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 692c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 693c9b443d4STobin Davis * configuration. 694c9b443d4STobin Davis */ 695c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = { 696c9b443d4STobin Davis .num_items = 5, 697c9b443d4STobin Davis .items = { 698c9b443d4STobin Davis { "MIXER", 0x0 }, 699c9b443d4STobin Davis { "MIC1 pin", 0x1 }, 700c9b443d4STobin Davis { "LINE1 pin", 0x2 }, 701c9b443d4STobin Davis { "HP-OUT pin", 0x3 }, 702c9b443d4STobin Davis { "CD pin", 0x4 }, 703c9b443d4STobin Davis }, 704c9b443d4STobin Davis }; 705c9b443d4STobin Davis 706c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = { 707c9b443d4STobin Davis 708c9b443d4STobin Davis /* Output controls */ 709c9b443d4STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x19, 0x00, HDA_OUTPUT), 710c9b443d4STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x19,0x00, HDA_OUTPUT), 711c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT), 712c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT), 713c9b443d4STobin Davis 714c9b443d4STobin Davis /* Modes for retasking pin widgets */ 715c9b443d4STobin Davis CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT), 716c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT), 717c9b443d4STobin Davis 718c9b443d4STobin Davis /* Loopback mixer controls */ 719c9b443d4STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x17, 0x01, HDA_INPUT), 720c9b443d4STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x17, 0x01, HDA_INPUT), 721c9b443d4STobin Davis HDA_CODEC_VOLUME("LINE loopback Playback Volume", 0x17, 0x02, HDA_INPUT), 722c9b443d4STobin Davis HDA_CODEC_MUTE("LINE loopback Playback Switch", 0x17, 0x02, HDA_INPUT), 723c9b443d4STobin Davis HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x17, 0x03, HDA_INPUT), 724c9b443d4STobin Davis HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x17, 0x03, HDA_INPUT), 725c9b443d4STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x04, HDA_INPUT), 726c9b443d4STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x04, HDA_INPUT), 727c9b443d4STobin Davis 728c9b443d4STobin Davis /* Controls for GPIO pins, assuming they exist and are configured as outputs */ 729c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01), 730c9b443d4STobin Davis #if 0 /* limit this to one GPIO pin for now */ 731c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02), 732c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04), 733c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08), 734c9b443d4STobin Davis #endif 735c9b443d4STobin Davis CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x13, 0x01), 736c9b443d4STobin Davis 737c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_OUTPUT), 738c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_OUTPUT), 739c9b443d4STobin Davis { 740c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 741c9b443d4STobin Davis .name = "Input Source", 742c9b443d4STobin Davis .info = conexant_mux_enum_info, 743c9b443d4STobin Davis .get = conexant_mux_enum_get, 744c9b443d4STobin Davis .put = conexant_mux_enum_put, 745c9b443d4STobin Davis }, 746c9b443d4STobin Davis 747c9b443d4STobin Davis { } /* end */ 748c9b443d4STobin Davis }; 749c9b443d4STobin Davis 750c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = { 751c9b443d4STobin Davis /* Enable all GPIOs as outputs with an initial value of 0 */ 752c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f}, 753c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, 754c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_MASK, 0x0f}, 755c9b443d4STobin Davis 756c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 757c9b443d4STobin Davis {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 758c9b443d4STobin Davis {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 759c9b443d4STobin Davis 760c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 761c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 762c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 763c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 764c9b443d4STobin Davis * control. 765c9b443d4STobin Davis */ 766c9b443d4STobin Davis {0x13, AC_VERB_SET_DIGI_CONVERT_1, 0}, 767c9b443d4STobin Davis 768c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 769c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 770c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 771c9b443d4STobin Davis 772c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 773c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 774c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 775c9b443d4STobin Davis * input/output buffers as needed. 776c9b443d4STobin Davis */ 777c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 778c9b443d4STobin Davis {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 779c9b443d4STobin Davis 780c9b443d4STobin Davis /* Mute capture amp left and right */ 781c9b443d4STobin Davis {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 782c9b443d4STobin Davis 783c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 784c9b443d4STobin Davis * pin) 785c9b443d4STobin Davis */ 786c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00}, 787c9b443d4STobin Davis 788c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 789c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */ 790c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */ 791c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */ 792c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */ 793c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 794c9b443d4STobin Davis 795c9b443d4STobin Davis { } 796c9b443d4STobin Davis }; 797c9b443d4STobin Davis #endif 798c9b443d4STobin Davis 799c9b443d4STobin Davis 800c9b443d4STobin Davis /* initialize jack-sensing, too */ 801c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec) 802c9b443d4STobin Davis { 803c9b443d4STobin Davis conexant_init(codec); 804c9b443d4STobin Davis cxt5045_hp_automute(codec); 805c9b443d4STobin Davis return 0; 806c9b443d4STobin Davis } 807c9b443d4STobin Davis 808c9b443d4STobin Davis 809c9b443d4STobin Davis enum { 810f5fcc13cSTakashi Iwai CXT5045_LAPTOP, /* Laptops w/ EAPD support */ 811c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 812c9b443d4STobin Davis CXT5045_TEST, 813c9b443d4STobin Davis #endif 814f5fcc13cSTakashi Iwai CXT5045_MODELS 815c9b443d4STobin Davis }; 816c9b443d4STobin Davis 817f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = { 818f5fcc13cSTakashi Iwai [CXT5045_LAPTOP] = "laptop", 819c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 820f5fcc13cSTakashi Iwai [CXT5045_TEST] = "test", 821c9b443d4STobin Davis #endif 822f5fcc13cSTakashi Iwai }; 823c9b443d4STobin Davis 824f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 825f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP), 826c9b443d4STobin Davis {} 827c9b443d4STobin Davis }; 828c9b443d4STobin Davis 829c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec) 830c9b443d4STobin Davis { 831c9b443d4STobin Davis struct conexant_spec *spec; 832c9b443d4STobin Davis int board_config; 833c9b443d4STobin Davis 834c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 835c9b443d4STobin Davis if (!spec) 836c9b443d4STobin Davis return -ENOMEM; 837c9b443d4STobin Davis mutex_init(&spec->amp_mutex); 838c9b443d4STobin Davis codec->spec = spec; 839c9b443d4STobin Davis 840c9b443d4STobin Davis spec->multiout.max_channels = 2; 841c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 842c9b443d4STobin Davis spec->multiout.dac_nids = cxt5045_dac_nids; 843c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT; 844c9b443d4STobin Davis spec->num_adc_nids = 1; 845c9b443d4STobin Davis spec->adc_nids = cxt5045_adc_nids; 846c9b443d4STobin Davis spec->capsrc_nids = cxt5045_capsrc_nids; 847c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 848c9b443d4STobin Davis spec->num_mixers = 1; 849c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 850c9b443d4STobin Davis spec->num_init_verbs = 1; 851c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_init_verbs; 852c9b443d4STobin Davis spec->spdif_route = 0; 8535cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes), 8545cd57529STobin Davis spec->channel_mode = cxt5045_modes, 8555cd57529STobin Davis 856c9b443d4STobin Davis 857c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 858c9b443d4STobin Davis codec->patch_ops.unsol_event = cxt5045_hp_unsol_event; 859c9b443d4STobin Davis 860f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5045_MODELS, 861f5fcc13cSTakashi Iwai cxt5045_models, 862f5fcc13cSTakashi Iwai cxt5045_cfg_tbl); 863c9b443d4STobin Davis switch (board_config) { 864c9b443d4STobin Davis case CXT5045_LAPTOP: 865c9b443d4STobin Davis spec->input_mux = &cxt5045_capture_source; 866c9b443d4STobin Davis spec->num_init_verbs = 2; 867c9b443d4STobin Davis spec->init_verbs[1] = cxt5045_init_verbs; 868c9b443d4STobin Davis spec->mixers[0] = cxt5045_mixers; 869c9b443d4STobin Davis codec->patch_ops.init = cxt5045_init; 870c9b443d4STobin Davis break; 871c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 872c9b443d4STobin Davis case CXT5045_TEST: 873c9b443d4STobin Davis spec->input_mux = &cxt5045_test_capture_source; 874c9b443d4STobin Davis spec->mixers[0] = cxt5045_test_mixer; 875c9b443d4STobin Davis spec->init_verbs[0] = cxt5045_test_init_verbs; 876c9b443d4STobin Davis #endif 877c9b443d4STobin Davis } 878c9b443d4STobin Davis return 0; 879c9b443d4STobin Davis } 880c9b443d4STobin Davis 881c9b443d4STobin Davis 882c9b443d4STobin Davis /* Conexant 5047 specific */ 883c9b443d4STobin Davis 884c9b443d4STobin Davis static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; 885c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 886c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 887c9b443d4STobin Davis #define CXT5047_SPDIF_OUT 0x11 888c9b443d4STobin Davis 8895cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = { 8905cd57529STobin Davis { 2, NULL }, 8915cd57529STobin Davis }; 892c9b443d4STobin Davis 893c9b443d4STobin Davis static struct hda_input_mux cxt5047_capture_source = { 894c9b443d4STobin Davis .num_items = 2, 895c9b443d4STobin Davis .items = { 896c9b443d4STobin Davis { "ExtMic", 0x1 }, 897c9b443d4STobin Davis { "IntMic", 0x2 }, 898c9b443d4STobin Davis } 899c9b443d4STobin Davis }; 900c9b443d4STobin Davis 901c9b443d4STobin Davis static struct hda_input_mux cxt5047_hp_capture_source = { 902c9b443d4STobin Davis .num_items = 1, 903c9b443d4STobin Davis .items = { 904c9b443d4STobin Davis { "ExtMic", 0x1 }, 905c9b443d4STobin Davis } 906c9b443d4STobin Davis }; 907c9b443d4STobin Davis 908c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */ 909c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol, 910c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 911c9b443d4STobin Davis { 912c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 913c9b443d4STobin Davis struct conexant_spec *spec = codec->spec; 914c9b443d4STobin Davis 915c9b443d4STobin Davis if (!conexant_eapd_put(kcontrol, ucontrol)) 916c9b443d4STobin Davis return 0; 917c9b443d4STobin Davis 918c9b443d4STobin Davis /* toggle HP mute appropriately */ 919c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 920c9b443d4STobin Davis 0x80, spec->cur_eapd ? 0 : 0x80); 921c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 922c9b443d4STobin Davis 0x80, spec->cur_eapd ? 0 : 0x80); 923c9b443d4STobin Davis return 1; 924c9b443d4STobin Davis } 925c9b443d4STobin Davis 926c9b443d4STobin Davis #if 0 927c9b443d4STobin Davis /* bind volumes of both NID 0x13 and 0x1d */ 928c9b443d4STobin Davis static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol, 929c9b443d4STobin Davis struct snd_ctl_elem_value *ucontrol) 930c9b443d4STobin Davis { 931c9b443d4STobin Davis struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 932c9b443d4STobin Davis long *valp = ucontrol->value.integer.value; 933c9b443d4STobin Davis int change; 934c9b443d4STobin Davis 935c9b443d4STobin Davis change = snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 936c9b443d4STobin Davis 0x7f, valp[0] & 0x7f); 937c9b443d4STobin Davis change |= snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 938c9b443d4STobin Davis 0x7f, valp[1] & 0x7f); 939c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0, 940c9b443d4STobin Davis 0x7f, valp[0] & 0x7f); 941c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0, 942c9b443d4STobin Davis 0x7f, valp[1] & 0x7f); 943c9b443d4STobin Davis return change; 944c9b443d4STobin Davis } 945c9b443d4STobin Davis #endif 946c9b443d4STobin Davis 947c9b443d4STobin Davis /* mute internal speaker if HP is plugged */ 948c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec) 949c9b443d4STobin Davis { 950c9b443d4STobin Davis unsigned int present; 951c9b443d4STobin Davis 952c9b443d4STobin Davis present = snd_hda_codec_read(codec, 0x13, 0, 953c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 954c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x1c, 0, HDA_OUTPUT, 0, 955c9b443d4STobin Davis 0x80, present ? 0x80 : 0); 956c9b443d4STobin Davis snd_hda_codec_amp_update(codec, 0x1c, 1, HDA_OUTPUT, 0, 957c9b443d4STobin Davis 0x80, present ? 0x80 : 0); 958c9b443d4STobin Davis } 959c9b443d4STobin Davis 960c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */ 961c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec) 962c9b443d4STobin Davis { 963c9b443d4STobin Davis static struct hda_verb mic_jack_on[] = { 964c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 965c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 966c9b443d4STobin Davis {} 967c9b443d4STobin Davis }; 968c9b443d4STobin Davis static struct hda_verb mic_jack_off[] = { 969c9b443d4STobin Davis {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 970c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 971c9b443d4STobin Davis {} 972c9b443d4STobin Davis }; 973c9b443d4STobin Davis unsigned int present; 974c9b443d4STobin Davis 975c9b443d4STobin Davis present = snd_hda_codec_read(codec, 0x08, 0, 976c9b443d4STobin Davis AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 977c9b443d4STobin Davis if (present) 978c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_on); 979c9b443d4STobin Davis else 980c9b443d4STobin Davis snd_hda_sequence_write(codec, mic_jack_off); 981c9b443d4STobin Davis } 982c9b443d4STobin Davis 983c9b443d4STobin Davis /* unsolicited event for HP jack sensing */ 984c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec, 985c9b443d4STobin Davis unsigned int res) 986c9b443d4STobin Davis { 987c9b443d4STobin Davis res >>= 26; 988c9b443d4STobin Davis switch (res) { 989c9b443d4STobin Davis case CONEXANT_HP_EVENT: 990c9b443d4STobin Davis cxt5047_hp_automute(codec); 991c9b443d4STobin Davis break; 992c9b443d4STobin Davis case CONEXANT_MIC_EVENT: 993c9b443d4STobin Davis cxt5047_hp_automic(codec); 994c9b443d4STobin Davis break; 995c9b443d4STobin Davis } 996c9b443d4STobin Davis } 997c9b443d4STobin Davis 998c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_mixers[] = { 999c9b443d4STobin Davis { 1000c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1001c9b443d4STobin Davis .name = "Capture Source", 1002c9b443d4STobin Davis .info = conexant_mux_enum_info, 1003c9b443d4STobin Davis .get = conexant_mux_enum_get, 1004c9b443d4STobin Davis .put = conexant_mux_enum_put 1005c9b443d4STobin Davis }, 1006c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1007c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT), 1008c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1009c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1010c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1011c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1012c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1013c9b443d4STobin Davis { 1014c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1015c9b443d4STobin Davis .name = "Master Playback Switch", 1016c9b443d4STobin Davis .info = conexant_eapd_info, 1017c9b443d4STobin Davis .get = conexant_eapd_get, 1018c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1019c9b443d4STobin Davis .private_value = 0x13, 1020c9b443d4STobin Davis }, 1021c9b443d4STobin Davis 1022c9b443d4STobin Davis {} 1023c9b443d4STobin Davis }; 1024c9b443d4STobin Davis 1025c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_hp_mixers[] = { 1026c9b443d4STobin Davis { 1027c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1028c9b443d4STobin Davis .name = "Capture Source", 1029c9b443d4STobin Davis .info = conexant_mux_enum_info, 1030c9b443d4STobin Davis .get = conexant_mux_enum_get, 1031c9b443d4STobin Davis .put = conexant_mux_enum_put 1032c9b443d4STobin Davis }, 1033c9b443d4STobin Davis HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT), 1034c9b443d4STobin Davis HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT), 1035c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1036c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1037c9b443d4STobin Davis HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1038c9b443d4STobin Davis HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1039c9b443d4STobin Davis HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1040c9b443d4STobin Davis { 1041c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1042c9b443d4STobin Davis .name = "Master Playback Switch", 1043c9b443d4STobin Davis .info = conexant_eapd_info, 1044c9b443d4STobin Davis .get = conexant_eapd_get, 1045c9b443d4STobin Davis .put = cxt5047_hp_master_sw_put, 1046c9b443d4STobin Davis .private_value = 0x13, 1047c9b443d4STobin Davis }, 1048c9b443d4STobin Davis { } /* end */ 1049c9b443d4STobin Davis }; 1050c9b443d4STobin Davis 1051c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = { 1052c9b443d4STobin Davis /* Line in, Mic, Built-in Mic */ 1053c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 1054c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1055c9b443d4STobin Davis {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1056c9b443d4STobin Davis /* HP, Amp */ 1057c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 10585cd57529STobin Davis {0x1A, AC_VERB_SET_CONNECT_SEL,0x03}, 1059c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1060c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00}, 1061c9b443d4STobin Davis {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, 1062c9b443d4STobin Davis AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03}, 1063c9b443d4STobin Davis /* Record selector: Front mic */ 1064c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 1065c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 1066c9b443d4STobin Davis AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17}, 1067c9b443d4STobin Davis /* SPDIF route: PCM */ 1068c9b443d4STobin Davis { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 }, 1069c9b443d4STobin Davis { } /* end */ 1070c9b443d4STobin Davis }; 1071c9b443d4STobin Davis 1072c9b443d4STobin Davis /* configuration for Toshiba Laptops */ 1073c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = { 1074c9b443d4STobin Davis {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ 1075c9b443d4STobin Davis /* pin sensing on HP and Mic jacks */ 1076c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1077c9b443d4STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1078c9b443d4STobin Davis {} 1079c9b443d4STobin Davis }; 1080c9b443d4STobin Davis 1081c9b443d4STobin Davis /* configuration for HP Laptops */ 1082c9b443d4STobin Davis static struct hda_verb cxt5047_hp_init_verbs[] = { 1083c9b443d4STobin Davis /* pin sensing on HP and Mic jacks */ 1084c9b443d4STobin Davis {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT}, 1085c9b443d4STobin Davis {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT}, 1086c9b443d4STobin Davis {} 1087c9b443d4STobin Davis }; 1088c9b443d4STobin Davis 1089c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test 1090c9b443d4STobin Davis * configuration. 1091c9b443d4STobin Davis */ 1092c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1093c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = { 1094c9b443d4STobin Davis .num_items = 5, 1095c9b443d4STobin Davis .items = { 1096c9b443d4STobin Davis { "MIXER", 0x0 }, 1097c9b443d4STobin Davis { "LINE1 pin", 0x1 }, 1098c9b443d4STobin Davis { "MIC1 pin", 0x2 }, 1099c9b443d4STobin Davis { "MIC2 pin", 0x3 }, 1100c9b443d4STobin Davis { "CD pin", 0x4 }, 1101c9b443d4STobin Davis }, 1102c9b443d4STobin Davis }; 1103c9b443d4STobin Davis 1104c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = { 1105c9b443d4STobin Davis 1106c9b443d4STobin Davis /* Output only controls */ 1107c9b443d4STobin Davis HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x00, HDA_OUTPUT), 1108c9b443d4STobin Davis HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x00, HDA_OUTPUT), 1109c9b443d4STobin Davis HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x00, HDA_OUTPUT), 1110c9b443d4STobin Davis HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x00, HDA_OUTPUT), 1111c9b443d4STobin Davis HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1112c9b443d4STobin Davis HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1113c9b443d4STobin Davis HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1114c9b443d4STobin Davis HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT), 1115c9b443d4STobin Davis 1116c9b443d4STobin Davis /* Modes for retasking pin widgets */ 1117c9b443d4STobin Davis CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT), 1118c9b443d4STobin Davis CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT), 1119c9b443d4STobin Davis 1120c9b443d4STobin Davis /* Loopback mixer controls */ 1121c9b443d4STobin Davis HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x19, 0x02, HDA_INPUT), 1122c9b443d4STobin Davis HDA_CODEC_MUTE("MIC1 Playback Switch", 0x19, 0x02, HDA_INPUT), 1123c9b443d4STobin Davis HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x19, 0x03, HDA_INPUT), 1124c9b443d4STobin Davis HDA_CODEC_MUTE("MIC2 Playback Switch", 0x19, 0x03, HDA_INPUT), 1125c9b443d4STobin Davis HDA_CODEC_VOLUME("LINE Playback Volume", 0x19, 0x01, HDA_INPUT), 1126c9b443d4STobin Davis HDA_CODEC_MUTE("LINE Playback Switch", 0x19, 0x01, HDA_INPUT), 1127c9b443d4STobin Davis HDA_CODEC_VOLUME("CD Playback Volume", 0x19, 0x04, HDA_INPUT), 1128c9b443d4STobin Davis HDA_CODEC_MUTE("CD Playback Switch", 0x19, 0x04, HDA_INPUT), 1129c9b443d4STobin Davis 11305cd57529STobin Davis #if 0 1131c9b443d4STobin Davis /* Controls for GPIO pins, assuming they exist and are configured as outputs */ 1132c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01), 1133c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02), 1134c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04), 1135c9b443d4STobin Davis CXT_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08), 1136c9b443d4STobin Davis #endif 1137c9b443d4STobin Davis CXT_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x18, 0x01), 1138c9b443d4STobin Davis 1139c9b443d4STobin Davis HDA_CODEC_VOLUME("Capture Volume", 0x19, 0x0, HDA_OUTPUT), 1140c9b443d4STobin Davis HDA_CODEC_MUTE("Capture Switch", 0x19, 0x0, HDA_OUTPUT), 1141c9b443d4STobin Davis { 1142c9b443d4STobin Davis .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1143c9b443d4STobin Davis .name = "Input Source", 1144c9b443d4STobin Davis .info = conexant_mux_enum_info, 1145c9b443d4STobin Davis .get = conexant_mux_enum_get, 1146c9b443d4STobin Davis .put = conexant_mux_enum_put, 1147c9b443d4STobin Davis }, 1148c9b443d4STobin Davis 1149c9b443d4STobin Davis { } /* end */ 1150c9b443d4STobin Davis }; 1151c9b443d4STobin Davis 1152c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = { 1153c9b443d4STobin Davis /* Enable all GPIOs as outputs with an initial value of 0 */ 1154c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f}, 1155c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_DATA, 0x00}, 1156c9b443d4STobin Davis {0x01, AC_VERB_SET_GPIO_MASK, 0x0f}, 1157c9b443d4STobin Davis 1158c9b443d4STobin Davis /* Enable retasking pins as output, initially without power amp */ 1159c9b443d4STobin Davis {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1160c9b443d4STobin Davis {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1161c9b443d4STobin Davis {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1162c9b443d4STobin Davis 1163c9b443d4STobin Davis /* Disable digital (SPDIF) pins initially, but users can enable 1164c9b443d4STobin Davis * them via a mixer switch. In the case of SPDIF-out, this initverb 1165c9b443d4STobin Davis * payload also sets the generation to 0, output to be in "consumer" 1166c9b443d4STobin Davis * PCM format, copyright asserted, no pre-emphasis and no validity 1167c9b443d4STobin Davis * control. 1168c9b443d4STobin Davis */ 1169c9b443d4STobin Davis {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0}, 1170c9b443d4STobin Davis 1171c9b443d4STobin Davis /* Ensure mic1, mic2, line1 pin widgets take input from the 1172c9b443d4STobin Davis * OUT1 sum bus when acting as an output. 1173c9b443d4STobin Davis */ 1174c9b443d4STobin Davis {0x1a, AC_VERB_SET_CONNECT_SEL, 0}, 1175c9b443d4STobin Davis {0x1b, AC_VERB_SET_CONNECT_SEL, 0}, 1176c9b443d4STobin Davis 1177c9b443d4STobin Davis /* Start with output sum widgets muted and their output gains at min */ 1178c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1179c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 1180c9b443d4STobin Davis 1181c9b443d4STobin Davis /* Unmute retasking pin widget output buffers since the default 1182c9b443d4STobin Davis * state appears to be output. As the pin mode is changed by the 1183c9b443d4STobin Davis * user the pin mode control will take care of enabling the pin's 1184c9b443d4STobin Davis * input/output buffers as needed. 1185c9b443d4STobin Davis */ 1186c9b443d4STobin Davis {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1187c9b443d4STobin Davis {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1188c9b443d4STobin Davis {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1189c9b443d4STobin Davis 1190c9b443d4STobin Davis /* Mute capture amp left and right */ 1191c9b443d4STobin Davis {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 1192c9b443d4STobin Davis 1193c9b443d4STobin Davis /* Set ADC connection select to match default mixer setting (mic1 1194c9b443d4STobin Davis * pin) 1195c9b443d4STobin Davis */ 1196c9b443d4STobin Davis {0x12, AC_VERB_SET_CONNECT_SEL, 0x00}, 1197c9b443d4STobin Davis 1198c9b443d4STobin Davis /* Mute all inputs to mixer widget (even unconnected ones) */ 1199c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ 1200c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */ 1201c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */ 1202c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */ 1203c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */ 1204c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */ 1205c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */ 1206c9b443d4STobin Davis {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */ 1207c9b443d4STobin Davis 1208c9b443d4STobin Davis { } 1209c9b443d4STobin Davis }; 1210c9b443d4STobin Davis #endif 1211c9b443d4STobin Davis 1212c9b443d4STobin Davis 1213c9b443d4STobin Davis /* initialize jack-sensing, too */ 1214c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec) 1215c9b443d4STobin Davis { 1216c9b443d4STobin Davis conexant_init(codec); 1217c9b443d4STobin Davis cxt5047_hp_automute(codec); 1218c9b443d4STobin Davis cxt5047_hp_automic(codec); 1219c9b443d4STobin Davis return 0; 1220c9b443d4STobin Davis } 1221c9b443d4STobin Davis 1222c9b443d4STobin Davis 1223c9b443d4STobin Davis enum { 1224f5fcc13cSTakashi Iwai CXT5047_LAPTOP, /* Laptops w/o EAPD support */ 1225f5fcc13cSTakashi Iwai CXT5047_LAPTOP_HP, /* Some HP laptops */ 1226f5fcc13cSTakashi Iwai CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */ 1227c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1228c9b443d4STobin Davis CXT5047_TEST, 1229c9b443d4STobin Davis #endif 1230f5fcc13cSTakashi Iwai CXT5047_MODELS 1231c9b443d4STobin Davis }; 1232c9b443d4STobin Davis 1233f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = { 1234f5fcc13cSTakashi Iwai [CXT5047_LAPTOP] = "laptop", 1235f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_HP] = "laptop-hp", 1236f5fcc13cSTakashi Iwai [CXT5047_LAPTOP_EAPD] = "laptop-eapd", 1237c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1238f5fcc13cSTakashi Iwai [CXT5047_TEST] = "test", 1239c9b443d4STobin Davis #endif 1240f5fcc13cSTakashi Iwai }; 1241c9b443d4STobin Davis 1242f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1243f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP), 1244f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), 1245f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1246f5fcc13cSTakashi Iwai SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1247c9b443d4STobin Davis {} 1248c9b443d4STobin Davis }; 1249c9b443d4STobin Davis 1250c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec) 1251c9b443d4STobin Davis { 1252c9b443d4STobin Davis struct conexant_spec *spec; 1253c9b443d4STobin Davis int board_config; 1254c9b443d4STobin Davis 1255c9b443d4STobin Davis spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1256c9b443d4STobin Davis if (!spec) 1257c9b443d4STobin Davis return -ENOMEM; 1258c9b443d4STobin Davis mutex_init(&spec->amp_mutex); 1259c9b443d4STobin Davis codec->spec = spec; 1260c9b443d4STobin Davis 1261c9b443d4STobin Davis spec->multiout.max_channels = 2; 1262c9b443d4STobin Davis spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1263c9b443d4STobin Davis spec->multiout.dac_nids = cxt5047_dac_nids; 1264c9b443d4STobin Davis spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT; 1265c9b443d4STobin Davis spec->num_adc_nids = 1; 1266c9b443d4STobin Davis spec->adc_nids = cxt5047_adc_nids; 1267c9b443d4STobin Davis spec->capsrc_nids = cxt5047_capsrc_nids; 1268c9b443d4STobin Davis spec->input_mux = &cxt5047_capture_source; 1269c9b443d4STobin Davis spec->num_mixers = 1; 1270c9b443d4STobin Davis spec->mixers[0] = cxt5047_mixers; 1271c9b443d4STobin Davis spec->num_init_verbs = 1; 1272c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_init_verbs; 1273c9b443d4STobin Davis spec->spdif_route = 0; 12745cd57529STobin Davis spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes), 12755cd57529STobin Davis spec->channel_mode = cxt5047_modes, 1276c9b443d4STobin Davis 1277c9b443d4STobin Davis codec->patch_ops = conexant_patch_ops; 1278c9b443d4STobin Davis codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1279c9b443d4STobin Davis 1280f5fcc13cSTakashi Iwai board_config = snd_hda_check_board_config(codec, CXT5047_MODELS, 1281f5fcc13cSTakashi Iwai cxt5047_models, 1282f5fcc13cSTakashi Iwai cxt5047_cfg_tbl); 1283c9b443d4STobin Davis switch (board_config) { 1284c9b443d4STobin Davis case CXT5047_LAPTOP: 1285c9b443d4STobin Davis break; 1286c9b443d4STobin Davis case CXT5047_LAPTOP_HP: 1287c9b443d4STobin Davis spec->input_mux = &cxt5047_hp_capture_source; 1288c9b443d4STobin Davis spec->num_init_verbs = 2; 1289c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_hp_init_verbs; 1290c9b443d4STobin Davis spec->mixers[0] = cxt5047_hp_mixers; 1291c9b443d4STobin Davis codec->patch_ops.init = cxt5047_hp_init; 1292c9b443d4STobin Davis break; 1293c9b443d4STobin Davis case CXT5047_LAPTOP_EAPD: 1294c9b443d4STobin Davis spec->num_init_verbs = 2; 1295c9b443d4STobin Davis spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1296c9b443d4STobin Davis break; 1297c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG 1298c9b443d4STobin Davis case CXT5047_TEST: 1299c9b443d4STobin Davis spec->input_mux = &cxt5047_test_capture_source; 1300c9b443d4STobin Davis spec->mixers[0] = cxt5047_test_mixer; 1301c9b443d4STobin Davis spec->init_verbs[0] = cxt5047_test_init_verbs; 1302c9b443d4STobin Davis #endif 1303c9b443d4STobin Davis } 1304c9b443d4STobin Davis return 0; 1305c9b443d4STobin Davis } 1306c9b443d4STobin Davis 1307c9b443d4STobin Davis struct hda_codec_preset snd_hda_preset_conexant[] = { 1308c9b443d4STobin Davis { .id = 0x14f15045, .name = "CXT5045", .patch = patch_cxt5045 }, 1309c9b443d4STobin Davis { .id = 0x14f15047, .name = "CXT5047", .patch = patch_cxt5047 }, 1310c9b443d4STobin Davis {} /* terminator */ 1311c9b443d4STobin Davis }; 1312