public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: broonie@kernel.org, brendan.higgins@linux.dev,
	davidgow@google.com, raemoar63@gmail.com
Cc: linux-sound@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH 1/4] ASoC: cs35l56: KUnit tests for setting dsp.system_name
Date: Wed,  4 Mar 2026 16:23:59 +0000	[thread overview]
Message-ID: <20260304162402.1714759-2-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20260304162402.1714759-1-rf@opensource.cirrus.com>

Add KUnit tests for setting the dsp.system_name string.

There are two sources of the string:

1. PCI SSID from struct snd_soc_card.
2. "cirrus,firmware-uid" property.

Either of these can then be qualified by a speaker ID integer.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 sound/soc/codecs/cs35l56-test.c | 80 +++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l56.c      |  3 +-
 sound/soc/codecs/cs35l56.h      |  1 +
 3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cs35l56-test.c b/sound/soc/codecs/cs35l56-test.c
index decedf76847d..ac3f34bf8adc 100644
--- a/sound/soc/codecs/cs35l56-test.c
+++ b/sound/soc/codecs/cs35l56-test.c
@@ -74,6 +74,78 @@ static const char *cs35l56_test_devm_get_vendor_specific_variant_id_none(struct
 	return ERR_PTR(-ENOENT);
 }
 
+static void cs35l56_test_system_name_from_ssid(struct kunit *test)
+{
+	struct cs35l56_test_priv *priv = test->priv;
+	struct cs35l56_private *cs35l56 = priv->cs35l56_priv;
+
+	cs35l56->speaker_id = -1;
+	snd_soc_card_set_pci_ssid(cs35l56->component->card, 0x12b4, 0xa7c8);
+
+	KUNIT_EXPECT_EQ(test, cs35l56_get_firmware_uid(cs35l56), 0);
+	KUNIT_EXPECT_EQ(test, cs35l56_set_fw_name(cs35l56->component), 0);
+	KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, "12b4a7c8");
+}
+
+static void cs35l56_test_system_name_from_ssid_and_spkid(struct kunit *test)
+{
+	struct cs35l56_test_priv *priv = test->priv;
+	struct cs35l56_private *cs35l56 = priv->cs35l56_priv;
+
+	cs35l56->speaker_id = 1;
+	snd_soc_card_set_pci_ssid(cs35l56->component->card, 0x12b4, 0xa7c8);
+
+	KUNIT_EXPECT_EQ(test, cs35l56_get_firmware_uid(cs35l56), 0);
+	KUNIT_EXPECT_EQ(test, cs35l56_set_fw_name(cs35l56->component), 0);
+	KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, "12b4a7c8-spkid1");
+}
+
+static void cs35l56_test_system_name_from_property(struct kunit *test)
+{
+	struct cs35l56_test_priv *priv = test->priv;
+	struct cs35l56_private *cs35l56 = priv->cs35l56_priv;
+	const struct property_entry dev_props[] = {
+		PROPERTY_ENTRY_STRING("cirrus,firmware-uid", "acme"),
+		{ }
+	};
+	const struct software_node dev_node = SOFTWARE_NODE("SPK1", dev_props, NULL);
+
+	cs35l56->speaker_id = -1;
+
+	KUNIT_ASSERT_EQ(test, device_add_software_node(cs35l56->base.dev, &dev_node), 0);
+	KUNIT_ASSERT_EQ(test, 0,
+			kunit_add_action_or_reset(test,
+						  device_remove_software_node_wrapper,
+						  cs35l56->base.dev));
+
+	KUNIT_EXPECT_EQ(test, cs35l56_get_firmware_uid(cs35l56), 0);
+	KUNIT_EXPECT_EQ(test, cs35l56_set_fw_name(cs35l56->component), 0);
+	KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, "acme");
+}
+
+static void cs35l56_test_system_name_from_property_and_spkid(struct kunit *test)
+{
+	struct cs35l56_test_priv *priv = test->priv;
+	struct cs35l56_private *cs35l56 = priv->cs35l56_priv;
+	const struct property_entry dev_props[] = {
+		PROPERTY_ENTRY_STRING("cirrus,firmware-uid", "acme"),
+		{ }
+	};
+	const struct software_node dev_node = SOFTWARE_NODE("SPK1", dev_props, NULL);
+
+	cs35l56->speaker_id = 1;
+
+	KUNIT_ASSERT_EQ(test, device_add_software_node(cs35l56->base.dev, &dev_node), 0);
+	KUNIT_ASSERT_EQ(test, 0,
+			kunit_add_action_or_reset(test,
+						  device_remove_software_node_wrapper,
+						  cs35l56->base.dev));
+
+	KUNIT_EXPECT_EQ(test, cs35l56_get_firmware_uid(cs35l56), 0);
+	KUNIT_EXPECT_EQ(test, cs35l56_set_fw_name(cs35l56->component), 0);
+	KUNIT_EXPECT_STREQ(test, cs35l56->dsp.system_name, "acme-spkid1");
+}
+
 static void cs35l56_test_l56_b0_suffix_sdw(struct kunit *test)
 {
 	struct cs35l56_test_priv *priv = test->priv;
@@ -596,6 +668,10 @@ KUNIT_ARRAY_PARAM(cs35l56_test_type_rev_all, cs35l56_test_type_rev_all_param_cas
 		  cs35l56_test_type_rev_param_desc);
 
 static struct kunit_case cs35l56_test_cases_soundwire[] = {
+	KUNIT_CASE(cs35l56_test_system_name_from_ssid),
+	KUNIT_CASE(cs35l56_test_system_name_from_ssid_and_spkid),
+	KUNIT_CASE(cs35l56_test_system_name_from_property),
+	KUNIT_CASE(cs35l56_test_system_name_from_property_and_spkid),
 	KUNIT_CASE(cs35l56_test_l56_b0_suffix_sdw),
 	KUNIT_CASE_PARAM(cs35l56_test_suffix_sdw, cs35l56_test_type_rev_ex_b0_gen_params),
 	KUNIT_CASE_PARAM(cs35l56_test_ssidexv2_suffix_sdw,
@@ -613,6 +689,10 @@ static struct kunit_case cs35l56_test_cases_soundwire[] = {
 };
 
 static struct kunit_case cs35l56_test_cases_not_soundwire[] = {
+	KUNIT_CASE(cs35l56_test_system_name_from_ssid),
+	KUNIT_CASE(cs35l56_test_system_name_from_ssid_and_spkid),
+	KUNIT_CASE(cs35l56_test_system_name_from_property),
+	KUNIT_CASE(cs35l56_test_system_name_from_property_and_spkid),
 	KUNIT_CASE_PARAM(cs35l56_test_suffix_i2cspi, cs35l56_test_type_rev_all_gen_params),
 	KUNIT_CASE_PARAM(cs35l56_test_ssidexv2_suffix_i2cspi,
 			 cs35l56_test_type_rev_all_gen_params),
diff --git a/sound/soc/codecs/cs35l56.c b/sound/soc/codecs/cs35l56.c
index 37909a319f88..9d35797e000a 100644
--- a/sound/soc/codecs/cs35l56.c
+++ b/sound/soc/codecs/cs35l56.c
@@ -1669,7 +1669,7 @@ VISIBLE_IF_KUNIT int cs35l56_process_xu_properties(struct cs35l56_private *cs35l
 }
 EXPORT_SYMBOL_IF_KUNIT(cs35l56_process_xu_properties);
 
-static int cs35l56_get_firmware_uid(struct cs35l56_private *cs35l56)
+VISIBLE_IF_KUNIT int cs35l56_get_firmware_uid(struct cs35l56_private *cs35l56)
 {
 	struct device *dev = cs35l56->base.dev;
 	const char *prop;
@@ -1694,6 +1694,7 @@ static int cs35l56_get_firmware_uid(struct cs35l56_private *cs35l56)
 
 	return 0;
 }
+EXPORT_SYMBOL_IF_KUNIT(cs35l56_get_firmware_uid);
 
 /*
  * Some SoundWire laptops have a spk-id-gpios property but it points to
diff --git a/sound/soc/codecs/cs35l56.h b/sound/soc/codecs/cs35l56.h
index 691f857d0bd8..747529be3e2e 100644
--- a/sound/soc/codecs/cs35l56.h
+++ b/sound/soc/codecs/cs35l56.h
@@ -78,6 +78,7 @@ void cs35l56_remove(struct cs35l56_private *cs35l56);
 int cs35l56_set_fw_suffix(struct cs35l56_private *cs35l56);
 int cs35l56_set_fw_name(struct snd_soc_component *component);
 int cs35l56_process_xu_properties(struct cs35l56_private *cs35l56);
+int cs35l56_get_firmware_uid(struct cs35l56_private *cs35l56);
 #endif
 
 #endif /* ifndef CS35L56_H */
-- 
2.47.3


  reply	other threads:[~2026-03-04 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 16:23 [PATCH 0/4] ASoC: cs35l56: More KUnit tests for speaker ID Richard Fitzgerald
2026-03-04 16:23 ` Richard Fitzgerald [this message]
2026-03-04 16:24 ` [PATCH 2/4] ASoC: cs35l56: Some KUnit testing of cs35l56_get_speaker_id() Richard Fitzgerald
2026-03-04 16:24 ` [PATCH 3/4] ASoC: cs35l56: KUnit tests for reading speaker ID from host GPIOs Richard Fitzgerald
2026-03-04 16:24 ` [PATCH 4/4] kunit: config: all_tests: Select CONFIG_GPIOLIB Richard Fitzgerald
2026-03-05 22:49 ` (subset) [PATCH 0/4] ASoC: cs35l56: More KUnit tests for speaker ID Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260304162402.1714759-2-rf@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=brendan.higgins@linux.dev \
    --cc=broonie@kernel.org \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=raemoar63@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox