nocodec.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <liam.r.girdwood@linux.intel.com>
  9. //
  10. #include <linux/module.h>
  11. #include <sound/sof.h>
  12. #include "sof-priv.h"
  13. static struct snd_soc_card sof_nocodec_card = {
  14. .name = "nocodec", /* the sof- prefix is added by the core */
  15. .owner = THIS_MODULE
  16. };
  17. static int sof_nocodec_bes_setup(struct device *dev,
  18. const struct snd_sof_dsp_ops *ops,
  19. struct snd_soc_dai_link *links,
  20. int link_num, struct snd_soc_card *card)
  21. {
  22. struct snd_soc_dai_link_component *dlc;
  23. int i;
  24. if (!ops || !links || !card)
  25. return -EINVAL;
  26. /* set up BE dai_links */
  27. for (i = 0; i < link_num; i++) {
  28. dlc = devm_kzalloc(dev, 3 * sizeof(*dlc), GFP_KERNEL);
  29. if (!dlc)
  30. return -ENOMEM;
  31. links[i].name = devm_kasprintf(dev, GFP_KERNEL,
  32. "NoCodec-%d", i);
  33. if (!links[i].name)
  34. return -ENOMEM;
  35. links[i].cpus = &dlc[0];
  36. links[i].codecs = &dlc[1];
  37. links[i].platforms = &dlc[2];
  38. links[i].num_cpus = 1;
  39. links[i].num_codecs = 1;
  40. links[i].num_platforms = 1;
  41. links[i].id = i;
  42. links[i].no_pcm = 1;
  43. links[i].cpus->dai_name = ops->drv[i].name;
  44. links[i].platforms->name = dev_name(dev);
  45. links[i].codecs->dai_name = "snd-soc-dummy-dai";
  46. links[i].codecs->name = "snd-soc-dummy";
  47. if (ops->drv[i].playback.channels_min)
  48. links[i].dpcm_playback = 1;
  49. if (ops->drv[i].capture.channels_min)
  50. links[i].dpcm_capture = 1;
  51. }
  52. card->dai_link = links;
  53. card->num_links = link_num;
  54. return 0;
  55. }
  56. int sof_nocodec_setup(struct device *dev,
  57. const struct snd_sof_dsp_ops *ops)
  58. {
  59. struct snd_soc_dai_link *links;
  60. /* create dummy BE dai_links */
  61. links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
  62. ops->num_drv, GFP_KERNEL);
  63. if (!links)
  64. return -ENOMEM;
  65. return sof_nocodec_bes_setup(dev, ops, links, ops->num_drv,
  66. &sof_nocodec_card);
  67. }
  68. EXPORT_SYMBOL(sof_nocodec_setup);
  69. static int sof_nocodec_probe(struct platform_device *pdev)
  70. {
  71. struct snd_soc_card *card = &sof_nocodec_card;
  72. card->dev = &pdev->dev;
  73. return devm_snd_soc_register_card(&pdev->dev, card);
  74. }
  75. static int sof_nocodec_remove(struct platform_device *pdev)
  76. {
  77. return 0;
  78. }
  79. static struct platform_driver sof_nocodec_audio = {
  80. .probe = sof_nocodec_probe,
  81. .remove = sof_nocodec_remove,
  82. .driver = {
  83. .name = "sof-nocodec",
  84. .pm = &snd_soc_pm_ops,
  85. },
  86. };
  87. module_platform_driver(sof_nocodec_audio)
  88. MODULE_DESCRIPTION("ASoC sof nocodec");
  89. MODULE_AUTHOR("Liam Girdwood");
  90. MODULE_LICENSE("Dual BSD/GPL");
  91. MODULE_ALIAS("platform:sof-nocodec");