public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] ASoC: Implement fully_routed card property
@ 2011-11-23 19:42 Stephen Warren
       [not found] ` <1322077326-5538-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2011-11-23 19:42 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

A card is fully routed if the DAPM route table describes all connections on
the board.

When a card is fully routed, some operations can be automated by the ASoC
core. The first, and currently only, such operation is described below, and
implemented by this patch.

Codecs often have a large number of external pins, and not all of these pins
will be connected on all board designs. Some machine drivers therefore call
snd_soc_dapm_nc_pin() for all the unused pins, in order to tell the ASoC core
never to activate them.

However, when a card is fully routed, the information needed to derive the
set of unused pins is present in card->dapm_routes. In this case, have
the ASoC core automatically call snd_soc_dapm_nc_pin() for each unused
codec pin.

This has been tested with soc/tegra/tegra_wm8903.c and soc/tegra/trimslice.c.

v2: Rename flag from auto_nc_pins to fully_routed. Adjust description.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 include/sound/soc-dapm.h |    1 +
 include/sound/soc.h      |    1 +
 sound/soc/soc-core.c     |    4 ++
 sound/soc/soc-dapm.c     |   73 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index 17a4c17..0c159a7 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -380,6 +380,7 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
 				  const char *pin);
 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
 				const char *pin);
+void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec);
 
 /* Mostly internal - should not normally be used */
 void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason);
diff --git a/include/sound/soc.h b/include/sound/soc.h
index b21b304..737a4f4 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -815,6 +815,7 @@ struct snd_soc_card {
 	int num_dapm_widgets;
 	const struct snd_soc_dapm_route *dapm_routes;
 	int num_dapm_routes;
+	bool fully_routed;
 
 	struct work_struct deferred_resume_work;
 
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a5d3685..15f29d3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1482,6 +1482,10 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
 
 	snd_soc_dapm_new_widgets(&card->dapm);
 
+	if (card->fully_routed)
+		list_for_each_entry(codec, &codec_list, list)
+			snd_soc_dapm_auto_nc_codec_pins(codec);
+
 	ret = snd_card_register(card->snd_card);
 	if (ret < 0) {
 		printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index f42e8b9..1ecd1b4 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2947,6 +2947,79 @@ int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
 
+static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
+					      struct snd_soc_dapm_widget *w)
+{
+	struct snd_soc_dapm_path *p;
+
+	list_for_each_entry(p, &card->paths, list) {
+		if ((p->source == w) || (p->sink == w)) {
+			dev_dbg(card->dev,
+			    "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
+			    p->source->name, p->source->id, p->source->dapm,
+			    p->sink->name, p->sink->id, p->sink->dapm);
+
+			/* Connected to something other than the codec */
+			if (p->source->dapm != p->sink->dapm)
+				return true;
+			/*
+			 * Loopback connection from codec external pin to
+			 * codec external pin
+			 */
+			if (p->sink->id == snd_soc_dapm_input) {
+				switch (p->source->id) {
+				case snd_soc_dapm_output:
+				case snd_soc_dapm_micbias:
+					return true;
+				default:
+					break;
+				}
+			}
+		}
+	}
+
+	return false;
+}
+
+/**
+ * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
+ * @codec: The codec whose pins should be processed
+ *
+ * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
+ * which are unused. Pins are used if they are connected externally to the
+ * codec, whether that be to some other device, or a loop-back connection to
+ * the codec itself.
+ */
+void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
+{
+	struct snd_soc_card *card = codec->card;
+	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	struct snd_soc_dapm_widget *w;
+
+	dev_dbg(card->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
+		&card->dapm, &codec->dapm);
+
+	list_for_each_entry(w, &card->widgets, list) {
+		if (w->dapm != dapm)
+			continue;
+		switch (w->id) {
+		case snd_soc_dapm_input:
+		case snd_soc_dapm_output:
+		case snd_soc_dapm_micbias:
+			dev_dbg(card->dev, "Auto NC: Checking widget %s\n",
+				w->name);
+			if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
+				dev_dbg(card->dev,
+					"... Not in map; disabling\n");
+				snd_soc_dapm_nc_pin(dapm, w->name);
+			}
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 /**
  * snd_soc_dapm_free - free dapm resources
  * @dapm: DAPM context
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag
       [not found] ` <1322077326-5538-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2011-11-23 19:42   ` Stephen Warren
       [not found]     ` <1322077326-5538-2-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2011-11-23 19:42   ` [PATCH v2 3/3] ASoC: TrimSlice " Stephen Warren
  2011-11-23 21:25   ` [PATCH v2 1/3] ASoC: Implement fully_routed card property Mark Brown
  2 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2011-11-23 19:42 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

