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>
49 #include <asm/uaccess.h>
51 #include <asm/hardware.h>
52 #include <asm/semaphore.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 device *dev);
110 static int audio_remove(struct device *dev);
112 static void audio_shutdown(struct device *dev);
114 static int audio_suspend(struct device *dev, pm_message_t mesg, u32 level);
116 static int audio_resume(struct device *dev, u32 level);
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 device_driver omap_audio_driver = {
145 .name = OMAP_AUDIO_NAME,
146 .bus = &platform_bus_type,
147 .probe = audio_probe,
148 .remove = audio_remove,
149 .suspend = audio_suspend,
150 .resume = audio_resume,
151 .shutdown = audio_shutdown,
154 /* Device Information */
155 static struct platform_device omap_audio_device = {
156 .name = OMAP_AUDIO_NAME,
158 .driver_data = &audio_state,
159 .release = audio_free,
164 /***************************** GLOBAL FUNCTIONs **********************************/
166 /* Power Management Functions for Linux Device Model */
167 /* DEBUG PUPOSES ONLY! */
173 /*********************************************************************************
175 * audio_ldm_suspend(): Suspend operation
177 *********************************************************************************/
178 static int audio_ldm_suspend(void *data)
180 audio_state_t *state = data;
185 * Reject the suspend request if we are already actively transmitting data
186 * Rationale: We dont want to be suspended while in the middle of a call!
188 if (AUDIO_ACTIVE(state) && state->hw_init) {
189 printk(KERN_ERR "Audio device Active, Cannot Suspend");
193 * This Piece of code is commented out in hope
194 * That one day we would need to suspend the device while
195 * audio operations are in progress and resume the operations
196 * once the resume is done.
197 * This is just a sample implementation of how it could be done.
198 * Currently NOT SUPPORTED
200 audio_stream_t *is = state->input_stream;
201 audio_stream_t *os = state->output_stream;
203 if (is && is->buffers) {
204 printk("IS Suspend\n");
205 stopstate = is->stopped;
209 is->stopped = stopstate;
211 if (os && os->buffers) {
212 printk("OS Suspend\n");
213 stopstate = os->stopped;
217 os->stopped = stopstate;
226 /*********************************************************************************
228 * audio_ldm_resume(): Resume Operations
230 *********************************************************************************/
231 static int audio_ldm_resume(void *data)
233 audio_state_t *state = data;
236 if (AUDIO_ACTIVE(state) && state->hw_init) {
237 /* Should never occur - since we never suspend with active state */
242 * This Piece of code is commented out in hope
243 * That one day we would need to suspend the device while
244 * audio operations are in progress and resume the operations
245 * once the resume is done.
246 * This is just a sample implementation of how it could be done.
247 * Currently NOT SUPPORTED
249 audio_stream_t *is = state->input_stream;
250 audio_stream_t *os = state->output_stream;
251 if (os && os->buffers) {
252 printk("OS Resume\n");
254 audio_process_dma(os);
256 if (is && is->buffers) {
257 printk("IS Resume\n");
259 audio_process_dma(is);
266 #endif /* End of #ifdef CONFIG_PM */
268 /*********************************************************************************
270 * audio_free(): The Audio driver release function
271 * This is a dummy function required by the platform driver
273 *********************************************************************************/
274 static void audio_free(struct device *dev)
276 /* Nothing to Release! */
279 /*********************************************************************************
281 * audio_probe(): The Audio driver probe function
282 * WARNING!!!! : It is expected that the codec would have registered with us by now
284 *********************************************************************************/
285 static int audio_probe(struct device *dev)
289 if (!audio_state.hw_probe) {
290 printk(KERN_ERR "Probe Function Not Registered\n");
293 ret = audio_state.hw_probe();
298 /*********************************************************************************
300 * audio_remove() Function to handle removal operations
302 *********************************************************************************/
303 static int audio_remove(struct device *dev)
306 if (audio_state.hw_remove) {
307 audio_state.hw_remove();
313 /*********************************************************************************
315 * audio_shutdown(): Function to handle shutdown operations
317 *********************************************************************************/
318 static void audio_shutdown(struct device *dev)
321 if (audio_state.hw_cleanup) {
322 audio_state.hw_cleanup();
328 /*********************************************************************************
330 * audio_suspend(): Function to handle suspend operations
332 *********************************************************************************/
333 static int audio_suspend(struct device *dev, pm_message_t mesg, u32 level)
338 void *data = dev->driver_data;
340 if (level != SUSPEND_POWER_DOWN) {
343 if (audio_state.hw_suspend) {
344 ret = audio_ldm_suspend(data);
346 ret = audio_state.hw_suspend();
349 printk(KERN_INFO "Audio Suspend Failed \n");
351 printk(KERN_INFO "Audio Suspend Success \n");
353 #endif /* CONFIG_PM */
359 /*********************************************************************************
361 * audio_resume(): Function to handle resume operations
363 *********************************************************************************/
364 static int audio_resume(struct device *dev, u32 level)
369 void *data = dev->driver_data;
371 if (level != RESUME_POWER_ON) {
374 if (audio_state.hw_resume) {
375 ret = audio_ldm_resume(data);
377 ret = audio_state.hw_resume();
380 printk(KERN_INFO " Audio Resume Failed \n");
382 printk(KERN_INFO " Audio Resume Success \n");
384 #endif /* CONFIG_PM */
390 /*********************************************************************************
392 * audio_get_fops(): Return the fops required to get the function pointers of
395 *********************************************************************************/
396 struct file_operations *audio_get_fops(void)
400 return &omap_audio_fops;
403 /*********************************************************************************
405 * audio_register_codec(): Register a Codec fn points using this function
406 * WARNING!!!!! : Codecs should ensure that they do so! no sanity checks
407 * during runtime is done due to obvious performance
410 *********************************************************************************/
411 int audio_register_codec(audio_state_t * codec_state)
416 /* We dont handle multiple codecs now */
417 if (audio_state.hw_init) {
418 printk(KERN_ERR " Codec Already registered\n");
422 /* Grab the dma Callback */
423 audio_dma_callback = audio_get_dma_callback();
424 if (!audio_dma_callback) {
425 printk(KERN_ERR "Unable to get call back function\n");
431 printk(KERN_ERR "NULL ARGUMENT!\n");
435 if (!codec_state->hw_probe || !codec_state->hw_init
436 || !codec_state->hw_shutdown || !codec_state->client_ioctl) {
438 "Required Fn Entry point Missing probe=%p init=%p,down=%p,ioctl=%p!\n",
439 codec_state->hw_probe, codec_state->hw_init,
440 codec_state->hw_shutdown, codec_state->client_ioctl);
444 memcpy(&audio_state, codec_state, sizeof(audio_state_t));
446 ret = platform_device_register(&omap_audio_device);
448 printk(KERN_ERR "Platform dev_register failed =%d\n", ret);
453 ret = driver_register(&omap_audio_driver);
455 printk(KERN_ERR "Device Register failed =%d\n", ret);
457 platform_device_unregister(&omap_audio_device);
467 /*********************************************************************************
469 * audio_unregister_codec(): Un-Register a Codec using this function
471 *********************************************************************************/
472 int audio_unregister_codec(audio_state_t * codec_state)
476 /* We dont handle multiple codecs now */
477 if (!audio_state.hw_init) {
478 printk(KERN_ERR " No Codec registered\n");
482 if (audio_state.hw_init != codec_state->hw_init) {
484 " Attempt to unregister codec which was not registered with us\n");
488 driver_unregister(&omap_audio_driver);
489 platform_device_unregister(&omap_audio_device);
491 memset(&audio_state, 0, sizeof(audio_state_t));
497 /***************************** MODULES SPECIFIC FUNCTION *************************/
499 /*********************************************************************************
501 * audio_write(): Exposed to write() call
503 *********************************************************************************/
505 audio_write(struct file *file, const char __user *buffer,
506 size_t count, loff_t * ppos)
508 const char __user *buffer0 = buffer;
509 audio_state_t *state = file->private_data;
510 audio_stream_t *s = state->output_stream;
511 int chunksize, ret = 0;
513 DPRINTK("audio_write: count=%d\n", count);
514 if (*ppos != file->f_pos) {
515 printk("FPOS not ppos ppos=0x%x fpos =0x%x\n", (u32) * ppos,
520 printk("s already mapped\n");
523 if (!s->buffers && audio_setup_buf(s)) {
524 printk("NO MEMORY\n");
529 audio_buf_t *b = &s->buffers[s->usr_head];
531 /* Wait for a buffer to become free */
532 if (file->f_flags & O_NONBLOCK) {
534 if (down_trylock(&s->sem))
538 if (down_interruptible(&s->sem))
542 /* Feed the current buffer */
543 chunksize = s->fragsize - b->offset;
544 if (chunksize > count)
546 DPRINTK("write %d to %d\n", chunksize, s->usr_head);
547 if (copy_from_user(b->data + b->offset, buffer, chunksize)) {
548 printk(KERN_ERR "Audio: CopyFrom User failed \n");
555 b->offset += chunksize;
557 if (b->offset < s->fragsize) {
562 /* Update pointers and send current fragment to DMA */
564 if (++s->usr_head >= s->nbfrags)
566 /* Add the num of frags pending */
570 audio_process_dma(s);
574 if ((buffer - buffer0))
575 ret = buffer - buffer0;
576 DPRINTK("audio_write: return=%d\n", ret);
580 /*********************************************************************************
582 * audio_read(): Exposed as read() function
584 *********************************************************************************/
586 audio_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
588 char __user *buffer0 = buffer;
589 audio_state_t *state = file->private_data;
590 audio_stream_t *s = state->input_stream;
591 int chunksize, ret = 0;
594 DPRINTK("audio_read: count=%d\n", count);
596 if (*ppos != file->f_pos) {
597 printk("AudioRead - FPOS not ppos ppos=0x%x fpos =0x%x\n",
598 (u32) * ppos, (u32) file->f_pos);
602 printk("AudioRead - s already mapped\n");
607 if (!s->buffers && audio_setup_buf(s)) {
608 printk("AudioRead - No Memory\n");
611 audio_prime_rx(state);
615 audio_buf_t *b = &s->buffers[s->usr_head];
617 /* Wait for a buffer to become full */
618 if (file->f_flags & O_NONBLOCK) {
620 if (down_trylock(&s->sem))
624 if (down_interruptible(&s->sem))
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 && atomic_read(&is->sem.count) > 0))
752 mask |= POLLIN | POLLRDNORM;
754 if (file->f_mode & FMODE_WRITE)
755 if ((os->mapped && os->bytecount > 0) ||
756 (!os->mapped && atomic_read(&os->sem.count) > 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 sema_init(&os->sem, 0);
904 local_irq_restore(flags);
905 audio_process_dma(os);
914 case SNDCTL_DSP_GETOPTR:
915 case SNDCTL_DSP_GETIPTR:
917 count_info inf = { 0, };
919 (cmd == SNDCTL_DSP_GETOPTR) ? os : is;
920 int bytecount, offset;
923 if ((s == is && !(file->f_mode & FMODE_READ)) ||
924 (s == os && !(file->f_mode & FMODE_WRITE))) {
929 local_irq_save(flags);
930 offset = audio_get_dma_pos(s);
931 inf.ptr = s->dma_tail * s->fragsize + offset;
932 bytecount = s->bytecount + offset;
933 s->bytecount = -offset;
934 inf.blocks = s->fragcount;
936 local_irq_restore(flags);
939 inf.bytes = bytecount;
942 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
945 case SNDCTL_DSP_GETOSPACE:
946 case SNDCTL_DSP_GETISPACE:
948 audio_buf_info inf = { 0, };
950 (cmd == SNDCTL_DSP_GETOSPACE) ? os : is;
952 if ((s == is && !(file->f_mode & FMODE_READ)) ||
953 (s == os && !(file->f_mode & FMODE_WRITE))) {
957 if (!s->buffers && audio_setup_buf(s)) {
961 inf.bytes = atomic_read(&s->sem.count) * s->fragsize;
963 inf.fragments = inf.bytes / s->fragsize;
964 inf.fragsize = s->fragsize;
965 inf.fragstotal = s->nbfrags;
967 return copy_to_user((void __user *)arg, &inf, sizeof(inf));
970 case SNDCTL_DSP_NONBLOCK:
971 file->f_flags |= O_NONBLOCK;
975 case SNDCTL_DSP_RESET:
976 if (file->f_mode & FMODE_READ) {
978 if (state->need_tx_for_rx) {
980 local_irq_save(flags);
982 local_irq_restore(flags);
985 if (file->f_mode & FMODE_WRITE) {
993 * Let the client of this module handle the
997 return state->client_ioctl(inode, file, cmd, arg);
1004 /*********************************************************************************
1006 * audio_open(): Exposed as open() function
1008 *********************************************************************************/
1009 static int audio_open(struct inode *inode, struct file *file)
1011 audio_state_t *state = (&audio_state);
1012 audio_stream_t *os = state->output_stream;
1013 audio_stream_t *is = state->input_stream;
1014 int err, need_tx_dma;
1015 static unsigned char tsc2101_init_flag = 0;
1019 /* Lock the module */
1020 if (!try_module_get(THIS_MODULE)) {
1021 printk(KERN_CRIT "Failed to get module\n");
1024 /* Lock the codec module */
1025 if (!try_module_get(state->owner)) {
1026 printk(KERN_CRIT "Failed to get codec module\n");
1027 module_put(THIS_MODULE);
1033 /* access control */
1035 if ((file->f_mode & FMODE_WRITE) && !os)
1037 if ((file->f_mode & FMODE_READ) && !is)
1040 if ((file->f_mode & FMODE_WRITE) && state->wr_ref)
1042 if ((file->f_mode & FMODE_READ) && state->rd_ref)
1045 if ((file->f_mode & FMODE_READ) && state->need_tx_for_rx && !os)
1048 /* request DMA channels */
1049 need_tx_dma = ((file->f_mode & FMODE_WRITE) ||
1050 ((file->f_mode & FMODE_READ) && state->need_tx_for_rx));
1051 if (state->wr_ref || (state->rd_ref && state->need_tx_for_rx))
1054 DMA_REQUEST(err, os, audio_dma_callback);
1058 if (file->f_mode & FMODE_READ) {
1059 DMA_REQUEST(err, is, audio_dma_callback);
1067 /* now complete initialisation */
1068 if (!AUDIO_ACTIVE(state)) {
1069 if (state->hw_init && !tsc2101_init_flag) {
1070 state->hw_init(state->data);
1071 tsc2101_init_flag = 0;
1077 if ((file->f_mode & FMODE_WRITE)) {
1080 os->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1081 os->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1083 init_waitqueue_head(&os->wq);
1086 if (file->f_mode & FMODE_READ) {
1089 is->fragsize = AUDIO_FRAGSIZE_DEFAULT;
1090 is->nbfrags = AUDIO_NBFRAGS_DEFAULT;
1092 init_waitqueue_head(&is->wq);
1095 file->private_data = state;
1101 module_put(state->owner);
1102 module_put(THIS_MODULE);
1108 /*********************************************************************************
1110 * audio_release(): Exposed as release function()
1112 *********************************************************************************/
1113 static int audio_release(struct inode *inode, struct file *file)
1115 audio_state_t *state = file->private_data;
1116 audio_stream_t *os = state->output_stream;
1117 audio_stream_t *is = state->input_stream;
1123 if (file->f_mode & FMODE_READ) {
1124 audio_discard_buf(is);
1126 is->dma_spinref = 0;
1127 if (state->need_tx_for_rx) {
1129 if (!state->wr_ref) {
1131 os->dma_spinref = 0;
1137 if (file->f_mode & FMODE_WRITE) {
1139 audio_discard_buf(os);
1140 if (!state->need_tx_for_rx || !state->rd_ref) {
1142 os->dma_spinref = 0;
1147 if (!AUDIO_ACTIVE(state)) {
1148 if (state->hw_shutdown)
1149 state->hw_shutdown(state->data);
1154 module_put(state->owner);
1155 module_put(THIS_MODULE);
1161 EXPORT_SYMBOL(audio_register_codec);
1162 EXPORT_SYMBOL(audio_unregister_codec);
1163 EXPORT_SYMBOL(audio_get_fops);
1165 MODULE_AUTHOR("Texas Instruments");
1166 MODULE_DESCRIPTION("Common audio handling for OMAP processors");
1167 MODULE_LICENSE("GPL");