]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/hda/patch_analog.c
[ALSA] HDA: Add Asus VX1 support
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_analog.c
index 4d7f8d11ad752c40688d4376c7fc69edf278bd80..cfe064a75ca6c4abafa644ab6fc5cc8d5acedf13 100644 (file)
@@ -72,7 +72,13 @@ struct ad198x_spec {
        unsigned int num_kctl_alloc, num_kctl_used;
        struct snd_kcontrol_new *kctl_alloc;
        struct hda_input_mux private_imux;
-       hda_nid_t private_dac_nids[4];
+       hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
+
+       unsigned int jack_present :1;
+
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       struct hda_loopback_check loopback;
+#endif
 };
 
 /*
@@ -144,6 +150,14 @@ static int ad198x_build_controls(struct hda_codec *codec)
        return 0;
 }
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
+{
+       struct ad198x_spec *spec = codec->spec;
+       return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
+}
+#endif
+
 /*
  * Analog playback callbacks
  */
@@ -318,30 +332,13 @@ static void ad198x_free(struct hda_codec *codec)
        kfree(codec->spec);
 }
 
-#ifdef CONFIG_PM
-static int ad198x_resume(struct hda_codec *codec)
-{
-       struct ad198x_spec *spec = codec->spec;
-       int i;
-
-       codec->patch_ops.init(codec);
-       for (i = 0; i < spec->num_mixers; i++)
-               snd_hda_resume_ctls(codec, spec->mixers[i]);
-       if (spec->multiout.dig_out_nid)
-               snd_hda_resume_spdif_out(codec);
-       if (spec->dig_in_nid)
-               snd_hda_resume_spdif_in(codec);
-       return 0;
-}
-#endif
-
 static struct hda_codec_ops ad198x_patch_ops = {
        .build_controls = ad198x_build_controls,
        .build_pcms = ad198x_build_pcms,
        .init = ad198x_init,
        .free = ad198x_free,
-#ifdef CONFIG_PM
-       .resume = ad198x_resume,
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       .check_power_status = ad198x_check_power_status,
 #endif
 };
 
@@ -350,15 +347,7 @@ static struct hda_codec_ops ad198x_patch_ops = {
  * EAPD control
  * the private value = nid | (invert << 8)
  */
-static int ad198x_eapd_info(struct snd_kcontrol *kcontrol,
-                           struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define ad198x_eapd_info       snd_ctl_boolean_mono_info
 
 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
                           struct snd_ctl_elem_value *ucontrol)
@@ -384,12 +373,12 @@ static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
        eapd = ucontrol->value.integer.value[0];
        if (invert)
                eapd = !eapd;
-       if (eapd == spec->cur_eapd && ! codec->in_resume)
+       if (eapd == spec->cur_eapd)
                return 0;
        spec->cur_eapd = eapd;
-       snd_hda_codec_write(codec, nid,
-                           0, AC_VERB_SET_EAPD_BTLENABLE,
-                           eapd ? 0x02 : 0x00);
+       snd_hda_codec_write_cache(codec, nid,
+                                 0, AC_VERB_SET_EAPD_BTLENABLE,
+                                 eapd ? 0x02 : 0x00);
        return 1;
 }
 
@@ -430,94 +419,36 @@ static struct hda_input_mux ad1986a_capture_source = {
        },
 };
 
-/*
- * PCM control
- *
- * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
- */
-
-#define ad1986a_pcm_amp_vol_info       snd_hda_mixer_amp_volume_info
-
-static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct ad198x_spec *ad = codec->spec;
-
-       mutex_lock(&ad->amp_mutex);
-       snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
-       mutex_unlock(&ad->amp_mutex);
-       return 0;
-}
-
-static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct ad198x_spec *ad = codec->spec;
-       int i, change = 0;
-
-       mutex_lock(&ad->amp_mutex);
-       for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
-               kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
-               change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
-       }
-       kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
-       mutex_unlock(&ad->amp_mutex);
-       return change;
-}
-
-#define ad1986a_pcm_amp_sw_info                snd_hda_mixer_amp_switch_info
 
