diff mbox series

[4/7] ASoC: amd: add ACP3x TDM mode support

Message ID 1571432760-3008-4-git-send-email-Vishnuvardhanrao.Ravulapati@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/7] ASoC: amd: Create multiple I2S platform device endpoints. | expand

Commit Message

RAVULAPATI, VISHNU VARDHAN RAO Oct. 18, 2019, 9:05 p.m. UTC
ACP3x I2S (CPU DAI) can act in normal I2S and TDM modes. Added support
for TDM mode. Desired mode can be selected from ASoC machine driver.

Signed-off-by: Ravulapati Vishnu vardhan rao <Vishnuvardhanrao.Ravulapati@amd.com>
---
 sound/soc/amd/raven/acp3x-i2s.c | 51 +++++++++++++++++++++++++++++++++--------
 sound/soc/amd/raven/acp3x.h     |  2 ++
 2 files changed, 43 insertions(+), 10 deletions(-)

Comments

vishnu Oct. 25, 2019, 7:06 a.m. UTC | #1
Hi Mark,

Any updates on this patch.

Regards,
Vishnu

On 19/10/19 2:35 AM, Ravulapati Vishnu vardhan rao wrote:
> ACP3x I2S (CPU DAI) can act in normal I2S and TDM modes. Added support
> for TDM mode. Desired mode can be selected from ASoC machine driver.
> 
> Signed-off-by: Ravulapati Vishnu vardhan rao <Vishnuvardhanrao.Ravulapati@amd.com>
> ---
>   sound/soc/amd/raven/acp3x-i2s.c | 51 +++++++++++++++++++++++++++++++++--------
>   sound/soc/amd/raven/acp3x.h     |  2 ++
>   2 files changed, 43 insertions(+), 10 deletions(-)
> 
> diff --git a/sound/soc/amd/raven/acp3x-i2s.c b/sound/soc/amd/raven/acp3x-i2s.c
> index b7f610f..7e22d22 100644
> --- a/sound/soc/amd/raven/acp3x-i2s.c
> +++ b/sound/soc/amd/raven/acp3x-i2s.c
> @@ -43,7 +43,8 @@ static int acp3x_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
>   		u32 rx_mask, int slots, int slot_width)
>   {
>   	u32 val = 0;
> -	u16 slot_len;
> +	u32 mode = 0;
> +	u16 slot_len, flen;
>   
>   	struct i2s_dev_data *adata = snd_soc_dai_get_drvdata(cpu_dai);
>   
> @@ -64,16 +65,46 @@ static int acp3x_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
>   		return -EINVAL;
>   	}
>   
> -	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_ITER);
> -	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_ITER);
> -	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_IRER);
> -	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_IRER);
> +	/* Enable I2S / BT channels TDM and respective
> +	 * I2S/BT`s TX/RX Formats frame lengths.
> +	 */
> +	flen = (FRM_LEN | (slots << 15) | (slot_len << 18));
>   
> -	val = (FRM_LEN | (slots << 15) | (slot_len << 18));
> -	rv_writel(val, adata->acp3x_base + mmACP_BTTDM_TXFRMT);
> -	rv_writel(val, adata->acp3x_base + mmACP_BTTDM_RXFRMT);
> -
> -	adata->tdm_fmt = val;
> +	if (adata->substream_type == SNDRV_PCM_STREAM_PLAYBACK) {
> +		switch (adata->i2s_instance) {
> +		case I2S_BT_INSTANCE:
> +			val = rv_readl(adata->acp3x_base + mmACP_BTTDM_ITER);
> +			rv_writel((val | 0x2),
> +				adata->acp3x_base + mmACP_BTTDM_ITER);
> +			rv_writel(flen,
> +				adata->acp3x_base + mmACP_BTTDM_TXFRMT);
> +		break;
> +		case I2S_SP_INSTANCE:
> +			val = rv_readl(adata->acp3x_base + mmACP_I2STDM_ITER);
> +			rv_writel((val | 0x2),
> +				adata->acp3x_base + mmACP_I2STDM_ITER);
> +			rv_writel(flen,
> +				adata->acp3x_base + mmACP_I2STDM_TXFRMT);
> +		}
> +	} else {
> +		switch (adata->i2s_instance) {
> +		case I2S_BT_INSTANCE:
> +			val = rv_readl(adata->acp3x_base + mmACP_BTTDM_IRER);
> +			rv_writel((val | 0x2),
> +				adata->acp3x_base + mmACP_BTTDM_IRER);
> +			rv_writel(flen,
> +				adata->acp3x_base + mmACP_BTTDM_RXFRMT);
> +		break;
> +		case I2S_SP_INSTANCE:
> +		default:
> +			val = rv_readl(adata->acp3x_base + mmACP_I2STDM_IRER);
> +			rv_writel((val | 0x2),
> +				adata->acp3x_base + mmACP_I2STDM_IRER);
> +			rv_writel(flen,
> +				adata->acp3x_base + mmACP_I2STDM_RXFRMT);
> +		}
> +	}
> +	adata->tdm_fmt = flen;
>   	return 0;
>   }
>   
> diff --git a/sound/soc/amd/raven/acp3x.h b/sound/soc/amd/raven/acp3x.h
> index b1990c9..dba7065 100644
> --- a/sound/soc/amd/raven/acp3x.h
> +++ b/sound/soc/amd/raven/acp3x.h
> @@ -76,6 +76,8 @@ struct i2s_dev_data {
>   	bool tdm_mode;
>   	unsigned int i2s_irq;
>   	u32 tdm_fmt;
> +	u16 i2s_instance;
> +	u32 substream_type;
>   	void __iomem *acp3x_base;
>   	struct snd_pcm_substream *play_stream;
>   	struct snd_pcm_substream *capture_stream;
>
diff mbox series

Patch

diff --git a/sound/soc/amd/raven/acp3x-i2s.c b/sound/soc/amd/raven/acp3x-i2s.c
index b7f610f..7e22d22 100644
--- a/sound/soc/amd/raven/acp3x-i2s.c
+++ b/sound/soc/amd/raven/acp3x-i2s.c
@@ -43,7 +43,8 @@  static int acp3x_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
 		u32 rx_mask, int slots, int slot_width)
 {
 	u32 val = 0;
-	u16 slot_len;
+	u32 mode = 0;
+	u16 slot_len, flen;
 
 	struct i2s_dev_data *adata = snd_soc_dai_get_drvdata(cpu_dai);
 
@@ -64,16 +65,46 @@  static int acp3x_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
 		return -EINVAL;
 	}
 
