smdk_wm8580pcm.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * sound/soc/samsung/smdk_wm8580pcm.c
  3. *
  4. * Copyright (c) 2011 Samsung Electronics Co. Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <sound/soc.h>
  12. #include <sound/pcm_params.h>
  13. #include <sound/pcm.h>
  14. #include <asm/mach-types.h>
  15. #include "../codecs/wm8580.h"
  16. #include "dma.h"
  17. #include "pcm.h"
  18. /*
  19. * Board Settings:
  20. * o '1' means 'ON'
  21. * o '0' means 'OFF'
  22. * o 'X' means 'Don't care'
  23. *
  24. * SMDK6410, SMDK6440, SMDK6450 Base B/D: CFG1-0000, CFG2-1111
  25. * SMDKC110, SMDKV210: CFGB11-100100, CFGB12-0000
  26. */
  27. #define SMDK_WM8580_EXT_OSC 12000000
  28. #define SMDK_WM8580_EXT_MCLK 4096000
  29. #define SMDK_WM8580_EXT_VOICE 2048000
  30. static unsigned long mclk_freq;
  31. static unsigned long xtal_freq;
  32. /*
  33. * If MCLK clock directly gets from XTAL, we don't have to use PLL
  34. * to make MCLK, but if XTAL clock source connects with other codec
  35. * pin (like XTI), we should have to set codec's PLL to make MCLK.
  36. * Because Samsung SoC does not support pcmcdclk output like I2S.
  37. */
  38. static int smdk_wm8580_pcm_hw_params(struct snd_pcm_substream *substream,
  39. struct snd_pcm_hw_params *params)
  40. {
  41. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  42. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  43. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  44. int rfs, ret;
  45. switch (params_rate(params)) {
  46. case 8000:
  47. break;
  48. default:
  49. printk(KERN_ERR "%s:%d Sampling Rate %u not supported!\n",
  50. __func__, __LINE__, params_rate(params));
  51. return -EINVAL;
  52. }
  53. rfs = mclk_freq / params_rate(params) / 2;
  54. /* Set the codec DAI configuration */
  55. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B
  56. | SND_SOC_DAIFMT_IB_NF
  57. | SND_SOC_DAIFMT_CBS_CFS);
  58. if (ret < 0)
  59. return ret;
  60. /* Set the cpu DAI configuration */
  61. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B
  62. | SND_SOC_DAIFMT_IB_NF
  63. | SND_SOC_DAIFMT_CBS_CFS);
  64. if (ret < 0)
  65. return ret;
  66. if (mclk_freq == xtal_freq) {
  67. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_MCLK,
  68. mclk_freq, SND_SOC_CLOCK_IN);
  69. if (ret < 0)
  70. return ret;
  71. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  72. WM8580_CLKSRC_MCLK);
  73. if (ret < 0)
  74. return ret;
  75. } else {
  76. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  77. mclk_freq, SND_SOC_CLOCK_IN);
  78. if (ret < 0)
  79. return ret;
  80. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  81. WM8580_CLKSRC_PLLA);
  82. if (ret < 0)
  83. return ret;
  84. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  85. xtal_freq, mclk_freq);
  86. if (ret < 0)
  87. return ret;
  88. }
  89. /* Set PCM source clock on CPU */
  90. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
  91. mclk_freq, SND_SOC_CLOCK_IN);
  92. if (ret < 0)
  93. return ret;
  94. /* Set SCLK_DIV for making bclk */
  95. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
  96. if (ret < 0)
  97. return ret;
  98. return 0;
  99. }
  100. static struct snd_soc_ops smdk_wm8580_pcm_ops = {
  101. .hw_params = smdk_wm8580_pcm_hw_params,
  102. };
  103. static struct snd_soc_dai_link smdk_dai[] = {
  104. {
  105. .name = "WM8580 PAIF PCM RX",
  106. .stream_name = "Playback",
  107. .cpu_dai_name = "samsung-pcm.0",
  108. .codec_dai_name = "wm8580-hifi-playback",
  109. .platform_name = "samsung-audio",
  110. .codec_name = "wm8580-codec.0-001b",
  111. .ops = &smdk_wm8580_pcm_ops,
  112. }, {
  113. .name = "WM8580 PAIF PCM TX",
  114. .stream_name = "Capture",
  115. .cpu_dai_name = "samsung-pcm.0",
  116. .codec_dai_name = "wm8580-hifi-capture",
  117. .platform_name = "samsung-audio",
  118. .codec_name = "wm8580-codec.0-001b",
  119. .ops = &smdk_wm8580_pcm_ops,
  120. },
  121. };
  122. static struct snd_soc_card smdk_pcm = {
  123. .name = "SMDK-PCM",
  124. .dai_link = smdk_dai,
  125. .num_links = 2,
  126. };
  127. /*
  128. * After SMDKC110 Base Board's Rev is '0.1', 12MHz External OSC(X1)
  129. * is absent (or not connected), so we connect EXT_VOICE_CLK(OSC4),
  130. * 2.0484Mhz, directly with MCLK both Codec and SoC.
  131. */
  132. static int __devinit snd_smdk_probe(struct platform_device *pdev)
  133. {
  134. int ret = 0;
  135. xtal_freq = SMDK_WM8580_EXT_OSC;
  136. mclk_freq = SMDK_WM8580_EXT_MCLK;
  137. if (machine_is_smdkc110() || machine_is_smdkv210())
  138. xtal_freq = mclk_freq = SMDK_WM8580_EXT_VOICE;
  139. smdk_pcm.dev = &pdev->dev;
  140. ret = snd_soc_register_card(&smdk_pcm);
  141. if (ret) {
  142. dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
  143. return ret;
  144. }
  145. return 0;
  146. }
  147. static int __devexit snd_smdk_remove(struct platform_device *pdev)
  148. {
  149. snd_soc_unregister_card(&smdk_pcm);
  150. platform_set_drvdata(pdev, NULL);
  151. return 0;
  152. }
  153. static struct platform_driver snd_smdk_driver = {
  154. .driver = {
  155. .owner = THIS_MODULE,
  156. .name = "samsung-smdk-pcm",
  157. },
  158. .probe = snd_smdk_probe,
  159. .remove = __devexit_p(snd_smdk_remove),
  160. };
  161. static int __init smdk_audio_init(void)
  162. {
  163. return platform_driver_register(&snd_smdk_driver);
  164. }
  165. module_init(smdk_audio_init);
  166. static void __exit smdk_audio_exit(void)
  167. {
  168. platform_driver_unregister(&snd_smdk_driver);
  169. }
  170. module_exit(smdk_audio_exit);
  171. MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
  172. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580 for PCM");
  173. MODULE_LICENSE("GPL");