]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/ac97/ac97_patch.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[linux-2.6-omap-h63xx.git] / sound / pci / ac97 / ac97_patch.c
index 43455fc07b778d1cbcf62c55a8ba06a17d2bae69..39198e505b12aabacd6842389647da8dff2c7c68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *  Universal interface for Audio Codec '97
  *
  *  For more details look to AC '97 component specification revision 2.2
@@ -114,10 +114,9 @@ static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd
 
 static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
-       static const char *texts[] = { "2ch", "4ch", "6ch" };
-       if (kcontrol->private_value)
-               return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */
-       return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
+       static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" };
+       return ac97_enum_text_info(kcontrol, uinfo, texts,
+               kcontrol->private_value);
 }
 
 static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -133,6 +132,9 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned char mode = ucontrol->value.enumerated.item[0];
 
+       if (mode >= kcontrol->private_value)
+               return -EINVAL;
+
        if (mode != ac97->channel_mode) {
                ac97->channel_mode = mode;
                if (ac97->build_ops->update_jacks)
@@ -150,6 +152,7 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                .get = ac97_surround_jack_mode_get, \
                .put = ac97_surround_jack_mode_put, \
        }
+/* 6ch */
 #define AC97_CHANNEL_MODE_CTL \
        { \
                .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -157,7 +160,9 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                .info = ac97_channel_mode_info, \
                .get = ac97_channel_mode_get, \
                .put = ac97_channel_mode_put, \
+               .private_value = 3, \
        }
+/* 4ch */
 #define AC97_CHANNEL_MODE_4CH_CTL \
        { \
                .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -165,7 +170,17 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
                .info = ac97_channel_mode_info, \
                .get = ac97_channel_mode_get, \
                .put = ac97_channel_mode_put, \
-               .private_value = 1, \
+               .private_value = 2, \
+       }
+/* 8ch */
+#define AC97_CHANNEL_MODE_8CH_CTL \
+       { \
+               .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, \
+               .name   = "Channel Mode", \
+               .info = ac97_channel_mode_info, \
+               .get = ac97_channel_mode_get, \
+               .put = ac97_channel_mode_put, \
+               .private_value = 4, \
        }
 
 static inline int is_surround_on(struct snd_ac97 *ac97)
@@ -202,11 +217,19 @@ static inline int is_shared_micin(struct snd_ac97 *ac97)
        return !ac97->indep_surround && !is_clfe_on(ac97);
 }
 
+static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
+{
+       return is_surround_on(ac97);
+}
 
 /* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
+/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
+
+/* It is possible to indicate to the Yamaha YMF7x3 the type of
+   speakers being used. */
 
-/* It is possible to indicate to the Yamaha YMF753 the type of speakers being used. */
-static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_info *uinfo)
 {
        static char *texts[3] = {
                "Standard", "Small", "Smaller"
@@ -221,12 +244,13 @@ static int snd_ac97_ymf753_info_speaker(struct snd_kcontrol *kcontrol, struct sn
        return 0;
 }
 
-static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
 
-       val = ac97->regs[AC97_YMF753_3D_MODE_SEL];
+       val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL];
        val = (val >> 10) & 3;
        if (val > 0)    /* 0 = invalid */
                val--;
@@ -234,7 +258,8 @@ static int snd_ac97_ymf753_get_speaker(struct snd_kcontrol *kcontrol, struct snd
        return 0;
 }
 
-static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
@@ -242,20 +267,22 @@ static int snd_ac97_ymf753_put_speaker(struct snd_kcontrol *kcontrol, struct snd
        if (ucontrol->value.enumerated.item[0] > 2)
                return -EINVAL;
        val = (ucontrol->value.enumerated.item[0] + 1) << 10;
-       return snd_ac97_update(ac97, AC97_YMF753_3D_MODE_SEL, val);
+       return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);
 }
 
-static const struct snd_kcontrol_new snd_ac97_ymf753_controls_speaker =
+static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker =
 {
        .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name   = "3D Control - Speaker",
-       .info   = snd_ac97_ymf753_info_speaker,
-       .get    = snd_ac97_ymf753_get_speaker,
-       .put    = snd_ac97_ymf753_put_speaker,
+       .info   = snd_ac97_ymf7x3_info_speaker,
+       .get    = snd_ac97_ymf7x3_get_speaker,
+       .put    = snd_ac97_ymf7x3_put_speaker,
 };
 
