goni_wm8994.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. /* set endpoints to not connected */
  83. snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
  84. snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
  85. snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
  86. snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
  87. snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
  88. snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
  89. if (machine_is_aquila()) {
  90. snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
  91. snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
  92. }
  93. /* Headset jack detection */
  94. ret = snd_soc_jack_new(codec, "Headset Jack",
  95. SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
  96. &jack);
  97. if (ret)
  98. return ret;
  99. ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
  100. if (ret)
  101. return ret;
  102. ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
  103. if (ret)
  104. return ret;
  105. return 0;
  106. }
  107. static int goni_hifi_hw_params(struct snd_pcm_substream *substream,
  108. struct snd_pcm_hw_params *params)
  109. {
  110. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  111. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  112. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  113. unsigned int pll_out = 24000000;
  114. int ret = 0;
  115. /* set the cpu DAI configuration */
  116. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  117. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  118. if (ret < 0)
  119. return ret;
  120. /* set codec DAI configuration */
  121. ret = snd_soc_dai_set_fmt(codec_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 codec FLL */
  126. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
  127. params_rate(params) * 256);
  128. if (ret < 0)
  129. return ret;
  130. /* set the codec system clock */
  131. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  132. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  133. if (ret < 0)
  134. return ret;
  135. return 0;
  136. }
  137. static struct snd_soc_ops goni_hifi_ops = {
  138. .hw_params = goni_hifi_hw_params,
  139. };
  140. static int goni_voice_hw_params(struct snd_pcm_substream *substream,
  141. struct snd_pcm_hw_params *params)
  142. {
  143. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  144. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  145. unsigned int pll_out = 24000000;
  146. int ret = 0;
  147. if (params_rate(params) != 8000)
  148. return -EINVAL;
  149. /* set codec DAI configuration */
  150. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
  151. SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
  152. if (ret < 0)
  153. return ret;
  154. /* set the codec FLL */
  155. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
  156. params_rate(params) * 256);
  157. if (ret < 0)
  158. return ret;
  159. /* set the codec system clock */
  160. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
  161. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  162. if (ret < 0)
  163. return ret;
  164. return 0;
  165. }
  166. static struct snd_soc_dai_driver voice_dai = {
  167. .name = "goni-voice-dai",
  168. .id = 0,
  169. .playback = {
  170. .channels_min = 1,
  171. .channels_max = 2,
  172. .rates = SNDRV_PCM_RATE_8000,
  173. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  174. .capture = {
  175. .channels_min = 1,
  176. .channels_max = 2,
  177. .rates = SNDRV_PCM_RATE_8000,
  178. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  179. };
  180. static struct snd_soc_ops goni_voice_ops = {
  181. .hw_params = goni_voice_hw_params,
  182. };
  183. static struct snd_soc_dai_link goni_dai[] = {
  184. {
  185. .name = "WM8994",
  186. .stream_name = "WM8994 HiFi",
  187. .cpu_dai_name = "samsung-i2s.0",
  188. .codec_dai_name = "wm8994-aif1",
  189. .platform_name = "samsung-audio",
  190. .codec_name = "wm8994-codec.0-001a",
  191. .init = goni_wm8994_init,
  192. .ops = &goni_hifi_ops,
  193. }, {
  194. .name = "WM8994 Voice",
  195. .stream_name = "Voice",
  196. .cpu_dai_name = "goni-voice-dai",
  197. .codec_dai_name = "wm8994-aif2",
  198. .codec_name = "wm8994-codec.0-001a",
  199. .ops = &goni_voice_ops,
  200. },
  201. };
  202. static struct snd_soc_card goni = {
  203. .name = "goni",
  204. .dai_link = goni_dai,
  205. .num_links = ARRAY_SIZE(goni_dai),
  206. .dapm_widgets = goni_dapm_widgets,
  207. .num_dapm_widgets = ARRAY_SIZE(goni_dapm_widgets),
  208. .dapm_routes = goni_dapm_routes,
  209. .num_dapm_routes = ARRAY_SIZE(goni_dapm_routes),
  210. };
  211. static int __init goni_init(void)
  212. {
  213. int ret;
  214. if (machine_is_aquila()) {
  215. voice_dai.name = aquila_str[CPU_VOICE_DAI];
  216. goni_dai[1].cpu_dai_name = aquila_str[CPU_VOICE_DAI];
  217. goni.name = aquila_str[MACHINE_NAME];
  218. } else if (!machine_is_goni())
  219. return -ENODEV;
  220. goni_snd_device = platform_device_alloc("soc-audio", -1);
  221. if (!goni_snd_device)
  222. return -ENOMEM;
  223. /* register voice DAI here */
  224. ret = snd_soc_register_dai(&goni_snd_device->dev, &voice_dai);
  225. if (ret) {
  226. platform_device_put(goni_snd_device);
  227. return ret;
  228. }
  229. platform_set_drvdata(goni_snd_device, &goni);
  230. ret = platform_device_add(goni_snd_device);
  231. if (ret) {
  232. snd_soc_unregister_dai(&goni_snd_device->dev);
  233. platform_device_put(goni_snd_device);
  234. }
  235. return ret;
  236. }
  237. static void __exit goni_exit(void)
  238. {
  239. snd_soc_unregister_dai(&goni_snd_device->dev);
  240. platform_device_unregister(goni_snd_device);
  241. }
  242. module_init(goni_init);
  243. module_exit(goni_exit);
  244. /* Module information */
  245. MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
  246. MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
  247. MODULE_LICENSE("GPL");