* PlaybackSwitch "name='Master Playback Switch',index=2"
* }
* }
+ *
+ * SupportedDevice and ConflictingDevice cannot be specified together.
+ * Both are optional.
*/
static int parse_device_by_name(snd_use_case_mgr_t *uc_mgr,
return -ENOENT;
}
+static bool verb_has_device(struct use_case_verb *verb, const char *name)
+{
+ struct list_head *pos;
+ struct use_case_device *device;
+
+ list_for_each(pos, &verb->device_list) {
+ device = list_entry(pos, struct use_case_device, list);
+ if (strcmp(device->name, name) == 0)
+ return true;
+ }
+ return false;
+}
+
+static int dev_list_resolve_optional(struct use_case_verb *verb,
+ struct dev_list *dev_list)
+{
+ struct list_head *pos, *npos;
+ struct dev_list_node *dlist;
+
+ list_for_each_safe(pos, npos, &dev_list->list) {
+ dlist = list_entry(pos, struct dev_list_node, list);
+ if (dlist->name[0] != '-')
+ continue;
+ if (verb_has_device(verb, dlist->name + 1)) {
+ memmove(dlist->name, dlist->name + 1, strlen(dlist->name));
+ } else {
+ list_del(&dlist->list);
+ free(dlist->name);
+ free(dlist);
+ }
+ }
+
+ return 0;
+}
+
+static int verb_resolve_optional_devices(snd_use_case_mgr_t *uc_mgr,
+ struct use_case_verb *verb)
+{
+ struct list_head *pos;
+ struct use_case_device *device;
+ struct use_case_modifier *modifier;
+ int err;
+
+ if (uc_mgr->conf_format < 10)
+ return 0;
+
+ list_for_each(pos, &verb->device_list) {
+ device = list_entry(pos, struct use_case_device, list);
+ err = dev_list_resolve_optional(verb, &device->dev_list);
+ if (err < 0)
+ return err;
+ }
+ list_for_each(pos, &verb->modifier_list) {
+ modifier = list_entry(pos, struct use_case_modifier, list);
+ err = dev_list_resolve_optional(verb, &modifier->dev_list);
+ if (err < 0)
+ return err;
+ }
+
+ return 0;
+}
+
static int verb_dev_list_check(struct use_case_verb *verb)
{
struct list_head *pos, *pos2, *pos3;
struct ucm_dev_name *dev;
int err;
+ /* resolve optional ('-' prefixed) device references before any rename
+ * or normalization so the kept references are processed like normal ones
+ */
+ err = verb_resolve_optional_devices(uc_mgr, verb);
+ if (err < 0)
+ return err;
+
/* rename devices */
list_for_each(pos, &verb->rename_list) {
dev = list_entry(pos, struct ucm_dev_name, list);
}
~~~
+### Device relationships (SupportedDevice / ConflictingDevice)
+
+A device or modifier may declare its relationship to other devices using the
+*SupportedDevice* and *ConflictingDevice* lists. Only one of the two may be
+specified for a given section; both are optional. The relationships declared for
+a device are automatically made bidirectional and transitive within the verb
+(if A conflicts with B and B conflicts with C, then A, B and C conflict with
+each other).
+
+By default, every name listed in *SupportedDevice* or *ConflictingDevice* must
+refer to an existing device in the verb. A reference to an unknown device aborts
+the configuration parsing with an error.
+
+#### Optional device references (Syntax 10+)
+
+Starting with **Syntax 10**, a device name in a *SupportedDevice* or
+*ConflictingDevice* list may be prefixed with a minus sign ('-') to mark the
+reference as *optional*. If no device with the given name exists in the verb,
+the reference is removed from the list instead of raising an error. The '-'
+prefix only affects error handling; when the referenced device does exist, the
+prefix is dropped and the entry behaves exactly like a normal reference.
+
+This is useful for configuration snippets that are shared between cards or
+layouts where some devices may or may not be present, avoiding the need to
+guard every reference with conditional blocks.
+
+Example - a headset device that conflicts with a speaker that may not exist on
+all models:
+
+~~~{.html}
+SectionDevice."Headset" {
+ ConflictingDevice [
+ "Headphones" # must exist - error if missing
+ "-Speaker" # optional - ignored if the card has no Speaker device
+ ]
+ EnableSequence [
+ ...
+ ]
+}
+~~~
+
### Device Variants
Starting with **Syntax 8**, devices can define variants using the *DeviceVariant* block.