smdk_wm8994.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 *cpu_dai = rtd->cpu_dai;
  40. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  41. unsigned int pll_out;
  42. int ret;
  43. /* AIF1CLK should be >=3MHz for optimal performance */
  44. if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
  45. pll_out = params_rate(params) * 384;
  46. else if (params_rate(params) == 8000 || params_rate(params) == 11025)
  47. pll_out = params_rate(params) * 512;
  48. else
  49. pll_out = params_rate(params) * 256;
  50. ret = snd_soc_dai_set_fmt(codec_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_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  56. | SND_SOC_DAIFMT_NB_NF
  57. | SND_SOC_DAIFMT_CBM_CFM);
  58. if (ret < 0)
  59. return ret;
  60. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
  61. SMDK_WM8994_FREQ, pll_out);
  62. if (ret < 0)
  63. return ret;
  64. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  65. pll_out, SND_SOC_CLOCK_IN);
  66. if (ret < 0)
  67. return ret;
  68. return 0;
  69. }
  70. /*
  71. * SMDK WM8994 DAI operations.
  72. */
  73. static struct snd_soc_ops smdk_ops = {
  74. .hw_params = smdk_hw_params,
  75. };
  76. static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  77. {
  78. struct snd_soc_codec *codec = rtd->codec;
  79. struct snd_soc_dapm_context *dapm = &codec->dapm;
  80. /* HeadPhone */
  81. snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
  82. snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
  83. /* MicIn */
  84. snd_soc_dapm_enable_pin(dapm, "IN1LN");
  85. snd_soc_dapm_enable_pin(dapm, "IN1RN");
  86. /* LineIn */
  87. snd_soc_dapm_enable_pin(dapm, "IN2LN");
  88. snd_soc_dapm_enable_pin(dapm, "IN2RN");
  89. /* Other pins NC */
  90. snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
  91. snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
  92. snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
  93. snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
  94. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  95. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  96. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  97. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  98. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  99. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  100. snd_soc_dapm_nc_pin(dapm, "IN1LP");
  101. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  102. snd_soc_dapm_nc_pin(dapm, "IN1RP");
  103. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  104. return 0;
  105. }
  106. static struct snd_soc_dai_link smdk_dai[] = {
  107. { /* Primary DAI i/f */
  108. .name = "WM8994 AIF1",
  109. .stream_name = "Pri_Dai",
  110. .cpu_dai_name = "samsung-i2s.0",
  111. .codec_dai_name = "wm8994-aif1",
  112. .platform_name = "samsung-i2s.0",
  113. .codec_name = "wm8994-codec",
  114. .init = smdk_wm8994_init_paiftx,
  115. .ops = &smdk_ops,
  116. }, { /* Sec_Fifo Playback i/f */
  117. .name = "Sec_FIFO TX",
  118. .stream_name = "Sec_Dai",
  119. .cpu_dai_name = "samsung-i2s-sec",
  120. .codec_dai_name = "wm8994-aif1",
  121. .platform_name = "samsung-i2s-sec",
  122. .codec_name = "wm8994-codec",
  123. .ops = &smdk_ops,
  124. },
  125. };
  126. static struct snd_soc_card smdk = {
  127. .name = "SMDK-I2S",
  128. .owner = THIS_MODULE,
  129. .dai_link = smdk_dai,
  130. .num_links = ARRAY_SIZE(smdk_dai),
  131. };
  132. static int smdk_audio_probe(struct platform_device *pdev)
  133. {
  134. int ret;
  135. struct device_node *np = pdev->dev.of_node;
  136. struct snd_soc_card *card = &smdk;
  137. card->dev = &pdev->dev;
  138. if (np) {
  139. smdk_dai[0].cpu_dai_name = NULL;
  140. smdk_dai[0].cpu_of_node = of_parse_phandle(np,
  141. "samsung,i2s-controller", 0);
  142. if (!smdk_dai[0].cpu_of_node) {
  143. dev_err(&pdev->dev,
  144. "Property 'samsung,i2s-controller' missing or invalid\n");
  145. ret = -EINVAL;
  146. }
  147. smdk_dai[0].platform_name = NULL;
  148. smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
  149. }
  150. ret = snd_soc_register_card(card);
  151. if (ret)
  152. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  153. return ret;
  154. }
  155. static int smdk_audio_remove(struct platform_device *pdev)
  156. {
  157. struct snd_soc_card *card = platform_get_drvdata(pdev);
  158. snd_soc_unregister_card(card);
  159. return 0;
  160. }
  161. #ifdef CONFIG_OF
  162. static const struct of_device_id samsung_wm8994_of_match[] = {
  163. { .compatible = "samsung,smdk-wm8994", },
  164. {},
  165. };
  166. MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
  167. #endif /* CONFIG_OF */
  168. static struct platform_driver smdk_audio_driver = {
  169. .driver = {
  170. .name = "smdk-audio",
  171. .owner = THIS_MODULE,
  172. .of_match_table = of_match_ptr(samsung_wm8994_of_match),
  173. },
  174. .probe = smdk_audio_probe,
  175. .remove = smdk_audio_remove,
  176. };
  177. module_platform_driver(smdk_audio_driver);
  178. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
  179. MODULE_LICENSE("GPL");
  180. MODULE_ALIAS("platform:smdk-audio");