pxa2xx-pcm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/dma-mapping.h>
  13. #include <linux/module.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/of.h>
  16. #include <sound/core.h>
  17. #include <sound/soc.h>
  18. #include <sound/pxa2xx-lib.h>
  19. #include <sound/dmaengine_pcm.h>
  20. #include "../../arm/pxa2xx-pcm.h"
  21. static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
  22. struct snd_pcm_hw_params *params)
  23. {
  24. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  25. struct snd_dmaengine_dai_dma_data *dma;
  26. dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
  27. /* return if this is a bufferless transfer e.g.
  28. * codec <--> BT codec or GSM modem -- lg FIXME */
  29. if (!dma)
  30. return 0;
  31. return __pxa2xx_pcm_hw_params(substream, params);
  32. }
  33. static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
  34. {
  35. __pxa2xx_pcm_hw_free(substream);
  36. return 0;
  37. }
  38. static struct snd_pcm_ops pxa2xx_pcm_ops = {
  39. .open = __pxa2xx_pcm_open,
  40. .close = __pxa2xx_pcm_close,
  41. .ioctl = snd_pcm_lib_ioctl,
  42. .hw_params = pxa2xx_pcm_hw_params,
  43. .hw_free = pxa2xx_pcm_hw_free,
  44. .prepare = __pxa2xx_pcm_prepare,
  45. .trigger = pxa2xx_pcm_trigger,
  46. .pointer = pxa2xx_pcm_pointer,
  47. .mmap = pxa2xx_pcm_mmap,
  48. };
  49. static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd)
  50. {
  51. struct snd_card *card = rtd->card->snd_card;
  52. struct snd_pcm *pcm = rtd->pcm;
  53. int ret;
  54. ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
  55. if (ret)
  56. return ret;
  57. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
  58. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  59. SNDRV_PCM_STREAM_PLAYBACK);
  60. if (ret)
  61. goto out;
  62. }
  63. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
  64. ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
  65. SNDRV_PCM_STREAM_CAPTURE);
  66. if (ret)
  67. goto out;
  68. }
  69. out:
  70. return ret;
  71. }
  72. static struct snd_soc_platform_driver pxa2xx_soc_platform = {
  73. .ops = &pxa2xx_pcm_ops,
  74. .pcm_new = pxa2xx_soc_pcm_new,
  75. .pcm_free = pxa2xx_pcm_free_dma_buffers,
  76. };
  77. static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
  78. {
  79. return devm_snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
  80. }
  81. #ifdef CONFIG_OF
  82. static const struct of_device_id snd_soc_pxa_audio_match[] = {
  83. { .compatible = "mrvl,pxa-pcm-audio" },
  84. { }
  85. };
  86. MODULE_DEVICE_TABLE(of, snd_soc_pxa_audio_match);
  87. #endif
  88. static struct platform_driver pxa_pcm_driver = {
  89. .driver = {
  90. .name = "pxa-pcm-audio",
  91. .of_match_table = of_match_ptr(snd_soc_pxa_audio_match),
  92. },
  93. .probe = pxa2xx_soc_platform_probe,
  94. };
  95. module_platform_driver(pxa_pcm_driver);
  96. MODULE_AUTHOR("Nicolas Pitre");
  97. MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
  98. MODULE_LICENSE("GPL");
  99. MODULE_ALIAS("platform:pxa-pcm-audio");