-	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_ITER);
-	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_ITER);
-	val = rv_readl(adata->acp3x_base + mmACP_BTTDM_IRER);
-	rv_writel((val | 0x2), adata->acp3x_base + mmACP_BTTDM_IRER);
+	/* Enable I2S / BT channels TDM and respective
+	 * I2S/BT`s TX/RX Formats frame lengths.
+	 */
+	flen = (FRM_LEN | (slots << 15) | (slot_len << 18));
 
-	val = (FRM_LEN | (slots << 15) | (slot_len << 18));
-	rv_writel(val, adata->acp3x_base + mmACP_BTTDM_TXFRMT);
-	rv_writel(val, adata->acp3x_base + mmACP_BTTDM_RXFRMT);
-
-	adata->tdm_fmt = val;
+	if (adata->substream_type == SNDRV_PCM_STREAM_PLAYBACK) {
+		switch (adata->i2s_instance) {
+		case I2S_BT_INSTANCE:
+			val = rv_readl(adata->acp3x_base + mmACP_BTTDM_ITER);
+			rv_writel((val | 0x2),
+				adata->acp3x_base + mmACP_BTTDM_ITER);
+			rv_writel(flen,
+				adata->acp3x_base + mmACP_BTTDM_TXFRMT);
+		break;
+		case I2S_SP_INSTANCE:
+			val = rv_readl(adata->acp3x_base + mmACP_I2STDM_ITER);
+			rv_writel((val | 0x2),
+				adata->acp3x_base + mmACP_I2STDM_ITER);
+			rv_writel(flen,
+				adata->acp3x_base + mmACP_I2STDM_TXFRMT);
+		}
+	} else {
+		switch (adata->i2s_instance) {
+		case I2S_BT_INSTANCE:
+			val = rv_readl(adata->acp3x_base + mmACP_BTTDM_IRER);
+			rv_writel((val | 0x2),
+				adata->acp3x_base + mmACP_BTTDM_IRER);
+			rv_writel(flen,
+				adata->acp3x_base + mmACP_BTTDM_RXFRMT);
+		break;
+		case I2S_SP_INSTANCE:
+		default:
+			val = rv_readl(adata->acp3x_base + mmACP_I2STDM_IRER);
+			rv_writel((val | 0x2),
+				adata->acp3x_base + mmACP_I2STDM_IRER);
+			rv_writel(flen,
+				adata->acp3x_base + mmACP_I2STDM_RXFRMT);
+		}
+	}
+	adata->tdm_fmt = flen;
 	return 0;
 }
 
diff --git a/sound/soc/amd/raven/acp3x.h b/sound/soc/amd/raven/acp3x.h
index b1990c9..dba7065 100644
--- a/sound/soc/amd/raven/acp3x.h
+++ b/sound/soc/amd/raven/acp3x.h
@@ -76,6 +76,8 @@  struct i2s_dev_data {
 	bool tdm_mode;
 	unsigned int i2s_irq;
 	u32 tdm_fmt;
+	u16 i2s_instance;
+	u32 substream_type;
 	void __iomem *acp3x_base;
 	struct snd_pcm_substream *play_stream;
 	struct snd_pcm_substream *capture_stream;