smdk_wm8994.c 4.6 KB

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