smdk_wm8994.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <sound/soc.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/of_device.h>
  15. /*
  16. * Default CFG switch settings to use this driver:
  17. * SMDKV310: CFG5-1000, CFG7-111111
  18. */
  19. /*
  20. * Configure audio route as :-
  21. * $ amixer sset 'DAC1' on,on
  22. * $ amixer sset 'Right Headphone Mux' 'DAC'
  23. * $ amixer sset 'Left Headphone Mux' 'DAC'
  24. * $ amixer sset 'DAC1R Mixer AIF1.1' on
  25. * $ amixer sset 'DAC1L Mixer AIF1.1' on
  26. * $ amixer sset 'IN2L' on
  27. * $ amixer sset 'IN2L PGA IN2LN' on
  28. * $ amixer sset 'MIXINL IN2L' on
  29. * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
  30. * $ amixer sset 'IN2R' on
  31. * $ amixer sset 'IN2R PGA IN2RN' on
  32. * $ amixer sset 'MIXINR IN2R' on
  33. * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
  34. */
  35. /* SMDK has a 16.934MHZ crystal attached to WM8994 */
  36. #define SMDK_WM8994_FREQ 16934000
  37. struct smdk_wm8994_data {
  38. int mclk1_rate;
  39. };
  40. /* Default SMDKs */
  41. static struct smdk_wm8994_data smdk_board_data = {
  42. .mclk1_rate = SMDK_WM8994_FREQ,
  43. };
  44. static int smdk_hw_params(struct snd_pcm_substream *substream,
  45. struct snd_pcm_hw_params *params)
  46. {
  47. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  48. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  49. unsigned int pll_out;
  50. int ret;
  51. /* AIF1CLK should be >=3MHz for optimal performance */
  52. if (params_width(params) == 24)
  53. pll_out = params_rate(params) * 384;
  54. else if (params_rate(params) == 8000 || params_rate(params) == 11025)
  55. pll_out = params_rate(params) * 512;
  56. else
  57. pll_out = params_rate(params) * 256;
  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_dapm_context *dapm = &rtd->card->dapm;
  77. /* Other pins NC */
  78. snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
  79. snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
  80. snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
  81. snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
  82. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  83. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  84. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  85. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  86. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  87. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  88. snd_soc_dapm_nc_pin(dapm, "IN1LP");
  89. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  90. snd_soc_dapm_nc_pin(dapm, "IN1RP");
  91. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  92. return 0;
  93. }
  94. static struct snd_soc_dai_link smdk_dai[] = {
  95. { /* Primary DAI i/f */
  96. .name = "WM8994 AIF1",
  97. .stream_name = "Pri_Dai",
  98. .cpu_dai_name = "samsung-i2s.0",
  99. .codec_dai_name = "wm8994-aif1",
  100. .platform_name = "samsung-i2s.0",
  101. .codec_name = "wm8994-codec",
  102. .init = smdk_wm8994_init_paiftx,
  103. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  104. SND_SOC_DAIFMT_CBM_CFM,
  105. .ops = &smdk_ops,
  106. }, { /* Sec_Fifo Playback i/f */
  107. .name = "Sec_FIFO TX",
  108. .stream_name = "Sec_Dai",
  109. .cpu_dai_name = "samsung-i2s-sec",
  110. .codec_dai_name = "wm8994-aif1",
  111. .platform_name = "samsung-i2s-sec",
  112. .codec_name = "wm8994-codec",
  113. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  114. SND_SOC_DAIFMT_CBM_CFM,
  115. .ops = &smdk_ops,
  116. },
  117. };
  118. static struct snd_soc_card smdk = {
  119. .name = "SMDK-I2S",
  120. .owner = THIS_MODULE,
  121. .dai_link = smdk_dai,
  122. .num_links = ARRAY_SIZE(smdk_dai),
  123. };
  124. static const struct of_device_id samsung_wm8994_of_match[] = {
  125. { .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data },
  126. {},
  127. };
  128. MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
  129. static int smdk_audio_probe(struct platform_device *pdev)
  130. {
  131. int ret;
  132. struct device_node *np = pdev->dev.of_node;
  133. struct snd_soc_card *card = &smdk;
  134. struct smdk_wm8994_data *board;
  135. const struct of_device_id *id;
  136. card->dev = &pdev->dev;
  137. board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL);
  138. if (!board)
  139. return -ENOMEM;
  140. if (np) {
  141. smdk_dai[0].cpu_dai_name = NULL;
  142. smdk_dai[0].cpu_of_node = of_parse_phandle(np,
  143. "samsung,i2s-controller", 0);
  144. if (!smdk_dai[0].cpu_of_node) {
  145. dev_err(&pdev->dev,
  146. "Property 'samsung,i2s-controller' missing or invalid\n");
  147. ret = -EINVAL;
  148. }
  149. smdk_dai[0].platform_name = NULL;
  150. smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
  151. }
  152. id = of_match_device(of_match_ptr(samsung_wm8994_of_match), &pdev->dev);
  153. if (id)
  154. *board = *((struct smdk_wm8994_data *)id->data);
  155. platform_set_drvdata(pdev, board);
  156. ret = devm_snd_soc_register_card(&pdev->dev, card);
  157. if (ret)
  158. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  159. return ret;
  160. }
  161. static struct platform_driver smdk_audio_driver = {
  162. .driver = {
  163. .name = "smdk-audio-wm8994",
  164. .of_match_table = of_match_ptr(samsung_wm8994_of_match),
  165. .pm = &snd_soc_pm_ops,
  166. },
  167. .probe = smdk_audio_probe,
  168. };
  169. module_platform_driver(smdk_audio_driver);
  170. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
  171. MODULE_LICENSE("GPL");
  172. MODULE_ALIAS("platform:smdk-audio-wm8994");