Lines Matching +full:loop +full:- +full:powered

1 // SPDX-License-Identifier: GPL-2.0-or-later
47 /* return non-zero if the given index is reserved for the given
56 if (!module || !*module->name || !slots[idx]) in module_slot_match()
59 s1 = module->name; in module_slot_match()
71 if (c1 == '-') in module_slot_match()
73 if (c2 == '-') in module_slot_match()
95 * @mask == -1 == 0xffffffff means: take any free slot up to 32
123 * snd_device_initialize - Initialize struct device for sound devices
131 dev->parent = &card->card_dev; in snd_device_initialize()
132 dev->class = sound_class; in snd_device_initialize()
133 dev->release = default_release; in snd_device_initialize()
149 * snd_card_new - create and initialize a soundcard structure
151 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
171 return -EINVAL; in snd_card_new()
178 return -ENOMEM; in snd_card_new()
195 * snd_devm_card_new - managed snd_card object creation
197 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
230 return -ENOMEM; in snd_devm_card_new()
231 card->managed = true; in snd_devm_card_new()
245 * snd_card_free_on_error - a small helper for handling devm probe errors
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()
283 if (idx < 0) /* first check the matching module-name slot */ in snd_card_init()
288 err = -ENODEV; in snd_card_init()
291 err = -EBUSY; /* invalid */ in snd_card_init()
293 err = -ENODEV; in snd_card_init()
296 dev_err(parent, "cannot find the slot for index %d (range 0-%i), error: %d\n", in snd_card_init()
297 idx, snd_ecards_limit - 1, err); in snd_card_init()
298 if (!card->managed) 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()
360 card->debugfs_root = debugfs_create_dir(name, sound_debugfs_root); in snd_card_init()
367 put_device(&card->card_dev); in snd_card_init()
372 * snd_card_ref - Get the card object from the index
387 get_device(&card->card_dev); in snd_card_ref()
393 /* return non-zero if a card is already locked */
406 return -ENODEV; in snd_disconnect_llseek()
412 return -ENODEV; in snd_disconnect_read()
418 return -ENODEV; in snd_disconnect_write()
427 if (_df->file == file) { in snd_disconnect_release()
429 list_del_init(&df->shutdown_list); in snd_disconnect_release()
436 if ((file->f_flags & FASYNC) && df->disconnected_f_op->fasync) in snd_disconnect_release()
437 df->disconnected_f_op->fasync(-1, file, 0); in snd_disconnect_release()
438 return df->disconnected_f_op->release(inode, file); in snd_disconnect_release()
452 return -ENODEV; in snd_disconnect_ioctl()
457 return -ENODEV; in snd_disconnect_mmap()
462 return -ENODEV; in snd_disconnect_fasync()
482 * snd_card_disconnect - disconnect all APIs from the file-operations (user space)
485 * Disconnects all APIs from the file-operations (user space).
489 * Note: The current implementation replaces all active file->f_op with special
497 return -EINVAL; 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()
506 /* replace file->f_op with special dummy operations */ in snd_card_disconnect()
507 list_for_each_entry(mfile, &card->files_list, list) { in snd_card_disconnect()
508 /* it's critical part, use endless loop */ in snd_card_disconnect()
510 mfile->disconnected_f_op = mfile->file->f_op; in snd_card_disconnect()
513 list_add(&mfile->shutdown_list, &shutdown_files); in snd_card_disconnect()
516 mfile->file->f_op = &snd_shutdown_f_ops; in snd_card_disconnect()
517 fops_get(mfile->file->f_op); in snd_card_disconnect()
519 spin_unlock(&card->files_lock); in snd_card_disconnect()
532 if (card->sync_irq > 0) in snd_card_disconnect()
533 synchronize_irq(card->sync_irq); 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()
556 * snd_card_disconnect_sync - disconnect card and wait until files get closed
561 * It assures that all accesses from user-space finished so that the driver
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()
586 card->releasing = true; 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()
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()
610 * snd_card_free_when_closed - Disconnect the card, free it later eventually
625 put_device(&card->card_dev); in snd_card_free_when_closed()
631 * snd_card_free - frees given soundcard structure
650 * we need to avoid double-free. Moreover, the release via devres in snd_card_free()
654 if (card->releasing) in snd_card_free()
657 card->release_completion = &released; in snd_card_free()
689 !strcmp(snd_cards[i]->id, id)) in card_id_ok()
695 /* copy to card->id only with valid letters from nid */
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()
713 /* Set card->id from the given string
724 id = 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()
765 * snd_card_set_id - set card identification name
774 /* check if user specified own card->id */ in snd_card_set_id()
775 if (card->id[0] != '\0') in snd_card_set_id()
787 return sysfs_emit(buf, "%s\n", card->id); in id_show()
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()
802 if (!isalnum(c) && c != '_' && c != '-') in id_store()
803 return -EINVAL; in id_store()
810 return -EEXIST; in id_store()
812 strcpy(card->id, buf1); in id_store()
825 return sysfs_emit(buf, "%i\n", card->number); in number_show()
841 * snd_card_add_dev_attr - Append a new sysfs attribute group to card
852 /* loop for (arraysize-1) here to keep NULL at the last entry */ in snd_card_add_dev_attr()
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()
861 return -ENOSPC; in snd_card_add_dev_attr()
871 * snd_card_register - register the soundcard
886 return -EINVAL; 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()
908 if (snd_cards[card->number]) { 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()
921 src = *card->shortname ? card->shortname : card->longname; in snd_card_register()
925 snd_cards[card->number] = card; in snd_card_register()
951 snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n", 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()
962 snd_iprintf(buffer, "--- no soundcards ---\n"); in snd_card_info_read()
976 snd_iprintf(buffer, "%s\n", card->longname); in snd_card_info_read_oss()
981 snd_iprintf(buffer, "--- no soundcards ---\n"); in snd_card_info_read_oss()
999 idx, card->module->name); in snd_card_module_info_read()
1011 return -ENOMEM; in snd_card_info_init()
1012 entry->c.text.read = snd_card_info_read; in snd_card_info_init()
1014 return -ENOMEM; /* freed in error path */ in snd_card_info_init()
1019 return -ENOMEM; in snd_card_info_init()
1020 entry->c.text.read = snd_card_module_info_read; in snd_card_info_init()
1022 return -ENOMEM; /* freed in error path */ in snd_card_info_init()
1030 * snd_component_add - add a component string
1035 * The component can be referred from the alsa-lib.
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()
1052 return -ENOMEM; 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()
1062 * snd_card_file_add - add the file to the file list of the card
1066 * This function adds the file to the file linked-list of the card.
1067 * This linked-list is used to keep tracking the connection state,
1078 return -ENOMEM; in snd_card_file_add()
1079 mfile->file = file; in snd_card_file_add()
1080 mfile->disconnected_f_op = NULL; in snd_card_file_add()
1081 INIT_LIST_HEAD(&mfile->shutdown_list); in snd_card_file_add()
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()
1086 return -ENODEV; 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()
1096 * snd_card_file_remove - remove the file from the file list
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()
1114 if (mfile->file == file) { in snd_card_file_remove()
1115 list_del(&mfile->list); in snd_card_file_remove()
1117 list_del(&mfile->shutdown_list); in snd_card_file_remove()
1119 if (mfile->disconnected_f_op) in snd_card_file_remove()
1120 fops_put(mfile->disconnected_f_op); 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()
1130 return -ENOENT; in snd_card_file_remove()
1133 put_device(&card->card_dev); in snd_card_file_remove()
1140 * snd_power_ref_and_wait - wait until the card gets powered up
1144 * wait until the card gets powered up to SNDRV_CTL_POWER_D0 state.
1145 * The refcount is down again while sleeping until power-up, hence this
1159 wait_event_cmd(card->power_sleep, in snd_power_ref_and_wait()
1160 card->shutdown || in snd_power_ref_and_wait()
1163 return card->shutdown ? -ENODEV : 0; in snd_power_ref_and_wait()
1168 * snd_power_wait - wait until the card gets powered up (old form)
1171 * Wait until the card gets powered up to SNDRV_CTL_POWER_D0 state.