Lines Matching refs:card
85 int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
127 void snd_device_initialize(struct device *dev, struct snd_card *card) in snd_device_initialize() argument
130 if (card) in snd_device_initialize()
131 dev->parent = &card->card_dev; in snd_device_initialize()
137 static int snd_card_init(struct snd_card *card, struct device *parent,
140 static int snd_card_do_free(struct snd_card *card);
167 struct snd_card *card; in snd_card_new() local
176 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); in snd_card_new()
177 if (!card) in snd_card_new()
180 err = snd_card_init(card, parent, idx, xid, module, extra_size); in snd_card_new()
184 *card_ret = card; in snd_card_new()
223 struct snd_card *card; in snd_devm_card_new() local
227 card = devres_alloc(__snd_card_release, sizeof(*card) + extra_size, in snd_devm_card_new()
229 if (!card) in snd_devm_card_new()
231 card->managed = true; in snd_devm_card_new()
232 err = snd_card_init(card, parent, idx, xid, module, extra_size); in snd_devm_card_new()
234 devres_free(card); /* in managed mode, we need to free manually */ in snd_devm_card_new()
238 devres_add(parent, card); in snd_devm_card_new()
239 *card_ret = card; in snd_devm_card_new()
257 struct snd_card *card; in snd_card_free_on_error() local
261 card = devres_find(dev, __snd_card_release, NULL, NULL); in snd_card_free_on_error()
262 if (card) in snd_card_free_on_error()
263 snd_card_free(card); in snd_card_free_on_error()
268 static int snd_card_init(struct snd_card *card, struct device *parent, in snd_card_init() argument
278 card->private_data = (char *)card + sizeof(struct snd_card); in snd_card_init()
280 strscpy(card->id, xid, sizeof(card->id)); in snd_card_init()
298 if (!card->managed) in snd_card_init()
299 kfree(card); /* manually free here, as no destructor called */ in snd_card_init()
306 card->dev = parent; in snd_card_init()
307 card->number = idx; in snd_card_init()
310 card->module = module; in snd_card_init()
312 INIT_LIST_HEAD(&card->devices); in snd_card_init()
313 init_rwsem(&card->controls_rwsem); in snd_card_init()
314 rwlock_init(&card->ctl_files_rwlock); in snd_card_init()
315 INIT_LIST_HEAD(&card->controls); in snd_card_init()
316 INIT_LIST_HEAD(&card->ctl_files); in snd_card_init()
318 xa_init(&card->ctl_numids); in snd_card_init()
319 xa_init(&card->ctl_hash); in snd_card_init()
321 spin_lock_init(&card->files_lock); in snd_card_init()
322 INIT_LIST_HEAD(&card->files_list); in snd_card_init()
323 mutex_init(&card->memory_mutex); in snd_card_init()
325 init_waitqueue_head(&card->power_sleep); in snd_card_init()
326 init_waitqueue_head(&card->power_ref_sleep); in snd_card_init()
327 atomic_set(&card->power_ref, 0); in snd_card_init()
329 init_waitqueue_head(&card->remove_sleep); in snd_card_init()
330 card->sync_irq = -1; in snd_card_init()
332 device_initialize(&card->card_dev); in snd_card_init()
333 card->card_dev.parent = parent; in snd_card_init()
334 card->card_dev.class = sound_class; in snd_card_init()
335 card->card_dev.release = release_card_device; in snd_card_init()
336 card->card_dev.groups = card->dev_groups; in snd_card_init()
337 card->dev_groups[0] = &card_dev_attr_group; in snd_card_init()
338 err = kobject_set_name(&card->card_dev.kobj, "card%d", idx); in snd_card_init()
342 snprintf(card->irq_descr, sizeof(card->irq_descr), "%s:%s", in snd_card_init()
343 dev_driver_string(card->dev), dev_name(&card->card_dev)); in snd_card_init()
347 err = snd_ctl_create(card); in snd_card_init()
352 err = snd_info_card_create(card); in snd_card_init()
360 card->debugfs_root = debugfs_create_dir(name, sound_debugfs_root); in snd_card_init()
365 snd_device_free_all(card); in snd_card_init()
367 put_device(&card->card_dev); in snd_card_init()
382 struct snd_card *card; in snd_card_ref() local
385 card = snd_cards[idx]; in snd_card_ref()
386 if (card) in snd_card_ref()
387 get_device(&card->card_dev); in snd_card_ref()
389 return card; in snd_card_ref()
394 int snd_card_locked(int card) in snd_card_locked() argument
399 locked = test_bit(card, snd_cards_lock); in snd_card_locked()
492 int snd_card_disconnect(struct snd_card *card) in snd_card_disconnect() argument
496 if (!card) in snd_card_disconnect()
499 spin_lock(&card->files_lock); in snd_card_disconnect()
500 if (card->shutdown) { in snd_card_disconnect()
501 spin_unlock(&card->files_lock); in snd_card_disconnect()
504 card->shutdown = 1; in snd_card_disconnect()
507 list_for_each_entry(mfile, &card->files_list, list) { in snd_card_disconnect()
519 spin_unlock(&card->files_lock); in snd_card_disconnect()
526 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT); in snd_card_disconnect()
530 snd_device_disconnect_all(card); in snd_card_disconnect()
532 if (card->sync_irq > 0) in snd_card_disconnect()
533 synchronize_irq(card->sync_irq); in snd_card_disconnect()
535 snd_info_card_disconnect(card); in snd_card_disconnect()
536 if (card->registered) { in snd_card_disconnect()
537 device_del(&card->card_dev); in snd_card_disconnect()
538 card->registered = false; in snd_card_disconnect()
543 snd_cards[card->number] = NULL; in snd_card_disconnect()
544 clear_bit(card->number, snd_cards_lock); in snd_card_disconnect()
548 wake_up(&card->power_sleep); in snd_card_disconnect()
549 snd_power_sync_ref(card); in snd_card_disconnect()
564 void snd_card_disconnect_sync(struct snd_card *card) in snd_card_disconnect_sync() argument
568 err = snd_card_disconnect(card); in snd_card_disconnect_sync()
570 dev_err(card->dev, in snd_card_disconnect_sync()
576 spin_lock_irq(&card->files_lock); in snd_card_disconnect_sync()
577 wait_event_lock_irq(card->remove_sleep, in snd_card_disconnect_sync()
578 list_empty(&card->files_list), in snd_card_disconnect_sync()
579 card->files_lock); in snd_card_disconnect_sync()
580 spin_unlock_irq(&card->files_lock); in snd_card_disconnect_sync()
584 static int snd_card_do_free(struct snd_card *card) in snd_card_do_free() argument
586 card->releasing = true; in snd_card_do_free()
589 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); in snd_card_do_free()
591 snd_device_free_all(card); in snd_card_do_free()
592 if (card->private_free) in snd_card_do_free()
593 card->private_free(card); in snd_card_do_free()
594 if (snd_info_card_free(card) < 0) { in snd_card_do_free()
595 dev_warn(card->dev, "unable to free card info\n"); in snd_card_do_free()
599 debugfs_remove(card->debugfs_root); in snd_card_do_free()
600 card->debugfs_root = NULL; in snd_card_do_free()
602 if (card->release_completion) in snd_card_do_free()
603 complete(card->release_completion); in snd_card_do_free()
604 if (!card->managed) in snd_card_do_free()
605 kfree(card); in snd_card_do_free()
620 int snd_card_free_when_closed(struct snd_card *card) in snd_card_free_when_closed() argument
622 int ret = snd_card_disconnect(card); in snd_card_free_when_closed()
625 put_device(&card->card_dev); in snd_card_free_when_closed()
643 int snd_card_free(struct snd_card *card) in snd_card_free() argument
654 if (card->releasing) in snd_card_free()
657 card->release_completion = &released; in snd_card_free()
658 ret = snd_card_free_when_closed(card); in snd_card_free()
682 static bool card_id_ok(struct snd_card *card, const char *id) in card_id_ok() argument
688 if (snd_cards[i] && snd_cards[i] != card && in card_id_ok()
696 static void copy_valid_id_string(struct snd_card *card, const char *src, in copy_valid_id_string() argument
699 char *id = card->id; in copy_valid_id_string()
705 while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) { in copy_valid_id_string()
716 static void snd_card_set_id_no_lock(struct snd_card *card, const char *src, in snd_card_set_id_no_lock() argument
723 copy_valid_id_string(card, src, nid); in snd_card_set_id_no_lock()
724 id = card->id; in snd_card_set_id_no_lock()
741 if (card_id_ok(card, id)) in snd_card_set_id_no_lock()
747 if (len + sfxlen >= sizeof(card->id)) in snd_card_set_id_no_lock()
748 spos = id + sizeof(card->id) - sfxlen - 1; in snd_card_set_id_no_lock()
759 dev_err(card->dev, "unable to set card id (%s)\n", id); in snd_card_set_id_no_lock()
760 if (card->proc_root->name) in snd_card_set_id_no_lock()
761 strscpy(card->id, card->proc_root->name, sizeof(card->id)); in snd_card_set_id_no_lock()
772 void snd_card_set_id(struct snd_card *card, const char *nid) in snd_card_set_id() argument
775 if (card->id[0] != '\0') in snd_card_set_id()
778 snd_card_set_id_no_lock(card, nid, nid); in snd_card_set_id()
786 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in id_show() local
787 return sysfs_emit(buf, "%s\n", card->id); in id_show()
793 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in id_store() local
794 char buf1[sizeof(card->id)]; in id_store()
795 size_t copy = count > sizeof(card->id) - 1 ? in id_store()
796 sizeof(card->id) - 1 : count; in id_store()
812 strcpy(card->id, buf1); in id_store()
813 snd_info_card_id_change(card); in id_store()
824 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in number_show() local
825 return sysfs_emit(buf, "%i\n", card->number); in number_show()
847 int snd_card_add_dev_attr(struct snd_card *card, in snd_card_add_dev_attr() argument
853 for (i = 0; i < ARRAY_SIZE(card->dev_groups) - 1; i++) { in snd_card_add_dev_attr()
854 if (!card->dev_groups[i]) { in snd_card_add_dev_attr()
855 card->dev_groups[i] = group; in snd_card_add_dev_attr()
860 dev_err(card->dev, "Too many groups assigned\n"); in snd_card_add_dev_attr()
881 int snd_card_register(struct snd_card *card) in snd_card_register() argument
885 if (snd_BUG_ON(!card)) in snd_card_register()
888 if (!card->registered) { in snd_card_register()
889 err = device_add(&card->card_dev); in snd_card_register()
892 card->registered = true; in snd_card_register()
894 if (card->managed) in snd_card_register()
895 devm_remove_action(card->dev, trigger_card_free, card); in snd_card_register()
898 if (card->managed) { in snd_card_register()
899 err = devm_add_action(card->dev, trigger_card_free, card); in snd_card_register()
904 err = snd_device_register_all(card); in snd_card_register()
908 if (snd_cards[card->number]) { in snd_card_register()
911 return snd_info_card_register(card); /* register pending info */ in snd_card_register()
913 if (*card->id) { in snd_card_register()
915 char tmpid[sizeof(card->id)]; in snd_card_register()
916 memcpy(tmpid, card->id, sizeof(card->id)); in snd_card_register()
917 snd_card_set_id_no_lock(card, tmpid, tmpid); in snd_card_register()
921 src = *card->shortname ? card->shortname : card->longname; in snd_card_register()
922 snd_card_set_id_no_lock(card, src, in snd_card_register()
925 snd_cards[card->number] = card; in snd_card_register()
927 err = snd_info_card_register(card); in snd_card_register()
933 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); in snd_card_register()
944 struct snd_card *card; in snd_card_info_read() local
948 card = snd_cards[idx]; in snd_card_info_read()
949 if (card) { in snd_card_info_read()
953 card->id, in snd_card_info_read()
954 card->driver, in snd_card_info_read()
955 card->shortname); in snd_card_info_read()
957 card->longname); in snd_card_info_read()
969 struct snd_card *card; in snd_card_info_read_oss() local
973 card = snd_cards[idx]; in snd_card_info_read_oss()
974 if (card) { in snd_card_info_read_oss()
976 snd_iprintf(buffer, "%s\n", card->longname); in snd_card_info_read_oss()
992 struct snd_card *card; in snd_card_module_info_read() local
996 card = snd_cards[idx]; in snd_card_module_info_read()
997 if (card) in snd_card_module_info_read()
999 idx, card->module->name); in snd_card_module_info_read()
1040 int snd_component_add(struct snd_card *card, const char *component) in snd_component_add() argument
1045 ptr = strstr(card->components, component); in snd_component_add()
1050 if (strlen(card->components) + 1 + len + 1 > sizeof(card->components)) { in snd_component_add()
1054 if (card->components[0] != '\0') in snd_component_add()
1055 strcat(card->components, " "); in snd_component_add()
1056 strcat(card->components, component); in snd_component_add()
1072 int snd_card_file_add(struct snd_card *card, struct file *file) in snd_card_file_add() argument
1082 spin_lock(&card->files_lock); in snd_card_file_add()
1083 if (card->shutdown) { in snd_card_file_add()
1084 spin_unlock(&card->files_lock); in snd_card_file_add()
1088 list_add(&mfile->list, &card->files_list); in snd_card_file_add()
1089 get_device(&card->card_dev); in snd_card_file_add()
1090 spin_unlock(&card->files_lock); in snd_card_file_add()
1108 int snd_card_file_remove(struct snd_card *card, struct file *file) in snd_card_file_remove() argument
1112 spin_lock(&card->files_lock); in snd_card_file_remove()
1113 list_for_each_entry(mfile, &card->files_list, list) { in snd_card_file_remove()
1125 if (list_empty(&card->files_list)) in snd_card_file_remove()
1126 wake_up_all(&card->remove_sleep); in snd_card_file_remove()
1127 spin_unlock(&card->files_lock); in snd_card_file_remove()
1129 dev_err(card->dev, "card file remove problem (%p)\n", file); in snd_card_file_remove()
1133 put_device(&card->card_dev); in snd_card_file_remove()
1154 int snd_power_ref_and_wait(struct snd_card *card) in snd_power_ref_and_wait() argument
1156 snd_power_ref(card); in snd_power_ref_and_wait()
1157 if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) in snd_power_ref_and_wait()
1159 wait_event_cmd(card->power_sleep, in snd_power_ref_and_wait()
1160 card->shutdown || in snd_power_ref_and_wait()
1161 snd_power_get_state(card) == SNDRV_CTL_POWER_D0, in snd_power_ref_and_wait()
1162 snd_power_unref(card), snd_power_ref(card)); in snd_power_ref_and_wait()
1163 return card->shutdown ? -ENODEV : 0; in snd_power_ref_and_wait()
1175 int snd_power_wait(struct snd_card *card) in snd_power_wait() argument
1179 ret = snd_power_ref_and_wait(card); in snd_power_wait()
1180 snd_power_unref(card); in snd_power_wait()