lowland.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
  51. SND_JACK_HEADSET | SND_JACK_BTN_0,
  52. &lowland_headset, lowland_headset_pins,
  53. ARRAY_SIZE(lowland_headset_pins));
  54. if (ret)
  55. return ret;
  56. wm5100_detect(codec, &lowland_headset);
  57. return 0;
  58. }
  59. static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
  60. {
  61. struct snd_soc_codec *codec = rtd->codec;
  62. snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
  63. /* At any time the WM9081 is active it will have this clock */
  64. return snd_soc_codec_set_sysclk(codec, WM9081_SYSCLK_MCLK, 0,
  65. CLKOUT_RATE, 0);
  66. }
  67. static const struct snd_soc_pcm_stream sub_params = {
  68. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  69. .rate_min = 44100,
  70. .rate_max = 44100,
  71. .channels_min = 2,
  72. .channels_max = 2,
  73. };
  74. static struct snd_soc_dai_link lowland_dai[] = {
  75. {
  76. .name = "CPU",
  77. .stream_name = "CPU",
  78. .cpu_dai_name = "samsung-i2s.0",
  79. .codec_dai_name = "wm5100-aif1",
  80. .platform_name = "samsung-i2s.0",
  81. .codec_name = "wm5100.1-001a",
  82. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  83. SND_SOC_DAIFMT_CBM_CFM,
  84. .init = lowland_wm5100_init,
  85. },
  86. {
  87. .name = "Baseband",
  88. .stream_name = "Baseband",
  89. .cpu_dai_name = "wm5100-aif2",
  90. .codec_dai_name = "wm1250-ev1",
  91. .codec_name = "wm1250-ev1.1-0027",
  92. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  93. SND_SOC_DAIFMT_CBM_CFM,
  94. .ignore_suspend = 1,
  95. },
  96. {
  97. .name = "Sub Speaker",
  98. .stream_name = "Sub Speaker",
  99. .cpu_dai_name = "wm5100-aif3",
  100. .codec_dai_name = "wm9081-hifi",
  101. .codec_name = "wm9081.1-006c",
  102. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  103. SND_SOC_DAIFMT_CBM_CFM,
  104. .ignore_suspend = 1,
  105. .params = &sub_params,
  106. .init = lowland_wm9081_init,
  107. },
  108. };
  109. static struct snd_soc_codec_conf lowland_codec_conf[] = {
  110. {
  111. .dev_name = "wm9081.1-006c",
  112. .name_prefix = "Sub",
  113. },
  114. };
  115. static const struct snd_kcontrol_new controls[] = {
  116. SOC_DAPM_PIN_SWITCH("Main Speaker"),
  117. SOC_DAPM_PIN_SWITCH("Main DMIC"),
  118. SOC_DAPM_PIN_SWITCH("Main AMIC"),
  119. SOC_DAPM_PIN_SWITCH("WM1250 Input"),
  120. SOC_DAPM_PIN_SWITCH("WM1250 Output"),
  121. SOC_DAPM_PIN_SWITCH("Headphone"),
  122. };
  123. static struct snd_soc_dapm_widget widgets[] = {
  124. SND_SOC_DAPM_HP("Headphone", NULL),
  125. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  126. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  127. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  128. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  129. };
  130. static struct snd_soc_dapm_route audio_paths[] = {
  131. { "Sub IN1", NULL, "HPOUT2L" },
  132. { "Sub IN2", NULL, "HPOUT2R" },
  133. { "Main Speaker", NULL, "Sub SPKN" },
  134. { "Main Speaker", NULL, "Sub SPKP" },
  135. { "Main Speaker", NULL, "SPKDAT1" },
  136. };
  137. static struct snd_soc_card lowland = {
  138. .name = "Lowland",
  139. .owner = THIS_MODULE,
  140. .dai_link = lowland_dai,
  141. .num_links = ARRAY_SIZE(lowland_dai),
  142. .codec_conf = lowland_codec_conf,
  143. .num_configs = ARRAY_SIZE(lowland_codec_conf),
  144. .controls = controls,
  145. .num_controls = ARRAY_SIZE(controls),
  146. .dapm_widgets = widgets,
  147. .num_dapm_widgets = ARRAY_SIZE(widgets),
  148. .dapm_routes = audio_paths,
  149. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  150. };
  151. static int lowland_probe(struct platform_device *pdev)
  152. {
  153. struct snd_soc_card *card = &lowland;
  154. int ret;
  155. card->dev = &pdev->dev;
  156. ret = devm_snd_soc_register_card(&pdev->dev, card);
  157. if (ret)
  158. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  159. ret);
  160. return ret;
  161. }
  162. static struct platform_driver lowland_driver = {
  163. .driver = {
  164. .name = "lowland",
  165. .pm = &snd_soc_pm_ops,
  166. },
  167. .probe = lowland_probe,
  168. };
  169. module_platform_driver(lowland_driver);
  170. MODULE_DESCRIPTION("Lowland audio support");
  171. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  172. MODULE_LICENSE("GPL");
  173. MODULE_ALIAS("platform:lowland");