pxa2xx-pcm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * linux/sound/arm/pxa2xx-pcm.c -- ALSA PCM interface for the Intel PXA2xx chip
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Nov 30, 2004
  6. * Copyright: (C) 2004 MontaVista Software, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/dma-mapping.h>
  13. #include <linux/module.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/of.h>
  16. #include <sound/core.h>
  17. #include <sound/soc.h>
  18. #include <sound/pxa2xx-lib.h>
  19. #include <sound/dmaengine_pcm.h>
  20. #include "../../arm/pxa2xx-pcm.h"
  21. static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
  22. struct snd_pcm_hw_params *params)
  23. {
  24. struct snd_pcm_runtime *runtime = substream->runtime;
  25. struct pxa2xx_runtime_data *prtd = runtime->private_data;
  26. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  27. struct snd_dmaengine_dai_dma_data *dma;
  28. int ret;
  29. dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
  30. /* return if this is a bufferless transfer e.g.
  31. * codec <--> BT codec or GSM modem -- lg FIXME */
  32. if (!dma)
  33. return 0;
  34. /* this may get called several times by oss emulation
  35. * with different params */
  36. if (prtd->params == NULL) {
  37. prtd->params = dma;
  38. ret = pxa_request_dma("name", DMA_PRIO_LOW,
  39. pxa2xx_pcm_dma_irq, substream);
  40. if (ret < 0)
  41. return ret;
  42. prtd->dma_ch = ret;
  43. } else if (prtd->params != dma) {
  44. pxa_free_dma(prtd->dma_ch);
  45. prtd->params = dma;
  46. ret = pxa_request_dma("name", DMA_PRIO_LOW,
  47. pxa2xx_pcm_dma_irq, substream);
  48. if (ret < 0)
  49. return ret;
  50. prtd->dma_ch = ret;
  51. }
  52. return __pxa2xx_pcm_hw_params(substream, params);
  53. }
  54. static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
  55. {
  56. struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
  57. __pxa2xx_pcm_hw_free(substream);
  58. if (prtd->dma_ch >= 0) {
  59. pxa_free_dma(prtd->dma_ch);
  60. prtd->dma_ch = -1;
  61. prtd->params = NULL;
  62. }
  63. return 0;
  64. }
  65. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  66. .open = __pxa2xx_pcm_open,
  67. .close = __pxa2xx_pcm_close,
  68. .ioctl = snd_pcm_lib_ioctl,
  69. .hw_params = pxa2xx_pcm_hw_params,
  70. .hw_free = pxa2xx_pcm_hw_free,
  71. .prepare = __pxa2xx_pcm_prepare,
  72. .trigger = pxa2xx_pcm_trigger,
  73. .pointer = pxa2xx_pcm_pointer,
  74. .mmap = pxa2xx_pcm_mmap,
  75. };
  76. static u64 pxa2xx_pcm_dmamask = DMA_BIT_MASK(32);
  77. static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd)
  78. {
  79. struct snd_card *card = rtd->card->snd_card;
  80. struct snd_pcm *pcm = rtd->pcm;
  81. int ret = 0;
  82. if (!card->dev->dma_mask)
  83. card->dev->dma_mask = &pxa2xx_pcm_dmamask;
  84. if (!card->dev->coherent_dma_mask)
  85. card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
  86. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
  87. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  88. SNDRV_PCM_STREAM_PLAYBACK);
  89. if (ret)
  90. goto out;
  91. }
  92. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
  93. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  94. SNDRV_PCM_STREAM_CAPTURE);
  95. if (ret)
  96. goto out;
  97. }
  98. out:
  99. return ret;
  100. }
  101. static struct snd_soc_platform_driver pxa2xx_soc_platform = {
  102. .ops = &pxa2xx_pcm_ops,
  103. .pcm_new = pxa2xx_soc_pcm_new,
  104. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  105. };
  106. static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
  107. {
  108. return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
  109. }
  110. static int pxa2xx_soc_platform_remove(struct platform_device *pdev)
  111. {
  112. snd_soc_unregister_platform(&pdev->dev);
  113. return 0;
  114. }
  115. #ifdef CONFIG_OF
  116. static const struct of_device_id snd_soc_pxa_audio_match[] = {
  117. { .compatible = "mrvl,pxa-pcm-audio" },
  118. { }
  119. };
  120. #endif
  121. static struct platform_driver pxa_pcm_driver = {
  122. .driver = {
  123. .name = "pxa-pcm-audio",
  124. .owner = THIS_MODULE,
  125. .of_match_table = of_match_ptr(snd_soc_pxa_audio_match),
  126. },
  127. .probe = pxa2xx_soc_platform_probe,
  128. .remove = pxa2xx_soc_platform_remove,
  129. };
  130. module_platform_driver(pxa_pcm_driver);
  131. MODULE_AUTHOR("Nicolas Pitre");
  132. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  133. MODULE_LICENSE("GPL");