From patchwork Thu Jul 3 04:51:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 4469331 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 97D519F36A for ; Thu, 3 Jul 2014 04:53:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B26F4203AA for ; Thu, 3 Jul 2014 04:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFB3F203A1 for ; Thu, 3 Jul 2014 04:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbaGCEwU (ORCPT ); Thu, 3 Jul 2014 00:52:20 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:47464 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbaGCEwR (ORCPT ); Thu, 3 Jul 2014 00:52:17 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s634qApp020873; Wed, 2 Jul 2014 23:52:10 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s634qARg025079; Wed, 2 Jul 2014 23:52:10 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Wed, 2 Jul 2014 23:52:10 -0500 Received: from szilva.Elisa (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s634puTC028101; Wed, 2 Jul 2014 23:52:07 -0500 From: Peter Ujfalusi To: , , , , Mark Brown , Liam Girdwood , , CC: , , Subject: [PATCH v3 3/5] ASoC: generic-dmaengine-pcm: Prepare formats mask for valid physical sample sizes Date: Thu, 3 Jul 2014 07:51:54 +0300 Message-ID: <1404363116-10538-4-git-send-email-peter.ujfalusi@ti.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1404363116-10538-1-git-send-email-peter.ujfalusi@ti.com> References: <1404363116-10538-1-git-send-email-peter.ujfalusi@ti.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 Based on the dma_slave_caps's addr_widths queried from the dma driver prepare the hw.formats mask to include only formats which is supported by the DMA engine. In case the dma driver does not implement the slave_caps the default assumption is that it supports 1, 2 and 4 bytes widths. Signed-off-by: Peter Ujfalusi Acked-by: Lars-Peter Clausen Acked-by: Mark Brown --- I know that the format validation could be done like this: + if (bits > 0 && bits <=64 && !(bits % 8) && + (addr_widths & (1 << (bits / 8)))) + hw.formats |= (1LL << i); But I think the switch() implementation is more readable. sound/soc/soc-generic-dmaengine-pcm.c | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index 5bace124ef43..6307f85e871b 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -119,7 +119,10 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea struct snd_dmaengine_dai_dma_data *dma_data; struct dma_slave_caps dma_caps; struct snd_pcm_hardware hw; - int ret; + u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | + BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | + BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); + int i, ret; if (pcm->config && pcm->config->pcm_hardware) return snd_soc_set_runtime_hwparams(substream, @@ -146,6 +149,38 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea 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; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + addr_widths = dma_caps.dstn_addr_widths; + else + addr_widths = dma_caps.src_addr_widths; + } + + /* + * Prepare formats mask for valid/allowed sample types. If the dma does + * not have support for the given physical word size, it needs to be + * masked out so user space can not use the format which produces + * corrupted audio. + * In case the dma driver does not implement the slave_caps the default + * assumption is that it supports 1, 2 and 4 bytes widths. + */ + for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { + int bits = snd_pcm_format_physical_width(i); + + /* Enable only samples with DMA supported physical widths */ + switch (bits) { + case 8: + case 16: + case 24: + case 32: + case 64: + if (addr_widths & (1 << (bits / 8))) + hw.formats |= (1LL << i); + break; + default: + /* Unsupported types */ + break; + } } return snd_soc_set_runtime_hwparams(substream, &hw);