smdk64xx_wm8580.c 6.6 KB

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