smdk_wm8580pcm.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "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 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. if (mclk_freq == xtal_freq) {
  55. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_MCLK,
  56. mclk_freq, SND_SOC_CLOCK_IN);
  57. if (ret < 0)
  58. return ret;
  59. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  60. WM8580_CLKSRC_MCLK);
  61. if (ret < 0)
  62. return ret;
  63. } else {
  64. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  65. mclk_freq, SND_SOC_CLOCK_IN);
  66. if (ret < 0)
  67. return ret;
  68. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  69. WM8580_CLKSRC_PLLA);
  70. if (ret < 0)
  71. return ret;
  72. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  73. xtal_freq, mclk_freq);
  74. if (ret < 0)
  75. return ret;
  76. }
  77. /* Set PCM source clock on CPU */
  78. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
  79. mclk_freq, SND_SOC_CLOCK_IN);
  80. if (ret < 0)
  81. return ret;
  82. /* Set SCLK_DIV for making bclk */
  83. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
  84. if (ret < 0)
  85. return ret;
  86. return 0;
  87. }
  88. static struct snd_soc_ops smdk_wm8580_pcm_ops = {
  89. .hw_params = smdk_wm8580_pcm_hw_params,
  90. };
  91. #define SMDK_DAI_FMT (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | \
  92. SND_SOC_DAIFMT_CBS_CFS)
  93. static struct snd_soc_dai_link smdk_dai[] = {
  94. {
  95. .name = "WM8580 PAIF PCM RX",
  96. .stream_name = "Playback",
  97. .cpu_dai_name = "samsung-pcm.0",
  98. .codec_dai_name = "wm8580-hifi-playback",
  99. .platform_name = "samsung-audio",
  100. .codec_name = "wm8580.0-001b",
  101. .dai_fmt = SMDK_DAI_FMT,
  102. .ops = &smdk_wm8580_pcm_ops,
  103. }, {
  104. .name = "WM8580 PAIF PCM TX",
  105. .stream_name = "Capture",
  106. .cpu_dai_name = "samsung-pcm.0",
  107. .codec_dai_name = "wm8580-hifi-capture",
  108. .platform_name = "samsung-pcm.0",
  109. .codec_name = "wm8580.0-001b",
  110. .dai_fmt = SMDK_DAI_FMT,
  111. .ops = &smdk_wm8580_pcm_ops,
  112. },
  113. };
  114. static struct snd_soc_card smdk_pcm = {
  115. .name = "SMDK-PCM",
  116. .owner = THIS_MODULE,
  117. .dai_link = smdk_dai,
  118. .num_links = 2,
  119. };
  120. /*
  121. * After SMDKC110 Base Board's Rev is '0.1', 12MHz External OSC(X1)
  122. * is absent (or not connected), so we connect EXT_VOICE_CLK(OSC4),
  123. * 2.0484Mhz, directly with MCLK both Codec and SoC.
  124. */
  125. static int snd_smdk_probe(struct platform_device *pdev)
  126. {
  127. int ret = 0;
  128. xtal_freq = SMDK_WM8580_EXT_OSC;
  129. mclk_freq = SMDK_WM8580_EXT_MCLK;
  130. if (machine_is_smdkc110() || machine_is_smdkv210())
  131. xtal_freq = mclk_freq = SMDK_WM8580_EXT_VOICE;
  132. smdk_pcm.dev = &pdev->dev;
  133. ret = devm_snd_soc_register_card(&pdev->dev, &smdk_pcm);
  134. if (ret)
  135. dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
  136. return ret;
  137. }
  138. static struct platform_driver snd_smdk_driver = {
  139. .driver = {
  140. .name = "samsung-smdk-pcm",
  141. },
  142. .probe = snd_smdk_probe,
  143. };
  144. module_platform_driver(snd_smdk_driver);
  145. MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
  146. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580 for PCM");
  147. MODULE_LICENSE("GPL");