-/* It is possible to indicate to the Yamaha YMF753 the source to direct to the S/PDIF output. */
-static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
+/* It is possible to indicate to the Yamaha YMF7x3 the source to
+   direct to the S/PDIF output. */
+static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol,
+                                            struct snd_ctl_elem_info *uinfo)
 {
        static char *texts[2] = { "AC-Link", "A/D Converter" };
 
@@ -268,17 +295,19 @@ static int snd_ac97_ymf753_spdif_source_info(struct snd_kcontrol *kcontrol, stru
        return 0;
 }
 
-static int snd_ac97_ymf753_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol,
+                                           struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
 
-       val = ac97->regs[AC97_YMF753_DIT_CTRL2];
+       val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
        ucontrol->value.enumerated.item[0] = (val >> 1) & 1;
        return 0;
 }
 
-static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol,
+                                           struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
@@ -286,7 +315,75 @@ static int snd_ac97_ymf753_spdif_source_put(struct snd_kcontrol *kcontrol, struc
        if (ucontrol->value.enumerated.item[0] > 1)
                return -EINVAL;
        val = ucontrol->value.enumerated.item[0] << 1;
-       return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0002, val);
+       return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);
+}
+
+static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97)
+{
+       struct snd_kcontrol *kctl;
+       int err;
+
+       kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
+       err = snd_ctl_add(ac97->bus->card, kctl);
+       if (err < 0)
+               return err;
+       strcpy(kctl->id.name, "3D Control - Wide");
+       kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
+       snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
+       err = snd_ctl_add(ac97->bus->card,
+                         snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker,
+                                       ac97));
+       if (err < 0)
+               return err;
+       snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00);
+       return 0;
+}
+
+static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] =
+{
+       AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH),
+                   AC97_YMF7X3_DIT_CTRL, 0, 1, 0),
+       {
+               .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name   = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source",
+               .info   = snd_ac97_ymf7x3_spdif_source_info,
+               .get    = snd_ac97_ymf7x3_spdif_source_get,
+               .put    = snd_ac97_ymf7x3_spdif_source_put,
+       },
+       AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
+                   AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
+};
+
+static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97)
+{
+       int err;
+
+       err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3);
+       if (err < 0)
+               return err;
+       err = patch_build_controls(ac97,
+                                  snd_ac97_yamaha_ymf743_controls_spdif, 3);
+       if (err < 0)
+               return err;
+       /* set default PCM S/PDIF params */
+       /* PCM audio,no copyright,no preemphasis,PCM coder,original */
+       snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201);
+       return 0;
+}
+
+static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = {
+       .build_spdif    = patch_yamaha_ymf743_build_spdif,
+       .build_3d       = patch_yamaha_ymf7x3_3d,
+};
+
+static int patch_yamaha_ymf743(struct snd_ac97 *ac97)
+{
+       ac97->build_ops = &patch_yamaha_ymf743_ops;
+       ac97->caps |= AC97_BC_BASS_TREBLE;
+       ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */
+       ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */
+       ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
+       return 0;
 }
 
 /* The AC'97 spec states that the S/PDIF signal is to be output at pin 48.
@@ -311,7 +408,7 @@ static int snd_ac97_ymf753_spdif_output_pin_get(struct snd_kcontrol *kcontrol, s
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
 
-       val = ac97->regs[AC97_YMF753_DIT_CTRL2];
+       val = ac97->regs[AC97_YMF7X3_DIT_CTRL];
        ucontrol->value.enumerated.item[0] = (val & 0x0008) ? 2 : (val & 0x0020) ? 1 : 0;
        return 0;
 }
@@ -325,7 +422,7 @@ static int snd_ac97_ymf753_spdif_output_pin_put(struct snd_kcontrol *kcontrol, s
                return -EINVAL;
        val = (ucontrol->value.enumerated.item[0] == 2) ? 0x0008 :
              (ucontrol->value.enumerated.item[0] == 1) ? 0x0020 : 0;
-       return snd_ac97_update_bits(ac97, AC97_YMF753_DIT_CTRL2, 0x0028, val);
+       return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0028, val);
        /* The following can be used to direct S/PDIF output to pin 47 (EAPD).
           snd_ac97_write_cache(ac97, 0x62, snd_ac97_read(ac97, 0x62) | 0x0008); */
 }
@@ -334,9 +431,9 @@ static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
        {
                .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name   = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
-               .info   = snd_ac97_ymf753_spdif_source_info,
-               .get    = snd_ac97_ymf753_spdif_source_get,
-               .put    = snd_ac97_ymf753_spdif_source_put,
+               .info   = snd_ac97_ymf7x3_spdif_source_info,
+               .get    = snd_ac97_ymf7x3_spdif_source_get,
+               .put    = snd_ac97_ymf7x3_spdif_source_put,
        },
        {
                .iface  = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -345,25 +442,10 @@ static const struct snd_kcontrol_new snd_ac97_ymf753_controls_spdif[3] = {
                .get    = snd_ac97_ymf753_spdif_output_pin_get,
                .put    = snd_ac97_ymf753_spdif_output_pin_put,
        },
-       AC97_SINGLE(SNDRV_CTL_NAME_IEC958("",NONE,NONE) "Mute", AC97_YMF753_DIT_CTRL2, 2, 1, 1)
+       AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute",
+                   AC97_YMF7X3_DIT_CTRL, 2, 1, 1)
 };
 
