]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: SDCA: Support devices with multiple functions of identical type
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Thu, 30 Apr 2026 15:09:31 +0000 (16:09 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 4 May 2026 13:24:42 +0000 (22:24 +0900)
It is possible that SDCAs devices might have multiple functions of
the same type, as the entity names within a function are defined by
the specification it is very likely such a device will have duplicate
entities. This causes problems where DAIs and ALSA controls end up
with clashing names.

This can be handled by adding the function address into the names to
ensure uniqueness, although, ideally this would have been included from
the start. User-space already has UCM using the current control names,
so as a compromise the first function of a given type will use the
raw entity names, then duplicates will get an added function address.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260430150931.2025953-4-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/sdca.h
sound/soc/sdca/sdca_functions.c
sound/soc/sdca/sdca_interrupts.c

index 67ff3c88705d5e0fcb18e7454c747a4df1b2ef3a..2bdf4e333e0449d6192a27617b0b3c82317186f2 100644 (file)
@@ -26,6 +26,8 @@ struct sdca_dev;
  * @name: Human-readable string.
  * @type: Function topology type.
  * @adr: ACPI address (used for SDCA register access).
+ * @duplicate: Internal flag to indicate if other functions of the same type
+ * exist.
  */
 struct sdca_function_desc {
        struct fwnode_handle *node;
@@ -33,6 +35,8 @@ struct sdca_function_desc {
        const char *name;
        u32 type;
        u8 adr;
+
+       bool duplicate;
 };
 
 /**
index 02abb7315b7272bd7542a20ba3fc1ee3b37a419d..77940bd6b33c95d1151d1b0ec964146a2a766ea6 100644 (file)
@@ -98,7 +98,7 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
        u32 function_type;
        int function_index;
        u64 addr;
-       int ret;
+       int i, ret;
 
        if (sdca_data->num_functions >= SDCA_MAX_FUNCTION_COUNT) {
                dev_err(dev, "maximum number of functions exceeded\n");
@@ -159,6 +159,14 @@ static int find_sdca_function(struct acpi_device *adev, void *data)
 
        /* store results */
        function_index = sdca_data->num_functions;
+
+       for (i = 0; i < function_index; i++) {
+               if (sdca_data->function[i].type == function_type) {
+                       sdca_data->function[function_index].duplicate = true;
+                       break;
+               }
+       }
+
        sdca_data->function[function_index].adr = addr;
        sdca_data->function[function_index].type = function_type;
        sdca_data->function[function_index].name = function_name;
@@ -1466,6 +1474,7 @@ static int find_sdca_entity_xu(struct device *dev,
 }
 
 static int find_sdca_entity(struct device *dev, struct sdw_slave *sdw,
+                           struct sdca_function_data *function,
                            struct fwnode_handle *function_node,
                            struct fwnode_handle *entity_node,
                            struct sdca_entity *entity)
@@ -1481,6 +1490,13 @@ static int find_sdca_entity(struct device *dev, struct sdw_slave *sdw,
                return ret;
        }
 
+       if (function->desc->duplicate) {
+               entity->label = devm_kasprintf(dev, GFP_KERNEL, "%d %s",
+                                              function->desc->adr, entity->label);
+               if (!entity->label)
+                       return -ENOMEM;
+       }
+
        ret = fwnode_property_read_u32(entity_node, "mipi-sdca-entity-type", &tmp);
        if (ret) {
                dev_err(dev, "%s: type missing: %d\n", entity->label, ret);
@@ -1578,7 +1594,7 @@ static int find_sdca_entities(struct device *dev, struct sdw_slave *sdw,
                        return -EINVAL;
                }
 
-               ret = find_sdca_entity(dev, sdw, function_node,
+               ret = find_sdca_entity(dev, sdw, function, function_node,
                                       entity_node, &entities[i]);
                fwnode_handle_put(entity_node);
                if (ret)
@@ -1605,8 +1621,14 @@ static struct sdca_entity *find_sdca_entity_by_label(struct sdca_function_data *
                                                     const char *entity_label)
 {
        struct sdca_entity *entity = NULL;
+       char tmp[64];
        int i;
 
+       if (function->desc->duplicate) {
+               snprintf(tmp, sizeof(tmp), "%d %s", function->desc->adr, entity_label);
+               entity_label = tmp;
+       }
+
        for (i = 0; i < function->num_entities; i++) {
                entity = &function->entities[i];
 
index 6e10b4e660d96bc3a98bbbbc9d804eac21fadb2b..4539a52a8e32ba4a83929e9790ebbf7b246a4d4a 100644 (file)
@@ -375,8 +375,7 @@ int sdca_irq_data_populate(struct device *dev, struct regmap *regmap,
        if (!dev)
                return -ENODEV;
 
-       name = kasprintf(GFP_KERNEL, "%s %s %s", function->desc->name,
-                        entity->label, control->label);
+       name = kasprintf(GFP_KERNEL, "%s %s", entity->label, control->label);
        if (!name)
                return -ENOMEM;