common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. struct of_phandle_args args;
  15. int ret, num_links;
  16. ret = snd_soc_of_parse_card_name(card, "model");
  17. if (ret) {
  18. dev_err(dev, "Error parsing card name: %d\n", ret);
  19. return ret;
  20. }
  21. /* DAPM routes */
  22. if (of_property_read_bool(dev->of_node, "audio-routing")) {
  23. ret = snd_soc_of_parse_audio_routing(card,
  24. "audio-routing");
  25. if (ret)
  26. return ret;
  27. }
  28. /* Populate links */
  29. num_links = of_get_child_count(dev->of_node);
  30. /* Allocate the DAI link array */
  31. card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
  32. if (!card->dai_link)
  33. return -ENOMEM;
  34. card->num_links = num_links;
  35. link = card->dai_link;
  36. for_each_child_of_node(dev->of_node, np) {
  37. cpu = of_get_child_by_name(np, "cpu");
  38. platform = of_get_child_by_name(np, "platform");
  39. codec = of_get_child_by_name(np, "codec");
  40. if (!cpu) {
  41. dev_err(dev, "Can't find cpu DT node\n");
  42. ret = -EINVAL;
  43. goto err;
  44. }
  45. ret = of_parse_phandle_with_args(cpu, "sound-dai",
  46. "#sound-dai-cells", 0, &args);
  47. if (ret) {
  48. dev_err(card->dev, "error getting cpu phandle\n");
  49. goto err;
  50. }
  51. link->cpu_of_node = args.np;
  52. link->id = args.args[0];
  53. ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
  54. if (ret) {
  55. dev_err(card->dev, "error getting cpu dai name\n");
  56. goto err;
  57. }
  58. if (codec && platform) {
  59. link->platform_of_node = of_parse_phandle(platform,
  60. "sound-dai",
  61. 0);
  62. if (!link->platform_of_node) {
  63. dev_err(card->dev, "platform dai not found\n");
  64. ret = -EINVAL;
  65. goto err;
  66. }
  67. ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
  68. if (ret < 0) {
  69. dev_err(card->dev, "codec dai not found\n");
  70. goto err;
  71. }
  72. link->no_pcm = 1;
  73. link->ignore_pmdown_time = 1;
  74. } else {
  75. link->platform_of_node = link->cpu_of_node;
  76. link->codec_dai_name = "snd-soc-dummy-dai";
  77. link->codec_name = "snd-soc-dummy";
  78. link->dynamic = 1;
  79. }
  80. link->ignore_suspend = 1;
  81. ret = of_property_read_string(np, "link-name", &link->name);
  82. if (ret) {
  83. dev_err(card->dev, "error getting codec dai_link name\n");
  84. goto err;
  85. }
  86. link->dpcm_playback = 1;
  87. link->dpcm_capture = 1;
  88. link->stream_name = link->name;
  89. link++;
  90. of_node_put(cpu);
  91. of_node_put(codec);
  92. of_node_put(platform);
  93. }
  94. return 0;
  95. err:
  96. of_node_put(np);
  97. of_node_put(cpu);
  98. of_node_put(codec);
  99. of_node_put(platform);
  100. kfree(card->dai_link);
  101. return ret;
  102. }
  103. EXPORT_SYMBOL(qcom_snd_parse_of);
  104. MODULE_LICENSE("GPL v2");