Browse Source

ASoC: codecs: Add swr dmic as multi codec

Add codec backend dai for soundwire dmic's.
Add swr dmic as multi codec

CRs-Fixed: 2600577
Change-Id: I6d6f812d702c1422752e2841bfcad6495e388aad
Signed-off-by: Vignesh Kulothungan <vigneshk@codeaurora.org>
Vignesh Kulothungan 5 years ago
parent
commit
4fd97a1e75
2 changed files with 52 additions and 13 deletions
  1. 47 12
      asoc/codecs/swr-dmic.c
  2. 5 1
      asoc/msm_dailink.h

+ 47 - 12
asoc/codecs/swr-dmic.c

@@ -56,6 +56,7 @@ struct swr_dmic_priv {
 	struct swr_device *swr_slave;
 	struct snd_soc_component *component;
 	struct snd_soc_component_driver *driver;
+	struct snd_soc_dai_driver *dai_driver;
 	struct snd_soc_component *supply_component;
 	u32 micb_num;
 	struct device_node *wcd_handle;
@@ -66,10 +67,10 @@ struct swr_dmic_priv {
 };
 
 const char *codec_name_list[] = {
-	"swr-dmic-01",
-	"swr-dmic-02",
-	"swr-dmic-03",
-	"swr-dmic-04",
+	"swr-dmic.01",
+	"swr-dmic.02",
+	"swr-dmic.03",
+	"swr-dmic.04",
 };
 
 const char *dai_name_list[] = {
@@ -80,10 +81,10 @@ const char *dai_name_list[] = {
 };
 
 const char *aif_name_list[] = {
-	"SWR_DMIC_AIF0 Playback",
-	"SWR_DMIC_AIF1 Playback",
-	"SWR_DMIC_AIF2 Playback",
-	"SWR_DMIC_AIF3 Playback",
+	"SWR_DMIC_AIF0 Capture",
+	"SWR_DMIC_AIF1 Capture",
+	"SWR_DMIC_AIF2 Capture",
+	"SWR_DMIC_AIF3 Capture",
 };
 
 static int swr_dmic_reset(struct swr_device *pdev);
@@ -391,6 +392,26 @@ static int swr_dmic_parse_supply(struct device_node *np,
 	return 0;
 }
 
+static struct snd_soc_dai_driver swr_dmic_dai[] = {
+	{
+		.name = "",
+		.id = 0,
+		.capture = {
+			.stream_name = "",
+			.rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
+				SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |
+				SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
+			.formats = (SNDRV_PCM_FMTBIT_S16_LE |
+				SNDRV_PCM_FMTBIT_S24_LE |
+				SNDRV_PCM_FMTBIT_S32_LE),
+			.rate_max = 192000,
+			.rate_min = 8000,
+			.channels_min = 1,
+			.channels_max = 2,
+		},
+	},
+};
+
 static int swr_dmic_probe(struct swr_device *pdev)
 {
 	int ret = 0;
@@ -497,10 +518,24 @@ static int swr_dmic_probe(struct swr_device *pdev)
 		goto dev_err;
 	}
 
-	swr_dmic->driver->name = dai_name_list[dev_index];
+	swr_dmic->driver->name = codec_name_list[dev_index];
+
+	swr_dmic->dai_driver = devm_kzalloc(&pdev->dev,
+			sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
+	if (!swr_dmic->dai_driver) {
+		ret = -ENOMEM;
+		goto dev_err;
+	}
+
+	memcpy(swr_dmic->dai_driver, swr_dmic_dai,
+			sizeof(struct snd_soc_dai_driver));
+	swr_dmic->dai_driver->id = dev_index;
+	swr_dmic->dai_driver->name = dai_name_list[dev_index];
+	swr_dmic->dai_driver->capture.stream_name = aif_name_list[dev_index];
 
+	/* Number of DAI's used is 1 */
 	ret = snd_soc_register_component(&pdev->dev, swr_dmic->driver,
-				NULL, 0);
+				swr_dmic->dai_driver, 1);
 	if (ret) {
 		dev_err(&pdev->dev, "%s: Codec registration failed\n",
 			__func__);
@@ -511,14 +546,14 @@ static int swr_dmic_probe(struct swr_device *pdev)
 						swr_dmic->driver->name);
 	swr_dmic->component = component;
 	prefix_name = devm_kzalloc(&pdev->dev,
-					strlen(swr_dmic_name_prefix_of),
+					strlen(swr_dmic_name_prefix_of) + 1,
 					GFP_KERNEL);
 	if (!prefix_name) {
 		ret = -ENOMEM;
 		goto dev_err;
 	}
 	strlcpy(prefix_name, swr_dmic_name_prefix_of,
-			strlen(swr_dmic_name_prefix_of));
+			strlen(swr_dmic_name_prefix_of) + 1);
 	component->name_prefix = prefix_name;
 
 	if (swr_dmic->is_en_supply == 1) {

+ 5 - 1
asoc/msm_dailink.h

@@ -512,7 +512,11 @@ SND_SOC_DAILINK_DEFS(tx_dma_tx3,
 SND_SOC_DAILINK_DEFS(tx_dma_tx4,
 	DAILINK_COMP_ARRAY(COMP_CPU("msm-dai-cdc-dma-dev.45113")),
 	DAILINK_COMP_ARRAY(COMP_CODEC("bolero_codec", "tx_macro_tx2"),
-			   COMP_CODEC("wcd938x_codec", "wcd938x_cdc")),
+			   COMP_CODEC("wcd938x_codec", "wcd938x_cdc"),
+			   COMP_CODEC("swr-dmic.01", "swr_dmic_tx0"),
+			   COMP_CODEC("swr-dmic.02", "swr_dmic_tx1"),
+			   COMP_CODEC("swr-dmic.03", "swr_dmic_tx2"),
+			   COMP_CODEC("swr-dmic.04", "swr_dmic_tx3")),
 	DAILINK_COMP_ARRAY(COMP_PLATFORM("msm-pcm-routing")));
 
 SND_SOC_DAILINK_DEFS(va_dma_tx0,