bfin-eval-adau1373.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Machine driver for EVAL-ADAU1373 on Analog Devices bfin
  3. * evaluation boards.
  4. *
  5. * Copyright 2011 Analog Devices Inc.
  6. * Author: Lars-Peter Clausen <lars@metafoo.de>
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/device.h>
  12. #include <sound/core.h>
  13. #include <sound/pcm.h>
  14. #include <sound/soc.h>
  15. #include <sound/pcm_params.h>
  16. #include "../codecs/adau1373.h"
  17. static const struct snd_soc_dapm_widget bfin_eval_adau1373_dapm_widgets[] = {
  18. SND_SOC_DAPM_LINE("Line In1", NULL),
  19. SND_SOC_DAPM_LINE("Line In2", NULL),
  20. SND_SOC_DAPM_LINE("Line In3", NULL),
  21. SND_SOC_DAPM_LINE("Line In4", NULL),
  22. SND_SOC_DAPM_LINE("Line Out1", NULL),
  23. SND_SOC_DAPM_LINE("Line Out2", NULL),
  24. SND_SOC_DAPM_LINE("Stereo Out", NULL),
  25. SND_SOC_DAPM_HP("Headphone", NULL),
  26. SND_SOC_DAPM_HP("Earpiece", NULL),
  27. SND_SOC_DAPM_SPK("Speaker", NULL),
  28. };
  29. static const struct snd_soc_dapm_route bfin_eval_adau1373_dapm_routes[] = {
  30. { "AIN1L", NULL, "Line In1" },
  31. { "AIN1R", NULL, "Line In1" },
  32. { "AIN2L", NULL, "Line In2" },
  33. { "AIN2R", NULL, "Line In2" },
  34. { "AIN3L", NULL, "Line In3" },
  35. { "AIN3R", NULL, "Line In3" },
  36. { "AIN4L", NULL, "Line In4" },
  37. { "AIN4R", NULL, "Line In4" },
  38. /* MICBIAS can be connected via a jumper to the line-in jack, since w
  39. don't know which one is going to be used, just power both. */
  40. { "Line In1", NULL, "MICBIAS1" },
  41. { "Line In2", NULL, "MICBIAS1" },
  42. { "Line In3", NULL, "MICBIAS1" },
  43. { "Line In4", NULL, "MICBIAS1" },
  44. { "Line In1", NULL, "MICBIAS2" },
  45. { "Line In2", NULL, "MICBIAS2" },
  46. { "Line In3", NULL, "MICBIAS2" },
  47. { "Line In4", NULL, "MICBIAS2" },
  48. { "Line Out1", NULL, "LOUT1L" },
  49. { "Line Out1", NULL, "LOUT1R" },
  50. { "Line Out2", NULL, "LOUT2L" },
  51. { "Line Out2", NULL, "LOUT2R" },
  52. { "Headphone", NULL, "HPL" },
  53. { "Headphone", NULL, "HPR" },
  54. { "Earpiece", NULL, "EP" },
  55. { "Speaker", NULL, "SPKL" },
  56. { "Stereo Out", NULL, "SPKR" },
  57. };
  58. static int bfin_eval_adau1373_hw_params(struct snd_pcm_substream *substream,
  59. struct snd_pcm_hw_params *params)
  60. {
  61. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  62. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  63. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  64. int ret;
  65. int pll_rate;
  66. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  67. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  68. if (ret)
  69. return ret;
  70. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  71. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  72. if (ret)
  73. return ret;
  74. switch (params_rate(params)) {
  75. case 48000:
  76. case 8000:
  77. case 12000:
  78. case 16000:
  79. case 24000:
  80. case 32000:
  81. pll_rate = 48000 * 1024;
  82. break;
  83. case 44100:
  84. case 7350:
  85. case 11025:
  86. case 14700:
  87. case 22050:
  88. case 29400:
  89. pll_rate = 44100 * 1024;
  90. break;
  91. default:
  92. return -EINVAL;
  93. }
  94. ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
  95. ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
  96. if (ret)
  97. return ret;
  98. ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
  99. SND_SOC_CLOCK_IN);
  100. return ret;
  101. }
  102. static int bfin_eval_adau1373_codec_init(struct snd_soc_pcm_runtime *rtd)
  103. {
  104. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  105. unsigned int pll_rate = 48000 * 1024;
  106. int ret;
  107. ret = snd_soc_dai_set_pll(codec_dai, ADAU1373_PLL1,
  108. ADAU1373_PLL_SRC_MCLK1, 12288000, pll_rate);
  109. if (ret)
  110. return ret;
  111. ret = snd_soc_dai_set_sysclk(codec_dai, ADAU1373_CLK_SRC_PLL1, pll_rate,
  112. SND_SOC_CLOCK_IN);
  113. return ret;
  114. }
  115. static struct snd_soc_ops bfin_eval_adau1373_ops = {
  116. .hw_params = bfin_eval_adau1373_hw_params,
  117. };
  118. static struct snd_soc_dai_link bfin_eval_adau1373_dai = {
  119. .name = "adau1373",
  120. .stream_name = "adau1373",
  121. .cpu_dai_name = "bfin-i2s.0",
  122. .codec_dai_name = "adau1373-aif1",
  123. .platform_name = "bfin-i2s-pcm-audio",
  124. .codec_name = "adau1373.0-001a",
  125. .ops = &bfin_eval_adau1373_ops,
  126. .init = bfin_eval_adau1373_codec_init,
  127. };
  128. static struct snd_soc_card bfin_eval_adau1373 = {
  129. .name = "bfin-eval-adau1373",
  130. .dai_link = &bfin_eval_adau1373_dai,
  131. .num_links = 1,
  132. .dapm_widgets = bfin_eval_adau1373_dapm_widgets,
  133. .num_dapm_widgets = ARRAY_SIZE(bfin_eval_adau1373_dapm_widgets),
  134. .dapm_routes = bfin_eval_adau1373_dapm_routes,
  135. .num_dapm_routes = ARRAY_SIZE(bfin_eval_adau1373_dapm_routes),
  136. };
  137. static int bfin_eval_adau1373_probe(struct platform_device *pdev)
  138. {
  139. struct snd_soc_card *card = &bfin_eval_adau1373;
  140. card->dev = &pdev->dev;
  141. return snd_soc_register_card(&bfin_eval_adau1373);
  142. }
  143. static int __devexit bfin_eval_adau1373_remove(struct platform_device *pdev)
  144. {
  145. struct snd_soc_card *card = platform_get_drvdata(pdev);
  146. snd_soc_unregister_card(card);
  147. return 0;
  148. }
  149. static struct platform_driver bfin_eval_adau1373_driver = {
  150. .driver = {
  151. .name = "bfin-eval-adau1373",
  152. .owner = THIS_MODULE,
  153. .pm = &snd_soc_pm_ops,
  154. },
  155. .probe = bfin_eval_adau1373_probe,
  156. .remove = __devexit_p(bfin_eval_adau1373_remove),
  157. };
  158. static int __init bfin_eval_adau1373_init(void)
  159. {
  160. return platform_driver_register(&bfin_eval_adau1373_driver);
  161. }
  162. module_init(bfin_eval_adau1373_init);
  163. static void __exit bfin_eval_adau1373_exit(void)
  164. {
  165. platform_driver_unregister(&bfin_eval_adau1373_driver);
  166. }
  167. module_exit(bfin_eval_adau1373_exit);
  168. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  169. MODULE_DESCRIPTION("ALSA SoC bfin adau1373 driver");
  170. MODULE_LICENSE("GPL");
  171. MODULE_ALIAS("platform:bfin-eval-adau1373");