smdk_wm8994.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_format(params) == SNDRV_PCM_FORMAT_S24_LE)
  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_codec *codec = rtd->codec;
  77. struct snd_soc_dapm_context *dapm = &codec->dapm;
  78. /* HeadPhone */
  79. snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
  80. snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
  81. /* MicIn */
  82. snd_soc_dapm_enable_pin(dapm, "IN1LN");
  83. snd_soc_dapm_enable_pin(dapm, "IN1RN");
  84. /* LineIn */
  85. snd_soc_dapm_enable_pin(dapm, "IN2LN");
  86. snd_soc_dapm_enable_pin(dapm, "IN2RN");
  87. /* Other pins NC */
  88. snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
  89. snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
  90. snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
  91. snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
  92. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  93. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  94. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  95. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  96. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  97. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  98. snd_soc_dapm_nc_pin(dapm, "IN1LP");
  99. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  100. snd_soc_dapm_nc_pin(dapm, "IN1RP");
  101. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  102. return 0;
  103. }
  104. static struct snd_soc_dai_link smdk_dai[] = {
  105. { /* Primary DAI i/f */
  106. .name = "WM8994 AIF1",
  107. .stream_name = "Pri_Dai",
  108. .cpu_dai_name = "samsung-i2s.0",
  109. .codec_dai_name = "wm8994-aif1",
  110. .platform_name = "samsung-i2s.0",
  111. .codec_name = "wm8994-codec",
  112. .init = smdk_wm8994_init_paiftx,
  113. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  114. SND_SOC_DAIFMT_CBM_CFM,
  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. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  124. SND_SOC_DAIFMT_CBM_CFM,
  125. .ops = &smdk_ops,
  126. },
  127. };
  128. static struct snd_soc_card smdk = {
  129. .name = "SMDK-I2S",
  130. .owner = THIS_MODULE,
  131. .dai_link = smdk_dai,
  132. .num_links = ARRAY_SIZE(smdk_dai),
  133. };
  134. #ifdef CONFIG_OF
  135. static const struct of_device_id samsung_wm8994_of_match[] = {
  136. { .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data },
  137. {},
  138. };
  139. MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
  140. #endif /* CONFIG_OF */
  141. static int smdk_audio_probe(struct platform_device *pdev)
  142. {
  143. int ret;
  144. struct device_node *np = pdev->dev.of_node;
  145. struct snd_soc_card *card = &smdk;
  146. struct smdk_wm8994_data *board;
  147. const struct of_device_id *id;
  148. card->dev = &pdev->dev;
  149. board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL);
  150. if (!board)
  151. return -ENOMEM;
  152. if (np) {
  153. smdk_dai[0].cpu_dai_name = NULL;
  154. smdk_dai[0].cpu_of_node = of_parse_phandle(np,
  155. "samsung,i2s-controller", 0);
  156. if (!smdk_dai[0].cpu_of_node) {
  157. dev_err(&pdev->dev,
  158. "Property 'samsung,i2s-controller' missing or invalid\n");
  159. ret = -EINVAL;
  160. }
  161. smdk_dai[0].platform_name = NULL;
  162. smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
  163. }
  164. id = of_match_device(samsung_wm8994_of_match, &pdev->dev);
  165. if (id)
  166. *board = *((struct smdk_wm8994_data *)id->data);
  167. platform_set_drvdata(pdev, board);
  168. ret = devm_snd_soc_register_card(&pdev->dev, card);
  169. if (ret)
  170. dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
  171. return ret;
  172. }
  173. static struct platform_driver smdk_audio_driver = {
  174. .driver = {
  175. .name = "smdk-audio-wm8894",
  176. .owner = THIS_MODULE,
  177. .of_match_table = of_match_ptr(samsung_wm8994_of_match),
  178. .pm = &snd_soc_pm_ops,
  179. },
  180. .probe = smdk_audio_probe,
  181. };
  182. module_platform_driver(smdk_audio_driver);
  183. MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
  184. MODULE_LICENSE("GPL");
  185. MODULE_ALIAS("platform:smdk-audio-wm8994");