goni_wm8994.c 7.7 KB

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