pxa2xx-pcm.c 3.1 KB

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