Skip to contentSkip to conversation

ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP

PATCH Superseded Sen Wang 3 participants 13 messages Jan 30 – Feb 5

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sen Wang

author maintainer
#0 lore raw

cover ASoC: ti: davinci-mcasp: Add asynchronous mode support for McASP

This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations.

It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze.

The implementation is based on vendor documentation and patches tested in both SK-AM62P-LP (sync mode, McASP slave) and AM62D-EVM (async mode, McASP master, rx & tx has different TDM configs). Testing verifies async mode functionality while maintaining backward compatibility with the default sync mode.

Bootlog and Async mode tests on AM62D-EVM: [0]

[0]: https://gist.github.com/SenWang125/f31f9172b186d414695e37c8b9ef127d

Sen Wang (4):
dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode
ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function
ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams
ASoC: ti: davinci-mcasp: Add asynchronous mode support

 .../bindings/sound/davinci-mcasp-audio.yaml   |  71 ++-
 include/linux/platform_data/davinci_asp.h     |   3 +-
 sound/soc/ti/davinci-mcasp.c                  | 510 ++++++++++++++----
 sound/soc/ti/davinci-mcasp.h                  |  10 +
 4 files changed, 479 insertions(+), 115 deletions(-)

base-commit: dbf8fe85a16a33d6b6bd01f2bc606fc017771465

Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 3/4 ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams

Simplify the mcasp_set_clk_pdir caller convention in start/stop stream function, to make it so that set_clk_pdir gets called regardless when stream starts and also disables when stream ends.

Functionality-wise, everything remains the same as the previously skipped calls are now either correctly configured
(when McASP is SND_SOC_DAIFMT_BP_FC - pdir needs to be enabled) or called with a bitmask of zero (when McASP is SND_SOC_DAIFMT_BC_FC - pdir gets disabled).

On brief regarding McASP Clock and Frame sync configurations, refer to [0].

[0]:TRM Section 12.1.1.4.2 https://www.ti.com/lit/ug/sprujd4a/sprujd4a.pdf

---
 sound/soc/ti/davinci-mcasp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/ti/davinci-mcasp.c +5 -5
index aa14fc1c8011..4f8a2ce6ce78 100644
@@ -235,8 +235,8 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
 	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) {
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
-		mcasp_set_clk_pdir(mcasp, true);
 	}
+	mcasp_set_clk_pdir(mcasp, true);
 
 	/* Activate serializer(s) */
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
@@ -311,10 +311,10 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode stop the TX clocks if no other stream is
 	 * running
 	 */
-	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) {
-		mcasp_set_clk_pdir(mcasp, false);
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams)
 		mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
-	}
+	if (!mcasp->streams)
+		mcasp_set_clk_pdir(mcasp, false);
 
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
@@ -340,7 +340,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
 	 */
 	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams)
 		val =  TXHCLKRST | TXCLKRST | TXFSRST;
-	else
+	if (!mcasp->streams)
 		mcasp_set_clk_pdir(mcasp, false);
 
 
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 4/4 ASoC: ti: davinci-mcasp: Add asynchronous mode support

In reply to Sen Wang

McASP has dedicated clock & frame sync registers for both transmit and receive. Currently McASP driver only supports synchronous behavior and couples both TX & RX settings.

Add logic that enables asynchronous mode via ti,async-mode property. In async mode, playback & record can be done simultaneously with different audio configurations (tdm slots, tdm width, audio bit depth).

Note the ability to have different tx/rx DSP formats (i2s, dsp_a, etc.), while possible in hardware, remains to be a gap as it require changes to the corresponding machine driver interface.

Existing IIS (sync mode) and DIT mode logic remains mostly unchanged. Exceptions are IIS mode logic that previously assumed sync mode, which has now been made aware of the distinction. And shared logic across all modes also now checks for McASP tx/rx-specific driver attributes. Those attributes have been populated according to the original extent, ensuring no divergence in functionality.

