pxa2xx-pcm.c 3.4 KB

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