smdk_wm8580.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Copyright (c) 2009 Samsung Electronics Co. Ltd
  4. // Author: Jaswinder Singh <[email protected]>
  5. #include <linux/module.h>
  6. #include <sound/soc.h>
  7. #include <sound/pcm_params.h>
  8. #include "../codecs/wm8580.h"
  9. #include "i2s.h"
  10. /*
  11. * Default CFG switch settings to use this driver:
  12. *
  13. * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
  14. */
  15. /* SMDK has a 12MHZ crystal attached to WM8580 */
  16. #define SMDK_WM8580_FREQ 12000000
  17. static int smdk_hw_params(struct snd_pcm_substream *substream,
  18. struct snd_pcm_hw_params *params)
  19. {
  20. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  21. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  22. unsigned int pll_out;
  23. int rfs, ret;
  24. switch (params_width(params)) {
  25. case 8:
  26. case 16:
  27. break;
  28. default:
  29. return -EINVAL;
  30. }
  31. /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
  32. * This criterion can't be met if we request PLL output
  33. * as {8000x256, 64000x256, 11025x256}Hz.
  34. * As a wayout, we rather change rfs to a minimum value that
  35. * results in (params_rate(params) * rfs), and itself, acceptable
  36. * to both - the CODEC and the CPU.
  37. */
  38. switch (params_rate(params)) {
  39. case 16000:
  40. case 22050:
  41. case 32000:
  42. case 44100:
  43. case 48000:
  44. case 88200:
  45. case 96000:
  46. rfs = 256;
  47. break;
  48. case 64000:
  49. rfs = 384;
  50. break;
  51. case 8000:
  52. case 11025:
  53. rfs = 512;
  54. break;
  55. default:
  56. return -EINVAL;
  57. }
  58. pll_out = params_rate(params) * rfs;
  59. /* Set WM8580 to drive MCLK from its PLLA */
  60. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  61. WM8580_CLKSRC_PLLA);
  62. if (ret < 0)
  63. return ret;
  64. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  65. SMDK_WM8580_FREQ, pll_out);
  66. if (ret < 0)
  67. return ret;
  68. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  69. pll_out, SND_SOC_CLOCK_IN);
  70. if (ret < 0)
  71. return ret;
  72. return 0;
  73. }
  74. /*
  75. * SMDK WM8580 DAI operations.
  76. */
  77. static const struct snd_soc_ops smdk_ops = {
  78. .hw_params = smdk_hw_params,
  79. };
  80. /* SMDK Playback widgets */
  81. static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
  82. SND_SOC_DAPM_HP("Front", NULL),
  83. SND_SOC_DAPM_HP("Center+Sub", NULL),
  84. SND_SOC_DAPM_HP("Rear", NULL),
  85. SND_SOC_DAPM_MIC("MicIn", NULL),
  86. SND_SOC_DAPM_LINE("LineIn", NULL),
  87. };
  88. /* SMDK-PAIFTX connections */
  89. static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
  90. /* MicIn feeds AINL */
  91. {"AINL", NULL, "MicIn"},
  92. /* LineIn feeds AINL/R */
  93. {"AINL", NULL, "LineIn"},
  94. {"AINR", NULL, "LineIn"},
  95. /* Front Left/Right are fed VOUT1L/R */
  96. {"Front", NULL, "VOUT1L"},
  97. {"Front", NULL, "VOUT1R"},
  98. /* Center/Sub are fed VOUT2L/R */
  99. {"Center+Sub", NULL, "VOUT2L"},
  100. {"Center+Sub", NULL, "VOUT2R"},
  101. /* Rear Left/Right are fed VOUT3L/R */
  102. {"Rear", NULL, "VOUT3L"},
  103. {"Rear", NULL, "VOUT3R"},
  104. };
  105. static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  106. {
  107. /* Enabling the microphone requires the fitting of a 0R
  108. * resistor to connect the line from the microphone jack.
  109. */
  110. snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
  111. return 0;
  112. }
  113. enum {
  114. PRI_PLAYBACK = 0,
  115. PRI_CAPTURE,
  116. };
  117. #define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
  118. SND_SOC_DAIFMT_CBM_CFM)
  119. SND_SOC_DAILINK_DEFS(paif_rx,
  120. DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.2")),
  121. DAILINK_COMP_ARRAY(COMP_CODEC("wm8580.0-001b", "wm8580-hifi-playback")),
  122. DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
  123. SND_SOC_DAILINK_DEFS(paif_tx,
  124. DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.2")),
  125. DAILINK_COMP_ARRAY(COMP_CODEC("wm8580.0-001b", "wm8580-hifi-capture")),
  126. DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
  127. static struct snd_soc_dai_link smdk_dai[] = {
  128. [PRI_PLAYBACK] = { /* Primary Playback i/f */
  129. .name = "WM8580 PAIF RX",
  130. .stream_name = "Playback",
  131. .dai_fmt = SMDK_DAI_FMT,
  132. .ops = &smdk_ops,
  133. SND_SOC_DAILINK_REG(paif_rx),
  134. },
  135. [PRI_CAPTURE] = { /* Primary Capture i/f */
  136. .name = "WM8580 PAIF TX",
  137. .stream_name = "Capture",
  138. .dai_fmt = SMDK_DAI_FMT,
  139. .init = smdk_wm8580_init_paiftx,
  140. .ops = &smdk_ops,
  141. SND_SOC_DAILINK_REG(paif_tx),
  142. },
  143. };
  144. static struct snd_soc_card smdk = {
  145. .name = "SMDK-I2S",
  146. .owner = THIS_MODULE,
  147. .dai_link = smdk_dai,
  148. .num_links = ARRAY_SIZE(smdk_dai),
  149. .dapm_widgets = smdk_wm8580_dapm_widgets,
  150. .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
  151. .dapm_routes = smdk_wm8580_audio_map,
  152. .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
  153. };
  154. static struct platform_device *smdk_snd_device;
  155. static int __init smdk_audio_init(void)
  156. {
  157. int ret;
  158. smdk_snd_device = platform_device_alloc("soc-audio", -1);
  159. if (!smdk_snd_device)
  160. return -ENOMEM;
  161. platform_set_drvdata(smdk_snd_device, &smdk);
  162. ret = platform_device_add(smdk_snd_device);
  163. if (ret)
  164. platform_device_put(smdk_snd_device);
  165. return ret;
  166. }
  167. module_init(smdk_audio_init);
  168. static void __exit smdk_audio_exit(void)
  169. {
  170. platform_device_unregister(smdk_snd_device);
  171. }
  172. module_exit(smdk_audio_exit);
  173. MODULE_AUTHOR("Jaswinder Singh, [email protected]");
  174. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
  175. MODULE_LICENSE("GPL");