Constraints no longer applicable for async mode are skipped. Clock selection options have also been added to include rx/tx-only clk_ids, exposing independent configuration via the machine driver as well.

Note that asynchronous mode is not applicable for McASP in DIT mode, which is a transmitter-only mode to interface w/ self-clocking formats.

---
 include/linux/platform_data/davinci_asp.h |   3 +-
 sound/soc/ti/davinci-mcasp.c              | 487 +++++++++++++++++-----
 sound/soc/ti/davinci-mcasp.h              |  10 +
 3 files changed, 398 insertions(+), 102 deletions(-)
include/linux/platform_data/davinci_asp.h +2 -1
index b9c8520b4bd3..509c5592aab0 100644
@@ -59,7 +59,8 @@ struct davinci_mcasp_pdata {
 	bool i2s_accurate_sck;
 
 	/* McASP specific fields */
-	int tdm_slots;
+	int tdm_slots_tx;
+	int tdm_slots_rx;
 	u8 op_mode;
 	u8 dismod;
 	u8 num_serializer;
sound/soc/ti/davinci-mcasp.c +386 -101

848 lines not on this page · raw message

sound/soc/ti/davinci-mcasp.h +10 -0
index 5de2b8a31061..4eba8c918c5f 100644
@@ -298,10 +298,20 @@
 /* Source of High-frequency transmit/receive clock */
 #define MCASP_CLK_HCLK_AHCLK		0 /* AHCLKX/R */
 #define MCASP_CLK_HCLK_AUXCLK		1 /* Internal functional clock */
+#define MCASP_CLK_HCLK_AHCLK_TXONLY	2 /* AHCLKX for TX only */
+#define MCASP_CLK_HCLK_AHCLK_RXONLY	3 /* AHCLKR for RX only */
+#define MCASP_CLK_HCLK_AUXCLK_TXONLY	4 /* AUXCLK for TX only */
+#define MCASP_CLK_HCLK_AUXCLK_RXONLY	5 /* AUXCLK for RX only */
 
 /* clock divider IDs */
 #define MCASP_CLKDIV_AUXCLK		0 /* HCLK divider from AUXCLK */
 #define MCASP_CLKDIV_BCLK		1 /* BCLK divider from HCLK */
 #define MCASP_CLKDIV_BCLK_FS_RATIO	2 /* to set BCLK FS ration */
+#define MCASP_CLKDIV_AUXCLK_TXONLY	3 /* AUXCLK divider for TX only */
+#define MCASP_CLKDIV_AUXCLK_RXONLY	4 /* AUXCLK divider for RX only */
+#define MCASP_CLKDIV_BCLK_TXONLY	5 /* BCLK divider for TX only */
+#define MCASP_CLKDIV_BCLK_RXONLY	6 /* BCLK divider for RX only */
+#define MCASP_CLKDIV_BCLK_FS_RATIO_TXONLY 7 /* BCLK/FS ratio for TX only */
+#define MCASP_CLKDIV_BCLK_FS_RATIO_RXONLY 8 /* BCLK/FS ratio for RX only */
 
 #endif	/* DAVINCI_MCASP_H */
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 2/4 ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function

In reply to Sen Wang

The current mcasp_is_synchronous() function does more than what it proclaims, it also checks if McASP is a frame producer.

Therefore split the original function into two separate ones and replace all occurrences with the new equivalent logic. So the functions can be re-used when checking async/sync status in light of async mode enhancements.

---
 sound/soc/ti/davinci-mcasp.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
sound/soc/ti/davinci-mcasp.c +14 -7
index 621a9d5f9377..aa14fc1c8011 100644
@@ -179,10 +179,16 @@ static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val)
 
 static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
 {
-	u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
 	u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
 
-	return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE;
+	return !(aclkxctl & TX_ASYNC);
+}
+
+static bool mcasp_is_frame_producer(struct davinci_mcasp *mcasp)
+{
+	u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
+
+	return rxfmctl & AFSRE;
 }
 
 static inline void mcasp_set_clk_pdir(struct davinci_mcasp *mcasp, bool enable)
