devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Kochetkov <fido_max@inbox.ru>
To: alsa-devel@alsa-project.org
Cc: Maxim Kochetkov <fido_max@inbox.ru>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Sameer Pujar <spujar@nvidia.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Aidan MacDonald <aidanmacdonald.0x0@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Astrid Rost <astrid.rost@axis.com>,
	Herve Codina <herve.codina@bootlin.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] ASoC: simple-card-utils: introduce asoc_simple_parse_triggers()
Date: Sat, 15 Jul 2023 11:30:42 +0300	[thread overview]
Message-ID: <20230715083046.108674-2-fido_max@inbox.ru> (raw)
In-Reply-To: <20230715083046.108674-1-fido_max@inbox.ru>

This function parses DT DAI link triggers params and assigns
the appropriate fields in struct snd_soc_dai_link.
It supports two triggers trigger-stop and trigger-start.

Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
---
 include/sound/simple_card_utils.h     |  3 ++
 sound/soc/generic/simple-card-utils.c | 45 +++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index b450d5873227..ea8c17f7b280 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -180,6 +180,9 @@ int asoc_simple_parse_widgets(struct snd_soc_card *card,
 				      char *prefix);
 int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
 				   char *prefix);
+int asoc_simple_parse_triggers(struct device_node *node,
+			       char *prefix,
+			       struct snd_soc_dai_link *dai_link);
 
 int asoc_simple_init_jack(struct snd_soc_card *card,
 			       struct asoc_simple_jack *sjack,
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 3019626b0592..58f5c672184a 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -737,6 +737,51 @@ int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches);
 
+static enum snd_soc_trigger_order asoc_simple_parse_trigger(
+					struct device_node *node,
+					char *prefix,
+					char *trigger_name)
+{
+	enum snd_soc_trigger_order trigger = SND_SOC_TRIGGER_ORDER_DEFAULT;
+	struct {
+		char *name;
+		unsigned int val;
+	} of_trigger_table[] = {
+		{ "default",	SND_SOC_TRIGGER_ORDER_DEFAULT },
+		{ "ldc",	SND_SOC_TRIGGER_ORDER_LDC },
+	};
+	const char *str;
+	char prop[128];
+	int ret;
+
+	if (!prefix)
+		prefix = "";
+
+	snprintf(prop, sizeof(prop), "%s%s", prefix, trigger_name);
+
+	ret = of_property_read_string(node, prop, &str);
+	if (ret == 0) {
+		for (int i = 0; i < ARRAY_SIZE(of_trigger_table); i++) {
+			if (strcmp(str, of_trigger_table[i].name) == 0) {
+				trigger = of_trigger_table[i].val;
+				break;
+			}
+		}
+	}
+
+	return trigger;
+}
+
+int asoc_simple_parse_triggers(struct device_node *node,
+			       char *prefix,
+			       struct snd_soc_dai_link *dai_link)
+{
+	dai_link->trigger_stop = asoc_simple_parse_trigger(node, prefix, "trigger-stop");
+	dai_link->trigger_start = asoc_simple_parse_trigger(node, prefix, "trigger-start");
+	return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_simple_parse_triggers);
+
 int asoc_simple_init_jack(struct snd_soc_card *card,
 			  struct asoc_simple_jack *sjack,
 			  int is_hp, char *prefix,
-- 
2.40.1


  reply	other threads:[~2023-07-15  8:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-15  8:30 [PATCH v2] Add support for trigger-start/stop for simple audio card Maxim Kochetkov
2023-07-15  8:30 ` Maxim Kochetkov [this message]
2023-07-15  8:30 ` [PATCH v2] ASoC: dt-bindings: simple-card: add triggers properties Maxim Kochetkov
2023-07-18 22:08   ` Rob Herring
2023-07-19  7:13     ` Maxim Kochetkov
2023-07-15  8:30 ` [PATCH v2] ASoC: simple-card: add triggers parsing from DT node support Maxim Kochetkov

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=20230715083046.108674-2-fido_max@inbox.ru \
    --to=fido_max@inbox.ru \
    --cc=aidanmacdonald.0x0@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=astrid.rost@axis.com \
    --cc=broonie@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=herve.codina@bootlin.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=spujar@nvidia.com \
    --cc=tiwai@suse.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;
as well as URLs for NNTP newsgroup(s).