skl_hda_dsp_generic.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright(c) 2015-18 Intel Corporation.
  3. /*
  4. * Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs
  5. */
  6. #include <linux/module.h>
  7. #include <linux/platform_device.h>
  8. #include <sound/core.h>
  9. #include <sound/jack.h>
  10. #include <sound/pcm.h>
  11. #include <sound/pcm_params.h>
  12. #include <sound/soc.h>
  13. #include "../../codecs/hdac_hdmi.h"
  14. #include "../skylake/skl.h"
  15. #include "skl_hda_dsp_common.h"
  16. static const struct snd_soc_dapm_widget skl_hda_widgets[] = {
  17. SND_SOC_DAPM_HP("Analog Out", NULL),
  18. SND_SOC_DAPM_MIC("Analog In", NULL),
  19. SND_SOC_DAPM_HP("Alt Analog Out", NULL),
  20. SND_SOC_DAPM_MIC("Alt Analog In", NULL),
  21. SND_SOC_DAPM_SPK("Digital Out", NULL),
  22. SND_SOC_DAPM_MIC("Digital In", NULL),
  23. };
  24. static const struct snd_soc_dapm_route skl_hda_map[] = {
  25. { "hifi3", NULL, "iDisp3 Tx"},
  26. { "iDisp3 Tx", NULL, "iDisp3_out"},
  27. { "hifi2", NULL, "iDisp2 Tx"},
  28. { "iDisp2 Tx", NULL, "iDisp2_out"},
  29. { "hifi1", NULL, "iDisp1 Tx"},
  30. { "iDisp1 Tx", NULL, "iDisp1_out"},
  31. { "Analog Out", NULL, "Codec Output Pin1" },
  32. { "Digital Out", NULL, "Codec Output Pin2" },
  33. { "Alt Analog Out", NULL, "Codec Output Pin3" },
  34. { "Codec Input Pin1", NULL, "Analog In" },
  35. { "Codec Input Pin2", NULL, "Digital In" },
  36. { "Codec Input Pin3", NULL, "Alt Analog In" },
  37. /* CODEC BE connections */
  38. { "Analog Codec Playback", NULL, "Analog CPU Playback" },
  39. { "Analog CPU Playback", NULL, "codec0_out" },
  40. { "Digital Codec Playback", NULL, "Digital CPU Playback" },
  41. { "Digital CPU Playback", NULL, "codec1_out" },
  42. { "Alt Analog Codec Playback", NULL, "Alt Analog CPU Playback" },
  43. { "Alt Analog CPU Playback", NULL, "codec2_out" },
  44. { "codec0_in", NULL, "Analog CPU Capture" },
  45. { "Analog CPU Capture", NULL, "Analog Codec Capture" },
  46. { "codec1_in", NULL, "Digital CPU Capture" },
  47. { "Digital CPU Capture", NULL, "Digital Codec Capture" },
  48. { "codec2_in", NULL, "Alt Analog CPU Capture" },
  49. { "Alt Analog CPU Capture", NULL, "Alt Analog Codec Capture" },
  50. };
  51. static int skl_hda_card_late_probe(struct snd_soc_card *card)
  52. {
  53. return skl_hda_hdmi_jack_init(card);
  54. }
  55. static int
  56. skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link)
  57. {
  58. struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
  59. int ret = 0;
  60. dev_dbg(card->dev, "%s: dai link name - %s\n", __func__, link->name);
  61. link->platform_name = ctx->platform_name;
  62. link->nonatomic = 1;
  63. if (strstr(link->name, "HDMI")) {
  64. ret = skl_hda_hdmi_add_pcm(card, ctx->pcm_count);
  65. if (ret < 0)
  66. return ret;
  67. ctx->dai_index++;
  68. }
  69. ctx->pcm_count++;
  70. return ret;
  71. }
  72. static struct snd_soc_card hda_soc_card = {
  73. .name = "skl_hda_card",
  74. .owner = THIS_MODULE,
  75. .dai_link = skl_hda_be_dai_links,
  76. .dapm_widgets = skl_hda_widgets,
  77. .dapm_routes = skl_hda_map,
  78. .add_dai_link = skl_hda_add_dai_link,
  79. .fully_routed = true,
  80. .late_probe = skl_hda_card_late_probe,
  81. };
  82. #define IDISP_DAI_COUNT 3
  83. /* there are two routes per iDisp output */
  84. #define IDISP_ROUTE_COUNT (IDISP_DAI_COUNT * 2)
  85. #define IDISP_CODEC_MASK 0x4
  86. static int skl_hda_fill_card_info(struct skl_machine_pdata *pdata)
  87. {
  88. struct snd_soc_card *card = &hda_soc_card;
  89. struct snd_soc_dai_link *dai_link;
  90. u32 codec_count, codec_mask;
  91. int i, num_links, num_route;
  92. codec_mask = pdata->codec_mask;
  93. codec_count = hweight_long(codec_mask);
  94. if (codec_count == 1 && pdata->codec_mask & IDISP_CODEC_MASK) {
  95. num_links = IDISP_DAI_COUNT;
  96. num_route = IDISP_ROUTE_COUNT;
  97. } else if (codec_count == 2 && codec_mask & IDISP_CODEC_MASK) {
  98. num_links = ARRAY_SIZE(skl_hda_be_dai_links);
  99. num_route = ARRAY_SIZE(skl_hda_map),
  100. card->dapm_widgets = skl_hda_widgets;
  101. card->num_dapm_widgets = ARRAY_SIZE(skl_hda_widgets);
  102. } else {
  103. return -EINVAL;
  104. }
  105. card->num_links = num_links;
  106. card->num_dapm_routes = num_route;
  107. for_each_card_prelinks(card, i, dai_link)
  108. dai_link->platform_name = pdata->platform;
  109. return 0;
  110. }
  111. static int skl_hda_audio_probe(struct platform_device *pdev)
  112. {
  113. struct skl_machine_pdata *pdata;
  114. struct skl_hda_private *ctx;
  115. int ret;
  116. dev_dbg(&pdev->dev, "%s: entry\n", __func__);
  117. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
  118. if (!ctx)
  119. return -ENOMEM;
  120. INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
  121. pdata = dev_get_drvdata(&pdev->dev);
  122. if (!pdata)
  123. return -EINVAL;
  124. ret = skl_hda_fill_card_info(pdata);
  125. if (ret < 0) {
  126. dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n");
  127. return ret;
  128. }
  129. ctx->pcm_count = hda_soc_card.num_links;
  130. ctx->dai_index = 1; /* hdmi codec dai name starts from index 1 */
  131. ctx->platform_name = pdata->platform;
  132. hda_soc_card.dev = &pdev->dev;
  133. snd_soc_card_set_drvdata(&hda_soc_card, ctx);
  134. return devm_snd_soc_register_card(&pdev->dev, &hda_soc_card);
  135. }
  136. static struct platform_driver skl_hda_audio = {
  137. .probe = skl_hda_audio_probe,
  138. .driver = {
  139. .name = "skl_hda_dsp_generic",
  140. .pm = &snd_soc_pm_ops,
  141. },
  142. };
  143. module_platform_driver(skl_hda_audio)
  144. /* Module information */
  145. MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
  146. MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
  147. MODULE_LICENSE("GPL v2");
  148. MODULE_ALIAS("platform:skl_hda_dsp_generic");