lowland.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Lowland audio support
  4. //
  5. // Copyright 2011 Wolfson Microelectronics
  6. #include <sound/soc.h>
  7. #include <sound/soc-dapm.h>
  8. #include <sound/jack.h>
  9. #include <linux/gpio.h>
  10. #include <linux/module.h>
  11. #include "../codecs/wm5100.h"
  12. #include "../codecs/wm9081.h"
  13. #define MCLK1_RATE (44100 * 512)
  14. #define CLKOUT_RATE (44100 * 256)
  15. static struct snd_soc_jack lowland_headset;
  16. /* Headset jack detection DAPM pins */
  17. static struct snd_soc_jack_pin lowland_headset_pins[] = {
  18. {
  19. .pin = "Headphone",
  20. .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
  21. },
  22. {
  23. .pin = "Headset Mic",
  24. .mask = SND_JACK_MICROPHONE,
  25. },
  26. };
  27. static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
  28. {
  29. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  30. int ret;
  31. ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK,
  32. WM5100_CLKSRC_MCLK1, MCLK1_RATE,
  33. SND_SOC_CLOCK_IN);
  34. if (ret < 0) {
  35. pr_err("Failed to set SYSCLK clock source: %d\n", ret);
  36. return ret;
  37. }
  38. /* Clock OPCLK, used by the other audio components. */
  39. ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0,
  40. CLKOUT_RATE, 0);
  41. if (ret < 0) {
  42. pr_err("Failed to set OPCLK rate: %d\n", ret);
  43. return ret;
  44. }
  45. ret = snd_soc_card_jack_new_pins(rtd->card, "Headset",
  46. SND_JACK_LINEOUT | SND_JACK_HEADSET |
  47. SND_JACK_BTN_0,
  48. &lowland_headset, lowland_headset_pins,
  49. ARRAY_SIZE(lowland_headset_pins));
  50. if (ret)
  51. return ret;
  52. wm5100_detect(component, &lowland_headset);
  53. return 0;
  54. }
  55. static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
  56. {
  57. struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
  58. snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
  59. /* At any time the WM9081 is active it will have this clock */
  60. return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
  61. CLKOUT_RATE, 0);
  62. }
  63. static const struct snd_soc_pcm_stream sub_params = {
  64. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  65. .rate_min = 44100,
  66. .rate_max = 44100,
  67. .channels_min = 2,
  68. .channels_max = 2,
  69. };
  70. SND_SOC_DAILINK_DEFS(cpu,
  71. DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
  72. DAILINK_COMP_ARRAY(COMP_CODEC("wm5100.1-001a", "wm5100-aif1")),
  73. DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
  74. SND_SOC_DAILINK_DEFS(baseband,
  75. DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif2")),
  76. DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
  77. SND_SOC_DAILINK_DEFS(speaker,
  78. DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif3")),
  79. DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
  80. static struct snd_soc_dai_link lowland_dai[] = {
  81. {
  82. .name = "CPU",
  83. .stream_name = "CPU",
  84. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  85. SND_SOC_DAIFMT_CBM_CFM,
  86. .init = lowland_wm5100_init,
  87. SND_SOC_DAILINK_REG(cpu),
  88. },
  89. {
  90. .name = "Baseband",
  91. .stream_name = "Baseband",
  92. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  93. SND_SOC_DAIFMT_CBM_CFM,
  94. .ignore_suspend = 1,
  95. SND_SOC_DAILINK_REG(baseband),
  96. },
  97. {
  98. .name = "Sub Speaker",
  99. .stream_name = "Sub Speaker",
  100. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  101. SND_SOC_DAIFMT_CBM_CFM,
  102. .ignore_suspend = 1,
  103. .params = &sub_params,
  104. .init = lowland_wm9081_init,
  105. SND_SOC_DAILINK_REG(speaker),
  106. },
  107. };
  108. static struct snd_soc_codec_conf lowland_codec_conf[] = {
  109. {
  110. .dlc = COMP_CODEC_CONF("wm9081.1-006c"),
  111. .name_prefix = "Sub",
  112. },
  113. };
  114. static const struct snd_kcontrol_new controls[] = {
  115. SOC_DAPM_PIN_SWITCH("Main Speaker"),
  116. SOC_DAPM_PIN_SWITCH("Main DMIC"),
  117. SOC_DAPM_PIN_SWITCH("Main AMIC"),
  118. SOC_DAPM_PIN_SWITCH("WM1250 Input"),
  119. SOC_DAPM_PIN_SWITCH("WM1250 Output"),
  120. SOC_DAPM_PIN_SWITCH("Headphone"),
  121. };
  122. static const struct snd_soc_dapm_widget widgets[] = {
  123. SND_SOC_DAPM_HP("Headphone", NULL),
  124. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  125. SND_SOC_DAPM_SPK("Main Speaker", NULL),
  126. SND_SOC_DAPM_MIC("Main AMIC", NULL),
  127. SND_SOC_DAPM_MIC("Main DMIC", NULL),
  128. };
  129. static const struct snd_soc_dapm_route audio_paths[] = {
  130. { "Sub IN1", NULL, "HPOUT2L" },
  131. { "Sub IN2", NULL, "HPOUT2R" },
  132. { "Main Speaker", NULL, "Sub SPKN" },
  133. { "Main Speaker", NULL, "Sub SPKP" },
  134. { "Main Speaker", NULL, "SPKDAT1" },
  135. };
  136. static struct snd_soc_card lowland = {
  137. .name = "Lowland",
  138. .owner = THIS_MODULE,
  139. .dai_link = lowland_dai,
  140. .num_links = ARRAY_SIZE(lowland_dai),
  141. .codec_conf = lowland_codec_conf,
  142. .num_configs = ARRAY_SIZE(lowland_codec_conf),
  143. .controls = controls,
  144. .num_controls = ARRAY_SIZE(controls),
  145. .dapm_widgets = widgets,
  146. .num_dapm_widgets = ARRAY_SIZE(widgets),
  147. .dapm_routes = audio_paths,
  148. .num_dapm_routes = ARRAY_SIZE(audio_paths),
  149. };
  150. static int lowland_probe(struct platform_device *pdev)
  151. {
  152. struct snd_soc_card *card = &lowland;
  153. int ret;
  154. card->dev = &pdev->dev;
  155. ret = devm_snd_soc_register_card(&pdev->dev, card);
  156. if (ret)
  157. dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
  158. return ret;
  159. }
  160. static struct platform_driver lowland_driver = {
  161. .driver = {
  162. .name = "lowland",
  163. .pm = &snd_soc_pm_ops,
  164. },
  165. .probe = lowland_probe,
  166. };
  167. module_platform_driver(lowland_driver);
  168. MODULE_DESCRIPTION("Lowland audio support");
  169. MODULE_AUTHOR("Mark Brown <[email protected]>");
  170. MODULE_LICENSE("GPL");
  171. MODULE_ALIAS("platform:lowland");