]> git.karo-electronics.de Git - linux-beck.git/blobdiff - sound/pci/hda/patch_analog.c
[ALSA] hda-codec - Fix AD1988 SPDIF playback route control
[linux-beck.git] / sound / pci / hda / patch_analog.c
index 00ace59b05c982f9867fa40886604f1c5f44192b..0e1a879663fa548b2ce8fde95f20c86ecb795262 100644 (file)
@@ -192,6 +192,17 @@ static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
        return snd_hda_multi_out_dig_close(codec, &spec->multiout);
 }
 
+static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
+                                          struct hda_codec *codec,
+                                          unsigned int stream_tag,
+                                          unsigned int format,
+                                          struct snd_pcm_substream *substream)
+{
+       struct ad198x_spec *spec = codec->spec;
+       return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
+                                            format, substream);
+}
+
 /*
  * Analog capture
  */
@@ -250,7 +261,8 @@ static struct hda_pcm_stream ad198x_pcm_digital_playback = {
        .nid = 0, /* fill later */
        .ops = {
                .open = ad198x_dig_playback_pcm_open,
-               .close = ad198x_dig_playback_pcm_close
+               .close = ad198x_dig_playback_pcm_close,
+               .prepare = ad198x_dig_playback_pcm_prepare
        },
 };
 
@@ -739,41 +751,35 @@ static struct hda_verb ad1986a_init_verbs[] = {
        { } /* end */
 };
 
-/* additional verbs for 3-stack model */
-static struct hda_verb ad1986a_3st_init_verbs[] = {
-       /* Mic and line-in selectors */
-       {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
-       {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
-       { } /* end */
-};
-
 static struct hda_verb ad1986a_ch2_init[] = {
        /* Surround out -> Line In */
-       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
+       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
+       /* Line-in selectors */
+       { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
        /* CLFE -> Mic in */
-       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
+       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
+       /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
+       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
        { } /* end */
 };
 
 static struct hda_verb ad1986a_ch4_init[] = {
        /* Surround out -> Surround */
-       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
+       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
        /* CLFE -> Mic in */
-       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
-       { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
+       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
+       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
        { } /* end */
 };
 
 static struct hda_verb ad1986a_ch6_init[] = {
        /* Surround out -> Surround out */
-       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
+       { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
        /* CLFE -> CLFE */
-       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
-       { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
+       { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
+       { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
        { } /* end */
 };
 
@@ -828,17 +834,20 @@ 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, 0x1447, "ASUS A8J", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
        SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
        SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
+       SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
        SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
        SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
        SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
        SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
        SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
        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(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
@@ -880,9 +889,8 @@ static int patch_ad1986a(struct hda_codec *codec)
        case AD1986A_3STACK:
                spec->num_mixers = 2;
                spec->mixers[1] = ad1986a_3st_mixers;
-               spec->num_init_verbs = 3;
-               spec->init_verbs[1] = ad1986a_3st_init_verbs;
-               spec->init_verbs[2] = ad1986a_ch2_init;
+               spec->num_init_verbs = 2;
+               spec->init_verbs[1] = ad1986a_ch2_init;
                spec->channel_mode = ad1986a_modes;
                spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
                spec->need_dac_fix = 1;
@@ -1205,7 +1213,7 @@ static struct hda_verb ad1981_init_verbs[] = {
 /*
  * Patch for HP nx6320
  *
- * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
+ * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
  * speaker output enabled _and_ mute-LED off.
  */
 
@@ -1373,6 +1381,21 @@ static int ad1981_hp_init(struct hda_codec *codec)
        return 0;
 }
 
+/* configuration for Toshiba Laptops */
+static struct hda_verb ad1981_toshiba_init_verbs[] = {
+       {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
+       /* pin sensing on HP and Mic jacks */
+       {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
+       {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
+       {}
+};
+
+static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
+       HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
+       { }
+};
+
 /* configuration for Lenovo Thinkpad T60 */
 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
        HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
@@ -1418,6 +1441,7 @@ enum {
        AD1981_BASIC,
        AD1981_HP,
        AD1981_THINKPAD,
+       AD1981_TOSHIBA,
        AD1981_MODELS
 };
 
@@ -1425,6 +1449,7 @@ static const char *ad1981_models[AD1981_MODELS] = {
        [AD1981_HP]             = "hp",
        [AD1981_THINKPAD]       = "thinkpad",
        [AD1981_BASIC]          = "basic",
+       [AD1981_TOSHIBA]        = "toshiba"
 };
 
 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
@@ -1435,6 +1460,7 @@ static struct snd_pci_quirk ad1981_cfg_tbl[] = {
        /* Lenovo Thinkpad T60/X60/Z6xx */
        SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
        SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
+       SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
        {}
 };
 
@@ -1485,8 +1511,17 @@ static int patch_ad1981(struct hda_codec *codec)
                spec->mixers[0] = ad1981_thinkpad_mixers;
                spec->input_mux = &ad1981_thinkpad_capture_source;
                break;
+       case AD1981_TOSHIBA:
+               spec->mixers[0] = ad1981_hp_mixers;
+               spec->mixers[1] = ad1981_toshiba_mixers;
+               spec->num_init_verbs = 2;
+               spec->init_verbs[1] = ad1981_toshiba_init_verbs;
+               spec->multiout.dig_out_nid = 0;
+               spec->input_mux = &ad1981_hp_capture_source;
+               codec->patch_ops.init = ad1981_hp_init;
+               codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
+               break;
        }
-
        return 0;
 }
 
@@ -1863,8 +1898,9 @@ static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
 
        sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
        if (sel > 0) {
-               sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
-               if (sel <= 3)
+               sel = snd_hda_codec_read(codec, 0x0b, 0,
+                                        AC_VERB_GET_CONNECT_SEL, 0);
+               if (sel < 3)
                        sel++;
                else
                        sel = 0;
@@ -1877,23 +1913,27 @@ static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
                                            struct snd_ctl_elem_value *ucontrol)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       unsigned int sel;
+       unsigned int val, sel;
        int change;
 
+       val = ucontrol->value.enumerated.item[0];
        sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
-       if (! ucontrol->value.enumerated.item[0]) {
+       if (!val) {
                change = sel != 0;
-               if (change)
-                       snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
+               if (change || codec->in_resume)
+                       snd_hda_codec_write(codec, 0x02, 0,
+                                           AC_VERB_SET_CONNECT_SEL, 0);
        } else {
                change = sel == 0;
-               if (change)
-                       snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
-               sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
-               change |= sel == ucontrol->value.enumerated.item[0];
-               if (change)
-                       snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
-                                           ucontrol->value.enumerated.item[0] - 1);
+               if (change || codec->in_resume)
+                       snd_hda_codec_write(codec, 0x02, 0,
+                                           AC_VERB_SET_CONNECT_SEL, 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);
        }
        return change;
 }
@@ -2607,6 +2647,12 @@ static const char *ad1988_models[AD1988_MODEL_LAST] = {
        [AD1988_AUTO]           = "auto",
 };
 
+static struct snd_pci_quirk ad1988_cfg_tbl[] = {
+       SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
+       SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
+       {}
+};
+
 static int patch_ad1988(struct hda_codec *codec)
 {
        struct ad198x_spec *spec;
@@ -2623,7 +2669,7 @@ static int patch_ad1988(struct hda_codec *codec)
                snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
 
        board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
-                                                 ad1988_models, NULL);
+                                                 ad1988_models, ad1988_cfg_tbl);
        if (board_config < 0) {
                printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
                board_config = AD1988_AUTO;