@@ -226,7 +232,7 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
 	 * synchronously from the transmit clock and frame sync. We need to make
 	 * sure that the TX signlas are enabled when starting reception.
 	 */
-	if (mcasp_is_synchronous(mcasp)) {
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) {
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
 		mcasp_set_clk_pdir(mcasp, true);
@@ -239,7 +245,7 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
 	mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
 	/* Release Frame Sync generator */
 	mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
-	if (mcasp_is_synchronous(mcasp))
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp))
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
 
 	/* enable receive IRQs */
@@ -305,7 +311,7 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode stop the TX clocks if no other stream is
 	 * running
 	 */
-	if (mcasp_is_synchronous(mcasp) && !mcasp->streams) {
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) {
 		mcasp_set_clk_pdir(mcasp, false);
 		mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
 	}
@@ -332,7 +338,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode keep TX clocks running if the capture stream is
 	 * still running.
 	 */
-	if (mcasp_is_synchronous(mcasp) && mcasp->streams)
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams)
 		val =  TXHCLKRST | TXCLKRST | TXFSRST;
 	else
 		mcasp_set_clk_pdir(mcasp, false);
@@ -1041,7 +1047,8 @@ static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream,
 		 * not running already we need to configure the TX slots in
 		 * order to have correct FSX on the bus
 		 */
-		if (mcasp_is_synchronous(mcasp) && !mcasp->channels)
+		if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) &&
+		    !mcasp->channels)
 			mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
 				       FSXMOD(total_slots), FSXMOD(0x1FF));
 	}
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/4 dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode

In reply to Sen Wang

McASP supports the independent configuration of TX & RX clk and frame sync registers. By default, the driver is configured in synchronous mode where RX clock generator is disabled and it uses transmit clock signals as bit clock and frame sync. Therefore add optional properties needed for asynchronous mode.

Add ti,async-mode boolean binding to provide a way to decouple the default behavior and allows for independent TX & RX clocking.

Add tdm-slots-rx uint32 binding to provide an alternative hardware specifier stating the number of RX serializers.
The existing property tdm-slots will still dictate number of TX serializers, and RX if tdm-slots-rx isn't given for backwards compatibility.

Add auxclk-fs-ratio-rx which allows to specify the ratio just for RX. The driver can be supplied with two different ratios (auxclk-fs-ratio and auxclk-fs-ratio-rx in tandem) and achieve two different sampling rates for tx & rx.

---
 .../bindings/sound/davinci-mcasp-audio.yaml   | 71 +++++++++++++++++--
 1 file changed, 66 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/sound/davinci-mcasp-audio.yaml +66 -5
index beef193aaaeb..87559d0d079a 100644
@@ -40,11 +40,33 @@ properties:
   tdm-slots:
     $ref: /schemas/types.yaml#/definitions/uint32
     description:
-      number of channels over one serializer
-      the property is ignored in DIT mode
+      Number of channels over one serializer. This property
+      specifies the TX playback TDM slot count, along with default RX slot count
+      if tdm-slots-rx is not specified.
+      The property is ignored in DIT mode.
     minimum: 2
     maximum: 32
 
+  tdm-slots-rx:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Number of RX capture channels over one serializer. If specified,
+      allows independent RX TDM slot count separate from TX. Requires
+      ti,async-mode to be enabled for independent TX/RX clock rates.
+      The property is ignored in DIT mode.
+    minimum: 2
+    maximum: 32
+
+  ti,async-mode:
+    description:
+      Specify to allow independent TX & RX clocking,
+      to enable audio playback & record with different sampling rate,
+      and different number of bits per frame.
+      if property is omitted, TX and RX will share same bit clock and frame clock signals,
+      thus RX need to use same bits per frame and sampling rate as TX in synchronous mode.
+      the property is ignored in DIT mode (as DIT is TX-only)
+    type: boolean
+
   serial-dir:
     description:
       A list of serializer configuration
