smdk64xx_wm8580.c 6.6 KB

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