]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - sound/pci/hda/patch_hdmi.c
ALSA: hda - hdmi: Fix unused slots being enabled in manual and non-PCM mappings
[karo-tx-linux.git] / sound / pci / hda / patch_hdmi.c
index b187cce64fa4bfe2789f35cbde82ebf2a887af1c..8bf526ea8cf27919f0c3fd9fe35ffe3aa2247eee 100644 (file)
@@ -63,6 +63,7 @@ struct hdmi_spec_per_pin {
        hda_nid_t pin_nid;
        int num_mux_nids;
        hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
+       hda_nid_t cvt_nid;
 
        struct hda_codec *codec;
        struct hdmi_eld sink_eld;
@@ -621,9 +622,9 @@ static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
 
        if (non_pcm) {
                for (i = 0; i < ch_alloc->channels; i++)
-                       non_pcm_mapping[i] = i | (i << 4);
+                       non_pcm_mapping[i] = (i << 4) | i;
                for (; i < 8; i++)
-                       non_pcm_mapping[i] = 0xf | (i << 4);
+                       non_pcm_mapping[i] = (0xf << 4) | i;
        }
 
        for (i = 0; i < 8; i++) {
@@ -677,7 +678,7 @@ static int to_cea_slot(unsigned char c)
                if (t->map == c)
                        return t->cea_slot;
        }
-       return 0x0f;
+       return -1;
 }
 
 /* from CEA slot to ALSA API channel position */
@@ -730,14 +731,23 @@ static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
                                             hda_nid_t pin_nid,
                                             int chs, unsigned char *map)
 {
-       int i;
-       for (i = 0; i < 8; i++) {
+       int alsa_pos, hdmi_slot;
+       int assignments[8] = {[0 ... 7] = 0xf};
+
+       for (alsa_pos = 0; alsa_pos < chs; alsa_pos++) {
+
+               hdmi_slot = to_cea_slot(map[alsa_pos]);
+
+               if (hdmi_slot < 0)
+                       continue; /* unassigned channel */
+
+               assignments[hdmi_slot] = alsa_pos;
+       }
+
+       for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++) {
                int val, err;
-               if (i < chs)
-                       val = to_cea_slot(map[i]);
-               else
-                       val = 0xf;
-               val |= (i << 4);
+
+               val = (assignments[hdmi_slot] << 4) | hdmi_slot;
                err = snd_hda_codec_write(codec, pin_nid, 0,
                                          AC_VERB_SET_HDMI_CHAN_SLOT, val);
                if (err)
@@ -900,8 +910,9 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
 {
        hda_nid_t pin_nid = per_pin->pin_nid;
        int channels = per_pin->channels;
+       int active_channels;
        struct hdmi_eld *eld;
-       int ca;
+       int ca, ordered_ca;
        union audio_infoframe ai;
 
        if (!channels)
@@ -923,6 +934,11 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
        if (ca < 0)
                ca = 0;
 
+       ordered_ca = get_channel_allocation_order(ca);
+       active_channels = channel_allocations[ordered_ca].channels;
+
+       hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
+
        memset(&ai, 0, sizeof(ai));
        if (eld->info.conn_type == 0) { /* HDMI */
                struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
@@ -930,7 +946,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
                hdmi_ai->type           = 0x84;
                hdmi_ai->ver            = 0x01;
                hdmi_ai->len            = 0x0a;
-               hdmi_ai->CC02_CT47      = channels - 1;
+               hdmi_ai->CC02_CT47      = active_channels - 1;
                hdmi_ai->CA             = ca;
                hdmi_checksum_audio_infoframe(hdmi_ai);
        } else if (eld->info.conn_type == 1) { /* DisplayPort */
@@ -939,7 +955,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
                dp_ai->type             = 0x84;
                dp_ai->len              = 0x1b;
                dp_ai->ver              = 0x11 << 2;
-               dp_ai->CC02_CT47        = channels - 1;
+               dp_ai->CC02_CT47        = active_channels - 1;
                dp_ai->CA               = ca;
        } else {
                snd_printd("HDMI: unknown connection type at pin %d\n",
@@ -957,7 +973,7 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
                snd_printdd("hdmi_setup_audio_infoframe: "
                            "pin=%d channels=%d\n",
                            pin_nid,
-                           channels);
+                           active_channels);
                hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
                                           channels, per_pin->chmap,
                                           per_pin->chmap_set);
@@ -1230,6 +1246,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
        per_cvt = get_cvt(spec, cvt_idx);
        /* Claim converter */
        per_cvt->assigned = 1;
+       per_pin->cvt_nid = per_cvt->cvt_nid;
        hinfo->nid = per_cvt->cvt_nid;
 
        snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
@@ -1552,8 +1569,6 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
        per_pin->channels = substream->runtime->channels;
        per_pin->setup = true;
 
-       hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
-
        hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
 
        return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);