smdk_wm8580.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * smdk_wm8580.c
  3. *
  4. * Copyright (c) 2009 Samsung Electronics Co. Ltd
  5. * Author: Jaswinder Singh <jassi.brar@samsung.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 <sound/soc.h>
  13. #include <sound/pcm_params.h>
  14. #include <asm/mach-types.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 *cpu_dai = rtd->cpu_dai;
  29. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  30. unsigned int pll_out;
  31. int bfs, rfs, ret;
  32. switch (params_format(params)) {
  33. case SNDRV_PCM_FORMAT_U8:
  34. case SNDRV_PCM_FORMAT_S8:
  35. bfs = 16;
  36. break;
  37. case SNDRV_PCM_FORMAT_U16_LE:
  38. case SNDRV_PCM_FORMAT_S16_LE:
  39. bfs = 32;
  40. break;
  41. default:
  42. return -EINVAL;
  43. }
  44. /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
  45. * This criterion can't be met if we request PLL output
  46. * as {8000x256, 64000x256, 11025x256}Hz.
  47. * As a wayout, we rather change rfs to a minimum value that
  48. * results in (params_rate(params) * rfs), and itself, acceptable
  49. * to both - the CODEC and the CPU.
  50. */
  51. switch (params_rate(params)) {
  52. case 16000:
  53. case 22050:
  54. case 32000:
  55. case 44100:
  56. case 48000:
  57. case 88200:
  58. case 96000:
  59. rfs = 256;
  60. break;
  61. case 64000:
  62. rfs = 384;
  63. break;
  64. case 8000:
  65. case 11025:
  66. rfs = 512;
  67. break;
  68. default:
  69. return -EINVAL;
  70. }
  71. pll_out = params_rate(params) * rfs;
  72. /* Set the Codec DAI configuration */
  73. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  74. | SND_SOC_DAIFMT_NB_NF
  75. | SND_SOC_DAIFMT_CBM_CFM);
  76. if (ret < 0)
  77. return ret;
  78. /* Set the AP DAI configuration */
  79. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  80. | SND_SOC_DAIFMT_NB_NF
  81. | SND_SOC_DAIFMT_CBM_CFM);
  82. if (ret < 0)
  83. return ret;
  84. /* Set WM8580 to drive MCLK from its PLLA */
  85. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  86. WM8580_CLKSRC_PLLA);
  87. if (ret < 0)
  88. return ret;
  89. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  90. SMDK_WM8580_FREQ, pll_out);
  91. if (ret < 0)
  92. return ret;
  93. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  94. pll_out, SND_SOC_CLOCK_IN);
  95. if (ret < 0)
  96. return ret;
  97. return 0;
  98. }
  99. /*
  100. * SMDK WM8580 DAI operations.
  101. */
  102. static struct snd_soc_ops smdk_ops = {
  103. .hw_params = smdk_hw_params,
  104. };
  105. /* SMDK Playback widgets */
  106. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
  107. SND_SOC_DAPM_HP("Front", NULL),
  108. SND_SOC_DAPM_HP("Center+Sub", NULL),
  109. SND_SOC_DAPM_HP("Rear", NULL),
  110. };
  111. /* SMDK Capture widgets */
  112. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
  113. SND_SOC_DAPM_MIC("MicIn", NULL),
  114. SND_SOC_DAPM_LINE("LineIn", NULL),
  115. };
  116. /* SMDK-PAIFTX connections */
  117. static const struct snd_soc_dapm_route audio_map_tx[] = {
  118. /* MicIn feeds AINL */
  119. {"AINL", NULL, "MicIn"},
  120. /* LineIn feeds AINL/R */
  121. {"AINL", NULL, "LineIn"},
  122. {"AINR", NULL, "LineIn"},
  123. };
  124. /* SMDK-PAIFRX connections */
  125. static const struct snd_soc_dapm_route audio_map_rx[] = {
  126. /* Front Left/Right are fed VOUT1L/R */
  127. {"Front", NULL, "VOUT1L"},
  128. {"Front", NULL, "VOUT1R"},
  129. /* Center/Sub are fed VOUT2L/R */
  130. {"Center+Sub", NULL, "VOUT2L"},
  131. {"Center+Sub", NULL, "VOUT2R"},
  132. /* Rear Left/Right are fed VOUT3L/R */
  133. {"Rear", NULL, "VOUT3L"},
  134. {"Rear", NULL, "VOUT3R"},
  135. };
  136. static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  137. {
  138. struct snd_soc_codec *codec = rtd->codec;
  139. struct snd_soc_dapm_context *dapm = &codec->dapm;
  140. /* Add smdk specific Capture widgets */
  141. snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt,
  142. ARRAY_SIZE(wm8580_dapm_widgets_cpt));
  143. /* Set up PAIFTX audio path */
  144. snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx));
  145. /* Enabling the microphone requires the fitting of a 0R
  146. * resistor to connect the line from the microphone jack.
  147. */
  148. snd_soc_dapm_disable_pin(dapm, "MicIn");
  149. /* signal a DAPM event */
  150. snd_soc_dapm_sync(dapm);
  151. return 0;
  152. }
  153. static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd)
  154. {
  155. struct snd_soc_codec *codec = rtd->codec;
  156. struct snd_soc_dapm_context *dapm = &codec->dapm;
  157. /* Add smdk specific Playback widgets */
  158. snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk,
  159. ARRAY_SIZE(wm8580_dapm_widgets_pbk));
  160. /* Set up PAIFRX audio path */
  161. snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx));
  162. /* signal a DAPM event */
  163. snd_soc_dapm_sync(dapm);
  164. return 0;
  165. }
  166. enum {
  167. PRI_PLAYBACK = 0,
  168. PRI_CAPTURE,
  169. SEC_PLAYBACK,
  170. };
  171. static struct snd_soc_dai_link smdk_dai[] = {
  172. [PRI_PLAYBACK] = { /* Primary Playback i/f */
  173. .name = "WM8580 PAIF RX",
  174. .stream_name = "Playback",
  175. .cpu_dai_name = "samsung-i2s.0",
  176. .codec_dai_name = "wm8580-hifi-playback",
  177. .platform_name = "samsung-audio",
  178. .codec_name = "wm8580-codec.0-001b",
  179. .init = smdk_wm8580_init_paifrx,
  180. .ops = &smdk_ops,
  181. },
  182. [PRI_CAPTURE] = { /* Primary Capture i/f */
  183. .name = "WM8580 PAIF TX",
  184. .stream_name = "Capture",
  185. .cpu_dai_name = "samsung-i2s.0",
  186. .codec_dai_name = "wm8580-hifi-capture",
  187. .platform_name = "samsung-audio",
  188. .codec_name = "wm8580-codec.0-001b",
  189. .init = smdk_wm8580_init_paiftx,
  190. .ops = &smdk_ops,
  191. },
  192. [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
  193. .name = "Sec_FIFO TX",
  194. .stream_name = "Playback",
  195. .cpu_dai_name = "samsung-i2s.x",
  196. .codec_dai_name = "wm8580-hifi-playback",
  197. .platform_name = "samsung-audio",
  198. .codec_name = "wm8580-codec.0-001b",
  199. .init = smdk_wm8580_init_paifrx,
  200. .ops = &smdk_ops,
  201. },
  202. };
  203. static struct snd_soc_card smdk = {
  204. .name = "SMDK-I2S",
  205. .dai_link = smdk_dai,
  206. .num_links = 2,
  207. };
  208. static struct platform_device *smdk_snd_device;
  209. static int __init smdk_audio_init(void)
  210. {
  211. int ret;
  212. char *str;
  213. if (machine_is_smdkc100()
  214. || machine_is_smdkv210() || machine_is_smdkc110()) {
  215. smdk.num_links = 3;
  216. /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
  217. str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
  218. str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
  219. } else if (machine_is_smdk6410()) {
  220. str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
  221. str[strlen(str) - 1] = '2';
  222. str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
  223. str[strlen(str) - 1] = '2';
  224. }
  225. smdk_snd_device = platform_device_alloc("soc-audio", -1);
  226. if (!smdk_snd_device)
  227. return -ENOMEM;
  228. platform_set_drvdata(smdk_snd_device, &smdk);
  229. ret = platform_device_add(smdk_snd_device);
  230. if (ret)
  231. platform_device_put(smdk_snd_device);
  232. return ret;
  233. }
  234. module_init(smdk_audio_init);
  235. static void __exit smdk_audio_exit(void)
  236. {
  237. platform_device_unregister(smdk_snd_device);
  238. }
  239. module_exit(smdk_audio_exit);
  240. MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
  241. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
  242. MODULE_LICENSE("GPL");