goni_wm8994.c 7.3 KB

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