init.c (97f2aab6698f3ab2552c41c1024a65ffd0763a6d) | init.c (512bbd6a85230f16389f0dd51925472e72fc8a91) |
---|---|
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 --- 26 unchanged lines hidden (view full) --- 35#include <sound/info.h> 36 37struct snd_shutdown_f_ops { 38 struct file_operations f_ops; 39 struct snd_shutdown_f_ops *next; 40}; 41 42unsigned int snd_cards_lock = 0; /* locked for registering/using */ | 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 --- 26 unchanged lines hidden (view full) --- 35#include <sound/info.h> 36 37struct snd_shutdown_f_ops { 38 struct file_operations f_ops; 39 struct snd_shutdown_f_ops *next; 40}; 41 42unsigned int snd_cards_lock = 0; /* locked for registering/using */ |
43snd_card_t *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL}; | 43struct snd_card *snd_cards[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = NULL}; |
44DEFINE_RWLOCK(snd_card_rwlock); 45 46#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) | 44DEFINE_RWLOCK(snd_card_rwlock); 45 46#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) |
47int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int free_flag); | 47int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag); |
48#endif 49 | 48#endif 49 |
50static void snd_card_id_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) | 50static void snd_card_id_read(struct snd_info_entry *entry, 51 struct snd_info_buffer *buffer) |
51{ 52 snd_iprintf(buffer, "%s\n", entry->card->id); 53} 54 55static void snd_card_free_thread(void * __card); 56 57/** 58 * snd_card_new - create and initialize a soundcard structure 59 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 60 * @xid: card identification (ASCII string) 61 * @module: top level module for locking 62 * @extra_size: allocate this extra size after the main soundcard structure 63 * 64 * Creates and initializes a soundcard structure. 65 * | 52{ 53 snd_iprintf(buffer, "%s\n", entry->card->id); 54} 55 56static void snd_card_free_thread(void * __card); 57 58/** 59 * snd_card_new - create and initialize a soundcard structure 60 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 61 * @xid: card identification (ASCII string) 62 * @module: top level module for locking 63 * @extra_size: allocate this extra size after the main soundcard structure 64 * 65 * Creates and initializes a soundcard structure. 66 * |
66 * Returns kmallocated snd_card_t structure. Creates the ALSA control interface | 67 * Returns kmallocated snd_card structure. Creates the ALSA control interface |
67 * (which is blocked until snd_card_register function is called). 68 */ | 68 * (which is blocked until snd_card_register function is called). 69 */ |
69snd_card_t *snd_card_new(int idx, const char *xid, | 70struct snd_card *snd_card_new(int idx, const char *xid, |
70 struct module *module, int extra_size) 71{ | 71 struct module *module, int extra_size) 72{ |
72 snd_card_t *card; | 73 struct snd_card *card; |
73 int err; 74 75 if (extra_size < 0) 76 extra_size = 0; 77 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 78 if (card == NULL) 79 return NULL; 80 if (xid) { --- 46 unchanged lines hidden (view full) --- 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) | 74 int err; 75 76 if (extra_size < 0) 77 extra_size = 0; 78 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 79 if (card == NULL) 80 return NULL; 81 if (xid) { --- 46 unchanged lines hidden (view full) --- 128 snd_printd("unable to register control minors\n"); 129 goto __error; 130 } 131 if ((err = snd_info_card_create(card)) < 0) { 132 snd_printd("unable to create card info\n"); 133 goto __error_ctl; 134 } 135 if (extra_size > 0) |
135 card->private_data = (char *)card + sizeof(snd_card_t); | 136 card->private_data = (char *)card + sizeof(struct snd_card); |
136 return card; 137 138 __error_ctl: 139 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 140 __error: 141 kfree(card); 142 return NULL; 143} --- 9 unchanged lines hidden (view full) --- 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 */ | 137 return card; 138 139 __error_ctl: 140 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 141 __error: 142 kfree(card); 143 return NULL; 144} --- 9 unchanged lines hidden (view full) --- 154 * 155 * Disconnects all APIs from the file-operations (user space). 156 * 157 * Returns zero, otherwise a negative error code. 158 * 159 * Note: The current implementation replaces all active file->f_op with special 160 * dummy file operations (they do nothing except release). 161 */ |
161int snd_card_disconnect(snd_card_t * card) | 162int snd_card_disconnect(struct snd_card *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); --- 54 unchanged lines hidden (view full) --- 224 err = snd_device_disconnect_all(card); 225 if (err < 0) 226 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 227 228 return 0; 229} 230 231#ifdef CONFIG_SND_GENERIC_DRIVER | 163{ 164 struct snd_monitor_file *mfile; 165 struct file *file; 166 struct snd_shutdown_f_ops *s_f_ops; 167 struct file_operations *f_ops, *old_f_ops; 168 int err; 169 170 spin_lock(&card->files_lock); --- 54 unchanged lines hidden (view full) --- 225 err = snd_device_disconnect_all(card); 226 if (err < 0) 227 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 228 229 return 0; 230} 231 232#ifdef CONFIG_SND_GENERIC_DRIVER |
232static void snd_generic_device_unregister(snd_card_t *card); | 233static void snd_generic_device_unregister(struct snd_card *card); |
233#else 234#define snd_generic_device_unregister(x) /*NOP*/ 235#endif 236 237/** 238 * snd_card_free - frees given soundcard structure 239 * @card: soundcard structure 240 * 241 * This function releases the soundcard structure and the all assigned 242 * devices automatically. That is, you don't have to release the devices 243 * by yourself. 244 * 245 * Returns zero. Frees all associated devices and frees the control 246 * interface associated to given soundcard. 247 */ | 234#else 235#define snd_generic_device_unregister(x) /*NOP*/ 236#endif 237 238/** 239 * snd_card_free - frees given soundcard structure 240 * @card: soundcard structure 241 * 242 * This function releases the soundcard structure and the all assigned 243 * devices automatically. That is, you don't have to release the devices 244 * by yourself. 245 * 246 * Returns zero. Frees all associated devices and frees the control 247 * interface associated to given soundcard. 248 */ |
248int snd_card_free(snd_card_t * card) | 249int snd_card_free(struct snd_card *card) |
249{ 250 struct snd_shutdown_f_ops *s_f_ops; 251 252 if (card == NULL) 253 return -EINVAL; 254 write_lock(&snd_card_rwlock); 255 snd_cards[card->number] = NULL; 256 write_unlock(&snd_card_rwlock); --- 38 unchanged lines hidden (view full) --- 295 snd_cards_lock &= ~(1 << card->number); 296 write_unlock(&snd_card_rwlock); 297 kfree(card); 298 return 0; 299} 300 301static void snd_card_free_thread(void * __card) 302{ | 250{ 251 struct snd_shutdown_f_ops *s_f_ops; 252 253 if (card == NULL) 254 return -EINVAL; 255 write_lock(&snd_card_rwlock); 256 snd_cards[card->number] = NULL; 257 write_unlock(&snd_card_rwlock); --- 38 unchanged lines hidden (view full) --- 296 snd_cards_lock &= ~(1 << card->number); 297 write_unlock(&snd_card_rwlock); 298 kfree(card); 299 return 0; 300} 301 302static void snd_card_free_thread(void * __card) 303{ |
303 snd_card_t *card = __card; | 304 struct snd_card *card = __card; |
304 struct module * module = card->module; 305 306 if (!try_module_get(module)) { 307 snd_printk(KERN_ERR "unable to lock toplevel module for card %i in free thread\n", card->number); 308 module = NULL; 309 } 310 311 snd_card_free(card); --- 10 unchanged lines hidden (view full) --- 322 * is woken up and calls snd_card_free(). 323 * 324 * When a card can be disconnected at any time by hotplug service, 325 * this function should be used in disconnect (or detach) callback 326 * instead of calling snd_card_free() directly. 327 * 328 * Returns - zero otherwise a negative error code if the start of thread failed. 329 */ | 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); --- 10 unchanged lines hidden (view full) --- 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 */ |
330int snd_card_free_in_thread(snd_card_t * card) | 331int snd_card_free_in_thread(struct snd_card *card) |
331{ 332 if (card->files == NULL) { 333 snd_card_free(card); 334 return 0; 335 } 336 337 if (schedule_work(&card->free_workq)) 338 return 0; 339 340 snd_printk(KERN_ERR "schedule_work() failed in snd_card_free_in_thread for card %i\n", card->number); 341 /* try to free the structure immediately */ 342 snd_card_free(card); 343 return -EFAULT; 344} 345 | 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 |
346static void choose_default_id(snd_card_t * card) | 347static void choose_default_id(struct snd_card *card) |
347{ 348 int i, len, idx_flag = 0, loops = 8; 349 char *id, *spos; 350 351 id = spos = card->shortname; 352 while (*id != '\0') { 353 if (*id == ' ') 354 spos = id + 1; --- 55 unchanged lines hidden (view full) --- 410 * 411 * This function registers all the devices assigned to the soundcard. 412 * Until calling this, the ALSA control interface is blocked from the 413 * external accesses. Thus, you should call this function at the end 414 * of the initialization of the card. 415 * 416 * Returns zero otherwise a negative error code if the registrain failed. 417 */ | 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; --- 55 unchanged lines hidden (view full) --- 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 */ |
418int snd_card_register(snd_card_t * card) | 419int snd_card_register(struct snd_card *card) |
419{ 420 int err; | 420{ 421 int err; |
421 snd_info_entry_t *entry; | 422 struct snd_info_entry *entry; |
422 423 snd_assert(card != NULL, return -EINVAL); 424 if ((err = snd_device_register_all(card)) < 0) 425 return err; 426 write_lock(&snd_card_rwlock); 427 if (snd_cards[card->number]) { 428 /* already registered */ 429 write_unlock(&snd_card_rwlock); --- 21 unchanged lines hidden (view full) --- 451 __skip_info: 452#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 453 if (snd_mixer_oss_notify_callback) 454 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); 455#endif 456 return 0; 457} 458 | 423 424 snd_assert(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); --- 21 unchanged lines hidden (view full) --- 452 __skip_info: 453#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 454 if (snd_mixer_oss_notify_callback) 455 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); 456#endif 457 return 0; 458} 459 |
459static snd_info_entry_t *snd_card_info_entry = NULL; | 460static struct snd_info_entry *snd_card_info_entry = NULL; |
460 | 461 |
461static void snd_card_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) | 462static void snd_card_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
462{ 463 int idx, count; | 463{ 464 int idx, count; |
464 snd_card_t *card; | 465 struct snd_card *card; |
465 466 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 467 read_lock(&snd_card_rwlock); 468 if ((card = snd_cards[idx]) != NULL) { 469 count++; 470 snd_iprintf(buffer, "%i [%-15s]: %s - %s\n", 471 idx, 472 card->id, --- 5 unchanged lines hidden (view full) --- 478 read_unlock(&snd_card_rwlock); 479 } 480 if (!count) 481 snd_iprintf(buffer, "--- no soundcards ---\n"); 482} 483 484#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) 485 | 466 467 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 468 read_lock(&snd_card_rwlock); 469 if ((card = snd_cards[idx]) != NULL) { 470 count++; 471 snd_iprintf(buffer, "%i [%-15s]: %s - %s\n", 472 idx, 473 card->id, --- 5 unchanged lines hidden (view full) --- 479 read_unlock(&snd_card_rwlock); 480 } 481 if (!count) 482 snd_iprintf(buffer, "--- no soundcards ---\n"); 483} 484 485#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS) 486 |
486void snd_card_info_read_oss(snd_info_buffer_t * buffer) | 487void snd_card_info_read_oss(struct snd_info_buffer *buffer) |
487{ 488 int idx, count; | 488{ 489 int idx, count; |
489 snd_card_t *card; | 490 struct snd_card *card; |
490 491 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 492 read_lock(&snd_card_rwlock); 493 if ((card = snd_cards[idx]) != NULL) { 494 count++; 495 snd_iprintf(buffer, "%s\n", card->longname); 496 } 497 read_unlock(&snd_card_rwlock); 498 } 499 if (!count) { 500 snd_iprintf(buffer, "--- no soundcards ---\n"); 501 } 502} 503 504#endif 505 506#ifdef MODULE | 491 492 for (idx = count = 0; idx < SNDRV_CARDS; idx++) { 493 read_lock(&snd_card_rwlock); 494 if ((card = snd_cards[idx]) != NULL) { 495 count++; 496 snd_iprintf(buffer, "%s\n", card->longname); 497 } 498 read_unlock(&snd_card_rwlock); 499 } 500 if (!count) { 501 snd_iprintf(buffer, "--- no soundcards ---\n"); 502 } 503} 504 505#endif 506 507#ifdef MODULE |
507static snd_info_entry_t *snd_card_module_info_entry; 508static void snd_card_module_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer) | 508static struct snd_info_entry *snd_card_module_info_entry; 509static void snd_card_module_info_read(struct snd_info_entry *entry, 510 struct snd_info_buffer *buffer) |
509{ 510 int idx; | 511{ 512 int idx; |
511 snd_card_t *card; | 513 struct snd_card *card; |
512 513 for (idx = 0; idx < SNDRV_CARDS; idx++) { 514 read_lock(&snd_card_rwlock); 515 if ((card = snd_cards[idx]) != NULL) 516 snd_iprintf(buffer, "%i %s\n", idx, card->module->name); 517 read_unlock(&snd_card_rwlock); 518 } 519} 520#endif 521 522int __init snd_card_info_init(void) 523{ | 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 524int __init snd_card_info_init(void) 525{ |
524 snd_info_entry_t *entry; | 526 struct snd_info_entry *entry; |
525 526 entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); 527 if (! entry) 528 return -ENOMEM; 529 entry->c.text.read_size = PAGE_SIZE; 530 entry->c.text.read = snd_card_info_read; 531 if (snd_info_register(entry) < 0) { 532 snd_info_free_entry(entry); --- 33 unchanged lines hidden (view full) --- 566 * @component: the component id string 567 * 568 * This function adds the component id string to the supported list. 569 * The component can be referred from the alsa-lib. 570 * 571 * Returns zero otherwise a negative error code. 572 */ 573 | 527 528 entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); 529 if (! entry) 530 return -ENOMEM; 531 entry->c.text.read_size = PAGE_SIZE; 532 entry->c.text.read = snd_card_info_read; 533 if (snd_info_register(entry) < 0) { 534 snd_info_free_entry(entry); --- 33 unchanged lines hidden (view full) --- 568 * @component: the component id string 569 * 570 * This function adds the component id string to the supported list. 571 * The component can be referred from the alsa-lib. 572 * 573 * Returns zero otherwise a negative error code. 574 */ 575 |
574int snd_component_add(snd_card_t *card, const char *component) | 576int snd_component_add(struct snd_card *card, const char *component) |
575{ 576 char *ptr; 577 int len = strlen(component); 578 579 ptr = strstr(card->components, component); 580 if (ptr != NULL) { 581 if (ptr[len] == '\0' || ptr[len] == ' ') /* already there */ 582 return 1; --- 14 unchanged lines hidden (view full) --- 597 * @file: file pointer 598 * 599 * This function adds the file to the file linked-list of the card. 600 * This linked-list is used to keep tracking the connection state, 601 * and to avoid the release of busy resources by hotplug. 602 * 603 * Returns zero or a negative error code. 604 */ | 577{ 578 char *ptr; 579 int len = strlen(component); 580 581 ptr = strstr(card->components, component); 582 if (ptr != NULL) { 583 if (ptr[len] == '\0' || ptr[len] == ' ') /* already there */ 584 return 1; --- 14 unchanged lines hidden (view full) --- 599 * @file: file pointer 600 * 601 * This function adds the file to the file linked-list of the card. 602 * This linked-list is used to keep tracking the connection state, 603 * and to avoid the release of busy resources by hotplug. 604 * 605 * Returns zero or a negative error code. 606 */ |
605int snd_card_file_add(snd_card_t *card, struct file *file) | 607int snd_card_file_add(struct snd_card *card, struct file *file) |
606{ 607 struct snd_monitor_file *mfile; 608 609 mfile = kmalloc(sizeof(*mfile), GFP_KERNEL); 610 if (mfile == NULL) 611 return -ENOMEM; 612 mfile->file = file; 613 mfile->next = NULL; --- 17 unchanged lines hidden (view full) --- 631 * This function removes the file formerly added to the card via 632 * snd_card_file_add() function. 633 * If all files are removed and the release of the card is 634 * scheduled, it will wake up the the thread to call snd_card_free() 635 * (see snd_card_free_in_thread() function). 636 * 637 * Returns zero or a negative error code. 638 */ | 608{ 609 struct snd_monitor_file *mfile; 610 611 mfile = kmalloc(sizeof(*mfile), GFP_KERNEL); 612 if (mfile == NULL) 613 return -ENOMEM; 614 mfile->file = file; 615 mfile->next = NULL; --- 17 unchanged lines hidden (view full) --- 633 * This function removes the file formerly added to the card via 634 * snd_card_file_add() function. 635 * If all files are removed and the release of the card is 636 * scheduled, it will wake up the the thread to call snd_card_free() 637 * (see snd_card_free_in_thread() function). 638 * 639 * Returns zero or a negative error code. 640 */ |
639int snd_card_file_remove(snd_card_t *card, struct file *file) | 641int snd_card_file_remove(struct snd_card *card, struct file *file) |
640{ 641 struct snd_monitor_file *mfile, *pfile = NULL; 642 643 spin_lock(&card->files_lock); 644 mfile = card->files; 645 while (mfile) { 646 if (mfile->file == file) { 647 if (pfile) --- 18 unchanged lines hidden (view full) --- 666 667#ifdef CONFIG_SND_GENERIC_DRIVER 668/* 669 * generic device without a proper bus using platform_device 670 * (e.g. ISA) 671 */ 672struct snd_generic_device { 673 struct platform_device pdev; | 642{ 643 struct snd_monitor_file *mfile, *pfile = NULL; 644 645 spin_lock(&card->files_lock); 646 mfile = card->files; 647 while (mfile) { 648 if (mfile->file == file) { 649 if (pfile) --- 18 unchanged lines hidden (view full) --- 668 669#ifdef CONFIG_SND_GENERIC_DRIVER 670/* 671 * generic device without a proper bus using platform_device 672 * (e.g. ISA) 673 */ 674struct snd_generic_device { 675 struct platform_device pdev; |
674 snd_card_t *card; | 676 struct snd_card *card; |
675}; 676 677#define get_snd_generic_card(dev) container_of(dev, struct snd_generic_device, pdev)->card 678 679#define SND_GENERIC_NAME "snd_generic" 680 681#ifdef CONFIG_PM 682static int snd_generic_suspend(struct platform_device *dev, pm_message_t state); --- 10 unchanged lines hidden (view full) --- 693 .name = SND_GENERIC_NAME, 694 }, 695}; 696 697void snd_generic_device_release(struct device *dev) 698{ 699} 700 | 677}; 678 679#define get_snd_generic_card(dev) container_of(dev, struct snd_generic_device, pdev)->card 680 681#define SND_GENERIC_NAME "snd_generic" 682 683#ifdef CONFIG_PM 684static int snd_generic_suspend(struct platform_device *dev, pm_message_t state); --- 10 unchanged lines hidden (view full) --- 695 .name = SND_GENERIC_NAME, 696 }, 697}; 698 699void snd_generic_device_release(struct device *dev) 700{ 701} 702 |
701static int snd_generic_device_register(snd_card_t *card) | 703static int snd_generic_device_register(struct snd_card *card) |
702{ 703 struct snd_generic_device *dev; 704 int err; 705 706 if (card->generic_dev) 707 return 0; /* already registered */ 708 709 dev = kzalloc(sizeof(*dev), GFP_KERNEL); --- 9 unchanged lines hidden (view full) --- 719 if ((err = platform_device_register(&dev->pdev)) < 0) { 720 kfree(dev); 721 return err; 722 } 723 card->generic_dev = dev; 724 return 0; 725} 726 | 704{ 705 struct snd_generic_device *dev; 706 int err; 707 708 if (card->generic_dev) 709 return 0; /* already registered */ 710 711 dev = kzalloc(sizeof(*dev), GFP_KERNEL); --- 9 unchanged lines hidden (view full) --- 721 if ((err = platform_device_register(&dev->pdev)) < 0) { 722 kfree(dev); 723 return err; 724 } 725 card->generic_dev = dev; 726 return 0; 727} 728 |
727static void snd_generic_device_unregister(snd_card_t *card) | 729static void snd_generic_device_unregister(struct snd_card *card) |
728{ 729 struct snd_generic_device *dev = card->generic_dev; 730 if (dev) { 731 platform_device_unregister(&dev->pdev); 732 kfree(dev); 733 card->generic_dev = NULL; 734 } 735} 736 737/** 738 * snd_card_set_generic_dev - assign the generic device to the card 739 * @card: soundcard structure 740 * 741 * Assigns a generic device to the card. This function is provided as the 742 * last resort, for devices without any proper bus. Thus this won't override 743 * the device already assigned to the card. 744 * 745 * Returns zero if successful, or a negative error code. 746 */ | 730{ 731 struct snd_generic_device *dev = card->generic_dev; 732 if (dev) { 733 platform_device_unregister(&dev->pdev); 734 kfree(dev); 735 card->generic_dev = NULL; 736 } 737} 738 739/** 740 * snd_card_set_generic_dev - assign the generic device to the card 741 * @card: soundcard structure 742 * 743 * Assigns a generic device to the card. This function is provided as the 744 * last resort, for devices without any proper bus. Thus this won't override 745 * the device already assigned to the card. 746 * 747 * Returns zero if successful, or a negative error code. 748 */ |
747int snd_card_set_generic_dev(snd_card_t *card) | 749int snd_card_set_generic_dev(struct snd_card *card) |
748{ 749 int err; 750 if ((err = snd_generic_device_register(card)) < 0) 751 return err; 752 if (! card->dev) 753 snd_card_set_dev(card, &card->generic_dev->pdev.dev); 754 return 0; 755} --- 5 unchanged lines hidden (view full) --- 761 * @card: soundcard structure 762 * @power_state: expected power state 763 * @file: file structure for the O_NONBLOCK check (optional) 764 * 765 * Waits until the power-state is changed. 766 * 767 * Note: the power lock must be active before call. 768 */ | 750{ 751 int err; 752 if ((err = snd_generic_device_register(card)) < 0) 753 return err; 754 if (! card->dev) 755 snd_card_set_dev(card, &card->generic_dev->pdev.dev); 756 return 0; 757} --- 5 unchanged lines hidden (view full) --- 763 * @card: soundcard structure 764 * @power_state: expected power state 765 * @file: file structure for the O_NONBLOCK check (optional) 766 * 767 * Waits until the power-state is changed. 768 * 769 * Note: the power lock must be active before call. 770 */ |
769int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file) | 771int snd_power_wait(struct snd_card *card, unsigned int power_state, struct file *file) |
770{ 771 wait_queue_t wait; 772 int result = 0; 773 774 /* fastpath */ 775 if (snd_power_get_state(card) == power_state) 776 return 0; 777 init_waitqueue_entry(&wait, current); --- 26 unchanged lines hidden (view full) --- 804 * @suspend: suspend callback function 805 * @resume: resume callback function 806 * @private_data: private data to pass to the callback functions 807 * 808 * Sets the power-management callback functions of the card. 809 * These callbacks are called from ALSA's common PCI suspend/resume 810 * handler and from the control API. 811 */ | 772{ 773 wait_queue_t wait; 774 int result = 0; 775 776 /* fastpath */ 777 if (snd_power_get_state(card) == power_state) 778 return 0; 779 init_waitqueue_entry(&wait, current); --- 26 unchanged lines hidden (view full) --- 806 * @suspend: suspend callback function 807 * @resume: resume callback function 808 * @private_data: private data to pass to the callback functions 809 * 810 * Sets the power-management callback functions of the card. 811 * These callbacks are called from ALSA's common PCI suspend/resume 812 * handler and from the control API. 813 */ |
812int snd_card_set_pm_callback(snd_card_t *card, 813 int (*suspend)(snd_card_t *, pm_message_t), 814 int (*resume)(snd_card_t *), | 814int snd_card_set_pm_callback(struct snd_card *card, 815 int (*suspend)(struct snd_card *, pm_message_t), 816 int (*resume)(struct snd_card *), |
815 void *private_data) 816{ 817 card->pm_suspend = suspend; 818 card->pm_resume = resume; 819 card->pm_private_data = private_data; 820 return 0; 821} 822 823#ifdef CONFIG_SND_GENERIC_DRIVER 824/* suspend/resume callbacks for snd_generic platform device */ 825static int snd_generic_suspend(struct platform_device *dev, pm_message_t state) 826{ | 817 void *private_data) 818{ 819 card->pm_suspend = suspend; 820 card->pm_resume = resume; 821 card->pm_private_data = private_data; 822 return 0; 823} 824 825#ifdef CONFIG_SND_GENERIC_DRIVER 826/* suspend/resume callbacks for snd_generic platform device */ 827static int snd_generic_suspend(struct platform_device *dev, pm_message_t state) 828{ |
827 snd_card_t *card; | 829 struct snd_card *card; |
828 829 card = get_snd_generic_card(dev); 830 if (card->power_state == SNDRV_CTL_POWER_D3hot) 831 return 0; 832 if (card->pm_suspend) 833 card->pm_suspend(card, PMSG_SUSPEND); 834 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 835 return 0; 836} 837 838static int snd_generic_resume(struct platform_device *dev) 839{ | 830 831 card = get_snd_generic_card(dev); 832 if (card->power_state == SNDRV_CTL_POWER_D3hot) 833 return 0; 834 if (card->pm_suspend) 835 card->pm_suspend(card, PMSG_SUSPEND); 836 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 837 return 0; 838} 839 840static int snd_generic_resume(struct platform_device *dev) 841{ |
840 snd_card_t *card; | 842 struct snd_card *card; |
841 842 card = get_snd_generic_card(dev); 843 if (card->power_state == SNDRV_CTL_POWER_D0) 844 return 0; 845 if (card->pm_resume) 846 card->pm_resume(card); 847 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 848 return 0; --- 5 unchanged lines hidden (view full) --- 854 * @suspend: suspend callback function 855 * @resume: resume callback function 856 * @private_data: private data to pass to the callback functions 857 * 858 * Registers the power-management and sets the lowlevel callbacks for 859 * the given card. These callbacks are called from the ALSA's common 860 * PM handler and from the control API. 861 */ | 843 844 card = get_snd_generic_card(dev); 845 if (card->power_state == SNDRV_CTL_POWER_D0) 846 return 0; 847 if (card->pm_resume) 848 card->pm_resume(card); 849 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 850 return 0; --- 5 unchanged lines hidden (view full) --- 856 * @suspend: suspend callback function 857 * @resume: resume callback function 858 * @private_data: private data to pass to the callback functions 859 * 860 * Registers the power-management and sets the lowlevel callbacks for 861 * the given card. These callbacks are called from the ALSA's common 862 * PM handler and from the control API. 863 */ |
862int snd_card_set_generic_pm_callback(snd_card_t *card, 863 int (*suspend)(snd_card_t *, pm_message_t), 864 int (*resume)(snd_card_t *), | 864int snd_card_set_generic_pm_callback(struct snd_card *card, 865 int (*suspend)(struct snd_card *, pm_message_t), 866 int (*resume)(struct snd_card *), |
865 void *private_data) 866{ 867 int err; 868 if ((err = snd_generic_device_register(card)) < 0) 869 return err; 870 return snd_card_set_pm_callback(card, suspend, resume, private_data); 871} 872#endif /* CONFIG_SND_GENERIC_DRIVER */ 873 874#ifdef CONFIG_PCI 875int snd_card_pci_suspend(struct pci_dev *dev, pm_message_t state) 876{ | 867 void *private_data) 868{ 869 int err; 870 if ((err = snd_generic_device_register(card)) < 0) 871 return err; 872 return snd_card_set_pm_callback(card, suspend, resume, private_data); 873} 874#endif /* CONFIG_SND_GENERIC_DRIVER */ 875 876#ifdef CONFIG_PCI 877int snd_card_pci_suspend(struct pci_dev *dev, pm_message_t state) 878{ |
877 snd_card_t *card = pci_get_drvdata(dev); | 879 struct snd_card *card = pci_get_drvdata(dev); |
878 int err; 879 if (! card || ! card->pm_suspend) 880 return 0; 881 if (card->power_state == SNDRV_CTL_POWER_D3hot) 882 return 0; 883 err = card->pm_suspend(card, PMSG_SUSPEND); 884 pci_save_state(dev); 885 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 886 return err; 887} 888 889int snd_card_pci_resume(struct pci_dev *dev) 890{ | 880 int err; 881 if (! card || ! card->pm_suspend) 882 return 0; 883 if (card->power_state == SNDRV_CTL_POWER_D3hot) 884 return 0; 885 err = card->pm_suspend(card, PMSG_SUSPEND); 886 pci_save_state(dev); 887 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 888 return err; 889} 890 891int snd_card_pci_resume(struct pci_dev *dev) 892{ |
891 snd_card_t *card = pci_get_drvdata(dev); | 893 struct snd_card *card = pci_get_drvdata(dev); |
892 if (! card || ! card->pm_resume) 893 return 0; 894 if (card->power_state == SNDRV_CTL_POWER_D0) 895 return 0; 896 /* restore the PCI config space */ 897 pci_restore_state(dev); 898 card->pm_resume(card); 899 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 900 return 0; 901} 902#endif 903 904#endif /* CONFIG_PM */ | 894 if (! card || ! card->pm_resume) 895 return 0; 896 if (card->power_state == SNDRV_CTL_POWER_D0) 897 return 0; 898 /* restore the PCI config space */ 899 pci_restore_state(dev); 900 card->pm_resume(card); 901 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 902 return 0; 903} 904#endif 905 906#endif /* CONFIG_PM */ |