mop500.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. static 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. .owner = THIS_MODULE,
  49. .probe = NULL,
  50. .dai_link = mop500_dai_links,
  51. .num_links = ARRAY_SIZE(mop500_dai_links),
  52. };
  53. static void mop500_of_node_put(void)
  54. {
  55. int i;
  56. for (i = 0; i < 2; i++) {
  57. if (mop500_dai_links[i].cpu_of_node)
  58. of_node_put((struct device_node *)
  59. mop500_dai_links[i].cpu_of_node);
  60. if (mop500_dai_links[i].codec_of_node)
  61. of_node_put((struct device_node *)
  62. mop500_dai_links[i].codec_of_node);
  63. }
  64. }
  65. static int mop500_of_probe(struct platform_device *pdev,
  66. struct device_node *np)
  67. {
  68. struct device_node *codec_np, *msp_np[2];
  69. int i;
  70. msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
  71. msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
  72. codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0);
  73. if (!(msp_np[0] && msp_np[1] && codec_np)) {
  74. dev_err(&pdev->dev, "Phandle missing or invalid\n");
  75. mop500_of_node_put();
  76. return -EINVAL;
  77. }
  78. for (i = 0; i < 2; i++) {
  79. mop500_dai_links[i].cpu_of_node = msp_np[i];
  80. mop500_dai_links[i].cpu_dai_name = NULL;
  81. mop500_dai_links[i].codec_of_node = codec_np;
  82. mop500_dai_links[i].codec_name = NULL;
  83. }
  84. snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
  85. return 0;
  86. }
  87. static int mop500_probe(struct platform_device *pdev)
  88. {
  89. struct device_node *np = pdev->dev.of_node;
  90. int ret;
  91. dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
  92. mop500_card.dev = &pdev->dev;
  93. if (np) {
  94. ret = mop500_of_probe(pdev, np);
  95. if (ret)
  96. return ret;
  97. }
  98. dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
  99. __func__, mop500_card.name);
  100. platform_set_drvdata(pdev, &mop500_card);
  101. snd_soc_card_set_drvdata(&mop500_card, NULL);
  102. dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
  103. __func__, mop500_card.name, mop500_card.num_links);
  104. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
  105. __func__, mop500_card.name, mop500_card.dai_link[0].name);
  106. dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
  107. __func__, mop500_card.name,
  108. mop500_card.dai_link[0].stream_name);
  109. ret = snd_soc_register_card(&mop500_card);
  110. if (ret)
  111. dev_err(&pdev->dev,
  112. "Error: snd_soc_register_card failed (%d)!\n", ret);
  113. return ret;
  114. }
  115. static int mop500_remove(struct platform_device *pdev)
  116. {
  117. struct snd_soc_card *mop500_card = platform_get_drvdata(pdev);
  118. pr_debug("%s: Enter.\n", __func__);
  119. snd_soc_unregister_card(mop500_card);
  120. mop500_ab8500_remove(mop500_card);
  121. mop500_of_node_put();
  122. return 0;
  123. }
  124. static const struct of_device_id snd_soc_mop500_match[] = {
  125. { .compatible = "stericsson,snd-soc-mop500", },
  126. {},
  127. };
  128. static struct platform_driver snd_soc_mop500_driver = {
  129. .driver = {
  130. .owner = THIS_MODULE,
  131. .name = "snd-soc-mop500",
  132. .of_match_table = snd_soc_mop500_match,
  133. },
  134. .probe = mop500_probe,
  135. .remove = mop500_remove,
  136. };
  137. module_platform_driver(snd_soc_mop500_driver);