All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: alsa-devel@alsa-project.org,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	patches@opensource.wolfsonmicro.com,
	"Philippe Rétornaz" <philippe.retornaz@epfl.ch>,
	"Charles Keepax" <ckeepax@opensource.wolfsonmicro.com>,
	"Steffen Trumtrar" <s.trumtrar@pengutronix.de>,
	"Jerry Wong" <jerry.wong@maximintegrated.com>
Subject: [PATCH 11/11] ASoC: dapm: Break dapm_set_path_status() appart
Date: Sun, 23 Feb 2014 16:10:21 +0100	[thread overview]
Message-ID: <1393168221-23018-12-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1393168221-23018-1-git-send-email-lars@metafoo.de>

There are three different completely independent code paths in
dapm_set_path_status(). One of them is never used at all and the other two (one
for mixers, one for MUXs) have their distincive callsites that always go onto
the same path. Breaking the function into two parts allows us to reduce the code
size and in the MUX case also do some optimizations to avoid having to calcualte
the selected item for each item again.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/soc/soc-dapm.c | 133 +++++++++++++++++----------------------------------
 1 file changed, 44 insertions(+), 89 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c07c7fb..3651a37 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -495,93 +495,6 @@ out:
 	return ret;
 }
 
-/* set up initial codec paths */
-static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
-	struct snd_soc_dapm_path *p, int i)
-{
-	switch (w->id) {
-	case snd_soc_dapm_switch:
-	case snd_soc_dapm_mixer:
-	case snd_soc_dapm_mixer_named_ctl: {
-		unsigned int val;
-		struct soc_mixer_control *mc = (struct soc_mixer_control *)
-			w->kcontrol_news[i].private_value;
-		int reg = mc->reg;
-		unsigned int shift = mc->shift;
-		int max = mc->max;
-		unsigned int mask = (1 << fls(max)) - 1;
-		unsigned int invert = mc->invert;
-
-		if (reg != SND_SOC_NOPM) {
-			soc_widget_read(w, reg, &val);
-			val = (val >> shift) & mask;
-			if (invert)
-				val = max - val;
-			p->connect = !!val;
-		} else {
-			p->connect = 0;
-		}
-
-	}
-	break;
-	case snd_soc_dapm_mux: {
-		struct soc_enum *e = (struct soc_enum *)
-			w->kcontrol_news[i].private_value;
-		unsigned int val, item;
-
-		if (e->reg != SND_SOC_NOPM) {
-			soc_widget_read(w, e->reg, &val);
-			val = (val >> e->shift_l) & e->mask;
-			item = snd_soc_enum_val_to_item(e, val);
-		} else {
-			/* since a virtual mux has no backing registers to
-			 * decide which path to connect, it will try to match
-			 * with the first enumeration.  This is to ensure
-			 * that the default mux choice (the first) will be
-			 * correctly powered up during initialization.
-			 */
-			item = 0;
-		}
-
-		if (item < e->items && !strcmp(p->name, e->texts[item]))
-			p->connect = 1;
-		else
-			p->connect = 0;
-	}
-	break;
-	/* does not affect routing - always connected */
-	case snd_soc_dapm_pga:
-	case snd_soc_dapm_out_drv:
-	case snd_soc_dapm_output:
-	case snd_soc_dapm_adc:
-	case snd_soc_dapm_input:
-	case snd_soc_dapm_siggen:
-	case snd_soc_dapm_dac:
-	case snd_soc_dapm_micbias:
-	case snd_soc_dapm_vmid:
-	case snd_soc_dapm_supply:
-	case snd_soc_dapm_regulator_supply:
-	case snd_soc_dapm_clock_supply:
-	case snd_soc_dapm_aif_in:
-	case snd_soc_dapm_aif_out:
-	case snd_soc_dapm_dai_in:
-	case snd_soc_dapm_dai_out:
-	case snd_soc_dapm_hp:
-	case snd_soc_dapm_mic:
-	case snd_soc_dapm_spk:
-	case snd_soc_dapm_line:
-	case snd_soc_dapm_dai_link:
-	case snd_soc_dapm_kcontrol:
-		p->connect = 1;
-	break;
-	/* does affect routing - dynamically connected */
-	case snd_soc_dapm_pre:
-	case snd_soc_dapm_post:
-		p->connect = 0;
-	break;
-	}
-}
-
 /* connect mux widget to its interconnecting audio paths */
 static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
 	struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
