common.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2018, Linaro Limited.
  3. // Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. #include <linux/module.h>
  5. #include "common.h"
  6. int qcom_snd_parse_of(struct snd_soc_card *card)
  7. {
  8. struct device_node *np;
  9. struct device_node *codec = NULL;
  10. struct device_node *platform = NULL;
  11. struct device_node *cpu = NULL;
  12. struct device *dev = card->dev;
  13. struct snd_soc_dai_link *link;
  14. int ret, num_links;
  15. ret = snd_soc_of_parse_card_name(card, "model");
  16. if (ret) {
  17. dev_err(dev, "Error parsing card name: %d\n", ret);
  18. return ret;
  19. }
  20. /* DAPM routes */
  21. if (of_property_read_bool(dev->of_node, "audio-routing")) {
  22. ret = snd_soc_of_parse_audio_routing(card,
  23. "audio-routing");
  24. if (ret)
  25. return ret;
  26. }
  27. /* Populate links */
  28. num_links = of_get_child_count(dev->of_node);
  29. /* Allocate the DAI link array */
  30. card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
  31. if (!card->dai_link)
  32. return -ENOMEM;
  33. card->num_links = num_links;
  34. link = card->dai_link;
  35. for_each_child_of_node(dev->of_node, np) {
  36. cpu = of_get_child_by_name(np, "cpu");
  37. if (!cpu) {
  38. dev_err(dev, "Can't find cpu DT node\n");
  39. ret = -EINVAL;
  40. goto err;
  41. }
  42. link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
  43. if (!link->cpu_of_node) {
  44. dev_err(card->dev, "error getting cpu phandle\n");
  45. ret = -EINVAL;
  46. goto err;
  47. }
  48. ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
  49. if (ret) {
  50. dev_err(card->dev, "error getting cpu dai name\n");
  51. goto err;
  52. }
  53. platform = of_get_child_by_name(np, "platform");
  54. codec = of_get_child_by_name(np, "codec");
  55. if (codec && platform) {
  56. link->platform_of_node = of_parse_phandle(platform,
  57. "sound-dai",
  58. 0);
  59. if (!link->platform_of_node) {
  60. dev_err(card->dev, "platform dai not found\n");
  61. ret = -EINVAL;
  62. goto err;
  63. }
  64. ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
  65. if (ret < 0) {
  66. dev_err(card->dev, "codec dai not found\n");
  67. goto err;
  68. }
  69. link->no_pcm = 1;
  70. link->ignore_pmdown_time = 1;
  71. } else {
  72. link->platform_of_node = link->cpu_of_node;
  73. link->codec_dai_name = "snd-soc-dummy-dai";
  74. link->codec_name = "snd-soc-dummy";
  75. link->dynamic = 1;
  76. }
  77. link->ignore_suspend = 1;
  78. ret = of_property_read_string(np, "link-name", &link->name);
  79. if (ret) {
  80. dev_err(card->dev, "error getting codec dai_link name\n");
  81. goto err;
  82. }
  83. link->dpcm_playback = 1;
  84. link->dpcm_capture = 1;
  85. link->stream_name = link->name;
  86. link++;
  87. }
  88. return 0;
  89. err:
  90. of_node_put(cpu);
  91. of_node_put(codec);
  92. of_node_put(platform);
  93. kfree(card->dai_link);
  94. return ret;
  95. }
  96. EXPORT_SYMBOL(qcom_snd_parse_of);
  97. MODULE_LICENSE("GPL v2");