1 /* arch/arm/mach-msm/qdsp5/audio_mp3.c
3 * mp3 audio output device
5 * Copyright (C) 2008 Google, Inc.
6 * Copyright (C) 2008 HTC Corporation
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/module.h>
21 #include <linux/miscdevice.h>
22 #include <linux/uaccess.h>
23 #include <linux/kthread.h>
24 #include <linux/wait.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/gfp.h>
28 #include <linux/delay.h>
30 #include <asm/atomic.h>
31 #include <asm/ioctls.h>
32 #include <mach/msm_adsp.h>
34 #include <linux/msm_audio.h>
38 #include <mach/qdsp5/qdsp5audppcmdi.h>
39 #include <mach/qdsp5/qdsp5audppmsg.h>
40 #include <mach/qdsp5/qdsp5audplaycmdi.h>
41 #include <mach/qdsp5/qdsp5audplaymsg.h>
43 /* for queue ids - should be relative to module number*/
47 #define dprintk(format, arg...) \
48 printk(KERN_DEBUG format, ## arg)
50 #define dprintk(format, arg...) do {} while (0)
53 /* Size must be power of 2 */
54 #define BUFSZ_MAX 32768
55 #define BUFSZ_MIN 4096
56 #define DMASZ_MAX (BUFSZ_MAX * 2)
57 #define DMASZ_MIN (BUFSZ_MIN * 2)
59 #define AUDPLAY_INVALID_READ_PTR_OFFSET 0xFFFF
60 #define AUDDEC_DEC_MP3 2
62 #define PCM_BUFSZ_MIN 4800 /* Hold one stereo MP3 frame */
63 #define PCM_BUF_MAX_COUNT 5 /* DSP only accepts 5 buffers at most
64 but support 2 buffers currently */
65 #define ROUTING_MODE_FTRT 1
66 #define ROUTING_MODE_RT 2
67 /* Decoder status received from AUDPPTASK */
68 #define AUDPP_DEC_STATUS_SLEEP 0
69 #define AUDPP_DEC_STATUS_INIT 1
70 #define AUDPP_DEC_STATUS_CFG 2
71 #define AUDPP_DEC_STATUS_PLAY 3
76 unsigned used; /* Input usage actual DSP produced PCM size */
87 uint8_t out_needed; /* number of buffers the dsp is waiting for */
93 struct mutex write_lock;
94 wait_queue_head_t write_wait;
96 /* Host PCM section */
97 struct buffer in[PCM_BUF_MAX_COUNT];
98 struct mutex read_lock;
99 wait_queue_head_t read_wait; /* Wait queue for read */
100 char *read_data; /* pointer to reader buffer */
101 dma_addr_t read_phys; /* physical address of reader buffer */
102 uint8_t read_next; /* index to input buffers to be read next */
103 uint8_t fill_next; /* index to buffer that DSP should be filling */
104 uint8_t pcm_buf_count; /* number of pcm buffer allocated */
105 /* ---- End of Host PCM section */
107 struct msm_adsp_module *audplay;
109 /* configuration to use on next enable */
110 uint32_t out_sample_rate;
111 uint32_t out_channel_mode;
113 struct audmgr audmgr;
115 /* data allocated for various buffers */
119 int rflush; /* Read flush */
120 int wflush; /* Write flush */
124 int stopped; /* set when stopped, cleared on flush */
128 int reserved; /* A byte is being reserved */
129 char rsv_byte; /* Handle odd length user data */
134 uint32_t read_ptr_offset;
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 audplay_send_data(struct audio *audio, unsigned needed);
141 static void audplay_config_hostpcm(struct audio *audio);
142 static void audplay_buffer_refresh(struct audio *audio);
143 static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
145 /* must be called with audio->lock held */
146 static int audio_enable(struct audio *audio)
148 struct audmgr_config cfg;
151 pr_info("audio_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_MP3;
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, audio_dsp_event, audio)) {
176 pr_err("audio: audpp_enable() failed\n");
177 msm_adsp_disable(audio->audplay);
178 audmgr_disable(&audio->audmgr);
186 /* must be called with audio->lock held */
187 static int audio_disable(struct audio *audio)
189 pr_info("audio_disable()\n");
190 if (audio->enabled) {
192 auddec_dsp_config(audio, 0);
193 wake_up(&audio->write_wait);
194 wake_up(&audio->read_wait);
195 msm_adsp_disable(audio->audplay);
196 audpp_disable(audio->dec_id, audio);
197 audmgr_disable(&audio->audmgr);
198 audio->out_needed = 0;
203 /* ------------------- dsp --------------------- */
204 static void audio_update_pcm_buf_entry(struct audio *audio, uint32_t *payload)
210 audio->buf_refresh = 1;
213 spin_lock_irqsave(&audio->dsp_lock, flags);
214 for (index = 0; index < payload[1]; index++) {
215 if (audio->in[audio->fill_next].addr ==
216 payload[2 + index * 2]) {
217 pr_info("audio_update_pcm_buf_entry: in[%d] ready\n",
219 audio->in[audio->fill_next].used =
220 payload[3 + index * 2];
221 if ((++audio->fill_next) == audio->pcm_buf_count)
222 audio->fill_next = 0;
226 ("audio_update_pcm_buf_entry: expected=%x ret=%x\n"
227 , audio->in[audio->fill_next].addr,
228 payload[1 + index * 2]);
232 if (audio->in[audio->fill_next].used == 0) {
233 audplay_buffer_refresh(audio);
235 pr_info("audio_update_pcm_buf_entry: read cannot keep up\n");
236 audio->buf_refresh = 1;
238 wake_up(&audio->read_wait);
239 spin_unlock_irqrestore(&audio->dsp_lock, flags);
243 static void audplay_dsp_event(void *data, unsigned id, size_t len,
244 void (*getevent) (void *ptr, size_t len))
246 struct audio *audio = data;
248 getevent(msg, sizeof(msg));
250 dprintk("audplay_dsp_event: msg_id=%x\n", id);
253 case AUDPLAY_MSG_DEC_NEEDS_DATA:
254 audplay_send_data(audio, 1);
257 case AUDPLAY_MSG_BUFFER_UPDATE:
258 audio_update_pcm_buf_entry(audio, msg);
262 pr_err("unexpected message from decoder \n");
267 static void audio_dsp_event(void *private, unsigned id, uint16_t *msg)
269 struct audio *audio = private;
272 case AUDPP_MSG_STATUS_MSG:{
273 unsigned status = msg[1];
276 case AUDPP_DEC_STATUS_SLEEP:
277 pr_info("decoder status: sleep \n");
280 case AUDPP_DEC_STATUS_INIT:
281 pr_info("decoder status: init \n");
282 audpp_cmd_cfg_routing_mode(audio);
285 case AUDPP_DEC_STATUS_CFG:
286 pr_info("decoder status: cfg \n");
288 case AUDPP_DEC_STATUS_PLAY:
289 pr_info("decoder status: play \n");
290 if (audio->pcm_feedback) {
291 audplay_config_hostpcm(audio);
292 audplay_buffer_refresh(audio);
296 pr_err("unknown decoder status \n");
301 case AUDPP_MSG_CFG_MSG:
302 if (msg[0] == AUDPP_MSG_ENA_ENA) {
303 pr_info("audio_dsp_event: CFG_MSG ENABLE\n");
304 auddec_dsp_config(audio, 1);
305 audio->out_needed = 0;
307 audpp_set_volume_and_pan(audio->dec_id, audio->volume,
309 audpp_avsync(audio->dec_id, 22050);
310 } else if (msg[0] == AUDPP_MSG_ENA_DIS) {
311 pr_info("audio_dsp_event: CFG_MSG DISABLE\n");
312 audpp_avsync(audio->dec_id, 0);
315 pr_err("audio_dsp_event: CFG_MSG %d?\n", msg[0]);
318 case AUDPP_MSG_ROUTING_ACK:
319 pr_info("audio_dsp_event: ROUTING_ACK mode=%d\n", msg[1]);
320 audpp_cmd_cfg_adec_params(audio);
323 case AUDPP_MSG_FLUSH_ACK:
324 dprintk("%s: FLUSH_ACK\n", __func__);
327 if (audio->pcm_feedback)
328 audplay_buffer_refresh(audio);
332 pr_err("audio_dsp_event: UNKNOWN (%d)\n", id);
338 struct msm_adsp_ops audplay_adsp_ops = {
339 .event = audplay_dsp_event,
343 #define audplay_send_queue0(audio, cmd, len) \
344 msm_adsp_write(audio->audplay, QDSP_uPAudPlay0BitStreamCtrlQueue, \
347 static int auddec_dsp_config(struct audio *audio, int enable)
349 audpp_cmd_cfg_dec_type cmd;
351 memset(&cmd, 0, sizeof(cmd));
352 cmd.cmd_id = AUDPP_CMD_CFG_DEC_TYPE;
354 cmd.dec0_cfg = AUDPP_CMD_UPDATDE_CFG_DEC |
355 AUDPP_CMD_ENA_DEC_V |
358 cmd.dec0_cfg = AUDPP_CMD_UPDATDE_CFG_DEC |
361 return audpp_send_queue1(&cmd, sizeof(cmd));
364 static void audpp_cmd_cfg_adec_params(struct audio *audio)
366 audpp_cmd_cfg_adec_params_mp3 cmd;
368 memset(&cmd, 0, sizeof(cmd));
369 cmd.common.cmd_id = AUDPP_CMD_CFG_ADEC_PARAMS;
370 cmd.common.length = AUDPP_CMD_CFG_ADEC_PARAMS_MP3_LEN;
371 cmd.common.dec_id = audio->dec_id;
372 cmd.common.input_sampling_frequency = audio->out_sample_rate;
374 audpp_send_queue2(&cmd, sizeof(cmd));
377 static void audpp_cmd_cfg_routing_mode(struct audio *audio)
379 struct audpp_cmd_routing_mode cmd;
380 pr_info("audpp_cmd_cfg_routing_mode()\n");
381 memset(&cmd, 0, sizeof(cmd));
382 cmd.cmd_id = AUDPP_CMD_ROUTING_MODE;
383 cmd.object_number = audio->dec_id;
384 if (audio->pcm_feedback)
385 cmd.routing_mode = ROUTING_MODE_FTRT;
387 cmd.routing_mode = ROUTING_MODE_RT;
389 audpp_send_queue1(&cmd, sizeof(cmd));
392 static int audplay_dsp_send_data_avail(struct audio *audio,
393 unsigned idx, unsigned len)
395 audplay_cmd_bitstream_data_avail cmd;
397 cmd.cmd_id = AUDPLAY_CMD_BITSTREAM_DATA_AVAIL;
398 cmd.decoder_id = audio->dec_id;
399 cmd.buf_ptr = audio->out[idx].addr;
400 cmd.buf_size = len/2;
401 cmd.partition_number = 0;
402 return audplay_send_queue0(audio, &cmd, sizeof(cmd));
405 static void audplay_buffer_refresh(struct audio *audio)
407 struct audplay_cmd_buffer_refresh refresh_cmd;
409 refresh_cmd.cmd_id = AUDPLAY_CMD_BUFFER_REFRESH;
410 refresh_cmd.num_buffers = 1;
411 refresh_cmd.buf0_address = audio->in[audio->fill_next].addr;
412 refresh_cmd.buf0_length = audio->in[audio->fill_next].size -
413 (audio->in[audio->fill_next].size % 576); /* Mp3 frame size */
414 refresh_cmd.buf_read_count = 0;
415 pr_info("audplay_buffer_fresh: buf0_addr=%x buf0_len=%d\n",
416 refresh_cmd.buf0_address, refresh_cmd.buf0_length);
417 (void)audplay_send_queue0(audio, &refresh_cmd, sizeof(refresh_cmd));
420 static void audplay_config_hostpcm(struct audio *audio)
422 struct audplay_cmd_hpcm_buf_cfg cfg_cmd;
424 pr_info("audplay_config_hostpcm()\n");
425 cfg_cmd.cmd_id = AUDPLAY_CMD_HPCM_BUF_CFG;
426 cfg_cmd.max_buffers = 1;
427 cfg_cmd.byte_swap = 0;
428 cfg_cmd.hostpcm_config = (0x8000) | (0x4000);
429 cfg_cmd.feedback_frequency = 1;
430 cfg_cmd.partition_number = 0;
431 (void)audplay_send_queue0(audio, &cfg_cmd, sizeof(cfg_cmd));
435 static void audplay_send_data(struct audio *audio, unsigned needed)
437 struct buffer *frame;
440 spin_lock_irqsave(&audio->dsp_lock, flags);
445 audio->out_needed = 1;
449 if (needed && !audio->wflush) {
450 /* We were called from the callback because the DSP
451 * requested more data. Note that the DSP does want
452 * more data, and if a buffer was in-flight, mark it
453 * as available (since the DSP must now be done with
456 audio->out_needed = 1;
457 frame = audio->out + audio->out_tail;
458 if (frame->used == 0xffffffff) {
459 dprintk("frame %d free\n", audio->out_tail);
461 audio->out_tail ^= 1;
462 wake_up(&audio->write_wait);
466 if (audio->out_needed) {
467 /* If the DSP currently wants data and we have a
468 * buffer available, we will send it and reset
469 * the needed flag. We'll mark the buffer as in-flight
470 * so that it won't be recycled until the next buffer
474 frame = audio->out + audio->out_tail;
476 BUG_ON(frame->used == 0xffffffff);
477 dprintk("frame %d busy\n", audio->out_tail);
478 audplay_dsp_send_data_avail(audio, audio->out_tail,
480 frame->used = 0xffffffff;
481 audio->out_needed = 0;
485 spin_unlock_irqrestore(&audio->dsp_lock, flags);
488 /* ------------------- device --------------------- */
490 static void audio_flush(struct audio *audio)
492 audio->out[0].used = 0;
493 audio->out[1].used = 0;
497 atomic_set(&audio->out_bytes, 0);
500 static void audio_flush_pcm_buf(struct audio *audio)
504 for (index = 0; index < PCM_BUF_MAX_COUNT; index++)
505 audio->in[index].used = 0;
507 audio->read_next = 0;
508 audio->fill_next = 0;
511 static void audio_ioport_reset(struct audio *audio)
513 /* Make sure read/write thread are free from
514 * sleep and knowing that system is not able
515 * to process io request at the moment
517 wake_up(&audio->write_wait);
518 mutex_lock(&audio->write_lock);
520 mutex_unlock(&audio->write_lock);
521 wake_up(&audio->read_wait);
522 mutex_lock(&audio->read_lock);
523 audio_flush_pcm_buf(audio);
524 mutex_unlock(&audio->read_lock);
527 static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
529 struct audio *audio = file->private_data;
532 pr_info("audio_ioctl() cmd = %d\n", cmd);
534 if (cmd == AUDIO_GET_STATS) {
535 struct msm_audio_stats stats;
536 stats.byte_count = audpp_avsync_byte_count(audio->dec_id);
537 stats.sample_count = audpp_avsync_sample_count(audio->dec_id);
538 if (copy_to_user((void *) arg, &stats, sizeof(stats)))
542 if (cmd == AUDIO_SET_VOLUME) {
544 spin_lock_irqsave(&audio->dsp_lock, flags);
547 audpp_set_volume_and_pan(audio->dec_id, arg, 0);
548 spin_unlock_irqrestore(&audio->dsp_lock, flags);
551 mutex_lock(&audio->lock);
554 rc = audio_enable(audio);
557 rc = audio_disable(audio);
559 audio_ioport_reset(audio);
563 dprintk("%s: AUDIO_FLUSH\n", __func__);
566 audio_ioport_reset(audio);
570 if (audio->buf_refresh) {
571 audio->buf_refresh = 0;
572 audplay_buffer_refresh(audio);
576 case AUDIO_SET_CONFIG: {
577 struct msm_audio_config config;
578 if (copy_from_user(&config, (void *) arg, sizeof(config))) {
582 if (config.channel_count == 1) {
583 config.channel_count = AUDPP_CMD_PCM_INTF_MONO_V;
584 } else if (config.channel_count == 2) {
585 config.channel_count = AUDPP_CMD_PCM_INTF_STEREO_V;
590 audio->out_sample_rate = config.sample_rate;
591 audio->out_channel_mode = config.channel_count;
595 case AUDIO_GET_CONFIG: {
596 struct msm_audio_config config;
597 config.buffer_size = (audio->out_dma_sz >> 1);
598 config.buffer_count = 2;
599 config.sample_rate = audio->out_sample_rate;
600 if (audio->out_channel_mode == AUDPP_CMD_PCM_INTF_MONO_V) {
601 config.channel_count = 1;
603 config.channel_count = 2;
605 config.unused[0] = 0;
606 config.unused[1] = 0;
607 config.unused[2] = 0;
608 config.unused[3] = 0;
609 if (copy_to_user((void *) arg, &config, sizeof(config))) {
616 case AUDIO_GET_PCM_CONFIG:{
617 struct msm_audio_pcm_config config;
618 config.pcm_feedback = 0;
619 config.buffer_count = PCM_BUF_MAX_COUNT;
620 config.buffer_size = PCM_BUFSZ_MIN;
621 if (copy_to_user((void *)arg, &config,
628 case AUDIO_SET_PCM_CONFIG:{
629 struct msm_audio_pcm_config config;
631 (&config, (void *)arg, sizeof(config))) {
635 if ((config.buffer_count > PCM_BUF_MAX_COUNT) ||
636 (config.buffer_count == 1))
637 config.buffer_count = PCM_BUF_MAX_COUNT;
639 if (config.buffer_size < PCM_BUFSZ_MIN)
640 config.buffer_size = PCM_BUFSZ_MIN;
642 /* Check if pcm feedback is required */
643 if ((config.pcm_feedback) && (!audio->read_data)) {
644 pr_info("ioctl: allocate PCM buffer %d\n",
645 config.buffer_count *
648 dma_alloc_coherent(NULL,
653 if (!audio->read_data) {
654 pr_err("audio_mp3: malloc pcm buf failed\n");
659 audio->pcm_feedback = 1;
660 audio->buf_refresh = 0;
661 audio->pcm_buf_count =
663 audio->read_next = 0;
664 audio->fill_next = 0;
667 index < config.buffer_count;
669 audio->in[index].data =
670 audio->read_data + offset;
671 audio->in[index].addr =
672 audio->read_phys + offset;
673 audio->in[index].size =
675 audio->in[index].used = 0;
676 offset += config.buffer_size;
686 dprintk("%s: AUDIO_PAUSE %ld\n", __func__, arg);
687 rc = audpp_pause(audio->dec_id, (int) arg);
692 mutex_unlock(&audio->lock);
696 static ssize_t audio_read(struct file *file, char __user *buf, size_t count,
699 struct audio *audio = file->private_data;
700 const char __user *start = buf;
703 if (!audio->pcm_feedback)
704 return 0; /* PCM feedback disabled. Nothing to read */
706 mutex_lock(&audio->read_lock);
707 pr_info("audio_read() %d \n", count);
709 rc = wait_event_interruptible(audio->read_wait,
710 (audio->in[audio->read_next].
711 used > 0) || (audio->stopped)
717 if (audio->stopped || audio->rflush) {
722 if (count < audio->in[audio->read_next].used) {
723 /* Read must happen in frame boundary. Since
724 * driver does not know frame size, read count
725 * must be greater or equal
726 * to size of PCM samples
728 pr_info("audio_read: no partial frame done reading\n");
731 pr_info("audio_read: read from in[%d]\n",
734 (buf, audio->in[audio->read_next].data,
735 audio->in[audio->read_next].used)) {
736 pr_err("audio_read: invalid addr %x \n",
741 count -= audio->in[audio->read_next].used;
742 buf += audio->in[audio->read_next].used;
743 audio->in[audio->read_next].used = 0;
744 if ((++audio->read_next) == audio->pcm_buf_count)
745 audio->read_next = 0;
746 if (audio->in[audio->read_next].used == 0)
747 break; /* No data ready at this moment
748 * Exit while loop to prevent
749 * output thread sleep too long
754 /* don't feed output buffer to HW decoder during flushing
755 * buffer refresh command will be sent once flush completes
756 * send buf refresh command here can confuse HW decoder
758 if (audio->buf_refresh && !audio->rflush) {
759 audio->buf_refresh = 0;
760 pr_info("audio_read: kick start pcm feedback again\n");
761 audplay_buffer_refresh(audio);
764 mutex_unlock(&audio->read_lock);
769 pr_info("audio_read: read %d bytes\n", rc);
773 static ssize_t audio_write(struct file *file, const char __user *buf,
774 size_t count, loff_t *pos)
776 struct audio *audio = file->private_data;
777 const char __user *start = buf;
778 struct buffer *frame;
784 mutex_lock(&audio->write_lock);
786 frame = audio->out + audio->out_head;
787 cpy_ptr = frame->data;
789 rc = wait_event_interruptible(audio->write_wait,
795 if (audio->stopped || audio->wflush) {
800 if (audio->reserved) {
801 dprintk("%s: append reserved byte %x\n",
802 __func__, audio->rsv_byte);
803 *cpy_ptr = audio->rsv_byte;
804 xfer = (count > (frame->size - 1)) ?
805 frame->size - 1 : count;
810 xfer = (count > frame->size) ? frame->size : count;
812 if (copy_from_user(cpy_ptr, buf, xfer)) {
819 audio->rsv_byte = ((char *) frame->data)[dsize - 1];
820 dprintk("%s: odd length buf reserve last byte %x\n",
821 __func__, audio->rsv_byte);
829 audio->out_head ^= 1;
831 audplay_send_data(audio, 0);
834 mutex_unlock(&audio->write_lock);
840 static int audio_release(struct inode *inode, struct file *file)
842 struct audio *audio = file->private_data;
844 dprintk("audio_release()\n");
846 mutex_lock(&audio->lock);
847 audio_disable(audio);
849 audio_flush_pcm_buf(audio);
850 msm_adsp_put(audio->audplay);
851 audio->audplay = NULL;
854 dma_free_coherent(NULL, audio->out_dma_sz, audio->data, audio->phys);
856 if (audio->read_data != NULL) {
857 dma_free_coherent(NULL,
858 audio->in[0].size * audio->pcm_buf_count,
859 audio->read_data, audio->read_phys);
860 audio->read_data = NULL;
862 audio->pcm_feedback = 0;
863 mutex_unlock(&audio->lock);
867 static struct audio the_mp3_audio;
869 static int audio_open(struct inode *inode, struct file *file)
871 struct audio *audio = &the_mp3_audio;
875 mutex_lock(&audio->lock);
878 pr_err("audio: busy\n");
885 while (pmem_sz >= DMASZ_MIN) {
886 audio->data = dma_alloc_coherent(NULL, pmem_sz,
887 &audio->phys, GFP_KERNEL);
890 else if (pmem_sz == DMASZ_MIN) {
891 pr_err("audio: could not allocate DMA buffers\n");
898 dprintk("%s: allocated %d bytes DMA buffer\n", __func__, pmem_sz);
900 rc = audmgr_open(&audio->audmgr);
902 dma_free_coherent(NULL, pmem_sz,
903 audio->data, audio->phys);
907 rc = msm_adsp_get("AUDPLAY0TASK", &audio->audplay, &audplay_adsp_ops,
910 pr_err("audio: failed to get audplay0 dsp module\n");
911 dma_free_coherent(NULL, pmem_sz,
912 audio->data, audio->phys);
913 audmgr_close(&audio->audmgr);
917 audio->out_dma_sz = pmem_sz;
918 pmem_sz >>= 1; /* Shift by 1 to get size of ping pong buffer */
920 audio->out_sample_rate = 44100;
921 audio->out_channel_mode = AUDPP_CMD_PCM_INTF_STEREO_V;
924 audio->out[0].data = audio->data + 0;
925 audio->out[0].addr = audio->phys + 0;
926 audio->out[0].size = pmem_sz;
928 audio->out[1].data = audio->data + pmem_sz;
929 audio->out[1].addr = audio->phys + pmem_sz;
930 audio->out[1].size = pmem_sz;
932 audio->volume = 0x2000; /* equal to Q13 number 1.0 Unit Gain */
936 file->private_data = audio;
940 mutex_unlock(&audio->lock);
944 static struct file_operations audio_mp3_fops = {
945 .owner = THIS_MODULE,
947 .release = audio_release,
949 .write = audio_write,
950 .unlocked_ioctl = audio_ioctl,
953 struct miscdevice audio_mp3_misc = {
954 .minor = MISC_DYNAMIC_MINOR,
956 .fops = &audio_mp3_fops,
959 static int __init audio_init(void)
961 mutex_init(&the_mp3_audio.lock);
962 mutex_init(&the_mp3_audio.write_lock);
963 mutex_init(&the_mp3_audio.read_lock);
964 spin_lock_init(&the_mp3_audio.dsp_lock);
965 init_waitqueue_head(&the_mp3_audio.write_wait);
966 init_waitqueue_head(&the_mp3_audio.read_wait);
967 the_mp3_audio.read_data = NULL;
968 return misc_register(&audio_mp3_misc);
971 device_initcall(audio_init);