smdk_wm8580.c 6.9 KB

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