aquila_wm8994.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * aquila_wm8994.c
  3. *
  4. * Copyright (C) 2010 Samsung Electronics Co.Ltd
  5. * Author: Chanwoo Choi <cw00.choi@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. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <sound/soc.h>
  18. #include <sound/soc-dapm.h>
  19. #include <sound/jack.h>
  20. #include <asm/mach-types.h>
  21. #include <mach/gpio.h>
  22. #include <mach/regs-clock.h>
  23. #include <linux/mfd/wm8994/core.h>
  24. #include <linux/mfd/wm8994/registers.h>
  25. #include "../codecs/wm8994.h"
  26. #include "s3c-dma.h"
  27. #include "s3c64xx-i2s.h"
  28. static struct snd_soc_card aquila;
  29. static struct platform_device *aquila_snd_device;
  30. /* 3.5 pie jack */
  31. static struct snd_soc_jack jack;
  32. /* 3.5 pie jack detection DAPM pins */
  33. static struct snd_soc_jack_pin jack_pins[] = {
  34. {
  35. .pin = "Headset Mic",
  36. .mask = SND_JACK_MICROPHONE,
  37. }, {
  38. .pin = "Headset Stereophone",
  39. .mask = SND_JACK_HEADPHONE | SND_JACK_MECHANICAL |
  40. SND_JACK_AVOUT,
  41. },
  42. };
  43. /* 3.5 pie jack detection gpios */
  44. static struct snd_soc_jack_gpio jack_gpios[] = {
  45. {
  46. .gpio = S5PV210_GPH0(6),
  47. .name = "DET_3.5",
  48. .report = SND_JACK_HEADSET | SND_JACK_MECHANICAL |
  49. SND_JACK_AVOUT,
  50. .debounce_time = 200,
  51. },
  52. };
  53. static const struct snd_soc_dapm_widget aquila_dapm_widgets[] = {
  54. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  55. SND_SOC_DAPM_SPK("Ext Rcv", NULL),
  56. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  57. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  58. SND_SOC_DAPM_MIC("Main Mic", NULL),
  59. SND_SOC_DAPM_MIC("2nd Mic", NULL),
  60. SND_SOC_DAPM_LINE("Radio In", NULL),
  61. };
  62. static const struct snd_soc_dapm_route aquila_dapm_routes[] = {
  63. {"Ext Spk", NULL, "SPKOUTLP"},
  64. {"Ext Spk", NULL, "SPKOUTLN"},
  65. {"Ext Rcv", NULL, "HPOUT2N"},
  66. {"Ext Rcv", NULL, "HPOUT2P"},
  67. {"Headset Stereophone", NULL, "HPOUT1L"},
  68. {"Headset Stereophone", NULL, "HPOUT1R"},
  69. {"IN1RN", NULL, "Headset Mic"},
  70. {"IN1RP", NULL, "Headset Mic"},
  71. {"IN1RN", NULL, "2nd Mic"},
  72. {"IN1RP", NULL, "2nd Mic"},
  73. {"IN1LN", NULL, "Main Mic"},
  74. {"IN1LP", NULL, "Main Mic"},
  75. {"IN2LN", NULL, "Radio In"},
  76. {"IN2RN", NULL, "Radio In"},
  77. };
  78. static int aquila_wm8994_init(struct snd_soc_pcm_runtime *rtd)
  79. {
  80. struct snd_soc_codec *codec = rtd->codec;
  81. int ret;
  82. /* add aquila specific widgets */
  83. snd_soc_dapm_new_controls(codec, aquila_dapm_widgets,
  84. ARRAY_SIZE(aquila_dapm_widgets));
  85. /* set up aquila specific audio routes */
  86. snd_soc_dapm_add_routes(codec, aquila_dapm_routes,
  87. ARRAY_SIZE(aquila_dapm_routes));
  88. /* set endpoints to not connected */
  89. snd_soc_dapm_nc_pin(codec, "IN2LP:VXRN");
  90. snd_soc_dapm_nc_pin(codec, "IN2RP:VXRP");
  91. snd_soc_dapm_nc_pin(codec, "LINEOUT1N");
  92. snd_soc_dapm_nc_pin(codec, "LINEOUT1P");
  93. snd_soc_dapm_nc_pin(codec, "LINEOUT2N");
  94. snd_soc_dapm_nc_pin(codec, "LINEOUT2P");
  95. snd_soc_dapm_nc_pin(codec, "SPKOUTRN");
  96. snd_soc_dapm_nc_pin(codec, "SPKOUTRP");
  97. snd_soc_dapm_sync(codec);
  98. /* Headset jack detection */
  99. ret = snd_soc_jack_new(&aquila, "Headset Jack",
  100. SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
  101. &jack);
  102. if (ret)
  103. return ret;
  104. ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
  105. if (ret)
  106. return ret;
  107. ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
  108. if (ret)
  109. return ret;
  110. return 0;
  111. }
  112. static int aquila_hifi_hw_params(struct snd_pcm_substream *substream,
  113. struct snd_pcm_hw_params *params)
  114. {
  115. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  116. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  117. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  118. unsigned int pll_out = 24000000;
  119. int ret = 0;
  120. /* set the cpu DAI configuration */
  121. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  122. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  123. if (ret < 0)
  124. return ret;
  125. /* set the cpu system clock */
  126. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
  127. 0, SND_SOC_CLOCK_IN);
  128. if (ret < 0)
  129. return ret;
  130. /* set codec DAI configuration */
  131. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  132. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  133. if (ret < 0)
  134. return ret;
  135. /* set the codec FLL */
  136. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
  137. params_rate(params) * 256);
  138. if (ret < 0)
  139. return ret;
  140. /* set the codec system clock */
  141. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  142. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  143. if (ret < 0)
  144. return ret;
  145. return 0;
  146. }
  147. static struct snd_soc_ops aquila_hifi_ops = {
  148. .hw_params = aquila_hifi_hw_params,
  149. };
  150. static int aquila_voice_hw_params(struct snd_pcm_substream *substream,
  151. struct snd_pcm_hw_params *params)
  152. {
  153. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  154. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  155. unsigned int pll_out = 24000000;
  156. int ret = 0;
  157. if (params_rate(params) != 8000)
  158. return -EINVAL;
  159. /* set codec DAI configuration */
  160. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
  161. SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
  162. if (ret < 0)
  163. return ret;
  164. /* set the codec FLL */
  165. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
  166. params_rate(params) * 256);
  167. if (ret < 0)
  168. return ret;
  169. /* set the codec system clock */
  170. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
  171. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  172. if (ret < 0)
  173. return ret;
  174. return 0;
  175. }
  176. static struct snd_soc_dai_driver voice_dai = {
  177. .name = "aquila-voice-dai",
  178. .playback = {
  179. .channels_min = 1,
  180. .channels_max = 2,
  181. .rates = SNDRV_PCM_RATE_8000,
  182. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  183. .capture = {
  184. .channels_min = 1,
  185. .channels_max = 2,
  186. .rates = SNDRV_PCM_RATE_8000,
  187. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  188. };
  189. static struct snd_soc_ops aquila_voice_ops = {
  190. .hw_params = aquila_voice_hw_params,
  191. };
  192. static struct snd_soc_dai_link aquila_dai[] = {
  193. {
  194. .name = "WM8994",
  195. .stream_name = "WM8994 HiFi",
  196. .cpu_dai_name = "s3c64xx-i2s-v4",
  197. .codec_dai_name = "wm8994-hifi",
  198. .platform_name = "s3c24xx-pcm-audio",
  199. .codec_name = "wm8994-codec.0-0x1a",
  200. .init = aquila_wm8994_init,
  201. .ops = &aquila_hifi_ops,
  202. }, {
  203. .name = "WM8994 Voice",
  204. .stream_name = "Voice",
  205. .cpu_dai_name = "aquila-voice-dai",
  206. .codec_dai_name = "wm8994-voice",
  207. .platform_name = "s3c24xx-pcm-audio",
  208. .codec_name = "wm8994-codec.0-0x1a",
  209. .ops = &aquila_voice_ops,
  210. },
  211. };
  212. static struct snd_soc_card aquila = {
  213. .name = "aquila",
  214. .dai_link = aquila_dai,
  215. .num_links = ARRAY_SIZE(aquila_dai),
  216. };
  217. static int __init aquila_init(void)
  218. {
  219. int ret;
  220. if (!machine_is_aquila())
  221. return -ENODEV;
  222. aquila_snd_device = platform_device_alloc("soc-audio", -1);
  223. if (!aquila_snd_device)
  224. return -ENOMEM;
  225. /* register voice DAI here */
  226. ret = snd_soc_register_dai(&aquila_snd_device->dev, &voice_dai);
  227. if (ret)
  228. return ret;
  229. platform_set_drvdata(aquila_snd_device, &aquila);
  230. ret = platform_device_add(aquila_snd_device);
  231. if (ret)
  232. platform_device_put(aquila_snd_device);
  233. return ret;
  234. }
  235. static void __exit aquila_exit(void)
  236. {
  237. platform_device_unregister(aquila_snd_device);
  238. }
  239. module_init(aquila_init);
  240. module_exit(aquila_exit);
  241. /* Module information */
  242. MODULE_DESCRIPTION("ALSA SoC WM8994 Aquila(S5PC110)");
  243. MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
  244. MODULE_LICENSE("GPL");