ux500_pcm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2012
  3. *
  4. * Author: Ola Lilja <ola.o.lilja@stericsson.com>,
  5. * Roger Nilsson <roger.xr.nilsson@stericsson.com>
  6. * for ST-Ericsson.
  7. *
  8. * License terms:
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <asm/page.h>
  15. #include <linux/module.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/dmaengine.h>
  18. #include <linux/slab.h>
  19. #include <linux/platform_data/dma-ste-dma40.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/soc.h>
  23. #include <sound/dmaengine_pcm.h>
  24. #include "ux500_msp_i2s.h"
  25. #include "ux500_pcm.h"
  26. #define UX500_PLATFORM_MIN_RATE 8000
  27. #define UX500_PLATFORM_MAX_RATE 48000
  28. #define UX500_PLATFORM_MIN_CHANNELS 1
  29. #define UX500_PLATFORM_MAX_CHANNELS 8
  30. #define UX500_PLATFORM_PERIODS_BYTES_MIN 128
  31. #define UX500_PLATFORM_PERIODS_BYTES_MAX (64 * PAGE_SIZE)
  32. #define UX500_PLATFORM_PERIODS_MIN 2
  33. #define UX500_PLATFORM_PERIODS_MAX 48
  34. #define UX500_PLATFORM_BUFFER_BYTES_MAX (2048 * PAGE_SIZE)
  35. static const struct snd_pcm_hardware ux500_pcm_hw = {
  36. .info = SNDRV_PCM_INFO_INTERLEAVED |
  37. SNDRV_PCM_INFO_MMAP |
  38. SNDRV_PCM_INFO_RESUME |
  39. SNDRV_PCM_INFO_PAUSE,
  40. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  41. SNDRV_PCM_FMTBIT_U16_LE |
  42. SNDRV_PCM_FMTBIT_S16_BE |
  43. SNDRV_PCM_FMTBIT_U16_BE,
  44. .rates = SNDRV_PCM_RATE_KNOT,
  45. .rate_min = UX500_PLATFORM_MIN_RATE,
  46. .rate_max = UX500_PLATFORM_MAX_RATE,
  47. .channels_min = UX500_PLATFORM_MIN_CHANNELS,
  48. .channels_max = UX500_PLATFORM_MAX_CHANNELS,
  49. .buffer_bytes_max = UX500_PLATFORM_BUFFER_BYTES_MAX,
  50. .period_bytes_min = UX500_PLATFORM_PERIODS_BYTES_MIN,
  51. .period_bytes_max = UX500_PLATFORM_PERIODS_BYTES_MAX,
  52. .periods_min = UX500_PLATFORM_PERIODS_MIN,
  53. .periods_max = UX500_PLATFORM_PERIODS_MAX,
  54. };
  55. static struct dma_chan *ux500_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
  56. struct snd_pcm_substream *substream)
  57. {
  58. struct snd_soc_dai *dai = rtd->cpu_dai;
  59. struct device *dev = dai->dev;
  60. u16 per_data_width, mem_data_width;
  61. struct stedma40_chan_cfg *dma_cfg;
  62. struct ux500_msp_dma_params *dma_params;
  63. dev_dbg(dev, "%s: MSP %d (%s): Enter.\n", __func__, dai->id,
  64. snd_pcm_stream_str(substream));
  65. dma_params = snd_soc_dai_get_dma_data(dai, substream);
  66. dma_cfg = dma_params->dma_cfg;
  67. mem_data_width = STEDMA40_HALFWORD_WIDTH;
  68. switch (dma_params->data_size) {
  69. case 32:
  70. per_data_width = STEDMA40_WORD_WIDTH;
  71. break;
  72. case 16:
  73. per_data_width = STEDMA40_HALFWORD_WIDTH;
  74. break;
  75. case 8:
  76. per_data_width = STEDMA40_BYTE_WIDTH;
  77. break;
  78. default:
  79. per_data_width = STEDMA40_WORD_WIDTH;
  80. }
  81. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  82. dma_cfg->src_info.data_width = mem_data_width;
  83. dma_cfg->dst_info.data_width = per_data_width;
  84. } else {
  85. dma_cfg->src_info.data_width = per_data_width;
  86. dma_cfg->dst_info.data_width = mem_data_width;
  87. }
  88. return snd_dmaengine_pcm_request_channel(stedma40_filter, dma_cfg);
  89. }
  90. static const struct snd_dmaengine_pcm_config ux500_dmaengine_pcm_config = {
  91. .pcm_hardware = &ux500_pcm_hw,
  92. .compat_request_channel = ux500_pcm_request_chan,
  93. .prealloc_buffer_size = 128 * 1024,
  94. };
  95. int ux500_pcm_register_platform(struct platform_device *pdev)
  96. {
  97. int ret;
  98. ret = snd_dmaengine_pcm_register(&pdev->dev,
  99. &ux500_dmaengine_pcm_config,
  100. SND_DMAENGINE_PCM_FLAG_NO_RESIDUE |
  101. SND_DMAENGINE_PCM_FLAG_COMPAT |
  102. SND_DMAENGINE_PCM_FLAG_NO_DT);
  103. if (ret < 0) {
  104. dev_err(&pdev->dev,
  105. "%s: ERROR: Failed to register platform '%s' (%d)!\n",
  106. __func__, pdev->name, ret);
  107. return ret;
  108. }
  109. return 0;
  110. }
  111. EXPORT_SYMBOL_GPL(ux500_pcm_register_platform);
  112. int ux500_pcm_unregister_platform(struct platform_device *pdev)
  113. {
  114. snd_dmaengine_pcm_unregister(&pdev->dev);
  115. return 0;
  116. }
  117. EXPORT_SYMBOL_GPL(ux500_pcm_unregister_platform);