pxa2xx-pcm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_card *card, struct snd_soc_dai *dai,
  74. struct snd_pcm *pcm)
  75. {
  76. int ret = 0;
  77. if (!card->dev->dma_mask)
  78. card->dev->dma_mask = &pxa2xx_pcm_dmamask;
  79. if (!card->dev->coherent_dma_mask)
  80. card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
  81. if (dai->driver->playback.channels_min) {
  82. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  83. SNDRV_PCM_STREAM_PLAYBACK);
  84. if (ret)
  85. goto out;
  86. }
  87. if (dai->driver->capture.channels_min) {
  88. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  89. SNDRV_PCM_STREAM_CAPTURE);
  90. if (ret)
  91. goto out;
  92. }
  93. out:
  94. return ret;
  95. }
  96. static struct snd_soc_platform_driver pxa2xx_soc_platform = {
  97. .ops = &pxa2xx_pcm_ops,
  98. .pcm_new = pxa2xx_soc_pcm_new,
  99. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  100. };
  101. static int __devinit pxa2xx_soc_platform_probe(struct platform_device *pdev)
  102. {
  103. return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
  104. }
  105. static int __devexit pxa2xx_soc_platform_remove(struct platform_device *pdev)
  106. {
  107. snd_soc_unregister_platform(&pdev->dev);
  108. return 0;
  109. }
  110. static struct platform_driver pxa_pcm_driver = {
  111. .driver = {
  112. .name = "pxa-pcm-audio",
  113. .owner = THIS_MODULE,
  114. },
  115. .probe = pxa2xx_soc_platform_probe,
  116. .remove = __devexit_p(pxa2xx_soc_platform_remove),
  117. };
  118. static int __init snd_pxa_pcm_init(void)
  119. {
  120. return platform_driver_register(&pxa_pcm_driver);
  121. }
  122. module_init(snd_pxa_pcm_init);
  123. static void __exit snd_pxa_pcm_exit(void)
  124. {
  125. platform_driver_unregister(&pxa_pcm_driver);
  126. }
  127. module_exit(snd_pxa_pcm_exit);
  128. MODULE_AUTHOR("Nicolas Pitre");
  129. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  130. MODULE_LICENSE("GPL");