omap-hdmi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * omap-hdmi.c
  3. *
  4. * OMAP ALSA SoC DAI driver for HDMI audio on OMAP4 processors.
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  6. * Authors: Jorge Candelaria <jorge.candelaria@ti.com>
  7. * Ricardo Neri <ricardo.neri@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/device.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/initval.h>
  31. #include <sound/soc.h>
  32. #include <plat/dma.h>
  33. #include "omap-pcm.h"
  34. #include "omap-hdmi.h"
  35. #define DRV_NAME "hdmi-audio-dai"
  36. static struct omap_pcm_dma_data omap_hdmi_dai_dma_params = {
  37. .name = "HDMI playback",
  38. .sync_mode = OMAP_DMA_SYNC_PACKET,
  39. };
  40. static int omap_hdmi_dai_startup(struct snd_pcm_substream *substream,
  41. struct snd_soc_dai *dai)
  42. {
  43. int err;
  44. /*
  45. * Make sure that the period bytes are multiple of the DMA packet size.
  46. * Largest packet size we use is 32 32-bit words = 128 bytes
  47. */
  48. err = snd_pcm_hw_constraint_step(substream->runtime, 0,
  49. SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
  50. if (err < 0)
  51. return err;
  52. return 0;
  53. }
  54. static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
  55. struct snd_pcm_hw_params *params,
  56. struct snd_soc_dai *dai)
  57. {
  58. int err = 0;
  59. switch (params_format(params)) {
  60. case SNDRV_PCM_FORMAT_S16_LE:
  61. omap_hdmi_dai_dma_params.packet_size = 16;
  62. break;
  63. case SNDRV_PCM_FORMAT_S24_LE:
  64. omap_hdmi_dai_dma_params.packet_size = 32;
  65. break;
  66. default:
  67. err = -EINVAL;
  68. }
  69. omap_hdmi_dai_dma_params.data_type = OMAP_DMA_DATA_TYPE_S32;
  70. snd_soc_dai_set_dma_data(dai, substream,
  71. &omap_hdmi_dai_dma_params);
  72. return err;
  73. }
  74. static const struct snd_soc_dai_ops omap_hdmi_dai_ops = {
  75. .startup = omap_hdmi_dai_startup,
  76. .hw_params = omap_hdmi_dai_hw_params,
  77. };
  78. static struct snd_soc_dai_driver omap_hdmi_dai = {
  79. .playback = {
  80. .channels_min = 2,
  81. .channels_max = 2,
  82. .rates = OMAP_HDMI_RATES,
  83. .formats = OMAP_HDMI_FORMATS,
  84. },
  85. .ops = &omap_hdmi_dai_ops,
  86. };
  87. static __devinit int omap_hdmi_probe(struct platform_device *pdev)
  88. {
  89. int ret;
  90. struct resource *hdmi_rsrc;
  91. hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  92. if (!hdmi_rsrc) {
  93. dev_err(&pdev->dev, "Cannot obtain IORESOURCE_MEM HDMI\n");
  94. return -EINVAL;
  95. }
  96. omap_hdmi_dai_dma_params.port_addr = hdmi_rsrc->start
  97. + OMAP_HDMI_AUDIO_DMA_PORT;
  98. hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  99. if (!hdmi_rsrc) {
  100. dev_err(&pdev->dev, "Cannot obtain IORESOURCE_DMA HDMI\n");
  101. return -EINVAL;
  102. }
  103. omap_hdmi_dai_dma_params.dma_req = hdmi_rsrc->start;
  104. ret = snd_soc_register_dai(&pdev->dev, &omap_hdmi_dai);
  105. return ret;
  106. }
  107. static int __devexit omap_hdmi_remove(struct platform_device *pdev)
  108. {
  109. snd_soc_unregister_dai(&pdev->dev);
  110. return 0;
  111. }
  112. static struct platform_driver hdmi_dai_driver = {
  113. .driver = {
  114. .name = DRV_NAME,
  115. .owner = THIS_MODULE,
  116. },
  117. .probe = omap_hdmi_probe,
  118. .remove = __devexit_p(omap_hdmi_remove),
  119. };
  120. module_platform_driver(hdmi_dai_driver);
  121. MODULE_AUTHOR("Jorge Candelaria <jorge.candelaria@ti.com>");
  122. MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
  123. MODULE_DESCRIPTION("OMAP HDMI SoC Interface");
  124. MODULE_LICENSE("GPL");
  125. MODULE_ALIAS("platform:" DRV_NAME);