From patchwork Sun Dec 8 16:18:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 3307271 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B6EAFC0D4A for ; Sun, 8 Dec 2013 16:17:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E10F02024F for ; Sun, 8 Dec 2013 16:17:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C7DB2021E for ; Sun, 8 Dec 2013 16:17:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754987Ab3LHQR2 (ORCPT ); Sun, 8 Dec 2013 11:17:28 -0500 Received: from smtp-out-205.synserver.de ([212.40.185.205]:1157 "EHLO smtp-out-151.synserver.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759377Ab3LHQR2 (ORCPT ); Sun, 8 Dec 2013 11:17:28 -0500 Received: (qmail 11547 invoked by uid 0); 8 Dec 2013 16:17:26 -0000 X-SynServer-TrustedSrc: 1 X-SynServer-AuthUser: lars@metafoo.de X-SynServer-PPID: 11221 Received: from ppp-83-171-154-177.dynamic.mnet-online.de (HELO lars-adi-laptop.fritz.box) [83.171.154.177] by 217.119.54.81 with SMTP; 8 Dec 2013 16:17:25 -0000 From: Lars-Peter Clausen To: Vinod Koul , Dan Williams , Mark Brown , Liam Girdwood , Takashi Iwai Cc: dmaengine@vger.kernel.org, alsa-devel@alsa-project.org, Lars-Peter Clausen Subject: [PATCH 3/3] ASoC: generic-dmaengine-pcm: Check DMA residue granularity Date: Sun, 8 Dec 2013 17:18:09 +0100 Message-Id: <1386519489-1935-4-git-send-email-lars@metafoo.de> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1386519489-1935-1-git-send-email-lars@metafoo.de> References: <1386519489-1935-1-git-send-email-lars@metafoo.de> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);