@@ -125,7 +147,21 @@ properties:
 
   auxclk-fs-ratio:
     $ref: /schemas/types.yaml#/definitions/uint32
-    description: ratio of AUCLK and FS rate if applicable
+    description:
+      Ratio of AUCLK and FS rate if applicable. This property specifies
+      the TX ratio, along with default RX ratio if auxclk-fs-ratio-rx
+      is not specified.
+      When not specified, the inputted system clock frequency via set_sysclk
+      callback by the machine driver is used for divider calculation.
+
+  auxclk-fs-ratio-rx:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Ratio of AUCLK and FS rate for RX. If specified, allows
+      for a different RX ratio. Requires ti,async-mode to be
+      enabled when the ratio differs from auxclk-fs-ratio.
+      When not specified, it defaults to the value of auxclk-fs-ratio.
+      The property is ignored in DIT mode.
 
   gpio-controller: true
 
@@ -170,14 +206,38 @@ allOf:
   - $ref: dai-common.yaml#
   - if:
       properties:
-        opmode:
+        op-mode:
           enum:
             - 0
-
     then:
       required:
         - tdm-slots
 
+  - if:
+      properties:
+        op-mode:
+          const: 1
+    then:
+      properties:
+        tdm-slots: false
+        tdm-slots-rx: false
+        ti,async-mode: false
+        auxclk-fs-ratio-rx: false
+
+  - if:
+      required:
+        - tdm-slots-rx
+    then:
+      required:
+        - ti,async-mode
+
+  - if:
+      required:
+        - auxclk-fs-ratio-rx
+    then:
+      required:
+        - ti,async-mode
+
 unevaluatedProperties: false
 
 examples:
@@ -190,6 +250,7 @@ examples:
       interrupt-names = "tx", "rx";
       op-mode = <0>;		/* MCASP_IIS_MODE */
       tdm-slots = <2>;
+      ti,async-mode;
       dmas = <&main_udmap 0xc400>, <&main_udmap 0x4400>;
       dma-names = "tx", "rx";
       serial-dir = <
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/4] dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode

Quoted 5 lines · Sen Wang

McASP supports the independent configuration of TX & RX clk and frame sync registers. By default, the driver is configured in synchronous mode where RX clock generator is disabled and it uses transmit clock signals as bit clock and frame sync. Therefore add optional properties needed for asynchronous mode.

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

Acked-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function

In reply to Sen Wang
Quoted 2 lines · Sen Wang

The current mcasp_is_synchronous() function does more than what it proclaims, it also checks if McASP is a frame producer.

True, the naming was not too precise. It is tasked to decide if the TX clock needs to be enabled for RX operation, which precisely when McASP is in synchronous mode _and_ it is clock provider.

Quoted 4 lines

Therefore split the original function into two separate ones and replace all occurrences with the new equivalent logic. So the functions can be re-used when checking async/sync status in light of async mode enhancements.

sound/soc/ti/davinci-mcasp.c static void mcasp_set_ctl_reg(struct

Quoted 11 lines
---
 sound/soc/ti/davinci-mcasp.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
sound/soc/ti/davinci-mcasp.c +0 -0
index 621a9d5f9377..aa14fc1c8011 100644
@@ -179,10 +179,16 @@ static void mcasp_set_ctl_reg(struct

davinci_mcasp *mcasp, u32 ctl_reg, u32 val)

Quoted 8 lines
sound/soc/ti/davinci-mcasp.c +1 -2
 static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
 {
-	u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
 	u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
 
-	return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE;
+	return !(aclkxctl & TX_ASYNC);

sound/soc/ti/davinci-mcasp.c static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val)

Quoted 10 lines
sound/soc/ti/davinci-mcasp.c +7 -0
+}
+
+static bool mcasp_is_frame_producer(struct davinci_mcasp *mcasp)
+{
+	u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
+
+	return rxfmctl & AFSRE;
 }
 
 static inline void mcasp_set_clk_pdir(struct davinci_mcasp *mcasp,

bool enable)

