linux/sound/pci/hda/patch_realtek.c
<<
>>
Prefs
   1/*
   2 * Universal Interface for Intel High Definition Audio Codec
   3 *
   4 * HD audio interface patch for ALC 260/880/882 codecs
   5 *
   6 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
   7 *                    PeiSen Hou <pshou@realtek.com.tw>
   8 *                    Takashi Iwai <tiwai@suse.de>
   9 *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
  10 *
  11 *  This driver is free software; you can redistribute it and/or modify
  12 *  it under the terms of the GNU General Public License as published by
  13 *  the Free Software Foundation; either version 2 of the License, or
  14 *  (at your option) any later version.
  15 *
  16 *  This driver is distributed in the hope that it will be useful,
  17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 *  GNU General Public License for more details.
  20 *
  21 *  You should have received a copy of the GNU General Public License
  22 *  along with this program; if not, write to the Free Software
  23 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  24 */
  25
  26#include <linux/init.h>
  27#include <linux/delay.h>
  28#include <linux/slab.h>
  29#include <linux/pci.h>
  30#include <sound/core.h>
  31#include <sound/jack.h>
  32#include "hda_codec.h"
  33#include "hda_local.h"
  34#include "hda_beep.h"
  35
  36#define ALC880_FRONT_EVENT              0x01
  37#define ALC880_DCVOL_EVENT              0x02
  38#define ALC880_HP_EVENT                 0x04
  39#define ALC880_MIC_EVENT                0x08
  40
  41/* ALC880 board config type */
  42enum {
  43        ALC880_3ST,
  44        ALC880_3ST_DIG,
  45        ALC880_5ST,
  46        ALC880_5ST_DIG,
  47        ALC880_W810,
  48        ALC880_Z71V,
  49        ALC880_6ST,
  50        ALC880_6ST_DIG,
  51        ALC880_F1734,
  52        ALC880_ASUS,
  53        ALC880_ASUS_DIG,
  54        ALC880_ASUS_W1V,
  55        ALC880_ASUS_DIG2,
  56        ALC880_FUJITSU,
  57        ALC880_UNIWILL_DIG,
  58        ALC880_UNIWILL,
  59        ALC880_UNIWILL_P53,
  60        ALC880_CLEVO,
  61        ALC880_TCL_S700,
  62        ALC880_LG,
  63        ALC880_LG_LW,
  64        ALC880_MEDION_RIM,
  65#ifdef CONFIG_SND_DEBUG
  66        ALC880_TEST,
  67#endif
  68        ALC880_AUTO,
  69        ALC880_MODEL_LAST /* last tag */
  70};
  71
  72/* ALC260 models */
  73enum {
  74        ALC260_BASIC,
  75        ALC260_HP,
  76        ALC260_HP_DC7600,
  77        ALC260_HP_3013,
  78        ALC260_FUJITSU_S702X,
  79        ALC260_ACER,
  80        ALC260_WILL,
  81        ALC260_REPLACER_672V,
  82        ALC260_FAVORIT100,
  83#ifdef CONFIG_SND_DEBUG
  84        ALC260_TEST,
  85#endif
  86        ALC260_AUTO,
  87        ALC260_MODEL_LAST /* last tag */
  88};
  89
  90/* ALC262 models */
  91enum {
  92        ALC262_BASIC,
  93        ALC262_HIPPO,
  94        ALC262_HIPPO_1,
  95        ALC262_FUJITSU,
  96        ALC262_HP_BPC,
  97        ALC262_HP_BPC_D7000_WL,
  98        ALC262_HP_BPC_D7000_WF,
  99        ALC262_HP_TC_T5735,
 100        ALC262_HP_RP5700,
 101        ALC262_BENQ_ED8,
 102        ALC262_SONY_ASSAMD,
 103        ALC262_BENQ_T31,
 104        ALC262_ULTRA,
 105        ALC262_LENOVO_3000,
 106        ALC262_NEC,
 107        ALC262_TOSHIBA_S06,
 108        ALC262_TOSHIBA_RX1,
 109        ALC262_TYAN,
 110        ALC262_AUTO,
 111        ALC262_MODEL_LAST /* last tag */
 112};
 113
 114/* ALC268 models */
 115enum {
 116        ALC267_QUANTA_IL1,
 117        ALC268_3ST,
 118        ALC268_TOSHIBA,
 119        ALC268_ACER,
 120        ALC268_ACER_DMIC,
 121        ALC268_ACER_ASPIRE_ONE,
 122        ALC268_DELL,
 123        ALC268_ZEPTO,
 124#ifdef CONFIG_SND_DEBUG
 125        ALC268_TEST,
 126#endif
 127        ALC268_AUTO,
 128        ALC268_MODEL_LAST /* last tag */
 129};
 130
 131/* ALC269 models */
 132enum {
 133        ALC269_BASIC,
 134        ALC269_QUANTA_FL1,
 135        ALC269_AMIC,
 136        ALC269_DMIC,
 137        ALC269VB_AMIC,
 138        ALC269VB_DMIC,
 139        ALC269_FUJITSU,
 140        ALC269_LIFEBOOK,
 141        ALC271_ACER,
 142        ALC269_AUTO,
 143        ALC269_MODEL_LAST /* last tag */
 144};
 145
 146/* ALC861 models */
 147enum {
 148        ALC861_3ST,
 149        ALC660_3ST,
 150        ALC861_3ST_DIG,
 151        ALC861_6ST_DIG,
 152        ALC861_UNIWILL_M31,
 153        ALC861_TOSHIBA,
 154        ALC861_ASUS,
 155        ALC861_ASUS_LAPTOP,
 156        ALC861_AUTO,
 157        ALC861_MODEL_LAST,
 158};
 159
 160/* ALC861-VD models */
 161enum {
 162        ALC660VD_3ST,
 163        ALC660VD_3ST_DIG,
 164        ALC660VD_ASUS_V1S,
 165        ALC861VD_3ST,
 166        ALC861VD_3ST_DIG,
 167        ALC861VD_6ST_DIG,
 168        ALC861VD_LENOVO,
 169        ALC861VD_DALLAS,
 170        ALC861VD_HP,
 171        ALC861VD_AUTO,
 172        ALC861VD_MODEL_LAST,
 173};
 174
 175/* ALC662 models */
 176enum {
 177        ALC662_3ST_2ch_DIG,
 178        ALC662_3ST_6ch_DIG,
 179        ALC662_3ST_6ch,
 180        ALC662_5ST_DIG,
 181        ALC662_LENOVO_101E,
 182        ALC662_ASUS_EEEPC_P701,
 183        ALC662_ASUS_EEEPC_EP20,
 184        ALC663_ASUS_M51VA,
 185        ALC663_ASUS_G71V,
 186        ALC663_ASUS_H13,
 187        ALC663_ASUS_G50V,
 188        ALC662_ECS,
 189        ALC663_ASUS_MODE1,
 190        ALC662_ASUS_MODE2,
 191        ALC663_ASUS_MODE3,
 192        ALC663_ASUS_MODE4,
 193        ALC663_ASUS_MODE5,
 194        ALC663_ASUS_MODE6,
 195        ALC663_ASUS_MODE7,
 196        ALC663_ASUS_MODE8,
 197        ALC272_DELL,
 198        ALC272_DELL_ZM1,
 199        ALC272_SAMSUNG_NC10,
 200        ALC662_AUTO,
 201        ALC662_MODEL_LAST,
 202};
 203
 204/* ALC882 models */
 205enum {
 206        ALC882_3ST_DIG,
 207        ALC882_6ST_DIG,
 208        ALC882_ARIMA,
 209        ALC882_W2JC,
 210        ALC882_TARGA,
 211        ALC882_ASUS_A7J,
 212        ALC882_ASUS_A7M,
 213        ALC885_MACPRO,
 214        ALC885_MBA21,
 215        ALC885_MBP3,
 216        ALC885_MB5,
 217        ALC885_MACMINI3,
 218        ALC885_IMAC24,
 219        ALC885_IMAC91,
 220        ALC883_3ST_2ch_DIG,
 221        ALC883_3ST_6ch_DIG,
 222        ALC883_3ST_6ch,
 223        ALC883_6ST_DIG,
 224        ALC883_TARGA_DIG,
 225        ALC883_TARGA_2ch_DIG,
 226        ALC883_TARGA_8ch_DIG,
 227        ALC883_ACER,
 228        ALC883_ACER_ASPIRE,
 229        ALC888_ACER_ASPIRE_4930G,
 230        ALC888_ACER_ASPIRE_6530G,
 231        ALC888_ACER_ASPIRE_8930G,
 232        ALC888_ACER_ASPIRE_7730G,
 233        ALC883_MEDION,
 234        ALC883_MEDION_WIM2160,
 235        ALC883_LAPTOP_EAPD,
 236        ALC883_LENOVO_101E_2ch,
 237        ALC883_LENOVO_NB0763,
 238        ALC888_LENOVO_MS7195_DIG,
 239        ALC888_LENOVO_SKY,
 240        ALC883_HAIER_W66,
 241        ALC888_3ST_HP,
 242        ALC888_6ST_DELL,
 243        ALC883_MITAC,
 244        ALC883_CLEVO_M540R,
 245        ALC883_CLEVO_M720,
 246        ALC883_FUJITSU_PI2515,
 247        ALC888_FUJITSU_XA3530,
 248        ALC883_3ST_6ch_INTEL,
 249        ALC889A_INTEL,
 250        ALC889_INTEL,
 251        ALC888_ASUS_M90V,
 252        ALC888_ASUS_EEE1601,
 253        ALC889A_MB31,
 254        ALC1200_ASUS_P5Q,
 255        ALC883_SONY_VAIO_TT,
 256        ALC882_AUTO,
 257        ALC882_MODEL_LAST,
 258};
 259
 260/* ALC680 models */
 261enum {
 262        ALC680_BASE,
 263        ALC680_AUTO,
 264        ALC680_MODEL_LAST,
 265};
 266
 267/* for GPIO Poll */
 268#define GPIO_MASK       0x03
 269
 270/* extra amp-initialization sequence types */
 271enum {
 272        ALC_INIT_NONE,
 273        ALC_INIT_DEFAULT,
 274        ALC_INIT_GPIO1,
 275        ALC_INIT_GPIO2,
 276        ALC_INIT_GPIO3,
 277};
 278
 279struct alc_mic_route {
 280        hda_nid_t pin;
 281        unsigned char mux_idx;
 282        unsigned char amix_idx;
 283};
 284
 285#define MUX_IDX_UNDEF   ((unsigned char)-1)
 286
 287struct alc_customize_define {
 288        unsigned int  sku_cfg;
 289        unsigned char port_connectivity;
 290        unsigned char check_sum;
 291        unsigned char customization;
 292        unsigned char external_amp;
 293        unsigned int  enable_pcbeep:1;
 294        unsigned int  platform_type:1;
 295        unsigned int  swap:1;
 296        unsigned int  override:1;
 297        unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
 298};
 299
 300struct alc_fixup;
 301
 302struct alc_spec {
 303        /* codec parameterization */
 304        struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
 305        unsigned int num_mixers;
 306        struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
 307        unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
 308
 309        const struct hda_verb *init_verbs[10];  /* initialization verbs
 310                                                 * don't forget NULL
 311                                                 * termination!
 312                                                 */
 313        unsigned int num_init_verbs;
 314
 315        char stream_name_analog[32];    /* analog PCM stream */
 316        struct hda_pcm_stream *stream_analog_playback;
 317        struct hda_pcm_stream *stream_analog_capture;
 318        struct hda_pcm_stream *stream_analog_alt_playback;
 319        struct hda_pcm_stream *stream_analog_alt_capture;
 320
 321        char stream_name_digital[32];   /* digital PCM stream */
 322        struct hda_pcm_stream *stream_digital_playback;
 323        struct hda_pcm_stream *stream_digital_capture;
 324
 325        /* playback */
 326        struct hda_multi_out multiout;  /* playback set-up
 327                                         * max_channels, dacs must be set
 328                                         * dig_out_nid and hp_nid are optional
 329                                         */
 330        hda_nid_t alt_dac_nid;
 331        hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
 332        int dig_out_type;
 333
 334        /* capture */
 335        unsigned int num_adc_nids;
 336        hda_nid_t *adc_nids;
 337        hda_nid_t *capsrc_nids;
 338        hda_nid_t dig_in_nid;           /* digital-in NID; optional */
 339
 340        /* capture setup for dynamic dual-adc switch */
 341        unsigned int cur_adc_idx;
 342        hda_nid_t cur_adc;
 343        unsigned int cur_adc_stream_tag;
 344        unsigned int cur_adc_format;
 345
 346        /* capture source */
 347        unsigned int num_mux_defs;
 348        const struct hda_input_mux *input_mux;
 349        unsigned int cur_mux[3];
 350        struct alc_mic_route ext_mic;
 351        struct alc_mic_route int_mic;
 352
 353        /* channel model */
 354        const struct hda_channel_mode *channel_mode;
 355        int num_channel_mode;
 356        int need_dac_fix;
 357        int const_channel_count;
 358        int ext_channel_count;
 359
 360        /* PCM information */
 361        struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
 362
 363        /* dynamic controls, init_verbs and input_mux */
 364        struct auto_pin_cfg autocfg;
 365        struct alc_customize_define cdefine;
 366        struct snd_array kctls;
 367        struct hda_input_mux private_imux[3];
 368        hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
 369        hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
 370        hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
 371
 372        /* hooks */
 373        void (*init_hook)(struct hda_codec *codec);
 374        void (*unsol_event)(struct hda_codec *codec, unsigned int res);
 375#ifdef CONFIG_SND_HDA_POWER_SAVE
 376        void (*power_hook)(struct hda_codec *codec);
 377#endif
 378
 379        /* for pin sensing */
 380        unsigned int sense_updated: 1;
 381        unsigned int jack_present: 1;
 382        unsigned int master_sw: 1;
 383        unsigned int auto_mic:1;
 384
 385        /* other flags */
 386        unsigned int no_analog :1; /* digital I/O only */
 387        unsigned int dual_adc_switch:1; /* switch ADCs (for ALC275) */
 388        unsigned int single_input_src:1;
 389        int init_amp;
 390        int codec_variant;      /* flag for other variants */
 391
 392        /* for virtual master */
 393        hda_nid_t vmaster_nid;
 394#ifdef CONFIG_SND_HDA_POWER_SAVE
 395        struct hda_loopback_check loopback;
 396#endif
 397
 398        /* for PLL fix */
 399        hda_nid_t pll_nid;
 400        unsigned int pll_coef_idx, pll_coef_bit;
 401
 402        /* fix-up list */
 403        int fixup_id;
 404        const struct alc_fixup *fixup_list;
 405        const char *fixup_name;
 406};
 407
 408/*
 409 * configuration template - to be copied to the spec instance
 410 */
 411struct alc_config_preset {
 412        struct snd_kcontrol_new *mixers[5]; /* should be identical size
 413                                             * with spec
 414                                             */
 415        struct snd_kcontrol_new *cap_mixer; /* capture mixer */
 416        const struct hda_verb *init_verbs[5];
 417        unsigned int num_dacs;
 418        hda_nid_t *dac_nids;
 419        hda_nid_t dig_out_nid;          /* optional */
 420        hda_nid_t hp_nid;               /* optional */
 421        hda_nid_t *slave_dig_outs;
 422        unsigned int num_adc_nids;
 423        hda_nid_t *adc_nids;
 424        hda_nid_t *capsrc_nids;
 425        hda_nid_t dig_in_nid;
 426        unsigned int num_channel_mode;
 427        const struct hda_channel_mode *channel_mode;
 428        int need_dac_fix;
 429        int const_channel_count;
 430        unsigned int num_mux_defs;
 431        const struct hda_input_mux *input_mux;
 432        void (*unsol_event)(struct hda_codec *, unsigned int);
 433        void (*setup)(struct hda_codec *);
 434        void (*init_hook)(struct hda_codec *);
 435#ifdef CONFIG_SND_HDA_POWER_SAVE
 436        struct hda_amp_list *loopbacks;
 437        void (*power_hook)(struct hda_codec *codec);
 438#endif
 439};
 440
 441
 442/*
 443 * input MUX handling
 444 */
 445static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
 446                             struct snd_ctl_elem_info *uinfo)
 447{
 448        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 449        struct alc_spec *spec = codec->spec;
 450        unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
 451        if (mux_idx >= spec->num_mux_defs)
 452                mux_idx = 0;
 453        if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
 454                mux_idx = 0;
 455        return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
 456}
 457
 458static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
 459                            struct snd_ctl_elem_value *ucontrol)
 460{
 461        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 462        struct alc_spec *spec = codec->spec;
 463        unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
 464
 465        ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
 466        return 0;
 467}
 468
 469static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
 470                            struct snd_ctl_elem_value *ucontrol)
 471{
 472        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 473        struct alc_spec *spec = codec->spec;
 474        const struct hda_input_mux *imux;
 475        unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
 476        unsigned int mux_idx;
 477        hda_nid_t nid = spec->capsrc_nids ?
 478                spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
 479        unsigned int type;
 480
 481        mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
 482        imux = &spec->input_mux[mux_idx];
 483        if (!imux->num_items && mux_idx > 0)
 484                imux = &spec->input_mux[0];
 485
 486        type = get_wcaps_type(get_wcaps(codec, nid));
 487        if (type == AC_WID_AUD_MIX) {
 488                /* Matrix-mixer style (e.g. ALC882) */
 489                unsigned int *cur_val = &spec->cur_mux[adc_idx];
 490                unsigned int i, idx;
 491
 492                idx = ucontrol->value.enumerated.item[0];
 493                if (idx >= imux->num_items)
 494                        idx = imux->num_items - 1;
 495                if (*cur_val == idx)
 496                        return 0;
 497                for (i = 0; i < imux->num_items; i++) {
 498                        unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
 499                        snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
 500                                                 imux->items[i].index,
 501                                                 HDA_AMP_MUTE, v);
 502                }
 503                *cur_val = idx;
 504                return 1;
 505        } else {
 506                /* MUX style (e.g. ALC880) */
 507                return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
 508                                             &spec->cur_mux[adc_idx]);
 509        }
 510}
 511
 512/*
 513 * channel mode setting
 514 */
 515static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
 516                            struct snd_ctl_elem_info *uinfo)
 517{
 518        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 519        struct alc_spec *spec = codec->spec;
 520        return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
 521                                    spec->num_channel_mode);
 522}
 523
 524static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
 525                           struct snd_ctl_elem_value *ucontrol)
 526{
 527        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 528        struct alc_spec *spec = codec->spec;
 529        return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
 530                                   spec->num_channel_mode,
 531                                   spec->ext_channel_count);
 532}
 533
 534static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
 535                           struct snd_ctl_elem_value *ucontrol)
 536{
 537        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 538        struct alc_spec *spec = codec->spec;
 539        int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
 540                                      spec->num_channel_mode,
 541                                      &spec->ext_channel_count);
 542        if (err >= 0 && !spec->const_channel_count) {
 543                spec->multiout.max_channels = spec->ext_channel_count;
 544                if (spec->need_dac_fix)
 545                        spec->multiout.num_dacs = spec->multiout.max_channels / 2;
 546        }
 547        return err;
 548}
 549
 550/*
 551 * Control the mode of pin widget settings via the mixer.  "pc" is used
 552 * instead of "%" to avoid consequences of accidentally treating the % as
 553 * being part of a format specifier.  Maximum allowed length of a value is
 554 * 63 characters plus NULL terminator.
 555 *
 556 * Note: some retasking pin complexes seem to ignore requests for input
 557 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
 558 * are requested.  Therefore order this list so that this behaviour will not
 559 * cause problems when mixer clients move through the enum sequentially.
 560 * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
 561 * March 2006.
 562 */
 563static char *alc_pin_mode_names[] = {
 564        "Mic 50pc bias", "Mic 80pc bias",
 565        "Line in", "Line out", "Headphone out",
 566};
 567static unsigned char alc_pin_mode_values[] = {
 568        PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
 569};
 570/* The control can present all 5 options, or it can limit the options based
 571 * in the pin being assumed to be exclusively an input or an output pin.  In
 572 * addition, "input" pins may or may not process the mic bias option
 573 * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
 574 * accept requests for bias as of chip versions up to March 2006) and/or
 575 * wiring in the computer.
 576 */
 577#define ALC_PIN_DIR_IN              0x00
 578#define ALC_PIN_DIR_OUT             0x01
 579#define ALC_PIN_DIR_INOUT           0x02
 580#define ALC_PIN_DIR_IN_NOMICBIAS    0x03
 581#define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
 582
 583/* Info about the pin modes supported by the different pin direction modes.
 584 * For each direction the minimum and maximum values are given.
 585 */
 586static signed char alc_pin_mode_dir_info[5][2] = {
 587        { 0, 2 },    /* ALC_PIN_DIR_IN */
 588        { 3, 4 },    /* ALC_PIN_DIR_OUT */
 589        { 0, 4 },    /* ALC_PIN_DIR_INOUT */
 590        { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
 591        { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
 592};
 593#define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
 594#define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
 595#define alc_pin_mode_n_items(_dir) \
 596        (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
 597
 598static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
 599                             struct snd_ctl_elem_info *uinfo)
 600{
 601        unsigned int item_num = uinfo->value.enumerated.item;
 602        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
 603
 604        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
 605        uinfo->count = 1;
 606        uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
 607
 608        if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
 609                item_num = alc_pin_mode_min(dir);
 610        strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
 611        return 0;
 612}
 613
 614static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
 615                            struct snd_ctl_elem_value *ucontrol)
 616{
 617        unsigned int i;
 618        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 619        hda_nid_t nid = kcontrol->private_value & 0xffff;
 620        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
 621        long *valp = ucontrol->value.integer.value;
 622        unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
 623                                                 AC_VERB_GET_PIN_WIDGET_CONTROL,
 624                                                 0x00);
 625
 626        /* Find enumerated value for current pinctl setting */
 627        i = alc_pin_mode_min(dir);
 628        while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
 629                i++;
 630        *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
 631        return 0;
 632}
 633
 634static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
 635                            struct snd_ctl_elem_value *ucontrol)
 636{
 637        signed int change;
 638        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 639        hda_nid_t nid = kcontrol->private_value & 0xffff;
 640        unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
 641        long val = *ucontrol->value.integer.value;
 642        unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
 643                                                 AC_VERB_GET_PIN_WIDGET_CONTROL,
 644                                                 0x00);
 645
 646        if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
 647                val = alc_pin_mode_min(dir);
 648
 649        change = pinctl != alc_pin_mode_values[val];
 650        if (change) {
 651                /* Set pin mode to that requested */
 652                snd_hda_codec_write_cache(codec, nid, 0,
 653                                          AC_VERB_SET_PIN_WIDGET_CONTROL,
 654                                          alc_pin_mode_values[val]);
 655
 656                /* Also enable the retasking pin's input/output as required
 657                 * for the requested pin mode.  Enum values of 2 or less are
 658                 * input modes.
 659                 *
 660                 * Dynamically switching the input/output buffers probably
 661                 * reduces noise slightly (particularly on input) so we'll
 662                 * do it.  However, having both input and output buffers
 663                 * enabled simultaneously doesn't seem to be problematic if
 664                 * this turns out to be necessary in the future.
 665                 */
 666                if (val <= 2) {
 667                        snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
 668                                                 HDA_AMP_MUTE, HDA_AMP_MUTE);
 669                        snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
 670                                                 HDA_AMP_MUTE, 0);
 671                } else {
 672                        snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
 673                                                 HDA_AMP_MUTE, HDA_AMP_MUTE);
 674                        snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
 675                                                 HDA_AMP_MUTE, 0);
 676                }
 677        }
 678        return change;
 679}
 680
 681#define ALC_PIN_MODE(xname, nid, dir) \
 682        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 683          .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
 684          .info = alc_pin_mode_info, \
 685          .get = alc_pin_mode_get, \
 686          .put = alc_pin_mode_put, \
 687          .private_value = nid | (dir<<16) }
 688
 689/* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
 690 * together using a mask with more than one bit set.  This control is
 691 * currently used only by the ALC260 test model.  At this stage they are not
 692 * needed for any "production" models.
 693 */
 694#ifdef CONFIG_SND_DEBUG
 695#define alc_gpio_data_info      snd_ctl_boolean_mono_info
 696
 697static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
 698                             struct snd_ctl_elem_value *ucontrol)
 699{
 700        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 701        hda_nid_t nid = kcontrol->private_value & 0xffff;
 702        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 703        long *valp = ucontrol->value.integer.value;
 704        unsigned int val = snd_hda_codec_read(codec, nid, 0,
 705                                              AC_VERB_GET_GPIO_DATA, 0x00);
 706
 707        *valp = (val & mask) != 0;
 708        return 0;
 709}
 710static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
 711                             struct snd_ctl_elem_value *ucontrol)
 712{
 713        signed int change;
 714        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 715        hda_nid_t nid = kcontrol->private_value & 0xffff;
 716        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 717        long val = *ucontrol->value.integer.value;
 718        unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
 719                                                    AC_VERB_GET_GPIO_DATA,
 720                                                    0x00);
 721
 722        /* Set/unset the masked GPIO bit(s) as needed */
 723        change = (val == 0 ? 0 : mask) != (gpio_data & mask);
 724        if (val == 0)
 725                gpio_data &= ~mask;
 726        else
 727                gpio_data |= mask;
 728        snd_hda_codec_write_cache(codec, nid, 0,
 729                                  AC_VERB_SET_GPIO_DATA, gpio_data);
 730
 731        return change;
 732}
 733#define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
 734        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 735          .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
 736          .info = alc_gpio_data_info, \
 737          .get = alc_gpio_data_get, \
 738          .put = alc_gpio_data_put, \
 739          .private_value = nid | (mask<<16) }
 740#endif   /* CONFIG_SND_DEBUG */
 741
 742/* A switch control to allow the enabling of the digital IO pins on the
 743 * ALC260.  This is incredibly simplistic; the intention of this control is
 744 * to provide something in the test model allowing digital outputs to be
 745 * identified if present.  If models are found which can utilise these
 746 * outputs a more complete mixer control can be devised for those models if
 747 * necessary.
 748 */
 749#ifdef CONFIG_SND_DEBUG
 750#define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
 751
 752static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
 753                              struct snd_ctl_elem_value *ucontrol)
 754{
 755        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 756        hda_nid_t nid = kcontrol->private_value & 0xffff;
 757        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 758        long *valp = ucontrol->value.integer.value;
 759        unsigned int val = snd_hda_codec_read(codec, nid, 0,
 760                                              AC_VERB_GET_DIGI_CONVERT_1, 0x00);
 761
 762        *valp = (val & mask) != 0;
 763        return 0;
 764}
 765static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
 766                              struct snd_ctl_elem_value *ucontrol)
 767{
 768        signed int change;
 769        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 770        hda_nid_t nid = kcontrol->private_value & 0xffff;
 771        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 772        long val = *ucontrol->value.integer.value;
 773        unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
 774                                                    AC_VERB_GET_DIGI_CONVERT_1,
 775                                                    0x00);
 776
 777        /* Set/unset the masked control bit(s) as needed */
 778        change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
 779        if (val==0)
 780                ctrl_data &= ~mask;
 781        else
 782                ctrl_data |= mask;
 783        snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
 784                                  ctrl_data);
 785
 786        return change;
 787}
 788#define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
 789        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 790          .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
 791          .info = alc_spdif_ctrl_info, \
 792          .get = alc_spdif_ctrl_get, \
 793          .put = alc_spdif_ctrl_put, \
 794          .private_value = nid | (mask<<16) }
 795#endif   /* CONFIG_SND_DEBUG */
 796
 797/* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
 798 * Again, this is only used in the ALC26x test models to help identify when
 799 * the EAPD line must be asserted for features to work.
 800 */
 801#ifdef CONFIG_SND_DEBUG
 802#define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
 803
 804static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
 805                              struct snd_ctl_elem_value *ucontrol)
 806{
 807        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 808        hda_nid_t nid = kcontrol->private_value & 0xffff;
 809        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 810        long *valp = ucontrol->value.integer.value;
 811        unsigned int val = snd_hda_codec_read(codec, nid, 0,
 812                                              AC_VERB_GET_EAPD_BTLENABLE, 0x00);
 813
 814        *valp = (val & mask) != 0;
 815        return 0;
 816}
 817
 818static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
 819                              struct snd_ctl_elem_value *ucontrol)
 820{
 821        int change;
 822        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 823        hda_nid_t nid = kcontrol->private_value & 0xffff;
 824        unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
 825        long val = *ucontrol->value.integer.value;
 826        unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
 827                                                    AC_VERB_GET_EAPD_BTLENABLE,
 828                                                    0x00);
 829
 830        /* Set/unset the masked control bit(s) as needed */
 831        change = (!val ? 0 : mask) != (ctrl_data & mask);
 832        if (!val)
 833                ctrl_data &= ~mask;
 834        else
 835                ctrl_data |= mask;
 836        snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
 837                                  ctrl_data);
 838
 839        return change;
 840}
 841
 842#define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
 843        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
 844          .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
 845          .info = alc_eapd_ctrl_info, \
 846          .get = alc_eapd_ctrl_get, \
 847          .put = alc_eapd_ctrl_put, \
 848          .private_value = nid | (mask<<16) }
 849#endif   /* CONFIG_SND_DEBUG */
 850
 851/*
 852 * set up the input pin config (depending on the given auto-pin type)
 853 */
 854static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
 855                              int auto_pin_type)
 856{
 857        unsigned int val = PIN_IN;
 858
 859        if (auto_pin_type == AUTO_PIN_MIC) {
 860                unsigned int pincap;
 861                unsigned int oldval;
 862                oldval = snd_hda_codec_read(codec, nid, 0,
 863                                            AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
 864                pincap = snd_hda_query_pin_caps(codec, nid);
 865                pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
 866                /* if the default pin setup is vref50, we give it priority */
 867                if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
 868                        val = PIN_VREF80;
 869                else if (pincap & AC_PINCAP_VREF_50)
 870                        val = PIN_VREF50;
 871                else if (pincap & AC_PINCAP_VREF_100)
 872                        val = PIN_VREF100;
 873                else if (pincap & AC_PINCAP_VREF_GRD)
 874                        val = PIN_VREFGRD;
 875        }
 876        snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
 877}
 878
 879static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
 880{
 881        struct alc_spec *spec = codec->spec;
 882        struct auto_pin_cfg *cfg = &spec->autocfg;
 883
 884        if (!cfg->line_outs) {
 885                while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
 886                       cfg->line_out_pins[cfg->line_outs])
 887                        cfg->line_outs++;
 888        }
 889        if (!cfg->speaker_outs) {
 890                while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
 891                       cfg->speaker_pins[cfg->speaker_outs])
 892                        cfg->speaker_outs++;
 893        }
 894        if (!cfg->hp_outs) {
 895                while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
 896                       cfg->hp_pins[cfg->hp_outs])
 897                        cfg->hp_outs++;
 898        }
 899}
 900
 901/*
 902 */
 903static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
 904{
 905        if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
 906                return;
 907        spec->mixers[spec->num_mixers++] = mix;
 908}
 909
 910static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
 911{
 912        if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
 913                return;
 914        spec->init_verbs[spec->num_init_verbs++] = verb;
 915}
 916
 917/*
 918 * set up from the preset table
 919 */
 920static void setup_preset(struct hda_codec *codec,
 921                         const struct alc_config_preset *preset)
 922{
 923        struct alc_spec *spec = codec->spec;
 924        int i;
 925
 926        for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
 927                add_mixer(spec, preset->mixers[i]);
 928        spec->cap_mixer = preset->cap_mixer;
 929        for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
 930             i++)
 931                add_verb(spec, preset->init_verbs[i]);
 932
 933        spec->channel_mode = preset->channel_mode;
 934        spec->num_channel_mode = preset->num_channel_mode;
 935        spec->need_dac_fix = preset->need_dac_fix;
 936        spec->const_channel_count = preset->const_channel_count;
 937
 938        if (preset->const_channel_count)
 939                spec->multiout.max_channels = preset->const_channel_count;
 940        else
 941                spec->multiout.max_channels = spec->channel_mode[0].channels;
 942        spec->ext_channel_count = spec->channel_mode[0].channels;
 943
 944        spec->multiout.num_dacs = preset->num_dacs;
 945        spec->multiout.dac_nids = preset->dac_nids;
 946        spec->multiout.dig_out_nid = preset->dig_out_nid;
 947        spec->multiout.slave_dig_outs = preset->slave_dig_outs;
 948        spec->multiout.hp_nid = preset->hp_nid;
 949
 950        spec->num_mux_defs = preset->num_mux_defs;
 951        if (!spec->num_mux_defs)
 952                spec->num_mux_defs = 1;
 953        spec->input_mux = preset->input_mux;
 954
 955        spec->num_adc_nids = preset->num_adc_nids;
 956        spec->adc_nids = preset->adc_nids;
 957        spec->capsrc_nids = preset->capsrc_nids;
 958        spec->dig_in_nid = preset->dig_in_nid;
 959
 960        spec->unsol_event = preset->unsol_event;
 961        spec->init_hook = preset->init_hook;
 962#ifdef CONFIG_SND_HDA_POWER_SAVE
 963        spec->power_hook = preset->power_hook;
 964        spec->loopback.amplist = preset->loopbacks;
 965#endif
 966
 967        if (preset->setup)
 968                preset->setup(codec);
 969
 970        alc_fixup_autocfg_pin_nums(codec);
 971}
 972
 973/* Enable GPIO mask and set output */
 974static struct hda_verb alc_gpio1_init_verbs[] = {
 975        {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
 976        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
 977        {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
 978        { }
 979};
 980
 981static struct hda_verb alc_gpio2_init_verbs[] = {
 982        {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
 983        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
 984        {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
 985        { }
 986};
 987
 988static struct hda_verb alc_gpio3_init_verbs[] = {
 989        {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
 990        {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
 991        {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
 992        { }
 993};
 994
 995/*
 996 * Fix hardware PLL issue
 997 * On some codecs, the analog PLL gating control must be off while
 998 * the default value is 1.
 999 */
1000static void alc_fix_pll(struct hda_codec *codec)
1001{
1002        struct alc_spec *spec = codec->spec;
1003        unsigned int val;
1004
1005        if (!spec->pll_nid)
1006                return;
1007        snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1008                            spec->pll_coef_idx);
1009        val = snd_hda_codec_read(codec, spec->pll_nid, 0,
1010                                 AC_VERB_GET_PROC_COEF, 0);
1011        snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1012                            spec->pll_coef_idx);
1013        snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
1014                            val & ~(1 << spec->pll_coef_bit));
1015}
1016
1017static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
1018                             unsigned int coef_idx, unsigned int coef_bit)
1019{
1020        struct alc_spec *spec = codec->spec;
1021        spec->pll_nid = nid;
1022        spec->pll_coef_idx = coef_idx;
1023        spec->pll_coef_bit = coef_bit;
1024        alc_fix_pll(codec);
1025}
1026
1027static int alc_init_jacks(struct hda_codec *codec)
1028{
1029#ifdef CONFIG_SND_HDA_INPUT_JACK
1030        struct alc_spec *spec = codec->spec;
1031        int err;
1032        unsigned int hp_nid = spec->autocfg.hp_pins[0];
1033        unsigned int mic_nid = spec->ext_mic.pin;
1034
1035        if (hp_nid) {
1036                err = snd_hda_input_jack_add(codec, hp_nid,
1037                                             SND_JACK_HEADPHONE, NULL);
1038                if (err < 0)
1039                        return err;
1040                snd_hda_input_jack_report(codec, hp_nid);
1041        }
1042
1043        if (mic_nid) {
1044                err = snd_hda_input_jack_add(codec, mic_nid,
1045                                             SND_JACK_MICROPHONE, NULL);
1046                if (err < 0)
1047                        return err;
1048                snd_hda_input_jack_report(codec, mic_nid);
1049        }
1050#endif /* CONFIG_SND_HDA_INPUT_JACK */
1051        return 0;
1052}
1053
1054static void alc_automute_speaker(struct hda_codec *codec, int pinctl)
1055{
1056        struct alc_spec *spec = codec->spec;
1057        unsigned int mute;
1058        hda_nid_t nid;
1059        int i;
1060
1061        spec->jack_present = 0;
1062        for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1063                nid = spec->autocfg.hp_pins[i];
1064                if (!nid)
1065                        break;
1066                snd_hda_input_jack_report(codec, nid);
1067                spec->jack_present |= snd_hda_jack_detect(codec, nid);
1068        }
1069
1070        mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1071        /* Toggle internal speakers muting */
1072        for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1073                nid = spec->autocfg.speaker_pins[i];
1074                if (!nid)
1075                        break;
1076                if (pinctl) {
1077                        snd_hda_codec_write(codec, nid, 0,
1078                                    AC_VERB_SET_PIN_WIDGET_CONTROL,
1079                                    spec->jack_present ? 0 : PIN_OUT);
1080                } else {
1081                        snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1082                                         HDA_AMP_MUTE, mute);
1083                }
1084        }
1085}
1086
1087static void alc_automute_pin(struct hda_codec *codec)
1088{
1089        alc_automute_speaker(codec, 1);
1090}
1091
1092static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1093                                hda_nid_t nid)
1094{
1095        hda_nid_t conn[HDA_MAX_NUM_INPUTS];
1096        int i, nums;
1097
1098        nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
1099        for (i = 0; i < nums; i++)
1100                if (conn[i] == nid)
1101                        return i;
1102        return -1;
1103}
1104
1105/* switch the current ADC according to the jack state */
1106static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
1107{
1108        struct alc_spec *spec = codec->spec;
1109        unsigned int present;
1110        hda_nid_t new_adc;
1111
1112        present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1113        if (present)
1114                spec->cur_adc_idx = 1;
1115        else
1116                spec->cur_adc_idx = 0;
1117        new_adc = spec->adc_nids[spec->cur_adc_idx];
1118        if (spec->cur_adc && spec->cur_adc != new_adc) {
1119                /* stream is running, let's swap the current ADC */
1120                __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1121                spec->cur_adc = new_adc;
1122                snd_hda_codec_setup_stream(codec, new_adc,
1123                                           spec->cur_adc_stream_tag, 0,
1124                                           spec->cur_adc_format);
1125        }
1126}
1127
1128static void alc_mic_automute(struct hda_codec *codec)
1129{
1130        struct alc_spec *spec = codec->spec;
1131        struct alc_mic_route *dead, *alive;
1132        unsigned int present, type;
1133        hda_nid_t cap_nid;
1134
1135        if (!spec->auto_mic)
1136                return;
1137        if (!spec->int_mic.pin || !spec->ext_mic.pin)
1138                return;
1139        if (snd_BUG_ON(!spec->adc_nids))
1140                return;
1141
1142        if (spec->dual_adc_switch) {
1143                alc_dual_mic_adc_auto_switch(codec);
1144                return;
1145        }
1146
1147        cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1148
1149        present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1150        if (present) {
1151                alive = &spec->ext_mic;
1152                dead = &spec->int_mic;
1153        } else {
1154                alive = &spec->int_mic;
1155                dead = &spec->ext_mic;
1156        }
1157
1158        type = get_wcaps_type(get_wcaps(codec, cap_nid));
1159        if (type == AC_WID_AUD_MIX) {
1160                /* Matrix-mixer style (e.g. ALC882) */
1161                snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1162                                         alive->mux_idx,
1163                                         HDA_AMP_MUTE, 0);
1164                snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1165                                         dead->mux_idx,
1166                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
1167        } else {
1168                /* MUX style (e.g. ALC880) */
1169                snd_hda_codec_write_cache(codec, cap_nid, 0,
1170                                          AC_VERB_SET_CONNECT_SEL,
1171                                          alive->mux_idx);
1172        }
1173        snd_hda_input_jack_report(codec, spec->ext_mic.pin);
1174
1175        /* FIXME: analog mixer */
1176}
1177
1178/* unsolicited event for HP jack sensing */
1179static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1180{
1181        if (codec->vendor_id == 0x10ec0880)
1182                res >>= 28;
1183        else
1184                res >>= 26;
1185        switch (res) {
1186        case ALC880_HP_EVENT:
1187                alc_automute_pin(codec);
1188                break;
1189        case ALC880_MIC_EVENT:
1190                alc_mic_automute(codec);
1191                break;
1192        }
1193}
1194
1195static void alc_inithook(struct hda_codec *codec)
1196{
1197        alc_automute_pin(codec);
1198        alc_mic_automute(codec);
1199}
1200
1201/* additional initialization for ALC888 variants */
1202static void alc888_coef_init(struct hda_codec *codec)
1203{
1204        unsigned int tmp;
1205
1206        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1207        tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1208        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1209        if ((tmp & 0xf0) == 0x20)
1210                /* alc888S-VC */
1211                snd_hda_codec_read(codec, 0x20, 0,
1212                                   AC_VERB_SET_PROC_COEF, 0x830);
1213         else
1214                 /* alc888-VB */
1215                 snd_hda_codec_read(codec, 0x20, 0,
1216                                    AC_VERB_SET_PROC_COEF, 0x3030);
1217}
1218
1219static void alc889_coef_init(struct hda_codec *codec)
1220{
1221        unsigned int tmp;
1222
1223        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1224        tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1225        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1226        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1227}
1228
1229/* turn on/off EAPD control (only if available) */
1230static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1231{
1232        if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1233                return;
1234        if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1235                snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1236                                    on ? 2 : 0);
1237}
1238
1239static void alc_auto_init_amp(struct hda_codec *codec, int type)
1240{
1241        unsigned int tmp;
1242
1243        switch (type) {
1244        case ALC_INIT_GPIO1:
1245                snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1246                break;
1247        case ALC_INIT_GPIO2:
1248                snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1249                break;
1250        case ALC_INIT_GPIO3:
1251                snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1252                break;
1253        case ALC_INIT_DEFAULT:
1254                switch (codec->vendor_id) {
1255                case 0x10ec0260:
1256                        set_eapd(codec, 0x0f, 1);
1257                        set_eapd(codec, 0x10, 1);
1258                        break;
1259                case 0x10ec0262:
1260                case 0x10ec0267:
1261                case 0x10ec0268:
1262                case 0x10ec0269:
1263                case 0x10ec0270:
1264                case 0x10ec0272:
1265                case 0x10ec0660:
1266                case 0x10ec0662:
1267                case 0x10ec0663:
1268                case 0x10ec0665:
1269                case 0x10ec0862:
1270                case 0x10ec0889:
1271                        set_eapd(codec, 0x14, 1);
1272                        set_eapd(codec, 0x15, 1);
1273                        break;
1274                }
1275                switch (codec->vendor_id) {
1276                case 0x10ec0260:
1277                        snd_hda_codec_write(codec, 0x1a, 0,
1278                                            AC_VERB_SET_COEF_INDEX, 7);
1279                        tmp = snd_hda_codec_read(codec, 0x1a, 0,
1280                                                 AC_VERB_GET_PROC_COEF, 0);
1281                        snd_hda_codec_write(codec, 0x1a, 0,
1282                                            AC_VERB_SET_COEF_INDEX, 7);
1283                        snd_hda_codec_write(codec, 0x1a, 0,
1284                                            AC_VERB_SET_PROC_COEF,
1285                                            tmp | 0x2010);
1286                        break;
1287                case 0x10ec0262:
1288                case 0x10ec0880:
1289                case 0x10ec0882:
1290                case 0x10ec0883:
1291                case 0x10ec0885:
1292                case 0x10ec0887:
1293                /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
1294                        alc889_coef_init(codec);
1295                        break;
1296                case 0x10ec0888:
1297                        alc888_coef_init(codec);
1298                        break;
1299#if 0 /* XXX: This may cause the silent output on speaker on some machines */
1300                case 0x10ec0267:
1301                case 0x10ec0268:
1302                        snd_hda_codec_write(codec, 0x20, 0,
1303                                            AC_VERB_SET_COEF_INDEX, 7);
1304                        tmp = snd_hda_codec_read(codec, 0x20, 0,
1305                                                 AC_VERB_GET_PROC_COEF, 0);
1306                        snd_hda_codec_write(codec, 0x20, 0,
1307                                            AC_VERB_SET_COEF_INDEX, 7);
1308                        snd_hda_codec_write(codec, 0x20, 0,
1309                                            AC_VERB_SET_PROC_COEF,
1310                                            tmp | 0x3000);
1311                        break;
1312#endif /* XXX */
1313                }
1314                break;
1315        }
1316}
1317
1318static void alc_init_auto_hp(struct hda_codec *codec)
1319{
1320        struct alc_spec *spec = codec->spec;
1321        struct auto_pin_cfg *cfg = &spec->autocfg;
1322        int i;
1323
1324        if (!cfg->hp_pins[0]) {
1325                if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1326                        return;
1327        }
1328
1329        if (!cfg->speaker_pins[0]) {
1330                if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1331                        return;
1332                memcpy(cfg->speaker_pins, cfg->line_out_pins,
1333                       sizeof(cfg->speaker_pins));
1334                cfg->speaker_outs = cfg->line_outs;
1335        }
1336
1337        if (!cfg->hp_pins[0]) {
1338                memcpy(cfg->hp_pins, cfg->line_out_pins,
1339                       sizeof(cfg->hp_pins));
1340                cfg->hp_outs = cfg->line_outs;
1341        }
1342
1343        for (i = 0; i < cfg->hp_outs; i++) {
1344                snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1345                            cfg->hp_pins[i]);
1346                snd_hda_codec_write_cache(codec, cfg->hp_pins[i], 0,
1347                                  AC_VERB_SET_UNSOLICITED_ENABLE,
1348                                  AC_USRSP_EN | ALC880_HP_EVENT);
1349        }
1350        spec->unsol_event = alc_sku_unsol_event;
1351}
1352
1353static void alc_init_auto_mic(struct hda_codec *codec)
1354{
1355        struct alc_spec *spec = codec->spec;
1356        struct auto_pin_cfg *cfg = &spec->autocfg;
1357        hda_nid_t fixed, ext;
1358        int i;
1359
1360        /* there must be only two mic inputs exclusively */
1361        for (i = 0; i < cfg->num_inputs; i++)
1362                if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
1363                        return;
1364
1365        fixed = ext = 0;
1366        for (i = 0; i < cfg->num_inputs; i++) {
1367                hda_nid_t nid = cfg->inputs[i].pin;
1368                unsigned int defcfg;
1369                defcfg = snd_hda_codec_get_pincfg(codec, nid);
1370                switch (snd_hda_get_input_pin_attr(defcfg)) {
1371                case INPUT_PIN_ATTR_INT:
1372                        if (fixed)
1373                                return; /* already occupied */
1374                        fixed = nid;
1375                        break;
1376                case INPUT_PIN_ATTR_UNUSED:
1377                        return; /* invalid entry */
1378                default:
1379                        if (ext)
1380                                return; /* already occupied */
1381                        ext = nid;
1382                        break;
1383                }
1384        }
1385        if (!ext || !fixed)
1386                return;
1387        if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1388                return; /* no unsol support */
1389        snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1390                    ext, fixed);
1391        spec->ext_mic.pin = ext;
1392        spec->int_mic.pin = fixed;
1393        spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1394        spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1395        spec->auto_mic = 1;
1396        snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1397                                  AC_VERB_SET_UNSOLICITED_ENABLE,
1398                                  AC_USRSP_EN | ALC880_MIC_EVENT);
1399        spec->unsol_event = alc_sku_unsol_event;
1400}
1401
1402/* Could be any non-zero and even value. When used as fixup, tells
1403 * the driver to ignore any present sku defines.
1404 */
1405#define ALC_FIXUP_SKU_IGNORE (2)
1406
1407static int alc_auto_parse_customize_define(struct hda_codec *codec)
1408{
1409        unsigned int ass, tmp, i;
1410        unsigned nid = 0;
1411        struct alc_spec *spec = codec->spec;
1412
1413        spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1414
1415        if (spec->cdefine.fixup) {
1416                ass = spec->cdefine.sku_cfg;
1417                if (ass == ALC_FIXUP_SKU_IGNORE)
1418                        return -1;
1419                goto do_sku;
1420        }
1421
1422        ass = codec->subsystem_id & 0xffff;
1423        if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1424                goto do_sku;
1425
1426        nid = 0x1d;
1427        if (codec->vendor_id == 0x10ec0260)
1428                nid = 0x17;
1429        ass = snd_hda_codec_get_pincfg(codec, nid);
1430
1431        if (!(ass & 1)) {
1432                printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1433                       codec->chip_name, ass);
1434                return -1;
1435        }
1436
1437        /* check sum */
1438        tmp = 0;
1439        for (i = 1; i < 16; i++) {
1440                if ((ass >> i) & 1)
1441                        tmp++;
1442        }
1443        if (((ass >> 16) & 0xf) != tmp)
1444                return -1;
1445
1446        spec->cdefine.port_connectivity = ass >> 30;
1447        spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1448        spec->cdefine.check_sum = (ass >> 16) & 0xf;
1449        spec->cdefine.customization = ass >> 8;
1450do_sku:
1451        spec->cdefine.sku_cfg = ass;
1452        spec->cdefine.external_amp = (ass & 0x38) >> 3;
1453        spec->cdefine.platform_type = (ass & 0x4) >> 2;
1454        spec->cdefine.swap = (ass & 0x2) >> 1;
1455        spec->cdefine.override = ass & 0x1;
1456
1457        snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1458                   nid, spec->cdefine.sku_cfg);
1459        snd_printd("SKU: port_connectivity=0x%x\n",
1460                   spec->cdefine.port_connectivity);
1461        snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1462        snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1463        snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1464        snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1465        snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1466        snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1467        snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1468
1469        return 0;
1470}
1471
1472/* check subsystem ID and set up device-specific initialization;
1473 * return 1 if initialized, 0 if invalid SSID
1474 */
1475/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1476 *      31 ~ 16 :       Manufacture ID
1477 *      15 ~ 8  :       SKU ID
1478 *      7  ~ 0  :       Assembly ID
1479 *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1480 */
1481static int alc_subsystem_id(struct hda_codec *codec,
1482                            hda_nid_t porta, hda_nid_t porte,
1483                            hda_nid_t portd, hda_nid_t porti)
1484{
1485        unsigned int ass, tmp, i;
1486        unsigned nid;
1487        struct alc_spec *spec = codec->spec;
1488
1489        if (spec->cdefine.fixup) {
1490                ass = spec->cdefine.sku_cfg;
1491                if (ass == ALC_FIXUP_SKU_IGNORE)
1492                        return 0;
1493                goto do_sku;
1494        }
1495
1496        ass = codec->subsystem_id & 0xffff;
1497        if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1498                goto do_sku;
1499
1500        /* invalid SSID, check the special NID pin defcfg instead */
1501        /*
1502         * 31~30        : port connectivity
1503         * 29~21        : reserve
1504         * 20           : PCBEEP input
1505         * 19~16        : Check sum (15:1)
1506         * 15~1         : Custom
1507         * 0            : override
1508        */
1509        nid = 0x1d;
1510        if (codec->vendor_id == 0x10ec0260)
1511                nid = 0x17;
1512        ass = snd_hda_codec_get_pincfg(codec, nid);
1513        snd_printd("realtek: No valid SSID, "
1514                   "checking pincfg 0x%08x for NID 0x%x\n",
1515                   ass, nid);
1516        if (!(ass & 1))
1517                return 0;
1518        if ((ass >> 30) != 1)   /* no physical connection */
1519                return 0;
1520
1521        /* check sum */
1522        tmp = 0;
1523        for (i = 1; i < 16; i++) {
1524                if ((ass >> i) & 1)
1525                        tmp++;
1526        }
1527        if (((ass >> 16) & 0xf) != tmp)
1528                return 0;
1529do_sku:
1530        snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1531                   ass & 0xffff, codec->vendor_id);
1532        /*
1533         * 0 : override
1534         * 1 :  Swap Jack
1535         * 2 : 0 --> Desktop, 1 --> Laptop
1536         * 3~5 : External Amplifier control
1537         * 7~6 : Reserved
1538        */
1539        tmp = (ass & 0x38) >> 3;        /* external Amp control */
1540        switch (tmp) {
1541        case 1:
1542                spec->init_amp = ALC_INIT_GPIO1;
1543                break;
1544        case 3:
1545                spec->init_amp = ALC_INIT_GPIO2;
1546                break;
1547        case 7:
1548                spec->init_amp = ALC_INIT_GPIO3;
1549                break;
1550        case 5:
1551        default:
1552                spec->init_amp = ALC_INIT_DEFAULT;
1553                break;
1554        }
1555
1556        /* is laptop or Desktop and enable the function "Mute internal speaker
1557         * when the external headphone out jack is plugged"
1558         */
1559        if (!(ass & 0x8000))
1560                return 1;
1561        /*
1562         * 10~8 : Jack location
1563         * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1564         * 14~13: Resvered
1565         * 15   : 1 --> enable the function "Mute internal speaker
1566         *              when the external headphone out jack is plugged"
1567         */
1568        if (!spec->autocfg.hp_pins[0]) {
1569                hda_nid_t nid;
1570                tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1571                if (tmp == 0)
1572                        nid = porta;
1573                else if (tmp == 1)
1574                        nid = porte;
1575                else if (tmp == 2)
1576                        nid = portd;
1577                else if (tmp == 3)
1578                        nid = porti;
1579                else
1580                        return 1;
1581                for (i = 0; i < spec->autocfg.line_outs; i++)
1582                        if (spec->autocfg.line_out_pins[i] == nid)
1583                                return 1;
1584                spec->autocfg.hp_pins[0] = nid;
1585        }
1586
1587        alc_init_auto_hp(codec);
1588        alc_init_auto_mic(codec);
1589        return 1;
1590}
1591
1592static void alc_ssid_check(struct hda_codec *codec,
1593                           hda_nid_t porta, hda_nid_t porte,
1594                           hda_nid_t portd, hda_nid_t porti)
1595{
1596        if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1597                struct alc_spec *spec = codec->spec;
1598                snd_printd("realtek: "
1599                           "Enable default setup for auto mode as fallback\n");
1600                spec->init_amp = ALC_INIT_DEFAULT;
1601                alc_init_auto_hp(codec);
1602                alc_init_auto_mic(codec);
1603        }
1604}
1605
1606/*
1607 * Fix-up pin default configurations and add default verbs
1608 */
1609
1610struct alc_pincfg {
1611        hda_nid_t nid;
1612        u32 val;
1613};
1614
1615struct alc_model_fixup {
1616        const int id;
1617        const char *name;
1618};
1619
1620struct alc_fixup {
1621        int type;
1622        bool chained;
1623        int chain_id;
1624        union {
1625                unsigned int sku;
1626                const struct alc_pincfg *pins;
1627                const struct hda_verb *verbs;
1628                void (*func)(struct hda_codec *codec,
1629                             const struct alc_fixup *fix,
1630                             int action);
1631        } v;
1632};
1633
1634enum {
1635        ALC_FIXUP_INVALID,
1636        ALC_FIXUP_SKU,
1637        ALC_FIXUP_PINS,
1638        ALC_FIXUP_VERBS,
1639        ALC_FIXUP_FUNC,
1640};
1641
1642enum {
1643        ALC_FIXUP_ACT_PRE_PROBE,
1644        ALC_FIXUP_ACT_PROBE,
1645        ALC_FIXUP_ACT_INIT,
1646};
1647
1648static void alc_apply_fixup(struct hda_codec *codec, int action)
1649{
1650        struct alc_spec *spec = codec->spec;
1651        int id = spec->fixup_id;
1652#ifdef CONFIG_SND_DEBUG_VERBOSE
1653        const char *modelname = spec->fixup_name;
1654#endif
1655        int depth = 0;
1656
1657        if (!spec->fixup_list)
1658                return;
1659
1660        while (id >= 0) {
1661                const struct alc_fixup *fix = spec->fixup_list + id;
1662                const struct alc_pincfg *cfg;
1663
1664                switch (fix->type) {
1665                case ALC_FIXUP_SKU:
1666                        if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1667                                break;;
1668                        snd_printdd(KERN_INFO "hda_codec: %s: "
1669                                    "Apply sku override for %s\n",
1670                                    codec->chip_name, modelname);
1671                        spec->cdefine.sku_cfg = fix->v.sku;
1672                        spec->cdefine.fixup = 1;
1673                        break;
1674                case ALC_FIXUP_PINS:
1675                        cfg = fix->v.pins;
1676                        if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1677                                break;
1678                        snd_printdd(KERN_INFO "hda_codec: %s: "
1679                                    "Apply pincfg for %s\n",
1680                                    codec->chip_name, modelname);
1681                        for (; cfg->nid; cfg++)
1682                                snd_hda_codec_set_pincfg(codec, cfg->nid,
1683                                                         cfg->val);
1684                        break;
1685                case ALC_FIXUP_VERBS:
1686                        if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1687                                break;
1688                        snd_printdd(KERN_INFO "hda_codec: %s: "
1689                                    "Apply fix-verbs for %s\n",
1690                                    codec->chip_name, modelname);
1691                        add_verb(codec->spec, fix->v.verbs);
1692                        break;
1693                case ALC_FIXUP_FUNC:
1694                        if (!fix->v.func)
1695                                break;
1696                        snd_printdd(KERN_INFO "hda_codec: %s: "
1697                                    "Apply fix-func for %s\n",
1698                                    codec->chip_name, modelname);
1699                        fix->v.func(codec, fix, action);
1700                        break;
1701                default:
1702                        snd_printk(KERN_ERR "hda_codec: %s: "
1703                                   "Invalid fixup type %d\n",
1704                                   codec->chip_name, fix->type);
1705                        break;
1706                }
1707                if (!fix->chained)
1708                        break;
1709                if (++depth > 10)
1710                        break;
1711                id = fix->chain_id;
1712        }
1713}
1714
1715static void alc_pick_fixup(struct hda_codec *codec,
1716                           const struct alc_model_fixup *models,
1717                           const struct snd_pci_quirk *quirk,
1718                           const struct alc_fixup *fixlist)
1719{
1720        struct alc_spec *spec = codec->spec;
1721        int id = -1;
1722        const char *name = NULL;
1723
1724        if (codec->modelname && models) {
1725                while (models->name) {
1726                        if (!strcmp(codec->modelname, models->name)) {
1727                                id = models->id;
1728                                name = models->name;
1729                                break;
1730                        }
1731                        models++;
1732                }
1733        }
1734        if (id < 0) {
1735                quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1736                if (quirk) {
1737                        id = quirk->value;
1738#ifdef CONFIG_SND_DEBUG_VERBOSE
1739                        name = quirk->name;
1740#endif
1741                }
1742        }
1743
1744        spec->fixup_id = id;
1745        if (id >= 0) {
1746                spec->fixup_list = fixlist;
1747                spec->fixup_name = name;
1748        }
1749}
1750
1751static int alc_read_coef_idx(struct hda_codec *codec,
1752                        unsigned int coef_idx)
1753{
1754        unsigned int val;
1755        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1756                                coef_idx);
1757        val = snd_hda_codec_read(codec, 0x20, 0,
1758                                AC_VERB_GET_PROC_COEF, 0);
1759        return val;
1760}
1761
1762static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1763                                                        unsigned int coef_val)
1764{
1765        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1766                            coef_idx);
1767        snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1768                            coef_val);
1769}
1770
1771/* set right pin controls for digital I/O */
1772static void alc_auto_init_digital(struct hda_codec *codec)
1773{
1774        struct alc_spec *spec = codec->spec;
1775        int i;
1776        hda_nid_t pin;
1777
1778        for (i = 0; i < spec->autocfg.dig_outs; i++) {
1779                pin = spec->autocfg.dig_out_pins[i];
1780                if (pin) {
1781                        snd_hda_codec_write(codec, pin, 0,
1782                                            AC_VERB_SET_PIN_WIDGET_CONTROL,
1783                                            PIN_OUT);
1784                }
1785        }
1786        pin = spec->autocfg.dig_in_pin;
1787        if (pin)
1788                snd_hda_codec_write(codec, pin, 0,
1789                                    AC_VERB_SET_PIN_WIDGET_CONTROL,
1790                                    PIN_IN);
1791}
1792
1793/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1794static void alc_auto_parse_digital(struct hda_codec *codec)
1795{
1796        struct alc_spec *spec = codec->spec;
1797        int i, err;
1798        hda_nid_t dig_nid;
1799
1800        /* support multiple SPDIFs; the secondary is set up as a slave */
1801        for (i = 0; i < spec->autocfg.dig_outs; i++) {
1802                err = snd_hda_get_connections(codec,
1803                                              spec->autocfg.dig_out_pins[i],
1804                                              &dig_nid, 1);
1805                if (err < 0)
1806                        continue;
1807                if (!i) {
1808                        spec->multiout.dig_out_nid = dig_nid;
1809                        spec->dig_out_type = spec->autocfg.dig_out_type[0];
1810                } else {
1811                        spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1812                        if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1813                                break;
1814                        spec->slave_dig_outs[i - 1] = dig_nid;
1815                }
1816        }
1817
1818        if (spec->autocfg.dig_in_pin) {
1819                dig_nid = codec->start_nid;
1820                for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1821                        unsigned int wcaps = get_wcaps(codec, dig_nid);
1822                        if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1823                                continue;
1824                        if (!(wcaps & AC_WCAP_DIGITAL))
1825                                continue;
1826                        if (!(wcaps & AC_WCAP_CONN_LIST))
1827                                continue;
1828                        err = get_connection_index(codec, dig_nid,
1829                                                   spec->autocfg.dig_in_pin);
1830                        if (err >= 0) {
1831                                spec->dig_in_nid = dig_nid;
1832                                break;
1833                        }
1834                }
1835        }
1836}
1837
1838/*
1839 * ALC888
1840 */
1841
1842/*
1843 * 2ch mode
1844 */
1845static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1846/* Mic-in jack as mic in */
1847        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1848        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1849/* Line-in jack as Line in */
1850        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1851        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1852/* Line-Out as Front */
1853        { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1854        { } /* end */
1855};
1856
1857/*
1858 * 4ch mode
1859 */
1860static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1861/* Mic-in jack as mic in */
1862        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1863        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1864/* Line-in jack as Surround */
1865        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1866        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1867/* Line-Out as Front */
1868        { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1869        { } /* end */
1870};
1871
1872/*
1873 * 6ch mode
1874 */
1875static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1876/* Mic-in jack as CLFE */
1877        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1878        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1879/* Line-in jack as Surround */
1880        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1881        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1882/* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1883        { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1884        { } /* end */
1885};
1886
1887/*
1888 * 8ch mode
1889 */
1890static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1891/* Mic-in jack as CLFE */
1892        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1893        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1894/* Line-in jack as Surround */
1895        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1896        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1897/* Line-Out as Side */
1898        { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1899        { } /* end */
1900};
1901
1902static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1903        { 2, alc888_4ST_ch2_intel_init },
1904        { 4, alc888_4ST_ch4_intel_init },
1905        { 6, alc888_4ST_ch6_intel_init },
1906        { 8, alc888_4ST_ch8_intel_init },
1907};
1908
1909/*
1910 * ALC888 Fujitsu Siemens Amillo xa3530
1911 */
1912
1913static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1914/* Front Mic: set to PIN_IN (empty by default) */
1915        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1916/* Connect Internal HP to Front */
1917        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1918        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1919        {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1920/* Connect Bass HP to Front */
1921        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1922        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1923        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1924/* Connect Line-Out side jack (SPDIF) to Side */
1925        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1926        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1927        {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1928/* Connect Mic jack to CLFE */
1929        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1930        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1931        {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1932/* Connect Line-in jack to Surround */
1933        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1934        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935        {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1936/* Connect HP out jack to Front */
1937        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1938        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1939        {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1940/* Enable unsolicited event for HP jack and Line-out jack */
1941        {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1942        {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1943        {}
1944};
1945
1946static void alc_automute_amp(struct hda_codec *codec)
1947{
1948        alc_automute_speaker(codec, 0);
1949}
1950
1951static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1952                                         unsigned int res)
1953{
1954        if (codec->vendor_id == 0x10ec0880)
1955                res >>= 28;
1956        else
1957                res >>= 26;
1958        if (res == ALC880_HP_EVENT)
1959                alc_automute_amp(codec);
1960}
1961
1962static void alc889_automute_setup(struct hda_codec *codec)
1963{
1964        struct alc_spec *spec = codec->spec;
1965
1966        spec->autocfg.hp_pins[0] = 0x15;
1967        spec->autocfg.speaker_pins[0] = 0x14;
1968        spec->autocfg.speaker_pins[1] = 0x16;
1969        spec->autocfg.speaker_pins[2] = 0x17;
1970        spec->autocfg.speaker_pins[3] = 0x19;
1971        spec->autocfg.speaker_pins[4] = 0x1a;
1972}
1973
1974static void alc889_intel_init_hook(struct hda_codec *codec)
1975{
1976        alc889_coef_init(codec);
1977        alc_automute_amp(codec);
1978}
1979
1980static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1981{
1982        struct alc_spec *spec = codec->spec;
1983
1984        spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1985        spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1986        spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1987        spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1988}
1989
1990/*
1991 * ALC888 Acer Aspire 4930G model
1992 */
1993
1994static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1995/* Front Mic: set to PIN_IN (empty by default) */
1996        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1997/* Unselect Front Mic by default in input mixer 3 */
1998        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1999/* Enable unsolicited event for HP jack */
2000        {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2001/* Connect Internal HP to front */
2002        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2003        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2004        {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2005/* Connect HP out to front */
2006        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2007        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2008        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2009        {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2010        { }
2011};
2012
2013/*
2014 * ALC888 Acer Aspire 6530G model
2015 */
2016
2017static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
2018/* Route to built-in subwoofer as well as speakers */
2019        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2020        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2021        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2022        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2023/* Bias voltage on for external mic port */
2024        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2025/* Front Mic: set to PIN_IN (empty by default) */
2026        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2027/* Unselect Front Mic by default in input mixer 3 */
2028        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2029/* Enable unsolicited event for HP jack */
2030        {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2031/* Enable speaker output */
2032        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2033        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2034        {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2035/* Enable headphone output */
2036        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2037        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2039        {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2040        { }
2041};
2042
2043/*
2044 *ALC888 Acer Aspire 7730G model
2045 */
2046
2047static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
2048/* Bias voltage on for external mic port */
2049        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2050/* Front Mic: set to PIN_IN (empty by default) */
2051        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2052/* Unselect Front Mic by default in input mixer 3 */
2053        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2054/* Enable unsolicited event for HP jack */
2055        {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2056/* Enable speaker output */
2057        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2058        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2059        {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2060/* Enable headphone output */
2061        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2062        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2063        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2064        {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2065/*Enable internal subwoofer */
2066        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2067        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2068        {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
2069        {0x17, AC_VERB_SET_EAPD_BTLENABLE, 2},
2070        { }
2071};
2072
2073/*
2074 * ALC889 Acer Aspire 8930G model
2075 */
2076
2077static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
2078/* Front Mic: set to PIN_IN (empty by default) */
2079        {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2080/* Unselect Front Mic by default in input mixer 3 */
2081        {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2082/* Enable unsolicited event for HP jack */
2083        {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2084/* Connect Internal Front to Front */
2085        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2086        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2087        {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2088/* Connect Internal Rear to Rear */
2089        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2090        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091        {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
2092/* Connect Internal CLFE to CLFE */
2093        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2094        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2095        {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2096/* Connect HP out to Front */
2097        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2098        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2099        {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2100/* Enable all DACs */
2101/*  DAC DISABLE/MUTE 1? */
2102/*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
2103        {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
2104        {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2105/*  DAC DISABLE/MUTE 2? */
2106/*  some bit here disables the other DACs. Init=0x4900 */
2107        {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
2108        {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2109/* DMIC fix
2110 * This laptop has a stereo digital microphone. The mics are only 1cm apart
2111 * which makes the stereo useless. However, either the mic or the ALC889
2112 * makes the signal become a difference/sum signal instead of standard
2113 * stereo, which is annoying. So instead we flip this bit which makes the
2114 * codec replicate the sum signal to both channels, turning it into a
2115 * normal mono mic.
2116 */
2117/*  DMIC_CONTROL? Init value = 0x0001 */
2118        {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
2119        {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
2120        { }
2121};
2122
2123static struct hda_input_mux alc888_2_capture_sources[2] = {
2124        /* Front mic only available on one ADC */
2125        {
2126                .num_items = 4,
2127                .items = {
2128                        { "Mic", 0x0 },
2129                        { "Line", 0x2 },
2130                        { "CD", 0x4 },
2131                        { "Front Mic", 0xb },
2132                },
2133        },
2134        {
2135                .num_items = 3,
2136                .items = {
2137                        { "Mic", 0x0 },
2138                        { "Line", 0x2 },
2139                        { "CD", 0x4 },
2140                },
2141        }
2142};
2143
2144static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2145        /* Interal mic only available on one ADC */
2146        {
2147                .num_items = 5,
2148                .items = {
2149                        { "Mic", 0x0 },
2150                        { "Line In", 0x2 },
2151                        { "CD", 0x4 },
2152                        { "Input Mix", 0xa },
2153                        { "Internal Mic", 0xb },
2154                },
2155        },
2156        {
2157                .num_items = 4,
2158                .items = {
2159                        { "Mic", 0x0 },
2160                        { "Line In", 0x2 },
2161                        { "CD", 0x4 },
2162                        { "Input Mix", 0xa },
2163                },
2164        }
2165};
2166
2167static struct hda_input_mux alc889_capture_sources[3] = {
2168        /* Digital mic only available on first "ADC" */
2169        {
2170                .num_items = 5,
2171                .items = {
2172                        { "Mic", 0x0 },
2173                        { "Line", 0x2 },
2174                        { "CD", 0x4 },
2175                        { "Front Mic", 0xb },
2176                        { "Input Mix", 0xa },
2177                },
2178        },
2179        {
2180                .num_items = 4,
2181                .items = {
2182                        { "Mic", 0x0 },
2183                        { "Line", 0x2 },
2184                        { "CD", 0x4 },
2185                        { "Input Mix", 0xa },
2186                },
2187        },
2188        {
2189                .num_items = 4,
2190                .items = {
2191                        { "Mic", 0x0 },
2192                        { "Line", 0x2 },
2193                        { "CD", 0x4 },
2194                        { "Input Mix", 0xa },
2195                },
2196        }
2197};
2198
2199static struct snd_kcontrol_new alc888_base_mixer[] = {
2200        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2201        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2202        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2203        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2204        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2205                HDA_OUTPUT),
2206        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2207        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2208        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2209        HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2210        HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2211        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2212        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2213        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2214        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2215        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2216        HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2217        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2218        { } /* end */
2219};
2220
2221static struct snd_kcontrol_new alc888_acer_aspire_4930g_mixer[] = {
2222        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2223        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2224        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2225        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2226        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2227                HDA_OUTPUT),
2228        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2229        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2230        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2231        HDA_CODEC_VOLUME_MONO("Internal LFE Playback Volume", 0x0f, 1, 0x0, HDA_OUTPUT),
2232        HDA_BIND_MUTE_MONO("Internal LFE Playback Switch", 0x0f, 1, 2, HDA_INPUT),
2233        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2234        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2235        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2236        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2237        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2238        HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2239        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2240        { } /* end */
2241};
2242
2243static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2244        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2245        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2246        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2247        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2248        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2249                HDA_OUTPUT),
2250        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2251        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2252        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2253        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2254        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2255        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2256        HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2257        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2258        { } /* end */
2259};
2260
2261
2262static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
2263{
2264        struct alc_spec *spec = codec->spec;
2265
2266        spec->autocfg.hp_pins[0] = 0x15;
2267        spec->autocfg.speaker_pins[0] = 0x14;
2268        spec->autocfg.speaker_pins[1] = 0x16;
2269        spec->autocfg.speaker_pins[2] = 0x17;
2270}
2271
2272static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2273{
2274        struct alc_spec *spec = codec->spec;
2275
2276        spec->autocfg.hp_pins[0] = 0x15;
2277        spec->autocfg.speaker_pins[0] = 0x14;
2278        spec->autocfg.speaker_pins[1] = 0x16;
2279        spec->autocfg.speaker_pins[2] = 0x17;
2280}
2281
2282static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
2283{
2284        struct alc_spec *spec = codec->spec;
2285
2286        spec->autocfg.hp_pins[0] = 0x15;
2287        spec->autocfg.speaker_pins[0] = 0x14;
2288        spec->autocfg.speaker_pins[1] = 0x16;
2289        spec->autocfg.speaker_pins[2] = 0x17;
2290}
2291
2292static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2293{
2294        struct alc_spec *spec = codec->spec;
2295
2296        spec->autocfg.hp_pins[0] = 0x15;
2297        spec->autocfg.speaker_pins[0] = 0x14;
2298        spec->autocfg.speaker_pins[1] = 0x16;
2299        spec->autocfg.speaker_pins[2] = 0x1b;
2300}
2301
2302/*
2303 * ALC880 3-stack model
2304 *
2305 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
2306 * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
2307 *                 F-Mic = 0x1b, HP = 0x19
2308 */
2309
2310static hda_nid_t alc880_dac_nids[4] = {
2311        /* front, rear, clfe, rear_surr */
2312        0x02, 0x05, 0x04, 0x03
2313};
2314
2315static hda_nid_t alc880_adc_nids[3] = {
2316        /* ADC0-2 */
2317        0x07, 0x08, 0x09,
2318};
2319
2320/* The datasheet says the node 0x07 is connected from inputs,
2321 * but it shows zero connection in the real implementation on some devices.
2322 * Note: this is a 915GAV bug, fixed on 915GLV
2323 */
2324static hda_nid_t alc880_adc_nids_alt[2] = {
2325        /* ADC1-2 */
2326        0x08, 0x09,
2327};
2328
2329#define ALC880_DIGOUT_NID       0x06
2330#define ALC880_DIGIN_NID        0x0a
2331
2332static struct hda_input_mux alc880_capture_source = {
2333        .num_items = 4,
2334        .items = {
2335                { "Mic", 0x0 },
2336                { "Front Mic", 0x3 },
2337                { "Line", 0x2 },
2338                { "CD", 0x4 },
2339        },
2340};
2341
2342/* channel source setting (2/6 channel selection for 3-stack) */
2343/* 2ch mode */
2344static struct hda_verb alc880_threestack_ch2_init[] = {
2345        /* set line-in to input, mute it */
2346        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2347        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2348        /* set mic-in to input vref 80%, mute it */
2349        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2350        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2351        { } /* end */
2352};
2353
2354/* 6ch mode */
2355static struct hda_verb alc880_threestack_ch6_init[] = {
2356        /* set line-in to output, unmute it */
2357        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2358        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2359        /* set mic-in to output, unmute it */
2360        { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2361        { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2362        { } /* end */
2363};
2364
2365static struct hda_channel_mode alc880_threestack_modes[2] = {
2366        { 2, alc880_threestack_ch2_init },
2367        { 6, alc880_threestack_ch6_init },
2368};
2369
2370static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
2371        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2372        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2373        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2374        HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2375        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2376        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2377        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2378        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2379        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2380        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2381        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2382        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2383        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2384        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2385        HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
2386        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
2387        HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
2388        {
2389                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2390                .name = "Channel Mode",
2391                .info = alc_ch_mode_info,
2392                .get = alc_ch_mode_get,
2393                .put = alc_ch_mode_put,
2394        },
2395        { } /* end */
2396};
2397
2398/* capture mixer elements */
2399static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
2400                            struct snd_ctl_elem_info *uinfo)
2401{
2402        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2403        struct alc_spec *spec = codec->spec;
2404        int err;
2405
2406        mutex_lock(&codec->control_mutex);
2407        kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2408                                                      HDA_INPUT);
2409        err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
2410        mutex_unlock(&codec->control_mutex);
2411        return err;
2412}
2413
2414static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2415                           unsigned int size, unsigned int __user *tlv)
2416{
2417        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2418        struct alc_spec *spec = codec->spec;
2419        int err;
2420
2421        mutex_lock(&codec->control_mutex);
2422        kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2423                                                      HDA_INPUT);
2424        err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
2425        mutex_unlock(&codec->control_mutex);
2426        return err;
2427}
2428
2429typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
2430                             struct snd_ctl_elem_value *ucontrol);
2431
2432static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
2433                                 struct snd_ctl_elem_value *ucontrol,
2434                                 getput_call_t func)
2435{
2436        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437        struct alc_spec *spec = codec->spec;
2438        unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2439        int err;
2440
2441        mutex_lock(&codec->control_mutex);
2442        kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
2443                                                      3, 0, HDA_INPUT);
2444        err = func(kcontrol, ucontrol);
2445        mutex_unlock(&codec->control_mutex);
2446        return err;
2447}
2448
2449static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
2450                           struct snd_ctl_elem_value *ucontrol)
2451{
2452        return alc_cap_getput_caller(kcontrol, ucontrol,
2453                                     snd_hda_mixer_amp_volume_get);
2454}
2455
2456static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
2457                           struct snd_ctl_elem_value *ucontrol)
2458{
2459        return alc_cap_getput_caller(kcontrol, ucontrol,
2460                                     snd_hda_mixer_amp_volume_put);
2461}
2462
2463/* capture mixer elements */
2464#define alc_cap_sw_info         snd_ctl_boolean_stereo_info
2465
2466static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
2467                          struct snd_ctl_elem_value *ucontrol)
2468{
2469        return alc_cap_getput_caller(kcontrol, ucontrol,
2470                                     snd_hda_mixer_amp_switch_get);
2471}
2472
2473static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
2474                          struct snd_ctl_elem_value *ucontrol)
2475{
2476        return alc_cap_getput_caller(kcontrol, ucontrol,
2477                                     snd_hda_mixer_amp_switch_put);
2478}
2479
2480#define _DEFINE_CAPMIX(num) \
2481        { \
2482                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2483                .name = "Capture Switch", \
2484                .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2485                .count = num, \
2486                .info = alc_cap_sw_info, \
2487                .get = alc_cap_sw_get, \
2488                .put = alc_cap_sw_put, \
2489        }, \
2490        { \
2491                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2492                .name = "Capture Volume", \
2493                .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2494                           SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2495                           SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2496                .count = num, \
2497                .info = alc_cap_vol_info, \
2498                .get = alc_cap_vol_get, \
2499                .put = alc_cap_vol_put, \
2500                .tlv = { .c = alc_cap_vol_tlv }, \
2501        }
2502
2503#define _DEFINE_CAPSRC(num) \
2504        { \
2505                .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2506                /* .name = "Capture Source", */ \
2507                .name = "Input Source", \
2508                .count = num, \
2509                .info = alc_mux_enum_info, \
2510                .get = alc_mux_enum_get, \
2511                .put = alc_mux_enum_put, \
2512        }
2513
2514#define DEFINE_CAPMIX(num) \
2515static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2516        _DEFINE_CAPMIX(num),                                  \
2517        _DEFINE_CAPSRC(num),                                  \
2518        { } /* end */                                         \
2519}
2520
2521#define DEFINE_CAPMIX_NOSRC(num) \
2522static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2523        _DEFINE_CAPMIX(num),                                        \
2524        { } /* end */                                               \
2525}
2526
2527/* up to three ADCs */
2528DEFINE_CAPMIX(1);
2529DEFINE_CAPMIX(2);
2530DEFINE_CAPMIX(3);
2531DEFINE_CAPMIX_NOSRC(1);
2532DEFINE_CAPMIX_NOSRC(2);
2533DEFINE_CAPMIX_NOSRC(3);
2534
2535/*
2536 * ALC880 5-stack model
2537 *
2538 * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2539 *      Side = 0x02 (0xd)
2540 * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2541 *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2542 */
2543
2544/* additional mixers to alc880_three_stack_mixer */
2545static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2546        HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2547        HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2548        { } /* end */
2549};
2550
2551/* channel source setting (6/8 channel selection for 5-stack) */
2552/* 6ch mode */
2553static struct hda_verb alc880_fivestack_ch6_init[] = {
2554        /* set line-in to input, mute it */
2555        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2556        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2557        { } /* end */
2558};
2559
2560/* 8ch mode */
2561static struct hda_verb alc880_fivestack_ch8_init[] = {
2562        /* set line-in to output, unmute it */
2563        { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2564        { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2565        { } /* end */
2566};
2567
2568static struct hda_channel_mode alc880_fivestack_modes[2] = {
2569        { 6, alc880_fivestack_ch6_init },
2570        { 8, alc880_fivestack_ch8_init },
2571};
2572
2573
2574/*
2575 * ALC880 6-stack model
2576 *
2577 * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2578 *      Side = 0x05 (0x0f)
2579 * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2580 *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2581 */
2582
2583static hda_nid_t alc880_6st_dac_nids[4] = {
2584        /* front, rear, clfe, rear_surr */
2585        0x02, 0x03, 0x04, 0x05
2586};
2587
2588static struct hda_input_mux alc880_6stack_capture_source = {
2589        .num_items = 4,
2590        .items = {
2591                { "Mic", 0x0 },
2592                { "Front Mic", 0x1 },
2593                { "Line", 0x2 },
2594                { "CD", 0x4 },
2595        },
2596};
2597
2598/* fixed 8-channels */
2599static struct hda_channel_mode alc880_sixstack_modes[1] = {
2600        { 8, NULL },
2601};
2602
2603static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2604        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2605        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2606        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2607        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2608        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2609        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2610        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2611        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2612        HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2613        HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2614        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2615        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2616        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2617        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2618        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2619        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2620        HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2621        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2622        {
2623                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2624                .name = "Channel Mode",
2625                .info = alc_ch_mode_info,
2626                .get = alc_ch_mode_get,
2627                .put = alc_ch_mode_put,
2628        },
2629        { } /* end */
2630};
2631
2632
2633/*
2634 * ALC880 W810 model
2635 *
2636 * W810 has rear IO for:
2637 * Front (DAC 02)
2638 * Surround (DAC 03)
2639 * Center/LFE (DAC 04)
2640 * Digital out (06)
2641 *
2642 * The system also has a pair of internal speakers, and a headphone jack.
2643 * These are both connected to Line2 on the codec, hence to DAC 02.
2644 *
2645 * There is a variable resistor to control the speaker or headphone
2646 * volume. This is a hardware-only device without a software API.
2647 *
2648 * Plugging headphones in will disable the internal speakers. This is
2649 * implemented in hardware, not via the driver using jack sense. In
2650 * a similar fashion, plugging into the rear socket marked "front" will
2651 * disable both the speakers and headphones.
2652 *
2653 * For input, there's a microphone jack, and an "audio in" jack.
2654 * These may not do anything useful with this driver yet, because I
2655 * haven't setup any initialization verbs for these yet...
2656 */
2657
2658static hda_nid_t alc880_w810_dac_nids[3] = {
2659        /* front, rear/surround, clfe */
2660        0x02, 0x03, 0x04
2661};
2662
2663/* fixed 6 channels */
2664static struct hda_channel_mode alc880_w810_modes[1] = {
2665        { 6, NULL }
2666};
2667
2668/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2669static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2670        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2671        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2672        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2673        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2674        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2675        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2676        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2677        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2678        HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2679        { } /* end */
2680};
2681
2682
2683/*
2684 * Z710V model
2685 *
2686 * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2687 * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2688 *                 Line = 0x1a
2689 */
2690
2691static hda_nid_t alc880_z71v_dac_nids[1] = {
2692        0x02
2693};
2694#define ALC880_Z71V_HP_DAC      0x03
2695
2696/* fixed 2 channels */
2697static struct hda_channel_mode alc880_2_jack_modes[1] = {
2698        { 2, NULL }
2699};
2700
2701static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2702        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2703        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2704        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2705        HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2706        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2707        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2708        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2709        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2710        { } /* end */
2711};
2712
2713
2714/*
2715 * ALC880 F1734 model
2716 *
2717 * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2718 * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2719 */
2720
2721static hda_nid_t alc880_f1734_dac_nids[1] = {
2722        0x03
2723};
2724#define ALC880_F1734_HP_DAC     0x02
2725
2726static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2727        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2728        HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2729        HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2730        HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2731        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2732        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2733        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2734        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2735        { } /* end */
2736};
2737
2738static struct hda_input_mux alc880_f1734_capture_source = {
2739        .num_items = 2,
2740        .items = {
2741                { "Mic", 0x1 },
2742                { "CD", 0x4 },
2743        },
2744};
2745
2746
2747/*
2748 * ALC880 ASUS model
2749 *
2750 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2751 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2752 *  Mic = 0x18, Line = 0x1a
2753 */
2754
2755#define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2756#define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2757
2758static struct snd_kcontrol_new alc880_asus_mixer[] = {
2759        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2760        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2761        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2762        HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2763        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2764        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2765        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2766        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2767        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2768        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2769        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2770        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2771        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2772        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2773        {
2774                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2775                .name = "Channel Mode",
2776                .info = alc_ch_mode_info,
2777                .get = alc_ch_mode_get,
2778                .put = alc_ch_mode_put,
2779        },
2780        { } /* end */
2781};
2782
2783/*
2784 * ALC880 ASUS W1V model
2785 *
2786 * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2787 * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2788 *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2789 */
2790
2791/* additional mixers to alc880_asus_mixer */
2792static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2793        HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2794        HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2795        { } /* end */
2796};
2797
2798/* TCL S700 */
2799static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2800        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2801        HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2802        HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2803        HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2804        HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2805        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2806        HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2807        HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2808        HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2809        { } /* end */
2810};
2811
2812/* Uniwill */
2813static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2814        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2815        HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2816        HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2817        HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2818        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2819        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2820        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2821        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2822        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2823        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2824        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2825        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2826        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2827        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2828        HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2829        HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2830        {
2831                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2832                .name = "Channel Mode",
2833                .info = alc_ch_mode_info,
2834                .get = alc_ch_mode_get,
2835                .put = alc_ch_mode_put,
2836        },
2837        { } /* end */
2838};
2839
2840static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2841        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2842        HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2843        HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2844        HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2845        HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2846        HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2847        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2848        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2849        HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2850        HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2851        { } /* end */
2852};
2853
2854static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2855        HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2856        HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2857        HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2858        HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2859        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2860        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2861        { } /* end */
2862};
2863
2864/*
2865 * virtual master controls
2866 */
2867
2868/*
2869 * slave controls for virtual master
2870 */
2871static const char * const alc_slave_vols[] = {
2872        "Front Playback Volume",
2873        "Surround Playback Volume",
2874        "Center Playback Volume",
2875        "LFE Playback Volume",
2876        "Side Playback Volume",
2877        "Headphone Playback Volume",
2878        "Speaker Playback Volume",
2879        "Mono Playback Volume",
2880        "Line-Out Playback Volume",
2881        "PCM Playback Volume",
2882        NULL,
2883};
2884
2885static const char * const alc_slave_sws[] = {
2886        "Front Playback Switch",
2887        "Surround Playback Switch",
2888        "Center Playback Switch",
2889        "LFE Playback Switch",
2890        "Side Playback Switch",
2891        "Headphone Playback Switch",
2892        "Speaker Playback Switch",
2893        "Mono Playback Switch",
2894        "IEC958 Playback Switch",
2895        "Line-Out Playback Switch",
2896        "PCM Playback Switch",
2897        NULL,
2898};
2899
2900/*
2901 * build control elements
2902 */
2903
2904#define NID_MAPPING             (-1)
2905
2906#define SUBDEV_SPEAKER_         (0 << 6)
2907#define SUBDEV_HP_              (1 << 6)
2908#define SUBDEV_LINE_            (2 << 6)
2909#define SUBDEV_SPEAKER(x)       (SUBDEV_SPEAKER_ | ((x) & 0x3f))
2910#define SUBDEV_HP(x)            (SUBDEV_HP_ | ((x) & 0x3f))
2911#define SUBDEV_LINE(x)          (SUBDEV_LINE_ | ((x) & 0x3f))
2912
2913static void alc_free_kctls(struct hda_codec *codec);
2914
2915#ifdef CONFIG_SND_HDA_INPUT_BEEP
2916/* additional beep mixers; the actual parameters are overwritten at build */
2917static struct snd_kcontrol_new alc_beep_mixer[] = {
2918        HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2919        HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2920        { } /* end */
2921};
2922#endif
2923
2924static int alc_build_controls(struct hda_codec *codec)
2925{
2926        struct alc_spec *spec = codec->spec;
2927        struct snd_kcontrol *kctl = NULL;
2928        struct snd_kcontrol_new *knew;
2929        int i, j, err;
2930        unsigned int u;
2931        hda_nid_t nid;
2932
2933        for (i = 0; i < spec->num_mixers; i++) {
2934                err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2935                if (err < 0)
2936                        return err;
2937        }
2938        if (spec->cap_mixer) {
2939                err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2940                if (err < 0)
2941                        return err;
2942        }
2943        if (spec->multiout.dig_out_nid) {
2944                err = snd_hda_create_spdif_out_ctls(codec,
2945                                                    spec->multiout.dig_out_nid);
2946                if (err < 0)
2947                        return err;
2948                if (!spec->no_analog) {
2949                        err = snd_hda_create_spdif_share_sw(codec,
2950                                                            &spec->multiout);
2951                        if (err < 0)
2952                                return err;
2953                        spec->multiout.share_spdif = 1;
2954                }
2955        }
2956        if (spec->dig_in_nid) {
2957                err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2958                if (err < 0)
2959                        return err;
2960        }
2961
2962#ifdef CONFIG_SND_HDA_INPUT_BEEP
2963        /* create beep controls if needed */
2964        if (spec->beep_amp) {
2965                struct snd_kcontrol_new *knew;
2966                for (knew = alc_beep_mixer; knew->name; knew++) {
2967                        struct snd_kcontrol *kctl;
2968                        kctl = snd_ctl_new1(knew, codec);
2969                        if (!kctl)
2970                                return -ENOMEM;
2971                        kctl->private_value = spec->beep_amp;
2972                        err = snd_hda_ctl_add(codec, 0, kctl);
2973                        if (err < 0)
2974                                return err;
2975                }
2976        }
2977#endif
2978
2979        /* if we have no master control, let's create it */
2980        if (!spec->no_analog &&
2981            !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2982                unsigned int vmaster_tlv[4];
2983                snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2984                                        HDA_OUTPUT, vmaster_tlv);
2985                err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2986                                          vmaster_tlv, alc_slave_vols);
2987                if (err < 0)
2988                        return err;
2989        }
2990        if (!spec->no_analog &&
2991            !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2992                err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2993                                          NULL, alc_slave_sws);
2994                if (err < 0)
2995                        return err;
2996        }
2997
2998        /* assign Capture Source enums to NID */
2999        if (spec->capsrc_nids || spec->adc_nids) {
3000                kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
3001                if (!kctl)
3002                        kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
3003                for (i = 0; kctl && i < kctl->count; i++) {
3004                        hda_nid_t *nids = spec->capsrc_nids;
3005                        if (!nids)
3006                                nids = spec->adc_nids;
3007                        err = snd_hda_add_nid(codec, kctl, i, nids[i]);
3008                        if (err < 0)
3009                                return err;
3010                }
3011        }
3012        if (spec->cap_mixer) {
3013                const char *kname = kctl ? kctl->id.name : NULL;
3014                for (knew = spec->cap_mixer; knew->name; knew++) {
3015                        if (kname && strcmp(knew->name, kname) == 0)
3016                                continue;
3017                        kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3018                        for (i = 0; kctl && i < kctl->count; i++) {
3019                                err = snd_hda_add_nid(codec, kctl, i,
3020                                                      spec->adc_nids[i]);
3021                                if (err < 0)
3022                                        return err;
3023                        }
3024                }
3025        }
3026
3027        /* other nid->control mapping */
3028        for (i = 0; i < spec->num_mixers; i++) {
3029                for (knew = spec->mixers[i]; knew->name; knew++) {
3030                        if (knew->iface != NID_MAPPING)
3031                                continue;
3032                        kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3033                        if (kctl == NULL)
3034                                continue;
3035                        u = knew->subdevice;
3036                        for (j = 0; j < 4; j++, u >>= 8) {
3037                                nid = u & 0x3f;
3038                                if (nid == 0)
3039                                        continue;
3040                                switch (u & 0xc0) {
3041                                case SUBDEV_SPEAKER_:
3042                                        nid = spec->autocfg.speaker_pins[nid];
3043                                        break;
3044                                case SUBDEV_LINE_:
3045                                        nid = spec->autocfg.line_out_pins[nid];
3046                                        break;
3047                                case SUBDEV_HP_:
3048                                        nid = spec->autocfg.hp_pins[nid];
3049                                        break;
3050                                default:
3051                                        continue;
3052                                }
3053                                err = snd_hda_add_nid(codec, kctl, 0, nid);
3054                                if (err < 0)
3055                                        return err;
3056                        }
3057                        u = knew->private_value;
3058                        for (j = 0; j < 4; j++, u >>= 8) {
3059                                nid = u & 0xff;
3060                                if (nid == 0)
3061                                        continue;
3062                                err = snd_hda_add_nid(codec, kctl, 0, nid);
3063                                if (err < 0)
3064                                        return err;
3065                        }
3066                }
3067        }
3068
3069        alc_free_kctls(codec); /* no longer needed */
3070
3071        return 0;
3072}
3073
3074
3075/*
3076 * initialize the codec volumes, etc
3077 */
3078
3079/*
3080 * generic initialization of ADC, input mixers and output mixers
3081 */
3082static struct hda_verb alc880_volume_init_verbs[] = {
3083        /*
3084         * Unmute ADC0-2 and set the default input to mic-in
3085         */
3086        {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3087        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3088        {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3089        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3090        {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3091        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3092
3093        /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3094         * mixer widget
3095         * Note: PASD motherboards uses the Line In 2 as the input for front
3096         * panel mic (mic 2)
3097         */
3098        /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3099        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3100        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3101        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3102        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3103        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3104        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3105        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3106
3107        /*
3108         * Set up output mixers (0x0c - 0x0f)
3109         */
3110        /* set vol=0 to output mixers */
3111        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3112        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3113        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3114        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3115        /* set up input amps for analog loopback */
3116        /* Amp Indices: DAC = 0, mixer = 1 */
3117        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3118        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3119        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3120        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3121        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3122        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3123        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3124        {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3125
3126        { }
3127};
3128
3129/*
3130 * 3-stack pin configuration:
3131 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
3132 */
3133static struct hda_verb alc880_pin_3stack_init_verbs[] = {
3134        /*
3135         * preset connection lists of input pins
3136         * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3137         */
3138        {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3139        {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3140        {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3141
3142        /*
3143         * Set pin mode and muting
3144         */
3145        /* set front pin widgets 0x14 for output */
3146        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3147        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3148        /* Mic1 (rear panel) pin widget for input and vref at 80% */
3149        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3150        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3151        /* Mic2 (as headphone out) for HP output */
3152        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3153        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3154        /* Line In pin widget for input */
3155        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3156        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3157        /* Line2 (as front mic) pin widget for input and vref at 80% */
3158        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3159        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3160        /* CD pin widget for input */
3161        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3162
3163        { }
3164};
3165
3166/*
3167 * 5-stack pin configuration:
3168 * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
3169 * line-in/side = 0x1a, f-mic = 0x1b
3170 */
3171static struct hda_verb alc880_pin_5stack_init_verbs[] = {
3172        /*
3173         * preset connection lists of input pins
3174         * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3175         */
3176        {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3177        {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
3178
3179        /*
3180         * Set pin mode and muting
3181         */
3182        /* set pin widgets 0x14-0x17 for output */
3183        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3184        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3185        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3186        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3187        /* unmute pins for output (no gain on this amp) */
3188        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3189        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3190        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3191        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3192
3193        /* Mic1 (rear panel) pin widget for input and vref at 80% */
3194        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3195        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3196        /* Mic2 (as headphone out) for HP output */
3197        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3198        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3199        /* Line In pin widget for input */
3200        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3201        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3202        /* Line2 (as front mic) pin widget for input and vref at 80% */
3203        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3204        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3205        /* CD pin widget for input */
3206        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3207
3208        { }
3209};
3210
3211/*
3212 * W810 pin configuration:
3213 * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
3214 */
3215static struct hda_verb alc880_pin_w810_init_verbs[] = {
3216        /* hphone/speaker input selector: front DAC */
3217        {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
3218
3219        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3220        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3221        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3222        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3223        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3224        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3225
3226        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3227        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3228
3229        { }
3230};
3231
3232/*
3233 * Z71V pin configuration:
3234 * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
3235 */
3236static struct hda_verb alc880_pin_z71v_init_verbs[] = {
3237        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3238        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3239        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3240        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3241
3242        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3243        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3244        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3245        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3246
3247        { }
3248};
3249
3250/*
3251 * 6-stack pin configuration:
3252 * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
3253 * f-mic = 0x19, line = 0x1a, HP = 0x1b
3254 */
3255static struct hda_verb alc880_pin_6stack_init_verbs[] = {
3256        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3257
3258        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3259        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3260        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3261        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3262        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3263        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3264        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3265        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3266
3267        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3268        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3269        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3270        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3271        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3272        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3273        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3274        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3275        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3276
3277        { }
3278};
3279
3280/*
3281 * Uniwill pin configuration:
3282 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
3283 * line = 0x1a
3284 */
3285static struct hda_verb alc880_uniwill_init_verbs[] = {
3286        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3287
3288        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3289        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3290        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3291        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3292        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3293        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3294        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3295        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3296        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3297        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3298        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3299        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3300        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3301        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3302
3303        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3304        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3305        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3306        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3307        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3308        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3309        /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
3310        /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
3311        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3312
3313        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3314        {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
3315
3316        { }
3317};
3318
3319/*
3320* Uniwill P53
3321* HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
3322 */
3323static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
3324        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3325
3326        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3327        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3328        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3329        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3330        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3331        {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3332        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3333        {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3334        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3335        {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3336        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3337        {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3338
3339        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3340        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3341        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3342        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3343        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3344        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3345
3346        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3347        {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
3348
3349        { }
3350};
3351
3352static struct hda_verb alc880_beep_init_verbs[] = {
3353        { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
3354        { }
3355};
3356
3357/* auto-toggle front mic */
3358static void alc88x_simple_mic_automute(struct hda_codec *codec)
3359{
3360        unsigned int present;
3361        unsigned char bits;
3362
3363        present = snd_hda_jack_detect(codec, 0x18);
3364        bits = present ? HDA_AMP_MUTE : 0;
3365        snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
3366}
3367
3368static void alc880_uniwill_setup(struct hda_codec *codec)
3369{
3370        struct alc_spec *spec = codec->spec;
3371
3372        spec->autocfg.hp_pins[0] = 0x14;
3373        spec->autocfg.speaker_pins[0] = 0x15;
3374        spec->autocfg.speaker_pins[0] = 0x16;
3375}
3376
3377static void alc880_uniwill_init_hook(struct hda_codec *codec)
3378{
3379        alc_automute_amp(codec);
3380        alc88x_simple_mic_automute(codec);
3381}
3382
3383static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3384                                       unsigned int res)
3385{
3386        /* Looks like the unsol event is incompatible with the standard
3387         * definition.  4bit tag is placed at 28 bit!
3388         */
3389        switch (res >> 28) {
3390        case ALC880_MIC_EVENT:
3391                alc88x_simple_mic_automute(codec);
3392                break;
3393        default:
3394                alc_automute_amp_unsol_event(codec, res);
3395                break;
3396        }
3397}
3398
3399static void alc880_uniwill_p53_setup(struct hda_codec *codec)
3400{
3401        struct alc_spec *spec = codec->spec;
3402
3403        spec->autocfg.hp_pins[0] = 0x14;
3404        spec->autocfg.speaker_pins[0] = 0x15;
3405}
3406
3407static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
3408{
3409        unsigned int present;
3410
3411        present = snd_hda_codec_read(codec, 0x21, 0,
3412                                     AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
3413        present &= HDA_AMP_VOLMASK;
3414        snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
3415                                 HDA_AMP_VOLMASK, present);
3416        snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
3417                                 HDA_AMP_VOLMASK, present);
3418}
3419
3420static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
3421                                           unsigned int res)
3422{
3423        /* Looks like the unsol event is incompatible with the standard
3424         * definition.  4bit tag is placed at 28 bit!
3425         */
3426        if ((res >> 28) == ALC880_DCVOL_EVENT)
3427                alc880_uniwill_p53_dcvol_automute(codec);
3428        else
3429                alc_automute_amp_unsol_event(codec, res);
3430}
3431
3432/*
3433 * F1734 pin configuration:
3434 * HP = 0x14, speaker-out = 0x15, mic = 0x18
3435 */
3436static struct hda_verb alc880_pin_f1734_init_verbs[] = {
3437        {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
3438        {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3439        {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3440        {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3441        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3442
3443        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3444        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3445        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3446        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3447
3448        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3449        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3450        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3451        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3452        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3453        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3454        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3455        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3456        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3457
3458        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
3459        {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
3460
3461        { }
3462};
3463
3464/*
3465 * ASUS pin configuration:
3466 * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
3467 */
3468static struct hda_verb alc880_pin_asus_init_verbs[] = {
3469        {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3470        {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3471        {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3472        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3473
3474        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3475        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3476        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3477        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3478        {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3479        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3480        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3481        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3482
3483        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3484        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3486        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3487        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3488        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3489        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3490        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3491        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3492
3493        { }
3494};
3495
3496/* Enable GPIO mask and set output */
3497#define alc880_gpio1_init_verbs alc_gpio1_init_verbs
3498#define alc880_gpio2_init_verbs alc_gpio2_init_verbs
3499#define alc880_gpio3_init_verbs alc_gpio3_init_verbs
3500
3501/* Clevo m520g init */
3502static struct hda_verb alc880_pin_clevo_init_verbs[] = {
3503        /* headphone output */
3504        {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3505        /* line-out */
3506        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3507        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3508        /* Line-in */
3509        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3510        {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3511        /* CD */
3512        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3513        {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3514        /* Mic1 (rear panel) */
3515        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3516        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3517        /* Mic2 (front panel) */
3518        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3519        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3520        /* headphone */
3521        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3522        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3523        /* change to EAPD mode */
3524        {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3525        {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3526
3527        { }
3528};
3529
3530static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3531        /* change to EAPD mode */
3532        {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3533        {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3534
3535        /* Headphone output */
3536        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3537        /* Front output*/
3538        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3539        {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
3540
3541        /* Line In pin widget for input */
3542        {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3543        /* CD pin widget for input */
3544        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3545        /* Mic1 (rear panel) pin widget for input and vref at 80% */
3546        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3547
3548        /* change to EAPD mode */
3549        {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3550        {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
3551
3552        { }
3553};
3554
3555/*
3556 * LG m1 express dual
3557 *
3558 * Pin assignment:
3559 *   Rear Line-In/Out (blue): 0x14
3560 *   Build-in Mic-In: 0x15
3561 *   Speaker-out: 0x17
3562 *   HP-Out (green): 0x1b
3563 *   Mic-In/Out (red): 0x19
3564 *   SPDIF-Out: 0x1e
3565 */
3566
3567/* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3568static hda_nid_t alc880_lg_dac_nids[3] = {
3569        0x05, 0x02, 0x03
3570};
3571
3572/* seems analog CD is not working */
3573static struct hda_input_mux alc880_lg_capture_source = {
3574        .num_items = 3,
3575        .items = {
3576                { "Mic", 0x1 },
3577                { "Line", 0x5 },
3578                { "Internal Mic", 0x6 },
3579        },
3580};
3581
3582/* 2,4,6 channel modes */
3583static struct hda_verb alc880_lg_ch2_init[] = {
3584        /* set line-in and mic-in to input */
3585        { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3586        { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3587        { }
3588};
3589
3590static struct hda_verb alc880_lg_ch4_init[] = {
3591        /* set line-in to out and mic-in to input */
3592        { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3593        { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3594        { }
3595};
3596
3597static struct hda_verb alc880_lg_ch6_init[] = {
3598        /* set line-in and mic-in to output */
3599        { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3600        { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3601        { }
3602};
3603
3604static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3605        { 2, alc880_lg_ch2_init },
3606        { 4, alc880_lg_ch4_init },
3607        { 6, alc880_lg_ch6_init },
3608};
3609
3610static struct snd_kcontrol_new alc880_lg_mixer[] = {
3611        HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3612        HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3613        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3614        HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3615        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3616        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3617        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3618        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3619        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3620        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3621        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3622        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3623        HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3624        HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3625        {
3626                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3627                .name = "Channel Mode",
3628                .info = alc_ch_mode_info,
3629                .get = alc_ch_mode_get,
3630                .put = alc_ch_mode_put,
3631        },
3632        { } /* end */
3633};
3634
3635static struct hda_verb alc880_lg_init_verbs[] = {
3636        /* set capture source to mic-in */
3637        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3638        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3639        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3640        /* mute all amp mixer inputs */
3641        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3642        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3643        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3644        /* line-in to input */
3645        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3646        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3647        /* built-in mic */
3648        {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3649        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3650        /* speaker-out */
3651        {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3652        {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3653        /* mic-in to input */
3654        {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3655        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3656        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3657        /* HP-out */
3658        {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3659        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3660        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3661        /* jack sense */
3662        {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3663        { }
3664};
3665
3666/* toggle speaker-output according to the hp-jack state */
3667static void alc880_lg_setup(struct hda_codec *codec)
3668{
3669        struct alc_spec *spec = codec->spec;
3670
3671        spec->autocfg.hp_pins[0] = 0x1b;
3672        spec->autocfg.speaker_pins[0] = 0x17;
3673}
3674
3675/*
3676 * LG LW20
3677 *
3678 * Pin assignment:
3679 *   Speaker-out: 0x14
3680 *   Mic-In: 0x18
3681 *   Built-in Mic-In: 0x19
3682 *   Line-In: 0x1b
3683 *   HP-Out: 0x1a
3684 *   SPDIF-Out: 0x1e
3685 */
3686
3687static struct hda_input_mux alc880_lg_lw_capture_source = {
3688        .num_items = 3,
3689        .items = {
3690                { "Mic", 0x0 },
3691                { "Internal Mic", 0x1 },
3692                { "Line In", 0x2 },
3693        },
3694};
3695
3696#define alc880_lg_lw_modes alc880_threestack_modes
3697
3698static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3699        HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3700        HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3701        HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3702        HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3703        HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3704        HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3705        HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3706        HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3707        HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3708        HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3709        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3710        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3711        HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3712        HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3713        {
3714                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3715                .name = "Channel Mode",
3716                .info = alc_ch_mode_info,
3717                .get = alc_ch_mode_get,
3718                .put = alc_ch_mode_put,
3719        },
3720        { } /* end */
3721};
3722
3723static struct hda_verb alc880_lg_lw_init_verbs[] = {
3724        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3725        {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3726        {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3727
3728        /* set capture source to mic-in */
3729        {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3730        {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3731        {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3732        {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3733        /* speaker-out */
3734        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3735        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3736        /* HP-out */
3737        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3738        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3739        /* mic-in to input */
3740        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3741        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3742        /* built-in mic */
3743        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3744        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3745        /* jack sense */
3746        {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3747        { }
3748};
3749
3750/* toggle speaker-output according to the hp-jack state */
3751static void alc880_lg_lw_setup(struct hda_codec *codec)
3752{
3753        struct alc_spec *spec = codec->spec;
3754
3755        spec->autocfg.hp_pins[0] = 0x1b;
3756        spec->autocfg.speaker_pins[0] = 0x14;
3757}
3758
3759static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3760        HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3761        HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3762        HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3763        HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3764        HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3765        HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3766        { } /* end */
3767};
3768
3769static struct hda_input_mux alc880_medion_rim_capture_source = {
3770        .num_items = 2,
3771        .items = {
3772                { "Mic", 0x0 },
3773                { "Internal Mic", 0x1 },
3774        },
3775};
3776
3777static struct hda_verb alc880_medion_rim_init_verbs[] = {
3778        {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3779
3780        {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3781        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3782
3783        /* Mic1 (rear panel) pin widget for input and vref at 80% */
3784        {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3785        {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3786        /* Mic2 (as headphone out) for HP output */
3787        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3788        {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3789        /* Internal Speaker */
3790        {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3791        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3792
3793        {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3794        {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3795
3796        {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3797        { }
3798};
3799
3800/* toggle speaker-output according to the hp-jack state */
3801static void alc880_medion_rim_automute(struct hda_codec *codec)
3802{
3803        struct alc_spec *spec = codec->spec;
3804        alc_automute_amp(codec);
3805        /* toggle EAPD */
3806        if (spec->jack_present)
3807                snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3808        else
3809                snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3810}
3811
3812static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3813                                          unsigned int res)
3814{
3815        /* Looks like the unsol event is incompatible with the standard
3816         * definition.  4bit tag is placed at 28 bit!
3817         */
3818        if ((res >> 28) == ALC880_HP_EVENT)
3819                alc880_medion_rim_automute(codec);
3820}
3821
3822static void alc880_medion_rim_setup(struct hda_codec *codec)
3823{
3824        struct alc_spec *spec = codec->spec;
3825
3826        spec->autocfg.hp_pins[0] = 0x14;
3827        spec->autocfg.speaker_pins[0] = 0x1b;
3828}
3829
3830#ifdef CONFIG_SND_HDA_POWER_SAVE
3831static struct hda_amp_list alc880_loopbacks[] = {
3832        { 0x0b, HDA_INPUT, 0 },
3833        { 0x0b, HDA_INPUT, 1 },
3834        { 0x0b, HDA_INPUT, 2 },
3835        { 0x0b, HDA_INPUT, 3 },
3836        { 0x0b, HDA_INPUT, 4 },
3837        { } /* end */
3838};
3839
3840static struct hda_amp_list alc880_lg_loopbacks[] = {
3841        { 0x0b, HDA_INPUT, 1 },
3842        { 0x0b, HDA_INPUT, 6 },
3843        { 0x0b, HDA_INPUT, 7 },
3844        { } /* end */
3845};
3846#endif
3847
3848/*
3849 * Common callbacks
3850 */
3851
3852static void alc_init_special_input_src(struct hda_codec *codec);
3853
3854static int alc_init(struct hda_codec *codec)
3855{
3856        struct alc_spec *spec = codec->spec;
3857        unsigned int i;
3858
3859        alc_fix_pll(codec);
3860        alc_auto_init_amp(codec, spec->init_amp);
3861
3862        for (i = 0; i < spec->num_init_verbs; i++)
3863                snd_hda_sequence_write(codec, spec->init_verbs[i]);
3864        alc_init_special_input_src(codec);
3865
3866        if (spec->init_hook)
3867                spec->init_hook(codec);
3868
3869        alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
3870
3871        hda_call_check_power_status(codec, 0x01);
3872        return 0;
3873}
3874
3875static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3876{
3877        struct alc_spec *spec = codec->spec;
3878
3879        if (spec->unsol_event)
3880                spec->unsol_event(codec, res);
3881}
3882
3883#ifdef CONFIG_SND_HDA_POWER_SAVE
3884static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3885{
3886        struct alc_spec *spec = codec->spec;
3887        return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3888}
3889#endif
3890
3891/*
3892 * Analog playback callbacks
3893 */
3894static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3895                                    struct hda_codec *codec,
3896                                    struct snd_pcm_substream *substream)
3897{
3898        struct alc_spec *spec = codec->spec;
3899        return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3900                                             hinfo);
3901}
3902
3903static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3904                                       struct hda_codec *codec,
3905                                       unsigned int stream_tag,
3906                                       unsigned int format,
3907                                       struct snd_pcm_substream *substream)
3908{
3909        struct alc_spec *spec = codec->spec;
3910        return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3911                                                stream_tag, format, substream);
3912}
3913
3914static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3915                                       struct hda_codec *codec,
3916                                       struct snd_pcm_substream *substream)
3917{
3918        struct alc_spec *spec = codec->spec;
3919        return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3920}
3921
3922/*
3923 * Digital out
3924 */
3925static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3926                                        struct hda_codec *codec,
3927                                        struct snd_pcm_substream *substream)
3928{
3929        struct alc_spec *spec = codec->spec;
3930        return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3931}
3932
3933static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3934                                           struct hda_codec *codec,
3935                                           unsigned int stream_tag,
3936                                           unsigned int format,
3937                                           struct snd_pcm_substream *substream)
3938{
3939        struct alc_spec *spec = codec->spec;
3940        return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3941                                             stream_tag, format, substream);
3942}
3943
3944static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3945                                           struct hda_codec *codec,
3946                                           struct snd_pcm_substream *substream)
3947{
3948        struct alc_spec *spec = codec->spec;
3949        return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3950}
3951
3952static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3953                                         struct hda_codec *codec,
3954                                         struct snd_pcm_substream *substream)
3955{
3956        struct alc_spec *spec = codec->spec;
3957        return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3958}
3959
3960/*
3961 * Analog capture
3962 */
3963static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3964                                      struct hda_codec *codec,
3965                                      unsigned int stream_tag,
3966                                      unsigned int format,
3967                                      struct snd_pcm_substream *substream)
3968{
3969        struct alc_spec *spec = codec->spec;
3970
3971        snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3972                                   stream_tag, 0, format);
3973        return 0;
3974}
3975
3976static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3977                                      struct hda_codec *codec,
3978                                      struct snd_pcm_substream *substream)
3979{
3980        struct alc_spec *spec = codec->spec;
3981
3982        snd_hda_codec_cleanup_stream(codec,
3983                                     spec->adc_nids[substream->number + 1]);
3984        return 0;
3985}
3986
3987/* analog capture with dynamic dual-adc changes */
3988static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3989                                       struct hda_codec *codec,
3990                                       unsigned int stream_tag,
3991                                       unsigned int format,
3992                                       struct snd_pcm_substream *substream)
3993{
3994        struct alc_spec *spec = codec->spec;
3995        spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
3996        spec->cur_adc_stream_tag = stream_tag;
3997        spec->cur_adc_format = format;
3998        snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
3999        return 0;
4000}
4001
4002static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4003                                       struct hda_codec *codec,
4004                                       struct snd_pcm_substream *substream)
4005{
4006        struct alc_spec *spec = codec->spec;
4007        snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4008        spec->cur_adc = 0;
4009        return 0;
4010}
4011
4012static struct hda_pcm_stream dualmic_pcm_analog_capture = {
4013        .substreams = 1,
4014        .channels_min = 2,
4015        .channels_max = 2,
4016        .nid = 0, /* fill later */
4017        .ops = {
4018                .prepare = dualmic_capture_pcm_prepare,
4019                .cleanup = dualmic_capture_pcm_cleanup
4020        },
4021};
4022
4023/*
4024 */
4025static struct hda_pcm_stream alc880_pcm_analog_playback = {
4026        .substreams = 1,
4027        .channels_min = 2,
4028        .channels_max = 8,
4029        /* NID is set in alc_build_pcms */
4030        .ops = {
4031                .open = alc880_playback_pcm_open,
4032                .prepare = alc880_playback_pcm_prepare,
4033                .cleanup = alc880_playback_pcm_cleanup
4034        },
4035};
4036
4037static struct hda_pcm_stream alc880_pcm_analog_capture = {
4038        .substreams = 1,
4039        .channels_min = 2,
4040        .channels_max = 2,
4041        /* NID is set in alc_build_pcms */
4042};
4043
4044static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
4045        .substreams = 1,
4046        .channels_min = 2,
4047        .channels_max = 2,
4048        /* NID is set in alc_build_pcms */
4049};
4050
4051static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
4052        .substreams = 2, /* can be overridden */
4053        .channels_min = 2,
4054        .channels_max = 2,
4055        /* NID is set in alc_build_pcms */
4056        .ops = {
4057                .prepare = alc880_alt_capture_pcm_prepare,
4058                .cleanup = alc880_alt_capture_pcm_cleanup
4059        },
4060};
4061
4062static struct hda_pcm_stream alc880_pcm_digital_playback = {
4063        .substreams = 1,
4064        .channels_min = 2,
4065        .channels_max = 2,
4066        /* NID is set in alc_build_pcms */
4067        .ops = {
4068                .open = alc880_dig_playback_pcm_open,
4069                .close = alc880_dig_playback_pcm_close,
4070                .prepare = alc880_dig_playback_pcm_prepare,
4071                .cleanup = alc880_dig_playback_pcm_cleanup
4072        },
4073};
4074
4075static struct hda_pcm_stream alc880_pcm_digital_capture = {
4076        .substreams = 1,
4077        .channels_min = 2,
4078        .channels_max = 2,
4079        /* NID is set in alc_build_pcms */
4080};
4081
4082/* Used by alc_build_pcms to flag that a PCM has no playback stream */
4083static struct hda_pcm_stream alc_pcm_null_stream = {
4084        .substreams = 0,
4085        .channels_min = 0,
4086        .channels_max = 0,
4087};
4088
4089static int alc_build_pcms(struct hda_codec *codec)
4090{
4091        struct alc_spec *spec = codec->spec;
4092        struct hda_pcm *info = spec->pcm_rec;
4093        int i;
4094
4095        codec->num_pcms = 1;
4096        codec->pcm_info = info;
4097
4098        if (spec->no_analog)
4099                goto skip_analog;
4100
4101        snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
4102                 "%s Analog", codec->chip_name);
4103        info->name = spec->stream_name_analog;
4104
4105        if (spec->stream_analog_playback) {
4106                if (snd_BUG_ON(!spec->multiout.dac_nids))
4107                        return -EINVAL;
4108                info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
4109                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4110        }
4111        if (spec->stream_analog_capture) {
4112                if (snd_BUG_ON(!spec->adc_nids))
4113                        return -EINVAL;
4114                info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
4115                info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4116        }
4117
4118        if (spec->channel_mode) {
4119                info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
4120                for (i = 0; i < spec->num_channel_mode; i++) {
4121                        if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
4122                                info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
4123                        }
4124                }
4125        }
4126
4127 skip_analog:
4128        /* SPDIF for stream index #1 */
4129        if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4130                snprintf(spec->stream_name_digital,
4131                         sizeof(spec->stream_name_digital),
4132                         "%s Digital", codec->chip_name);
4133                codec->num_pcms = 2;
4134                codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4135                info = spec->pcm_rec + 1;
4136                info->name = spec->stream_name_digital;
4137                if (spec->dig_out_type)
4138                        info->pcm_type = spec->dig_out_type;
4139                else
4140                        info->pcm_type = HDA_PCM_TYPE_SPDIF;
4141                if (spec->multiout.dig_out_nid &&
4142                    spec->stream_digital_playback) {
4143                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
4144                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4145                }
4146                if (spec->dig_in_nid &&
4147                    spec->stream_digital_capture) {
4148                        info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
4149                        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4150                }
4151                /* FIXME: do we need this for all Realtek codec models? */
4152                codec->spdif_status_reset = 1;
4153        }
4154
4155        if (spec->no_analog)
4156                return 0;
4157
4158        /* If the use of more than one ADC is requested for the current
4159         * model, configure a second analog capture-only PCM.
4160         */
4161        /* Additional Analaog capture for index #2 */
4162        if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
4163            (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
4164                codec->num_pcms = 3;
4165                info = spec->pcm_rec + 2;
4166                info->name = spec->stream_name_analog;
4167                if (spec->alt_dac_nid) {
4168                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4169                                *spec->stream_analog_alt_playback;
4170                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4171                                spec->alt_dac_nid;
4172                } else {
4173                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4174                                alc_pcm_null_stream;
4175                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4176                }
4177                if (spec->num_adc_nids > 1) {
4178                        info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4179                                *spec->stream_analog_alt_capture;
4180                        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4181                                spec->adc_nids[1];
4182                        info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4183                                spec->num_adc_nids - 1;
4184                } else {
4185                        info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4186                                alc_pcm_null_stream;
4187                        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4188                }
4189        }
4190
4191        return 0;
4192}
4193
4194static inline void alc_shutup(struct hda_codec *codec)
4195{
4196        snd_hda_shutup_pins(codec);
4197}
4198
4199static void alc_free_kctls(struct hda_codec *codec)
4200{
4201        struct alc_spec *spec = codec->spec;
4202
4203        if (spec->kctls.list) {
4204                struct snd_kcontrol_new *kctl = spec->kctls.list;
4205                int i;
4206                for (i = 0; i < spec->kctls.used; i++)
4207                        kfree(kctl[i].name);
4208        }
4209        snd_array_free(&spec->kctls);
4210}
4211
4212static void alc_free(struct hda_codec *codec)
4213{
4214        struct alc_spec *spec = codec->spec;
4215
4216        if (!spec)
4217                return;
4218
4219        alc_shutup(codec);
4220        snd_hda_input_jack_free(codec);
4221        alc_free_kctls(codec);
4222        kfree(spec);
4223        snd_hda_detach_beep_device(codec);
4224}
4225
4226#ifdef CONFIG_SND_HDA_POWER_SAVE
4227static void alc_power_eapd(struct hda_codec *codec)
4228{
4229        /* We currently only handle front, HP */
4230        switch (codec->vendor_id) {
4231        case 0x10ec0260:
4232                set_eapd(codec, 0x0f, 0);
4233                set_eapd(codec, 0x10, 0);
4234                break;
4235        case 0x10ec0262:
4236        case 0x10ec0267:
4237        case 0x10ec0268:
4238        case 0x10ec0269:
4239        case 0x10ec0270:
4240        case 0x10ec0272:
4241        case 0x10ec0660:
4242        case 0x10ec0662:
4243        case 0x10ec0663:
4244        case 0x10ec0665:
4245        case 0x10ec0862:
4246        case 0x10ec0889:
4247                set_eapd(codec, 0x14, 0);
4248                set_eapd(codec, 0x15, 0);
4249                break;
4250        }
4251}
4252
4253static int alc_suspend(struct hda_codec *codec, pm_message_t state)
4254{
4255        struct alc_spec *spec = codec->spec;
4256        alc_shutup(codec);
4257        if (spec && spec->power_hook)
4258                spec->power_hook(codec);
4259        return 0;
4260}
4261#endif
4262
4263#ifdef SND_HDA_NEEDS_RESUME
4264static int alc_resume(struct hda_codec *codec)
4265{
4266        codec->patch_ops.init(codec);
4267        snd_hda_codec_resume_amp(codec);
4268        snd_hda_codec_resume_cache(codec);
4269        hda_call_check_power_status(codec, 0x01);
4270        return 0;
4271}
4272#endif
4273
4274/*
4275 */
4276static struct hda_codec_ops alc_patch_ops = {
4277        .build_controls = alc_build_controls,
4278        .build_pcms = alc_build_pcms,
4279        .init = alc_init,
4280        .free = alc_free,
4281        .unsol_event = alc_unsol_event,
4282#ifdef SND_HDA_NEEDS_RESUME
4283        .resume = alc_resume,
4284#endif
4285#ifdef CONFIG_SND_HDA_POWER_SAVE
4286        .suspend = alc_suspend,
4287        .check_power_status = alc_check_power_status,
4288#endif
4289        .reboot_notify = alc_shutup,
4290};
4291
4292/* replace the codec chip_name with the given string */
4293static int alc_codec_rename(struct hda_codec *codec, const char *name)
4294{
4295        kfree(codec->chip_name);
4296        codec->chip_name = kstrdup(name, GFP_KERNEL);
4297        if (!codec->chip_name) {
4298                alc_free(codec);
4299                return -ENOMEM;
4300        }
4301        return 0;
4302}
4303
4304/*
4305 * Test configuration for debugging
4306 *
4307 * Almost all inputs/outputs are enabled.  I/O pins can be configured via
4308 * enum controls.
4309 */
4310#ifdef CONFIG_SND_DEBUG
4311static hda_nid_t alc880_test_dac_nids[4] = {
4312        0x02, 0x03, 0x04, 0x05
4313};
4314
4315static struct hda_input_mux alc880_test_capture_source = {
4316        .num_items = 7,
4317        .items = {
4318                { "In-1", 0x0 },
4319                { "In-2", 0x1 },
4320                { "In-3", 0x2 },
4321                { "In-4", 0x3 },
4322                { "CD", 0x4 },
4323                { "Front", 0x5 },
4324                { "Surround", 0x6 },
4325        },
4326};
4327
4328static struct hda_channel_mode alc880_test_modes[4] = {
4329        { 2, NULL },
4330        { 4, NULL },
4331        { 6, NULL },
4332        { 8, NULL },
4333};