All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Flax <flatmax@flatmax.org>
To: alsa-devel@alsa-project.org,
	Stephen Warren <swarren@wwwdotorg.org>,
	Lee Jones <lee@kernel.org>, Eric Anholt <eric@anholt.net>,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	Florian Meier <florian.meier@koalo.de>,
	broonie@kernel.org, phil@raspberrypi.org, hias@horus.com,
	ckeepax@opensource.wolfsonmicro.com, florian.kauer@koalo.de,
	Liam Girdwood <lgirdwood@gmail.com>,
	Martin Sperl <kernel@martin.sperl.org>,
	Scott Branden <sbranden@broadcom.com>,
	Ray Jui <rjui@broadcom.com>,
	Florian Fainelli <f.fainelli@gmail.com>
Cc: Matt Flax <flatmax@flatmax.org>
Subject: [PATCH] ASoC: bcm_2835: Simplify mono guard by returning error on mono
Date: Wed,  8 Mar 2017 21:58:54 +1100	[thread overview]
Message-ID: <1488970734-6596-1-git-send-email-flatmax@flatmax.org> (raw)

This patch simplifies the bcm2835_i2s.c code when the driver returns
error on mono channel requests. It does this by testing for mono
instead of using a switch statement to test for stereo.

The bcm2835_i2s driver can only work in stereo mode. Whilst leaving
the driver entirel compliant with the I2S protocol, it simplifies the
code by removing a few redundant lines of code.

Signed-off-by: Matt Flax <flatmax@flatmax.org>
---
 sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 6ba2049..1e6a1da 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 	ch1pos = data_delay;
 	ch2pos = bclk_ratio / 2 + data_delay;
 
-	switch (params_channels(params)) {
-	case 2:
-		format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format);
-		format |= BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(ch1pos));
-		format |= BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(ch2pos));
-		break;
-	default:
+	/* C
+	 * Check we aren't setting channel 2 on a mono stream.
+	 * We currently only support stereo
+	 */
+	if (params_channels(params) == 1)
 		return -EINVAL;
-	}
+
+	format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format);
+	format |= BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(ch1pos));
+	format |= BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(ch2pos));
 
 	/*
 	 * Set format for both streams.
-- 
2.7.4

WARNING: multiple messages have this Message-ID (diff)
From: flatmax@flatmax.org (Matt Flax)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ASoC: bcm_2835: Simplify mono guard by returning error on mono
Date: Wed,  8 Mar 2017 21:58:54 +1100	[thread overview]
Message-ID: <1488970734-6596-1-git-send-email-flatmax@flatmax.org> (raw)

This patch simplifies the bcm2835_i2s.c code when the driver returns
error on mono channel requests. It does this by testing for mono
instead of using a switch statement to test for stereo.

The bcm2835_i2s driver can only work in stereo mode. Whilst leaving
the driver entirel compliant with the I2S protocol, it simplifies the
code by removing a few redundant lines of code.

Signed-off-by: Matt Flax <flatmax@flatmax.org>
---
 sound/soc/bcm/bcm2835-i2s.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 6ba2049..1e6a1da 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -310,15 +310,16 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 	ch1pos = data_delay;
 	ch2pos = bclk_ratio / 2 + data_delay;
 
-	switch (params_channels(params)) {
-	case 2:
-		format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format);
-		format |= BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(ch1pos));
-		format |= BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(ch2pos));
-		break;
-	default:
+	/* C
+	 * Check we aren't setting channel 2 on a mono stream.
+	 * We currently only support stereo
+	 */
+	if (params_channels(params) == 1)
 		return -EINVAL;
-	}
+
+	format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format);
+	format |= BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(ch1pos));
+	format |= BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(ch2pos));
 
 	/*
 	 * Set format for both streams.
-- 
2.7.4

             reply	other threads:[~2017-03-08 10:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 10:58 Matt Flax [this message]
2017-03-08 10:58 ` [PATCH] ASoC: bcm_2835: Simplify mono guard by returning error on mono Matt Flax
2017-03-08 11:13 ` Florian Kauer
2017-03-08 11:13   ` Florian Kauer
2017-03-08 11:35   ` Matt Flax
2017-03-08 11:35     ` [alsa-devel] " Matt Flax
2017-03-08 11:33 ` Matthias Reichl
2017-03-08 11:33   ` Matthias Reichl
2017-03-08 11:43   ` Matt Flax
2017-03-08 11:43     ` [alsa-devel] " Matt Flax
2017-03-08 12:00     ` Matthias Reichl
2017-03-08 12:00       ` [alsa-devel] " Matthias Reichl

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=1488970734-6596-1-git-send-email-flatmax@flatmax.org \
    --to=flatmax@flatmax.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=florian.kauer@koalo.de \
    --cc=florian.meier@koalo.de \
    --cc=hias@horus.com \
    --cc=kernel@martin.sperl.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=phil@raspberrypi.org \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=swarren@wwwdotorg.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.