omap4-hdmi-card.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * omap4-hdmi-card.c
  3. *
  4. * OMAP ALSA SoC machine driver for TI OMAP4 HDMI
  5. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  6. * Author: Ricardo Neri <ricardo.neri@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <sound/pcm.h>
  24. #include <sound/soc.h>
  25. #include <asm/mach-types.h>
  26. #include <video/omapdss.h>
  27. #define DRV_NAME "omap4-hdmi-audio"
  28. static int omap4_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
  29. struct snd_pcm_hw_params *params)
  30. {
  31. int i;
  32. struct omap_overlay_manager *mgr = NULL;
  33. struct device *dev = substream->pcm->card->dev;
  34. /* Find DSS HDMI device */
  35. for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
  36. mgr = omap_dss_get_overlay_manager(i);
  37. if (mgr && mgr->device
  38. && mgr->device->type == OMAP_DISPLAY_TYPE_HDMI)
  39. break;
  40. }
  41. if (i == omap_dss_get_num_overlay_managers()) {
  42. dev_err(dev, "HDMI display device not found!\n");
  43. return -ENODEV;
  44. }
  45. /* Make sure HDMI is power-on to avoid L3 interconnect errors */
  46. if (mgr->device->state != OMAP_DSS_DISPLAY_ACTIVE) {
  47. dev_err(dev, "HDMI display is not active!\n");
  48. return -EIO;
  49. }
  50. return 0;
  51. }
  52. static struct snd_soc_ops omap4_hdmi_dai_ops = {
  53. .hw_params = omap4_hdmi_dai_hw_params,
  54. };
  55. static struct snd_soc_dai_link omap4_hdmi_dai = {
  56. .name = "HDMI",
  57. .stream_name = "HDMI",
  58. .cpu_dai_name = "hdmi-audio-dai",
  59. .platform_name = "omap-pcm-audio",
  60. .codec_name = "omapdss_hdmi",
  61. .codec_dai_name = "hdmi-audio-codec",
  62. .ops = &omap4_hdmi_dai_ops,
  63. };
  64. static struct snd_soc_card snd_soc_omap4_hdmi = {
  65. .name = "OMAP4HDMI",
  66. .dai_link = &omap4_hdmi_dai,
  67. .num_links = 1,
  68. };
  69. static __devinit int omap4_hdmi_probe(struct platform_device *pdev)
  70. {
  71. struct snd_soc_card *card = &snd_soc_omap4_hdmi;
  72. int ret;
  73. card->dev = &pdev->dev;
  74. ret = snd_soc_register_card(card);
  75. if (ret) {
  76. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  77. card->dev = NULL;
  78. return ret;
  79. }
  80. return 0;
  81. }
  82. static int __devexit omap4_hdmi_remove(struct platform_device *pdev)
  83. {
  84. struct snd_soc_card *card = platform_get_drvdata(pdev);
  85. snd_soc_unregister_card(card);
  86. card->dev = NULL;
  87. return 0;
  88. }
  89. static struct platform_driver omap4_hdmi_driver = {
  90. .driver = {
  91. .name = "omap4-hdmi-audio",
  92. .owner = THIS_MODULE,
  93. },
  94. .probe = omap4_hdmi_probe,
  95. .remove = __devexit_p(omap4_hdmi_remove),
  96. };
  97. static int __init omap4_hdmi_init(void)
  98. {
  99. return platform_driver_register(&omap4_hdmi_driver);
  100. }
  101. module_init(omap4_hdmi_init);
  102. static void __exit omap4_hdmi_exit(void)
  103. {
  104. platform_driver_unregister(&omap4_hdmi_driver);
  105. }
  106. module_exit(omap4_hdmi_exit);
  107. MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
  108. MODULE_DESCRIPTION("OMAP4 HDMI machine ASoC driver");
  109. MODULE_LICENSE("GPL");
  110. MODULE_ALIAS("platform:" DRV_NAME);