lowland.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Lowland 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/wm5100.h"
  17. #include "../codecs/wm9081.h"
  18. #define MCLK1_RATE (44100 * 512)
  19. #define CLKOUT_RATE (44100 * 256)
  20. static int lowland_hw_params(struct snd_pcm_substream *substream,
  21. struct snd_pcm_hw_params *params)
  22. {
  23. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  24. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  25. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  26. int ret;
  27. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  28. | SND_SOC_DAIFMT_NB_NF
  29. | SND_SOC_DAIFMT_CBM_CFM);
  30. if (ret < 0)
  31. return ret;
  32. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  33. | SND_SOC_DAIFMT_NB_NF
  34. | SND_SOC_DAIFMT_CBM_CFM);
  35. if (ret < 0)
  36. return ret;
  37. return 0;
  38. }
  39. static struct snd_soc_ops lowland_ops = {
  40. .hw_params = lowland_hw_params,
  41. };
  42. static struct snd_soc_jack lowland_headset;
  43. /* Headset jack detection DAPM pins */
  44. static struct snd_soc_jack_pin lowland_headset_pins[] = {
  45. {
  46. .pin = "Headphone",
  47. .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
  48. },
  49. {
  50. .pin = "Headset Mic",
  51. .mask = SND_JACK_MICROPHONE,
  52. },
  53. };
  54. static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
  55. {
  56. struct snd_soc_codec *codec = rtd->codec;
  57. int ret;
  58. ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_SYSCLK,
  59. WM5100_CLKSRC_MCLK1, MCLK1_RATE,
  60. SND_SOC_CLOCK_IN);
  61. if (ret < 0) {
  62. pr_err("Failed to set SYSCLK clock source: %d\n", ret);
  63. return ret;
  64. }
  65. /* Clock OPCLK, used by the other audio components. */
  66. ret = snd_soc_codec_set_sysclk(codec, WM5100_CLK_OPCLK, 0,
  67. CLKOUT_RATE, 0);
  68. if (ret < 0) {
  69. pr_err("Failed to set OPCLK rate: %d\n", ret);
  70. return ret;
  71. }
  72. ret = snd_soc_jack_new(codec, "Headset",
  73. SND_JACK_LINEOUT | SND_JACK_HEADSET |
  74. SND_JACK_BTN_0,
  75. &lowland_headset);
  76. if (ret)
  77. return ret;
  78. ret = snd_soc_jack_add_pins(&lowland_headset,
  79. ARRAY_SIZE(lowland_headset_pins),
  80. lowland_headset_pins);
  81. if (ret)
  82. return ret;
  83. wm5100_detect(codec, &lowland_headset);
  84. return 0;
  85. }
  86. static struct snd_soc_dai_link lowland_dai[] = {
  87. {
  88. .name = "CPU",
  89. .stream_name = "CPU",
  90. .cpu_dai_name = "samsung-i2s.0",
  91. .codec_dai_name = "wm5100-aif1",
  92. .platform_name = "samsung-audio",
  93. .codec_name = "wm5100.1-001a",
  94. .ops = &lowland_ops,
  95. .init = lowland_wm5100_init,
  96. },
  97. {
  98. .name = "Baseband",
  99. .stream_name = "Baseband",
  100. .cpu_dai_name = "wm5100-aif2",
  101. .codec_dai_name = "wm1250-ev1",
  102. .codec_name = "wm1250-ev1.1-0027",
  103. .ops = &lowland_ops,
  104. .ignore_suspend = 1,
  105. },
  106. };
  107. static int lowland_wm9081_init(struct snd_soc_dapm_context *dapm)
  108. {
  109. snd_soc_dapm_nc_pin(dapm, "LINEOUT");
  110. /* At any time the WM9081 is active it will have this clock */
  111. return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK, 0,
  112. CLKOUT_RATE, 0);
  113. }
  114. static struct snd_soc_aux_dev lowland_aux_dev[] = {
  115. {
  116. .name = "wm9081",
  117. .codec_name = "wm9081.1-006c",
  118. .init = lowland_wm9081_init,
  119. },
  120. };
  121. static struct snd_soc_codec_conf lowland_codec_conf[] = {
  122. {
  123. .dev_name = "wm9081.1-006c",
  124. .name_prefix = "Sub",
  125. },
  126. };
  127. static const struct snd_kcontrol_new controls[] = {
  128. SOC_DAPM_PIN_SWITCH("Main Speaker"),
  129. SOC_DAPM_PIN_SWITCH("Main DMIC"),
  130. SOC_DAPM_PIN_SWITCH("Main AMIC"),
  131. SOC_DAPM_PIN_SWITCH("WM1250 Input"),
  132. SOC_DAPM_PIN_SWITCH("WM1250 Output"),
  133. SOC_DAPM_PIN_SWITCH("Headphone"),
  134. };
  135. static struct snd_soc_dapm_widget widgets[] = {
  136. SND_SOC_DAPM_HP("Headphone", NULL),
  137. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  138. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  139. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  140. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  141. };
  142. static struct snd_soc_dapm_route audio_paths[] = {
  143. { "Sub IN1", NULL, "HPOUT2L" },
  144. { "Sub IN2", NULL, "HPOUT2R" },
  145. { "Main Speaker", NULL, "Sub SPKN" },
  146. { "Main Speaker", NULL, "Sub SPKP" },
  147. { "Main Speaker", NULL, "SPKDAT1" },
  148. };
  149. static struct snd_soc_card lowland = {
  150. .name = "Lowland",
  151. .owner = THIS_MODULE,
  152. .dai_link = lowland_dai,
  153. .num_links = ARRAY_SIZE(lowland_dai),
  154. .aux_dev = lowland_aux_dev,
  155. .num_aux_devs = ARRAY_SIZE(lowland_aux_dev),
  156. .codec_conf = lowland_codec_conf,
  157. .num_configs = ARRAY_SIZE(lowland_codec_conf),
  158. .controls = controls,
  159. .num_controls = ARRAY_SIZE(controls),
  160. .dapm_widgets = widgets,
  161. .num_dapm_widgets = ARRAY_SIZE(widgets),
  162. .dapm_routes = audio_paths,
  163. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  164. };
  165. static __devinit int lowland_probe(struct platform_device *pdev)
  166. {
  167. struct snd_soc_card *card = &lowland;
  168. int ret;
  169. card->dev = &pdev->dev;
  170. ret = snd_soc_register_card(card);
  171. if (ret) {
  172. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  173. ret);
  174. return ret;
  175. }
  176. return 0;
  177. }
  178. static int __devexit lowland_remove(struct platform_device *pdev)
  179. {
  180. struct snd_soc_card *card = platform_get_drvdata(pdev);
  181. snd_soc_unregister_card(card);
  182. return 0;
  183. }
  184. static struct platform_driver lowland_driver = {
  185. .driver = {
  186. .name = "lowland",
  187. .owner = THIS_MODULE,
  188. .pm = &snd_soc_pm_ops,
  189. },
  190. .probe = lowland_probe,
  191. .remove = __devexit_p(lowland_remove),
  192. };
  193. module_platform_driver(lowland_driver);
  194. MODULE_DESCRIPTION("Lowland audio support");
  195. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  196. MODULE_LICENSE("GPL");
  197. MODULE_ALIAS("platform:lowland");