2 * linux/sound/oss/omap-audio.c
4 * Common audio handling for the OMAP processors
6 * Copyright (C) 2004 Texas Instruments, Inc.
8 * Copyright (C) 2000, 2001 Nicolas Pitre <nico@cam.org>
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 * 2004/08/12 Nishanth Menon - Modified to integrate Audio requirements on 1610,1710 platforms
22 * 2004-11-01 Nishanth Menon - modified to support 16xx and 17xx
23 * platform multi channel chaining.
25 * 2004-11-04 Nishanth Menon - Added support for power management
27 * 2004-12-17 Nishanth Menon - Provided proper module handling support
30 /***************************** INCLUDES ************************************/
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/types.h>
37 #include <linux/slab.h>
38 #include <linux/sched.h>
39 #include <linux/poll.h>
41 #include <linux/errno.h>
42 #include <linux/sound.h>
43 #include <linux/soundcard.h>
44 #include <linux/sysrq.h>
45 #include <linux/delay.h>
46 #include <linux/platform_device.h>
47 #include <linux/completion.h>
48 #include <linux/mutex.h>
50 #include <asm/uaccess.h>
52 #include <asm/hardware.h>
54 #include "omap-audio-dma-intfc.h"
55 #include "omap-audio.h"
57 /***************************** MACROS ************************************/
62 #define DPRINTK printk
63 #define FN_IN printk("[omap_audio.c:[%s] start\n", __FUNCTION__)
64 #define FN_OUT(n) printk("[omap_audio.c:[%s] end(%d)\n", __FUNCTION__ , n)
66 #define DPRINTK( x... )
71 #define OMAP_AUDIO_NAME "omap-audio"
72 #define AUDIO_NBFRAGS_DEFAULT 8
73 #define AUDIO_FRAGSIZE_DEFAULT 8192
75 /* HACK ALERT!: These values will bave to be tuned as this is a trade off b/w
76 * Sampling Rate vs buffer size and delay we are prepared to do before giving up
78 #define MAX_QUEUE_FULL_RETRIES 1000000
79 #define QUEUE_WAIT_TIME 10
81 #define AUDIO_ACTIVE(state) ((state)->rd_ref || (state)->wr_ref)
83 #define SPIN_ADDR (dma_addr_t)0
84 #define SPIN_SIZE 2048
86 /***************************** MODULES SPECIFIC FUNCTION PROTOTYPES ********************/
88 static int audio_write(struct file *file, const char __user *buffer,
89 size_t count, loff_t * ppos);
91 static int audio_read(struct file *file, char __user *buffer, size_t count,
94 static int audio_mmap(struct file *file, struct vm_area_struct *vma);
96 static unsigned int audio_poll(struct file *file,
97 struct poll_table_struct *wait);
99 static loff_t audio_llseek(struct file *file, loff_t offset, int origin);
101 static int audio_ioctl(struct inode *inode, struct file *file, uint cmd,
104 static int audio_open(struct inode *inode, struct file *file);
106 static int audio_release(struct inode *inode, struct file *file);
108 static int audio_probe(struct platform_device *pdev);
110 static int audio_remove(struct platform_device *pdev);
112 static void audio_shutdown(struct platform_device *pdev);
114 static int audio_suspend(struct platform_device *pdev, pm_message_t mesg);
116 static int audio_resume(struct platform_device *pdev);
118 static void audio_free(struct device *dev);
120 /***************************** Data Structures **********************************/
123 * The function pointer set to be registered by the codec.
125 static audio_state_t audio_state = { NULL };
127 /* DMA Call back function */
128 static dma_callback_t audio_dma_callback = NULL;
130 /* File Ops structure */
131 static struct file_operations omap_audio_fops = {
133 .release = audio_release,
134 .write = audio_write,
138 .ioctl = audio_ioctl,
139 .llseek = audio_llseek,
143 /* Driver information */
144 static struct platform_driver omap_audio_driver = {
145 .probe = audio_probe,
146 .remove = audio_remove,
147 .suspend = audio_suspend,
148 .shutdown = audio_shutdown,
149 .resume = audio_resume,
151 .name = OMAP_AUDIO_NAME,
155 /* Device Information */
156 static struct platform_device omap_audio_device = {
157 .name = OMAP_AUDIO_NAME,
159 .driver_data = &audio_state,
160 .release = audio_free,
165 /***************************** GLOBAL FUNCTIONs **********************************/
167 /* Power Management Functions for Linux Device Model */
168 /* DEBUG PUPOSES ONLY! */
174 /*********************************************************************************
176 * audio_ldm_suspend(): Suspend operation
178 *********************************************************************************/
179 static int audio_ldm_suspend(void *data)
181 audio_state_t *state = data;
186 * Reject the suspend request if we are already actively transmitting data
187 * Rationale: We dont want to be suspended while in the middle of a call!
189 if (AUDIO_ACTIVE(state) && state->hw_init) {
190 printk(KERN_ERR "Audio device Active, Cannot Suspend");
194 * This Piece of code is commented out in hope
195 * That one day we would need to suspend the device while
196 * audio operations are in progress and resume the operations
197 * once the resume is done.
198 * This is just a sample implementation of how it could be done.
199 * Currently NOT SUPPORTED
201 audio_stream_t *is = state->input_stream;
202 audio_stream_t *os = state->output_stream;
204 if (is && is->buffers) {
205 printk("IS Suspend\n");
206 stopstate = is->stopped;
210 is->stopped = stopstate;
212 if (os && os->buffers) {
213 printk("OS Suspend\n");
214 stopstate = os->stopped;
218 os->stopped = stopstate;
227 /*********************************************************************************
229 * audio_ldm_resume(): Resume Operations
231 *********************************************************************************/
232 static int audio_ldm_resume(void *data)
234 audio_state_t *state = data;
237 if (AUDIO_ACTIVE(state) && state->hw_init) {
238 /* Should never occur - since we never suspend with active state */
243 * This Piece of code is commented out in hope
244 * That one day we would need to suspend the device while
245 * audio operations are in progress and resume the operations
246 * once the resume is done.
247 * This is just a sample implementation of how it could be done.
248 * Currently NOT SUPPORTED
250 audio_stream_t *is = state->input_stream;
251 audio_stream_t *os = state->output_stream;
252 if (os && os->buffers) {
253 printk("OS Resume\n");
255 audio_process_dma(os);
257 if (is && is->buffers) {
258 printk("IS Resume\n");
260 audio_process_dma(is);
267 #endif /* End of #ifdef CONFIG_PM */
269 /*********************************************************************************
271 * audio_free(): The Audio driver release function
272 * This is a dummy function required by the platform driver
274 *********************************************************************************/
275 static void audio_free(struct device *dev)
277 /* Nothing to Release! */
280 /*********************************************************************************
282 * audio_probe(): The Audio driver probe function
283 * WARNING!!!! : It is expected that the codec would have registered with us by now
285 *********************************************************************************/
286 static int audio_probe(struct platform_device *pdev)
290 if (!audio_state.hw_probe) {
291 printk(KERN_ERR "Probe Function Not Registered\n");
294 ret = audio_state.hw_probe();
299 /*********************************************************************************
301 * audio_remove() Function to handle removal operations
303 *********************************************************************************/
304 static int audio_remove(struct platform_device *pdev)
307 if (audio_state.hw_remove) {
308 audio_state.hw_remove();
314 /*********************************************************************************
316 * audio_shutdown(): Function to handle shutdown operations
318 *********************************************************************************/
319 static void audio_shutdown(struct platform_device *pdev)
322 if (audio_state.hw_cleanup) {
323 audio_state.hw_cleanup();
329 /*********************************************************************************
331 * audio_suspend(): Function to handle suspend operations
333 *********************************************************************************/
334 static int audio_suspend(struct platform_device *pdev, pm_message_t mesg)
339 void *data = pdev->dev.driver_data;
341 if (audio_state.hw_suspend) {
342 ret = audio_ldm_suspend(data);
344 ret = audio_state.hw_suspend();
347 printk(KERN_INFO "Audio Suspend Failed \n");
349 printk(KERN_INFO "Audio Suspend Success \n");
351 #endif /* CONFIG_PM */
357 /*********************************************************************************
359 * audio_resume(): Function to handle resume operations
361 *********************************************************************************/
362 static int audio_resume(struct platform_device *pdev)
367 void *data = pdev->dev.driver_data;
369 if (audio_state.hw_resume) {
370 ret = audio_ldm_resume(data);
372 ret = audio_state.hw_resume();
375 printk(KERN_INFO " Audio Resume Failed \n");
377 printk(KERN_INFO " Audio Resume Success \n");
379 #endif /* CONFIG_PM */
385 /*********************************************************************************
387 * audio_get_fops(): Return the fops required to get the function pointers of
390 *********************************************************************************/
391 struct file_operations *audio_get_fops(void)
395 return &omap_audio_fops;
398 /*********************************************************************************
400 * audio_register_codec(): Register a Codec fn points using this function
401 * WARNING!!!!! : Codecs should ensure that they do so! no sanity checks
402 * during runtime is done due to obvious performance
405 *********************************************************************************/
406 int audio_register_codec(audio_state_t * codec_state)
411 /* We dont handle multiple codecs now */
412 if (audio_state.hw_init) {
413 printk(KERN_ERR " Codec Already registered\n");
417 /* Grab the dma Callback */
418 audio_dma_callback = audio_get_dma_callback();
419 if (!audio_dma_callback) {
420 printk(KERN_ERR "Unable to get call back function\n");
426 printk(KERN_ERR "NULL ARGUMENT!\n");
430 if (!codec_state->hw_probe || !codec_state->hw_init
431 || !codec_state->hw_shutdown || !codec_state->client_ioctl) {
433 "Required Fn Entry point Missing probe=%p init=%p,down=%p,ioctl=%p!\n",
434 codec_state->hw_probe, codec_state->hw_init,
435 codec_state->hw_shutdown, codec_state->client_ioctl);
439 memcpy(&audio_state, codec_state, sizeof(audio_state_t));
440 mutex_init(&audio_state.mutex);
442 ret = platform_device_register(&omap_audio_device);
444 printk(KERN_ERR "Platform dev_register failed =%d\n", ret);
449 ret = platform_driver_register(&omap_audio_driver);
451 printk(KERN_ERR "Device Register failed =%d\n", ret);
453 platform_device_unregister(&omap_audio_device);
463 /*********************************************************************************
465 * audio_unregister_codec(): Un-Register a Codec using this function
467 *********************************************************************************/
468 int audio_unregister_codec(audio_state_t * codec_state)
472 /* We dont handle multiple codecs now */
473 if (!audio_state.hw_init) {
474 printk(KERN_ERR " No Codec registered\n");
478 if (audio_state.hw_init != codec_state->hw_init) {
480 " Attempt to unregister codec which was not registered with us\n");
484 platform_driver_unregister(&omap_audio_driver);
485 platform_device_unregister(&omap_audio_device);
487 memset(&audio_state, 0, sizeof(audio_state_t));
493 /***************************** MODULES SPECIFIC FUNCTION *************************/
495 /*********************************************************************************
497 * audio_write(): Exposed to write() call
499 *********************************************************************************/
501 audio_write(struct file *file, const char __user *buffer,
502 size_t count, loff_t * ppos)
504 const char __user *buffer0 = buffer;
505 audio_state_t *state = file->private_data;
506 audio_stream_t *s = state->output_stream;
507 int chunksize, ret = 0;
509 DPRINTK("audio_write: count=%d\n", count);
510 if (*ppos != file->f_pos) {
511 printk("FPOS not ppos ppos=0x%x fpos =0x%x\n", (u32) * ppos,
516 printk("s already mapped\n");
519 if (!s->buffers && audio_setup_buf(s)) {
520 printk("NO MEMORY\n");
525 audio_buf_t *b = &s->buffers[s->usr_head];
527 /* Wait for a buffer to become free */
528 if (file->f_flags & O_NONBLOCK) {
534 if (wait_for_completion_interruptible(&s->wfc))
537 /* Feed the current buffer */
538 chunksize = s->fragsize - b->offset;
539 if (chunksize > count)
541 DPRINTK("write %d to %d\n", chunksize, s->usr_head);
542 if (copy_from_user(b->data + b->offset, buffer, chunksize)) {
543 printk(KERN_ERR "Audio: CopyFrom User failed \n");
550 b->offset += chunksize;
552 if (b->offset < s->fragsize) {
557 /* Update pointers and send current fragment to DMA */
559 if (++s->usr_head >= s->nbfrags)
561 /* Add the num of frags pending */
565 audio_process_dma(s);
569 if ((buffer - buffer0))
570 ret = buffer - buffer0;
571 DPRINTK("audio_write: return=%d\n", ret);
575 /*********************************************************************************
577 * audio_read(): Exposed as read() function
579 *********************************************************************************/
581 audio_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
583 char __user *buffer0 = buffer;
584 audio_state_t *state = file->private_data;
585 audio_stream_t *s = state->input_stream;
586 int chunksize, ret = 0;
589 DPRINTK("audio_read: count=%d\n", count);
591 if (*ppos != file->f_pos) {
592 printk("AudioRead - FPOS not ppos ppos=0x%x fpos =0x%x\n",
593 (u32) * ppos, (u32) file->f_pos);
597 printk("AudioRead - s already mapped\n");
602 if (!s->buffers && audio_setup_buf(s)) {
603 printk("AudioRead - No Memory\n");
606 audio_prime_rx(state);
610 audio_buf_t *b = &s->buffers[s->usr_head];
612 /* Wait for a buffer to become full */
613 if (file->f_flags & O_NONBLOCK) {
619 if (wait_for_completion_interruptible(&s->wfc))
622 /* Grab data from the current buffer */
623 chunksize = s->fragsize - b->offset;
624 if (chunksize > count)
626 DPRINTK("read %d from %d\n", chunksize, s->usr_head);
627 if (copy_to_user(buffer, b->data + b->offset, chunksize)) {
633 b->offset += chunksize;
634 if (b->offset < s->fragsize) {
639 /* Update pointers and return current fragment to DMA */
640 local_irq_save(flags);
642 if (++s->usr_head >= s->nbfrags)
646 local_irq_restore(flags);
647 audio_process_dma(s);
651 if ((buffer - buffer0))
652 ret = buffer - buffer0;
653 DPRINTK("audio_read: return=%d\n", ret);
657 /*********************************************************************************
659 * audio_mmap(): Exposed as mmap Function
660 * !!WARNING: Still under development
662 *********************************************************************************/
663 static int audio_mmap(struct file *file, struct vm_area_struct *vma)
665 audio_state_t *state = file->private_data;
667 unsigned long size, vma_addr;
671 if (vma->vm_pgoff != 0)
674 if (vma->vm_flags & VM_WRITE) {
677 s = state->output_stream;
678 } else if (vma->vm_flags & VM_READ) {
681 s = state->input_stream;
687 size = vma->vm_end - vma->vm_start;
688 if (size != s->fragsize * s->nbfrags)
690 if (!s->buffers && audio_setup_buf(s))
692 vma_addr = vma->vm_start;
693 for (i = 0; i < s->nbfrags; i++) {
694 audio_buf_t *buf = &s->buffers[i];
698 remap_pfn_range(vma, vma_addr, buf->dma_addr >> PAGE_SHIFT,
699 buf->master, vma->vm_page_prot);
702 vma_addr += buf->master;
710 /*********************************************************************************
712 * audio_poll(): Exposed as poll function
714 *********************************************************************************/
716 audio_poll(struct file *file, struct poll_table_struct *wait)
718 audio_state_t *state = file->private_data;
719 audio_stream_t *is = state->input_stream;
720 audio_stream_t *os = state->output_stream;
721 unsigned int mask = 0;
723 DPRINTK("audio_poll(): mode=%s%s\n",
724 (file->f_mode & FMODE_READ) ? "r" : "",
725 (file->f_mode & FMODE_WRITE) ? "w" : "");
727 if (file->f_mode & FMODE_READ) {
728 /* Start audio input if not already active */
730 if (!is->buffers && audio_setup_buf(is))
732 audio_prime_rx(state);
734 poll_wait(file, &is->wq, wait);
737 if (file->f_mode & FMODE_WRITE) {
738 if (!os->buffers && audio_setup_buf(os))
740 poll_wait(file, &os->wq, wait);
743 if (file->f_mode & FMODE_READ)
744 if ((is->mapped && is->bytecount > 0) ||
745 (!is->mapped && is->wfc.done > 0))
746 mask |= POLLIN | POLLRDNORM;
748 if (file->f_mode & FMODE_WRITE)
749 if ((os->mapped && os->bytecount > 0) ||
750 (!os->mapped && os->wfc.done > 0))
751 mask |= POLLOUT | POLLWRNORM;
753 DPRINTK("audio_poll() returned mask of %s%s\n",
754 (mask & POLLIN) ? "r" : "", (mask & POLLOUT) ? "w" : "");
760 /*********************************************************************************
762 * audio_llseek(): Exposed as lseek() function.
764 *********************************************************************************/
765 static loff_t audio_llseek(struct file *file, loff_t offset, int origin)
772 /*********************************************************************************
774 * audio_ioctl(): Handles generic ioctls. If there is a request for something this
775 * fn cannot handle, its then given to client specific ioctl routine, that will take
776 * up platform specific requests
778 *********************************************************************************/
780 audio_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
782 audio_state_t *state = file->private_data;
783 audio_stream_t *os = state->output_stream;
784 audio_stream_t *is = state->input_stream;
787 DPRINTK(__FILE__ " audio_ioctl 0x%08x\n", cmd);
789 /* dispatch based on command */
792 return put_user(SOUND_VERSION, (int __user *)arg);
794 case SNDCTL_DSP_GETBLKSIZE:
795 if (file->f_mode & FMODE_WRITE)
796 return put_user(os->fragsize, (int __user *)arg);
798 return put_user(is->fragsize, (int __user *)arg);
800 case SNDCTL_DSP_GETCAPS:
801 val = DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP;
803 val |= DSP_CAP_DUPLEX;
805 return put_user(val, (int __user *)arg);
807 case SNDCTL_DSP_SETFRAGMENT:
808 if (get_user(val, (long __user *)arg)) {
812 if (file->f_mode & FMODE_READ) {
813 int ret = audio_set_fragments(is, val);
818 ret = put_user(ret, (int __user *)arg);
824 if (file->f_mode & FMODE_WRITE) {
825 int ret = audio_set_fragments(os, val);
830 ret = put_user(ret, (int __user *)arg);
839 case SNDCTL_DSP_SYNC:
841 return audio_sync(file);
843 case SNDCTL_DSP_SETDUPLEX:
847 case SNDCTL_DSP_POST:
851 case SNDCTL_DSP_GETTRIGGER:
853 if (file->f_mode & FMODE_READ && is->active && !is->stopped)
854 val |= PCM_ENABLE_INPUT;
855 if (file->f_mode & FMODE_WRITE && os->active && !os->stopped)
856 val |= PCM_ENABLE_OUTPUT;
858 return put_user(val, (int __user *)arg);
860 case SNDCTL_DSP_SETTRIGGER:
861 if (get_user(val, (int __user *)arg)) {
865 if (file->f_mode & FMODE_READ) {
866 if (val & PCM_ENABLE_INPUT) {
869 if (!is->buffers && audio_setup_buf(is)) {
873 audio_prime_rx(state);
875 local_irq_save(flags);
877 local_irq_restore(flags);
878 audio_process_dma(is);
884 if (file->f_mode & FMODE_WRITE) {
885 if (val & PCM_ENABLE_OUTPUT) {
887 if (!os->buffers && audio_setup_buf(os)) {
891 local_irq_save(flags);
892 if (os->mapped && !os->pending_frags) {
893 os->pending_frags = os->nbfrags;
894 init_completion(&os->wfc);
899 local_irq_restore(flags);
900 audio_process_dma(os);
909 case SNDCTL_DSP_GETOPTR:
910 case SNDCTL_DSP_GETIPTR:
912 count_info inf = { 0, };
914 (cmd == SNDCTL_DSP_GETOPTR) ? os : is;
915 int bytecount, offset;
918 if ((s == is && !(file->f_mode & FMODE_READ)) ||
919 (s == os && !(file->f_mode & FMODE_WRITE))) {
924 local_irq_save(flags);
925 offset = audio_get_dma_pos(s);
926 inf.ptr = s->dma_tail * s->fragsize + offset;
927 bytecount = s->bytecount + offset;
928 s->bytecount = -offset;
929 inf.blocks = s->fragcount;
931 local_irq_restore(flags);
934 inf.bytes = bytecount;
937 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
940 case SNDCTL_DSP_GETOSPACE:
941 case SNDCTL_DSP_GETISPACE:
943 audio_buf_info inf = { 0, };
945 (cmd == SNDCTL_DSP_GETOSPACE) ? os : is;
947 if ((s == is && !(file->f_mode & FMODE_READ)) ||
948 (s == os && !(file->f_mode & FMODE_WRITE))) {
952 if (!s->buffers && audio_setup_buf(s)) {
956 inf.bytes = s->wfc.done * s->fragsize;
958 inf.fragments = inf.bytes / s->fragsize;
959 inf.fragsize = s->fragsize;
960 inf.fragstotal = s->nbfrags;
962 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
965 case SNDCTL_DSP_NONBLOCK:
966 file->f_flags |= O_NONBLOCK;
970 case SNDCTL_DSP_RESET:
971 if (file->f_mode & FMODE_READ) {
973 if (state->need_tx_for_rx) {
975 local_irq_save(flags);
977 local_irq_restore(flags);
980 if (file->f_mode & FMODE_WRITE) {
988 * Let the client of this module handle the
992 return state->client_ioctl(inode, file, cmd, arg);
999 /*********************************************************************************
1001 * audio_open(): Exposed as open() function
1003 *********************************************************************************/
1004 static int audio_open(struct inode *inode, struct file *file)
1006 audio_state_t *state = (&audio_state);
1007 audio_stream_t *os = state->output_stream;
1008 audio_stream_t *is = state->input_stream;
1009 int err, need_tx_dma;
1010 static unsigned char tsc2101_init_flag = 0;
1014 /* Lock the module */
1015 if (!try_module_get(THIS_MODULE)) {
1016 printk(KERN_CRIT "Failed to get module\n");
1019 /* Lock the codec module */
1020 if (!try_module_get(state->owner)) {
1021 printk(KERN_CRIT "Failed to get codec module\n");
1022 module_put(THIS_MODULE);
1026 mutex_lock(&state->mutex);
1028 /* access control */
1030 if ((file->f_mode & FMODE_WRITE) && !os)
1032 if ((file->f_mode & FMODE_READ) && !is)
1035 if ((file->f_mode & FMODE_WRITE) && state->wr_ref)
1037 if ((file->f_mode & FMODE_READ) && state->rd_ref)
1040 if ((file->f_mode & FMODE_READ) && state->need_tx_for_rx && !os)
1043 /* request DMA channels */
1044 need_tx_dma = ((file->f_mode & FMODE_WRITE) ||
1045 ((file->f_mode & FMODE_READ) && state->need_tx_for_rx));
1046 if (state->wr_ref || (state->rd_ref && state->need_tx_for_rx))
1049 DMA_REQUEST(err, os, audio_dma_callback);
1053 if (file->f_mode & FMODE_READ) {
1054 DMA_REQUEST(err, is, audio_dma_callback);
1062 /* now complete initialisation */
1063 if (!AUDIO_ACTIVE(state)) {
1064 if (state->hw_init && !tsc2101_init_flag) {
1065 state->hw_init(state->data);
1066 tsc2101_init_flag = 0;
1072 if ((file->f_mode & FMODE_WRITE)) {
1075 os->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1076 os->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1078 init_waitqueue_head(&os->wq);
1081 if (file->f_mode & FMODE_READ) {
1084 is->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1085 is->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1087 init_waitqueue_head(&is->wq);
1090 file->private_data = state;
1094 mutex_unlock(&state->mutex);
1096 module_put(state->owner);
1097 module_put(THIS_MODULE);
1103 /*********************************************************************************
1105 * audio_release(): Exposed as release function()
1107 *********************************************************************************/
1108 static int audio_release(struct inode *inode, struct file *file)
1110 audio_state_t *state = file->private_data;
1111 audio_stream_t *os = state->output_stream;
1112 audio_stream_t *is = state->input_stream;
1116 mutex_lock(&state->mutex);
1118 if (file->f_mode & FMODE_READ) {
1119 audio_discard_buf(is);
1121 is->dma_spinref = 0;
1122 if (state->need_tx_for_rx) {
1124 if (!state->wr_ref) {
1126 os->dma_spinref = 0;
1132 if (file->f_mode & FMODE_WRITE) {
1134 audio_discard_buf(os);
1135 if (!state->need_tx_for_rx || !state->rd_ref) {
1137 os->dma_spinref = 0;
1142 if (!AUDIO_ACTIVE(state)) {
1143 if (state->hw_shutdown)
1144 state->hw_shutdown(state->data);
1147 mutex_unlock(&state->mutex);
1149 module_put(state->owner);
1150 module_put(THIS_MODULE);
1156 EXPORT_SYMBOL(audio_register_codec);
1157 EXPORT_SYMBOL(audio_unregister_codec);
1158 EXPORT_SYMBOL(audio_get_fops);
1160 MODULE_AUTHOR("Texas Instruments");
1161 MODULE_DESCRIPTION("Common audio handling for OMAP processors");
1162 MODULE_LICENSE("GPL");