mop500.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2012
  4. *
  5. * Author: Ola Lilja ([email protected])
  6. * for ST-Ericsson.
  7. */
  8. #include <asm/mach-types.h>
  9. #include <linux/module.h>
  10. #include <linux/io.h>
  11. #include <linux/spi/spi.h>
  12. #include <linux/of.h>
  13. #include <sound/soc.h>
  14. #include <sound/initval.h>
  15. #include "ux500_pcm.h"
  16. #include "ux500_msp_dai.h"
  17. #include "mop500_ab8500.h"
  18. /* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
  19. SND_SOC_DAILINK_DEFS(link1,
  20. DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.1")),
  21. DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.0")),
  22. DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.1")));
  23. SND_SOC_DAILINK_DEFS(link2,
  24. DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.3")),
  25. DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.1")),
  26. DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.3")));
  27. static struct snd_soc_dai_link mop500_dai_links[] = {
  28. {
  29. .name = "ab8500_0",
  30. .stream_name = "ab8500_0",
  31. .init = mop500_ab8500_machine_init,
  32. .ops = mop500_ab8500_ops,
  33. SND_SOC_DAILINK_REG(link1),
  34. },
  35. {
  36. .name = "ab8500_1",
  37. .stream_name = "ab8500_1",
  38. .init = NULL,
  39. .ops = mop500_ab8500_ops,
  40. SND_SOC_DAILINK_REG(link2),
  41. },
  42. };
  43. static struct snd_soc_card mop500_card = {
  44. .name = "MOP500-card",
  45. .owner = THIS_MODULE,
  46. .probe = NULL,
  47. .dai_link = mop500_dai_links,
  48. .num_links = ARRAY_SIZE(mop500_dai_links),
  49. };
  50. static void mop500_of_node_put(void)
  51. {
  52. int i;
  53. for (i = 0; i < 2; i++)
  54. of_node_put(mop500_dai_links[i].cpus->of_node);
  55. /* Both links use the same codec, which is refcounted only once */
  56. of_node_put(mop500_dai_links[0].codecs->of_node);
  57. }
  58. static int mop500_of_probe(struct platform_device *pdev,
  59. struct device_node *np)
  60. {
  61. struct device_node *codec_np, *msp_np[2];
  62. int i;
  63. msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
  64. msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
  65. codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0);
  66. if (!(msp_np[0] && msp_np[1] && codec_np)) {
  67. dev_err(&pdev->dev, "Phandle missing or invalid\n");
  68. for (i = 0; i < 2; i++)
  69. of_node_put(msp_np[i]);
  70. of_node_put(codec_np);
  71. return -EINVAL;
  72. }
  73. for (i = 0; i < 2; i++) {
  74. mop500_dai_links[i].cpus->of_node = msp_np[i];
  75. mop500_dai_links[i].cpus->dai_name = NULL;
  76. mop500_dai_links[i].platforms->of_node = msp_np[i];
  77. mop500_dai_links[i].platforms->name = NULL;
  78. mop500_dai_links[i].codecs->of_node = codec_np;
  79. mop500_dai_links[i].codecs->name = NULL;
  80. }
  81. snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
  82. return 0;
  83. }
  84. static int mop500_probe(struct platform_device *pdev)
  85. {
  86. struct device_node *np = pdev->dev.of_node;
  87. int ret;
  88. dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
  89. mop500_card.dev = &pdev->dev;
  90. if (np) {
  91. ret = mop500_of_probe(pdev, np);
  92. if (ret)
  93. return ret;
  94. }
  95. dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
  96. __func__, mop500_card.name);
  97. snd_soc_card_set_drvdata(&mop500_card, NULL);
  98. dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
  99. __func__, mop500_card.name, mop500_card.num_links);
  100. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
  101. __func__, mop500_card.name, mop500_card.dai_link[0].name);
  102. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
  103. __func__, mop500_card.name,
  104. mop500_card.dai_link[0].stream_name);
  105. ret = snd_soc_register_card(&mop500_card);
  106. if (ret)
  107. dev_err(&pdev->dev,
  108. "Error: snd_soc_register_card failed (%d)!\n", ret);
  109. return ret;
  110. }
  111. static int mop500_remove(struct platform_device *pdev)
  112. {
  113. struct snd_soc_card *card = platform_get_drvdata(pdev);
  114. pr_debug("%s: Enter.\n", __func__);
  115. snd_soc_unregister_card(card);
  116. mop500_ab8500_remove(card);
  117. mop500_of_node_put();
  118. return 0;
  119. }
  120. static const struct of_device_id snd_soc_mop500_match[] = {
  121. { .compatible = "stericsson,snd-soc-mop500", },
  122. {},
  123. };
  124. MODULE_DEVICE_TABLE(of, snd_soc_mop500_match);
  125. static struct platform_driver snd_soc_mop500_driver = {
  126. .driver = {
  127. .name = "snd-soc-mop500",
  128. .of_match_table = snd_soc_mop500_match,
  129. },
  130. .probe = mop500_probe,
  131. .remove = mop500_remove,
  132. };
  133. module_platform_driver(snd_soc_mop500_driver);
  134. MODULE_LICENSE("GPL v2");
  135. MODULE_DESCRIPTION("ASoC MOP500 board driver");
  136. MODULE_AUTHOR("Ola Lilja");