-static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct ad198x_spec *ad = codec->spec;
-
-       mutex_lock(&ad->amp_mutex);
-       snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
-       mutex_unlock(&ad->amp_mutex);
-       return 0;
-}
-
-static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct ad198x_spec *ad = codec->spec;
-       int i, change = 0;
+static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
-       mutex_lock(&ad->amp_mutex);
-       for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) {
-               kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT);
-               change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
-       }
-       kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT);
-       mutex_unlock(&ad->amp_mutex);
-       return change;
-}
+static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
+       .ops = &snd_hda_bind_sw,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /*
  * mixers
  */
 static struct snd_kcontrol_new ad1986a_mixers[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "PCM Playback Volume",
-               .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
-                         SNDRV_CTL_ELEM_ACCESS_TLV_READ |
-                         SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
-               .info = ad1986a_pcm_amp_vol_info,
-               .get = ad1986a_pcm_amp_vol_get,
-               .put = ad1986a_pcm_amp_vol_put,
-               .tlv = { .c = snd_hda_mixer_amp_tlv },
-               .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "PCM Playback Switch",
-               .info = ad1986a_pcm_amp_sw_info,
-               .get = ad1986a_pcm_amp_sw_get,
-               .put = ad1986a_pcm_amp_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT)
-       },
+       /*
+        * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
+        */
+       HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
+       HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
        HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
@@ -569,13 +500,30 @@ static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
 /* laptop model - 2ch only */
 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
 
+/* master controls both pins 0x1a and 0x1b */
+static struct hda_bind_ctls ad1986a_laptop_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
+               0,
+       },
+};
+
+static struct hda_bind_ctls ad1986a_laptop_master_sw = {
+       .ops = &snd_hda_bind_sw,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
+               0,
+       },
+};
+
 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
        HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
-       HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
-       HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
-       /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
-          HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
+       HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
+       HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
        HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
@@ -603,68 +551,115 @@ static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
 
 /* laptop-eapd model - 2ch only */
 
-/* master controls both pins 0x1a and 0x1b */
-static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol,
-                                        struct snd_ctl_elem_value *ucontrol)
+static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
+       .num_items = 3,
+       .items = {
+               { "Mic", 0x0 },
+               { "Internal Mic", 0x4 },
+               { "Mix", 0x5 },
+       },
+};
+
+static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
+       HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
+       HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
+       HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Capture Source",
+               .info = ad198x_mux_enum_info,
+               .get = ad198x_mux_enum_get,
+               .put = ad198x_mux_enum_put,
+       },
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "External Amplifier",
+               .info = ad198x_eapd_info,
+               .get = ad198x_eapd_get,
+               .put = ad198x_eapd_put,
+               .private_value = 0x1b | (1 << 8), /* port-D, inversed */
+       },
+       { } /* end */
+};
+
+/* laptop-automute - 2ch only */
+
+static void ad1986a_update_hp(struct hda_codec *codec)
 {
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
+       struct ad198x_spec *spec = codec->spec;
+       unsigned int mute;
 
-       change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
-                                         0x7f, valp[0] & 0x7f);
-       change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
-                                          0x7f, valp[1] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
-                                0x7f, valp[0] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
-                                0x7f, valp[1] & 0x7f);
-       return change;
+       if (spec->jack_present)
+               mute = HDA_AMP_MUTE; /* mute internal speaker */
+       else
+               /* unmute internal speaker if necessary */
+               mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
+       snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, mute);
+}
+
+static void ad1986a_hp_automute(struct hda_codec *codec)
+{
+       struct ad198x_spec *spec = codec->spec;
+       unsigned int present;
+
+       present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
+       /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
+       spec->jack_present = !(present & 0x80000000);
+       ad1986a_update_hp(codec);
+}
+
+#define AD1986A_HP_EVENT               0x37
+
+static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
+{
+       if ((res >> 26) != AD1986A_HP_EVENT)
+               return;
+       ad1986a_hp_automute(codec);
+}
+
+static int ad1986a_hp_init(struct hda_codec *codec)
+{
+       ad198x_init(codec);
+       ad1986a_hp_automute(codec);
+       return 0;
 }
 
-static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol,
-                                       struct snd_ctl_elem_value *ucontrol)
+/* bind hp and internal speaker mute (with plug check) */
+static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
+                                   struct snd_ctl_elem_value *ucontrol)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        long *valp = ucontrol->value.integer.value;
        int change;
 
        change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
-                                         0x80, valp[0] ? 0 : 0x80);
+                                         HDA_AMP_MUTE,
+                                         valp[0] ? 0 : HDA_AMP_MUTE);
        change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
-                                          0x80, valp[1] ? 0 : 0x80);
-       snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
-                                0x80, valp[0] ? 0 : 0x80);
-       snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
-                                0x80, valp[1] ? 0 : 0x80);
+                                          HDA_AMP_MUTE,
+                                          valp[1] ? 0 : HDA_AMP_MUTE);
+       if (change)
+               ad1986a_update_hp(codec);
        return change;
 }
 
