pcm030-audio-fabric.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Phytec pcm030 driver for the PSC of the Freescale MPC52xx
  3. * configured as AC97 interface
  4. *
  5. * Copyright 2008 Jon Smirl, Digispeaker
  6. * Author: Jon Smirl <jonsmirl@gmail.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of any
  10. * kind, whether express or implied.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/device.h>
  15. #include <linux/of_device.h>
  16. #include <linux/of_platform.h>
  17. #include <sound/soc.h>
  18. #include "mpc5200_dma.h"
  19. #define DRV_NAME "pcm030-audio-fabric"
  20. struct pcm030_audio_data {
  21. struct snd_soc_card *card;
  22. struct platform_device *codec_device;
  23. };
  24. static struct snd_soc_dai_link pcm030_fabric_dai[] = {
  25. {
  26. .name = "AC97.0",
  27. .stream_name = "AC97 Analog",
  28. .codec_dai_name = "wm9712-hifi",
  29. .cpu_dai_name = "mpc5200-psc-ac97.0",
  30. .codec_name = "wm9712-codec",
  31. },
  32. {
  33. .name = "AC97.1",
  34. .stream_name = "AC97 IEC958",
  35. .codec_dai_name = "wm9712-aux",
  36. .cpu_dai_name = "mpc5200-psc-ac97.1",
  37. .codec_name = "wm9712-codec",
  38. },
  39. };
  40. static struct snd_soc_card pcm030_card = {
  41. .name = "pcm030",
  42. .owner = THIS_MODULE,
  43. .dai_link = pcm030_fabric_dai,
  44. .num_links = ARRAY_SIZE(pcm030_fabric_dai),
  45. };
  46. static int pcm030_fabric_probe(struct platform_device *op)
  47. {
  48. struct device_node *np = op->dev.of_node;
  49. struct device_node *platform_np;
  50. struct snd_soc_card *card = &pcm030_card;
  51. struct pcm030_audio_data *pdata;
  52. int ret;
  53. int i;
  54. if (!of_machine_is_compatible("phytec,pcm030"))
  55. return -ENODEV;
  56. pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data),
  57. GFP_KERNEL);
  58. if (!pdata)
  59. return -ENOMEM;
  60. card->dev = &op->dev;
  61. pdata->card = card;
  62. platform_np = of_parse_phandle(np, "asoc-platform", 0);
  63. if (!platform_np) {
  64. dev_err(&op->dev, "ac97 not registered\n");
  65. return -ENODEV;
  66. }
  67. for (i = 0; i < card->num_links; i++)
  68. card->dai_link[i].platform_of_node = platform_np;
  69. ret = request_module("snd-soc-wm9712");
  70. if (ret)
  71. dev_err(&op->dev, "request_module returned: %d\n", ret);
  72. pdata->codec_device = platform_device_alloc("wm9712-codec", -1);
  73. if (!pdata->codec_device)
  74. dev_err(&op->dev, "platform_device_alloc() failed\n");
  75. ret = platform_device_add(pdata->codec_device);
  76. if (ret)
  77. dev_err(&op->dev, "platform_device_add() failed: %d\n", ret);
  78. ret = snd_soc_register_card(card);
  79. if (ret)
  80. dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret);
  81. platform_set_drvdata(op, pdata);
  82. return ret;
  83. }
  84. static int pcm030_fabric_remove(struct platform_device *op)
  85. {
  86. struct pcm030_audio_data *pdata = platform_get_drvdata(op);
  87. int ret;
  88. ret = snd_soc_unregister_card(pdata->card);
  89. platform_device_unregister(pdata->codec_device);
  90. return ret;
  91. }
  92. static const struct of_device_id pcm030_audio_match[] = {
  93. { .compatible = "phytec,pcm030-audio-fabric", },
  94. {}
  95. };
  96. MODULE_DEVICE_TABLE(of, pcm030_audio_match);
  97. static struct platform_driver pcm030_fabric_driver = {
  98. .probe = pcm030_fabric_probe,
  99. .remove = pcm030_fabric_remove,
  100. .driver = {
  101. .name = DRV_NAME,
  102. .of_match_table = pcm030_audio_match,
  103. },
  104. };
  105. module_platform_driver(pcm030_fabric_driver);
  106. MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>");
  107. MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver");
  108. MODULE_LICENSE("GPL");