pxa2xx-pcm.c 3.7 KB

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