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>
27 #include <linux/delay.h>
29 #include <asm/atomic.h>
30 #include <asm/ioctls.h>
31 #include <mach/msm_adsp.h>
33 #include <linux/msm_audio.h>
37 #include <mach/qdsp5/qdsp5audppcmdi.h>
38 #include <mach/qdsp5/qdsp5audppmsg.h>
39 #include <mach/qdsp5/qdsp5audplaycmdi.h>
40 #include <mach/qdsp5/qdsp5audplaymsg.h>
42 /* for queue ids - should be relative to module number*/
46 #define dprintk(format, arg...) \
47 printk(KERN_DEBUG format, ## arg)
49 #define dprintk(format, arg...) do {} while (0)
52 /* Size must be power of 2 */
53 #define BUFSZ_MAX 32768
54 #define BUFSZ_MIN 4096
55 #define DMASZ_MAX (BUFSZ_MAX * 2)
56 #define DMASZ_MIN (BUFSZ_MIN * 2)
58 #define AUDPLAY_INVALID_READ_PTR_OFFSET 0xFFFF
59 #define AUDDEC_DEC_MP3 2
61 #define PCM_BUFSZ_MIN 4800 /* Hold one stereo MP3 frame */
62 #define PCM_BUF_MAX_COUNT 5 /* DSP only accepts 5 buffers at most
63 but support 2 buffers currently */
64 #define ROUTING_MODE_FTRT 1
65 #define ROUTING_MODE_RT 2
66 /* Decoder status received from AUDPPTASK */
67 #define AUDPP_DEC_STATUS_SLEEP 0
68 #define AUDPP_DEC_STATUS_INIT 1
69 #define AUDPP_DEC_STATUS_CFG 2
70 #define AUDPP_DEC_STATUS_PLAY 3
75 unsigned used; /* Input usage actual DSP produced PCM size */
86 uint8_t out_needed; /* number of buffers the dsp is waiting for */
92 struct mutex write_lock;
93 wait_queue_head_t write_wait;
95 /* Host PCM section */
96 struct buffer in[PCM_BUF_MAX_COUNT];
97 struct mutex read_lock;
98 wait_queue_head_t read_wait; /* Wait queue for read */
99 char *read_data; /* pointer to reader buffer */
100 dma_addr_t read_phys; /* physical address of reader buffer */
101 uint8_t read_next; /* index to input buffers to be read next */
102 uint8_t fill_next; /* index to buffer that DSP should be filling */
103 uint8_t pcm_buf_count; /* number of pcm buffer allocated */
104 /* ---- End of Host PCM section */
106 struct msm_adsp_module *audplay;
108 /* configuration to use on next enable */
109 uint32_t out_sample_rate;
110 uint32_t out_channel_mode;
112 struct audmgr audmgr;
114 /* data allocated for various buffers */
118 int rflush; /* Read flush */
119 int wflush; /* Write flush */
123 int stopped; /* set when stopped, cleared on flush */
127 int reserved; /* A byte is being reserved */
128 char rsv_byte; /* Handle odd length user data */
133 uint32_t read_ptr_offset;
136 static int auddec_dsp_config(struct audio *audio, int enable);
137 static void audpp_cmd_cfg_adec_params(struct audio *audio);
138 static void audpp_cmd_cfg_routing_mode(struct audio *audio);
139 static void audplay_send_data(struct audio *audio, unsigned needed);
140 static void audplay_config_hostpcm(struct audio *audio);
141 static void audplay_buffer_refresh(struct audio *audio);
142 static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
144 /* must be called with audio->lock held */
145 static int audio_enable(struct audio *audio)
147 struct audmgr_config cfg;
150 pr_info("audio_enable()\n");
156 audio->out_needed = 0;
158 cfg.tx_rate = RPC_AUD_DEF_SAMPLE_RATE_NONE;
159 cfg.rx_rate = RPC_AUD_DEF_SAMPLE_RATE_48000;
160 cfg.def_method = RPC_AUD_DEF_METHOD_PLAYBACK;
161 cfg.codec = RPC_AUD_DEF_CODEC_MP3;
162 cfg.snd_method = RPC_SND_METHOD_MIDI;
164 rc = audmgr_enable(&audio->audmgr, &cfg);
168 if (msm_adsp_enable(audio->audplay)) {
169 pr_err("audio: msm_adsp_enable(audplay) failed\n");
170 audmgr_disable(&audio->audmgr);
174 if (audpp_enable(audio->dec_id, audio_dsp_event, audio)) {
175 pr_err("audio: audpp_enable() failed\n");
176 msm_adsp_disable(audio->audplay);
177 audmgr_disable(&audio->audmgr);
185 /* must be called with audio->lock held */
186 static int audio_disable(struct audio *audio)
188 pr_info("audio_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 audio_update_pcm_buf_entry(struct audio *audio, uint32_t *payload)
209 audio->buf_refresh = 1;
212 spin_lock_irqsave(&audio->dsp_lock, flags);
213 for (index = 0; index < payload[1]; index++) {
214 if (audio->in[audio->fill_next].addr ==
215 payload[2 + index * 2]) {
216 pr_info("audio_update_pcm_buf_entry: in[%d] ready\n",
218 audio->in[audio->fill_next].used =
219 payload[3 + index * 2];
220 if ((++audio->fill_next) == audio->pcm_buf_count)
221 audio->fill_next = 0;
225 ("audio_update_pcm_buf_entry: expected=%x ret=%x\n"
226 , audio->in[audio->fill_next].addr,
227 payload[1 + index * 2]);
231 if (audio->in[audio->fill_next].used == 0) {
232 audplay_buffer_refresh(audio);
234 pr_info("audio_update_pcm_buf_entry: read cannot keep up\n");
235 audio->buf_refresh = 1;
237 wake_up(&audio->read_wait);
238 spin_unlock_irqrestore(&audio->dsp_lock, flags);
242 static void audplay_dsp_event(void *data, unsigned id, size_t len,
243 void (*getevent) (void *ptr, size_t len))
245 struct audio *audio = data;
247 getevent(msg, sizeof(msg));
249 dprintk("audplay_dsp_event: msg_id=%x\n", id);
252 case AUDPLAY_MSG_DEC_NEEDS_DATA:
253 audplay_send_data(audio, 1);
256 case AUDPLAY_MSG_BUFFER_UPDATE:
257 audio_update_pcm_buf_entry(audio, msg);
261 pr_err("unexpected message from decoder \n");
266 static void audio_dsp_event(void *private, unsigned id, uint16_t *msg)
268 struct audio *audio = private;
271 case AUDPP_MSG_STATUS_MSG:{
272 unsigned status = msg[1];
275 case AUDPP_DEC_STATUS_SLEEP:
276 pr_info("decoder status: sleep \n");
279 case AUDPP_DEC_STATUS_INIT:
280 pr_info("decoder status: init \n");
281 audpp_cmd_cfg_routing_mode(audio);
284 case AUDPP_DEC_STATUS_CFG:
285 pr_info("decoder status: cfg \n");
287 case AUDPP_DEC_STATUS_PLAY:
288 pr_info("decoder status: play \n");
289 if (audio->pcm_feedback) {
290 audplay_config_hostpcm(audio);
291 audplay_buffer_refresh(audio);
295 pr_err("unknown decoder status \n");
300 case AUDPP_MSG_CFG_MSG:
301 if (msg[0] == AUDPP_MSG_ENA_ENA) {
302 pr_info("audio_dsp_event: CFG_MSG ENABLE\n");
303 auddec_dsp_config(audio, 1);
304 audio->out_needed = 0;
306 audpp_set_volume_and_pan(audio->dec_id, audio->volume,
308 audpp_avsync(audio->dec_id, 22050);
309 } else if (msg[0] == AUDPP_MSG_ENA_DIS) {
310 pr_info("audio_dsp_event: CFG_MSG DISABLE\n");
311 audpp_avsync(audio->dec_id, 0);
314 pr_err("audio_dsp_event: CFG_MSG %d?\n", msg[0]);
317 case AUDPP_MSG_ROUTING_ACK:
318 pr_info("audio_dsp_event: ROUTING_ACK mode=%d\n", msg[1]);
319 audpp_cmd_cfg_adec_params(audio);
322 case AUDPP_MSG_FLUSH_ACK:
323 dprintk("%s: FLUSH_ACK\n", __func__);
326 if (audio->pcm_feedback)
327 audplay_buffer_refresh(audio);
331 pr_err("audio_dsp_event: UNKNOWN (%d)\n", id);
337 struct msm_adsp_ops audplay_adsp_ops = {
338 .event = audplay_dsp_event,
342 #define audplay_send_queue0(audio, cmd, len) \
343 msm_adsp_write(audio->audplay, QDSP_uPAudPlay0BitStreamCtrlQueue, \
346 static int auddec_dsp_config(struct audio *audio, int enable)
348 audpp_cmd_cfg_dec_type cmd;
350 memset(&cmd, 0, sizeof(cmd));
351 cmd.cmd_id = AUDPP_CMD_CFG_DEC_TYPE;
353 cmd.dec0_cfg = AUDPP_CMD_UPDATDE_CFG_DEC |
354 AUDPP_CMD_ENA_DEC_V |
357 cmd.dec0_cfg = AUDPP_CMD_UPDATDE_CFG_DEC |
360 return audpp_send_queue1(&cmd, sizeof(cmd));
363 static void audpp_cmd_cfg_adec_params(struct audio *audio)
365 audpp_cmd_cfg_adec_params_mp3 cmd;
367 memset(&cmd, 0, sizeof(cmd));
368 cmd.common.cmd_id = AUDPP_CMD_CFG_ADEC_PARAMS;
369 cmd.common.length = AUDPP_CMD_CFG_ADEC_PARAMS_MP3_LEN;
370 cmd.common.dec_id = audio->dec_id;
371 cmd.common.input_sampling_frequency = audio->out_sample_rate;
373 audpp_send_queue2(&cmd, sizeof(cmd));
376 static void audpp_cmd_cfg_routing_mode(struct audio *audio)
378 struct audpp_cmd_routing_mode cmd;
379 pr_info("audpp_cmd_cfg_routing_mode()\n");
380 memset(&cmd, 0, sizeof(cmd));
381 cmd.cmd_id = AUDPP_CMD_ROUTING_MODE;
382 cmd.object_number = audio->dec_id;
383 if (audio->pcm_feedback)
384 cmd.routing_mode = ROUTING_MODE_FTRT;
386 cmd.routing_mode = ROUTING_MODE_RT;
388 audpp_send_queue1(&cmd, sizeof(cmd));
391 static int audplay_dsp_send_data_avail(struct audio *audio,
392 unsigned idx, unsigned len)
394 audplay_cmd_bitstream_data_avail cmd;
396 cmd.cmd_id = AUDPLAY_CMD_BITSTREAM_DATA_AVAIL;
397 cmd.decoder_id = audio->dec_id;
398 cmd.buf_ptr = audio->out[idx].addr;
399 cmd.buf_size = len/2;
400 cmd.partition_number = 0;
401 return audplay_send_queue0(audio, &cmd, sizeof(cmd));
404 static void audplay_buffer_refresh(struct audio *audio)
406 struct audplay_cmd_buffer_refresh refresh_cmd;
408 refresh_cmd.cmd_id = AUDPLAY_CMD_BUFFER_REFRESH;
409 refresh_cmd.num_buffers = 1;
410 refresh_cmd.buf0_address = audio->in[audio->fill_next].addr;
411 refresh_cmd.buf0_length = audio->in[audio->fill_next].size -
412 (audio->in[audio->fill_next].size % 576); /* Mp3 frame size */
413 refresh_cmd.buf_read_count = 0;
414 pr_info("audplay_buffer_fresh: buf0_addr=%x buf0_len=%d\n",
415 refresh_cmd.buf0_address, refresh_cmd.buf0_length);
416 (void)audplay_send_queue0(audio, &refresh_cmd, sizeof(refresh_cmd));
419 static void audplay_config_hostpcm(struct audio *audio)
421 struct audplay_cmd_hpcm_buf_cfg cfg_cmd;
423 pr_info("audplay_config_hostpcm()\n");
424 cfg_cmd.cmd_id = AUDPLAY_CMD_HPCM_BUF_CFG;
425 cfg_cmd.max_buffers = 1;
426 cfg_cmd.byte_swap = 0;
427 cfg_cmd.hostpcm_config = (0x8000) | (0x4000);
428 cfg_cmd.feedback_frequency = 1;
429 cfg_cmd.partition_number = 0;
430 (void)audplay_send_queue0(audio, &cfg_cmd, sizeof(cfg_cmd));
434 static void audplay_send_data(struct audio *audio, unsigned needed)
436 struct buffer *frame;
439 spin_lock_irqsave(&audio->dsp_lock, flags);
444 audio->out_needed = 1;
448 if (needed && !audio->wflush) {
449 /* We were called from the callback because the DSP
450 * requested more data. Note that the DSP does want
451 * more data, and if a buffer was in-flight, mark it
452 * as available (since the DSP must now be done with
455 audio->out_needed = 1;
456 frame = audio->out + audio->out_tail;
457 if (frame->used == 0xffffffff) {
458 dprintk("frame %d free\n", audio->out_tail);
460 audio->out_tail ^= 1;
461 wake_up(&audio->write_wait);
465 if (audio->out_needed) {
466 /* If the DSP currently wants data and we have a
467 * buffer available, we will send it and reset
468 * the needed flag. We'll mark the buffer as in-flight
469 * so that it won't be recycled until the next buffer
473 frame = audio->out + audio->out_tail;
475 BUG_ON(frame->used == 0xffffffff);
476 dprintk("frame %d busy\n", audio->out_tail);
477 audplay_dsp_send_data_avail(audio, audio->out_tail,
479 frame->used = 0xffffffff;
480 audio->out_needed = 0;
484 spin_unlock_irqrestore(&audio->dsp_lock, flags);
487 /* ------------------- device --------------------- */
489 static void audio_flush(struct audio *audio)
491 audio->out[0].used = 0;
492 audio->out[1].used = 0;
496 atomic_set(&audio->out_bytes, 0);
499 static void audio_flush_pcm_buf(struct audio *audio)
503 for (index = 0; index < PCM_BUF_MAX_COUNT; index++)
504 audio->in[index].used = 0;
506 audio->read_next = 0;
507 audio->fill_next = 0;
510 static void audio_ioport_reset(struct audio *audio)
512 /* Make sure read/write thread are free from
513 * sleep and knowing that system is not able
514 * to process io request at the moment
516 wake_up(&audio->write_wait);
517 mutex_lock(&audio->write_lock);
519 mutex_unlock(&audio->write_lock);
520 wake_up(&audio->read_wait);
521 mutex_lock(&audio->read_lock);
522 audio_flush_pcm_buf(audio);
523 mutex_unlock(&audio->read_lock);
526 static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
528 struct audio *audio = file->private_data;
531 pr_info("audio_ioctl() cmd = %d\n", cmd);
533 if (cmd == AUDIO_GET_STATS) {
534 struct msm_audio_stats stats;
535 stats.byte_count = audpp_avsync_byte_count(audio->dec_id);
536 stats.sample_count = audpp_avsync_sample_count(audio->dec_id);
537 if (copy_to_user((void *) arg, &stats, sizeof(stats)))
541 if (cmd == AUDIO_SET_VOLUME) {
543 spin_lock_irqsave(&audio->dsp_lock, flags);
546 audpp_set_volume_and_pan(audio->dec_id, arg, 0);
547 spin_unlock_irqrestore(&audio->dsp_lock, flags);
550 mutex_lock(&audio->lock);
553 rc = audio_enable(audio);
556 rc = audio_disable(audio);
558 audio_ioport_reset(audio);
562 dprintk("%s: AUDIO_FLUSH\n", __func__);
565 audio_ioport_reset(audio);
569 if (audio->buf_refresh) {
570 audio->buf_refresh = 0;
571 audplay_buffer_refresh(audio);
575 case AUDIO_SET_CONFIG: {
576 struct msm_audio_config config;
577 if (copy_from_user(&config, (void *) arg, sizeof(config))) {
581 if (config.channel_count == 1) {
582 config.channel_count = AUDPP_CMD_PCM_INTF_MONO_V;
583 } else if (config.channel_count == 2) {
584 config.channel_count = AUDPP_CMD_PCM_INTF_STEREO_V;
589 audio->out_sample_rate = config.sample_rate;
590 audio->out_channel_mode = config.channel_count;
594 case AUDIO_GET_CONFIG: {
595 struct msm_audio_config config;
596 config.buffer_size = (audio->out_dma_sz >> 1);
597 config.buffer_count = 2;
598 config.sample_rate = audio->out_sample_rate;
599 if (audio->out_channel_mode == AUDPP_CMD_PCM_INTF_MONO_V) {
600 config.channel_count = 1;
602 config.channel_count = 2;
604 config.unused[0] = 0;
605 config.unused[1] = 0;
606 config.unused[2] = 0;
607 config.unused[3] = 0;
608 if (copy_to_user((void *) arg, &config, sizeof(config))) {
615 case AUDIO_GET_PCM_CONFIG:{
616 struct msm_audio_pcm_config config;
617 config.pcm_feedback = 0;
618 config.buffer_count = PCM_BUF_MAX_COUNT;
619 config.buffer_size = PCM_BUFSZ_MIN;
620 if (copy_to_user((void *)arg, &config,
627 case AUDIO_SET_PCM_CONFIG:{
628 struct msm_audio_pcm_config config;
630 (&config, (void *)arg, sizeof(config))) {
634 if ((config.buffer_count > PCM_BUF_MAX_COUNT) ||
635 (config.buffer_count == 1))
636 config.buffer_count = PCM_BUF_MAX_COUNT;
638 if (config.buffer_size < PCM_BUFSZ_MIN)
639 config.buffer_size = PCM_BUFSZ_MIN;
641 /* Check if pcm feedback is required */
642 if ((config.pcm_feedback) && (!audio->read_data)) {
643 pr_info("ioctl: allocate PCM buffer %d\n",
644 config.buffer_count *
647 dma_alloc_coherent(NULL,
652 if (!audio->read_data) {
653 pr_err("audio_mp3: malloc pcm buf failed\n");
658 audio->pcm_feedback = 1;
659 audio->buf_refresh = 0;
660 audio->pcm_buf_count =
662 audio->read_next = 0;
663 audio->fill_next = 0;
666 index < config.buffer_count;
668 audio->in[index].data =
669 audio->read_data + offset;
670 audio->in[index].addr =
671 audio->read_phys + offset;
672 audio->in[index].size =
674 audio->in[index].used = 0;
675 offset += config.buffer_size;
685 dprintk("%s: AUDIO_PAUSE %ld\n", __func__, arg);
686 rc = audpp_pause(audio->dec_id, (int) arg);
691 mutex_unlock(&audio->lock);
695 static ssize_t audio_read(struct file *file, char __user *buf, size_t count,
698 struct audio *audio = file->private_data;
699 const char __user *start = buf;
702 if (!audio->pcm_feedback)
703 return 0; /* PCM feedback disabled. Nothing to read */
705 mutex_lock(&audio->read_lock);
706 pr_info("audio_read() %d \n", count);
708 rc = wait_event_interruptible(audio->read_wait,
709 (audio->in[audio->read_next].
710 used > 0) || (audio->stopped)
716 if (audio->stopped || audio->rflush) {
721 if (count < audio->in[audio->read_next].used) {
722 /* Read must happen in frame boundary. Since
723 * driver does not know frame size, read count
724 * must be greater or equal
725 * to size of PCM samples
727 pr_info("audio_read: no partial frame done reading\n");
730 pr_info("audio_read: read from in[%d]\n",
733 (buf, audio->in[audio->read_next].data,
734 audio->in[audio->read_next].used)) {
735 pr_err("audio_read: invalid addr %x \n",
740 count -= audio->in[audio->read_next].used;
741 buf += audio->in[audio->read_next].used;
742 audio->in[audio->read_next].used = 0;
743 if ((++audio->read_next) == audio->pcm_buf_count)
744 audio->read_next = 0;
745 if (audio->in[audio->read_next].used == 0)
746 break; /* No data ready at this moment
747 * Exit while loop to prevent
748 * output thread sleep too long
753 /* don't feed output buffer to HW decoder during flushing
754 * buffer refresh command will be sent once flush completes
755 * send buf refresh command here can confuse HW decoder
757 if (audio->buf_refresh && !audio->rflush) {
758 audio->buf_refresh = 0;
759 pr_info("audio_read: kick start pcm feedback again\n");
760 audplay_buffer_refresh(audio);
763 mutex_unlock(&audio->read_lock);
768 pr_info("audio_read: read %d bytes\n", rc);
772 static ssize_t audio_write(struct file *file, const char __user *buf,
773 size_t count, loff_t *pos)
775 struct audio *audio = file->private_data;
776 const char __user *start = buf;
777 struct buffer *frame;
783 mutex_lock(&audio->write_lock);
785 frame = audio->out + audio->out_head;
786 cpy_ptr = frame->data;
788 rc = wait_event_interruptible(audio->write_wait,
794 if (audio->stopped || audio->wflush) {
799 if (audio->reserved) {
800 dprintk("%s: append reserved byte %x\n",
801 __func__, audio->rsv_byte);
802 *cpy_ptr = audio->rsv_byte;
803 xfer = (count > (frame->size - 1)) ?
804 frame->size - 1 : count;
809 xfer = (count > frame->size) ? frame->size : count;
811 if (copy_from_user(cpy_ptr, buf, xfer)) {
818 audio->rsv_byte = ((char *) frame->data)[dsize - 1];
819 dprintk("%s: odd length buf reserve last byte %x\n",
820 __func__, audio->rsv_byte);
828 audio->out_head ^= 1;
830 audplay_send_data(audio, 0);
833 mutex_unlock(&audio->write_lock);
839 static int audio_release(struct inode *inode, struct file *file)
841 struct audio *audio = file->private_data;
843 dprintk("audio_release()\n");
845 mutex_lock(&audio->lock);
846 audio_disable(audio);
848 audio_flush_pcm_buf(audio);
849 msm_adsp_put(audio->audplay);
850 audio->audplay = NULL;
853 dma_free_coherent(NULL, audio->out_dma_sz, audio->data, audio->phys);
855 if (audio->read_data != NULL) {
856 dma_free_coherent(NULL,
857 audio->in[0].size * audio->pcm_buf_count,
858 audio->read_data, audio->read_phys);
859 audio->read_data = NULL;
861 audio->pcm_feedback = 0;
862 mutex_unlock(&audio->lock);
866 static struct audio the_mp3_audio;
868 static int audio_open(struct inode *inode, struct file *file)
870 struct audio *audio = &the_mp3_audio;
874 mutex_lock(&audio->lock);
877 pr_err("audio: busy\n");
884 while (pmem_sz >= DMASZ_MIN) {
885 audio->data = dma_alloc_coherent(NULL, pmem_sz,
886 &audio->phys, GFP_KERNEL);
889 else if (pmem_sz == DMASZ_MIN) {
890 pr_err("audio: could not allocate DMA buffers\n");
897 dprintk("%s: allocated %d bytes DMA buffer\n", __func__, pmem_sz);
899 rc = audmgr_open(&audio->audmgr);
901 dma_free_coherent(NULL, pmem_sz,
902 audio->data, audio->phys);
906 rc = msm_adsp_get("AUDPLAY0TASK", &audio->audplay, &audplay_adsp_ops,
909 pr_err("audio: failed to get audplay0 dsp module\n");
910 dma_free_coherent(NULL, pmem_sz,
911 audio->data, audio->phys);
912 audmgr_close(&audio->audmgr);
916 audio->out_dma_sz = pmem_sz;
917 pmem_sz >>= 1; /* Shift by 1 to get size of ping pong buffer */
919 audio->out_sample_rate = 44100;
920 audio->out_channel_mode = AUDPP_CMD_PCM_INTF_STEREO_V;
923 audio->out[0].data = audio->data + 0;
924 audio->out[0].addr = audio->phys + 0;
925 audio->out[0].size = pmem_sz;
927 audio->out[1].data = audio->data + pmem_sz;
928 audio->out[1].addr = audio->phys + pmem_sz;
929 audio->out[1].size = pmem_sz;
931 audio->volume = 0x2000; /* equal to Q13 number 1.0 Unit Gain */
935 file->private_data = audio;
939 mutex_unlock(&audio->lock);
943 static struct file_operations audio_mp3_fops = {
944 .owner = THIS_MODULE,
946 .release = audio_release,
948 .write = audio_write,
949 .unlocked_ioctl = audio_ioctl,
952 struct miscdevice audio_mp3_misc = {
953 .minor = MISC_DYNAMIC_MINOR,
955 .fops = &audio_mp3_fops,
958 static int __init audio_init(void)
960 mutex_init(&the_mp3_audio.lock);
961 mutex_init(&the_mp3_audio.write_lock);
962 mutex_init(&the_mp3_audio.read_lock);
963 spin_lock_init(&the_mp3_audio.dsp_lock);
964 init_waitqueue_head(&the_mp3_audio.write_wait);
965 init_waitqueue_head(&the_mp3_audio.read_wait);
966 the_mp3_audio.read_data = NULL;
967 return misc_register(&audio_mp3_misc);
970 device_initcall(audio_init);