aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/fsl
diff options
context:
space:
mode:
authorShengjiu Wang <b02247@freescale.com>2014-04-17 03:32:12 -0400
committerNitin Garg <nitin.garg@freescale.com>2014-04-17 22:19:16 -0400
commit85230971c5e685e688f2d5446f01a723ba617488 (patch)
tree1985b87ef5cf6119866453cf94526a606b155758 /sound/soc/fsl
parent0924629b0c90d8060cd135058aafb3877a57c562 (diff)
ENGR00309073-2 ASoC: fsl: Add new p2p struct for code ligibility
improve code ligibility. Signed-off-by: Shengjiu Wang <b02247@freescale.com>
Diffstat (limited to 'sound/soc/fsl')
-rw-r--r--sound/soc/fsl/fsl_asrc.c85
-rw-r--r--sound/soc/fsl/fsl_asrc.h13
2 files changed, 55 insertions, 43 deletions
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 8d68f5a7468e..2d801cd66c1a 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -49,12 +49,12 @@ static int asrc_p2p_request_channel(struct snd_pcm_substream *substream)
49 struct snd_dmaengine_dai_dma_data *dma_params_fe = NULL; 49 struct snd_dmaengine_dai_dma_data *dma_params_fe = NULL;
50 struct imx_dma_data *fe_filter_data = NULL; 50 struct imx_dma_data *fe_filter_data = NULL;
51 struct imx_dma_data *be_filter_data = NULL; 51 struct imx_dma_data *be_filter_data = NULL;
52 52 struct fsl_asrc_p2p_params *p2p_params = &asrc_p2p->p2p_params[substream->stream];
53 enum asrc_pair_index asrc_index = p2p_params->asrc_index;
53 struct dma_slave_config slave_config; 54 struct dma_slave_config slave_config;
54 dma_cap_mask_t mask; 55 dma_cap_mask_t mask;
55 struct dma_chan *chan;
56 int ret;
57 struct snd_soc_dpcm *dpcm; 56 struct snd_soc_dpcm *dpcm;
57 int ret;
58 58
59 /* find the be for this fe stream */ 59 /* find the be for this fe stream */
60 list_for_each_entry(dpcm, &rtd->dpcm[substream->stream].be_clients, list_be) { 60 list_for_each_entry(dpcm, &rtd->dpcm[substream->stream].be_clients, list_be) {
@@ -80,6 +80,10 @@ static int asrc_p2p_request_channel(struct snd_pcm_substream *substream)
80 80
81 fe_filter_data = dma_params_fe->filter_data; 81 fe_filter_data = dma_params_fe->filter_data;
82 be_filter_data = dma_params_be->filter_data; 82 be_filter_data = dma_params_be->filter_data;
83 if (!fe_filter_data || !be_filter_data) {
84 dev_err(rtd->card->dev, "can't get be or fe filter data\n");
85 return -EINVAL;
86 }
83 87
84 if (asrc_p2p->p2p_width == 16) 88 if (asrc_p2p->p2p_width == 16)
85 buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; 89 buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
@@ -87,48 +91,43 @@ static int asrc_p2p_request_channel(struct snd_pcm_substream *substream)
87 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; 91 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
88 92
89 /* reconfig memory to FIFO dma request */ 93 /* reconfig memory to FIFO dma request */
90 dma_params_fe->addr = asrc_p2p->asrc_ops.asrc_p2p_per_addr( 94 dma_params_fe->addr = asrc_p2p->asrc_ops.asrc_p2p_per_addr(asrc_index, 1);
91 asrc_p2p->asrc_index, 1);
92 fe_filter_data->dma_request0 = asrc_p2p->dmarx[asrc_p2p->asrc_index];
93 dma_params_fe->maxburst = dma_params_be->maxburst; 95 dma_params_fe->maxburst = dma_params_be->maxburst;
96 fe_filter_data->dma_request0 = asrc_p2p->dmarx[asrc_index];
94 97
95 dma_cap_zero(mask); 98 dma_cap_zero(mask);
96 dma_cap_set(DMA_SLAVE, mask); 99 dma_cap_set(DMA_SLAVE, mask);
97 dma_cap_set(DMA_CYCLIC, mask); 100 dma_cap_set(DMA_CYCLIC, mask);
98 101
99 /* config p2p dma channel */ 102 /* config p2p dma channel */
100 asrc_p2p->asrc_p2p_dma_data.peripheral_type = IMX_DMATYPE_ASRC; 103 p2p_params->dma_data.peripheral_type = IMX_DMATYPE_ASRC;
101 asrc_p2p->asrc_p2p_dma_data.priority = DMA_PRIO_HIGH; 104 p2p_params->dma_data.priority = DMA_PRIO_HIGH;
102 asrc_p2p->asrc_p2p_dma_data.dma_request1 = asrc_p2p->dmatx[asrc_p2p->asrc_index]; 105 p2p_params->dma_data.dma_request1 = asrc_p2p->dmatx[asrc_index];
103 /* need to get target device's dma dma_addr, burstsize */ 106 /* need to get target device's dma dma_addr, burstsize */
104 asrc_p2p->asrc_p2p_dma_data.dma_request0 = be_filter_data->dma_request0; 107 p2p_params->dma_data.dma_request0 = be_filter_data->dma_request0;
105 108
106 /* Request channel */ 109 /* Request channel */
107 asrc_p2p->asrc_p2p_dma_chan = 110 p2p_params->dma_chan = dma_request_channel(mask, filter, &p2p_params->dma_data);
108 dma_request_channel(mask, filter, &asrc_p2p->asrc_p2p_dma_data); 111 if (!p2p_params->dma_chan) {
109
110 if (!asrc_p2p->asrc_p2p_dma_chan) {
111 dev_err(rtd->card->dev, "can not request dma channel\n"); 112 dev_err(rtd->card->dev, "can not request dma channel\n");
112 goto error; 113 goto error;
113 } 114 }
114 chan = asrc_p2p->asrc_p2p_dma_chan;
115 115
116 /* 116 /*
117 * Buswidth is not used in the sdma for p2p. Here we set the maxburst fix to 117 * Buswidth is not used in the sdma for p2p. Here we set the maxburst fix to
118 * twice of dma_params's burstsize. 118 * twice of dma_params's burstsize.
119 */ 119 */
120 slave_config.direction = DMA_DEV_TO_DEV; 120 slave_config.direction = DMA_DEV_TO_DEV;
121 slave_config.src_addr = asrc_p2p->asrc_ops.asrc_p2p_per_addr(asrc_p2p->asrc_index, 0); 121 slave_config.src_addr = asrc_p2p->asrc_ops.asrc_p2p_per_addr(asrc_index, 0);
122 slave_config.src_addr_width = buswidth; 122 slave_config.src_addr_width = buswidth;
123 slave_config.src_maxburst = dma_params_be->maxburst * 2; 123 slave_config.src_maxburst = dma_params_be->maxburst * 2;
124 slave_config.dst_addr = dma_params_be->addr; 124 slave_config.dst_addr = dma_params_be->addr;
125 slave_config.dst_addr_width = buswidth; 125 slave_config.dst_addr_width = buswidth;
126 slave_config.dst_maxburst = dma_params_be->maxburst * 2; 126 slave_config.dst_maxburst = dma_params_be->maxburst * 2;
127 slave_config.dma_request0 = be_filter_data->dma_request0; 127 slave_config.dma_request0 = be_filter_data->dma_request0;
128 slave_config.dma_request1 = asrc_p2p->dmatx[asrc_p2p->asrc_index]; 128 slave_config.dma_request1 = asrc_p2p->dmatx[asrc_index];
129 129
130 ret = dmaengine_slave_config(asrc_p2p->asrc_p2p_dma_chan, 130 ret = dmaengine_slave_config(p2p_params->dma_chan, &slave_config);
131 &slave_config);
132 if (ret) { 131 if (ret) {
133 dev_err(rtd->card->dev, "can not config dma channel\n"); 132 dev_err(rtd->card->dev, "can not config dma channel\n");
134 goto error; 133 goto error;
@@ -136,9 +135,9 @@ static int asrc_p2p_request_channel(struct snd_pcm_substream *substream)
136 135
137 return 0; 136 return 0;
138error: 137error:
139 if (asrc_p2p->asrc_p2p_dma_chan) { 138 if (p2p_params->dma_chan) {
140 dma_release_channel(asrc_p2p->asrc_p2p_dma_chan); 139 dma_release_channel(p2p_params->dma_chan);
141 asrc_p2p->asrc_p2p_dma_chan = NULL; 140 p2p_params->dma_chan = NULL;
142 } 141 }
143 142
144 return -EINVAL; 143 return -EINVAL;
@@ -150,6 +149,7 @@ static int config_asrc(struct snd_pcm_substream *substream,
150 struct snd_soc_pcm_runtime *rtd = substream->private_data; 149 struct snd_soc_pcm_runtime *rtd = substream->private_data;
151 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 150 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
152 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai); 151 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai);
152 struct fsl_asrc_p2p_params *p2p_params = &asrc_p2p->p2p_params[substream->stream];
153 unsigned int rate = params_rate(params); 153 unsigned int rate = params_rate(params);
154 unsigned int channel = params_channels(params); 154 unsigned int channel = params_channels(params);
155 struct asrc_config config = {0}; 155 struct asrc_config config = {0};
@@ -161,7 +161,7 @@ static int config_asrc(struct snd_pcm_substream *substream,
161 return -EINVAL; 161 return -EINVAL;
162 } 162 }
163 163
164 ret = asrc_p2p->asrc_ops.asrc_p2p_req_pair(channel, &asrc_p2p->asrc_index); 164 ret = asrc_p2p->asrc_ops.asrc_p2p_req_pair(channel, &p2p_params->asrc_index);
165 if (ret < 0) { 165 if (ret < 0) {
166 dev_err(cpu_dai->dev, "Fail to request asrc pair\n"); 166 dev_err(cpu_dai->dev, "Fail to request asrc pair\n");
167 return -EINVAL; 167 return -EINVAL;
@@ -201,12 +201,11 @@ static int config_asrc(struct snd_pcm_substream *substream,
201 201
202 config.input_word_width = word_width; 202 config.input_word_width = word_width;
203 config.output_word_width = p2p_word_width; 203 config.output_word_width = p2p_word_width;
204 config.pair = asrc_p2p->asrc_index; 204 config.pair = p2p_params->asrc_index;
205 config.channel_num = channel; 205 config.channel_num = channel;
206 config.input_sample_rate = rate; 206 config.input_sample_rate = rate;
207 config.output_sample_rate = asrc_p2p->p2p_rate; 207 config.output_sample_rate = asrc_p2p->p2p_rate;
208 config.inclk = INCLK_NONE; 208 config.inclk = INCLK_NONE;
209
210 switch (asrc_p2p->per_dev) { 209 switch (asrc_p2p->per_dev) {
211 case SSI1: 210 case SSI1:
212 config.outclk = OUTCLK_SSI1_TX; 211 config.outclk = OUTCLK_SSI1_TX;
@@ -251,18 +250,21 @@ static int fsl_asrc_p2p_hw_free(struct snd_pcm_substream *substream,
251 struct snd_soc_dai *cpu_dai) 250 struct snd_soc_dai *cpu_dai)
252{ 251{
253 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai); 252 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai);
253 struct fsl_asrc_p2p_params *p2p_params = &asrc_p2p->p2p_params[substream->stream];
254 struct dma_chan *chan = p2p_params->dma_chan;
255 enum asrc_pair_index asrc_index = p2p_params->asrc_index;
254 256
255 if (asrc_p2p->asrc_p2p_dma_chan) { 257 if (chan) {
256 /* Release p2p dma resource */ 258 /* Release p2p dma resource */
257 dma_release_channel(asrc_p2p->asrc_p2p_dma_chan); 259 dma_release_channel(chan);
258 asrc_p2p->asrc_p2p_dma_chan = NULL; 260 p2p_params->dma_chan = NULL;
259 } 261 }
260 262
261 if (asrc_p2p->asrc_index != -1) { 263 if (asrc_index != -1) {
262 asrc_p2p->asrc_ops.asrc_p2p_release_pair(asrc_p2p->asrc_index); 264 asrc_p2p->asrc_ops.asrc_p2p_release_pair(asrc_index);
263 asrc_p2p->asrc_ops.asrc_p2p_finish_conv(asrc_p2p->asrc_index); 265 asrc_p2p->asrc_ops.asrc_p2p_finish_conv(asrc_index);
266 p2p_params->asrc_index = -1;
264 } 267 }
265 asrc_p2p->asrc_index = -1;
266 268
267 return 0; 269 return 0;
268} 270}
@@ -270,8 +272,9 @@ static int fsl_asrc_p2p_hw_free(struct snd_pcm_substream *substream,
270static int fsl_asrc_dma_prepare_and_submit(struct snd_pcm_substream *substream, 272static int fsl_asrc_dma_prepare_and_submit(struct snd_pcm_substream *substream,
271 struct fsl_asrc_p2p *asrc_p2p) 273 struct fsl_asrc_p2p *asrc_p2p)
272{ 274{
273 struct dma_async_tx_descriptor *desc = asrc_p2p->asrc_p2p_desc; 275 struct fsl_asrc_p2p_params *p2p_params = &asrc_p2p->p2p_params[substream->stream];
274 struct dma_chan *chan = asrc_p2p->asrc_p2p_dma_chan; 276 struct dma_chan *chan = p2p_params->dma_chan;
277 struct dma_async_tx_descriptor *desc = p2p_params->desc;
275 struct snd_soc_pcm_runtime *rtd = substream->private_data; 278 struct snd_soc_pcm_runtime *rtd = substream->private_data;
276 struct device *dev = rtd->platform->dev; 279 struct device *dev = rtd->platform->dev;
277 280
@@ -290,6 +293,9 @@ static int fsl_asrc_p2p_trigger(struct snd_pcm_substream *substream, int cmd,
290 struct snd_soc_dai *cpu_dai) 293 struct snd_soc_dai *cpu_dai)
291{ 294{
292 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai); 295 struct fsl_asrc_p2p *asrc_p2p = snd_soc_dai_get_drvdata(cpu_dai);
296 struct fsl_asrc_p2p_params *p2p_params = &asrc_p2p->p2p_params[substream->stream];
297 struct dma_chan *chan = p2p_params->dma_chan;
298 enum asrc_pair_index asrc_index = p2p_params->asrc_index;
293 int ret; 299 int ret;
294 300
295 switch (cmd) { 301 switch (cmd) {
@@ -299,8 +305,8 @@ static int fsl_asrc_p2p_trigger(struct snd_pcm_substream *substream, int cmd,
299 ret = fsl_asrc_dma_prepare_and_submit(substream, asrc_p2p); 305 ret = fsl_asrc_dma_prepare_and_submit(substream, asrc_p2p);
300 if (ret) 306 if (ret)
301 return ret; 307 return ret;
302 dma_async_issue_pending(asrc_p2p->asrc_p2p_dma_chan); 308 dma_async_issue_pending(chan);
303 asrc_p2p->asrc_ops.asrc_p2p_start_conv(asrc_p2p->asrc_index); 309 asrc_p2p->asrc_ops.asrc_p2p_start_conv(asrc_index);
304 310
305 /* Output enough data to content the DMA burstsize of BE */ 311 /* Output enough data to content the DMA burstsize of BE */
306 mdelay(1); 312 mdelay(1);
@@ -308,8 +314,8 @@ static int fsl_asrc_p2p_trigger(struct snd_pcm_substream *substream, int cmd,
308 case SNDRV_PCM_TRIGGER_SUSPEND: 314 case SNDRV_PCM_TRIGGER_SUSPEND:
309 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 315 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
310 case SNDRV_PCM_TRIGGER_STOP: 316 case SNDRV_PCM_TRIGGER_STOP:
311 dmaengine_terminate_all(asrc_p2p->asrc_p2p_dma_chan); 317 dmaengine_terminate_all(chan);
312 asrc_p2p->asrc_ops.asrc_p2p_stop_conv(asrc_p2p->asrc_index); 318 asrc_p2p->asrc_ops.asrc_p2p_stop_conv(asrc_index);
313 break; 319 break;
314 default: 320 default:
315 return -EINVAL; 321 return -EINVAL;
@@ -491,7 +497,8 @@ static int fsl_asrc_p2p_probe(struct platform_device *pdev)
491 asrc_p2p->asrc_ops.asrc_p2p_release_pair = asrc_release_pair; 497 asrc_p2p->asrc_ops.asrc_p2p_release_pair = asrc_release_pair;
492 asrc_p2p->asrc_ops.asrc_p2p_finish_conv = asrc_finish_conv; 498 asrc_p2p->asrc_ops.asrc_p2p_finish_conv = asrc_finish_conv;
493 499
494 asrc_p2p->asrc_index = -1; 500 asrc_p2p->p2p_params[0].asrc_index = -1;
501 asrc_p2p->p2p_params[1].asrc_index = -1;
495 502
496 iprop_rate = of_get_property(np, "fsl,p2p-rate", NULL); 503 iprop_rate = of_get_property(np, "fsl,p2p-rate", NULL);
497 if (iprop_rate) 504 if (iprop_rate)
diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h
index 857f7f0f93a7..fc518f12c553 100644
--- a/sound/soc/fsl/fsl_asrc.h
+++ b/sound/soc/fsl/fsl_asrc.h
@@ -22,10 +22,16 @@ enum peripheral_device_type {
22 ESAI, 22 ESAI,
23}; 23};
24 24
25struct fsl_asrc_p2p_params {
26 enum asrc_pair_index asrc_index;
27 struct dma_async_tx_descriptor *desc;
28 struct dma_chan *dma_chan;
29 struct imx_dma_data dma_data;
30};
31
25struct fsl_asrc_p2p { 32struct fsl_asrc_p2p {
26 int p2p_rate; 33 int p2p_rate;
27 int p2p_width; 34 int p2p_width;
28 enum asrc_pair_index asrc_index;
29 enum peripheral_device_type per_dev; 35 enum peripheral_device_type per_dev;
30 struct asrc_p2p_ops asrc_ops; 36 struct asrc_p2p_ops asrc_ops;
31 37
@@ -35,9 +41,8 @@ struct fsl_asrc_p2p {
35 struct imx_dma_data filter_data_rx; 41 struct imx_dma_data filter_data_rx;
36 struct snd_pcm_substream *substream[2]; 42 struct snd_pcm_substream *substream[2];
37 43
38 struct dma_async_tx_descriptor *asrc_p2p_desc; 44 /* playback and record p2p params */
39 struct dma_chan *asrc_p2p_dma_chan; 45 struct fsl_asrc_p2p_params p2p_params[2];
40 struct imx_dma_data asrc_p2p_dma_data;
41 struct platform_device *soc_platform_pdev; 46 struct platform_device *soc_platform_pdev;
42 47
43 int dmarx[3]; 48 int dmarx[3];