init.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 811 行 · 第 1/2 页
C
811 行
spos++; *spos++ = '_'; *spos++ = '1'; *spos++ = '\0'; idx_flag++; } }}/** * snd_card_register - register the soundcard * @card: soundcard structure * * This function registers all the devices assigned to the soundcard. * Until calling this, the ALSA control interface is blocked from the * external accesses. Thus, you should call this function at the end * of the initialization of the card. * * Returns zero otherwise a negative error code if the registrain failed. */int snd_card_register(snd_card_t * card){ int err; snd_info_entry_t *entry; snd_runtime_check(card != NULL, return -EINVAL); if ((err = snd_device_register_all(card)) < 0) return err; write_lock(&snd_card_rwlock); if (snd_cards[card->number]) { /* already registered */ write_unlock(&snd_card_rwlock); return 0; } if (card->id[0] == '\0') choose_default_id(card); snd_cards[card->number] = card; snd_cards_count++; write_unlock(&snd_card_rwlock); if ((err = snd_info_card_register(card)) < 0) { snd_printd("unable to create card info\n"); goto __skip_info; } if ((entry = snd_info_create_card_entry(card, "id", card->proc_root)) == NULL) { snd_printd("unable to create card entry\n"); goto __skip_info; } entry->c.text.read_size = PAGE_SIZE; entry->c.text.read = snd_card_id_read; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } card->proc_id = entry; __skip_info:#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);#endif return 0;}static snd_info_entry_t *snd_card_info_entry = NULL;static void snd_card_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer){ int idx, count; snd_card_t *card; for (idx = count = 0; idx < SNDRV_CARDS; idx++) { read_lock(&snd_card_rwlock); if ((card = snd_cards[idx]) != NULL) { count++; snd_iprintf(buffer, "%i [%-15s]: %s - %s\n", idx, card->id, card->driver, card->shortname); snd_iprintf(buffer, " %s\n", card->longname); } read_unlock(&snd_card_rwlock); } if (!count) snd_iprintf(buffer, "--- no soundcards ---\n");}#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_PROC_FS)void snd_card_info_read_oss(snd_info_buffer_t * buffer){ int idx, count; snd_card_t *card; for (idx = count = 0; idx < SNDRV_CARDS; idx++) { read_lock(&snd_card_rwlock); if ((card = snd_cards[idx]) != NULL) { count++; snd_iprintf(buffer, "%s\n", card->longname); } read_unlock(&snd_card_rwlock); } if (!count) { snd_iprintf(buffer, "--- no soundcards ---\n"); }}#endif#ifdef MODULEstatic snd_info_entry_t *snd_card_module_info_entry;static void snd_card_module_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer){ int idx; snd_card_t *card; for (idx = 0; idx < SNDRV_CARDS; idx++) { read_lock(&snd_card_rwlock); if ((card = snd_cards[idx]) != NULL) snd_iprintf(buffer, "%i %s\n", idx, card->module->name); read_unlock(&snd_card_rwlock); }}#endifint __init snd_card_info_init(void){ snd_info_entry_t *entry; entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); snd_runtime_check(entry != NULL, return -ENOMEM); entry->c.text.read_size = PAGE_SIZE; entry->c.text.read = snd_card_info_read; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); return -ENOMEM; } snd_card_info_entry = entry;#ifdef MODULE entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL); if (entry) { entry->c.text.read_size = PAGE_SIZE; entry->c.text.read = snd_card_module_info_read; if (snd_info_register(entry) < 0) snd_info_free_entry(entry); else snd_card_module_info_entry = entry; }#endif return 0;}int __exit snd_card_info_done(void){ if (snd_card_info_entry) snd_info_unregister(snd_card_info_entry);#ifdef MODULE if (snd_card_module_info_entry) snd_info_unregister(snd_card_module_info_entry);#endif return 0;}/** * snd_component_add - add a component string * @card: soundcard structure * @component: the component id string * * This function adds the component id string to the supported list. * The component can be referred from the alsa-lib. * * Returns zero otherwise a negative error code. */ int snd_component_add(snd_card_t *card, const char *component){ char *ptr; int len = strlen(component); ptr = strstr(card->components, component); if (ptr != NULL) { if (ptr[len] == '\0' || ptr[len] == ' ') /* already there */ return 1; } if (strlen(card->components) + 1 + len + 1 > sizeof(card->components)) { snd_BUG(); return -ENOMEM; } if (card->components[0] != '\0') strcat(card->components, " "); strcat(card->components, component); return 0;}/** * snd_card_file_add - add the file to the file list of the card * @card: soundcard structure * @file: file pointer * * This function adds the file to the file linked-list of the card. * This linked-list is used to keep tracking the connection state, * and to avoid the release of busy resources by hotplug. * * Returns zero or a negative error code. */int snd_card_file_add(snd_card_t *card, struct file *file){ struct snd_monitor_file *mfile; mfile = kmalloc(sizeof(*mfile), GFP_KERNEL); if (mfile == NULL) return -ENOMEM; mfile->file = file; mfile->next = NULL; spin_lock(&card->files_lock); if (card->shutdown) { spin_unlock(&card->files_lock); kfree(mfile); return -ENODEV; } mfile->next = card->files; card->files = mfile; spin_unlock(&card->files_lock); return 0;}/** * snd_card_file_remove - remove the file from the file list * @card: soundcard structure * @file: file pointer * * This function removes the file formerly added to the card via * snd_card_file_add() function. * If all files are removed and the release of the card is * scheduled, it will wake up the the thread to call snd_card_free() * (see snd_card_free_in_thread() function). * * Returns zero or a negative error code. */int snd_card_file_remove(snd_card_t *card, struct file *file){ struct snd_monitor_file *mfile, *pfile = NULL; spin_lock(&card->files_lock); mfile = card->files; while (mfile) { if (mfile->file == file) { if (pfile) pfile->next = mfile->next; else card->files = mfile->next; break; } pfile = mfile; mfile = mfile->next; } spin_unlock(&card->files_lock); if (card->files == NULL) wake_up(&card->shutdown_sleep); if (mfile) { kfree(mfile); } else { snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file); return -ENOENT; } return 0;}#ifdef CONFIG_PM/** * snd_power_wait - wait until the power-state is changed. * @card: soundcard structure * @power_state: expected power state * @file: file structure for the O_NONBLOCK check (optional) * * Waits until the power-state is changed. * * Note: the power lock must be active before call. */int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file){ wait_queue_t wait; int result = 0; /* fastpath */ if (snd_power_get_state(card) == power_state) return 0; init_waitqueue_entry(&wait, current); add_wait_queue(&card->power_sleep, &wait); while (1) { if (card->shutdown) { result = -ENODEV; break; } if (snd_power_get_state(card) == power_state) break;#if 0 /* block all devices */ if (file && (file->f_flags & O_NONBLOCK)) { result = -EAGAIN; break; }#endif set_current_state(TASK_UNINTERRUPTIBLE); snd_power_unlock(card); schedule_timeout(30 * HZ); snd_power_lock(card); } remove_wait_queue(&card->power_sleep, &wait); return result;}/** * snd_card_set_pm_callback - set the PCI power-management callbacks * @card: soundcard structure * @suspend: suspend callback function * @resume: resume callback function * @private_data: private data to pass to the callback functions * * Sets the power-management callback functions of the card. * These callbacks are called from ALSA's common PCI suspend/resume * handler and from the control API. */int snd_card_set_pm_callback(snd_card_t *card, int (*suspend)(snd_card_t *, unsigned int), int (*resume)(snd_card_t *, unsigned int), void *private_data){ card->pm_suspend = suspend; card->pm_resume = resume; card->pm_private_data = private_data; return 0;}static int snd_generic_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data){ snd_card_t *card = dev->data; switch (rqst) { case PM_SUSPEND: /* FIXME: the correct state value? */ card->pm_suspend(card, 0); break; case PM_RESUME: /* FIXME: the correct state value? */ card->pm_resume(card, 0); break; } return 0;}/** * snd_card_set_dev_pm_callback - set the generic power-management callbacks * @card: soundcard structure * @type: PM device type (PM_XXX) * @suspend: suspend callback function * @resume: resume callback function * @private_data: private data to pass to the callback functions * * Registers the power-management and sets the lowlevel callbacks for * the given card with the given PM type. These callbacks are called * from the ALSA's common PM handler and from the control API. */int snd_card_set_dev_pm_callback(snd_card_t *card, int type, int (*suspend)(snd_card_t *, unsigned int), int (*resume)(snd_card_t *, unsigned int), void *private_data){ card->pm_dev = pm_register(type, 0, snd_generic_pm_callback); if (! card->pm_dev) return -ENOMEM; card->pm_dev->data = card; snd_card_set_pm_callback(card, suspend, resume, private_data); return 0;}#ifdef CONFIG_PCIint snd_card_pci_suspend(struct pci_dev *dev, u32 state){ snd_card_t *card = pci_get_drvdata(dev); if (! card || ! card->pm_suspend) return 0; if (card->power_state == SNDRV_CTL_POWER_D3hot) return 0; /* FIXME: correct state value? */ return card->pm_suspend(card, 0);}int snd_card_pci_resume(struct pci_dev *dev){ snd_card_t *card = pci_get_drvdata(dev); if (! card || ! card->pm_resume) return 0; if (card->power_state == SNDRV_CTL_POWER_D0) return 0; /* restore the PCI config space */ pci_restore_state(dev, dev->saved_config_space); /* FIXME: correct state value? */ return card->pm_resume(card, 0);}#endif#endif /* CONFIG_PM */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?