alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Matt Flax <flatmax@flatmax.org>
To: flatmax@flatmax.org
Cc: hias@horus.com, alsa-devel@alsa-project.org,
	Stephen Warren <swarren@wwwdotorg.org>,
	Lee Jones <lee@kernel.org>,
	phil@raspberrypi.org, Liam Girdwood <lgirdwood@gmail.com>,
	Eric Anholt <eric@anholt.net>,
	florian.kauer@koalo.de, broonie@kernel.org,
	Florian Meier <florian.meier@koalo.de>,
	linux-rpi-kernel@lists.infradead.org,
	ckeepax@opensource.wolfsonmicro.com,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] ASoC: bcm2835: Add mutichannel mode in DSP and IC master modes.
Date: Sat, 25 Feb 2017 16:03:14 +1100	[thread overview]
Message-ID: <32f49c14cda226c5011f30522ff376e604496f1d.1487997974.git.flatmax@flatmax.org> (raw)
In-Reply-To: <cover.1487997974.git.flatmax@flatmax.org>
In-Reply-To: <cover.1487997974.git.flatmax@flatmax.org>

This patch adds multitrack capability if in DSP mode A and an IC
(between the SoC and codec) is master.

In bcm2835_i2s_startup, snd_pcm_hw_constraint_single is used to set
channels to 8 if both SND_SOC_DAIFMT_IBM_IFM and SND_SOC_DAIFMT_DSP_A
are set. Otherwise, channels are set to 2. These settings are
accomplished using the SNDRV_PCM_HW_PARAM_CHANNELS variable.

This patch protects against DSP mode misuse by failing if either the
SoC or Codec is master. i.e. if SND_SOC_DAIFMT_DSP_A is chosen but not
in SND_SOC_DAIFMT_IBM_IFM mode, then -EINVAL is returned.

In bcm2835_i2s_shutdown the channels are set to 2 by default.

In bcm2835_i2s_hw_params, DSP mode A format is now an option.
Before replicating the format variable (from ch2 to ch1) for
register loading, requested channels are checked to be either 2 or 8.
This can be expanded later to accomodate other channel counts if
supported by the sound card hardware.

It has been tested to work with both a regular stereo sound card and
an 8 channel sound card.

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

diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 6ba2049..dbfecb3 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -296,6 +296,7 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 
 	switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_DSP_A:
 		data_delay = 1;
 		break;
 	default:
@@ -312,6 +313,7 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
 
 	switch (params_channels(params)) {
 	case 2:
+	case 8:
 		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));
@@ -526,7 +528,20 @@ static int bcm2835_i2s_startup(struct snd_pcm_substream *substream,
 	regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG,
 			BCM2835_I2S_STBY, BCM2835_I2S_STBY);
 
-	return 0;
+	/* Only allow 2 channels, unless in DSP mode where an IC (between 
+	 * the SoC and codec) is master.
+	 */
+	if ((dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK)
+					== SND_SOC_DAIFMT_DSP_A)
+		if ((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK)
+					!= SND_SOC_DAIFMT_IBM_IFM)
+			return -EINVAL;
+		else
+			return snd_pcm_hw_constraint_single(substream->runtime,
+						SNDRV_PCM_HW_PARAM_CHANNELS, 8);
+	else
+		return snd_pcm_hw_constraint_single(substream->runtime,
+			SNDRV_PCM_HW_PARAM_CHANNELS, 2);
 }
 
 static void bcm2835_i2s_shutdown(struct snd_pcm_substream *substream,
@@ -549,6 +564,10 @@ static void bcm2835_i2s_shutdown(struct snd_pcm_substream *substream,
 	 * not stop the clock when SND_SOC_DAIFMT_CONT
 	 */
 	bcm2835_i2s_stop_clock(dev);
+
+	/* Default to 2 channels */
+	snd_pcm_hw_constraint_single(substream->runtime,
+			SNDRV_PCM_HW_PARAM_CHANNELS, 2);
 }
 
 static const struct snd_soc_dai_ops bcm2835_i2s_dai_ops = {
-- 
2.7.4

  parent reply	other threads:[~2017-02-25  5:04 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-25  5:03 [PATCH 0/3] ASoC: Enable a new IC master mode: bcm2835<=>IC<=>cs42xx8 Matt Flax
2017-02-25  5:03 ` [PATCH 1/3] ASoC : Add an IC bit and frame master mode (SoC and Codec slave) Matt Flax
2017-03-15 19:02   ` Mark Brown
2017-02-25  5:03 ` [PATCH 2/3] ASoC: cs42xx8: allow IC master mode Matt Flax
2017-02-25  5:03 ` Matt Flax [this message]
2017-02-25 13:39 ` [PATCH 0/3] ASoC: Enable a new IC master mode: bcm2835<=>IC<=>cs42xx8 Matthias Reichl
2017-02-25 22:13   ` Matt Flax
2017-02-26 14:49     ` Matthias Reichl
2017-02-26 20:21       ` Matt Flax
2017-02-26 22:16         ` Matthias Reichl
2017-02-26 22:35           ` Matt Flax
2017-02-27  8:04             ` Matthias Reichl
2017-02-27 10:08               ` Matt Flax
2017-02-27 10:30                 ` Matthias Reichl
2017-02-27 11:21                   ` Matt Flax
2017-02-27 11:51                     ` Matthias Reichl
2017-02-28  9:59                       ` Charles Keepax
2017-03-15 19:01                         ` Mark Brown
2017-03-16 20:51                           ` Matt Flax
2017-03-16 21:27                             ` Lars-Peter Clausen
2017-03-16 22:14                               ` Matt Flax
2017-03-21 21:21                                 ` Emmanuel Fusté
2017-03-21 22:11                                   ` Matthias Reichl
2017-03-21 23:29                                     ` Matt Flax
2017-03-22  9:43                                       ` Charles Keepax
2017-03-22 12:04                                         ` Matt Flax
2017-03-22 12:34                                           ` [alsa-devel] " Charles Keepax
2017-03-22 15:38                                           ` Stephen Warren
2017-03-24 19:11                                             ` Mark Brown
2017-03-24 19:09                                           ` Mark Brown
2017-03-25  5:45                                             ` Matt Flax
2017-03-27 10:01                                               ` Mark Brown
2017-03-27 10:35                                                 ` Matt Flax
2017-03-27 11:30                                                   ` Mark Brown
2017-03-26 19:02                                     ` Emmanuel Fusté
2017-02-28 10:10         ` Charles Keepax
2017-02-26 20:41       ` Emmanuel Fusté
2017-02-26 21:44         ` Matt Flax
2017-02-26 22:49           ` Emmanuel Fusté
2017-02-27  9:14         ` Matthias Reichl
2017-02-27 18:19           ` Emmanuel Fusté
2017-02-27 19:12           ` Emmanuel Fusté

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=32f49c14cda226c5011f30522ff376e604496f1d.1487997974.git.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=florian.kauer@koalo.de \
    --cc=florian.meier@koalo.de \
    --cc=hias@horus.com \
    --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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).