goni_wm8994.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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/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 goni;
  29. static struct platform_device *goni_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 goni_dapm_widgets[] = {
  54. SND_SOC_DAPM_SPK("Ext Left Spk", NULL),
  55. SND_SOC_DAPM_SPK("Ext Right Spk", NULL),
  56. SND_SOC_DAPM_SPK("Ext Rcv", NULL),
  57. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  58. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  59. SND_SOC_DAPM_MIC("Main Mic", NULL),
  60. SND_SOC_DAPM_MIC("2nd Mic", NULL),
  61. SND_SOC_DAPM_LINE("Radio In", NULL),
  62. };
  63. static const struct snd_soc_dapm_route goni_dapm_routes[] = {
  64. {"Ext Left Spk", NULL, "SPKOUTLP"},
  65. {"Ext Left Spk", NULL, "SPKOUTLN"},
  66. {"Ext Right Spk", NULL, "SPKOUTRP"},
  67. {"Ext Right Spk", NULL, "SPKOUTRN"},
  68. {"Ext Rcv", NULL, "HPOUT2N"},
  69. {"Ext Rcv", NULL, "HPOUT2P"},
  70. {"Headset Stereophone", NULL, "HPOUT1L"},
  71. {"Headset Stereophone", NULL, "HPOUT1R"},
  72. {"IN1RN", NULL, "Headset Mic"},
  73. {"IN1RP", NULL, "Headset Mic"},
  74. {"IN1RN", NULL, "2nd Mic"},
  75. {"IN1RP", NULL, "2nd Mic"},
  76. {"IN1LN", NULL, "Main Mic"},
  77. {"IN1LP", NULL, "Main Mic"},
  78. {"IN2LN", NULL, "Radio In"},
  79. {"IN2RN", NULL, "Radio In"},
  80. };
  81. static int goni_wm8994_init(struct snd_soc_pcm_runtime *rtd)
  82. {
  83. struct snd_soc_codec *codec = rtd->codec;
  84. int ret;
  85. /* add goni specific widgets */
  86. snd_soc_dapm_new_controls(codec, goni_dapm_widgets,
  87. ARRAY_SIZE(goni_dapm_widgets));
  88. /* set up goni specific audio routes */
  89. snd_soc_dapm_add_routes(codec, goni_dapm_routes,
  90. ARRAY_SIZE(goni_dapm_routes));
  91. /* set endpoints to not connected */
  92. snd_soc_dapm_nc_pin(codec, "IN2LP:VXRN");
  93. snd_soc_dapm_nc_pin(codec, "IN2RP:VXRP");
  94. snd_soc_dapm_nc_pin(codec, "LINEOUT1N");
  95. snd_soc_dapm_nc_pin(codec, "LINEOUT1P");
  96. snd_soc_dapm_nc_pin(codec, "LINEOUT2N");
  97. snd_soc_dapm_nc_pin(codec, "LINEOUT2P");
  98. snd_soc_dapm_sync(codec);
  99. /* Headset jack detection */
  100. ret = snd_soc_jack_new(&goni, "Headset Jack",
  101. SND_JACK_HEADSET | SND_JACK_MECHANICAL | SND_JACK_AVOUT,
  102. &jack);
  103. if (ret)
  104. return ret;
  105. ret = snd_soc_jack_add_pins(&jack, ARRAY_SIZE(jack_pins), jack_pins);
  106. if (ret)
  107. return ret;
  108. ret = snd_soc_jack_add_gpios(&jack, ARRAY_SIZE(jack_gpios), jack_gpios);
  109. if (ret)
  110. return ret;
  111. return 0;
  112. }
  113. static int goni_hifi_hw_params(struct snd_pcm_substream *substream,
  114. struct snd_pcm_hw_params *params)
  115. {
  116. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  117. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  118. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  119. unsigned int pll_out = 24000000;
  120. int ret = 0;
  121. /* set the cpu DAI configuration */
  122. ret = snd_soc_dai_set_fmt(cpu_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 cpu system clock */
  127. ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
  128. 0, SND_SOC_CLOCK_IN);
  129. if (ret < 0)
  130. return ret;
  131. /* set codec DAI configuration */
  132. ret = snd_soc_dai_set_fmt(codec_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 the codec FLL */
  137. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
  138. params_rate(params) * 256);
  139. if (ret < 0)
  140. return ret;
  141. /* set the codec system clock */
  142. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
  143. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  144. if (ret < 0)
  145. return ret;
  146. return 0;
  147. }
  148. static struct snd_soc_ops goni_hifi_ops = {
  149. .hw_params = goni_hifi_hw_params,
  150. };
  151. static int goni_voice_hw_params(struct snd_pcm_substream *substream,
  152. struct snd_pcm_hw_params *params)
  153. {
  154. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  155. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  156. unsigned int pll_out = 24000000;
  157. int ret = 0;
  158. if (params_rate(params) != 8000)
  159. return -EINVAL;
  160. /* set codec DAI configuration */
  161. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
  162. SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
  163. if (ret < 0)
  164. return ret;
  165. /* set the codec FLL */
  166. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
  167. params_rate(params) * 256);
  168. if (ret < 0)
  169. return ret;
  170. /* set the codec system clock */
  171. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
  172. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  173. if (ret < 0)
  174. return ret;
  175. return 0;
  176. }
  177. static struct snd_soc_dai_driver voice_dai = {
  178. .name = "goni-voice-dai",
  179. .id = 0,
  180. .playback = {
  181. .channels_min = 1,
  182. .channels_max = 2,
  183. .rates = SNDRV_PCM_RATE_8000,
  184. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  185. .capture = {
  186. .channels_min = 1,
  187. .channels_max = 2,
  188. .rates = SNDRV_PCM_RATE_8000,
  189. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  190. };
  191. static struct snd_soc_ops goni_voice_ops = {
  192. .hw_params = goni_voice_hw_params,
  193. };
  194. static struct snd_soc_dai_link goni_dai[] = {
  195. {
  196. .name = "WM8994",
  197. .stream_name = "WM8994 HiFi",
  198. .cpu_dai_name = "s3c64xx-i2s-v4",
  199. .codec_dai_name = "wm8994-hifi",
  200. .platform_name = "s3c24xx-pcm-audio",
  201. .codec_name = "wm8994-codec.0-0x1a",
  202. .init = goni_wm8994_init,
  203. .ops = &goni_hifi_ops,
  204. }, {
  205. .name = "WM8994 Voice",
  206. .stream_name = "Voice",
  207. .cpu_dai_name = "goni-voice-dai",
  208. .codec_dai_name = "wm8994-voice",
  209. .platform_name = "s3c24xx-pcm-audio",
  210. .codec_name = "wm8994-codec.0-0x1a",
  211. .ops = &goni_voice_ops,
  212. },
  213. };
  214. static struct snd_soc_card goni = {
  215. .name = "goni",
  216. .dai_link = goni_dai,
  217. .num_links = ARRAY_SIZE(goni_dai),
  218. };
  219. static int __init goni_init(void)
  220. {
  221. int ret;
  222. 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. return ret;
  231. platform_set_drvdata(goni_snd_device, &goni);
  232. ret = platform_device_add(goni_snd_device);
  233. if (ret)
  234. platform_device_put(goni_snd_device);
  235. return ret;
  236. }
  237. static void __exit goni_exit(void)
  238. {
  239. platform_device_unregister(goni_snd_device);
  240. }
  241. module_init(goni_init);
  242. module_exit(goni_exit);
  243. /* Module information */
  244. MODULE_DESCRIPTION("ALSA SoC WM8994 GONI(S5PV210)");
  245. MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
  246. MODULE_LICENSE("GPL");