mop500.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. of_node_put(mop500_dai_links[i].cpu_of_node);
  58. of_node_put(mop500_dai_links[i].codec_of_node);
  59. }
  60. }
  61. static int mop500_of_probe(struct platform_device *pdev,
  62. struct device_node *np)
  63. {
  64. struct device_node *codec_np, *msp_np[2];
  65. int i;
  66. msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
  67. msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
  68. codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0);
  69. if (!(msp_np[0] && msp_np[1] && codec_np)) {
  70. dev_err(&pdev->dev, "Phandle missing or invalid\n");
  71. mop500_of_node_put();
  72. return -EINVAL;
  73. }
  74. for (i = 0; i < 2; i++) {
  75. mop500_dai_links[i].cpu_of_node = msp_np[i];
  76. mop500_dai_links[i].cpu_dai_name = NULL;
  77. mop500_dai_links[i].platform_of_node = msp_np[i];
  78. mop500_dai_links[i].platform_name = NULL;
  79. mop500_dai_links[i].codec_of_node = codec_np;
  80. mop500_dai_links[i].codec_name = NULL;
  81. }
  82. snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
  83. return 0;
  84. }
  85. static int mop500_probe(struct platform_device *pdev)
  86. {
  87. struct device_node *np = pdev->dev.of_node;
  88. int ret;
  89. dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
  90. mop500_card.dev = &pdev->dev;
  91. if (np) {
  92. ret = mop500_of_probe(pdev, np);
  93. if (ret)
  94. return ret;
  95. }
  96. dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
  97. __func__, mop500_card.name);
  98. platform_set_drvdata(pdev, &mop500_card);
  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");