From patchwork Mon Sep 9 22:33:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 173367 Delivered-To: patch@linaro.org Received: by 2002:ac9:19ad:0:0:0:0:0 with SMTP id d45csp3921484oce; Mon, 9 Sep 2019 03:35:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiSRnVOnDetsrNVs0c1aoQKpyLF/mSviIpkqOXA5wrK9ilOPJQkT+dvHwfTl3qDCqzpWNA X-Received: by 2002:aa7:c586:: with SMTP id g6mr2672112edq.38.1568025305043; Mon, 09 Sep 2019 03:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568025305; cv=none; d=google.com; s=arc-20160816; b=u8UJj5aJz5b35l/RXJnPBYpZrrMmR3zMW6utJ1KaZIiwgCjch0bWTrGbDIuAB9iDWz G2uyaw07Gf2GSkAYO5dMrvq9BHC4tUDNbkr/R8C4u9TMpbpm5Ton+AOK2VwTaIqesz4X TDCxH0gVpZIr/gF6h34Ud502+Uc1V6KrWjPjL8OJrdJzB6NRk8QExHpmJ8zcBCoCABFQ QQ08wMTGt2zipJwbbs5y5j5HqvN0Hz4o+qJibiLf0t/QHYC5YsK+UNhTy9m3BSkJWUZV T4/JWwMpIjB/ueclmn/7fuqh2agR5c7LsYrq2aeCvDorby1nS+SnDHKFTXB81Fmvt35K Q73A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from; bh=DIFqQpxdM7PP+JjWiNSutETsH9olbS84r/055+79ibw=; b=J4z/B+JW1Rrch6uTrHCH2uC8aDgcQiEmdt9jWN3Sk5tBF0x3/XDrKUlOxJVHGG4d+N /wfdsHbMRFBJbiL3wwxFFAaGt996MBu0hXmj/Sv9GXCZdvX9Eng3VjXORt2/UFLp1i0R XTckP03wL4IpkXAZGZcXaKg0XmjkIxKxVYZX1wTm17WyEU7Aqy7JY+wYUPL9z62dM4kG lPL3tNF56qTSc+Hmg4C8klk5uywaAkibQQlDV+CIPFBpyTp9GtKEyBr4aZplbE5c38JH 6wYRmXT5xsghV7Jh8nxinYdDLpUoo1F1xQsFSzCwJf2uT/ErrjHZ9WQdGlWGZqsMpsuj RawA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si6151968edi.410.2019.09.09.03.35.04; Mon, 09 Sep 2019 03:35:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731637AbfIIKfB (ORCPT + 28 others); Mon, 9 Sep 2019 06:35:01 -0400 Received: from inva020.nxp.com ([92.121.34.13]:58252 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730682AbfIIKev (ORCPT ); Mon, 9 Sep 2019 06:34:51 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id C8ED21A001D; Mon, 9 Sep 2019 12:34:48 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A00171A003B; Mon, 9 Sep 2019 12:34:43 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 48A2F402F2; Mon, 9 Sep 2019 18:34:37 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] ASoC: fsl_asrc: Use in(out)put_format instead of in(out)put_word_width Date: Mon, 9 Sep 2019 18:33:19 -0400 Message-Id: <65e96ca15afd4a282b122f3ea8b13642cf4614c7.1568025083.git.shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org snd_pcm_format_t is more formal than enum asrc_word_width, which has two property, width and physical width, which is more accurate than enum asrc_word_width. So it is better to use in(out)put_format instead of in(out)put_word_width. Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_asrc.c | 56 +++++++++++++++++++++++++++------------- sound/soc/fsl/fsl_asrc.h | 4 +-- 2 files changed, 40 insertions(+), 20 deletions(-) -- 2.21.0 diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index cfa40ef6b1ca..4d3804a1ea55 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -265,6 +265,8 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) struct asrc_config *config = pair->config; struct fsl_asrc *asrc_priv = pair->asrc_priv; enum asrc_pair_index index = pair->index; + enum asrc_word_width input_word_width; + enum asrc_word_width output_word_width; u32 inrate, outrate, indiv, outdiv; u32 clk_index[2], div[2]; int in, out, channels; @@ -283,9 +285,32 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) return -EINVAL; } - /* Validate output width */ - if (config->output_word_width == ASRC_WIDTH_8_BIT) { - pair_err("does not support 8bit width output\n"); + switch (snd_pcm_format_width(config->input_format)) { + case 8: + input_word_width = ASRC_WIDTH_8_BIT; + break; + case 16: + input_word_width = ASRC_WIDTH_16_BIT; + break; + case 24: + input_word_width = ASRC_WIDTH_24_BIT; + break; + default: + pair_err("does not support this input format, %d\n", + config->input_format); + return -EINVAL; + } + + switch (snd_pcm_format_width(config->output_format)) { + case 16: + output_word_width = ASRC_WIDTH_16_BIT; + break; + case 24: + output_word_width = ASRC_WIDTH_24_BIT; + break; + default: + pair_err("does not support this output format, %d\n", + config->output_format); return -EINVAL; } @@ -383,8 +408,8 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) /* Implement word_width configurations */ regmap_update_bits(asrc_priv->regmap, REG_ASRMCR1(index), ASRMCR1i_OW16_MASK | ASRMCR1i_IWD_MASK, - ASRMCR1i_OW16(config->output_word_width) | - ASRMCR1i_IWD(config->input_word_width)); + ASRMCR1i_OW16(output_word_width) | + ASRMCR1i_IWD(input_word_width)); /* Enable BUFFER STALL */ regmap_update_bits(asrc_priv->regmap, REG_ASRMCR(index), @@ -497,13 +522,13 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai); - int width = params_width(params); struct snd_pcm_runtime *runtime = substream->runtime; struct fsl_asrc_pair *pair = runtime->private_data; unsigned int channels = params_channels(params); unsigned int rate = params_rate(params); struct asrc_config config; - int word_width, ret; + snd_pcm_format_t format; + int ret; ret = fsl_asrc_request_pair(channels, pair); if (ret) { @@ -513,15 +538,10 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream, pair->config = &config; - if (width == 16) - width = ASRC_WIDTH_16_BIT; - else - width = ASRC_WIDTH_24_BIT; - if (asrc_priv->asrc_width == 16) - word_width = ASRC_WIDTH_16_BIT; + format = SNDRV_PCM_FORMAT_S16_LE; else - word_width = ASRC_WIDTH_24_BIT; + format = SNDRV_PCM_FORMAT_S24_LE; config.pair = pair->index; config.channel_num = channels; @@ -529,13 +549,13 @@ static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream, config.outclk = OUTCLK_ASRCK1_CLK; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - config.input_word_width = width; - config.output_word_width = word_width; + config.input_format = params_format(params); + config.output_format = format; config.input_sample_rate = rate; config.output_sample_rate = asrc_priv->asrc_rate; } else { - config.input_word_width = word_width; - config.output_word_width = width; + config.input_format = format; + config.output_format = params_format(params); config.input_sample_rate = asrc_priv->asrc_rate; config.output_sample_rate = rate; } diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h index c60075112570..38af485bdd22 100644 --- a/sound/soc/fsl/fsl_asrc.h +++ b/sound/soc/fsl/fsl_asrc.h @@ -342,8 +342,8 @@ struct asrc_config { unsigned int dma_buffer_size; unsigned int input_sample_rate; unsigned int output_sample_rate; - enum asrc_word_width input_word_width; - enum asrc_word_width output_word_width; + snd_pcm_format_t input_format; + snd_pcm_format_t output_format; enum asrc_inclk inclk; enum asrc_outclk outclk; }; From patchwork Mon Sep 9 22:33:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 173365 Delivered-To: patch@linaro.org Received: by 2002:ac9:19ad:0:0:0:0:0 with SMTP id d45csp3921351oce; Mon, 9 Sep 2019 03:34:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxajY2xMpKa6zPuIpWj+X8C540h8fFwoyu1JJNdok1ti6SPm7Q8B65vmrO0qR0elzc6Zfii X-Received: by 2002:aa7:dacc:: with SMTP id x12mr17076264eds.116.1568025294336; Mon, 09 Sep 2019 03:34:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568025294; cv=none; d=google.com; s=arc-20160816; b=uqYTCYBZmJiU5O6qkTa7xbpWKD3Cax6GX7EB8BqYQKusTcz4JfHmhQepoy+h6f4sm4 JaYIyuGMt/NmAHLdDIbpuqPzJysJ/6nPrwbdak+YxqqmXC4WXwqJBmOfEJLnhJfwCXKK RuPVio09vfUZ2/APwKpOJhcJFHMQ59XyhSknXbo6WOoJA9Kv8GCkAOXlRVI9EdkzJf42 V9nG4wytEvXgn1nSkEtOPArTHl58sV9vXFUaaqyZT5jbZrDfyOlY5nKUkJza8/oD2ui8 pqj3tE03OioCPy8oN8fBWFoC30lHtt1WOiyEG+8RvhU8M11uL60EDR1hHmY8MMDw/GS8 ZAzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from; bh=E3azs1hVn5ybyTVGB0DwK0X5yX+rfxDbMRUleLk2Iqs=; b=JlQSixOkhy7UcYrihEGsVc1RVUmKr0+C2pGxC87Q1fCCysKxRdGQzyh6z3nq/iq+CF +BtyWi4pMp+gbLxrrFQcCop7Ze/8DDmPlKJfD1OouCJQj1J5mTCfGXG0fCLu36w1SNtv J1hUtaYA9kcZOpo+TzebE5uwJp90o8n2voxrpI6YbUXBuVBny6ag+rJnnlRumiKsMns/ vPhiU7Frs22uL4/yk7ClkrS0hlvCfTf+UZPb6ePeW1EOblWxkTKE/fWBuanh03Vk6PmR QRYpYkpJGCU0ICxUo5mp8TfrMrD03uDVZ3oCF6PMYXlsnFT0SwUTCUd7/u1YSgnJlpWq 6sZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l50si8339653edd.273.2019.09.09.03.34.54; Mon, 09 Sep 2019 03:34:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731153AbfIIKex (ORCPT + 28 others); Mon, 9 Sep 2019 06:34:53 -0400 Received: from inva021.nxp.com ([92.121.34.21]:34772 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730179AbfIIKeu (ORCPT ); Mon, 9 Sep 2019 06:34:50 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id BB17A200148; Mon, 9 Sep 2019 12:34:49 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C12212001C3; Mon, 9 Sep 2019 12:34:44 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 60346402F3; Mon, 9 Sep 2019 18:34:38 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] ASoC: fsl_asrc: update supported sample format Date: Mon, 9 Sep 2019 18:33:20 -0400 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ASRC support 24bit/16bit/8bit input width, so S20_3LE format should not be supported, it is word width is 20bit. So replace S20_3LE with S24_3LE in supported list and add S8 format in TX supported list Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_asrc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index 4d3804a1ea55..584badf956d2 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -624,7 +624,7 @@ static int fsl_asrc_dai_probe(struct snd_soc_dai *dai) #define FSL_ASRC_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | \ SNDRV_PCM_FMTBIT_S16_LE | \ - SNDRV_PCM_FMTBIT_S20_3LE) + SNDRV_PCM_FMTBIT_S24_3LE) static struct snd_soc_dai_driver fsl_asrc_dai = { .probe = fsl_asrc_dai_probe, @@ -635,7 +635,8 @@ static struct snd_soc_dai_driver fsl_asrc_dai = { .rate_min = 5512, .rate_max = 192000, .rates = SNDRV_PCM_RATE_KNOT, - .formats = FSL_ASRC_FORMATS, + .formats = FSL_ASRC_FORMATS | + SNDRV_PCM_FMTBIT_S8, }, .capture = { .stream_name = "ASRC-Capture", From patchwork Mon Sep 9 22:33:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 173366 Delivered-To: patch@linaro.org Received: by 2002:ac9:19ad:0:0:0:0:0 with SMTP id d45csp3921413oce; Mon, 9 Sep 2019 03:34:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+kc4riCQvZESumDia/DNwXhpK7Mv7pZHAJQrIRqWEpFVO2eFu5IYRwzi8tdtcvYFbEm5j X-Received: by 2002:a50:f38b:: with SMTP id g11mr23920168edm.292.1568025298596; Mon, 09 Sep 2019 03:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568025298; cv=none; d=google.com; s=arc-20160816; b=w/1YhqCrODr9kRIUv8ghpSma6V2HzEVn2hF/YcdslfwX7o4PPk/sePalbVJKyBMC14 2Ws/Uym9sqKPzUIlEjN/xUubYbZ0HWq/tCQP0YhPGyuQ2kINxvWWjaFlTHgKW/bKh6Np JjFo7lrTV/xNzEAQM4VpHLZBQRX+auQMu7jRK5SMjOSbvR0+0sNxNL3DtvAR0qDqo68Y XYQe3w16gnIsGB8PB9BevibOw1Gu2hlg3+5/oGkd4nL42ACR1QqgSlvqvEDxKC3GZ4iI lJ5mfCYXRS8et89MdHMiYIWtFcP6wPIflCHCPlVUk0aW/KavCUK2U77j76d5i/8AY4bI X4Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from; bh=qgKcnBoZTEXnoEEzf6nlQZfv9Tk53HCZ3wjKywHN+fQ=; b=EdfaMwiTTVWUh4WQIbzymi8bI1lJCz2zawc0L4rqwTVTl6Yx3xbqCPKJFiSdh7gNu/ IoAlOzqVLhKbbn2jSHUi0GuNwgUr9BCVg9swVSNMX1VVD/lYYYlvzxSHLPQK2MAd6tlS B6zNU+lpe1rKSjjFUpjGHxK9TAhtC2it5pAntvQY1sYFt+1e0iPx9oBfiXu3rn1x5vIC BxCuQHWbgfZB2avawO6ygXn+zkqYVpOQEA814wHn8jjriAKa/t+iUn4JfiC5xHGLlVlA Ew3G5QF5Eg9eG/PJfan2wFIw0TAZupO6yUm8kvK8nlc8dCJ9roqMwObkMrYAnj8vwwKd m7jA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l50si8339653edd.273.2019.09.09.03.34.58; Mon, 09 Sep 2019 03:34:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731481AbfIIKe5 (ORCPT + 28 others); Mon, 9 Sep 2019 06:34:57 -0400 Received: from inva020.nxp.com ([92.121.34.13]:58298 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730940AbfIIKew (ORCPT ); Mon, 9 Sep 2019 06:34:52 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 061931A0084; Mon, 9 Sep 2019 12:34:51 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D7CE31A018F; Mon, 9 Sep 2019 12:34:45 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 80C1A402AF; Mon, 9 Sep 2019 18:34:39 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] ASoC: fsl_asrc: Fix error with S24_3LE format bitstream in i.MX8 Date: Mon, 9 Sep 2019 18:33:21 -0400 Message-Id: <2b6e028ca27b8569da4ab7868d7b90ff8c3225d0.1568025083.git.shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is error "aplay: pcm_write:2023: write error: Input/output error" on i.MX8QM/i.MX8QXP platform for S24_3LE format. In i.MX8QM/i.MX8QXP, the DMA is EDMA, which don't support 24bit sample, but we didn't add any constraint, that cause issues. So we need to query the caps of dma, then update the hw parameters according to the caps. Signed-off-by: Shengjiu Wang --- sound/soc/fsl/fsl_asrc.c | 4 +- sound/soc/fsl/fsl_asrc.h | 3 ++ sound/soc/fsl/fsl_asrc_dma.c | 93 +++++++++++++++++++++++++++++++++--- 3 files changed, 92 insertions(+), 8 deletions(-) -- 2.21.0 diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index 584badf956d2..0bf91a6f54b9 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -115,7 +115,7 @@ static void fsl_asrc_sel_proc(int inrate, int outrate, * within range [ANCA, ANCA+ANCB-1], depends on the channels of pair A * while pair A and pair C are comparatively independent. */ -static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) +int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) { enum asrc_pair_index index = ASRC_INVALID_PAIR; struct fsl_asrc *asrc_priv = pair->asrc_priv; @@ -158,7 +158,7 @@ static int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair) * * It clears the resource from asrc_priv and releases the occupied channels. */ -static void fsl_asrc_release_pair(struct fsl_asrc_pair *pair) +void fsl_asrc_release_pair(struct fsl_asrc_pair *pair) { struct fsl_asrc *asrc_priv = pair->asrc_priv; enum asrc_pair_index index = pair->index; diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h index 38af485bdd22..2b57e8c53728 100644 --- a/sound/soc/fsl/fsl_asrc.h +++ b/sound/soc/fsl/fsl_asrc.h @@ -462,4 +462,7 @@ struct fsl_asrc { #define DRV_NAME "fsl-asrc-dai" extern struct snd_soc_component_driver fsl_asrc_component; struct dma_chan *fsl_asrc_get_dma_channel(struct fsl_asrc_pair *pair, bool dir); +int fsl_asrc_request_pair(int channels, struct fsl_asrc_pair *pair); +void fsl_asrc_release_pair(struct fsl_asrc_pair *pair); + #endif /* _FSL_ASRC_H */ diff --git a/sound/soc/fsl/fsl_asrc_dma.c b/sound/soc/fsl/fsl_asrc_dma.c index 01052a0808b0..30e27917016e 100644 --- a/sound/soc/fsl/fsl_asrc_dma.c +++ b/sound/soc/fsl/fsl_asrc_dma.c @@ -16,13 +16,11 @@ #define FSL_ASRC_DMABUF_SIZE (256 * 1024) -static const struct snd_pcm_hardware snd_imx_hardware = { +static struct snd_pcm_hardware snd_imx_hardware = { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | - SNDRV_PCM_INFO_MMAP_VALID | - SNDRV_PCM_INFO_PAUSE | - SNDRV_PCM_INFO_RESUME, + SNDRV_PCM_INFO_MMAP_VALID, .buffer_bytes_max = FSL_ASRC_DMABUF_SIZE, .period_bytes_min = 128, .period_bytes_max = 65535, /* Limited by SDMA engine */ @@ -276,6 +274,16 @@ static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) struct device *dev = component->dev; struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); struct fsl_asrc_pair *pair; + bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; + u8 dir = tx ? OUT : IN; + struct dma_slave_caps dma_caps; + struct dma_chan *tmp_chan; + struct snd_dmaengine_dai_dma_data *dma_data; + u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | + BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | + BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); + int ret; + int i; pair = kzalloc(sizeof(struct fsl_asrc_pair), GFP_KERNEL); if (!pair) @@ -285,8 +293,81 @@ static int fsl_asrc_dma_startup(struct snd_pcm_substream *substream) runtime->private_data = pair; - snd_pcm_hw_constraint_integer(substream->runtime, - SNDRV_PCM_HW_PARAM_PERIODS); + ret = snd_pcm_hw_constraint_integer(substream->runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (ret < 0) { + dev_err(dev, "failed to set pcm hw params periods\n"); + return ret; + } + + dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); + + /* Request a temp pair, which is release in the end */ + fsl_asrc_request_pair(1, pair); + + tmp_chan = fsl_asrc_get_dma_channel(pair, dir); + if (!tmp_chan) { + dev_err(dev, "can't get dma channel\n"); + return -EINVAL; + } + + ret = dma_get_slave_caps(tmp_chan, &dma_caps); + if (ret == 0) { + if (dma_caps.cmd_pause) + snd_imx_hardware.info |= SNDRV_PCM_INFO_PAUSE | + SNDRV_PCM_INFO_RESUME; + if (dma_caps.residue_granularity <= + DMA_RESIDUE_GRANULARITY_SEGMENT) + snd_imx_hardware.info |= SNDRV_PCM_INFO_BATCH; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + addr_widths = dma_caps.dst_addr_widths; + else + addr_widths = dma_caps.src_addr_widths; + } + + /* + * If SND_DMAENGINE_PCM_DAI_FLAG_PACK is set keep + * hw.formats set to 0, meaning no restrictions are in place. + * In this case it's the responsibility of the DAI driver to + * provide the supported format information. + */ + if (!(dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK)) + /* + * 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))) + snd_imx_hardware.formats |= (1LL << i); + break; + default: + /* Unsupported types */ + break; + } + } + + if (tmp_chan) + dma_release_channel(tmp_chan); + fsl_asrc_release_pair(pair); + snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware); return 0;