1313#include <linux/of_gpio.h>
1414#include <linux/of_device.h>
1515#include <linux/clk.h>
16- #include <linux/pinctrl/consumer.h>
1716#include <linux/pm_runtime.h>
1817#include <linux/regmap.h>
1918#include <linux/spinlock.h>
@@ -55,40 +54,8 @@ struct rk_i2s_dev {
5554 const struct rk_i2s_pins * pins ;
5655 unsigned int bclk_ratio ;
5756 spinlock_t lock ; /* tx/rx lock */
58- struct pinctrl * pinctrl ;
59- struct pinctrl_state * bclk_on ;
60- struct pinctrl_state * bclk_off ;
6157};
6258
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-
9259static int i2s_runtime_suspend (struct device * dev )
9360{
9461 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)
12592 return snd_soc_dai_get_drvdata (dai );
12693}
12794
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 )
12996{
13097 unsigned int val = 0 ;
13198 int retry = 10 ;
132- int ret = 0 ;
13399
134100 spin_lock (& i2s -> lock );
135101 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 );
140104
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 );
146108
147109 i2s -> tx_start = true;
148110 } else {
149111 i2s -> tx_start = false;
150112
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 );
155115
156116 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 );
164122
165123 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 );
171127
172128 regmap_read (i2s -> regmap , I2S_CLR , & val );
173129
@@ -182,57 +138,44 @@ static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
182138 }
183139 }
184140 }
185- end :
186141 spin_unlock (& i2s -> lock );
187- if (ret < 0 )
188- dev_err (i2s -> dev , "lrclk update failed\n" );
189-
190- return ret ;
191142}
192143
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 )
194145{
195146 unsigned int val = 0 ;
196147 int retry = 10 ;
197- int ret = 0 ;
198148
199149 spin_lock (& i2s -> lock );
200150 if (on ) {
201- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
151+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
202152 I2S_DMACR_RDE_ENABLE , I2S_DMACR_RDE_ENABLE );
203- if (ret < 0 )
204- goto end ;
205153
206- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
154+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
207155 I2S_XFER_TXS_START | I2S_XFER_RXS_START ,
208156 I2S_XFER_TXS_START | I2S_XFER_RXS_START );
209- if (ret < 0 )
210- goto end ;
211157
212158 i2s -> rx_start = true;
213159 } else {
214160 i2s -> rx_start = false;
215161
216- ret = regmap_update_bits (i2s -> regmap , I2S_DMACR ,
162+ regmap_update_bits (i2s -> regmap , I2S_DMACR ,
217163 I2S_DMACR_RDE_ENABLE , I2S_DMACR_RDE_DISABLE );
218- if (ret < 0 )
219- goto end ;
220164
221165 if (!i2s -> tx_start ) {
222- ret = regmap_update_bits (i2s -> regmap , I2S_XFER ,
166+ regmap_update_bits (i2s -> regmap , I2S_XFER ,
223167 I2S_XFER_TXS_START |
224168 I2S_XFER_RXS_START ,
225169 I2S_XFER_TXS_STOP |
226170 I2S_XFER_RXS_STOP );
227- if (ret < 0 )
228- goto end ;
171+
229172 udelay (150 );
230- ret = regmap_update_bits (i2s -> regmap , I2S_CLR ,
173+ regmap_update_bits (i2s -> regmap , I2S_CLR ,
231174 I2S_CLR_TXC | I2S_CLR_RXC ,
232175 I2S_CLR_TXC | I2S_CLR_RXC );
233- if (ret < 0 )
234- goto end ;
176+
235177 regmap_read (i2s -> regmap , I2S_CLR , & val );
178+
236179 /* Should wait for clear operation to finish */
237180 while (val ) {
238181 regmap_read (i2s -> regmap , I2S_CLR , & val );
@@ -244,12 +187,7 @@ static int rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
244187 }
245188 }
246189 }
247- end :
248190 spin_unlock (& i2s -> lock );
249- if (ret < 0 )
250- dev_err (i2s -> dev , "lrclk update failed\n" );
251-
252- return ret ;
253191}
254192
255193static 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,
487425 case SNDRV_PCM_TRIGGER_RESUME :
488426 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :
489427 if (substream -> stream == SNDRV_PCM_STREAM_CAPTURE )
490- ret = rockchip_snd_rxctrl (i2s , 1 );
428+ rockchip_snd_rxctrl (i2s , 1 );
491429 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 );
497431 break ;
498432 case SNDRV_PCM_TRIGGER_SUSPEND :
499433 case SNDRV_PCM_TRIGGER_STOP :
500434 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 );
510439 break ;
511440 default :
512441 ret = - EINVAL ;
@@ -807,33 +736,6 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
807736 }
808737
809738 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 ;
837739
838740 dev_set_drvdata (& pdev -> dev , i2s );
839741
0 commit comments