ASoC: ux500_pcm: Take out pointless dev_dbg() call
[firefly-linux-kernel-4.4.55.git] / sound / soc / ux500 / ux500_pcm.c
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
15 #include <asm/page.h>
16
17 #include <linux/module.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/dmaengine.h>
20 #include <linux/slab.h>
21 #include <linux/platform_data/dma-ste-dma40.h>
22
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/dmaengine_pcm.h>
27
28 #include "ux500_msp_i2s.h"
29 #include "ux500_pcm.h"
30
31 #define UX500_PLATFORM_MIN_RATE 8000
32 #define UX500_PLATFORM_MAX_RATE 48000
33
34 #define UX500_PLATFORM_MIN_CHANNELS 1
35 #define UX500_PLATFORM_MAX_CHANNELS 8
36
37 #define UX500_PLATFORM_PERIODS_BYTES_MIN        128
38 #define UX500_PLATFORM_PERIODS_BYTES_MAX        (64 * PAGE_SIZE)
39 #define UX500_PLATFORM_PERIODS_MIN              2
40 #define UX500_PLATFORM_PERIODS_MAX              48
41 #define UX500_PLATFORM_BUFFER_BYTES_MAX         (2048 * PAGE_SIZE)
42
43 static const struct snd_pcm_hardware ux500_pcm_hw = {
44         .info = SNDRV_PCM_INFO_INTERLEAVED |
45                 SNDRV_PCM_INFO_MMAP |
46                 SNDRV_PCM_INFO_RESUME |
47                 SNDRV_PCM_INFO_PAUSE,
48         .formats = SNDRV_PCM_FMTBIT_S16_LE |
49                 SNDRV_PCM_FMTBIT_U16_LE |
50                 SNDRV_PCM_FMTBIT_S16_BE |
51                 SNDRV_PCM_FMTBIT_U16_BE,
52         .rates = SNDRV_PCM_RATE_KNOT,
53         .rate_min = UX500_PLATFORM_MIN_RATE,
54         .rate_max = UX500_PLATFORM_MAX_RATE,
55         .channels_min = UX500_PLATFORM_MIN_CHANNELS,
56         .channels_max = UX500_PLATFORM_MAX_CHANNELS,
57         .buffer_bytes_max = UX500_PLATFORM_BUFFER_BYTES_MAX,
58         .period_bytes_min = UX500_PLATFORM_PERIODS_BYTES_MIN,
59         .period_bytes_max = UX500_PLATFORM_PERIODS_BYTES_MAX,
60         .periods_min = UX500_PLATFORM_PERIODS_MIN,
61         .periods_max = UX500_PLATFORM_PERIODS_MAX,
62 };
63
64 static struct dma_chan *ux500_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
65         struct snd_pcm_substream *substream)
66 {
67         struct snd_soc_dai *dai = rtd->cpu_dai;
68         u16 per_data_width, mem_data_width;
69         struct stedma40_chan_cfg *dma_cfg;
70         struct ux500_msp_dma_params *dma_params;
71
72         dma_params = snd_soc_dai_get_dma_data(dai, substream);
73         dma_cfg = dma_params->dma_cfg;
74
75         mem_data_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
76
77         switch (dma_params->data_size) {
78         case 32:
79                 per_data_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
80                 break;
81         case 16:
82                 per_data_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
83                 break;
84         case 8:
85                 per_data_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
86                 break;
87         default:
88                 per_data_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
89         }
90
91         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
92                 dma_cfg->src_info.data_width = mem_data_width;
93                 dma_cfg->dst_info.data_width = per_data_width;
94         } else {
95                 dma_cfg->src_info.data_width = per_data_width;
96                 dma_cfg->dst_info.data_width = mem_data_width;
97         }
98
99         return snd_dmaengine_pcm_request_channel(stedma40_filter, dma_cfg);
100 }
101
102 static int ux500_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
103                 struct snd_pcm_hw_params *params,
104                 struct dma_slave_config *slave_config)
105 {
106         struct snd_soc_pcm_runtime *rtd = substream->private_data;
107         struct msp_i2s_platform_data *pdata = rtd->cpu_dai->dev->platform_data;
108         struct snd_dmaengine_dai_dma_data *snd_dma_params;
109         struct ux500_msp_dma_params *ste_dma_params;
110         dma_addr_t dma_addr;
111         int ret;
112
113         if (pdata) {
114                 ste_dma_params =
115                         snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
116                 dma_addr = ste_dma_params->tx_rx_addr;
117         } else {
118                 snd_dma_params =
119                         snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
120                 dma_addr = snd_dma_params->addr;
121         }
122
123         ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
124         if (ret)
125                 return ret;
126
127         slave_config->dst_maxburst = 4;
128         slave_config->src_maxburst = 4;
129
130         slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
131         slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
132
133         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
134                 slave_config->dst_addr = dma_addr;
135         else
136                 slave_config->src_addr = dma_addr;
137
138         return 0;
139 }
140
141 static const struct snd_dmaengine_pcm_config ux500_dmaengine_pcm_config = {
142         .pcm_hardware = &ux500_pcm_hw,
143         .compat_request_channel = ux500_pcm_request_chan,
144         .prealloc_buffer_size = 128 * 1024,
145         .prepare_slave_config = ux500_pcm_prepare_slave_config,
146 };
147
148 int ux500_pcm_register_platform(struct platform_device *pdev)
149 {
150         int ret;
151
152         ret = snd_dmaengine_pcm_register(&pdev->dev,
153                         &ux500_dmaengine_pcm_config,
154                         SND_DMAENGINE_PCM_FLAG_NO_RESIDUE |
155                         SND_DMAENGINE_PCM_FLAG_COMPAT |
156                         SND_DMAENGINE_PCM_FLAG_NO_DT);
157         if (ret < 0) {
158                 dev_err(&pdev->dev,
159                         "%s: ERROR: Failed to register platform '%s' (%d)!\n",
160                         __func__, pdev->name, ret);
161                 return ret;
162         }
163
164         return 0;
165 }
166 EXPORT_SYMBOL_GPL(ux500_pcm_register_platform);
167
168 int ux500_pcm_unregister_platform(struct platform_device *pdev)
169 {
170         snd_dmaengine_pcm_unregister(&pdev->dev);
171         return 0;
172 }
173 EXPORT_SYMBOL_GPL(ux500_pcm_unregister_platform);