mop500.c 4.3 KB

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