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/config.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
38 #include <linux/slab.h>
39 #include <linux/sched.h>
40 #include <linux/poll.h>
42 #include <linux/errno.h>
43 #include <linux/sound.h>
44 #include <linux/soundcard.h>
45 #include <linux/sysrq.h>
46 #include <linux/delay.h>
47 #include <linux/device.h>
48 #include <linux/completion.h>
50 #include <asm/uaccess.h>
52 #include <asm/hardware.h>
53 #include <asm/semaphore.h>
55 #include "omap-audio-dma-intfc.h"
56 #include "omap-audio.h"
58 /***************************** MACROS ************************************/
63 #define DPRINTK printk
64 #define FN_IN printk("[omap_audio.c:[%s] start\n", __FUNCTION__)
65 #define FN_OUT(n) printk("[omap_audio.c:[%s] end(%d)\n", __FUNCTION__ , n)
67 #define DPRINTK( x... )
72 #define OMAP_AUDIO_NAME "omap-audio"
73 #define AUDIO_NBFRAGS_DEFAULT 8
74 #define AUDIO_FRAGSIZE_DEFAULT 8192
76 /* HACK ALERT!: These values will bave to be tuned as this is a trade off b/w
77 * Sampling Rate vs buffer size and delay we are prepared to do before giving up
79 #define MAX_QUEUE_FULL_RETRIES 1000000
80 #define QUEUE_WAIT_TIME 10
82 #define AUDIO_ACTIVE(state) ((state)->rd_ref || (state)->wr_ref)
84 #define SPIN_ADDR (dma_addr_t)0
85 #define SPIN_SIZE 2048
87 /***************************** MODULES SPECIFIC FUNCTION PROTOTYPES ********************/
89 static int audio_write(struct file *file, const char __user *buffer,
90 size_t count, loff_t * ppos);
92 static int audio_read(struct file *file, char __user *buffer, size_t count,
95 static int audio_mmap(struct file *file, struct vm_area_struct *vma);
97 static unsigned int audio_poll(struct file *file,
98 struct poll_table_struct *wait);
100 static loff_t audio_llseek(struct file *file, loff_t offset, int origin);
102 static int audio_ioctl(struct inode *inode, struct file *file, uint cmd,
105 static int audio_open(struct inode *inode, struct file *file);
107 static int audio_release(struct inode *inode, struct file *file);
109 static int audio_probe(struct device *dev);
111 static int audio_remove(struct device *dev);
113 static void audio_shutdown(struct device *dev);
115 static int audio_suspend(struct device *dev, pm_message_t mesg, u32 level);
117 static int audio_resume(struct device *dev, u32 level);
119 static void audio_free(struct device *dev);
121 /***************************** Data Structures **********************************/
124 * The function pointer set to be registered by the codec.
126 static audio_state_t audio_state = { NULL };
128 /* DMA Call back function */
129 static dma_callback_t audio_dma_callback = NULL;
131 /* File Ops structure */
132 static struct file_operations omap_audio_fops = {
134 .release = audio_release,
135 .write = audio_write,
139 .ioctl = audio_ioctl,
140 .llseek = audio_llseek,
144 /* Driver information */
145 static struct device_driver omap_audio_driver = {
146 .name = OMAP_AUDIO_NAME,
147 .bus = &platform_bus_type,
148 .probe = audio_probe,
149 .remove = audio_remove,
150 .suspend = audio_suspend,
151 .resume = audio_resume,
152 .shutdown = audio_shutdown,
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 device *dev)
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 device *dev)
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 device *dev)
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 device *dev, pm_message_t mesg, u32 level)
339 void *data = dev->driver_data;
341 if (level != SUSPEND_POWER_DOWN) {
344 if (audio_state.hw_suspend) {
345 ret = audio_ldm_suspend(data);
347 ret = audio_state.hw_suspend();
350 printk(KERN_INFO "Audio Suspend Failed \n");
352 printk(KERN_INFO "Audio Suspend Success \n");
354 #endif /* CONFIG_PM */
360 /*********************************************************************************
362 * audio_resume(): Function to handle resume operations
364 *********************************************************************************/
365 static int audio_resume(struct device *dev, u32 level)
370 void *data = dev->driver_data;
372 if (level != RESUME_POWER_ON) {
375 if (audio_state.hw_resume) {
376 ret = audio_ldm_resume(data);
378 ret = audio_state.hw_resume();
381 printk(KERN_INFO " Audio Resume Failed \n");
383 printk(KERN_INFO " Audio Resume Success \n");
385 #endif /* CONFIG_PM */
391 /*********************************************************************************
393 * audio_get_fops(): Return the fops required to get the function pointers of
396 *********************************************************************************/
397 struct file_operations *audio_get_fops(void)
401 return &omap_audio_fops;
404 /*********************************************************************************
406 * audio_register_codec(): Register a Codec fn points using this function
407 * WARNING!!!!! : Codecs should ensure that they do so! no sanity checks
408 * during runtime is done due to obvious performance
411 *********************************************************************************/
412 int audio_register_codec(audio_state_t * codec_state)
417 /* We dont handle multiple codecs now */
418 if (audio_state.hw_init) {
419 printk(KERN_ERR " Codec Already registered\n");
423 /* Grab the dma Callback */
424 audio_dma_callback = audio_get_dma_callback();
425 if (!audio_dma_callback) {
426 printk(KERN_ERR "Unable to get call back function\n");
432 printk(KERN_ERR "NULL ARGUMENT!\n");
436 if (!codec_state->hw_probe || !codec_state->hw_init
437 || !codec_state->hw_shutdown || !codec_state->client_ioctl) {
439 "Required Fn Entry point Missing probe=%p init=%p,down=%p,ioctl=%p!\n",
440 codec_state->hw_probe, codec_state->hw_init,
441 codec_state->hw_shutdown, codec_state->client_ioctl);
445 memcpy(&audio_state, codec_state, sizeof(audio_state_t));
446 sema_init(&audio_state.sem, 1);
448 ret = platform_device_register(&omap_audio_device);
450 printk(KERN_ERR "Platform dev_register failed =%d\n", ret);
455 ret = driver_register(&omap_audio_driver);
457 printk(KERN_ERR "Device Register failed =%d\n", ret);
459 platform_device_unregister(&omap_audio_device);
469 /*********************************************************************************
471 * audio_unregister_codec(): Un-Register a Codec using this function
473 *********************************************************************************/
474 int audio_unregister_codec(audio_state_t * codec_state)
478 /* We dont handle multiple codecs now */
479 if (!audio_state.hw_init) {
480 printk(KERN_ERR " No Codec registered\n");
484 if (audio_state.hw_init != codec_state->hw_init) {
486 " Attempt to unregister codec which was not registered with us\n");
490 driver_unregister(&omap_audio_driver);
491 platform_device_unregister(&omap_audio_device);
493 memset(&audio_state, 0, sizeof(audio_state_t));
499 /***************************** MODULES SPECIFIC FUNCTION *************************/
501 /*********************************************************************************
503 * audio_write(): Exposed to write() call
505 *********************************************************************************/
507 audio_write(struct file *file, const char __user *buffer,
508 size_t count, loff_t * ppos)
510 const char __user *buffer0 = buffer;
511 audio_state_t *state = file->private_data;
512 audio_stream_t *s = state->output_stream;
513 int chunksize, ret = 0;
515 DPRINTK("audio_write: count=%d\n", count);
516 if (*ppos != file->f_pos) {
517 printk("FPOS not ppos ppos=0x%x fpos =0x%x\n", (u32) * ppos,
522 printk("s already mapped\n");
525 if (!s->buffers && audio_setup_buf(s)) {
526 printk("NO MEMORY\n");
531 audio_buf_t *b = &s->buffers[s->usr_head];
533 /* Wait for a buffer to become free */
534 if (file->f_flags & O_NONBLOCK) {
540 if (wait_for_completion_interruptible(&s->wfc))
543 /* Feed the current buffer */
544 chunksize = s->fragsize - b->offset;
545 if (chunksize > count)
547 DPRINTK("write %d to %d\n", chunksize, s->usr_head);
548 if (copy_from_user(b->data + b->offset, buffer, chunksize)) {
549 printk(KERN_ERR "Audio: CopyFrom User failed \n");
556 b->offset += chunksize;
558 if (b->offset < s->fragsize) {
563 /* Update pointers and send current fragment to DMA */
565 if (++s->usr_head >= s->nbfrags)
567 /* Add the num of frags pending */
571 audio_process_dma(s);
575 if ((buffer - buffer0))
576 ret = buffer - buffer0;
577 DPRINTK("audio_write: return=%d\n", ret);
581 /*********************************************************************************
583 * audio_read(): Exposed as read() function
585 *********************************************************************************/
587 audio_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
589 char __user *buffer0 = buffer;
590 audio_state_t *state = file->private_data;
591 audio_stream_t *s = state->input_stream;
592 int chunksize, ret = 0;
595 DPRINTK("audio_read: count=%d\n", count);
597 if (*ppos != file->f_pos) {
598 printk("AudioRead - FPOS not ppos ppos=0x%x fpos =0x%x\n",
599 (u32) * ppos, (u32) file->f_pos);
603 printk("AudioRead - s already mapped\n");
608 if (!s->buffers && audio_setup_buf(s)) {
609 printk("AudioRead - No Memory\n");
612 audio_prime_rx(state);
616 audio_buf_t *b = &s->buffers[s->usr_head];
618 /* Wait for a buffer to become full */
619 if (file->f_flags & O_NONBLOCK) {
625 if (wait_for_completion_interruptible(&s->wfc))
628 /* Grab data from the current buffer */
629 chunksize = s->fragsize - b->offset;
630 if (chunksize > count)
632 DPRINTK("read %d from %d\n", chunksize, s->usr_head);
633 if (copy_to_user(buffer, b->data + b->offset, chunksize)) {
639 b->offset += chunksize;
640 if (b->offset < s->fragsize) {
645 /* Update pointers and return current fragment to DMA */
646 local_irq_save(flags);
648 if (++s->usr_head >= s->nbfrags)
652 local_irq_restore(flags);
653 audio_process_dma(s);
657 if ((buffer - buffer0))
658 ret = buffer - buffer0;
659 DPRINTK("audio_read: return=%d\n", ret);
663 /*********************************************************************************
665 * audio_mmap(): Exposed as mmap Function
666 * !!WARNING: Still under development
668 *********************************************************************************/
669 static int audio_mmap(struct file *file, struct vm_area_struct *vma)
671 audio_state_t *state = file->private_data;
673 unsigned long size, vma_addr;
677 if (vma->vm_pgoff != 0)
680 if (vma->vm_flags & VM_WRITE) {
683 s = state->output_stream;
684 } else if (vma->vm_flags & VM_READ) {
687 s = state->input_stream;
693 size = vma->vm_end - vma->vm_start;
694 if (size != s->fragsize * s->nbfrags)
696 if (!s->buffers && audio_setup_buf(s))
698 vma_addr = vma->vm_start;
699 for (i = 0; i < s->nbfrags; i++) {
700 audio_buf_t *buf = &s->buffers[i];
704 remap_pfn_range(vma, vma_addr, buf->dma_addr >> PAGE_SHIFT,
705 buf->master, vma->vm_page_prot);
708 vma_addr += buf->master;
716 /*********************************************************************************
718 * audio_poll(): Exposed as poll function
720 *********************************************************************************/
722 audio_poll(struct file *file, struct poll_table_struct *wait)
724 audio_state_t *state = file->private_data;
725 audio_stream_t *is = state->input_stream;
726 audio_stream_t *os = state->output_stream;
727 unsigned int mask = 0;
729 DPRINTK("audio_poll(): mode=%s%s\n",
730 (file->f_mode & FMODE_READ) ? "r" : "",
731 (file->f_mode & FMODE_WRITE) ? "w" : "");
733 if (file->f_mode & FMODE_READ) {
734 /* Start audio input if not already active */
736 if (!is->buffers && audio_setup_buf(is))
738 audio_prime_rx(state);
740 poll_wait(file, &is->wq, wait);
743 if (file->f_mode & FMODE_WRITE) {
744 if (!os->buffers && audio_setup_buf(os))
746 poll_wait(file, &os->wq, wait);
749 if (file->f_mode & FMODE_READ)
750 if ((is->mapped && is->bytecount > 0) ||
751 (!is->mapped && is->wfc.done > 0))
752 mask |= POLLIN | POLLRDNORM;
754 if (file->f_mode & FMODE_WRITE)
755 if ((os->mapped && os->bytecount > 0) ||
756 (!os->mapped && os->wfc.done > 0))
757 mask |= POLLOUT | POLLWRNORM;
759 DPRINTK("audio_poll() returned mask of %s%s\n",
760 (mask & POLLIN) ? "r" : "", (mask & POLLOUT) ? "w" : "");
766 /*********************************************************************************
768 * audio_llseek(): Exposed as lseek() function.
770 *********************************************************************************/
771 static loff_t audio_llseek(struct file *file, loff_t offset, int origin)
778 /*********************************************************************************
780 * audio_ioctl(): Handles generic ioctls. If there is a request for something this
781 * fn cannot handle, its then given to client specific ioctl routine, that will take
782 * up platform specific requests
784 *********************************************************************************/
786 audio_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
788 audio_state_t *state = file->private_data;
789 audio_stream_t *os = state->output_stream;
790 audio_stream_t *is = state->input_stream;
793 DPRINTK(__FILE__ " audio_ioctl 0x%08x\n", cmd);
795 /* dispatch based on command */
798 return put_user(SOUND_VERSION, (int __user *)arg);
800 case SNDCTL_DSP_GETBLKSIZE:
801 if (file->f_mode & FMODE_WRITE)
802 return put_user(os->fragsize, (int __user *)arg);
804 return put_user(is->fragsize, (int __user *)arg);
806 case SNDCTL_DSP_GETCAPS:
807 val = DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP;
809 val |= DSP_CAP_DUPLEX;
811 return put_user(val, (int __user *)arg);
813 case SNDCTL_DSP_SETFRAGMENT:
814 if (get_user(val, (long __user *)arg)) {
818 if (file->f_mode & FMODE_READ) {
819 int ret = audio_set_fragments(is, val);
824 ret = put_user(ret, (int __user *)arg);
830 if (file->f_mode & FMODE_WRITE) {
831 int ret = audio_set_fragments(os, val);
836 ret = put_user(ret, (int __user *)arg);
845 case SNDCTL_DSP_SYNC:
847 return audio_sync(file);
849 case SNDCTL_DSP_SETDUPLEX:
853 case SNDCTL_DSP_POST:
857 case SNDCTL_DSP_GETTRIGGER:
859 if (file->f_mode & FMODE_READ && is->active && !is->stopped)
860 val |= PCM_ENABLE_INPUT;
861 if (file->f_mode & FMODE_WRITE && os->active && !os->stopped)
862 val |= PCM_ENABLE_OUTPUT;
864 return put_user(val, (int __user *)arg);
866 case SNDCTL_DSP_SETTRIGGER:
867 if (get_user(val, (int __user *)arg)) {
871 if (file->f_mode & FMODE_READ) {
872 if (val & PCM_ENABLE_INPUT) {
875 if (!is->buffers && audio_setup_buf(is)) {
879 audio_prime_rx(state);
881 local_irq_save(flags);
883 local_irq_restore(flags);
884 audio_process_dma(is);
890 if (file->f_mode & FMODE_WRITE) {
891 if (val & PCM_ENABLE_OUTPUT) {
893 if (!os->buffers && audio_setup_buf(os)) {
897 local_irq_save(flags);
898 if (os->mapped && !os->pending_frags) {
899 os->pending_frags = os->nbfrags;
900 init_completion(&os->wfc);
905 local_irq_restore(flags);
906 audio_process_dma(os);
915 case SNDCTL_DSP_GETOPTR:
916 case SNDCTL_DSP_GETIPTR:
918 count_info inf = { 0, };
920 (cmd == SNDCTL_DSP_GETOPTR) ? os : is;
921 int bytecount, offset;
924 if ((s == is && !(file->f_mode & FMODE_READ)) ||
925 (s == os && !(file->f_mode & FMODE_WRITE))) {
930 local_irq_save(flags);
931 offset = audio_get_dma_pos(s);
932 inf.ptr = s->dma_tail * s->fragsize + offset;
933 bytecount = s->bytecount + offset;
934 s->bytecount = -offset;
935 inf.blocks = s->fragcount;
937 local_irq_restore(flags);
940 inf.bytes = bytecount;
943 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
946 case SNDCTL_DSP_GETOSPACE:
947 case SNDCTL_DSP_GETISPACE:
949 audio_buf_info inf = { 0, };
951 (cmd == SNDCTL_DSP_GETOSPACE) ? os : is;
953 if ((s == is && !(file->f_mode & FMODE_READ)) ||
954 (s == os && !(file->f_mode & FMODE_WRITE))) {
958 if (!s->buffers && audio_setup_buf(s)) {
962 inf.bytes = s->wfc.done * s->fragsize;
964 inf.fragments = inf.bytes / s->fragsize;
965 inf.fragsize = s->fragsize;
966 inf.fragstotal = s->nbfrags;
968 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
971 case SNDCTL_DSP_NONBLOCK:
972 file->f_flags |= O_NONBLOCK;
976 case SNDCTL_DSP_RESET:
977 if (file->f_mode & FMODE_READ) {
979 if (state->need_tx_for_rx) {
981 local_irq_save(flags);
983 local_irq_restore(flags);
986 if (file->f_mode & FMODE_WRITE) {
994 * Let the client of this module handle the
998 return state->client_ioctl(inode, file, cmd, arg);
1005 /*********************************************************************************
1007 * audio_open(): Exposed as open() function
1009 *********************************************************************************/
1010 static int audio_open(struct inode *inode, struct file *file)
1012 audio_state_t *state = (&audio_state);
1013 audio_stream_t *os = state->output_stream;
1014 audio_stream_t *is = state->input_stream;
1015 int err, need_tx_dma;
1016 static unsigned char tsc2101_init_flag = 0;
1020 /* Lock the module */
1021 if (!try_module_get(THIS_MODULE)) {
1022 printk(KERN_CRIT "Failed to get module\n");
1025 /* Lock the codec module */
1026 if (!try_module_get(state->owner)) {
1027 printk(KERN_CRIT "Failed to get codec module\n");
1028 module_put(THIS_MODULE);
1034 /* access control */
1036 if ((file->f_mode & FMODE_WRITE) && !os)
1038 if ((file->f_mode & FMODE_READ) && !is)
1041 if ((file->f_mode & FMODE_WRITE) && state->wr_ref)
1043 if ((file->f_mode & FMODE_READ) && state->rd_ref)
1046 if ((file->f_mode & FMODE_READ) && state->need_tx_for_rx && !os)
1049 /* request DMA channels */
1050 need_tx_dma = ((file->f_mode & FMODE_WRITE) ||
1051 ((file->f_mode & FMODE_READ) && state->need_tx_for_rx));
1052 if (state->wr_ref || (state->rd_ref && state->need_tx_for_rx))
1055 DMA_REQUEST(err, os, audio_dma_callback);
1059 if (file->f_mode & FMODE_READ) {
1060 DMA_REQUEST(err, is, audio_dma_callback);
1068 /* now complete initialisation */
1069 if (!AUDIO_ACTIVE(state)) {
1070 if (state->hw_init && !tsc2101_init_flag) {
1071 state->hw_init(state->data);
1072 tsc2101_init_flag = 0;
1078 if ((file->f_mode & FMODE_WRITE)) {
1081 os->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1082 os->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1084 init_waitqueue_head(&os->wq);
1087 if (file->f_mode & FMODE_READ) {
1090 is->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1091 is->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1093 init_waitqueue_head(&is->wq);
1096 file->private_data = state;
1102 module_put(state->owner);
1103 module_put(THIS_MODULE);
1109 /*********************************************************************************
1111 * audio_release(): Exposed as release function()
1113 *********************************************************************************/
1114 static int audio_release(struct inode *inode, struct file *file)
1116 audio_state_t *state = file->private_data;
1117 audio_stream_t *os = state->output_stream;
1118 audio_stream_t *is = state->input_stream;
1124 if (file->f_mode & FMODE_READ) {
1125 audio_discard_buf(is);
1127 is->dma_spinref = 0;
1128 if (state->need_tx_for_rx) {
1130 if (!state->wr_ref) {
1132 os->dma_spinref = 0;
1138 if (file->f_mode & FMODE_WRITE) {
1140 audio_discard_buf(os);
1141 if (!state->need_tx_for_rx || !state->rd_ref) {
1143 os->dma_spinref = 0;
1148 if (!AUDIO_ACTIVE(state)) {
1149 if (state->hw_shutdown)
1150 state->hw_shutdown(state->data);
1155 module_put(state->owner);
1156 module_put(THIS_MODULE);
1162 EXPORT_SYMBOL(audio_register_codec);
1163 EXPORT_SYMBOL(audio_unregister_codec);
1164 EXPORT_SYMBOL(audio_get_fops);
1166 MODULE_AUTHOR("Texas Instruments");
1167 MODULE_DESCRIPTION("Common audio handling for OMAP processors");
1168 MODULE_LICENSE("GPL");