dmic.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
  4. //
  5. // Authors: Cezary Rojewski <[email protected]>
  6. // Amadeusz Slawinski <[email protected]>
  7. //
  8. #include <linux/device.h>
  9. #include <linux/module.h>
  10. #include <sound/soc.h>
  11. #include <sound/soc-acpi.h>
  12. SND_SOC_DAILINK_DEF(dmic_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
  13. SND_SOC_DAILINK_DEF(dmic_wov_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC WoV Pin")));
  14. SND_SOC_DAILINK_DEF(dmic_codec, DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
  15. /* Name overridden on probe */
  16. SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("")));
  17. static struct snd_soc_dai_link card_dai_links[] = {
  18. /* Back ends */
  19. {
  20. .name = "DMIC",
  21. .id = 0,
  22. .dpcm_capture = 1,
  23. .nonatomic = 1,
  24. .no_pcm = 1,
  25. SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
  26. },
  27. {
  28. .name = "DMIC WoV",
  29. .id = 1,
  30. .dpcm_capture = 1,
  31. .nonatomic = 1,
  32. .no_pcm = 1,
  33. .ignore_suspend = 1,
  34. SND_SOC_DAILINK_REG(dmic_wov_pin, dmic_codec, platform),
  35. },
  36. };
  37. static const struct snd_soc_dapm_widget card_widgets[] = {
  38. SND_SOC_DAPM_MIC("SoC DMIC", NULL),
  39. };
  40. static const struct snd_soc_dapm_route card_routes[] = {
  41. {"DMic", NULL, "SoC DMIC"},
  42. {"DMIC Rx", NULL, "Capture"},
  43. {"DMIC WoV Rx", NULL, "Capture"},
  44. };
  45. static int avs_dmic_probe(struct platform_device *pdev)
  46. {
  47. struct snd_soc_acpi_mach *mach;
  48. struct snd_soc_card *card;
  49. struct device *dev = &pdev->dev;
  50. int ret;
  51. mach = dev_get_platdata(dev);
  52. card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
  53. if (!card)
  54. return -ENOMEM;
  55. card->name = "avs_dmic";
  56. card->dev = dev;
  57. card->owner = THIS_MODULE;
  58. card->dai_link = card_dai_links;
  59. card->num_links = ARRAY_SIZE(card_dai_links);
  60. card->dapm_widgets = card_widgets;
  61. card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
  62. card->dapm_routes = card_routes;
  63. card->num_dapm_routes = ARRAY_SIZE(card_routes);
  64. card->fully_routed = true;
  65. ret = snd_soc_fixup_dai_links_platform_name(card, mach->mach_params.platform);
  66. if (ret)
  67. return ret;
  68. return devm_snd_soc_register_card(dev, card);
  69. }
  70. static struct platform_driver avs_dmic_driver = {
  71. .probe = avs_dmic_probe,
  72. .driver = {
  73. .name = "avs_dmic",
  74. .pm = &snd_soc_pm_ops,
  75. },
  76. };
  77. module_platform_driver(avs_dmic_driver);
  78. MODULE_LICENSE("GPL");
  79. MODULE_ALIAS("platform:avs_dmic");