Quaternary MI2S Full Duplex

Hello,

We have connected the external codec on External Secondary MI2S pins.

Pin Function
GPIO117 WS
GPIO118 SCLK
GPIO119 SD0
GPIO112 SD1

We have referred the link Enabling LS-I2S on Dragonboard 410c

We would like to test playback and capture both simultaneously. Can you please suggest the kernel and dtsi changes?

Thanks,
Darshak

I think there is already a thread for this question:

Hey @danielt, see the thread you have suggested.

Can you please share the kernel changes for the MI2S_QUAT , similar as MI2S_PRIMARY.

static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
@@ -51,7 +55,9 @@ static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)

 	switch (cpu_dai->id) {
 	case MI2S_PRIMARY:
-		writel(readl(pdata->spkr_iomux) | SPKR_CTL_PRI_WS_SLAVE_SEL_11,
+		writel(readl(pdata->spkr_iomux) | SPKR_CTL_PRI_WS_SLAVE_SEL_11 |
+				SPKR_CTL_SCLK_EN | SPKR_CTL_DATA0_EN |
+				SPKR_CTL_DATA1_EN,
 			pdata->spkr_iomux);
 		break;

Because, I didn’t found this information in any documents.

Hi @darshak, I have never enabled input via the quaternary MI2S and thus don’t have any kernel changes to share.

Its okay @danielt , if you don’t have such changes.

Can you please guide us for spkr_iomux and mic_iomux register value or share detailed register description?

Thanks in advance

I’m afraid I don’t have access to non-public info about the 410E. For this type if info It is probably best to contact the support team from whoever sells you the chips (usually either Qualcomm or Arrow).

Hi,

We are able to play and record simultaneously on QUAT MI2S. Please refer the kernel changes to enable the support.

This patch fixes a bug where playback on bidirectional I2S interface stops
when we start recording on the same interface.

We use regmap_update_bits instead of regmap_write so that we will not clear
SPKEN and SPKMODE bits when we start/stop recording.

 sound/soc/qcom/lpass-apq8016.c   |  4 ++++
 sound/soc/qcom/lpass-cpu.c       | 23 +++++++++++++++++------
 sound/soc/qcom/lpass-lpaif-reg.h |  2 +-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/sound/soc/qcom/lpass-apq8016.c b/sound/soc/qcom/lpass-apq8016.c
index 8a74844..cb5f59d 100644
--- a/sound/soc/qcom/lpass-apq8016.c
+++ b/sound/soc/qcom/lpass-apq8016.c
@@ -130,6 +130,10 @@ static struct snd_soc_dai_driver apq8016_lpass_cpu_dai_driver[] = {
 		},
 		.probe	= &asoc_qcom_lpass_cpu_dai_probe,
 		.ops    = &asoc_qcom_lpass_cpu_dai_ops,
+		.symmetric_samplebits   = 1,
+		.symmetric_rates        = 1,
+
+
 	},
 };
 
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index c15d40f..032920e 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -82,6 +82,7 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
 	snd_pcm_format_t format = params_format(params);
 	unsigned int channels = params_channels(params);
 	unsigned int rate = params_rate(params);
+	unsigned int mask;
 	unsigned int regval;
 	int bitwidth, ret;
 
@@ -91,6 +92,7 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
 		return bitwidth;
 	}
 
+	mask   = LPAIF_I2SCTL_LOOPBACK_MASK | LPAIF_I2SCTL_WSSRC_MASK | LPAIF_I2SCTL_BITWIDTH_MASK;
 	regval = LPAIF_I2SCTL_LOOPBACK_DISABLE |
 			LPAIF_I2SCTL_WSSRC_INTERNAL;
 
@@ -110,6 +112,7 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
 	}
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		mask   |= LPAIF_I2SCTL_SPKMODE_MASK | LPAIF_I2SCTL_SPKMONO_MASK;
 		switch (channels) {
 		case 1:
 			if (dai->driver->id == MI2S_QUATERNARY)
@@ -152,6 +155,7 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
 			return -EINVAL;
 		}
 	} else {
+		mask   |= LPAIF_I2SCTL_MICMODE_MASK | LPAIF_I2SCTL_MICMONO_MASK;
 		switch (channels) {
 		case 1:
 			regval |= LPAIF_I2SCTL_MICMODE_SD0;
@@ -180,9 +184,9 @@ static int lpass_cpu_daiops_hw_params(struct snd_pcm_substream *substream,
 		}
 	}
 
-	ret = regmap_write(drvdata->lpaif_map,
-			   LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id),
-			   regval);
+	ret = regmap_update_bits(drvdata->lpaif_map,
+				 LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id),
+				 mask, regval);
 	if (ret) {
 		dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret);
 		return ret;
@@ -203,11 +207,18 @@ static int lpass_cpu_daiops_hw_free(struct snd_pcm_substream *substream,
 		struct snd_soc_dai *dai)
 {
 	struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
+	unsigned int mask;
 	int ret;
 
-	ret = regmap_write(drvdata->lpaif_map,
-			   LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id),
-			   0);
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		mask   = LPAIF_I2SCTL_SPKMODE_MASK;
+	} else {
+		mask   = LPAIF_I2SCTL_MICMODE_MASK;
+	}
+
+	ret = regmap_update_bits(drvdata->lpaif_map,
+				 LPAIF_I2SCTL_REG(drvdata->variant, dai->driver->id),
+				 mask, 0);
 	if (ret)
 		dev_err(dai->dev, "error writing to i2sctl reg: %d\n", ret);
 
