Lines Matching full:card
85 int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
123 * @card: card to assign, optional
127 int snd_device_alloc(struct device **dev_p, struct snd_card *card) in snd_device_alloc() argument
136 if (card) in snd_device_alloc()
137 dev->parent = &card->card_dev; in snd_device_alloc()
145 static int snd_card_init(struct snd_card *card, struct device *parent,
148 static int snd_card_do_free(struct snd_card *card);
159 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
160 * @xid: card identification (ASCII string)
163 * @card_ret: the pointer to store the created card instance
175 struct snd_card *card; in snd_card_new() local
184 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); in snd_card_new()
185 if (!card) in snd_card_new()
188 err = snd_card_init(card, parent, idx, xid, module, extra_size); in snd_card_new()
190 return err; /* card is freed by error handler */ in snd_card_new()
192 *card_ret = card; in snd_card_new()
205 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
206 * @xid: card identification (ASCII string)
209 * @card_ret: the pointer to store the created card instance
220 * there have been other devres resources, you'd need to free the card manually
231 struct snd_card *card; in snd_devm_card_new() local
235 card = devres_alloc(__snd_card_release, sizeof(*card) + extra_size, in snd_devm_card_new()
237 if (!card) in snd_devm_card_new()
239 card->managed = true; in snd_devm_card_new()
240 err = snd_card_init(card, parent, idx, xid, module, extra_size); in snd_devm_card_new()
242 devres_free(card); /* in managed mode, we need to free manually */ in snd_devm_card_new()
246 devres_add(parent, card); in snd_devm_card_new()
247 *card_ret = card; in snd_devm_card_new()
265 struct snd_card *card; in snd_card_free_on_error() local
269 card = devres_find(dev, __snd_card_release, NULL, NULL); in snd_card_free_on_error()
270 if (card) in snd_card_free_on_error()
271 snd_card_free(card); in snd_card_free_on_error()
276 static int snd_card_init(struct snd_card *card, struct device *parent, in snd_card_init() argument
283 card->private_data = (char *)card + sizeof(struct snd_card); in snd_card_init()
285 strscpy(card->id, xid, sizeof(card->id)); in snd_card_init()
308 if (!card->managed) in snd_card_init()
309 kfree(card); /* manually free here, as no destructor called */ in snd_card_init()
312 card->dev = parent; in snd_card_init()
313 card->number = idx; in snd_card_init()
315 card->module = module; in snd_card_init()
316 INIT_LIST_HEAD(&card->devices); in snd_card_init()
317 init_rwsem(&card->controls_rwsem); in snd_card_init()
318 rwlock_init(&card->controls_rwlock); in snd_card_init()
319 INIT_LIST_HEAD(&card->controls); in snd_card_init()
320 INIT_LIST_HEAD(&card->ctl_files); in snd_card_init()
322 xa_init(&card->ctl_numids); in snd_card_init()
323 xa_init(&card->ctl_hash); in snd_card_init()
325 spin_lock_init(&card->files_lock); in snd_card_init()
326 INIT_LIST_HEAD(&card->files_list); in snd_card_init()
327 mutex_init(&card->memory_mutex); in snd_card_init()
329 init_waitqueue_head(&card->power_sleep); in snd_card_init()
330 init_waitqueue_head(&card->power_ref_sleep); in snd_card_init()
331 atomic_set(&card->power_ref, 0); in snd_card_init()
333 init_waitqueue_head(&card->remove_sleep); in snd_card_init()
334 card->sync_irq = -1; in snd_card_init()
336 device_initialize(&card->card_dev); in snd_card_init()
337 card->card_dev.parent = parent; in snd_card_init()
338 card->card_dev.class = &sound_class; in snd_card_init()
339 card->card_dev.release = release_card_device; in snd_card_init()
340 card->card_dev.groups = card->dev_groups; in snd_card_init()
341 card->dev_groups[0] = &card_dev_attr_group; in snd_card_init()
342 err = kobject_set_name(&card->card_dev.kobj, "card%d", idx); in snd_card_init()
346 snprintf(card->irq_descr, sizeof(card->irq_descr), "%s:%s", in snd_card_init()
347 dev_driver_string(card->dev), dev_name(&card->card_dev)); in snd_card_init()
351 err = snd_ctl_create(card); in snd_card_init()
356 err = snd_info_card_create(card); in snd_card_init()
358 dev_err(parent, "unable to create card info\n"); in snd_card_init()
363 card->debugfs_root = debugfs_create_dir(dev_name(&card->card_dev), in snd_card_init()
369 snd_device_free_all(card); in snd_card_init()
371 put_device(&card->card_dev); in snd_card_init()
376 * snd_card_ref - Get the card object from the index
377 * @idx: the card index
379 * Returns a card object corresponding to the given index or NULL if not found.
382 * Return: a card object or NULL
386 struct snd_card *card; in snd_card_ref() local
389 card = snd_cards[idx]; in snd_card_ref()
390 if (card) in snd_card_ref()
391 get_device(&card->card_dev); in snd_card_ref()
392 return card; in snd_card_ref()
396 /* return non-zero if a card is already locked */
397 int snd_card_locked(int card) in snd_card_locked() argument
400 return test_bit(card, snd_cards_lock); in snd_card_locked()
482 * @card: soundcard structure
491 void snd_card_disconnect(struct snd_card *card) in snd_card_disconnect() argument
495 if (!card) in snd_card_disconnect()
498 scoped_guard(spinlock, &card->files_lock) { in snd_card_disconnect()
499 if (card->shutdown) in snd_card_disconnect()
501 card->shutdown = 1; in snd_card_disconnect()
504 list_for_each_entry(mfile, &card->files_list, list) { in snd_card_disconnect()
522 wake_up_all(&card->power_sleep); in snd_card_disconnect()
530 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT); in snd_card_disconnect()
534 snd_device_disconnect_all(card); in snd_card_disconnect()
536 if (card->sync_irq > 0) in snd_card_disconnect()
537 synchronize_irq(card->sync_irq); in snd_card_disconnect()
539 snd_info_card_disconnect(card); in snd_card_disconnect()
541 debugfs_remove(card->debugfs_root); in snd_card_disconnect()
542 card->debugfs_root = NULL; in snd_card_disconnect()
545 if (card->registered) { in snd_card_disconnect()
546 device_del(&card->card_dev); in snd_card_disconnect()
547 card->registered = false; in snd_card_disconnect()
552 snd_cards[card->number] = NULL; in snd_card_disconnect()
553 clear_bit(card->number, snd_cards_lock); in snd_card_disconnect()
556 snd_power_sync_ref(card); in snd_card_disconnect()
561 * snd_card_disconnect_sync - disconnect card and wait until files get closed
562 * @card: card object to disconnect
569 void snd_card_disconnect_sync(struct snd_card *card) in snd_card_disconnect_sync() argument
571 snd_card_disconnect(card); in snd_card_disconnect_sync()
573 guard(spinlock_irq)(&card->files_lock); in snd_card_disconnect_sync()
574 wait_event_lock_irq(card->remove_sleep, in snd_card_disconnect_sync()
575 list_empty(&card->files_list), in snd_card_disconnect_sync()
576 card->files_lock); in snd_card_disconnect_sync()
580 static int snd_card_do_free(struct snd_card *card) in snd_card_do_free() argument
582 card->releasing = true; in snd_card_do_free()
585 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); in snd_card_do_free()
587 snd_device_free_all(card); in snd_card_do_free()
588 if (card->private_free) in snd_card_do_free()
589 card->private_free(card); in snd_card_do_free()
590 if (snd_info_card_free(card) < 0) { in snd_card_do_free()
591 dev_warn(card->dev, "unable to free card info\n"); in snd_card_do_free()
594 if (card->release_completion) in snd_card_do_free()
595 complete(card->release_completion); in snd_card_do_free()
596 if (!card->managed) in snd_card_do_free()
597 kfree(card); in snd_card_do_free()
602 * snd_card_free_when_closed - Disconnect the card, free it later eventually
603 * @card: soundcard structure
605 * Unlike snd_card_free(), this function doesn't try to release the card
606 * resource immediately, but tries to disconnect at first. When the card
608 * The card resources will be freed when the refcount gets to zero.
612 void snd_card_free_when_closed(struct snd_card *card) in snd_card_free_when_closed() argument
614 if (!card) in snd_card_free_when_closed()
617 snd_card_disconnect(card); in snd_card_free_when_closed()
618 put_device(&card->card_dev); in snd_card_free_when_closed()
625 * @card: soundcard structure
636 void snd_card_free(struct snd_card *card) in snd_card_free() argument
646 if (card->releasing) in snd_card_free()
649 card->release_completion = &released; in snd_card_free()
650 snd_card_free_when_closed(card); in snd_card_free()
676 /* return true if the given id string doesn't conflict any other card ids */
677 static bool card_id_ok(struct snd_card *card, const char *id) in card_id_ok() argument
683 if (snd_cards[i] && snd_cards[i] != card && in card_id_ok()
690 /* copy to card->id only with valid letters from nid */
691 static void copy_valid_id_string(struct snd_card *card, const char *src, in copy_valid_id_string() argument
694 char *id = card->id; in copy_valid_id_string()
700 while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) { in copy_valid_id_string()
708 /* Set card->id from the given string
711 static void snd_card_set_id_no_lock(struct snd_card *card, const char *src, in snd_card_set_id_no_lock() argument
718 copy_valid_id_string(card, src, nid); in snd_card_set_id_no_lock()
719 id = card->id; in snd_card_set_id_no_lock()
723 * ("card" conflicts with proc directories) in snd_card_set_id_no_lock()
725 if (!*id || !strncmp(id, "card", 4)) { in snd_card_set_id_no_lock()
736 if (card_id_ok(card, id)) in snd_card_set_id_no_lock()
742 if (len + sfxlen >= sizeof(card->id)) in snd_card_set_id_no_lock()
743 spos = id + sizeof(card->id) - sfxlen - 1; in snd_card_set_id_no_lock()
754 dev_err(card->dev, "unable to set card id (%s)\n", id); in snd_card_set_id_no_lock()
755 if (card->proc_root->name) in snd_card_set_id_no_lock()
756 strscpy(card->id, card->proc_root->name, sizeof(card->id)); in snd_card_set_id_no_lock()
760 * snd_card_set_id - set card identification name
761 * @card: soundcard structure
764 * This function sets the card identification and checks for name
767 void snd_card_set_id(struct snd_card *card, const char *nid) in snd_card_set_id() argument
769 /* check if user specified own card->id */ in snd_card_set_id()
770 if (card->id[0] != '\0') in snd_card_set_id()
773 snd_card_set_id_no_lock(card, nid, nid); in snd_card_set_id()
780 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in id_show() local
781 return sysfs_emit(buf, "%s\n", card->id); in id_show()
787 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in id_store() local
788 char buf1[sizeof(card->id)]; in id_store()
789 size_t copy = count > sizeof(card->id) - 1 ? in id_store()
790 sizeof(card->id) - 1 : count; in id_store()
804 strcpy(card->id, buf1); in id_store()
805 snd_info_card_id_change(card); in id_store()
815 struct snd_card *card = container_of(dev, struct snd_card, card_dev); in number_show() local
816 return sysfs_emit(buf, "%i\n", card->number); in number_show()
832 * snd_card_add_dev_attr - Append a new sysfs attribute group to card
833 * @card: card instance
838 int snd_card_add_dev_attr(struct snd_card *card, in snd_card_add_dev_attr() argument
844 for (i = 0; i < ARRAY_SIZE(card->dev_groups) - 1; i++) { in snd_card_add_dev_attr()
845 if (!card->dev_groups[i]) { in snd_card_add_dev_attr()
846 card->dev_groups[i] = group; in snd_card_add_dev_attr()
851 dev_err(card->dev, "Too many groups assigned\n"); in snd_card_add_dev_attr()
863 * @card: soundcard structure
868 * of the initialization of the card.
872 int snd_card_register(struct snd_card *card) in snd_card_register() argument
876 if (snd_BUG_ON(!card)) in snd_card_register()
879 if (!card->registered) { in snd_card_register()
880 err = device_add(&card->card_dev); in snd_card_register()
883 card->registered = true; in snd_card_register()
885 if (card->managed) in snd_card_register()
886 devm_remove_action(card->dev, trigger_card_free, card); in snd_card_register()
889 if (card->managed) { in snd_card_register()
890 err = devm_add_action(card->dev, trigger_card_free, card); in snd_card_register()
895 err = snd_device_register_all(card); in snd_card_register()
899 if (snd_cards[card->number]) { in snd_card_register()
901 return snd_info_card_register(card); /* register pending info */ in snd_card_register()
903 if (*card->id) { in snd_card_register()
905 char tmpid[sizeof(card->id)]; in snd_card_register()
907 memcpy(tmpid, card->id, sizeof(card->id)); in snd_card_register()
908 snd_card_set_id_no_lock(card, tmpid, tmpid); in snd_card_register()
913 src = *card->shortname ? card->shortname : card->longname; in snd_card_register()
914 snd_card_set_id_no_lock(card, src, in snd_card_register()
917 snd_cards[card->number] = card; in snd_card_register()
919 err = snd_info_card_register(card); in snd_card_register()
925 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); in snd_card_register()
936 struct snd_card *card; in snd_card_info_read() local
940 card = snd_cards[idx]; in snd_card_info_read()
941 if (card) { in snd_card_info_read()
945 card->id, in snd_card_info_read()
946 card->driver, in snd_card_info_read()
947 card->shortname); in snd_card_info_read()
949 card->longname); in snd_card_info_read()
960 struct snd_card *card; in snd_card_info_read_oss() local
964 card = snd_cards[idx]; in snd_card_info_read_oss()
965 if (card) { in snd_card_info_read_oss()
967 snd_iprintf(buffer, "%s\n", card->longname); in snd_card_info_read_oss()
982 struct snd_card *card; in snd_card_module_info_read() local
986 card = snd_cards[idx]; in snd_card_module_info_read()
987 if (card) in snd_card_module_info_read()
989 idx, card->module->name); in snd_card_module_info_read()
1020 * @card: soundcard structure
1029 int snd_component_add(struct snd_card *card, const char *component) in snd_component_add() argument
1034 ptr = strstr(card->components, component); in snd_component_add()
1039 if (strlen(card->components) + 1 + len + 1 > sizeof(card->components)) { in snd_component_add()
1043 if (card->components[0] != '\0') in snd_component_add()
1044 strcat(card->components, " "); in snd_component_add()
1045 strcat(card->components, component); in snd_component_add()
1051 * snd_card_file_add - add the file to the file list of the card
1052 * @card: soundcard structure
1055 * This function adds the file to the file linked-list of the card.
1061 int snd_card_file_add(struct snd_card *card, struct file *file) in snd_card_file_add() argument
1071 guard(spinlock)(&card->files_lock); in snd_card_file_add()
1072 if (card->shutdown) { in snd_card_file_add()
1076 list_add(&mfile->list, &card->files_list); in snd_card_file_add()
1077 get_device(&card->card_dev); in snd_card_file_add()
1084 * @card: soundcard structure
1087 * This function removes the file formerly added to the card via
1095 int snd_card_file_remove(struct snd_card *card, struct file *file) in snd_card_file_remove() argument
1099 scoped_guard(spinlock, &card->files_lock) { in snd_card_file_remove()
1100 list_for_each_entry(mfile, &card->files_list, list) { in snd_card_file_remove()
1111 if (list_empty(&card->files_list)) in snd_card_file_remove()
1112 wake_up_all(&card->remove_sleep); in snd_card_file_remove()
1115 dev_err(card->dev, "card file remove problem (%p)\n", file); in snd_card_file_remove()
1119 put_device(&card->card_dev); in snd_card_file_remove()
1126 * snd_power_ref_and_wait - wait until the card gets powered up
1127 * @card: soundcard structure
1129 * Take the power_ref reference count of the given card, and
1130 * wait until the card gets powered up to SNDRV_CTL_POWER_D0 state.
1140 int snd_power_ref_and_wait(struct snd_card *card) in snd_power_ref_and_wait() argument
1142 snd_power_ref(card); in snd_power_ref_and_wait()
1143 if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) in snd_power_ref_and_wait()
1145 wait_event_cmd(card->power_sleep, in snd_power_ref_and_wait()
1146 card->shutdown || in snd_power_ref_and_wait()
1147 snd_power_get_state(card) == SNDRV_CTL_POWER_D0, in snd_power_ref_and_wait()
1148 snd_power_unref(card), snd_power_ref(card)); in snd_power_ref_and_wait()
1149 return card->shutdown ? -ENODEV : 0; in snd_power_ref_and_wait()
1154 * snd_power_wait - wait until the card gets powered up (old form)
1155 * @card: soundcard structure
1157 * Wait until the card gets powered up to SNDRV_CTL_POWER_D0 state.
1161 int snd_power_wait(struct snd_card *card) in snd_power_wait() argument
1165 ret = snd_power_ref_and_wait(card); in snd_power_wait()
1166 snd_power_unref(card); in snd_power_wait()