pxa2xx-pcm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. }
  58. return 0;
  59. }
  60. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  61. .open = __pxa2xx_pcm_open,
  62. .close = __pxa2xx_pcm_close,
  63. .ioctl = snd_pcm_lib_ioctl,
  64. .hw_params = pxa2xx_pcm_hw_params,
  65. .hw_free = pxa2xx_pcm_hw_free,
  66. .prepare = __pxa2xx_pcm_prepare,
  67. .trigger = pxa2xx_pcm_trigger,
  68. .pointer = pxa2xx_pcm_pointer,
  69. .mmap = pxa2xx_pcm_mmap,
  70. };
  71. static u64 pxa2xx_pcm_dmamask = DMA_BIT_MASK(32);
  72. static int pxa2xx_soc_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
  73. struct snd_pcm *pcm)
  74. {
  75. int ret = 0;
  76. if (!card->dev->dma_mask)
  77. card->dev->dma_mask = &pxa2xx_pcm_dmamask;
  78. if (!card->dev->coherent_dma_mask)
  79. card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
  80. if (dai->driver->playback.channels_min) {
  81. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  82. SNDRV_PCM_STREAM_PLAYBACK);
  83. if (ret)
  84. goto out;
  85. }
  86. if (dai->driver->capture.channels_min) {
  87. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  88. SNDRV_PCM_STREAM_CAPTURE);
  89. if (ret)
  90. goto out;
  91. }
  92. out:
  93. return ret;
  94. }
  95. static struct snd_soc_platform_driver pxa2xx_soc_platform = {
  96. .ops = &pxa2xx_pcm_ops,
  97. .pcm_new = pxa2xx_soc_pcm_new,
  98. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  99. };
  100. static int __devinit pxa2xx_soc_platform_probe(struct platform_device *pdev)
  101. {
  102. return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
  103. }
  104. static int __devexit pxa2xx_soc_platform_remove(struct platform_device *pdev)
  105. {
  106. snd_soc_unregister_platform(&pdev->dev);
  107. return 0;
  108. }
  109. static struct platform_driver pxa_pcm_driver = {
  110. .driver = {
  111. .name = "pxa-pcm-audio",
  112. .owner = THIS_MODULE,
  113. },
  114. .probe = pxa2xx_soc_platform_probe,
  115. .remove = __devexit_p(pxa2xx_soc_platform_remove),
  116. };
  117. static int __init snd_pxa_pcm_init(void)
  118. {
  119. return platform_driver_register(&pxa_pcm_driver);
  120. }
  121. module_init(snd_pxa_pcm_init);
  122. static void __exit snd_pxa_pcm_exit(void)
  123. {
  124. platform_driver_unregister(&pxa_pcm_driver);
  125. }
  126. module_exit(snd_pxa_pcm_exit);
  127. MODULE_AUTHOR("Nicolas Pitre");
  128. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  129. MODULE_LICENSE("GPL");