aml_m1.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include <linux/module.h>
  2. #include <linux/moduleparam.h>
  3. #include <linux/kernel.h>
  4. #include <linux/clk.h>
  5. #include <linux/timer.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/i2c.h>
  9. #include <sound/core.h>
  10. #include <sound/pcm.h>
  11. #include <sound/pcm_params.h>
  12. #include <sound/soc.h>
  13. #include <sound/soc-dapm.h>
  14. #include <asm/mach-types.h>
  15. #include <mach/hardware.h>
  16. #include <mach/gpio.h>
  17. #include "aml_dai.h"
  18. #include "aml_pcm.h"
  19. #include "aml_m1_codec.h"
  20. static int aml_m1_set_bias_level(struct snd_soc_card *card,
  21. enum snd_soc_bias_level level)
  22. {
  23. int ret = 0;
  24. //struct snd_soc_codec *codec = card->codec;
  25. switch(level){
  26. case SND_SOC_BIAS_ON:
  27. case SND_SOC_BIAS_PREPARE:
  28. break;
  29. case SND_SOC_BIAS_OFF:
  30. case SND_SOC_BIAS_STANDBY:
  31. break;
  32. }
  33. return ret;
  34. }
  35. static const struct snd_soc_dapm_widget aml_m1_dapm_widgets[] = {
  36. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  37. SND_SOC_DAPM_LINE("HP", NULL),
  38. };
  39. static const struct snd_soc_dapm_route intercon[] = {
  40. {"Ext Spk", NULL, "LINEOUTL"},
  41. {"Ext Spk", NULL, "LINEOUTR"},
  42. {"HP", NULL, "HP_L"},
  43. {"HP", NULL, "HP_R"},
  44. };
  45. static int aml_m1_codec_init(struct snd_soc_codec *codec)
  46. {
  47. struct snd_soc_card *card = codec->socdev->card;
  48. int err;
  49. err = snd_soc_dapm_new_controls(codec, aml_m1_dapm_widgets, ARRAY_SIZE(aml_m1_dapm_widgets));
  50. if(err){
  51. dev_warn(card->dev, "Failed to register DAPM widgets\n");
  52. return 0;
  53. }
  54. err = snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
  55. if(err){
  56. dev_warn(card->dev, "Failed to setup dapm widgets routine\n");
  57. return 0;
  58. }
  59. snd_soc_dapm_enable_pin(codec, "Ext Spk");
  60. snd_soc_dapm_enable_pin(codec, "HP");
  61. snd_soc_dapm_sync(codec);
  62. return 0;
  63. }
  64. static struct snd_soc_dai_link aml_m1_dai = {
  65. .name = "AML-M1",
  66. .stream_name = "AML M1 PCM",
  67. .cpu_dai = &aml_dai[0], //////
  68. .codec_dai = &aml_m1_codec_dai,
  69. .init = aml_m1_codec_init,
  70. };
  71. static struct snd_soc_card snd_soc_aml_m1 = {
  72. .name = "AML-M1",
  73. .platform = &aml_soc_platform,
  74. .dai_link = &aml_m1_dai,
  75. .num_links = 1,
  76. .set_bias_level = aml_m1_set_bias_level,
  77. };
  78. static struct snd_soc_device aml_m1_snd_devdata = {
  79. .card = &snd_soc_aml_m1,
  80. .codec_dev = &soc_codec_dev_aml_m1,
  81. };
  82. static struct platform_device *aml_m1_snd_device;
  83. static struct platform_device *aml_m1_platform_device;
  84. static int aml_m1_audio_probe(struct platform_device *pdev)
  85. {
  86. int ret;
  87. aml_m1_snd_device = platform_device_alloc("soc-audio", -1);
  88. if (!aml_m1_snd_device) {
  89. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  90. ret = -ENOMEM;
  91. }
  92. platform_set_drvdata(aml_m1_snd_device,&aml_m1_snd_devdata);
  93. aml_m1_snd_devdata.dev = &aml_m1_snd_device->dev;
  94. ret = platform_device_add(aml_m1_snd_device);
  95. if (ret) {
  96. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  97. goto error;
  98. }
  99. aml_m1_platform_device = platform_device_register_simple("aml_m1_codec",
  100. -1, NULL, 0);
  101. return 0;
  102. error:
  103. platform_device_put(aml_m1_snd_device);
  104. return ret;
  105. }
  106. static int aml_m1_audio_remove(struct platform_device *pdev)
  107. {
  108. printk("***Entered %s:%s\n", __FILE__,__func__);
  109. platform_device_unregister(aml_m1_snd_device);
  110. return 0;
  111. }
  112. static struct platform_driver aml_m1_audio_driver = {
  113. .probe = aml_m1_audio_probe,
  114. .remove = aml_m1_audio_remove,
  115. .driver = {
  116. .name = "aml_m1_audio",
  117. .owner = THIS_MODULE,
  118. },
  119. };
  120. static int __init aml_m1_init(void)
  121. {
  122. return platform_driver_register(&aml_m1_audio_driver);
  123. }
  124. static void __exit aml_m1_exit(void)
  125. {
  126. platform_driver_unregister(&aml_m1_audio_driver);
  127. }
  128. module_init(aml_m1_init);
  129. module_exit(aml_m1_exit);
  130. /* Module information */
  131. MODULE_AUTHOR("AMLogic, Inc.");
  132. MODULE_DESCRIPTION("ALSA SoC AML M1 AUDIO");
  133. MODULE_LICENSE("GPL");