smdk_wm8580.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 <asm/mach-types.h>
  16. #include "../codecs/wm8580.h"
  17. #include "i2s.h"
  18. /*
  19. * Default CFG switch settings to use this driver:
  20. *
  21. * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
  22. */
  23. /* SMDK has a 12MHZ crystal attached to WM8580 */
  24. #define SMDK_WM8580_FREQ 12000000
  25. static int smdk_hw_params(struct snd_pcm_substream *substream,
  26. struct snd_pcm_hw_params *params)
  27. {
  28. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  29. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  30. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  31. unsigned int pll_out;
  32. int bfs, rfs, ret;
  33. switch (params_width(params)) {
  34. case 8:
  35. bfs = 16;
  36. break;
  37. case 16:
  38. bfs = 32;
  39. break;
  40. default:
  41. return -EINVAL;
  42. }
  43. /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
  44. * This criterion can't be met if we request PLL output
  45. * as {8000x256, 64000x256, 11025x256}Hz.
  46. * As a wayout, we rather change rfs to a minimum value that
  47. * results in (params_rate(params) * rfs), and itself, acceptable
  48. * to both - the CODEC and the CPU.
  49. */
  50. switch (params_rate(params)) {
  51. case 16000:
  52. case 22050:
  53. case 32000:
  54. case 44100:
  55. case 48000:
  56. case 88200:
  57. case 96000:
  58. rfs = 256;
  59. break;
  60. case 64000:
  61. rfs = 384;
  62. break;
  63. case 8000:
  64. case 11025:
  65. rfs = 512;
  66. break;
  67. default:
  68. return -EINVAL;
  69. }
  70. pll_out = params_rate(params) * rfs;
  71. /* Set the Codec DAI configuration */
  72. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  73. | SND_SOC_DAIFMT_NB_NF
  74. | SND_SOC_DAIFMT_CBM_CFM);
  75. if (ret < 0)
  76. return ret;
  77. /* Set the AP DAI configuration */
  78. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  79. | SND_SOC_DAIFMT_NB_NF
  80. | SND_SOC_DAIFMT_CBM_CFM);
  81. if (ret < 0)
  82. return ret;
  83. /* Set WM8580 to drive MCLK from its PLLA */
  84. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  85. WM8580_CLKSRC_PLLA);
  86. if (ret < 0)
  87. return ret;
  88. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  89. SMDK_WM8580_FREQ, pll_out);
  90. if (ret < 0)
  91. return ret;
  92. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  93. pll_out, SND_SOC_CLOCK_IN);
  94. if (ret < 0)
  95. return ret;
  96. return 0;
  97. }
  98. /*
  99. * SMDK WM8580 DAI operations.
  100. */
  101. static struct snd_soc_ops smdk_ops = {
  102. .hw_params = smdk_hw_params,
  103. };
  104. /* SMDK Playback widgets */
  105. static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
  106. SND_SOC_DAPM_HP("Front", NULL),
  107. SND_SOC_DAPM_HP("Center+Sub", NULL),
  108. SND_SOC_DAPM_HP("Rear", NULL),
  109. SND_SOC_DAPM_MIC("MicIn", NULL),
  110. SND_SOC_DAPM_LINE("LineIn", NULL),
  111. };
  112. /* SMDK-PAIFTX connections */
  113. static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
  114. /* MicIn feeds AINL */
  115. {"AINL", NULL, "MicIn"},
  116. /* LineIn feeds AINL/R */
  117. {"AINL", NULL, "LineIn"},
  118. {"AINR", NULL, "LineIn"},
  119. /* Front Left/Right are fed VOUT1L/R */
  120. {"Front", NULL, "VOUT1L"},
  121. {"Front", NULL, "VOUT1R"},
  122. /* Center/Sub are fed VOUT2L/R */
  123. {"Center+Sub", NULL, "VOUT2L"},
  124. {"Center+Sub", NULL, "VOUT2R"},
  125. /* Rear Left/Right are fed VOUT3L/R */
  126. {"Rear", NULL, "VOUT3L"},
  127. {"Rear", NULL, "VOUT3R"},
  128. };
  129. static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  130. {
  131. struct snd_soc_codec *codec = rtd->codec;
  132. struct snd_soc_dapm_context *dapm = &codec->dapm;
  133. /* Enabling the microphone requires the fitting of a 0R
  134. * resistor to connect the line from the microphone jack.
  135. */
  136. snd_soc_dapm_disable_pin(dapm, "MicIn");
  137. return 0;
  138. }
  139. enum {
  140. PRI_PLAYBACK = 0,
  141. PRI_CAPTURE,
  142. SEC_PLAYBACK,
  143. };
  144. static struct snd_soc_dai_link smdk_dai[] = {
  145. [PRI_PLAYBACK] = { /* Primary Playback i/f */
  146. .name = "WM8580 PAIF RX",
  147. .stream_name = "Playback",
  148. .cpu_dai_name = "samsung-i2s.0",
  149. .codec_dai_name = "wm8580-hifi-playback",
  150. .platform_name = "samsung-i2s.0",
  151. .codec_name = "wm8580.0-001b",
  152. .ops = &smdk_ops,
  153. },
  154. [PRI_CAPTURE] = { /* Primary Capture i/f */
  155. .name = "WM8580 PAIF TX",
  156. .stream_name = "Capture",
  157. .cpu_dai_name = "samsung-i2s.0",
  158. .codec_dai_name = "wm8580-hifi-capture",
  159. .platform_name = "samsung-i2s.0",
  160. .codec_name = "wm8580.0-001b",
  161. .init = smdk_wm8580_init_paiftx,
  162. .ops = &smdk_ops,
  163. },
  164. [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
  165. .name = "Sec_FIFO TX",
  166. .stream_name = "Playback",
  167. .cpu_dai_name = "samsung-i2s-sec",
  168. .codec_dai_name = "wm8580-hifi-playback",
  169. .platform_name = "samsung-i2s-sec",
  170. .codec_name = "wm8580.0-001b",
  171. .ops = &smdk_ops,
  172. },
  173. };
  174. static struct snd_soc_card smdk = {
  175. .name = "SMDK-I2S",
  176. .owner = THIS_MODULE,
  177. .dai_link = smdk_dai,
  178. .num_links = 2,
  179. .dapm_widgets = smdk_wm8580_dapm_widgets,
  180. .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
  181. .dapm_routes = smdk_wm8580_audio_map,
  182. .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
  183. };
  184. static struct platform_device *smdk_snd_device;
  185. static int __init smdk_audio_init(void)
  186. {
  187. int ret;
  188. char *str;
  189. if (machine_is_smdkc100()
  190. || machine_is_smdkv210() || machine_is_smdkc110()) {
  191. smdk.num_links = 3;
  192. } else if (machine_is_smdk6410()) {
  193. str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
  194. str[strlen(str) - 1] = '2';
  195. str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
  196. str[strlen(str) - 1] = '2';
  197. }
  198. smdk_snd_device = platform_device_alloc("soc-audio", -1);
  199. if (!smdk_snd_device)
  200. return -ENOMEM;
  201. platform_set_drvdata(smdk_snd_device, &smdk);
  202. ret = platform_device_add(smdk_snd_device);
  203. if (ret)
  204. platform_device_put(smdk_snd_device);
  205. return ret;
  206. }
  207. module_init(smdk_audio_init);
  208. static void __exit smdk_audio_exit(void)
  209. {
  210. platform_device_unregister(smdk_snd_device);
  211. }
  212. module_exit(smdk_audio_exit);
  213. MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
  214. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
  215. MODULE_LICENSE("GPL");