sound/soc/ti/davinci-mcasp.c static void mcasp_start_rx(struct davinci_mcasp

Quoted 1 line
sound/soc/ti/davinci-mcasp.c +0 -0
@@ -226,7 +232,7 @@ static void mcasp_start_rx(struct davinci_mcasp

*mcasp)

sound/soc/ti/davinci-mcasp.c static void mcasp_start_rx(struct davinci_mcasp

Quoted 9 lines
sound/soc/ti/davinci-mcasp.c +1 -1
 	 * synchronously from the transmit clock and frame sync. We need to make
 	 * sure that the TX signlas are enabled when starting reception.
 	 */
-	if (mcasp_is_synchronous(mcasp)) {
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) {
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
 		mcasp_set_clk_pdir(mcasp, true);
@@ -239,7 +245,7 @@ static void mcasp_start_rx(struct davinci_mcasp

*mcasp)

Quoted 9 lines
sound/soc/ti/davinci-mcasp.c +1 -1
 	mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
 	/* Release Frame Sync generator */
 	mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
-	if (mcasp_is_synchronous(mcasp))
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp))
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
 
 	/* enable receive IRQs */

sound/soc/ti/davinci-mcasp.c static void mcasp_stop_rx(struct davinci_mcasp *mcasp) · line 314

Quoted 5 lines
sound/soc/ti/davinci-mcasp.c +1 -1
@@ -305,7 +311,7 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode stop the TX clocks if no other stream is
 	 * running
 	 */
-	if (mcasp_is_synchronous(mcasp) && !mcasp->streams) {
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) &&

!mcasp->streams) {

sound/soc/ti/davinci-mcasp.c static void mcasp_stop_tx(struct davinci_mcasp *mcasp) · line 341

Quoted 9 lines
sound/soc/ti/davinci-mcasp.c +1 -1
 		mcasp_set_clk_pdir(mcasp, false);
 		mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
 	}
@@ -332,7 +338,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode keep TX clocks running if the capture stream is
 	 * still running.
 	 */
-	if (mcasp_is_synchronous(mcasp) && mcasp->streams)
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) &&

mcasp->streams)

sound/soc/ti/davinci-mcasp.c static int mcasp_i2s_hw_param(struct

Quoted 4 lines
sound/soc/ti/davinci-mcasp.c +0 -0
 		val =  TXHCLKRST | TXCLKRST | TXFSRST;
 	else
 		mcasp_set_clk_pdir(mcasp, false);
@@ -1041,7 +1047,8 @@ static int mcasp_i2s_hw_param(struct

davinci_mcasp *mcasp, int stream,

Quoted 9 lines
sound/soc/ti/davinci-mcasp.c +2 -1
 		 * not running already we need to configure the TX slots in
 		 * order to have correct FSX on the bus
 		 */
-		if (mcasp_is_synchronous(mcasp) && !mcasp->channels)
+		if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) &&
+		    !mcasp->channels)
 			mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
 				       FSXMOD(total_slots), FSXMOD(0x1FF));
 	}
Signature · 1 line
Péter
#7 lore raw

Re: [PATCH 3/4] ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams

In reply to Sen Wang
Quoted 34 lines · Sen Wang

Simplify the mcasp_set_clk_pdir caller convention in start/stop stream function, to make it so that set_clk_pdir gets called regardless when stream starts and also disables when stream ends.

Functionality-wise, everything remains the same as the previously skipped calls are now either correctly configured
(when McASP is SND_SOC_DAIFMT_BP_FC - pdir needs to be enabled) or called with a bitmask of zero (when McASP is SND_SOC_DAIFMT_BC_FC - pdir gets disabled).

On brief regarding McASP Clock and Frame sync configurations, refer to [0].