@@ -589,15 +502,33 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
 	const struct snd_kcontrol_new *kcontrol)
 {
 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
+	unsigned int val, item;
 	int i;
 
+	if (e->reg != SND_SOC_NOPM) {
+		soc_widget_read(dest, e->reg, &val);
+		val = (val >> e->shift_l) & e->mask;
+		item = snd_soc_enum_val_to_item(e, val);
+	} else {
+		/* since a virtual mux has no backing registers to
+		 * decide which path to connect, it will try to match
+		 * with the first enumeration.  This is to ensure
+		 * that the default mux choice (the first) will be
+		 * correctly powered up during initialization.
+		 */
+		item = 0;
+	}
+
 	for (i = 0; i < e->items; i++) {
 		if (!(strcmp(control_name, e->texts[i]))) {
 			list_add(&path->list, &dapm->card->paths);
 			list_add(&path->list_sink, &dest->sources);
 			list_add(&path->list_source, &src->sinks);
 			path->name = (char*)e->texts[i];
-			dapm_set_path_status(dest, path, 0);
+			if (i == item)
+				path->connect = 1;
+			else
+				path->connect = 0;
 			return 0;
 		}
 	}
@@ -605,6 +536,30 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
 	return -ENODEV;
 }
 
+/* set up initial codec paths */
+static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,
+	struct snd_soc_dapm_path *p, int i)
+{
+	struct soc_mixer_control *mc = (struct soc_mixer_control *)
+		w->kcontrol_news[i].private_value;
+	unsigned int reg = mc->reg;
+	unsigned int shift = mc->shift;
+	unsigned int max = mc->max;
+	unsigned int mask = (1 << fls(max)) - 1;
+	unsigned int invert = mc->invert;
+	unsigned int val;
+
+	if (reg != SND_SOC_NOPM) {
+		soc_widget_read(w, reg, &val);
+		val = (val >> shift) & mask;
+		if (invert)
+			val = max - val;
+		p->connect = !!val;
+	} else {
+		p->connect = 0;
+	}
+}
+
 /* connect mixer widget to its interconnecting audio paths */
 static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
 	struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
@@ -619,7 +574,7 @@ static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
 			list_add(&path->list_sink, &dest->sources);
 			list_add(&path->list_source, &src->sinks);
 			path->name = dest->kcontrol_news[i].name;
-			dapm_set_path_status(dest, path, i);
+			dapm_set_mixer_path_status(dest, path, i);
 			return 0;
 		}
 	}
-- 
1.8.0

  parent reply	other threads:[~2014-02-23 15:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-23 15:10 [PATCH 00/11] ASoC: Consolidate enum controls and DAPM MUXs Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 01/11] ASoC: Remove unused 'reg2' field from soc_enum struct Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 02/11] ASoC: Consolidate enum and value enum controls Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 03/11] ASoC: dapm: Consolidate MUXs and value MUXs Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 04/11] ASoC: Add macros for defining virtual enums Lars-Peter Clausen
2014-02-24  9:29   ` Takashi Iwai
2014-02-24 11:50     ` Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 05/11] ASoC: adau1373: Use SOC_ENUM_SINGLE_VIRT_DECL() Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 06/11] ASoC: max98090: " Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 07/11] ASoC: mc13783: " Lars-Peter Clausen
2014-02-24 14:28   ` Philippe Rétornaz
2014-02-28  7:19     ` Lars-Peter Clausen
2014-02-23 15:10 ` [PATCH 08/11] ASoC: wm8994: " Lars-Peter Clausen
2014-02-25  9:47   ` Charles Keepax
2014-02-23 15:10 ` [PATCH 09/11] ASoC: wm8995: " Lars-Peter Clausen
2014-02-25  9:47   ` Charles Keepax
2014-02-23 15:10 ` [PATCH 10/11] ASoC: dapm: Consolidate MUXs and virtual MUXs Lars-Peter Clausen
2014-02-23 15:10 ` Lars-Peter Clausen [this message]
2014-02-25  1:57 ` [PATCH 00/11] ASoC: Consolidate enum controls and DAPM MUXs 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=1393168221-23018-12-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=jerry.wong@maximintegrated.com \
    --cc=lgirdwood@gmail.com \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=philippe.retornaz@epfl.ch \
    --cc=s.trumtrar@pengutronix.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.