nocodec.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2018 Intel Corporation. All rights reserved.
  7. //
  8. // Author: Liam Girdwood <[email protected]>
  9. //
  10. #include <linux/module.h>
  11. #include <sound/sof.h>
  12. #include "sof-audio.h"
  13. #include "sof-priv.h"
  14. static struct snd_soc_card sof_nocodec_card = {
  15. .name = "nocodec", /* the sof- prefix is added by the core */
  16. .topology_shortname = "sof-nocodec",
  17. .owner = THIS_MODULE
  18. };
  19. static int sof_nocodec_bes_setup(struct device *dev,
  20. struct snd_soc_dai_driver *drv,
  21. struct snd_soc_dai_link *links,
  22. int link_num, struct snd_soc_card *card)
  23. {
  24. struct snd_soc_dai_link_component *dlc;
  25. int i;
  26. if (!drv || !links || !card)
  27. return -EINVAL;
  28. /* set up BE dai_links */
  29. for (i = 0; i < link_num; i++) {
  30. dlc = devm_kcalloc(dev, 3, sizeof(*dlc), GFP_KERNEL);
  31. if (!dlc)
  32. return -ENOMEM;
  33. links[i].name = devm_kasprintf(dev, GFP_KERNEL,
  34. "NoCodec-%d", i);
  35. if (!links[i].name)
  36. return -ENOMEM;
  37. links[i].stream_name = links[i].name;
  38. links[i].cpus = &dlc[0];
  39. links[i].codecs = &dlc[1];
  40. links[i].platforms = &dlc[2];
  41. links[i].num_cpus = 1;
  42. links[i].num_codecs = 1;
  43. links[i].num_platforms = 1;
  44. links[i].id = i;
  45. links[i].no_pcm = 1;
  46. links[i].cpus->dai_name = drv[i].name;
  47. links[i].platforms->name = dev_name(dev->parent);
  48. links[i].codecs->dai_name = "snd-soc-dummy-dai";
  49. links[i].codecs->name = "snd-soc-dummy";
  50. if (drv[i].playback.channels_min)
  51. links[i].dpcm_playback = 1;
  52. if (drv[i].capture.channels_min)
  53. links[i].dpcm_capture = 1;
  54. links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup;
  55. }
  56. card->dai_link = links;
  57. card->num_links = link_num;
  58. return 0;
  59. }
  60. static int sof_nocodec_setup(struct device *dev,
  61. u32 num_dai_drivers,
  62. struct snd_soc_dai_driver *dai_drivers)
  63. {
  64. struct snd_soc_dai_link *links;
  65. /* create dummy BE dai_links */
  66. links = devm_kcalloc(dev, num_dai_drivers, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
  67. if (!links)
  68. return -ENOMEM;
  69. return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card);
  70. }
  71. static int sof_nocodec_probe(struct platform_device *pdev)
  72. {
  73. struct snd_soc_card *card = &sof_nocodec_card;
  74. struct snd_soc_acpi_mach *mach;
  75. int ret;
  76. card->dev = &pdev->dev;
  77. card->topology_shortname_created = true;
  78. mach = pdev->dev.platform_data;
  79. ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers,
  80. mach->mach_params.dai_drivers);
  81. if (ret < 0)
  82. return ret;
  83. return devm_snd_soc_register_card(&pdev->dev, card);
  84. }
  85. static int sof_nocodec_remove(struct platform_device *pdev)
  86. {
  87. return 0;
  88. }
  89. static struct platform_driver sof_nocodec_audio = {
  90. .probe = sof_nocodec_probe,
  91. .remove = sof_nocodec_remove,
  92. .driver = {
  93. .name = "sof-nocodec",
  94. .pm = &snd_soc_pm_ops,
  95. },
  96. };
  97. module_platform_driver(sof_nocodec_audio)
  98. MODULE_DESCRIPTION("ASoC sof nocodec");
  99. MODULE_AUTHOR("Liam Girdwood");
  100. MODULE_LICENSE("Dual BSD/GPL");
  101. MODULE_ALIAS("platform:sof-nocodec");