[0]:TRM Section 12.1.1.4.2 https://www.ti.com/lit/ug/sprujd4a/sprujd4a.pdf

---
 sound/soc/ti/davinci-mcasp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/ti/davinci-mcasp.c +1 -1
index aa14fc1c8011..4f8a2ce6ce78 100644
@@ -235,8 +235,8 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
 	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) {
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
 		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
-		mcasp_set_clk_pdir(mcasp, true);
 	}
+	mcasp_set_clk_pdir(mcasp, true);
 
 	/* Activate serializer(s) */
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);

sound/soc/ti/davinci-mcasp.c static void mcasp_stop_rx(struct davinci_mcasp *mcasp) · line 317

Quoted 10 lines
sound/soc/ti/davinci-mcasp.c +3 -3
@@ -311,10 +311,10 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
 	 * In synchronous mode stop the TX clocks if no other stream is
 	 * running
 	 */
-	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) {
-		mcasp_set_clk_pdir(mcasp, false);
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams)
 		mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
-	}
+	if (!mcasp->streams)
+		mcasp_set_clk_pdir(mcasp, false);

I'm not sure about this, but the sequence should be preserved, PDIR change first.

Quoted 12 lines
sound/soc/ti/davinci-mcasp.c +1 -1
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
 	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
@@ -340,7 +340,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
 	 */
 	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams)
 		val =  TXHCLKRST | TXCLKRST | TXFSRST;
-	else
+	if (!mcasp->streams)
 		mcasp_set_clk_pdir(mcasp, false);
 
 
Signature · 1 line
Péter
Acked-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support

In reply to Sen Wang

sound/soc/ti/davinci-mcasp.c

Quoted 35 lines · Sen Wang

McASP has dedicated clock & frame sync registers for both transmit and receive. Currently McASP driver only supports synchronous behavior and couples both TX & RX settings.

Add logic that enables asynchronous mode via ti,async-mode property. In async mode, playback & record can be done simultaneously with different audio configurations (tdm slots, tdm width, audio bit depth).

Note the ability to have different tx/rx DSP formats (i2s, dsp_a, etc.), while possible in hardware, remains to be a gap as it require changes to the corresponding machine driver interface.

Existing IIS (sync mode) and DIT mode logic remains mostly unchanged. Exceptions are IIS mode logic that previously assumed sync mode, which has now been made aware of the distinction. And shared logic across all modes also now checks for McASP tx/rx-specific driver attributes. Those attributes have been populated according to the original extent, ensuring no divergence in functionality.

Constraints no longer applicable for async mode are skipped. Clock selection options have also been added to include rx/tx-only clk_ids, exposing independent configuration via the machine driver as well.

Note that asynchronous mode is not applicable for McASP in DIT mode, which is a transmitter-only mode to interface w/ self-clocking formats.

---
 include/linux/platform_data/davinci_asp.h |   3 +-
 sound/soc/ti/davinci-mcasp.c              | 487 +++++++++++++++++-----
 sound/soc/ti/davinci-mcasp.h              |  10 +
 3 files changed, 398 insertions(+), 102 deletions(-)
sound/soc/ti/davinci-mcasp.c +0 -0

static void mcasp_start_rx(struct davinci_mcasp *mcasp)

sound/soc/ti/davinci-mcasp.c static void mcasp_start_rx(struct davinci_mcasp *mcasp) · line 292

Quoted 9 lines

