smdk_wm8580.c 5.0 KB

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