omap4-hdmi-card.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <linux/module.h>
  24. #include <sound/pcm.h>
  25. #include <sound/soc.h>
  26. #include <asm/mach-types.h>
  27. #include <video/omapdss.h>
  28. #define DRV_NAME "omap4-hdmi-audio"
  29. static int omap4_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
  30. struct snd_pcm_hw_params *params)
  31. {
  32. int i;
  33. struct omap_overlay_manager *mgr = NULL;
  34. struct device *dev = substream->pcm->card->dev;
  35. /* Find DSS HDMI device */
  36. for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
  37. mgr = omap_dss_get_overlay_manager(i);
  38. if (mgr && mgr->device
  39. && mgr->device->type == OMAP_DISPLAY_TYPE_HDMI)
  40. break;
  41. }
  42. if (i == omap_dss_get_num_overlay_managers()) {
  43. dev_err(dev, "HDMI display device not found!\n");
  44. return -ENODEV;
  45. }
  46. /* Make sure HDMI is power-on to avoid L3 interconnect errors */
  47. if (mgr->device->state != OMAP_DSS_DISPLAY_ACTIVE) {
  48. dev_err(dev, "HDMI display is not active!\n");
  49. return -EIO;
  50. }
  51. return 0;
  52. }
  53. static struct snd_soc_ops omap4_hdmi_dai_ops = {
  54. .hw_params = omap4_hdmi_dai_hw_params,
  55. };
  56. static struct snd_soc_dai_link omap4_hdmi_dai = {
  57. .name = "HDMI",
  58. .stream_name = "HDMI",
  59. .cpu_dai_name = "hdmi-audio-dai",
  60. .platform_name = "omap-pcm-audio",
  61. .codec_name = "omapdss_hdmi",
  62. .codec_dai_name = "hdmi-audio-codec",
  63. .ops = &omap4_hdmi_dai_ops,
  64. };
  65. static struct snd_soc_card snd_soc_omap4_hdmi = {
  66. .name = "OMAP4HDMI",
  67. .owner = THIS_MODULE,
  68. .dai_link = &omap4_hdmi_dai,
  69. .num_links = 1,
  70. };
  71. static __devinit int omap4_hdmi_probe(struct platform_device *pdev)
  72. {
  73. struct snd_soc_card *card = &snd_soc_omap4_hdmi;
  74. int ret;
  75. card->dev = &pdev->dev;
  76. ret = snd_soc_register_card(card);
  77. if (ret) {
  78. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
  79. card->dev = NULL;
  80. return ret;
  81. }
  82. return 0;
  83. }
  84. static int __devexit omap4_hdmi_remove(struct platform_device *pdev)
  85. {
  86. struct snd_soc_card *card = platform_get_drvdata(pdev);
  87. snd_soc_unregister_card(card);
  88. card->dev = NULL;
  89. return 0;
  90. }
  91. static struct platform_driver omap4_hdmi_driver = {
  92. .driver = {
  93. .name = "omap4-hdmi-audio",
  94. .owner = THIS_MODULE,
  95. },
  96. .probe = omap4_hdmi_probe,
  97. .remove = __devexit_p(omap4_hdmi_remove),
  98. };
  99. module_platform_driver(omap4_hdmi_driver);
  100. MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
  101. MODULE_DESCRIPTION("OMAP4 HDMI machine ASoC driver");
  102. MODULE_LICENSE("GPL");
  103. MODULE_ALIAS("platform:" DRV_NAME);