goni_wm8994.c 7.4 KB

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