1 /* linux/arch/arm/mach-msm/qdsp5/audio_amrnb.c
3 * amrnb audio decoder device
5 * Copyright (c) 2008 QUALCOMM USA, INC.
7 * Based on the mp3 native driver in arch/arm/mach-msm/qdsp5/audio_mp3.c
9 * Copyright (C) 2008 Google, Inc.
10 * Copyright (C) 2008 HTC Corporation
12 * All source code in this file is licensed under the following license except
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License version 2 as published
17 * by the Free Software Foundation.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, you can find it at http://www.fsf.org
28 #include <linux/module.h>
30 #include <linux/miscdevice.h>
31 #include <linux/uaccess.h>
32 #include <linux/kthread.h>
33 #include <linux/wait.h>
34 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
38 #include <asm/atomic.h>
39 #include <asm/ioctls.h>
40 #include <mach/msm_adsp.h>
41 #include <linux/msm_audio.h>
44 #include <mach/qdsp5/qdsp5audppcmdi.h>
45 #include <mach/qdsp5/qdsp5audppmsg.h>
46 #include <mach/qdsp5/qdsp5audplaycmdi.h>
47 #include <mach/qdsp5/qdsp5audplaymsg.h>
49 /* for queue ids - should be relative to module number*/
54 #define dprintk(format, arg...) \
55 printk(KERN_DEBUG format, ## arg)
57 #define dprintk(format, arg...) do {} while (0)
60 #define BUFSZ 1024 /* Hold minimum 700ms voice data */
61 #define DMASZ (BUFSZ * 2)
63 #define AUDPLAY_INVALID_READ_PTR_OFFSET 0xFFFF
64 #define AUDDEC_DEC_AMRNB 10
66 #define PCM_BUFSZ_MIN 1600 /* 100ms worth of data */
67 #define AMRNB_DECODED_FRSZ 320 /* AMR-NB 20ms 8KHz mono PCM size */
68 #define PCM_BUF_MAX_COUNT 5 /* DSP only accepts 5 buffers at most
69 but support 2 buffers currently */
70 #define ROUTING_MODE_FTRT 1
71 #define ROUTING_MODE_RT 2
72 /* Decoder status received from AUDPPTASK */
73 #define AUDPP_DEC_STATUS_SLEEP 0
74 #define AUDPP_DEC_STATUS_INIT 1
75 #define AUDPP_DEC_STATUS_CFG 2
76 #define AUDPP_DEC_STATUS_PLAY 3
81 unsigned used
; /* Input usage actual DSP produced PCM size */
92 uint8_t out_needed
; /* number of buffers the dsp is waiting for */
97 struct mutex write_lock
;
98 wait_queue_head_t write_wait
;
100 /* Host PCM section */
101 struct buffer in
[PCM_BUF_MAX_COUNT
];
102 struct mutex read_lock
;
103 wait_queue_head_t read_wait
; /* Wait queue for read */
104 char *read_data
; /* pointer to reader buffer */
105 dma_addr_t read_phys
; /* physical address of reader buffer */
106 uint8_t read_next
; /* index to input buffers to be read next */
107 uint8_t fill_next
; /* index to buffer that DSP should be filling */
108 uint8_t pcm_buf_count
; /* number of pcm buffer allocated */
109 /* ---- End of Host PCM section */
111 struct msm_adsp_module
*audplay
;
113 struct audmgr audmgr
;
115 /* data allocated for various buffers */
122 uint8_t stopped
:1; /* set when stopped, cleared on flush */
123 uint8_t pcm_feedback
:1;
124 uint8_t buf_refresh
:1;
129 uint32_t read_ptr_offset
;
132 struct audpp_cmd_cfg_adec_params_amrnb
{
133 audpp_cmd_cfg_adec_params_common common
;
134 unsigned short stereo_cfg
;
135 } __attribute__((packed
)) ;
137 static int auddec_dsp_config(struct audio
*audio
, int enable
);
138 static void audpp_cmd_cfg_adec_params(struct audio
*audio
);
139 static void audpp_cmd_cfg_routing_mode(struct audio
*audio
);
140 static void audamrnb_send_data(struct audio
*audio
, unsigned needed
);
141 static void audamrnb_config_hostpcm(struct audio
*audio
);
142 static void audamrnb_buffer_refresh(struct audio
*audio
);
143 static void audamrnb_dsp_event(void *private, unsigned id
, uint16_t *msg
);
145 /* must be called with audio->lock held */
146 static int audamrnb_enable(struct audio
*audio
)
148 struct audmgr_config cfg
;
151 dprintk("audamrnb_enable()\n");
157 audio
->out_needed
= 0;
159 cfg
.tx_rate
= RPC_AUD_DEF_SAMPLE_RATE_NONE
;
160 cfg
.rx_rate
= RPC_AUD_DEF_SAMPLE_RATE_48000
;
161 cfg
.def_method
= RPC_AUD_DEF_METHOD_PLAYBACK
;
162 cfg
.codec
= RPC_AUD_DEF_CODEC_AMR_NB
;
163 cfg
.snd_method
= RPC_SND_METHOD_MIDI
;
165 rc
= audmgr_enable(&audio
->audmgr
, &cfg
);
169 if (msm_adsp_enable(audio
->audplay
)) {
170 pr_err("audio: msm_adsp_enable(audplay) failed\n");
171 audmgr_disable(&audio
->audmgr
);
175 if (audpp_enable(audio
->dec_id
, audamrnb_dsp_event
, audio
)) {
176 pr_err("audio: audpp_enable() failed\n");
177 msm_adsp_disable(audio
->audplay
);
178 audmgr_disable(&audio
->audmgr
);
185 /* must be called with audio->lock held */
186 static int audamrnb_disable(struct audio
*audio
)
188 dprintk("audamrnb_disable()\n");
189 if (audio
->enabled
) {
191 auddec_dsp_config(audio
, 0);
192 wake_up(&audio
->write_wait
);
193 wake_up(&audio
->read_wait
);
194 msm_adsp_disable(audio
->audplay
);
195 audpp_disable(audio
->dec_id
, audio
);
196 audmgr_disable(&audio
->audmgr
);
197 audio
->out_needed
= 0;
202 /* ------------------- dsp --------------------- */
203 static void audamrnb_update_pcm_buf_entry(struct audio
*audio
,
209 spin_lock_irqsave(&audio
->dsp_lock
, flags
);
210 for (index
= 0; index
< payload
[1]; index
++) {
211 if (audio
->in
[audio
->fill_next
].addr
==
212 payload
[2 + index
* 2]) {
213 dprintk("audamrnb_update_pcm_buf_entry: in[%d] ready\n",
215 audio
->in
[audio
->fill_next
].used
=
216 payload
[3 + index
* 2];
217 if ((++audio
->fill_next
) == audio
->pcm_buf_count
)
218 audio
->fill_next
= 0;
222 ("audamrnb_update_pcm_buf_entry: expected=%x ret=%x\n"
223 , audio
->in
[audio
->fill_next
].addr
,
224 payload
[1 + index
* 2]);
228 if (audio
->in
[audio
->fill_next
].used
== 0) {
229 audamrnb_buffer_refresh(audio
);
231 dprintk("audamrnb_update_pcm_buf_entry: read cannot keep up\n");
232 audio
->buf_refresh
= 1;
235 spin_unlock_irqrestore(&audio
->dsp_lock
, flags
);
236 wake_up(&audio
->read_wait
);
239 static void audplay_dsp_event(void *data
, unsigned id
, size_t len
,
240 void (*getevent
) (void *ptr
, size_t len
))
242 struct audio
*audio
= data
;
244 getevent(msg
, sizeof(msg
));
246 dprintk("audplay_dsp_event: msg_id=%x\n", id
);
249 case AUDPLAY_MSG_DEC_NEEDS_DATA
:
250 audamrnb_send_data(audio
, 1);
253 case AUDPLAY_MSG_BUFFER_UPDATE
:
254 audamrnb_update_pcm_buf_entry(audio
, msg
);
258 pr_err("unexpected message from decoder \n");
262 static void audamrnb_dsp_event(void *private, unsigned id
, uint16_t *msg
)
264 struct audio
*audio
= private;
267 case AUDPP_MSG_STATUS_MSG
:{
268 unsigned status
= msg
[1];
271 case AUDPP_DEC_STATUS_SLEEP
:
272 dprintk("decoder status: sleep \n");
275 case AUDPP_DEC_STATUS_INIT
:
276 dprintk("decoder status: init \n");
277 audpp_cmd_cfg_routing_mode(audio
);
280 case AUDPP_DEC_STATUS_CFG
:
281 dprintk("decoder status: cfg \n");
283 case AUDPP_DEC_STATUS_PLAY
:
284 dprintk("decoder status: play \n");
285 if (audio
->pcm_feedback
) {
286 audamrnb_config_hostpcm(audio
);
287 audamrnb_buffer_refresh(audio
);
291 pr_err("unknown decoder status \n");
296 case AUDPP_MSG_CFG_MSG
:
297 if (msg
[0] == AUDPP_MSG_ENA_ENA
) {
298 dprintk("audamrnb_dsp_event: CFG_MSG ENABLE\n");
299 auddec_dsp_config(audio
, 1);
300 audio
->out_needed
= 0;
302 audpp_set_volume_and_pan(audio
->dec_id
, audio
->volume
,
304 audpp_avsync(audio
->dec_id
, 22050);
305 } else if (msg
[0] == AUDPP_MSG_ENA_DIS
) {
306 dprintk("audamrnb_dsp_event: CFG_MSG DISABLE\n");
307 audpp_avsync(audio
->dec_id
, 0);
310 pr_err("audamrnb_dsp_event: CFG_MSG %d?\n", msg
[0]);
313 case AUDPP_MSG_ROUTING_ACK
:
314 dprintk("audamrnb_dsp_event: ROUTING_ACK mode=%d\n", msg
[1]);
315 audpp_cmd_cfg_adec_params(audio
);
319 pr_err("audamrnb_dsp_event: UNKNOWN (%d)\n", id
);
324 struct msm_adsp_ops audplay_adsp_ops_amrnb
= {
325 .event
= audplay_dsp_event
,
328 #define audplay_send_queue0(audio, cmd, len) \
329 msm_adsp_write(audio->audplay, QDSP_uPAudPlay0BitStreamCtrlQueue, \
332 static int auddec_dsp_config(struct audio
*audio
, int enable
)
334 audpp_cmd_cfg_dec_type cmd
;
336 memset(&cmd
, 0, sizeof(cmd
));
337 cmd
.cmd_id
= AUDPP_CMD_CFG_DEC_TYPE
;
339 cmd
.dec0_cfg
= AUDPP_CMD_UPDATDE_CFG_DEC
|
340 AUDPP_CMD_ENA_DEC_V
| AUDDEC_DEC_AMRNB
;
342 cmd
.dec0_cfg
= AUDPP_CMD_UPDATDE_CFG_DEC
| AUDPP_CMD_DIS_DEC_V
;
344 return audpp_send_queue1(&cmd
, sizeof(cmd
));
347 static void audpp_cmd_cfg_adec_params(struct audio
*audio
)
349 struct audpp_cmd_cfg_adec_params_amrnb cmd
;
351 memset(&cmd
, 0, sizeof(cmd
));
352 cmd
.common
.cmd_id
= AUDPP_CMD_CFG_ADEC_PARAMS
;
353 cmd
.common
.length
= AUDPP_CMD_CFG_ADEC_PARAMS_V13K_LEN
;
354 cmd
.common
.dec_id
= audio
->dec_id
;
355 cmd
.common
.input_sampling_frequency
= 8000;
356 cmd
.stereo_cfg
= AUDPP_CMD_PCM_INTF_MONO_V
;
358 audpp_send_queue2(&cmd
, sizeof(cmd
));
361 static void audpp_cmd_cfg_routing_mode(struct audio
*audio
)
363 struct audpp_cmd_routing_mode cmd
;
364 dprintk("audpp_cmd_cfg_routing_mode()\n");
365 memset(&cmd
, 0, sizeof(cmd
));
366 cmd
.cmd_id
= AUDPP_CMD_ROUTING_MODE
;
367 cmd
.object_number
= audio
->dec_id
;
368 if (audio
->pcm_feedback
)
369 cmd
.routing_mode
= ROUTING_MODE_FTRT
;
371 cmd
.routing_mode
= ROUTING_MODE_RT
;
373 audpp_send_queue1(&cmd
, sizeof(cmd
));
376 static int audplay_dsp_send_data_avail(struct audio
*audio
,
377 unsigned idx
, unsigned len
)
379 audplay_cmd_bitstream_data_avail cmd
;
381 cmd
.cmd_id
= AUDPLAY_CMD_BITSTREAM_DATA_AVAIL
;
382 cmd
.decoder_id
= audio
->dec_id
;
383 cmd
.buf_ptr
= audio
->out
[idx
].addr
;
384 cmd
.buf_size
= len
/ 2;
385 cmd
.partition_number
= 0;
386 return audplay_send_queue0(audio
, &cmd
, sizeof(cmd
));
389 static void audamrnb_buffer_refresh(struct audio
*audio
)
391 struct audplay_cmd_buffer_refresh refresh_cmd
;
393 refresh_cmd
.cmd_id
= AUDPLAY_CMD_BUFFER_REFRESH
;
394 refresh_cmd
.num_buffers
= 1;
395 refresh_cmd
.buf0_address
= audio
->in
[audio
->fill_next
].addr
;
396 refresh_cmd
.buf0_length
= audio
->in
[audio
->fill_next
].size
-
397 (audio
->in
[audio
->fill_next
].size
% AMRNB_DECODED_FRSZ
);
398 refresh_cmd
.buf_read_count
= 0;
399 dprintk("audplay_buffer_fresh: buf0_addr=%x buf0_len=%d\n",
400 refresh_cmd
.buf0_address
, refresh_cmd
.buf0_length
);
401 (void)audplay_send_queue0(audio
, &refresh_cmd
, sizeof(refresh_cmd
));
404 static void audamrnb_config_hostpcm(struct audio
*audio
)
406 struct audplay_cmd_hpcm_buf_cfg cfg_cmd
;
408 dprintk("audamrnb_config_hostpcm()\n");
409 cfg_cmd
.cmd_id
= AUDPLAY_CMD_HPCM_BUF_CFG
;
410 cfg_cmd
.max_buffers
= audio
->pcm_buf_count
;
411 cfg_cmd
.byte_swap
= 0;
412 cfg_cmd
.hostpcm_config
= (0x8000) | (0x4000);
413 cfg_cmd
.feedback_frequency
= 1;
414 cfg_cmd
.partition_number
= 0;
415 (void)audplay_send_queue0(audio
, &cfg_cmd
, sizeof(cfg_cmd
));
419 static void audamrnb_send_data(struct audio
*audio
, unsigned needed
)
421 struct buffer
*frame
;
424 spin_lock_irqsave(&audio
->dsp_lock
, flags
);
429 /* We were called from the callback because the DSP
430 * requested more data. Note that the DSP does want
431 * more data, and if a buffer was in-flight, mark it
432 * as available (since the DSP must now be done with
435 audio
->out_needed
= 1;
436 frame
= audio
->out
+ audio
->out_tail
;
437 if (frame
->used
== 0xffffffff) {
439 audio
->out_tail
^= 1;
440 wake_up(&audio
->write_wait
);
444 if (audio
->out_needed
) {
445 /* If the DSP currently wants data and we have a
446 * buffer available, we will send it and reset
447 * the needed flag. We'll mark the buffer as in-flight
448 * so that it won't be recycled until the next buffer
452 frame
= audio
->out
+ audio
->out_tail
;
454 BUG_ON(frame
->used
== 0xffffffff);
455 /* printk("frame %d busy\n", audio->out_tail); */
456 audplay_dsp_send_data_avail(audio
, audio
->out_tail
,
458 frame
->used
= 0xffffffff;
459 audio
->out_needed
= 0;
463 spin_unlock_irqrestore(&audio
->dsp_lock
, flags
);
466 /* ------------------- device --------------------- */
468 static void audamrnb_flush(struct audio
*audio
)
470 audio
->out
[0].used
= 0;
471 audio
->out
[1].used
= 0;
475 atomic_set(&audio
->out_bytes
, 0);
478 static void audamrnb_flush_pcm_buf(struct audio
*audio
)
482 for (index
= 0; index
< PCM_BUF_MAX_COUNT
; index
++)
483 audio
->in
[index
].used
= 0;
485 audio
->read_next
= 0;
486 audio
->fill_next
= 0;
489 static long audamrnb_ioctl(struct file
*file
, unsigned int cmd
,
492 struct audio
*audio
= file
->private_data
;
495 dprintk("audamrnb_ioctl() cmd = %d\n", cmd
);
497 if (cmd
== AUDIO_GET_STATS
) {
498 struct msm_audio_stats stats
;
499 stats
.byte_count
= audpp_avsync_byte_count(audio
->dec_id
);
500 stats
.sample_count
= audpp_avsync_sample_count(audio
->dec_id
);
501 if (copy_to_user((void *)arg
, &stats
, sizeof(stats
)))
505 if (cmd
== AUDIO_SET_VOLUME
) {
507 spin_lock_irqsave(&audio
->dsp_lock
, flags
);
510 audpp_set_volume_and_pan(audio
->dec_id
, arg
, 0);
511 spin_unlock_irqrestore(&audio
->dsp_lock
, flags
);
514 mutex_lock(&audio
->lock
);
517 rc
= audamrnb_enable(audio
);
520 rc
= audamrnb_disable(audio
);
524 if (audio
->stopped
) {
525 /* Make sure we're stopped and we wake any threads
526 * that might be blocked holding the write_lock.
527 * While audio->stopped write threads will always
530 wake_up(&audio
->write_wait
);
531 mutex_lock(&audio
->write_lock
);
532 audamrnb_flush(audio
);
533 mutex_unlock(&audio
->write_lock
);
534 wake_up(&audio
->read_wait
);
535 mutex_lock(&audio
->read_lock
);
536 audamrnb_flush_pcm_buf(audio
);
537 mutex_unlock(&audio
->read_lock
);
541 case AUDIO_SET_CONFIG
:{
542 dprintk("AUDIO_SET_CONFIG not applicable \n");
545 case AUDIO_GET_CONFIG
:{
546 struct msm_audio_config config
;
547 config
.buffer_size
= BUFSZ
;
548 config
.buffer_count
= 2;
549 config
.sample_rate
= 8000;
550 config
.channel_count
= 1;
551 config
.unused
[0] = 0;
552 config
.unused
[1] = 0;
553 config
.unused
[2] = 0;
554 config
.unused
[3] = 0;
555 if (copy_to_user((void *)arg
, &config
,
563 case AUDIO_GET_PCM_CONFIG
:{
564 struct msm_audio_pcm_config config
;
565 config
.pcm_feedback
= 0;
566 config
.buffer_count
= PCM_BUF_MAX_COUNT
;
567 config
.buffer_size
= PCM_BUFSZ_MIN
;
568 if (copy_to_user((void *)arg
, &config
,
575 case AUDIO_SET_PCM_CONFIG
:{
576 struct msm_audio_pcm_config config
;
578 (&config
, (void *)arg
, sizeof(config
))) {
582 if ((config
.buffer_count
> PCM_BUF_MAX_COUNT
) ||
583 (config
.buffer_count
== 1))
584 config
.buffer_count
= PCM_BUF_MAX_COUNT
;
586 if (config
.buffer_size
< PCM_BUFSZ_MIN
)
587 config
.buffer_size
= PCM_BUFSZ_MIN
;
589 /* Check if pcm feedback is required */
590 if ((config
.pcm_feedback
) && (!audio
->read_data
)) {
591 dprintk("audamrnb_ioctl: allocate PCM buf %d\n",
592 config
.buffer_count
*
595 dma_alloc_coherent(NULL
,
600 if (!audio
->read_data
) {
601 pr_err("audamrnb_ioctl: no mem for pcm buf\n");
606 audio
->pcm_feedback
= 1;
607 audio
->buf_refresh
= 0;
608 audio
->pcm_buf_count
=
610 audio
->read_next
= 0;
611 audio
->fill_next
= 0;
614 index
< config
.buffer_count
; index
++) {
615 audio
->in
[index
].data
=
616 audio
->read_data
+ offset
;
617 audio
->in
[index
].addr
=
618 audio
->read_phys
+ offset
;
619 audio
->in
[index
].size
=
621 audio
->in
[index
].used
= 0;
622 offset
+= config
.buffer_size
;
634 mutex_unlock(&audio
->lock
);
638 static ssize_t
audamrnb_read(struct file
*file
, char __user
*buf
, size_t count
,
641 struct audio
*audio
= file
->private_data
;
642 const char __user
*start
= buf
;
645 if (!audio
->pcm_feedback
)
646 return 0; /* PCM feedback is not enabled. Nothing to read */
648 mutex_lock(&audio
->read_lock
);
649 dprintk("audamrnb_read() %d \n", count
);
651 rc
= wait_event_interruptible(audio
->read_wait
,
652 (audio
->in
[audio
->read_next
].
653 used
> 0) || (audio
->stopped
));
658 if (audio
->stopped
) {
663 if (count
< audio
->in
[audio
->read_next
].used
) {
664 /* Read must happen in frame boundary. Since driver does
665 * not know frame size, read count must be greater or
666 * equal to size of PCM samples
668 dprintk("audamrnb_read:read stop - partial frame\n");
671 dprintk("audamrnb_read: read from in[%d]\n",
674 (buf
, audio
->in
[audio
->read_next
].data
,
675 audio
->in
[audio
->read_next
].used
)) {
676 pr_err("audamrnb_read: invalid addr %x \n",
681 count
-= audio
->in
[audio
->read_next
].used
;
682 buf
+= audio
->in
[audio
->read_next
].used
;
683 audio
->in
[audio
->read_next
].used
= 0;
684 if ((++audio
->read_next
) == audio
->pcm_buf_count
)
685 audio
->read_next
= 0;
689 if (audio
->buf_refresh
) {
690 audio
->buf_refresh
= 0;
691 dprintk("audamrnb_read: kick start pcm feedback again\n");
692 audamrnb_buffer_refresh(audio
);
695 mutex_unlock(&audio
->read_lock
);
700 dprintk("audamrnb_read: read %d bytes\n", rc
);
704 static ssize_t
audamrnb_write(struct file
*file
, const char __user
*buf
,
705 size_t count
, loff_t
*pos
)
707 struct audio
*audio
= file
->private_data
;
708 const char __user
*start
= buf
;
709 struct buffer
*frame
;
715 dprintk("audamrnb_write() \n");
716 mutex_lock(&audio
->write_lock
);
718 frame
= audio
->out
+ audio
->out_head
;
719 rc
= wait_event_interruptible(audio
->write_wait
,
721 || (audio
->stopped
));
722 dprintk("audamrnb_write() buffer available\n");
725 if (audio
->stopped
) {
729 xfer
= (count
> frame
->size
) ? frame
->size
: count
;
730 if (copy_from_user(frame
->data
, buf
, xfer
)) {
736 audio
->out_head
^= 1;
740 audamrnb_send_data(audio
, 0);
743 mutex_unlock(&audio
->write_lock
);
749 static int audamrnb_release(struct inode
*inode
, struct file
*file
)
751 struct audio
*audio
= file
->private_data
;
753 dprintk("audamrnb_release()\n");
755 mutex_lock(&audio
->lock
);
756 audamrnb_disable(audio
);
757 audamrnb_flush(audio
);
758 audamrnb_flush_pcm_buf(audio
);
759 msm_adsp_put(audio
->audplay
);
760 audio
->audplay
= NULL
;
762 dma_free_coherent(NULL
, DMASZ
, audio
->data
, audio
->phys
);
764 if (audio
->read_data
!= NULL
) {
765 dma_free_coherent(NULL
,
766 audio
->in
[0].size
* audio
->pcm_buf_count
,
767 audio
->read_data
, audio
->read_phys
);
768 audio
->read_data
= NULL
;
770 audio
->pcm_feedback
= 0;
771 mutex_unlock(&audio
->lock
);
775 static struct audio the_amrnb_audio
;
777 static int audamrnb_open(struct inode
*inode
, struct file
*file
)
779 struct audio
*audio
= &the_amrnb_audio
;
782 mutex_lock(&audio
->lock
);
785 pr_err("audio: busy\n");
791 audio
->data
= dma_alloc_coherent(NULL
, DMASZ
,
792 &audio
->phys
, GFP_KERNEL
);
794 pr_err("audio: could not allocate DMA buffers\n");
800 rc
= audmgr_open(&audio
->audmgr
);
804 rc
= msm_adsp_get("AUDPLAY0TASK", &audio
->audplay
,
805 &audplay_adsp_ops_amrnb
, audio
);
807 pr_err("audio: failed to get audplay0 dsp module\n");
808 audmgr_disable(&audio
->audmgr
);
809 dma_free_coherent(NULL
, DMASZ
, audio
->data
, audio
->phys
);
816 audio
->out
[0].data
= audio
->data
+ 0;
817 audio
->out
[0].addr
= audio
->phys
+ 0;
818 audio
->out
[0].size
= BUFSZ
;
820 audio
->out
[1].data
= audio
->data
+ BUFSZ
;
821 audio
->out
[1].addr
= audio
->phys
+ BUFSZ
;
822 audio
->out
[1].size
= BUFSZ
;
824 audio
->volume
= 0x2000; /* Q13 1.0 */
826 audamrnb_flush(audio
);
828 file
->private_data
= audio
;
832 mutex_unlock(&audio
->lock
);
836 static struct file_operations audio_amrnb_fops
= {
837 .owner
= THIS_MODULE
,
838 .open
= audamrnb_open
,
839 .release
= audamrnb_release
,
840 .read
= audamrnb_read
,
841 .write
= audamrnb_write
,
842 .unlocked_ioctl
= audamrnb_ioctl
,
845 struct miscdevice audio_amrnb_misc
= {
846 .minor
= MISC_DYNAMIC_MINOR
,
848 .fops
= &audio_amrnb_fops
,
851 static int __init
audamrnb_init(void)
853 mutex_init(&the_amrnb_audio
.lock
);
854 mutex_init(&the_amrnb_audio
.write_lock
);
855 mutex_init(&the_amrnb_audio
.read_lock
);
856 spin_lock_init(&the_amrnb_audio
.dsp_lock
);
857 init_waitqueue_head(&the_amrnb_audio
.write_wait
);
858 init_waitqueue_head(&the_amrnb_audio
.read_wait
);
859 the_amrnb_audio
.read_data
= NULL
;
860 return misc_register(&audio_amrnb_misc
);
863 static void __exit
audamrnb_exit(void)
865 misc_deregister(&audio_amrnb_misc
);
868 module_init(audamrnb_init
);
869 module_exit(audamrnb_exit
);
871 MODULE_DESCRIPTION("MSM AMR-NB driver");
872 MODULE_LICENSE("GPL v2");
873 MODULE_AUTHOR("QUALCOMM Inc");