All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH v3 10/16] ASoC: add Rich Graph Card Custom Sample
Date: 10 Sep 2021 10:22:43 +0900	[thread overview]
Message-ID: <87fsudusv0.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87tuitusy4.wl-kuninori.morimoto.gx@renesas.com>


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

rich-graph-card has customizing support.
This means user can re-use rich-graph-card DT parsing, and possible
to expand to own special handling.

This patch adds Rich Graph Card's Customize Sample Driver.
It can re-use rich-graph-card parsing by calling
rich_graph_parse_of(...), and user can expand each functions by
using hooks.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/generic/Kconfig                   |   6 +
 sound/soc/generic/Makefile                  |   2 +
 sound/soc/generic/rich-custom-card-sample.c | 174 ++++++++++++++++++++
 3 files changed, 182 insertions(+)
 create mode 100644 sound/soc/generic/rich-custom-card-sample.c

diff --git a/sound/soc/generic/Kconfig b/sound/soc/generic/Kconfig
index 8af35415d162..4caf6c007752 100644
--- a/sound/soc/generic/Kconfig
+++ b/sound/soc/generic/Kconfig
@@ -26,6 +26,12 @@ config SND_RICH_GRAPH_CARD
 	  This option enables generic rich graph card support
 	  with OF-graph DT bindings.
 
+config SND_RICH_CUSTOM_CARD_SAMPLE
+	tristate "ASoC Audio Rich Graph Card base custom card sample support"
+	depends on SND_RICH_GRAPH_CARD
+	help
+	  This option enables Audio Rich Graph Card base custom card support
+
 config SND_TEST_COMPONENT
 	tristate "ASoC Test component sound support"
 	depends on OF
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile
index 60a2e90a4a6b..030ab7e83483 100644
--- a/sound/soc/generic/Makefile
+++ b/sound/soc/generic/Makefile
@@ -4,9 +4,11 @@ snd-soc-simple-card-objs	:= simple-card.o
 snd-soc-audio-graph-card-objs	:= audio-graph-card.o
 snd-soc-rich-graph-card-objs	:= rich-graph-card.o
 snd-soc-test-component-objs	:= test-component.o
+snd-soc-rich-custom-card-sample-objs := rich-custom-card-sample.o
 
 obj-$(CONFIG_SND_SIMPLE_CARD_UTILS)	+= snd-soc-simple-card-utils.o
 obj-$(CONFIG_SND_SIMPLE_CARD)		+= snd-soc-simple-card.o
 obj-$(CONFIG_SND_AUDIO_GRAPH_CARD)	+= snd-soc-audio-graph-card.o
 obj-$(CONFIG_SND_RICH_GRAPH_CARD)	+= snd-soc-rich-graph-card.o
 obj-$(CONFIG_SND_TEST_COMPONENT)	+= snd-soc-test-component.o
