smdk_wm8994.c 5.9 KB

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