]>
Commit | Line | Data |
---|---|---|
4495c89f JX |
1 | /* sound/soc/rockchip/rockchip_i2s.c |
2 | * | |
3 | * ALSA SoC Audio Layer - Rockchip I2S Controller driver | |
4 | * | |
5 | * Copyright (c) 2014 Rockchip Electronics Co. Ltd. | |
6 | * Author: Jianqun <jay.xu@rock-chips.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
12 | ||
1b21572f | 13 | #include <linux/module.h> |
4495c89f JX |
14 | #include <linux/delay.h> |
15 | #include <linux/of_gpio.h> | |
16 | #include <linux/clk.h> | |
17 | #include <linux/pm_runtime.h> | |
18 | #include <linux/regmap.h> | |
19 | #include <sound/pcm_params.h> | |
20 | #include <sound/dmaengine_pcm.h> | |
21 | ||
22 | #include "rockchip_i2s.h" | |
23 | ||
24 | #define DRV_NAME "rockchip-i2s" | |
25 | ||
26 | struct rk_i2s_dev { | |
27 | struct device *dev; | |
28 | ||
29 | struct clk *hclk; | |
30 | struct clk *mclk; | |
31 | ||
32 | struct snd_dmaengine_dai_dma_data capture_dma_data; | |
33 | struct snd_dmaengine_dai_dma_data playback_dma_data; | |
34 | ||
35 | struct regmap *regmap; | |
36 | ||
2458c377 | 37 | bool is_master_mode; |
4495c89f JX |
38 | }; |
39 | ||
40 | static int i2s_runtime_suspend(struct device *dev) | |
41 | { | |
42 | struct rk_i2s_dev *i2s = dev_get_drvdata(dev); | |
43 | ||
44 | clk_disable_unprepare(i2s->mclk); | |
45 | ||
46 | return 0; | |
47 | } | |
48 | ||
49 | static int i2s_runtime_resume(struct device *dev) | |
50 | { | |
51 | struct rk_i2s_dev *i2s = dev_get_drvdata(dev); | |
52 | int ret; | |
53 | ||
54 | ret = clk_prepare_enable(i2s->mclk); | |
55 | if (ret) { | |
56 | dev_err(i2s->dev, "clock enable failed %d\n", ret); | |
57 | return ret; | |
58 | } | |
59 | ||
60 | return 0; | |
61 | } | |
62 | ||
63 | static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) | |
64 | { | |
65 | return snd_soc_dai_get_drvdata(dai); | |
66 | } | |
67 | ||
68 | static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) | |
69 | { | |
70 | unsigned int val = 0; | |
71 | int retry = 10; | |
72 | ||
73 | if (on) { | |
74 | regmap_update_bits(i2s->regmap, I2S_DMACR, | |
75 | I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); | |
76 | ||
77 | regmap_update_bits(i2s->regmap, I2S_XFER, | |
eba65d17 JK |
78 | I2S_XFER_TXS_START, |
79 | I2S_XFER_TXS_START); | |
4495c89f | 80 | } else { |
4495c89f | 81 | regmap_update_bits(i2s->regmap, I2S_DMACR, |
4c5258ac | 82 | I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_DISABLE); |
4495c89f | 83 | |
eba65d17 JK |
84 | regmap_update_bits(i2s->regmap, I2S_XFER, |
85 | I2S_XFER_TXS_START, | |
86 | I2S_XFER_TXS_STOP); | |
4495c89f | 87 | |
eba65d17 JK |
88 | regmap_update_bits(i2s->regmap, I2S_CLR, |
89 | I2S_CLR_TXC, | |
90 | I2S_CLR_TXC); | |
4495c89f | 91 | |
eba65d17 | 92 | regmap_read(i2s->regmap, I2S_CLR, &val); |
4495c89f | 93 | |
eba65d17 JK |
94 | /* Should wait for clear operation to finish */ |
95 | while (val & I2S_CLR_TXC) { | |
96 | regmap_read(i2s->regmap, I2S_CLR, &val); | |
97 | retry--; | |
98 | if (!retry) { | |
99 | dev_warn(i2s->dev, "fail to clear\n"); | |
100 | break; | |
4495c89f JX |
101 | } |
102 | } | |
103 | } | |
104 | } | |
105 | ||
106 | static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) | |
107 | { | |
108 | unsigned int val = 0; | |
109 | int retry = 10; | |
110 | ||
111 | if (on) { | |
112 | regmap_update_bits(i2s->regmap, I2S_DMACR, | |
113 | I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); | |
114 | ||
115 | regmap_update_bits(i2s->regmap, I2S_XFER, | |
eba65d17 JK |
116 | I2S_XFER_RXS_START, |
117 | I2S_XFER_RXS_START); | |
4495c89f | 118 | } else { |
4495c89f JX |
119 | regmap_update_bits(i2s->regmap, I2S_DMACR, |
120 | I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_DISABLE); | |
121 | ||
eba65d17 JK |
122 | regmap_update_bits(i2s->regmap, I2S_XFER, |
123 | I2S_XFER_RXS_START, | |
124 | I2S_XFER_RXS_STOP); | |
4495c89f | 125 | |
eba65d17 JK |
126 | regmap_update_bits(i2s->regmap, I2S_CLR, |
127 | I2S_CLR_RXC, | |
128 | I2S_CLR_RXC); | |
4495c89f | 129 | |
eba65d17 | 130 | regmap_read(i2s->regmap, I2S_CLR, &val); |
4495c89f | 131 | |
eba65d17 JK |
132 | /* Should wait for clear operation to finish */ |
133 | while (val & I2S_CLR_RXC) { | |
134 | regmap_read(i2s->regmap, I2S_CLR, &val); | |
135 | retry--; | |
136 | if (!retry) { | |
137 | dev_warn(i2s->dev, "fail to clear\n"); | |
138 | break; | |
4495c89f JX |
139 | } |
140 | } | |
141 | } | |
142 | } | |
143 | ||
144 | static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, | |
145 | unsigned int fmt) | |
146 | { | |
147 | struct rk_i2s_dev *i2s = to_info(cpu_dai); | |
148 | unsigned int mask = 0, val = 0; | |
149 | ||
07833d88 | 150 | mask = I2S_CKR_MSS_MASK; |
4495c89f JX |
151 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
152 | case SND_SOC_DAIFMT_CBS_CFS: | |
07833d88 J |
153 | /* Set source clock in Master mode */ |
154 | val = I2S_CKR_MSS_MASTER; | |
2458c377 | 155 | i2s->is_master_mode = true; |
4495c89f JX |
156 | break; |
157 | case SND_SOC_DAIFMT_CBM_CFM: | |
07833d88 | 158 | val = I2S_CKR_MSS_SLAVE; |
2458c377 | 159 | i2s->is_master_mode = false; |
4495c89f JX |
160 | break; |
161 | default: | |
162 | return -EINVAL; | |
163 | } | |
164 | ||
165 | regmap_update_bits(i2s->regmap, I2S_CKR, mask, val); | |
166 | ||
167 | mask = I2S_TXCR_IBM_MASK; | |
168 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
169 | case SND_SOC_DAIFMT_RIGHT_J: | |
170 | val = I2S_TXCR_IBM_RSJM; | |
171 | break; | |
172 | case SND_SOC_DAIFMT_LEFT_J: | |
173 | val = I2S_TXCR_IBM_LSJM; | |
174 | break; | |
175 | case SND_SOC_DAIFMT_I2S: | |
176 | val = I2S_TXCR_IBM_NORMAL; | |
177 | break; | |
178 | default: | |
179 | return -EINVAL; | |
180 | } | |
181 | ||
182 | regmap_update_bits(i2s->regmap, I2S_TXCR, mask, val); | |
183 | ||
184 | mask = I2S_RXCR_IBM_MASK; | |
185 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
186 | case SND_SOC_DAIFMT_RIGHT_J: | |
187 | val = I2S_RXCR_IBM_RSJM; | |
188 | break; | |
189 | case SND_SOC_DAIFMT_LEFT_J: | |
190 | val = I2S_RXCR_IBM_LSJM; | |
191 | break; | |
192 | case SND_SOC_DAIFMT_I2S: | |
193 | val = I2S_RXCR_IBM_NORMAL; | |
194 | break; | |
195 | default: | |
196 | return -EINVAL; | |
197 | } | |
198 | ||
199 | regmap_update_bits(i2s->regmap, I2S_RXCR, mask, val); | |
200 | ||
201 | return 0; | |
202 | } | |
203 | ||
204 | static int rockchip_i2s_hw_params(struct snd_pcm_substream *substream, | |
205 | struct snd_pcm_hw_params *params, | |
206 | struct snd_soc_dai *dai) | |
207 | { | |
208 | struct rk_i2s_dev *i2s = to_info(dai); | |
b3f2dcdd | 209 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
4495c89f | 210 | unsigned int val = 0; |
2458c377 CW |
211 | unsigned int mclk_rate, bclk_rate, div_bclk, div_lrck; |
212 | ||
213 | if (i2s->is_master_mode) { | |
214 | mclk_rate = clk_get_rate(i2s->mclk); | |
215 | bclk_rate = 2 * 32 * params_rate(params); | |
216 | if (bclk_rate && mclk_rate % bclk_rate) | |
217 | return -EINVAL; | |
218 | ||
219 | div_bclk = mclk_rate / bclk_rate; | |
220 | div_lrck = bclk_rate / params_rate(params); | |
221 | regmap_update_bits(i2s->regmap, I2S_CKR, | |
222 | I2S_CKR_MDIV_MASK, | |
223 | I2S_CKR_MDIV(div_bclk)); | |
224 | ||
225 | regmap_update_bits(i2s->regmap, I2S_CKR, | |
226 | I2S_CKR_TSD_MASK | | |
227 | I2S_CKR_RSD_MASK, | |
228 | I2S_CKR_TSD(div_lrck) | | |
229 | I2S_CKR_RSD(div_lrck)); | |
230 | } | |
4495c89f JX |
231 | |
232 | switch (params_format(params)) { | |
233 | case SNDRV_PCM_FORMAT_S8: | |
234 | val |= I2S_TXCR_VDW(8); | |
235 | break; | |
236 | case SNDRV_PCM_FORMAT_S16_LE: | |
237 | val |= I2S_TXCR_VDW(16); | |
238 | break; | |
239 | case SNDRV_PCM_FORMAT_S20_3LE: | |
240 | val |= I2S_TXCR_VDW(20); | |
241 | break; | |
242 | case SNDRV_PCM_FORMAT_S24_LE: | |
243 | val |= I2S_TXCR_VDW(24); | |
244 | break; | |
245 | default: | |
246 | return -EINVAL; | |
247 | } | |
248 | ||
4c9c018b SZ |
249 | switch (params_channels(params)) { |
250 | case 8: | |
251 | val |= I2S_CHN_8; | |
252 | break; | |
253 | case 6: | |
254 | val |= I2S_CHN_6; | |
255 | break; | |
256 | case 4: | |
257 | val |= I2S_CHN_4; | |
258 | break; | |
259 | case 2: | |
260 | val |= I2S_CHN_2; | |
261 | break; | |
262 | default: | |
263 | dev_err(i2s->dev, "invalid channel: %d\n", | |
264 | params_channels(params)); | |
265 | return -EINVAL; | |
266 | } | |
267 | ||
268 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) | |
269 | regmap_update_bits(i2s->regmap, I2S_RXCR, | |
270 | I2S_RXCR_VDW_MASK | I2S_RXCR_CSR_MASK, | |
271 | val); | |
272 | else | |
273 | regmap_update_bits(i2s->regmap, I2S_TXCR, | |
274 | I2S_TXCR_VDW_MASK | I2S_TXCR_CSR_MASK, | |
275 | val); | |
276 | ||
bba14312 JX |
277 | regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDL_MASK, |
278 | I2S_DMACR_TDL(16)); | |
279 | regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_RDL_MASK, | |
280 | I2S_DMACR_RDL(16)); | |
4495c89f | 281 | |
b3f2dcdd SZ |
282 | val = I2S_CKR_TRCM_TXRX; |
283 | if (dai->driver->symmetric_rates || rtd->dai_link->symmetric_rates) | |
284 | val = I2S_CKR_TRCM_TXSHARE; | |
285 | ||
286 | regmap_update_bits(i2s->regmap, I2S_CKR, | |
287 | I2S_CKR_TRCM_MASK, | |
288 | val); | |
4495c89f JX |
289 | return 0; |
290 | } | |
291 | ||
292 | static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, | |
293 | int cmd, struct snd_soc_dai *dai) | |
294 | { | |
295 | struct rk_i2s_dev *i2s = to_info(dai); | |
296 | int ret = 0; | |
297 | ||
298 | switch (cmd) { | |
299 | case SNDRV_PCM_TRIGGER_START: | |
300 | case SNDRV_PCM_TRIGGER_RESUME: | |
301 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | |
302 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) | |
303 | rockchip_snd_rxctrl(i2s, 1); | |
304 | else | |
305 | rockchip_snd_txctrl(i2s, 1); | |
306 | break; | |
307 | case SNDRV_PCM_TRIGGER_SUSPEND: | |
308 | case SNDRV_PCM_TRIGGER_STOP: | |
309 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | |
310 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) | |
311 | rockchip_snd_rxctrl(i2s, 0); | |
312 | else | |
313 | rockchip_snd_txctrl(i2s, 0); | |
314 | break; | |
315 | default: | |
316 | ret = -EINVAL; | |
317 | break; | |
318 | } | |
319 | ||
320 | return ret; | |
321 | } | |
322 | ||
323 | static int rockchip_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, int clk_id, | |
324 | unsigned int freq, int dir) | |
325 | { | |
326 | struct rk_i2s_dev *i2s = to_info(cpu_dai); | |
327 | int ret; | |
328 | ||
329 | ret = clk_set_rate(i2s->mclk, freq); | |
330 | if (ret) | |
331 | dev_err(i2s->dev, "Fail to set mclk %d\n", ret); | |
332 | ||
333 | return ret; | |
334 | } | |
335 | ||
3b40a802 J |
336 | static int rockchip_i2s_dai_probe(struct snd_soc_dai *dai) |
337 | { | |
338 | struct rk_i2s_dev *i2s = snd_soc_dai_get_drvdata(dai); | |
339 | ||
340 | dai->capture_dma_data = &i2s->capture_dma_data; | |
341 | dai->playback_dma_data = &i2s->playback_dma_data; | |
342 | ||
343 | return 0; | |
344 | } | |
345 | ||
4495c89f JX |
346 | static const struct snd_soc_dai_ops rockchip_i2s_dai_ops = { |
347 | .hw_params = rockchip_i2s_hw_params, | |
348 | .set_sysclk = rockchip_i2s_set_sysclk, | |
349 | .set_fmt = rockchip_i2s_set_fmt, | |
350 | .trigger = rockchip_i2s_trigger, | |
351 | }; | |
352 | ||
353 | static struct snd_soc_dai_driver rockchip_i2s_dai = { | |
3b40a802 | 354 | .probe = rockchip_i2s_dai_probe, |
4495c89f | 355 | .playback = { |
3b40a802 | 356 | .stream_name = "Playback", |
4495c89f JX |
357 | .channels_min = 2, |
358 | .channels_max = 8, | |
359 | .rates = SNDRV_PCM_RATE_8000_192000, | |
360 | .formats = (SNDRV_PCM_FMTBIT_S8 | | |
361 | SNDRV_PCM_FMTBIT_S16_LE | | |
362 | SNDRV_PCM_FMTBIT_S20_3LE | | |
363 | SNDRV_PCM_FMTBIT_S24_LE), | |
364 | }, | |
365 | .capture = { | |
3b40a802 | 366 | .stream_name = "Capture", |
4495c89f JX |
367 | .channels_min = 2, |
368 | .channels_max = 2, | |
369 | .rates = SNDRV_PCM_RATE_8000_192000, | |
370 | .formats = (SNDRV_PCM_FMTBIT_S8 | | |
371 | SNDRV_PCM_FMTBIT_S16_LE | | |
372 | SNDRV_PCM_FMTBIT_S20_3LE | | |
373 | SNDRV_PCM_FMTBIT_S24_LE), | |
374 | }, | |
375 | .ops = &rockchip_i2s_dai_ops, | |
a12d159d | 376 | .symmetric_rates = 1, |
4495c89f JX |
377 | }; |
378 | ||
379 | static const struct snd_soc_component_driver rockchip_i2s_component = { | |
380 | .name = DRV_NAME, | |
381 | }; | |
382 | ||
383 | static bool rockchip_i2s_wr_reg(struct device *dev, unsigned int reg) | |
384 | { | |
385 | switch (reg) { | |
386 | case I2S_TXCR: | |
387 | case I2S_RXCR: | |
388 | case I2S_CKR: | |
389 | case I2S_DMACR: | |
390 | case I2S_INTCR: | |
391 | case I2S_XFER: | |
392 | case I2S_CLR: | |
393 | case I2S_TXDR: | |
394 | return true; | |
395 | default: | |
396 | return false; | |
397 | } | |
398 | } | |
399 | ||
400 | static bool rockchip_i2s_rd_reg(struct device *dev, unsigned int reg) | |
401 | { | |
402 | switch (reg) { | |
403 | case I2S_TXCR: | |
404 | case I2S_RXCR: | |
405 | case I2S_CKR: | |
406 | case I2S_DMACR: | |
407 | case I2S_INTCR: | |
408 | case I2S_XFER: | |
409 | case I2S_CLR: | |
410 | case I2S_RXDR: | |
2f1e93f8 J |
411 | case I2S_FIFOLR: |
412 | case I2S_INTSR: | |
4495c89f JX |
413 | return true; |
414 | default: | |
415 | return false; | |
416 | } | |
417 | } | |
418 | ||
419 | static bool rockchip_i2s_volatile_reg(struct device *dev, unsigned int reg) | |
420 | { | |
421 | switch (reg) { | |
4495c89f | 422 | case I2S_INTSR: |
2f1e93f8 | 423 | case I2S_CLR: |
4495c89f JX |
424 | return true; |
425 | default: | |
426 | return false; | |
427 | } | |
428 | } | |
429 | ||
430 | static bool rockchip_i2s_precious_reg(struct device *dev, unsigned int reg) | |
431 | { | |
432 | switch (reg) { | |
4495c89f JX |
433 | default: |
434 | return false; | |
435 | } | |
436 | } | |
437 | ||
438 | static const struct regmap_config rockchip_i2s_regmap_config = { | |
439 | .reg_bits = 32, | |
440 | .reg_stride = 4, | |
441 | .val_bits = 32, | |
442 | .max_register = I2S_RXDR, | |
443 | .writeable_reg = rockchip_i2s_wr_reg, | |
444 | .readable_reg = rockchip_i2s_rd_reg, | |
445 | .volatile_reg = rockchip_i2s_volatile_reg, | |
446 | .precious_reg = rockchip_i2s_precious_reg, | |
447 | .cache_type = REGCACHE_FLAT, | |
448 | }; | |
449 | ||
450 | static int rockchip_i2s_probe(struct platform_device *pdev) | |
451 | { | |
4c9c018b | 452 | struct device_node *node = pdev->dev.of_node; |
4495c89f | 453 | struct rk_i2s_dev *i2s; |
c4f9374d | 454 | struct snd_soc_dai_driver *soc_dai; |
4495c89f JX |
455 | struct resource *res; |
456 | void __iomem *regs; | |
457 | int ret; | |
4c9c018b | 458 | int val; |
4495c89f JX |
459 | |
460 | i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); | |
461 | if (!i2s) { | |
462 | dev_err(&pdev->dev, "Can't allocate rk_i2s_dev\n"); | |
463 | return -ENOMEM; | |
464 | } | |
465 | ||
466 | /* try to prepare related clocks */ | |
467 | i2s->hclk = devm_clk_get(&pdev->dev, "i2s_hclk"); | |
468 | if (IS_ERR(i2s->hclk)) { | |
469 | dev_err(&pdev->dev, "Can't retrieve i2s bus clock\n"); | |
470 | return PTR_ERR(i2s->hclk); | |
471 | } | |
01605ad1 J |
472 | ret = clk_prepare_enable(i2s->hclk); |
473 | if (ret) { | |
474 | dev_err(i2s->dev, "hclock enable failed %d\n", ret); | |
475 | return ret; | |
476 | } | |
4495c89f JX |
477 | |
478 | i2s->mclk = devm_clk_get(&pdev->dev, "i2s_clk"); | |
479 | if (IS_ERR(i2s->mclk)) { | |
480 | dev_err(&pdev->dev, "Can't retrieve i2s master clock\n"); | |
481 | return PTR_ERR(i2s->mclk); | |
482 | } | |
483 | ||
484 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
485 | regs = devm_ioremap_resource(&pdev->dev, res); | |
55b21944 | 486 | if (IS_ERR(regs)) |
4495c89f | 487 | return PTR_ERR(regs); |
4495c89f JX |
488 | |
489 | i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs, | |
490 | &rockchip_i2s_regmap_config); | |
491 | if (IS_ERR(i2s->regmap)) { | |
492 | dev_err(&pdev->dev, | |
493 | "Failed to initialise managed register map\n"); | |
494 | return PTR_ERR(i2s->regmap); | |
495 | } | |
496 | ||
497 | i2s->playback_dma_data.addr = res->start + I2S_TXDR; | |
498 | i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | |
27fd36ab | 499 | i2s->playback_dma_data.maxburst = 4; |
4495c89f JX |
500 | |
501 | i2s->capture_dma_data.addr = res->start + I2S_RXDR; | |
502 | i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | |
27fd36ab | 503 | i2s->capture_dma_data.maxburst = 4; |
4495c89f JX |
504 | |
505 | i2s->dev = &pdev->dev; | |
506 | dev_set_drvdata(&pdev->dev, i2s); | |
507 | ||
508 | pm_runtime_enable(&pdev->dev); | |
509 | if (!pm_runtime_enabled(&pdev->dev)) { | |
510 | ret = i2s_runtime_resume(&pdev->dev); | |
511 | if (ret) | |
512 | goto err_pm_disable; | |
513 | } | |
514 | ||
c4f9374d SZ |
515 | soc_dai = devm_kzalloc(&pdev->dev, |
516 | sizeof(*soc_dai), GFP_KERNEL); | |
517 | if (!soc_dai) | |
518 | return -ENOMEM; | |
519 | ||
520 | memcpy(soc_dai, &rockchip_i2s_dai, sizeof(*soc_dai)); | |
521 | if (!of_property_read_u32(node, "rockchip,playback-channels", &val)) { | |
522 | if (val >= 2 && val <= 8) | |
523 | soc_dai->playback.channels_max = val; | |
524 | } | |
525 | ||
4c9c018b SZ |
526 | if (!of_property_read_u32(node, "rockchip,capture-channels", &val)) { |
527 | if (val >= 2 && val <= 8) | |
c4f9374d | 528 | soc_dai->capture.channels_max = val; |
4c9c018b SZ |
529 | } |
530 | ||
4495c89f JX |
531 | ret = devm_snd_soc_register_component(&pdev->dev, |
532 | &rockchip_i2s_component, | |
c4f9374d SZ |
533 | soc_dai, 1); |
534 | ||
4495c89f JX |
535 | if (ret) { |
536 | dev_err(&pdev->dev, "Could not register DAI\n"); | |
537 | goto err_suspend; | |
538 | } | |
539 | ||
ebb75c0b | 540 | ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); |
4495c89f JX |
541 | if (ret) { |
542 | dev_err(&pdev->dev, "Could not register PCM\n"); | |
ebb75c0b | 543 | return ret; |
4495c89f JX |
544 | } |
545 | ||
546 | return 0; | |
547 | ||
4495c89f JX |
548 | err_suspend: |
549 | if (!pm_runtime_status_suspended(&pdev->dev)) | |
550 | i2s_runtime_suspend(&pdev->dev); | |
551 | err_pm_disable: | |
552 | pm_runtime_disable(&pdev->dev); | |
553 | ||
554 | return ret; | |
555 | } | |
556 | ||
557 | static int rockchip_i2s_remove(struct platform_device *pdev) | |
558 | { | |
559 | struct rk_i2s_dev *i2s = dev_get_drvdata(&pdev->dev); | |
560 | ||
561 | pm_runtime_disable(&pdev->dev); | |
562 | if (!pm_runtime_status_suspended(&pdev->dev)) | |
563 | i2s_runtime_suspend(&pdev->dev); | |
564 | ||
565 | clk_disable_unprepare(i2s->mclk); | |
566 | clk_disable_unprepare(i2s->hclk); | |
4495c89f JX |
567 | |
568 | return 0; | |
569 | } | |
570 | ||
571 | static const struct of_device_id rockchip_i2s_match[] = { | |
572 | { .compatible = "rockchip,rk3066-i2s", }, | |
573 | {}, | |
574 | }; | |
575 | ||
576 | static const struct dev_pm_ops rockchip_i2s_pm_ops = { | |
577 | SET_RUNTIME_PM_OPS(i2s_runtime_suspend, i2s_runtime_resume, | |
578 | NULL) | |
579 | }; | |
580 | ||
581 | static struct platform_driver rockchip_i2s_driver = { | |
582 | .probe = rockchip_i2s_probe, | |
583 | .remove = rockchip_i2s_remove, | |
584 | .driver = { | |
585 | .name = DRV_NAME, | |
4495c89f JX |
586 | .of_match_table = of_match_ptr(rockchip_i2s_match), |
587 | .pm = &rockchip_i2s_pm_ops, | |
588 | }, | |
589 | }; | |
590 | module_platform_driver(rockchip_i2s_driver); | |
591 | ||
592 | MODULE_DESCRIPTION("ROCKCHIP IIS ASoC Interface"); | |
593 | MODULE_AUTHOR("jianqun <jay.xu@rock-chips.com>"); | |
594 | MODULE_LICENSE("GPL v2"); | |
595 | MODULE_ALIAS("platform:" DRV_NAME); | |
596 | MODULE_DEVICE_TABLE(of, rockchip_i2s_match); |