smdk_wm8994.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #include <linux/of.h>
  13. /*
  14. * Default CFG switch settings to use this driver:
  15. * SMDKV310: CFG5-1000, CFG7-111111
  16. */
  17. /*
  18. * Configure audio route as :-
  19. * $ amixer sset 'DAC1' on,on
  20. * $ amixer sset 'Right Headphone Mux' 'DAC'
  21. * $ amixer sset 'Left Headphone Mux' 'DAC'
  22. * $ amixer sset 'DAC1R Mixer AIF1.1' on
  23. * $ amixer sset 'DAC1L Mixer AIF1.1' on
  24. * $ amixer sset 'IN2L' on
  25. * $ amixer sset 'IN2L PGA IN2LN' on
  26. * $ amixer sset 'MIXINL IN2L' on
  27. * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
  28. * $ amixer sset 'IN2R' on
  29. * $ amixer sset 'IN2R PGA IN2RN' on
  30. * $ amixer sset 'MIXINR IN2R' on
  31. * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
  32. */
  33. /* SMDK has a 16.934MHZ crystal attached to WM8994 */
  34. #define SMDK_WM8994_FREQ 16934000
  35. static int smdk_hw_params(struct snd_pcm_substream *substream,
  36. struct snd_pcm_hw_params *params)
  37. {
  38. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  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_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
  50. SMDK_WM8994_FREQ, pll_out);
  51. if (ret < 0)
  52. return ret;
  53. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  54. pll_out, SND_SOC_CLOCK_IN);
  55. if (ret < 0)
  56. return ret;
  57. return 0;
  58. }
  59. /*
  60. * SMDK WM8994 DAI operations.
  61. */
  62. static struct snd_soc_ops smdk_ops = {
  63. .hw_params = smdk_hw_params,
  64. };
  65. static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  66. {
  67. struct snd_soc_codec *codec = rtd->codec;
  68. struct snd_soc_dapm_context *dapm = &codec->dapm;
  69. /* HeadPhone */
  70. snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
  71. snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
  72. /* MicIn */
  73. snd_soc_dapm_enable_pin(dapm, "IN1LN");
  74. snd_soc_dapm_enable_pin(dapm, "IN1RN");
  75. /* LineIn */
  76. snd_soc_dapm_enable_pin(dapm, "IN2LN");
  77. snd_soc_dapm_enable_pin(dapm, "IN2RN");
  78. /* Other pins NC */
  79. snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
  80. snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
  81. snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
  82. snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
  83. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  84. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  85. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  86. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  87. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  88. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  89. snd_soc_dapm_nc_pin(dapm, "IN1LP");
  90. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  91. snd_soc_dapm_nc_pin(dapm, "IN1RP");
  92. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  93. return 0;
  94. }
  95. static struct snd_soc_dai_link smdk_dai[] = {
  96. { /* Primary DAI i/f */
  97. .name = "WM8994 AIF1",
  98. .stream_name = "Pri_Dai",
  99. .cpu_dai_name = "samsung-i2s.0",
  100. .codec_dai_name = "wm8994-aif1",
  101. .platform_name = "samsung-i2s.0",
  102. .codec_name = "wm8994-codec",
  103. .init = smdk_wm8994_init_paiftx,
  104. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  105. SND_SOC_DAIFMT_CBM_CFM,
  106. .ops = &smdk_ops,
  107. }, { /* Sec_Fifo Playback i/f */
  108. .name = "Sec_FIFO TX",
  109. .stream_name = "Sec_Dai",
  110. .cpu_dai_name = "samsung-i2s-sec",
  111. .codec_dai_name = "wm8994-aif1",
  112. .platform_name = "samsung-i2s-sec",
  113. .codec_name = "wm8994-codec",
  114. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  115. SND_SOC_DAIFMT_CBM_CFM,
  116. .ops = &smdk_ops,
  117. },
  118. };
  119. static struct snd_soc_card smdk = {
  120. .name = "SMDK-I2S",
  121. .owner = THIS_MODULE,
  122. .dai_link = smdk_dai,
  123. .num_links = ARRAY_SIZE(smdk_dai),
  124. };
  125. static int smdk_audio_probe(struct platform_device *pdev)
  126. {
  127. int ret;
  128. struct device_node *np = pdev->dev.of_node;
  129. struct snd_soc_card *card = &smdk;
  130. card->dev = &pdev->dev;
  131. if (np) {
  132. smdk_dai[0].cpu_dai_name = NULL;
  133. smdk_dai[0].cpu_of_node = of_parse_phandle(np,
  134. "samsung,i2s-controller", 0);
  135. if (!smdk_dai[0].cpu_of_node) {
  136. dev_err(&pdev->dev,
  137. "Property 'samsung,i2s-controller' missing or invalid\n");
  138. ret = -EINVAL;
  139. }
  140. smdk_dai[0].platform_name = NULL;
  141. smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
  142. }
  143. ret = snd_soc_register_card(card);
  144. if (ret)
  145. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  146. return ret;
  147. }
  148. static int smdk_audio_remove(struct platform_device *pdev)
  149. {
  150. struct snd_soc_card *card = platform_get_drvdata(pdev);
  151. snd_soc_unregister_card(card);
  152. return 0;
  153. }
  154. #ifdef CONFIG_OF
  155. static const struct of_device_id samsung_wm8994_of_match[] = {
  156. { .compatible = "samsung,smdk-wm8994", },
  157. {},
  158. };
  159. MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
  160. #endif /* CONFIG_OF */
  161. static struct platform_driver smdk_audio_driver = {
  162. .driver = {
  163. .name = "smdk-audio-wm8894",
  164. .owner = THIS_MODULE,
  165. .of_match_table = of_match_ptr(samsung_wm8994_of_match),
  166. },
  167. .probe = smdk_audio_probe,
  168. .remove = smdk_audio_remove,
  169. };
  170. module_platform_driver(smdk_audio_driver);
  171. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
  172. MODULE_LICENSE("GPL");
  173. MODULE_ALIAS("platform:smdk-audio-wm8994");