alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint
@ 2012-01-18  9:51 Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI Peter Ujfalusi
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

Hi Mark,

Changes from v2:
- initialize ret to zero in soc_pcm_apply_msb

I would prefer to have the msbits constraints to be applied to only sample sizes
bigger than the requested msbits from dais.
I'm resending your patch plus the modification which will make the possible.
I have also converted the drivers I know have this constraint.

If you prefer, you can squash the first two patch.

Regards,
Peter
---
Mark Brown (2):
  ASoC: Allow drivers to specify how many bits are significant on a DAI
  ASoC: 24 bits are significant on the WM8996 audio interfaces

Peter Ujfalusi (5):
  ASoC: Apply msbits constraint for sample size bigger than the msbits
  ASoC: omap-dmic: Use core to set the msbits constraint
  ASoC: omap-mcpdm: Set 24msbits constraint
  ASoC: tlv320dac33: Use core to set the msbits constraint
  ASoC: twl4030: Use core to set the msbits constraint

 include/sound/soc.h            |    1 +
 sound/soc/codecs/tlv320dac33.c |    3 +--
 sound/soc/codecs/twl4030.c     |    7 ++++---
 sound/soc/codecs/wm8996.c      |    4 ++++
 sound/soc/omap/omap-dmic.c     |    7 +++----
 sound/soc/omap/omap-mcpdm.c    |    2 ++
 sound/soc/soc-pcm.c            |   39 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 54 insertions(+), 9 deletions(-)

-- 
1.7.8.3

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

* [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18 10:41   ` Mark Brown
  2012-01-18  9:51 ` [PATCH v3 2/7] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

From: Mark Brown <broonie@opensource.wolfsonmicro.com>

Most devices accept data in formats that don't correspond directly to
their internal format. ALSA allows us to set a msbits constraint which
tells userspace about this in case it finds it useful (for example, in
order to avoid wasting effort dithering bits that will be ignored when
raising the sample size of data) so provide a mechanism for drivers to
specify the number of bits that are actually significant on a DAI and
add the appropriate constraints along with all the others.

This is done slightly awkwardly as the constraint is specified per sample
size - we loop over every possible sample size, including ones that the
device doesn't support and including ones that have fewer bits than are
actually used, but this is harmless as the upper layers do the right thing
in these cases.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 include/sound/soc.h |    1 +
 sound/soc/soc-pcm.c |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 0992dff..55381fc 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -505,6 +505,7 @@ struct snd_soc_pcm_stream {
 	unsigned int rate_max;		/* max rate */
 	unsigned int channels_min;	/* min channels */
 	unsigned int channels_max;	/* max channels */
+	unsigned int sig_bits;		/* number of bits of content */
 };
 
 /* SoC audio ops */
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index cdc860a..8bb1793 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -63,6 +63,39 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
 }
 
 /*
+ * List of sample sizes that might go over the bus for parameter
+ * application.  There ought to be a wildcard sample size for things
+ * like the DAC/ADC resolution to use but there isn't right now.
+ */
+static int sample_sizes[] = {
+	8, 16, 24, 32,
+};
+
+static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
+			      struct snd_soc_dai *dai)
+{
+	int ret, i, bits;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		bits = dai->driver->playback.sig_bits;
+	else
+		bits = dai->driver->capture.sig_bits;
+
+	if (!bits)
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
+		ret = snd_pcm_hw_constraint_msbits(substream->runtime,
+						   0, sample_sizes[i],
+						   bits);
+		if (ret != 0)
+			dev_warn(dai->dev,
+				 "Failed to set MSB %d/%d: %d\n",
+				 bits, sample_sizes[i], ret);
+	}
+}
+
+/*
  * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  * then initialized and any private data can be allocated. This also calls
  * startup for the cpu DAI, platform, machine and codec DAI.
@@ -187,6 +220,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 		goto config_err;
 	}
 
+	soc_pcm_apply_msb(substream, codec_dai);
+	soc_pcm_apply_msb(substream, cpu_dai);
+
 	/* Symmetry only applies if we've already got an active stream. */
 	if (cpu_dai->active) {
 		ret = soc_pcm_apply_symmetry(substream, cpu_dai);
-- 
1.7.8.3

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

* [PATCH v3 2/7] ASoC: Apply msbits constraint for sample size bigger than the msbits
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 3/7] ASoC: 24 bits are significant on the WM8996 audio interfaces Peter Ujfalusi
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