-static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
-       .num_items = 3,
-       .items = {
-               { "Mic", 0x0 },
-               { "Internal Mic", 0x4 },
-               { "Mix", 0x5 },
-       },
-};
-
-static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = ad1986a_laptop_master_vol_put,
-               .tlv = { .c = snd_hda_mixer_amp_tlv },
-               .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
-       },
+static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
+       HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
                .info = snd_hda_mixer_amp_switch_info,
                .get = snd_hda_mixer_amp_switch_get,
-               .put = ad1986a_laptop_master_sw_put,
+               .put = ad1986a_hp_master_sw_put,
                .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
        },
        HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
@@ -674,6 +669,8 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
        HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
        HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
        {
@@ -807,12 +804,20 @@ static struct hda_verb ad1986a_ultra_init[] = {
        { } /* end */
 };
 
+/* pin sensing on HP jack */
+static struct hda_verb ad1986a_hp_init_verbs[] = {
+       {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
+       {}
+};
+
+
 /* models */
 enum {
        AD1986A_6STACK,
        AD1986A_3STACK,
        AD1986A_LAPTOP,
        AD1986A_LAPTOP_EAPD,
+       AD1986A_LAPTOP_AUTOMUTE,
        AD1986A_ULTRA,
        AD1986A_MODELS
 };
@@ -822,6 +827,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
        [AD1986A_3STACK]        = "3stack",
        [AD1986A_LAPTOP]        = "laptop",
        [AD1986A_LAPTOP_EAPD]   = "laptop-eapd",
+       [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
        [AD1986A_ULTRA]         = "ultra",
 };
 
@@ -835,6 +841,7 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
        SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
        SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
+       SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
        SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
@@ -850,11 +857,22 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
        SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
        SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
        SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
-       SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
+       SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
        SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
        {}
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1986a_loopbacks[] = {
+       { 0x13, HDA_OUTPUT, 0 }, /* Mic */
+       { 0x14, HDA_OUTPUT, 0 }, /* Phone */
+       { 0x15, HDA_OUTPUT, 0 }, /* CD */
+       { 0x16, HDA_OUTPUT, 0 }, /* Aux */
+       { 0x17, HDA_OUTPUT, 0 }, /* Line */
+       { } /* end */
+};
+#endif
+
 static int patch_ad1986a(struct hda_codec *codec)
 {
        struct ad198x_spec *spec;
@@ -864,7 +882,6 @@ static int patch_ad1986a(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 6;
@@ -879,6 +896,9 @@ static int patch_ad1986a(struct hda_codec *codec)
        spec->mixers[0] = ad1986a_mixers;
        spec->num_init_verbs = 1;
        spec->init_verbs[0] = ad1986a_init_verbs;
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1986a_loopbacks;
+#endif
 
        codec->patch_ops = ad198x_patch_ops;
 
@@ -914,6 +934,19 @@ static int patch_ad1986a(struct hda_codec *codec)
                spec->multiout.dig_out_nid = 0;
                spec->input_mux = &ad1986a_laptop_eapd_capture_source;
                break;
+       case AD1986A_LAPTOP_AUTOMUTE:
+               spec->mixers[0] = ad1986a_laptop_automute_mixers;
+               spec->num_init_verbs = 3;
+               spec->init_verbs[1] = ad1986a_eapd_init_verbs;
+               spec->init_verbs[2] = ad1986a_hp_init_verbs;
+               spec->multiout.max_channels = 2;
+               spec->multiout.num_dacs = 1;
+               spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
+               spec->multiout.dig_out_nid = 0;
+               spec->input_mux = &ad1986a_laptop_eapd_capture_source;
+               codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
+               codec->patch_ops.init = ad1986a_hp_init;
+               break;
        case AD1986A_ULTRA:
                spec->mixers[0] = ad1986a_laptop_eapd_mixers;
                spec->num_init_verbs = 2;
@@ -925,6 +958,14 @@ static int patch_ad1986a(struct hda_codec *codec)
                break;
        }
 
+       /* AD1986A has a hardware problem that it can't share a stream
+        * with multiple output pins.  The copy of front to surrounds
+        * causes noisy or silent outputs at a certain timing, e.g.
+        * changing the volume.
+        * So, let's disable the shared stream.
+        */
+       spec->multiout.no_share_stream = 1;
+
        return 0;
 }
 
@@ -982,8 +1023,9 @@ static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
 
        if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
                spec->spdif_route = ucontrol->value.enumerated.item[0];
-               snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
-                                   AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
+               snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
+                                         AC_VERB_SET_CONNECT_SEL,
+                                         spec->spdif_route);
                return 1;
        }
        return 0;