-static int patch_yamaha_ymf753_3d(struct snd_ac97 * ac97)
-{
-       struct snd_kcontrol *kctl;
-       int err;
-
-       if ((err = snd_ctl_add(ac97->bus->card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
-               return err;
-       strcpy(kctl->id.name, "3D Control - Wide");
-       kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0);
-       snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
-       if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf753_controls_speaker, ac97))) < 0)
-               return err;
-       snd_ac97_write_cache(ac97, AC97_YMF753_3D_MODE_SEL, 0x0c00);
-       return 0;
-}
-
 static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
 {
        int err;
@@ -374,7 +456,7 @@ static int patch_yamaha_ymf753_post_spdif(struct snd_ac97 * ac97)
 }
 
 static struct snd_ac97_build_ops patch_yamaha_ymf753_ops = {
-       .build_3d       = patch_yamaha_ymf753_3d,
+       .build_3d       = patch_yamaha_ymf7x3_3d,
        .build_post_spdif = patch_yamaha_ymf753_post_spdif
 };
 
@@ -1782,6 +1864,11 @@ static unsigned int ad1981_jacks_blacklist[] = {
        0x10140534, /* Thinkpad X31 */
        0x10140537, /* Thinkpad T41p */
        0x10140554, /* Thinkpad T42p/R50p */
+       0x10140567, /* Thinkpad T43p 2668-G7U */
+       0x10140581, /* Thinkpad X41-2527 */
+       0x104380b0, /* Asus A7V8X-MX */
+       0x11790241, /* Toshiba Satellite A-15 S127 */
+       0x144dc01a, /* Samsung NP-X20C004/SEG */
        0 /* end */
 };
 
@@ -1875,14 +1962,7 @@ static int patch_ad1981b(struct snd_ac97 *ac97)
        return 0;
 }
 
-static int snd_ac97_ad1888_lohpsel_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 snd_ac97_ad1888_lohpsel_info   snd_ctl_boolean_mono_info
 
 static int snd_ac97_ad1888_lohpsel_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
@@ -2081,8 +2161,7 @@ static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol,
        struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
        unsigned short val;
 
-       if (ucontrol->value.enumerated.item[0] > 3
-           || ucontrol->value.enumerated.item[0] < 0)
+       if (ucontrol->value.enumerated.item[0] > 3)
                return -EINVAL;
        val = ctrl2reg[ucontrol->value.enumerated.item[0]]
              << AC97_AD198X_VREF_SHIFT;
@@ -2181,15 +2260,7 @@ static int patch_ad1985(struct snd_ac97 * ac97)
        return 0;
 }
 
-static int snd_ac97_ad1986_bool_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 snd_ac97_ad1986_bool_info      snd_ctl_boolean_mono_info
 
 static int snd_ac97_ad1986_lososel_get(struct snd_kcontrol *kcontrol,
                                       struct snd_ctl_elem_value *ucontrol)
@@ -2756,10 +2827,12 @@ static int patch_alc655(struct snd_ac97 * ac97)
 
 #define AC97_ALC850_JACK_SELECT        0x76
 #define AC97_ALC850_MISC1      0x7a
+#define AC97_ALC850_MULTICH    0x6a
 
 static void alc850_update_jacks(struct snd_ac97 *ac97)
 {
        int shared;
+       int aux_is_back_surround;
        
        /* shared Line-In / Surround Out */
        shared = is_shared_surrout(ac97);
@@ -2777,13 +2850,18 @@ static void alc850_update_jacks(struct snd_ac97 *ac97)
        /* MIC-IN = 1, CENTER-LFE = 5 */
        snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
                             shared ? (5<<4) : (1<<4));
+
+       aux_is_back_surround = alc850_is_aux_back_surround(ac97);
+       /* Aux is Back Surround */
+       snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
+                                aux_is_back_surround ? (1<<10) : (0<<10));
 }
 
 static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
        AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
        AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
        AC97_SURROUND_JACK_MODE_CTL,
-       AC97_CHANNEL_MODE_CTL,
+       AC97_CHANNEL_MODE_8CH_CTL,
 };
 
 static int patch_alc850_specific(struct snd_ac97 *ac97)
@@ -2809,6 +2887,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
        ac97->build_ops = &patch_alc850_ops;
 
        ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
+       ac97->flags |= AC97_HAS_8CH;
 
        /* assume only page 0 for writing cache */
        snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
