aml_dai.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/interrupt.h>
  4. #include <linux/device.h>
  5. #include <linux/delay.h>
  6. #include <linux/clk.h>
  7. #include <sound/core.h>
  8. #include <sound/pcm.h>
  9. #include <sound/pcm_params.h>
  10. #include <sound/initval.h>
  11. #include <sound/soc.h>
  12. #include <mach/hardware.h>
  13. #include "aml_dai.h"
  14. //#define AML_DAI_DEBUG
  15. //#if defined(CONFIG_ARCH_MESON3) || defined(CONFIG_ARCH_MESON6)
  16. //#define AML_DAI_PCM_SUPPORT
  17. //#endif
  18. static int aml_dai_i2s_startup(struct snd_pcm_substream *substream,
  19. struct snd_soc_dai *dai)
  20. {
  21. #ifdef AML_DAI_DEBUG
  22. printk("***Entered %s:%s\n", __FILE__,__func__);
  23. #endif
  24. return 0;
  25. }
  26. static void aml_dai_i2s_shutdown(struct snd_pcm_substream *substream,
  27. struct snd_soc_dai *dai)
  28. {
  29. #ifdef AML_DAI_DEBUG
  30. printk("***Entered %s:%s\n", __FILE__,__func__);
  31. #endif
  32. }
  33. static int aml_dai_i2s_prepare(struct snd_pcm_substream *substream,
  34. struct snd_soc_dai *dai)
  35. {
  36. #ifdef AML_DAI_DEBUG
  37. printk("***Entered %s:%s\n", __FILE__,__func__);
  38. #endif
  39. return 0;
  40. }
  41. static int aml_dai_i2s_hw_params(struct snd_pcm_substream *substream,
  42. struct snd_pcm_hw_params *params,
  43. struct snd_soc_dai *dai)
  44. {
  45. #ifdef AML_DAI_DEBUG
  46. printk("***Entered %s:%s\n", __FILE__,__func__);
  47. #endif
  48. return 0;
  49. }
  50. static int aml_dai_set_i2s_fmt(struct snd_soc_dai *dai,
  51. unsigned int fmt)
  52. {
  53. #ifdef AML_DAI_DEBUG
  54. printk("***Entered %s:%s\n", __FILE__,__func__);
  55. #endif
  56. return 0;
  57. }
  58. static int aml_dai_set_i2s_sysclk(struct snd_soc_dai *dai,
  59. int clk_id, unsigned int freq, int dir)
  60. {
  61. #ifdef AML_DAI_DEBUG
  62. printk("***Entered %s:%s\n", __FILE__,__func__);
  63. #endif
  64. return 0;
  65. }
  66. #ifdef CONFIG_PM
  67. static int aml_dai_i2s_suspend(struct snd_soc_dai *dai)
  68. {
  69. printk("***Entered %s:%s\n", __FILE__,__func__);
  70. return 0;
  71. }
  72. static int aml_dai_i2s_resume(struct snd_soc_dai *dai)
  73. {
  74. printk("***Entered %s:%s\n", __FILE__,__func__);
  75. return 0;
  76. }
  77. #else /* CONFIG_PM */
  78. # define aml_dai_i2s_suspend NULL
  79. # define aml_dai_i2s_resume NULL
  80. #endif /* CONFIG_PM */
  81. #ifdef AML_DAI_PCM_SUPPORT
  82. static int aml_dai_pcm_startup(struct snd_pcm_substream *substream,
  83. struct snd_soc_dai *dai)
  84. {
  85. #ifdef AML_DAI_DEBUG
  86. printk("***Entered %s:%s\n", __FILE__,__func__);
  87. #endif
  88. return 0;
  89. }
  90. static void aml_dai_pcm_shutdown(struct snd_pcm_substream *substream,
  91. struct snd_soc_dai *dai)
  92. {
  93. #ifdef AML_DAI_DEBUG
  94. printk("***Entered %s:%s\n", __FILE__,__func__);
  95. #endif
  96. }
  97. static int aml_dai_pcm_prepare(struct snd_pcm_substream *substream,
  98. struct snd_soc_dai *dai)
  99. {
  100. #ifdef AML_DAI_DEBUG
  101. printk("***Entered %s:%s\n", __FILE__,__func__);
  102. #endif
  103. return 0;
  104. }
  105. static int aml_dai_pcm_hw_params(struct snd_pcm_substream *substream,
  106. struct snd_pcm_hw_params *params,
  107. struct snd_soc_dai *dai)
  108. {
  109. #ifdef AML_DAI_DEBUG
  110. printk("***Entered %s:%s\n", __FILE__,__func__);
  111. #endif
  112. return 0;
  113. }
  114. static int aml_dai_set_pcm_fmt(struct snd_soc_dai *dai,
  115. unsigned int fmt)
  116. {
  117. #ifdef AML_DAI_DEBUG
  118. printk("***Entered %s:%s\n", __FILE__,__func__);
  119. #endif
  120. return 0;
  121. }
  122. static int aml_dai_set_pcm_sysclk(struct snd_soc_dai *dai,
  123. int clk_id, unsigned int freq, int dir);
  124. {
  125. #ifdef AML_DAI_DEBUG
  126. printk("***Entered %s:%s\n", __FILE__,__func__);
  127. #endif
  128. return 0;
  129. }
  130. #ifdef CONFIG_PM
  131. static int aml_dai_pcm_suspend(struct snd_soc_dai *dai)
  132. {
  133. printk("***Entered %s:%s\n", __FILE__,__func__);
  134. return 0;
  135. }
  136. static int aml_dai_pcm_resume(struct snd_soc_dai *dai)
  137. {
  138. printk("***Entered %s:%s\n", __FILE__,__func__);
  139. return 0;
  140. }
  141. #else /* CONFIG_PM */
  142. # define aml_dai_i2s_suspend NULL
  143. # define aml_dai_i2s_resume NULL
  144. #endif /* CONFIG_PM */
  145. #endif
  146. #define AML_DAI_I2S_RATES (SNDRV_PCM_RATE_8000_96000)
  147. #define AML_DAI_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  148. #ifdef AML_DAI_PCM_SUPPORT
  149. #define AML_DAI_PCM_RATES (SNDRV_PCM_RATE_8000)
  150. #define AML_DAI_PCM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  151. #endif
  152. static struct snd_soc_dai_ops aml_dai_i2s_ops = {
  153. .startup = aml_dai_i2s_startup,
  154. .shutdown = aml_dai_i2s_shutdown,
  155. .prepare = aml_dai_i2s_prepare,
  156. .hw_params = aml_dai_i2s_hw_params,
  157. .set_fmt = aml_dai_set_i2s_fmt,
  158. .set_sysclk = aml_dai_set_i2s_sysclk,
  159. };
  160. #ifdef AML_DAI_PCM_SUPPORT
  161. static struct snd_soc_dai_ops aml_dai_pcm_ops = {
  162. .startup = aml_dai_pcm_startup,
  163. .shutdown = aml_dai_pcm_shutdown,
  164. .prepare = aml_dai_pcm_prepare,
  165. .hw_params = aml_dai_pcm_hw_params,
  166. .set_fmt = aml_dai_set_pcm_fmt,
  167. .set_sysclk = aml_dai_set_pcm_sysclk,
  168. };
  169. #endif
  170. struct snd_soc_dai_driver aml_dai[] = {
  171. { .name = "aml-dai0",
  172. .id = 0,
  173. .suspend = aml_dai_i2s_suspend,
  174. .resume = aml_dai_i2s_resume,
  175. .playback = {
  176. .channels_min = 1,
  177. .channels_max = 2,
  178. .rates = AML_DAI_I2S_RATES,
  179. .formats = AML_DAI_I2S_FORMATS,},
  180. .capture = {
  181. .channels_min = 1,
  182. .channels_max = 2,
  183. .rates = AML_DAI_I2S_RATES,
  184. .formats = AML_DAI_I2S_FORMATS,},
  185. .ops = &aml_dai_i2s_ops,
  186. },
  187. #ifdef AML_DAI_PCM_SUPPORT
  188. { .name = "aml-dai1",
  189. .id = 1,
  190. .suspend = aml_dai_pcm_suspend,
  191. .resume = aml_dai_pcm_resume,
  192. .playback = {
  193. .channels_min = 1,
  194. .channels_max = 1,
  195. .rates = AML_DAI_PCM_RATES,
  196. .formats = AML_DAI_PCM_FORMATS,},
  197. .capture = {
  198. .channels_min = 1,
  199. .channels_max = 1,
  200. .rates = AML_DAI_PCM_RATES,
  201. .formats = AML_DAI_PCM_FORMATS,},
  202. .ops = &aml_dai_pcm_ops,
  203. },
  204. #endif
  205. };
  206. EXPORT_SYMBOL_GPL(aml_dai);
  207. static __devinit int aml_dai_probe(struct platform_device *pdev)
  208. {
  209. printk(KERN_DEBUG "enter %s\n", __func__);
  210. #if 0
  211. BUG_ON(pdev->id < 0);
  212. BUG_ON(pdev->id >= ARRAY_SIZE(aml_dai));
  213. return snd_soc_register_dai(&pdev->dev, &aml_dai[pdev->id]);
  214. #else
  215. return snd_soc_register_dais(&pdev->dev, aml_dai, ARRAY_SIZE(aml_dai));
  216. #endif
  217. }
  218. static int __devexit aml_dai_remove(struct platform_device *pdev)
  219. {
  220. snd_soc_unregister_dai(&pdev->dev);
  221. return 0;
  222. }
  223. static struct platform_driver aml_dai_driver = {
  224. .driver = {
  225. .name = "aml-dai",
  226. .owner = THIS_MODULE,
  227. },
  228. .probe = aml_dai_probe,
  229. .remove = __devexit_p(aml_dai_remove),
  230. };
  231. static int __init aml_dai_modinit(void)
  232. {
  233. return platform_driver_register(&aml_dai_driver);
  234. }
  235. module_init(aml_dai_modinit);
  236. static void __exit aml_dai_modexit(void)
  237. {
  238. platform_driver_unregister(&aml_dai_driver);
  239. }
  240. module_exit(aml_dai_modexit);
  241. /* Module information */
  242. MODULE_AUTHOR("AMLogic, Inc.");
  243. MODULE_DESCRIPTION("AML DAI driver for ALSA");
  244. MODULE_LICENSE("GPL");