Root/
Source at commit ef60fc3200a68f7ebd2a5a9fff585073f233bb5e created 14 years 3 months ago. By xiangfu, file | |
---|---|
1 | /* |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License version 2 as |
5 | * published by the Free Software Foundation. |
6 | */ |
7 | |
8 | #include <linux/module.h> |
9 | #include <linux/interrupt.h> |
10 | #include <linux/init.h> |
11 | #include <linux/platform_device.h> |
12 | #include <linux/slab.h> |
13 | #include <linux/dma-mapping.h> |
14 | |
15 | #include <sound/core.h> |
16 | #include <sound/pcm.h> |
17 | #include <sound/pcm_params.h> |
18 | #include <sound/soc.h> |
19 | |
20 | #include <asm/io.h> |
21 | #include "jz4740-pcm.h" |
22 | |
23 | static long sum_bytes = 0; |
24 | static int first_transfer = 0; |
25 | static int printk_flag = 0; |
26 | static int tran_bit = 0; |
27 | #ifdef CONFIG_SND_OSSEMUL |
28 | static int hw_params_cnt = 0; |
29 | #endif |
30 | |
31 | static struct jz4740_dma_client jz4740_dma_client_out = { |
32 | .name = "I2S PCM Stereo out" |
33 | }; |
34 | |
35 | static struct jz4740_dma_client jz4740_dma_client_in = { |
36 | .name = "I2S PCM Stereo in" |
37 | }; |
38 | |
39 | static struct jz4740_pcm_dma_params jz4740_i2s_pcm_stereo_out = { |
40 | .client = &jz4740_dma_client_out, |
41 | .channel = DMA_ID_AIC_TX, |
42 | .dma_addr = AIC_DR, |
43 | .dma_size = 2, |
44 | }; |
45 | |
46 | static struct jz4740_pcm_dma_params jz4740_i2s_pcm_stereo_in = { |
47 | .client = &jz4740_dma_client_in, |
48 | .channel = DMA_ID_AIC_RX, |
49 | .dma_addr = AIC_DR, |
50 | .dma_size = 2, |
51 | }; |
52 | |
53 | |
54 | struct jz4740_dma_buf_aic { |
55 | struct jz4740_dma_buf_aic *next; |
56 | int size; /* buffer size in bytes */ |
57 | dma_addr_t data; /* start of DMA data */ |
58 | dma_addr_t ptr; /* where the DMA got to [1] */ |
59 | void *id; /* client's id */ |
60 | }; |
61 | |
62 | struct jz4740_runtime_data { |
63 | spinlock_t lock; |
64 | int state; |
65 | int aic_dma_flag; /* start dma transfer or not */ |
66 | unsigned int dma_loaded; |
67 | unsigned int dma_limit; |
68 | unsigned int dma_period; |
69 | dma_addr_t dma_start; |
70 | dma_addr_t dma_pos; |
71 | dma_addr_t dma_end; |
72 | struct jz4740_pcm_dma_params *params; |
73 | |
74 | dma_addr_t user_cur_addr; /* user current write buffer start address */ |
75 | unsigned int user_cur_len; /* user current write buffer length */ |
76 | |
77 | /* buffer list and information */ |
78 | struct jz4740_dma_buf_aic *curr; /* current dma buffer */ |
79 | struct jz4740_dma_buf_aic *next; /* next buffer to load */ |
80 | struct jz4740_dma_buf_aic *end; /* end of queue */ |
81 | |
82 | }; |
83 | |
84 | /* identify hardware playback capabilities */ |
85 | static const struct snd_pcm_hardware jz4740_pcm_hardware = { |
86 | .info = SNDRV_PCM_INFO_MMAP | |
87 | SNDRV_PCM_INFO_MMAP_VALID | |
88 | SNDRV_PCM_INFO_INTERLEAVED | |
89 | SNDRV_PCM_INFO_BLOCK_TRANSFER, |
90 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
91 | SNDRV_PCM_FMTBIT_S8, |
92 | .rates = SNDRV_PCM_RATE_8000_48000/*0x3fe*/, |
93 | .rate_min = 8000, |
94 | .rate_min = 48000, |
95 | .channels_min = 2, |
96 | .channels_max = 2, |
97 | .buffer_bytes_max = 128 * 1024,//16 * 1024 |
98 | .period_bytes_min = PAGE_SIZE, |
99 | .period_bytes_max = PAGE_SIZE * 2, |
100 | .periods_min = 2, |
101 | .periods_max = 128,//16, |
102 | .fifo_size = 32, |
103 | }; |
104 | |
105 | /* jz4740__dma_buf_enqueue |
106 | * |
107 | * queue an given buffer for dma transfer. |
108 | * |
109 | * data the physical address of the buffer data |
110 | * size the size of the buffer in bytes |
111 | * |
112 | */ |
113 | static int jz4740_dma_buf_enqueue(struct jz4740_runtime_data *prtd, dma_addr_t data, int size) |
114 | { |
115 | struct jz4740_dma_buf_aic *aic_buf; |
116 | |
117 | aic_buf = kzalloc(sizeof(struct jz4740_dma_buf_aic), GFP_KERNEL); |
118 | if (aic_buf == NULL) { |
119 | printk("aic buffer allocate failed,no memory!\n"); |
120 | return -ENOMEM; |
121 | } |
122 | aic_buf->next = NULL; |
123 | aic_buf->data = aic_buf->ptr = data; |
124 | aic_buf->size = size; |
125 | if( prtd->curr == NULL) { |
126 | prtd->curr = aic_buf; |
127 | prtd->end = aic_buf; |
128 | prtd->next = NULL; |
129 | } else { |
130 | if (prtd->end == NULL) |
131 | printk("prtd->end is NULL\n"); |
132 | prtd->end->next = aic_buf; |
133 | prtd->end = aic_buf; |
134 | } |
135 | |
136 | /* if necessary, update the next buffer field */ |
137 | if (prtd->next == NULL) |
138 | prtd->next = aic_buf; |
139 | |
140 | return 0; |
141 | } |
142 | |
143 | |
144 | void audio_start_dma(struct jz4740_runtime_data *prtd, int mode) |
145 | { |
146 | unsigned long flags; |
147 | struct jz4740_dma_buf_aic *aic_buf; |
148 | int channel; |
149 | |
150 | switch (mode) { |
151 | case DMA_MODE_WRITE: |
152 | /* free cur aic_buf */ |
153 | if (first_transfer == 1) { |
154 | first_transfer = 0; |
155 | } else { |
156 | aic_buf = prtd->curr; |
157 | if (aic_buf != NULL) { |
158 | prtd->curr = aic_buf->next; |
159 | prtd->next = aic_buf->next; |
160 | aic_buf->next = NULL; |
161 | kfree(aic_buf); |
162 | aic_buf = NULL; |
163 | } |
164 | } |
165 | |
166 | aic_buf = prtd->next; |
167 | channel = prtd->params->channel; |
168 | if (aic_buf) { |
169 | disable_dma(channel); |
170 | jz_set_alsa_dma(channel, mode, tran_bit); |
171 | set_dma_addr(channel, aic_buf->data); |
172 | set_dma_count(channel, aic_buf->size); |
173 | enable_dma(channel); |
174 | prtd->aic_dma_flag |= AIC_START_DMA; |
175 | } else { |
176 | printk("next buffer is NULL for playback\n"); |
177 | prtd->aic_dma_flag &= ~AIC_START_DMA; |
178 | return; |
179 | } |
180 | break; |
181 | case DMA_MODE_READ: |
182 | /* free cur aic_buf */ |
183 | if (first_transfer == 1) { |
184 | first_transfer = 0; |
185 | } else { |
186 | aic_buf = prtd->curr; |
187 | if (aic_buf != NULL) { |
188 | prtd->curr = aic_buf->next; |
189 | prtd->next = aic_buf->next; |
190 | aic_buf->next = NULL; |
191 | kfree(aic_buf); |
192 | aic_buf = NULL; |
193 | } |
194 | } |
195 | |
196 | aic_buf = prtd->next; |
197 | channel = prtd->params->channel; |
198 | |
199 | if (aic_buf) { |
200 | disable_dma(channel); |
201 | jz_set_alsa_dma(channel, mode, tran_bit); |
202 | set_dma_addr(channel, aic_buf->data); |
203 | set_dma_count(channel, aic_buf->size); |
204 | enable_dma(channel); |
205 | prtd->aic_dma_flag |= AIC_START_DMA; |
206 | } else { |
207 | printk("next buffer is NULL for capture\n"); |
208 | prtd->aic_dma_flag &= ~AIC_START_DMA; |
209 | return; |
210 | } |
211 | break; |
212 | } |
213 | /* dump_jz_dma_channel(channel); */ |
214 | } |
215 | |
216 | /* |
217 | * place a dma buffer onto the queue for the dma system to handle. |
218 | */ |
219 | static void jz4740_pcm_enqueue(struct snd_pcm_substream *substream) |
220 | { |
221 | struct snd_pcm_runtime *runtime = substream->runtime; |
222 | struct jz4740_runtime_data *prtd = runtime->private_data; |
223 | /*struct snd_dma_buffer *buf = &substream->dma_buffer;*/ |
224 | dma_addr_t pos = prtd->dma_pos; |
225 | int ret; |
226 | |
227 | while (prtd->dma_loaded < prtd->dma_limit) { |
228 | unsigned long len = prtd->dma_period; |
229 | |
230 | if ((pos + len) > prtd->dma_end) { |
231 | len = prtd->dma_end - pos; |
232 | } |
233 | ret = jz4740_dma_buf_enqueue(prtd, pos, len); |
234 | if (ret == 0) { |
235 | prtd->dma_loaded++; |
236 | pos += prtd->dma_period; |
237 | if (pos >= prtd->dma_end) |
238 | pos = prtd->dma_start; |
239 | } else |
240 | break; |
241 | } |
242 | |
243 | prtd->dma_pos = pos; |
244 | } |
245 | |
246 | /* |
247 | * call the function:jz4740_pcm_dma_irq() after DMA has transfered the current buffer |
248 | */ |
249 | static irqreturn_t jz4740_pcm_dma_irq(int dma_ch, void *dev_id) |
250 | { |
251 | struct snd_pcm_substream *substream = dev_id; |
252 | struct snd_pcm_runtime *runtime = substream->runtime; |
253 | struct jz4740_runtime_data *prtd = runtime->private_data; |
254 | /*struct jz4740_dma_buf_aic *aic_buf = prtd->curr;*/ |
255 | int channel = prtd->params->channel; |
256 | unsigned long flags; |
257 | |
258 | disable_dma(channel); |
259 | prtd->aic_dma_flag &= ~AIC_START_DMA; |
260 | /* must clear TT bit in DCCSR to avoid interrupt again */ |
261 | if (__dmac_channel_transmit_end_detected(channel)) { |
262 | __dmac_channel_clear_transmit_end(channel); |
263 | } |
264 | if (__dmac_channel_transmit_halt_detected(channel)) { |
265 | __dmac_channel_clear_transmit_halt(channel); |
266 | } |
267 | |
268 | if (__dmac_channel_address_error_detected(channel)) { |
269 | __dmac_channel_clear_address_error(channel); |
270 | } |
271 | |
272 | if (substream) |
273 | snd_pcm_period_elapsed(substream); |
274 | |
275 | spin_lock(&prtd->lock); |
276 | prtd->dma_loaded--; |
277 | if (prtd->state & ST_RUNNING) { |
278 | jz4740_pcm_enqueue(substream); |
279 | } |
280 | spin_unlock(&prtd->lock); |
281 | |
282 | local_irq_save(flags); |
283 | if (prtd->state & ST_RUNNING) { |
284 | if (prtd->dma_loaded) { |
285 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
286 | audio_start_dma(prtd, DMA_MODE_WRITE); |
287 | else |
288 | audio_start_dma(prtd, DMA_MODE_READ); |
289 | } |
290 | } |
291 | local_irq_restore(flags); |
292 | return IRQ_HANDLED; |
293 | } |
294 | |
295 | /* some parameter about DMA operation */ |
296 | static int jz4740_pcm_hw_params(struct snd_pcm_substream *substream, |
297 | struct snd_pcm_hw_params *params) |
298 | { |
299 | struct snd_pcm_runtime *runtime = substream->runtime; |
300 | struct jz4740_runtime_data *prtd = runtime->private_data; |
301 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
302 | struct jz4740_pcm_dma_params *dma = &jz4740_i2s_pcm_stereo_out; |
303 | size_t totbytes = params_buffer_bytes(params); |
304 | int ret; |
305 | |
306 | if (!dma) |
307 | return 0; |
308 | |
309 | switch (params_format(params)) { |
310 | case SNDRV_PCM_FORMAT_S8: |
311 | tran_bit = 8; |
312 | break; |
313 | case SNDRV_PCM_FORMAT_S16_LE: |
314 | tran_bit = 16; |
315 | break; |
316 | } |
317 | |
318 | /* prepare DMA */ |
319 | prtd->params = dma; |
320 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
321 | ret = jz_request_dma(DMA_ID_AIC_TX, prtd->params->client->name, |
322 | jz4740_pcm_dma_irq, IRQF_DISABLED, substream); |
323 | if (ret < 0) |
324 | return ret; |
325 | prtd->params->channel = ret; |
326 | } else { |
327 | ret = jz_request_dma(DMA_ID_AIC_RX, prtd->params->client->name, |
328 | jz4740_pcm_dma_irq, IRQF_DISABLED, substream); |
329 | if (ret < 0) |
330 | return ret; |
331 | prtd->params->channel = ret; |
332 | } |
333 | |
334 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
335 | runtime->dma_bytes = totbytes; |
336 | |
337 | spin_lock_irq(&prtd->lock); |
338 | prtd->dma_loaded = 0; |
339 | prtd->aic_dma_flag = 0; |
340 | prtd->dma_limit = runtime->hw.periods_min; |
341 | prtd->dma_period = params_period_bytes(params); |
342 | prtd->dma_start = runtime->dma_addr; |
343 | prtd->dma_pos = prtd->dma_start; |
344 | prtd->dma_end = prtd->dma_start + totbytes; |
345 | prtd->curr = NULL; |
346 | prtd->next = NULL; |
347 | prtd->end = NULL; |
348 | sum_bytes = 0; |
349 | first_transfer = 1; |
350 | printk_flag = 0; |
351 | |
352 | __dmac_disable_descriptor(prtd->params->channel); |
353 | __dmac_channel_disable_irq(prtd->params->channel); |
354 | spin_unlock_irq(&prtd->lock); |
355 | return ret; |
356 | } |
357 | |
358 | static int jz4740_pcm_hw_free(struct snd_pcm_substream *substream) |
359 | { |
360 | struct jz4740_runtime_data *prtd = substream->runtime->private_data; |
361 | |
362 | snd_pcm_set_runtime_buffer(substream, NULL); |
363 | if (prtd->params) { |
364 | jz_free_dma(prtd->params->channel); |
365 | prtd->params = NULL; |
366 | } |
367 | |
368 | return 0; |
369 | } |
370 | |
371 | /* set some dma para for playback/capture */ |
372 | static int jz4740_dma_ctrl(int channel) |
373 | { |
374 | |
375 | disable_dma(channel); |
376 | |
377 | /* must clear TT bit in DCCSR to avoid interrupt again */ |
378 | if (__dmac_channel_transmit_end_detected(channel)) { |
379 | __dmac_channel_clear_transmit_end(channel); |
380 | } |
381 | if (__dmac_channel_transmit_halt_detected(channel)) { |
382 | __dmac_channel_clear_transmit_halt(channel); |
383 | } |
384 | |
385 | if (__dmac_channel_address_error_detected(channel)) { |
386 | __dmac_channel_clear_address_error(channel); |
387 | } |
388 | |
389 | return 0; |
390 | |
391 | } |
392 | |
393 | static int jz4740_pcm_prepare(struct snd_pcm_substream *substream) |
394 | { |
395 | struct jz4740_runtime_data *prtd = substream->runtime->private_data; |
396 | int ret = 0; |
397 | |
398 | /* return if this is a bufferless transfer e.g */ |
399 | if (!prtd->params) |
400 | return 0; |
401 | |
402 | /* flush the DMA channel and DMA channel bit check */ |
403 | jz4740_dma_ctrl(prtd->params->channel); |
404 | prtd->dma_loaded = 0; |
405 | prtd->dma_pos = prtd->dma_start; |
406 | |
407 | /* enqueue dma buffers */ |
408 | jz4740_pcm_enqueue(substream); |
409 | |
410 | return ret; |
411 | |
412 | } |
413 | |
414 | static int jz4740_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
415 | { |
416 | struct snd_pcm_runtime *runtime = substream->runtime; |
417 | struct jz4740_runtime_data *prtd = runtime->private_data; |
418 | |
419 | int ret = 0; |
420 | |
421 | switch (cmd) { |
422 | case SNDRV_PCM_TRIGGER_START: |
423 | prtd->state |= ST_RUNNING; |
424 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
425 | audio_start_dma(prtd, DMA_MODE_WRITE); |
426 | } else { |
427 | audio_start_dma(prtd, DMA_MODE_READ); |
428 | } |
429 | |
430 | break; |
431 | |
432 | case SNDRV_PCM_TRIGGER_STOP: |
433 | case SNDRV_PCM_TRIGGER_SUSPEND: |
434 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
435 | prtd->state &= ~ST_RUNNING; |
436 | break; |
437 | |
438 | case SNDRV_PCM_TRIGGER_RESUME: |
439 | printk(" RESUME \n"); |
440 | break; |
441 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
442 | printk(" RESTART \n"); |
443 | break; |
444 | |
445 | default: |
446 | ret = -EINVAL; |
447 | } |
448 | |
449 | return ret; |
450 | } |
451 | |
452 | static snd_pcm_uframes_t |
453 | jz4740_pcm_pointer(struct snd_pcm_substream *substream) |
454 | { |
455 | struct snd_pcm_runtime *runtime = substream->runtime; |
456 | struct jz4740_runtime_data *prtd = runtime->private_data; |
457 | struct jz4740_dma_buf_aic *aic_buf = prtd->curr; |
458 | long count,res; |
459 | |
460 | dma_addr_t ptr; |
461 | snd_pcm_uframes_t x; |
462 | int channel = prtd->params->channel; |
463 | |
464 | spin_lock(&prtd->lock); |
465 | #if 1 |
466 | |
467 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
468 | count = get_dma_residue(channel); |
469 | count = aic_buf->size - count; |
470 | ptr = aic_buf->data + count; |
471 | res = ptr - prtd->dma_start; |
472 | } else { |
473 | count = get_dma_residue(channel); |
474 | count = aic_buf->size - count; |
475 | ptr = aic_buf->data + count; |
476 | res = ptr - prtd->dma_start; |
477 | } |
478 | |
479 | # else |
480 | |
481 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
482 | if ((prtd->aic_dma_flag & AIC_START_DMA) == 0) { |
483 | count = get_dma_residue(channel); |
484 | count = aic_buf->size - count; |
485 | ptr = aic_buf->data + count; |
486 | REG_DMAC_DSAR(channel) = ptr; |
487 | res = ptr - prtd->dma_start; |
488 | } else { |
489 | ptr = REG_DMAC_DSAR(channel); |
490 | if (ptr == 0x0) |
491 | printk("\ndma address is 00000000 in running!\n"); |
492 | res = ptr - prtd->dma_start; |
493 | } |
494 | } else { |
495 | if ((prtd->aic_dma_flag & AIC_START_DMA) == 0) { |
496 | count = get_dma_residue(channel); |
497 | count = aic_buf->size - count; |
498 | ptr = aic_buf->data + count; |
499 | REG_DMAC_DTAR(channel) = ptr; |
500 | res = ptr - prtd->dma_start; |
501 | } else { |
502 | ptr = REG_DMAC_DTAR(channel); |
503 | if (ptr == 0x0) |
504 | printk("\ndma address is 00000000 in running!\n"); |
505 | res = ptr - prtd->dma_start; |
506 | } |
507 | } |
508 | #endif |
509 | spin_unlock(&prtd->lock); |
510 | x = bytes_to_frames(runtime, res); |
511 | if (x == runtime->buffer_size) |
512 | x = 0; |
513 | |
514 | return x; |
515 | } |
516 | |
517 | static int jz4740_pcm_open(struct snd_pcm_substream *substream) |
518 | { |
519 | struct snd_pcm_runtime *runtime = substream->runtime; |
520 | struct jz4740_runtime_data *prtd; |
521 | |
522 | #ifdef CONFIG_SND_OSSEMUL |
523 | hw_params_cnt = 0; |
524 | #endif |
525 | snd_soc_set_runtime_hwparams(substream, &jz4740_pcm_hardware); |
526 | prtd = kzalloc(sizeof(struct jz4740_runtime_data), GFP_KERNEL); |
527 | if (prtd == NULL) |
528 | return -ENOMEM; |
529 | |
530 | spin_lock_init(&prtd->lock); |
531 | |
532 | runtime->private_data = prtd; |
533 | REG_AIC_I2SCR = 0x10; |
534 | return 0; |
535 | } |
536 | |
537 | static int jz4740_pcm_close(struct snd_pcm_substream *substream) |
538 | { |
539 | struct snd_pcm_runtime *runtime = substream->runtime; |
540 | struct jz4740_runtime_data *prtd = runtime->private_data; |
541 | struct jz4740_dma_buf_aic *aic_buf = NULL; |
542 | |
543 | #ifdef CONFIG_SND_OSSEMUL |
544 | hw_params_cnt = 0; |
545 | #endif |
546 | |
547 | if (prtd) |
548 | aic_buf = prtd->curr; |
549 | |
550 | while (aic_buf != NULL) { |
551 | prtd->curr = aic_buf->next; |
552 | prtd->next = aic_buf->next; |
553 | aic_buf->next = NULL; |
554 | kfree(aic_buf); |
555 | aic_buf = NULL; |
556 | aic_buf = prtd->curr; |
557 | } |
558 | |
559 | if (prtd) { |
560 | prtd->curr = NULL; |
561 | prtd->next = NULL; |
562 | prtd->end = NULL; |
563 | kfree(prtd); |
564 | } |
565 | |
566 | return 0; |
567 | } |
568 | |
569 | static int jz4740_pcm_mmap(struct snd_pcm_substream *substream, |
570 | struct vm_area_struct *vma) |
571 | { |
572 | struct snd_pcm_runtime *runtime = substream->runtime; |
573 | |
574 | return remap_pfn_range(vma, vma->vm_start, |
575 | substream->dma_buffer.addr >> PAGE_SHIFT, |
576 | vma->vm_end - vma->vm_start, vma->vm_page_prot); |
577 | } |
578 | |
579 | struct snd_pcm_ops jz4740_pcm_ops = { |
580 | .open = jz4740_pcm_open, |
581 | .close = jz4740_pcm_close, |
582 | .ioctl = snd_pcm_lib_ioctl, |
583 | .hw_params = jz4740_pcm_hw_params, |
584 | .hw_free = jz4740_pcm_hw_free, |
585 | .prepare = jz4740_pcm_prepare, |
586 | .trigger = jz4740_pcm_trigger, |
587 | .pointer = jz4740_pcm_pointer, |
588 | .mmap = jz4740_pcm_mmap, |
589 | }; |
590 | |
591 | static int jz4740_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) |
592 | { |
593 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; |
594 | struct snd_dma_buffer *buf = &substream->dma_buffer; |
595 | size_t size = jz4740_pcm_hardware.buffer_bytes_max; |
596 | buf->dev.type = SNDRV_DMA_TYPE_DEV; |
597 | buf->dev.dev = pcm->card->dev; |
598 | buf->private_data = NULL; |
599 | |
600 | /*buf->area = dma_alloc_coherent(pcm->card->dev, size, |
601 | &buf->addr, GFP_KERNEL);*/ |
602 | buf->area = dma_alloc_noncoherent(pcm->card->dev, size, |
603 | &buf->addr, GFP_KERNEL); |
604 | if (!buf->area) |
605 | return -ENOMEM; |
606 | buf->bytes = size; |
607 | return 0; |
608 | } |
609 | |
610 | static void jz4740_pcm_free_dma_buffers(struct snd_pcm *pcm) |
611 | { |
612 | struct snd_pcm_substream *substream; |
613 | struct snd_dma_buffer *buf; |
614 | int stream; |
615 | |
616 | for (stream = 0; stream < 2; stream++) { |
617 | substream = pcm->streams[stream].substream; |
618 | if (!substream) |
619 | continue; |
620 | |
621 | buf = &substream->dma_buffer; |
622 | if (!buf->area) |
623 | continue; |
624 | |
625 | dma_free_noncoherent(pcm->card->dev, buf->bytes, |
626 | buf->area, buf->addr); |
627 | buf->area = NULL; |
628 | } |
629 | } |
630 | |
631 | static u64 jz4740_pcm_dmamask = DMA_BIT_MASK(32); |
632 | |
633 | int jz4740_pcm_new(struct snd_card *card, struct snd_soc_dai *dai, |
634 | struct snd_pcm *pcm) |
635 | { |
636 | int ret = 0; |
637 | |
638 | printk("pcm new\n"); |
639 | |
640 | if (!card->dev->dma_mask) |
641 | card->dev->dma_mask = &jz4740_pcm_dmamask; |
642 | if (!card->dev->coherent_dma_mask) |
643 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); |
644 | |
645 | if (dai->playback.channels_min) { |
646 | ret = jz4740_pcm_preallocate_dma_buffer(pcm, |
647 | SNDRV_PCM_STREAM_PLAYBACK); |
648 | if (ret) |
649 | goto out; |
650 | } |
651 | |
652 | if (dai->capture.channels_min) { |
653 | ret = jz4740_pcm_preallocate_dma_buffer(pcm, |
654 | SNDRV_PCM_STREAM_CAPTURE); |
655 | if (ret) |
656 | goto out; |
657 | } |
658 | out: |
659 | |
660 | return ret; |
661 | } |
662 | |
663 | struct snd_soc_platform jz4740_soc_platform = { |
664 | .name = "jz4740-audio", |
665 | .pcm_ops = &jz4740_pcm_ops, |
666 | .pcm_new = jz4740_pcm_new, |
667 | .pcm_free = jz4740_pcm_free_dma_buffers, |
668 | }; |
669 | |
670 | EXPORT_SYMBOL_GPL(jz4740_soc_platform); |
671 | |
672 | static int __init jz4740_soc_platform_init(void) |
673 | { |
674 | return snd_soc_register_platform(&jz4740_soc_platform); |
675 | } |
676 | module_init(jz4740_soc_platform_init); |
677 | |
678 | static void __exit jz4740_soc_platform_exit(void) |
679 | { |
680 | snd_soc_unregister_platform(&jz4740_soc_platform); |
681 | } |
682 | module_exit(jz4740_soc_platform_exit); |
683 | |
684 | MODULE_AUTHOR("Richard"); |
685 | MODULE_DESCRIPTION("Ingenic Jz4740 PCM DMA module"); |
686 | MODULE_LICENSE("GPL"); |
687 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9