pxa2xx-pcm.c 3.1 KB

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