import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / sound / soc / mediatek / mt_soc_audio_v3 / mt_soc_dai_stub.c
1 /*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /*******************************************************************************
17 *
18 * Filename:
19 * ---------
20 * mtk_dai_stub
21 *
22 * Project:
23 * --------
24 *
25 *
26 * Description:
27 * ------------
28 * Audio dai stub file
29 *
30 * Author:
31 * -------
32 * Chipeng Chang
33 *
34 *------------------------------------------------------------------------------
35 * $Revision: #1 $
36 * $Modtime:$
37 * $Log:$
38 *
39 *
40 *******************************************************************************/
41
42
43 /*****************************************************************************
44 * C O M P I L E R F L A G S
45 *****************************************************************************/
46
47
48 /*****************************************************************************
49 * E X T E R N A L R E F E R E N C E S
50 *****************************************************************************/
51
52 #include <linux/dma-mapping.h>
53 #include <linux/init.h>
54 #include <linux/module.h>
55 #include <linux/device.h>
56 #include <linux/platform_device.h>
57 #include <sound/core.h>
58 #include <sound/pcm.h>
59 #include <sound/soc.h>
60
61 #include "AudDrv_Common.h"
62 #include "AudDrv_Def.h"
63 #include "AudDrv_Afe.h"
64 #include "AudDrv_Ana.h"
65 #include "AudDrv_Clk.h"
66 #include "mt_soc_pcm_common.h"
67
68
69 /* Conventional and unconventional sample rate supported */
70 static unsigned int audio_ap_supported_high_sample_rates[] =
71 {
72 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
73 96000, 192000
74 };
75
76 static struct snd_pcm_hw_constraint_list constraints_sample_rates =
77 {
78 .count = ARRAY_SIZE(audio_ap_supported_high_sample_rates),
79 .list = audio_ap_supported_high_sample_rates,
80 .mask = 0,
81 };
82
83
84 static int multimedia_startup(struct snd_pcm_substream *substream,
85 struct snd_soc_dai *dai)
86 {
87 snd_pcm_hw_constraint_list(substream->runtime, 0,
88 SNDRV_PCM_HW_PARAM_RATE,
89 &constraints_sample_rates);
90 return 0;
91 }
92
93 static struct snd_soc_dai_ops mtk_dai_stub_ops =
94 {
95 .startup = multimedia_startup,
96 };
97
98 static struct snd_soc_dai_driver mtk_dai_stub_dai[] =
99 {
100 {
101 .playback = {
102 .stream_name = MT_SOC_DL1_STREAM_NAME,
103 .rates = SNDRV_PCM_RATE_8000_192000,
104 .formats = SND_SOC_ADV_MT_FMTS,
105 .channels_min = 1,
106 .channels_max = 2,
107 .rate_min = 8000,
108 .rate_max = 192000,
109 },
110 .name = MT_SOC_DL1DAI_NAME,
111 .ops = &mtk_dai_stub_ops,
112 },
113 {
114 .capture = {
115 .stream_name = MT_SOC_UL1_STREAM_NAME,
116 .rates = SNDRV_PCM_RATE_8000_192000,
117 .formats = SND_SOC_ADV_MT_FMTS,
118 .channels_min = 1,
119 .channels_max = 2,
120 .rate_min = 8000,
121 .rate_max = 192000,
122 },
123 .name = MT_SOC_UL1DAI_NAME,
124 .ops = &mtk_dai_stub_ops,
125 },
126 {
127 .capture = {
128 .stream_name = MT_SOC_TDM_CAPTURE_STREAM_NAME,
129 .rates = SNDRV_PCM_RATE_8000_48000,
130 .formats = SNDRV_PCM_FMTBIT_S16_LE,
131 .channels_min = 1,
132 .channels_max = 8,
133 .rate_min = 8000,
134 .rate_max = 48000,
135 },
136 .name = MT_SOC_TDMRX_NAME,
137 .ops = &mtk_dai_stub_ops,
138 },
139 {
140 .playback = {
141 .stream_name = MT_SOC_HDMI_STREAM_NAME,
142 .rates = SNDRV_PCM_RATE_8000_192000,
143 .formats = SND_SOC_ADV_MT_FMTS,
144 .channels_min = 1,
145 .channels_max = 8,
146 .rate_min = 8000,
147 .rate_max = 192000,
148 },
149 .capture = {
150 .stream_name = MT_SOC_HDMI_STREAM_NAME,
151 .rates = SNDRV_PCM_RATE_8000_192000,
152 .formats = SND_SOC_ADV_MT_FMTS,
153 .channels_min = 1,
154 .channels_max = 8,
155 .rate_min = 8000,
156 .rate_max = 192000,
157 },
158 .name = MT_SOC_HDMI_NAME,
159 .ops = &mtk_dai_stub_ops,
160 },
161 {
162 .playback = {
163 .stream_name = MT_SOC_VOICE_MD1_BT_STREAM_NAME,
164 .rates = SNDRV_PCM_RATE_8000_48000,
165 .formats = SND_SOC_ADV_MT_FMTS,
166 .channels_min = 1,
167 .channels_max = 2,
168 .rate_min = 8000,
169 .rate_max = 32000,
170 },
171 .name = MT_SOC_VOICE_MD1_BT_NAME,
172 .ops = &mtk_dai_stub_ops,
173 },
174
175 {
176 .playback = {
177 .stream_name = MT_SOC_VOICE_MD2_BT_STREAM_NAME,
178 .rates = SNDRV_PCM_RATE_8000_48000,
179 .formats = SND_SOC_ADV_MT_FMTS,
180 .channels_min = 1,
181 .channels_max = 2,
182 .rate_min = 8000,
183 .rate_max = 32000,
184 },
185 .name = MT_SOC_VOICE_MD2_BT_NAME,
186 .ops = &mtk_dai_stub_ops,
187 },
188 {
189 .playback = {
190 .stream_name = MT_SOC_VOIP_BT_OUT_STREAM_NAME,
191 .rates = SNDRV_PCM_RATE_8000_48000,
192 .formats = SND_SOC_ADV_MT_FMTS,
193 .channels_min = 1,
194 .channels_max = 2,
195 .rate_min = 8000,
196 .rate_max = 48000,
197 },
198 .name = MT_SOC_VOIP_CALL_BT_OUT_NAME,
199 .ops = &mtk_dai_stub_ops,
200 },
201 {
202 .capture = {
203 .stream_name = MT_SOC_VOIP_BT_IN_STREAM_NAME,
204 .rates = SNDRV_PCM_RATE_8000_48000,
205 .formats = SND_SOC_ADV_MT_FMTS,
206 .channels_min = 1,
207 .channels_max = 2,
208 .rate_min = 8000,
209 .rate_max = 48000,
210 },
211 .name = MT_SOC_VOIP_CALL_BT_IN_NAME,
212 .ops = &mtk_dai_stub_ops,
213 },
214 {
215 .playback = {
216 .stream_name = MT_SOC_FM_I2S2_STREAM_NAME,
217 .rates = SNDRV_PCM_RATE_8000_48000 ,
218 .formats = SND_SOC_ADV_MT_FMTS,
219 .channels_min = 1,
220 .channels_max = 2,
221 .rate_min = 8000,
222 .rate_max = 48000,
223 },
224 .name = "FM_I2S2_OUT",
225 .ops = &mtk_dai_stub_ops,
226 },
227 {
228 .capture = {
229 .stream_name = MT_SOC_FM_I2S2_RECORD_STREAM_NAME,
230 .rates = SNDRV_PCM_RATE_8000_48000,
231 .formats = SND_SOC_ADV_MT_FMTS,
232 .channels_min = 1,
233 .channels_max = 2,
234 .rate_min = 8000,
235 .rate_max = 48000,
236 },
237 .name = "FM_I2S2_IN",
238 .ops = &mtk_dai_stub_ops,
239 },
240 {
241 .playback = {
242 .stream_name = MT_SOC_VOICE_MD1_STREAM_NAME,
243 .rates = SNDRV_PCM_RATE_8000_48000,
244 .formats = SND_SOC_STD_MT_FMTS,
245 .channels_min = 1,
246 .channels_max = 2,
247 .rate_min = 8000,
248 .rate_max = 32000,
249 },
250 .capture = {
251 .stream_name = MT_SOC_VOICE_MD1_STREAM_NAME,
252 .rates = SNDRV_PCM_RATE_8000_48000,
253 .formats = SND_SOC_STD_MT_FMTS,
254 .channels_min = 1,
255 .channels_max = 2,
256 .rate_min = 8000,
257 .rate_max = 32000,
258 },
259 .name = MT_SOC_VOICE_MD1_NAME,
260 .ops = &mtk_dai_stub_ops,
261 },
262 {
263 .playback = {
264 .stream_name = MT_SOC_VOICE_MD2_STREAM_NAME,
265 .rates = SNDRV_PCM_RATE_8000_48000,
266 .formats = SND_SOC_STD_MT_FMTS,
267 .channels_min = 1,
268 .channels_max = 2,
269 .rate_min = 8000,
270 .rate_max = 32000,
271 },
272 .capture = {
273 .stream_name = MT_SOC_VOICE_MD2_STREAM_NAME,
274 .rates = SNDRV_PCM_RATE_8000_48000,
275 .formats = SND_SOC_STD_MT_FMTS,
276 .channels_min = 1,
277 .channels_max = 2,
278 .rate_min = 8000,
279 .rate_max = 32000,
280 },
281 .name = MT_SOC_VOICE_MD2_NAME,
282 .ops = &mtk_dai_stub_ops,
283 },
284 {
285 .playback = {
286 .stream_name = MT_SOC_ULDLLOOPBACK_STREAM_NAME,
287 .rates = SNDRV_PCM_RATE_8000_48000,
288 .formats = SND_SOC_ADV_MT_FMTS,
289 .channels_min = 1,
290 .channels_max = 2,
291 .rate_min = 8000,
292 .rate_max = 48000,
293 },
294 .capture = {
295 .stream_name = MT_SOC_ULDLLOOPBACK_STREAM_NAME,
296 .rates = SNDRV_PCM_RATE_8000_48000,
297 .formats = SND_SOC_ADV_MT_FMTS,
298 .channels_min = 1,
299 .channels_max = 2,
300 .rate_min = 8000,
301 .rate_max = 48000,
302 },
303 .name = MT_SOC_ULDLLOOPBACK_NAME,
304 .ops = &mtk_dai_stub_ops,
305 },
306 {
307 .playback = {
308 .stream_name = MT_SOC_I2S0_STREAM_NAME,
309 .rates = SNDRV_PCM_RATE_8000_192000,
310 .formats = SND_SOC_ADV_MT_FMTS,
311 .channels_min = 1,
312 .channels_max = 2,
313 .rate_min = 8000,
314 .rate_max = 192000,
315 },
316 .capture = {
317 .stream_name = MT_SOC_I2S0_STREAM_NAME,
318 .rates = SNDRV_PCM_RATE_8000_192000,
319 .formats = SND_SOC_ADV_MT_FMTS,
320 .channels_min = 1,
321 .channels_max = 2,
322 .rate_min = 8000,
323 .rate_max = 192000,
324 },
325 .name = MT_SOC_I2S0_NAME,
326 .ops = &mtk_dai_stub_ops,
327 },
328 {
329 .playback = {
330 .stream_name = MT_SOC_I2SDL1_STREAM_NAME,
331 .rates = SNDRV_PCM_RATE_8000_192000,
332 .formats = SND_SOC_ADV_MT_FMTS,
333 .channels_min = 1,
334 .channels_max = 2,
335 .rate_min = 8000,
336 .rate_max = 192000,
337 },
338 .name = MT_SOC_I2S0DL1_NAME,
339 .ops = &mtk_dai_stub_ops,
340 },
341 {
342 .capture = {
343 .stream_name = MT_SOC_DL1_AWB_RECORD_STREAM_NAME,
344 .rates = SNDRV_PCM_RATE_8000_192000,
345 .formats = SND_SOC_ADV_MT_FMTS,
346 .channels_min = 1,
347 .channels_max = 2,
348 .rate_min = 8000,
349 .rate_max = 48000,
350 },
351 .name = MT_SOC_DL1AWB_NAME,
352 .ops = &mtk_dai_stub_ops,
353 },
354 {
355 .playback = {
356 .stream_name = MT_SOC_MRGRX_STREAM_NAME,
357 .rates = SNDRV_PCM_RATE_8000_48000,
358 .formats = SND_SOC_ADV_MT_FMTS,
359 .channels_min = 1,
360 .channels_max = 2,
361 .rate_min = 8000,
362 .rate_max = 48000,
363 },
364 .capture = {
365 .stream_name = MT_SOC_MRGRX_STREAM_NAME,
366 .rates = SNDRV_PCM_RATE_8000_48000,
367 .formats = SND_SOC_ADV_MT_FMTS,
368 .channels_min = 1,
369 .channels_max = 2,
370 .rate_min = 8000,
371 .rate_max = 48000,
372 },
373 .name = MT_SOC_MRGRX_NAME,
374 .ops = &mtk_dai_stub_ops,
375 },
376 {
377 .playback = {
378 .stream_name = MT_SOC_MRGRX_CAPTURE_STREAM_NAME,
379 .rates = SNDRV_PCM_RATE_8000_48000,
380 .formats = SND_SOC_ADV_MT_FMTS,
381 .channels_min = 1,
382 .channels_max = 2,
383 .rate_min = 8000,
384 .rate_max = 48000,
385 },
386 .capture = {
387 .stream_name = MT_SOC_MRGRX_CAPTURE_STREAM_NAME,
388 .rates = SNDRV_PCM_RATE_8000_48000,
389 .formats = SND_SOC_ADV_MT_FMTS,
390 .channels_min = 1,
391 .channels_max = 2,
392 .rate_min = 8000,
393 .rate_max = 48000,
394 },
395 .name = MT_SOC_MRGRXCAPTURE_NAME,
396 .ops = &mtk_dai_stub_ops,
397 },
398 {
399 .playback = {
400 .stream_name = MT_SOC_FM_MRGTX_STREAM_NAME,
401 .rates = SNDRV_PCM_RATE_44100,
402 .formats = SND_SOC_ADV_MT_FMTS,
403 .channels_min = 1,
404 .channels_max = 2,
405 .rate_min = 44100,
406 .rate_max = 44100,
407 },
408 .name = MT_SOC_FM_MRGTX_NAME,
409 .ops = &mtk_dai_stub_ops,
410 },
411 {
412 .capture = {
413 .stream_name = MT_SOC_UL1DATA2_STREAM_NAME,
414 .rates = SNDRV_PCM_RATE_8000_48000,
415 .formats = SNDRV_PCM_FMTBIT_S16_LE,
416 .channels_min = 1,
417 .channels_max = 2,
418 .rate_min = 8000,
419 .rate_max = 48000,
420 },
421 .name = MT_SOC_UL2DAI_NAME,
422 .ops = &mtk_dai_stub_ops,
423 },
424 {
425 .capture = {
426 .stream_name = MT_SOC_I2S0AWB_STREAM_NAME,
427 .rates = SNDRV_PCM_RATE_8000_48000,
428 .formats = SNDRV_PCM_FMTBIT_S16_LE,
429 .channels_min = 1,
430 .channels_max = 2,
431 .rate_min = 8000,
432 .rate_max = 48000,
433 },
434 .name = MT_SOC_I2S0AWBDAI_NAME,
435 .ops = &mtk_dai_stub_ops,
436 },
437
438 {
439 .capture = {
440 .stream_name = MT_SOC_MODADCI2S_STREAM_NAME,
441 .rates = SNDRV_PCM_RATE_8000_48000,
442 .formats = SNDRV_PCM_FMTBIT_S16_LE,
443 .channels_min = 1,
444 .channels_max = 2,
445 .rate_min = 8000,
446 .rate_max = 48000,
447 },
448 .name = MT_SOC_MODADCI2SDAI_NAME,
449 .ops = &mtk_dai_stub_ops,
450 },
451
452 {
453 .capture = {
454 .stream_name = MT_SOC_ADC2AWB_STREAM_NAME,
455 .rates = SNDRV_PCM_RATE_8000_192000,
456 .formats = SNDRV_PCM_FMTBIT_S16_LE,
457 .channels_min = 1,
458 .channels_max = 2,
459 .rate_min = 8000,
460 .rate_max = 192000,
461 },
462 .name = MT_SOC_ADC2AWBDAI_NAME,
463 .ops = &mtk_dai_stub_ops,
464 },
465 {
466 .capture = {
467 .stream_name = MT_SOC_IO2DAI_STREAM_NAME,
468 .rates = SNDRV_PCM_RATE_8000_48000,
469 .formats = SNDRV_PCM_FMTBIT_S16_LE,
470 .channels_min = 1,
471 .channels_max = 2,
472 .rate_min = 8000,
473 .rate_max = 48000,
474 },
475 .name = MT_SOC_IO2DAIDAI_NAME,
476 .ops = &mtk_dai_stub_ops,
477 },
478 {
479 .playback = {
480 .stream_name = MT_SOC_HP_IMPEDANCE_STREAM_NAME,
481 .rates = SNDRV_PCM_RATE_8000_48000,
482 .formats = SND_SOC_ADV_MT_FMTS,
483 .channels_min = 1,
484 .channels_max = 8,
485 .rate_min = 8000,
486 .rate_max = 48000,
487 },
488 .name = MT_SOC_HP_IMPEDANCE_NAME,
489 .ops = &mtk_dai_stub_ops,
490 },
491 {
492 .playback = {
493 .stream_name = MT_SOC_FM_I2S_PLAYBACK_STREAM_NAME,
494 .rates = SNDRV_PCM_RATE_8000_48000,
495 .formats = SND_SOC_ADV_MT_FMTS,
496 .channels_min = 1,
497 .channels_max = 2,
498 .rate_min = 8000,
499 .rate_max = 48000,
500 },
501 .capture = {
502 .stream_name = MT_SOC_FM_I2S_PLAYBACK_STREAM_NAME,
503 .rates = SNDRV_PCM_RATE_8000_48000,
504 .formats = SND_SOC_ADV_MT_FMTS,
505 .channels_min = 1,
506 .channels_max = 2,
507 .rate_min = 8000,
508 .rate_max = 48000,
509 },
510 .name = MT_SOC_FM_I2S_NAME,
511 .ops = &mtk_dai_stub_ops,
512 },
513 {
514 .playback = {
515 .stream_name = MT_SOC_FM_I2S_CAPTURE_STREAM_NAME,
516 .rates = SNDRV_PCM_RATE_8000_48000,
517 .formats = SND_SOC_ADV_MT_FMTS,
518 .channels_min = 1,
519 .channels_max = 2,
520 .rate_min = 8000,
521 .rate_max = 48000,
522 },
523 .capture = {
524 .stream_name = MT_SOC_FM_I2S_CAPTURE_STREAM_NAME,
525 .rates = SNDRV_PCM_RATE_8000_48000,
526 .formats = SND_SOC_ADV_MT_FMTS,
527 .channels_min = 1,
528 .channels_max = 2,
529 .rate_min = 8000,
530 .rate_max = 48000,
531 },
532 .name = MT_SOC_FM_I2S_CAPTURE_NAME,
533 .ops = &mtk_dai_stub_ops,
534 },
535 };
536
537
538 static const struct snd_soc_component_driver mt_dai_component =
539 {
540 .name = MT_SOC_DAI_NAME,
541 };
542
543 static int mtk_dai_stub_dev_probe(struct platform_device *pdev)
544 {
545 int rc = 0;
546
547 printk("mtk_dai_stub_dev_probe name %s\n", dev_name(&pdev->dev));
548
549 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
550 if (pdev->dev.dma_mask == NULL)
551 {
552 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
553 }
554
555 if (pdev->dev.of_node)
556 {
557 dev_set_name(&pdev->dev, "%s", MT_SOC_DAI_NAME);
558 }
559 printk("%s: dev name %s\n", __func__, dev_name(&pdev->dev));
560
561 rc = snd_soc_register_component(&pdev->dev, &mt_dai_component,
562 mtk_dai_stub_dai, ARRAY_SIZE(mtk_dai_stub_dai));
563
564 printk("%s: rc = %d\n", __func__, rc);
565 return rc;
566 }
567
568 static int mtk_dai_stub_dev_remove(struct platform_device *pdev)
569 {
570 printk("%s:\n", __func__);
571
572 snd_soc_unregister_component(&pdev->dev);
573
574 return 0;
575 }
576
577 #ifdef CONFIG_OF
578 static const struct of_device_id mt_soc_dai_stub_of_ids[] =
579 {
580 { .compatible = "mediatek,mt_soc_dai_stub", },
581 {}
582 };
583 #endif
584
585 static struct platform_driver mtk_dai_stub_driver =
586 {
587 .probe = mtk_dai_stub_dev_probe,
588 .remove = mtk_dai_stub_dev_remove,
589 .driver = {
590 .name = MT_SOC_DAI_NAME,
591 .owner = THIS_MODULE,
592 #ifdef CONFIG_OF
593 .of_match_table = mt_soc_dai_stub_of_ids,
594 #endif
595 },
596 };
597
598 #ifndef CONFIG_OF
599 static struct platform_device *soc_mtk_dai_dev;
600 #endif
601
602 static int __init mtk_dai_stub_init(void)
603 {
604 printk("%s:\n", __func__);
605 #ifndef CONFIG_OF
606 int ret;
607 soc_mtk_dai_dev = platform_device_alloc(MT_SOC_DAI_NAME , -1);
608 if (!soc_mtk_dai_dev)
609 {
610 return -ENOMEM;
611 }
612 ret = platform_device_add(soc_mtk_dai_dev);
613 if (ret != 0)
614 {
615 platform_device_put(soc_mtk_dai_dev);
616 return ret;
617 }
618 #endif
619 return platform_driver_register(&mtk_dai_stub_driver);
620 }
621
622 static void __exit mtk_dai_stub_exit(void)
623 {
624 printk("%s:\n", __func__);
625
626 platform_driver_unregister(&mtk_dai_stub_driver);
627 }
628
629 module_init(mtk_dai_stub_init);
630 module_exit(mtk_dai_stub_exit);
631
632 /* Module information */
633 MODULE_DESCRIPTION("MTK SOC DAI driver");
634 MODULE_LICENSE("GPL v2");
635
636