In order to avoid confusing the applications with msbits bigger
than the selected sample size apply the msbits constraint only
to sample seze bigger than the requested msbits.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/soc-pcm.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 8bb1793..e150ede 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -68,13 +68,14 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
  * like the DAC/ADC resolution to use but there isn't right now.
  */
 static int sample_sizes[] = {
-	8, 16, 24, 32,
+	32, 24, 16, 8,
 };
 
 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 			      struct snd_soc_dai *dai)
 {
-	int ret, i, bits;
+	int i, bits;
+	int ret = 0;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		bits = dai->driver->playback.sig_bits;
@@ -85,6 +86,8 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
+		if (sample_sizes[i] <= bits)
+			break;
 		ret = snd_pcm_hw_constraint_msbits(substream->runtime,
 						   0, sample_sizes[i],
 						   bits);
-- 
1.7.8.3

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

* [PATCH v3 3/7] ASoC: 24 bits are significant on the WM8996 audio interfaces
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 2/7] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 4/7] ASoC: omap-dmic: Use core to set the msbits constraint Peter Ujfalusi
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

From: Mark Brown <broonie@opensource.wolfsonmicro.com>

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 sound/soc/codecs/wm8996.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index d8da10f..691ae4e 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -3082,6 +3082,7 @@ static struct snd_soc_dai_driver wm8996_dai[] = {
 			.channels_max = 6,
 			.rates = WM8996_RATES,
 			.formats = WM8996_FORMATS,
+			.sig_bits = 24,
 		},
 		.capture = {
 			 .stream_name = "AIF1 Capture",
@@ -3089,6 +3090,7 @@ static struct snd_soc_dai_driver wm8996_dai[] = {
 			 .channels_max = 6,
 			 .rates = WM8996_RATES,
 			 .formats = WM8996_FORMATS,
+			 .sig_bits = 24,
 		 },
 		.ops = &wm8996_dai_ops,
 	},
@@ -3100,6 +3102,7 @@ static struct snd_soc_dai_driver wm8996_dai[] = {
 			.channels_max = 2,
 			.rates = WM8996_RATES,
 			.formats = WM8996_FORMATS,
+			.sig_bits = 24,
 		},
 		.capture = {
 			 .stream_name = "AIF2 Capture",
@@ -3107,6 +3110,7 @@ static struct snd_soc_dai_driver wm8996_dai[] = {
 			 .channels_max = 2,
 			 .rates = WM8996_RATES,
 			 .formats = WM8996_FORMATS,
+			.sig_bits = 24,
 		 },
 		.ops = &wm8996_dai_ops,
 	},
-- 
1.7.8.3

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

* [PATCH v3 4/7] ASoC: omap-dmic: Use core to set the msbits constraint
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
                   ` (2 preceding siblings ...)
  2012-01-18  9:51 ` [PATCH v3 3/7] ASoC: 24 bits are significant on the WM8996 audio interfaces Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 5/7] ASoC: omap-mcpdm: Set 24msbits constraint Peter Ujfalusi
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

Core can set the msbits constraint in behalf of the dai.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/omap/omap-dmic.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/sound/soc/omap/omap-dmic.c b/sound/soc/omap/omap-dmic.c
index 0855c1c..4dcb5a7 100644
--- a/sound/soc/omap/omap-dmic.c
+++ b/sound/soc/omap/omap-dmic.c
@@ -113,12 +113,10 @@ static int omap_dmic_dai_startup(struct snd_pcm_substream *substream,
 
 	mutex_lock(&dmic->mutex);
 
-	if (!dai->active) {
-		snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
+	if (!dai->active)
 		dmic->active = 1;
-	} else {
+	else
 		ret = -EBUSY;
-	}
 
 	mutex_unlock(&dmic->mutex);
 
@@ -445,6 +443,7 @@ static struct snd_soc_dai_driver omap_dmic_dai = {
 		.channels_max = 6,
 		.rates = SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000,
 		.formats = SNDRV_PCM_FMTBIT_S32_LE,
+		.sig_bits = 24,
 	},
 	.ops = &omap_dmic_dai_ops,
 };
-- 
1.7.8.3

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

* [PATCH v3 5/7] ASoC: omap-mcpdm: Set 24msbits constraint
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
                   ` (3 preceding siblings ...)
  2012-01-18  9:51 ` [PATCH v3 4/7] ASoC: omap-dmic: Use core to set the msbits constraint Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 6/7] ASoC: tlv320dac33: Use core to set the msbits constraint Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 7/7] ASoC: twl4030: " Peter Ujfalusi
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

McPDM internal FIFO is 24 bit wide. From the 32 bit sample
8 bit is discarded. Let application know about this
via msbits constraint.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/omap/omap-mcpdm.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/sound/soc/omap/omap-mcpdm.c b/sound/soc/omap/omap-mcpdm.c
index 0e25df4..3970556 100644
--- a/sound/soc/omap/omap-mcpdm.c
+++ b/sound/soc/omap/omap-mcpdm.c
@@ -419,12 +419,14 @@ static struct snd_soc_dai_driver omap_mcpdm_dai = {
 		.channels_max = 5,
 		.rates = OMAP_MCPDM_RATES,
 		.formats = OMAP_MCPDM_FORMATS,
+		.sig_bits = 24,
 	},
 	.capture = {
 		.channels_min = 1,
 		.channels_max = 3,
 		.rates = OMAP_MCPDM_RATES,
 		.formats = OMAP_MCPDM_FORMATS,
+		.sig_bits = 24,
 	},
 	.ops = &omap_mcpdm_dai_ops,
 };
