smdk_wm8994.c 5.3 KB

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