Set card.fully_routed to request the ASoC core calculated unused codec
pins, and call snd_soc_dapm_nc_pin() for them. Remove the open-coded
calls.

v2: Rename flag from auto_nc_pins to fully_routed. Adjust description.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 sound/soc/tegra/tegra_wm8903.c |   22 +---------------------
 1 files changed, 1 insertions(+), 21 deletions(-)

diff --git a/sound/soc/tegra/tegra_wm8903.c b/sound/soc/tegra/tegra_wm8903.c
index 33feee8..b260f54 100644
--- a/sound/soc/tegra/tegra_wm8903.c
+++ b/sound/soc/tegra/tegra_wm8903.c
@@ -331,27 +331,6 @@ static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
 
 	snd_soc_dapm_force_enable_pin(dapm, "Mic Bias");
 
-	/* FIXME: Calculate automatically based on DAPM routes? */
-	if (!machine_is_harmony())
-		snd_soc_dapm_nc_pin(dapm, "IN1L");
-	if (!machine_is_seaboard() && !machine_is_aebl())
-		snd_soc_dapm_nc_pin(dapm, "IN1R");
-	snd_soc_dapm_nc_pin(dapm, "IN2L");
-	if (!machine_is_kaen())
-		snd_soc_dapm_nc_pin(dapm, "IN2R");
-	snd_soc_dapm_nc_pin(dapm, "IN3L");
-	snd_soc_dapm_nc_pin(dapm, "IN3R");
-
-	if (machine_is_aebl()) {
-		snd_soc_dapm_nc_pin(dapm, "LON");
-		snd_soc_dapm_nc_pin(dapm, "RON");
-		snd_soc_dapm_nc_pin(dapm, "ROP");
-		snd_soc_dapm_nc_pin(dapm, "LOP");
-	} else {
-		snd_soc_dapm_nc_pin(dapm, "LINEOUTR");
-		snd_soc_dapm_nc_pin(dapm, "LINEOUTL");
-	}
-
 	return 0;
 }
 
@@ -375,6 +354,7 @@ static struct snd_soc_card snd_soc_tegra_wm8903 = {
 	.num_controls = ARRAY_SIZE(tegra_wm8903_controls),
 	.dapm_widgets = tegra_wm8903_dapm_widgets,
 	.num_dapm_widgets = ARRAY_SIZE(tegra_wm8903_dapm_widgets),
+	.fully_routed = true,
 };
 
 static __devinit int tegra_wm8903_driver_probe(struct platform_device *pdev)
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] ASoC: TrimSlice machine: Set the new fully_routed flag
       [not found] ` <1322077326-5538-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2011-11-23 19:42   ` [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag Stephen Warren
@ 2011-11-23 19:42   ` Stephen Warren
  2011-11-23 21:25   ` [PATCH v2 1/3] ASoC: Implement fully_routed card property Mark Brown
  2 siblings, 0 replies; 7+ messages in thread
From: Stephen Warren @ 2011-11-23 19:42 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

Set card.fully_routed to request the ASoC core calculated unused codec
pins, and call snd_soc_dapm_nc_pin() for them. Remove the open-coded
calls.

v2: Rename flag from auto_nc_pins to fully_routed. Adjust description.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 sound/soc/tegra/trimslice.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/sound/soc/tegra/trimslice.c b/sound/soc/tegra/trimslice.c
index d564b40..043eb7c 100644
--- a/sound/soc/tegra/trimslice.c
+++ b/sound/soc/tegra/trimslice.c
@@ -119,7 +119,6 @@ static int trimslice_asoc_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_codec *codec = rtd->codec;
 	struct snd_soc_card *card = codec->card;
-	struct snd_soc_dapm_context *dapm = &codec->dapm;
 	int ret;
 
 	ret = tegra_das_connect_dap_to_dac(TEGRA_DAS_DAP_ID_1,
@@ -135,10 +134,6 @@ static int trimslice_asoc_init(struct snd_soc_pcm_runtime *rtd)
 		return ret;
 	}
 
-	snd_soc_dapm_nc_pin(dapm, "LHPOUT");
-	snd_soc_dapm_nc_pin(dapm, "RHPOUT");
-	snd_soc_dapm_nc_pin(dapm, "MICIN");
-
 	return 0;
 }
 
