2fb5789ef30a447563b0d0e72afbdc44eead0cb7
[openwrt/staging/ldir.git] /
1 From 06d8069b308a1655e0c248b6bd556e63d9b38099 Mon Sep 17 00:00:00 2001
2 From: Viorel Suman <viorel.suman@nxp.com>
3 Date: Wed, 3 May 2017 10:16:02 +0300
4 Subject: [PATCH] ASoC: fsl_sai: handle slave mode per TX/RX direction
5
6 The SAI interface can be a clock supplier or consummer
7 as function of stream direction, ie when interacting
8 with I2S XTOR. Removed FSL_SAI_RFR define as it is now
9 referred as FSL_SAI_RFR0.
10
11 Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
12 ---
13 sound/soc/fsl/fsl_sai.c | 18 +++++++++---------
14 sound/soc/fsl/fsl_sai.h | 3 +--
15 2 files changed, 10 insertions(+), 11 deletions(-)
16
17 --- a/sound/soc/fsl/fsl_sai.c
18 +++ b/sound/soc/fsl/fsl_sai.c
19 @@ -300,7 +300,7 @@ static int fsl_sai_set_dai_fmt_tr(struct
20 return -EINVAL;
21 }
22
23 - sai->is_slave_mode = false;
24 + sai->slave_mode[tx] = false;
25
26 /* DAI clock master masks */
27 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
28 @@ -310,7 +310,7 @@ static int fsl_sai_set_dai_fmt_tr(struct
29 sai->is_slave_mode = false;
30 break;
31 case SND_SOC_DAIFMT_CBM_CFM:
32 - sai->is_slave_mode = true;
33 + sai->slave_mode[tx] = true;
34 break;
35 case SND_SOC_DAIFMT_CBS_CFM:
36 val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
37 @@ -318,7 +318,7 @@ static int fsl_sai_set_dai_fmt_tr(struct
38 break;
39 case SND_SOC_DAIFMT_CBM_CFS:
40 val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
41 - sai->is_slave_mode = true;
42 + sai->slave_mode[tx] = true;
43 break;
44 default:
45 return -EINVAL;
46 @@ -359,7 +359,7 @@ static int fsl_sai_set_bclk(struct snd_s
47 int ret = 0;
48
49 /* Don't apply to slave mode */
50 - if (sai->is_slave_mode)
51 + if (sai->slave_mode[tx])
52 return 0;
53
54 for (id = 0; id < FSL_SAI_MCLK_MAX; id++) {
55 @@ -454,7 +454,7 @@ static int fsl_sai_hw_params(struct snd_
56 if (sai->slot_width)
57 slot_width = sai->slot_width;
58
59 - if (!sai->is_slave_mode) {
60 + if (!sai->slave_mode[tx]) {
61 ret = fsl_sai_set_bclk(cpu_dai, tx,
62 slots * slot_width * params_rate(params));
63 if (ret)
64 @@ -490,7 +490,7 @@ static int fsl_sai_hw_params(struct snd_
65 * error.
66 */
67
68 - if (!sai->is_slave_mode) {
69 + if (!sai->slave_mode[tx]) {
70 if (!sai->synchronous[TX] && sai->synchronous[RX] && !tx) {
71 regmap_update_bits(sai->regmap, FSL_SAI_TCR4,
72 FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK,
73 @@ -519,7 +519,7 @@ static int fsl_sai_hw_params(struct snd_
74 * error.
75 */
76
77 - if (!sai->is_slave_mode) {
78 + if (!sai->slave_mode[tx]) {
79 if (!sai->synchronous[TX] && sai->synchronous[RX] && !tx) {
80 regmap_update_bits(sai->regmap, FSL_SAI_TCR4,
81 FSL_SAI_CR4_SYWD_MASK | FSL_SAI_CR4_FRSZ_MASK,
82 @@ -577,7 +577,7 @@ static int fsl_sai_hw_free(struct snd_pc
83 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai);
84 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
85
86 - if (!sai->is_slave_mode &&
87 + if (!sai->slave_mode[tx] &&
88 sai->mclk_streams & BIT(substream->stream)) {
89 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[tx]]);
90 sai->mclk_streams &= ~BIT(substream->stream);
91 @@ -672,7 +672,7 @@ static int fsl_sai_trigger(struct snd_pc
92 * This is a hardware bug, and will be fix in the
93 * next sai version.
94 */
95 - if (!sai->is_slave_mode) {
96 + if (!sai->slave_mode[tx]) {
97 /* Software Reset for both Tx and Rx */
98 regmap_write(sai->regmap,
99 FSL_SAI_TCSR, FSL_SAI_CSR_SR);
100 --- a/sound/soc/fsl/fsl_sai.h
101 +++ b/sound/soc/fsl/fsl_sai.h
102 @@ -37,7 +37,6 @@
103 #define FSL_SAI_RDR1 0xa4 /* SAI Receive Data */
104 #define FSL_SAI_RFR0 0xc0 /* SAI Receive FIFO */
105 #define FSL_SAI_RFR1 0xc4 /* SAI Receive FIFO */
106 -#define FSL_SAI_RFR 0xc0 /* SAI Receive FIFO */
107 #define FSL_SAI_RMR 0xe0 /* SAI Receive Mask */
108
109 #define FSL_SAI_xCSR(tx) (tx ? FSL_SAI_TCSR : FSL_SAI_RCSR)
110 @@ -158,7 +157,7 @@ struct fsl_sai {
111 struct clk *bus_clk;
112 struct clk *mclk_clk[FSL_SAI_MCLK_MAX];
113
114 - bool is_slave_mode;
115 + bool slave_mode[2];
116 bool is_lsb_first;
117 bool is_dsp_mode;
118 bool sai_on_imx;