@@ -1063,6 +1105,13 @@ static struct hda_verb ad1983_init_verbs[] = {
        { } /* end */
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1983_loopbacks[] = {
+       { 0x12, HDA_OUTPUT, 0 }, /* Mic */
+       { 0x13, HDA_OUTPUT, 0 }, /* Line */
+       { } /* end */
+};
+#endif
 
 static int patch_ad1983(struct hda_codec *codec)
 {
@@ -1072,7 +1121,6 @@ static int patch_ad1983(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -1088,6 +1136,9 @@ static int patch_ad1983(struct hda_codec *codec)
        spec->num_init_verbs = 1;
        spec->init_verbs[0] = ad1983_init_verbs;
        spec->spdif_route = 0;
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1983_loopbacks;
+#endif
 
        codec->patch_ops = ad198x_patch_ops;
 
@@ -1211,6 +1262,17 @@ static struct hda_verb ad1981_init_verbs[] = {
        { } /* end */
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1981_loopbacks[] = {
+       { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
+       { 0x13, HDA_OUTPUT, 0 }, /* Line */
+       { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
+       { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
+       { 0x1d, HDA_OUTPUT, 0 }, /* CD */
+       { } /* end */
+};
+#endif
+
 /*
  * Patch for HP nx6320
  *
@@ -1240,31 +1302,21 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
                return 0;
 
        /* toggle HP mute appropriately */
-       snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
-                                0x80, spec->cur_eapd ? 0 : 0x80);
-       snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
-                                0x80, spec->cur_eapd ? 0 : 0x80);
+       snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE,
+                                spec->cur_eapd ? 0 : HDA_AMP_MUTE);
        return 1;
 }
 
 /* bind volumes of both NID 0x05 and 0x06 */
-static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
-                                   struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                         0x7f, valp[0] & 0x7f);
-       change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                          0x7f, valp[1] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
-                                0x7f, valp[0] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
-                                0x7f, valp[1] & 0x7f);
-       return change;
-}
+static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* mute internal speaker if HP is plugged */
 static void ad1981_hp_automute(struct hda_codec *codec)
@@ -1273,10 +1325,8 @@ static void ad1981_hp_automute(struct hda_codec *codec)
 
        present = snd_hda_codec_read(codec, 0x06, 0,
                                     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
-       snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                0x80, present ? 0x80 : 0);
-       snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                0x80, present ? 0x80 : 0);
+       snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
+                                HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
 }
 
 /* toggle input of built-in and mic jack appropriately */
@@ -1327,14 +1377,7 @@ static struct hda_input_mux ad1981_hp_capture_source = {
 };
 
 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = ad1981_hp_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
@@ -1474,7 +1517,6 @@ static int patch_ad1981(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        spec->multiout.max_channels = 2;
@@ -1490,6 +1532,9 @@ static int patch_ad1981(struct hda_codec *codec)
        spec->num_init_verbs = 1;
        spec->init_verbs[0] = ad1981_init_verbs;
        spec->spdif_route = 0;
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1981_loopbacks;
+#endif
 
        codec->patch_ops = ad198x_patch_ops;
 
@@ -1897,16 +1942,19 @@ static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        unsigned int sel;
 
-       sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
-       if (sel > 0) {
+       sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
+                                AC_AMP_GET_INPUT);
+       if (!(sel & 0x80))
+               ucontrol->value.enumerated.item[0] = 0;
+       else {
                sel = snd_hda_codec_read(codec, 0x0b, 0,
                                         AC_VERB_GET_CONNECT_SEL, 0);
                if (sel < 3)
                        sel++;
                else
                        sel = 0;
+               ucontrol->value.enumerated.item[0] = sel;
        }
-       ucontrol->value.enumerated.item[0] = sel;
        return 0;
 }
 
@@ -1918,23 +1966,39 @@ static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
        int change;
 
        val = ucontrol->value.enumerated.item[0];