@@ -162,6 +157,7 @@ static struct snd_soc_card snd_soc_trimslice = {
 	.num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
 	.dapm_routes = trimslice_audio_map,
 	.num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
+	.fully_routed = true,
 };
 
 static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev)
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/3] ASoC: Implement fully_routed card property
       [not found] ` <1322077326-5538-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2011-11-23 19:42   ` [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag Stephen Warren
  2011-11-23 19:42   ` [PATCH v2 3/3] ASoC: TrimSlice " Stephen Warren
@ 2011-11-23 21:25   ` Mark Brown
  2 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2011-11-23 21:25 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Liam Girdwood, alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA

On Wed, Nov 23, 2011 at 12:42:04PM -0700, Stephen Warren wrote:
> A card is fully routed if the DAPM route table describes all connections on
> the board.

Applied, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [alsa-devel] [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag
       [not found]     ` <1322077326-5538-2-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2011-11-23 21:32       ` Mark Brown
       [not found]         ` <20111123213220.GA8149-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2011-11-23 21:32 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Liam Girdwood, linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw

On Wed, Nov 23, 2011 at 12:42:05PM -0700, Stephen Warren wrote:

> v2: Rename flag from auto_nc_pins to fully_routed. Adjust description.
> 
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  sound/soc/tegra/tegra_wm8903.c |   22 +---------------------
>  1 files changed, 1 insertions(+), 21 deletions(-)

Things like your above "v2" line really ought to go here below the ---
so they're automatically cut from the changelog by the tools.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [alsa-devel] [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag
       [not found]         ` <20111123213220.GA8149-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2011-11-23 21:56           ` Stephen Warren
       [not found]             ` <74CDBE0F657A3D45AFBB94109FB122FF174F08C81E-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2011-11-23 21:56 UTC (permalink / raw)
  To: Mark Brown
  Cc: Liam Girdwood,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org

Mark Brown wrote at Wednesday, November 23, 2011 2:32 PM:
> On Wed, Nov 23, 2011 at 12:42:05PM -0700, Stephen Warren wrote:
> 
> > v2: Rename flag from auto_nc_pins to fully_routed. Adjust description.
> >
> > Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> > ---
> >  sound/soc/tegra/tegra_wm8903.c |   22 +---------------------
> >  1 files changed, 1 insertions(+), 21 deletions(-)
> 
> Things like your above "v2" line really ought to go here below the ---
> so they're automatically cut from the changelog by the tools.

That was deliberate; some advantages:
* Documents the review process in git, potentially giving some insight
  into reasoning behind parts of the patch.
* Allows confirmation that the correct version was checked in.
  (rarely an issue, but occasionally, albeit I haven't seen it in ASoC)

It's been mentioned a couple of times briefly on various lists before,
and while I'm sure it's not standard practice or anything, at least
there are some people supporting it. However, if you prefer, I'll try
to remember to move the changelog for ASoC patches.

-- 
nvpublic

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [alsa-devel] [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag
       [not found]             ` <74CDBE0F657A3D45AFBB94109FB122FF174F08C81E-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
@ 2011-11-23 22:06               ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2011-11-23 22:06 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Liam Girdwood,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org

On Wed, Nov 23, 2011 at 01:56:14PM -0800, Stephen Warren wrote:

> * Documents the review process in git, potentially giving some insight
>   into reasoning behind parts of the patch.

If this is an issue write better changelogs (with similar reasoning to
why we don't merge incremental versions of the code either; besides
without knowing what the old versions were it's generally not so useful).
The lkml-reference: stuff looks a lot more useful if you really do want
to do that as it'll show the older versions and discussions.

> * Allows confirmation that the correct version was checked in.
>   (rarely an issue, but occasionally, albeit I haven't seen it in ASoC)

Diff is useful for that (especially if people do what I do when I notice
this stuff and manually strip the noise).

> It's been mentioned a couple of times briefly on various lists before,
> and while I'm sure it's not standard practice or anything, at least
> there are some people supporting it. However, if you prefer, I'll try
> to remember to move the changelog for ASoC patches.

I've genuinely never seen this before except where it looked like an
error on the part of the sender.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-11-23 22:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-23 19:42 [PATCH v2 1/3] ASoC: Implement fully_routed card property Stephen Warren
     [not found] ` <1322077326-5538-1-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-11-23 19:42   ` [PATCH v2 2/3] ASoC: Tegra+WM903 machine: Set the new fully_routed flag Stephen Warren
     [not found]     ` <1322077326-5538-2-git-send-email-swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-11-23 21:32       ` [alsa-devel] " Mark Brown
     [not found]         ` <20111123213220.GA8149-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2011-11-23 21:56           ` Stephen Warren
     [not found]             ` <74CDBE0F657A3D45AFBB94109FB122FF174F08C81E-C7FfzLzN0UxDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2011-11-23 22:06               ` Mark Brown
2011-11-23 19:42   ` [PATCH v2 3/3] ASoC: TrimSlice " Stephen Warren
2011-11-23 21:25   ` [PATCH v2 1/3] ASoC: Implement fully_routed card property Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox