13
13
#include <linux/of_gpio.h>
14
14
#include <linux/of_device.h>
15
15
#include <linux/clk.h>
16
- #include <linux/pinctrl/consumer.h>
17
16
#include <linux/pm_runtime.h>
18
17
#include <linux/regmap.h>
19
18
#include <linux/spinlock.h>
@@ -55,40 +54,8 @@ struct rk_i2s_dev {
55
54
const struct rk_i2s_pins * pins ;
56
55
unsigned int bclk_ratio ;
57
56
spinlock_t lock ; /* tx/rx lock */
58
- struct pinctrl * pinctrl ;
59
- struct pinctrl_state * bclk_on ;
60
- struct pinctrl_state * bclk_off ;
61
57
};
62
58
63
- static int i2s_pinctrl_select_bclk_on (struct rk_i2s_dev * i2s )
64
- {
65
- int ret = 0 ;
66
-
67
- if (!IS_ERR (i2s -> pinctrl ) && !IS_ERR_OR_NULL (i2s -> bclk_on ))
68
- ret = pinctrl_select_state (i2s -> pinctrl ,
69
- i2s -> bclk_on );
70
-
71
- if (ret )
72
- dev_err (i2s -> dev , "bclk enable failed %d\n" , ret );
73
-
74
- return ret ;
75
- }
76
-
77
- static int i2s_pinctrl_select_bclk_off (struct rk_i2s_dev * i2s )
78
- {
79
-
80
- int ret = 0 ;
81
-
82
- if (!IS_ERR (i2s -> pinctrl ) && !IS_ERR_OR_NULL (i2s -> bclk_off ))
83
- ret = pinctrl_select_state (i2s -> pinctrl ,
84
- i2s -> bclk_off );
85
-
86
- if (ret )
87
- dev_err (i2s -> dev , "bclk disable failed %d\n" , ret );
88
-
89
- return ret ;
90
- }
91
-
92
59
static int i2s_runtime_suspend (struct device * dev )
93
60
{
94
61
struct rk_i2s_dev * i2s = dev_get_drvdata (dev );
@@ -125,49 +92,38 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai)
125
92
return snd_soc_dai_get_drvdata (dai );
126
93
}
127
94
128
- static int rockchip_snd_txctrl (struct rk_i2s_dev * i2s , int on )
95
+ static void rockchip_snd_txctrl (struct rk_i2s_dev * i2s , int on )
129
96
{
130
97
unsigned int val = 0 ;
131
98
int retry = 10 ;
132
- int ret = 0 ;
133
99
134
100
spin_lock (& i2s -> lock );
135
101
if (on ) {
136
- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
137
- I2S_DMACR_TDE_ENABLE , I2S_DMACR_TDE_ENABLE );
138
- if (ret < 0 )
139
- goto end ;
102
+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
103
+ I2S_DMACR_TDE_ENABLE , I2S_DMACR_TDE_ENABLE );
140
104
141
- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
142
- I2S_XFER_TXS_START | I2S_XFER_RXS_START ,
143
- I2S_XFER_TXS_START | I2S_XFER_RXS_START );
144
- if (ret < 0 )
145
- goto end ;
105
+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
106
+ I2S_XFER_TXS_START | I2S_XFER_RXS_START ,
107
+ I2S_XFER_TXS_START | I2S_XFER_RXS_START );
146
108
147
109
i2s -> tx_start = true;
148
110
} else {
149
111
i2s -> tx_start = false;
150
112
151
- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
152
- I2S_DMACR_TDE_ENABLE , I2S_DMACR_TDE_DISABLE );
153
- if (ret < 0 )
154
- goto end ;
113
+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
114
+ I2S_DMACR_TDE_ENABLE , I2S_DMACR_TDE_DISABLE );
155
115
156
116
if (!i2s -> rx_start ) {
157
- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
158
- I2S_XFER_TXS_START |
159
- I2S_XFER_RXS_START ,
160
- I2S_XFER_TXS_STOP |
161
- I2S_XFER_RXS_STOP );
162
- if (ret < 0 )
163
- goto end ;
117
+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
118
+ I2S_XFER_TXS_START |
119
+ I2S_XFER_RXS_START ,
120
+ I2S_XFER_TXS_STOP |
121
+ I2S_XFER_RXS_STOP );
164
122
165
123
udelay (150 );
166
- ret = regmap_update_bits (i2s -> regmap , I2S_CLR ,
167
- I2S_CLR_TXC | I2S_CLR_RXC ,
168
- I2S_CLR_TXC | I2S_CLR_RXC );
169
- if (ret < 0 )
170
- goto end ;
124
+ regmap_update_bits (i2s -> regmap , I2S_CLR ,
125
+ I2S_CLR_TXC | I2S_CLR_RXC ,
126
+ I2S_CLR_TXC | I2S_CLR_RXC );
171
127
172
128
regmap_read (i2s -> regmap , I2S_CLR , & val );
173
129
@@ -182,57 +138,44 @@ static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
182
138
}
183
139
}
184
140
}
185
- end :
186
141
spin_unlock (& i2s -> lock );
187
- if (ret < 0 )
188
- dev_err (i2s -> dev , "lrclk update failed\n" );
189
-
190
- return ret ;
191
142
}
192
143
193
- static int rockchip_snd_rxctrl (struct rk_i2s_dev * i2s , int on )
144
+ static void rockchip_snd_rxctrl (struct rk_i2s_dev * i2s , int on )
194
145
{
195
146
unsigned int val = 0 ;
196
147
int retry = 10 ;
197
- int ret = 0 ;
198
148
199
149
spin_lock (& i2s -> lock );
200
150
if (on ) {
201
- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
151
+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
202
152
I2S_DMACR_RDE_ENABLE , I2S_DMACR_RDE_ENABLE );
203
- if (ret < 0 )
204
- goto end ;
205
153
206
- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
154
+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
207
155
I2S_XFER_TXS_START | I2S_XFER_RXS_START ,
208
156
I2S_XFER_TXS_START | I2S_XFER_RXS_START );
209
- if (ret < 0 )
210
- goto end ;
211
157
212
158
i2s -> rx_start = true;
213
159
} else {
214
160
i2s -> rx_start = false;
215
161
216
- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
162
+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
217
163
I2S_DMACR_RDE_ENABLE , I2S_DMACR_RDE_DISABLE );
218
- if (ret < 0 )
219
- goto end ;
220
164
221
165
if (!i2s -> tx_start ) {
222
- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
166
+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
223
167
I2S_XFER_TXS_START |
224
168
I2S_XFER_RXS_START ,
225
169
I2S_XFER_TXS_STOP |
226
170
I2S_XFER_RXS_STOP );
227
- if (ret < 0 )
228
- goto end ;
171
+
229
172
udelay (150 );
230
- ret = regmap_update_bits (i2s -> regmap , I2S_CLR ,
173
+ regmap_update_bits (i2s -> regmap , I2S_CLR ,
231
174
I2S_CLR_TXC | I2S_CLR_RXC ,
232
175
I2S_CLR_TXC | I2S_CLR_RXC );
233
- if (ret < 0 )
234
- goto end ;
176
+
235
177
regmap_read (i2s -> regmap , I2S_CLR , & val );
178
+
236
179
/* Should wait for clear operation to finish */
237
180
while (val ) {
238
181
regmap_read (i2s -> regmap , I2S_CLR , & val );
@@ -244,12 +187,7 @@ static int rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
244
187
}
245
188
}
246
189
}
247
- end :
248
190
spin_unlock (& i2s -> lock );
249
- if (ret < 0 )
250
- dev_err (i2s -> dev , "lrclk update failed\n" );
251
-
252
- return ret ;
253
191
}
254
192
255
193
static int rockchip_i2s_set_fmt (struct snd_soc_dai * cpu_dai ,
@@ -487,26 +425,17 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream,
487
425
case SNDRV_PCM_TRIGGER_RESUME :
488
426
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :
489
427
if (substream -> stream == SNDRV_PCM_STREAM_CAPTURE )
490
- ret = rockchip_snd_rxctrl (i2s , 1 );
428
+ rockchip_snd_rxctrl (i2s , 1 );
491
429
else
492
- ret = rockchip_snd_txctrl (i2s , 1 );
493
- /* Do not turn on bclk if lrclk open fails. */
494
- if (ret < 0 )
495
- return ret ;
496
- i2s_pinctrl_select_bclk_on (i2s );
430
+ rockchip_snd_txctrl (i2s , 1 );
497
431
break ;
498
432
case SNDRV_PCM_TRIGGER_SUSPEND :
499
433
case SNDRV_PCM_TRIGGER_STOP :
500
434
case SNDRV_PCM_TRIGGER_PAUSE_PUSH :
501
- if (substream -> stream == SNDRV_PCM_STREAM_CAPTURE ) {
502
- if (!i2s -> tx_start )
503
- i2s_pinctrl_select_bclk_off (i2s );
504
- ret = rockchip_snd_rxctrl (i2s , 0 );
505
- } else {
506
- if (!i2s -> rx_start )
507
- i2s_pinctrl_select_bclk_off (i2s );
508
- ret = rockchip_snd_txctrl (i2s , 0 );
509
- }
435
+ if (substream -> stream == SNDRV_PCM_STREAM_CAPTURE )
436
+ rockchip_snd_rxctrl (i2s , 0 );
437
+ else
438
+ rockchip_snd_txctrl (i2s , 0 );
510
439
break ;
511
440
default :
512
441
ret = - EINVAL ;
@@ -807,33 +736,6 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
807
736
}
808
737
809
738
i2s -> bclk_ratio = 64 ;
810
- i2s -> pinctrl = devm_pinctrl_get (& pdev -> dev );
811
- if (IS_ERR (i2s -> pinctrl ))
812
- dev_err (& pdev -> dev , "failed to find i2s pinctrl\n" );
813
-
814
- i2s -> bclk_on = pinctrl_lookup_state (i2s -> pinctrl ,
815
- "bclk_on" );
816
- if (IS_ERR_OR_NULL (i2s -> bclk_on ))
817
- dev_err (& pdev -> dev , "failed to find i2s default state\n" );
818
- else
819
- dev_dbg (& pdev -> dev , "find i2s bclk state\n" );
820
-
821
- i2s -> bclk_off = pinctrl_lookup_state (i2s -> pinctrl ,
822
- "bclk_off" );
823
- if (IS_ERR_OR_NULL (i2s -> bclk_off ))
824
- dev_err (& pdev -> dev , "failed to find i2s gpio state\n" );
825
- else
826
- dev_dbg (& pdev -> dev , "find i2s bclk_off state\n" );
827
-
828
- i2s_pinctrl_select_bclk_off (i2s );
829
-
830
- i2s -> playback_dma_data .addr = res -> start + I2S_TXDR ;
831
- i2s -> playback_dma_data .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ;
832
- i2s -> playback_dma_data .maxburst = 4 ;
833
-
834
- i2s -> capture_dma_data .addr = res -> start + I2S_RXDR ;
835
- i2s -> capture_dma_data .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ;
836
- i2s -> capture_dma_data .maxburst = 4 ;
837
739
838
740
dev_set_drvdata (& pdev -> dev , i2s );
839
741
0 commit comments