imx-pcm-dma.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * imx-pcm-dma-mx2.c -- ALSA Soc Audio Layer
  3. *
  4. * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
  5. *
  6. * This code is based on code copyrighted by Freescale,
  7. * Liam Girdwood, Javier Martin and probably others.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/delay.h>
  16. #include <linux/device.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/slab.h>
  23. #include <linux/dmaengine.h>
  24. #include <linux/types.h>
  25. #include <sound/core.h>
  26. #include <sound/initval.h>
  27. #include <sound/pcm.h>
  28. #include <sound/pcm_params.h>
  29. #include <sound/soc.h>
  30. #include <sound/dmaengine_pcm.h>
  31. #include "imx-pcm.h"
  32. static bool filter(struct dma_chan *chan, void *param)
  33. {
  34. struct snd_dmaengine_dai_dma_data *dma_data = param;
  35. if (!imx_dma_is_general_purpose(chan))
  36. return false;
  37. chan->private = dma_data->filter_data;
  38. return true;
  39. }
  40. static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
  41. struct snd_pcm_hw_params *params)
  42. {
  43. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  44. struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
  45. struct dma_slave_config slave_config;
  46. int ret;
  47. ret = snd_hwparams_to_dma_slave_config(substream, params, &slave_config);
  48. if (ret)
  49. return ret;
  50. snd_dmaengine_pcm_set_config_from_dai_data(substream,
  51. snd_soc_dai_get_dma_data(rtd->cpu_dai, substream),
  52. &slave_config);
  53. ret = dmaengine_slave_config(chan, &slave_config);
  54. if (ret)
  55. return ret;
  56. snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
  57. return 0;
  58. }
  59. static struct snd_pcm_hardware snd_imx_hardware = {
  60. .info = SNDRV_PCM_INFO_INTERLEAVED |
  61. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  62. SNDRV_PCM_INFO_MMAP |
  63. SNDRV_PCM_INFO_MMAP_VALID |
  64. SNDRV_PCM_INFO_PAUSE |
  65. SNDRV_PCM_INFO_RESUME,
  66. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  67. .rate_min = 8000,
  68. .channels_min = 2,
  69. .channels_max = 2,
  70. .buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
  71. .period_bytes_min = 128,
  72. .period_bytes_max = 65535, /* Limited by SDMA engine */
  73. .periods_min = 2,
  74. .periods_max = 255,
  75. .fifo_size = 0,
  76. };
  77. static int snd_imx_open(struct snd_pcm_substream *substream)
  78. {
  79. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  80. snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
  81. return snd_dmaengine_pcm_open(substream, filter,
  82. snd_soc_dai_get_dma_data(rtd->cpu_dai, substream));
  83. }
  84. static struct snd_pcm_ops imx_pcm_ops = {
  85. .open = snd_imx_open,
  86. .close = snd_dmaengine_pcm_close,
  87. .ioctl = snd_pcm_lib_ioctl,
  88. .hw_params = snd_imx_pcm_hw_params,
  89. .trigger = snd_dmaengine_pcm_trigger,
  90. .pointer = snd_dmaengine_pcm_pointer_no_residue,
  91. .mmap = snd_imx_pcm_mmap,
  92. };
  93. static struct snd_soc_platform_driver imx_soc_platform_mx2 = {
  94. .ops = &imx_pcm_ops,
  95. .pcm_new = imx_pcm_new,
  96. .pcm_free = imx_pcm_free,
  97. };
  98. int imx_pcm_dma_init(struct platform_device *pdev)
  99. {
  100. return snd_soc_register_platform(&pdev->dev, &imx_soc_platform_mx2);
  101. }