littlemill.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Littlemill audio support
  3. *
  4. * Copyright 2011 Wolfson Microelectronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include <sound/jack.h>
  14. #include <linux/gpio.h>
  15. #include <linux/module.h>
  16. #include "../codecs/wm8994.h"
  17. static int sample_rate = 44100;
  18. static int littlemill_set_bias_level(struct snd_soc_card *card,
  19. struct snd_soc_dapm_context *dapm,
  20. enum snd_soc_bias_level level)
  21. {
  22. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  23. int ret;
  24. if (dapm->dev != codec_dai->dev)
  25. return 0;
  26. switch (level) {
  27. case SND_SOC_BIAS_PREPARE:
  28. /*
  29. * If we've not already clocked things via hw_params()
  30. * then do so now, otherwise these are noops.
  31. */
  32. if (dapm->bias_level == SND_SOC_BIAS_STANDBY) {
  33. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
  34. WM8994_FLL_SRC_MCLK2, 32768,
  35. sample_rate * 512);
  36. if (ret < 0) {
  37. pr_err("Failed to start FLL: %d\n", ret);
  38. return ret;
  39. }
  40. ret = snd_soc_dai_set_sysclk(codec_dai,
  41. WM8994_SYSCLK_FLL1,
  42. sample_rate * 512,
  43. SND_SOC_CLOCK_IN);
  44. if (ret < 0) {
  45. pr_err("Failed to set SYSCLK: %d\n", ret);
  46. return ret;
  47. }
  48. }
  49. break;
  50. default:
  51. break;
  52. }
  53. return 0;
  54. }
  55. static int littlemill_set_bias_level_post(struct snd_soc_card *card,
  56. struct snd_soc_dapm_context *dapm,
  57. enum snd_soc_bias_level level)
  58. {
  59. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  60. int ret;
  61. if (dapm->dev != codec_dai->dev)
  62. return 0;
  63. switch (level) {
  64. case SND_SOC_BIAS_STANDBY:
  65. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2,
  66. 32768, SND_SOC_CLOCK_IN);
  67. if (ret < 0) {
  68. pr_err("Failed to switch away from FLL: %d\n", ret);
  69. return ret;
  70. }
  71. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
  72. 0, 0, 0);
  73. if (ret < 0) {
  74. pr_err("Failed to stop FLL: %d\n", ret);
  75. return ret;
  76. }
  77. break;
  78. default:
  79. break;
  80. }
  81. dapm->bias_level = level;
  82. return 0;
  83. }
  84. static int littlemill_hw_params(struct snd_pcm_substream *substream,
  85. struct snd_pcm_hw_params *params)
  86. {
  87. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  88. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  89. int ret;
  90. sample_rate = params_rate(params);
  91. ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1,
  92. WM8994_FLL_SRC_MCLK2, 32768,
  93. sample_rate * 512);
  94. if (ret < 0) {
  95. pr_err("Failed to start FLL: %d\n", ret);
  96. return ret;
  97. }
  98. ret = snd_soc_dai_set_sysclk(codec_dai,
  99. WM8994_SYSCLK_FLL1,
  100. sample_rate * 512,
  101. SND_SOC_CLOCK_IN);
  102. if (ret < 0) {
  103. pr_err("Failed to set SYSCLK: %d\n", ret);
  104. return ret;
  105. }
  106. return 0;
  107. }
  108. static struct snd_soc_ops littlemill_ops = {
  109. .hw_params = littlemill_hw_params,
  110. };
  111. static struct snd_soc_dai_link littlemill_dai[] = {
  112. {
  113. .name = "CPU",
  114. .stream_name = "CPU",
  115. .cpu_dai_name = "samsung-i2s.0",
  116. .codec_dai_name = "wm8994-aif1",
  117. .platform_name = "samsung-audio",
  118. .codec_name = "wm8994-codec",
  119. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
  120. | SND_SOC_DAIFMT_CBM_CFM,
  121. .ops = &littlemill_ops,
  122. },
  123. };
  124. static struct snd_soc_dapm_widget widgets[] = {
  125. SND_SOC_DAPM_HP("Headphone", NULL),
  126. SND_SOC_DAPM_MIC("AMIC", NULL),
  127. SND_SOC_DAPM_MIC("DMIC", NULL),
  128. };
  129. static struct snd_soc_dapm_route audio_paths[] = {
  130. { "Headphone", NULL, "HPOUT1L" },
  131. { "Headphone", NULL, "HPOUT1R" },
  132. { "AMIC", NULL, "MICBIAS1" }, /* Default for AMICBIAS jumper */
  133. { "IN1LN", NULL, "AMIC" },
  134. { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */
  135. { "DMIC1DAT", NULL, "DMIC" },
  136. { "DMIC2DAT", NULL, "DMIC" },
  137. };
  138. static struct snd_soc_jack littlemill_headset;
  139. static int littlemill_late_probe(struct snd_soc_card *card)
  140. {
  141. struct snd_soc_codec *codec = card->rtd[0].codec;
  142. struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
  143. int ret;
  144. ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2,
  145. 32768, SND_SOC_CLOCK_IN);
  146. if (ret < 0)
  147. return ret;
  148. ret = snd_soc_jack_new(codec, "Headset",
  149. SND_JACK_HEADSET | SND_JACK_MECHANICAL |
  150. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  151. SND_JACK_BTN_2 | SND_JACK_BTN_3 |
  152. SND_JACK_BTN_4 | SND_JACK_BTN_5,
  153. &littlemill_headset);
  154. if (ret)
  155. return ret;
  156. /* This will check device compatibility itself */
  157. wm8958_mic_detect(codec, &littlemill_headset, NULL, NULL);
  158. /* As will this */
  159. wm8994_mic_detect(codec, &littlemill_headset, 1);
  160. return 0;
  161. }
  162. static struct snd_soc_card littlemill = {
  163. .name = "Littlemill",
  164. .owner = THIS_MODULE,
  165. .dai_link = littlemill_dai,
  166. .num_links = ARRAY_SIZE(littlemill_dai),
  167. .set_bias_level = littlemill_set_bias_level,
  168. .set_bias_level_post = littlemill_set_bias_level_post,
  169. .dapm_widgets = widgets,
  170. .num_dapm_widgets = ARRAY_SIZE(widgets),
  171. .dapm_routes = audio_paths,
  172. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  173. .late_probe = littlemill_late_probe,
  174. };
  175. static __devinit int littlemill_probe(struct platform_device *pdev)
  176. {
  177. struct snd_soc_card *card = &littlemill;
  178. int ret;
  179. card->dev = &pdev->dev;
  180. ret = snd_soc_register_card(card);
  181. if (ret) {
  182. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  183. ret);
  184. return ret;
  185. }
  186. return 0;
  187. }
  188. static int __devexit littlemill_remove(struct platform_device *pdev)
  189. {
  190. struct snd_soc_card *card = platform_get_drvdata(pdev);
  191. snd_soc_unregister_card(card);
  192. return 0;
  193. }
  194. static struct platform_driver littlemill_driver = {
  195. .driver = {
  196. .name = "littlemill",
  197. .owner = THIS_MODULE,
  198. .pm = &snd_soc_pm_ops,
  199. },
  200. .probe = littlemill_probe,
  201. .remove = __devexit_p(littlemill_remove),
  202. };
  203. module_platform_driver(littlemill_driver);
  204. MODULE_DESCRIPTION("Littlemill audio support");
  205. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  206. MODULE_LICENSE("GPL");
  207. MODULE_ALIAS("platform:littlemill");