smdk_wm8994.c 4.5 KB

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