{

sound/soc/ti/davinci-mcasp.c +2 -1
 	if (mcasp->rxnumevt) {	/* enable FIFO */
@@ -230,13 +288,17 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
 	/*
 	 * When ASYNC == 0 the transmit and receive sections operate
 	 * synchronously from the transmit clock and frame sync. We need to make
-	 * sure that the TX signlas are enabled when starting reception.
+	 * sure that the TX signals are enabled when starting reception.
+	 * Else set pin to be output when McASP is the master

In new code - while it might not match with old code - use producer instead of master.

Otherwise it looks nice, I trust you have tested the sync and DIT mode.

With this nitpick addressed:

Signature · 1 line
Péter
author maintainer
#3 lore raw

Re: [PATCH 1/4] dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode

In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 5 lines · Sen Wang

McASP supports the independent configuration of TX & RX clk and frame sync registers. By default, the driver is configured in synchronous mode where RX clock generator is disabled and it uses transmit clock signals as bit clock and frame sync. Therefore add optional properties needed for asynchronous mode.

Quoted 5 lines

Please submit patches using subject lines reflecting the style for the subsystem, this makes it easier for people to identify relevant patches. Look at what existing commits in the area you're changing are doing and make sure your subject lines visually resemble what they're doing. There's no need to resubmit to fix this alone.

Understood, my apologies for the malformed subject line. I picked a bad cherry to follow. Will ensure future patches align with the norm. Thank you for the catch.

Best,
Sen Wang

author maintainer
#8 lore raw

Re: [PATCH 3/4] ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams

In reply to Péter Ujfalusi
Quoted 34 lines · Péter Ujfalusi
Quoted 31 lines · Sen Wang

Simplify the mcasp_set_clk_pdir caller convention in start/stop stream function, to make it so that set_clk_pdir gets called regardless when stream starts and also disables when stream ends.

Functionality-wise, everything remains the same as the previously skipped calls are now either correctly configured
(when McASP is SND_SOC_DAIFMT_BP_FC - pdir needs to be enabled) or called with a bitmask of zero (when McASP is SND_SOC_DAIFMT_BC_FC - pdir gets disabled).

On brief regarding McASP Clock and Frame sync configurations, refer to [0].

[0]:TRM Section 12.1.1.4.2 https://www.ti.com/lit/ug/sprujd4a/sprujd4a.pdf

---
  sound/soc/ti/davinci-mcasp.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/ti/davinci-mcasp.c +1 -1
index aa14fc1c8011..4f8a2ce6ce78 100644
@@ -235,8 +235,8 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
  	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp)) {
  		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
  		mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
-		mcasp_set_clk_pdir(mcasp, true);
  	}
+	mcasp_set_clk_pdir(mcasp, true);
 
Quoted 17 lines

sound/soc/ti/davinci-mcasp.c static void mcasp_stop_rx(struct davinci_mcasp *mcasp) · line 317

Quoted 13 lines
sound/soc/ti/davinci-mcasp.c +3 -3
  	/* Activate serializer(s) */
  	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
@@ -311,10 +311,10 @@ static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
  	 * In synchronous mode stop the TX clocks if no other stream is
  	 * running
  	 */
-	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams) {
-		mcasp_set_clk_pdir(mcasp, false);
+	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && !mcasp->streams)
  		mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
-	}
+	if (!mcasp->streams)
+		mcasp_set_clk_pdir(mcasp, false);

I'm not sure about this, but the sequence should be preserved, PDIR change first.

Sounds good, I'll enforce the original order of operation in the new patch.

Quoted 13 lines

sound/soc/ti/davinci-mcasp.c static void mcasp_stop_tx(struct davinci_mcasp *mcasp) · line 346

Quoted 12 lines
sound/soc/ti/davinci-mcasp.c +1 -1
  	mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
  	mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
@@ -340,7 +340,7 @@ static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
  	 */
  	if (mcasp_is_frame_producer(mcasp) && mcasp_is_synchronous(mcasp) && mcasp->streams)
  		val =  TXHCLKRST | TXCLKRST | TXFSRST;
-	else
+	if (!mcasp->streams)
  		mcasp_set_clk_pdir(mcasp, false);
 
 

Best,
Sen Wang

author maintainer
#11 lore raw

