smdk_wm8580.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * smdk_wm8580.c
  3. *
  4. * Copyright (c) 2009 Samsung Electronics Co. Ltd
  5. * Author: Jaswinder Singh <jassisinghbrar@gmail.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/module.h>
  13. #include <sound/soc.h>
  14. #include <sound/pcm_params.h>
  15. #include <asm/mach-types.h>
  16. #include "../codecs/wm8580.h"
  17. #include "i2s.h"
  18. /*
  19. * Default CFG switch settings to use this driver:
  20. *
  21. * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
  22. */
  23. /* SMDK has a 12MHZ crystal attached to WM8580 */
  24. #define SMDK_WM8580_FREQ 12000000
  25. static int smdk_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->cpu_dai;
  30. struct snd_soc_dai *codec_dai = rtd->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. /* Set WM8580 to drive MCLK from its PLLA */
  86. ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
  87. WM8580_CLKSRC_PLLA);
  88. if (ret < 0)
  89. return ret;
  90. ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
  91. SMDK_WM8580_FREQ, pll_out);
  92. if (ret < 0)
  93. return ret;
  94. ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
  95. pll_out, SND_SOC_CLOCK_IN);
  96. if (ret < 0)
  97. return ret;
  98. return 0;
  99. }
  100. /*
  101. * SMDK WM8580 DAI operations.
  102. */
  103. static struct snd_soc_ops smdk_ops = {
  104. .hw_params = smdk_hw_params,
  105. };
  106. /* SMDK Playback widgets */
  107. static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
  108. SND_SOC_DAPM_HP("Front", NULL),
  109. SND_SOC_DAPM_HP("Center+Sub", NULL),
  110. SND_SOC_DAPM_HP("Rear", NULL),
  111. SND_SOC_DAPM_MIC("MicIn", NULL),
  112. SND_SOC_DAPM_LINE("LineIn", NULL),
  113. };
  114. /* SMDK-PAIFTX connections */
  115. static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
  116. /* MicIn feeds AINL */
  117. {"AINL", NULL, "MicIn"},
  118. /* LineIn feeds AINL/R */
  119. {"AINL", NULL, "LineIn"},
  120. {"AINR", NULL, "LineIn"},
  121. /* Front Left/Right are fed VOUT1L/R */
  122. {"Front", NULL, "VOUT1L"},
  123. {"Front", NULL, "VOUT1R"},
  124. /* Center/Sub are fed VOUT2L/R */
  125. {"Center+Sub", NULL, "VOUT2L"},
  126. {"Center+Sub", NULL, "VOUT2R"},
  127. /* Rear Left/Right are fed VOUT3L/R */
  128. {"Rear", NULL, "VOUT3L"},
  129. {"Rear", NULL, "VOUT3R"},
  130. };
  131. static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
  132. {
  133. struct snd_soc_codec *codec = rtd->codec;
  134. struct snd_soc_dapm_context *dapm = &codec->dapm;
  135. /* Enabling the microphone requires the fitting of a 0R
  136. * resistor to connect the line from the microphone jack.
  137. */
  138. snd_soc_dapm_disable_pin(dapm, "MicIn");
  139. return 0;
  140. }
  141. enum {
  142. PRI_PLAYBACK = 0,
  143. PRI_CAPTURE,
  144. SEC_PLAYBACK,
  145. };
  146. static struct snd_soc_dai_link smdk_dai[] = {
  147. [PRI_PLAYBACK] = { /* Primary Playback i/f */
  148. .name = "WM8580 PAIF RX",
  149. .stream_name = "Playback",
  150. .cpu_dai_name = "samsung-i2s.0",
  151. .codec_dai_name = "wm8580-hifi-playback",
  152. .platform_name = "samsung-audio",
  153. .codec_name = "wm8580.0-001b",
  154. .ops = &smdk_ops,
  155. },
  156. [PRI_CAPTURE] = { /* Primary Capture i/f */
  157. .name = "WM8580 PAIF TX",
  158. .stream_name = "Capture",
  159. .cpu_dai_name = "samsung-i2s.0",
  160. .codec_dai_name = "wm8580-hifi-capture",
  161. .platform_name = "samsung-audio",
  162. .codec_name = "wm8580.0-001b",
  163. .init = smdk_wm8580_init_paiftx,
  164. .ops = &smdk_ops,
  165. },
  166. [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
  167. .name = "Sec_FIFO TX",
  168. .stream_name = "Playback",
  169. .cpu_dai_name = "samsung-i2s.x",
  170. .codec_dai_name = "wm8580-hifi-playback",
  171. .platform_name = "samsung-audio",
  172. .codec_name = "wm8580.0-001b",
  173. .ops = &smdk_ops,
  174. },
  175. };
  176. static struct snd_soc_card smdk = {
  177. .name = "SMDK-I2S",
  178. .owner = THIS_MODULE,
  179. .dai_link = smdk_dai,
  180. .num_links = 2,
  181. .dapm_widgets = smdk_wm8580_dapm_widgets,
  182. .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
  183. .dapm_routes = smdk_wm8580_audio_map,
  184. .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
  185. };
  186. static struct platform_device *smdk_snd_device;
  187. static int __init smdk_audio_init(void)
  188. {
  189. int ret;
  190. char *str;
  191. if (machine_is_smdkc100()
  192. || machine_is_smdkv210() || machine_is_smdkc110()) {
  193. smdk.num_links = 3;
  194. /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
  195. str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
  196. str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
  197. } else if (machine_is_smdk6410()) {
  198. str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
  199. str[strlen(str) - 1] = '2';
  200. str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
  201. str[strlen(str) - 1] = '2';
  202. }
  203. smdk_snd_device = platform_device_alloc("soc-audio", -1);
  204. if (!smdk_snd_device)
  205. return -ENOMEM;
  206. platform_set_drvdata(smdk_snd_device, &smdk);
  207. ret = platform_device_add(smdk_snd_device);
  208. if (ret)
  209. platform_device_put(smdk_snd_device);
  210. return ret;
  211. }
  212. module_init(smdk_audio_init);
  213. static void __exit smdk_audio_exit(void)
  214. {
  215. platform_device_unregister(smdk_snd_device);
  216. }
  217. module_exit(smdk_audio_exit);
  218. MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
  219. MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
  220. MODULE_LICENSE("GPL");