Skip to contentSkip to conversation

ASoC: Fix sdw_utils calling wrong codec init callbacks

PATCH In review Richard Fitzgerald 5 participants 7 messages Jan 12 – Jan 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ASoC: Fix sdw_utils calling wrong codec init callbacks

This series fixes a problem with soc_sdw_utils.c calling the wrong codec init callbacks, because it assumed that the DAI name could be used to uniquely identify the codec. This isn't the case, especially on SDCA which is a generic driver for many parts.

The second patch is the actual fix.
The first patch is needed to add a missing export to SoundWire core.

Richard Fitzgerald (2):
soundwire: Add missing EXPORT for sdw_slave_type
ASoC: sdw_utils: Call init callbacks on the correct codec DAI

 drivers/soundwire/slave.c           |  1 +
 sound/soc/sdw_utils/soc_sdw_utils.c | 43 ++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 soundwire: Add missing EXPORT for sdw_slave_type

include/sdw_type.h provides the function is_sdw_slave() which requires sdw_slave_type. But sdw_slave_type was not exported.

---
 drivers/soundwire/slave.c | 1 +
 1 file changed, 1 insertion(+)
drivers/soundwire/slave.c +1 -0
index 3d4d00188c26..d933cebad52b 100644
@@ -23,6 +23,7 @@ const struct device_type sdw_slave_type = {
 	.release =	sdw_slave_release,
 	.uevent =	sdw_slave_uevent,
 };
+EXPORT_SYMBOL_GPL(sdw_slave_type);
 
 int sdw_slave_add(struct sdw_bus *bus,
 		  struct sdw_slave_id *id, struct fwnode_handle *fwnode)
Signature · 1 line
2.47.3
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] soundwire: Add missing EXPORT for sdw_slave_type

Quoted 2 lines · Richard Fitzgerald

include/sdw_type.h provides the function is_sdw_slave() which requires sdw_slave_type. But sdw_slave_type was not exported.

Signature · 1 line
~Vinod
#3 lore raw

PATCH 2/2 ASoC: sdw_utils: Call init callbacks on the correct codec DAI

In reply to Richard Fitzgerald

asoc_sdw_rtd_init() needs to call the rtd_init() callbacks for each codec in a dailink. It was finding the codecs by looking for the matching DAI name in codec_info_list[] but this isn't correct, because the DAI name isn't guaranteed to be unique. Parts using the same codec driver (so the same DAI names) might require different machine driver setup.

Instead, get the struct sdw_slave and extract the SoundWire part ID. Use this to lookup the entry in codec_info_list[]. This is the same identity info that was used to find the entry when the machine driver created the dailink.

Fixes e377c9477317 ("ASoC: intel/sdw_utils: move soundwire codec_info_list structure")
---
 sound/soc/sdw_utils/soc_sdw_utils.c | 43 ++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
sound/soc/sdw_utils/soc_sdw_utils.c +42 -1
index e4ce952e56aa..6bf81ed132d8 100644
@@ -855,6 +855,19 @@ struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_part(const u64 adr)
 }
 EXPORT_SYMBOL_NS(asoc_sdw_find_codec_info_part, "SND_SOC_SDW_UTILS");
 
