ALSA: hda - enable HDMI audio pin out at module loading time
[safe/jmp/linux-2.6] / sound / pci / hda / patch_intelhdmi.c
index e10fa1e..f2610d6 100644 (file)
@@ -32,7 +32,6 @@
 #include <sound/core.h>
 #include "hda_codec.h"
 #include "hda_local.h"
-#include "hda_patch.h"
 
 #define CVT_NID                0x02    /* audio converter */
 #define PIN_NID                0x03    /* HDMI output pin */
@@ -50,11 +49,6 @@ static struct hda_verb pinout_enable_verb[] = {
        {} /* terminator */
 };
 
-static struct hda_verb pinout_disable_verb[] = {
-       {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00},
-       {}
-};
-
 static struct hda_verb unsolicited_response_verb[] = {
        {PIN_NID, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN |
                                                  INTEL_HDMI_EVENT_TAG},
@@ -249,10 +243,6 @@ static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid,
 
 static void hdmi_enable_output(struct hda_codec *codec)
 {
-       /* Enable Audio InfoFrame Transmission */
-       hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
-       snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT,
-                                               AC_DIPXMIT_BEST);
        /* Unmute */
        if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
                snd_hda_codec_write(codec, PIN_NID, 0,
@@ -261,17 +251,24 @@ static void hdmi_enable_output(struct hda_codec *codec)
        snd_hda_sequence_write(codec, pinout_enable_verb);
 }
 
-static void hdmi_disable_output(struct hda_codec *codec)
+/*
+ * Enable Audio InfoFrame Transmission
+ */
+static void hdmi_start_infoframe_trans(struct hda_codec *codec)
 {
-       snd_hda_sequence_write(codec, pinout_disable_verb);
-       if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
-               snd_hda_codec_write(codec, PIN_NID, 0,
-                               AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
+       hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
+       snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT,
+                                               AC_DIPXMIT_BEST);
+}
 
-       /*
-        * FIXME: noises may arise when playing music after reloading the
-        * kernel module, until the next X restart or monitor repower.
-        */
+/*
+ * Disable Audio InfoFrame Transmission
+ */
+static void hdmi_stop_infoframe_trans(struct hda_codec *codec)
+{
+       hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
+       snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT,
+                                               AC_DIPXMIT_DISABLE);
 }
 
 static int hdmi_get_channel_count(struct hda_codec *codec)
@@ -286,7 +283,7 @@ static void hdmi_set_channel_count(struct hda_codec *codec, int chs)
                                        AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
 
        if (chs != hdmi_get_channel_count(codec))
-               snd_printd(KERN_INFO "Channel count expect=%d, real=%d\n",
+               snd_printd(KERN_INFO "HDMI channel count: expect %d, get %d\n",
                                        chs, hdmi_get_channel_count(codec));
 }
 
@@ -299,7 +296,7 @@ static void hdmi_debug_channel_mapping(struct hda_codec *codec)
        for (i = 0; i < 8; i++) {
                slot = snd_hda_codec_read(codec, CVT_NID, 0,
                                                AC_VERB_GET_HDMI_CHAN_SLOT, i);
-               printk(KERN_DEBUG "ASP channel %d => slot %d\n",
+               printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
                                                slot >> 4, slot & 0x7);
        }
 #endif
@@ -326,12 +323,12 @@ static void hdmi_debug_dip_size(struct hda_codec *codec)
        int size;
 
        size = snd_hdmi_get_eld_size(codec, PIN_NID);
-       printk(KERN_DEBUG "ELD buf size is %d\n", size);
+       printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
 
        for (i = 0; i < 8; i++) {
                size = snd_hda_codec_read(codec, PIN_NID, 0,
                                                AC_VERB_GET_HDMI_DIP_SIZE, i);
-               printk(KERN_DEBUG "DIP GP[%d] buf size is %d\n", i, size);
+               printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
        }
 #endif
 }
@@ -359,8 +356,8 @@ static void hdmi_clear_dip_buffers(struct hda_codec *codec)
                                break;
                }
                snd_printd(KERN_INFO
-                               "DIP GP[%d] buf reported size=%d, written=%d\n",
-                               i, size, j);
+                       "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
+                       i, size, j);
        }
 #endif
 }
@@ -420,14 +417,18 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
        /*
         * CA defaults to 0 for basic stereo audio
         */
