nocodec.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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
  7. //
  8. // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
  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, 2, 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 = &snd_soc_dummy_dlc;
  40. links[i].platforms = &dlc[1];
  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. if (drv[i].playback.channels_min)
  49. links[i].dpcm_playback = 1;
  50. if (drv[i].capture.channels_min)
  51. links[i].dpcm_capture = 1;
  52. links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup;
  53. }
  54. card->dai_link = links;
  55. card->num_links = link_num;
  56. return 0;
  57. }
  58. static int sof_nocodec_setup(struct device *dev,
  59. u32 num_dai_drivers,
  60. struct snd_soc_dai_driver *dai_drivers)
  61. {
  62. struct snd_soc_dai_link *links;
  63. /* create dummy BE dai_links */
  64. links = devm_kcalloc(dev, num_dai_drivers, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
  65. if (!links)
  66. return -ENOMEM;
  67. return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card);
  68. }
  69. static int sof_nocodec_probe(struct platform_device *pdev)
  70. {
  71. struct snd_soc_card *card = &sof_nocodec_card;
  72. struct snd_soc_acpi_mach *mach;
  73. int ret;
  74. card->dev = &pdev->dev;
  75. card->topology_shortname_created = true;
  76. mach = pdev->dev.platform_data;
  77. ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers,
  78. mach->mach_params.dai_drivers);
  79. if (ret < 0)
  80. return ret;
  81. return devm_snd_soc_register_card(&pdev->dev, card);
  82. }
  83. static struct platform_driver sof_nocodec_audio = {
  84. .probe = sof_nocodec_probe,
  85. .driver = {
  86. .name = "sof-nocodec",
  87. .pm = &snd_soc_pm_ops,
  88. },
  89. };
  90. module_platform_driver(sof_nocodec_audio)
  91. MODULE_LICENSE("Dual BSD/GPL");
  92. MODULE_DESCRIPTION("ASoC sof nocodec");
  93. MODULE_AUTHOR("Liam Girdwood");
  94. MODULE_ALIAS("platform:sof-nocodec");