smdk64xx_wm8580.c 6.6 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->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. 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. 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_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  108. pll_out, SND_SOC_CLOCK_IN);
  109. if (ret < 0)
  110. return ret;
  111. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
  112. if (ret < 0)
  113. return ret;
  114. ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
  115. if (ret < 0)
  116. return ret;
  117. return 0;
  118. }
  119. /*
  120. * SMDK64XX WM8580 DAI operations.
  121. */
  122. static struct snd_soc_ops smdk64xx_ops = {
  123. .hw_params = smdk64xx_hw_params,
  124. };
  125. /* SMDK64xx Playback widgets */
  126. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
  127. SND_SOC_DAPM_HP("Front", NULL),
  128. SND_SOC_DAPM_HP("Center+Sub", NULL),
  129. SND_SOC_DAPM_HP("Rear", NULL),
  130. };
  131. /* SMDK64xx Capture widgets */
  132. static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
  133. SND_SOC_DAPM_MIC("MicIn", NULL),
  134. SND_SOC_DAPM_LINE("LineIn", NULL),
  135. };
  136. /* SMDK-PAIFTX connections */
  137. static const struct snd_soc_dapm_route audio_map_tx[] = {
  138. /* MicIn feeds AINL */
  139. {"AINL", NULL, "MicIn"},
  140. /* LineIn feeds AINL/R */
  141. {"AINL", NULL, "LineIn"},
  142. {"AINR", NULL, "LineIn"},
  143. };
  144. /* SMDK-PAIFRX connections */
  145. static const struct snd_soc_dapm_route audio_map_rx[] = {
  146. /* Front Left/Right are fed VOUT1L/R */
  147. {"Front", NULL, "VOUT1L"},
  148. {"Front", NULL, "VOUT1R"},
  149. /* Center/Sub are fed VOUT2L/R */
  150. {"Center+Sub", NULL, "VOUT2L"},
  151. {"Center+Sub", NULL, "VOUT2R"},
  152. /* Rear Left/Right are fed VOUT3L/R */
  153. {"Rear", NULL, "VOUT3L"},
  154. {"Rear", NULL, "VOUT3R"},
  155. };
  156. static int smdk64xx_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  157. {
  158. struct snd_soc_codec *codec = rtd->codec;
  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_pcm_runtime *rtd)
  173. {
  174. struct snd_soc_codec *codec = rtd->codec;
  175. /* Add smdk64xx specific Playback widgets */
  176. snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk,
  177. ARRAY_SIZE(wm8580_dapm_widgets_pbk));
  178. /* Set up PAIFRX audio path */
  179. snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx));
  180. /* signal a DAPM event */
  181. snd_soc_dapm_sync(codec);
  182. return 0;
  183. }
  184. static struct snd_soc_dai_link smdk64xx_dai[] = {
  185. { /* Primary Playback i/f */
  186. .name = "WM8580 PAIF RX",
  187. .stream_name = "Playback",
  188. .cpu_dai_name = "s3c64xx-iis-v4",
  189. .codec_dai_name = "wm8580-hifi-playback",
  190. .platform_name = "s3c24xx-pcm-audio",
  191. .codec_name = "wm8580-codec.0-001b",
  192. .init = smdk64xx_wm8580_init_paifrx,
  193. .ops = &smdk64xx_ops,
  194. },
  195. { /* Primary Capture i/f */
  196. .name = "WM8580 PAIF TX",
  197. .stream_name = "Capture",
  198. .cpu_dai_name = "s3c64xx-iis-v4",
  199. .codec_dai_name = "wm8580-hifi-capture",
  200. .platform_name = "s3c24xx-pcm-audio",
  201. .codec_name = "wm8580-codec.0-001b",
  202. .init = smdk64xx_wm8580_init_paiftx,
  203. .ops = &smdk64xx_ops,
  204. },
  205. };
  206. static struct snd_soc_card smdk64xx = {
  207. .name = "SMDK64xx 5.1",
  208. .dai_link = smdk64xx_dai,
  209. .num_links = ARRAY_SIZE(smdk64xx_dai),
  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);
  219. ret = platform_device_add(smdk64xx_snd_device);
  220. if (ret)
  221. platform_device_put(smdk64xx_snd_device);
  222. return ret;
  223. }
  224. module_init(smdk64xx_audio_init);
  225. MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
  226. MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580");
  227. MODULE_LICENSE("GPL");