From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@ti.com>
Cc: alsa-devel@alsa-project.org
Subject: [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI
Date: Wed, 18 Jan 2012 10:51:02 +0100 [thread overview]
Message-ID: <1326880268-3509-2-git-send-email-peter.ujfalusi@ti.com> (raw)
In-Reply-To: <1326880268-3509-1-git-send-email-peter.ujfalusi@ti.com>
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
next prev parent reply other threads:[~2012-01-18 9:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2012-01-18 10:41 ` [PATCH v3 1/7] ASoC: Allow drivers to specify how many bits are significant on a DAI 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
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=1326880268-3509-2-git-send-email-peter.ujfalusi@ti.com \
--to=peter.ujfalusi@ti.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=lrg@ti.com \
/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).