ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / core / init.c
1 /*
2  *  Initialization routines
3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/sched.h>
25 #include <linux/file.h>
26 #include <linux/slab.h>
27 #include <linux/time.h>
28 #include <linux/ctype.h>
29 #include <sound/core.h>
30 #include <sound/control.h>
31 #include <sound/info.h>
32
33 struct snd_shutdown_f_ops {
34         struct file_operations f_ops;
35         struct snd_shutdown_f_ops *next;
36 };
37
38 int snd_cards_count = 0;
39 unsigned int snd_cards_lock = 0;        /* locked for registering/using */
40 snd_card_t *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL};
41 rwlock_t snd_card_rwlock = RW_LOCK_UNLOCKED;
42
43 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
44 int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int free_flag);
45 #endif
46
47 static void snd_card_id_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
48 {
49         snd_iprintf(buffer, "%s\n", entry->card->id);
50 }
51
52 static void snd_card_free_thread(void * __card);
53
54 /**
55  *  snd_card_new - create and initialize a soundcard structure
56  *  @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
57  *  @xid: card identification (ASCII string)
58  *  @module: top level module for locking
59  *  @extra_size: allocate this extra size after the main soundcard structure
60  *
61  *  Creates and initializes a soundcard structure.
62  *
63  *  Returns kmallocated snd_card_t structure. Creates the ALSA control interface
64  *  (which is blocked until snd_card_register function is called).
65  */
66 snd_card_t *snd_card_new(int idx, const char *xid,
67                          struct module *module, int extra_size)
68 {
69         snd_card_t *card;
70         int err;
71
72         if (extra_size < 0)
73                 extra_size = 0;
74         card = (snd_card_t *) snd_kcalloc(sizeof(snd_card_t) + extra_size, GFP_KERNEL);
75         if (card == NULL)
76                 return NULL;
77         if (xid) {
78                 if (!snd_info_check_reserved_words(xid))
79                         goto __error;
80                 strlcpy(card->id, xid, sizeof(card->id));
81         }
82         err = 0;
83         write_lock(&snd_card_rwlock);
84         if (idx < 0) {
85                 int idx2;
86                 for (idx2 = 0; idx2 < snd_ecards_limit; idx2++)
87                         if (!(snd_cards_lock & (1 << idx2))) {
88                                 idx = idx2;
89                                 break;
90                         }
91                 if (idx < 0 && snd_ecards_limit < SNDRV_CARDS)
92                         /* for dynamically additional devices like hotplug:
93                          * increment the limit if still free slot exists.
94                          */
95                         idx = snd_ecards_limit++;
96         } else if (idx < snd_ecards_limit) {
97                 if (snd_cards_lock & (1 << idx))
98                         err = -ENODEV;  /* invalid */
99         } else if (idx < SNDRV_CARDS)
100                 snd_ecards_limit = idx + 1; /* increase the limit */
101         else
102                 err = -ENODEV;
103         if (idx < 0 || err < 0) {
104                 write_unlock(&snd_card_rwlock);
105                 snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1);
106                 goto __error;
107         }
108         snd_cards_lock |= 1 << idx;             /* lock it */
109         write_unlock(&snd_card_rwlock);
110         card->number = idx;
111         card->module = module;
112         INIT_LIST_HEAD(&card->devices);
113         init_rwsem(&card->controls_rwsem);
114         rwlock_init(&card->ctl_files_rwlock);
115         INIT_LIST_HEAD(&card->controls);
116         INIT_LIST_HEAD(&card->ctl_files);
117         spin_lock_init(&card->files_lock);
118         init_waitqueue_head(&card->shutdown_sleep);
119         INIT_WORK(&card->free_workq, snd_card_free_thread, card);
120 #ifdef CONFIG_PM
121         init_MUTEX(&card->power_lock);
122         init_waitqueue_head(&card->power_sleep);
123 #endif
124         /* the control interface cannot be accessed from the user space until */
125         /* snd_cards_bitmask and snd_cards are set with snd_card_register */
126         if ((err = snd_ctl_register(card)) < 0) {
127                 snd_printd("unable to register control minors\n");
128                 goto __error;
129         }
130         if ((err = snd_info_card_create(card)) < 0) {
131                 snd_printd("unable to create card info\n");
132                 goto __error_ctl;
133         }
134         if (extra_size > 0)
135                 card->private_data = (char *)card + sizeof(snd_card_t);
136         return card;
137
138       __error_ctl:
139         snd_ctl_unregister(card);
140       __error:
141         kfree(card);
142         return NULL;
143 }
144
145 static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait)
146 {
147         return POLLERR | POLLNVAL;
148 }
149
150 /**
151  *  snd_card_disconnect - disconnect all APIs from the file-operations (user space)
152  *  @card: soundcard structure
153  *
154  *  Disconnects all APIs from the file-operations (user space).
155  *
156  *  Returns zero, otherwise a negative error code.
157  *
158  *  Note: The current implementation replaces all active file->f_op with special
159  *        dummy file operations (they do nothing except release).
160  */
161 int snd_card_disconnect(snd_card_t * card)
162 {
163         struct snd_monitor_file *mfile;
164         struct file *file;
165         struct snd_shutdown_f_ops *s_f_ops;
166         struct file_operations *f_ops, *old_f_ops;
167         int err;
168
169         spin_lock(&card->files_lock);
170         if (card->shutdown) {
171                 spin_unlock(&card->files_lock);
172                 return 0;
173         }
174         card->shutdown = 1;
175         spin_unlock(&card->files_lock);
176
177         /* phase 1: disable fops (user space) operations for ALSA API */
178         write_lock(&snd_card_rwlock);
179         snd_cards[card->number] = NULL;
180         write_unlock(&snd_card_rwlock);
181         
182         /* phase 2: replace file->f_op with special dummy operations */
183         
184         spin_lock(&card->files_lock);
185         mfile = card->files;
186         while (mfile) {
187                 file = mfile->file;
188
189                 /* it's critical part, use endless loop */
190                 /* we have no room to fail */
191                 s_f_ops = kmalloc(sizeof(struct snd_shutdown_f_ops), GFP_ATOMIC);
192                 if (s_f_ops == NULL)
193                         panic("Atomic allocation failed for snd_shutdown_f_ops!");
194
195                 f_ops = &s_f_ops->f_ops;
196
197                 memset(f_ops, 0, sizeof(*f_ops));
198                 f_ops->owner = file->f_op->owner;
199                 f_ops->release = file->f_op->release;
200                 f_ops->poll = snd_disconnect_poll;
201
202                 s_f_ops->next = card->s_f_ops;
203                 card->s_f_ops = s_f_ops;
204                 
205                 f_ops = fops_get(f_ops);
206
207                 old_f_ops = file->f_op;
208                 file->f_op = f_ops;     /* must be atomic */
209                 fops_put(old_f_ops);
210                 
211                 mfile = mfile->next;
212         }
213         spin_unlock(&card->files_lock); 
214
215         /* phase 3: notify all connected devices about disconnection */
216         /* at this point, they cannot respond to any calls except release() */
217
218         snd_ctl_disconnect(card);
219
220 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
221         if (snd_mixer_oss_notify_callback)
222                 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT);
223 #endif
224
225         /* notify all devices that we are disconnected */
226         err = snd_device_disconnect_all(card);
227         if (err < 0)
228                 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number);
229
230         return 0;       
231 }
232
233 /**
234  *  snd_card_free - frees given soundcard structure
235  *  @card: soundcard structure
236  *
237  *  This function releases the soundcard structure and the all assigned
238  *  devices automatically.  That is, you don't have to release the devices
239  *  by yourself.
240  *
241  *  Returns zero. Frees all associated devices and frees the control
242  *  interface associated to given soundcard.
243  */
244 int snd_card_free(snd_card_t * card)
245 {
246         struct snd_shutdown_f_ops *s_f_ops;
247
248         if (card == NULL)
249                 return -EINVAL;
250         write_lock(&snd_card_rwlock);
251         snd_cards[card->number] = NULL;
252         snd_cards_count--;
253         write_unlock(&snd_card_rwlock);
254
255 #ifdef CONFIG_PM
256         wake_up(&card->power_sleep);
257 #endif
258
259         /* wait, until all devices are ready for the free operation */
260         wait_event(card->shutdown_sleep, card->files == NULL);
261
262 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
263         if (snd_mixer_oss_notify_callback)
264                 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE);
265 #endif
266         if (snd_device_free_all(card, SNDRV_DEV_CMD_PRE) < 0) {
267                 snd_printk(KERN_ERR "unable to free all devices (pre)\n");
268                 /* Fatal, but this situation should never occur */
269         }
270         if (snd_device_free_all(card, SNDRV_DEV_CMD_NORMAL) < 0) {
271                 snd_printk(KERN_ERR "unable to free all devices (normal)\n");
272                 /* Fatal, but this situation should never occur */
273         }
274         if (snd_ctl_unregister(card) < 0) {
275                 snd_printk(KERN_ERR "unable to unregister control minors\n");
276                 /* Not fatal error */
277         }
278         if (snd_device_free_all(card, SNDRV_DEV_CMD_POST) < 0) {
279                 snd_printk(KERN_ERR "unable to free all devices (post)\n");
280                 /* Fatal, but this situation should never occur */
281         }
282         if (card->private_free)
283                 card->private_free(card);
284         if (card->proc_id)
285                 snd_info_unregister(card->proc_id);
286         if (snd_info_card_free(card) < 0) {
287                 snd_printk(KERN_WARNING "unable to free card info\n");
288                 /* Not fatal error */
289         }
290         while (card->s_f_ops) {
291                 s_f_ops = card->s_f_ops;
292                 card->s_f_ops = s_f_ops->next;
293                 kfree(s_f_ops);
294         }
295         write_lock(&snd_card_rwlock);
296         snd_cards_lock &= ~(1 << card->number);
297         write_unlock(&snd_card_rwlock);
298         kfree(card);
299         return 0;
300 }
301
302 static void snd_card_free_thread(void * __card)
303 {
304         snd_card_t *card = __card;
305         struct module * module = card->module;
306
307         if (!try_module_get(module)) {
308                 snd_printk(KERN_ERR "unable to lock toplevel module for card %i in free thread\n", card->number);
309                 module = NULL;
310         }
311
312         snd_card_free(card);
313
314         module_put(module);
315 }
316
317 /**
318  *  snd_card_free_in_thread - call snd_card_free() in thread
319  *  @card: soundcard structure
320  *
321  *  This function schedules the call of snd_card_free() function in a
322  *  work queue.  When all devices are released (non-busy), the work
323  *  is woken up and calls snd_card_free().
324  *
325  *  When a card can be disconnected at any time by hotplug service,
326  *  this function should be used in disconnect (or detach) callback
327  *  instead of calling snd_card_free() directly.
328  *  
329  *  Returns - zero otherwise a negative error code if the start of thread failed.
330  */
331 int snd_card_free_in_thread(snd_card_t * card)
332 {
333         if (card->files == NULL) {
334                 snd_card_free(card);
335                 return 0;
336         }
337
338         if (schedule_work(&card->free_workq))
339                 return 0;
340
341         snd_printk(KERN_ERR "schedule_work() failed in snd_card_free_in_thread for card %i\n", card->number);
342         /* try to free the structure immediately */
343         snd_card_free(card);
344         return -EFAULT;
345 }
346
347 static void choose_default_id(snd_card_t * card)
348 {
349         int i, len, idx_flag = 0, loops = 8;
350         char *id, *spos;
351         
352         id = spos = card->shortname;    
353         while (*id != '\0') {
354                 if (*id == ' ')
355                         spos = id + 1;
356                 id++;
357         }
358         id = card->id;
359         while (*spos != '\0' && !isalnum(*spos))
360                 spos++;
361         if (isdigit(*spos))
362                 *id++ = isalpha(card->shortname[0]) ? card->shortname[0] : 'D';
363         while (*spos != '\0' && (size_t)(id - card->id) < sizeof(card->id) - 1) {
364                 if (isalnum(*spos))
365                         *id++ = *spos;
366                 spos++;
367         }
368         *id = '\0';
369
370         id = card->id;
371         
372         if (*id == '\0')
373                 strcpy(id, "default");
374
375         while (1) {
376                 if (loops-- == 0) {
377                         snd_printk(KERN_ERR "unable to choose default card id (%s)", id);
378                         strcpy(card->id, card->proc_root->name);
379                         return;
380                 }
381                 if (!snd_info_check_reserved_words(id))
382                         goto __change;
383                 for (i = 0; i < snd_ecards_limit; i++) {
384                         if (snd_cards[i] && !strcmp(snd_cards[i]->id, id))
385                                 goto __change;
386                 }
387                 break;
388
389               __change:
390                 len = strlen(id);
391                 if (idx_flag)
392                         id[len-1]++;
393                 else if ((size_t)len <= sizeof(card->id) - 3) {
394                         strcat(id, "_1");
395                         idx_flag++;
396                 } else {
397                         spos = id + len - 2;
398                         if ((size_t)len <= sizeof(card->id) - 2)
399                                 spos++;
400                         *spos++ = '_';
401                         *spos++ = '1';
402                         *spos++ = '\0';
403                         idx_flag++;
404                 }
405         }
406 }
407
408 /**
409  *  snd_card_register - register the soundcard
410  *  @card: soundcard structure
411  *
412  *  This function registers all the devices assigned to the soundcard.
413  *  Until calling this, the ALSA control interface is blocked from the
414  *  external accesses.  Thus, you should call this function at the end
415  *  of the initialization of the card.
416  *
417  *  Returns zero otherwise a negative error code if the registrain failed.
418  */
419 int snd_card_register(snd_card_t * card)
420 {
421         int err;
422         snd_info_entry_t *entry;
423
424         snd_runtime_check(card != NULL, return -EINVAL);
425         if ((err = snd_device_register_all(card)) < 0)
426                 return err;
427         write_lock(&snd_card_rwlock);
428         if (snd_cards[card->number]) {
429                 /* already registered */
430                 write_unlock(&snd_card_rwlock);
431                 return 0;
432         }
433         if (card->id[0] == '\0')
434                 choose_default_id(card);
435         snd_cards[card->number] = card;
436         snd_cards_count++;
437         write_unlock(&snd_card_rwlock);
438         if ((err = snd_info_card_register(card)) < 0) {
439                 snd_printd("unable to create card info\n");
440                 goto __skip_info;
441         }
442         if ((entry = snd_info_create_card_entry(card, "id", card->proc_root)) == NULL) {
443                 snd_printd("unable to create card entry\n");
444                 goto __skip_info;
445         }
446         entry->c.text.read_size = PAGE_SIZE;
447         entry->c.text.read = snd_card_id_read;
448         if (snd_info_register(entry) < 0) {
449                 snd_info_free_entry(entry);
450                 entry = NULL;
451         }
452         card->proc_id = entry;
453       __skip_info:
454 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
455         if (snd_mixer_oss_notify_callback)
456                 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);
457 #endif
458         return 0;
459 }
460
461 static snd_info_entry_t *snd_card_info_entry = NULL;
462
463 static void snd_card_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
464 {
465         int idx, count;
466         snd_card_t *card;
467
468         for (idx = count = 0; idx < SNDRV_CARDS; idx++) {
469                 read_lock(&snd_card_rwlock);
470                 if ((card = snd_cards[idx]) != NULL) {
471                         count++;
472                         snd_iprintf(buffer, "%i [%-15s]: %s - %s\n",
473                                         idx,
474                                         card->id,
475                                         card->driver,
476                                         card->shortname);
477                         snd_iprintf(buffer, "                     %s\n",
478                                         card->longname);
479                 }
480                 read_unlock(&snd_card_rwlock);
481         }
482         if (!count)
483                 snd_iprintf(buffer, "--- no soundcards ---\n");
484 }
485
486 #if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS)
487
488 void snd_card_info_read_oss(snd_info_buffer_t * buffer)
489 {
490         int idx, count;
491         snd_card_t *card;
492
493         for (idx = count = 0; idx < SNDRV_CARDS; idx++) {
494                 read_lock(&snd_card_rwlock);
495                 if ((card = snd_cards[idx]) != NULL) {
496                         count++;
497                         snd_iprintf(buffer, "%s\n", card->longname);
498                 }
499                 read_unlock(&snd_card_rwlock);
500         }
501         if (!count) {
502                 snd_iprintf(buffer, "--- no soundcards ---\n");
503         }
504 }
505
506 #endif
507
508 #ifdef MODULE
509 static snd_info_entry_t *snd_card_module_info_entry;
510 static void snd_card_module_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
511 {
512         int idx;
513         snd_card_t *card;
514
515         for (idx = 0; idx < SNDRV_CARDS; idx++) {
516                 read_lock(&snd_card_rwlock);
517                 if ((card = snd_cards[idx]) != NULL)
518                         snd_iprintf(buffer, "%i %s\n", idx, card->module->name);
519                 read_unlock(&snd_card_rwlock);
520         }
521 }
522 #endif
523
524 int __init snd_card_info_init(void)
525 {
526         snd_info_entry_t *entry;
527
528         entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL);
529         snd_runtime_check(entry != NULL, return -ENOMEM);
530         entry->c.text.read_size = PAGE_SIZE;
531         entry->c.text.read = snd_card_info_read;
532         if (snd_info_register(entry) < 0) {
533                 snd_info_free_entry(entry);
534                 return -ENOMEM;
535         }
536         snd_card_info_entry = entry;
537
538 #ifdef MODULE
539         entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL);
540         if (entry) {
541                 entry->c.text.read_size = PAGE_SIZE;
542                 entry->c.text.read = snd_card_module_info_read;
543                 if (snd_info_register(entry) < 0)
544                         snd_info_free_entry(entry);
545                 else
546                         snd_card_module_info_entry = entry;
547         }
548 #endif
549
550         return 0;
551 }
552
553 int __exit snd_card_info_done(void)
554 {
555         if (snd_card_info_entry)
556                 snd_info_unregister(snd_card_info_entry);
557 #ifdef MODULE
558         if (snd_card_module_info_entry)
559                 snd_info_unregister(snd_card_module_info_entry);
560 #endif
561         return 0;
562 }
563
564 /**
565  *  snd_component_add - add a component string
566  *  @card: soundcard structure
567  *  @component: the component id string
568  *
569  *  This function adds the component id string to the supported list.
570  *  The component can be referred from the alsa-lib.
571  *
572  *  Returns zero otherwise a negative error code.
573  */
574   
575 int snd_component_add(snd_card_t *card, const char *component)
576 {
577         char *ptr;
578         int len = strlen(component);
579
580         ptr = strstr(card->components, component);
581         if (ptr != NULL) {
582                 if (ptr[len] == '\0' || ptr[len] == ' ')        /* already there */
583                         return 1;
584         }
585         if (strlen(card->components) + 1 + len + 1 > sizeof(card->components)) {
586                 snd_BUG();
587                 return -ENOMEM;
588         }
589         if (card->components[0] != '\0')
590                 strcat(card->components, " ");
591         strcat(card->components, component);
592         return 0;
593 }
594
595 /**
596  *  snd_card_file_add - add the file to the file list of the card
597  *  @card: soundcard structure
598  *  @file: file pointer
599  *
600  *  This function adds the file to the file linked-list of the card.
601  *  This linked-list is used to keep tracking the connection state,
602  *  and to avoid the release of busy resources by hotplug.
603  *
604  *  Returns zero or a negative error code.
605  */
606 int snd_card_file_add(snd_card_t *card, struct file *file)
607 {
608         struct snd_monitor_file *mfile;
609
610         mfile = kmalloc(sizeof(*mfile), GFP_KERNEL);
611         if (mfile == NULL)
612                 return -ENOMEM;
613         mfile->file = file;
614         mfile->next = NULL;
615         spin_lock(&card->files_lock);
616         if (card->shutdown) {
617                 spin_unlock(&card->files_lock);
618                 kfree(mfile);
619                 return -ENODEV;
620         }
621         mfile->next = card->files;
622         card->files = mfile;
623         spin_unlock(&card->files_lock);
624         return 0;
625 }
626
627 /**
628  *  snd_card_file_remove - remove the file from the file list
629  *  @card: soundcard structure
630  *  @file: file pointer
631  *
632  *  This function removes the file formerly added to the card via
633  *  snd_card_file_add() function.
634  *  If all files are removed and the release of the card is
635  *  scheduled, it will wake up the the thread to call snd_card_free()
636  *  (see snd_card_free_in_thread() function).
637  *
638  *  Returns zero or a negative error code.
639  */
640 int snd_card_file_remove(snd_card_t *card, struct file *file)
641 {
642         struct snd_monitor_file *mfile, *pfile = NULL;
643
644         spin_lock(&card->files_lock);
645         mfile = card->files;
646         while (mfile) {
647                 if (mfile->file == file) {
648                         if (pfile)
649                                 pfile->next = mfile->next;
650                         else
651                                 card->files = mfile->next;
652                         break;
653                 }
654                 pfile = mfile;
655                 mfile = mfile->next;
656         }
657         spin_unlock(&card->files_lock);
658         if (card->files == NULL)
659                 wake_up(&card->shutdown_sleep);
660         if (mfile) {
661                 kfree(mfile);
662         } else {
663                 snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file);
664                 return -ENOENT;
665         }
666         return 0;
667 }
668
669 #ifdef CONFIG_PM
670 /**
671  *  snd_power_wait - wait until the power-state is changed.
672  *  @card: soundcard structure
673  *  @power_state: expected power state
674  *  @file: file structure for the O_NONBLOCK check (optional)
675  *
676  *  Waits until the power-state is changed.
677  *
678  *  Note: the power lock must be active before call.
679  */
680 int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file)
681 {
682         wait_queue_t wait;
683         int result = 0;
684
685         /* fastpath */
686         if (snd_power_get_state(card) == power_state)
687                 return 0;
688         init_waitqueue_entry(&wait, current);
689         add_wait_queue(&card->power_sleep, &wait);
690         while (1) {
691                 if (card->shutdown) {
692                         result = -ENODEV;
693                         break;
694                 }
695                 if (snd_power_get_state(card) == power_state)
696                         break;
697 #if 0 /* block all devices */
698                 if (file && (file->f_flags & O_NONBLOCK)) {
699                         result = -EAGAIN;
700                         break;
701                 }
702 #endif
703                 set_current_state(TASK_UNINTERRUPTIBLE);
704                 snd_power_unlock(card);
705                 schedule_timeout(30 * HZ);
706                 snd_power_lock(card);
707         }
708         remove_wait_queue(&card->power_sleep, &wait);
709         return result;
710 }
711 #endif /* CONFIG_PM */