0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <asm/page.h>
0011
0012 #include <linux/module.h>
0013 #include <linux/dma-mapping.h>
0014 #include <linux/dmaengine.h>
0015 #include <linux/slab.h>
0016 #include <linux/platform_data/dma-ste-dma40.h>
0017
0018 #include <sound/pcm.h>
0019 #include <sound/pcm_params.h>
0020 #include <sound/soc.h>
0021 #include <sound/dmaengine_pcm.h>
0022
0023 #include "ux500_msp_i2s.h"
0024 #include "ux500_pcm.h"
0025
0026 #define UX500_PLATFORM_PERIODS_BYTES_MIN 128
0027 #define UX500_PLATFORM_PERIODS_BYTES_MAX (64 * PAGE_SIZE)
0028 #define UX500_PLATFORM_PERIODS_MIN 2
0029 #define UX500_PLATFORM_PERIODS_MAX 48
0030 #define UX500_PLATFORM_BUFFER_BYTES_MAX (2048 * PAGE_SIZE)
0031
0032 static const struct snd_pcm_hardware ux500_pcm_hw = {
0033 .info = SNDRV_PCM_INFO_INTERLEAVED |
0034 SNDRV_PCM_INFO_MMAP |
0035 SNDRV_PCM_INFO_RESUME |
0036 SNDRV_PCM_INFO_PAUSE,
0037 .buffer_bytes_max = UX500_PLATFORM_BUFFER_BYTES_MAX,
0038 .period_bytes_min = UX500_PLATFORM_PERIODS_BYTES_MIN,
0039 .period_bytes_max = UX500_PLATFORM_PERIODS_BYTES_MAX,
0040 .periods_min = UX500_PLATFORM_PERIODS_MIN,
0041 .periods_max = UX500_PLATFORM_PERIODS_MAX,
0042 };
0043
0044 static struct dma_chan *ux500_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
0045 struct snd_pcm_substream *substream)
0046 {
0047 struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0);
0048 u16 per_data_width, mem_data_width;
0049 struct stedma40_chan_cfg *dma_cfg;
0050 struct ux500_msp_dma_params *dma_params;
0051
0052 dma_params = snd_soc_dai_get_dma_data(dai, substream);
0053 dma_cfg = dma_params->dma_cfg;
0054
0055 mem_data_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
0056
0057 switch (dma_params->data_size) {
0058 case 32:
0059 per_data_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
0060 break;
0061 case 16:
0062 per_data_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
0063 break;
0064 case 8:
0065 per_data_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
0066 break;
0067 default:
0068 per_data_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
0069 }
0070
0071 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
0072 dma_cfg->src_info.data_width = mem_data_width;
0073 dma_cfg->dst_info.data_width = per_data_width;
0074 } else {
0075 dma_cfg->src_info.data_width = per_data_width;
0076 dma_cfg->dst_info.data_width = mem_data_width;
0077 }
0078
0079 return snd_dmaengine_pcm_request_channel(stedma40_filter, dma_cfg);
0080 }
0081
0082 static int ux500_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
0083 struct snd_pcm_hw_params *params,
0084 struct dma_slave_config *slave_config)
0085 {
0086 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0087 struct msp_i2s_platform_data *pdata = asoc_rtd_to_cpu(rtd, 0)->dev->platform_data;
0088 struct snd_dmaengine_dai_dma_data *snd_dma_params;
0089 struct ux500_msp_dma_params *ste_dma_params;
0090 dma_addr_t dma_addr;
0091 int ret;
0092
0093 if (pdata) {
0094 ste_dma_params =
0095 snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
0096 dma_addr = ste_dma_params->tx_rx_addr;
0097 } else {
0098 snd_dma_params =
0099 snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
0100 dma_addr = snd_dma_params->addr;
0101 }
0102
0103 ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
0104 if (ret)
0105 return ret;
0106
0107 slave_config->dst_maxburst = 4;
0108 slave_config->src_maxburst = 4;
0109
0110 slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
0111 slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
0112
0113 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
0114 slave_config->dst_addr = dma_addr;
0115 else
0116 slave_config->src_addr = dma_addr;
0117
0118 return 0;
0119 }
0120
0121 static const struct snd_dmaengine_pcm_config ux500_dmaengine_pcm_config = {
0122 .pcm_hardware = &ux500_pcm_hw,
0123 .compat_request_channel = ux500_pcm_request_chan,
0124 .prealloc_buffer_size = 128 * 1024,
0125 .prepare_slave_config = ux500_pcm_prepare_slave_config,
0126 };
0127
0128 static const struct snd_dmaengine_pcm_config ux500_dmaengine_of_pcm_config = {
0129 .compat_request_channel = ux500_pcm_request_chan,
0130 .prepare_slave_config = ux500_pcm_prepare_slave_config,
0131 };
0132
0133 int ux500_pcm_register_platform(struct platform_device *pdev)
0134 {
0135 const struct snd_dmaengine_pcm_config *pcm_config;
0136 struct device_node *np = pdev->dev.of_node;
0137 int ret;
0138
0139 if (np)
0140 pcm_config = &ux500_dmaengine_of_pcm_config;
0141 else
0142 pcm_config = &ux500_dmaengine_pcm_config;
0143
0144 ret = snd_dmaengine_pcm_register(&pdev->dev, pcm_config,
0145 SND_DMAENGINE_PCM_FLAG_COMPAT);
0146 if (ret < 0) {
0147 dev_err(&pdev->dev,
0148 "%s: ERROR: Failed to register platform '%s' (%d)!\n",
0149 __func__, pdev->name, ret);
0150 return ret;
0151 }
0152
0153 return 0;
0154 }
0155 EXPORT_SYMBOL_GPL(ux500_pcm_register_platform);
0156
0157 int ux500_pcm_unregister_platform(struct platform_device *pdev)
0158 {
0159 snd_dmaengine_pcm_unregister(&pdev->dev);
0160 return 0;
0161 }
0162 EXPORT_SYMBOL_GPL(ux500_pcm_unregister_platform);
0163
0164 MODULE_AUTHOR("Ola Lilja");
0165 MODULE_AUTHOR("Roger Nilsson");
0166 MODULE_DESCRIPTION("ASoC UX500 driver");
0167 MODULE_LICENSE("GPL v2");