@@ -2818,6 +2897,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
           spdif-in monitor off, spdif-in PCM off
           center on mic off, surround on line-in off
           duplicate front off
+          NB default bit 10=0 = Aux is Capture, not Back Surround
        */
        snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
        /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
@@ -3277,16 +3357,111 @@ static int patch_vt1616(struct snd_ac97 * ac97)
 /*
  * VT1617A codec
  */
-static int patch_vt1617a(struct snd_ac97 * ac97)
+
+/*
+ * unfortunately, the vt1617a stashes the twiddlers required for
+ * nooding the i/o jacks on 2 different regs. * thameans that we cant
+ * use the easy way provided by AC97_ENUM_DOUBLE() we have to write
+ * are own funcs.
+ *
+ * NB: this is absolutely and utterly different from the vt1618. dunno
+ * about the 1616.
+ */
+
+/* copied from ac97_surround_jack_mode_info() */
+static int snd_ac97_vt1617a_smart51_info(struct snd_kcontrol *kcontrol,
+                                        struct snd_ctl_elem_info *uinfo)
+{
+       /* ordering in this list reflects vt1617a docs for Reg 20 and
+        * 7a and Table 6 that lays out the matrix NB WRT Table6: SM51
+        * is SM51EN *AND* it's Bit14, not Bit15 so the table is very
+        * counter-intuitive */ 
+
+       static const char* texts[] = { "LineIn Mic1", "LineIn Mic1 Mic3",
+                                      "Surr LFE/C Mic3", "LineIn LFE/C Mic3",
+                                      "LineIn Mic2", "LineIn Mic2 Mic1",
+                                      "Surr LFE Mic1", "Surr LFE Mic1 Mic2"};
+       return ac97_enum_text_info(kcontrol, uinfo, texts, 8);
+}
+
+static int snd_ac97_vt1617a_smart51_get(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_value *ucontrol)
+{
+       ushort usSM51, usMS;  
+
+       struct snd_ac97 *pac97;
+       
+       pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
+
+       /* grab our desirec bits, then mash them together in a manner
+        * consistent with Table 6 on page 17 in the 1617a docs */
+       usSM51 = snd_ac97_read(pac97, 0x7a) >> 14;
+       usMS   = snd_ac97_read(pac97, 0x20) >> 8;
+  
+       ucontrol->value.enumerated.item[0] = (usSM51 << 1) + usMS;
+
+       return 0;
+}
+
+static int snd_ac97_vt1617a_smart51_put(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_value *ucontrol)
 {
-       /* bring analog power consumption to normal, like WinXP driver
-        * for EPIA SP
+       ushort usSM51, usMS, usReg;  
+
+       struct snd_ac97 *pac97;
+
+       pac97 = snd_kcontrol_chip(kcontrol); /* grab codec handle */
+
+       usSM51 = ucontrol->value.enumerated.item[0] >> 1;
+       usMS   = ucontrol->value.enumerated.item[0] &  1;
+
+       /* push our values into the register - consider that things will be left
+        * in a funky state if the write fails */
+
+       usReg = snd_ac97_read(pac97, 0x7a);
+       snd_ac97_write_cache(pac97, 0x7a, (usReg & 0x3FFF) + (usSM51 << 14));
+       usReg = snd_ac97_read(pac97, 0x20);
+       snd_ac97_write_cache(pac97, 0x20, (usReg & 0xFEFF) + (usMS   <<  8));
+
+       return 0;
+}
+
+static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
+
+       AC97_SINGLE("Center/LFE Exchange", 0x5a, 8, 1, 0),
+       /*
+        * These are used to enable/disable surround sound on motherboards
+        * that have 3 bidirectional analog jacks
+        */
+       {
+               .iface         = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name          = "Smart 5.1 Select",
+               .info          = snd_ac97_vt1617a_smart51_info,
+               .get           = snd_ac97_vt1617a_smart51_get,
+               .put           = snd_ac97_vt1617a_smart51_put,
+       },
+};
+
+int patch_vt1617a(struct snd_ac97 * ac97)
+{
+       int err = 0;
+
+       /* we choose to not fail out at this point, but we tell the
+          caller when we return */
+
+       err = patch_build_controls(ac97, &snd_ac97_controls_vt1617a[0],
+                                  ARRAY_SIZE(snd_ac97_controls_vt1617a));
+
+       /* bring analog power consumption to normal by turning off the
+        * headphone amplifier, like WinXP driver for EPIA SP
         */
        snd_ac97_write_cache(ac97, 0x5c, 0x20);
        ac97->ext_id |= AC97_EI_SPDIF;  /* force the detection of spdif */
        ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
        ac97->build_ops = &patch_vt1616_ops;
-       return 0;
+
+       return err;
 }
 
 /*