-- 
1.7.8.3

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

* [PATCH v3 6/7] ASoC: tlv320dac33: Use core to set the msbits constraint
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
                   ` (4 preceding siblings ...)
  2012-01-18  9:51 ` [PATCH v3 5/7] ASoC: omap-mcpdm: Set 24msbits constraint Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  2012-01-18  9:51 ` [PATCH v3 7/7] ASoC: twl4030: " Peter Ujfalusi
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

Core can set the msbits constraint in behalf of the dai.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/tlv320dac33.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index f0aad26..21ccf0a 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -806,8 +806,6 @@ static int dac33_startup(struct snd_pcm_substream *substream,
 	/* Stream started, save the substream pointer */
 	dac33->substream = substream;
 
-	snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
-
 	return 0;
 }
 
@@ -1516,6 +1514,7 @@ static struct snd_soc_dai_driver dac33_dai = {
 		.channels_max = 2,
 		.rates = DAC33_RATES,
 		.formats = DAC33_FORMATS,},
+		.sig_bits = 24,
 	.ops = &dac33_dai_ops,
 };
 
-- 
1.7.8.3

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

* [PATCH v3 7/7] ASoC: twl4030: Use core to set the msbits constraint
  2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
                   ` (5 preceding siblings ...)
  2012-01-18  9:51 ` [PATCH v3 6/7] ASoC: tlv320dac33: Use core to set the msbits constraint Peter Ujfalusi
@ 2012-01-18  9:51 ` Peter Ujfalusi
  6 siblings, 0 replies; 9+ messages in thread
From: Peter Ujfalusi @ 2012-01-18  9:51 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood; +Cc: alsa-devel

Core can set the msbits constraint in behalf of the dai.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
---
 sound/soc/codecs/twl4030.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 18e7101..a193f5f 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -1689,7 +1689,6 @@ static int twl4030_startup(struct snd_pcm_substream *substream,
 	struct snd_soc_codec *codec = rtd->codec;
 	struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
-	snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
 	if (twl4030->master_substream) {
 		twl4030->slave_substream = substream;
 		/* The DAI has one configuration for playback and capture, so
@@ -2175,13 +2174,15 @@ static struct snd_soc_dai_driver twl4030_dai[] = {
 		.channels_min = 2,
 		.channels_max = 4,
 		.rates = TWL4030_RATES | SNDRV_PCM_RATE_96000,
-		.formats = TWL4030_FORMATS,},
+		.formats = TWL4030_FORMATS,
+		.sig_bits = 24,},
 	.capture = {
 		.stream_name = "Capture",
 		.channels_min = 2,
 		.channels_max = 4,
 		.rates = TWL4030_RATES,
-		.formats = TWL4030_FORMATS,},
+		.formats = TWL4030_FORMATS,
+		.sig_bits = 24,},
 	.ops = &twl4030_dai_hifi_ops,
 },
 {
-- 
1.7.8.3

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

* Re: [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI
  2012-01-18  9:51 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI Peter Ujfalusi
@ 2012-01-18 10:41   ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2012-01-18 10:41 UTC (permalink / raw)
  To: Peter Ujfalusi; +Cc: alsa-devel, Liam Girdwood

On Wed, Jan 18, 2012 at 10:51:02AM +0100, Peter Ujfalusi wrote:
> From: Mark Brown <broonie@opensource.wolfsonmicro.com>
> 
> Most devices accept data in formats that don't correspond directly to
> their internal format. ALSA allows us to set a msbits constraint which

Resend this against for-3.4.

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

end of thread, other threads:[~2012-01-18 10:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18  9:51 [PATCH v3 0/7] ASoC: Add support in core to set msbits constraint Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI Peter Ujfalusi
2012-01-18 10:41   ` Mark Brown
2012-01-18  9:51 ` [PATCH v3 2/7] ASoC: Apply msbits constraint for sample size bigger than the msbits Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 3/7] ASoC: 24 bits are significant on the WM8996 audio interfaces Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 4/7] ASoC: omap-dmic: Use core to set the msbits constraint Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 5/7] ASoC: omap-mcpdm: Set 24msbits constraint Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 6/7] ASoC: tlv320dac33: Use core to set the msbits constraint Peter Ujfalusi
2012-01-18  9:51 ` [PATCH v3 7/7] ASoC: twl4030: " Peter Ujfalusi

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).