pxa2xx-pcm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <mach/dma.h>
  17. #include <sound/core.h>
  18. #include <sound/soc.h>
  19. #include <sound/pxa2xx-lib.h>
  20. #include <sound/dmaengine_pcm.h>
  21. #include "../../arm/pxa2xx-pcm.h"
  22. static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
  23. struct snd_pcm_hw_params *params)
  24. {
  25. struct snd_pcm_runtime *runtime = substream->runtime;
  26. struct pxa2xx_runtime_data *prtd = runtime->private_data;
  27. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  28. struct snd_dmaengine_dai_dma_data *dma;
  29. int ret;
  30. dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
  31. /* return if this is a bufferless transfer e.g.
  32. * codec <--> BT codec or GSM modem -- lg FIXME */
  33. if (!dma)
  34. return 0;
  35. /* this may get called several times by oss emulation
  36. * with different params */
  37. if (prtd->params == NULL) {
  38. prtd->params = dma;
  39. ret = pxa_request_dma("name", DMA_PRIO_LOW,
  40. pxa2xx_pcm_dma_irq, substream);
  41. if (ret < 0)
  42. return ret;
  43. prtd->dma_ch = ret;
  44. } else if (prtd->params != dma) {
  45. pxa_free_dma(prtd->dma_ch);
  46. prtd->params = dma;
  47. ret = pxa_request_dma("name", DMA_PRIO_LOW,
  48. pxa2xx_pcm_dma_irq, substream);
  49. if (ret < 0)
  50. return ret;
  51. prtd->dma_ch = ret;
  52. }
  53. return __pxa2xx_pcm_hw_params(substream, params);
  54. }
  55. static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
  56. {
  57. struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
  58. __pxa2xx_pcm_hw_free(substream);
  59. if (prtd->dma_ch >= 0) {
  60. pxa_free_dma(prtd->dma_ch);
  61. prtd->dma_ch = -1;
  62. prtd->params = NULL;
  63. }
  64. return 0;
  65. }
  66. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  67. .open = __pxa2xx_pcm_open,
  68. .close = __pxa2xx_pcm_close,
  69. .ioctl = snd_pcm_lib_ioctl,
  70. .hw_params = pxa2xx_pcm_hw_params,
  71. .hw_free = pxa2xx_pcm_hw_free,
  72. .prepare = __pxa2xx_pcm_prepare,
  73. .trigger = pxa2xx_pcm_trigger,
  74. .pointer = pxa2xx_pcm_pointer,
  75. .mmap = pxa2xx_pcm_mmap,
  76. };
  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;
  82. ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
  83. if (ret)
  84. return ret;
  85. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
  86. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  87. SNDRV_PCM_STREAM_PLAYBACK);
  88. if (ret)
  89. goto out;
  90. }
  91. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
  92. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  93. SNDRV_PCM_STREAM_CAPTURE);
  94. if (ret)
  95. goto out;
  96. }
  97. out:
  98. return ret;
  99. }
  100. static struct snd_soc_platform_driver pxa2xx_soc_platform = {
  101. .ops = &pxa2xx_pcm_ops,
  102. .pcm_new = pxa2xx_soc_pcm_new,
  103. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  104. };
  105. static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
  106. {
  107. return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
  108. }
  109. static int pxa2xx_soc_platform_remove(struct platform_device *pdev)
  110. {
  111. snd_soc_unregister_platform(&pdev->dev);
  112. return 0;
  113. }
  114. #ifdef CONFIG_OF
  115. static const struct of_device_id snd_soc_pxa_audio_match[] = {
  116. { .compatible = "mrvl,pxa-pcm-audio" },
  117. { }
  118. };
  119. #endif
  120. static struct platform_driver pxa_pcm_driver = {
  121. .driver = {
  122. .name = "pxa-pcm-audio",
  123. .of_match_table = of_match_ptr(snd_soc_pxa_audio_match),
  124. },
  125. .probe = pxa2xx_soc_platform_probe,
  126. .remove = pxa2xx_soc_platform_remove,
  127. };
  128. module_platform_driver(pxa_pcm_driver);
  129. MODULE_AUTHOR("Nicolas Pitre");
  130. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  131. MODULE_LICENSE("GPL");