smdk_wm8994.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * smdk_wm8994.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. */
  9. #include "../codecs/wm8994.h"
  10. #include <sound/pcm_params.h>
  11. /*
  12. * Default CFG switch settings to use this driver:
  13. * SMDKV310: CFG5-1000, CFG7-111111
  14. */
  15. /*
  16. * Configure audio route as :-
  17. * $ amixer sset 'DAC1' on,on
  18. * $ amixer sset 'Right Headphone Mux' 'DAC'
  19. * $ amixer sset 'Left Headphone Mux' 'DAC'
  20. * $ amixer sset 'DAC1R Mixer AIF1.1' on
  21. * $ amixer sset 'DAC1L Mixer AIF1.1' on
  22. * $ amixer sset 'IN2L' on
  23. * $ amixer sset 'IN2L PGA IN2LN' on
  24. * $ amixer sset 'MIXINL IN2L' on
  25. * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
  26. * $ amixer sset 'IN2R' on
  27. * $ amixer sset 'IN2R PGA IN2RN' on
  28. * $ amixer sset 'MIXINR IN2R' on
  29. * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
  30. */
  31. /* SMDK has a 16.934MHZ crystal attached to WM8994 */
  32. #define SMDK_WM8994_FREQ 16934000
  33. static int smdk_hw_params(struct snd_pcm_substream *substream,
  34. struct snd_pcm_hw_params *params)
  35. {
  36. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  37. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  38. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  39. unsigned int pll_out;
  40. int ret;
  41. /* AIF1CLK should be >=3MHz for optimal performance */
  42. if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
  43. pll_out = params_rate(params) * 384;
  44. else if (params_rate(params) == 8000 || params_rate(params) == 11025)
  45. pll_out = params_rate(params) * 512;
  46. else
  47. pll_out = params_rate(params) * 256;
  48. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  49. | SND_SOC_DAIFMT_NB_NF
  50. | SND_SOC_DAIFMT_CBM_CFM);
  51. if (ret < 0)
  52. return ret;
  53. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  54. | SND_SOC_DAIFMT_NB_NF
  55. | SND_SOC_DAIFMT_CBM_CFM);
  56. if (ret < 0)
  57. return ret;
  58. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
  59. SMDK_WM8994_FREQ, pll_out);
  60. if (ret < 0)
  61. return ret;
  62. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  63. pll_out, SND_SOC_CLOCK_IN);
  64. if (ret < 0)
  65. return ret;
  66. return 0;
  67. }
  68. /*
  69. * SMDK WM8994 DAI operations.
  70. */
  71. static struct snd_soc_ops smdk_ops = {
  72. .hw_params = smdk_hw_params,
  73. };
  74. static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  75. {
  76. struct snd_soc_codec *codec = rtd->codec;
  77. struct snd_soc_dapm_context *dapm = &codec->dapm;
  78. /* HeadPhone */
  79. snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
  80. snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
  81. /* MicIn */
  82. snd_soc_dapm_enable_pin(dapm, "IN1LN");
  83. snd_soc_dapm_enable_pin(dapm, "IN1RN");
  84. /* LineIn */
  85. snd_soc_dapm_enable_pin(dapm, "IN2LN");
  86. snd_soc_dapm_enable_pin(dapm, "IN2RN");
  87. /* Other pins NC */
  88. snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
  89. snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
  90. snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
  91. snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
  92. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  93. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  94. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  95. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  96. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  97. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  98. snd_soc_dapm_nc_pin(dapm, "IN1LP");
  99. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  100. snd_soc_dapm_nc_pin(dapm, "IN1RP");
  101. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  102. return 0;
  103. }
  104. static struct snd_soc_dai_link smdk_dai[] = {
  105. { /* Primary DAI i/f */
  106. .name = "WM8994 AIF1",
  107. .stream_name = "Pri_Dai",
  108. .cpu_dai_name = "samsung-i2s.0",
  109. .codec_dai_name = "wm8994-aif1",
  110. .platform_name = "samsung-audio",
  111. .codec_name = "wm8994-codec",
  112. .init = smdk_wm8994_init_paiftx,
  113. .ops = &smdk_ops,
  114. }, { /* Sec_Fifo Playback i/f */
  115. .name = "Sec_FIFO TX",
  116. .stream_name = "Sec_Dai",
  117. .cpu_dai_name = "samsung-i2s.4",
  118. .codec_dai_name = "wm8994-aif1",
  119. .platform_name = "samsung-audio",
  120. .codec_name = "wm8994-codec",
  121. .ops = &smdk_ops,
  122. },
  123. };
  124. static struct snd_soc_card smdk = {
  125. .name = "SMDK-I2S",
  126. .dai_link = smdk_dai,
  127. .num_links = ARRAY_SIZE(smdk_dai),
  128. };
  129. static struct platform_device *smdk_snd_device;
  130. static int __init smdk_audio_init(void)
  131. {
  132. int ret;
  133. smdk_snd_device = platform_device_alloc("soc-audio", -1);
  134. if (!smdk_snd_device)
  135. return -ENOMEM;
  136. platform_set_drvdata(smdk_snd_device, &smdk);
  137. ret = platform_device_add(smdk_snd_device);
  138. if (ret)
  139. platform_device_put(smdk_snd_device);
  140. return ret;
  141. }
  142. module_init(smdk_audio_init);
  143. static void __exit smdk_audio_exit(void)
  144. {
  145. platform_device_unregister(smdk_snd_device);
  146. }
  147. module_exit(smdk_audio_exit);
  148. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
  149. MODULE_LICENSE("GPL");