imx-spdif.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2013 Freescale Semiconductor, Inc.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. */
  11. #include <linux/module.h>
  12. #include <linux/of_platform.h>
  13. #include <sound/soc.h>
  14. struct imx_spdif_data {
  15. struct snd_soc_dai_link dai;
  16. struct snd_soc_card card;
  17. };
  18. static int imx_spdif_audio_probe(struct platform_device *pdev)
  19. {
  20. struct device_node *spdif_np, *np = pdev->dev.of_node;
  21. struct imx_spdif_data *data;
  22. int ret = 0;
  23. spdif_np = of_parse_phandle(np, "spdif-controller", 0);
  24. if (!spdif_np) {
  25. dev_err(&pdev->dev, "failed to find spdif-controller\n");
  26. ret = -EINVAL;
  27. goto end;
  28. }
  29. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  30. if (!data) {
  31. ret = -ENOMEM;
  32. goto end;
  33. }
  34. data->dai.name = "S/PDIF PCM";
  35. data->dai.stream_name = "S/PDIF PCM";
  36. data->dai.codec_dai_name = "snd-soc-dummy-dai";
  37. data->dai.codec_name = "snd-soc-dummy";
  38. data->dai.cpu_of_node = spdif_np;
  39. data->dai.platform_of_node = spdif_np;
  40. data->dai.playback_only = true;
  41. data->dai.capture_only = true;
  42. if (of_property_read_bool(np, "spdif-out"))
  43. data->dai.capture_only = false;
  44. if (of_property_read_bool(np, "spdif-in"))
  45. data->dai.playback_only = false;
  46. if (data->dai.playback_only && data->dai.capture_only) {
  47. dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
  48. goto end;
  49. }
  50. data->card.dev = &pdev->dev;
  51. data->card.dai_link = &data->dai;
  52. data->card.num_links = 1;
  53. data->card.owner = THIS_MODULE;
  54. ret = snd_soc_of_parse_card_name(&data->card, "model");
  55. if (ret)
  56. goto end;
  57. ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
  58. if (ret) {
  59. dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
  60. goto end;
  61. }
  62. end:
  63. of_node_put(spdif_np);
  64. return ret;
  65. }
  66. static const struct of_device_id imx_spdif_dt_ids[] = {
  67. { .compatible = "fsl,imx-audio-spdif", },
  68. { /* sentinel */ }
  69. };
  70. MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
  71. static struct platform_driver imx_spdif_driver = {
  72. .driver = {
  73. .name = "imx-spdif",
  74. .pm = &snd_soc_pm_ops,
  75. .of_match_table = imx_spdif_dt_ids,
  76. },
  77. .probe = imx_spdif_audio_probe,
  78. };
  79. module_platform_driver(imx_spdif_driver);
  80. MODULE_AUTHOR("Freescale Semiconductor, Inc.");
  81. MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
  82. MODULE_LICENSE("GPL v2");
  83. MODULE_ALIAS("platform:imx-spdif");