ASoC: SDCA: Remove sdca_function_data duplication

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>
This commit is contained in:
Charles Keepax 2026-04-30 16:09:30 +01:00 committed by Mark Brown
parent cb3c257e08
commit df036250d7
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
6 changed files with 18 additions and 45 deletions

View 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);

View 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

View File

@ -183,7 +183,6 @@ static void class_boot_work(struct work_struct *work)
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);

View 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;

View 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;

View 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;