]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: SDCA: Remove sdca_function_data duplication
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Thu, 30 Apr 2026 15:09:30 +0000 (16:09 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 4 May 2026 13:24:41 +0000 (22:24 +0900)
The class driver internally has an array of sdca_function_data pointers
that it uses to store the parsed DisCo data. However, there is already
an sdca_function_data attached to the auxdev device. It makes more sense
to use the one already provided in the auxdev device, as it could also
be used by custom drivers for parts that require those.

Using the auxdev copy also prevents the need for the class function
drivers to search through the array for the correct data, which
currently is based off matching the function type. This has problems
when two functions have the same type as the current code will find the
same data for both drivers, using the auxdev copy of the data avoids
this problem.

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-3-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/sdca_function.h
sound/soc/codecs/tas2783-sdw.c
sound/soc/sdca/sdca_class.c
sound/soc/sdca/sdca_class.h
sound/soc/sdca/sdca_class_function.c
sound/soc/sdca/sdca_functions.c

index 0e871c786513f671383a6d20a4a3bb5179a6c8e8..b1489178b0ef897cd944306f1d7e9ed676a441f6 100644 (file)
@@ -1452,7 +1452,6 @@ static inline u32 sdca_range_search(struct sdca_control_range *range,
 }
 
 int sdca_parse_function(struct device *dev, struct sdw_slave *sdw,
-                       struct sdca_function_desc *desc,
                        struct sdca_function_data *function);
 
 const char *sdca_find_terminal_name(enum sdca_terminal_type type);
index 90008d2d06e2c77dc3b8b5c71ca99c418cd3412f..38009168c5a114847b82f7a30aa2dafed5409058 100644 (file)
@@ -1310,10 +1310,10 @@ static s32 tas_sdw_probe(struct sdw_slave *peripheral,
                        return dev_err_probe(dev, -ENOMEM,
                                             "failed to parse sdca functions");
 
+               function_data->desc = &peripheral->sdca_data.function[i];
+
                /* Parse the function */
-               ret = sdca_parse_function(dev, peripheral,
-                                         &peripheral->sdca_data.function[i],
-                                         function_data);
+               ret = sdca_parse_function(dev, peripheral, function_data);
                if (!ret)
                        tas_dev->sa_func_data = function_data;
                else
index 6e9b66f718019162a3f1d54002292fbba25d8acc..a6a3da8de4371a9f58e0ebaa4ef2cff3dd41a2d3 100644 (file)
@@ -183,7 +183,6 @@ err:
 static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id)
 {
        struct device *dev = &sdw->dev;
-       struct sdca_device_data *data = &sdw->sdca_data;
        struct regmap_config *dev_config;
        struct sdca_class_drv *drv;
        int ret;
@@ -199,12 +198,6 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id
        if (!dev_config)
                return -ENOMEM;
 
-       drv->functions = devm_kcalloc(dev, data->num_functions,
-                                     sizeof(*drv->functions),
-                                     GFP_KERNEL);
-       if (!drv->functions)
-               return -ENOMEM;
-
        drv->dev = dev;
        drv->sdw = sdw;
        mutex_init(&drv->regmap_lock);
index 6f24ea2bbd381723d16986c38895873e52e0fe0a..8b63e62485e6476966cab147e4b5190b06d265a3 100644 (file)
@@ -24,7 +24,6 @@ struct sdca_class_drv {
        struct regmap *dev_regmap;
        struct sdw_slave *sdw;
 
-       struct sdca_function_data *functions;
        struct sdca_interrupt_info *irq_info;
 
        struct mutex regmap_lock;
index 31fc08d513077279805408f6d1db2487f8241d48..1496a15f7d2ac7d5e22ab3605be9af6012931c10 100644 (file)
@@ -27,6 +27,7 @@
 #include <sound/soc-dai.h>
 #include <sound/soc.h>
 #include "sdca_class.h"
+#include "sdca_function_device.h"
 
 struct class_function_drv {
        struct device *dev;
@@ -294,8 +295,7 @@ static int class_function_probe(struct auxiliary_device *auxdev,
 {
        struct device *dev = &auxdev->dev;
        struct sdca_class_drv *core = dev_get_drvdata(dev->parent);
-       struct sdca_device_data *data = &core->sdw->sdca_data;
-       struct sdca_function_desc *desc;
+       struct sdca_dev *sdev = auxiliary_dev_to_sdca_dev(auxdev);
        struct snd_soc_component_driver *cmp_drv;
        struct snd_soc_dai_driver *dais;
        struct class_function_drv *drv;
@@ -305,7 +305,6 @@ static int class_function_probe(struct auxiliary_device *auxdev,
        int ndefaults;
        int num_dais;
        int ret;
-       int i;
 
        drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
        if (!drv)
@@ -328,21 +327,9 @@ static int class_function_probe(struct auxiliary_device *auxdev,
 
        drv->dev = dev;
        drv->core = core;
+       drv->function = &sdev->function;
 
-       for (i = 0; i < data->num_functions; i++) {
-               desc = &data->function[i];
-
-               if (desc->type == aux_dev_id->driver_data)
-                       break;
-       }
-       if (i == core->sdw->sdca_data.num_functions) {
-               dev_err(dev, "failed to locate function\n");
-               return -EINVAL;
-       }
-
-       drv->function = &core->functions[i];
-
-       ret = sdca_parse_function(dev, core->sdw, desc, drv->function);
+       ret = sdca_parse_function(dev, core->sdw, drv->function);
        if (ret)
                return ret;
 
@@ -377,7 +364,7 @@ static int class_function_probe(struct auxiliary_device *auxdev,
                return dev_err_probe(dev, PTR_ERR(drv->regmap),
                                     "failed to create regmap");
 
-       switch (desc->type) {
+       switch (drv->function->desc->type) {
        case SDCA_FUNCTION_TYPE_UAJ:
        case SDCA_FUNCTION_TYPE_RJ:
                cmp_drv->set_jack = class_function_set_jack;
index 196bade11ab5dd4e7ee87b7e1b098726d1ac92ef..02abb7315b7272bd7542a20ba3fc1ee3b37a419d 100644 (file)
@@ -2158,27 +2158,22 @@ static int find_sdca_filesets(struct device *dev, struct sdw_slave *sdw,
  * sdca_parse_function - parse ACPI DisCo for a Function
  * @dev: Pointer to device against which function data will be allocated.
  * @sdw: SoundWire slave device to be processed.
- * @function_desc: Pointer to the Function short descriptor.
  * @function: Pointer to the Function information, to be populated.
  *
  * Return: Returns 0 for success.
  */
 int sdca_parse_function(struct device *dev, struct sdw_slave *sdw,
-                       struct sdca_function_desc *function_desc,
                        struct sdca_function_data *function)
 {
+       struct fwnode_handle *node = function->desc->node;
        u32 tmp;
        int ret;
 
-       function->desc = function_desc;
-
-       ret = fwnode_property_read_u32(function_desc->node,
-                                      "mipi-sdca-function-busy-max-delay", &tmp);
+       ret = fwnode_property_read_u32(node, "mipi-sdca-function-busy-max-delay", &tmp);
        if (!ret)
                function->busy_max_delay = tmp;
 
-       ret = fwnode_property_read_u32(function_desc->node,
-                                      "mipi-sdca-function-reset-max-delay", &tmp);
+       ret = fwnode_property_read_u32(node, "mipi-sdca-function-reset-max-delay", &tmp);
        if (ret || tmp == 0) {
                dev_dbg(dev, "reset delay missing, defaulting to 100mS\n");
                function->reset_max_delay = 100000;
@@ -2187,26 +2182,26 @@ int sdca_parse_function(struct device *dev, struct sdw_slave *sdw,
        }
 
        dev_dbg(dev, "%pfwP: name %s busy delay %dus reset delay %dus\n",
-               function->desc->node, function->desc->name,
-               function->busy_max_delay, function->reset_max_delay);
+               node, function->desc->name, function->busy_max_delay,
+               function->reset_max_delay);
 
-       ret = find_sdca_init_table(dev, function_desc->node, function);
+       ret = find_sdca_init_table(dev, node, function);
        if (ret)
                return ret;
 
-       ret = find_sdca_entities(dev, sdw, function_desc->node, function);
+       ret = find_sdca_entities(dev, sdw, node, function);
        if (ret)
                return ret;
 
-       ret = find_sdca_connections(dev, function_desc->node, function);
+       ret = find_sdca_connections(dev, node, function);
        if (ret)
                return ret;
 
-       ret = find_sdca_clusters(dev, function_desc->node, function);
+       ret = find_sdca_clusters(dev, node, function);
        if (ret < 0)
                return ret;
 
-       ret = find_sdca_filesets(dev, sdw, function_desc->node, function);
+       ret = find_sdca_filesets(dev, sdw, node, function);
        if (ret)
                return ret;