Skip to contentSkip to conversation

ASoC: cs35l56: Prepare for SDCA Companion Amp

PATCH In review Richard Fitzgerald 2 participants 6 messages Nov 20

Subsystems (3)
lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

cover ASoC: cs35l56: Prepare for SDCA Companion Amp

This series removes some unused legacy implementation of the SoundWire DP3 port. This old code conflicts with the actual purpose of DP3 as the SDCA Companion Amp output.

0001 and 0002 are the two changes to switch the code over to being suitable for Companion Amp.

0003 cleans up a regmap table that has been made redundant by #1 and #2

0004 is KUnit testing for the changes in #1. This patch depends on code introduced by the previous pending patch:
"ASoC: cs35l56: Add KUnit test that widget init doesn't write ASP registers"
https://lore.kernel.org/linux-sound/[email protected]/T/#t

Richard Fitzgerald (4):
ASoC: cs35l56: Remove SDW1 TX source controls and widgets
ASoC: cs35l56: Rename the DP3 DAI to cs35l56-ot127
ASoC: cs35l56: Eliminate trivial regmap patch
ASoC: cs35l56: Add test that probe() doesn't write SDW mux registers

 sound/soc/codecs/cs35l56-shared.c | 44 +++-------------
 sound/soc/codecs/cs35l56-test.c   | 84 +++++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l56.c        | 55 ++------------------
 3 files changed, 95 insertions(+), 88 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 1/4 ASoC: cs35l56: Remove SDW1 TX source controls and widgets

Remove the ALSA controls and mux widgets for the SDW1 capture DAI. Connect this DAI to a dummy siggen source like the OT25 DAI. This is to allow DP3 to be used for its intended purpose as the SDCA companion amp output.

The implementation of this DAI was incorrect. It provided a capture DAI for the SoundWire DP3 port. But DP4 (OT25 DAI) is the port for feedback to the host.

The DP3 port is used for SDCA companion amp (OT127) and the mixer source registers are owned by the firmware. The driver should not be writing to them.

Nothing has ever used these ALSA controls so they can safely be removed. The incorrect use of DP3 as the feedback to the host has already been fixed in these commits:

commit 86c8360c97f6 ("ASoC: cs35l56: Add DAI for SDCA OT25 stream") commit 4b7f393a01f8 ("ASoC: sdw_utils: Switch CS35L56/57/62/63 to use OT25 DAI")

---
 sound/soc/codecs/cs35l56-shared.c | 16 ----------
 sound/soc/codecs/cs35l56.c        | 51 ++-----------------------------
 2 files changed, 2 insertions(+), 65 deletions(-)
sound/soc/codecs/cs35l56-shared.c +0 -16
index 4d76f1777927..073f7bdd3b0d 100644
@@ -49,14 +49,6 @@ int cs35l56_set_asp_defaults(struct cs35l56_base *cs35l56_base)
 EXPORT_SYMBOL_NS_GPL(cs35l56_set_asp_defaults, "SND_SOC_CS35L56_SHARED");
 
 static const struct reg_sequence cs35l56_patch[] = {
-	/*
-	 * Firmware can change these to non-defaults to satisfy SDCA.
-	 * Ensure that they are at known defaults.
-	 */
-	{ CS35L56_SWIRE_DP3_CH1_INPUT,		0x00000018 },
-	{ CS35L56_SWIRE_DP3_CH2_INPUT,		0x00000019 },
-	{ CS35L56_SWIRE_DP3_CH3_INPUT,		0x00000029 },
-	{ CS35L56_SWIRE_DP3_CH4_INPUT,		0x00000028 },
 	{ CS35L56_IRQ1_MASK_18,			0x1f7df0ff },
 };
 