+static struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_sdw_id(const struct sdw_slave_id *id)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(codec_info_list); i++)
+		if (id->part_id == codec_info_list[i].part_id &&
+		    (!codec_info_list[i].version_id ||
+		     id->sdw_version == codec_info_list[i].version_id))
+			return &codec_info_list[i];
+
+	return NULL;
+}
+
 struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_acpi(const u8 *acpi_id)
 {
 	int i;
@@ -887,22 +900,46 @@ struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_dai(const char *dai_name, i
 }
 EXPORT_SYMBOL_NS(asoc_sdw_find_codec_info_dai, "SND_SOC_SDW_UTILS");
 
+static int asoc_sdw_find_codec_info_dai_index(const struct asoc_sdw_codec_info *codec_info,
+					      const char *dai_name)
+{
+	int i;
+
+	for (i = 0; i < codec_info->dai_num; i++) {
+		if (!strcmp(codec_info->dais[i].dai_name, dai_name))
+			return i;
+	}
+
+	return -ENOENT;
+}
+
 int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_card *card = rtd->card;
 	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
 	struct asoc_sdw_codec_info *codec_info;
 	struct snd_soc_dai *dai;
+	struct sdw_slave *sdw_peripheral;
 	const char *spk_components="";
 	int dai_index;
 	int ret;
 	int i;
 
 	for_each_rtd_codec_dais(rtd, i, dai) {
-		codec_info = asoc_sdw_find_codec_info_dai(dai->name, &dai_index);
+		if (is_sdw_slave(dai->component->dev))
+			sdw_peripheral = dev_to_sdw_dev(dai->component->dev);
+		else if (dai->component->dev->parent && is_sdw_slave(dai->component->dev->parent))
+			sdw_peripheral = dev_to_sdw_dev(dai->component->dev->parent);
+		else
+			continue;
+
+		codec_info = asoc_sdw_find_codec_info_sdw_id(&sdw_peripheral->id);
 		if (!codec_info)
 			return -EINVAL;
 
+		dai_index = asoc_sdw_find_codec_info_dai_index(codec_info, dai->name);
+		WARN_ON(dai_index < 0);
+
 		/*
 		 * A codec dai can be connected to different dai links for capture and playback,
 		 * but we only need to call the rtd_init function once.
@@ -912,6 +949,10 @@ int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd)
 		if (codec_info->dais[dai_index].rtd_init_done)
 			continue;
 
+		dev_dbg(card->dev, "%#x/%s initializing for %s/%s\n",
+			codec_info->part_id, codec_info->dais[dai_index].dai_name,
+			dai->component->name, dai->name);
+
 		/*
 		 * Add card controls and dapm widgets for the first codec dai.
 		 * The controls and widgets will be used for all codec dais.
Signature · 1 line
2.47.3
Reviewed-by on the v1 series
#4 lore raw
In reply to Richard Fitzgerald
Quoted 8 lines · Richard Fitzgerald

This series fixes a problem with soc_sdw_utils.c calling the wrong codec init callbacks, because it assumed that the DAI name could be used to uniquely identify the codec. This isn't the case, especially on SDCA which is a generic driver for many parts.

The second patch is the actual fix.
The first patch is needed to add a missing export to SoundWire core.

Quoted 7 lines

Richard Fitzgerald (2):
soundwire: Add missing EXPORT for sdw_slave_type
ASoC: sdw_utils: Call init callbacks on the correct codec DAI

 drivers/soundwire/slave.c           |  1 +
 sound/soc/sdw_utils/soc_sdw_utils.c | 43 ++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

Thanks,
Charles

reviewer Reviewed-by
#5 lore raw
Quoted 13 lines · Charles Keepax
Quoted 12 lines · Richard Fitzgerald

This series fixes a problem with soc_sdw_utils.c calling the wrong codec init callbacks, because it assumed that the DAI name could be used to uniquely identify the codec. This isn't the case, especially on SDCA which is a generic driver for many parts.

The second patch is the actual fix.
The first patch is needed to add a missing export to SoundWire core.

Richard Fitzgerald (2):
soundwire: Add missing EXPORT for sdw_slave_type
ASoC: sdw_utils: Call init callbacks on the correct codec DAI

Quoted 5 lines
Quoted 3 lines
 drivers/soundwire/slave.c           |  1 +
 sound/soc/sdw_utils/soc_sdw_utils.c | 43 ++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

It's not obvious from the patchset title that the first patch probably needs Vinod's Acked-by tag

maintainer
#6 lore raw
In reply to Richard Fitzgerald
Quoted 9 lines · Richard Fitzgerald

This series fixes a problem with soc_sdw_utils.c calling the wrong codec init callbacks, because it assumed that the DAI name could be used to uniquely identify the codec. This isn't the case, especially on SDCA which is a generic driver for many parts.

The second patch is the actual fix.
The first patch is needed to add a missing export to SoundWire core.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] soundwire: Add missing EXPORT for sdw_slave_type

      commit: 1ddbcb910a06f53fc2b14e1743c6ad4ccfd7107f
[2/2] ASoC: sdw_utils: Call init callbacks on the correct codec DAI
      commit: 5b027c74f3ee8979193c50d31187edfa31acc0db

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark