From: Lars-Peter Clausen <lars@metafoo.de>
To: Vinod Koul <vinod.koul@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>, Takashi Iwai <tiwai@suse.de>
Cc: dmaengine@vger.kernel.org, alsa-devel@alsa-project.org,
Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 3/3] ASoC: generic-dmaengine-pcm: Check DMA residue granularity
Date: Sun, 8 Dec 2013 17:18:09 +0100 [thread overview]
Message-ID: <1386519489-1935-4-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1386519489-1935-1-git-send-email-lars@metafoo.de>
The dmaengine framework now exposes the granularity with which it is able to
report the transfer residue for a certain DMA channel. Check the granularity in
the generic dmaengine PCM driver and
a) Set the SNDRV_PCM_INFO_BATCH if the granularity is per period or worse.
b) Fallback to the (race condition prone) period counting if the driver does
not support any residue reporting.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
sound/soc/soc-generic-dmaengine-pcm.c | 37 +++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 87e8635..7bdee7b 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -144,6 +144,8 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
if (ret == 0) {
if (dma_caps.cmd_pause)
hw.info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
+ if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
+ hw.info |= SNDRV_PCM_INFO_BATCH;
}
return snd_soc_set_runtime_hwparams(substream, &hw);
@@ -282,6 +284,27 @@ static const struct snd_soc_platform_driver dmaengine_no_residue_pcm_platform =
.probe_order = SND_SOC_COMP_ORDER_LATE,
};
+static bool dmaengine_pcm_can_report_residue(struct dmaengine_pcm *pcm)
+{
+ struct dma_slave_caps dma_caps;
+ int ret;
+ int i;
+
+ for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) {
+ if (!pcm->chan[i])
+ continue;
+
+ ret = dma_get_slave_caps(pcm->chan[i], &dma_caps);
+ if (ret != 0)
+ continue;
+
+ if (dma_caps.residue_granularity == DMA_RESIDUE_GRANULARITY_DESCRIPTOR)
+ return false;
+ }
+
+ return true;
+}
+
static const char * const dmaengine_pcm_dma_channel_names[] = {
[SNDRV_PCM_STREAM_PLAYBACK] = "tx",
[SNDRV_PCM_STREAM_CAPTURE] = "rx",
@@ -323,11 +346,21 @@ int snd_dmaengine_pcm_register(struct device *dev,
if (!pcm)
return -ENOMEM;
+ dmaengine_pcm_request_chan_of(pcm, dev);
+
+ /*
+ * This will only return false if we know for sure that at least one
+ * channel does not support residue reporting. If the compat path is
+ * used for requesting the channels or the dma driver does not implement
+ * the slave_caps API we rely on the caller to set the NO_RESIDUE flag
+ * in case residue reporting is not supported.
+ */
+ if (!dmaengine_pcm_can_report_residue(pcm))
+ flags |= SND_DMAENGINE_PCM_FLAG_NO_RESIDUE;
+
pcm->config = config;
pcm->flags = flags;
- dmaengine_pcm_request_chan_of(pcm, dev);
-
if (flags & SND_DMAENGINE_PCM_FLAG_NO_RESIDUE)
return snd_soc_add_platform(dev, &pcm->platform,
&dmaengine_no_residue_pcm_platform);
--
1.8.0
next prev parent reply other threads:[~2013-12-08 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-08 16:18 [PATCH 0/3] dma: Indicate residue granularity in dma_slave_caps Lars-Peter Clausen
2013-12-08 16:18 ` [PATCH 1/3] " Lars-Peter Clausen
2013-12-08 16:18 ` [PATCH 2/3] dma: pl330: Set residue_granularity Lars-Peter Clausen
2013-12-08 16:18 ` Lars-Peter Clausen [this message]
2013-12-09 17:13 ` [PATCH 0/3] dma: Indicate residue granularity in dma_slave_caps 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=1386519489-1935-4-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=tiwai@suse.de \
--cc=vinod.koul@intel.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).