ALSA: hda - Apply a proper chmap for built-in 2.1 speakers
authorTakashi Iwai <tiwai@suse.de>
Thu, 8 Nov 2012 16:12:10 +0000 (17:12 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 8 Nov 2012 16:13:59 +0000 (17:13 +0100)
When 2.1 speakers are detected, use the corresponding channel map
instead of the standard map with front+rear surrounds.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_codec.h
sound/pci/hda/patch_cirrus.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c
sound/pci/hda/patch_via.c

index 569bc05aad6c5d75ded1269b67927c1a66fbd2a8..a8e7b00fe90d87aece5e63f8a35c36dcee4855b1 100644 (file)
@@ -3747,13 +3747,14 @@ static int add_std_chmaps(struct hda_codec *codec)
                        struct hda_pcm_stream *hinfo =
                                &codec->pcm_info[i].stream[str];
                        struct snd_pcm_chmap *chmap;
+                       const struct snd_pcm_chmap_elem *elem;
 
                        if (codec->pcm_info[i].own_chmap)
                                continue;
                        if (!pcm || !hinfo->substreams)
                                continue;
-                       err = snd_pcm_add_chmap_ctls(pcm, str,
-                                                    snd_pcm_std_chmaps,
+                       elem = hinfo->chmap ? hinfo->chmap : snd_pcm_std_chmaps;
+                       err = snd_pcm_add_chmap_ctls(pcm, str, elem,
                                                     hinfo->channels_max,
                                                     0, &chmap);
                        if (err < 0)
@@ -3764,6 +3765,19 @@ static int add_std_chmaps(struct hda_codec *codec)
        return 0;
 }
 
+/* default channel maps for 2.1 speakers;
+ * since HD-audio supports only stereo, odd number channels are omitted
+ */
+const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[] = {
+       { .channels = 2,
+         .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
+       { .channels = 4,
+         .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
+                  SNDRV_CHMAP_LFE, SNDRV_CHMAP_LFE } },
+       { }
+};
+EXPORT_SYMBOL_GPL(snd_pcm_2_1_chmaps);
+
 int snd_hda_codec_build_controls(struct hda_codec *codec)
 {
        int err = 0;
index 62d4229c7b95c80c3e655615fa5a8c864f60ebeb..baad7bf6133b1774b12789379867d5ee45db087d 100644 (file)
@@ -757,6 +757,7 @@ struct hda_pcm_stream {
        u32 rates;      /* supported rates */
        u64 formats;    /* supported formats (SNDRV_PCM_FMTBIT_) */
        unsigned int maxbps;    /* supported max. bit per sample */
+       const struct snd_pcm_chmap_elem *chmap; /* chmap to override */
        struct hda_pcm_ops ops;
 };
 
@@ -1026,6 +1027,8 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
 int snd_hda_is_supported_format(struct hda_codec *codec, hda_nid_t nid,
                                unsigned int format);
 
+extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
+
 /*
  * Misc
  */
index 794b0da11212c5366b324ab2cdaffcb2204e1a0e..f99cbf942b8d6893b67932021ed2e3637916facc 100644 (file)
@@ -344,6 +344,9 @@ static int cs_build_pcms(struct hda_codec *codec)
        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->dac_nid[0];
        info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
                spec->multiout.max_channels;
+       if (spec->speaker_2_1)
+               info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
+                       snd_pcm_2_1_chmaps;
        info->stream[SNDRV_PCM_STREAM_CAPTURE] = cs_pcm_analog_capture;
        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
                spec->adc_nid[spec->cur_input];
index f8e9ff493dc720f4374872fb25d372532943e30f..3401a087de80db655d8220cc0442d9a4477c181e 100644 (file)
@@ -337,6 +337,8 @@ static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
        },
 };
 
+static bool is_2_1_speaker(struct conexant_spec *spec);
+
 static int conexant_build_pcms(struct hda_codec *codec)
 {
        struct conexant_spec *spec = codec->spec;
@@ -351,6 +353,9 @@ static int conexant_build_pcms(struct hda_codec *codec)
                spec->multiout.max_channels;
        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
                spec->multiout.dac_nids[0];
+       if (is_2_1_speaker(spec))
+               info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
+                       snd_pcm_2_1_chmaps;
        if (spec->capture_stream)
                info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
        else {
index bc71be32232e2b29e0b434281cdcda3b81df6fd3..89737ae491527963d57d3f002729040680aba629 100644 (file)
@@ -2260,6 +2260,10 @@ static int alc_build_pcms(struct hda_codec *codec)
                info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
                info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
                        spec->multiout.max_channels;
+               if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
+                   spec->autocfg.line_outs == 2)
+                       info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
+                               snd_pcm_2_1_chmaps;
        }
        if (spec->adc_nids) {
                p = spec->stream_analog_capture;
index f799406f4404a2c7bbd27ed9482a034acec1ded6..a6aeb6260719d09d81b90f450e50b471c1a5bd34 100644 (file)
@@ -2516,6 +2516,11 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
                spec->multiout.dac_nids[0];
+       if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
+           spec->autocfg.line_outs == 2)
+               info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
+                       snd_pcm_2_1_chmaps;
+
        info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
        info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
        info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
index 0e9b0747adc6d51b5565833e8738f96974bb58bd..9ae8cfcecf1d9720e146018388b807773d96fcb6 100644 (file)
@@ -1555,6 +1555,10 @@ static int via_build_pcms(struct hda_codec *codec)
                                spec->multiout.dac_nids[0];
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
                                spec->multiout.max_channels;
+                       if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT
+                           && spec->autocfg.line_outs == 2)
+                               info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
+                                       snd_pcm_2_1_chmaps;
                }
 
                if (!spec->stream_analog_capture) {