smdk_wm8580pcm.c 4.9 KB

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