Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1941293ybi; Thu, 20 Jun 2019 06:33:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrYbkrhmLN8RUWsk+crkQ62GQ26jZSB+RZi7770o5yP2t/Zw2ZXr9wxlZggbwIlCTM3Gjt X-Received: by 2002:a63:6a49:: with SMTP id f70mr12684634pgc.55.1561037584220; Thu, 20 Jun 2019 06:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561037584; cv=none; d=google.com; s=arc-20160816; b=Y60mF6B0E7N6o4Ez82aZkz//xTxsRUeoaPJO6ZSENLzRI6CDu4pLBIpFbjh9X4IOnF /07jts6Z2CQHbXv0iSrUflP9BqXkAZfSoikh3SFVmG+g43uIZn5rZXE3i8nG4XGnAnm5 Xe83Jb4Qt8AFOGdZUbA1HL6RikYDwlivCyUeZ2a+7nJ2MadOA1iJ6H5PehTr7oBooQYv 3nY3OlbeEtuO+WNTuHMI7acUVD5mgTVREoNWcPhsJjxpU2IjLS3Pcb0VGb1bJcVvRZI2 7TpD7zoNhifsAAmgYSZT9nA0dBKimJAFtbSJ5QvIgRF6vWrpRE+107JSVR2+pOcA7rln iRsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature; bh=Xmh5kmupsYkZefSvmh0+GLUxUu6Ox/qAde76AztFzu4=; b=h8KqcnmkbQPJm3RVbopb3a+9mtHHd54ws6gV6fkxZgEv7R4h+usrqoGEWLcEqja3eZ AiJhCCVjFyhKW59gJlESWnTobYVSTDfBbR7HH7bveyrPftLEhbpoDzPkcitDYbykGR8/ izQjZ/Ft94TTEokHE03brMQNpEwMAeg1hUe3oNi1jJ/t5+fDq9Q8WLzp1YiwntMvcxLU lPJhjx+kobKf8Xvu/Bf94m8BMFXQDqKerhmAQ6sh+clZmySOqAEnTi+cpJL0eEK/YIga M7Auqfwvxt+g0hpUFChUTR1DU/xTYy6Qc6y+GtNn/WlIaF8LD3BB2xbnL7FxfEmDuoCq zOTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=Sekp60hr; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g22si5771480pgb.107.2019.06.20.06.32.48; Thu, 20 Jun 2019 06:33:04 -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; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=Sekp60hr; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731798AbfFTNch (ORCPT + 99 others); Thu, 20 Jun 2019 09:32:37 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:59216 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731747AbfFTNcf (ORCPT ); Thu, 20 Jun 2019 09:32:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=Xmh5kmupsYkZefSvmh0+GLUxUu6Ox/qAde76AztFzu4=; b=Sekp60hrd2xU NaNS8uehgVfNNmU7fz0afMhE/ijpwcij5kGZqeYgJ8jKgq7tnqLmGhVpAUyVrTZiMCO24bpzmvdwI cw9IrkK86Vph290bcxyVQNkq1/3kTy+kHwglnRKCFsJ/ASBE4WFx/acJniTFIeGMi7iqLQdzvYmpI WOcOQ=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=finisterre.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hdxAw-0000jB-TU; Thu, 20 Jun 2019 13:32:27 +0000 Received: by finisterre.sirena.org.uk (Postfix, from userid 1000) id 587E544004B; Thu, 20 Jun 2019 14:32:26 +0100 (BST) From: Mark Brown To: Olivier Moysan Cc: alexandre.torgue@st.com, alsa-devel@alsa-project.org, arnaud.pouliquen@st.com, benjamin.gaignard@st.com, broonie@kernel.org, lgirdwood@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Mark Brown , mcoquelin.stm32@gmail.com, olivier.moysan@st.com, perex@perex.cz, tiwai@suse.com Subject: Applied "ASoC: stm32: dfsdm: add 16 bits audio record support" to the asoc tree In-Reply-To: <1560944402-8115-1-git-send-email-olivier.moysan@st.com> X-Patchwork-Hint: ignore Message-Id: <20190620133226.587E544004B@finisterre.sirena.org.uk> Date: Thu, 20 Jun 2019 14:32:26 +0100 (BST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch ASoC: stm32: dfsdm: add 16 bits audio record support has been applied to the asoc tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.3 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 1e7f6e1c69f0ff35c90878f9b44adcff77995eb9 Mon Sep 17 00:00:00 2001 From: Olivier Moysan Date: Wed, 19 Jun 2019 13:40:02 +0200 Subject: [PATCH] ASoC: stm32: dfsdm: add 16 bits audio record support Add support of audio 16 bits format record to STM32 DFSDM driver. Signed-off-by: Olivier Moysan Signed-off-by: Mark Brown --- sound/soc/stm/stm32_adfsdm.c | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/sound/soc/stm/stm32_adfsdm.c b/sound/soc/stm/stm32_adfsdm.c index cc517e007039..3c9a9deec9af 100644 --- a/sound/soc/stm/stm32_adfsdm.c +++ b/sound/soc/stm/stm32_adfsdm.c @@ -45,7 +45,7 @@ struct stm32_adfsdm_priv { static const struct snd_pcm_hardware stm32_adfsdm_pcm_hw = { .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_PAUSE, - .formats = SNDRV_PCM_FMTBIT_S32_LE, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, .rate_min = 8000, .rate_max = 32000, @@ -141,7 +141,8 @@ static const struct snd_soc_dai_driver stm32_adfsdm_dai = { .capture = { .channels_min = 1, .channels_max = 1, - .formats = SNDRV_PCM_FMTBIT_S32_LE, + .formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000), }, @@ -152,30 +153,58 @@ static const struct snd_soc_component_driver stm32_adfsdm_dai_component = { .name = "stm32_dfsdm_audio", }; +static void memcpy_32to16(void *dest, const void *src, size_t n) +{ + unsigned int i = 0; + u16 *d = (u16 *)dest, *s = (u16 *)src; + + s++; + for (i = n; i > 0; i--) { + *d++ = *s++; + s++; + } +} + static int stm32_afsdm_pcm_cb(const void *data, size_t size, void *private) { struct stm32_adfsdm_priv *priv = private; struct snd_soc_pcm_runtime *rtd = priv->substream->private_data; u8 *pcm_buff = priv->pcm_buff; u8 *src_buff = (u8 *)data; - unsigned int buff_size = snd_pcm_lib_buffer_bytes(priv->substream); - unsigned int period_size = snd_pcm_lib_period_bytes(priv->substream); unsigned int old_pos = priv->pos; - unsigned int cur_size = size; + size_t buff_size = snd_pcm_lib_buffer_bytes(priv->substream); + size_t period_size = snd_pcm_lib_period_bytes(priv->substream); + size_t cur_size, src_size = size; + snd_pcm_format_t format = priv->substream->runtime->format; + + if (format == SNDRV_PCM_FORMAT_S16_LE) + src_size >>= 1; + cur_size = src_size; dev_dbg(rtd->dev, "%s: buff_add :%pK, pos = %d, size = %zu\n", - __func__, &pcm_buff[priv->pos], priv->pos, size); + __func__, &pcm_buff[priv->pos], priv->pos, src_size); - if ((priv->pos + size) > buff_size) { - memcpy(&pcm_buff[priv->pos], src_buff, buff_size - priv->pos); + if ((priv->pos + src_size) > buff_size) { + if (format == SNDRV_PCM_FORMAT_S16_LE) + memcpy_32to16(&pcm_buff[priv->pos], src_buff, + buff_size - priv->pos); + else + memcpy(&pcm_buff[priv->pos], src_buff, + buff_size - priv->pos); cur_size -= buff_size - priv->pos; priv->pos = 0; } - memcpy(&pcm_buff[priv->pos], &src_buff[size - cur_size], cur_size); + if (format == SNDRV_PCM_FORMAT_S16_LE) + memcpy_32to16(&pcm_buff[priv->pos], + &src_buff[src_size - cur_size], cur_size); + else + memcpy(&pcm_buff[priv->pos], &src_buff[src_size - cur_size], + cur_size); + priv->pos = (priv->pos + cur_size) % buff_size; - if (cur_size != size || (old_pos && (old_pos % period_size < size))) + if (cur_size != src_size || (old_pos && (old_pos % period_size < size))) snd_pcm_period_elapsed(priv->substream); return 0; -- 2.20.1