mop500.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2012
  3. *
  4. * Author: Ola Lilja (ola.o.lilja@stericsson.com)
  5. * for ST-Ericsson.
  6. *
  7. * License terms:
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <asm/mach-types.h>
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <linux/spi/spi.h>
  17. #include <linux/of.h>
  18. #include <sound/soc.h>
  19. #include <sound/initval.h>
  20. #include "ux500_pcm.h"
  21. #include "ux500_msp_dai.h"
  22. #include "mop500_ab8500.h"
  23. /* Define the whole MOP500 soundcard, linking platform to the codec-drivers */
  24. struct snd_soc_dai_link mop500_dai_links[] = {
  25. {
  26. .name = "ab8500_0",
  27. .stream_name = "ab8500_0",
  28. .cpu_dai_name = "ux500-msp-i2s.1",
  29. .codec_dai_name = "ab8500-codec-dai.0",
  30. .platform_name = "ux500-msp-i2s.1",
  31. .codec_name = "ab8500-codec.0",
  32. .init = mop500_ab8500_machine_init,
  33. .ops = mop500_ab8500_ops,
  34. },
  35. {
  36. .name = "ab8500_1",
  37. .stream_name = "ab8500_1",
  38. .cpu_dai_name = "ux500-msp-i2s.3",
  39. .codec_dai_name = "ab8500-codec-dai.1",
  40. .platform_name = "ux500-msp-i2s.3",
  41. .codec_name = "ab8500-codec.0",
  42. .init = NULL,
  43. .ops = mop500_ab8500_ops,
  44. },
  45. };
  46. static struct snd_soc_card mop500_card = {
  47. .name = "MOP500-card",
  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. if (mop500_dai_links[i].cpu_of_node)
  57. of_node_put((struct device_node *)
  58. mop500_dai_links[i].cpu_of_node);
  59. if (mop500_dai_links[i].codec_of_node)
  60. of_node_put((struct device_node *)
  61. mop500_dai_links[i].codec_of_node);
  62. }
  63. }
  64. static int mop500_of_probe(struct platform_device *pdev,
  65. struct device_node *np)
  66. {
  67. struct device_node *codec_np, *msp_np[2];
  68. int i;
  69. msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
  70. msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
  71. codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0);
  72. if (!(msp_np[0] && msp_np[1] && codec_np)) {
  73. dev_err(&pdev->dev, "Phandle missing or invalid\n");
  74. mop500_of_node_put();
  75. return -EINVAL;
  76. }
  77. for (i = 0; i < 2; i++) {
  78. mop500_dai_links[i].cpu_of_node = msp_np[i];
  79. mop500_dai_links[i].cpu_dai_name = NULL;
  80. mop500_dai_links[i].codec_of_node = codec_np;
  81. mop500_dai_links[i].codec_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. platform_set_drvdata(pdev, &mop500_card);
  100. snd_soc_card_set_drvdata(&mop500_card, NULL);
  101. dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
  102. __func__, mop500_card.name, mop500_card.num_links);
  103. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
  104. __func__, mop500_card.name, mop500_card.dai_link[0].name);
  105. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
  106. __func__, mop500_card.name,
  107. mop500_card.dai_link[0].stream_name);
  108. ret = snd_soc_register_card(&mop500_card);
  109. if (ret)
  110. dev_err(&pdev->dev,
  111. "Error: snd_soc_register_card failed (%d)!\n", ret);
  112. return ret;
  113. }
  114. static int mop500_remove(struct platform_device *pdev)
  115. {
  116. struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
  117. pr_debug("%s: Enter.\n", __func__);
  118. snd_soc_unregister_card(mop500_card);
  119. mop500_ab8500_remove(mop500_card);
  120. mop500_of_node_put();
  121. return 0;
  122. }
  123. static const struct of_device_id snd_soc_mop500_match[] = {
  124. { .compatible = "stericsson,snd-soc-mop500", },
  125. {},
  126. };
  127. static struct platform_driver snd_soc_mop500_driver = {
  128. .driver = {
  129. .owner = THIS_MODULE,
  130. .name = "snd-soc-mop500",
  131. .of_match_table = snd_soc_mop500_match,
  132. },
  133. .probe = mop500_probe,
  134. .remove = mop500_remove,
  135. };
  136. module_platform_driver(snd_soc_mop500_driver);