Re: [PATCH 4/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support

In reply to Péter Ujfalusi
Quoted 53 lines · Péter Ujfalusi

sound/soc/ti/davinci-mcasp.c

Quoted 35 lines · Sen Wang

McASP has dedicated clock & frame sync registers for both transmit and receive. Currently McASP driver only supports synchronous behavior and couples both TX & RX settings.

Add logic that enables asynchronous mode via ti,async-mode property. In async mode, playback & record can be done simultaneously with different audio configurations (tdm slots, tdm width, audio bit depth).

Note the ability to have different tx/rx DSP formats (i2s, dsp_a, etc.), while possible in hardware, remains to be a gap as it require changes to the corresponding machine driver interface.

Existing IIS (sync mode) and DIT mode logic remains mostly unchanged. Exceptions are IIS mode logic that previously assumed sync mode, which has now been made aware of the distinction. And shared logic across all modes also now checks for McASP tx/rx-specific driver attributes. Those attributes have been populated according to the original extent, ensuring no divergence in functionality.

Constraints no longer applicable for async mode are skipped. Clock selection options have also been added to include rx/tx-only clk_ids, exposing independent configuration via the machine driver as well.

Note that asynchronous mode is not applicable for McASP in DIT mode, which is a transmitter-only mode to interface w/ self-clocking formats.

---
  include/linux/platform_data/davinci_asp.h |   3 +-
  sound/soc/ti/davinci-mcasp.c              | 487 +++++++++++++++++-----
  sound/soc/ti/davinci-mcasp.h              |  10 +
  3 files changed, 398 insertions(+), 102 deletions(-)
sound/soc/ti/davinci-mcasp.c +0 -0

static void mcasp_start_rx(struct davinci_mcasp *mcasp)

sound/soc/ti/davinci-mcasp.c static void mcasp_start_rx(struct davinci_mcasp *mcasp) · line 292

Quoted 9 lines
  {
  	if (mcasp->rxnumevt) {	/* enable FIFO */
sound/soc/ti/davinci-mcasp.c +2 -1
@@ -230,13 +288,17 @@ static void mcasp_start_rx(struct davinci_mcasp *mcasp)
  	/*
  	 * When ASYNC == 0 the transmit and receive sections operate
  	 * synchronously from the transmit clock and frame sync. We need to make
-	 * sure that the TX signlas are enabled when starting reception.
+	 * sure that the TX signals are enabled when starting reception.
+	 * Else set pin to be output when McASP is the master

In new code - while it might not match with old code - use producer instead of master.

Quoted 5 lines

Otherwise it looks nice, I trust you have tested the sync and DIT mode.

With this nitpick addressed:

Hi Péter, thanks for your review

I'll use inclusive terminology (producer) instead.

I've functionally tested IIS sync mode. For DIT mode, since I don't have hardware available, I've only done a register dump in comparison, during idle, playback & shutdown - all registers in effect stay unchanged.

Will post a V2 shortly with all the corrections.

Best,
Sen Wang

maintainer
#12 lore raw
In reply to Sen Wang
Quoted 10 lines · Sen Wang

This series adds asynchronous mode support to the McASP driver, which enables independent configuration of bitclocks, frame sync, and audio configurations between tx(playback) and rx(record). And achieves simultaneous playback & record using different audio configurations.

It also adds two clean up patches to the McASP driver that disambiguate and simplifies the logic which avoids the async enhancement from being too convoluted to review and analyze.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/4] dt-bindings: sound: davinci-mcasp: Add optional properties for asynchronous mode
(no commit info)
[2/4] ASoC: ti: davinci-mcasp: Disambiguate mcasp_is_synchronous function

      commit: e683cb088fdcbdc86fc30008319312cc0bb80226
[3/4] ASoC: ti: davinci-mcasp: Streamline pdir behavior across rx & tx streams
      commit: 016efcaa470cdbc658df46d968d875f6a1cf9a78
[4/4] ASoC: ti: davinci-mcasp: Add asynchronous mode support
      commit: 9db327083f7e0da702e2ec0169f8a34f3576f371

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark