pxa2xx-pcm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/module.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/dmaengine.h>
  15. #include <sound/core.h>
  16. #include <sound/pxa2xx-lib.h>
  17. #include <sound/dmaengine_pcm.h>
  18. #include "pxa2xx-pcm.h"
  19. static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
  20. {
  21. struct pxa2xx_pcm_client *client = substream->private_data;
  22. __pxa2xx_pcm_prepare(substream);
  23. return client->prepare(substream);
  24. }
  25. static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
  26. {
  27. struct pxa2xx_pcm_client *client = substream->private_data;
  28. struct snd_pcm_runtime *runtime = substream->runtime;
  29. struct pxa2xx_runtime_data *rtd;
  30. int ret;
  31. ret = __pxa2xx_pcm_open(substream);
  32. if (ret)
  33. goto out;
  34. rtd = runtime->private_data;
  35. rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  36. client->playback_params : client->capture_params;
  37. ret = pxa_request_dma("dma", DMA_PRIO_LOW,
  38. pxa2xx_pcm_dma_irq, substream);
  39. if (ret < 0)
  40. goto err2;
  41. rtd->dma_ch = ret;
  42. ret = client->startup(substream);
  43. if (!ret)
  44. goto out;
  45. pxa_free_dma(rtd->dma_ch);
  46. err2:
  47. __pxa2xx_pcm_close(substream);
  48. out:
  49. return ret;
  50. }
  51. static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
  52. {
  53. struct pxa2xx_pcm_client *client = substream->private_data;
  54. struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
  55. pxa_free_dma(rtd->dma_ch);
  56. client->shutdown(substream);
  57. return __pxa2xx_pcm_close(substream);
  58. }
  59. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  60. .open = pxa2xx_pcm_open,
  61. .close = pxa2xx_pcm_close,
  62. .ioctl = snd_pcm_lib_ioctl,
  63. .hw_params = __pxa2xx_pcm_hw_params,
  64. .hw_free = __pxa2xx_pcm_hw_free,
  65. .prepare = pxa2xx_pcm_prepare,
  66. .trigger = pxa2xx_pcm_trigger,
  67. .pointer = pxa2xx_pcm_pointer,
  68. .mmap = pxa2xx_pcm_mmap,
  69. };
  70. int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
  71. struct snd_pcm **rpcm)
  72. {
  73. struct snd_pcm *pcm;
  74. int play = client->playback_params ? 1 : 0;
  75. int capt = client->capture_params ? 1 : 0;
  76. int ret;
  77. ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm);
  78. if (ret)
  79. goto out;
  80. pcm->private_data = client;
  81. pcm->private_free = pxa2xx_pcm_free_dma_buffers;
  82. ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
  83. if (ret)
  84. goto out;
  85. if (play) {
  86. int stream = SNDRV_PCM_STREAM_PLAYBACK;
  87. snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
  88. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
  89. if (ret)
  90. goto out;
  91. }
  92. if (capt) {
  93. int stream = SNDRV_PCM_STREAM_CAPTURE;
  94. snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
  95. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
  96. if (ret)
  97. goto out;
  98. }
  99. if (rpcm)
  100. *rpcm = pcm;
  101. ret = 0;
  102. out:
  103. return ret;
  104. }
  105. EXPORT_SYMBOL(pxa2xx_pcm_new);
  106. MODULE_AUTHOR("Nicolas Pitre");
  107. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  108. MODULE_LICENSE("GPL");