pxa2xx-pcm.c 3.9 KB

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