aml_m_dummy.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * aml_m_dummy_codec.c -- SoC audio for AML M series
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. */
  10. #include <linux/module.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/clk.h>
  15. #include <linux/timer.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/i2c.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <sound/jack.h>
  26. #include <sound/dummy_codec.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/hardware.h>
  29. #include "aml_dai.h"
  30. #include "aml_pcm.h"
  31. #include "aml_audio_hw.h"
  32. static struct dummy_codec_platform_data *dummy_codec_snd_pdata = NULL;
  33. static void dummy_codec_dev_init(void)
  34. {
  35. if (dummy_codec_snd_pdata->device_init) {
  36. dummy_codec_snd_pdata->device_init();
  37. }
  38. }
  39. static void dummy_codec_dev_uninit(void)
  40. {
  41. if (dummy_codec_snd_pdata->device_uninit) {
  42. dummy_codec_snd_pdata->device_uninit();
  43. }
  44. }
  45. static int dummy_codec_hw_params(struct snd_pcm_substream *substream,
  46. struct snd_pcm_hw_params *params)
  47. {
  48. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  49. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  50. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  51. int ret;
  52. printk(KERN_DEBUG "enter %s rate: %d format: %d\n", __func__, params_rate(params), params_format(params));
  53. /* set codec DAI configuration */
  54. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
  55. if (ret < 0) {
  56. printk(KERN_ERR "%s: set codec dai fmt failed!\n", __func__);
  57. return ret;
  58. }
  59. /* set cpu DAI configuration */
  60. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  61. if (ret < 0) {
  62. printk(KERN_ERR "%s: set cpu dai fmt failed!\n", __func__);
  63. return ret;
  64. }
  65. #if 0 //no audio in
  66. /* set codec DAI clock */
  67. ret = snd_soc_dai_set_sysclk(codec_dai, 0, params_rate(params) * 256, SND_SOC_CLOCK_IN);
  68. if (ret < 0) {
  69. printk(KERN_ERR "%s: set codec dai sysclk failed (rate: %d)!\n", __func__, params_rate(params));
  70. return ret;
  71. }
  72. #endif
  73. /* set cpu DAI clock */
  74. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256, SND_SOC_CLOCK_OUT);
  75. if (ret < 0) {
  76. printk(KERN_ERR "%s: set cpu dai sysclk failed (rate: %d)!\n", __func__, params_rate(params));
  77. return ret;
  78. }
  79. return 0;
  80. }
  81. static struct snd_soc_ops dummy_codec_soc_ops = {
  82. .hw_params = dummy_codec_hw_params,
  83. };
  84. static int dummy_codec_set_bias_level(struct snd_soc_card *card,
  85. enum snd_soc_bias_level level)
  86. {
  87. return 0;
  88. }
  89. static int dummy_codec_codec_init(struct snd_soc_pcm_runtime *rtd)
  90. {
  91. return 0;
  92. }
  93. static struct snd_soc_dai_link dummy_codec_dai_link[] = {
  94. {
  95. .name = "DUMMY_CODEC",
  96. .stream_name = "DUMMY_CODEC PCM",
  97. .cpu_dai_name = "aml-dai0",
  98. .codec_dai_name = "dummy_codec",
  99. .init = dummy_codec_codec_init,
  100. .platform_name = "aml-audio.0",
  101. .codec_name = "dummy_codec.0",
  102. .ops = &dummy_codec_soc_ops,
  103. },
  104. };
  105. static struct snd_soc_card snd_soc_dummy_codec = {
  106. .name = "AML-DUMMY-CODEC",
  107. .driver_name = "SOC-Audio",
  108. .dai_link = &dummy_codec_dai_link[0],
  109. .num_links = ARRAY_SIZE(dummy_codec_dai_link),
  110. .set_bias_level = dummy_codec_set_bias_level,
  111. };
  112. static struct platform_device *dummy_codec_snd_device = NULL;
  113. static int dummy_codec_audio_probe(struct platform_device *pdev)
  114. {
  115. int ret = 0;
  116. //printk(KERN_DEBUG "enter %s\n", __func__);
  117. printk("enter %s\n", __func__);
  118. dummy_codec_snd_pdata = pdev->dev.platform_data;
  119. snd_BUG_ON(!dummy_codec_snd_pdata);
  120. dummy_codec_snd_device = platform_device_alloc("soc-audio", -1);
  121. if (!dummy_codec_snd_device) {
  122. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  123. ret = -ENOMEM;
  124. goto err;
  125. }
  126. platform_set_drvdata(dummy_codec_snd_device, &snd_soc_dummy_codec);
  127. ret = platform_device_add(dummy_codec_snd_device);
  128. if (ret) {
  129. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  130. goto err_device_add;
  131. }
  132. dummy_codec_dev_init();
  133. return ret;
  134. err_device_add:
  135. platform_device_put(dummy_codec_snd_device);
  136. err:
  137. return ret;
  138. }
  139. static int dummy_codec_audio_remove(struct platform_device *pdev)
  140. {
  141. int ret = 0;
  142. dummy_codec_dev_uninit();
  143. platform_device_put(dummy_codec_snd_device);
  144. dummy_codec_snd_device = NULL;
  145. dummy_codec_snd_pdata = NULL;
  146. return ret;
  147. }
  148. static struct platform_driver aml_m_dummy_codec_driver = {
  149. .probe = dummy_codec_audio_probe,
  150. .remove = __devexit_p(dummy_codec_audio_remove),
  151. .driver = {
  152. .name = "aml_dummy_codec_audio",
  153. .owner = THIS_MODULE,
  154. },
  155. };
  156. static int __init aml_m_dummy_codec_init(void)
  157. {
  158. return platform_driver_register(&aml_m_dummy_codec_driver);
  159. }
  160. static void __exit aml_m_dummy_codec_exit(void)
  161. {
  162. platform_driver_unregister(&aml_m_dummy_codec_driver);
  163. }
  164. module_init(aml_m_dummy_codec_init);
  165. module_exit(aml_m_dummy_codec_exit);
  166. /* Module information */
  167. MODULE_AUTHOR("AMLogic, Inc.");
  168. MODULE_DESCRIPTION("AML dummy_codec audio driver");
  169. MODULE_LICENSE("GPL");