-       if (!eld->eld_ver)
-               return 0;
-       if (!eld->spk_alloc)
-               return 0;
        if (channels <= 2)
                return 0;
 
        /*
+        * HDMI sink's ELD info cannot always be retrieved for now, e.g.
+        * in console or for audio devices. Assume the highest speakers
+        * configuration, to _not_ prohibit multi-channel audio playback.
+        */
+       if (!eld->spk_alloc)
+               eld->spk_alloc = 0xffff;
+
+       /*
         * expand ELD's speaker allocation mask
         *
         * ELD tells the speaker mask in a compact(paired) form,
@@ -444,14 +445,16 @@ static int hdmi_setup_channel_allocation(struct hda_codec *codec,
                    (spk_mask & channel_allocations[i].spk_mask) ==
                                channel_allocations[i].spk_mask) {
                        ai->CA = channel_allocations[i].ca_index;
-                       return 0;
+                       break;
                }
        }
 
        snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
-       snd_printd(KERN_INFO "failed to setup channel allocation: %d of %s\n",
-                       channels, buf);
-       return -1;
+       snd_printdd(KERN_INFO
+                       "HDMI: select CA 0x%x for %d-channel allocation: %s\n",
+                       ai->CA, channels, buf);
+
+       return ai->CA;
 }
 
 static void hdmi_setup_channel_mapping(struct hda_codec *codec,
@@ -484,6 +487,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
        hdmi_setup_channel_mapping(codec, &ai);
 
        hdmi_fill_audio_infoframe(codec, &ai);
+       hdmi_start_infoframe_trans(codec);
 }
 
 
@@ -496,7 +500,9 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
        int pind = !!(res & AC_UNSOL_RES_PD);
        int eldv = !!(res & AC_UNSOL_RES_ELDV);
 
-       printk(KERN_INFO "HDMI intrinsic event: PD=%d ELDV=%d\n", pind, eldv);
+       printk(KERN_INFO
+               "HDMI hot plug event: Presence_Detect=%d ELD_Valid=%d\n",
+               pind, eldv);
 
        if (pind && eldv) {
                hdmi_parse_eld(codec);
@@ -510,13 +516,13 @@ static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
        int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
        int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
 
-       printk(KERN_INFO "HDMI non-intrinsic event: "
-                       "SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
-                       subtag,
-                       cp_state,
-                       cp_ready);
+       printk(KERN_INFO
+               "HDMI content protection event: SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
+               subtag,
+               cp_state,
+               cp_ready);
 
-       /* who cares? */
+       /* TODO */
        if (cp_state)
                ;
        if (cp_ready)
@@ -530,9 +536,7 @@ static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
        int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
 
        if (tag != INTEL_HDMI_EVENT_TAG) {
-               snd_printd(KERN_INFO
-                               "Unexpected HDMI unsolicited event tag 0x%x\n",
-                               tag);
+               snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
                return;
        }
 
@@ -561,7 +565,7 @@ static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo,
 {
        struct intel_hdmi_spec *spec = codec->spec;
 
-       hdmi_disable_output(codec);
+       hdmi_stop_infoframe_trans(codec);
 
        return snd_hda_multi_out_dig_close(codec, &spec->multiout);
 }
@@ -581,8 +585,6 @@ static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
 
        hdmi_setup_audio_infoframe(codec, substream);
 
-       hdmi_enable_output(codec);
-
        return 0;
 }
 
@@ -627,8 +629,7 @@ static int intel_hdmi_build_controls(struct hda_codec *codec)
 
 static int intel_hdmi_init(struct hda_codec *codec)
 {
-       /* disable audio output as early as possible */
-       hdmi_disable_output(codec);
+       hdmi_enable_output(codec);
 
        snd_hda_sequence_write(codec, unsolicited_response_verb);
 
@@ -673,11 +674,38 @@ static int patch_intel_hdmi(struct hda_codec *codec)
        return 0;
 }
 
-struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
-       { .id = 0x808629fb, .name = "INTEL G45 DEVCL",  .patch = patch_intel_hdmi },
-       { .id = 0x80862801, .name = "INTEL G45 DEVBLC", .patch = patch_intel_hdmi },
-       { .id = 0x80862802, .name = "INTEL G45 DEVCTG", .patch = patch_intel_hdmi },
-       { .id = 0x80862803, .name = "INTEL G45 DEVELK", .patch = patch_intel_hdmi },
+static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
+       { .id = 0x808629fb, .name = "G45 DEVCL",  .patch = patch_intel_hdmi },
+       { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
+       { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
+       { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
        { .id = 0x10951392, .name = "SiI1392 HDMI",     .patch = patch_intel_hdmi },
        {} /* terminator */
 };
+
+MODULE_ALIAS("snd-hda-codec-id:808629fb");
+MODULE_ALIAS("snd-hda-codec-id:80862801");
+MODULE_ALIAS("snd-hda-codec-id:80862802");
+MODULE_ALIAS("snd-hda-codec-id:80862803");
+MODULE_ALIAS("snd-hda-codec-id:10951392");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
+
+static struct hda_codec_preset_list intel_list = {
+       .preset = snd_hda_preset_intelhdmi,
+       .owner = THIS_MODULE,
+};
+
+static int __init patch_intelhdmi_init(void)
+{
+       return snd_hda_add_codec_preset(&intel_list);
+}
+
+static void __exit patch_intelhdmi_exit(void)
+{
+       snd_hda_delete_codec_preset(&intel_list);
+}
+
+module_init(patch_intelhdmi_init)
+module_exit(patch_intelhdmi_exit)