@@ -105,10 +97,6 @@ int cs35l56_set_patch(struct cs35l56_base *cs35l56_base)
 EXPORT_SYMBOL_NS_GPL(cs35l56_set_patch, "SND_SOC_CS35L56_SHARED");
 
 static const struct reg_default cs35l56_reg_defaults[] = {
-	{ CS35L56_SWIRE_DP3_CH1_INPUT,		0x00000018 },
-	{ CS35L56_SWIRE_DP3_CH2_INPUT,		0x00000019 },
-	{ CS35L56_SWIRE_DP3_CH3_INPUT,		0x00000029 },
-	{ CS35L56_SWIRE_DP3_CH4_INPUT,		0x00000028 },
 	{ CS35L56_IRQ1_MASK_1,			0x83ffffff },
 	{ CS35L56_IRQ1_MASK_2,			0xffff7fff },
 	{ CS35L56_IRQ1_MASK_4,			0xe0ffffff },
@@ -121,10 +109,6 @@ static const struct reg_default cs35l56_reg_defaults[] = {
 };
 
 static const struct reg_default cs35l63_reg_defaults[] = {
-	{ CS35L56_SWIRE_DP3_CH1_INPUT,		0x00000018 },
-	{ CS35L56_SWIRE_DP3_CH2_INPUT,		0x00000019 },
-	{ CS35L56_SWIRE_DP3_CH3_INPUT,		0x00000029 },
-	{ CS35L56_SWIRE_DP3_CH4_INPUT,		0x00000028 },
 	{ CS35L56_IRQ1_MASK_1,			0x8003ffff },
 	{ CS35L56_IRQ1_MASK_2,			0xffff7fff },
 	{ CS35L56_IRQ1_MASK_4,			0xe0ffffff },
sound/soc/codecs/cs35l56.c +2 -49

75 lines not on this page · raw message

Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH 2/4 ASoC: cs35l56: Rename the DP3 DAI to cs35l56-ot127

In reply to Richard Fitzgerald

Rename the DAI for DP3 to cs35l56-ot127 to match its actual function as the SDCA OT127 Companion Amp output (a type of codec-codec link).

The previous designation as "SDW1 Capture" was incorrect. It is not for host capture and never has been (this function is on DP4).

The use of the old DAI name was already removed in previous commit 4b7f393a01f8 ("ASoC: sdw_utils: Switch CS35L56/57/62/63 to use OT25 DAI"), so there are no users of the old DAI name in the kernel.

---
 sound/soc/codecs/cs35l56.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/codecs/cs35l56.c +3 -3
index acb202559dff..439063084d4b 100644
@@ -436,7 +436,7 @@ static const struct snd_soc_dapm_route cs35l56_audio_map[] = {
 	{ "ASP1 Capture", NULL, "ASP1TX3" },
 	{ "ASP1 Capture", NULL, "ASP1TX4" },
 
-	{ "SDW1 Capture", NULL, "OT127 Source" },
+	{ "OT127", NULL, "OT127 Source" },
 
 	{ "OT25", NULL, "OT25 Reference" },
 };
@@ -855,10 +855,10 @@ static struct snd_soc_dai_driver cs35l56_dai[] = {
 		.ops = &cs35l56_sdw_dai_ops,
 	},
 	{
-		.name = "cs35l56-sdw1c",
+		.name = "cs35l56-ot127",
 		.id = 2,
 		.capture = {
-			.stream_name = "SDW1 Capture",
+			.stream_name = "OT127",
 			.channels_min = 1,
 			.channels_max = 4,
 			.rates = CS35L56_RATES,
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH 3/4 ASoC: cs35l56: Eliminate trivial regmap patch

In reply to Richard Fitzgerald

Previous commits removed most of the registers from the common cs35l56_patch, leaving only one register in this patch. Move that single register patch into the separate cs35l56 and cs35l63 patches and remove the trivial common patch.

---
 sound/soc/codecs/cs35l56-shared.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)
sound/soc/codecs/cs35l56-shared.c +7 -21
index 073f7bdd3b0d..34aebf81f4a4 100644
@@ -50,16 +50,14 @@ EXPORT_SYMBOL_NS_GPL(cs35l56_set_asp_defaults, "SND_SOC_CS35L56_SHARED");
 
 static const struct reg_sequence cs35l56_patch[] = {
 	{ CS35L56_IRQ1_MASK_18,			0x1f7df0ff },
-};
-
-static const struct reg_sequence cs35l56_patch_fw[] = {
 	/* These are not reset by a soft-reset, so patch to defaults. */
 	{ CS35L56_MAIN_RENDER_USER_MUTE,	0x00000000 },
 	{ CS35L56_MAIN_RENDER_USER_VOLUME,	0x00000000 },
 	{ CS35L56_MAIN_POSTURE_NUMBER,		0x00000000 },
 };
 
-static const struct reg_sequence cs35l63_patch_fw[] = {
+static const struct reg_sequence cs35l63_patch[] = {
+	{ CS35L56_IRQ1_MASK_18,			0x1f7df0ff },
 	/* These are not reset by a soft-reset, so patch to defaults. */
 	{ CS35L63_MAIN_RENDER_USER_MUTE,	0x00000000 },
 	{ CS35L63_MAIN_RENDER_USER_VOLUME,	0x00000000 },
@@ -68,31 +66,19 @@ static const struct reg_sequence cs35l63_patch_fw[] = {
 
 int cs35l56_set_patch(struct cs35l56_base *cs35l56_base)
 {
-	int ret;
-
-	ret = regmap_register_patch(cs35l56_base->regmap, cs35l56_patch,
-				     ARRAY_SIZE(cs35l56_patch));
-	if (ret)
-		return ret;
-
-
 	switch (cs35l56_base->type) {
 	case 0x54:
 	case 0x56:
 	case 0x57:
-		ret = regmap_register_patch(cs35l56_base->regmap, cs35l56_patch_fw,
-					    ARRAY_SIZE(cs35l56_patch_fw));
-		break;
+		return regmap_register_patch(cs35l56_base->regmap, cs35l56_patch,
+					     ARRAY_SIZE(cs35l56_patch));
 	case 0x63:
 	case 0x62:
-		ret = regmap_register_patch(cs35l56_base->regmap, cs35l63_patch_fw,
-					    ARRAY_SIZE(cs35l63_patch_fw));
-		break;
+		return regmap_register_patch(cs35l56_base->regmap, cs35l63_patch,
+					     ARRAY_SIZE(cs35l63_patch));
 	default:
-		break;
+		return 0;
 	}
-
-	return ret;
 }
 EXPORT_SYMBOL_NS_GPL(cs35l56_set_patch, "SND_SOC_CS35L56_SHARED");
 
Signature · 1 line
2.47.3
author maintainer
#4 lore raw

PATCH 4/4 ASoC: cs35l56: Add test that probe() doesn't write SDW mux registers

In reply to Richard Fitzgerald

The driver cannot assume that it owns control of the CS35L56_SWIRE_DP3_CH?_INPUT registers so it must not do anything during probe() or component_probe() that could result in a write to these registers. Add a test case for this.

---
 sound/soc/codecs/cs35l56-test.c | 84 +++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
sound/soc/codecs/cs35l56-test.c +84 -0
index b422d19ba0b2..362da30b949e 100644
@@ -63,6 +63,7 @@ struct cs35l56_test_priv {
 
 	bool asp_config_regs_written;
 	bool asp_mixer_regs_written;
+	bool sdw_mux_regs_written;
 };
 
 struct cs35l56_test_param {
@@ -124,6 +125,11 @@ static const struct range cs35l56_test_asp_mixer_registers_range = {
 	.end = CS35L56_ASP1TX4_INPUT,
 };
 
+static const struct range cs35l56_test_sdw_mux_registers_range = {
+	.start = CS35L56_SWIRE_DP3_CH1_INPUT,
+	.end = CS35L56_SWIRE_DP3_CH4_INPUT,
+};
+
 static int cs35l56_test_mock_registers_read(void *context,
 					    const void *reg_buf, size_t reg_size,
 					    void *val_buf, size_t val_size)
@@ -200,6 +206,9 @@ static int cs35l56_test_mock_registers_write(void *context, const void *data, si
 	if (range_overlaps(&addr_range, &cs35l56_test_asp_mixer_registers_range))
 		priv->asp_mixer_regs_written = true;
 
+	if (range_overlaps(&addr_range, &cs35l56_test_sdw_mux_registers_range))
+		priv->sdw_mux_regs_written = true;
+
 	for (i = 0; i < count; i += sizeof(u32)) {
 		val = get_unaligned_be32(buf + i);
 		ret = regmap_write(priv->registers, reg + i, val);
@@ -929,6 +938,79 @@ static void cs35l56_test_component_probe_omits_asp(struct kunit *test)
 	KUNIT_EXPECT_FALSE(test, priv->asp_mixer_regs_written);
 }
 
+/*
+ * Probing the component must not write the SoundWire TX mux registers,
+ * either directly or through a subsequent regcache_sync().
+ */
+static void cs35l56_test_component_probe_omits_sdw_mux(struct kunit *test)
+{
+	struct cs35l56_test_priv *priv = test->priv;
+	struct cs35l56_private *cs35l56 = priv->cs35l56_priv;
+	struct snd_soc_card *card = cs35l56->component->card;
+	struct snd_soc_aux_dev *aux;
+	struct faux_device *card_dev;
+
+	cs35l56_test_create_mock_supplies(test);
+	cs35l56_test_create_mock_device_registers(test);
+
+	KUNIT_ASSERT_NOT_NULL(test, priv->regmap_config);
+	cs35l56->base.regmap = devm_regmap_init(cs35l56->base.dev,
+						&cs35l56_test_mock_registers_client_regmap_bus,
+						test, priv->regmap_config);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cs35l56->base.regmap);
+
+	KUNIT_ASSERT_EQ(test, 0, cs35l56_common_probe(cs35l56, 0));
+	KUNIT_ASSERT_EQ(test, 0,
+			kunit_add_action_or_reset(test, cs35l56_remove_wrapper, cs35l56));
+
+	/* Prevent real dsp_work */
+	INIT_WORK(&cs35l56->dsp_work, cs35l56_test_dummy_dsp_work);
+
+	/* Simulate first attachment and re-attachment after the soft reset. */
+	regcache_cache_only(cs35l56->base.regmap, false);
+	KUNIT_ASSERT_EQ(test, 0, cs35l56_init(cs35l56));
+	KUNIT_ASSERT_EQ(test, 0, cs35l56_init(cs35l56));
+	KUNIT_ASSERT_TRUE(test, cs35l56->base.init_done);
+	flush_work(&cs35l56->component_register_work);
+	KUNIT_ASSERT_TRUE(test, cs35l56->component_registered);
+
+	card_dev = faux_device_create("cs35l56_test_card", NULL, NULL);
+	KUNIT_ASSERT_NOT_NULL(test, card_dev);
+	KUNIT_ASSERT_EQ(test, 0,
+			kunit_add_action_or_reset(test, faux_device_destroy_wrapper, card_dev));
+
+	/* Bind as an auxiliary component so the ASP DAI is never probed. */
+	aux = kunit_kzalloc(test, sizeof(*aux), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, aux);
+	aux->dlc.name = dev_name(cs35l56->base.dev);
+	card->name = "cs35l56-test";
+	card->dev = &card_dev->dev;
+	card->owner = THIS_MODULE;
+	card->aux_dev = aux;
+	card->num_aux_devs = 1;
+	KUNIT_ASSERT_EQ(test, 0, snd_soc_register_card(card));
+	KUNIT_ASSERT_EQ(test, 0,
+			kunit_add_action_or_reset(test, snd_soc_unregister_card_wrapper, card));
+	KUNIT_ASSERT_TRUE(test, card->instantiated);
+	KUNIT_EXPECT_FALSE(test, priv->sdw_mux_regs_written);
+
+	/*
+	 * Flush cache to ensure there aren't cached values for the SoundWire muxes.
+	 * The first case without regcache_mark_dirty() tests flushing when
+	 * hardware registers have not reset, and requires a dummy write to
+	 * the cache to make it dirty.
+	 */
+	regcache_cache_only(cs35l56->base.regmap, true);
+	KUNIT_ASSERT_EQ(test, 0, regmap_write(cs35l56->base.regmap,
+					      CS35L56_DSP_VIRTUAL1_MBOX_1, 0));
+	regcache_cache_only(cs35l56->base.regmap, false);
+	KUNIT_ASSERT_EQ(test, 0, regcache_sync(cs35l56->base.regmap));
+	regcache_mark_dirty(cs35l56->base.regmap);
+	KUNIT_ASSERT_EQ(test, 0, regcache_sync(cs35l56->base.regmap));
+
+	KUNIT_EXPECT_FALSE(test, priv->sdw_mux_regs_written);
+}
+
 static int cs35l56_test_case_init_common(struct kunit *test)
 {
 	struct cs35l56_test_priv *priv;
@@ -1233,6 +1315,8 @@ static struct kunit_case cs35l56_test_cases_soundwire[] = {
 	KUNIT_CASE(cs35l56_test_set_fw_name_preserves_spkid_without_onchip_gpios),
 	KUNIT_CASE_PARAM(cs35l56_test_component_probe_omits_asp,
 			 cs35l56_test_type_rev_all_gen_params),
+	KUNIT_CASE_PARAM(cs35l56_test_component_probe_omits_sdw_mux,
+			 cs35l56_test_type_rev_all_gen_params),
 
 	{ } /* terminator */
 };
Signature · 1 line
2.47.3