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