All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <daniel@zonque.org>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, broonie@kernel.org, Daniel Mack <daniel@zonque.org>
Subject: [alsa-devel] [PATCH 2/2] ASoC: simple-card: add support for codec-to-codec links
Date: Thu,  5 Dec 2019 09:14:28 +0100	[thread overview]
Message-ID: <20191205081428.611572-2-daniel@zonque.org> (raw)
In-Reply-To: <20191205081428.611572-1-daniel@zonque.org>

DAI links in ASoC can be turned into codec-to-codec links by populating
the .params field. This patch adds support for this to the simple-card
driver and exposes the feature via three new device-tree properties that
configure the pcm format, the sampling rate and the channel count.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 .../devicetree/bindings/sound/simple-card.txt | 10 ++++++
 include/sound/simple_card_utils.h             |  6 +++-
 sound/soc/generic/simple-card-utils.c         | 33 +++++++++++++++++++
 sound/soc/generic/simple-card.c               | 19 +++++++++++
 4 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt
index 79954cd6e37b..13f0c0da8b53 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
@@ -27,6 +27,16 @@ Optional properties:
 - simple-audio-card,pin-switches	: List of strings containing the widget names for
 					  which pin switches must be created.
 
+Optional dai-link properies for CODEC-to-CODEC links:
+
+- codec-to-codec-format			: Format to configure
+					  "s16_le"; "s24_le", "s32_le", ...
+- codec-to-codec-rate			: Sample rate to configure
+- codec-to-codec-channels		: Number of channels to configure
+
+Note that for a CODEC-to-CODEC link to be activated, you also need to provide a
+valid DAPM path that connects the two components.
+
 Optional subnodes:
 
 - simple-audio-card,dai-link		: Container for dai-link level
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index 31f76b6abf71..2d34a34c5e74 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -47,6 +47,7 @@ struct asoc_simple_priv {
 		struct snd_soc_dai_link_component platforms;
 		struct asoc_simple_data adata;
 		struct snd_soc_codec_conf *codec_conf;
+		struct snd_soc_pcm_stream c2c_params;
 		unsigned int mclk_fs;
 	} *dai_props;
 	struct asoc_simple_jack hp_jack;
@@ -120,7 +121,10 @@ void asoc_simple_convert_fixup(struct asoc_simple_data *data,
 void asoc_simple_parse_convert(struct device *dev,
 			       struct device_node *np, char *prefix,
 			       struct asoc_simple_data *data);
-
+void asoc_simple_parse_c2c_params(struct device *dev,
+				  struct device_node *np,
+				  char *prefix,
+				  struct snd_soc_pcm_stream *dest);
 int asoc_simple_parse_routing(struct snd_soc_card *card,
 				      char *prefix);
 int asoc_simple_parse_widgets(struct snd_soc_card *card,
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 9b794775df53..208708cd880b 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -52,6 +52,39 @@ void asoc_simple_parse_convert(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(asoc_simple_parse_convert);
 
+void asoc_simple_parse_c2c_params(struct device *dev,
+				  struct device_node *np,
+				  char *prefix,
+				  struct snd_soc_pcm_stream *dest)
+{
+	char prop[128];
+	unsigned int rate, channels;
+	const char *format_string;
+
+	if (!prefix)
+		prefix = "";
+
+	snprintf(prop, sizeof(prop), "%s%s", prefix, "codec-to-codec-rate");
+	of_property_read_u32(np, prop, &rate);
+
+	snprintf(prop, sizeof(prop), "%s%s", prefix, "codec-to-codec-channels");
+	of_property_read_u32(np, prop, &channels);
+
+	snprintf(prop, sizeof(prop), "%s%s", prefix, "codec-to-codec-format");
+	if (!of_property_read_string(np, prop, &format_string)) {
+		int format = snd_pcm_format_by_name(format_string);
+
+		if (format >= 0) {
+			dest->formats = 1ULL << format;
+			dest->channels_min = dest->channels_max = channels;
+			dest->rate_min = dest->rate_max = rate;
+		} else {
+			dev_err(dev, "unknown dai format %s\n", format_string);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(asoc_simple_parse_c2c_params);
+
 int asoc_simple_parse_daifmt(struct device *dev,
 			     struct device_node *node,
 			     struct device_node *codec,
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 8b30e5bc73af..854d871eb5bd 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -94,6 +94,21 @@ static void simple_parse_convert(struct device *dev,
 	of_node_put(node);
 }
 
+static void simple_parse_c2c_params(struct device *dev,
+				    struct device_node *np,
+				    struct snd_soc_pcm_stream *dest)
+{
+	struct device_node *top = dev->of_node;
+	struct device_node *node = of_get_parent(np);
+
+	asoc_simple_parse_c2c_params(dev, top,  PREFIX, dest);
+	asoc_simple_parse_c2c_params(dev, node, PREFIX, dest);
+	asoc_simple_parse_c2c_params(dev, node, NULL,   dest);
+	asoc_simple_parse_c2c_params(dev, np,   NULL,   dest);
+
+	of_node_put(node);
+}
+
 static void simple_parse_mclk_fs(struct device_node *top,
 				 struct device_node *cpu,
 				 struct device_node *codec,
@@ -334,6 +349,10 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
 	dai_link->ops = &simple_ops;
 	dai_link->init = asoc_simple_dai_init;
 
+	simple_parse_c2c_params(dev, node, &dai_props->c2c_params);
+	if (dai_props->c2c_params.formats != 0)
+		dai_link->params = &dai_props->c2c_params;
+
 	asoc_simple_canonicalize_cpu(dai_link, single_cpu);
 	asoc_simple_canonicalize_platform(dai_link);
 
-- 
2.23.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2019-12-05  8:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05  8:14 [alsa-devel] [PATCH 1/2] ALSA: core: add snd_pcm_format_by_name() Daniel Mack
2019-12-05  8:14 ` Daniel Mack [this message]
2019-12-05  9:18   ` [alsa-devel] [PATCH 2/2] ASoC: simple-card: add support for codec-to-codec links Mark Brown
2019-12-05  8:25 ` [alsa-devel] [PATCH 1/2] ALSA: core: add snd_pcm_format_by_name() Takashi Iwai
2019-12-05  9:21   ` Daniel Mack

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=20191205081428.611572-2-daniel@zonque.org \
    --to=daniel@zonque.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.