+obj-$(CONFIG_SND_RICH_CUSTOM_CARD_SAMPLE) += snd-soc-rich-custom-card-sample.o
diff --git a/sound/soc/generic/rich-custom-card-sample.c b/sound/soc/generic/rich-custom-card-sample.c
new file mode 100644
index 000000000000..6b9bc0393f60
--- /dev/null
+++ b/sound/soc/generic/rich-custom-card-sample.c
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// rich-custom-card-sample.c
+//
+// Copyright (C) 2020 Renesas Electronics Corp.
+// Copyright (C) 2020 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+//
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <sound/graph_card.h>
+
+/*
+ * Custom driver can have own priv
+ * which includes asoc_simple_priv.
+ */
+struct custom_priv {
+	struct asoc_simple_priv simple_priv;
+
+	/* custom driver's own params */
+	int custom_params;
+};
+
+/* You can get custom_priv from simple_priv */
+#define simple_to_custom(simple) container_of((simple), struct custom_priv, simple_priv)
+
+static int custom_card_probe(struct snd_soc_card *card)
+{
+	struct asoc_simple_priv *simple_priv = snd_soc_card_get_drvdata(card);
+	struct custom_priv *custom_priv = simple_to_custom(simple_priv);
+	struct device *dev = simple_priv_to_dev(simple_priv);
+
+	dev_info(dev, "custom probe\n");
+
+	custom_priv->custom_params = 1;
+
+	/* you can use generic probe function */
+	return asoc_graph_card_probe(card);
+}
+
+static int custom_hook_pre(struct asoc_simple_priv *priv)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+
+	/* You can custom before parsing */
+	dev_info(dev, "hook : %s\n", __func__);
+
+	return 0;
+}
+
+static int custom_hook_post(struct asoc_simple_priv *priv)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+	struct snd_soc_card *card;
+
+	/* You can custom after parsing */
+	dev_info(dev, "hook : %s\n", __func__);
+
+	card = simple_priv_to_card(priv);
+	card->probe = custom_card_probe; /* overwrite .probe */
+
+	return 0;
+}
+
+static int custom_normal(struct asoc_simple_priv *priv,
+			 struct device_node *lnk,
+			 struct link_info *li)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+
+	/* You can custom for DPCM parsing */
+	dev_info(dev, "hook : %s\n", __func__);
+
+	return rich_graph_link_dpcm(priv, lnk, li);
+}
+
+
+static int custom_dpcm(struct asoc_simple_priv *priv,
+		       struct device_node *lnk,
+		       struct link_info *li)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+
+	/* You can custom for DPCM parsing */
+	dev_info(dev, "hook : %s\n", __func__);
+
+	return rich_graph_link_dpcm(priv, lnk, li);
+}
+
+static int custom_c2c(struct asoc_simple_priv *priv,
+		      struct device_node *lnk,
+		      struct link_info *li)
+{
+	struct device *dev = simple_priv_to_dev(priv);
+
+	/* You can custom for Codec2Codec parsing */
+	dev_info(dev, "hook : %s\n", __func__);
+
+	return rich_graph_link_c2c(priv, lnk, li);
+}
+
+/*
+ * rich-graph-card has many hooks for your customizing.
+ */
+static struct graph_custom_hooks custom_hooks = {
+	.hook_pre	= custom_hook_pre,
+	.hook_post	= custom_hook_post,
+	.custom_normal	= custom_normal,
+	.custom_dpcm	= custom_dpcm,
+	.custom_c2c	= custom_c2c,
+};
+
+static int custom_startup(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
+	struct device *dev = simple_priv_to_dev(priv);
+
+	dev_info(dev, "custom startup\n");
+
+	return asoc_simple_startup(substream);
+}
+
+/* You can use custom ops */
+static const struct snd_soc_ops custom_ops = {
+	.startup	= custom_startup,
+	.shutdown	= asoc_simple_shutdown,
+	.hw_params	= asoc_simple_hw_params,
+};
+
+static int custom_probe(struct platform_device *pdev)
+{
+	struct custom_priv *custom_priv;
+	struct asoc_simple_priv *simple_priv;
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	custom_priv = devm_kzalloc(dev, sizeof(*custom_priv), GFP_KERNEL);
+	if (!custom_priv)
+		return -ENOMEM;
+
+	simple_priv		= &custom_priv->simple_priv;
+	simple_priv->ops	= &custom_ops; /* customize dai_link ops */
+
+	/* use rich-graph-card parsing with own custom hooks */
+	ret = rich_graph_parse_of(simple_priv, dev, &custom_hooks);
+	if (ret < 0)
+		return ret;
+
+	/* customize more if needed */
+
+	return 0;
+}
+
+static const struct of_device_id custom_of_match[] = {
+	{ .compatible = "rich-custom-card-sample", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, custom_of_match);
+
+static struct platform_driver custom_card = {
+	.driver = {
+		.name = "rich-custom-card-sample",
+		.of_match_table = custom_of_match,
+	},
+	.probe	= custom_probe,
+	.remove	= asoc_simple_remove,
+};
+module_platform_driver(custom_card);
+
+MODULE_ALIAS("platform:asoc-rich-custom-card-sample");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("ASoC Rich Custom Card Sample");
+MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
-- 
2.25.1


  parent reply	other threads:[~2021-09-10  1:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10  1:20 [PATCH v3 00/16] ASoC: Add Rich Graph Card support Kuninori Morimoto
2021-09-10  1:21 ` [PATCH v3 01/16] ASoC: test-component: add Test Component YAML bindings Kuninori Morimoto
2021-10-01 20:11   ` Mark Brown
2021-09-10  1:21 ` [PATCH v3 02/16] ASoC: test-component: add Test Component for Sound debug/test Kuninori Morimoto
2021-09-10  1:21 ` [PATCH v3 03/16] ASoC: simple-card-utils: add asoc_graph_is_ports0() Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 04/16] ASoC: simple-card-utils: add codec2codec support Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 05/16] ASoC: add Rich Graph Card driver Kuninori Morimoto
2021-09-12 10:24   ` kernel test robot
2021-09-12 10:24     ` kernel test robot
2021-09-10  1:22 ` [PATCH v3 06/16] ASoC: rich-graph-card: add Multi CPU/Codec support Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 07/16] ASoC: rich-graph-card: add DPCM support Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 08/16] ASoC: rich-graph-card: add Codec2Codec support Kuninori Morimoto
2021-09-12  6:43   ` kernel test robot
2021-09-12  6:43     ` kernel test robot
2021-09-10  1:22 ` [PATCH v3 09/16] ASoC: add Rich Graph Card Yaml Document Kuninori Morimoto
2021-10-01 21:06   ` Mark Brown
2021-10-04  1:50     ` Kuninori Morimoto
2021-10-05 17:26       ` Mark Brown
2021-09-10  1:22 ` Kuninori Morimoto [this message]
2021-09-10  1:22 ` [PATCH v3 11/16] ASoC: rich-graph-card-sample.dtsi: add Sample DT for Normal (Single) Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 12/16] ASoC: rich-graph-card-sample.dtsi: add Sample DT for Normal (Nulti) Kuninori Morimoto
2021-09-10  1:22 ` [PATCH v3 13/16] ASoC: rich-graph-card-sample.dtsi: add DPCM sample (Single) Kuninori Morimoto
2021-09-10  1:23 ` [PATCH v3 14/16] ASoC: rich-graph-card-sample.dtsi: add DPCM sample (Multi) Kuninori Morimoto
2021-09-10  1:23 ` [PATCH v3 15/16] ASoC: rich-graph-card-sample.dtsi: add Codec2Codec sample (Single) Kuninori Morimoto
2021-09-10  1:23 ` [PATCH v3 16/16] ASoC: rich-graph-card-sample.dtsi: add Codec2Codec sample (Multi) Kuninori Morimoto
2021-09-29 22:23 ` [PATCH v3 00/16] ASoC: Add Rich Graph Card support Kuninori Morimoto
2021-09-30 12:15   ` Mark Brown
2021-09-30 22:38     ` Kuninori Morimoto
2021-10-01  5:43 ` Péter Ujfalusi
2021-10-01  6:48   ` Kuninori Morimoto
2021-10-01 20:01     ` Mark Brown
2021-10-03 23:52       ` Kuninori Morimoto
2021-10-04 16:54         ` 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=87fsudusv0.wl-kuninori.morimoto.gx@renesas.com \
    --to=kuninori.morimoto.gx@renesas.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    /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.