diff --git a/sound/soc/qcom/lpass-lpaif-reg.h b/sound/soc/qcom/lpass-lpaif-reg.h
index 2240bc6..ff9dbc69 100644
--- a/sound/soc/qcom/lpass-lpaif-reg.h
+++ b/sound/soc/qcom/lpass-lpaif-reg.h
@@ -64,7 +64,7 @@
 #define LPAIF_I2SCTL_MICMODE_6CH	(7 << LPAIF_I2SCTL_MICMODE_SHIFT)
 #define LPAIF_I2SCTL_MICMODE_8CH	(8 << LPAIF_I2SCTL_MICMODE_SHIFT)
 
-#define LPAIF_I2SCTL_MIMONO_MASK	GENMASK(3, 3)
+#define LPAIF_I2SCTL_MICMONO_MASK	GENMASK(3, 3)
 #define LPAIF_I2SCTL_MICMONO_SHIFT	3
 #define LPAIF_I2SCTL_MICMONO_STEREO	(0 << LPAIF_I2SCTL_MICMONO_SHIFT)
 #define LPAIF_I2SCTL_MICMONO_MONO	(1 << LPAIF_I2SCTL_MICMONO_SHIFT)

Thanks,
Darshak

Thanks @darshak. @srini is working on getting these patches upstreamed. And these will be backported to LT kernel soon.

1 Like

Hi @srini,

With suggested patches, we are able to enable the full duplex support.
below command working fine every time.

arecord -D plughw:0,0 -c 2 -f S16_LE -r 48000 | tee hendset.wav | aplay -D plughw:0,0

But using below Gstreamer command pipeline not properly free by CTRL+C and audio not working every time

gst-launch-1.0 alsasrc device=plughw:0,0 ! capsfilter caps=“audio/x-raw, channels=2, rate=48000, format=S16LE, layout=interleaved” ! alsasink device=plughw:0,0

gst-launch-1.0 -v filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! capsfilter caps=“audio/x-raw, channels=1, rate=48000, format=S16LE, layout=interleaved” ! alsasink device=plughw:0,0

Our observation:
After Rebooting or first time run command it working fine.

Logs:

root@linaro-alip:~# gst-launch-1.0 -v filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! capsfilter caps=“audio/x-raw, channels=1, rate=48000, format=S16LE, layout=interleaved” ! alsasink device=plughw:0,0
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Redistribute latency…
/GstPipeline:pipeline0/GstAlsaSink:alsasink0.GstPad:sink: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstAudioSinkClock
Got EOS from element “pipeline0”.
Execution ended after 0:00:01.083614843
Setting pipeline to PAUSED …
Setting pipeline to READY …
Setting pipeline to NULL …
Freeing pipeline …
root@linaro-alip:~#

When we run same command second time, audio is not working and pipeline hang
Log:

root@linaro-alip:~# gst-launch-1.0 -v filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! capsfilter caps="audio/x-raw, channels=1, rate=48000, format=S16LE, layout=interleaved" ! alsasink device=plughw:0,0
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Redistribute latency…
/GstPipeline:pipeline0/GstAlsaSink:alsasink0.GstPad:sink: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstAudioSinkClock

no audio + Press CTRL+c then it hang at ‘Setting pipeline to PAUSED’ ,

^Chandling interrupt.
Interrupt: Stopping pipeline …
Execution ended after 0:00:07.383965934
Setting pipeline to PAUSED …

Again Press CTRL+c then run Gsteamer command now it’s work because we interrupted above pipeline at PAUSED stage.

All Logs,

root@linaro-alip:~# gst-launch-1.0 -v filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! capsfilter caps="audio/x-raw, channels=1, rate=48000, format=S16LE, layout=interleaved" ! alsasink device=plughw:0,0
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Redistribute latency…
/GstPipeline:pipeline0/GstAlsaSink:alsasink0.GstPad:sink: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstAudioSinkClock
^Chandling interrupt.
Interrupt: Stopping pipeline …
Execution ended after 0:00:02.652495051
Setting pipeline to PAUSED …
^C
root@linaro-alip:~# gst-launch-1.0 -v filesrc location= /usr/share/sounds/alsa/Front_Center.wav ! capsfilter caps="audio/x-raw, channels=1, rate=48000, format=S16LE, layout=interleaved" ! alsasink device=plughw:0,0
Setting pipeline to PAUSED …
Pipeline is PREROLLING …
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Redistribute latency…
/GstPipeline:pipeline0/GstAlsaSink:alsasink0.GstPad:sink: caps = audio/x-raw, channels=(int)1, rate=(int)48000, format=(string)S16LE, layout=(string)interleaved
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstAudioSinkClock
Got EOS from element “pipeline0”.
Execution ended after 0:00:01.082949010
Setting pipeline to PAUSED …
Setting pipeline to READY …
Setting pipeline to NULL …
Freeing pipeline …
root@linaro-alip:~#

Commands failed one time out of three try.

Thanks,
Darshak