Skip to content

Commit 08fdf65

Browse files
Nicolin Chenbroonie
Nicolin Chen
authored andcommitted
ASoC: fsl_sai: Add asynchronous mode support
SAI supports these operation modes: 1) asynchronous mode Both Tx and Rx are set to be asynchronous. 2) synchronous mode (Rx sync with Tx) Tx is set to be asynchronous, Rx is set to be synchronous. 3) synchronous mode (Tx sync with Rx) Rx is set to be asynchronous, Tx is set to be synchronous. 4) synchronous mode (Tx/Rx sync with another SAI's Tx) 5) synchronous mode (Tx/Rx sync with another SAI's Rx) * 4) and 5) are beyond this patch because they are related with another SAI. As the initial version of this SAI driver, it supported 2) as default while the others were totally missing. So this patch just adds supports for 1) and 3). Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent af96ff5 commit 08fdf65

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Documentation/devicetree/bindings/sound/fsl-sai.txt

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ Required properties:
2424
- big-endian-data: If this property is absent, the little endian mode will
2525
be in use as default, or the big endian mode will be in use for all the
2626
fifo data.
27+
- fsl,sai-synchronous-rx: This is a boolean property. If present, indicating
28+
that SAI will work in the synchronous mode (sync Tx with Rx) which means
29+
both the transimitter and receiver will send and receive data by following
30+
receiver's bit clocks and frame sync clocks.
31+
- fsl,sai-asynchronous: This is a boolean property. If present, indicating
32+
that SAI will work in the asynchronous mode, which means both transimitter
33+
and receiver will send and receive data by following their own bit clocks
34+
and frame sync clocks separately.
35+
36+
Note:
37+
- If both fsl,sai-asynchronous and fsl,sai-synchronous-rx are absent, the
38+
default synchronous mode (sync Rx with Tx) will be used, which means both
39+
transimitter and receiver will send and receive data by following clocks
40+
of transimitter.
41+
- fsl,sai-asynchronous will be ignored if fsl,sai-synchronous-rx property is
42+
already present.
2743

2844
Example:
2945
sai2: sai@40031000 {

sound/soc/fsl/fsl_sai.c

+26-4
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
330330
u32 xcsr, count = 100;
331331

332332
/*
333-
* The transmitter bit clock and frame sync are to be
334-
* used by both the transmitter and receiver.
333+
* Asynchronous mode: Clear SYNC for both Tx and Rx.
334+
* Rx sync with Tx clocks: Clear SYNC for Tx, set it for Rx.
335+
* Tx sync with Rx clocks: Clear SYNC for Rx, set it for Tx.
335336
*/
336-
regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC, 0);
337+
regmap_update_bits(sai->regmap, FSL_SAI_TCR2, FSL_SAI_CR2_SYNC,
338+
sai->synchronous[TX] ? FSL_SAI_CR2_SYNC : 0);
337339
regmap_update_bits(sai->regmap, FSL_SAI_RCR2, FSL_SAI_CR2_SYNC,
338-
FSL_SAI_CR2_SYNC);
340+
sai->synchronous[RX] ? FSL_SAI_CR2_SYNC : 0);
339341

340342
/*
341343
* It is recommended that the transmitter is the last enabled
@@ -625,6 +627,26 @@ static int fsl_sai_probe(struct platform_device *pdev)
625627
return ret;
626628
}
627629

630+
/* Sync Tx with Rx as default by following old DT binding */
631+
sai->synchronous[RX] = true;
632+
sai->synchronous[TX] = false;
633+
fsl_sai_dai.symmetric_rates = 1;
634+
fsl_sai_dai.symmetric_channels = 1;
635+
fsl_sai_dai.symmetric_samplebits = 1;
636+
637+
if (of_find_property(np, "fsl,sai-synchronous-rx", NULL)) {
638+
/* Sync Rx with Tx */
639+
sai->synchronous[RX] = false;
640+
sai->synchronous[TX] = true;
641+
} else if (of_find_property(np, "fsl,sai-asynchronous", NULL)) {
642+
/* Discard all settings for asynchronous mode */
643+
sai->synchronous[RX] = false;
644+
sai->synchronous[TX] = false;
645+
fsl_sai_dai.symmetric_rates = 0;
646+
fsl_sai_dai.symmetric_channels = 0;
647+
fsl_sai_dai.symmetric_samplebits = 0;
648+
}
649+
628650
sai->dma_params_rx.addr = res->start + FSL_SAI_RDR;
629651
sai->dma_params_tx.addr = res->start + FSL_SAI_TDR;
630652
sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX;

sound/soc/fsl/fsl_sai.h

+4
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ struct fsl_sai {
136136
bool big_endian_data;
137137
bool is_dsp_mode;
138138
bool sai_on_imx;
139+
bool synchronous[2];
139140

140141
struct snd_dmaengine_dai_dma_data dma_params_rx;
141142
struct snd_dmaengine_dai_dma_data dma_params_tx;
142143
};
143144

145+
#define TX 1
146+
#define RX 0
147+
144148
#endif /* __FSL_SAI_H */

0 commit comments

Comments
 (0)