]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ASoC: qcom: x1e80100: Support boards with two speakers
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Wed, 23 Oct 2024 12:41:52 +0000 (14:41 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 5 Nov 2024 12:53:26 +0000 (12:53 +0000)
Some Qualcomm X1E laptops have only two speakers.  Regardless whether
this sound card driver is suitable for them (we could re-use one for
some older SoC), we should set reasonable channel map depending on the
number of channels, not always 4-speaker setup.

This change is necessary for bringing audio support on Lenovo Thinkpad
T14s with Qualcomm X1E78100 and only two speakers.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20241023124152.130706-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/x1e80100.c

index 898b5c26bf1ee6bfa6a7a296f90257c6b31851fb..8eb57fc12f0dab3050428a10de03219fd1b8d5dd 100644 (file)
@@ -95,23 +95,53 @@ static int x1e80100_snd_hw_params(struct snd_pcm_substream *substream,
        return qcom_snd_sdw_hw_params(substream, params, &data->sruntime[cpu_dai->id]);
 }
 
+static int x1e80100_snd_hw_map_channels(unsigned int *ch_map, int num)
+{
+       switch (num) {
+       case 1:
+               ch_map[0] = PCM_CHANNEL_FC;
+               break;
+       case 2:
+               ch_map[0] = PCM_CHANNEL_FL;
+               ch_map[1] = PCM_CHANNEL_FR;
+               break;
+       case 3:
+               ch_map[0] = PCM_CHANNEL_FL;
+               ch_map[1] = PCM_CHANNEL_FR;
+               ch_map[2] = PCM_CHANNEL_FC;
+               break;
+       case 4:
+               ch_map[0] = PCM_CHANNEL_FL;
+               ch_map[1] = PCM_CHANNEL_LB;
+               ch_map[2] = PCM_CHANNEL_FR;
+               ch_map[3] = PCM_CHANNEL_RB;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int x1e80100_snd_prepare(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
        struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
        struct x1e80100_snd_data *data = snd_soc_card_get_drvdata(rtd->card);
        struct sdw_stream_runtime *sruntime = data->sruntime[cpu_dai->id];
-       const unsigned int rx_slot[4] = { PCM_CHANNEL_FL,
-                                         PCM_CHANNEL_LB,
-                                         PCM_CHANNEL_FR,
-                                         PCM_CHANNEL_RB };
+       unsigned int channels = substream->runtime->channels;
+       unsigned int rx_slot[4];
        int ret;
 
        switch (cpu_dai->id) {
        case WSA_CODEC_DMA_RX_0:
        case WSA_CODEC_DMA_RX_1:
+               ret = x1e80100_snd_hw_map_channels(rx_slot, channels);
+               if (ret)
+                       return ret;
+
                ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
-                                                 ARRAY_SIZE(rx_slot), rx_slot);
+                                                 channels, rx_slot);
                if (ret)
                        return ret;
                break;