smdk64xx_wm8580.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 <sound/soc-dapm.h>
  19. #include "../codecs/wm8580.h"
  20. #include "s3c-dma.h"
  21. #include "s3c64xx-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. /* SMDK64XX has a 12MHZ crystal attached to WM8580 */
  28. #define SMDK64XX_WM8580_FREQ 12000000
  29. static int smdk64xx_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->dai->cpu_dai;
  34. struct snd_soc_dai *codec_dai = rtd->dai->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. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK,
  90. 0, SND_SOC_CLOCK_IN);
  91. if (ret < 0)
  92. return ret;
  93. /* We use PCLK for basic ops in SoC-Slave mode */
  94. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
  95. 0, SND_SOC_CLOCK_IN);
  96. if (ret < 0)
  97. return ret;
  98. /* Set WM8580 to drive MCLK from its PLLA */
  99. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  100. WM8580_CLKSRC_PLLA);
  101. if (ret < 0)
  102. return ret;
  103. /* Explicitly set WM8580-DAC to source from MCLK */
  104. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_DAC_CLKSEL,
  105. WM8580_CLKSRC_MCLK);
  106. if (ret < 0)
  107. return ret;
  108. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  109. SMDK64XX_WM8580_FREQ, pll_out);
  110. if (ret < 0)
  111. return ret;
  112. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
  113. if (ret < 0)
  114. return ret;
  115. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
  116. if (ret < 0)
  117. return ret;
  118. return 0;
  119. }
  120. /*
  121. * SMDK64XX WM8580 DAI operations.
  122. */
  123. static struct snd_soc_ops smdk64xx_ops = {
  124. .hw_params = smdk64xx_hw_params,
  125. };
  126. /* SMDK64xx Playback widgets */
  127. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
  128. SND_SOC_DAPM_HP("Front", NULL),
  129. SND_SOC_DAPM_HP("Center+Sub", NULL),
  130. SND_SOC_DAPM_HP("Rear", NULL),
  131. };
  132. /* SMDK64xx Capture widgets */
  133. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
  134. SND_SOC_DAPM_MIC("MicIn", NULL),
  135. SND_SOC_DAPM_LINE("LineIn", NULL),
  136. };
  137. /* SMDK-PAIFTX connections */
  138. static const struct snd_soc_dapm_route audio_map_tx[] = {
  139. /* MicIn feeds AINL */
  140. {"AINL", NULL, "MicIn"},
  141. /* LineIn feeds AINL/R */
  142. {"AINL", NULL, "LineIn"},
  143. {"AINR", NULL, "LineIn"},
  144. };
  145. /* SMDK-PAIFRX connections */
  146. static const struct snd_soc_dapm_route audio_map_rx[] = {
  147. /* Front Left/Right are fed VOUT1L/R */
  148. {"Front", NULL, "VOUT1L"},
  149. {"Front", NULL, "VOUT1R"},
  150. /* Center/Sub are fed VOUT2L/R */
  151. {"Center+Sub", NULL, "VOUT2L"},
  152. {"Center+Sub", NULL, "VOUT2R"},
  153. /* Rear Left/Right are fed VOUT3L/R */
  154. {"Rear", NULL, "VOUT3L"},
  155. {"Rear", NULL, "VOUT3R"},
  156. };
  157. static int smdk64xx_wm8580_init_paiftx(struct snd_soc_codec *codec)
  158. {
  159. /* Add smdk64xx specific Capture widgets */
  160. snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt,
  161. ARRAY_SIZE(wm8580_dapm_widgets_cpt));
  162. /* Set up PAIFTX audio path */
  163. snd_soc_dapm_add_routes(codec, 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(codec, "MicIn");
  168. /* signal a DAPM event */
  169. snd_soc_dapm_sync(codec);
  170. return 0;
  171. }
  172. static int smdk64xx_wm8580_init_paifrx(struct snd_soc_codec *codec)
  173. {
  174. /* Add smdk64xx specific Playback widgets */
  175. snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk,
  176. ARRAY_SIZE(wm8580_dapm_widgets_pbk));
  177. /* Set up PAIFRX audio path */
  178. snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx));
  179. /* signal a DAPM event */
  180. snd_soc_dapm_sync(codec);
  181. return 0;
  182. }
  183. static struct snd_soc_dai_link smdk64xx_dai[] = {
  184. { /* Primary Playback i/f */
  185. .name = "WM8580 PAIF RX",
  186. .stream_name = "Playback",
  187. .cpu_dai = &s3c64xx_i2s_v4_dai,
  188. .codec_dai = &wm8580_dai[WM8580_DAI_PAIFRX],
  189. .init = smdk64xx_wm8580_init_paifrx,
  190. .ops = &smdk64xx_ops,
  191. },
  192. { /* Primary Capture i/f */
  193. .name = "WM8580 PAIF TX",
  194. .stream_name = "Capture",
  195. .cpu_dai = &s3c64xx_i2s_v4_dai,
  196. .codec_dai = &wm8580_dai[WM8580_DAI_PAIFTX],
  197. .init = smdk64xx_wm8580_init_paiftx,
  198. .ops = &smdk64xx_ops,
  199. },
  200. };
  201. static struct snd_soc_card smdk64xx = {
  202. .name = "smdk64xx",
  203. .platform = &s3c24xx_soc_platform,
  204. .dai_link = smdk64xx_dai,
  205. .num_links = ARRAY_SIZE(smdk64xx_dai),
  206. };
  207. static struct snd_soc_device smdk64xx_snd_devdata = {
  208. .card = &smdk64xx,
  209. .codec_dev = &soc_codec_dev_wm8580,
  210. };
  211. static struct platform_device *smdk64xx_snd_device;
  212. static int __init smdk64xx_audio_init(void)
  213. {
  214. int ret;
  215. smdk64xx_snd_device = platform_device_alloc("soc-audio", -1);
  216. if (!smdk64xx_snd_device)
  217. return -ENOMEM;
  218. platform_set_drvdata(smdk64xx_snd_device, &smdk64xx_snd_devdata);
  219. smdk64xx_snd_devdata.dev = &smdk64xx_snd_device->dev;
  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");