mop500.c 3.7 KB

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