-       sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
        if (!val) {
-               change = sel != 0;
-               if (change || codec->in_resume)
-                       snd_hda_codec_write(codec, 0x02, 0,
-                                           AC_VERB_SET_CONNECT_SEL, 0);
+               sel = snd_hda_codec_read(codec, 0x1d, 0,
+                                        AC_VERB_GET_AMP_GAIN_MUTE,
+                                        AC_AMP_GET_INPUT);
+               change = sel & 0x80;
+               if (change) {
+                       snd_hda_codec_write_cache(codec, 0x1d, 0,
+                                                 AC_VERB_SET_AMP_GAIN_MUTE,
+                                                 AMP_IN_UNMUTE(0));
+                       snd_hda_codec_write_cache(codec, 0x1d, 0,
+                                                 AC_VERB_SET_AMP_GAIN_MUTE,
+                                                 AMP_IN_MUTE(1));
+               }
        } else {
-               change = sel == 0;
-               if (change || codec->in_resume)
-                       snd_hda_codec_write(codec, 0x02, 0,
-                                           AC_VERB_SET_CONNECT_SEL, 1);
+               sel = snd_hda_codec_read(codec, 0x1d, 0,
+                                        AC_VERB_GET_AMP_GAIN_MUTE,
+                                        AC_AMP_GET_INPUT | 0x01);
+               change = sel & 0x80;
+               if (change) {
+                       snd_hda_codec_write_cache(codec, 0x1d, 0,
+                                                 AC_VERB_SET_AMP_GAIN_MUTE,
+                                                 AMP_IN_MUTE(0));
+                       snd_hda_codec_write_cache(codec, 0x1d, 0,
+                                                 AC_VERB_SET_AMP_GAIN_MUTE,
+                                                 AMP_IN_UNMUTE(1));
+               }
                sel = snd_hda_codec_read(codec, 0x0b, 0,
                                         AC_VERB_GET_CONNECT_SEL, 0) + 1;
                change |= sel != val;
-               if (change || codec->in_resume)
-                       snd_hda_codec_write(codec, 0x0b, 0,
-                                           AC_VERB_SET_CONNECT_SEL, val - 1);
+               if (change)
+                       snd_hda_codec_write_cache(codec, 0x0b, 0,
+                                                 AC_VERB_SET_CONNECT_SEL,
+                                                 val - 1);
        }
        return change;
 }
@@ -2047,10 +2111,9 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
        {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
        {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
        {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
-       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
+       {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
        /* SPDIF out pin */
        {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
-       {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
 
        { }
 };
@@ -2225,6 +2288,15 @@ static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
                snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
 } 
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1988_loopbacks[] = {
+       { 0x20, HDA_INPUT, 0 }, /* Front Mic */
+       { 0x20, HDA_INPUT, 1 }, /* Line */
+       { 0x20, HDA_INPUT, 4 }, /* Mic */
+       { 0x20, HDA_INPUT, 6 }, /* CD */
+       { } /* end */
+};
+#endif
 
 /*
  * Automatic parse of I/O pins from the BIOS configuration
@@ -2663,7 +2735,6 @@ static int patch_ad1988(struct hda_codec *codec)
        if (spec == NULL)
                return -ENOMEM;
 
-       mutex_init(&spec->amp_mutex);
        codec->spec = spec;
 
        if (is_rev2(codec))
@@ -2770,6 +2841,9 @@ static int patch_ad1988(struct hda_codec *codec)
                codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
                break;
        }
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1988_loopbacks;
+#endif
 
        return 0;
 }
@@ -2926,6 +3000,16 @@ static struct hda_verb ad1884_init_verbs[] = {
        { } /* end */
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1884_loopbacks[] = {
+       { 0x20, HDA_INPUT, 0 }, /* Front Mic */
+       { 0x20, HDA_INPUT, 1 }, /* Mic */
+       { 0x20, HDA_INPUT, 2 }, /* CD */
+       { 0x20, HDA_INPUT, 4 }, /* Docking */
+       { } /* end */
+};
+#endif
+
 static int patch_ad1884(struct hda_codec *codec)
 {
        struct ad198x_spec *spec;
@@ -2950,6 +3034,9 @@ static int patch_ad1884(struct hda_codec *codec)
        spec->num_init_verbs = 1;
        spec->init_verbs[0] = ad1884_init_verbs;
        spec->spdif_route = 0;
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1884_loopbacks;
+#endif
 
        codec->patch_ops = ad198x_patch_ops;
 
@@ -3331,6 +3418,16 @@ static struct hda_verb ad1882_init_verbs[] = {
        { } /* end */
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static struct hda_amp_list ad1882_loopbacks[] = {
+       { 0x20, HDA_INPUT, 0 }, /* Front Mic */
+       { 0x20, HDA_INPUT, 1 }, /* Mic */
+       { 0x20, HDA_INPUT, 4 }, /* Line */
+       { 0x20, HDA_INPUT, 6 }, /* CD */
+       { } /* end */
+};
+#endif
+
 /* models */
 enum {
        AD1882_3STACK,
@@ -3369,6 +3466,9 @@ static int patch_ad1882(struct hda_codec *codec)
        spec->num_init_verbs = 1;
        spec->init_verbs[0] = ad1882_init_verbs;
        spec->spdif_route = 0;
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       spec->loopback.amplist = ad1882_loopbacks;
+#endif
 
        codec->patch_ops = ad198x_patch_ops;