Merge branch 'asoc-4.18' into asoc-4.19 wmadsp dep
[muen/linux.git] / sound / soc / qcom / qdsp6 / q6afe-dai.c
index 9ba95956ada8b6b2dc183d2562fb96dc8ca99e16..60ff4a2d35774eebdaced12f36a275ce2738f5f2 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <linux/err.h>
 #include <linux/init.h>
-#include <linux/component.h>
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
@@ -81,7 +80,6 @@ static int q6slim_hw_params(struct snd_pcm_substream *substream,
        struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev);
        struct q6afe_slim_cfg *slim = &dai_data->port_config[dai->id].slim;
 
-       slim->num_channels = params_channels(params);
        slim->sample_rate = params_rate(params);
 
        switch (params_format(params)) {
@@ -385,23 +383,31 @@ static int q6slim_set_channel_map(struct snd_soc_dai *dai,
        struct q6afe_port_config *pcfg = &dai_data->port_config[dai->id];
        int i;
 
-       if (!rx_slot) {
-               pr_err("%s: rx slot not found\n", __func__);
-               return -EINVAL;
-       }
+       if (dai->id & 0x1) {
+               /* TX */
+               if (!tx_slot) {
+                       pr_err("%s: tx slot not found\n", __func__);
+                       return -EINVAL;
+               }
 
-       for (i = 0; i < rx_num; i++) {
-               pcfg->slim.ch_mapping[i] =   rx_slot[i];
-               pr_debug("%s: find number of channels[%d] ch[%d]\n",
-                      __func__, i, rx_slot[i]);
-       }
+               for (i = 0; i < tx_num; i++)
+                       pcfg->slim.ch_mapping[i] = tx_slot[i];
 
-       pcfg->slim.num_channels = rx_num;
+               pcfg->slim.num_channels = tx_num;
 
-       pr_debug("%s: SLIMBUS_%d_RX cnt[%d] ch[%d %d]\n", __func__,
-               (dai->id - SLIMBUS_0_RX) / 2, rx_num,
-               pcfg->slim.ch_mapping[0],
-               pcfg->slim.ch_mapping[1]);
+
+       } else {
+               if (!rx_slot) {
+                       pr_err("%s: rx slot not found\n", __func__);
+                       return -EINVAL;
+               }
+
+               for (i = 0; i < rx_num; i++)
+                       pcfg->slim.ch_mapping[i] =   rx_slot[i];
+
+               pcfg->slim.num_channels = rx_num;
+
+       }
 
        return 0;
 }
@@ -446,6 +452,14 @@ static const struct snd_soc_dapm_route q6afe_dapm_routes[] = {
        {"Slimbus5 Playback", NULL, "SLIMBUS_5_RX"},
        {"Slimbus6 Playback", NULL, "SLIMBUS_6_RX"},
 
+       {"SLIMBUS_0_TX", NULL, "Slimbus Capture"},
+       {"SLIMBUS_1_TX", NULL, "Slimbus1 Capture"},
+       {"SLIMBUS_2_TX", NULL, "Slimbus2 Capture"},
+       {"SLIMBUS_3_TX", NULL, "Slimbus3 Capture"},
+       {"SLIMBUS_4_TX", NULL, "Slimbus4 Capture"},
+       {"SLIMBUS_5_TX", NULL, "Slimbus5 Capture"},
+       {"SLIMBUS_6_TX", NULL, "Slimbus6 Capture"},
+
        {"Primary MI2S Playback", NULL, "PRI_MI2S_RX"},
        {"Secondary MI2S Playback", NULL, "SEC_MI2S_RX"},
        {"Tertiary MI2S Playback", NULL, "TERT_MI2S_RX"},
@@ -639,6 +653,24 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                        .rate_min = 8000,
                        .rate_max = 192000,
                },
+       }, {
+               .name = "SLIMBUS_0_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_0_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus1 Playback",
@@ -657,6 +689,24 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_1_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+       }, {
+               .name = "SLIMBUS_1_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_1_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus1 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus2 Playback",
@@ -675,6 +725,25 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_2_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+
+       }, {
+               .name = "SLIMBUS_2_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_2_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus2 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus3 Playback",
@@ -693,6 +762,25 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_3_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+
+       }, {
+               .name = "SLIMBUS_3_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_3_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus3 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus4 Playback",
@@ -711,6 +799,25 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_4_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+
+       }, {
+               .name = "SLIMBUS_4_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_4_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus4 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus5 Playback",
@@ -729,6 +836,25 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_5_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+
+       }, {
+               .name = "SLIMBUS_5_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_5_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus5 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Slimbus6 Playback",
@@ -747,6 +873,25 @@ static struct snd_soc_dai_driver q6afe_dais[] = {
                .id = SLIMBUS_6_RX,
                .probe = msm_dai_q6_dai_probe,
                .remove = msm_dai_q6_dai_remove,
+
+       }, {
+               .name = "SLIMBUS_6_TX",
+               .ops = &q6slim_ops,
+               .id = SLIMBUS_6_TX,
+               .probe = msm_dai_q6_dai_probe,
+               .remove = msm_dai_q6_dai_remove,
+               .capture = {
+                       .stream_name = "Slimbus6 Capture",
+                       .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
+                                SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_96000 |
+                                SNDRV_PCM_RATE_192000,
+                       .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                  SNDRV_PCM_FMTBIT_S24_LE,
+                       .channels_min = 1,
+                       .channels_max = 8,
+                       .rate_min = 8000,
+                       .rate_max = 192000,
+               },
        }, {
                .playback = {
                        .stream_name = "Primary MI2S Playback",
@@ -975,6 +1120,13 @@ static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = {
        SND_SOC_DAPM_AIF_OUT("SLIMBUS_4_RX", "Slimbus4 Playback", 0, 0, 0, 0),
        SND_SOC_DAPM_AIF_OUT("SLIMBUS_5_RX", "Slimbus5 Playback", 0, 0, 0, 0),
        SND_SOC_DAPM_AIF_OUT("SLIMBUS_6_RX", "Slimbus6 Playback", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_0_TX", "Slimbus Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_1_TX", "Slimbus1 Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_2_TX", "Slimbus2 Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_3_TX", "Slimbus3 Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_4_TX", "Slimbus4 Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_5_TX", "Slimbus5 Capture", 0, 0, 0, 0),
+       SND_SOC_DAPM_AIF_IN("SLIMBUS_6_TX", "Slimbus6 Capture", 0, 0, 0, 0),
        SND_SOC_DAPM_AIF_OUT("QUAT_MI2S_RX", "Quaternary MI2S Playback",
                                                0, 0, 0, 0),
        SND_SOC_DAPM_AIF_IN("QUAT_MI2S_TX", "Quaternary MI2S Capture",
@@ -1252,11 +1404,12 @@ static void of_q6afe_parse_dai_data(struct device *dev,
        }
 }
 
-static int q6afe_dai_bind(struct device *dev, struct device *master, void *data)
+static int q6afe_dai_dev_probe(struct platform_device *pdev)
 {
        struct q6afe_dai_data *dai_data;
+       struct device *dev = &pdev->dev;
 
-       dai_data = kzalloc(sizeof(*dai_data), GFP_KERNEL);
+       dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL);
        if (!dai_data)
                return -ENOMEM;
 
@@ -1264,41 +1417,22 @@ static int q6afe_dai_bind(struct device *dev, struct device *master, void *data)
 
        of_q6afe_parse_dai_data(dev, dai_data);
 
-       return snd_soc_register_component(dev, &q6afe_dai_component,
+       return devm_snd_soc_register_component(dev, &q6afe_dai_component,
                                          q6afe_dais, ARRAY_SIZE(q6afe_dais));
 }
 
-static void q6afe_dai_unbind(struct device *dev, struct device *master,
-                            void *data)
-{
-       struct q6afe_dai_data *dai_data = dev_get_drvdata(dev);
-
-       snd_soc_unregister_component(dev);
-       kfree(dai_data);
-}
-
-static const struct component_ops q6afe_dai_comp_ops = {
-       .bind   = q6afe_dai_bind,
-       .unbind = q6afe_dai_unbind,
+static const struct of_device_id q6afe_dai_device_id[] = {
+       { .compatible = "qcom,q6afe-dais" },
+       {},
 };
-
-static int q6afe_dai_dev_probe(struct platform_device *pdev)
-{
-       return component_add(&pdev->dev, &q6afe_dai_comp_ops);
-}
-
-static int q6afe_dai_dev_remove(struct platform_device *pdev)
-{
-       component_del(&pdev->dev, &q6afe_dai_comp_ops);
-       return 0;
-}
+MODULE_DEVICE_TABLE(of, q6afe_dai_device_id);
 
 static struct platform_driver q6afe_dai_platform_driver = {
        .driver = {
                .name = "q6afe-dai",
+               .of_match_table = of_match_ptr(q6afe_dai_device_id),
        },
        .probe = q6afe_dai_dev_probe,
-       .remove = q6afe_dai_dev_remove,
 };
 module_platform_driver(q6afe_dai_platform_driver);