pxa2xx-pcm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "pxa2xx-pcm.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->dai->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. }
  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->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->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. struct snd_soc_platform pxa2xx_soc_platform = {
  97. .name = "pxa2xx-audio",
  98. .pcm_ops = &pxa2xx_pcm_ops,
  99. .pcm_new = pxa2xx_soc_pcm_new,
  100. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  101. };
  102. EXPORT_SYMBOL_GPL(pxa2xx_soc_platform);
  103. static int __init pxa2xx_soc_platform_init(void)
  104. {
  105. return snd_soc_register_platform(&pxa2xx_soc_platform);
  106. }
  107. module_init(pxa2xx_soc_platform_init);
  108. static void __exit pxa2xx_soc_platform_exit(void)
  109. {
  110. snd_soc_unregister_platform(&pxa2xx_soc_platform);
  111. }
  112. module_exit(pxa2xx_soc_platform_exit);
  113. MODULE_AUTHOR("Nicolas Pitre");
  114. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  115. MODULE_LICENSE("GPL");