Skip to contentSkip to conversation

ASoC: fsl_sai: Set SAI Channel Mode to Output Mode

PATCH In review Daniel Baluta 4 participants 5 messages Aug 30, 2019 – Sep 2, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: fsl_sai: Set SAI Channel Mode to Output Mode

Quoted 1 line

From SAI datasheet:

CHMOD, configures if transmit data pins are configured for TDM mode or Output mode.
* (0) TDM mode, transmit data pins are tri-stated when slots are masked or channels are disabled.
* (1) Output mode, transmit data pins are never tri-stated and will output zero when slots are masked or channels are disabled.

When data pins are tri-stated, there is noise on some channels when FS clock value is high and data is read while fsclk is transitioning from high to low.

Fix this by setting CHMOD to Output Mode so that pins will output zero when slots are masked or channels are disabled.

---
 sound/soc/fsl/fsl_sai.c | 15 ++++++++++++---
 sound/soc/fsl/fsl_sai.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/fsl/fsl_sai.c +12 -3
index e896b577b1f7..b9daab0eb6eb 100644
@@ -467,6 +467,12 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 
 	val_cr4 |= FSL_SAI_CR4_FRSZ(slots);
 
+	/*
+	 * set CHMOD to Output Mode so that transmit data pins will
+	 * output zero when slots are masked or channels are disabled
+	 */
+	val_cr4 |= FSL_SAI_CR4_CHMOD;
+
 	/*
 	 * For SAI master mode, when Tx(Rx) sync with Rx(Tx) clock, Rx(Tx) will
 	 * generate bclk and frame clock for Tx(Rx), we should set RCR4(TCR4),
@@ -477,7 +483,8 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 	if (!sai->is_slave_mode) {
 		if (!sai->synchronous[TX] && sai->synchronous[RX] && !tx) {
 			regmap_update_bits(sai->regmap, FSL_SAI_TCR4(ofs),
-				FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK,
+				FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK |
+				FSL_SAI_CR4_CHMOD_MASK,
 				val_cr4);
 			regmap_update_bits(sai->regmap, FSL_SAI_TCR5(ofs),
 				FSL_SAI_CR5_WNW_MASK | FSL_SAI_CR5_W0W_MASK |
@@ -486,7 +493,8 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 				~0UL - ((1 << channels) - 1));
 		} else if (!sai->synchronous[RX] && sai->synchronous[TX] && tx) {
 			regmap_update_bits(sai->regmap, FSL_SAI_RCR4(ofs),
-				FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK,
+				FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK |
+				FSL_SAI_CR4_CHMOD_MASK,
 				val_cr4);
 			regmap_update_bits(sai->regmap, FSL_SAI_RCR5(ofs),
 				FSL_SAI_CR5_WNW_MASK | FSL_SAI_CR5_W0W_MASK |
@@ -497,7 +505,8 @@ static int fsl_sai_hw_params(struct snd_pcm_substream *substream,
 	}
 
 	regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs),
-			   FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK,
+			   FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK |
+			   FSL_SAI_CR4_CHMOD_MASK,
 			   val_cr4);
 	regmap_update_bits(sai->regmap, FSL_SAI_xCR5(tx, ofs),
 			   FSL_SAI_CR5_WNW_MASK | FSL_SAI_CR5_W0W_MASK |
sound/soc/fsl/fsl_sai.h +2 -0
index f96f8d97489d..1e3b4a6889a8 100644
@@ -119,6 +119,8 @@
 #define FSL_SAI_CR4_FRSZ_MASK	(0x1f << 16)
 #define FSL_SAI_CR4_SYWD(x)	(((x) - 1) << 8)
 #define FSL_SAI_CR4_SYWD_MASK	(0x1f << 8)
+#define FSL_SAI_CR4_CHMOD	BIT(5)
+#define FSL_SAI_CR4_CHMOD_MASK	GENMASK(5, 5)
 #define FSL_SAI_CR4_MF		BIT(4)
 #define FSL_SAI_CR4_FSE		BIT(3)
 #define FSL_SAI_CR4_FSP		BIT(1)
Signature · 1 line
2.17.1
#1 lore raw

Looks good to me!

Best regards,
Cosmin

Quoted 108 lines · Daniel Baluta

From SAI datasheet:

CHMOD, configures if transmit data pins are configured for TDM mode or Output mode.
* (0) TDM mode, transmit data pins are tri-stated when slots
are
masked or channels are disabled.
* (1) Output mode, transmit data pins are never tri-stated and will output zero when slots are masked or channels are
disabled.

When data pins are tri-stated, there is noise on some channels when FS clock value is high and data is read while fsclk is transitioning from high to low.

Fix this by setting CHMOD to Output Mode so that pins will output zero
when slots are masked or channels are disabled.

---
 sound/soc/fsl/fsl_sai.c | 15 ++++++++++++---
 sound/soc/fsl/fsl_sai.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/fsl/fsl_sai.c +6 -0
index e896b577b1f7..b9daab0eb6eb 100644
@@ -467,6 +467,12 @@ static int fsl_sai_hw_params(struct
 snd_pcm_substream *substream,
 
 	val_cr4 |= FSL_SAI_CR4_FRSZ(slots);
 
+	/*
+	 * set CHMOD to Output Mode so that transmit data pins will
+	 * output zero when slots are masked or channels are disabled
+	 */
+	val_cr4 |= FSL_SAI_CR4_CHMOD;
+
 	/*
 	 * For SAI master mode, when Tx(Rx) sync with Rx(Tx) clock,

Rx(Tx) will
* generate bclk and frame clock for Tx(Rx), we should set
RCR4(TCR4),

sound/soc/fsl/fsl_sai.c +0 -1
@@ -477,7 +483,8 @@ static int fsl_sai_hw_params(struct
 snd_pcm_substream *substream,
 	if (!sai->is_slave_mode) {
 		if (!sai->synchronous[TX] && sai->synchronous[RX] &&
 !tx) {
 			regmap_update_bits(sai->regmap,
 FSL_SAI_TCR4(ofs),
-				FSL_SAI_CR4_SYWD_MASK |

FSL_SAI_CR4_FRSZ_MASK,

sound/soc/fsl/fsl_sai.c +1 -0
+				FSL_SAI_CR4_SYWD_MASK |

FSL_SAI_CR4_FRSZ_MASK |

sound/soc/fsl/fsl_sai.c +1 -0
+				FSL_SAI_CR4_CHMOD_MASK,
 				val_cr4);
 			regmap_update_bits(sai->regmap,

FSL_SAI_TCR5(ofs),
FSL_SAI_CR5_WNW_MASK |
FSL_SAI_CR5_W0W_MASK |

sound/soc/fsl/fsl_sai.c +0 -1
@@ -486,7 +493,8 @@ static int fsl_sai_hw_params(struct
 snd_pcm_substream *substream,
 				~0UL - ((1 << channels) - 1));
 		} else if (!sai->synchronous[RX] && sai-
 >synchronous[TX] && tx) {
 			regmap_update_bits(sai->regmap,
 FSL_SAI_RCR4(ofs),
-				FSL_SAI_CR4_SYWD_MASK |

FSL_SAI_CR4_FRSZ_MASK,

sound/soc/fsl/fsl_sai.c +1 -0
+				FSL_SAI_CR4_SYWD_MASK |

FSL_SAI_CR4_FRSZ_MASK |

sound/soc/fsl/fsl_sai.c +1 -0
+				FSL_SAI_CR4_CHMOD_MASK,
 				val_cr4);
 			regmap_update_bits(sai->regmap,

FSL_SAI_RCR5(ofs),
FSL_SAI_CR5_WNW_MASK |
FSL_SAI_CR5_W0W_MASK |

sound/soc/fsl/fsl_sai.c +1 -1
@@ -497,7 +505,8 @@ static int fsl_sai_hw_params(struct
 snd_pcm_substream *substream,
 	}
 
 	regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs),
-			   FSL_SAI_CR4_SYWD_MASK |
 FSL_SAI_CR4_FRSZ_MASK,
+			   FSL_SAI_CR4_SYWD_MASK |

FSL_SAI_CR4_FRSZ_MASK |

sound/soc/fsl/fsl_sai.c +1 -0
+			   FSL_SAI_CR4_CHMOD_MASK,
 			   val_cr4);
 	regmap_update_bits(sai->regmap, FSL_SAI_xCR5(tx, ofs),
 			   FSL_SAI_CR5_WNW_MASK | FSL_SAI_CR5_W0W_MASK

|

sound/soc/fsl/fsl_sai.h +2 -0
index f96f8d97489d..1e3b4a6889a8 100644
@@ -119,6 +119,8 @@
 #define FSL_SAI_CR4_FRSZ_MASK	(0x1f << 16)
 #define FSL_SAI_CR4_SYWD(x)	(((x) - 1) << 8)
 #define FSL_SAI_CR4_SYWD_MASK	(0x1f << 8)
+#define FSL_SAI_CR4_CHMOD	BIT(5)
+#define FSL_SAI_CR4_CHMOD_MASK	GENMASK(5, 5)
 #define FSL_SAI_CR4_MF		BIT(4)
 #define FSL_SAI_CR4_FSE		BIT(3)
 #define FSL_SAI_CR4_FSP		BIT(1)
maintainer
#2 lore raw
In reply to Daniel Baluta
Quoted 2 lines · Daniel Baluta

Fix this by setting CHMOD to Output Mode so that pins will output zero when slots are masked or channels are disabled.

This patch seems to do this unconditionally. This is fine for configurations where the SoC is the only thing driving the bus but will mean that for TDM configurations where something else also drives some of the slots we'll end up with both devices driving simultaneously. The safest thing would be to set this only if TDM isn't configured.

#3 lore raw
Quoted 11 lines · Mark Brown
Quoted 2 lines · Daniel Baluta

Fix this by setting CHMOD to Output Mode so that pins will output zero when slots are masked or channels are disabled.

This patch seems to do this unconditionally. This is fine for configurations where the SoC is the only thing driving the bus but will mean that for TDM configurations where something else also drives some of the slots we'll end up with both devices driving simultaneously. The safest thing would be to set this only if TDM isn't configured.

I thought that the SAI IP is the single owner of the audio data lines, so even in TDM
mode SAI IP (which is inside SoC) is the only one adding data on the bus.

Now, you say that there could be two devices driving some of he masked slots right?
I'm not sure how to really figure out that SAI is running in TDM mode.

RM says:

When enabled, the SAI continuously transmits and/or receives frames of data. Each
frame consists of a fixed number of words and each word consists of a fixed number of
bits. Within each frame, any given word can be masked causing the receiver to ignore
that word and the transmitter to tri-state for the duration of that word.

Will try to ask IP designer about this, thanks a lot for your comment!

Daniel.

maintainer
#4 lore raw
Quoted 8 lines · Daniel Baluta
Quoted 5 lines · Mark Brown

This patch seems to do this unconditionally. This is fine for configurations where the SoC is the only thing driving the bus but will mean that for TDM configurations where something else also drives some of the slots we'll end up with both devices driving simultaneously. The safest thing would be to set this only if TDM isn't configured.

Quoted 6 lines

I thought that the SAI IP is the single owner of the audio data lines, so even in TDM
mode SAI IP (which is inside SoC) is the only one adding data on the bus.

Now, you say that there could be two devices driving some of he masked slots right?

Doing that is the major point of TDM modes. It could even be another SAI on the same bus.

Quoted 1 line

I'm not sure how to really figure out that SAI is running in TDM mode.

As a first approximation you could just check if set_tdm_slots() has been called, it might still be the only device but it's a good first guess.