lowland.c 5.3 KB

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