smdk64xx_wm8580.c 6.7 KB

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