pxa2xx-pcm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 = client->startup(substream);
  39. if (!ret)
  40. goto err2;
  41. return 0;
  42. err2:
  43. __pxa2xx_pcm_close(substream);
  44. out:
  45. return ret;
  46. }
  47. static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
  48. {
  49. struct pxa2xx_pcm_client *client = substream->private_data;
  50. client->shutdown(substream);
  51. return __pxa2xx_pcm_close(substream);
  52. }
  53. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  54. .open = pxa2xx_pcm_open,
  55. .close = pxa2xx_pcm_close,
  56. .ioctl = snd_pcm_lib_ioctl,
  57. .hw_params = __pxa2xx_pcm_hw_params,
  58. .hw_free = __pxa2xx_pcm_hw_free,
  59. .prepare = pxa2xx_pcm_prepare,
  60. .trigger = pxa2xx_pcm_trigger,
  61. .pointer = pxa2xx_pcm_pointer,
  62. .mmap = pxa2xx_pcm_mmap,
  63. };
  64. int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
  65. struct snd_pcm **rpcm)
  66. {
  67. struct snd_pcm *pcm;
  68. int play = client->playback_params ? 1 : 0;
  69. int capt = client->capture_params ? 1 : 0;
  70. int ret;
  71. ret = snd_pcm_new(card, "PXA2xx-PCM", 0, play, capt, &pcm);
  72. if (ret)
  73. goto out;
  74. pcm->private_data = client;
  75. pcm->private_free = pxa2xx_pcm_free_dma_buffers;
  76. ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
  77. if (ret)
  78. goto out;
  79. if (play) {
  80. int stream = SNDRV_PCM_STREAM_PLAYBACK;
  81. snd_pcm_set_ops(pcm, stream, &pxa2xx_pcm_ops);
  82. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
  83. if (ret)
  84. goto out;
  85. }
  86. if (capt) {
  87. int stream = SNDRV_PCM_STREAM_CAPTURE;
  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 (rpcm)
  94. *rpcm = pcm;
  95. ret = 0;
  96. out:
  97. return ret;
  98. }
  99. EXPORT_SYMBOL(pxa2xx_pcm_new);
  100. MODULE_AUTHOR("Nicolas Pitre");
  101. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  102. MODULE_LICENSE("GPL");