pxa2xx-pcm.c 3.2 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/module.h>
  13. #include <linux/dmaengine.h>
  14. #include <sound/core.h>
  15. #include <sound/pxa2xx-lib.h>
  16. #include <sound/dmaengine_pcm.h>
  17. #include "pxa2xx-pcm.h"
  18. static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
  19. {
  20. struct pxa2xx_pcm_client *client = substream->private_data;
  21. __pxa2xx_pcm_prepare(substream);
  22. return client->prepare(substream);
  23. }
  24. static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
  25. {
  26. struct pxa2xx_pcm_client *client = substream->private_data;
  27. struct snd_pcm_runtime *runtime = substream->runtime;
  28. struct pxa2xx_runtime_data *rtd;
  29. int ret;
  30. ret = __pxa2xx_pcm_open(substream);
  31. if (ret)
  32. goto out;
  33. rtd = runtime->private_data;
  34. rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
  35. client->playback_params : client->capture_params;
  36. ret = pxa_request_dma("dma", DMA_PRIO_LOW,
  37. pxa2xx_pcm_dma_irq, substream);
  38. if (ret < 0)
  39. goto err2;
  40. rtd->dma_ch = ret;
  41. ret = client->startup(substream);
  42. if (!ret)
  43. goto out;
  44. pxa_free_dma(rtd->dma_ch);
  45. err2:
  46. __pxa2xx_pcm_close(substream);
  47. out:
  48. return ret;
  49. }
  50. static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
  51. {
  52. struct pxa2xx_pcm_client *client = substream->private_data;
  53. struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
  54. pxa_free_dma(rtd->dma_ch);
  55. client->shutdown(substream);
  56. return __pxa2xx_pcm_close(substream);
  57. }
  58. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  59. .open = pxa2xx_pcm_open,
  60. .close = pxa2xx_pcm_close,
  61. .ioctl = snd_pcm_lib_ioctl,
  62. .hw_params = __pxa2xx_pcm_hw_params,
  63. .hw_free = __pxa2xx_pcm_hw_free,
  64. .prepare = pxa2xx_pcm_prepare,
  65. .trigger = pxa2xx_pcm_trigger,
  66. .pointer = pxa2xx_pcm_pointer,
  67. .mmap = pxa2xx_pcm_mmap,
  68. };
  69. static u64 pxa2xx_pcm_dmamask = 0xffffffff;
  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. if (!card->dev->dma_mask)
  83. card->dev->dma_mask = &pxa2xx_pcm_dmamask;
  84. if (!card->dev->coherent_dma_mask)
  85. card->dev->coherent_dma_mask = 0xffffffff;
  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");