smdk_wm8994pcm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * sound/soc/samsung/smdk_wm8994pcm.c
  3. *
  4. * Copyright (c) 2011 Samsung Electronics Co., Ltd
  5. * http://www.samsung.com
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <sound/soc.h>
  14. #include <sound/pcm.h>
  15. #include <sound/pcm_params.h>
  16. #include "../codecs/wm8994.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. * SMDKC210, SMDKV310: CFG3- 1001, CFG5-1000, CFG7-111111
  26. */
  27. /*
  28. * Configure audio route as :-
  29. * $ amixer sset 'DAC1' on,on
  30. * $ amixer sset 'Right Headphone Mux' 'DAC'
  31. * $ amixer sset 'Left Headphone Mux' 'DAC'
  32. * $ amixer sset 'DAC1R Mixer AIF1.1' on
  33. * $ amixer sset 'DAC1L Mixer AIF1.1' on
  34. * $ amixer sset 'IN2L' on
  35. * $ amixer sset 'IN2L PGA IN2LN' on
  36. * $ amixer sset 'MIXINL IN2L' on
  37. * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
  38. * $ amixer sset 'IN2R' on
  39. * $ amixer sset 'IN2R PGA IN2RN' on
  40. * $ amixer sset 'MIXINR IN2R' on
  41. * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
  42. */
  43. /* SMDK has a 16.9344MHZ crystal attached to WM8994 */
  44. #define SMDK_WM8994_FREQ 16934400
  45. static int smdk_wm8994_pcm_hw_params(struct snd_pcm_substream *substream,
  46. struct snd_pcm_hw_params *params)
  47. {
  48. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  49. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  50. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  51. unsigned long mclk_freq;
  52. int rfs, ret;
  53. switch(params_rate(params)) {
  54. case 8000:
  55. rfs = 512;
  56. break;
  57. default:
  58. dev_err(cpu_dai->dev, "%s:%d Sampling Rate %u not supported!\n",
  59. __func__, __LINE__, params_rate(params));
  60. return -EINVAL;
  61. }
  62. mclk_freq = params_rate(params) * rfs;
  63. /* Set the codec DAI configuration */
  64. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B
  65. | SND_SOC_DAIFMT_IB_NF
  66. | SND_SOC_DAIFMT_CBS_CFS);
  67. if (ret < 0)
  68. return ret;
  69. /* Set the cpu DAI configuration */
  70. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B
  71. | SND_SOC_DAIFMT_IB_NF
  72. | SND_SOC_DAIFMT_CBS_CFS);
  73. if (ret < 0)
  74. return ret;
  75. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  76. mclk_freq, SND_SOC_CLOCK_IN);
  77. if (ret < 0)
  78. return ret;
  79. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
  80. SMDK_WM8994_FREQ, mclk_freq);
  81. if (ret < 0)
  82. return ret;
  83. /* Set PCM source clock on CPU */
  84. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX,
  85. mclk_freq, SND_SOC_CLOCK_IN);
  86. if (ret < 0)
  87. return ret;
  88. /* Set SCLK_DIV for making bclk */
  89. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs);
  90. if (ret < 0)
  91. return ret;
  92. return 0;
  93. }
  94. static struct snd_soc_ops smdk_wm8994_pcm_ops = {
  95. .hw_params = smdk_wm8994_pcm_hw_params,
  96. };
  97. static struct snd_soc_dai_link smdk_dai[] = {
  98. {
  99. .name = "WM8994 PAIF PCM",
  100. .stream_name = "Primary PCM",
  101. .cpu_dai_name = "samsung-pcm.0",
  102. .codec_dai_name = "wm8994-aif1",
  103. .platform_name = "samsung-audio",
  104. .codec_name = "wm8994-codec",
  105. .ops = &smdk_wm8994_pcm_ops,
  106. },
  107. };
  108. static struct snd_soc_card smdk_pcm = {
  109. .name = "SMDK-PCM",
  110. .owner = THIS_MODULE,
  111. .dai_link = smdk_dai,
  112. .num_links = 1,
  113. };
  114. static int __devinit snd_smdk_probe(struct platform_device *pdev)
  115. {
  116. int ret = 0;
  117. smdk_pcm.dev = &pdev->dev;
  118. ret = snd_soc_register_card(&smdk_pcm);
  119. if (ret) {
  120. dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret);
  121. return ret;
  122. }
  123. return 0;
  124. }
  125. static int __devexit snd_smdk_remove(struct platform_device *pdev)
  126. {
  127. snd_soc_unregister_card(&smdk_pcm);
  128. platform_set_drvdata(pdev, NULL);
  129. return 0;
  130. }
  131. static struct platform_driver snd_smdk_driver = {
  132. .driver = {
  133. .owner = THIS_MODULE,
  134. .name = "samsung-smdk-pcm",
  135. },
  136. .probe = snd_smdk_probe,
  137. .remove = __devexit_p(snd_smdk_remove),
  138. };
  139. module_platform_driver(snd_smdk_driver);
  140. MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>");
  141. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994 for PCM");
  142. MODULE_LICENSE("GPL");